Add methods to automatically change the theme to night mode when the user selects it and also avoid a crash in the TransfersLoader.

This commit is contained in:
Severiano Jaramillo 2018-12-13 13:10:19 -06:00
parent ffebc39bcf
commit e1c32eb7f8
3 changed files with 9 additions and 3 deletions

View file

@ -2,6 +2,7 @@ package cy.agorise.bitsybitshareswallet.activities
import android.content.res.Resources import android.content.res.Resources
import android.os.Bundle import android.os.Bundle
import android.preference.PreferenceManager
import android.view.MenuItem import android.view.MenuItem
import androidx.navigation.findNavController import androidx.navigation.findNavController
import androidx.navigation.fragment.NavHostFragment import androidx.navigation.fragment.NavHostFragment
@ -10,6 +11,7 @@ import androidx.navigation.ui.navigateUp
import androidx.navigation.ui.onNavDestinationSelected import androidx.navigation.ui.onNavDestinationSelected
import androidx.navigation.ui.setupActionBarWithNavController import androidx.navigation.ui.setupActionBarWithNavController
import cy.agorise.bitsybitshareswallet.R import cy.agorise.bitsybitshareswallet.R
import cy.agorise.bitsybitshareswallet.utils.Constants
import cy.agorise.graphenej.api.ConnectionStatusUpdate import cy.agorise.graphenej.api.ConnectionStatusUpdate
import cy.agorise.graphenej.models.JsonRpcResponse import cy.agorise.graphenej.models.JsonRpcResponse
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
@ -21,6 +23,11 @@ class MainActivity : ConnectedActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
// 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_NoActionBar)
}
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
setSupportActionBar(toolbar) setSupportActionBar(toolbar)

View file

@ -40,8 +40,7 @@ class SettingsFragment : Fragment() {
.putBoolean(Constants.KEY_NIGHT_MODE_ACTIVATED, isChecked).apply() .putBoolean(Constants.KEY_NIGHT_MODE_ACTIVATED, isChecked).apply()
// Recreates the activity to apply the selected theme // Recreates the activity to apply the selected theme
// TODO find a way to automatically change the theme activity?.recreate()
// this.recreate()
} }
} }
} }

View file

@ -155,7 +155,7 @@ class TransfersLoader(private var mContext: Context?): ServiceConnection {
} }
override fun onServiceDisconnected(name: ComponentName?) { override fun onServiceDisconnected(name: ComponentName?) {
mShouldUnbindNetwork = false
} }
override fun onServiceConnected(name: ComponentName?, service: IBinder?) { override fun onServiceConnected(name: ComponentName?, service: IBinder?) {