@@ -13,48 +13,27 @@ import it.niedermann.owncloud.notes.R
1313import it.niedermann.owncloud.notes.activities.model.Activity
1414import it.niedermann.owncloud.notes.util.HumanReadableFormatter
1515
16- class ActivityListItem : Comparable <ActivityListItem > {
17- val context: Context
18- val activity: Activity ?
19- val fileVersion: FileVersion ?
16+ sealed class ActivityListItem : Comparable <ActivityListItem > {
17+ abstract fun getTimestamp (): Long
18+ abstract fun getTitle (): String?
19+ abstract fun getMessage (): String?
20+ open fun getIconUrl (): String? = null
21+ open fun canBeRestored (): Boolean = false
2022
21- constructor (context: Context , activity: Activity ) {
22- this .context = context
23- this .activity = activity
24- this .fileVersion = null
25- }
23+ override fun compareTo (other : ActivityListItem ): Int =
24+ getTimestamp().compareTo(other.getTimestamp())
2625
27- constructor (context: Context , fileVersion: FileVersion ) {
28- this .context = context
29- this .activity = null
30- this .fileVersion = fileVersion
26+ data class ActivityItem (val activity : Activity ) : ActivityListItem() {
27+ override fun getTimestamp (): Long = activity.datetime.time
28+ override fun getTitle (): String = activity.subject
29+ override fun getMessage (): String? = activity.message
30+ override fun getIconUrl (): String? = activity.icon
3131 }
3232
33- fun getTimestamp () : Long =
34- when {
35- activity != null -> activity.datetime.time
36- fileVersion != null -> fileVersion.modifiedTimestamp
37- else -> 0
38- }
39-
40- fun getTitle () : String? =
41- when {
42- activity != null -> activity.subject
43- fileVersion != null -> context.getString(R .string.new_version_was_created)
44- else -> null
45- }
46-
47- fun getMessage () : String? =
48- when {
49- activity != null -> activity.message
50- fileVersion != null -> HumanReadableFormatter .formatBytes(fileVersion.fileLength)
51- else -> null
52- }
53-
54- fun getIconUrl () : String? = activity?.icon
55-
56- fun canBeRestored () : Boolean = fileVersion != null
57-
58- override fun compareTo (other : ActivityListItem ): Int =
59- getTimestamp().compareTo(other.getTimestamp())
60- }
33+ data class FileVersionItem (val context : Context , val fileVersion : FileVersion ) : ActivityListItem() {
34+ override fun getTimestamp (): Long = fileVersion.modifiedTimestamp
35+ override fun getTitle (): String = context.getString(R .string.new_version_was_created)
36+ override fun getMessage (): String = HumanReadableFormatter .formatBytes(fileVersion.fileLength) ? : " "
37+ override fun canBeRestored (): Boolean = true
38+ }
39+ }
0 commit comments