Fabio Arnold 7 years ago
parent
commit
319c38bb95

+ 2 - 0
res/values-de/strings.xml

@@ -262,6 +262,8 @@
     <string name="no_portbinder_msg">Ihr Smartphone hat keinen  \'Portbinder\' installiert. Aufgrund von Einschränkungen unter Android können sie nur Dienste mit Ports >1024 benutzten.\n\nUm die volle Funktionalität von  HosTaGe nutzen zu können, müssen sie sicherstellen, dass ihr Smartphone gerootet ist und  der \'Portbinder\' installiert ist.</string>
     <string name="no_portbinder_msg2">Ihr Smartphone unterstützt zur Zeit nicht alle Funktionen von HosTaGe. Klicken sie auf \'Hilfe\' um mehr zu erfahren.</string>
     <string name="confirm">Bestätigen</string>
+    <string name="pref_sync_frequency_summary">Der Intervall in minuten in dem eine Synchronisierung mit TraCINg durchgeführt werden soll.</string>
+    <string name="pref_sync_frequency_title">Synchronisierungsinterval</string>
     <string name="hostage_live_threat">Netzwerk ist infiziert!</string>
     <string name="hostage_no_threat">Netzwerk sieht sicher aus</string>
     <string name="hostage_not_monitoring">HosTaGe ist inaktiv</string>

+ 0 - 2
res/values-de/strings_preferences.xml

@@ -15,8 +15,6 @@
     <string name="pref_vibration_summ">Aktiviere Vibration</string>
     <string name="pref_upload">Upload von Aufzeichnungen</string>
     <string name="pref_upload_server">Server-Adresse</string>
-    <string name="pref_sync_frequency">Upload-Häufigkeit</string>
-    <string name="pref_sync_frequency_summary">Intervall in Sekunden, in dem Aufzeichnungen zur Online-Datenbank hochgeladen werden</string>
     <string name="pref_connection_settings">Verbindungs Einstellungen</string>
     <string name="pref_max_connections">Max Verbindungen</string>
     <string name="pref_max_connections_default">5</string>

+ 2 - 0
res/values/strings.xml

@@ -268,4 +268,6 @@
     <string name="pref_download_server">Download server</string>
 	<string name="google_play_services_unavailable">Error: Google Play Services are unavailable.
 	</string>
+    <string name="pref_sync_frequency_summary">The interval in minutes synchronization with TraCINg should be performed</string>
+    <string name="pref_sync_frequency_title">Synchronization interval</string>
 </resources>

+ 0 - 2
res/values/strings_preferences.xml

@@ -15,8 +15,6 @@
 	<string name="pref_vibration_summ">Enable Vibration</string>
 	<string name="pref_upload">Online Database</string>
 	<string name="pref_upload_server">Server Address</string>
-	<string name="pref_sync_frequency">Sync Frequency</string>
-	<string name="pref_sync_frequency_summary">Interval in seconds at which records will be uploaded to the online database</string>
 	<string name="pref_connection_settings">Connection Settings</string>
 	<string name="pref_max_connections">Max Connections</string>	
 	<integer name="pref_max_connections_default">5</integer>

+ 7 - 8
res/xml/settings_preferences.xml

@@ -37,14 +37,13 @@
 				android:defaultValue="https://ssi.cased.de"
 				android:title="@string/pref_upload_server" />
 
-		<EditTextPreference
-				android:inputType="number"
-				android:numeric="decimal"
-				android:key="pref_sync_frequency"
-				android:defaultValue="300"
-				android:title="@string/pref_sync_frequency"
-				android:summary="@string/pref_sync_frequency_summary" />
-
+        <EditTextPreference
+                android:key="pref_sync_frequency"
+                android:defaultValue="5"
+                android:title="@string/pref_sync_frequency_title"
+                android:summary="@string/pref_sync_frequency_summary"
+                android:inputType="number"
+                android:numeric="decimal" />
         <!--<EditTextPreference
             android:key="pref_download_server"
             android:defaultValue="http://ssi.cased.de/api"

+ 22 - 5
src/de/tudarmstadt/informatik/hostage/sync/android/SyncUtils.java

