add BaseDialogFragment

This commit is contained in:
Chumva 2018-08-28 12:24:39 +03:00
parent cd1f6a58e5
commit 6db6e83949
4 changed files with 29 additions and 47 deletions

View file

@ -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)
}
}
}

View file

@ -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? {

View file

@ -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,

View file

@ -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?,