Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@

<activity
android:name=".ReCaptchaActivity"
android:label="@string/recaptcha"/>
android:label="@string/recaptcha" />

<provider
android:name="androidx.core.content.FileProvider"
Expand Down
14 changes: 7 additions & 7 deletions app/src/main/java/org/schabi/newpipe/ReCaptchaActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import androidx.core.app.NavUtils;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
Expand All @@ -16,6 +11,11 @@
import android.webkit.WebView;
import android.webkit.WebViewClient;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.app.NavUtils;

import org.schabi.newpipe.util.ThemeHelper;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -137,10 +137,10 @@ private void saveCookiesAndFinish() {
}



private void handleCookies(String url) {
String cookies = CookieManager.getInstance().getCookie(url);
if (MainActivity.DEBUG) Log.d(TAG, "handleCookies: url=" + url + "; cookies=" + (cookies == null ? "null" : cookies));
if (MainActivity.DEBUG)
Log.d(TAG, "handleCookies: url=" + url + "; cookies=" + (cookies == null ? "null" : cookies));
if (cookies == null) return;

addYoutubeCookies(cookies);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import io.reactivex.disposables.Disposable;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
import org.schabi.newpipe.NewPipeDatabase;
Expand All @@ -39,6 +39,7 @@
import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;

public final class BookmarkFragment
extends BaseLocalListFragment<List<PlaylistLocalItem>, Void> {
Expand Down Expand Up @@ -261,17 +262,17 @@ private void showLocalDialog(PlaylistMetadataEntry selectedItem) {

Builder builder = new AlertDialog.Builder(activity);
builder.setView(dialogView)
.setPositiveButton(R.string.rename_playlist, (dialog, which) -> {
changeLocalPlaylistName(selectedItem.uid, editText.getText().toString());
})
.setNegativeButton(R.string.cancel, null)
.setNeutralButton(R.string.delete, (dialog, which) -> {
showDeleteDialog(selectedItem.name,
localPlaylistManager.deletePlaylist(selectedItem.uid));
dialog.dismiss();
})
.create()
.show();
.setPositiveButton(R.string.rename_playlist, (dialog, which) -> {
changeLocalPlaylistName(selectedItem.uid, editText.getText().toString());
})
.setNegativeButton(R.string.cancel, null)
.setNeutralButton(R.string.delete, (dialog, which) -> {
showDeleteDialog(selectedItem.name,
localPlaylistManager.deletePlaylist(selectedItem.uid));
dialog.dismiss();
})
.create()
.show();
}

private void showDeleteDialog(final String name, final Single<Integer> deleteReactor) {
Expand All @@ -297,13 +298,13 @@ private void changeLocalPlaylistName(long id, String name) {

if (DEBUG) {
Log.d(TAG, "Updating playlist id=[" + id +
"] with new name=[" + name + "] items");
"] with new name=[" + name + "] items");
}

localPlaylistManager.renamePlaylist(id, name);
final Disposable disposable = localPlaylistManager.renamePlaylist(id, name)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(longs -> {/*Do nothing on success*/}, this::onError);
.observeOn(AndroidSchedulers.mainThread())
.subscribe(longs -> {/*Do nothing on success*/}, this::onError);
disposables.add(disposable);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ private void changePlaylistName(final String name) {

if (DEBUG) {
Log.d(TAG, "Updating playlist id=[" + playlistId +
"] with new name=[" + name + "] items");
"] with new name=[" + name + "] items");
}

final Disposable disposable = playlistManager.renamePlaylist(playlistId, name)
Expand All @@ -408,7 +408,7 @@ private void changeThumbnailUrl(final String thumbnailUrl) {

if (DEBUG) {
Log.d(TAG, "Updating playlist id=[" + playlistId +
"] with new thumbnail url=[" + thumbnailUrl + "]");
"] with new thumbnail url=[" + thumbnailUrl + "]");
}

final Disposable disposable = playlistManager
Expand Down Expand Up @@ -478,7 +478,7 @@ private void saveImmediate() {

if (DEBUG) {
Log.d(TAG, "Updating playlist id=[" + playlistId +
"] with [" + streamIds.size() + "] items");
"] with [" + streamIds.size() + "] items");
}

final Disposable disposable = playlistManager.updateJoin(playlistId, streamIds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@
import android.graphics.Bitmap;
import android.os.Build;
import android.os.IBinder;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationCompat;

import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.widget.RemoteViews;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationCompat;

import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.source.MediaSource;
Expand Down Expand Up @@ -211,10 +211,7 @@ private NotificationCompat.Builder createNotification() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setLockScreenThumbnail(builder);
}

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
builder.setPriority(NotificationCompat.PRIORITY_MAX);
}
builder.setPriority(NotificationCompat.PRIORITY_MAX);
return builder;
}

Expand Down
56 changes: 56 additions & 0 deletions app/src/main/java/org/schabi/newpipe/player/BasePlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.AudioManager;
import android.os.Handler;
import android.os.Looper;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
Expand Down Expand Up @@ -78,6 +80,9 @@

import java.io.IOException;
import java.net.UnknownHostException;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
Expand Down Expand Up @@ -193,6 +198,17 @@ public abstract class BasePlayer implements

//////////////////////////////////////////////////////////////////////////*/


/*//////////////////////////////////////////////////////////////////////////
// Timer
//////////////////////////////////////////////////////////////////////////*/

private Timer timer = new Timer();
private int timerHour = 0;
private int timerMinute = 0;
Comment on lines +207 to +208
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove these


//////////////////////////////////////////////////////////////////////////*/

public BasePlayer(@NonNull final Context context) {
this.context = context;

Expand Down Expand Up @@ -1285,4 +1301,44 @@ private boolean isPlaybackResumeEnabled() {
return prefs.getBoolean(context.getString(R.string.enable_watch_history_key), true)
&& prefs.getBoolean(context.getString(R.string.enable_playback_resume_key), true);
}

public void setTimer(int hourOfDay, int minute, Context ctx) {
long time = ((hourOfDay * 60) + minute) * 60 * 1000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a logical error here.
I suggested you to use the number picker which would indeed return the remaining hours and minutes to pause the player. But when using the TimePicker you get the actual time of the day wich means the player will be paused at a completely different time. You add the selected time to the current time. Selecting 11:45AM means that the timer will pause the player in 11 hours and 45 minutes, but not at 11:45AM.But the TimePicker is intended to give people a specific time to select.
For this reason, the best thing would be to implement something which lets you pick the remaining time.

if (time == 0) {
Toast.makeText(ctx, ctx.getString(R.string.timer_select_time_message), Toast.LENGTH_SHORT).show();
return;
}
timer.cancel();
timer.purge();
timerHour = hourOfDay;
timerMinute = minute;
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
new Handler(Looper.getMainLooper()).post(() -> {
if (DEBUG) Log.d(TAG, "Timer finished: Stopping the player");
onPause();
});

}
}, time);
Date d = new Date();
d.setTime(System.currentTimeMillis() + time);
Toast.makeText(ctx.getApplicationContext(), String.format(ctx.getString(R.string.player_stop_message), d.toString()), Toast.LENGTH_LONG).show();
Comment on lines +1306 to +1328
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Format suggestion:

        long time = ((hourOfDay * 60) + minute) * 60 * 1000;
        if (time == 0) {
            Toast.makeText(ctx, ctx.getString(R.string.timer_select_time_message), Toast.LENGTH_SHORT).show();
            return;
        }

        timer.cancel();
        timer.purge();
        timer = new Timer();
        timer.schedule(() -> {
            if (DEBUG) Log.d(TAG, "Timer finished: stopping the player");
            onPause();
        }, time);

        Date d = new Date();
        d.setTime(System.currentTimeMillis() + time);
        Toast.makeText(ctx.getApplicationContext(), String.format(ctx.getString(R.string.player_stop_message), d.toString()), Toast.LENGTH_LONG).show();

