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);
|
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||||
rootView = findViewById(R.id.rootView);
|
rootView = findViewById(R.id.rootView);
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
Intent i = getIntent();
|
if(savedInstanceState == null) {
|
||||||
channelUrl = i.getStringExtra(NavStack.URL);
|
Intent i = getIntent();
|
||||||
serviceId = i.getIntExtra(NavStack.SERVICE_ID, -1);
|
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);
|
infoListAdapter = new InfoListAdapter(this, rootView);
|
||||||
|
@ -136,6 +143,15 @@ public class ChannelActivity extends AppCompatActivity {
|
||||||
requestData(false);
|
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) {
|
private void updateUi(final ChannelInfo info) {
|
||||||
CollapsingToolbarLayout ctl = (CollapsingToolbarLayout) findViewById(R.id.channel_toolbar_layout);
|
CollapsingToolbarLayout ctl = (CollapsingToolbarLayout) findViewById(R.id.channel_toolbar_layout);
|
||||||
ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar);
|
ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar);
|
||||||
|
|
|
@ -88,6 +88,8 @@ public class VideoItemDetailActivity extends ThemableActivity {
|
||||||
} else {
|
} else {
|
||||||
videoUrl = savedInstanceState.getString(NavStack.URL);
|
videoUrl = savedInstanceState.getString(NavStack.URL);
|
||||||
currentStreamingService = savedInstanceState.getInt(NavStack.SERVICE_ID);
|
currentStreamingService = savedInstanceState.getInt(NavStack.SERVICE_ID);
|
||||||
|
NavStack.getInstance()
|
||||||
|
.restoreSavedInstanceState(savedInstanceState);
|
||||||
addFragment(savedInstanceState);
|
addFragment(savedInstanceState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,6 +152,8 @@ public class VideoItemDetailActivity extends ThemableActivity {
|
||||||
outState.putString(NavStack.URL, videoUrl);
|
outState.putString(NavStack.URL, videoUrl);
|
||||||
outState.putInt(NavStack.SERVICE_ID, currentStreamingService);
|
outState.putInt(NavStack.SERVICE_ID, currentStreamingService);
|
||||||
outState.putBoolean(VideoItemDetailFragment.AUTO_PLAY, false);
|
outState.putBoolean(VideoItemDetailFragment.AUTO_PLAY, false);
|
||||||
|
NavStack.getInstance()
|
||||||
|
.onSaveInstanceState(outState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -164,9 +168,8 @@ public class VideoItemDetailActivity extends ThemableActivity {
|
||||||
|
|
||||||
// http://developer.android.com/design/patterns/navigation.html#up-vs-back
|
// http://developer.android.com/design/patterns/navigation.html#up-vs-back
|
||||||
|
|
||||||
Intent intent = new Intent(this, MainActivity.class);
|
NavStack.getInstance()
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
.openMainActivity(this);
|
||||||
NavUtils.navigateUpTo(this, intent);
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
|
|
|
@ -242,9 +242,7 @@ public class DownloadActivity extends ThemableActivity implements AdapterView.On
|
||||||
|
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case android.R.id.home: {
|
case android.R.id.home: {
|
||||||
Intent intent = new Intent(this, org.schabi.newpipe.MainActivity.class);
|
onBackPressed();
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
||||||
NavUtils.navigateUpTo(this, intent);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case R.id.action_settings: {
|
case R.id.action_settings: {
|
||||||
|
@ -252,14 +250,6 @@ public class DownloadActivity extends ThemableActivity implements AdapterView.On
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
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:
|
default:
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.schabi.newpipe.util;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.NavUtils;
|
import android.support.v4.app.NavUtils;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.util.Log;
|
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.NewPipe;
|
||||||
import org.schabi.newpipe.extractor.StreamingService;
|
import org.schabi.newpipe.extractor.StreamingService;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,6 +47,8 @@ public class NavStack {
|
||||||
public static final String SERVICE_ID = "service_id";
|
public static final String SERVICE_ID = "service_id";
|
||||||
public static final String URL = "url";
|
public static final String URL = "url";
|
||||||
|
|
||||||
|
private static final String NAV_STACK="nav_stack";
|
||||||
|
|
||||||
private enum ActivityId {
|
private enum ActivityId {
|
||||||
CHANNEL,
|
CHANNEL,
|
||||||
DETAIL
|
DETAIL
|
||||||
|
@ -74,33 +78,39 @@ public class NavStack {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void navBack(Activity activity) throws Exception {
|
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
|
stack.pop(); // remove curent activty, since we dont want to return to itself
|
||||||
if(stack.size() == 0) {
|
if (stack.size() == 0) {
|
||||||
openMainActivity(activity); // if no more page is on the stack this means we are home
|
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
|
NavEntry entry = stack.pop(); // this element will reapear, since by calling the old page
|
||||||
try {
|
// this element will be pushed on top again
|
||||||
StreamingService service = NewPipe.getService(entry.serviceId);
|
try {
|
||||||
switch (service.getLinkTypeByUrl(entry.url)) {
|
StreamingService service = NewPipe.getService(entry.serviceId);
|
||||||
case STREAM:
|
switch (service.getLinkTypeByUrl(entry.url)) {
|
||||||
openDetailActivity(activity, entry.url, entry.serviceId);
|
case STREAM:
|
||||||
break;
|
openDetailActivity(activity, entry.url, entry.serviceId);
|
||||||
case CHANNEL:
|
break;
|
||||||
openChannelActivity(activity, entry.url, entry.serviceId);
|
case CHANNEL:
|
||||||
break;
|
openChannelActivity(activity, entry.url, entry.serviceId);
|
||||||
case NONE:
|
break;
|
||||||
throw new Exception("Url not known to service. service="
|
case NONE:
|
||||||
+ Integer.toString(entry.serviceId) + " url=" + entry.url);
|
throw new Exception("Url not known to service. service="
|
||||||
default:
|
+ Integer.toString(entry.serviceId) + " url=" + entry.url);
|
||||||
openMainActivity(activity);
|
default:
|
||||||
}
|
openMainActivity(activity);
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void openChannelActivity(Context context, String url, int serviceId) {
|
public void openChannelActivity(Context context, String url, int serviceId) {
|
||||||
openActivity(context, url, serviceId, ChannelActivity.class);
|
openActivity(context, url, serviceId, ChannelActivity.class);
|
||||||
}
|
}
|
||||||
|
@ -117,9 +127,25 @@ public class NavStack {
|
||||||
context.startActivity(i);
|
context.startActivity(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openMainActivity(Activity a) {
|
public void openMainActivity(Activity a) {
|
||||||
|
stack.clear();
|
||||||
Intent i = new Intent(a, MainActivity.class);
|
Intent i = new Intent(a, MainActivity.class);
|
||||||
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
NavUtils.navigateUpTo(a, i);
|
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"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
|
||||||
<item android:id="@+id/action_settings"
|
<item android:id="@+id/action_settings"
|
||||||
app:showAsAction="never"
|
app:showAsAction="never"
|
||||||
android:title="@string/settings"/>
|
android:title="@string/settings"/>
|
||||||
|
|
||||||
<item android:id="@+id/action_report_error"
|
|
||||||
app:showAsAction="never"
|
|
||||||
android:title="@string/report_error" />
|
|
||||||
</menu>
|
</menu>
|
Loading…
Reference in New Issue