From 6db6e83949975abb72b4195e75fd59fccef01f41 Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 28 Aug 2018 12:24:39 +0300 Subject: [PATCH] add BaseDialogFragment --- .../osmand/telegram/ui/BaseDialogFragment.kt | 25 +++++++++++++++++++ .../osmand/telegram/ui/LoginDialogFragment.kt | 12 ++------- .../telegram/ui/SetTimeDialogFragment.kt | 20 +-------------- .../telegram/ui/SettingsDialogFragment.kt | 19 +------------- 4 files changed, 29 insertions(+), 47 deletions(-) create mode 100644 OsmAnd-telegram/src/net/osmand/telegram/ui/BaseDialogFragment.kt diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/BaseDialogFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/BaseDialogFragment.kt new file mode 100644 index 0000000000..449ac9de6c --- /dev/null +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/BaseDialogFragment.kt @@ -0,0 +1,25 @@ +package net.osmand.telegram.ui + +import android.os.Build +import android.os.Bundle +import android.support.v4.app.DialogFragment +import net.osmand.telegram.R +import net.osmand.telegram.TelegramApplication + +open class BaseDialogFragment : DialogFragment() { + + val app: TelegramApplication + get() = activity?.application as TelegramApplication + + val telegramHelper get() = app.telegramHelper + val settings get() = app.settings + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + when { + Build.VERSION.SDK_INT >= 23 -> setStyle(DialogFragment.STYLE_NO_FRAME, R.style.AppTheme_NoActionbar_Transparent) + Build.VERSION.SDK_INT >= 19 -> setStyle(DialogFragment.STYLE_NO_FRAME, R.style.AppTheme_NoActionbar_Translucent) + else -> setStyle(DialogFragment.STYLE_NO_FRAME, R.style.AppTheme_NoActionbar) + } + } +} \ No newline at end of file diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/LoginDialogFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/LoginDialogFragment.kt index c12723ace8..4ae7441621 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/LoginDialogFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/LoginDialogFragment.kt @@ -6,7 +6,6 @@ import android.graphics.Rect import android.os.Build import android.os.Bundle import android.support.annotation.StringRes -import android.support.v4.app.DialogFragment import android.support.v4.app.FragmentManager import android.support.v4.content.ContextCompat import android.support.v7.widget.AppCompatImageView @@ -30,7 +29,7 @@ import net.osmand.telegram.utils.AndroidUtils import studio.carbonylgroup.textfieldboxes.ExtendedEditText -class LoginDialogFragment : DialogFragment() { +class LoginDialogFragment : BaseDialogFragment() { companion object { @@ -118,14 +117,7 @@ class LoginDialogFragment : DialogFragment() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - val activity = requireActivity() - val window = activity.window - when { - Build.VERSION.SDK_INT >= 23 -> setStyle(DialogFragment.STYLE_NO_FRAME, R.style.AppTheme_NoActionbar_Transparent) - Build.VERSION.SDK_INT >= 19 -> setStyle(DialogFragment.STYLE_NO_FRAME, R.style.AppTheme_NoActionbar_Translucent) - else -> setStyle(DialogFragment.STYLE_NO_FRAME, R.style.AppTheme_NoActionbar) - } - window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) + requireActivity().window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/SetTimeDialogFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/SetTimeDialogFragment.kt index 4dad2c54f2..2e866ae624 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/SetTimeDialogFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/SetTimeDialogFragment.kt @@ -1,9 +1,7 @@ package net.osmand.telegram.ui import android.app.TimePickerDialog -import android.os.Build import android.os.Bundle -import android.support.v4.app.DialogFragment import android.support.v4.app.Fragment import android.support.v4.app.FragmentManager import android.support.v7.widget.LinearLayoutManager @@ -16,7 +14,6 @@ import android.widget.TextView import net.osmand.Location import net.osmand.data.LatLon import net.osmand.telegram.R -import net.osmand.telegram.TelegramApplication import net.osmand.telegram.TelegramLocationProvider.TelegramLocationListener import net.osmand.telegram.TelegramLocationProvider.TelegramCompassListener import net.osmand.telegram.helpers.ShareLocationHelper @@ -30,13 +27,7 @@ import org.drinkless.td.libcore.telegram.TdApi import java.util.* import java.util.concurrent.TimeUnit -class SetTimeDialogFragment : DialogFragment(), TelegramLocationListener, TelegramCompassListener { - - private val app: TelegramApplication - get() = activity?.application as TelegramApplication - - private val telegramHelper get() = app.telegramHelper - private val settings get() = app.settings +class SetTimeDialogFragment : BaseDialogFragment(), TelegramLocationListener, TelegramCompassListener { private lateinit var locationViewCache: UiUtils.UpdateLocationViewCache private val adapter = SetTimeListAdapter() @@ -49,15 +40,6 @@ class SetTimeDialogFragment : DialogFragment(), TelegramLocationListener, Telegr private var location: Location? = null private var heading: Float? = null private var locationUiUpdateAllowed: Boolean = true - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - when { - Build.VERSION.SDK_INT >= 23 -> setStyle(DialogFragment.STYLE_NO_FRAME, R.style.AppTheme_NoActionbar_Transparent) - Build.VERSION.SDK_INT >= 19 -> setStyle(DialogFragment.STYLE_NO_FRAME, R.style.AppTheme_NoActionbar_Translucent) - else -> setStyle(DialogFragment.STYLE_NO_FRAME, R.style.AppTheme_NoActionbar) - } - } override fun onCreateView( inflater: LayoutInflater, diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/SettingsDialogFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/SettingsDialogFragment.kt index ef180e3d9b..77ab6944e2 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/SettingsDialogFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/SettingsDialogFragment.kt @@ -1,10 +1,8 @@ package net.osmand.telegram.ui -import android.os.Build import android.os.Bundle import android.support.annotation.DrawableRes import android.support.annotation.StringRes -import android.support.v4.app.DialogFragment import android.support.v4.app.FragmentManager import android.support.v7.widget.ListPopupWindow import android.support.v7.widget.Toolbar @@ -22,27 +20,12 @@ import net.osmand.telegram.helpers.TelegramUiHelper import net.osmand.telegram.utils.AndroidUtils import net.osmand.telegram.utils.OsmandFormatter -class SettingsDialogFragment : DialogFragment() { - - private val app: TelegramApplication - get() = activity?.application as TelegramApplication +class SettingsDialogFragment : BaseDialogFragment() { private val uiUtils get() = app.uiUtils - private val telegramHelper get() = app.telegramHelper - private val settings get() = app.settings private val gpsAndLocPrefs = listOf(SendMyLocPref(), StaleLocPref(), LocHistoryPref()) - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setStyle(android.support.v4.app.DialogFragment.STYLE_NO_FRAME, R.style.AppTheme_NoActionbar) - when { - Build.VERSION.SDK_INT >= 23 -> setStyle(DialogFragment.STYLE_NO_FRAME, R.style.AppTheme_NoActionbar_Transparent) - Build.VERSION.SDK_INT >= 19 -> setStyle(DialogFragment.STYLE_NO_FRAME, R.style.AppTheme_NoActionbar_Translucent) - else -> setStyle(DialogFragment.STYLE_NO_FRAME, R.style.AppTheme_NoActionbar) - } - } - override fun onCreateView( inflater: LayoutInflater, parent: ViewGroup?,