From 0deecca8ed7c7a4cf1b2c646b582a0b1ff55172a Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Fri, 4 Jan 2019 17:01:06 -0600 Subject: [PATCH] Remove no longer needed code from ConnectedActivity and MainActivity and add a description to each of the Activities to describe their purpose. --- .../activities/ConnectedActivity.kt | 34 +++++++------------ .../activities/MainActivity.kt | 19 +++-------- 2 files changed, 16 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/activities/ConnectedActivity.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/activities/ConnectedActivity.kt index 9021743..1e43ab6 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/activities/ConnectedActivity.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/activities/ConnectedActivity.kt @@ -40,16 +40,21 @@ import kotlin.collections.ArrayList import kotlin.collections.HashMap /** - * Class in charge of managing the connection to graphenej's NetworkService + * The app uses the single Activity methodology, but this activity was created so that MainActivity can extend from it. + * This class manages everything related to keeping the information in the database updated using graphenej's + * NetworkService, leaving to MainActivity only the Navigation work and some other UI features. */ abstract class ConnectedActivity : AppCompatActivity(), ServiceConnection { - private val TAG = this.javaClass.simpleName - private val RESPONSE_GET_FULL_ACCOUNTS = 1 - private val RESPONSE_GET_ACCOUNTS = 2 - private val RESPONSE_GET_ACCOUNT_BALANCES = 3 - private val RESPONSE_GET_ASSETS = 4 - private val RESPONSE_GET_BLOCK_HEADER = 5 + companion object { + private const val TAG = "ConnectedActivity" + + private const val RESPONSE_GET_FULL_ACCOUNTS = 1 + private const val RESPONSE_GET_ACCOUNTS = 2 + private const val RESPONSE_GET_ACCOUNT_BALANCES = 3 + private const val RESPONSE_GET_ASSETS = 4 + private const val RESPONSE_GET_BLOCK_HEADER = 5 + } private lateinit var mUserAccountViewModel: UserAccountViewModel private lateinit var mBalanceViewModel: BalanceViewModel @@ -141,8 +146,6 @@ abstract class ConnectedActivity : AppCompatActivity(), ServiceConnection { private fun handleIncomingMessage(message: Any?) { if (message is JsonRpcResponse<*>) { - // Generic processing taken care by subclasses - handleJsonRpcResponse(message) if (message.error == null) { if (responseMap.containsKey(message.id)) { @@ -178,7 +181,6 @@ abstract class ConnectedActivity : AppCompatActivity(), ServiceConnection { ).show() } } else if (message is ConnectionStatusUpdate) { - handleConnectionStatusUpdate(message) if (message.updateCode == ConnectionStatusUpdate.DISCONNECTED) { // If we got a disconnection notification, we should clear our response map, since // all its stored request ids will now be reset @@ -405,16 +407,4 @@ abstract class ConnectedActivity : AppCompatActivity(), ServiceConnection { super.onDestroy() if (!mDisposable!!.isDisposed) mDisposable!!.dispose() } - - /** - * Method to be implemented by all subclasses in order to be notified of JSON-RPC responses. - * @param response - */ - internal abstract fun handleJsonRpcResponse(response: JsonRpcResponse<*>) - - /** - * Method to be implemented by all subclasses in order to be notified of connection status updates - * @param connectionStatusUpdate - */ - internal abstract fun handleConnectionStatusUpdate(connectionStatusUpdate: ConnectionStatusUpdate) } \ No newline at end of file diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/activities/MainActivity.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/activities/MainActivity.kt index 05b0425..21cf69c 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/activities/MainActivity.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/activities/MainActivity.kt @@ -12,12 +12,13 @@ import androidx.navigation.ui.onNavDestinationSelected import androidx.navigation.ui.setupActionBarWithNavController import cy.agorise.bitsybitshareswallet.R import cy.agorise.bitsybitshareswallet.utils.Constants -import cy.agorise.graphenej.api.ConnectionStatusUpdate -import cy.agorise.graphenej.models.JsonRpcResponse import kotlinx.android.synthetic.main.activity_main.* +/** + * Uses the AAC Navigation Component with a NavHostFragment which is the place where all Fragments are shown, + * following the philosophy of using a single Activity. + */ class MainActivity : ConnectedActivity() { - private val TAG = this.javaClass.simpleName private lateinit var appBarConfiguration : AppBarConfiguration @@ -100,18 +101,6 @@ class MainActivity : ConnectedActivity() { return findNavController(R.id.navHostFragment).navigateUp(appBarConfiguration) } - override fun handleJsonRpcResponse(response: JsonRpcResponse<*>) { - - } - - /** - * Private method called whenever there's an update to the connection status - * @param connectionStatusUpdate Connection status update. - */ - override fun handleConnectionStatusUpdate(connectionStatusUpdate: ConnectionStatusUpdate) { - - } - override fun onBackPressed() { // Trick used to avoid crashes when the user is in the License or ImportBrainkey and presses the back button val currentDestination=NavHostFragment.findNavController(navHostFragment).currentDestination