make history ui more consistent
This commit is contained in:
parent
a09b9d3e4d
commit
cfa697fab2
|
@ -152,7 +152,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
settings.setOnClickListener(view -> NavigationHelper.openSettings(this));
|
settings.setOnClickListener(view -> NavigationHelper.openSettings(this));
|
||||||
downloads.setOnClickListener(view ->NavigationHelper.openDownloads(this));
|
downloads.setOnClickListener(view ->NavigationHelper.openDownloads(this));
|
||||||
history.setOnClickListener(view ->
|
history.setOnClickListener(view ->
|
||||||
NavigationHelper.openLastPlayedFragment(getSupportFragmentManager()));
|
NavigationHelper.openStatisticFragment(getSupportFragmentManager()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupDrawerHeader() {
|
private void setupDrawerHeader() {
|
||||||
|
|
|
@ -39,8 +39,6 @@ import io.reactivex.disposables.CompositeDisposable;
|
||||||
public final class BookmarkFragment
|
public final class BookmarkFragment
|
||||||
extends BaseLocalListFragment<List<PlaylistLocalItem>, Void> {
|
extends BaseLocalListFragment<List<PlaylistLocalItem>, Void> {
|
||||||
|
|
||||||
private View mostPlayedButton;
|
|
||||||
|
|
||||||
@State
|
@State
|
||||||
protected Parcelable itemsListState;
|
protected Parcelable itemsListState;
|
||||||
|
|
||||||
|
@ -94,14 +92,6 @@ public final class BookmarkFragment
|
||||||
super.initViews(rootView, savedInstanceState);
|
super.initViews(rootView, savedInstanceState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected View getListHeader() {
|
|
||||||
final View headerRootLayout = activity.getLayoutInflater()
|
|
||||||
.inflate(R.layout.bookmark_header, itemsList, false);
|
|
||||||
mostPlayedButton = headerRootLayout.findViewById(R.id.mostPlayed);
|
|
||||||
return headerRootLayout;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initListeners() {
|
protected void initListeners() {
|
||||||
super.initListeners();
|
super.initListeners();
|
||||||
|
@ -135,12 +125,6 @@ public final class BookmarkFragment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mostPlayedButton.setOnClickListener(view -> {
|
|
||||||
if (getParentFragment() != null) {
|
|
||||||
NavigationHelper.openMostPlayedFragment(getParentFragment().getFragmentManager());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -173,7 +157,6 @@ public final class BookmarkFragment
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
if (mostPlayedButton != null) mostPlayedButton.setOnClickListener(null);
|
|
||||||
|
|
||||||
if (disposables != null) disposables.clear();
|
if (disposables != null) disposables.clear();
|
||||||
if (databaseSubscription != null) databaseSubscription.cancel();
|
if (databaseSubscription != null) databaseSubscription.cancel();
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
package org.schabi.newpipe.local.history;
|
|
||||||
|
|
||||||
import org.schabi.newpipe.R;
|
|
||||||
import org.schabi.newpipe.database.stream.StreamStatisticsEntry;
|
|
||||||
import org.schabi.newpipe.local.history.StatisticsPlaylistFragment;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public final class LastPlayedFragment extends StatisticsPlaylistFragment {
|
|
||||||
@Override
|
|
||||||
protected String getName() {
|
|
||||||
return getString(R.string.title_last_played);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<StreamStatisticsEntry> processResult(List<StreamStatisticsEntry> results) {
|
|
||||||
Collections.sort(results, (left, right) ->
|
|
||||||
right.latestAccessDate.compareTo(left.latestAccessDate));
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
package org.schabi.newpipe.local.history;
|
|
||||||
|
|
||||||
import org.schabi.newpipe.R;
|
|
||||||
import org.schabi.newpipe.database.stream.StreamStatisticsEntry;
|
|
||||||
import org.schabi.newpipe.local.history.StatisticsPlaylistFragment;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public final class MostPlayedFragment extends StatisticsPlaylistFragment {
|
|
||||||
@Override
|
|
||||||
protected String getName() {
|
|
||||||
return getString(R.string.title_most_played);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<StreamStatisticsEntry> processResult(List<StreamStatisticsEntry> results) {
|
|
||||||
Collections.sort(results, (left, right) ->
|
|
||||||
((Long) right.watchCount).compareTo(left.watchCount));
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -7,11 +7,12 @@ import android.os.Bundle;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.annotation.StringRes;
|
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.reactivestreams.Subscriber;
|
import org.reactivestreams.Subscriber;
|
||||||
import org.reactivestreams.Subscription;
|
import org.reactivestreams.Subscription;
|
||||||
|
@ -36,12 +37,16 @@ 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;
|
||||||
|
|
||||||
public abstract class StatisticsPlaylistFragment
|
public class StatisticsPlaylistFragment
|
||||||
extends BaseLocalListFragment<List<StreamStatisticsEntry>, Void> {
|
extends BaseLocalListFragment<List<StreamStatisticsEntry>, Void> {
|
||||||
|
|
||||||
private View headerPlayAllButton;
|
private View headerPlayAllButton;
|
||||||
private View headerPopupButton;
|
private View headerPopupButton;
|
||||||
private View headerBackgroundButton;
|
private View headerBackgroundButton;
|
||||||
|
private View playlistCtrl;
|
||||||
|
private View sortButton;
|
||||||
|
private ImageView sortButtonIcon;
|
||||||
|
private TextView sortButtonText;
|
||||||
|
|
||||||
@State
|
@State
|
||||||
protected Parcelable itemsListState;
|
protected Parcelable itemsListState;
|
||||||
|
@ -51,14 +56,26 @@ public abstract class StatisticsPlaylistFragment
|
||||||
private HistoryRecordManager recordManager;
|
private HistoryRecordManager recordManager;
|
||||||
private CompositeDisposable disposables = new CompositeDisposable();
|
private CompositeDisposable disposables = new CompositeDisposable();
|
||||||
|
|
||||||
|
private enum StatisticSortMode {
|
||||||
|
LAST_PLAYED,
|
||||||
|
MOST_PLAYED,
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
StatisticSortMode sortMode = StatisticSortMode.LAST_PLAYED;
|
||||||
// Abstracts
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
protected abstract String getName();
|
protected List<StreamStatisticsEntry> processResult(final List<StreamStatisticsEntry> results) {
|
||||||
|
switch (sortMode) {
|
||||||
protected abstract List<StreamStatisticsEntry> processResult(final List<StreamStatisticsEntry> results);
|
case LAST_PLAYED:
|
||||||
|
Collections.sort(results, (left, right) ->
|
||||||
|
right.latestAccessDate.compareTo(left.latestAccessDate));
|
||||||
|
return results;
|
||||||
|
case MOST_PLAYED:
|
||||||
|
Collections.sort(results, (left, right) ->
|
||||||
|
((Long) right.watchCount).compareTo(left.watchCount));
|
||||||
|
return results;
|
||||||
|
default: return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// Fragment LifeCycle - Creation
|
// Fragment LifeCycle - Creation
|
||||||
|
@ -84,16 +101,20 @@ public abstract class StatisticsPlaylistFragment
|
||||||
@Override
|
@Override
|
||||||
protected void initViews(View rootView, Bundle savedInstanceState) {
|
protected void initViews(View rootView, Bundle savedInstanceState) {
|
||||||
super.initViews(rootView, savedInstanceState);
|
super.initViews(rootView, savedInstanceState);
|
||||||
setTitle(getName());
|
setTitle(getString(R.string.title_last_played));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected View getListHeader() {
|
protected View getListHeader() {
|
||||||
final View headerRootLayout = activity.getLayoutInflater().inflate(R.layout.playlist_control,
|
final View headerRootLayout = activity.getLayoutInflater().inflate(R.layout.statistic_playlist_control,
|
||||||
itemsList, false);
|
itemsList, false);
|
||||||
|
playlistCtrl = headerRootLayout.findViewById(R.id.playlist_control);
|
||||||
headerPlayAllButton = headerRootLayout.findViewById(R.id.playlist_ctrl_play_all_button);
|
headerPlayAllButton = headerRootLayout.findViewById(R.id.playlist_ctrl_play_all_button);
|
||||||
headerPopupButton = headerRootLayout.findViewById(R.id.playlist_ctrl_play_popup_button);
|
headerPopupButton = headerRootLayout.findViewById(R.id.playlist_ctrl_play_popup_button);
|
||||||
headerBackgroundButton = headerRootLayout.findViewById(R.id.playlist_ctrl_play_bg_button);
|
headerBackgroundButton = headerRootLayout.findViewById(R.id.playlist_ctrl_play_bg_button);
|
||||||
|
sortButton = headerRootLayout.findViewById(R.id.sortButton);
|
||||||
|
sortButtonIcon = headerRootLayout.findViewById(R.id.sortButtonIcon);
|
||||||
|
sortButtonText = headerRootLayout.findViewById(R.id.sortButtonText);
|
||||||
return headerRootLayout;
|
return headerRootLayout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,6 +220,8 @@ public abstract class StatisticsPlaylistFragment
|
||||||
super.handleResult(result);
|
super.handleResult(result);
|
||||||
if (itemListAdapter == null) return;
|
if (itemListAdapter == null) return;
|
||||||
|
|
||||||
|
playlistCtrl.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
itemListAdapter.clearStreamItemList();
|
itemListAdapter.clearStreamItemList();
|
||||||
|
|
||||||
if (result.isEmpty()) {
|
if (result.isEmpty()) {
|
||||||
|
@ -218,6 +241,7 @@ public abstract class StatisticsPlaylistFragment
|
||||||
NavigationHelper.playOnPopupPlayer(activity, getPlayQueue()));
|
NavigationHelper.playOnPopupPlayer(activity, getPlayQueue()));
|
||||||
headerBackgroundButton.setOnClickListener(view ->
|
headerBackgroundButton.setOnClickListener(view ->
|
||||||
NavigationHelper.playOnBackgroundPlayer(activity, getPlayQueue()));
|
NavigationHelper.playOnBackgroundPlayer(activity, getPlayQueue()));
|
||||||
|
sortButton.setOnClickListener(view -> toogleSortMode());
|
||||||
|
|
||||||
hideLoading();
|
hideLoading();
|
||||||
}
|
}
|
||||||
|
@ -244,6 +268,21 @@ public abstract class StatisticsPlaylistFragment
|
||||||
// Utils
|
// Utils
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
private void toogleSortMode() {
|
||||||
|
if(sortMode == StatisticSortMode.LAST_PLAYED) {
|
||||||
|
sortMode = StatisticSortMode.MOST_PLAYED;
|
||||||
|
setTitle(getString(R.string.title_most_played));
|
||||||
|
sortButtonIcon.setImageResource(getIconByAttr(R.attr.history));
|
||||||
|
sortButtonText.setText(R.string.title_last_played);
|
||||||
|
} else {
|
||||||
|
sortMode = StatisticSortMode.LAST_PLAYED;
|
||||||
|
setTitle(getString(R.string.title_last_played));
|
||||||
|
sortButtonIcon.setImageResource(getIconByAttr(R.attr.filter));
|
||||||
|
sortButtonText.setText(R.string.title_most_played);
|
||||||
|
}
|
||||||
|
startLoading(true);
|
||||||
|
}
|
||||||
|
|
||||||
private void showStreamDialog(final StreamStatisticsEntry item) {
|
private void showStreamDialog(final StreamStatisticsEntry item) {
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
final Activity activity = getActivity();
|
final Activity activity = getActivity();
|
||||||
|
@ -324,5 +363,10 @@ public abstract class StatisticsPlaylistFragment
|
||||||
}
|
}
|
||||||
return new SinglePlayQueue(streamInfoItems, index);
|
return new SinglePlayQueue(streamInfoItems, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getIconByAttr(final int attr) {
|
||||||
|
return getContext().obtainStyledAttributes(new int[] {attr})
|
||||||
|
.getResourceId(0, -1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,9 +37,8 @@ import org.schabi.newpipe.local.feed.FeedFragment;
|
||||||
import org.schabi.newpipe.fragments.list.kiosk.KioskFragment;
|
import org.schabi.newpipe.fragments.list.kiosk.KioskFragment;
|
||||||
import org.schabi.newpipe.fragments.list.playlist.PlaylistFragment;
|
import org.schabi.newpipe.fragments.list.playlist.PlaylistFragment;
|
||||||
import org.schabi.newpipe.fragments.list.search.SearchFragment;
|
import org.schabi.newpipe.fragments.list.search.SearchFragment;
|
||||||
import org.schabi.newpipe.local.history.LastPlayedFragment;
|
import org.schabi.newpipe.local.history.StatisticsPlaylistFragment;
|
||||||
import org.schabi.newpipe.local.playlist.LocalPlaylistFragment;
|
import org.schabi.newpipe.local.playlist.LocalPlaylistFragment;
|
||||||
import org.schabi.newpipe.local.history.MostPlayedFragment;
|
|
||||||
import org.schabi.newpipe.local.subscription.SubscriptionsImportFragment;
|
import org.schabi.newpipe.local.subscription.SubscriptionsImportFragment;
|
||||||
import org.schabi.newpipe.player.BackgroundPlayer;
|
import org.schabi.newpipe.player.BackgroundPlayer;
|
||||||
import org.schabi.newpipe.player.BackgroundPlayerActivity;
|
import org.schabi.newpipe.player.BackgroundPlayerActivity;
|
||||||
|
@ -351,16 +350,9 @@ public class NavigationHelper {
|
||||||
.commit();
|
.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void openLastPlayedFragment(FragmentManager fragmentManager) {
|
public static void openStatisticFragment(FragmentManager fragmentManager) {
|
||||||
defaultTransaction(fragmentManager)
|
defaultTransaction(fragmentManager)
|
||||||
.replace(R.id.fragment_holder, new LastPlayedFragment())
|
.replace(R.id.fragment_holder, new StatisticsPlaylistFragment())
|
||||||
.addToBackStack(null)
|
|
||||||
.commit();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void openMostPlayedFragment(FragmentManager fragmentManager) {
|
|
||||||
defaultTransaction(fragmentManager)
|
|
||||||
.replace(R.id.fragment_holder, new MostPlayedFragment())
|
|
||||||
.addToBackStack(null)
|
.addToBackStack(null)
|
||||||
.commit();
|
.commit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,20 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout
|
<LinearLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="12dp"
|
android:background="?attr/selectableItemBackground"
|
||||||
android:background="?attr/selectableItemBackground">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/mostPlayed"
|
android:id="@+id/sortButton"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?attr/selectableItemBackground"
|
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
android:focusable="true">
|
android:focusable="true">
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/mostPlayedIcon"
|
android:id="@+id/sortButtonIcon"
|
||||||
android:layout_width="48dp"
|
android:layout_width="48dp"
|
||||||
android:layout_height="28dp"
|
android:layout_height="28dp"
|
||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentLeft="true"
|
||||||
|
@ -26,10 +25,10 @@
|
||||||
tools:ignore="ContentDescription,RtlHardcoded"/>
|
tools:ignore="ContentDescription,RtlHardcoded"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/mostPlayedText"
|
android:id="@+id/sortButtonText"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="50dp"
|
android:layout_height="50dp"
|
||||||
android:layout_toRightOf="@+id/mostPlayedIcon"
|
android:layout_toRightOf="@id/sortButtonIcon"
|
||||||
android:gravity="left|center"
|
android:gravity="left|center"
|
||||||
android:text="@string/title_most_played"
|
android:text="@string/title_most_played"
|
||||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||||
|
@ -38,12 +37,6 @@
|
||||||
tools:ignore="RtlHardcoded"/>
|
tools:ignore="RtlHardcoded"/>
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
<View
|
<include layout="@layout/playlist_control" />
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="1dp"
|
|
||||||
android:layout_below="@+id/mostPlayed"
|
|
||||||
android:layout_marginLeft="8dp"
|
|
||||||
android:layout_marginRight="8dp"
|
|
||||||
android:background="?attr/separator_color"/>
|
|
||||||
|
|
||||||
</RelativeLayout>
|
</LinearLayout>
|
Loading…
Reference in New Issue