2014-10-22 16:38:44 +00:00
|
|
|
package eu.siacs.conversations.ui;
|
|
|
|
|
2018-02-16 18:49:14 +00:00
|
|
|
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;
|
2016-11-08 10:45:20 +00:00
|
|
|
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;
|
2018-02-16 18:49:14 +00:00
|
|
|
import android.text.TextUtils;
|
2018-08-28 15:50:36 +00:00
|
|
|
import android.widget.ListView;
|
2014-12-03 11:33:32 +00:00
|
|
|
|
2016-11-08 10:45:20 +00:00
|
|
|
import eu.siacs.conversations.Config;
|
2014-12-03 11:33:32 +00:00
|
|
|
import eu.siacs.conversations.R;
|
2018-09-05 19:37:05 +00:00
|
|
|
import eu.siacs.conversations.utils.Compatibility;
|
2014-10-22 16:38:44 +00:00
|
|
|
|
|
|
|
public class SettingsFragment extends PreferenceFragment {
|
2014-12-03 11:33:32 +00:00
|
|
|
|
2018-02-16 18:49:14 +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);
|
2016-11-08 10:45:20 +00:00
|
|
|
|
2018-02-16 21:20:14 +00:00
|
|
|
// Remove from standard preferences if the flag ONLY_INTERNAL_STORAGE is false
|
2016-11-08 10:45:20 +00:00
|
|
|
if (!Config.ONLY_INTERNAL_STORAGE) {
|
|
|
|
PreferenceCategory mCategory = (PreferenceCategory) findPreference("security_options");
|
2018-02-16 18:49:14 +00:00
|
|
|
if (mCategory != null) {
|
|
|
|
Preference cleanCache = findPreference("clean_cache");
|
|
|
|
Preference cleanPrivateStorage = findPreference("clean_private_storage");
|
|
|
|
mCategory.removePreference(cleanCache);
|
|
|
|
mCategory.removePreference(cleanPrivateStorage);
|
|
|
|
}
|
|
|
|
}
|
2018-09-05 19:37:05 +00:00
|
|
|
Compatibility.removeUnusedPreferences(this);
|
2018-02-16 18:49:14 +00:00
|
|
|
|
|
|
|
if (!TextUtils.isEmpty(page)) {
|
|
|
|
openPreferenceScreen(page);
|
2016-11-08 10:45:20 +00:00
|
|
|
}
|
|
|
|
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|
2014-12-03 11:33:32 +00:00
|
|
|
|
2018-08-28 15:50:36 +00:00
|
|
|
@Override
|
|
|
|
public void onActivityCreated(Bundle bundle) {
|
|
|
|
super.onActivityCreated(bundle);
|
|
|
|
|
|
|
|
final ListView listView = getActivity().findViewById(android.R.id.list);
|
|
|
|
if (listView != null) {
|
|
|
|
listView.setDivider(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-16 18:49:14 +00:00
|
|
|
public void setActivityIntent(final Intent intent) {
|
2018-03-16 11:58:43 +00:00
|
|
|
boolean wasEmpty = TextUtils.isEmpty(page);
|
2018-02-16 18:49:14 +00:00
|
|
|
if (intent != null) {
|
|
|
|
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
|
|
|
if (intent.getExtras() != null) {
|
|
|
|
this.page = intent.getExtras().getString("page");
|
2018-03-16 11:58:43 +00:00
|
|
|
if (wasEmpty) {
|
|
|
|
openPreferenceScreen(page);
|
|
|
|
}
|
2018-02-16 18:49:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|