Improve time for videos

This commit is contained in:
Thomas 2020-09-12 17:54:37 +02:00
parent 5660fb15e5
commit cb9f8605d5
4 changed files with 47 additions and 16 deletions

View File

@ -90,7 +90,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
Helper.loadGiF(context, peertube.getChannel(), holder.peertube_profile); Helper.loadGiF(context, peertube.getChannel(), holder.peertube_profile);
} }
holder.peertube_title.setText(peertube.getName()); holder.peertube_title.setText(peertube.getName());
holder.peertube_duration.setText(context.getString(R.string.duration_video, Helper.secondsToString(peertube.getDuration()))); holder.peertube_duration.setText(Helper.secondsToString(peertube.getDuration()));
holder.peertube_date.setText(String.format(" - %s", Helper.dateDiff(context, peertube.getCreated_at()))); holder.peertube_date.setText(String.format(" - %s", Helper.dateDiff(context, peertube.getCreated_at())));
holder.peertube_views.setText(context.getString(R.string.number_view_video, Helper.withSuffix(peertube.getView()))); holder.peertube_views.setText(context.getString(R.string.number_view_video, Helper.withSuffix(peertube.getView())));

View File

@ -361,12 +361,12 @@ public class Helper {
long months = days / 30; long months = days / 30;
long years = days / 365; long years = days / 365;
String format = DateFormat.getDateInstance(DateFormat.SHORT).format(dateToot); String format = DateFormat.getDateInstance(DateFormat.LONG).format(dateToot);
if (years > 0) { if (years > 0) {
return format; return format;
} else if (months > 0 || days > 7) { } else if (months > 0 || days > 7) {
//Removes the year depending of the locale from DateFormat.SHORT format //Removes the year depending of the locale from DateFormat.SHORT format
SimpleDateFormat df = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()); SimpleDateFormat df = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.LONG, Locale.getDefault());
df.applyPattern(df.toPattern().replaceAll("[^\\p{Alpha}]*y+[^\\p{Alpha}]*", "")); df.applyPattern(df.toPattern().replaceAll("[^\\p{Alpha}]*y+[^\\p{Alpha}]*", ""));
return df.format(dateToot); return df.format(dateToot);
} else if (days > 0) } else if (days > 0)

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="1dp"
android:color="@android:color/black" />
<solid android:color="@android:color/black" />
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<corners android:radius="5dp" />
</shape>

View File

@ -15,6 +15,7 @@
see <http://www.gnu.org/licenses>. see <http://www.gnu.org/licenses>.
--> -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_container" android:id="@+id/main_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -39,13 +40,34 @@
android:textStyle="bold" android:textStyle="bold"
android:visibility="gone" /> android:visibility="gone" />
<ImageView <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/peertube_video_image"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="200dp" android:layout_height="200dp">
android:contentDescription="@string/image_preview"
android:gravity="center" <ImageView
android:scaleType="centerCrop" /> android:id="@+id/peertube_video_image"
android:layout_width="match_parent"
android:layout_height="200dp"
android:contentDescription="@string/image_preview"
android:gravity="center"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/peertube_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@drawable/rounded_corner"
android:paddingStart="4dp"
android:paddingEnd="4dp"
android:textColor="@android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout <LinearLayout
android:id="@+id/bottom_container" android:id="@+id/bottom_container"
@ -93,16 +115,10 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"> android:orientation="horizontal">
<TextView
android:id="@+id/peertube_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView <TextView
android:id="@+id/peertube_views" android:id="@+id/peertube_views"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content" />
android:layout_marginStart="5dp" />
<TextView <TextView
android:id="@+id/peertube_date" android:id="@+id/peertube_date"