Skip to content

Commit

Permalink
Fixed serveral things:
Browse files Browse the repository at this point in the history
* ugly workaround for the details_view_layout problem on older devices
* removed "display button on the left side" option since it's not nececeay anymore.
  • Loading branch information
theScrabi committed Dec 15, 2015
1 parent 63b16d9 commit f9ad0f1
Show file tree
Hide file tree
Showing 20 changed files with 260 additions and 68 deletions.
47 changes: 19 additions & 28 deletions app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Point;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
Expand Down Expand Up @@ -379,20 +380,6 @@ public void onActivityCreated(Bundle savedInstanceBundle) {
e.printStackTrace();
}

if (PreferenceManager.getDefaultSharedPreferences(getActivity())
.getBoolean(getString(R.string.leftHandLayout), false) && checkIfLandscape()) {
RelativeLayout.LayoutParams oldLayout =
(RelativeLayout.LayoutParams) playVideoButton.getLayoutParams();
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
layoutParams.setMargins(oldLayout.leftMargin, oldLayout.topMargin,
oldLayout.rightMargin, oldLayout.bottomMargin);
playVideoButton.setLayoutParams(layoutParams);
}

playVideoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down Expand Up @@ -422,22 +409,26 @@ public void onClick(View v) {
}
});

ImageView thumbnailView = (ImageView) activity.findViewById(R.id.detailThumbnailView);
thumbnailView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
// This is used to synchronize the thumbnailWindowButton and the playVideoButton
// inside the ScrollView with the actual size of the thumbnail.
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
RelativeLayout.LayoutParams newWindowLayoutParams =
(RelativeLayout.LayoutParams) thumbnailWindowLayout.getLayoutParams();
newWindowLayoutParams.height = bottom - top;
thumbnailWindowLayout.setLayoutParams(newWindowLayoutParams);
// todo: Fix this workaround (probably with a better design), so that older android
// versions don't have problems rendering the thumbnail right.
if(Build.VERSION.SDK_INT >= 18) {
ImageView thumbnailView = (ImageView) activity.findViewById(R.id.detailThumbnailView);
thumbnailView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
// This is used to synchronize the thumbnailWindowButton and the playVideoButton
// inside the ScrollView with the actual size of the thumbnail.
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
RelativeLayout.LayoutParams newWindowLayoutParams =
(RelativeLayout.LayoutParams) thumbnailWindowLayout.getLayoutParams();
newWindowLayoutParams.height = bottom - top;
thumbnailWindowLayout.setLayoutParams(newWindowLayoutParams);

//noinspection SuspiciousNameCombination
initialThumbnailPos.set(top, left);
//noinspection SuspiciousNameCombination
initialThumbnailPos.set(top, left);

}
});
}
});
}
}
}

Expand Down
219 changes: 219 additions & 0 deletions app/src/main/res/layout-v18/fragment_videoitem_detail.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".VideoItemDetailFragment"
android:textIsSelectable="true"
style="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/videoitem_detail">

<ImageView android:id="@+id/detailThumbnailView"
android:contentDescription="@string/detailThumbnailViewDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="@android:color/black"
android:src="@drawable/dummy_thumbnail_dark"
tools:ignore="RtlHardcoded" />

<ScrollView
android:id="@+id/detailMainContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<RelativeLayout
android:id="@+id/detailVideoThumbnailWindowLayout"
android:layout_width="match_parent"
android:layout_height="@dimen/video_item_detail_thumbnail_image_height"
android:background="?attr/selectableItemBackground">

<ProgressBar android:id="@+id/detailProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:indeterminate="true"/>

<android.support.design.widget.FloatingActionButton
android:id="@+id/playVideoButton"
android:visibility="invisible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
app:backgroundTint="@color/primaryColorYoutube"
android:src="@drawable/ic_play_arrow_black"
android:layout_margin="@dimen/video_item_detail_play_fab_margin"/>

<Button
android:id="@+id/detailVideoThumbnailWindowBackgroundButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/selectableItemBackground"/>

</RelativeLayout>

<RelativeLayout android:id="@+id/detailTextContentLayout"
android:visibility="invisible"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/video_item_detail_info_text_padding"
android:layout_below="@id/detailVideoThumbnailWindowLayout"
android:background="@color/background_gray">

<TextView android:id="@+id/detailVideoTitleView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textStyle="bold"
android:textSize="@dimen/video_item_detail_title_text_size"
android:textAppearance="?android:attr/textAppearanceLarge"
tools:ignore="RtlHardcoded" />

<ImageView android:id="@+id/detailUploaderThumbnailView"
android:contentDescription="@string/detailUploaderThumbnailViewDescription"
android:layout_width="@dimen/video_item_detail_uploader_image_size"
android:layout_height="@dimen/video_item_detail_uploader_image_size"
android:layout_below="@id/detailVideoTitleView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="@drawable/buddy"
tools:ignore="RtlHardcoded" />

<TextView android:id="@+id/detailUploaderView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/detailUploaderThumbnailView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textStyle="bold"
android:textSize="@dimen/video_item_detail_uploader_text_size"
android:textAppearance="?android:attr/textAppearanceLarge"
tools:ignore="RtlHardcoded" />

