1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-22 04:12:08 +01:00

Added info Toasts to Proxy preference, that inform the user about required restart and successful preset setting

This commit is contained in:
vanitasvitae 2016-10-27 21:42:41 +02:00
parent f08fb9e349
commit 30ca937461
Signed by: vanitasvitae
GPG key ID: DCCFB3302C9E4615
5 changed files with 60 additions and 6 deletions

View file

@ -7,7 +7,7 @@
06l>> Firstname Lastname (E-Mail): Text 06l>> Firstname Lastname (E-Mail): Text
07l>> Username (Link): Text 07l>> Username (Link): Text
08l>> Username (E-Mail): Text 08l>> Username (E-Mail): Text
## 99l CONTRIBUTORS ## 99l CONTRIBUTORS
Martín Vukovic (martinvukovic@protonmail.com): Diaspora Native WebApp Martín Vukovic (martinvukovic@protonmail.com): Diaspora Native WebApp
Gaukler Faun (https://github.com/scoute-dich): Diaspora Native WebApp additions Gaukler Faun (https://github.com/scoute-dich): Diaspora Native WebApp additions
Abhijith Balan (abhijithb21 AT openmailbox DOT org): Malayalam translation Abhijith Balan (abhijithb21 AT openmailbox DOT org): Malayalam translation

View file

@ -511,11 +511,7 @@ public class MainActivity extends ThemedActivity
* @return top fragment or null if there is none displayed * @return top fragment or null if there is none displayed
*/ */
private CustomFragment getTopFragment() { private CustomFragment getTopFragment() {
Fragment top = fm.findFragmentById(R.id.fragment_container); return (CustomFragment) fm.findFragmentById(R.id.fragment_container);
if (top != null) {
return (CustomFragment) top;
}
return null;
} }
/** /**

View file

@ -14,15 +14,18 @@ import android.preference.Preference;
import android.preference.PreferenceFragment; import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.support.design.widget.AppBarLayout; import android.support.design.widget.AppBarLayout;
import android.support.v4.app.Fragment;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import com.github.dfa.diaspora_android.App; import com.github.dfa.diaspora_android.App;
import com.github.dfa.diaspora_android.R; import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.ui.theme.ColorPalette; import com.github.dfa.diaspora_android.ui.theme.ColorPalette;
import com.github.dfa.diaspora_android.ui.theme.CustomFragment;
import com.github.dfa.diaspora_android.ui.theme.ThemeHelper; import com.github.dfa.diaspora_android.ui.theme.ThemeHelper;
import com.github.dfa.diaspora_android.ui.theme.ThemedActivity; import com.github.dfa.diaspora_android.ui.theme.ThemedActivity;
import com.github.dfa.diaspora_android.ui.theme.ThemedPreferenceFragment; import com.github.dfa.diaspora_android.ui.theme.ThemedPreferenceFragment;
@ -127,6 +130,31 @@ public class SettingsActivity extends ThemedActivity {
super.onStop(); super.onStop();
} }
@Override
public void onBackPressed() {
AppLog.d(this, "onBackPressed");
ThemedPreferenceFragment top = getTopFragment();
if(top != null && top.getFragmentTag().equals(SettingsFragmentProxy.TAG)) {
AppLog.d(this, "top was proxy");
ProxyHandler.ProxySettings newProxySettings = getAppSettings().getProxySettings();
if(oldProxySettings.isEnabled() && !newProxySettings.isEnabled()) {
AppLog.d(this, "proxy disabled");
Toast.makeText(this, R.string.toast__proxy_disabled__restart_required, Toast.LENGTH_LONG).show();
}
}
AppLog.d(this, "top is null: "+(top == null));
super.onBackPressed();
}
/**
* Return the fragment which is currently displayed in R.id.fragment_container
*
* @return top fragment or null if there is none displayed
*/
private ThemedPreferenceFragment getTopFragment() {
return (ThemedPreferenceFragment) getFragmentManager().findFragmentById(R.id.settings__fragment_container);
}
public static class SettingsFragmentMaster extends ThemedPreferenceFragment { public static class SettingsFragmentMaster extends ThemedPreferenceFragment {
public static final String TAG = "com.github.dfa.diaspora_android.settings.SettingsFragmentMaster"; public static final String TAG = "com.github.dfa.diaspora_android.settings.SettingsFragmentMaster";
@ -212,6 +240,11 @@ public class SettingsActivity extends ThemedActivity {
} }
return super.onPreferenceTreeClick(screen, preference); return super.onPreferenceTreeClick(screen, preference);
} }
@Override
public String getFragmentTag() {
return TAG;
}
} }
public static class SettingsFragmentThemes extends ThemedPreferenceFragment { public static class SettingsFragmentThemes extends ThemedPreferenceFragment {
@ -247,6 +280,11 @@ public class SettingsActivity extends ThemedActivity {
return super.onPreferenceTreeClick(screen, preference); return super.onPreferenceTreeClick(screen, preference);
} }
@Override
public String getFragmentTag() {
return TAG;
}
/** /**
* Show a colorPicker Dialog * Show a colorPicker Dialog
* *
@ -329,6 +367,11 @@ public class SettingsActivity extends ThemedActivity {
public void updateViewColors() { public void updateViewColors() {
} }
@Override
public String getFragmentTag() {
return TAG;
}
} }
public static class SettingsFragmentProxy extends ThemedPreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener { public static class SettingsFragmentProxy extends ThemedPreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
@ -364,12 +407,18 @@ public class SettingsActivity extends ThemedActivity {
if (appSettings.isKeyEqual(key, R.string.pref_key__http_proxy_load_tor_preset)) { if (appSettings.isKeyEqual(key, R.string.pref_key__http_proxy_load_tor_preset)) {
appSettings.setProxyHttpHost("127.0.0.1"); appSettings.setProxyHttpHost("127.0.0.1");
appSettings.setProxyHttpPort(8118); appSettings.setProxyHttpPort(8118);
Toast.makeText(screen.getContext(), R.string.toast__proxy_orbot_preset_loaded, Toast.LENGTH_SHORT).show();
return true; return true;
} }
} }
return super.onPreferenceTreeClick(screen, preference); return super.onPreferenceTreeClick(screen, preference);
} }
@Override
public String getFragmentTag() {
return TAG;
}
@Override @Override
public void updateViewColors() { public void updateViewColors() {
@ -399,5 +448,10 @@ public class SettingsActivity extends ThemedActivity {
public void updateViewColors() { public void updateViewColors() {
} }
@Override
public String getFragmentTag() {
return TAG;
}
} }
} }

View file

@ -39,4 +39,6 @@ public abstract class ThemedPreferenceFragment extends PreferenceFragment {
} }
return super.onPreferenceTreeClick(screen, preference); return super.onPreferenceTreeClick(screen, preference);
} }
public abstract String getFragmentTag();
} }

View file

@ -115,6 +115,8 @@
<string name="pref_title__http_proxy_port">Port</string> <string name="pref_title__http_proxy_port">Port</string>
<string name="HTTP" translatable="false">HTTP</string> <string name="HTTP" translatable="false">HTTP</string>
<string name="SOCKS5" translatable="false">SOCKS5</string> <string name="SOCKS5" translatable="false">SOCKS5</string>
<string name="toast__proxy_disabled__restart_required">App needs to restart to disable proxy usage</string>
<string name="toast__proxy_orbot_preset_loaded">Orbot proxy preset loaded</string>
<!-- Chrome custom tabs --> <!-- Chrome custom tabs -->