1package eu.siacs.conversations.ui;
2
3import android.content.Intent;
4import android.os.Bundle;
5import android.preference.Preference;
6import android.preference.PreferenceCategory;
7import android.preference.PreferenceFragment;
8import android.preference.PreferenceScreen;
9import android.text.TextUtils;
10import android.widget.ListView;
11
12import eu.siacs.conversations.Config;
13import eu.siacs.conversations.R;
14
15public class SettingsFragment extends PreferenceFragment {
16
17 private String page = null;
18
19 @Override
20 public void onCreate(Bundle savedInstanceState) {
21 super.onCreate(savedInstanceState);
22
23 addPreferencesFromResource(R.xml.preferences);
24
25 // Remove from standard preferences if the flag ONLY_INTERNAL_STORAGE is false
26 if (!Config.ONLY_INTERNAL_STORAGE) {
27 PreferenceCategory mCategory = (PreferenceCategory) findPreference("security_options");
28 if (mCategory != null) {
29 Preference cleanCache = findPreference("clean_cache");
30 Preference cleanPrivateStorage = findPreference("clean_private_storage");
31 mCategory.removePreference(cleanCache);
32 mCategory.removePreference(cleanPrivateStorage);
33 }
34 }
35
36 if (!TextUtils.isEmpty(page)) {
37 openPreferenceScreen(page);
38 }
39
40 }
41
42 @Override
43 public void onActivityCreated(Bundle bundle) {
44 super.onActivityCreated(bundle);
45
46 final ListView listView = getActivity().findViewById(android.R.id.list);
47 if (listView != null) {
48 listView.setDivider(null);
49 }
50 }
51
52 public void setActivityIntent(final Intent intent) {
53 boolean wasEmpty = TextUtils.isEmpty(page);
54 if (intent != null) {
55 if (Intent.ACTION_VIEW.equals(intent.getAction())) {
56 if (intent.getExtras() != null) {
57 this.page = intent.getExtras().getString("page");
58 if (wasEmpty) {
59 openPreferenceScreen(page);
60 }
61 }
62 }
63 }
64 }
65
66 private void openPreferenceScreen(final String screenName) {
67 final Preference pref = findPreference(screenName);
68 if (pref instanceof PreferenceScreen) {
69 final PreferenceScreen preferenceScreen = (PreferenceScreen) pref;
70 getActivity().setTitle(preferenceScreen.getTitle());
71 preferenceScreen.setDependency("");
72 setPreferenceScreen((PreferenceScreen) pref);
73 }
74 }
75}