Move theme checkbox to settings activity

This commit is contained in:
Neslihan 2017-03-18 01:49:19 +03:00
parent c7909b4f66
commit 7e256175dc
23 changed files with 118 additions and 121 deletions

View file

@ -0,0 +1,39 @@
package fr.free.nrw.commons.theme;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import fr.free.nrw.commons.R;
public class BaseActivity extends Activity {
boolean currentTheme;
@Override
protected void onCreate(Bundle savedInstanceState) {
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("theme",false)) {
currentTheme = true;
setTheme(R.style.DarkAppTheme);
}else {
currentTheme = false;
setTheme(R.style.LightAppTheme); //default
}
super.onCreate(savedInstanceState);
}
@Override
protected void onResume() {
//Restart activity if theme is changed
Log.d("deneme","onResume Base");
boolean newTheme = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("theme",false);
if(currentTheme!=newTheme){ //is activity theme changed
Intent intent = getIntent();
finish();
startActivity(intent);
}
super.onResume();
}
}

View file

@ -0,0 +1,38 @@
package fr.free.nrw.commons.theme;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import fr.free.nrw.commons.R;
public class BaseAppCompatActivity extends AppCompatActivity {
boolean currentTheme;
@Override
protected void onCreate(Bundle savedInstanceState) {
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("theme",false)) {
currentTheme = true;g
setTheme(R.style.DarkAppTheme);
}else {
currentTheme = false;
setTheme(R.style.LightAppTheme); //default
}
super.onCreate(savedInstanceState);
}
@Override
protected void onResume() {
//Restart activity if theme is changed
Log.d("deneme","onResume Base");
boolean newTheme = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("theme",false);
if(currentTheme!=newTheme){ //is activity theme changed
Intent intent = getIntent();
finish();
startActivity(intent);
}
super.onResume();
}
}