From 222c8fdb622fee18cccb6f8bb430fecb6329e226 Mon Sep 17 00:00:00 2001 From: Ritvik Saraf <13ritvik@gmail.com> Date: Sun, 9 Dec 2018 03:21:55 +0530 Subject: [PATCH] tablet ui support for comments --- .../fragments/detail/VideoDetailFragment.java | 64 ++-- .../list/comments/CommentsFragment.java | 5 + .../list/videos/RelatedVideosFragment.java | 5 + .../fragment_video_detail.xml | 273 +++++++++--------- 4 files changed, 186 insertions(+), 161 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 3d5ac2d14..9a0c3b1b0 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 @@ -16,6 +16,7 @@ import android.support.annotation.Nullable; import android.support.design.widget.AppBarLayout; import android.support.design.widget.TabLayout; import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentTransaction; import android.support.v4.content.ContextCompat; import android.support.v4.view.ViewPager; import android.support.v4.view.animation.FastOutSlowInInterpolator; @@ -152,7 +153,6 @@ public class VideoDetailFragment private View videoTitleRoot; private TextView videoTitleTextView; - @Nullable private ImageView videoTitleToggleArrow; private TextView videoCountView; @@ -184,6 +184,7 @@ public class VideoDetailFragment private ViewPager viewPager; private TabAdaptor pageAdapter; private TabLayout tabLayout; + private FrameLayout relatedStreamsLayout; /*////////////////////////////////////////////////////////////////////////*/ @@ -419,16 +420,14 @@ public class VideoDetailFragment } private void toggleTitleAndDescription() { - 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); - } + 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); } } @@ -483,6 +482,8 @@ public class VideoDetailFragment tabLayout = rootView.findViewById(R.id.tablayout); tabLayout.setupWithViewPager(viewPager); + relatedStreamsLayout = rootView.findViewById(R.id.relatedStreamsLayout); + setHeightThumbnail(); @@ -809,7 +810,7 @@ public class VideoDetailFragment pageAdapter.addFragment(CommentsFragment.getInstance(serviceId, url, name), COMMENTS_TAB_TAG); } - if(showRelatedStreams){ + if(showRelatedStreams && null == relatedStreamsLayout){ //temp empty fragment. will be updated in handleResult pageAdapter.addFragment(new Fragment(), RELATED_TAB_TAG); } @@ -1033,14 +1034,18 @@ public class VideoDetailFragment animateView(videoTitleTextView, true, 0); videoDescriptionRootLayout.setVisibility(View.GONE); - if (videoTitleToggleArrow != null) { //phone - videoTitleToggleArrow.setImageResource(R.drawable.arrow_down); - videoTitleToggleArrow.setVisibility(View.GONE); - } else { //tablet - //TODO make comments/related streams fragment invisible - } + videoTitleToggleArrow.setImageResource(R.drawable.arrow_down); + videoTitleToggleArrow.setVisibility(View.GONE); videoTitleRoot.setClickable(false); + if(relatedStreamsLayout != null){ + if(showRelatedStreams){ + relatedStreamsLayout.setVisibility(View.INVISIBLE); + }else{ + relatedStreamsLayout.setVisibility(View.GONE); + } + } + imageLoader.cancelDisplayTask(thumbnailImageView); imageLoader.cancelDisplayTask(uploaderThumb); thumbnailImageView.setImageBitmap(null); @@ -1054,8 +1059,15 @@ public class VideoDetailFragment setInitialData(info.getServiceId(), info.getOriginalUrl(), info.getName()); if(showRelatedStreams){ - pageAdapter.updateItem(RELATED_TAB_TAG, RelatedVideosFragment.getInstance(currentInfo)); - pageAdapter.notifyDataSetUpdate(); + if(null == relatedStreamsLayout){ //phone + pageAdapter.updateItem(RELATED_TAB_TAG, RelatedVideosFragment.getInstance(currentInfo)); + pageAdapter.notifyDataSetUpdate(); + }else{ //tablet + getChildFragmentManager().beginTransaction() + .replace(R.id.relatedStreamsLayout, RelatedVideosFragment.getInstance(currentInfo)) + .commitNow(); + relatedStreamsLayout.setVisibility(View.VISIBLE); + } } pushToStack(serviceId, url, name); @@ -1120,14 +1132,10 @@ public class VideoDetailFragment } videoDescriptionView.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); - } + videoTitleRoot.setClickable(true); + videoTitleToggleArrow.setVisibility(View.VISIBLE); + videoTitleToggleArrow.setImageResource(R.drawable.arrow_down); + videoDescriptionRootLayout.setVisibility(View.GONE); if (!TextUtils.isEmpty(info.getUploadDate())) { videoUploadDateView.setText(Localization.localizeDate(activity, info.getUploadDate())); } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentsFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentsFragment.java index e7778c905..21d01be16 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentsFragment.java @@ -184,4 +184,9 @@ public class CommentsFragment extends BaseListInfoFragment { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { return; } + + @Override + protected boolean isGridLayout() { + return false; + } } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/videos/RelatedVideosFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/videos/RelatedVideosFragment.java index 694731c69..5675bb81b 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/videos/RelatedVideosFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/videos/RelatedVideosFragment.java @@ -193,4 +193,9 @@ public class RelatedVideosFragment extends BaseListInfoFragment - + android:layout_height="match_parent" + android:layout_weight="5" + android:fitsSystemWindows="true"> - - + android:fitsSystemWindows="true" + app:elevation="0dp" + app:layout_behavior="android.support.design.widget.FlingBehavior"> - - + app:layout_scrollFlags="scroll"> - + + android:background="@android:color/black" + android:clickable="true" + android:focusable="true" + android:foreground="?attr/selectableItemBackground" + app:layout_collapseMode="parallax"> - + - + - - + + + + + + + android:layout_height="wrap_content" + android:background="?android:windowBackground" + app:layout_scrollFlags="scroll"> @@ -126,6 +140,15 @@ 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." /> + + @@ -209,17 +232,17 @@ tools:text="Uploader" /> + android:id="@+id/detail_uploader_subscribe" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical|right" + android:layout_marginRight="12dp" + android:text="@string/rss_button_title" + android:textSize="12sp" + android:theme="@style/RedButton" + android:drawableLeft="@drawable/ic_rss_feed_white_24dp" + tools:ignore="RtlHardcoded" + android:visibility="gone"/>--> @@ -401,7 +424,9 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="5dp" - android:orientation="vertical"> + android:orientation="vertical" + android:visibility="gone" + tools:visibility="visible"> + - - + - + + + + + + + + + - - - - - - - - - - +