aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/ui/SettingsFragment.java
blob: b40875f7c015c0ff54cc924fbda67c68d1b690ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package de.pixart.messenger.ui;

import android.content.Intent;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
import android.text.TextUtils;

import de.pixart.messenger.Config;
import de.pixart.messenger.R;

public class SettingsFragment extends PreferenceFragment {

    private String page = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences);

        // 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);
        }
    }

    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);
        }
    }
}