-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Expand file tree
/
Copy pathProxySettingsFragment.java
More file actions
70 lines (63 loc) · 2.39 KB
/
ProxySettingsFragment.java
File metadata and controls
70 lines (63 loc) · 2.39 KB
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
63
64
65
66
67
68
69
70
package org.schabi.newpipe.settings;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.annotation.Nullable;
import org.schabi.newpipe.R;
import org.schabi.newpipe.util.NavigationHelper;
/**
* A fragment that displays proxy settings.
*/
public class ProxySettingsFragment extends BasePreferenceFragment {
private boolean preferencesChanged = false;
private SharedPreferences.OnSharedPreferenceChangeListener preferenceChangeListener;
@Override
public void onCreatePreferences(@Nullable final Bundle savedInstanceState,
@Nullable final String rootKey) {
//addPreferencesFromResource(R.xml.proxy_settings);
addPreferencesFromResourceRegistry();
preferenceChangeListener = (sharedPreferences, key) -> {
preferencesChanged = true;
};
getPreferenceScreen().getSharedPreferences()
.registerOnSharedPreferenceChangeListener(preferenceChangeListener);
}
@Override
public void onStop() {
super.onStop();
if (preferencesChanged && getActivity() != null && !getActivity().isFinishing()) {
showRestartDialog();
}
}
private void showRestartDialog() {
// Show Alert Dialogue
final Activity activity = getActivity();
if (activity == null) {
return;
}
final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setMessage(R.string.restart_app_message);
builder.setTitle(R.string.restart_app_title);
builder.setCancelable(true);
builder.setPositiveButton(R.string.ok, (dialogInterface, i) -> {
// Restarts the app
if (activity == null) {
return;
}
NavigationHelper.restartApp(activity);
});
builder.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
});
final android.app.AlertDialog alertDialog = builder.create();
alertDialog.show();
}
@Override
public void onDestroy() {
super.onDestroy();
if (preferenceChangeListener != null && getPreferenceScreen() != null) {
getPreferenceScreen().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(preferenceChangeListener);
}
}
}