Skip to content

Commit

Permalink
Merge pull request #2312 from TeamNewPipe/release_v0.16.2
Browse files Browse the repository at this point in the history
Release v0.16.2
  • Loading branch information
TobiGr committed May 31, 2019
2 parents 48f966e + 0c354c4 commit 1670751
Show file tree
Hide file tree
Showing 104 changed files with 2,506 additions and 3,246 deletions.
10 changes: 5 additions & 5 deletions app/build.gradle
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "org.schabi.newpipe"
minSdkVersion 19
targetSdkVersion 28
versionCode 730
versionName "0.16.1"
versionCode 740
versionName "0.16.2"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down Expand Up @@ -44,10 +44,10 @@ android {

ext {
supportLibVersion = '28.0.0'
exoPlayerLibVersion = '2.8.4' //2.9.0
exoPlayerLibVersion = '2.9.6'
roomDbLibVersion = '1.1.1'
leakCanaryLibVersion = '1.5.4' //1.6.1
okHttpLibVersion = '3.11.0'
okHttpLibVersion = '3.12.1'
icepickLibVersion = '3.2.0'
stethoLibVersion = '1.5.0'
}
Expand All @@ -57,7 +57,7 @@ dependencies {
exclude module: 'support-annotations'
})

implementation 'com.github.TeamNewPipe:NewPipeExtractor:e072bf6461b295'
implementation 'com.github.TeamNewPipe:NewPipeExtractor:2ac713e'

testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.23.0'
Expand Down
Expand Up @@ -2,11 +2,13 @@

