Remove duplicate classes, move back theme preference

Also fix prefs to match arrays to remove spinner bug in SingleUploadFragment
This commit is contained in:
Adam Jones 2017-04-02 16:36:14 +01:00
parent 0fe7a05731
commit 2ab5fa7ff6
5 changed files with 11 additions and 187 deletions

View file

@ -1,16 +0,0 @@
package fr.free.nrw.commons;
public class Prefs {
public static String GLOBAL_PREFS = "fr.free.nrw.commons.preferences";
public static String TRACKING_ENABLED = "eventLogging";
public static final String DEFAULT_LICENSE = "defaultLicense";
public static class Licenses {
public static final String CC_BY_SA_3 = "CC BY-SA";
public static final String CC_BY_3 = "CC BY";
public static final String CC_BY_SA_4 = "CC BY-SA 4.0";
public static final String CC_BY_4 = "CC BY 4.0";
public static final String CC0 = "CC0";
}
}

View file

@ -1,161 +0,0 @@
package fr.free.nrw.commons;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.support.annotation.LayoutRes;
import android.support.v7.app.AppCompatDelegate;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
public class SettingsActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
CommonsApplication app;
private AppCompatDelegate mDelegate;
@Override
protected void onCreate(Bundle savedInstanceState) {
getDelegate().installViewFactory();
getDelegate().onCreate(savedInstanceState);
// Check prefs on every activity starts
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("theme",true)) {
setTheme(R.style.DarkAppTheme);
}else {
setTheme(R.style.LightAppTheme); // default
}
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
ListPreference licensePreference = (ListPreference) findPreference(Prefs.DEFAULT_LICENSE);
// WARNING: ORDERING NEEDS TO MATCH FOR THE LICENSE NAMES AND DISPLAY VALUES
licensePreference.setEntries(new String[]{
getString(R.string.license_name_cc0),
getString(R.string.license_name_cc_by),
getString(R.string.license_name_cc_by_four),
getString(R.string.license_name_cc_by_sa),
getString(R.string.license_name_cc_by_sa_four)
});
licensePreference.setEntryValues(new String[]{
Prefs.Licenses.CC0,
Prefs.Licenses.CC_BY_3,
Prefs.Licenses.CC_BY_4,
Prefs.Licenses.CC_BY_SA_3,
Prefs.Licenses.CC_BY_SA_4
});
licensePreference.setSummary(getString(Utils.licenseNameFor(licensePreference.getValue())));
licensePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
preference.setSummary(getString(Utils.licenseNameFor((String)newValue)));
return true;
}
});
app = (CommonsApplication)getApplicationContext();
}
@Override
protected void onResume() {
super.onResume();
getPreferenceScreen().getSharedPreferences()
.registerOnSharedPreferenceChangeListener(this);
}
@Override
protected void onPause() {
super.onPause();
getPreferenceScreen().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(this);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if(key.equals("theme")){
// Finish current activity and start new one with selected theme
Intent intent = getIntent();
finish();
startActivity(intent);
}
}
// All the stuff below is just to get a actionbar that says settings...
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
getDelegate().onPostCreate(savedInstanceState);
}
@Override
public MenuInflater getMenuInflater() {
return getDelegate().getMenuInflater();
}
@Override
public void setContentView(@LayoutRes int layoutResID) {
getDelegate().setContentView(layoutResID);
}
@Override
public void setContentView(View view) {
getDelegate().setContentView(view);
}
@Override
public void setContentView(View view, ViewGroup.LayoutParams params) {
getDelegate().setContentView(view, params);
}
@Override
public void addContentView(View view, ViewGroup.LayoutParams params) {
getDelegate().addContentView(view, params);
}
@Override
protected void onPostResume() {
super.onPostResume();
getDelegate().onPostResume();
}
@Override
protected void onTitleChanged(CharSequence title, int color) {
super.onTitleChanged(title, color);
getDelegate().setTitle(title);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
getDelegate().onConfigurationChanged(newConfig);
}
@Override
protected void onStop() {
super.onStop();
getDelegate().onStop();
}
@Override
protected void onDestroy() {
super.onDestroy();
getDelegate().onDestroy();
}
@Override
public void invalidateOptionsMenu() {
getDelegate().invalidateOptionsMenu();
}
private AppCompatDelegate getDelegate() {
if (mDelegate == null) {
mDelegate = AppCompatDelegate.create(this, null);
}
return mDelegate;
}
}

View file

@ -7,8 +7,8 @@ public class Prefs {
public static final String DEFAULT_LICENSE = "defaultLicense";
public static class Licenses {
public static final String CC_BY_SA_3 = "CC BY-SA";
public static final String CC_BY_3 = "CC BY";
public static final String CC_BY_SA_3 = "CC BY-SA 3.0";
public static final String CC_BY_3 = "CC BY 3.0";
public static final String CC_BY_SA_4 = "CC BY-SA 4.0";
public static final String CC_BY_4 = "CC BY 4.0";
public static final String CC0 = "CC0";

View file

@ -19,11 +19,11 @@ public class SettingsFragment extends PreferenceFragment {
// Update spinner to show selected value as summary
ListPreference licensePreference = (ListPreference) findPreference(Prefs.DEFAULT_LICENSE);
licensePreference.setSummary(Utils.licenseNameFor(licensePreference.getValue()));
licensePreference.setSummary(getString(Utils.licenseNameFor(licensePreference.getValue())));
licensePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
preference.setSummary(Utils.licenseNameFor((String) newValue));
preference.setSummary(getString(Utils.licenseNameFor((String) newValue)));
return true;
}
});

View file

@ -18,16 +18,17 @@
android:summary="@string/allow_gps_summary"
/>
<CheckBoxPreference
android:title="@string/preference_theme"
android:defaultValue="true"
android:summary="@string/preference_theme_summary"
android:key="theme" />
<Preference android:title="@string/become_a_tester_title"
android:summary="@string/become_a_tester_description">
<intent android:action="android.intent.action.VIEW"
android:data="@string/beta_opt_in_link" />
</Preference>
<CheckBoxPreference
android:title="@string/preference_theme"
android:defaultValue="true"
android:summary="@string/preference_theme_summary"
android:key="theme"
/>
</PreferenceScreen>