1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2025-10-24 20:07:39 +00:00

Merge branch 'dev' into trending

This commit is contained in:
Christian Schabesberger
2017-09-23 20:39:01 +02:00
committed by GitHub
50 changed files with 792 additions and 77 deletions

View File

@@ -26,6 +26,9 @@ android {
debuggable true
applicationIdSuffix ".debug"
}
beta {
applicationIdSuffix ".beta"
}
}
lintOptions {
@@ -44,7 +47,7 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2') {
exclude module: 'support-annotations'
}
compile 'com.github.TeamNewPipe:NewPipeExtractor:7fffef5'
testCompile 'junit:junit:4.12'
@@ -62,7 +65,7 @@ dependencies {
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.github.nirhart:parallaxscroll:1.0'
compile 'com.nononsenseapps:filepicker:3.0.0'
compile 'com.nononsenseapps:filepicker:3.0.1'
compile 'com.google.android.exoplayer:exoplayer:r2.5.1'
debugCompile 'com.facebook.stetho:stetho:1.5.0'

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:label="NewPipe Beta"
tools:replace="android:label">
</application>
</manifest>

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@@ -88,10 +88,14 @@
<service android:name="us.shandian.giga.service.DownloadManagerService"/>
<activity
android:name="com.nononsenseapps.filepicker.FilePickerActivity"
android:name=".util.FilePickerActivityHelper"
android:label="@string/app_name"
android:launchMode="singleTop"
android:theme="@style/FilePickerTheme"/>
android:theme="@style/FilePickerThemeDark">
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".ReCaptchaActivity"

View File

@@ -43,9 +43,8 @@ public class RouterActivity extends AppCompatActivity {
}
protected void handleUrl(String url) {
try {
NavigationHelper.openByLink(this, url);
} catch (Exception e) {
boolean success = NavigationHelper.openByLink(this, url);
if (!success) {
Toast.makeText(this, R.string.url_not_supported_toast, Toast.LENGTH_LONG).show();
}

View File

@@ -34,6 +34,7 @@ import org.schabi.newpipe.ReCaptchaActivity;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.search.SearchEngine;
import org.schabi.newpipe.extractor.search.SearchResult;
@@ -47,12 +48,14 @@ import org.schabi.newpipe.util.StateSaver;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import icepick.State;
import io.reactivex.Notification;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;
@@ -97,6 +100,7 @@ public class SearchFragment extends BaseListFragment<SearchResult, ListExtractor
private PublishSubject<String> suggestionPublisher = PublishSubject.create();
private Disposable searchDisposable;
private Disposable suggestionWorkerDisposable;
private CompositeDisposable disposables = new CompositeDisposable();
private SuggestionListAdapter suggestionListAdapter;
@@ -149,6 +153,7 @@ public class SearchFragment extends BaseListFragment<SearchResult, ListExtractor
if (searchDisposable != null) searchDisposable.dispose();
if (suggestionWorkerDisposable != null) suggestionWorkerDisposable.dispose();
if (disposables != null) disposables.clear();
hideSoftKeyboard(searchEditText);
}
@@ -192,6 +197,7 @@ public class SearchFragment extends BaseListFragment<SearchResult, ListExtractor
if (searchDisposable != null) searchDisposable.dispose();
if (suggestionWorkerDisposable != null) suggestionWorkerDisposable.dispose();
if (disposables != null) disposables.clear();
}
@Override
@@ -514,6 +520,38 @@ public class SearchFragment extends BaseListFragment<SearchResult, ListExtractor
private void search(final String query) {
if (DEBUG) Log.d(TAG, "search() called with: query = [" + query + "]");
try {
final StreamingService service = NewPipe.getServiceByUrl(query);
if (service != null) {
showLoading();
disposables.add(Observable
.fromCallable(new Callable<Intent>() {
@Override
public Intent call() throws Exception {
return NavigationHelper.getIntentByLink(activity, service, query);
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<Intent>() {
@Override
public void accept(Intent intent) throws Exception {
getFragmentManager().popBackStackImmediate();
activity.startActivity(intent);
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
showError(getString(R.string.url_not_supported_toast), false);
hideLoading();
}
}));
return;
}
} catch (Exception e) {
// Exception occurred, it's not a url
}
hideSoftKeyboard(searchEditText);
this.searchQuery = query;
this.currentPage = 0;
@@ -532,6 +570,7 @@ public class SearchFragment extends BaseListFragment<SearchResult, ListExtractor
@Override
public void startLoading(boolean forceLoad) {
super.startLoading(forceLoad);
if (disposables != null) disposables.clear();
if (searchDisposable != null) searchDisposable.dispose();
searchDisposable = ExtractorHelper.searchFor(serviceId, searchQuery, currentPage, searchLanguage, filter)
.subscribeOn(Schedulers.io())

View File

@@ -7,9 +7,8 @@ import android.support.annotation.Nullable;
import android.support.v7.preference.Preference;
import android.util.Log;
import com.nononsenseapps.filepicker.FilePickerActivity;
import org.schabi.newpipe.R;
import org.schabi.newpipe.util.FilePickerActivityHelper;
public class DownloadSettingsFragment extends BasePreferenceFragment {
private static final int REQUEST_DOWNLOAD_PATH = 0x1235;
@@ -48,10 +47,10 @@ public class DownloadSettingsFragment extends BasePreferenceFragment {
}
if (preference.getKey().equals(DOWNLOAD_PATH_PREFERENCE) || preference.getKey().equals(DOWNLOAD_PATH_AUDIO_PREFERENCE)) {
Intent i = new Intent(getActivity(), FilePickerActivity.class)
.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false)
.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, true)
.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_DIR);
Intent i = new Intent(getActivity(), FilePickerActivityHelper.class)
.putExtra(FilePickerActivityHelper.EXTRA_ALLOW_MULTIPLE, false)
.putExtra(FilePickerActivityHelper.EXTRA_ALLOW_CREATE_DIR, true)
.putExtra(FilePickerActivityHelper.EXTRA_MODE, FilePickerActivityHelper.MODE_DIR);
if (preference.getKey().equals(DOWNLOAD_PATH_PREFERENCE)) {
startActivityForResult(i, REQUEST_DOWNLOAD_PATH);
} else if (preference.getKey().equals(DOWNLOAD_PATH_AUDIO_PREFERENCE)) {

View File

@@ -0,0 +1,17 @@
package org.schabi.newpipe.util;
import android.os.Bundle;
import org.schabi.newpipe.R;
public class FilePickerActivityHelper extends com.nononsenseapps.filepicker.FilePickerActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
if(ThemeHelper.isLightThemeSelected(this)) {
this.setTheme(R.style.FilePickerThemeLight);
} else {
this.setTheme(R.style.FilePickerThemeDark);
}
super.onCreate(savedInstanceState);
}
}

View File

@@ -14,7 +14,9 @@ import org.schabi.newpipe.R;
import org.schabi.newpipe.about.AboutActivity;
import org.schabi.newpipe.download.DownloadActivity;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.stream.AudioStream;
import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.fragments.MainFragment;
@@ -228,13 +230,17 @@ public class NavigationHelper {
// Link handling
//////////////////////////////////////////////////////////////////////////*/
public static void openByLink(Context context, String url) throws Exception {
Intent intentByLink = getIntentByLink(context, url);
if (intentByLink == null)
throw new NullPointerException("getIntentByLink(context = [" + context + "], url = [" + url + "]) returned null");
public static boolean openByLink(Context context, String url) {
Intent intentByLink;
try {
intentByLink = getIntentByLink(context, url);
} catch (ExtractionException e) {
return false;
}
intentByLink.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intentByLink.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
context.startActivity(intentByLink);
return true;
}
private static Intent getOpenIntent(Context context, String url, int serviceId, StreamingService.LinkType type) {
@@ -245,14 +251,20 @@ public class NavigationHelper {
return mIntent;
}
private static Intent getIntentByLink(Context context, String url) throws Exception {
StreamingService service = NewPipe.getServiceByUrl(url);
public static Intent getIntentByLink(Context context, String url) throws ExtractionException {
return getIntentByLink(context, NewPipe.getServiceByUrl(url), url);
}
public static Intent getIntentByLink(Context context, StreamingService service, String url) throws ExtractionException {
if (service != ServiceList.YouTube.getService()) {
throw new ExtractionException("Service not supported at the moment");
}
int serviceId = service.getServiceId();
StreamingService.LinkType linkType = service.getLinkTypeByUrl(url);
if (linkType == StreamingService.LinkType.NONE) {
throw new Exception("Url not known to service. service=" + serviceId + " url=" + url);
throw new ExtractionException("Url not known to service. service=" + serviceId + " url=" + url);
}
url = getCleanUrl(service, url, linkType);
@@ -268,7 +280,7 @@ public class NavigationHelper {
return rIntent;
}
private static String getCleanUrl(StreamingService service, String dirtyUrl, StreamingService.LinkType linkType) throws Exception {
private static String getCleanUrl(StreamingService service, String dirtyUrl, StreamingService.LinkType linkType) throws ExtractionException {
switch (linkType) {
case STREAM:
return service.getStreamUrlIdHandler().cleanUrl(dirtyUrl);

View File

@@ -101,6 +101,18 @@ public class DownloadManagerImpl implements DownloadManager {
}
/**
* Sort a list of mission by its timestamp. Oldest first
* @param missions the missions to sort
*/
static void sortByTimestamp(List<DownloadMission> missions) {
Collections.sort(missions, new Comparator<DownloadMission>() {
@Override
public int compare(DownloadMission o1, DownloadMission o2) {
return Long.valueOf(o1.timestamp).compareTo(o2.timestamp);
}
});
}
/**
* Loads finished missions from the data source
@@ -111,12 +123,8 @@ public class DownloadManagerImpl implements DownloadManager {
finishedMissions = new ArrayList<>();
}
// Ensure its sorted
Collections.sort(finishedMissions, new Comparator<DownloadMission>() {
@Override
public int compare(DownloadMission o1, DownloadMission o2) {
return (int) (o1.timestamp - o2.timestamp);
}
});
sortByTimestamp(finishedMissions);
mMissions.ensureCapacity(mMissions.size() + finishedMissions.size());
for (DownloadMission mission : finishedMissions) {
File downloadedFile = mission.getDownloadedFile();

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 788 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#CD201F</color>
</resources>

View File

@@ -51,7 +51,7 @@
<string-array name="video_format_description_list" translatable="false">
<item>MPEG-4</item>
<item>WebM</item>
<item>3GPP</item>
<item>3GP</item>
</string-array>
<string-array name="video_format_values_list" translatable="false">
<item>@string/video_mp4_key</item>

View File

@@ -109,23 +109,47 @@
<item name="background">@color/video_overlay_color</item>
</style>
<!-- You can also inherit from NNF_BaseTheme.Light -->
<style name="FilePickerTheme" parent="NNF_BaseTheme.Light">
<!-- Set these to match your theme -->
<style name="FilePickerThemeLight" parent="NNF_BaseTheme.Light">
<item name="colorPrimary">@color/light_youtube_primary_color</item>
<item name="colorPrimaryDark">@color/light_youtube_dark_color</item>
<item name="colorAccent">@color/light_youtube_accent_color</item>
<item name="android:background">@color/light_background_color</item>
<item name="nnf_separator_color">@color/light_separator_color</item>
<!-- Need to set this also to style create folder dialog -->
<item name="alertDialogTheme">@style/FilePickerAlertDialogTheme</item>
<!-- If you want to set a specific toolbar theme, do it here -->
<!-- <item name="nnf_toolbarTheme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item> -->
<item name="alertDialogTheme">@style/FilePickerAlertDialogThemeLight</item>
<item name="nnf_toolbarTheme">@style/FilePickerToolbarLight</item>
</style>
<style name="FilePickerAlertDialogTheme" parent="Theme.AppCompat.Dialog.Alert">
<style name="FilePickerAlertDialogThemeLight" parent="Theme.AppCompat.Dialog.Alert">
<item name="colorPrimary">@color/light_youtube_primary_color</item>
<item name="colorPrimaryDark">@color/light_youtube_dark_color</item>
<item name="colorAccent">@color/light_youtube_accent_color</item>
</style>
<style name="FilePickerToolbarLight" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:background">@color/light_youtube_primary_color</item>
</style>
<style name="FilePickerThemeDark" parent="FilePickerThemeLight">
<item name="colorPrimary">@color/dark_youtube_primary_color</item>
<item name="colorPrimaryDark">@color/dark_youtube_dark_color</item>
<item name="colorAccent">@color/dark_youtube_accent_color</item>
<item name="android:background">@color/dark_background_color</item>
<item name="android:textColorPrimary">@color/dark_youtube_accent_color</item>
<item name="nnf_separator_color">@color/black_separator_color</item>
<item name="alertDialogTheme">@style/FilePickerAlertDialogThemeDark</item>
<item name="nnf_toolbarTheme">@style/FilePickerToolbarDark</item>
</style>
<style name="FilePickerAlertDialogThemeDark" parent="Theme.AppCompat.Dialog.Alert">
<item name="colorPrimary">@color/dark_youtube_primary_color</item>
<item name="colorPrimaryDark">@color/dark_youtube_dark_color</item>
<item name="colorAccent">@color/dark_youtube_accent_color</item>
</style>
<style name="FilePickerToolbarDark" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:background">@color/dark_youtube_primary_color</item>
</style>
</resources>

View File

@@ -1,4 +1,4 @@
package us.shandian.giga.get.get;
package us.shandian.giga.get;
import org.junit.Ignore;
import org.junit.Test;
@@ -153,4 +153,34 @@ public class DownloadManagerImplTest {
assertSame(missions.get(1), downloadManager.getMission(1));
}
@Test
public void sortByTimestamp() throws Exception {
ArrayList<DownloadMission> downloadMissions = new ArrayList<>();
DownloadMission mission = new DownloadMission();
mission.timestamp = 0;
DownloadMission mission1 = new DownloadMission();
mission1.timestamp = Integer.MAX_VALUE + 1L;
DownloadMission mission2 = new DownloadMission();
mission2.timestamp = 2L * Integer.MAX_VALUE ;
DownloadMission mission3 = new DownloadMission();
mission3.timestamp = 2L * Integer.MAX_VALUE + 5L;
downloadMissions.add(mission3);
downloadMissions.add(mission1);
downloadMissions.add(mission2);
downloadMissions.add(mission);
DownloadManagerImpl.sortByTimestamp(downloadMissions);
assertEquals(mission, downloadMissions.get(0));
assertEquals(mission1, downloadMissions.get(1));
assertEquals(mission2, downloadMissions.get(2));
assertEquals(mission3, downloadMissions.get(3));
}
}