Browse Source

Cleaning up settings

master
anthony restaino 8 years ago
parent
commit
7521415e94
  1. 12
      app/src/main/java/acr/browser/lightning/settings/activity/SettingsActivity.java
  2. 14
      app/src/main/java/acr/browser/lightning/settings/fragment/AboutSettingsFragment.java

12
app/src/main/java/acr/browser/lightning/settings/activity/SettingsActivity.java

@ -23,12 +23,12 @@ import acr.browser.lightning.BrowserApp;
public class SettingsActivity extends ThemableSettingsActivity { public class SettingsActivity extends ThemableSettingsActivity {
@NonNull private static final List<String> mFragments = new ArrayList<>(7); @NonNull private static final List<String> sFragments = new ArrayList<>(7);
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
// this is a workaround for the Toolbar in PreferenceActitivty // this is a workaround for the Toolbar in PreferenceActivity
ViewGroup root = findViewById(android.R.id.content); ViewGroup root = findViewById(android.R.id.content);
LinearLayout content = (LinearLayout) root.getChildAt(0); LinearLayout content = (LinearLayout) root.getChildAt(0);
LinearLayout toolbarContainer = (LinearLayout) View.inflate(this, R.layout.toolbar_settings, null); LinearLayout toolbarContainer = (LinearLayout) View.inflate(this, R.layout.toolbar_settings, null);
@ -46,7 +46,7 @@ public class SettingsActivity extends ThemableSettingsActivity {
@Override @Override
public void onBuildHeaders(List<Header> target) { public void onBuildHeaders(List<Header> target) {
loadHeadersFromResource(R.xml.preferences_headers, target); loadHeadersFromResource(R.xml.preferences_headers, target);
mFragments.clear(); sFragments.clear();
Iterator<Header> headerIterator = target.iterator(); Iterator<Header> headerIterator = target.iterator();
while (headerIterator.hasNext()) { while (headerIterator.hasNext()) {
Header header = headerIterator.next(); Header header = headerIterator.next();
@ -59,17 +59,17 @@ public class SettingsActivity extends ThemableSettingsActivity {
if (BrowserApp.isRelease()) { if (BrowserApp.isRelease()) {
headerIterator.remove(); headerIterator.remove();
} else { } else {
mFragments.add(header.fragment); sFragments.add(header.fragment);
} }
} else { } else {
mFragments.add(header.fragment); sFragments.add(header.fragment);
} }
} }
} }
@Override @Override
protected boolean isValidFragment(String fragmentName) { protected boolean isValidFragment(String fragmentName) {
return mFragments.contains(fragmentName); return sFragments.contains(fragmentName);
} }
@Override @Override

14
app/src/main/java/acr/browser/lightning/settings/fragment/AboutSettingsFragment.java

@ -9,13 +9,13 @@ import android.content.pm.PackageManager;
import android.os.Bundle; import android.os.Bundle;
import android.preference.Preference; import android.preference.Preference;
import android.preference.PreferenceFragment; import android.preference.PreferenceFragment;
import android.util.Log;
import acr.browser.lightning.R; import acr.browser.lightning.R;
public class AboutSettingsFragment extends PreferenceFragment { public class AboutSettingsFragment extends PreferenceFragment {
private Activity mActivity; private static final String TAG = "AboutSettingsFragment";
private static final String SETTINGS_VERSION = "pref_version"; private static final String SETTINGS_VERSION = "pref_version";
@Override @Override
@ -24,18 +24,18 @@ public class AboutSettingsFragment extends PreferenceFragment {
// Load the preferences from an XML resource // Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preference_about); addPreferencesFromResource(R.xml.preference_about);
mActivity = getActivity();
Preference version = findPreference(SETTINGS_VERSION); Preference version = findPreference(SETTINGS_VERSION);
version.setSummary(getVersion()); version.setSummary(getVersion());
} }
private String getVersion() { private String getVersion() {
try { try {
PackageInfo p = mActivity.getPackageManager().getPackageInfo(mActivity.getPackageName(), 0); Activity activity = getActivity();
return p.versionName; String packageName = activity.getPackageName();
PackageInfo packageInfo = activity.getPackageManager().getPackageInfo(packageName, 0);
return packageInfo.versionName;
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
e.printStackTrace(); Log.e(TAG, "getVersion: error", e);
return "1.0"; return "1.0";
} }
} }

Loading…
Cancel
Save