1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2026-04-23 15:21:24 +00:00

Merge branch 'dev' into buttons-hiding-fix-on-screen-off

This commit is contained in:
Tobias Groza
2019-08-12 13:57:02 +02:00
committed by GitHub
54 changed files with 152 additions and 94 deletions

View File

@@ -3,15 +3,24 @@ package org.schabi.newpipe.database;
import android.arch.persistence.db.SupportSQLiteDatabase;
import android.arch.persistence.room.migration.Migration;
import android.support.annotation.NonNull;
import android.util.Log;
import org.schabi.newpipe.BuildConfig;
public class Migrations {
public static final int DB_VER_11_0 = 1;
public static final int DB_VER_12_0 = 2;
public static final boolean DEBUG = !BuildConfig.BUILD_TYPE.equals("release");
private static final String TAG = Migrations.class.getName();
public static final Migration MIGRATION_11_12 = new Migration(DB_VER_11_0, DB_VER_12_0) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
if(DEBUG) {
Log.d(TAG, "Start migrating database");
}
/*
* Unfortunately these queries must be hardcoded due to the possibility of
* schema and names changing at a later date, thus invalidating the older migration
@@ -56,6 +65,10 @@ public class Migrations {
"ORDER BY creation_date DESC");
database.execSQL("DROP TABLE IF EXISTS watch_history");
if(DEBUG) {
Log.d(TAG, "Stop migrating database");
}
}
};
}

View File

@@ -75,7 +75,6 @@ import org.schabi.newpipe.player.playqueue.PlayQueue;
import org.schabi.newpipe.player.playqueue.SinglePlayQueue;
import org.schabi.newpipe.report.ErrorActivity;
import org.schabi.newpipe.report.UserAction;
import org.schabi.newpipe.util.AnimationUtils;
import org.schabi.newpipe.util.Constants;
import org.schabi.newpipe.util.ExtractorHelper;
import org.schabi.newpipe.util.ImageDisplayConstants;
@@ -963,7 +962,7 @@ public class VideoDetailFragment
}
private void showContent() {
AnimationUtils.slideUp(contentRootLayoutHiding,120, 96, 0.06f);
contentRootLayoutHiding.setVisibility(View.VISIBLE);
}
protected void setInitialData(int serviceId, String url, String name) {
@@ -996,9 +995,14 @@ public class VideoDetailFragment
@Override
public void showLoading() {
super.showLoading();
contentRootLayoutHiding.setVisibility(View.INVISIBLE);
//if data is already cached, transition from VISIBLE -> INVISIBLE -> VISIBLE is not required
if(!ExtractorHelper.isCached(serviceId, url, InfoItem.InfoType.STREAM)){
contentRootLayoutHiding.setVisibility(View.INVISIBLE);
}
animateView(spinnerToolbar, false, 200);
animateView(thumbnailPlayButton, false, 50);
animateView(detailDurationView, false, 100);

View File

@@ -75,17 +75,14 @@ public abstract class StateObjectsListAdapter extends RecyclerView.Adapter<Recyc
protected void loadStates(List<InfoItem> list, int offset, Runnable callback) {
if (isPlaybackStatesVisible()) {
stateLoaders.add(
recordManager.loadStreamStateBatch(list)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(streamStateEntities -> {
appendStates(streamStateEntities, offset);
callback.run();
}, throwable -> {
if (BuildConfig.DEBUG) throwable.printStackTrace();
callback.run();
})
);
List<StreamStateEntity> streamStateEntities = null;
try {
streamStateEntities = recordManager.loadStreamStateBatch(list).blockingGet();
} catch (Exception e) {
if (BuildConfig.DEBUG) e.printStackTrace();
}
if(streamStateEntities != null) appendStates(streamStateEntities, offset);
callback.run();
} else {
callback.run();
}
@@ -93,17 +90,14 @@ public abstract class StateObjectsListAdapter extends RecyclerView.Adapter<Recyc
protected void loadState(InfoItem item, int offset, Runnable callback) {
if (isPlaybackStatesVisible()) {
stateLoaders.add(
recordManager.loadStreamState(item)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(streamStateEntities -> {
appendState(streamStateEntities[0], offset);
callback.run();
}, throwable -> {
if (BuildConfig.DEBUG) throwable.printStackTrace();
callback.run();
})
);
StreamStateEntity[] streamStateEntities = null;
try {
streamStateEntities = recordManager.loadStreamState(item).blockingGet();
} catch (Exception e) {
if (BuildConfig.DEBUG) e.printStackTrace();
}
if(streamStateEntities != null && streamStateEntities.length > 0) appendState(streamStateEntities[0], offset);
callback.run();
} else {
callback.run();
}
@@ -111,17 +105,14 @@ public abstract class StateObjectsListAdapter extends RecyclerView.Adapter<Recyc
protected void loadStatesForLocal(List<? extends LocalItem> list, int offset, Runnable callback) {
if (isPlaybackStatesVisible()) {
stateLoaders.add(
recordManager.loadLocalStreamStateBatch(list)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(streamStateEntities -> {
appendStates(streamStateEntities, offset);
callback.run();
}, throwable -> {
if (BuildConfig.DEBUG) throwable.printStackTrace();
callback.run();
})
);
List<StreamStateEntity> streamStateEntities = null;
try {
streamStateEntities = recordManager.loadLocalStreamStateBatch(list).blockingGet();
} catch (Exception e) {
if (BuildConfig.DEBUG) e.printStackTrace();
}
if(streamStateEntities != null) appendStates(streamStateEntities, offset);
callback.run();
} else {
callback.run();
}

View File

@@ -51,6 +51,7 @@ import java.util.List;
import io.reactivex.Completable;
import io.reactivex.Flowable;
import io.reactivex.Maybe;
import io.reactivex.Scheduler;
import io.reactivex.Single;
import io.reactivex.schedulers.Schedulers;
@@ -109,6 +110,11 @@ public class HistoryRecordManager {
.subscribeOn(Schedulers.io());
}
public Single<Integer> deleteCompelteStreamStateHistory() {
return Single.fromCallable(streamStateTable::deleteAll)
.subscribeOn(Schedulers.io());
}
public Flowable<List<StreamHistoryEntry>> getStreamHistory() {
return streamHistoryTable.getHistory().subscribeOn(Schedulers.io());
}
@@ -165,7 +171,7 @@ public class HistoryRecordManager {
.subscribeOn(Schedulers.io());
}
public Single<Integer> deleteWholeSearchHistory() {
public Single<Integer> deleteCompleteSearchHistory() {
return Single.fromCallable(searchHistoryTable::deleteAll)
.subscribeOn(Schedulers.io());
}
@@ -291,4 +297,5 @@ public class HistoryRecordManager {
public Single<Integer> removeOrphanedRecords() {
return Single.fromCallable(streamTable::deleteOrphans).subscribeOn(Schedulers.io());
}
}

View File

@@ -180,7 +180,7 @@ public class StatisticsPlaylistFragment
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
howManyDeleted -> Toast.makeText(getContext(),
R.string.view_history_deleted,
R.string.watch_history_deleted,
Toast.LENGTH_SHORT).show(),
throwable -> ErrorActivity.reportError(getContext(),
throwable,

View File

@@ -187,6 +187,7 @@ public abstract class BasePlayer implements
protected MediaSessionManager mediaSessionManager;
private boolean isPrepared = false;
private Disposable stateLoader;
//////////////////////////////////////////////////////////////////////////*/
@@ -283,16 +284,14 @@ public abstract class BasePlayer implements
) {
simpleExoPlayer.seekTo(playQueue.getIndex(), queue.getItem().getRecoveryPosition());
return;
} else if (intent.getBooleanExtra(RESUME_PLAYBACK, false) && isPlaybackResumeEnabled()) {
final PlayQueueItem item = queue.getItem();
if (item != null && item.getRecoveryPosition() == PlayQueueItem.RECOVERY_UNSET && isPlaybackResumeEnabled()) {
final Disposable stateLoader = recordManager.loadStreamState(item)
if (item != null && item.getRecoveryPosition() == PlayQueueItem.RECOVERY_UNSET) {
stateLoader = recordManager.loadStreamState(item)
.observeOn(AndroidSchedulers.mainThread())
.doFinally(() -> {
if (simpleExoPlayer == null) return; // doFinally called while closing
initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence,
/*playOnInit=*/true);
})
.doFinally(() -> initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence,
/*playOnInit=*/true))
.subscribe(
state -> queue.setRecovery(queue.getIndex(), state.getProgressTime()),
error -> {
@@ -334,13 +333,13 @@ public abstract class BasePlayer implements
simpleExoPlayer.removeListener(this);
simpleExoPlayer.stop();
simpleExoPlayer.release();
simpleExoPlayer = null;
}
if (isProgressLoopRunning()) stopProgressLoop();
if (playQueue != null) playQueue.dispose();
if (audioReactor != null) audioReactor.dispose();
if (playbackManager != null) playbackManager.dispose();
if (mediaSessionManager != null) mediaSessionManager.dispose();
if (stateLoader != null) stateLoader.dispose();
if (playQueueAdapter != null) {
playQueueAdapter.unsetSelectedListener();

View File

@@ -274,7 +274,7 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
else if (v instanceof String)
prefEdit.putString(key, ((String) v));
}
prefEdit.apply();
prefEdit.commit();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {

View File

@@ -51,11 +51,26 @@ public class HistorySettingsFragment extends BasePreferenceFragment {
.setTitle(R.string.delete_view_history_alert)
.setNegativeButton(R.string.cancel, ((dialog, which) -> dialog.dismiss()))
.setPositiveButton(R.string.delete, ((dialog, which) -> {
final Disposable onDeletePlaybackStates = recordManager.deleteCompelteStreamStateHistory()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
howManyDeleted -> Toast.makeText(getActivity(),
R.string.watch_history_states_deleted,
Toast.LENGTH_SHORT).show(),
throwable -> ErrorActivity.reportError(getContext(),
throwable,
SettingsActivity.class, null,
ErrorActivity.ErrorInfo.make(
UserAction.DELETE_FROM_HISTORY,
"none",
"Delete view history",
R.string.general_error)));
final Disposable onDelete = recordManager.deleteWholeStreamHistory()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
howManyDeleted -> Toast.makeText(getActivity(),
R.string.view_history_deleted,
R.string.watch_history_deleted,
Toast.LENGTH_SHORT).show(),
throwable -> ErrorActivity.reportError(getContext(),
throwable,
@@ -78,6 +93,7 @@ public class HistorySettingsFragment extends BasePreferenceFragment {
"none",
"Delete search history",
R.string.general_error)));
disposables.add(onDeletePlaybackStates);
disposables.add(onClearOrphans);
disposables.add(onDelete);
}))
@@ -90,7 +106,7 @@ public class HistorySettingsFragment extends BasePreferenceFragment {
.setTitle(R.string.delete_search_history_alert)
.setNegativeButton(R.string.cancel, ((dialog, which) -> dialog.dismiss()))
.setPositiveButton(R.string.delete, ((dialog, which) -> {
final Disposable onDelete = recordManager.deleteWholeSearchHistory()
final Disposable onDelete = recordManager.deleteCompleteSearchHistory()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
howManyDeleted -> Toast.makeText(getActivity(),

View File

@@ -228,6 +228,10 @@ public final class ExtractorHelper {
});
}
public static boolean isCached(final int serviceId, final String url, InfoItem.InfoType infoType) {
return null != loadFromCache(serviceId, url, infoType).blockingGet();
}
/**
* A simple and general error handler that show a Toast for known exceptions, and for others, opens the report error activity with the (optional) error message.
*/