improved night mode

This commit is contained in:
Mariotaku Lee 2017-04-24 19:39:03 +08:00
parent b67cc84718
commit 7dcf2246d4
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
4 changed files with 23 additions and 5 deletions

View File

@ -10,4 +10,12 @@ object TwilightManagerAccessor {
fun isNight(context: Context): Boolean {
return TwilightManager.getInstance(context).isNight
}
fun getNightState(context: Context): Int {
return if (isNight(context)) NIGHT else DAY
}
const val UNSPECIFIED = 0
const val DAY = 1
const val NIGHT = 2
}

View File

@ -31,6 +31,7 @@ import android.nfc.NfcAdapter
import android.os.Bundle
import android.support.annotation.StyleRes
import android.support.v4.graphics.ColorUtils
import android.support.v7.app.TwilightManagerAccessor
import android.support.v7.preference.Preference
import android.support.v7.preference.PreferenceFragmentCompat
import android.support.v7.preference.PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback
@ -122,6 +123,7 @@ open class BaseActivity : ChameleonActivity(), IBaseActivity<BaseActivity>, IThe
protected val gifShareProvider: GifShareProvider?
get() = gifShareProviderFactory.newInstance(this)
private var isNightBackup: Int = TwilightManagerAccessor.UNSPECIFIED
private val actionHelper = IBaseActivity.ActionHelper(this)
private val themePreferences by lazy {
@ -212,7 +214,6 @@ open class BaseActivity : ChameleonActivity(), IBaseActivity<BaseActivity>, IThe
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)
@ -231,9 +232,15 @@ open class BaseActivity : ChameleonActivity(), IBaseActivity<BaseActivity>, IThe
} catch (e: Exception) {
// Ignore if blocked by modified roms
}
}
}
val nightState = TwilightManagerAccessor.getNightState(this)
if (isNightBackup != TwilightManagerAccessor.UNSPECIFIED && nightState != isNightBackup) {
recreate()
return
}
isNightBackup = nightState
}
override fun onPause() {

View File

@ -24,14 +24,16 @@ import android.text.format.DateUtils
import org.mariotaku.microblog.library.MicroBlogException
import org.mariotaku.twidere.R
import org.mariotaku.twidere.util.StatusCodeMessageUtils
import java.security.cert.CertPathValidatorException
/**
* Created by mariotaku on 2017/4/20.
*/
fun Throwable.getErrorMessage(context: Context): CharSequence {
if (this is MicroBlogException) return getMicroBlogErrorMessage(context)
return message ?: toString()
fun Throwable.getErrorMessage(context: Context): CharSequence = when (this) {
is MicroBlogException -> getMicroBlogErrorMessage(context)
is CertPathValidatorException -> context.getString(R.string.message_toast_ssl_tls_error)
else -> message ?: toString()
}

View File

@ -1342,4 +1342,5 @@
<string name="users_blocked">Blocked these users.</string>
<string name="users_lists_with_name"><xliff:g id="name">%s</xliff:g>\'s lists</string>
<string name="users_statuses">User\'s tweets</string>
<string name="message_toast_ssl_tls_error">TLS error, please check your clock or proxy settings</string>
</resources>