@@ -68,9 +68,14 @@ import de.tudarmstadt.informatik.hostage.ui.activity.MainActivity;
  */
 public class SyncUtils {
     public static final int SYNC_SUCCESSFUL = 0x0;
+    private static final long SYNC_FREQUENCY_MINUTES = 5;
+    private static final long SYNC_FREQUENCY_UNIT = 60;
+    private static final long SYNC_FREQUENCY = SYNC_FREQUENCY_UNIT * SYNC_FREQUENCY_MINUTES;  // 5 min (in seconds)
 
     public static final String CONTENT_AUTHORITY = "de.tudarmstadt.informatik.hostage.androidsync";
     private static final String PREF_SETUP_COMPLETE = "sync_setup_complete";
+    private static final String PREF_SYNC_INTERNAL_FREQUENCY = "pref_sync_internal_frequency";
+    private static final String PREF_SYNC_FREQUENCY = "pref_sync_frequency";
 
     private static final Map<String, Integer> protocolsTypeMap;
 
@@ -97,8 +102,8 @@ public class SyncUtils {
      */
     public static void CreateSyncAccount(Context context) {
         boolean newAccount = false;
-        boolean setupComplete = PreferenceManager
-                .getDefaultSharedPreferences(context).getBoolean(PREF_SETUP_COMPLETE, false);
+        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
+        boolean setupComplete = preferences.getBoolean(PREF_SETUP_COMPLETE, false);
 
         // Create account, if it's missing. (Either first run, or user has deleted account.)
         Account account = HostageAccountService.GetAccount();
@@ -113,7 +118,8 @@ public class SyncUtils {
             SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
             long syncFrequency = pref.getInt("pref_sync_frequency", 5*60); // default is 5min
             ContentResolver.addPeriodicSync(
-                    account, CONTENT_AUTHORITY, new Bundle(),syncFrequency);
+                    account, CONTENT_AUTHORITY, new Bundle(), SYNC_FREQUENCY);
+            preferences.edit().putLong(PREF_SYNC_INTERNAL_FREQUENCY, SYNC_FREQUENCY).commit();
             newAccount = true;
         }
 
@@ -122,8 +128,19 @@ public class SyncUtils {
         // the account list, so wee need to check both.)
         if (newAccount || !setupComplete) {
             TriggerRefresh();
-            PreferenceManager.getDefaultSharedPreferences(context).edit()
-                    .putBoolean(PREF_SETUP_COMPLETE, true).commit();
+            preferences.edit().putBoolean(PREF_SETUP_COMPLETE, true).commit();
+        }
+
+        if(setupComplete){
+            long syncFrequency = Long.valueOf(preferences.getString(PREF_SYNC_FREQUENCY, "" + SYNC_FREQUENCY_MINUTES)) * SYNC_FREQUENCY_UNIT;
+            long internalFrequency = preferences.getLong(PREF_SYNC_INTERNAL_FREQUENCY, SYNC_FREQUENCY);
+
+            if(syncFrequency != internalFrequency){
+                ContentResolver.removePeriodicSync(account, CONTENT_AUTHORITY, new Bundle());
+                ContentResolver.addPeriodicSync(account, CONTENT_AUTHORITY, new Bundle(), syncFrequency);
+
+                preferences.edit().putLong(PREF_SYNC_INTERNAL_FREQUENCY, syncFrequency).commit();
+            }
         }
     }
 

+ 4 - 0
src/de/tudarmstadt/informatik/hostage/ui/activity/MainActivity.java

@@ -321,10 +321,13 @@ public class MainActivity extends Activity {
 		} else {
             mDisplayedFragmentIndex = savedInstanceState.getInt("mDisplayedFragmentIndex");
             mDisplayedFragment = getFragmentManager().getFragment(savedInstanceState, "mDisplayedFragment");
+            mRootFragment = getFragmentManager().getFragment(savedInstanceState, "mRootFragment");
 
             mDrawerList.setItemChecked(mDisplayedFragmentIndex, true);
             mDrawerList.setSelection(mDisplayedFragmentIndex);
             setTitle(mDrawerItems.get(mDisplayedFragmentIndex).text);
+            getFragmentManager().popBackStack(HomeFragment.class.getName(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
+            getFragmentManager().putFragment(savedInstanceState, mRootFragment.getClass().getName(), mRootFragment);
 
             injectFragment(mDisplayedFragment);
         }
@@ -335,6 +338,7 @@ public class MainActivity extends Activity {
         super.onSaveInstanceState(outState);
 
         outState.putInt("mDisplayedFragmentIndex", mDisplayedFragmentIndex);
+        getFragmentManager().putFragment(outState, "mRootFragment", mRootFragment);
         getFragmentManager().putFragment(outState, "mDisplayedFragment", mDisplayedFragment);
     }