mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
Use DateTimeFormatter to create backup file timestamp.
This commit is contained in:
parent
987782bac2
commit
71976f45c1
@ -12,10 +12,12 @@ import com.github.libretube.ui.base.BasePreferenceFragment
|
|||||||
import com.github.libretube.ui.dialogs.BackupDialog
|
import com.github.libretube.ui.dialogs.BackupDialog
|
||||||
import com.github.libretube.util.BackupHelper
|
import com.github.libretube.util.BackupHelper
|
||||||
import com.github.libretube.util.ImportHelper
|
import com.github.libretube.util.ImportHelper
|
||||||
import java.time.LocalDate
|
import java.time.LocalDateTime
|
||||||
import java.time.LocalTime
|
import java.time.format.DateTimeFormatter
|
||||||
|
|
||||||
class BackupRestoreSettings : BasePreferenceFragment() {
|
class BackupRestoreSettings : BasePreferenceFragment() {
|
||||||
|
private val backupDateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH:mm:ss")
|
||||||
|
|
||||||
override val titleResourceId: Int = R.string.backup_restore
|
override val titleResourceId: Int = R.string.backup_restore
|
||||||
|
|
||||||
// backup and restore database
|
// backup and restore database
|
||||||
@ -105,7 +107,8 @@ class BackupRestoreSettings : BasePreferenceFragment() {
|
|||||||
advancesBackup?.setOnPreferenceClickListener {
|
advancesBackup?.setOnPreferenceClickListener {
|
||||||
BackupDialog {
|
BackupDialog {
|
||||||
backupFile = it
|
backupFile = it
|
||||||
createBackupFile.launch(getBackupFileName())
|
val timestamp = backupDateTimeFormatter.format(LocalDateTime.now())
|
||||||
|
createBackupFile.launch("libretube-backup-$timestamp.json")
|
||||||
}
|
}
|
||||||
.show(childFragmentManager, null)
|
.show(childFragmentManager, null)
|
||||||
true
|
true
|
||||||
@ -117,9 +120,4 @@ class BackupRestoreSettings : BasePreferenceFragment() {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getBackupFileName(): String {
|
|
||||||
val time = LocalTime.now().toString().split(".").firstOrNull()
|
|
||||||
return "libretube-backup-${LocalDate.now()}-$time.json"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user