2016-07-07 09:39:32 +02:00
|
|
|
/*
|
|
|
|
* Twidere - Twitter client for Android
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.mariotaku.twidere.activity
|
|
|
|
|
|
|
|
import android.app.Activity
|
|
|
|
import android.app.Dialog
|
|
|
|
import android.content.Context
|
|
|
|
import android.content.DialogInterface
|
|
|
|
import android.content.Intent
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.support.annotation.DrawableRes
|
|
|
|
import android.support.annotation.XmlRes
|
|
|
|
import android.support.v4.app.Fragment
|
|
|
|
import android.support.v7.app.AlertDialog
|
|
|
|
import android.support.v7.preference.Preference
|
|
|
|
import android.support.v7.preference.PreferenceFragmentCompat
|
|
|
|
import android.support.v7.preference.PreferenceFragmentCompat.OnPreferenceStartFragmentCallback
|
|
|
|
import android.text.TextUtils
|
|
|
|
import android.view.KeyEvent
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
|
|
|
import android.widget.*
|
|
|
|
import android.widget.AdapterView.OnItemClickListener
|
2016-12-07 08:10:14 +01:00
|
|
|
import kotlinx.android.synthetic.main.activity_settings.*
|
2017-02-07 07:35:11 +01:00
|
|
|
import org.mariotaku.ktextension.Bundle
|
|
|
|
import org.mariotaku.ktextension.set
|
2016-07-07 09:39:32 +02:00
|
|
|
import org.mariotaku.twidere.R
|
|
|
|
import org.mariotaku.twidere.constant.IntentConstants.*
|
|
|
|
import org.mariotaku.twidere.constant.KeyboardShortcutConstants.ACTION_NAVIGATION_BACK
|
|
|
|
import org.mariotaku.twidere.constant.KeyboardShortcutConstants.CONTEXT_TAG_NAVIGATION
|
2017-02-05 14:42:20 +01:00
|
|
|
import org.mariotaku.twidere.extension.applyTheme
|
2016-07-07 09:39:32 +02:00
|
|
|
import org.mariotaku.twidere.fragment.*
|
|
|
|
import org.mariotaku.twidere.util.KeyboardShortcutsHandler
|
|
|
|
import org.mariotaku.twidere.util.ThemeUtils
|
2017-02-05 06:03:18 +01:00
|
|
|
import org.mariotaku.twidere.util.Utils
|
2016-07-07 09:39:32 +02:00
|
|
|
import java.util.*
|
|
|
|
|
|
|
|
class SettingsActivity : BaseActivity(), OnItemClickListener, OnPreferenceStartFragmentCallback {
|
|
|
|
|
2016-07-26 09:12:25 +02:00
|
|
|
var shouldRecreate: Boolean = false
|
|
|
|
var shouldRestart: Boolean = false
|
2017-02-07 07:35:11 +01:00
|
|
|
var shouldTerminate: Boolean = false
|
2016-12-07 08:10:14 +01:00
|
|
|
private lateinit var entriesAdapter: EntriesAdapter
|
2016-07-07 09:39:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
setContentView(R.layout.activity_settings)
|
2017-02-07 07:35:11 +01:00
|
|
|
entriesAdapter = EntriesAdapter(this)
|
2016-07-07 09:39:32 +02:00
|
|
|
|
2017-01-07 16:51:21 +01:00
|
|
|
if (savedInstanceState != null) {
|
|
|
|
shouldRecreate = savedInstanceState.getBoolean(EXTRA_SHOULD_RECREATE, shouldRecreate)
|
|
|
|
shouldRestart = savedInstanceState.getBoolean(EXTRA_SHOULD_RESTART, shouldRestart)
|
2017-02-07 07:35:11 +01:00
|
|
|
shouldTerminate = savedInstanceState.getBoolean(EXTRA_SHOULD_TERMINATE, shouldTerminate)
|
|
|
|
} else if (intent.getBooleanExtra(EXTRA_SHOULD_TERMINATE, false)) {
|
|
|
|
finishNoRestart()
|
|
|
|
System.exit(0)
|
|
|
|
return
|
2017-01-07 16:51:21 +01:00
|
|
|
}
|
|
|
|
|
2016-07-07 09:39:32 +02:00
|
|
|
val backgroundAlpha = currentThemeBackgroundAlpha
|
|
|
|
|
2016-12-07 08:10:14 +01:00
|
|
|
detailFragmentContainer.setBackgroundColor(backgroundAlpha shl 24 or 0xFFFFFF and ThemeUtils.getThemeBackgroundColor(this))
|
2016-07-07 09:39:32 +02:00
|
|
|
|
2016-12-07 08:10:14 +01:00
|
|
|
slidingPane.setShadowResourceLeft(R.drawable.sliding_pane_shadow_left)
|
|
|
|
slidingPane.setShadowResourceRight(R.drawable.sliding_pane_shadow_right)
|
|
|
|
slidingPane.sliderFadeColor = 0
|
2017-02-07 07:35:11 +01:00
|
|
|
|
2016-07-07 09:39:32 +02:00
|
|
|
initEntries()
|
2016-12-07 08:10:14 +01:00
|
|
|
entriesList.adapter = entriesAdapter
|
|
|
|
entriesList.choiceMode = AbsListView.CHOICE_MODE_SINGLE
|
|
|
|
entriesList.onItemClickListener = this
|
2016-07-07 09:39:32 +02:00
|
|
|
|
|
|
|
if (savedInstanceState == null) {
|
|
|
|
val initialTag = intent.getStringExtra(EXTRA_INITIAL_TAG)
|
|
|
|
var initialItem = -1
|
|
|
|
var firstEntry = -1
|
2016-12-07 08:10:14 +01:00
|
|
|
for (i in 0 until entriesAdapter.count) {
|
|
|
|
val entry = entriesAdapter.getItem(i)
|
2016-07-07 09:39:32 +02:00
|
|
|
if (entry is PreferenceEntry) {
|
|
|
|
if (firstEntry == -1) {
|
|
|
|
firstEntry = i
|
|
|
|
}
|
|
|
|
if (TextUtils.equals(initialTag, entry.tag)) {
|
|
|
|
initialItem = i
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (initialItem == -1) {
|
|
|
|
initialItem = firstEntry
|
|
|
|
}
|
|
|
|
if (initialItem != -1) {
|
|
|
|
openDetails(initialItem)
|
2016-12-07 08:10:14 +01:00
|
|
|
entriesList.setItemChecked(initialItem, true)
|
2016-07-07 09:39:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
2016-07-26 09:12:25 +02:00
|
|
|
if (resultCode == RESULT_SETTINGS_CHANGED && data != null) {
|
|
|
|
shouldRecreate = data.getBooleanExtra(EXTRA_SHOULD_RECREATE, false)
|
|
|
|
shouldRestart = data.getBooleanExtra(EXTRA_SHOULD_RESTART, false)
|
2017-02-07 07:35:11 +01:00
|
|
|
shouldTerminate = data.getBooleanExtra(EXTRA_SHOULD_TERMINATE, false)
|
2016-07-07 09:39:32 +02:00
|
|
|
}
|
|
|
|
super.onActivityResult(requestCode, resultCode, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun finish() {
|
2016-07-26 09:12:25 +02:00
|
|
|
if (shouldRecreate || shouldRestart) {
|
2016-07-07 09:39:32 +02:00
|
|
|
val data = Intent()
|
2016-07-26 09:12:25 +02:00
|
|
|
data.putExtra(EXTRA_SHOULD_RECREATE, shouldRecreate)
|
|
|
|
data.putExtra(EXTRA_SHOULD_RESTART, shouldRestart)
|
2016-07-07 09:39:32 +02:00
|
|
|
setResult(RESULT_SETTINGS_CHANGED, data)
|
|
|
|
}
|
|
|
|
super.finish()
|
|
|
|
}
|
|
|
|
|
2017-01-07 16:51:21 +01:00
|
|
|
override fun onSaveInstanceState(outState: Bundle) {
|
|
|
|
super.onSaveInstanceState(outState)
|
|
|
|
outState.putBoolean(EXTRA_SHOULD_RECREATE, shouldRecreate)
|
|
|
|
outState.putBoolean(EXTRA_SHOULD_RESTART, shouldRestart)
|
2016-07-07 09:39:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun handleKeyboardShortcutSingle(handler: KeyboardShortcutsHandler, keyCode: Int, event: KeyEvent, metaState: Int): Boolean {
|
|
|
|
val action = handler.getKeyAction(CONTEXT_TAG_NAVIGATION, keyCode, event, metaState)
|
|
|
|
if (ACTION_NAVIGATION_BACK == action) {
|
|
|
|
onBackPressed()
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return super.handleKeyboardShortcutSingle(handler, keyCode, event, metaState)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun isKeyboardShortcutHandled(handler: KeyboardShortcutsHandler, keyCode: Int, event: KeyEvent, metaState: Int): Boolean {
|
|
|
|
val action = handler.getKeyAction(CONTEXT_TAG_NAVIGATION, keyCode, event, metaState)
|
|
|
|
return ACTION_NAVIGATION_BACK == action
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun handleKeyboardShortcutRepeat(handler: KeyboardShortcutsHandler, keyCode: Int, repeatCount: Int, event: KeyEvent, metaState: Int): Boolean {
|
|
|
|
return super.handleKeyboardShortcutRepeat(handler, keyCode, repeatCount, event, metaState)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onSupportNavigateUp(): Boolean {
|
|
|
|
if (notifyUnsavedChange()) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return super.onSupportNavigateUp()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onBackPressed() {
|
|
|
|
if (notifyUnsavedChange()) return
|
|
|
|
super.onBackPressed()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onPreferenceStartFragment(fragment: PreferenceFragmentCompat, preference: Preference): Boolean {
|
|
|
|
val fm = supportFragmentManager
|
|
|
|
val ft = fm.beginTransaction()
|
|
|
|
val f = Fragment.instantiate(this, preference.fragment, preference.extras)
|
2016-12-07 08:10:14 +01:00
|
|
|
ft.replace(R.id.detailFragmentContainer, f)
|
2016-07-07 09:39:32 +02:00
|
|
|
ft.addToBackStack(preference.title.toString())
|
|
|
|
ft.commit()
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onItemClick(parent: AdapterView<*>, view: View, position: Int, id: Long) {
|
|
|
|
openDetails(position)
|
|
|
|
}
|
|
|
|
|
2017-01-07 16:51:21 +01:00
|
|
|
private fun finishNoRestart() {
|
|
|
|
super.finish()
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-05 04:13:28 +01:00
|
|
|
private val isTopSettings: Boolean = true
|
2017-01-07 16:51:21 +01:00
|
|
|
|
|
|
|
private fun initEntries() {
|
|
|
|
entriesAdapter.addHeader(getString(R.string.appearance))
|
|
|
|
entriesAdapter.addPreference("theme", R.drawable.ic_action_color_palette, getString(R.string.theme),
|
|
|
|
R.xml.preferences_theme)
|
|
|
|
entriesAdapter.addPreference("cards", R.drawable.ic_action_card, getString(R.string.cards),
|
|
|
|
R.xml.preferences_cards)
|
2017-02-05 06:03:18 +01:00
|
|
|
if (Utils.isDeviceTablet(this)) {
|
|
|
|
entriesAdapter.addPreference("tablet_mode", R.drawable.ic_action_tablet, getString(R.string.preference_title_tablet_mode),
|
|
|
|
R.xml.preferences_tablet_mode)
|
|
|
|
}
|
2017-01-07 16:51:21 +01:00
|
|
|
|
|
|
|
entriesAdapter.addHeader(getString(R.string.function))
|
|
|
|
entriesAdapter.addPreference("tabs", R.drawable.ic_action_tab, getString(R.string.tabs),
|
|
|
|
CustomTabsFragment::class.java)
|
|
|
|
entriesAdapter.addPreference("extension", R.drawable.ic_action_extension, getString(R.string.extensions),
|
|
|
|
ExtensionsListFragment::class.java)
|
2017-01-12 17:34:45 +01:00
|
|
|
entriesAdapter.addPreference("refresh", R.drawable.ic_action_refresh, getString(R.string.action_refresh),
|
2017-01-07 16:51:21 +01:00
|
|
|
R.xml.preferences_refresh)
|
2017-03-10 19:16:23 +01:00
|
|
|
entriesAdapter.addPreference("streaming", R.drawable.ic_action_streaming, getString(R.string.settings_streaming),
|
|
|
|
R.xml.preferences_streaming)
|
2017-01-07 16:51:21 +01:00
|
|
|
entriesAdapter.addPreference("notifications", R.drawable.ic_action_notification, getString(R.string.settings_notifications),
|
|
|
|
R.xml.preferences_notifications)
|
|
|
|
entriesAdapter.addPreference("network", R.drawable.ic_action_web, getString(R.string.network),
|
|
|
|
R.xml.preferences_network)
|
|
|
|
entriesAdapter.addPreference("compose", R.drawable.ic_action_status_compose, getString(R.string.action_compose),
|
|
|
|
R.xml.preferences_compose)
|
|
|
|
entriesAdapter.addPreference("content", R.drawable.ic_action_twidere_square, getString(R.string.content),
|
|
|
|
R.xml.preferences_content)
|
|
|
|
entriesAdapter.addPreference("storage", R.drawable.ic_action_storage, getString(R.string.preference_title_storage),
|
|
|
|
R.xml.preferences_storage)
|
|
|
|
entriesAdapter.addPreference("other", R.drawable.ic_action_more_horizontal, getString(R.string.other_settings),
|
|
|
|
R.xml.preferences_other)
|
|
|
|
|
|
|
|
entriesAdapter.addHeader(getString(R.string.title_about))
|
|
|
|
entriesAdapter.addPreference("about", R.drawable.ic_action_info, getString(R.string.title_about),
|
|
|
|
R.xml.preferences_about)
|
|
|
|
val browserArgs = Bundle()
|
|
|
|
browserArgs.putString(EXTRA_URI, "file:///android_asset/gpl-3.0-standalone.html")
|
|
|
|
entriesAdapter.addPreference("license", R.drawable.ic_action_open_source, getString(R.string.title_open_source_license),
|
2017-01-12 17:26:44 +01:00
|
|
|
BrowserFragment::class.java, browserArgs)
|
2016-12-30 16:17:46 +01:00
|
|
|
}
|
|
|
|
|
2016-12-06 06:15:22 +01:00
|
|
|
private fun openDetails(position: Int) {
|
2016-07-07 09:39:32 +02:00
|
|
|
if (isFinishing) return
|
2016-12-07 08:10:14 +01:00
|
|
|
val entry = entriesAdapter.getItem(position) as? PreferenceEntry ?: return
|
2016-07-07 09:39:32 +02:00
|
|
|
val fm = supportFragmentManager
|
2016-12-16 14:02:41 +01:00
|
|
|
fm.popBackStackImmediate(null, 0)
|
2016-07-07 09:39:32 +02:00
|
|
|
val ft = fm.beginTransaction()
|
|
|
|
if (entry.preference != 0) {
|
|
|
|
val args = Bundle()
|
|
|
|
args.putInt(EXTRA_RESID, entry.preference)
|
|
|
|
val f = Fragment.instantiate(this, SettingsDetailsFragment::class.java.name,
|
|
|
|
args)
|
2016-12-07 08:10:14 +01:00
|
|
|
ft.replace(R.id.detailFragmentContainer, f)
|
2016-07-07 09:39:32 +02:00
|
|
|
} else if (entry.fragment != null) {
|
2016-12-07 08:10:14 +01:00
|
|
|
ft.replace(R.id.detailFragmentContainer, Fragment.instantiate(this, entry.fragment,
|
2016-07-07 09:39:32 +02:00
|
|
|
entry.args))
|
|
|
|
}
|
|
|
|
ft.setBreadCrumbTitle(entry.title)
|
|
|
|
ft.commit()
|
2016-12-07 08:10:14 +01:00
|
|
|
slidingPane.closePane()
|
2016-07-07 09:39:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun notifyUnsavedChange(): Boolean {
|
2017-02-07 07:35:11 +01:00
|
|
|
if (isTopSettings && (shouldRecreate || shouldRestart || shouldTerminate)) {
|
2016-07-07 09:39:32 +02:00
|
|
|
val df = RestartConfirmDialogFragment()
|
2017-02-07 07:35:11 +01:00
|
|
|
df.arguments = Bundle {
|
|
|
|
this[EXTRA_SHOULD_RECREATE] = shouldRecreate
|
|
|
|
this[EXTRA_SHOULD_RESTART] = shouldRestart
|
|
|
|
this[EXTRA_SHOULD_TERMINATE] = shouldTerminate
|
|
|
|
}
|
2016-07-07 09:39:32 +02:00
|
|
|
df.show(supportFragmentManager, "restart_confirm")
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2016-12-06 06:15:22 +01:00
|
|
|
internal class EntriesAdapter(context: Context) : BaseAdapter() {
|
2016-12-30 16:17:46 +01:00
|
|
|
private val inflater: LayoutInflater = LayoutInflater.from(context)
|
|
|
|
private val entries: MutableList<Entry> = ArrayList()
|
2016-07-07 09:39:32 +02:00
|
|
|
|
|
|
|
fun addPreference(tag: String, @DrawableRes icon: Int, title: String, @XmlRes preference: Int) {
|
2016-12-06 06:15:22 +01:00
|
|
|
entries.add(PreferenceEntry(tag, icon, title, preference, null, null))
|
2016-07-07 09:39:32 +02:00
|
|
|
notifyDataSetChanged()
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-06 06:15:22 +01:00
|
|
|
fun addPreference(tag: String, @DrawableRes icon: Int, title: String, cls: Class<out Fragment>,
|
2017-03-10 19:16:23 +01:00
|
|
|
args: Bundle? = null) {
|
2016-12-06 06:15:22 +01:00
|
|
|
entries.add(PreferenceEntry(tag, icon, title, 0, cls.name, args))
|
2016-07-07 09:39:32 +02:00
|
|
|
notifyDataSetChanged()
|
|
|
|
}
|
|
|
|
|
|
|
|
fun addHeader(title: String) {
|
2016-12-06 06:15:22 +01:00
|
|
|
entries.add(HeaderEntry(title))
|
2016-07-07 09:39:32 +02:00
|
|
|
notifyDataSetChanged()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getCount(): Int {
|
2016-12-06 06:15:22 +01:00
|
|
|
return entries.size
|
2016-07-07 09:39:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun getItem(position: Int): Entry {
|
2016-12-06 06:15:22 +01:00
|
|
|
return entries[position]
|
2016-07-07 09:39:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun getItemId(position: Int): Long {
|
|
|
|
return getItem(position).hashCode().toLong()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun isEnabled(position: Int): Boolean {
|
|
|
|
return getItemViewType(position) == VIEW_TYPE_PREFERENCE_ENTRY
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getViewTypeCount(): Int {
|
|
|
|
return 2
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getItemViewType(position: Int): Int {
|
|
|
|
val entry = getItem(position)
|
|
|
|
if (entry is PreferenceEntry) {
|
|
|
|
return VIEW_TYPE_PREFERENCE_ENTRY
|
|
|
|
} else if (entry is HeaderEntry) {
|
|
|
|
return VIEW_TYPE_HEADER_ENTRY
|
|
|
|
}
|
|
|
|
throw UnsupportedOperationException()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
|
|
|
val viewType = getItemViewType(position)
|
|
|
|
val entry = getItem(position)
|
2016-12-06 06:15:22 +01:00
|
|
|
val view: View = convertView ?: let {
|
2016-07-07 09:39:32 +02:00
|
|
|
when (viewType) {
|
|
|
|
VIEW_TYPE_PREFERENCE_ENTRY -> {
|
2016-12-06 06:15:22 +01:00
|
|
|
return@let inflater.inflate(R.layout.list_item_preference_header_item, parent, false)
|
2016-07-07 09:39:32 +02:00
|
|
|
}
|
|
|
|
VIEW_TYPE_HEADER_ENTRY -> {
|
2016-12-06 06:15:22 +01:00
|
|
|
return@let inflater.inflate(R.layout.list_item_preference_header_category, parent, false)
|
2016-07-07 09:39:32 +02:00
|
|
|
}
|
|
|
|
else -> {
|
|
|
|
throw UnsupportedOperationException()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
entry.bind(view)
|
|
|
|
return view
|
|
|
|
}
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
|
|
|
|
val VIEW_TYPE_PREFERENCE_ENTRY = 0
|
|
|
|
val VIEW_TYPE_HEADER_ENTRY = 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal abstract class Entry {
|
|
|
|
abstract fun bind(view: View)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
internal class PreferenceEntry(
|
|
|
|
val tag: String,
|
|
|
|
val icon: Int,
|
|
|
|
val title: String,
|
|
|
|
val preference: Int,
|
|
|
|
val fragment: String?,
|
|
|
|
val args: Bundle?
|
|
|
|
) : Entry() {
|
|
|
|
|
|
|
|
override fun bind(view: View) {
|
|
|
|
(view.findViewById(android.R.id.icon) as ImageView).setImageResource(icon)
|
|
|
|
(view.findViewById(android.R.id.title) as TextView).text = title
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
internal class HeaderEntry(private val title: String) : Entry() {
|
|
|
|
|
|
|
|
override fun bind(view: View) {
|
|
|
|
(view.findViewById(android.R.id.title) as TextView).text = title
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class RestartConfirmDialogFragment : BaseDialogFragment(), DialogInterface.OnClickListener {
|
|
|
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
|
|
|
val builder = AlertDialog.Builder(activity)
|
2017-02-07 07:35:11 +01:00
|
|
|
if (arguments.getBoolean(EXTRA_SHOULD_TERMINATE)) {
|
|
|
|
builder.setMessage(R.string.app_terminate_confirm)
|
|
|
|
builder.setNegativeButton(R.string.action_dont_terminate, this)
|
|
|
|
} else {
|
|
|
|
builder.setMessage(R.string.app_restart_confirm)
|
|
|
|
builder.setNegativeButton(R.string.action_dont_restart, this)
|
|
|
|
}
|
2016-07-07 09:39:32 +02:00
|
|
|
builder.setPositiveButton(android.R.string.ok, this)
|
2017-02-05 14:42:20 +01:00
|
|
|
val dialog = builder.create()
|
|
|
|
dialog.setOnShowListener {
|
|
|
|
it as AlertDialog
|
|
|
|
it.applyTheme()
|
|
|
|
}
|
|
|
|
return dialog
|
2016-07-07 09:39:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onClick(dialog: DialogInterface, which: Int) {
|
|
|
|
val activity = activity as SettingsActivity
|
|
|
|
when (which) {
|
|
|
|
DialogInterface.BUTTON_POSITIVE -> {
|
2017-02-07 07:35:11 +01:00
|
|
|
if (arguments.getBoolean(EXTRA_SHOULD_TERMINATE)) {
|
|
|
|
val intent = Intent(context, SettingsActivity::class.java)
|
|
|
|
intent.putExtra(EXTRA_SHOULD_TERMINATE, true)
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
|
|
activity.startActivity(intent)
|
|
|
|
} else {
|
|
|
|
activity.finish()
|
|
|
|
}
|
2016-07-07 09:39:32 +02:00
|
|
|
}
|
|
|
|
DialogInterface.BUTTON_NEGATIVE -> {
|
|
|
|
activity.finishNoRestart()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
|
|
|
|
val EXTRA_INITIAL_TAG = "initial_tag"
|
|
|
|
|
|
|
|
private val RESULT_SETTINGS_CHANGED = 10
|
|
|
|
|
2016-07-26 09:12:25 +02:00
|
|
|
fun setShouldRecreate(activity: Activity) {
|
|
|
|
if (activity !is SettingsActivity) return
|
|
|
|
activity.shouldRecreate = true
|
|
|
|
}
|
|
|
|
|
|
|
|
fun setShouldRestart(activity: Activity) {
|
2016-07-07 09:39:32 +02:00
|
|
|
if (activity !is SettingsActivity) return
|
2016-07-26 09:12:25 +02:00
|
|
|
activity.shouldRestart = true
|
2016-07-07 09:39:32 +02:00
|
|
|
}
|
2017-02-07 07:35:11 +01:00
|
|
|
|
|
|
|
fun setShouldTerminate(activity: Activity) {
|
|
|
|
if (activity !is SettingsActivity) return
|
|
|
|
activity.shouldTerminate = true
|
|
|
|
}
|
2016-07-07 09:39:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|