Skip to content

Commit

Permalink
- Refactored classes of Main screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Rekun committed Aug 6, 2018
1 parent 7fd27e9 commit a75f771
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.pavelrekun.rekado.screens.main_activity

import android.view.MenuItem

interface MainContract {

interface View {
Expand All @@ -14,6 +16,7 @@ interface MainContract {

fun onStop()

fun onOptionsItemSelected(item: MenuItem): Boolean
}

}
Original file line number Diff line number Diff line change
@@ -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.*


Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
}

appearanceNightMode.setOnPreferenceChangeListener { _, _ ->
Dialogs.openRestartDialog(activity as BaseActivity)
Dialogs.showRestartDialog(activity as BaseActivity)
true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a75f771

Please sign in to comment.