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

Optionally allow exit button in nav drawer

This commit is contained in:
Gregor Santner 2016-08-07 02:28:37 +02:00
parent e1b02c42d2
commit 78f6c7e6e2
8 changed files with 63 additions and 5 deletions

View file

@ -114,6 +114,7 @@ public class MainActivity extends AppCompatActivity
public static final String ACTION_CHANGE_ACCOUNT = "com.github.dfa.diaspora_android.MainActivity.change_account"; public static final String ACTION_CHANGE_ACCOUNT = "com.github.dfa.diaspora_android.MainActivity.change_account";
public static final String ACTION_CLEAR_CACHE = "com.github.dfa.diaspora_android.MainActivity.clear_cache"; public static final String ACTION_CLEAR_CACHE = "com.github.dfa.diaspora_android.MainActivity.clear_cache";
public static final String ACTION_UPDATE_TITLE_FROM_URL = "com.github.dfa.diaspora_android.MainActivity.set_title"; public static final String ACTION_UPDATE_TITLE_FROM_URL = "com.github.dfa.diaspora_android.MainActivity.set_title";
public static final String ACTION_RELOAD_ACTIVITY = "com.github.dfa.diaspora_android.MainActivity.reload_activity";
public static final String URL_MESSAGE = "URL_MESSAGE"; public static final String URL_MESSAGE = "URL_MESSAGE";
public static final String EXTRA_URL = "com.github.dfa.diaspora_android.extra_url"; public static final String EXTRA_URL = "com.github.dfa.diaspora_android.extra_url";
@ -408,6 +409,10 @@ public class MainActivity extends AppCompatActivity
app.getAvatarImageLoader().startImageDownload(navheaderImage, appSettings.getAvatarUrl()); app.getAvatarImageLoader().startImageDownload(navheaderImage, appSettings.getAvatarUrl());
} }
} }
Menu navMenu = navView.getMenu();
navMenu.findItem(R.id.nav_exit).setVisible(appSettings.isShowExitButtonInNavAlso());
} }
@OnClick(R.id.toolbar) @OnClick(R.id.toolbar)
@ -454,6 +459,9 @@ public class MainActivity extends AppCompatActivity
Helpers.animateToActivity(MainActivity.this, PodSelectionActivity.class, true); Helpers.animateToActivity(MainActivity.this, PodSelectionActivity.class, true);
} else if (ACTION_CLEAR_CACHE.equals(action)) { } else if (ACTION_CLEAR_CACHE.equals(action)) {
webView.clearCache(true); webView.clearCache(true);
} else if (ACTION_RELOAD_ACTIVITY.equals(action)) {
recreate();
return;
} else if (Intent.ACTION_SEND.equals(action) && type != null) { } else if (Intent.ACTION_SEND.equals(action) && type != null) {
switch (type) { switch (type) {
case "text/plain": case "text/plain":
@ -1062,8 +1070,8 @@ public class MainActivity extends AppCompatActivity
} else { } else {
snackbarNoInternet.show(); snackbarNoInternet.show();
} }
break;
} }
break;
case R.id.nav_public: { case R.id.nav_public: {
if (Helpers.isOnline(MainActivity.this)) { if (Helpers.isOnline(MainActivity.this)) {
@ -1071,8 +1079,15 @@ public class MainActivity extends AppCompatActivity
} else { } else {
snackbarNoInternet.show(); snackbarNoInternet.show();
} }
break;
}
case R.id.nav_exit: {
moveTaskToBack(true);
finish();
break;
} }
break;
case R.id.nav_settings_app: { case R.id.nav_settings_app: {
startActivity(new Intent(this, SettingsActivity.class)); startActivity(new Intent(this, SettingsActivity.class));

View file

@ -38,6 +38,7 @@ import com.github.dfa.diaspora_android.R;
public class SettingsActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener { public class SettingsActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
private SharedPreferences sharedPreferences; private SharedPreferences sharedPreferences;
private boolean activityRestartRequired = false;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -124,6 +125,12 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
intent.setAction(MainActivity.ACTION_CLEAR_CACHE); intent.setAction(MainActivity.ACTION_CLEAR_CACHE);
break; break;
} }
case R.string.pref_title__show_exit_button_in_nav_also:
case R.string.pref_title__intellihide_toolbars: {
activityRestartRequired = true;
return true;
}
default: { default: {
intent = null; intent = null;
break; break;
@ -136,4 +143,14 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
} }
return super.onPreferenceTreeClick(screen, preference); return super.onPreferenceTreeClick(screen, preference);
} }
@Override
protected void onStop() {
super.onStop();
if (activityRestartRequired){
Intent intent = new Intent(this, MainActivity.class);
intent.setAction(MainActivity.ACTION_RELOAD_ACTIVITY);
startActivity(intent);
}
}
} }

View file

@ -234,4 +234,8 @@ public class AppSettings {
public boolean isIntellihideToolbars() { public boolean isIntellihideToolbars() {
return getBoolean(prefApp, R.string.pref_key__intellihide_toolbars, true); return getBoolean(prefApp, R.string.pref_key__intellihide_toolbars, true);
} }
public boolean isShowExitButtonInNavAlso(){
return getBoolean(prefApp, R.string.pref_key__show_exit_button_in_nav_also, false);
}
} }

View file

@ -0,0 +1,4 @@
<vector android:height="24dp" android:viewportHeight="24.0"
android:viewportWidth="24.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#000000" android:pathData="M12,2C6.47,2 2,6.47 2,12s4.47,10 10,10 10,-4.47 10,-10S17.53,2 12,2zM17,15.59L15.59,17 12,13.41 8.41,17 7,15.59 10.59,12 7,8.41 8.41,7 12,10.59 15.59,7 17,8.41 13.41,12 17,15.59z"/>
</vector>

