diff options
Diffstat (limited to 'app/src/main/java')
-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 |
3 files changed, 46 insertions, 11 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 |