Skip to content

Commit

Permalink
added a simple view of the RYD info when the user clicks the area wit…
Browse files Browse the repository at this point in the history
…h views/thumbs (closes #44)
  • Loading branch information
polymorphicshade committed Mar 27, 2024
1 parent 786ea63 commit 57d216b
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import android.view.animation.DecelerateInterpolator;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.AttrRes;
Expand Down Expand Up @@ -360,6 +361,44 @@ public void onChange(final boolean selfChange) {
public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container,
final Bundle savedInstanceState) {
binding = FragmentVideoDetailBinding.inflate(inflater, container, false);
binding.detailsPanel.setOnClickListener(view -> {
if (currentInfo == null) {
return;
}

final Context context = requireContext();

final ReturnYouTubeDislikeInfo rydInfo = currentInfo.getRydInfo();

if (rydInfo == null) {
return;
}

final View alertDialogView = LayoutInflater.from(activity)
.inflate(R.layout.dialog_return_youtube_dislike_info, null);
// like count
final TextView likeCountTextView = alertDialogView.findViewById(R.id.likeCount);
likeCountTextView.setText(Localization.localizeNumber(activity, rydInfo.likes));
// dislike count
final TextView dislikeCountTextView = alertDialogView.findViewById(R.id.dislikeCount);
dislikeCountTextView.setText(Localization.localizeNumber(activity, rydInfo.dislikes));
// ratio
final TextView ratioTextView = alertDialogView.findViewById(R.id.ratio);
ratioTextView.setText(Localization.localizeRating(activity, rydInfo.rating));
// view count
final TextView viewCountTextView = alertDialogView.findViewById(R.id.viewCount);
viewCountTextView.setText(Localization.localizeNumber(activity, rydInfo.viewCount));

final AlertDialog alertDialog =
new AlertDialog.Builder(context)
.setView(alertDialogView)
.setPositiveButton(context.getString(R.string.close), (dialog, i) -> {
dialog.dismiss();
})
.create();

alertDialog.show();
});
return binding.getRoot();
}

Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/org/schabi/newpipe/util/Localization.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ public static String localizeWatchingCount(final Context context, final long wat
localizeNumber(context, watchingCount));
}

public static String localizeRating(final Context context, final double number) {
final NumberFormat nf = NumberFormat.getInstance(getAppLocale(context));
nf.setMaximumFractionDigits(2);
return nf.format(number) + " / 5";
}

public static String shortCount(final Context context, final long count) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return CompactDecimalFormat.getInstance(getAppLocale(context),
Expand Down
106 changes: 106 additions & 0 deletions app/src/main/res/layout/dialog_return_youtube_dislike_info.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingStart="32dp"
android:paddingTop="16dp"
android:paddingEnd="16dp"
android:paddingBottom="16dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:gravity="center"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="👍"
android:textSize="@dimen/video_item_detail_return_youtube_dislike_info_text_size" />

<TextView
android:id="@+id/likeCount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginStart="24dp"
android:gravity="start"
android:textSize="@dimen/video_item_detail_return_youtube_dislike_info_text_size"
tools:text="777" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:gravity="center"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="👎"
android:textSize="@dimen/video_item_detail_return_youtube_dislike_info_text_size" />

<TextView
android:id="@+id/dislikeCount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginStart="24dp"
android:gravity="start"
android:textSize="@dimen/video_item_detail_return_youtube_dislike_info_text_size"
tools:text="777" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:gravity="center"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="@dimen/video_item_detail_return_youtube_dislike_info_text_size" />

<TextView
android:id="@+id/ratio"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginStart="24dp"
android:gravity="start"
android:textSize="@dimen/video_item_detail_return_youtube_dislike_info_text_size"
tools:text="1.55 / 5" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:gravity="center"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="👁️"
android:textSize="@dimen/video_item_detail_return_youtube_dislike_info_text_size" />

<TextView
android:id="@+id/viewCount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginStart="24dp"
android:gravity="start"
android:textSize="@dimen/video_item_detail_return_youtube_dislike_info_text_size"
tools:text="7777777" />
</LinearLayout>
</LinearLayout>
4 changes: 3 additions & 1 deletion app/src/main/res/layout/fragment_video_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,9 @@
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:paddingLeft="6dp"
android:paddingRight="6dp">
android:paddingRight="6dp"
android:clickable="true"
android:focusable="true">

<org.schabi.newpipe.views.NewPipeTextView
android:id="@+id/detail_view_count_view"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<dimen name="video_item_detail_sub_channel_text_size">14sp</dimen>
<dimen name="video_item_detail_upload_date_text_size">13sp</dimen>
<dimen name="video_item_detail_description_text_size">13sp</dimen>
<dimen name="video_item_detail_return_youtube_dislike_info_text_size">16sp</dimen>
<dimen name="channel_rss_title_size">12sp</dimen>
<!-- Elements Size -->
<dimen name="video_item_detail_uploader_image_size">32dp</dimen>
Expand Down

0 comments on commit 57d216b

Please sign in to comment.