There is an issue: the user should be able to cancel the timer at any time, not just during the Toast.LENGTH_LONG time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, we need a custom TimePickerDialog which allows us to add

  1. A title which says something like "Select time to stop playback at"
  2. Buttons at the bottom to stop the timer

}

public void cancelTimer() {
timer.cancel();
timer.purge();
}

public int getHourOfDay() {
return this.timerHour;
}

public int getMinutes() {
return this.timerMinute;
}
Comment on lines +1335 to +1342
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete these, there is no need to store these values in the Player class.


}
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package org.schabi.newpipe.player;

import android.app.TimePickerDialog;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.provider.Settings;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.ItemTouchHelper;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
Expand All @@ -23,6 +19,12 @@
import android.widget.SeekBar;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player;

Expand Down Expand Up @@ -92,6 +94,7 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
private TextView playbackSpeedButton;
private TextView playbackPitchButton;


////////////////////////////////////////////////////////////////////////////
// Abstracts
////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -164,10 +167,19 @@ public boolean onOptionsItemSelected(MenuItem item) {
return true;
case R.id.action_switch_main:
return switchTo(MainVideoPlayer.class);
case R.id.action_set_timer:
updateTimer(this);
return true;
}
return onPlayerOptionSelected(item) || super.onOptionsItemSelected(item);
}

