🐛 Fix connectivity issues

This commit is contained in:
Christian Basler 2018-06-14 06:56:07 +02:00
parent c6e29c056b
commit a01f116065
4 changed files with 5 additions and 11 deletions

View File

@ -179,6 +179,8 @@ class MainActivity : AppCompatActivity(), ListSelectionListener<Serializable> {
.setDelay(1000) .setDelay(1000)
.show() .show()
} }
SyncAdapter.startSync(this)
} }
private fun <F> changeList(listFragment: F) where F : Fragment, F : ListHolder<*> { private fun <F> changeList(listFragment: F) where F : Fragment, F : ListHolder<*> {

View File

@ -189,21 +189,10 @@ class SettingsFragment : PreferenceFragmentCompat(), SharedPreferences.OnSharedP
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) { override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
when (key) { when (key) {
PREFERENCE_TRUSTED_NODE -> toggleSyncTrustedNode(sharedPreferences)
PREFERENCE_SERVER_POW -> toggleSyncServerPOW(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) { private fun toggleSyncServerPOW(sharedPreferences: SharedPreferences) {
val node = sharedPreferences.getString(PREFERENCE_TRUSTED_NODE, null) val node = sharedPreferences.getString(PREFERENCE_TRUSTED_NODE, null)
if (node != null) { if (node != null) {

View File

@ -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. * And stops it when the preconditions for the job (unmetered network) aren't met anymore.
*/ */
class StartupNodeOnWifiService : JobService() { class StartupNodeOnWifiService : JobService() {
override fun onStartJob(params: JobParameters?): Boolean { override fun onStartJob(params: JobParameters?): Boolean {
val bmc = Singleton.getBitmessageContext(this) val bmc = Singleton.getBitmessageContext(this)
if (Preferences.isFullNodeActive(this) && !bmc.isRunning()) { if (Preferences.isFullNodeActive(this) && !bmc.isRunning()) {
@ -28,4 +29,5 @@ class StartupNodeOnWifiService : JobService() {
* depending on Android version. * depending on Android version.
*/ */
override fun onStopJob(params: JobParameters?) = Preferences.isFullNodeActive(this) override fun onStopJob(params: JobParameters?) = Preferences.isFullNodeActive(this)
} }

View File

@ -76,6 +76,7 @@ class SyncAdapter(context: Context, autoInitialize: Boolean) : AbstractThreadedS
} }
val trustedNode = Preferences.getTrustedNode(context) val trustedNode = Preferences.getTrustedNode(context)
if (trustedNode == null) { 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) NetworkUtils.scheduleNodeStart(context)
return return
} }