-Merged bookmark buttons on playlist fragment into one.
-Fixed bookmark button flickering on visibility toggling. -Removed toolbar up button control from local fragments, delegating functionality back to main fragment. -Updated extractor to latest.
This commit is contained in:
parent
d0808ce159
commit
f62ae930c7
|
@ -55,7 +55,7 @@ dependencies {
|
||||||
exclude module: 'support-annotations'
|
exclude module: 'support-annotations'
|
||||||
}
|
}
|
||||||
|
|
||||||
implementation 'com.github.TeamNewPipe:NewPipeExtractor:7fd21ec08581d'
|
implementation 'com.github.TeamNewPipe:NewPipeExtractor:4fb49d54b5'
|
||||||
|
|
||||||
testImplementation 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.12'
|
||||||
testImplementation 'org.mockito:mockito-core:1.10.19'
|
testImplementation 'org.mockito:mockito-core:1.10.19'
|
||||||
|
|
|
@ -36,13 +36,16 @@ import org.schabi.newpipe.playlist.SinglePlayQueue;
|
||||||
import org.schabi.newpipe.report.UserAction;
|
import org.schabi.newpipe.report.UserAction;
|
||||||
import org.schabi.newpipe.util.ExtractorHelper;
|
import org.schabi.newpipe.util.ExtractorHelper;
|
||||||
import org.schabi.newpipe.util.NavigationHelper;
|
import org.schabi.newpipe.util.NavigationHelper;
|
||||||
|
import org.schabi.newpipe.util.ThemeHelper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import io.reactivex.Single;
|
import io.reactivex.Single;
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.disposables.CompositeDisposable;
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
import io.reactivex.disposables.Disposable;
|
import io.reactivex.disposables.Disposable;
|
||||||
|
import io.reactivex.disposables.Disposables;
|
||||||
|
|
||||||
import static org.schabi.newpipe.util.AnimationUtils.animateView;
|
import static org.schabi.newpipe.util.AnimationUtils.animateView;
|
||||||
|
|
||||||
|
@ -50,6 +53,7 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
|
||||||
|
|
||||||
private CompositeDisposable disposables;
|
private CompositeDisposable disposables;
|
||||||
private Subscription bookmarkReactor;
|
private Subscription bookmarkReactor;
|
||||||
|
private AtomicBoolean isBookmarkButtonReady;
|
||||||
|
|
||||||
private RemotePlaylistManager remotePlaylistManager;
|
private RemotePlaylistManager remotePlaylistManager;
|
||||||
private PlaylistRemoteEntity playlistEntity;
|
private PlaylistRemoteEntity playlistEntity;
|
||||||
|
@ -70,7 +74,6 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
|
||||||
private View headerBackgroundButton;
|
private View headerBackgroundButton;
|
||||||
|
|
||||||
private MenuItem playlistBookmarkButton;
|
private MenuItem playlistBookmarkButton;
|
||||||
private MenuItem playlistUnbookmarkButton;
|
|
||||||
|
|
||||||
public static PlaylistFragment getInstance(int serviceId, String url, String name) {
|
public static PlaylistFragment getInstance(int serviceId, String url, String name) {
|
||||||
PlaylistFragment instance = new PlaylistFragment();
|
PlaylistFragment instance = new PlaylistFragment();
|
||||||
|
@ -86,6 +89,7 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
disposables = new CompositeDisposable();
|
disposables = new CompositeDisposable();
|
||||||
|
isBookmarkButtonReady = new AtomicBoolean(false);
|
||||||
remotePlaylistManager = new RemotePlaylistManager(NewPipeDatabase.getInstance(getContext()));
|
remotePlaylistManager = new RemotePlaylistManager(NewPipeDatabase.getInstance(getContext()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,14 +180,14 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
|
||||||
inflater.inflate(R.menu.menu_playlist, menu);
|
inflater.inflate(R.menu.menu_playlist, menu);
|
||||||
|
|
||||||
playlistBookmarkButton = menu.findItem(R.id.menu_item_bookmark);
|
playlistBookmarkButton = menu.findItem(R.id.menu_item_bookmark);
|
||||||
playlistUnbookmarkButton = menu.findItem(R.id.menu_item_unbookmark);
|
updateBookmarkButtons();
|
||||||
|
|
||||||
updateBookmarkButtonsVisibility();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
|
if (isBookmarkButtonReady != null) isBookmarkButtonReady.set(false);
|
||||||
|
|
||||||
if (disposables != null) disposables.clear();
|
if (disposables != null) disposables.clear();
|
||||||
if (bookmarkReactor != null) bookmarkReactor.cancel();
|
if (bookmarkReactor != null) bookmarkReactor.cancel();
|
||||||
|
|
||||||
|
@ -199,6 +203,7 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
|
||||||
disposables = null;
|
disposables = null;
|
||||||
remotePlaylistManager = null;
|
remotePlaylistManager = null;
|
||||||
playlistEntity = null;
|
playlistEntity = null;
|
||||||
|
isBookmarkButtonReady = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -225,10 +230,7 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
|
||||||
shareUrl(name, url);
|
shareUrl(name, url);
|
||||||
break;
|
break;
|
||||||
case R.id.menu_item_bookmark:
|
case R.id.menu_item_bookmark:
|
||||||
bookmarkPlaylist();
|
onBookmarkClicked();
|
||||||
break;
|
|
||||||
case R.id.menu_item_unbookmark:
|
|
||||||
unbookmarkPlaylist();
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
|
@ -343,7 +345,9 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
|
||||||
@Override
|
@Override
|
||||||
public void onNext(List<PlaylistRemoteEntity> playlist) {
|
public void onNext(List<PlaylistRemoteEntity> playlist) {
|
||||||
playlistEntity = playlist.isEmpty() ? null : playlist.get(0);
|
playlistEntity = playlist.isEmpty() ? null : playlist.get(0);
|
||||||
updateBookmarkButtonsVisibility();
|
|
||||||
|
updateBookmarkButtons();
|
||||||
|
isBookmarkButtonReady.set(true);
|
||||||
|
|
||||||
if (bookmarkReactor != null) bookmarkReactor.request(1);
|
if (bookmarkReactor != null) bookmarkReactor.request(1);
|
||||||
}
|
}
|
||||||
|
@ -366,35 +370,39 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
|
||||||
headerTitleView.setText(title);
|
headerTitleView.setText(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bookmarkPlaylist() {
|
private void onBookmarkClicked() {
|
||||||
if (remotePlaylistManager == null || currentInfo == null) return;
|
if (isBookmarkButtonReady == null || !isBookmarkButtonReady.get() ||
|
||||||
|
remotePlaylistManager == null)
|
||||||
|
return;
|
||||||
|
|
||||||
playlistBookmarkButton.setVisible(false);
|
final Disposable action;
|
||||||
playlistUnbookmarkButton.setVisible(false);
|
|
||||||
|
|
||||||
final Disposable disposable = remotePlaylistManager.onBookmark(currentInfo)
|
if (currentInfo != null && playlistEntity == null) {
|
||||||
|
action = remotePlaylistManager.onBookmark(currentInfo)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(ignored -> {/* Do nothing */}, this::onError);
|
.subscribe(ignored -> {/* Do nothing */}, this::onError);
|
||||||
disposables.add(disposable);
|
} else if (playlistEntity != null) {
|
||||||
}
|
action = remotePlaylistManager.deletePlaylist(playlistEntity.getUid())
|
||||||
|
|
||||||
private void unbookmarkPlaylist() {
|
|
||||||
if (remotePlaylistManager == null || playlistEntity == null) return;
|
|
||||||
|
|
||||||
playlistBookmarkButton.setVisible(false);
|
|
||||||
playlistUnbookmarkButton.setVisible(false);
|
|
||||||
|
|
||||||
final Disposable disposable = remotePlaylistManager.deletePlaylist(playlistEntity.getUid())
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.doFinally(() -> playlistEntity = null)
|
.doFinally(() -> playlistEntity = null)
|
||||||
.subscribe(ignored -> {/* Do nothing */}, this::onError);
|
.subscribe(ignored -> {/* Do nothing */}, this::onError);
|
||||||
disposables.add(disposable);
|
} else {
|
||||||
|
action = Disposables.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateBookmarkButtonsVisibility() {
|
disposables.add(action);
|
||||||
if (playlistBookmarkButton == null || playlistUnbookmarkButton == null) return;
|
}
|
||||||
|
|
||||||
playlistBookmarkButton.setVisible(playlistEntity == null);
|
private void updateBookmarkButtons() {
|
||||||
playlistUnbookmarkButton.setVisible(playlistEntity != null);
|
if (playlistBookmarkButton == null || activity == null) return;
|
||||||
|
|
||||||
|
final int iconAttr = playlistEntity == null ?
|
||||||
|
R.attr.ic_playlist_add : R.attr.ic_playlist_check;
|
||||||
|
|
||||||
|
final int titleRes = playlistEntity == null ?
|
||||||
|
R.string.bookmark_playlist : R.string.unbookmark_playlist;
|
||||||
|
|
||||||
|
playlistBookmarkButton.setIcon(ThemeHelper.resolveResourceIdFromAttr(activity, iconAttr));
|
||||||
|
playlistBookmarkButton.setTitle(titleRes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,13 +87,6 @@ public abstract class BaseLocalListFragment<I, N> extends BaseStateFragment<I>
|
||||||
// Lifecycle - Menu
|
// Lifecycle - Menu
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
/** Determines if the fragment is part of the main fragment view pager.
|
|
||||||
* If so, then this method must be overriden to return true
|
|
||||||
* in order to show the hamburger menu. */
|
|
||||||
protected boolean isPartOfFrontPager() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
super.onCreateOptionsMenu(menu, inflater);
|
super.onCreateOptionsMenu(menu, inflater);
|
||||||
|
@ -104,14 +97,6 @@ public abstract class BaseLocalListFragment<I, N> extends BaseStateFragment<I>
|
||||||
if (supportActionBar == null) return;
|
if (supportActionBar == null) return;
|
||||||
|
|
||||||
supportActionBar.setDisplayShowTitleEnabled(true);
|
supportActionBar.setDisplayShowTitleEnabled(true);
|
||||||
|
|
||||||
// Show up arrow icon if the fragment is not used as front page or part of the front pager
|
|
||||||
if (!useAsFrontPage && !isPartOfFrontPager()) {
|
|
||||||
// If set true, an up arrow icon will be displayed.
|
|
||||||
// If set false, no icon will be shown.
|
|
||||||
// If unset, show hamburger menu
|
|
||||||
supportActionBar.setDisplayHomeAsUpEnabled(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -147,15 +147,6 @@ public final class BookmarkFragment
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
|
||||||
// Fragment Lifecycle - Menu
|
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean isPartOfFrontPager() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// Fragment LifeCycle - Loading
|
// Fragment LifeCycle - Loading
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -18,15 +18,7 @@
|
||||||
android:id="@+id/menu_item_bookmark"
|
android:id="@+id/menu_item_bookmark"
|
||||||
android:icon="?attr/ic_playlist_add"
|
android:icon="?attr/ic_playlist_add"
|
||||||
android:title="@string/bookmark_playlist"
|
android:title="@string/bookmark_playlist"
|
||||||
android:visible="false"
|
android:visible="true"
|
||||||
app:showAsAction="always"
|
app:showAsAction="ifRoom"
|
||||||
tools:visible="true"/>
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/menu_item_unbookmark"
|
|
||||||
android:icon="?attr/ic_playlist_check"
|
|
||||||
android:title="@string/unbookmark_playlist"
|
|
||||||
android:visible="false"
|
|
||||||
app:showAsAction="always"
|
|
||||||
tools:visible="true"/>
|
tools:visible="true"/>
|
||||||
</menu>
|
</menu>
|
Loading…
Reference in New Issue