<TextView android:id="@+id/detailViewCountView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/detailVideoTitleView"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textSize="@dimen/video_item_detail_views_text_size"
android:textAppearance="?android:attr/textAppearanceLarge"
tools:ignore="RtlHardcoded" />

<TextView android:id="@+id/detailThumbsDownCountView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/detailViewCountView"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textSize="@dimen/video_item_detail_likes_text_size"
android:textAppearance="?android:attr/textAppearanceMedium"
tools:ignore="RtlHardcoded" />

<ImageView android:id="@+id/detailThumbsDownImgView"
android:contentDescription="@string/detailThumbsDownImgViewDescription"
android:layout_width="@dimen/video_item_detail_like_image_width"
android:layout_height="@dimen/video_item_detail_like_image_height"
android:layout_below="@id/detailViewCountView"
android:layout_toLeftOf="@id/detailThumbsDownCountView"
android:layout_toStartOf="@id/detailThumbsDownCountView"
android:layout_marginLeft="@dimen/video_item_detail_like_margin"
android:src="@drawable/thumbs_down"
tools:ignore="RtlHardcoded" />

<TextView android:id="@+id/detailThumbsUpCountView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/detailViewCountView"
android:layout_toLeftOf="@id/detailThumbsDownImgView"
android:layout_toStartOf="@id/detailThumbsDownImgView"
android:textSize="@dimen/video_item_detail_likes_text_size"
android:textAppearance="?android:attr/textAppearanceMedium"
tools:ignore="RtlHardcoded" />

<ImageView android:id="@+id/detailThumbsUpImgView"
android:contentDescription="@string/detailThumbsUpImgViewDescription"
android:layout_width="@dimen/video_item_detail_like_image_width"
android:layout_height="@dimen/video_item_detail_like_image_height"
android:layout_below="@id/detailViewCountView"
android:layout_toLeftOf="@id/detailThumbsUpCountView"
android:layout_toStartOf="@id/detailThumbsUpCountView"
android:src="@drawable/thumbs_up"
tools:ignore="RtlHardcoded" />

<TextView android:id="@+id/detailUploadDateView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/detailUploaderView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="@dimen/video_item_detail_upload_date_text_size"
android:textAppearance="?android:attr/textAppearanceLarge"
tools:ignore="RtlHardcoded" />

<TextView android:id="@+id/detailDescriptionView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/detailUploadDateView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="@dimen/video_item_detail_description_text_size"
android:textAppearance="?android:attr/textAppearanceMedium"
tools:ignore="RtlHardcoded" />


<RelativeLayout android:id="@+id/detailNextVideoRootLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/video_item_detail_info_text_padding"
android:layout_below="@id/detailDescriptionView" >

<TextView android:id="@+id/detailNextVideoTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textSize="@dimen/video_item_detail_next_text_size"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/nextVideoTitle"
android:textAllCaps="true" />

<RelativeLayout android:id="@+id/detailNextVidButtonAndContentLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/detailNextVideoTitle">
<FrameLayout
android:id="@+id/detailNextVideoFrame"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/detailNextVideoButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignTop="@id/detailNextVideoFrame"
android:layout_alignBottom="@id/detailNextVideoFrame"
android:background="?attr/selectableItemBackground"/>
</RelativeLayout>
<Button android:id="@+id/detailShowSimilarButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/detailNextVidButtonAndContentLayout"
android:textSize="@dimen/video_item_detail_similar_text_size"
android:text="@string/showSimilarVideosButtonText"/>
</RelativeLayout>

</RelativeLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
34 changes: 17 additions & 17 deletions app/src/main/res/layout/fragment_videoitem_detail.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".VideoItemDetailFragment"
Expand All @@ -10,23 +10,12 @@
android:layout_height="match_parent"
android:id="@+id/videoitem_detail">

<ImageView android:id="@+id/detailThumbnailView"
android:contentDescription="@string/detailThumbnailViewDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="@android:color/black"
android:src="@drawable/dummy_thumbnail_dark"/>

<ScrollView
android:id="@+id/detailMainContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible">
android:visibility="visible"
tools:ignore="UselessParent">

<RelativeLayout
android:layout_width="match_parent"
Expand All @@ -35,9 +24,21 @@
<RelativeLayout
android:id="@+id/detailVideoThumbnailWindowLayout"
android:layout_width="match_parent"
android:layout_height="@dimen/video_item_detail_thumbnail_image_height"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground">

<ImageView android:id="@+id/detailThumbnailView"
android:contentDescription="@string/detailThumbnailViewDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="@android:color/black"
android:src="@drawable/dummy_thumbnail_dark"/>

<ProgressBar android:id="@+id/detailProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down Expand Up @@ -123,7 +124,6 @@
android:layout_below="@id/detailViewCountView"
android:layout_toLeftOf="@id/detailThumbsDownCountView"
android:layout_toStartOf="@id/detailThumbsDownCountView"
android:layout_marginLeft="@dimen/video_item_detail_like_margin"
android:src="@drawable/thumbs_down" />

<TextView android:id="@+id/detailThumbsUpCountView"
Expand Down Expand Up @@ -205,4 +205,4 @@
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
</FrameLayout>
Loading

0 comments on commit f9ad0f1

Please sign in to comment.