Update duration data to a floating text

This commit is contained in:
Ivan Agosto 2024-03-22 18:12:14 -06:00
parent ba0a298ea9
commit 40b193a816
5 changed files with 72 additions and 15 deletions

View File

@ -9,7 +9,9 @@ import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import com.squareup.picasso.Picasso
import kotlinx.android.synthetic.main.view_video.view.duration
import org.libre.agosto.p2play.*
import org.libre.agosto.p2play.helpers.mapSeconds
import org.libre.agosto.p2play.models.VideoModel
import java.io.Serializable
@ -27,6 +29,7 @@ class VideosAdapter(private val myDataset: ArrayList<VideoModel>) :
val tittle: TextView
val description: TextView
val context: Context
val duration: TextView
init {
// Define click listener for the ViewHolder's View
@ -35,6 +38,7 @@ class VideosAdapter(private val myDataset: ArrayList<VideoModel>) :
thumb = view.findViewById(R.id.thumb)
userImg = view.findViewById(R.id.userImg)
context = view.context
duration = view.duration
}
}
@ -71,19 +75,12 @@ class VideosAdapter(private val myDataset: ArrayList<VideoModel>) :
Picasso.get().load(R.drawable.default_avatar).into(holder.userImg)
val viewsText = holder.context.getString(R.string.view_text)
var timeText = holder.context.getString(R.string.timeSec_text)
var timeString = myDataset[position].duration.toString()
val seconds = myDataset[position].duration.toInt();
if(seconds > 60 && seconds < (60 * 60)){
timeText = holder.context.getString(R.string.timeMin_text)
timeString = (seconds / 60).toString() + ":" + (seconds % 60).toString()
}
else if(seconds > (60 * 60)){
timeText = holder.context.getString(R.string.timeHrs_text)
timeString = (seconds / 60 / 60).toString() + ":" + (seconds / 60 % 60).toString()
}
val timeString = mapSeconds(seconds)
holder.description.text = myDataset[position].username+" - "+myDataset[position].views+" "+viewsText+" - "+timeString+" "+timeText
holder.duration.text = timeString
holder.description.text = myDataset[position].username+" - "+myDataset[position].views+" "+viewsText
}

View File

@ -0,0 +1,20 @@
package org.libre.agosto.p2play.helpers
fun mapSeconds (inputSeconds: Int): String {
val seconds = (inputSeconds % 60)
var minutes = inputSeconds / 60
var hours = 0
if (minutes > 60) {
hours = minutes / 60
minutes = minutes % 60
}
var result = minutes.toString().padStart(2, '0') + ":" + seconds.toString().padStart(2, '0')
if (hours > 0) {
result = hours.toString().padStart(2, '0') + ":" + result
}
return result
}

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="5dp" />
<!-- This is the border color -->
<!--- This is the background color -->
<solid android:color="?attr/colorSecondary" />
</shape>

View File

@ -14,11 +14,34 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/thumb"
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="230dp"
app:srcCompat="@android:drawable/ic_menu_gallery" />
android:layout_height="match_parent">
<ImageView
android:id="@+id/thumb"
android:layout_width="match_parent"
android:layout_height="230dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@android:drawable/ic_menu_gallery" />
<TextView
android:id="@+id/duration"
android:layout_width="65dp"
android:layout_height="19dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="16dp"
android:textColor="?attr/colorOnSecondary"
android:background="@drawable/round_text"
android:ems="10"
android:text="00:00"
android:paddingHorizontal="3dp"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout
android:layout_width="match_parent"

View File

@ -10,6 +10,9 @@
<color name="colorLike">#FF3C9100</color>
<color name="colorDislike">#ec020e</color>
<color name="colorProfile">#262626</color>
<color name="durationBackground">#88000000</color>
<color name="durationColor">#ffffff</color>
<color name="seed">#f16805</color>
<color name="md_theme_light_primary">#9F4200</color>