This commit is contained in:
Aidan Follestad 2019-03-14 15:06:03 -07:00
parent 4da8cb5f11
commit df2652860e
3 changed files with 25 additions and 4 deletions

View file

@ -63,7 +63,13 @@ abstract class DarkModeSwitchActivity : AppCompatActivity() {
}
}
protected fun isDarkMode() = darkModePref.get()
protected fun isDarkMode(): Boolean {
return when (getCurrentNightMode()) {
ENABLED -> true
DISABLED -> false
else -> darkModePref.get()
}
}
protected fun toggleDarkMode() = setDarkMode(!isDarkMode())

View file

@ -1,3 +1,18 @@
/**
* Designed and developed by Aidan Follestad (@afollestad)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.afollestad.nocknock.ui
/** @author Aidan Follestad (@afollestad) */
@ -8,4 +23,4 @@ enum class NightMode {
DISABLED,
/** We don't know about night mode, fallback to custom impl. */
UNKNOWN
}
}

View file

@ -96,9 +96,9 @@ class MainActivity : DarkModeSwitchActivity() {
menu.findItem(R.id.dark_mode)
.apply {
if (getCurrentNightMode() == UNKNOWN) {
isVisible = false
} else {
isChecked = isDarkMode()
} else {
isVisible = false
}
}
setOnMenuItemClickListener { item ->