From 216e2367c63c0b8063e99cdb45da06dd3e35f895 Mon Sep 17 00:00:00 2001 From: Vasily Date: Wed, 22 Aug 2018 08:32:58 +0300 Subject: [PATCH 01/13] Video details tablet layout --- .../fragments/detail/VideoDetailFragment.java | 7 +- .../fragment_video_detail.xml | 505 ++++++++++++++++++ 2 files changed, 510 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/layout-large-land/fragment_video_detail.xml diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index d91502cdd..bb642cefa 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -179,7 +179,7 @@ public class VideoDetailFragment private TextView thumbsDisabledTextView; private TextView nextStreamTitle; - private LinearLayout relatedStreamRootLayout; + private View relatedStreamRootLayout; private LinearLayout relatedStreamsView; private ImageButton relatedStreamExpandButton; @@ -623,7 +623,10 @@ public class VideoDetailFragment infoItemBuilder.buildView(relatedStreamsView, info.getNextVideo())); relatedStreamsView.addView(getSeparatorView()); relatedStreamRootLayout.setVisibility(View.VISIBLE); - } else nextStreamTitle.setVisibility(View.GONE); + } else { + nextStreamTitle.setVisibility(View.GONE); + relatedStreamRootLayout.setVisibility(View.GONE); + } if (info.getRelatedStreams() != null && !info.getRelatedStreams().isEmpty() && showRelatedStreams) { diff --git a/app/src/main/res/layout-large-land/fragment_video_detail.xml b/app/src/main/res/layout-large-land/fragment_video_detail.xml new file mode 100644 index 000000000..4d3914947 --- /dev/null +++ b/app/src/main/res/layout-large-land/fragment_video_detail.xml @@ -0,0 +1,505 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 1e0f6f9e41e5d7c22fec18788615059e9f19c5af Mon Sep 17 00:00:00 2001 From: Vasily Date: Wed, 22 Aug 2018 10:14:01 +0300 Subject: [PATCH 02/13] Grid view --- .../fragments/list/BaseListFragment.java | 56 +++++++++++++-- .../newpipe/info_list/InfoListAdapter.java | 34 ++++++++- .../holder/ChannelGridInfoItemHolder.java | 13 ++++ .../holder/PlaylistGridInfoItemHolder.java | 13 ++++ .../holder/StreamGridInfoItemHolder.java | 13 ++++ .../res/layout/list_channel_grid_item.xml | 48 +++++++++++++ .../res/layout/list_playlist_grid_item.xml | 72 +++++++++++++++++++ .../main/res/layout/list_stream_grid_item.xml | 69 ++++++++++++++++++ app/src/main/res/values/dimens.xml | 2 + app/src/main/res/values/settings_keys.xml | 11 +++ app/src/main/res/values/strings.xml | 3 + app/src/main/res/xml/appearance_settings.xml | 8 +++ 12 files changed, 335 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/org/schabi/newpipe/info_list/holder/ChannelGridInfoItemHolder.java create mode 100644 app/src/main/java/org/schabi/newpipe/info_list/holder/PlaylistGridInfoItemHolder.java create mode 100644 app/src/main/java/org/schabi/newpipe/info_list/holder/StreamGridInfoItemHolder.java create mode 100644 app/src/main/res/layout/list_channel_grid_item.xml create mode 100644 app/src/main/res/layout/list_playlist_grid_item.xml create mode 100644 app/src/main/res/layout/list_stream_grid_item.xml diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java index 1db12bba9..bfa16fb08 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java @@ -3,10 +3,14 @@ package org.schabi.newpipe.fragments.list; import android.app.Activity; import android.content.Context; import android.content.DialogInterface; +import android.content.SharedPreferences; +import android.content.res.Resources; import android.os.Bundle; +import android.preference.PreferenceManager; import android.support.annotation.NonNull; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; @@ -21,9 +25,9 @@ import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.fragments.BaseStateFragment; import org.schabi.newpipe.fragments.OnScrollBelowItemsListener; -import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; import org.schabi.newpipe.info_list.InfoItemDialog; import org.schabi.newpipe.info_list.InfoListAdapter; +import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; import org.schabi.newpipe.player.playqueue.SinglePlayQueue; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.util.NavigationHelper; @@ -36,7 +40,7 @@ import java.util.Queue; import static org.schabi.newpipe.util.AnimationUtils.animateView; -public abstract class BaseListFragment extends BaseStateFragment implements ListViewContract, StateSaver.WriteRead { +public abstract class BaseListFragment extends BaseStateFragment implements ListViewContract, StateSaver.WriteRead, SharedPreferences.OnSharedPreferenceChangeListener { /*////////////////////////////////////////////////////////////////////////// // Views @@ -44,6 +48,9 @@ public abstract class BaseListFragment extends BaseStateFragment implem protected InfoListAdapter infoListAdapter; protected RecyclerView itemsList; + private int updateFlags = 0; + + private static final int LIST_MODE_UPDATE_FLAG = 0x32; /*////////////////////////////////////////////////////////////////////////// // LifeCycle @@ -59,12 +66,32 @@ public abstract class BaseListFragment extends BaseStateFragment implem public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true); + PreferenceManager.getDefaultSharedPreferences(activity) + .registerOnSharedPreferenceChangeListener(this); } @Override public void onDestroy() { super.onDestroy(); StateSaver.onDestroy(savedState); + PreferenceManager.getDefaultSharedPreferences(activity) + .unregisterOnSharedPreferenceChangeListener(this); + } + + @Override + public void onResume() { + super.onResume(); + + if (updateFlags != 0) { + if ((updateFlags & LIST_MODE_UPDATE_FLAG) != 0) { + final String list_key = getString(R.string.list_view_mode_value); + final boolean useGrid = !list_key.equals(PreferenceManager.getDefaultSharedPreferences(activity).getString(getString(R.string.list_view_mode_key), list_key)); + itemsList.setLayoutManager(useGrid ? getGridLayoutManager() : getListLayoutManager()); + infoListAdapter.setGridItemVariants(useGrid); + infoListAdapter.notifyDataSetChanged(); + } + updateFlags = 0; + } } /*////////////////////////////////////////////////////////////////////////// @@ -119,13 +146,27 @@ public abstract class BaseListFragment extends BaseStateFragment implem return new LinearLayoutManager(activity); } + protected RecyclerView.LayoutManager getGridLayoutManager() { + final Resources resources = activity.getResources(); + int width = resources.getDimensionPixelSize(R.dimen.video_item_grid_thumbnail_image_width); + width += (24 * resources.getDisplayMetrics().density); + final int spanCount = (int) Math.floor(resources.getDisplayMetrics().widthPixels / (double)width); + final GridLayoutManager lm = new GridLayoutManager(activity, spanCount); + lm.setSpanSizeLookup(infoListAdapter.getSpanSizeLookup(spanCount)); + return lm; + } + @Override protected void initViews(View rootView, Bundle savedInstanceState) { super.initViews(rootView, savedInstanceState); - itemsList = rootView.findViewById(R.id.items_list); - itemsList.setLayoutManager(getListLayoutManager()); + final String list_key = getString(R.string.list_view_mode_value); + final boolean useGrid = !list_key.equals(PreferenceManager.getDefaultSharedPreferences(activity).getString(getString(R.string.list_view_mode_key), list_key)); + itemsList = rootView.findViewById(R.id.items_list); + itemsList.setLayoutManager(useGrid ? getGridLayoutManager() : getListLayoutManager()); + + infoListAdapter.setGridItemVariants(useGrid); infoListAdapter.setFooter(getListFooter()); infoListAdapter.setHeader(getListHeader()); @@ -315,4 +356,11 @@ public abstract class BaseListFragment extends BaseStateFragment implem public void handleNextItems(N result) { isLoading.set(false); } + + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + if (key.equals(getString(R.string.list_view_mode_key))) { + updateFlags |= LIST_MODE_UPDATE_FLAG; + } + } } diff --git a/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java b/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java index cf12deb6f..15fdcad05 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java @@ -1,6 +1,7 @@ package org.schabi.newpipe.info_list; import android.app.Activity; +import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.View; @@ -12,9 +13,12 @@ import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.info_list.holder.ChannelInfoItemHolder; import org.schabi.newpipe.info_list.holder.ChannelMiniInfoItemHolder; +import org.schabi.newpipe.info_list.holder.ChannelGridInfoItemHolder; import org.schabi.newpipe.info_list.holder.InfoItemHolder; +import org.schabi.newpipe.info_list.holder.PlaylistGridInfoItemHolder; import org.schabi.newpipe.info_list.holder.PlaylistInfoItemHolder; import org.schabi.newpipe.info_list.holder.PlaylistMiniInfoItemHolder; +import org.schabi.newpipe.info_list.holder.StreamGridInfoItemHolder; import org.schabi.newpipe.info_list.holder.StreamInfoItemHolder; import org.schabi.newpipe.info_list.holder.StreamMiniInfoItemHolder; import org.schabi.newpipe.util.FallbackViewHolder; @@ -52,14 +56,18 @@ public class InfoListAdapter extends RecyclerView.Adapter infoItemList; private boolean useMiniVariant = false; + private boolean useGridVariant = false; private boolean showFooter = false; private View header = null; private View footer = null; @@ -94,6 +102,10 @@ public class InfoListAdapter extends RecyclerView.Adapter data) { if (data != null) { if (DEBUG) { @@ -206,11 +218,11 @@ public class InfoListAdapter extends RecyclerView.Adapter + + + + + + + + + diff --git a/app/src/main/res/layout/list_playlist_grid_item.xml b/app/src/main/res/layout/list_playlist_grid_item.xml new file mode 100644 index 000000000..949b1159b --- /dev/null +++ b/app/src/main/res/layout/list_playlist_grid_item.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/list_stream_grid_item.xml b/app/src/main/res/layout/list_stream_grid_item.xml new file mode 100644 index 000000000..cf73bf9b1 --- /dev/null +++ b/app/src/main/res/layout/list_stream_grid_item.xml @@ -0,0 +1,69 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index e7af3231e..229c00533 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -12,6 +12,8 @@ 124dp 70dp + 164dp + 92dp 94dp diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 02f065285..941f033d8 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -891,5 +891,16 @@ 144p + list_view_mode + list + + + list + grid + + + @string/list + @string/grid + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 240fef3dc..f3976c6a4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -514,5 +514,8 @@ None Minimize to background player Minimize to popup player + List view mode + List + Grid diff --git a/app/src/main/res/xml/appearance_settings.xml b/app/src/main/res/xml/appearance_settings.xml index 239f5f3b3..490310c91 100644 --- a/app/src/main/res/xml/appearance_settings.xml +++ b/app/src/main/res/xml/appearance_settings.xml @@ -22,6 +22,14 @@ android:title="@string/show_hold_to_append_title" android:summary="@string/show_hold_to_append_summary"/> + + Date: Wed, 22 Aug 2018 10:29:37 +0300 Subject: [PATCH 03/13] Fix crash on screen rotation --- .../fragments/detail/VideoDetailFragment.java | 31 +++++++++++++------ .../fragment_video_detail.xml | 2 +- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index bb642cefa..ad3dacf6b 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -33,12 +33,14 @@ import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import android.view.ViewParent; import android.widget.AdapterView; import android.widget.FrameLayout; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RelativeLayout; +import android.widget.ScrollView; import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; @@ -64,19 +66,17 @@ import org.schabi.newpipe.extractor.stream.StreamType; import org.schabi.newpipe.extractor.stream.VideoStream; import org.schabi.newpipe.fragments.BackPressable; import org.schabi.newpipe.fragments.BaseStateFragment; -import org.schabi.newpipe.local.history.HistoryRecordManager; -import org.schabi.newpipe.report.ErrorActivity; -import org.schabi.newpipe.util.StreamItemAdapter; -import org.schabi.newpipe.util.StreamItemAdapter.StreamSizeWrapper; -import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; import org.schabi.newpipe.info_list.InfoItemBuilder; import org.schabi.newpipe.info_list.InfoItemDialog; +import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; +import org.schabi.newpipe.local.history.HistoryRecordManager; import org.schabi.newpipe.player.MainVideoPlayer; import org.schabi.newpipe.player.PopupVideoPlayer; import org.schabi.newpipe.player.helper.PlayerHelper; import org.schabi.newpipe.player.old.PlayVideoActivity; 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.Constants; import org.schabi.newpipe.util.ExtractorHelper; @@ -87,6 +87,8 @@ import org.schabi.newpipe.util.Localization; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.OnClickGesture; import org.schabi.newpipe.util.PermissionHelper; +import org.schabi.newpipe.util.StreamItemAdapter; +import org.schabi.newpipe.util.StreamItemAdapter.StreamSizeWrapper; import org.schabi.newpipe.util.ThemeHelper; import java.io.Serializable; @@ -179,7 +181,7 @@ public class VideoDetailFragment private TextView thumbsDisabledTextView; private TextView nextStreamTitle; - private View relatedStreamRootLayout; + private LinearLayout relatedStreamRootLayout; private LinearLayout relatedStreamsView; private ImageButton relatedStreamExpandButton; @@ -622,10 +624,10 @@ public class VideoDetailFragment relatedStreamsView.addView( infoItemBuilder.buildView(relatedStreamsView, info.getNextVideo())); relatedStreamsView.addView(getSeparatorView()); - relatedStreamRootLayout.setVisibility(View.VISIBLE); + setRelatedStreamsVisibility(View.VISIBLE); } else { nextStreamTitle.setVisibility(View.GONE); - relatedStreamRootLayout.setVisibility(View.GONE); + setRelatedStreamsVisibility(View.GONE); } if (info.getRelatedStreams() != null @@ -642,13 +644,13 @@ public class VideoDetailFragment } //if (DEBUG) Log.d(TAG, "Total time " + ((System.nanoTime() - first) / 1000000L) + "ms"); - relatedStreamRootLayout.setVisibility(View.VISIBLE); + setRelatedStreamsVisibility(View.VISIBLE); relatedStreamExpandButton.setVisibility(View.VISIBLE); relatedStreamExpandButton.setImageDrawable(ContextCompat.getDrawable( activity, ThemeHelper.resolveResourceIdFromAttr(activity, R.attr.expand))); } else { - if (info.getNextVideo() == null) relatedStreamRootLayout.setVisibility(View.GONE); + if (info.getNextVideo() == null) setRelatedStreamsVisibility(View.GONE); relatedStreamExpandButton.setVisibility(View.GONE); } } @@ -1302,4 +1304,13 @@ public class VideoDetailFragment showError(getString(R.string.blocked_by_gema), false, R.drawable.gruese_die_gema); } + + private void setRelatedStreamsVisibility(int visibility) { + final ViewParent parent = relatedStreamRootLayout.getParent(); + if (parent instanceof ScrollView) { + ((ScrollView) parent).setVisibility(visibility); + } else { + relatedStreamRootLayout.setVisibility(visibility); + } + } } \ No newline at end of file diff --git a/app/src/main/res/layout-large-land/fragment_video_detail.xml b/app/src/main/res/layout-large-land/fragment_video_detail.xml index 4d3914947..bf49a01a6 100644 --- a/app/src/main/res/layout-large-land/fragment_video_detail.xml +++ b/app/src/main/res/layout-large-land/fragment_video_detail.xml @@ -456,13 +456,13 @@ Date: Wed, 22 Aug 2018 10:33:10 +0300 Subject: [PATCH 04/13] Update translations --- app/src/main/res/values-ru/strings.xml | 5 +++++ app/src/main/res/values-uk/strings.xml | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 3cacc83e8..e2198f240 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -485,6 +485,7 @@ Предел разрешения в мобильной сети Каналы Плейлисты + Видео Дорожки Пользователи Пропускать тишину @@ -497,4 +498,8 @@ Фоновый плеер Плеер в окне + Вид списка + Список + Сетка + diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index 78eb45590..e4d4106d4 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -481,8 +481,12 @@ Зменшити до фонового програвачу Зменшити до віконного програвачу -Канали + Канали Плейлисти Стежки Користувачі - + + Вигляд списку + Список + Сiтка + From ce21fe208738ea6f27936df4314b78d76a80074b Mon Sep 17 00:00:00 2001 From: Vasily Date: Wed, 29 Aug 2018 07:53:58 +0300 Subject: [PATCH 05/13] Always show description on tablets --- .../fragments/detail/VideoDetailFragment.java | 37 ++++++++++++------- .../fragment_video_detail.xml | 16 +------- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index ad3dacf6b..8f46ec7c6 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -156,6 +156,7 @@ public class VideoDetailFragment private View videoTitleRoot; private TextView videoTitleTextView; + @Nullable private ImageView videoTitleToggleArrow; private TextView videoCountView; @@ -417,14 +418,16 @@ public class VideoDetailFragment } private void toggleTitleAndDescription() { - if (videoDescriptionRootLayout.getVisibility() == View.VISIBLE) { - videoTitleTextView.setMaxLines(1); - videoDescriptionRootLayout.setVisibility(View.GONE); - videoTitleToggleArrow.setImageResource(R.drawable.arrow_down); - } else { - videoTitleTextView.setMaxLines(10); - videoDescriptionRootLayout.setVisibility(View.VISIBLE); - videoTitleToggleArrow.setImageResource(R.drawable.arrow_up); + if (videoTitleToggleArrow != null) { //it is null for tablets + if (videoDescriptionRootLayout.getVisibility() == View.VISIBLE) { + videoTitleTextView.setMaxLines(1); + videoDescriptionRootLayout.setVisibility(View.GONE); + videoTitleToggleArrow.setImageResource(R.drawable.arrow_down); + } else { + videoTitleTextView.setMaxLines(10); + videoDescriptionRootLayout.setVisibility(View.VISIBLE); + videoTitleToggleArrow.setImageResource(R.drawable.arrow_up); + } } } @@ -1119,8 +1122,10 @@ public class VideoDetailFragment animateView(videoTitleTextView, true, 0); videoDescriptionRootLayout.setVisibility(View.GONE); - videoTitleToggleArrow.setImageResource(R.drawable.arrow_down); - videoTitleToggleArrow.setVisibility(View.GONE); + if (videoTitleToggleArrow != null) { + videoTitleToggleArrow.setImageResource(R.drawable.arrow_down); + videoTitleToggleArrow.setVisibility(View.GONE); + } videoTitleRoot.setClickable(false); imageLoader.cancelDisplayTask(thumbnailImageView); @@ -1195,11 +1200,15 @@ public class VideoDetailFragment detailDurationView.setVisibility(View.GONE); } - videoTitleRoot.setClickable(true); - videoTitleToggleArrow.setVisibility(View.VISIBLE); - videoTitleToggleArrow.setImageResource(R.drawable.arrow_down); videoDescriptionView.setVisibility(View.GONE); - videoDescriptionRootLayout.setVisibility(View.GONE); + if (videoTitleToggleArrow != null) { + videoTitleRoot.setClickable(true); + videoTitleToggleArrow.setVisibility(View.VISIBLE); + videoTitleToggleArrow.setImageResource(R.drawable.arrow_down); + videoDescriptionRootLayout.setVisibility(View.GONE); + } else { + videoDescriptionRootLayout.setVisibility(View.VISIBLE); + } if (!TextUtils.isEmpty(info.getUploadDate())) { videoUploadDateView.setText(Localization.localizeDate(activity, info.getUploadDate())); } diff --git a/app/src/main/res/layout-large-land/fragment_video_detail.xml b/app/src/main/res/layout-large-land/fragment_video_detail.xml index bf49a01a6..73939d60a 100644 --- a/app/src/main/res/layout-large-land/fragment_video_detail.xml +++ b/app/src/main/res/layout-large-land/fragment_video_detail.xml @@ -109,9 +109,6 @@ android:id="@+id/detail_title_root_layout" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="?attr/selectableItemBackground" - android:clickable="true" - android:focusable="true" android:paddingLeft="12dp" android:paddingRight="12dp"> @@ -129,15 +126,6 @@ tools:ignore="RtlHardcoded" tools:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed a ultricies ex. Integer sit amet sodales risus. Duis non mi et urna pretium bibendum. Nunc eleifend est quis ipsum porttitor egestas. Sed facilisis, nisl quis eleifend pellentesque, orci metus egestas dolor, at accumsan eros metus quis libero." /> - - @@ -413,9 +401,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="5dp" - android:orientation="vertical" - android:visibility="gone" - tools:visibility="visible"> + android:orientation="vertical"> Date: Wed, 29 Aug 2018 08:08:19 +0300 Subject: [PATCH 06/13] Hide related streams while loading --- .../newpipe/fragments/detail/VideoDetailFragment.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index 8f46ec7c6..77583f2e5 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -1122,9 +1122,15 @@ public class VideoDetailFragment animateView(videoTitleTextView, true, 0); videoDescriptionRootLayout.setVisibility(View.GONE); - if (videoTitleToggleArrow != null) { + if (videoTitleToggleArrow != null) { //phone videoTitleToggleArrow.setImageResource(R.drawable.arrow_down); videoTitleToggleArrow.setVisibility(View.GONE); + } else { //tablet + final View related = (View) relatedStreamRootLayout.getParent(); + //don`t need to hide it if related streams are disabled + if (related.getVisibility() == View.VISIBLE) { + related.setVisibility(View.INVISIBLE); + } } videoTitleRoot.setClickable(false); From fb25f6c7ac9ff8e24241e79e94f7ac046f836ad0 Mon Sep 17 00:00:00 2001 From: Vasily Date: Wed, 29 Aug 2018 08:19:15 +0300 Subject: [PATCH 07/13] Automatic list layout --- .../fragments/list/BaseListFragment.java | 19 ++++++++++++++----- app/src/main/res/values-ru/strings.xml | 1 + app/src/main/res/values/settings_keys.xml | 4 +++- app/src/main/res/values/strings.xml | 1 + 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java index bfa16fb08..21abf40ad 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java @@ -4,6 +4,7 @@ import android.app.Activity; import android.content.Context; import android.content.DialogInterface; import android.content.SharedPreferences; +import android.content.res.Configuration; import android.content.res.Resources; import android.os.Bundle; import android.preference.PreferenceManager; @@ -84,8 +85,7 @@ public abstract class BaseListFragment extends BaseStateFragment implem if (updateFlags != 0) { if ((updateFlags & LIST_MODE_UPDATE_FLAG) != 0) { - final String list_key = getString(R.string.list_view_mode_value); - final boolean useGrid = !list_key.equals(PreferenceManager.getDefaultSharedPreferences(activity).getString(getString(R.string.list_view_mode_key), list_key)); + final boolean useGrid = isGridLayout(); itemsList.setLayoutManager(useGrid ? getGridLayoutManager() : getListLayoutManager()); infoListAdapter.setGridItemVariants(useGrid); infoListAdapter.notifyDataSetChanged(); @@ -160,9 +160,7 @@ public abstract class BaseListFragment extends BaseStateFragment implem protected void initViews(View rootView, Bundle savedInstanceState) { super.initViews(rootView, savedInstanceState); - final String list_key = getString(R.string.list_view_mode_value); - final boolean useGrid = !list_key.equals(PreferenceManager.getDefaultSharedPreferences(activity).getString(getString(R.string.list_view_mode_key), list_key)); - + final boolean useGrid = isGridLayout(); itemsList = rootView.findViewById(R.id.items_list); itemsList.setLayoutManager(useGrid ? getGridLayoutManager() : getListLayoutManager()); @@ -363,4 +361,15 @@ public abstract class BaseListFragment extends BaseStateFragment implem updateFlags |= LIST_MODE_UPDATE_FLAG; } } + + protected boolean isGridLayout() { + final String list_mode = PreferenceManager.getDefaultSharedPreferences(activity).getString(getString(R.string.list_view_mode_key), getString(R.string.list_view_mode_value)); + if ("auto".equals(list_mode)) { + final Configuration configuration = getResources().getConfiguration(); + return configuration.orientation == Configuration.ORIENTATION_LANDSCAPE + && configuration.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE); + } else { + return "grid".equals(list_mode); + } + } } diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index e2198f240..a053cafb3 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -501,5 +501,6 @@ Вид списка Список Сетка + Автоматически diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 941f033d8..0c71944c3 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -892,13 +892,15 @@ list_view_mode - list + auto + auto list grid + @string/auto @string/list @string/grid diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f3976c6a4..b63de7dbd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -517,5 +517,6 @@ List view mode List Grid + Auto From ee4942dfd70a980192c8b4e604c94a412553b2a8 Mon Sep 17 00:00:00 2001 From: Vasily Date: Fri, 31 Aug 2018 14:34:32 +0300 Subject: [PATCH 08/13] Grid layout for local lists --- .../newpipe/local/BaseLocalListFragment.java | 70 +++++++++++++++- .../newpipe/local/LocalItemListAdapter.java | 42 ++++++++-- .../holder/LocalPlaylistGridItemHolder.java | 13 +++ .../local/holder/LocalPlaylistItemHolder.java | 4 + .../LocalPlaylistStreamGridItemHolder.java | 13 +++ .../LocalStatisticStreamGridItemHolder.java | 13 +++ .../LocalStatisticStreamItemHolder.java | 14 +++- .../holder/RemotePlaylistGridItemHolder.java | 13 +++ .../holder/RemotePlaylistItemHolder.java | 4 + .../layout/list_stream_playlist_grid_item.xml | 84 +++++++++++++++++++ 10 files changed, 257 insertions(+), 13 deletions(-) create mode 100644 app/src/main/java/org/schabi/newpipe/local/holder/LocalPlaylistGridItemHolder.java create mode 100644 app/src/main/java/org/schabi/newpipe/local/holder/LocalPlaylistStreamGridItemHolder.java create mode 100644 app/src/main/java/org/schabi/newpipe/local/holder/LocalStatisticStreamGridItemHolder.java create mode 100644 app/src/main/java/org/schabi/newpipe/local/holder/RemotePlaylistGridItemHolder.java create mode 100644 app/src/main/res/layout/list_stream_playlist_grid_item.xml diff --git a/app/src/main/java/org/schabi/newpipe/local/BaseLocalListFragment.java b/app/src/main/java/org/schabi/newpipe/local/BaseLocalListFragment.java index 5192aa2ab..abdf82353 100644 --- a/app/src/main/java/org/schabi/newpipe/local/BaseLocalListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/BaseLocalListFragment.java @@ -1,8 +1,13 @@ package org.schabi.newpipe.local; +import android.content.SharedPreferences; +import android.content.res.Configuration; +import android.content.res.Resources; import android.os.Bundle; +import android.preference.PreferenceManager; import android.support.v4.app.Fragment; import android.support.v7.app.ActionBar; +import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; @@ -25,7 +30,7 @@ import static org.schabi.newpipe.util.AnimationUtils.animateView; * called and is memory efficient when in backstack. * */ public abstract class BaseLocalListFragment extends BaseStateFragment - implements ListViewContract { + implements ListViewContract, SharedPreferences.OnSharedPreferenceChangeListener { /*////////////////////////////////////////////////////////////////////////// // Views @@ -36,6 +41,9 @@ public abstract class BaseLocalListFragment extends BaseStateFragment protected LocalItemListAdapter itemListAdapter; protected RecyclerView itemsList; + private int updateFlags = 0; + + private static final int LIST_MODE_UPDATE_FLAG = 0x32; /*////////////////////////////////////////////////////////////////////////// // Lifecycle - Creation @@ -45,6 +53,29 @@ public abstract class BaseLocalListFragment extends BaseStateFragment public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true); + PreferenceManager.getDefaultSharedPreferences(activity) + .registerOnSharedPreferenceChangeListener(this); + } + + @Override + public void onDestroy() { + super.onDestroy(); + PreferenceManager.getDefaultSharedPreferences(activity) + .unregisterOnSharedPreferenceChangeListener(this); + } + + @Override + public void onResume() { + super.onResume(); + if (updateFlags != 0) { + if ((updateFlags & LIST_MODE_UPDATE_FLAG) != 0) { + final boolean useGrid = isGridLayout(); + itemsList.setLayoutManager(useGrid ? getGridLayoutManager() : getListLayoutManager()); + itemListAdapter.setGridItemVariants(useGrid); + itemListAdapter.notifyDataSetChanged(); + } + updateFlags = 0; + } } /*////////////////////////////////////////////////////////////////////////// @@ -59,6 +90,16 @@ public abstract class BaseLocalListFragment extends BaseStateFragment return activity.getLayoutInflater().inflate(R.layout.pignate_footer, itemsList, false); } + protected RecyclerView.LayoutManager getGridLayoutManager() { + final Resources resources = activity.getResources(); + int width = resources.getDimensionPixelSize(R.dimen.video_item_grid_thumbnail_image_width); + width += (24 * resources.getDisplayMetrics().density); + final int spanCount = (int) Math.floor(resources.getDisplayMetrics().widthPixels / (double)width); + final GridLayoutManager lm = new GridLayoutManager(activity, spanCount); + lm.setSpanSizeLookup(itemListAdapter.getSpanSizeLookup(spanCount)); + return lm; + } + protected RecyclerView.LayoutManager getListLayoutManager() { return new LinearLayoutManager(activity); } @@ -67,10 +108,13 @@ public abstract class BaseLocalListFragment extends BaseStateFragment protected void initViews(View rootView, Bundle savedInstanceState) { super.initViews(rootView, savedInstanceState); - itemsList = rootView.findViewById(R.id.items_list); - itemsList.setLayoutManager(getListLayoutManager()); - itemListAdapter = new LocalItemListAdapter(activity); + + final boolean useGrid = isGridLayout(); + itemsList = rootView.findViewById(R.id.items_list); + itemsList.setLayoutManager(useGrid ? getGridLayoutManager() : getListLayoutManager()); + + itemListAdapter.setGridItemVariants(useGrid); itemListAdapter.setHeader(headerRootView = getListHeader()); itemListAdapter.setFooter(footerRootView = getListFooter()); @@ -174,4 +218,22 @@ public abstract class BaseLocalListFragment extends BaseStateFragment resetFragment(); return super.onError(exception); } + + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + if (key.equals(getString(R.string.list_view_mode_key))) { + updateFlags |= LIST_MODE_UPDATE_FLAG; + } + } + + protected boolean isGridLayout() { + final String list_mode = PreferenceManager.getDefaultSharedPreferences(activity).getString(getString(R.string.list_view_mode_key), getString(R.string.list_view_mode_value)); + if ("auto".equals(list_mode)) { + final Configuration configuration = getResources().getConfiguration(); + return configuration.orientation == Configuration.ORIENTATION_LANDSCAPE + && configuration.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE); + } else { + return "grid".equals(list_mode); + } + } } diff --git a/app/src/main/java/org/schabi/newpipe/local/LocalItemListAdapter.java b/app/src/main/java/org/schabi/newpipe/local/LocalItemListAdapter.java index 99937b58c..e298dedd3 100644 --- a/app/src/main/java/org/schabi/newpipe/local/LocalItemListAdapter.java +++ b/app/src/main/java/org/schabi/newpipe/local/LocalItemListAdapter.java @@ -1,18 +1,21 @@ package org.schabi.newpipe.local; import android.app.Activity; +import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.View; import android.view.ViewGroup; import org.schabi.newpipe.database.LocalItem; -import org.schabi.newpipe.local.HeaderFooterHolder; -import org.schabi.newpipe.local.LocalItemBuilder; import org.schabi.newpipe.local.holder.LocalItemHolder; +import org.schabi.newpipe.local.holder.LocalPlaylistGridItemHolder; import org.schabi.newpipe.local.holder.LocalPlaylistItemHolder; +import org.schabi.newpipe.local.holder.LocalPlaylistStreamGridItemHolder; import org.schabi.newpipe.local.holder.LocalPlaylistStreamItemHolder; +import org.schabi.newpipe.local.holder.LocalStatisticStreamGridItemHolder; import org.schabi.newpipe.local.holder.LocalStatisticStreamItemHolder; +import org.schabi.newpipe.local.holder.RemotePlaylistGridItemHolder; import org.schabi.newpipe.local.holder.RemotePlaylistItemHolder; import org.schabi.newpipe.util.FallbackViewHolder; import org.schabi.newpipe.util.Localization; @@ -52,14 +55,19 @@ public class LocalItemListAdapter extends RecyclerView.Adapter localItems; private final DateFormat dateFormat; private boolean showFooter = false; + private boolean useGridVariant = false; private View header = null; private View footer = null; @@ -134,6 +142,10 @@ public class LocalItemListAdapter extends RecyclerView.Adapter + + + + + + + + + + + + + \ No newline at end of file From b1a5547de2357046e5d605cfd52af11b63b4b81b Mon Sep 17 00:00:00 2001 From: u1 Date: Fri, 31 Aug 2018 16:34:35 +0300 Subject: [PATCH 09/13] Fix reordering playlist items on grid layout --- .../newpipe/local/playlist/LocalPlaylistFragment.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java index 35a1530c9..f400061e1 100644 --- a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java @@ -459,7 +459,11 @@ public class LocalPlaylistFragment extends BaseLocalListFragment Date: Fri, 31 Aug 2018 16:49:25 +0300 Subject: [PATCH 10/13] Grid layout for subscriptions --- .../subscription/SubscriptionFragment.java | 59 ++++++++++++++++++- .../main/res/layout/fragment_subscription.xml | 1 - 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.java b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.java index d8a26f0eb..584acfaf8 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.java @@ -5,11 +5,15 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.SharedPreferences; +import android.content.res.Configuration; +import android.content.res.Resources; import android.graphics.Color; import android.graphics.PorterDuff; import android.os.Bundle; import android.os.Environment; import android.os.Parcelable; +import android.preference.PreferenceManager; import android.support.annotation.DrawableRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -17,6 +21,7 @@ import android.support.v4.app.FragmentManager; import android.support.v4.content.LocalBroadcastManager; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; @@ -72,7 +77,7 @@ import static org.schabi.newpipe.local.subscription.services.SubscriptionsImport import static org.schabi.newpipe.util.AnimationUtils.animateRotation; import static org.schabi.newpipe.util.AnimationUtils.animateView; -public class SubscriptionFragment extends BaseStateFragment> { +public class SubscriptionFragment extends BaseStateFragment> implements SharedPreferences.OnSharedPreferenceChangeListener { private static final int REQUEST_EXPORT_CODE = 666; private static final int REQUEST_IMPORT_CODE = 667; @@ -80,6 +85,9 @@ public class SubscriptionFragment extends BaseStateFragment From 1e53d6bfab9a2832e087029303c40b16ac0404f1 Mon Sep 17 00:00:00 2001 From: Vasily Date: Fri, 31 Aug 2018 17:08:13 +0300 Subject: [PATCH 11/13] Scroll top related streams when loading --- .../schabi/newpipe/fragments/detail/VideoDetailFragment.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index 65a423084..7e0a013ca 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -1262,6 +1262,11 @@ public class VideoDetailFragment // Only auto play in the first open autoPlayEnabled = false; } + + final ViewParent related = relatedStreamRootLayout.getParent(); + if (related instanceof ScrollView) { + ((ScrollView) related).scrollTo(0, 0); + } } From d4c1b8d32139ca33fdefe4ad1ca0e155ca8c1a01 Mon Sep 17 00:00:00 2001 From: Vasily Date: Fri, 31 Aug 2018 17:12:56 +0300 Subject: [PATCH 12/13] Fix: remove title from PlaylistDialog --- .../newpipe/local/dialog/PlaylistDialog.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistDialog.java b/app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistDialog.java index 4b8e391c7..15ba5d184 100644 --- a/app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistDialog.java +++ b/app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistDialog.java @@ -1,9 +1,11 @@ package org.schabi.newpipe.local.dialog; +import android.app.Dialog; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.DialogFragment; +import android.view.Window; import org.schabi.newpipe.database.stream.model.StreamEntity; import org.schabi.newpipe.util.StateSaver; @@ -41,6 +43,18 @@ public abstract class PlaylistDialog extends DialogFragment implements StateSave StateSaver.onDestroy(savedState); } + @NonNull + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + final Dialog dialog = super.onCreateDialog(savedInstanceState); + //remove title + final Window window = dialog.getWindow(); + if (window != null) { + window.requestFeature(Window.FEATURE_NO_TITLE); + } + return dialog; + } + /*////////////////////////////////////////////////////////////////////////// // State Saving //////////////////////////////////////////////////////////////////////////*/ From b24baa68ba36f8d54fe111e1efe7f3881c023e39 Mon Sep 17 00:00:00 2001 From: Vasily Date: Fri, 31 Aug 2018 17:30:06 +0300 Subject: [PATCH 13/13] Tablet UI in player --- .../activity_main_player.xml | 581 ++++++++++++++++++ 1 file changed, 581 insertions(+) create mode 100644 app/src/main/res/layout-large-land/activity_main_player.xml diff --git a/app/src/main/res/layout-large-land/activity_main_player.xml b/app/src/main/res/layout-large-land/activity_main_player.xml new file mode 100644 index 000000000..7d7e1230e --- /dev/null +++ b/app/src/main/res/layout-large-land/activity_main_player.xml @@ -0,0 +1,581 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +