Skip to content

Commit

Permalink
Merge pull request #3 from hapi-robo/dev
Browse files Browse the repository at this point in the history
Synchronize with upstream master
  • Loading branch information
r-oung committed Aug 21, 2020
2 parents c900ef0 + f1f0e7c commit cd9d682
Show file tree
Hide file tree
Showing 16 changed files with 111 additions and 101 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@
bin/
.vscode/
*.code-workspace

# temi-adaptation
*.apk
docs/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p align="center"><a href="https://newpipe.schabi.org"><img src="assets/new_pipe_icon_5.png" width="150"></a></p>
<h2 align="center"><b>NewPipe</b></h2>
<h2 align="center"><b>NewPipe (adapted for temi)</b></h2>
<h4 align="center">A libre lightweight streaming frontend for Android.</h4>
<p align="center"><a href="https://f-droid.org/packages/org.schabi.newpipe/"><img src="https://f-droid.org/wiki/images/0/06/F-Droid-button_get-it-on.png"></a></p>

Expand Down
14 changes: 8 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ android {
defaultConfig {
applicationId "org.schabi.newpipe"
resValue "string", "app_name", "NewPipe"
minSdkVersion 19
minSdkVersion 22
targetSdkVersion 29
versionCode 951
versionName "0.19.6"
versionCode 953
versionName "0.19.8"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand All @@ -37,7 +37,7 @@ android {
if (normalizedWorkingBranch.isEmpty() || workingBranch == "master" || workingBranch == "dev") {
// default values when branch name could not be determined or is master or dev
applicationIdSuffix ".debug"
resValue "string", "app_name", "NewPipe Debug"
resValue "string", "app_name", "NewPipe"
} else {
applicationIdSuffix ".debug." + normalizedWorkingBranch
resValue "string", "app_name", "NewPipe " + workingBranch
Expand All @@ -50,7 +50,7 @@ android {
// TODO: update Gradle version
release {
minifyEnabled true
shrinkResources true
shrinkResources false // disabled to fix F-Droid's reproducible build
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
archivesBaseName = 'app'
}
Expand Down Expand Up @@ -163,7 +163,7 @@ dependencies {
exclude module: 'support-annotations'
}

implementation 'com.github.TeamNewPipe:NewPipeExtractor:a70cb0283ffc3bba2709815673a5a7940aab0a3a'
implementation 'com.github.TeamNewPipe:NewPipeExtractor:5ac80624a40f4c600ae493e66881b5bf008f0ddb'

implementation "com.github.TeamNewPipe:nanojson:1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751"
implementation "org.jsoup:jsoup:1.13.1"
Expand Down Expand Up @@ -207,6 +207,8 @@ dependencies {
implementation "com.jakewharton.rxbinding2:rxbinding:2.2.0"

implementation "org.ocpsoft.prettytime:prettytime:4.0.5.Final"

implementation 'com.robotemi:sdk:0.10.65'
}

static String getGitWorkingBranch() {
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -334,5 +334,10 @@
<service
android:name=".RouterActivity$FetcherService"
android:exported="false" />

<!-- temi Meta Data -->
<meta-data
android:name="com.robotemi.sdk.metadata.SKILL"
android:value="@string/app_name"/>
</application>
</manifest>
2 changes: 1 addition & 1 deletion app/src/main/java/org/schabi/newpipe/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.os.Build;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager;

import com.nostra13.universalimageloader.cache.memory.impl.LRULimitedMemoryCache;
Expand Down Expand Up @@ -37,7 +38,6 @@
import java.util.Collections;
import java.util.List;

import io.reactivex.annotations.NonNull;
import io.reactivex.exceptions.CompositeException;
import io.reactivex.exceptions.MissingBackpressureException;
import io.reactivex.exceptions.OnErrorNotImplementedException;
Expand Down
38 changes: 37 additions & 1 deletion app/src/main/java/org/schabi/newpipe/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
Expand Down Expand Up @@ -52,6 +53,8 @@
import androidx.fragment.app.FragmentManager;

import com.google.android.material.navigation.NavigationView;
import com.robotemi.sdk.Robot;
import com.robotemi.sdk.listeners.OnRobotReadyListener;

import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
Expand Down Expand Up @@ -80,7 +83,7 @@

import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;

public class MainActivity extends AppCompatActivity {
public class MainActivity extends AppCompatActivity implements OnRobotReadyListener {
private static final String TAG = "MainActivity";
public static final boolean DEBUG = !BuildConfig.BUILD_TYPE.equals("release");

Expand All @@ -104,6 +107,8 @@ public class MainActivity extends AppCompatActivity {

private static final int ORDER = 0;

private Robot robot;

/*//////////////////////////////////////////////////////////////////////////
// Activity's LifeCycle
//////////////////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -140,6 +145,8 @@ && getSupportFragmentManager().getBackStackEntryCount() == 0) {
if (AndroidTvUtils.isTv(this)) {
FocusOverlayView.setupFocusObserver(this);
}

robot = Robot.getInstance();
}

private void setupDrawer() throws Exception {
Expand Down Expand Up @@ -742,4 +749,33 @@ private void handleIntent(final Intent intent) {
ErrorActivity.reportUiError(this, e);
}
}

/*//////////////////////////////////////////////////////////////////////////
// temi
//////////////////////////////////////////////////////////////////////////*/
@Override
protected void onStart() {
super.onStart();
robot.addOnRobotReadyListener(this);
}

@Override
protected void onStop() {
super.onStop();
robot.removeOnRobotReadyListener(this);
}

@Override
public void onRobotReady(final boolean isReady) {
if (isReady) {
try {
final ActivityInfo activityInfo = getPackageManager().getActivityInfo(
getComponentName(), PackageManager.GET_META_DATA);
robot.onStart(activityInfo);
} catch (PackageManager.NameNotFoundException e) {
throw new RuntimeException(e);
}
robot.hideTopBar();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,6 @@ public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences,
public void onSaveInstanceState(final Bundle outState) {
super.onSaveInstanceState(outState);

// Check if the next video label and video is visible,
// if it is, include the two elements in the next check
int nextCount = currentInfo != null && currentInfo.getNextVideo() != null ? 2 : 0;

if (!isLoading.get() && currentInfo != null && isVisible()) {
outState.putSerializable(INFO_KEY, currentInfo);
}
Expand Down Expand Up @@ -1018,14 +1014,14 @@ private VideoStream getSelectedVideoStream() {
}

private void prepareDescription(final Description description) {
if (TextUtils.isEmpty(description.getContent())
if (description == null || TextUtils.isEmpty(description.getContent())
|| description == Description.emptyDescription) {
return;
}

if (description.getType() == Description.HTML) {
disposables.add(Single.just(description.getContent())
.map((@io.reactivex.annotations.NonNull String descriptionText) -> {
.map((@NonNull String descriptionText) -> {
Spanned parsedDescription;
if (Build.VERSION.SDK_INT >= 24) {
parsedDescription = Html.fromHtml(descriptionText, 0);
Expand All @@ -1037,7 +1033,7 @@ private void prepareDescription(final Description description) {
})
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
.subscribe((@io.reactivex.annotations.NonNull Spanned spanned) -> {
.subscribe((@NonNull Spanned spanned) -> {
videoDescriptionView.setText(spanned);
videoDescriptionView.setVisibility(View.VISIBLE);
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,10 @@ protected void loadMoreItems() {
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doFinally(this::allowDownwardFocusScroll)
.subscribe((@io.reactivex.annotations.NonNull
ListExtractor.InfoItemsPage InfoItemsPage) -> {
.subscribe((@NonNull ListExtractor.InfoItemsPage InfoItemsPage) -> {
isLoading.set(false);
handleNextItems(InfoItemsPage);
}, (@io.reactivex.annotations.NonNull Throwable throwable) -> {
}, (@NonNull Throwable throwable) -> {
isLoading.set(false);
onError(throwable);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.Switch;

import androidx.annotation.NonNull;
Expand Down Expand Up @@ -40,22 +39,14 @@ public class RelatedVideosFragment extends BaseListInfoFragment<RelatedStreamInf
//////////////////////////////////////////////////////////////////////////*/

private View headerRootLayout;
private Switch aSwitch;

private boolean mIsVisibleToUser = false;
private Switch autoplaySwitch;

public static RelatedVideosFragment getInstance(final StreamInfo info) {
RelatedVideosFragment instance = new RelatedVideosFragment();
instance.setInitialData(info);
return instance;
}

@Override
public void setUserVisibleHint(final boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
mIsVisibleToUser = isVisibleToUser;
}

/*//////////////////////////////////////////////////////////////////////////
// LifeCycle
//////////////////////////////////////////////////////////////////////////*/
Expand All @@ -81,22 +72,18 @@ public void onDestroy() {
}

protected View getListHeader() {
if (relatedStreamInfo != null && relatedStreamInfo.getNextStream() != null) {
if (relatedStreamInfo != null && relatedStreamInfo.getRelatedItems() != null) {
headerRootLayout = activity.getLayoutInflater()
.inflate(R.layout.related_streams_header, itemsList, false);
aSwitch = headerRootLayout.findViewById(R.id.autoplay_switch);

SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getContext());
Boolean autoplay = pref.getBoolean(getString(R.string.auto_queue_key), false);
aSwitch.setChecked(autoplay);
aSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton compoundButton,
final boolean b) {
autoplaySwitch = headerRootLayout.findViewById(R.id.autoplay_switch);

final SharedPreferences pref = PreferenceManager
.getDefaultSharedPreferences(getContext());
final boolean autoplay = pref.getBoolean(getString(R.string.auto_queue_key), false);
autoplaySwitch.setChecked(autoplay);
autoplaySwitch.setOnCheckedChangeListener((compoundButton, b) ->
PreferenceManager.getDefaultSharedPreferences(getContext()).edit()
.putBoolean(getString(R.string.auto_queue_key), b).apply();
}
});
.putBoolean(getString(R.string.auto_queue_key), b).apply());
return headerRootLayout;
} else {
return null;
Expand All @@ -105,7 +92,7 @@ public void onCheckedChanged(final CompoundButton compoundButton,

@Override
protected Single<ListExtractor.InfoItemsPage> loadMoreItemsLogic() {
return Single.fromCallable(() -> ListExtractor.InfoItemsPage.emptyPage());
return Single.fromCallable(ListExtractor.InfoItemsPage::emptyPage);
}

/*//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -216,8 +203,8 @@ public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences,
final String s) {
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean autoplay = pref.getBoolean(getString(R.string.auto_queue_key), false);
if (null != aSwitch) {
aSwitch.setChecked(autoplay);
if (autoplaySwitch != null) {
autoplaySwitch.setChecked(autoplay);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,17 @@ public static String cacheKeyOf(@NonNull final StreamInfo info,
}

/**
* Given a {@link StreamInfo} and the existing queue items, provide the
* {@link SinglePlayQueue} consisting of the next video for auto queuing.
* Given a {@link StreamInfo} and the existing queue items,
* provide the {@link SinglePlayQueue} consisting of the next video for auto queueing.
* <p>
* This method detects and prevents cycle by naively checking if a
* candidate next video's url already exists in the existing items.
* This method detects and prevents cycles by naively checking
* if a candidate next video's url already exists in the existing items.
* </p>
* <p>
* To select the next video, {@link StreamInfo#getNextVideo()} is first
* checked. If it is nonnull and is not part of the existing items, then
* it will be used as the next video. Otherwise, an random item with
* non-repeating url will be selected from the {@link StreamInfo#getRelatedStreams()}.
* The first item in {@link StreamInfo#getRelatedStreams()} is checked first.
* If it is non-null and is not part of the existing items, it will be used as the next stream.
* Otherwise, a random item with non-repeating url will be selected
* from the {@link StreamInfo#getRelatedStreams()}.
* </p>
*
* @param info currently playing stream
Expand All @@ -152,27 +152,28 @@ public static String cacheKeyOf(@NonNull final StreamInfo info,
@Nullable
public static PlayQueue autoQueueOf(@NonNull final StreamInfo info,
@NonNull final List<PlayQueueItem> existingItems) {
Set<String> urls = new HashSet<>(existingItems.size());
final Set<String> urls = new HashSet<>(existingItems.size());
for (final PlayQueueItem item : existingItems) {
urls.add(item.getUrl());
}

final StreamInfoItem nextVideo = info.getNextVideo();
if (nextVideo != null && !urls.contains(nextVideo.getUrl())) {
return getAutoQueuedSinglePlayQueue(nextVideo);
}

final List<InfoItem> relatedItems = info.getRelatedStreams();
if (relatedItems == null) {
return null;
}

List<StreamInfoItem> autoQueueItems = new ArrayList<>();
for (final InfoItem item : info.getRelatedStreams()) {
if (relatedItems.get(0) != null && relatedItems.get(0) instanceof StreamInfoItem
&& !urls.contains(relatedItems.get(0).getUrl())) {
return getAutoQueuedSinglePlayQueue((StreamInfoItem) relatedItems.get(0));
}

final List<StreamInfoItem> autoQueueItems = new ArrayList<>();
for (final InfoItem item : relatedItems) {
if (item instanceof StreamInfoItem && !urls.contains(item.getUrl())) {
autoQueueItems.add((StreamInfoItem) item);
}
}

Collections.shuffle(autoQueueItems);
return autoQueueItems.isEmpty()
? null : getAutoQueuedSinglePlayQueue(autoQueueItems.get(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import android.util.Log;

import androidx.annotation.NonNull;

import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.ListInfo;
Expand All @@ -13,7 +15,6 @@
import java.util.List;

import io.reactivex.SingleObserver;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;

abstract class AbstractInfoPlayQueue<T extends ListInfo, U extends InfoItem> extends PlayQueue {
Expand Down
Loading

0 comments on commit cd9d682

Please sign in to comment.