diff --git a/app/src/main/java/ch/dissem/apps/abit/MainActivity.kt b/app/src/main/java/ch/dissem/apps/abit/MainActivity.kt index e7d5b88..ade79e1 100644 --- a/app/src/main/java/ch/dissem/apps/abit/MainActivity.kt +++ b/app/src/main/java/ch/dissem/apps/abit/MainActivity.kt @@ -179,6 +179,8 @@ class MainActivity : AppCompatActivity(), ListSelectionListener { .setDelay(1000) .show() } + + SyncAdapter.startSync(this) } private fun changeList(listFragment: F) where F : Fragment, F : ListHolder<*> { diff --git a/app/src/main/java/ch/dissem/apps/abit/SettingsFragment.kt b/app/src/main/java/ch/dissem/apps/abit/SettingsFragment.kt index 7ec83f6..7ddc4d7 100644 --- a/app/src/main/java/ch/dissem/apps/abit/SettingsFragment.kt +++ b/app/src/main/java/ch/dissem/apps/abit/SettingsFragment.kt @@ -189,21 +189,10 @@ class SettingsFragment : PreferenceFragmentCompat(), SharedPreferences.OnSharedP override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) { when (key) { - PREFERENCE_TRUSTED_NODE -> toggleSyncTrustedNode(sharedPreferences) PREFERENCE_SERVER_POW -> toggleSyncServerPOW(sharedPreferences) } } - private fun toggleSyncTrustedNode(sharedPreferences: SharedPreferences) { - val node = sharedPreferences.getString(PREFERENCE_TRUSTED_NODE, null) - val ctx = context ?: throw IllegalStateException("No context available") - if (node != null) { - SyncAdapter.startSync(ctx) - } else { - SyncAdapter.stopSync(ctx) - } - } - private fun toggleSyncServerPOW(sharedPreferences: SharedPreferences) { val node = sharedPreferences.getString(PREFERENCE_TRUSTED_NODE, null) if (node != null) { diff --git a/app/src/main/java/ch/dissem/apps/abit/service/StartupNodeOnWifiService.kt b/app/src/main/java/ch/dissem/apps/abit/service/StartupNodeOnWifiService.kt index 0ba1378..81f23f4 100644 --- a/app/src/main/java/ch/dissem/apps/abit/service/StartupNodeOnWifiService.kt +++ b/app/src/main/java/ch/dissem/apps/abit/service/StartupNodeOnWifiService.kt @@ -15,6 +15,7 @@ import ch.dissem.apps.abit.util.Preferences * And stops it when the preconditions for the job (unmetered network) aren't met anymore. */ class StartupNodeOnWifiService : JobService() { + override fun onStartJob(params: JobParameters?): Boolean { val bmc = Singleton.getBitmessageContext(this) if (Preferences.isFullNodeActive(this) && !bmc.isRunning()) { @@ -28,4 +29,5 @@ class StartupNodeOnWifiService : JobService() { * depending on Android version. */ override fun onStopJob(params: JobParameters?) = Preferences.isFullNodeActive(this) + } diff --git a/app/src/main/java/ch/dissem/apps/abit/synchronization/SyncAdapter.kt b/app/src/main/java/ch/dissem/apps/abit/synchronization/SyncAdapter.kt index 0bfd678..8dc6d22 100644 --- a/app/src/main/java/ch/dissem/apps/abit/synchronization/SyncAdapter.kt +++ b/app/src/main/java/ch/dissem/apps/abit/synchronization/SyncAdapter.kt @@ -76,6 +76,7 @@ class SyncAdapter(context: Context, autoInitialize: Boolean) : AbstractThreadedS } val trustedNode = Preferences.getTrustedNode(context) if (trustedNode == null) { + // As Abit tends to get killed by the system, let's leverage the sync mechanism to start it again: NetworkUtils.scheduleNodeStart(context) return }