aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/src/main/java/com/no_name
diff options
context:
space:
mode:
authorMarvin Borner2018-08-29 23:38:36 +0200
committerMarvin Borner2018-08-29 23:38:36 +0200
commitf88688213a7777fdb0361c9ddad36b490b90adfe (patch)
tree5ec681c7fbd214c418f5291c02d863352b29e287 /app/src/main/java/com/no_name
parent35f01b107d206f237763b10ebd6d5c25c71d5610 (diff)
Finished theme switcher (better library)
Diffstat (limited to 'app/src/main/java/com/no_name')
-rw-r--r--app/src/main/java/com/no_name/no_name/Application.kt16
-rw-r--r--app/src/main/java/com/no_name/no_name/LoginActivity.kt13
-rw-r--r--app/src/main/java/com/no_name/no_name/MainActivity.kt13
-rw-r--r--app/src/main/java/com/no_name/no_name/RoutingActivity.kt17
-rw-r--r--app/src/main/java/com/no_name/no_name/SettingsActivity.kt31
-rw-r--r--app/src/main/java/com/no_name/no_name/util/ThemeUtil.kt34
6 files changed, 93 insertions, 31 deletions
diff --git a/app/src/main/java/com/no_name/no_name/Application.kt b/app/src/main/java/com/no_name/no_name/Application.kt
new file mode 100644
index 0000000..441a728
--- /dev/null
+++ b/app/src/main/java/com/no_name/no_name/Application.kt
@@ -0,0 +1,16 @@
+package com.no_name.no_name
+
+import android.app.Application
+import daio.io.dresscode.DressCode
+import daio.io.dresscode.declareDressCode
+
+class Application : Application() {
+
+ override fun onCreate() {
+ super.onCreate()
+
+ declareDressCode(this,
+ DressCode("dark", R.style.AppTheme_Dark),
+ DressCode("light", R.style.AppTheme))
+ }
+} \ No newline at end of file
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 9443e9c..861e425 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,16 +15,18 @@ 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 com.no_name.no_name.util.ThemeUtil.getThemeName
+import daio.io.dresscode.dressCodeName
+import daio.io.dresscode.matchDressCode
import kotlinx.android.synthetic.main.activity_login.*
import org.jetbrains.anko.longToast
import org.jetbrains.anko.startActivity
@@ -34,7 +36,7 @@ import java.util.*
/**
* A login screen that offers login via email/password.
*/
-class LoginActivity : AestheticActivity(), LoaderCallbacks<Cursor> {
+class LoginActivity : AppCompatActivity(), LoaderCallbacks<Cursor> {
/**
* Keep track of the login task to ensure we can cancel it if requested.
*/
@@ -44,8 +46,11 @@ class LoginActivity : AestheticActivity(), LoaderCallbacks<Cursor> {
* Set up the login form and initial configuration
*/
override fun onCreate(savedInstanceState: Bundle?) {
+ matchDressCode()
super.onCreate(savedInstanceState)
+ dressCodeName = getThemeName(this)
setContentView(R.layout.activity_login)
+
populateAutoComplete()
password.setOnEditorActionListener(TextView.OnEditorActionListener { _, id, _ ->
if (id == EditorInfo.IME_ACTION_DONE || id == EditorInfo.IME_NULL) {
@@ -55,8 +60,6 @@ class LoginActivity : AestheticActivity(), 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 d82630d..299f5eb 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,10 +1,12 @@
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 com.no_name.no_name.util.ThemeUtil.getThemeName
+import daio.io.dresscode.dressCodeName
+import daio.io.dresscode.matchDressCode
import kotlinx.android.synthetic.main.activity_main.*
import org.jetbrains.anko.alert
import org.jetbrains.anko.longToast
@@ -13,15 +15,16 @@ import org.jetbrains.anko.startActivity
/**
* Main activity aka home screen of app
*/
-class MainActivity : AestheticActivity() {
+class MainActivity : AppCompatActivity() {
/**
* Set initial configuration
*/
override fun onCreate(savedInstanceState: Bundle?) {
+ matchDressCode()
super.onCreate(savedInstanceState)
+ dressCodeName = getThemeName(this)
setContentView(R.layout.activity_main)
-
- (ThemeUtil(this)::setActivityTheme)(false)
+ setSupportActionBar(toolbar)
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") {
diff --git a/app/src/main/java/com/no_name/no_name/RoutingActivity.kt b/app/src/main/java/com/no_name/no_name/RoutingActivity.kt
index efb3789..22c2813 100644
--- a/app/src/main/java/com/no_name/no_name/RoutingActivity.kt
+++ b/app/src/main/java/com/no_name/no_name/RoutingActivity.kt
@@ -1,12 +1,14 @@
package com.no_name.no_name
import android.os.Bundle
-import com.afollestad.aesthetic.AestheticActivity
+import android.support.v7.app.AppCompatActivity
import com.github.kittinunf.fuel.android.extension.responseJson
import com.github.kittinunf.fuel.core.FuelManager
import com.github.kittinunf.fuel.httpGet
import com.madapps.prefrences.EasyPrefrences
-import com.no_name.no_name.Util.ThemeUtil
+import com.no_name.no_name.util.ThemeUtil.getThemeName
+import daio.io.dresscode.dressCodeName
+import daio.io.dresscode.matchDressCode
import org.jetbrains.anko.alert
import org.jetbrains.anko.startActivity
import java.io.IOException
@@ -15,18 +17,19 @@ import java.io.IOException
* Activity which will be run before any other to verify user and choose which activity
* should be started next
*/
-class RoutingActivity : AestheticActivity() {
- private val server_address = "192.168.0.102"
+class RoutingActivity : AppCompatActivity() {
+ private val serverAddress = "192.168.0.102"
override fun onCreate(savedInstanceState: Bundle?) {
+ matchDressCode()
super.onCreate(savedInstanceState)
- FuelManager.instance.basePath = "http://$server_address"
+ dressCodeName = getThemeName(this)
+
+ FuelManager.instance.basePath = "http://$serverAddress"
alert("Logging you in.", "Loading...") {
isCancelable = false
}.show()
verifyLogin()
-
- (ThemeUtil(this)::setActivityTheme)(true)
}
@Throws(InterruptedException::class, IOException::class)
diff --git a/app/src/main/java/com/no_name/no_name/SettingsActivity.kt b/app/src/main/java/com/no_name/no_name/SettingsActivity.kt
index 11214d5..e4a9f74 100644
--- a/app/src/main/java/com/no_name/no_name/SettingsActivity.kt
+++ b/app/src/main/java/com/no_name/no_name/SettingsActivity.kt
@@ -9,8 +9,9 @@ import android.os.Bundle
import android.preference.*
import android.support.v4.app.NavUtils
import android.view.MenuItem
-import com.afollestad.aesthetic.Aesthetic
-import com.no_name.no_name.Util.ThemeUtil
+import com.no_name.no_name.util.ThemeUtil.getThemeName
+import daio.io.dresscode.dressCodeName
+import daio.io.dresscode.matchDressCode
/**
* A [PreferenceActivity] that presents a set of application settings. On
@@ -25,20 +26,10 @@ import com.no_name.no_name.Util.ThemeUtil
class SettingsActivity : PreferenceActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
- Aesthetic.attach(this)
+ matchDressCode()
super.onCreate(savedInstanceState)
+ dressCodeName = getThemeName(this)
setupActionBar()
- (ThemeUtil(this)::setActivityTheme)(true)
- }
-
- override fun onResume() {
- super.onResume()
- Aesthetic.resume(this)
- }
-
- override fun onPause() {
- Aesthetic.pause(this)
- super.onPause()
}
/**
@@ -48,6 +39,10 @@ class SettingsActivity : PreferenceActivity() {
actionBar?.setDisplayHomeAsUpEnabled(true)
}
+ fun updateTheme() {
+ dressCodeName = getThemeName(this)
+ }
+
/**
* Listener for menu item selector
*/
@@ -99,6 +94,14 @@ class SettingsActivity : PreferenceActivity() {
setHasOptionsMenu(true)
}
+ override fun onPreferenceTreeClick(preferenceScreen: PreferenceScreen?, preference: Preference?): Boolean {
+ if (preference?.key == "dark_theme_switch") {
+ (activity as SettingsActivity).updateTheme()
+ return true
+ }
+ return true
+ }
+
/**
* Listener for action bar option selector
*/
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..5125f12
--- /dev/null
+++ b/app/src/main/java/com/no_name/no_name/util/ThemeUtil.kt
@@ -0,0 +1,34 @@
+package com.no_name.no_name.util
+
+import android.content.Context
+import com.madapps.prefrences.EasyPrefrences
+import com.no_name.no_name.util.ThemeUtil.isDarkTheme
+
+/**
+ * Get the name of the theme depending on [actionBar] and [isDarkTheme]
+ */
+object ThemeUtil {
+ /**
+ * Checks if the theme saved in sharedPreferences is dark/light
+ */
+ private fun isDarkTheme(context: Context): Boolean {
+ val sharedPrefs = EasyPrefrences(context)
+ val darkTheme: Boolean? = sharedPrefs.getBoolean("dark_theme_switch")
+ darkTheme?.let {
+ return darkTheme
+ } ?: run {
+ return false
+ }
+ }
+
+ /**
+ * Get the name of the theme depending on [actionBar] and [isDarkTheme]
+ */
+ fun getThemeName(context: Context): String {
+ return if (isDarkTheme(context)) {
+ "dark"
+ } else {
+ "light"
+ }
+ }
+} \ No newline at end of file