Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Back button preference and functionality to open sidebar #1299

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ public void updateActionBarIcons() {

@Override
public void onBackPressed() {
Log.v(TAG,"NewsDetailActivity onBackPressed() Called");
if (!handlePodcastBackPressed())
super.onBackPressed();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
import android.widget.SearchView;
import android.widget.Toast;

import androidx.activity.OnBackPressedCallback;
import androidx.activity.OnBackPressedDispatcher;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.ActionBarDrawerToggle;
Expand Down Expand Up @@ -209,6 +211,33 @@ protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);


//trying to get back button working again
OnBackPressedDispatcher dispatcher = getOnBackPressedDispatcher();
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
Log.d(TAG, "NewsReaderListActivity handleOnBackPressed() called");
if (!handlePodcastBackPressed()) {

//Add in check for preference to determine if closes app or opens drawer
if (mPrefs.getBoolean(SettingsActivity.CB_PREF_BACK_OPENS_DRAWER, false)) { //change this line to the preference test - or add into an AND in the below iff

if (binding.drawerLayout != null) {
if (binding.drawerLayout.isDrawerOpen(GravityCompat.START))
setEnabled(false);
else
binding.drawerLayout.openDrawer(GravityCompat.START);
} else {
setEnabled(false);
}
} else {
setEnabled(false);
}
}
}
});

binding = ActivityNewsreaderBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

Expand Down Expand Up @@ -859,13 +888,30 @@ public boolean onMenuItemActionCollapse(MenuItem item) {
return true;
}

// remove this method overide as no longer works when using the new android predictive back gestures
// cleanup once confirmed new approach is working as expected
/*
@Override
public void onBackPressed() {
Log.e(TAG,"NewsReaderListActivity onBackPressed() Called");
if (!handlePodcastBackPressed()) {
super.onBackPressed();

//Add in check for preference to determine if closes app or opens drawer
if (mPrefs.getBoolean(SettingsActivity.CB_PREF_BACK_OPENS_DRAWER,false)) { //change this line to the preference test - or add into an AND in the below iff
if (binding.drawerLayout != null) {
if (binding.drawerLayout.isDrawerOpen(GravityCompat.START))
//super.onBackPressed();
//else
binding.drawerLayout.openDrawer(GravityCompat.START);
} else {
//super.onBackPressed();
}
}else {
super.onBackPressed();
}
}
}

*/
public static final int RESULT_SETTINGS = 15642;

private void syncMenuItemUnreadOnly() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class SettingsActivity extends AppCompatActivity {

public static final String CB_MARK_AS_READ_WHILE_SCROLLING_STRING = "cb_MarkAsReadWhileScrolling";
public static final String CB_SHOW_FAST_ACTIONS = "cb_ShowFastActions";
public static final String CB_PREF_BACK_OPENS_DRAWER = "cb_prefBackButtonOpensDrawer";
public static final String CB_DISABLE_HOSTNAME_VERIFICATION_STRING = "cb_DisableHostnameVerification";
public static final String CB_SKIP_DETAILVIEW_AND_OPEN_BROWSER_DIRECTLY_STRING = "cb_openInBrowserDirectly";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static de.luhmer.owncloudnewsreader.SettingsActivity.SP_SWIPE_LEFT_ACTION;
import static de.luhmer.owncloudnewsreader.SettingsActivity.SP_SWIPE_RIGHT_ACTION;
import static de.luhmer.owncloudnewsreader.SettingsActivity.SYNC_INTERVAL_IN_MINUTES_STRING_DEPRECATED;
import static de.luhmer.owncloudnewsreader.SettingsActivity.CB_PREF_BACK_OPENS_DRAWER;

import android.accounts.Account;
import android.accounts.AccountManager;
Expand Down Expand Up @@ -239,6 +240,7 @@ private void bindGeneralPreferences(DialogPreference.TargetFragment prefFrag)
bindPreferenceBooleanToValue(prefFrag.findPreference(CB_MARK_AS_READ_WHILE_SCROLLING_STRING));
bindPreferenceBooleanToValue(prefFrag.findPreference(CB_SHOW_FAST_ACTIONS));
bindPreferenceBooleanToValue(prefFrag.findPreference(CB_SKIP_DETAILVIEW_AND_OPEN_BROWSER_DIRECTLY_STRING));
bindPreferenceBooleanToValue(prefFrag.findPreference(CB_PREF_BACK_OPENS_DRAWER));
bindPreferenceSummaryToValue(prefFrag.findPreference(SP_SORT_ORDER));
bindPreferenceSummaryToValue(prefFrag.findPreference(SP_SEARCH_IN));
bindPreferenceSummaryToValue(prefFrag.findPreference(SP_SWIPE_RIGHT_ACTION));
Expand Down
1 change: 1 addition & 0 deletions News-Android-App/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
<string name="pref_title_MarkAsReadWhileScrolling">Mark as read while scrolling</string>
<string name="pref_title_ShowFastActions">Activate fast access functions</string>
<string name="pref_title_OpenInBrowserDirectly">Skip detailed view and open article in the browser</string>
<string name="pref_title_BackButtonOpensDrawer">Back button opens drawer</string>

<!-- MemorizingTrustManager -->
<string name="mtm_accept_cert">Accept Unknown Certificate?</string>
Expand Down
5 changes: 5 additions & 0 deletions News-Android-App/src/main/res/xml/pref_general.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@
android:title="@string/pref_title_OpenInBrowserDirectly"
app:iconSpaceReserved="false"/>

<SwitchPreference
android:key="cb_prefBackButtonOpensDrawer"
android:title="@string/pref_title_BackButtonOpensDrawer"
app:iconSpaceReserved="false" />

<ListPreference
android:defaultValue="1"
android:entries="@array/pref_general_swipe_action"
Expand Down
Loading