Added relative time to download history card

pull/44/head
Denis Çerri 3 years ago
parent 224c22a5ff
commit a88d35ea42
No known key found for this signature in database
GPG Key ID: 95C43D517D830350

@ -7,7 +7,7 @@ import android.graphics.ColorMatrix
import android.graphics.ColorMatrixColorFilter
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.text.format.DateUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -26,10 +26,9 @@ import com.google.android.material.button.MaterialButton
import com.google.android.material.card.MaterialCardView
import com.squareup.picasso.Picasso
import java.io.File
import java.text.DateFormat
import java.text.SimpleDateFormat
import java.util.*
class HistoryAdapter(onItemClickListener: OnItemClickListener, activity: Activity) : ListAdapter<HistoryItem?, HistoryAdapter.ViewHolder>(AsyncDifferConfig.Builder(DIFF_CALLBACK).build()) {
private val checkedItems: ArrayList<Long>
private val onItemClickListener: OnItemClickListener
@ -88,22 +87,29 @@ class HistoryAdapter(onItemClickListener: OnItemClickListener, activity: Activit
// TIME DOWNLOADED ----------------------------------
val datetime = card.findViewById<TextView>(R.id.downloads_info_time)
val time = item.time
val downloadedTime: String
if (time == 0L) {
downloadedTime = activity.getString(R.string.currently_downloading) + " " + item.type
} else {
val cal = Calendar.getInstance()
val date = Date(time * 1000L)
cal.time = date
val day = cal[Calendar.DAY_OF_MONTH]
val month = cal.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault())
val year = cal[Calendar.YEAR]
val formatter: DateFormat = SimpleDateFormat("HH:mm", Locale.getDefault())
val timeString = formatter.format(date)
downloadedTime = "$day $month $year - $timeString"
}
datetime.text = downloadedTime
val relativeTime = DateUtils.getRelativeTimeSpanString(
item.time * 1000L,
System.currentTimeMillis(),
DateUtils.MINUTE_IN_MILLIS
)
//
// val time = item.time
// val downloadedTime: String
// if (time == 0L) {
// downloadedTime = activity.getString(R.string.currently_downloading) + " " + item.type
// } else {
// val cal = Calendar.getInstance()
// val date = Date(time * 1000L)
// cal.time = date
// val day = cal[Calendar.DAY_OF_MONTH]
// val month = cal.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault())
// val year = cal[Calendar.YEAR]
// val formatter: DateFormat = SimpleDateFormat("HH:mm", Locale.getDefault())
// val timeString = formatter.format(date)
// downloadedTime = "$day $month $year - $timeString"
// }
datetime.text = relativeTime
// BUTTON ----------------------------------
val buttonLayout = card.findViewById<LinearLayout>(R.id.downloads_download_button_layout)

Loading…
Cancel
Save