conversations-classic/src/main/java/eu/siacs/conversations/ui/SettingsFragment.java

65 lines
1.9 KiB
Java
Raw Normal View History

2014-10-22 16:38:44 +00:00
package eu.siacs.conversations.ui;
import android.content.Intent;
2014-10-22 16:38:44 +00:00
import android.os.Bundle;
2014-12-03 11:33:32 +00:00
import android.preference.Preference;
import android.preference.PreferenceCategory;
2014-10-22 16:38:44 +00:00
import android.preference.PreferenceFragment;
2014-12-03 11:33:32 +00:00
import android.preference.PreferenceScreen;
import android.text.TextUtils;
2014-12-03 11:33:32 +00:00
import eu.siacs.conversations.Config;
2014-12-03 11:33:32 +00:00
import eu.siacs.conversations.R;
2014-10-22 16:38:44 +00:00
public class SettingsFragment extends PreferenceFragment {
2014-12-03 11:33:32 +00:00
private String page = null;
2014-12-03 11:33:32 +00:00
2014-10-22 16:38:44 +00:00
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
2018-02-16 21:20:14 +00:00
// Remove from standard preferences if the flag ONLY_INTERNAL_STORAGE is false
if (!Config.ONLY_INTERNAL_STORAGE) {
PreferenceCategory mCategory = (PreferenceCategory) findPreference("security_options");
if (mCategory != null) {
Preference cleanCache = findPreference("clean_cache");
Preference cleanPrivateStorage = findPreference("clean_private_storage");
mCategory.removePreference(cleanCache);
mCategory.removePreference(cleanPrivateStorage);
}
}
if (!TextUtils.isEmpty(page)) {
openPreferenceScreen(page);
}
2014-10-22 16:38:44 +00:00
}
2014-12-03 11:33:32 +00:00
public void setActivityIntent(final Intent intent) {
boolean wasEmpty = TextUtils.isEmpty(page);
if (intent != null) {
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
if (intent.getExtras() != null) {
this.page = intent.getExtras().getString("page");
if (wasEmpty) {
openPreferenceScreen(page);
}
}
}
}
}
private void openPreferenceScreen(final String screenName) {
final Preference pref = findPreference(screenName);
if (pref instanceof PreferenceScreen) {
final PreferenceScreen preferenceScreen = (PreferenceScreen) pref;
getActivity().setTitle(preferenceScreen.getTitle());
preferenceScreen.setDependency("");
setPreferenceScreen((PreferenceScreen) pref);
2014-12-03 11:33:32 +00:00
}
}
2014-10-22 16:38:44 +00:00
}