Fix backbutton behaviour

- close on MainActivity when back pressed
- clear NavStack on rotation
This commit is contained in:
Christian Schabesberger 2017-03-09 16:01:09 +01:00
parent 483fde5e42
commit a8ff4b0744
2 changed files with 5 additions and 10 deletions

View file

@ -85,9 +85,4 @@ public class MainActivity extends AppCompatActivity {
return super.onOptionsItemSelected(item);
}
}
@Override
public void onBackPressed() {
//ignore back
}
}

View file

@ -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<String> sa = state.getStringArrayList(NAV_STACK);
stack.clear();
for(String url : sa) {
stack.push(new NavEntry(url, NewPipe.getServiceByUrl(url).getServiceId()));
}