mirror of
https://github.com/nerzhul/ownCloud-SMS-App.git
synced 2025-06-08 00:16:09 +00:00
The checkboxes are now working. Apply the filter on all syncing methods. Add a button to launch a sync from MainActivity
This commit is contained in:
parent
810567c237
commit
24f72073a4
@ -46,7 +46,7 @@
|
|||||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/mail_button_accounts"
|
android:id="@+id/main_button_accounts"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below="@+id/main_tv_accounts"
|
android:layout_below="@+id/main_tv_accounts"
|
||||||
@ -63,7 +63,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignLeft="@+id/main_tv_accounts"
|
android:layout_alignLeft="@+id/main_tv_accounts"
|
||||||
android:layout_alignStart="@+id/main_tv_accounts"
|
android:layout_alignStart="@+id/main_tv_accounts"
|
||||||
android:layout_below="@+id/mail_button_accounts"
|
android:layout_below="@+id/main_button_accounts"
|
||||||
android:layout_marginTop="18dp"
|
android:layout_marginTop="18dp"
|
||||||
android:text="@string/ma_title_change_settings"
|
android:text="@string/ma_title_change_settings"
|
||||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||||
@ -79,6 +79,29 @@
|
|||||||
android:background="@drawable/standard_button"
|
android:background="@drawable/standard_button"
|
||||||
style="@style/StandardButton"
|
style="@style/StandardButton"
|
||||||
android:text="@string/ma_button_goto_settings" />
|
android:text="@string/ma_button_goto_settings" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tv_launchsync"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignLeft="@+id/main_tv_accounts"
|
||||||
|
android:layout_alignStart="@+id/main_tv_accounts"
|
||||||
|
android:layout_below="@+id/main_button_settings"
|
||||||
|
android:layout_marginTop="18dp"
|
||||||
|
android:text="@string/ma_title_sync_all"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/main_button_sync"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/tv_launchsync"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:layout_marginTop="19dp"
|
||||||
|
android:onClick="syncAllMessages"
|
||||||
|
android:background="@drawable/standard_button"
|
||||||
|
style="@style/StandardButton"
|
||||||
|
android:text="@string/ma_button_sync_accounts_now" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/imageView1"
|
android:id="@+id/imageView1"
|
||||||
@ -86,7 +109,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignLeft="@+id/textView1"
|
android:layout_alignLeft="@+id/textView1"
|
||||||
android:layout_alignStart="@+id/textView1"
|
android:layout_alignStart="@+id/textView1"
|
||||||
android:layout_below="@+id/main_button_settings"
|
android:layout_below="@+id/main_button_sync"
|
||||||
android:layout_marginTop="33dp"
|
android:layout_marginTop="33dp"
|
||||||
android:src="@drawable/next_arrow" />
|
android:src="@drawable/next_arrow" />
|
||||||
|
|
||||||
|
@ -136,6 +136,8 @@
|
|||||||
<string name="ma_content_welcome">Welcome to ownCloud SMS application. This application let you synchronize your SMS to your ownCloud instance using SMS app.</string>
|
<string name="ma_content_welcome">Welcome to ownCloud SMS application. This application let you synchronize your SMS to your ownCloud instance using SMS app.</string>
|
||||||
<string name="ma_thanksto_people">ownCloud developers\n\
|
<string name="ma_thanksto_people">ownCloud developers\n\
|
||||||
Contributors and issue\'s reporters</string>
|
Contributors and issue\'s reporters</string>
|
||||||
|
<string name="ma_title_sync_all">Synchronize all messages</string>
|
||||||
|
<string name="ma_button_sync_accounts_now">Launch synchronization now</string>
|
||||||
|
|
||||||
<!-- Notifications -->
|
<!-- Notifications -->
|
||||||
<string name="sync_title">Sync process</string>
|
<string name="sync_title">Sync process</string>
|
||||||
|
@ -28,15 +28,19 @@ import android.content.SharedPreferences.Editor;
|
|||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.preference.CheckBoxPreference;
|
||||||
import android.preference.ListPreference;
|
import android.preference.ListPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
import android.preference.PreferenceFragment;
|
import android.preference.PreferenceFragment;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import fr.unix_experience.owncloud_sms.R;
|
import fr.unix_experience.owncloud_sms.R;
|
||||||
|
import fr.unix_experience.owncloud_sms.defines.DefaultPrefs;
|
||||||
|
import fr.unix_experience.owncloud_sms.prefs.OCSMSSharedPrefs;
|
||||||
|
|
||||||
public class GeneralSettingsActivity extends PreferenceActivity {
|
public class GeneralSettingsActivity extends PreferenceActivity {
|
||||||
private static final boolean ALWAYS_SIMPLE_PREFS = false;
|
private static final boolean ALWAYS_SIMPLE_PREFS = false;
|
||||||
@ -73,11 +77,7 @@ public class GeneralSettingsActivity extends PreferenceActivity {
|
|||||||
|
|
||||||
mContext = getBaseContext();
|
mContext = getBaseContext();
|
||||||
|
|
||||||
// Bind the summaries of EditText/List/Dialog/Ringtone preferences to
|
bindPreferences();
|
||||||
// their values. When their values change, their summaries are updated
|
|
||||||
// to reflect the new value, per the Android Design guidelines.
|
|
||||||
bindPreferenceSummaryToValue(findPreference("sync_frequency"));
|
|
||||||
//bindPreferenceSummaryToValue(findPreference("slow_sync_frequency"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
@ -114,9 +114,9 @@ public class GeneralSettingsActivity extends PreferenceActivity {
|
|||||||
private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() {
|
private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object value) {
|
public boolean onPreferenceChange(Preference preference, Object value) {
|
||||||
String stringValue = value.toString();
|
|
||||||
|
|
||||||
if (preference instanceof ListPreference) {
|
if (preference instanceof ListPreference) {
|
||||||
|
String prefKey = preference.getKey();
|
||||||
|
String stringValue = value.toString();
|
||||||
// For list preferences, look up the correct display value in
|
// For list preferences, look up the correct display value in
|
||||||
// the preference's 'entries' list.
|
// the preference's 'entries' list.
|
||||||
ListPreference listPreference = (ListPreference) preference;
|
ListPreference listPreference = (ListPreference) preference;
|
||||||
@ -127,9 +127,6 @@ public class GeneralSettingsActivity extends PreferenceActivity {
|
|||||||
.setSummary(index >= 0 ? listPreference.getEntries()[index]
|
.setSummary(index >= 0 ? listPreference.getEntries()[index]
|
||||||
: null);
|
: null);
|
||||||
|
|
||||||
|
|
||||||
String prefKey = preference.getKey();
|
|
||||||
|
|
||||||
Account[] myAccountList = mAccountMgr.getAccountsByType(mAccountType);
|
Account[] myAccountList = mAccountMgr.getAccountsByType(mAccountType);
|
||||||
|
|
||||||
// Handle sync frequency change
|
// Handle sync frequency change
|
||||||
@ -161,16 +158,6 @@ public class GeneralSettingsActivity extends PreferenceActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Network types allowed for sync
|
|
||||||
else if(prefKey.equals("sync_wifi") || prefKey.equals("sync_2g") ||
|
|
||||||
prefKey.equals("sync_3g") || prefKey.equals("sync_gprs") ||
|
|
||||||
prefKey.equals("sync_4g") || prefKey.equals("sync_others")) {
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
|
|
||||||
|
|
||||||
Editor edit = prefs.edit();
|
|
||||||
edit.putBoolean(prefKey, Boolean.parseBoolean(stringValue));
|
|
||||||
edit.commit();
|
|
||||||
}
|
|
||||||
// Slow Sync frequency
|
// Slow Sync frequency
|
||||||
/*else if (prefKey.equals(new String("slow_sync_frequency"))) {
|
/*else if (prefKey.equals(new String("slow_sync_frequency"))) {
|
||||||
long syncFreq = Long.parseLong((String)value);
|
long syncFreq = Long.parseLong((String)value);
|
||||||
@ -201,10 +188,22 @@ public class GeneralSettingsActivity extends PreferenceActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
} else if (preference instanceof CheckBoxPreference) {
|
||||||
|
String prefKey = preference.getKey();
|
||||||
|
Boolean boolValue = (Boolean)value;
|
||||||
|
// Network types allowed for sync
|
||||||
|
if(prefKey.equals(new String("sync_wifi")) || prefKey.equals("sync_2g") ||
|
||||||
|
prefKey.equals(new String("sync_3g")) || prefKey.equals("sync_gprs") ||
|
||||||
|
prefKey.equals("sync_4g") || prefKey.equals("sync_others")) {
|
||||||
|
Log.d("FUCK",prefKey + " " + boolValue.toString());
|
||||||
|
|
||||||
|
OCSMSSharedPrefs prefs = new OCSMSSharedPrefs(mContext);
|
||||||
|
prefs.putBoolean(prefKey, boolValue);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// For all other preferences, set the summary to the value's
|
// For all other preferences, set the summary to the value's
|
||||||
// simple string representation.
|
// simple string representation.
|
||||||
preference.setSummary(stringValue);
|
//preference.setSummary(boolValue);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -219,7 +218,24 @@ public class GeneralSettingsActivity extends PreferenceActivity {
|
|||||||
*
|
*
|
||||||
* @see #sBindPreferenceSummaryToValueListener
|
* @see #sBindPreferenceSummaryToValueListener
|
||||||
*/
|
*/
|
||||||
private static void bindPreferenceSummaryToValue(Preference preference) {
|
private static void bindPreferenceBooleanToValue(Preference preference, Boolean defValue) {
|
||||||
|
// Set the listener to watch for value changes.
|
||||||
|
preference
|
||||||
|
.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
|
||||||
|
|
||||||
|
// Trigger the listener immediately with the preference's
|
||||||
|
// current value.
|
||||||
|
sBindPreferenceSummaryToValueListener.onPreferenceChange(
|
||||||
|
preference,
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(
|
||||||
|
preference.getContext()).getBoolean(
|
||||||
|
preference.getKey(),
|
||||||
|
defValue
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void bindPreferenceStringToValue(Preference preference) {
|
||||||
// Set the listener to watch for value changes.
|
// Set the listener to watch for value changes.
|
||||||
preference
|
preference
|
||||||
.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
|
.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
|
||||||
@ -251,8 +267,29 @@ public class GeneralSettingsActivity extends PreferenceActivity {
|
|||||||
// to their values. When their values change, their summaries are
|
// to their values. When their values change, their summaries are
|
||||||
// updated to reflect the new value, per the Android Design
|
// updated to reflect the new value, per the Android Design
|
||||||
// guidelines.
|
// guidelines.
|
||||||
bindPreferenceSummaryToValue(findPreference("sync_frequency"));
|
bindPreferenceStringToValue(findPreference("sync_frequency"));
|
||||||
|
bindPreferenceBooleanToValue(findPreference("sync_wifi"), DefaultPrefs.syncWifi);
|
||||||
|
bindPreferenceBooleanToValue(findPreference("sync_4g"), DefaultPrefs.sync4G);
|
||||||
|
bindPreferenceBooleanToValue(findPreference("sync_3g"), DefaultPrefs.sync3G);
|
||||||
|
bindPreferenceBooleanToValue(findPreference("sync_gprs"), DefaultPrefs.syncGPRS);
|
||||||
|
bindPreferenceBooleanToValue(findPreference("sync_2g"), DefaultPrefs.sync2G);
|
||||||
|
bindPreferenceBooleanToValue(findPreference("sync_others"), DefaultPrefs.syncOthers);
|
||||||
//bindPreferenceSummaryToValue(findPreference("slow_sync_frequency"));
|
//bindPreferenceSummaryToValue(findPreference("slow_sync_frequency"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void bindPreferences() {
|
||||||
|
mContext = getBaseContext();
|
||||||
|
|
||||||
|
// Bind the summaries of EditText/List/Dialog/Ringtone preferences to
|
||||||
|
// their values. When their values change, their summaries are updated
|
||||||
|
// to reflect the new value, per the Android Design guidelines.
|
||||||
|
bindPreferenceStringToValue(findPreference("sync_frequency"));
|
||||||
|
bindPreferenceBooleanToValue(findPreference("sync_wifi"), DefaultPrefs.syncWifi);
|
||||||
|
bindPreferenceBooleanToValue(findPreference("sync_4g"), DefaultPrefs.sync4G);
|
||||||
|
bindPreferenceBooleanToValue(findPreference("sync_3g"), DefaultPrefs.sync3G);
|
||||||
|
bindPreferenceBooleanToValue(findPreference("sync_gprs"), DefaultPrefs.syncGPRS);
|
||||||
|
bindPreferenceBooleanToValue(findPreference("sync_2g"), DefaultPrefs.sync2G);
|
||||||
|
bindPreferenceBooleanToValue(findPreference("sync_others"), DefaultPrefs.syncOthers);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,13 @@ package fr.unix_experience.owncloud_sms.activities;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
|
||||||
import fr.unix_experience.owncloud_sms.R;
|
import fr.unix_experience.owncloud_sms.R;
|
||||||
|
import fr.unix_experience.owncloud_sms.engine.ConnectivityMonitor;
|
||||||
|
import fr.unix_experience.owncloud_sms.engine.SmsFetcher;
|
||||||
|
import fr.unix_experience.owncloud_sms.engine.ASyncTask.SyncTask;
|
||||||
|
import fr.unix_experience.owncloud_sms.prefs.OCSMSSharedPrefs;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.app.FragmentManager;
|
import android.app.FragmentManager;
|
||||||
@ -39,6 +45,7 @@ import android.provider.Settings;
|
|||||||
import android.support.v13.app.FragmentPagerAdapter;
|
import android.support.v13.app.FragmentPagerAdapter;
|
||||||
import android.support.v4.view.PagerAdapter;
|
import android.support.v4.view.PagerAdapter;
|
||||||
import android.support.v4.view.ViewPager;
|
import android.support.v4.view.ViewPager;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -151,6 +158,20 @@ public class MainActivity extends Activity {
|
|||||||
public void openAddAccount(View view) {
|
public void openAddAccount(View view) {
|
||||||
startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT));
|
startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void syncAllMessages(View view) {
|
||||||
|
ConnectivityMonitor cMon = new ConnectivityMonitor(getApplicationContext());
|
||||||
|
|
||||||
|
if (cMon.isValid()) {
|
||||||
|
// Now fetch messages since last stored date
|
||||||
|
JSONArray smsList = new SmsFetcher(getApplicationContext())
|
||||||
|
.bufferizeMessagesSinceDate((long) 0);
|
||||||
|
|
||||||
|
if (smsList != null) {
|
||||||
|
new SyncTask(getApplicationContext(), smsList).execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void openGooglePlayStore(View view) {
|
public void openGooglePlayStore(View view) {
|
||||||
Intent intent;
|
Intent intent;
|
||||||
|
@ -34,12 +34,11 @@ public class ConnectivityChanged extends BroadcastReceiver implements ASyncTask
|
|||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
ConnectivityMonitor cMon = new ConnectivityMonitor(context);
|
ConnectivityMonitor cMon = new ConnectivityMonitor(context);
|
||||||
|
|
||||||
Log.d(TAG, "test");
|
|
||||||
// If data is available and previous dataConnectionState was false, then we need to sync
|
// If data is available and previous dataConnectionState was false, then we need to sync
|
||||||
if (cMon.isValid() && dataConnectionAvailable == false) {
|
if (cMon.isValid() && dataConnectionAvailable == false) {
|
||||||
dataConnectionAvailable = true;
|
dataConnectionAvailable = true;
|
||||||
Log.d(TAG,"ConnectivityChanged.onReceive, data conn available");
|
Log.d(TAG,"ConnectivityChanged.onReceive, data conn available");
|
||||||
checkMessagesToSend(context);
|
checkMessagesAndSend(context);
|
||||||
}
|
}
|
||||||
// No data available and previous dataConnectionState was true
|
// No data available and previous dataConnectionState was true
|
||||||
else if (dataConnectionAvailable == true && !cMon.isValid()) {
|
else if (dataConnectionAvailable == true && !cMon.isValid()) {
|
||||||
@ -48,7 +47,7 @@ public class ConnectivityChanged extends BroadcastReceiver implements ASyncTask
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkMessagesToSend(Context context) {
|
private void checkMessagesAndSend(Context context) {
|
||||||
// Get last message synced from preferences
|
// Get last message synced from preferences
|
||||||
Long lastMessageSynced = (new OCSMSSharedPrefs(context)).getLastMessageDate();
|
Long lastMessageSynced = (new OCSMSSharedPrefs(context)).getLastMessageDate();
|
||||||
Log.d(TAG,"Synced Last:" + lastMessageSynced);
|
Log.d(TAG,"Synced Last:" + lastMessageSynced);
|
||||||
@ -56,7 +55,10 @@ public class ConnectivityChanged extends BroadcastReceiver implements ASyncTask
|
|||||||
// Now fetch messages since last stored date
|
// Now fetch messages since last stored date
|
||||||
JSONArray smsList = new SmsFetcher(context).bufferizeMessagesSinceDate(lastMessageSynced);
|
JSONArray smsList = new SmsFetcher(context).bufferizeMessagesSinceDate(lastMessageSynced);
|
||||||
|
|
||||||
if (smsList != null) {
|
ConnectivityMonitor cMon = new ConnectivityMonitor(context);
|
||||||
|
|
||||||
|
// Synchronize if network is valid and there are SMS
|
||||||
|
if (cMon.isValid() && smsList != null) {
|
||||||
new SyncTask(context, smsList).execute();
|
new SyncTask(context, smsList).execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,12 +16,10 @@ package fr.unix_experience.owncloud_sms.engine;
|
|||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import fr.unix_experience.owncloud_sms.defines.DefaultPrefs;
|
import fr.unix_experience.owncloud_sms.prefs.OCSMSSharedPrefs;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
|
|
||||||
public class ConnectivityMonitor {
|
public class ConnectivityMonitor {
|
||||||
@ -42,21 +40,21 @@ public class ConnectivityMonitor {
|
|||||||
// Load the connectivity manager to determine on which network we are connected
|
// Load the connectivity manager to determine on which network we are connected
|
||||||
NetworkInfo netInfo = _cMgr.getActiveNetworkInfo();
|
NetworkInfo netInfo = _cMgr.getActiveNetworkInfo();
|
||||||
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(_context);
|
OCSMSSharedPrefs prefs = new OCSMSSharedPrefs(_context);
|
||||||
|
|
||||||
// Check
|
// Check
|
||||||
switch (netInfo.getType()) {
|
switch (netInfo.getType()) {
|
||||||
case ConnectivityManager.TYPE_WIFI:
|
case ConnectivityManager.TYPE_WIFI:
|
||||||
return prefs.getBoolean("sync_wifi", DefaultPrefs.syncWifi);
|
return prefs.syncInWifi();
|
||||||
case ConnectivityManager.TYPE_MOBILE:
|
case ConnectivityManager.TYPE_MOBILE:
|
||||||
switch (netInfo.getSubtype()) {
|
switch (netInfo.getSubtype()) {
|
||||||
case TelephonyManager.NETWORK_TYPE_EDGE:
|
case TelephonyManager.NETWORK_TYPE_EDGE:
|
||||||
case TelephonyManager.NETWORK_TYPE_CDMA:
|
case TelephonyManager.NETWORK_TYPE_CDMA:
|
||||||
case TelephonyManager.NETWORK_TYPE_1xRTT:
|
case TelephonyManager.NETWORK_TYPE_1xRTT:
|
||||||
case TelephonyManager.NETWORK_TYPE_IDEN:
|
case TelephonyManager.NETWORK_TYPE_IDEN:
|
||||||
return prefs.getBoolean("sync_2g", DefaultPrefs.sync2G);
|
return prefs.syncIn2G();
|
||||||
case TelephonyManager.NETWORK_TYPE_GPRS:
|
case TelephonyManager.NETWORK_TYPE_GPRS:
|
||||||
return prefs.getBoolean("sync_gprs", DefaultPrefs.syncGPRS);
|
return prefs.syncInGPRS();
|
||||||
case TelephonyManager.NETWORK_TYPE_HSDPA:
|
case TelephonyManager.NETWORK_TYPE_HSDPA:
|
||||||
case TelephonyManager.NETWORK_TYPE_HSPA:
|
case TelephonyManager.NETWORK_TYPE_HSPA:
|
||||||
case TelephonyManager.NETWORK_TYPE_HSUPA:
|
case TelephonyManager.NETWORK_TYPE_HSUPA:
|
||||||
@ -64,14 +62,14 @@ public class ConnectivityMonitor {
|
|||||||
case TelephonyManager.NETWORK_TYPE_EHRPD:
|
case TelephonyManager.NETWORK_TYPE_EHRPD:
|
||||||
case TelephonyManager.NETWORK_TYPE_EVDO_B:
|
case TelephonyManager.NETWORK_TYPE_EVDO_B:
|
||||||
case TelephonyManager.NETWORK_TYPE_HSPAP:
|
case TelephonyManager.NETWORK_TYPE_HSPAP:
|
||||||
return prefs.getBoolean("sync_3g", DefaultPrefs.sync3G);
|
return prefs.syncIn3G();
|
||||||
case TelephonyManager.NETWORK_TYPE_LTE:
|
case TelephonyManager.NETWORK_TYPE_LTE:
|
||||||
return prefs.getBoolean("sync_4g", DefaultPrefs.sync3G);
|
return prefs.syncIn4G();
|
||||||
default:
|
default:
|
||||||
return prefs.getBoolean("sync_others", DefaultPrefs.syncOthers);
|
return prefs.syncInOtherModes();
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return prefs.getBoolean("sync_others", DefaultPrefs.syncOthers);
|
return prefs.syncInOtherModes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ package fr.unix_experience.owncloud_sms.observers;
|
|||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
|
|
||||||
import fr.unix_experience.owncloud_sms.engine.ASyncTask;
|
import fr.unix_experience.owncloud_sms.engine.ASyncTask;
|
||||||
|
import fr.unix_experience.owncloud_sms.engine.ConnectivityMonitor;
|
||||||
import fr.unix_experience.owncloud_sms.engine.OCSMSOwnCloudClient;
|
import fr.unix_experience.owncloud_sms.engine.OCSMSOwnCloudClient;
|
||||||
import fr.unix_experience.owncloud_sms.engine.SmsFetcher;
|
import fr.unix_experience.owncloud_sms.engine.SmsFetcher;
|
||||||
import fr.unix_experience.owncloud_sms.enums.MailboxID;
|
import fr.unix_experience.owncloud_sms.enums.MailboxID;
|
||||||
@ -46,7 +47,10 @@ public class SmsObserver extends ContentObserver implements ASyncTask {
|
|||||||
SmsFetcher fetcher = new SmsFetcher(_context);
|
SmsFetcher fetcher = new SmsFetcher(_context);
|
||||||
JSONArray smsList = fetcher.getLastMessage(MailboxID.ALL);
|
JSONArray smsList = fetcher.getLastMessage(MailboxID.ALL);
|
||||||
|
|
||||||
if (smsList != null) {
|
ConnectivityMonitor cMon = new ConnectivityMonitor(_context);
|
||||||
|
|
||||||
|
// Synchronize if network is valid and there are SMS
|
||||||
|
if (cMon.isValid() && smsList != null) {
|
||||||
new SyncTask(_context, smsList).execute();
|
new SyncTask(_context, smsList).execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,10 @@ package fr.unix_experience.owncloud_sms.prefs;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import fr.unix_experience.owncloud_sms.R;
|
import fr.unix_experience.owncloud_sms.R;
|
||||||
|
import fr.unix_experience.owncloud_sms.defines.DefaultPrefs;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.SharedPreferences.Editor;
|
||||||
|
|
||||||
public class OCSMSSharedPrefs {
|
public class OCSMSSharedPrefs {
|
||||||
|
|
||||||
@ -29,6 +31,12 @@ public class OCSMSSharedPrefs {
|
|||||||
_sPrefs = _context.getSharedPreferences(_context.getString(R.string.shared_preference_file), Context.MODE_PRIVATE);
|
_sPrefs = _context.getSharedPreferences(_context.getString(R.string.shared_preference_file), Context.MODE_PRIVATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void putBoolean(String prefKey, Boolean boolValue) {
|
||||||
|
Editor edit = _sPrefs.edit();
|
||||||
|
edit.putBoolean(prefKey, boolValue);
|
||||||
|
edit.commit();
|
||||||
|
}
|
||||||
|
|
||||||
public void setLastMessageDate(Long msgDate) {
|
public void setLastMessageDate(Long msgDate) {
|
||||||
SharedPreferences.Editor editor = _sPrefs.edit();
|
SharedPreferences.Editor editor = _sPrefs.edit();
|
||||||
editor.putLong(_context.getString(R.string.pref_lastmsgdate), msgDate);
|
editor.putLong(_context.getString(R.string.pref_lastmsgdate), msgDate);
|
||||||
@ -39,6 +47,30 @@ public class OCSMSSharedPrefs {
|
|||||||
return _sPrefs.getLong(_context.getString(R.string.pref_lastmsgdate), 0);
|
return _sPrefs.getLong(_context.getString(R.string.pref_lastmsgdate), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean syncInWifi() {
|
||||||
|
return _sPrefs.getBoolean("sync_wifi", DefaultPrefs.syncWifi);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean syncIn2G() {
|
||||||
|
return _sPrefs.getBoolean("sync_2g", DefaultPrefs.sync2G);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean syncInGPRS() {
|
||||||
|
return _sPrefs.getBoolean("sync_gprs", DefaultPrefs.syncGPRS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean syncIn3G() {
|
||||||
|
return _sPrefs.getBoolean("sync_3g", DefaultPrefs.sync3G);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean syncIn4G() {
|
||||||
|
return _sPrefs.getBoolean("sync_4g", DefaultPrefs.sync4G);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean syncInOtherModes() {
|
||||||
|
return _sPrefs.getBoolean("sync_others", DefaultPrefs.syncOthers);
|
||||||
|
}
|
||||||
|
|
||||||
private SharedPreferences _sPrefs;
|
private SharedPreferences _sPrefs;
|
||||||
private Context _context;
|
private Context _context;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user