View file

@ -45,6 +45,12 @@
android:id="@+id/nav_public" android:id="@+id/nav_public"
android:icon="@drawable/jb_aspects" android:icon="@drawable/jb_aspects"
android:title="@string/nav_public_activities" /> android:title="@string/nav_public_activities" />
<item
android:id="@+id/nav_exit"
android:icon="@drawable/ic_cancel_black_48px"
android:title="@string/action_exit_app"
android:visible="false"/>
</group> </group>
<item android:title="@string/nav_menu_settings"> <item android:title="@string/nav_menu_settings">

View file

@ -14,6 +14,8 @@
<string name="pref_catkey__network" translatable="false">pref_key_category_network</string> <string name="pref_catkey__network" translatable="false">pref_key_category_network</string>
<string name="pref_key__load_images" translatable="false">pref_key_load_images</string> <string name="pref_key__load_images" translatable="false">pref_key_load_images</string>
<string name="pref_key__clear_cache" translatable="false">pref_key_clear_cache</string> <string name="pref_key__clear_cache" translatable="false">pref_key_clear_cache</string>
<string name="pref_key__show_exit_button_in_nav_also" translatable="false">pref_key__show_exit_button_in_nav_also</string>
<string name="pref_key__append_shared_via_app" translatable="false">pref_key_append_shared_via_app</string> <string name="pref_key__append_shared_via_app" translatable="false">pref_key_append_shared_via_app</string>
<string name="pref_key__proxy_enabled" translatable="false">pref_key_proxy_enabled</string> <string name="pref_key__proxy_enabled" translatable="false">pref_key_proxy_enabled</string>
<string name="pref_key__proxy_host" translatable="false">pref_key_proxy_host</string> <string name="pref_key__proxy_host" translatable="false">pref_key_proxy_host</string>
@ -21,6 +23,8 @@
<string name="pref_key__proxy_was_enabled" translatable="false">wasProxyEnabled</string> <string name="pref_key__proxy_was_enabled" translatable="false">wasProxyEnabled</string>
<string name="pref_key__podprofile_avatar_url" translatable="false">podUserProfile_avatar</string> <string name="pref_key__podprofile_avatar_url" translatable="false">podUserProfile_avatar</string>
<string name="pref_key__podprofile_name" translatable="false">podUserProfile_name</string> <string name="pref_key__podprofile_name" translatable="false">podUserProfile_name</string>
<string name="pref_key__podprofile_id" translatable="false">podUserProfile_guid</string> <string name="pref_key__podprofile_id" translatable="false">podUserProfile_guid</string>
@ -55,11 +59,13 @@
<!-- Proxy --> <!-- Proxy -->
<string name="pref_title__proxy_enabled">Enable Proxy</string> <string name="pref_title__proxy_enabled">Enable Proxy</string>
<string name="pref_desc__proxy_enabled">Proxy Diaspora\'s traffic to circumvent firewalls.\nMay require restart</string> <string name="pref_desc__proxy_enabled">Proxy Diaspora\'s traffic to circumvent firewalls.\nMay require restart</string>
<string name="pref_title__proxy_host">Host</string> <string name="pref_title__proxy_host">Host</string>
<string name="pref_title__proxy_port">Port</string> <string name="pref_title__proxy_port">Port</string>
<string name="pref_title__show_exit_button_in_nav_also">Exit button in navigation slider</string>
<string name="pref_desc__show_exit_button_in_nav_also">Adds an additional »Exit App« button to the navigation slider</string>
<!-- Diaspora Settings --> <!-- Diaspora Settings -->
<string name="pref_title__personal_settings">Personal settings</string> <string name="pref_title__personal_settings">Personal settings</string>
<string name="pref_desc__personal_settings">Open your diaspora account settings</string> <string name="pref_desc__personal_settings">Open your diaspora account settings</string>
@ -83,4 +89,5 @@
<string name="pref_title__append_shared_via_app">Append shared-by-notice</string> <string name="pref_title__append_shared_via_app">Append shared-by-notice</string>
<string name="pref_desc__append_shared_via_app">Append a reference to this app ("shared by…") to shared texts</string> <string name="pref_desc__append_shared_via_app">Append a reference to this app ("shared by…") to shared texts</string>
<!-- Recently added - Please move to right section-->
</resources> </resources>

View file

@ -169,7 +169,6 @@
&lt;i>The splashscreen images can be found on flickr: &lt;i>The splashscreen images can be found on flickr:
https://www.flickr.com/photos/129581906@N06/sets/72157651933980136/with/16594947123. https://www.flickr.com/photos/129581906@N06/sets/72157651933980136/with/16594947123.
They were published by \"Lydia\" and are licensed under cc by-nc-sa.&lt;/i></string> They were published by \"Lydia\" and are licensed under cc by-nc-sa.&lt;/i></string>
<!-- Recently added - Please move to right section--> <!-- Recently added - Please move to right section-->
</resources> </resources>

View file

@ -24,6 +24,12 @@
android:summary="@string/pref_desc__append_shared_via_app" android:summary="@string/pref_desc__append_shared_via_app"
android:title="@string/pref_title__append_shared_via_app"/> android:title="@string/pref_title__append_shared_via_app"/>
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/pref_key__show_exit_button_in_nav_also"
android:summary="@string/pref_desc__show_exit_button_in_nav_also"
android:title="@string/pref_title__show_exit_button_in_nav_also"/>
</PreferenceCategory> </PreferenceCategory>
<!-- Diaspora Pod Settings --> <!-- Diaspora Pod Settings -->