Merge branch 'master' of https://github.com/Agorise/bitsy-wallet
This commit is contained in:
commit
30e1be54d2
5 changed files with 82 additions and 2 deletions
|
@ -1,8 +1,12 @@
|
||||||
package cy.agorise.bitsybitshareswallet.activities
|
package cy.agorise.bitsybitshareswallet.activities
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.preference.PreferenceManager
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.support.v7.app.AppCompatActivity
|
import android.support.v7.app.AppCompatActivity
|
||||||
|
import cy.agorise.bitsybitshareswallet.R
|
||||||
|
import cy.agorise.bitsybitshareswallet.utils.Constants
|
||||||
|
import kotlinx.android.synthetic.main.activity_settings.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple activity for the user to select his preferences
|
* A simple activity for the user to select his preferences
|
||||||
|
@ -11,7 +15,20 @@ class SettingsActivity : AppCompatActivity() {
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
// TODO move the below to a BaseActivity to apply it to all activities
|
||||||
|
// Sets the theme to night mode if it has been selected by the user
|
||||||
|
if (PreferenceManager.getDefaultSharedPreferences(this)
|
||||||
|
.getBoolean(Constants.KEY_NIGHT_MODE_ACTIVATED, false)
|
||||||
|
) {
|
||||||
|
setTheme(R.style.AppTheme_Dark)
|
||||||
|
}
|
||||||
|
|
||||||
|
setContentView(R.layout.activity_settings)
|
||||||
|
|
||||||
setupActionBar()
|
setupActionBar()
|
||||||
|
|
||||||
|
initNightModeSwitch()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,6 +38,22 @@ class SettingsActivity : AppCompatActivity() {
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun initNightModeSwitch() {
|
||||||
|
val nightModeOn = PreferenceManager.getDefaultSharedPreferences(this)
|
||||||
|
.getBoolean(Constants.KEY_NIGHT_MODE_ACTIVATED, false)
|
||||||
|
|
||||||
|
switchNightMode.isChecked = nightModeOn
|
||||||
|
|
||||||
|
switchNightMode.setOnCheckedChangeListener { buttonView, isChecked ->
|
||||||
|
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(buttonView.context).edit()
|
||||||
|
.putBoolean(Constants.KEY_NIGHT_MODE_ACTIVATED, isChecked).apply()
|
||||||
|
|
||||||
|
// Recreates the activity to apply the selected theme
|
||||||
|
this.recreate()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
if (item.itemId == android.R.id.home) {
|
if (item.itemId == android.R.id.home) {
|
||||||
onBackPressed()
|
onBackPressed()
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
package cy.agorise.bitsybitshareswallet.utils;
|
||||||
|
|
||||||
|
public class Constants {
|
||||||
|
/**
|
||||||
|
* Key used to store the night mode setting into the shared preferences
|
||||||
|
*/
|
||||||
|
public static final String KEY_NIGHT_MODE_ACTIVATED = "key_night_mode_activated";
|
||||||
|
}
|
22
app/src/main/res/layout/activity_settings.xml
Normal file
22
app/src/main/res/layout/activity_settings.xml
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingStart="@dimen/activity_horizontal_margin"
|
||||||
|
android:paddingEnd="@dimen/activity_horizontal_margin"
|
||||||
|
android:paddingTop="@dimen/activity_vertical_margin"
|
||||||
|
android:paddingBottom="32dp"
|
||||||
|
tools:context=".activities.SettingsActivity">
|
||||||
|
|
||||||
|
<Switch
|
||||||
|
android:id="@+id/switchNightMode"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/night_mode"
|
||||||
|
android:textAppearance="@style/TextAppearance.Body1"
|
||||||
|
android:textColor="?android:textColorPrimary"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
|
@ -8,4 +8,5 @@
|
||||||
|
|
||||||
<!-- Settings -->
|
<!-- Settings -->
|
||||||
<string name="title_settings">Settings</string>
|
<string name="title_settings">Settings</string>
|
||||||
|
<string name="night_mode">Night mode</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<!-- Base application theme. -->
|
<!-- Base application light theme. -->
|
||||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||||
<!-- Customize your theme here. -->
|
<!-- Customize your theme here. -->
|
||||||
<item name="colorPrimary">@color/colorPrimary</item>
|
<item name="colorPrimary">@color/colorPrimary</item>
|
||||||
|
@ -12,6 +12,22 @@
|
||||||
<item name="windowNoTitle">true</item>
|
<item name="windowNoTitle">true</item>
|
||||||
</style>
|
</style>
|
||||||
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
|
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
|
||||||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
|
|
||||||
|
|
||||||
|
<!-- Base application dark theme. -->
|
||||||
|
<style name="AppTheme.Dark" parent="Theme.AppCompat">
|
||||||
|
<!-- Customize your theme here. -->
|
||||||
|
<item name="colorPrimary">@color/colorPrimary</item>
|
||||||
|
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||||
|
<item name="colorAccent">@color/colorAccent</item>
|
||||||
|
</style>
|
||||||
|
<style name="AppTheme.Dark.NoActionBar">
|
||||||
|
<item name="windowActionBar">false</item>
|
||||||
|
<item name="windowNoTitle">true</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<!-- Text styles -->
|
||||||
|
<style name="TextAppearance.Body1" parent="TextAppearance.AppCompat.Body1" >
|
||||||
|
<item name="android:textSize">16sp</item>
|
||||||
|
</style>
|
||||||
|
<style name="TextAppearance.Body2" parent="Base.TextAppearance.AppCompat.Body2" />
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue