Commit 776c2af0 authored by Konstantin Tskhovrebov's avatar Konstantin Tskhovrebov 🤖

Remove duplicate ConfirmDialog.

parent fafa7d06
......@@ -60,5 +60,8 @@ class NavigationDrawerPresenter @Inject constructor(
router.newRootFlow(Screens.AUTH_FLOW)
}
fun onUserClick(id: Long) = router.startFlow(Screens.USER_FLOW, id)
fun onUserClick(id: Long) {
menuController.close()
router.startFlow(Screens.USER_FLOW, id)
}
}
\ No newline at end of file
......@@ -14,13 +14,13 @@ import ru.terrakok.gitlabclient.presentation.drawer.NavigationDrawerView.MenuIte
import ru.terrakok.gitlabclient.presentation.drawer.NavigationDrawerView.MenuItem.*
import ru.terrakok.gitlabclient.toothpick.DI
import ru.terrakok.gitlabclient.ui.global.BaseFragment
import ru.terrakok.gitlabclient.ui.global.ConfirmDialog
import ru.terrakok.gitlabclient.ui.global.MessageDialogFragment
import toothpick.Toothpick
/**
* @author Konstantin Tskhovrebov (aka terrakok). Date: 04.04.17
*/
class NavigationDrawerFragment : BaseFragment(), NavigationDrawerView, ConfirmDialog.OnClickListener {
class NavigationDrawerFragment : BaseFragment(), NavigationDrawerView, MessageDialogFragment.OnClickListener {
override val layoutRes = R.layout.fragment_nav_drawer
private var userId: Long? = null
......@@ -44,13 +44,12 @@ class NavigationDrawerFragment : BaseFragment(), NavigationDrawerView, ConfirmDi
avatarImageView.setOnClickListener { userId?.let { presenter.onUserClick(it) } }
logoutIV.setOnClickListener {
ConfirmDialog
.newInstants(
msg = getString(R.string.logout_question),
positive = getString(R.string.exit),
tag = CONFIRM_LOGOUT_TAG
)
.show(childFragmentManager, CONFIRM_LOGOUT_TAG)
MessageDialogFragment.create(
message = getString(R.string.logout_question),
positive = getString(R.string.exit),
negative = getString(R.string.cancel),
tag = CONFIRM_LOGOUT_TAG
).show(childFragmentManager, CONFIRM_LOGOUT_TAG)
}
activityMI.tag = ACTIVITY
......@@ -88,7 +87,7 @@ class NavigationDrawerFragment : BaseFragment(), NavigationDrawerView, ConfirmDi
presenter.onScreenChanged(item)
}
override fun dialogConfirm(tag: String) {
override fun dialogPositiveClicked(tag: String) {
when (tag) {
CONFIRM_LOGOUT_TAG -> presenter.onLogoutClick()
}
......
package ru.terrakok.gitlabclient.ui.global
import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.support.v4.app.DialogFragment
import android.support.v7.app.AlertDialog
import ru.terrakok.gitlabclient.R
class ConfirmDialog : DialogFragment() {
private var clickListener: OnClickListener? = null
private val title: String? get() = arguments?.getString(TITLE)
private val msg: String get() = arguments?.getString(MSG) ?: ""
private val positive: String get() = arguments?.getString(POSITIVE_TEXT) ?: getString(R.string.ok)
private val negative: String get() = arguments?.getString(NEGATIVE_TEXT) ?: getString(R.string.cancel)
private val dialogTag: String get() = arguments?.getString(TAG) ?: "ConfirmDialog tag"
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog =
AlertDialog.Builder(context!!).apply {
title?.let { setTitle(title) }
setMessage(msg)
setPositiveButton(positive) { _, _ -> clickListener?.dialogConfirm(dialogTag) }
setNegativeButton(negative) { _, _ -> dismiss() }
}.create()
override fun onAttach(context: Context?) {
super.onAttach(context)
clickListener = when {
parentFragment is OnClickListener -> parentFragment as OnClickListener
activity is OnClickListener -> activity as OnClickListener
else -> null
}
}
override fun onDetach() {
clickListener = null
super.onDetach()
}
companion object {
private const val TITLE = "title"
private const val MSG = "msg"
private const val POSITIVE_TEXT = "positive_text"
private const val NEGATIVE_TEXT = "negative_text"
private const val TAG = "tag"
fun newInstants(
title: String? = null,
msg: String,
positive: String? = null,
negative: String? = null,
tag: String
) =
ConfirmDialog().apply {
arguments = Bundle().apply {
putString(TITLE, title)
putString(MSG, msg)
putString(POSITIVE_TEXT, positive)
putString(NEGATIVE_TEXT, negative)
putString(TAG, tag)
}
}
}
interface OnClickListener {
fun dialogConfirm(tag: String)
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment