From 3767d976c859f7a257aee29c90bb8ca11b33811a Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Thu, 5 Jul 2018 19:44:04 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=94=A5=20Massively=20simplified=20how?= =?UTF-8?q?=20Abit=20connects=20to=20the=20network?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Removed features "Synchronization" and "Server POW" * Service isn't foreground anymore (not yet sure this is a good decision) * "Full node" renamed to "online" --- app/src/main/AndroidManifest.xml | 36 +--- .../apps/abit/ComposeMessageFragment.kt | 2 +- .../java/ch/dissem/apps/abit/MainActivity.kt | 30 +-- .../dissem/apps/abit/MessageListFragment.kt | 35 ++-- .../ch/dissem/apps/abit/SettingsFragment.kt | 30 +-- .../adapter/SwitchingProofOfWorkEngine.kt | 48 ----- .../dialog/SelectEncodingDialogFragment.kt | 2 +- .../apps/abit/listener/MessageListener.kt | 2 +- .../dissem/apps/abit/pow/ServerPowEngine.kt | 83 -------- .../apps/abit/service/BitmessageService.kt | 4 +- ...OnWifiService.kt => NodeStartupService.kt} | 8 +- .../ch/dissem/apps/abit/service/Singleton.kt | 11 +- .../apps/abit/service/StartServiceReceiver.kt | 7 +- .../abit/synchronization/Authenticator.kt | 62 ------ .../synchronization/AuthenticatorService.kt | 42 ---- .../apps/abit/synchronization/StubProvider.kt | 72 ------- .../apps/abit/synchronization/SyncAdapter.kt | 188 ------------------ .../apps/abit/synchronization/SyncService.kt | 50 ----- .../ch/dissem/apps/abit/util/Constants.kt | 5 +- .../ch/dissem/apps/abit/util/NetworkUtils.kt | 22 +- .../ch/dissem/apps/abit/util/Observable.kt | 4 +- .../ch/dissem/apps/abit/util/Preferences.kt | 90 ++------- .../drawable/material_showcase_button_bg.xml | 9 - app/src/main/res/values-ar/strings.xml | 7 - app/src/main/res/values-de/strings.xml | 20 +- app/src/main/res/values-fr/strings.xml | 12 +- app/src/main/res/values/strings.xml | 3 + app/src/main/res/xml/authenticator.xml | 6 - app/src/main/res/xml/preferences.xml | 33 +-- app/src/main/res/xml/syncadapter.xml | 9 - .../dissem/bitmessage/repository/TestBase.kt | 2 +- 31 files changed, 101 insertions(+), 833 deletions(-) delete mode 100644 app/src/main/java/ch/dissem/apps/abit/adapter/SwitchingProofOfWorkEngine.kt delete mode 100644 app/src/main/java/ch/dissem/apps/abit/pow/ServerPowEngine.kt rename app/src/main/java/ch/dissem/apps/abit/service/{StartupNodeOnWifiService.kt => NodeStartupService.kt} (73%) delete mode 100644 app/src/main/java/ch/dissem/apps/abit/synchronization/Authenticator.kt delete mode 100644 app/src/main/java/ch/dissem/apps/abit/synchronization/AuthenticatorService.kt delete mode 100644 app/src/main/java/ch/dissem/apps/abit/synchronization/StubProvider.kt delete mode 100644 app/src/main/java/ch/dissem/apps/abit/synchronization/SyncAdapter.kt delete mode 100644 app/src/main/java/ch/dissem/apps/abit/synchronization/SyncService.kt delete mode 100644 app/src/main/res/drawable/material_showcase_button_bg.xml delete mode 100644 app/src/main/res/xml/authenticator.xml delete mode 100644 app/src/main/res/xml/syncadapter.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 81d0586..0f7bfcd 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -11,8 +11,6 @@ - - - - - - - - - - - - - - - - - - - @@ -182,7 +150,7 @@ diff --git a/app/src/main/java/ch/dissem/apps/abit/ComposeMessageFragment.kt b/app/src/main/java/ch/dissem/apps/abit/ComposeMessageFragment.kt index 10cb977..ff1b37b 100644 --- a/app/src/main/java/ch/dissem/apps/abit/ComposeMessageFragment.kt +++ b/app/src/main/java/ch/dissem/apps/abit/ComposeMessageFragment.kt @@ -76,7 +76,7 @@ class ComposeMessageFragment : Fragment() { parents.addAll(draft.parents) } else { var id = getSerializable(EXTRA_IDENTITY) as? BitmessageAddress - if (context != null && (id == null || id.privateKey == null)) { + if (context != null && id?.privateKey == null) { id = Singleton.getIdentity(context!!) } if (id?.privateKey != null) { 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 ade79e1..646579e 100644 --- a/app/src/main/java/ch/dissem/apps/abit/MainActivity.kt +++ b/app/src/main/java/ch/dissem/apps/abit/MainActivity.kt @@ -31,7 +31,6 @@ import ch.dissem.apps.abit.listener.ListSelectionListener import ch.dissem.apps.abit.repository.AndroidLabelRepository.Companion.LABEL_ARCHIVE import ch.dissem.apps.abit.service.Singleton import ch.dissem.apps.abit.service.Singleton.currentLabel -import ch.dissem.apps.abit.synchronization.SyncAdapter import ch.dissem.apps.abit.util.NetworkUtils import ch.dissem.apps.abit.util.Preferences import ch.dissem.apps.abit.util.getColor @@ -145,11 +144,6 @@ class MainActivity : AppCompatActivity(), ListSelectionListener { ComposeMessageActivity.launchReplyTo(this, item) } - if (Preferences.useTrustedNode(this)) { - SyncAdapter.startSync(this) - } else { - SyncAdapter.stopSync(this) - } if (drawer.isDrawerOpen) { MaterialShowcaseView.Builder(this) .setMaskColour(R.color.colorPrimary) @@ -179,8 +173,6 @@ class MainActivity : AppCompatActivity(), ListSelectionListener { .setDelay(1000) .show() } - - SyncAdapter.startSync(this) } private fun changeList(listFragment: F) where F : Fragment, F : ListHolder<*> { @@ -259,14 +251,13 @@ class MainActivity : AppCompatActivity(), ListSelectionListener { nodeSwitch = SwitchDrawerItem() .withIdentifier(ID_NODE_SWITCH) - .withName(R.string.full_node) + .withName(R.string.online) .withIcon(CommunityMaterial.Icon.cmd_cloud_outline) - .withChecked(Preferences.isFullNodeActive(this)) + .withChecked(Preferences.isOnline(this)) .withOnCheckedChangeListener { _, _, isChecked -> + Preferences.setOnline(this, isChecked) if (isChecked) { - NetworkUtils.enableNode(this@MainActivity) - } else { - NetworkUtils.disableNode(this@MainActivity) + NetworkUtils.enableNode(this, true) } } @@ -369,10 +360,8 @@ class MainActivity : AppCompatActivity(), ListSelectionListener { } override fun onResume() { + NetworkUtils.enableNode(this, false) updateUnread() - if (Preferences.isFullNodeActive(this) && Preferences.isConnectionAllowed(this@MainActivity)) { - NetworkUtils.enableNode(this, false) - } Singleton.getMessageListener(this).resetNotification() currentLabel.addObserver(this) { label -> if (label != null && label.id is Long) { @@ -578,15 +567,6 @@ class MainActivity : AppCompatActivity(), ListSelectionListener { private var instance: WeakReference? = null - fun updateNodeSwitch() { - apply { - runOnUiThread { - nodeSwitch.withChecked(Preferences.isFullNodeActive(this)) - drawer.updateStickyFooterItem(nodeSwitch) - } - } - } - /** * Runs the given code in the main activity context, if it currently exists. Otherwise, * it's ignored. diff --git a/app/src/main/java/ch/dissem/apps/abit/MessageListFragment.kt b/app/src/main/java/ch/dissem/apps/abit/MessageListFragment.kt index 6597810..dc0b30f 100644 --- a/app/src/main/java/ch/dissem/apps/abit/MessageListFragment.kt +++ b/app/src/main/java/ch/dissem/apps/abit/MessageListFragment.kt @@ -134,23 +134,27 @@ class MessageListFragment : Fragment(), ListHolder