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

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

View File

@ -40,8 +40,7 @@ class SettingsFragment : Fragment() {
.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()
activity?.recreate()
}
}
}

View File

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