import android.app.Application;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
Expand Down Expand Up @@ -68,6 +70,8 @@ protected void onPreExecute() {

@Override
protected String doInBackground(Void... voids) {

if(isCancelled() || !isConnected()) return null;

// Make a network request to get latest NewPipe data.
if (client == null) {
Expand Down Expand Up @@ -227,4 +231,12 @@ public static boolean isGithubApk() {

return getCertificateSHA1Fingerprint().equals(GITHUB_APK_SHA1);
}

private boolean isConnected() {

ConnectivityManager cm =
(ConnectivityManager) app.getSystemService(Context.CONNECTIVITY_SERVICE);
return cm.getActiveNetworkInfo() != null
&& cm.getActiveNetworkInfo().isConnected();
}
}
26 changes: 21 additions & 5 deletions app/src/main/java/org/schabi/newpipe/RouterActivity.java
Expand Up @@ -36,12 +36,12 @@
import org.schabi.newpipe.extractor.playlist.PlaylistInfo;
import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.extractor.stream.VideoStream;
import org.schabi.newpipe.player.helper.PlayerHelper;
import org.schabi.newpipe.player.playqueue.ChannelPlayQueue;
import org.schabi.newpipe.player.playqueue.PlayQueue;
import org.schabi.newpipe.player.playqueue.PlaylistPlayQueue;
import org.schabi.newpipe.player.playqueue.SinglePlayQueue;
import org.schabi.newpipe.report.UserAction;
import org.schabi.newpipe.util.Constants;
import org.schabi.newpipe.util.ExtractorHelper;
import org.schabi.newpipe.util.ListHelper;
import org.schabi.newpipe.util.NavigationHelper;
Expand Down Expand Up @@ -81,10 +81,13 @@ public class RouterActivity extends AppCompatActivity {
protected int selectedPreviously = -1;

protected String currentUrl;
protected boolean internalRoute = false;
protected final CompositeDisposable disposables = new CompositeDisposable();

private boolean selectionIsDownload = false;

public static final String internalRouteKey = "internalRoute";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -94,11 +97,13 @@ protected void onCreate(Bundle savedInstanceState) {
currentUrl = getUrl(getIntent());

if (TextUtils.isEmpty(currentUrl)) {
Toast.makeText(this, R.string.invalid_url_toast, Toast.LENGTH_LONG).show();
handleText();
finish();
}
}

internalRoute = getIntent().getBooleanExtra(internalRouteKey, false);

setTheme(ThemeHelper.isLightThemeSelected(this)
? R.style.RouterActivityThemeLight : R.style.RouterActivityThemeDark);
}
Expand All @@ -112,7 +117,7 @@ protected void onSaveInstanceState(Bundle outState) {
@Override
protected void onStart() {
super.onStart();

handleUrl(currentUrl);
}

Expand Down Expand Up @@ -353,6 +358,15 @@ private void setDialogButtonsState(AlertDialog dialog, boolean state) {
positiveButton.setEnabled(state);
}

private void handleText(){
String searchString = getIntent().getStringExtra(Intent.EXTRA_TEXT);
int serviceId = getIntent().getIntExtra(Constants.KEY_SERVICE_ID, 0);
Intent intent = new Intent(getThemeWrapperContext(), MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
NavigationHelper.openSearch(getThemeWrapperContext(),serviceId,searchString);
}

private void handleChoice(final String selectedChoiceKey) {
final List<String> validChoicesList = Arrays.asList(getResources().getStringArray(R.array.preferred_open_action_values_list));
if (validChoicesList.contains(selectedChoiceKey)) {
Expand Down Expand Up @@ -383,8 +397,10 @@ private void handleChoice(final String selectedChoiceKey) {
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(intent -> {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
if(!internalRoute){
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
}
startActivity(intent);

finish();
Expand Down
Expand Up @@ -47,7 +47,7 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public void onGlobalLayout() {
updateFragments();
getWindow().getDecorView().getViewTreeObserver().removeGlobalOnLayoutListener(this);
getWindow().getDecorView().getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
}
Expand Down
Expand Up @@ -230,21 +230,4 @@ public void showSnackBarError(List<Throwable> exception, UserAction userAction,
ErrorActivity.reportError(getContext(), exception, MainActivity.class, rootView,
ErrorActivity.ErrorInfo.make(userAction, serviceName, request, errorId));
}

/*//////////////////////////////////////////////////////////////////////////
// Utils
//////////////////////////////////////////////////////////////////////////*/

protected void openUrlInBrowser(String url) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(Intent.createChooser(intent, activity.getString(R.string.share_dialog_title)));
}

protected void shareUrl(String subject, String url) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, url);
startActivity(Intent.createChooser(intent, getString(R.string.share_dialog_title)));
}
}
17 changes: 17 additions & 0 deletions app/src/main/java/org/schabi/newpipe/fragments/EmptyFragment.java
@@ -0,0 +1,17 @@
package org.schabi.newpipe.fragments;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import org.schabi.newpipe.BaseFragment;
import org.schabi.newpipe.R;

public class EmptyFragment extends BaseFragment {
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_empty, container, false);
}
}
@@ -1,5 +1,6 @@
package org.schabi.newpipe.fragments.detail;

import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
Expand Down Expand Up @@ -61,6 +62,18 @@ public int getItemPosition(Object object) {
else return POSITION_NONE;
}

public int getItemPositionByTitle(String title) {
return mFragmentTitleList.indexOf(title);
}

@Nullable
public String getItemTitle(int position) {
if (position < 0 || position >= mFragmentTitleList.size()) {
return null;
}
return mFragmentTitleList.get(position);
}

public void notifyDataSetUpdate(){
notifyDataSetChanged();
}
Expand Down
Expand Up @@ -65,6 +65,7 @@
import org.schabi.newpipe.extractor.stream.VideoStream;
import org.schabi.newpipe.fragments.BackPressable;
import org.schabi.newpipe.fragments.BaseStateFragment;
import org.schabi.newpipe.fragments.EmptyFragment;
import org.schabi.newpipe.fragments.list.comments.CommentsFragment;
import org.schabi.newpipe.fragments.list.videos.RelatedVideosFragment;
import org.schabi.newpipe.info_list.InfoItemDialog;
Expand All @@ -85,6 +86,7 @@
import org.schabi.newpipe.util.Localization;
import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.PermissionHelper;
import org.schabi.newpipe.util.ShareUtils;
import org.schabi.newpipe.util.StreamItemAdapter;
import org.schabi.newpipe.util.StreamItemAdapter.StreamSizeWrapper;

Expand Down Expand Up @@ -121,6 +123,7 @@ public class VideoDetailFragment
private boolean autoPlayEnabled;
private boolean showRelatedStreams;
private boolean showComments;
private String selectedTabTag;

@State
protected int serviceId = Constants.NO_SERVICE_ID;
Expand Down Expand Up @@ -179,6 +182,7 @@ public class VideoDetailFragment

private static final String COMMENTS_TAB_TAG = "COMMENTS";
private static final String RELATED_TAB_TAG = "NEXT VIDEO";
private static final String EMPTY_TAB_TAG = "EMPTY TAB";

private AppBarLayout appBarLayout;
private ViewPager viewPager;
Expand Down Expand Up @@ -211,6 +215,9 @@ public static VideoDetailFragment getInstance(int serviceId, String videoUrl, St
showComments = PreferenceManager.getDefaultSharedPreferences(activity)
.getBoolean(getString(R.string.show_comments_key), true);

selectedTabTag = PreferenceManager.getDefaultSharedPreferences(activity)
.getString(getString(R.string.stream_info_selected_tab_key), COMMENTS_TAB_TAG);

PreferenceManager.getDefaultSharedPreferences(activity)
.registerOnSharedPreferenceChangeListener(this);
}
Expand All @@ -224,6 +231,10 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
public void onPause() {
super.onPause();
if (currentWorker != null) currentWorker.dispose();
PreferenceManager.getDefaultSharedPreferences(getContext())
.edit()
.putString(getString(R.string.stream_info_selected_tab_key), pageAdapter.getItemTitle(viewPager.getCurrentItem()))
.apply();
}

@Override
Expand Down Expand Up @@ -537,7 +548,7 @@ private void showStreamDialog(final StreamInfoItem item) {
}
break;
case 3:
shareUrl(item.getName(), item.getUrl());
ShareUtils.shareUrl(this.getContext(), item.getName(), item.getUrl());
break;
default:
break;
Expand Down Expand Up @@ -626,13 +637,13 @@ public boolean onOptionsItemSelected(MenuItem item) {
switch (id) {
case R.id.menu_item_share: {
if (currentInfo != null) {
shareUrl(currentInfo.getName(), currentInfo.getOriginalUrl());
ShareUtils.shareUrl(this.getContext(), currentInfo.getName(), currentInfo.getOriginalUrl());
}
return true;
}
case R.id.menu_item_openInBrowser: {
if (currentInfo != null) {
openUrlInBrowser(currentInfo.getOriginalUrl());
ShareUtils.openUrlInBrowser(this.getContext(), currentInfo.getOriginalUrl());
}
return true;
}
Expand Down Expand Up @@ -813,6 +824,9 @@ public void startLoading(boolean forceLoad) {
}

private void initTabs() {
if (pageAdapter.getCount() != 0) {
selectedTabTag = pageAdapter.getItemTitle(viewPager.getCurrentItem());
}
pageAdapter.clearAllItems();

if(shouldShowComments()){
Expand All @@ -824,11 +838,17 @@ private void initTabs() {
pageAdapter.addFragment(new Fragment(), RELATED_TAB_TAG);
}

if(pageAdapter.getCount() == 0){
pageAdapter.addFragment(new EmptyFragment(), EMPTY_TAB_TAG);
}

pageAdapter.notifyDataSetUpdate();

if(pageAdapter.getCount() < 2){
tabLayout.setVisibility(View.GONE);
}else{
int position = pageAdapter.getItemPositionByTitle(selectedTabTag);
if(position != -1) viewPager.setCurrentItem(position);
tabLayout.setVisibility(View.VISIBLE);
}
}
Expand Down
Expand Up @@ -34,6 +34,7 @@
import org.schabi.newpipe.report.ErrorActivity;
import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.OnClickGesture;
import org.schabi.newpipe.util.ShareUtils;
import org.schabi.newpipe.util.StateSaver;

import java.util.Collections;
Expand Down Expand Up @@ -255,6 +256,7 @@ protected void showStreamDialog(final StreamInfoItem item) {
if (context == null || context.getResources() == null || getActivity() == null) return;

final String[] commands = new String[]{
context.getResources().getString(R.string.direct_on_background),
context.getResources().getString(R.string.enqueue_on_background),
context.getResources().getString(R.string.enqueue_on_popup),
context.getResources().getString(R.string.append_playlist),
Expand All @@ -264,19 +266,22 @@ protected void showStreamDialog(final StreamInfoItem item) {
final DialogInterface.OnClickListener actions = (dialogInterface, i) -> {
switch (i) {
case 0:
NavigationHelper.enqueueOnBackgroundPlayer(context, new SinglePlayQueue(item));
NavigationHelper.playOnBackgroundPlayer(context, new SinglePlayQueue(item));
break;
case 1:
NavigationHelper.enqueueOnPopupPlayer(activity, new SinglePlayQueue(item));
NavigationHelper.enqueueOnBackgroundPlayer(context, new SinglePlayQueue(item));
break;
case 2:
NavigationHelper.enqueueOnPopupPlayer(activity, new SinglePlayQueue(item));
break;
case 3:
if (getFragmentManager() != null) {
PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(item))
.show(getFragmentManager(), TAG);
}
break;
case 3:
shareUrl(item.getName(), item.getUrl());
case 4:
ShareUtils.shareUrl(this.getContext(), item.getName(), item.getUrl());
break;
default:
break;
Expand Down

0 comments on commit 1670751

Please sign in to comment.