File tree Expand file tree Collapse file tree 7 files changed +28
-21
lines changed
Expand file tree Collapse file tree 7 files changed +28
-21
lines changed Original file line number Diff line number Diff line change 44 <uses-permission android : name =" android.permission.ACCESS_NETWORK_STATE" />
55 <uses-permission android : name =" android.permission.INTERNET" />
66 <uses-permission android : name =" android.permission.BLUETOOTH" />
7+ <uses-permission android : name =" android.permission.POST_NOTIFICATIONS" />
78 <uses-permission android : name =" android.permission.READ_EXTERNAL_STORAGE" />
89 <uses-permission android : name =" android.permission.RECEIVE_BOOT_COMPLETED" />
910 <uses-permission android : name =" android.permission.WRITE_EXTERNAL_STORAGE" />
Original file line number Diff line number Diff line change @@ -269,7 +269,7 @@ class BackupManager private constructor(context: Context) {
269269
270270 val historyEntry = BackupHistoryEntry (
271271 timestamp = ZonedDateTime .now(),
272- duration = Duration .ZERO ,
272+ duration = HourDuration ( Duration .ZERO ) ,
273273 scheduled = scheduled,
274274 cancelled = cancelled,
275275 snapshotId = summary?.snapshot_id,
@@ -291,7 +291,7 @@ class BackupManager private constructor(context: Context) {
291291 if (removeOld && throwable == null && (folder.keepLast != null || folder.keepWithin != null )) {
292292 resticRepo.forget(
293293 folder.keepLast,
294- folder.keepWithin,
294+ folder.keepWithin?.duration ,
295295 prune = true
296296 ).handle { _, _ ->
297297 callback()
Original file line number Diff line number Diff line change @@ -22,15 +22,17 @@ object ZonedDateTimeSerializer : KSerializer<ZonedDateTime> {
2222 ZonedDateTime .parse(decoder.decodeString())
2323}
2424
25- object DurationSerializer : KSerializer<Duration> {
25+ data class HourDuration (val duration : Duration )
26+
27+ object HourDurationSerializer : KSerializer<HourDuration> {
2628 override val descriptor: SerialDescriptor =
27- PrimitiveSerialDescriptor ((Duration ::class ).simpleName!! , PrimitiveKind .LONG )
29+ PrimitiveSerialDescriptor ((HourDuration ::class ).simpleName!! , PrimitiveKind .LONG )
2830
29- override fun serialize (encoder : Encoder , value : Duration ) =
30- encoder.encodeLong(value.toHours())
31+ override fun serialize (encoder : Encoder , value : HourDuration ) =
32+ encoder.encodeLong(value.duration. toHours())
3133
32- override fun deserialize (decoder : Decoder ): Duration =
33- Duration .ofHours(decoder.decodeLong())
34+ override fun deserialize (decoder : Decoder ): HourDuration =
35+ HourDuration ( Duration .ofHours(decoder.decodeLong() ))
3436}
3537
3638object FileSerializer : KSerializer<File> {
Original file line number Diff line number Diff line change 11package de.lolhens.resticui.config
22
3- import de.lolhens.resticui.DurationSerializer
3+ import de.lolhens.resticui.HourDuration
4+ import de.lolhens.resticui.HourDurationSerializer
45import de.lolhens.resticui.ZonedDateTimeSerializer
56import de.lolhens.resticui.restic.ResticSnapshotId
67import kotlinx.serialization.Serializable
7- import java.time.Duration
88import java.time.ZonedDateTime
99
1010@Serializable
1111data class BackupHistoryEntry (
1212 val timestamp : @Serializable(with = ZonedDateTimeSerializer ::class ) ZonedDateTime ,
13- val duration : @Serializable(with = DurationSerializer ::class ) Duration ,
13+ val duration : @Serializable(with = HourDurationSerializer ::class ) HourDuration ,
1414 val scheduled : Boolean ,
1515 val cancelled : Boolean ,
1616 val snapshotId : ResticSnapshotId ? ,
Original file line number Diff line number Diff line change 11package de.lolhens.resticui.config
22
3- import de.lolhens.resticui.DurationSerializer
43import de.lolhens.resticui.FileSerializer
4+ import de.lolhens.resticui.HourDuration
5+ import de.lolhens.resticui.HourDurationSerializer
56import de.lolhens.resticui.ui.folder.FolderEditFragment
67import kotlinx.serialization.Serializable
78import java.io.File
8- import java.time.Duration
99import java.time.ZonedDateTime
1010
1111@Serializable
@@ -15,7 +15,7 @@ data class FolderConfig(
1515 val path : @Serializable(with = FileSerializer ::class ) File ,
1616 val schedule : String ,
1717 val keepLast : Int? = null ,
18- val keepWithin : @Serializable(with = DurationSerializer ::class ) Duration ? = null ,
18+ val keepWithin : @Serializable(with = HourDurationSerializer ::class ) HourDuration ? = null ,
1919 val history : List <BackupHistoryEntry > = emptyList()
2020) {
2121 fun repo (config : Config ): RepoConfig ? = config.repos.find { it.base.id == repoId }
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import android.view.*
55import android.widget.ArrayAdapter
66import androidx.fragment.app.Fragment
77import de.lolhens.resticui.BackupManager
8+ import de.lolhens.resticui.HourDuration
89import de.lolhens.resticui.R
910import de.lolhens.resticui.config.FolderConfig
1011import de.lolhens.resticui.config.FolderConfigId
@@ -109,7 +110,7 @@ class FolderEditFragment : Fragment() {
109110 binding.editFolder.setText(folder.path.path)
110111 binding.spinnerSchedule.setSelection(schedules.indexOfFirst { it.first == folder.schedule })
111112 val scheduleIndex = retainProfiles.indexOfFirst {
112- it.toLong() == folder.keepWithin?.toHours()
113+ it.toLong() == folder.keepWithin?.duration?. toHours()
113114 }
114115 binding.spinnerRetainWithin.setSelection(if (scheduleIndex == - 1 ) 0 else scheduleIndex)
115116 }
@@ -133,7 +134,7 @@ class FolderEditFragment : Fragment() {
133134 val schedule = binding.spinnerSchedule.selectedItem?.toString()
134135 val keepWithin =
135136 if (retainProfiles[binding.spinnerRetainWithin.selectedItemPosition] < 0 ) null
136- else Duration .ofHours(retainProfiles[binding.spinnerRetainWithin.selectedItemPosition].toLong())
137+ else HourDuration ( Duration .ofHours(retainProfiles[binding.spinnerRetainWithin.selectedItemPosition].toLong() ))
137138
138139 if (
139140 repo != null &&
Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ class FolderFragment : Fragment() {
7373 if (folder.keepLast == null ) " " else " in last ${folder.keepLast} " ,
7474 if (folder.keepWithin == null ) " " else " within ${
7575 Formatters .durationDaysHours(
76- folder.keepWithin
76+ folder.keepWithin.duration
7777 )
7878 } "
7979 ).filter { it.isNotEmpty() }.joinToString(" and " )
@@ -82,9 +82,9 @@ class FolderFragment : Fragment() {
8282 val resticRepo = repo.repo(backupManager.restic)
8383
8484 backupManager.observeConfig(viewLifecycleOwner) { config ->
85- val folder = config.folders.find { it.id == folderId }!!
85+ val folder = config.folders.find { it.id == folderId }
8686
87- val lastSuccessfulBackup = folder.lastBackup(filterSuccessful = true )
87+ val lastSuccessfulBackup = folder? .lastBackup(filterSuccessful = true )
8888
8989 binding.textLastBackup.text =
9090 if (lastSuccessfulBackup == null ) " "
@@ -95,8 +95,11 @@ class FolderFragment : Fragment() {
9595 binding.progressFolderSnapshots.visibility = GONE
9696
9797 val snapshots =
98- snapshots?.filter { it.paths.contains(folder.path) }?.reversed()
99- ? : emptyList()
98+ if (folder != null )
99+ snapshots?.filter { it.paths.contains(folder.path) }?.reversed()
100+ ? : emptyList()
101+ else
102+ emptyList()
100103
101104 snapshotIds = snapshots.map { it.id }
102105 binding.listFolderSnapshots.adapter = ArrayAdapter (
You can’t perform that action at this time.
0 commit comments