Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2020-10-26 10:53:31 +01:00 committed by Andy Scherzinger
parent bff08bbc17
commit ad5ca22e23
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
6 changed files with 49 additions and 8 deletions

View file

@ -46,7 +46,7 @@ class SetStatusDialogFragmentIT : AbstractIT() {
PredefinedStatus("commuting", "🚌", "Commuting", ClearAt("period", "1800")),
PredefinedStatus("remote-work", "🏡", "Working remotely", ClearAt("end-of", "day")),
PredefinedStatus("sick-leave", "🤒", "Out sick", ClearAt("end-of", "day")),
PredefinedStatus("vacationing", "🌴", "Vacationing", ClearAt("", "")) // switch to null
PredefinedStatus("vacationing", "🌴", "Vacationing", null)
)
shortSleep()

View file

@ -98,7 +98,7 @@ class SetStatusDialogFragment : DialogFragment(),
super.onViewCreated(view, savedInstanceState)
accountManager = (activity as BaseActivity).userAccountManager
adapter = PredefinedStatusListAdapter()
adapter = PredefinedStatusListAdapter(requireContext())
if (this::predefinedStatus.isInitialized) {
adapter.list = predefinedStatus
}

View file

@ -22,13 +22,14 @@
package com.owncloud.android.ui.adapter
import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.owncloud.android.databinding.PredefinedStatusBinding
import com.owncloud.android.lib.resources.users.PredefinedStatus
class PredefinedStatusListAdapter : RecyclerView.Adapter<PredefinedStatusViewHolder>() {
class PredefinedStatusListAdapter(val context: Context) : RecyclerView.Adapter<PredefinedStatusViewHolder>() {
internal var list: List<PredefinedStatus> = emptyList()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PredefinedStatusViewHolder {
@ -37,7 +38,7 @@ class PredefinedStatusListAdapter : RecyclerView.Adapter<PredefinedStatusViewHol
}
override fun onBindViewHolder(holder: PredefinedStatusViewHolder, position: Int) {
holder.bind(list[position])
holder.bind(list[position], context)
}
override fun getItemCount(): Int {

View file

@ -22,14 +22,33 @@
package com.owncloud.android.ui.adapter
import android.content.Context
import androidx.recyclerview.widget.RecyclerView
import com.owncloud.android.R
import com.owncloud.android.databinding.PredefinedStatusBinding
import com.owncloud.android.lib.resources.users.PredefinedStatus
import com.owncloud.android.utils.DisplayUtils
class PredefinedStatusViewHolder(private val binding: PredefinedStatusBinding) : RecyclerView.ViewHolder(binding.root) {
fun bind(status: PredefinedStatus) {
fun bind(status: PredefinedStatus, context: Context) {
binding.icon.text = status.icon
binding.name.text = status.message
binding.clearAt.text = status.clearAt?.time // TODO better
if (status.clearAt == null) {
binding.clearAt.text = context.getString(R.string.dontClear)
} else {
val clearAt = status.clearAt!!
if (clearAt.type.equals("period")) {
binding.clearAt.text = DisplayUtils.getRelativeTimestamp(
context,
System.currentTimeMillis() + clearAt.time.toInt() * 1000,
true)
} else {
// end-of
if (clearAt.time.equals("day")) {
binding.clearAt.text = context.getString(R.string.today)
}
}
}
}
}

View file

@ -313,6 +313,15 @@ public final class DisplayUtils {
DateUtils.WEEK_IN_MILLIS, 0);
}
public static CharSequence getRelativeTimestamp(Context context, long modificationTimestamp, boolean showFuture) {
return getRelativeDateTimeString(context,
modificationTimestamp,
DateUtils.SECOND_IN_MILLIS,
DateUtils.WEEK_IN_MILLIS,
0,
showFuture);
}
/**
* determines the info level color based on {@link #RELATIVE_THRESHOLD_WARNING}.
@ -331,15 +340,25 @@ public final class DisplayUtils {
public static CharSequence getRelativeDateTimeString(Context c, long time, long minResolution,
long transitionResolution, int flags) {
return getRelativeDateTimeString(c, time, minResolution, transitionResolution, flags, false);
}
public static CharSequence getRelativeDateTimeString(Context c,
long time,
long minResolution,
long transitionResolution,
int flags,
boolean showFuture) {
CharSequence dateString = "";
// in Future
if (time > System.currentTimeMillis()) {
if (!showFuture && time > System.currentTimeMillis()) {
return DisplayUtils.unixTimeToHumanReadable(time);
}
// < 60 seconds -> seconds ago
else if ((System.currentTimeMillis() - time) < 60 * 1000 && minResolution == DateUtils.SECOND_IN_MILLIS) {
long diff = System.currentTimeMillis() - time;
if (diff > 0 && diff < 60 * 1000 && minResolution == DateUtils.SECOND_IN_MILLIS) {
return c.getString(R.string.file_list_seconds_ago);
} else {
dateString = DateUtils.getRelativeDateTimeString(c, time, minResolution, transitionResolution, flags);

View file

@ -951,4 +951,6 @@
<string name="away">Away</string>
<string name="invisible">Invisible</string>
<string translatable="false" name="divider"></string>
<string name="dontClear">Don\'t clear</string>
<string name="today">Today</string>
</resources>