From a75f771bc65b2c57f87c78b754241d47aad5bad7 Mon Sep 17 00:00:00 2001 From: Pavel Rekun Date: Mon, 6 Aug 2018 12:43:12 +0300 Subject: [PATCH] - Refactored classes of Main screen --- .../screens/main_activity/MainActivity.kt | 21 +------------ .../screens/main_activity/MainContract.kt | 3 ++ .../rekado/screens/main_activity/MainView.kt | 30 +++++++++++++++++++ .../settings_activity/SettingsFragment.kt | 2 +- .../rekado/services/dialogs/Dialogs.kt | 2 +- 5 files changed, 36 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/com/pavelrekun/rekado/screens/main_activity/MainActivity.kt b/app/src/main/java/com/pavelrekun/rekado/screens/main_activity/MainActivity.kt index 9e9d2dc..fb0b7ce 100644 --- a/app/src/main/java/com/pavelrekun/rekado/screens/main_activity/MainActivity.kt +++ b/app/src/main/java/com/pavelrekun/rekado/screens/main_activity/MainActivity.kt @@ -30,26 +30,7 @@ class MainActivity : BaseActivity() { } override fun onOptionsItemSelected(item: MenuItem): Boolean { - return when (item.itemId) { - R.id.navigation_about -> { - startActivity(Intent(this, AboutActivity::class.java)) - true - } - - R.id.navigation_settings -> { - startActivity(Intent(this, SettingsActivity::class.java)) - true - } - - R.id.navigation_donate -> { - val donateDialog = DonateDialog(this) - donateDialog.window.setLayout(DesignUtils.convertDPtoPX(360), ViewGroup.LayoutParams.WRAP_CONTENT) - donateDialog.show() - true - } - - else -> super.onOptionsItemSelected(item) - } + return mvpView.onOptionsItemSelected(item) } override fun onStart() { diff --git a/app/src/main/java/com/pavelrekun/rekado/screens/main_activity/MainContract.kt b/app/src/main/java/com/pavelrekun/rekado/screens/main_activity/MainContract.kt index 8be91ae..2db31de 100644 --- a/app/src/main/java/com/pavelrekun/rekado/screens/main_activity/MainContract.kt +++ b/app/src/main/java/com/pavelrekun/rekado/screens/main_activity/MainContract.kt @@ -1,5 +1,7 @@ package com.pavelrekun.rekado.screens.main_activity +import android.view.MenuItem + interface MainContract { interface View { @@ -14,6 +16,7 @@ interface MainContract { fun onStop() + fun onOptionsItemSelected(item: MenuItem): Boolean } } \ No newline at end of file diff --git a/app/src/main/java/com/pavelrekun/rekado/screens/main_activity/MainView.kt b/app/src/main/java/com/pavelrekun/rekado/screens/main_activity/MainView.kt index f2269ce..7e6c81a 100644 --- a/app/src/main/java/com/pavelrekun/rekado/screens/main_activity/MainView.kt +++ b/app/src/main/java/com/pavelrekun/rekado/screens/main_activity/MainView.kt @@ -1,16 +1,23 @@ package com.pavelrekun.rekado.screens.main_activity +import android.content.Intent import android.support.v4.app.Fragment +import android.view.MenuItem +import android.view.ViewGroup import com.github.javiersantos.appupdater.AppUpdater import com.github.javiersantos.appupdater.enums.Display import com.github.javiersantos.appupdater.enums.UpdateFrom import com.pavelrekun.rekado.R import com.pavelrekun.rekado.base.BaseActivity +import com.pavelrekun.rekado.screens.about_activity.AboutActivity import com.pavelrekun.rekado.screens.instructions_fragment.InstructionsFragment import com.pavelrekun.rekado.screens.lakka_fragment.LakkaFragment import com.pavelrekun.rekado.screens.logs_fragment.LogsFragment import com.pavelrekun.rekado.screens.payload_fragment.PayloadsFragment +import com.pavelrekun.rekado.screens.settings_activity.SettingsActivity import com.pavelrekun.rekado.services.Constants +import com.pavelrekun.rekado.services.dialogs.DonateDialog +import com.pavelrekun.rekado.services.utils.DesignUtils import kotlinx.android.synthetic.main.activity_main.* @@ -50,6 +57,29 @@ class MainView(private val activity: BaseActivity) : MainContract.View { } } + override fun onOptionsItemSelected(item: MenuItem): Boolean { + return when (item.itemId) { + R.id.navigation_about -> { + activity.startActivity(Intent(activity, AboutActivity::class.java)) + true + } + + R.id.navigation_settings -> { + activity.startActivity(Intent(activity, SettingsActivity::class.java)) + true + } + + R.id.navigation_donate -> { + val donateDialog = DonateDialog(activity) + donateDialog.window.setLayout(DesignUtils.convertDPtoPX(360), ViewGroup.LayoutParams.WRAP_CONTENT) + donateDialog.show() + true + } + + else -> return false + } + } + private fun chooseNavigationItem(id: Int) { var fragment: Fragment? = null diff --git a/app/src/main/java/com/pavelrekun/rekado/screens/settings_activity/SettingsFragment.kt b/app/src/main/java/com/pavelrekun/rekado/screens/settings_activity/SettingsFragment.kt index 8a5124b..b9e7a84 100644 --- a/app/src/main/java/com/pavelrekun/rekado/screens/settings_activity/SettingsFragment.kt +++ b/app/src/main/java/com/pavelrekun/rekado/screens/settings_activity/SettingsFragment.kt @@ -77,7 +77,7 @@ class SettingsFragment : PreferenceFragmentCompat() { } appearanceNightMode.setOnPreferenceChangeListener { _, _ -> - Dialogs.openRestartDialog(activity as BaseActivity) + Dialogs.showRestartDialog(activity as BaseActivity) true } diff --git a/app/src/main/java/com/pavelrekun/rekado/services/dialogs/Dialogs.kt b/app/src/main/java/com/pavelrekun/rekado/services/dialogs/Dialogs.kt index a3fc0ed..3967dd1 100644 --- a/app/src/main/java/com/pavelrekun/rekado/services/dialogs/Dialogs.kt +++ b/app/src/main/java/com/pavelrekun/rekado/services/dialogs/Dialogs.kt @@ -86,7 +86,7 @@ object Dialogs { return resetDialog } - fun openRestartDialog(activity: Activity) { + fun showRestartDialog(activity: BaseActivity) { val builder = AlertDialog.Builder(activity) builder.setTitle(R.string.settings_restart_title) builder.setMessage(R.string.settings_restart_message)