diff options
author | Marvin Borner | 2018-08-29 21:17:20 +0200 |
---|---|---|
committer | Marvin Borner | 2018-08-29 21:17:20 +0200 |
commit | 7e03dd99cb3f84f3d176ba44fcce84e551dc3c03 (patch) | |
tree | a54bccaba474a543d4aa0510e50363a2c1dc3afd /app/src/main | |
parent | 7c32f15a399b132e587db01308b7201483fd5f78 (diff) |
Added dark/light themes
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/java/com/no_name/no_name/LoginActivity.kt | 7 | ||||
-rw-r--r-- | app/src/main/java/com/no_name/no_name/MainActivity.kt | 19 | ||||
-rw-r--r-- | app/src/main/java/com/no_name/no_name/Util/ThemeUtil.kt | 31 | ||||
-rw-r--r-- | app/src/main/res/values/styles.xml | 17 |
4 files changed, 60 insertions, 14 deletions
diff --git a/app/src/main/java/com/no_name/no_name/LoginActivity.kt b/app/src/main/java/com/no_name/no_name/LoginActivity.kt index 3076e39..9443e9c 100644 --- a/app/src/main/java/com/no_name/no_name/LoginActivity.kt +++ b/app/src/main/java/com/no_name/no_name/LoginActivity.kt @@ -15,15 +15,16 @@ import android.os.Build import android.os.Bundle import android.provider.ContactsContract import android.support.design.widget.Snackbar -import android.support.v7.app.AppCompatActivity import android.text.TextUtils import android.view.View import android.view.inputmethod.EditorInfo import android.widget.ArrayAdapter import android.widget.TextView +import com.afollestad.aesthetic.AestheticActivity import com.github.kittinunf.fuel.android.extension.responseJson import com.github.kittinunf.fuel.httpPost import com.madapps.prefrences.EasyPrefrences +import com.no_name.no_name.Util.ThemeUtil import kotlinx.android.synthetic.main.activity_login.* import org.jetbrains.anko.longToast import org.jetbrains.anko.startActivity @@ -33,7 +34,7 @@ import java.util.* /** * A login screen that offers login via email/password. */ -class LoginActivity : AppCompatActivity(), LoaderCallbacks<Cursor> { +class LoginActivity : AestheticActivity(), LoaderCallbacks<Cursor> { /** * Keep track of the login task to ensure we can cancel it if requested. */ @@ -54,6 +55,8 @@ class LoginActivity : AppCompatActivity(), LoaderCallbacks<Cursor> { false }) + (ThemeUtil(this)::setActivityTheme)(true) + email_sign_in_button.setOnClickListener { attemptLogin() } } diff --git a/app/src/main/java/com/no_name/no_name/MainActivity.kt b/app/src/main/java/com/no_name/no_name/MainActivity.kt index b7e61cd..d82630d 100644 --- a/app/src/main/java/com/no_name/no_name/MainActivity.kt +++ b/app/src/main/java/com/no_name/no_name/MainActivity.kt @@ -1,27 +1,29 @@ package com.no_name.no_name import android.os.Bundle -import android.support.v7.app.AppCompatActivity import android.view.Menu import android.view.MenuItem +import com.afollestad.aesthetic.AestheticActivity +import com.no_name.no_name.Util.ThemeUtil import kotlinx.android.synthetic.main.activity_main.* import org.jetbrains.anko.alert import org.jetbrains.anko.longToast +import org.jetbrains.anko.startActivity /** * Main activity aka home screen of app */ -class MainActivity : AppCompatActivity() { +class MainActivity : AestheticActivity() { /** * Set initial configuration */ override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) - setSupportActionBar(toolbar) - val serverDown = intent.getBooleanExtra("serverDown", false) - if (serverDown) { + (ThemeUtil(this)::setActivityTheme)(false) + + if (intent.getBooleanExtra("serverDown", false)) { alert("We are sorry, but our servers do not seem to be working at the moment. Please wait a few minutes before you try again.", "Sorry") { positiveButton("Okay") { finishAffinity() // TODO: Loading activity will somehow still be opened after close @@ -30,16 +32,15 @@ class MainActivity : AppCompatActivity() { }.show() } - val notConnected = intent.getBooleanExtra("notConnected", false) - if (notConnected) { + if (intent.getBooleanExtra("notConnected", false)) longToast("No internet connection!") - } fab.setOnClickListener { view -> - // TODO: Set FAB onclick event + startActivity<SettingsActivity>() } } + /** * Inflate the [menu]; this adds items to the action bar if it is present */ diff --git a/app/src/main/java/com/no_name/no_name/Util/ThemeUtil.kt b/app/src/main/java/com/no_name/no_name/Util/ThemeUtil.kt new file mode 100644 index 0000000..d777281 --- /dev/null +++ b/app/src/main/java/com/no_name/no_name/Util/ThemeUtil.kt @@ -0,0 +1,31 @@ +package com.no_name.no_name.Util + +import android.content.Context +import com.afollestad.aesthetic.Aesthetic +import com.madapps.prefrences.EasyPrefrences +import com.no_name.no_name.R + +class ThemeUtil(context: Context) { + private val sharedPrefs = EasyPrefrences(context) + + private fun isDarkTheme(): Boolean { + val darkTheme: Boolean? = sharedPrefs.getBoolean("dark_theme_switch") + darkTheme?.let { + return darkTheme + } ?: run { + return false + } + } + + fun setActivityTheme(ActionBar: Boolean) { + val theme: Int = if (!ActionBar) { + if (isDarkTheme()) R.style.AppTheme_Dark_NoActionBar else R.style.AppTheme_NoActionBar + } else + if (isDarkTheme()) R.style.AppTheme_Dark else R.style.AppTheme + + Aesthetic.config { + activityTheme(R.style.AppTheme_NoActionBar) + isDark(isDarkTheme()) + } + } +}
\ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index d4ea9ae..f55ac2c 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,8 +1,13 @@ <resources> - <!-- Base application theme. --> - <style name="AppTheme" parent="Theme.AppCompat"> - <!-- Customize your theme here. --> + <!-- Base dark application theme. --> + <style name="AppTheme" parent="Theme.AppCompat.Light"> + <item name="colorPrimary">@color/colorPrimary</item> + <item name="colorPrimaryDark">@color/colorPrimaryDark</item> + <item name="colorAccent">@color/colorAccent</item> + </style> + + <style name="AppTheme.Dark" parent="Theme.AppCompat"> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> @@ -13,6 +18,12 @@ <item name="windowNoTitle">true</item> </style> + <style name="AppTheme.Dark.NoActionBar"> + <item name="windowActionBar">false</item> + <item name="windowNoTitle">true</item> + </style> + + <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> |