private void updateTimer(ServicePlayerActivity servicePlayerActivity) {
TimePickerDialog dialog = new TimePickerDialog(servicePlayerActivity, (view, hourOfDay, minute) ->
player.setTimer(hourOfDay, minute, getApplicationContext()), player.getHourOfDay(), player.getMinutes(), true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case we keep the TimePicker, you should initialize the clock with the current time if no timer is running and check if the user has enabled 24 hour format: DateFormat.is24HourFormat(servicePlayerActivity) works when importing android.text.format.

dialog.show();
}

@Override
protected void onDestroy() {
super.onDestroy();
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/baseline_timer_black_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M15,1L9,1v2h6L15,1zM11,14h2L13,8h-2v6zM19.03,7.39l1.42,-1.42c-0.43,-0.51 -0.9,-0.99 -1.41,-1.41l-1.42,1.42C16.07,4.74 14.12,4 12,4c-4.97,0 -9,4.03 -9,9s4.02,9 9,9 9,-4.03 9,-9c0,-2.12 -0.74,-4.07 -1.97,-5.61zM12,20c-3.87,0 -7,-3.13 -7,-7s3.13,-7 7,-7 7,3.13 7,7 -3.13,7 -7,7z" />
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/baseline_timer_white_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M15,1L9,1v2h6L15,1zM11,14h2L13,8h-2v6zM19.03,7.39l1.42,-1.42c-0.43,-0.51 -0.9,-0.99 -1.41,-1.41l-1.42,1.42C16.07,4.74 14.12,4 12,4c-4.97,0 -9,4.03 -9,9s4.02,9 9,9 9,-4.03 9,-9c0,-2.12 -0.74,-4.07 -1.97,-5.61zM12,20c-3.87,0 -7,-3.13 -7,-7s3.13,-7 7,-7 7,3.13 7,7 -3.13,7 -7,7z" />
</vector>
10 changes: 5 additions & 5 deletions app/src/main/res/drawable/ic_done_black_24dp.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M9,16.2L4.8,12l-1.4,1.4L9,19 21,7l-1.4,-1.4L9,16.2z"/>
android:pathData="M9,16.2L4.8,12l-1.4,1.4L9,19 21,7l-1.4,-1.4L9,16.2z" />
</vector>
13 changes: 9 additions & 4 deletions app/src/main/res/drawable/ic_done_white_24dp.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M9,16.2L4.8,12l-1.4,1.4L9,19 21,7l-1.4,-1.4L9,16.2z"/>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#FFFFFF"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M9,16.2L4.8,12l-1.4,1.4L9,19 21,7l-1.4,-1.4L9,16.2z" />
</vector>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_recaptcha.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.ActionBar"
app:titleTextAppearance="@style/Toolbar.Title"/>
app:titleTextAppearance="@style/Toolbar.Title" />

<WebView
android:id="@+id/reCaptchaWebView"
Expand Down
Loading