2016-07-02 05:54:53 +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.annotation.SuppressLint
|
|
|
|
import android.app.PendingIntent
|
2017-04-24 14:31:16 +02:00
|
|
|
import android.content.*
|
2016-07-02 05:54:53 +02:00
|
|
|
import android.content.res.Resources
|
|
|
|
import android.graphics.Rect
|
|
|
|
import android.nfc.NfcAdapter
|
2017-06-25 05:36:54 +02:00
|
|
|
import android.os.Build
|
2016-07-02 05:54:53 +02:00
|
|
|
import android.os.Bundle
|
2020-05-26 11:15:09 +02:00
|
|
|
import android.util.AttributeSet
|
|
|
|
import android.view.KeyEvent
|
|
|
|
import android.view.MotionEvent
|
|
|
|
import android.view.View
|
|
|
|
import android.view.WindowManager
|
2020-01-26 08:35:15 +01:00
|
|
|
import androidx.annotation.StyleRes
|
2020-05-26 11:15:09 +02:00
|
|
|
import androidx.appcompat.app.TwilightManagerAccessor
|
|
|
|
import androidx.appcompat.view.menu.ActionMenuItemView
|
|
|
|
import androidx.appcompat.widget.TwidereActionMenuView
|
2020-01-26 08:35:15 +01:00
|
|
|
import androidx.core.graphics.ColorUtils
|
|
|
|
import androidx.core.view.OnApplyWindowInsetsListener
|
|
|
|
import androidx.core.view.WindowInsetsCompat
|
2020-05-26 11:15:09 +02:00
|
|
|
import androidx.fragment.app.Fragment
|
2020-01-26 08:35:15 +01:00
|
|
|
import androidx.preference.Preference
|
|
|
|
import androidx.preference.PreferenceFragmentCompat
|
|
|
|
import androidx.preference.PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback
|
2017-09-03 15:23:45 +02:00
|
|
|
import com.bumptech.glide.Glide
|
|
|
|
import com.bumptech.glide.RequestManager
|
2016-07-02 05:54:53 +02:00
|
|
|
import com.squareup.otto.Bus
|
2017-03-22 13:00:29 +01:00
|
|
|
import nl.komponents.kovenant.Promise
|
2016-12-18 03:32:11 +01:00
|
|
|
import org.mariotaku.chameleon.Chameleon
|
2016-12-18 06:21:24 +01:00
|
|
|
import org.mariotaku.chameleon.ChameleonActivity
|
2016-12-12 06:42:27 +01:00
|
|
|
import org.mariotaku.kpreferences.KPreferences
|
2016-12-23 15:46:59 +01:00
|
|
|
import org.mariotaku.kpreferences.get
|
2017-09-04 18:21:41 +02:00
|
|
|
import org.mariotaku.ktextension.activityLabel
|
2017-06-25 17:01:33 +02:00
|
|
|
import org.mariotaku.ktextension.getSystemWindowInsets
|
2017-04-27 08:53:06 +02:00
|
|
|
import org.mariotaku.ktextension.unregisterReceiverSafe
|
2017-01-26 16:52:14 +01:00
|
|
|
import org.mariotaku.restfu.http.RestHttpClient
|
2016-07-02 05:54:53 +02:00
|
|
|
import org.mariotaku.twidere.BuildConfig
|
2017-08-01 08:42:20 +02:00
|
|
|
import org.mariotaku.twidere.R
|
2016-07-07 05:42:08 +02:00
|
|
|
import org.mariotaku.twidere.TwidereConstants.SHARED_PREFERENCES_NAME
|
2017-03-01 02:11:56 +01:00
|
|
|
import org.mariotaku.twidere.activity.iface.IBaseActivity
|
2017-03-21 03:33:27 +01:00
|
|
|
import org.mariotaku.twidere.activity.iface.IControlBarActivity
|
2016-07-02 05:54:53 +02:00
|
|
|
import org.mariotaku.twidere.activity.iface.IThemedActivity
|
2017-06-25 17:01:33 +02:00
|
|
|
import org.mariotaku.twidere.annotation.NavbarStyle
|
2017-06-25 05:36:54 +02:00
|
|
|
import org.mariotaku.twidere.constant.*
|
2017-09-04 13:24:23 +02:00
|
|
|
import org.mariotaku.twidere.extension.defaultSharedPreferences
|
2017-09-04 18:21:41 +02:00
|
|
|
import org.mariotaku.twidere.extension.firstLanguage
|
2017-09-04 13:24:23 +02:00
|
|
|
import org.mariotaku.twidere.extension.overriding
|
2017-06-25 05:36:54 +02:00
|
|
|
import org.mariotaku.twidere.fragment.iface.IBaseFragment.SystemWindowInsetsCallback
|
2017-01-26 16:52:14 +01:00
|
|
|
import org.mariotaku.twidere.model.DefaultFeatures
|
2016-07-02 05:54:53 +02:00
|
|
|
import org.mariotaku.twidere.preference.iface.IDialogPreference
|
|
|
|
import org.mariotaku.twidere.util.*
|
|
|
|
import org.mariotaku.twidere.util.KeyboardShortcutsHandler.KeyboardShortcutCallback
|
2017-04-16 15:09:56 +02:00
|
|
|
import org.mariotaku.twidere.util.dagger.GeneralComponent
|
2017-03-29 09:04:55 +02:00
|
|
|
import org.mariotaku.twidere.util.gifshare.GifShareProvider
|
2017-01-20 15:08:42 +01:00
|
|
|
import org.mariotaku.twidere.util.premium.ExtraFeaturesService
|
2017-09-18 07:28:36 +02:00
|
|
|
import org.mariotaku.twidere.util.promotion.PromotionService
|
2017-03-29 09:04:55 +02:00
|
|
|
import org.mariotaku.twidere.util.schedule.StatusScheduleProvider
|
2017-01-03 16:37:24 +01:00
|
|
|
import org.mariotaku.twidere.util.support.ActivitySupport
|
|
|
|
import org.mariotaku.twidere.util.support.ActivitySupport.TaskDescriptionCompat
|
2017-06-25 05:36:54 +02:00
|
|
|
import org.mariotaku.twidere.util.support.WindowSupport
|
2017-04-13 18:57:14 +02:00
|
|
|
import org.mariotaku.twidere.util.sync.TimelineSyncManager
|
2016-12-23 03:26:44 +01:00
|
|
|
import org.mariotaku.twidere.util.theme.TwidereAppearanceCreator
|
2017-01-07 16:51:21 +01:00
|
|
|
import org.mariotaku.twidere.util.theme.getCurrentThemeResource
|
2016-07-02 05:54:53 +02:00
|
|
|
import java.lang.reflect.InvocationTargetException
|
|
|
|
import java.util.*
|
|
|
|
import javax.inject.Inject
|
|
|
|
|
|
|
|
@SuppressLint("Registered")
|
2017-03-01 02:11:56 +01:00
|
|
|
open class BaseActivity : ChameleonActivity(), IBaseActivity<BaseActivity>, IThemedActivity,
|
2017-06-25 17:01:33 +02:00
|
|
|
IControlBarActivity, OnApplyWindowInsetsListener, SystemWindowInsetsCallback,
|
2016-12-18 06:21:24 +01:00
|
|
|
KeyboardShortcutCallback, OnPreferenceDisplayDialogCallback {
|
2016-12-24 05:30:43 +01:00
|
|
|
|
2016-07-02 05:54:53 +02:00
|
|
|
@Inject
|
|
|
|
lateinit var keyboardShortcutsHandler: KeyboardShortcutsHandler
|
|
|
|
@Inject
|
|
|
|
lateinit var twitterWrapper: AsyncTwitterWrapper
|
|
|
|
@Inject
|
|
|
|
lateinit var readStateManager: ReadStateManager
|
|
|
|
@Inject
|
|
|
|
lateinit var bus: Bus
|
|
|
|
@Inject
|
2017-04-17 15:10:14 +02:00
|
|
|
lateinit var preferences: SharedPreferences
|
2016-07-02 05:54:53 +02:00
|
|
|
@Inject
|
2016-12-12 06:42:27 +01:00
|
|
|
lateinit var kPreferences: KPreferences
|
|
|
|
@Inject
|
2016-07-02 05:54:53 +02:00
|
|
|
lateinit var notificationManager: NotificationManagerWrapper
|
|
|
|
@Inject
|
|
|
|
lateinit var userColorNameManager: UserColorNameManager
|
|
|
|
@Inject
|
|
|
|
lateinit var permissionsManager: PermissionsManager
|
2017-01-20 15:08:42 +01:00
|
|
|
@Inject
|
|
|
|
lateinit var extraFeaturesService: ExtraFeaturesService
|
2017-01-26 16:52:14 +01:00
|
|
|
@Inject
|
2017-03-29 09:04:55 +02:00
|
|
|
lateinit var statusScheduleProviderFactory: StatusScheduleProvider.Factory
|
|
|
|
@Inject
|
2017-04-13 18:57:14 +02:00
|
|
|
lateinit var timelineSyncManagerFactory: TimelineSyncManager.Factory
|
|
|
|
@Inject
|
2017-03-29 09:04:55 +02:00
|
|
|
lateinit var gifShareProviderFactory: GifShareProvider.Factory
|
2017-03-25 14:44:07 +01:00
|
|
|
@Inject
|
2017-01-26 16:52:14 +01:00
|
|
|
lateinit var defaultFeatures: DefaultFeatures
|
|
|
|
@Inject
|
|
|
|
lateinit var restHttpClient: RestHttpClient
|
2017-04-18 15:19:07 +02:00
|
|
|
@Inject
|
|
|
|
lateinit var mastodonApplicationRegistry: MastodonApplicationRegistry
|
2017-08-23 09:25:06 +02:00
|
|
|
@Inject
|
|
|
|
lateinit var taskServiceRunner: TaskServiceRunner
|
2017-09-18 07:28:36 +02:00
|
|
|
@Inject
|
|
|
|
lateinit var promotionService: PromotionService
|
2016-07-02 05:54:53 +02:00
|
|
|
|
2017-09-03 15:23:45 +02:00
|
|
|
lateinit var requestManager: RequestManager
|
|
|
|
private set
|
|
|
|
|
2017-03-29 09:04:55 +02:00
|
|
|
protected val statusScheduleProvider: StatusScheduleProvider?
|
|
|
|
get() = statusScheduleProviderFactory.newInstance(this)
|
|
|
|
|
2017-04-13 18:57:14 +02:00
|
|
|
protected val timelineSyncManager: TimelineSyncManager?
|
|
|
|
get() = timelineSyncManagerFactory.get()
|
|
|
|
|
2017-03-29 09:04:55 +02:00
|
|
|
protected val gifShareProvider: GifShareProvider?
|
|
|
|
get() = gifShareProviderFactory.newInstance(this)
|
2017-03-26 15:41:28 +02:00
|
|
|
|
2017-08-01 08:42:20 +02:00
|
|
|
protected val isDialogTheme: Boolean
|
|
|
|
get() = ThemeUtils.getBooleanFromAttribute(this, R.attr.isDialogTheme)
|
|
|
|
|
2019-10-24 17:52:11 +02:00
|
|
|
final override val currentThemeBackgroundAlpha by lazy {
|
2017-04-24 14:31:16 +02:00
|
|
|
themeBackgroundAlpha
|
|
|
|
}
|
|
|
|
|
2019-10-24 17:52:11 +02:00
|
|
|
final override val currentThemeBackgroundOption by lazy {
|
2017-04-24 14:31:16 +02:00
|
|
|
themeBackgroundOption
|
|
|
|
}
|
|
|
|
|
|
|
|
override val themeBackgroundAlpha: Int
|
|
|
|
get() = themePreferences[themeBackgroundAlphaKey]
|
|
|
|
|
|
|
|
|
|
|
|
override val themeBackgroundOption: String
|
|
|
|
get() = themePreferences[themeBackgroundOptionKey]
|
|
|
|
|
2017-08-22 09:39:47 +02:00
|
|
|
open val themeNavigationStyle: String
|
|
|
|
get() = themePreferences[navbarStyleKey]
|
|
|
|
|
2017-04-24 13:39:03 +02:00
|
|
|
private var isNightBackup: Int = TwilightManagerAccessor.UNSPECIFIED
|
2017-03-25 14:44:07 +01:00
|
|
|
|
2017-09-03 15:23:45 +02:00
|
|
|
private val actionHelper = IBaseActivity.ActionHelper<BaseActivity>()
|
2017-04-24 14:31:16 +02:00
|
|
|
|
2017-03-21 03:33:27 +01:00
|
|
|
private val themePreferences by lazy {
|
|
|
|
getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE)
|
|
|
|
}
|
2016-07-02 05:54:53 +02:00
|
|
|
|
|
|
|
// Registered listeners
|
2016-12-18 06:21:24 +01:00
|
|
|
private val controlBarOffsetListeners = ArrayList<IControlBarActivity.ControlBarOffsetListener>()
|
2016-07-02 05:54:53 +02:00
|
|
|
|
2016-12-20 01:10:45 +01:00
|
|
|
private val userTheme: Chameleon.Theme by lazy {
|
2017-04-15 10:18:01 +02:00
|
|
|
return@lazy ThemeUtils.getUserTheme(this, themePreferences)
|
2016-12-20 01:10:45 +01:00
|
|
|
}
|
|
|
|
|
2017-04-24 14:31:16 +02:00
|
|
|
private val nightTimeChangedReceiver = object : BroadcastReceiver() {
|
|
|
|
override fun onReceive(context: Context, intent: Intent) {
|
|
|
|
when (intent.action) {
|
|
|
|
Intent.ACTION_TIME_TICK, Intent.ACTION_TIME_CHANGED,
|
|
|
|
Intent.ACTION_TIMEZONE_CHANGED -> {
|
|
|
|
if (!isFinishing) {
|
|
|
|
updateNightMode()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-02 05:54:53 +02:00
|
|
|
// Data fields
|
2017-06-25 17:01:33 +02:00
|
|
|
protected var systemWindowsInsets: Rect? = null
|
|
|
|
private set
|
2016-07-02 05:54:53 +02:00
|
|
|
var keyMetaState: Int = 0
|
|
|
|
private set
|
|
|
|
|
2017-06-26 08:48:05 +02:00
|
|
|
override fun getSystemWindowInsets(caller: Fragment, insets: Rect): Boolean {
|
2021-03-01 06:55:17 +01:00
|
|
|
return systemWindowsInsets?.let {
|
|
|
|
insets.set(it)
|
|
|
|
true
|
|
|
|
} ?: false
|
2016-07-02 05:54:53 +02:00
|
|
|
}
|
|
|
|
|
2017-06-25 17:01:33 +02:00
|
|
|
override fun onApplyWindowInsets(v: View, insets: WindowInsetsCompat): WindowInsetsCompat {
|
|
|
|
if (systemWindowsInsets == null) {
|
2020-02-06 08:58:34 +01:00
|
|
|
systemWindowsInsets = Rect(insets.systemWindowInsets.left,
|
|
|
|
insets.systemWindowInsets.top,
|
|
|
|
insets.systemWindowInsets.right,
|
|
|
|
insets.systemWindowInsets.bottom)
|
2017-06-25 17:01:33 +02:00
|
|
|
} else {
|
|
|
|
insets.getSystemWindowInsets(systemWindowsInsets!!)
|
2016-07-02 05:54:53 +02:00
|
|
|
}
|
|
|
|
notifyControlBarOffsetChanged()
|
2017-06-25 17:01:33 +02:00
|
|
|
return insets
|
2016-07-02 05:54:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun dispatchKeyEvent(event: KeyEvent): Boolean {
|
|
|
|
val keyCode = event.keyCode
|
|
|
|
if (KeyEvent.isModifierKey(keyCode)) {
|
|
|
|
val action = event.action
|
|
|
|
if (action == MotionEvent.ACTION_DOWN) {
|
|
|
|
keyMetaState = keyMetaState or KeyboardShortcutsHandler.getMetaStateForKeyCode(keyCode)
|
|
|
|
} else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
|
|
|
|
keyMetaState = keyMetaState and KeyboardShortcutsHandler.getMetaStateForKeyCode(keyCode).inv()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return super.dispatchKeyEvent(event)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean {
|
|
|
|
if (handleKeyboardShortcutSingle(keyboardShortcutsHandler, keyCode, event, keyMetaState))
|
|
|
|
return true
|
|
|
|
return isKeyboardShortcutHandled(keyboardShortcutsHandler, keyCode, event, keyMetaState) || super.onKeyUp(keyCode, event)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
|
|
|
|
if (handleKeyboardShortcutRepeat(keyboardShortcutsHandler, keyCode, event.repeatCount, event, keyMetaState))
|
|
|
|
return true
|
|
|
|
return isKeyboardShortcutHandled(keyboardShortcutsHandler, keyCode, event, keyMetaState) || super.onKeyDown(keyCode, event)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun handleKeyboardShortcutSingle(handler: KeyboardShortcutsHandler, keyCode: Int, event: KeyEvent, metaState: Int): Boolean {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun isKeyboardShortcutHandled(handler: KeyboardShortcutsHandler, keyCode: Int, event: KeyEvent, metaState: Int): Boolean {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun handleKeyboardShortcutRepeat(handler: KeyboardShortcutsHandler, keyCode: Int, repeatCount: Int, event: KeyEvent, metaState: Int): Boolean {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
if (BuildConfig.DEBUG) {
|
|
|
|
StrictModeUtils.detectAllVmPolicy()
|
|
|
|
StrictModeUtils.detectAllThreadPolicy()
|
|
|
|
}
|
2017-08-22 09:39:47 +02:00
|
|
|
val themeColor = themePreferences[themeColorKey]
|
|
|
|
val themeResource = getThemeResource(themePreferences, themePreferences[themeKey], themeColor)
|
2016-12-23 15:46:59 +01:00
|
|
|
if (themeResource != 0) {
|
|
|
|
setTheme(themeResource)
|
|
|
|
}
|
2017-08-22 09:39:47 +02:00
|
|
|
onApplyNavigationStyle(themeNavigationStyle, themeColor)
|
2016-07-02 05:54:53 +02:00
|
|
|
super.onCreate(savedInstanceState)
|
2017-09-04 18:21:41 +02:00
|
|
|
title = activityLabel
|
2017-09-03 15:23:45 +02:00
|
|
|
requestManager = Glide.with(this)
|
2017-01-03 16:37:24 +01:00
|
|
|
ActivitySupport.setTaskDescription(this, TaskDescriptionCompat(title.toString(), null,
|
|
|
|
ColorUtils.setAlphaComponent(overrideTheme.colorToolbar, 0xFF)))
|
2017-04-16 15:09:56 +02:00
|
|
|
GeneralComponent.get(this).inject(this)
|
2016-07-02 05:54:53 +02:00
|
|
|
}
|
|
|
|
|
2017-09-03 15:23:45 +02:00
|
|
|
override fun onStart() {
|
|
|
|
super.onStart()
|
|
|
|
requestManager.onStart()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onStop() {
|
|
|
|
requestManager.onStop()
|
|
|
|
super.onStop()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onDestroy() {
|
|
|
|
requestManager.onDestroy()
|
|
|
|
super.onDestroy()
|
|
|
|
}
|
|
|
|
|
2016-07-02 05:54:53 +02:00
|
|
|
override fun onResume() {
|
|
|
|
super.onResume()
|
|
|
|
val adapter = NfcAdapter.getDefaultAdapter(this)
|
|
|
|
if (adapter != null && adapter.isEnabled) {
|
|
|
|
val handlerFilter = IntentUtils.getWebLinkIntentFilter(this)
|
|
|
|
if (handlerFilter != null) {
|
|
|
|
val linkIntent = Intent(this, WebLinkHandlerActivity::class.java)
|
|
|
|
val intent = PendingIntent.getActivity(this, 0, linkIntent, 0)
|
|
|
|
val intentFilter = IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED)
|
2016-08-21 15:30:07 +02:00
|
|
|
for (i in 0 until handlerFilter.countDataSchemes()) {
|
|
|
|
intentFilter.addDataScheme(handlerFilter.getDataScheme(i))
|
2016-07-02 05:54:53 +02:00
|
|
|
}
|
2016-08-21 15:30:07 +02:00
|
|
|
for (i in 0 until handlerFilter.countDataAuthorities()) {
|
2016-07-02 05:54:53 +02:00
|
|
|
val authorityEntry = handlerFilter.getDataAuthority(i)
|
|
|
|
val port = authorityEntry.port
|
2020-06-09 00:50:51 +02:00
|
|
|
intentFilter.addDataAuthority(authorityEntry.host, if (port < 0) null else port.toString())
|
2016-07-02 05:54:53 +02:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
adapter.enableForegroundDispatch(this, intent, arrayOf(intentFilter), null)
|
|
|
|
} catch (e: Exception) {
|
|
|
|
// Ignore if blocked by modified roms
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-04-24 13:39:03 +02:00
|
|
|
|
2017-04-24 14:31:16 +02:00
|
|
|
val filter = IntentFilter()
|
|
|
|
filter.addAction(Intent.ACTION_TIME_TICK)
|
|
|
|
filter.addAction(Intent.ACTION_TIME_CHANGED)
|
|
|
|
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED)
|
|
|
|
registerReceiver(nightTimeChangedReceiver, filter)
|
|
|
|
|
|
|
|
updateNightMode()
|
2016-07-02 05:54:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onPause() {
|
2017-04-24 14:31:16 +02:00
|
|
|
|
2017-04-27 08:53:06 +02:00
|
|
|
unregisterReceiverSafe(nightTimeChangedReceiver)
|
2017-04-24 14:31:16 +02:00
|
|
|
|
2016-07-02 05:54:53 +02:00
|
|
|
val adapter = NfcAdapter.getDefaultAdapter(this)
|
|
|
|
if (adapter != null && adapter.isEnabled) {
|
|
|
|
try {
|
|
|
|
adapter.disableForegroundDispatch(this)
|
|
|
|
} catch (e: Exception) {
|
|
|
|
// Ignore if blocked by modified roms
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
actionHelper.dispatchOnPause()
|
|
|
|
super.onPause()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun notifyControlBarOffsetChanged() {
|
|
|
|
val offset = controlBarOffset
|
2016-12-18 06:21:24 +01:00
|
|
|
for (l in controlBarOffsetListeners) {
|
2016-07-02 05:54:53 +02:00
|
|
|
l.onControlBarOffsetChanged(this, offset)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun registerControlBarOffsetListener(listener: IControlBarActivity.ControlBarOffsetListener) {
|
2016-12-18 06:21:24 +01:00
|
|
|
controlBarOffsetListeners.add(listener)
|
2016-07-02 05:54:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun unregisterControlBarOffsetListener(listener: IControlBarActivity.ControlBarOffsetListener) {
|
2016-12-18 06:21:24 +01:00
|
|
|
controlBarOffsetListeners.remove(listener)
|
2016-07-02 05:54:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onResumeFragments() {
|
|
|
|
super.onResumeFragments()
|
2017-09-03 15:23:45 +02:00
|
|
|
actionHelper.dispatchOnResumeFragments(this)
|
2016-07-02 05:54:53 +02:00
|
|
|
}
|
|
|
|
|
2017-09-04 18:21:41 +02:00
|
|
|
override fun attachBaseContext(newBase: Context) {
|
|
|
|
val locale = newBase.defaultSharedPreferences[overrideLanguageKey] ?: Resources.getSystem()
|
|
|
|
.firstLanguage
|
2017-09-04 13:24:23 +02:00
|
|
|
if (locale == null) {
|
|
|
|
super.attachBaseContext(newBase)
|
|
|
|
return
|
|
|
|
}
|
2020-05-26 11:15:09 +02:00
|
|
|
val newContext = newBase.overriding(locale)
|
|
|
|
super.attachBaseContext(newContext)
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
|
|
|
applyOverrideConfiguration(newContext.resources.configuration)
|
|
|
|
}
|
2017-09-04 13:24:23 +02:00
|
|
|
}
|
|
|
|
|
2017-03-22 13:00:29 +01:00
|
|
|
override fun executeAfterFragmentResumed(useHandler: Boolean, action: (BaseActivity) -> Unit): Promise<Unit, Exception> {
|
2017-09-03 15:23:45 +02:00
|
|
|
return actionHelper.executeAfterFragmentResumed(this, useHandler, action)
|
2016-07-02 05:54:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-08 05:12:25 +01:00
|
|
|
protected open val shouldApplyWindowBackground: Boolean
|
2017-01-01 15:37:37 +01:00
|
|
|
get() {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2016-07-02 05:54:53 +02:00
|
|
|
override fun onApplyThemeResource(theme: Resources.Theme, resId: Int, first: Boolean) {
|
|
|
|
super.onApplyThemeResource(theme, resId, first)
|
2016-07-07 05:42:08 +02:00
|
|
|
if (window != null && shouldApplyWindowBackground) {
|
2016-07-02 05:54:53 +02:00
|
|
|
ThemeUtils.applyWindowBackground(this, window, themeBackgroundOption,
|
|
|
|
themeBackgroundAlpha)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onCreateView(parent: View?, name: String, context: Context, attrs: AttributeSet): View? {
|
|
|
|
// Fix for https://github.com/afollestad/app-theme-engine/issues/109
|
2017-03-02 09:44:48 +01:00
|
|
|
if (context != this) {
|
2016-07-02 05:54:53 +02:00
|
|
|
val delegate = delegate
|
|
|
|
var view: View? = delegate.createView(parent, name, context, attrs)
|
|
|
|
if (view == null) {
|
|
|
|
view = newInstance(name, context, attrs)
|
|
|
|
}
|
|
|
|
if (view == null) {
|
|
|
|
view = newInstance(name, context, attrs)
|
|
|
|
}
|
|
|
|
if (view != null) {
|
|
|
|
return view
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (parent is TwidereActionMenuView) {
|
|
|
|
val cls = findClass(name)
|
|
|
|
if (cls != null && ActionMenuItemView::class.java.isAssignableFrom(cls)) {
|
|
|
|
return parent.createActionMenuView(context, attrs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return super.onCreateView(parent, name, context, attrs)
|
|
|
|
}
|
|
|
|
|
2017-04-24 14:31:16 +02:00
|
|
|
override fun onPreferenceDisplayDialog(fragment: PreferenceFragmentCompat, preference: Preference): Boolean {
|
|
|
|
if (preference is IDialogPreference) {
|
|
|
|
preference.displayDialog(fragment)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getOverrideTheme(): Chameleon.Theme {
|
|
|
|
return userTheme
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onCreateAppearanceCreator(): Chameleon.AppearanceCreator? {
|
|
|
|
return TwidereAppearanceCreator
|
|
|
|
}
|
|
|
|
|
|
|
|
@StyleRes
|
|
|
|
protected open fun getThemeResource(preferences: SharedPreferences, theme: String, themeColor: Int): Int {
|
|
|
|
return getCurrentThemeResource(this, theme)
|
|
|
|
}
|
|
|
|
|
2017-06-25 17:01:33 +02:00
|
|
|
private fun onApplyNavigationStyle(navbarStyle: String, themeColor: Int) {
|
2017-08-01 08:42:20 +02:00
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP || isDialogTheme) return
|
2017-06-25 05:36:54 +02:00
|
|
|
when (navbarStyle) {
|
2017-06-25 17:01:33 +02:00
|
|
|
NavbarStyle.TRANSPARENT -> {
|
2017-10-01 12:29:03 +02:00
|
|
|
if (resources.getBoolean(R.bool.support_translucent_navigation)) {
|
|
|
|
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION)
|
|
|
|
}
|
2017-06-25 05:36:54 +02:00
|
|
|
}
|
2017-06-25 17:01:33 +02:00
|
|
|
NavbarStyle.COLORED -> {
|
2017-06-25 05:36:54 +02:00
|
|
|
WindowSupport.setNavigationBarColor(window, themeColor)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-02 05:54:53 +02:00
|
|
|
private fun findClass(name: String): Class<*>? {
|
|
|
|
var cls: Class<*>? = null
|
|
|
|
try {
|
|
|
|
cls = Class.forName(name)
|
|
|
|
} catch (e: ClassNotFoundException) {
|
|
|
|
// Ignore
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cls != null) return cls
|
|
|
|
for (prefix in sClassPrefixList) {
|
|
|
|
try {
|
|
|
|
cls = Class.forName(prefix + name)
|
|
|
|
} catch (e: ClassNotFoundException) {
|
|
|
|
// Ignore
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cls != null) return cls
|
|
|
|
}
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun newInstance(name: String, context: Context, attrs: AttributeSet): View? {
|
2020-06-08 23:19:10 +02:00
|
|
|
return try {
|
2016-07-02 05:54:53 +02:00
|
|
|
val cls = findClass(name) ?: throw ClassNotFoundException(name)
|
|
|
|
val constructor = cls.getConstructor(Context::class.java, AttributeSet::class.java)
|
2020-06-08 23:19:10 +02:00
|
|
|
constructor.newInstance(context, attrs) as View
|
2016-07-02 05:54:53 +02:00
|
|
|
} catch (e: InstantiationException) {
|
2020-06-08 23:19:10 +02:00
|
|
|
null
|
2016-07-02 05:54:53 +02:00
|
|
|
} catch (e: IllegalAccessException) {
|
2020-06-08 23:19:10 +02:00
|
|
|
null
|
2016-07-02 05:54:53 +02:00
|
|
|
} catch (e: InvocationTargetException) {
|
2020-06-08 23:19:10 +02:00
|
|
|
null
|
2016-07-02 05:54:53 +02:00
|
|
|
} catch (e: NoSuchMethodException) {
|
2020-06-08 23:19:10 +02:00
|
|
|
null
|
2016-07-02 05:54:53 +02:00
|
|
|
} catch (e: ClassNotFoundException) {
|
2020-06-08 23:19:10 +02:00
|
|
|
null
|
2016-07-02 05:54:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-04-24 14:31:16 +02:00
|
|
|
private fun updateNightMode() {
|
|
|
|
val nightState = TwilightManagerAccessor.getNightState(this)
|
|
|
|
if (isNightBackup != TwilightManagerAccessor.UNSPECIFIED && nightState != isNightBackup) {
|
|
|
|
recreate()
|
|
|
|
return
|
2016-07-02 05:54:53 +02:00
|
|
|
}
|
2017-04-24 14:31:16 +02:00
|
|
|
isNightBackup = nightState
|
2017-01-07 16:51:21 +01:00
|
|
|
}
|
2016-12-23 15:46:59 +01:00
|
|
|
|
2016-07-02 05:54:53 +02:00
|
|
|
companion object {
|
|
|
|
|
|
|
|
private val sClassPrefixList = arrayOf("android.widget.", "android.view.", "android.webkit.")
|
|
|
|
}
|
|
|
|
}
|
2016-12-23 03:26:44 +01:00
|
|
|
|