mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-31 15:23:00 +00:00 
			
		
		
		
	did some finetuning
This commit is contained in:
		| @@ -91,9 +91,16 @@ public class ChannelActivity extends AppCompatActivity { | ||||
|         Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | ||||
|         rootView = findViewById(R.id.rootView); | ||||
|         setSupportActionBar(toolbar); | ||||
|         Intent i = getIntent(); | ||||
|         channelUrl = i.getStringExtra(NavStack.URL); | ||||
|         serviceId = i.getIntExtra(NavStack.SERVICE_ID, -1); | ||||
|         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,33 +78,39 @@ 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) { | ||||
|         if (stack.size() == 0) { | ||||
|             openMainActivity(activity); // if no more page is on the stack this means we are home | ||||
|         } else { | ||||
|             NavEntry entry = stack.pop();  // this element will reapear, since by calling the old page | ||||
|             // this element will be pushed on top again | ||||
|             try { | ||||
|                 StreamingService service = NewPipe.getService(entry.serviceId); | ||||
|                 switch (service.getLinkTypeByUrl(entry.url)) { | ||||
|                     case STREAM: | ||||
|                         openDetailActivity(activity, entry.url, entry.serviceId); | ||||
|                         break; | ||||
|                     case CHANNEL: | ||||
|                         openChannelActivity(activity, entry.url, entry.serviceId); | ||||
|                         break; | ||||
|                     case NONE: | ||||
|                         throw new Exception("Url not known to service. service=" | ||||
|                                 + Integer.toString(entry.serviceId) + " url=" + entry.url); | ||||
|                     default: | ||||
|                         openMainActivity(activity); | ||||
|                 } | ||||
|             } catch (Exception e) { | ||||
|                 e.printStackTrace(); | ||||
|             return; | ||||
|         } | ||||
|         NavEntry entry = stack.pop();  // this element will reapear, since by calling the old page | ||||
|         // this element will be pushed on top again | ||||
|         try { | ||||
|             StreamingService service = NewPipe.getService(entry.serviceId); | ||||
|             switch (service.getLinkTypeByUrl(entry.url)) { | ||||
|                 case STREAM: | ||||
|                     openDetailActivity(activity, entry.url, entry.serviceId); | ||||
|                     break; | ||||
|                 case CHANNEL: | ||||
|                     openChannelActivity(activity, entry.url, entry.serviceId); | ||||
|                     break; | ||||
|                 case NONE: | ||||
|                     throw new Exception("Url not known to service. service=" | ||||
|                             + Integer.toString(entry.serviceId) + " url=" + entry.url); | ||||
|                 default: | ||||
|                     openMainActivity(activity); | ||||
|             } | ||||
|         } catch (Exception e) { | ||||
|             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())); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Christian Schabesberger
					Christian Schabesberger