Replaced SettingsActivity with SettingsFragmet and created the Navigation methods to hook the Balances' Settings toolbar icon with the Settings fragment so it automatically opens when the icon is tapped.
This commit is contained in:
parent
1565bab28c
commit
5a6b098f38
6 changed files with 72 additions and 75 deletions
|
@ -31,9 +31,6 @@
|
||||||
android:theme="@style/Theme.Bitsy.NoActionBar"
|
android:theme="@style/Theme.Bitsy.NoActionBar"
|
||||||
android:screenOrientation="portrait"
|
android:screenOrientation="portrait"
|
||||||
android:windowSoftInputMode="adjustPan"/>
|
android:windowSoftInputMode="adjustPan"/>
|
||||||
<activity
|
|
||||||
android:name=".activities.SettingsActivity"
|
|
||||||
android:label="@string/title_settings"/>
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
|
@ -1,65 +0,0 @@
|
||||||
package cy.agorise.bitsybitshareswallet.activities
|
|
||||||
|
|
||||||
import android.os.Bundle
|
|
||||||
import android.preference.PreferenceManager
|
|
||||||
import android.view.MenuItem
|
|
||||||
import androidx.appcompat.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
|
|
||||||
*/
|
|
||||||
class SettingsActivity : AppCompatActivity() {
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
|
||||||
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.Theme_Bitsy_Dark)
|
|
||||||
}
|
|
||||||
|
|
||||||
setContentView(R.layout.activity_settings)
|
|
||||||
|
|
||||||
setupActionBar()
|
|
||||||
|
|
||||||
initNightModeSwitch()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set up the [android.app.ActionBar], if the API is available.
|
|
||||||
*/
|
|
||||||
private fun setupActionBar() {
|
|
||||||
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 {
|
|
||||||
if (item.itemId == android.R.id.home) {
|
|
||||||
onBackPressed()
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return super.onOptionsItemSelected(item)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
package cy.agorise.bitsybitshareswallet.fragments
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.preference.PreferenceManager
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import cy.agorise.bitsybitshareswallet.R
|
||||||
|
import cy.agorise.bitsybitshareswallet.utils.Constants
|
||||||
|
import kotlinx.android.synthetic.main.fragment_settings.*
|
||||||
|
|
||||||
|
class SettingsFragment : Fragment() {
|
||||||
|
|
||||||
|
|
||||||
|
override fun onCreateView(
|
||||||
|
inflater: LayoutInflater, container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?
|
||||||
|
): View? {
|
||||||
|
setHasOptionsMenu(true)
|
||||||
|
|
||||||
|
return inflater.inflate(R.layout.fragment_settings, container, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
|
initNightModeSwitch()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun initNightModeSwitch() {
|
||||||
|
val nightModeOn = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
.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
|
||||||
|
// TODO find a way to automatically change the theme
|
||||||
|
// this.recreate()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
android:paddingEnd="@dimen/activity_horizontal_margin"
|
android:paddingEnd="@dimen/activity_horizontal_margin"
|
||||||
android:paddingTop="@dimen/activity_vertical_margin"
|
android:paddingTop="@dimen/activity_vertical_margin"
|
||||||
android:paddingBottom="32dp"
|
android:paddingBottom="32dp"
|
||||||
tools:context=".activities.SettingsActivity">
|
tools:context=".fragments.SettingsFragment">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
|
@ -38,6 +38,12 @@
|
||||||
android:label="@string/title_transactions"
|
android:label="@string/title_transactions"
|
||||||
tools:layout="@layout/fragment_transactions"/>
|
tools:layout="@layout/fragment_transactions"/>
|
||||||
|
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/settings_dest"
|
||||||
|
android:name="cy.agorise.bitsybitshareswallet.fragments.SettingsFragment"
|
||||||
|
android:label="@string/title_settings"
|
||||||
|
tools:layout="@layout/fragment_settings"/>
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/receive_dest"
|
android:id="@+id/receive_dest"
|
||||||
android:name="cy.agorise.bitsybitshareswallet.fragments.ReceiveTransactionFragment"
|
android:name="cy.agorise.bitsybitshareswallet.fragments.ReceiveTransactionFragment"
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue