diff options
-rw-r--r-- | app/build.gradle | 4 | ||||
-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 |
5 files changed, 64 insertions, 14 deletions
diff --git a/app/build.gradle b/app/build.gradle index 186aadc..999fee0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,6 +13,7 @@ android { versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + vectorDrawables.useSupportLibrary = true } buildTypes { release { @@ -26,6 +27,7 @@ dependencies { implementation 'com.github.mukeshsolanki:easypreferences:1.0.6' implementation 'com.kazakago.cryptore:cryptore:1.3.0' implementation 'com.github.kittinunf.fuel:fuel-android:1.6.0' + implementation 'com.afollestad:aesthetic:0.5.3' implementation fileTree(dir: 'libs', include: ['*.jar']) implementation "org.jetbrains.anko:anko-commons:0.10.5" implementation "org.jetbrains.anko:anko-design:0.10.5" @@ -34,6 +36,8 @@ dependencies { implementation 'com.android.support.constraint:constraint-layout:1.1.2' implementation 'com.android.support:design:28.0.0-alpha1' implementation 'com.android.support:support-annotations:28.0.0-rc01' + implementation 'com.android.support:support-v4:28.0.0-rc01' + implementation 'com.android.support:support-vector-drawable:28.0.0-rc01' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 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" /> |