did some finetuning
This commit is contained in:
parent
7a6b5dd5b7
commit
c28fddc4dd
|
@ -91,9 +91,16 @@ public class ChannelActivity extends AppCompatActivity {
|
|||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
rootView = findViewById(R.id.rootView);
|
||||
setSupportActionBar(toolbar);
|
||||
if(savedInstanceState == null) {
|
||||
Intent i = getIntent();
|
||||
channelUrl = i.getStringExtra(NavStack.URL);
|
||||
serviceId = i.getIntExtra(NavStack.SERVICE_ID, -1);
|
||||
} else {
|
||||
channelUrl = savedInstanceState.getString(NavStack.URL);
|
||||
serviceId = savedInstanceState.getInt(NavStack.SERVICE_ID);
|
||||
NavStack.getInstance()
|
||||
.restoreSavedInstanceState(savedInstanceState);
|
||||
}
|
||||
|
||||
|
||||
infoListAdapter = new InfoListAdapter(this, rootView);
|
||||
|
@ -136,6 +143,15 @@ public class ChannelActivity extends AppCompatActivity {
|
|||
requestData(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putString(NavStack.URL, channelUrl);
|
||||
outState.putInt(NavStack.SERVICE_ID, serviceId);
|
||||
NavStack.getInstance()
|
||||
.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
private void updateUi(final ChannelInfo info) {
|
||||
CollapsingToolbarLayout ctl = (CollapsingToolbarLayout) findViewById(R.id.channel_toolbar_layout);
|
||||
ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar);
|
||||
|
|
|
@ -88,6 +88,8 @@ public class VideoItemDetailActivity extends ThemableActivity {
|
|||
} else {
|
||||
videoUrl = savedInstanceState.getString(NavStack.URL);
|
||||
currentStreamingService = savedInstanceState.getInt(NavStack.SERVICE_ID);
|
||||
NavStack.getInstance()
|
||||
.restoreSavedInstanceState(savedInstanceState);
|
||||
addFragment(savedInstanceState);
|
||||
}
|
||||
}
|
||||
|
@ -150,6 +152,8 @@ public class VideoItemDetailActivity extends ThemableActivity {
|
|||
outState.putString(NavStack.URL, videoUrl);
|
||||
outState.putInt(NavStack.SERVICE_ID, currentStreamingService);
|
||||
outState.putBoolean(VideoItemDetailFragment.AUTO_PLAY, false);
|
||||
NavStack.getInstance()
|
||||
.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -164,9 +168,8 @@ public class VideoItemDetailActivity extends ThemableActivity {
|
|||
|
||||
// http://developer.android.com/design/patterns/navigation.html#up-vs-back
|
||||
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
NavUtils.navigateUpTo(this, intent);
|
||||
NavStack.getInstance()
|
||||
.openMainActivity(this);
|
||||
return true;
|
||||
} else {
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
|
|
@ -242,9 +242,7 @@ public class DownloadActivity extends ThemableActivity implements AdapterView.On
|
|||
|
||||
switch (id) {
|
||||
case android.R.id.home: {
|
||||
Intent intent = new Intent(this, org.schabi.newpipe.MainActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
NavUtils.navigateUpTo(this, intent);
|
||||
onBackPressed();
|
||||
return true;
|
||||
}
|
||||
case R.id.action_settings: {
|
||||
|
@ -252,14 +250,6 @@ public class DownloadActivity extends ThemableActivity implements AdapterView.On
|
|||
startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
case R.id.action_report_error: {
|
||||
ErrorActivity.reportError(DownloadActivity.this, new Vector<Throwable>(),
|
||||
null, null,
|
||||
ErrorActivity.ErrorInfo.make(ErrorActivity.USER_REPORT,
|
||||
null,
|
||||
"user_report", R.string.user_report));
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.schabi.newpipe.util;
|
|||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.NavUtils;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
|
@ -14,6 +15,7 @@ import org.schabi.newpipe.detail.VideoItemDetailFragment;
|
|||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.StreamingService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
|
@ -45,6 +47,8 @@ public class NavStack {
|
|||
public static final String SERVICE_ID = "service_id";
|
||||
public static final String URL = "url";
|
||||
|
||||
private static final String NAV_STACK="nav_stack";
|
||||
|
||||
private enum ActivityId {
|
||||
CHANNEL,
|
||||
DETAIL
|
||||
|
@ -74,10 +78,16 @@ public class NavStack {
|
|||
}
|
||||
|
||||
public void navBack(Activity activity) throws Exception {
|
||||
if(stack.size() == 0) { // if stack is already empty here, activity was probably called
|
||||
// from another app
|
||||
activity.finish();
|
||||
return;
|
||||
}
|
||||
stack.pop(); // remove curent activty, since we dont want to return to itself
|
||||
if (stack.size() == 0) {
|
||||
openMainActivity(activity); // if no more page is on the stack this means we are home
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
NavEntry entry = stack.pop(); // this element will reapear, since by calling the old page
|
||||
// this element will be pushed on top again
|
||||
try {
|
||||
|
@ -99,7 +109,7 @@ public class NavStack {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void openChannelActivity(Context context, String url, int serviceId) {
|
||||
openActivity(context, url, serviceId, ChannelActivity.class);
|
||||
|
@ -117,9 +127,25 @@ public class NavStack {
|
|||
context.startActivity(i);
|
||||
}
|
||||
|
||||
private void openMainActivity(Activity a) {
|
||||
public void openMainActivity(Activity a) {
|
||||
stack.clear();
|
||||
Intent i = new Intent(a, MainActivity.class);
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
NavUtils.navigateUpTo(a, i);
|
||||
}
|
||||
|
||||
public void onSaveInstanceState(Bundle state) {
|
||||
ArrayList<String> sa = new ArrayList<>();
|
||||
for(NavEntry entry : stack) {
|
||||
sa.add(entry.url);
|
||||
}
|
||||
state.putStringArrayList(NAV_STACK, sa);
|
||||
}
|
||||
|
||||
public void restoreSavedInstanceState(Bundle state) {
|
||||
ArrayList<String> sa = state.getStringArrayList(NAV_STACK);
|
||||
for(String url : sa) {
|
||||
stack.push(new NavEntry(url, NewPipe.getServiceByUrl(url).getServiceId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,12 +2,7 @@
|
|||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
|
||||
<item android:id="@+id/action_settings"
|
||||
app:showAsAction="never"
|
||||
android:title="@string/settings"/>
|
||||
|
||||
<item android:id="@+id/action_report_error"
|
||||
app:showAsAction="never"
|
||||
android:title="@string/report_error" />
|
||||
</menu>
|
Loading…
Reference in New Issue