diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 89d6d1b3a7b65de4f69b985848b44351972888d0..9f16894aff3da95a5e16f7bd8d29a68910e37f92 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -12,7 +12,7 @@ android:fullBackupContent="false" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" - android:theme="@style/AppTheme"> + android:theme="@style/DarkTheme"> + val newTheme = when (resources.getStringArray(R.array.themes)[position]) { + resources.getString(R.string.dark_theme) -> R.style.DarkTheme + resources.getString(R.string.light_theme) -> R.style.LightTheme + else -> throw IllegalArgumentException("This theme does not exist") + } + + Prefs.theme = newTheme + finish() + startActivity(Intent(this, this::class.java)) + } + .create() + .show() } - fun bindPrefs() { + private fun bindPrefs() { switchRequireAuth.isChecked = Prefs.isRequiredDeviceAuth } } diff --git a/app/src/main/java/com/commit451/gitlab/data/Prefs.kt b/app/src/main/java/com/commit451/gitlab/data/Prefs.kt index 686fc41597694033c71372d84eddab6a6600996e..55d6de72b3bcdda2b8b3059d9db80acc5203d283 100644 --- a/app/src/main/java/com/commit451/gitlab/data/Prefs.kt +++ b/app/src/main/java/com/commit451/gitlab/data/Prefs.kt @@ -5,15 +5,13 @@ import android.content.Context import android.content.SharedPreferences import android.preference.PreferenceManager import android.support.annotation.IntDef +import android.support.annotation.StyleRes +import com.commit451.gitlab.R import com.commit451.gitlab.api.MoshiProvider import com.commit451.gitlab.model.Account -import java.io.IOException -import java.util.* -import com.squareup.moshi.Moshi -import com.squareup.moshi.JsonAdapter -import com.squareup.moshi.Types.newParameterizedType import com.squareup.moshi.Types import timber.log.Timber +import java.io.IOException /** @@ -24,6 +22,7 @@ object Prefs { private const val KEY_ACCOUNTS = "accounts" private const val KEY_STARTING_VIEW = "starting_view" private const val KEY_REQUIRE_DEVICE_AUTH = "require_device_auth" + private const val KEY_THEME_ID = "theme_id" const val STARTING_VIEW_PROJECTS = 0 const val STARTING_VIEW_GROUPS = 1 @@ -106,4 +105,10 @@ object Prefs { set(value) = prefs.edit() .putBoolean(KEY_REQUIRE_DEVICE_AUTH, value) .apply() + + var theme: Int + @StyleRes get() = prefs.getInt(KEY_THEME_ID, R.style.DarkTheme) + set(@StyleRes value) = prefs.edit() + .putInt(KEY_THEME_ID, value) + .apply() } diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index f4b15d2d5ec594b5362c389e1abf4eb78ec154ec..57459466687bdfe03373b88f4356bc9b48d6748b 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -1,9 +1,9 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent"> + android:background="?attr/colorPrimary"/> @@ -31,7 +31,7 @@ + android:text="@string/setting_require_device_auth"/> + android:textColor="@color/white_60"/> @@ -66,7 +66,42 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:layout_marginLeft="8dp" /> + android:layout_marginLeft="8dp"/> + + + + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4014f2b34b58c161917de40db878728ef9a400de..5739ceeffa2423d067c183c1608b6e7291150c0f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -530,4 +530,11 @@ Welcome to LabCoat We support GitLab.com, as well as any GitLab server running GitLab version 9.0 or later + Theme + + + Light + Dark + Choose a theme + \ 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 dceedd0870d094425243e4a721a35a226a51b0c1..74931e8893ce338f14e478f12711bdc165844006 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -2,7 +2,7 @@ - - + +