From a8ff4b0744510773e1f56d05eba4d13f1e559b7d Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Thu, 9 Mar 2017 16:01:09 +0100 Subject: [PATCH] Fix backbutton behaviour - close on MainActivity when back pressed - clear NavStack on rotation --- app/src/main/java/org/schabi/newpipe/MainActivity.java | 5 ----- .../main/java/org/schabi/newpipe/util/NavStack.java | 10 +++++----- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index eb9fd313c..781460f0a 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -85,9 +85,4 @@ public class MainActivity extends AppCompatActivity { return super.onOptionsItemSelected(item); } } - - @Override - public void onBackPressed() { - //ignore back - } } diff --git a/app/src/main/java/org/schabi/newpipe/util/NavStack.java b/app/src/main/java/org/schabi/newpipe/util/NavStack.java index f84c5725e..a5941ad83 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavStack.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavStack.java @@ -73,10 +73,6 @@ public class NavStack { return instance; } - private void addEntry(String url, Class ac, int serviceId) { - stack.push(new NavEntry(url, serviceId)); - } - public void navBack(Activity activity) throws Exception { if(stack.size() == 0) { // if stack is already empty here, activity was probably called // from another app @@ -120,7 +116,10 @@ public class NavStack { } private void openActivity(Context context, String url, int serviceId, Class acitivtyClass) { - stack.push(new NavEntry(url, serviceId)); + //if last element has the same url do not push to stack again + if(stack.isEmpty() || !stack.peek().url.equals(url)) { + stack.push(new NavEntry(url, serviceId)); + } Intent i = new Intent(context, acitivtyClass); i.putExtra(SERVICE_ID, serviceId); i.putExtra(URL, url); @@ -144,6 +143,7 @@ public class NavStack { public void restoreSavedInstanceState(Bundle state) { ArrayList sa = state.getStringArrayList(NAV_STACK); + stack.clear(); for(String url : sa) { stack.push(new NavEntry(url, NewPipe.getServiceByUrl(url).getServiceId())); }