Skip to content

Commit e79c7ed

Browse files
ottx96Manuel Ott
andauthored
Feature/cleanup (#66)
* auto cleanup implemented * Implement configuration (Setup) Auto-Delete old files (gdrive) * Implement configuration (Setup) Auto-Delete old files (gdrive) Co-authored-by: Manuel Ott <manuel.ott@x.de>
1 parent 55d708d commit e79c7ed

File tree

5 files changed

+12
-6
lines changed

5 files changed

+12
-6
lines changed

src/main/kotlin/de/ott/ivy/config/Configuration.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import java.util.*
1111
import java.util.concurrent.TimeUnit
1212

1313
@ExperimentalSerializationApi
14-
data class Configuration(val taskId: String, val cleanInterval: Int, val timeUnit: TimeUnit = TimeUnit.DAYS, val language: Locale = Locale.getDefault()) {
14+
data class Configuration(val taskId: String, val cleanInterval: Long, val timeUnit: ChronoUnit = ChronoUnit.DAYS, val language: Locale = Locale.getDefault()) {
1515

1616
companion object{
1717
private val gson: Gson by lazy{

src/main/kotlin/de/ott/ivy/gdrive/RemoteFilesHandler.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import java.time.temporal.ChronoUnit
1111

1212
class RemoteFilesHandler(val service: Drive) {
1313

14-
fun cleanupFilesOlderThan(time: Long, chronoUnit: ChronoUnit){
14+
fun cleanupFilesOlderThan(time: Long, chronoUnit: ChronoUnit) {
15+
println("cleaning outdated gdrive files..")
1516
val olderThan = LocalDateTime.now().minus(time + 1, chronoUnit)
1617
service.files().list().apply {
1718
spaces = "appDataFolder"

src/main/kotlin/de/ott/ivy/ui/IvyLee.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package de.ott.ivy.ui
22

3+
import de.ott.ivy.config.Configuration
34
import de.ott.ivy.data.IvyLeeTask
45
import de.ott.ivy.ui.dialog.TaskDialog
56
import de.ott.ivy.data.TaskGridCellContainer
@@ -120,8 +121,11 @@ class IvyLee : View("Ivy-Lee Tracking") {
120121
// auto-sync tasks to gdrive
121122
Thread{
122123
while(true){
124+
var ct = 0
123125
try {
124126
sleep( 1000 * 60 * 15 ) // 15 Minuten
127+
if(++ct % 10 == 0) // 150 Minuten
128+
gdrive.cleanupFilesOlderThan(Configuration.instance.cleanInterval, Configuration.instance.timeUnit)
125129
// write file
126130
println("syncing tasks to gdrive..")
127131
val tasks = File("tasks-auto-sync.db")

src/main/kotlin/de/ott/ivy/ui/dialog/SetupDialog.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import javafx.scene.image.Image
1616
import javafx.scene.layout.BorderPane
1717
import javafx.stage.Stage
1818
import tornadofx.*
19+
import java.time.temporal.ChronoUnit
1920
import java.util.*
2021
import java.util.concurrent.TimeUnit
2122

@@ -86,7 +87,7 @@ class SetupDialog : View("Setup") {
8687
}
8788
buttonOK.onAction = EventHandler {
8889
Entrypoint.CONFIG_FILE.outputStream().writer().use {
89-
it.write(Configuration(comboBoxTaskID.value, sliderInterval.value.toInt(), TimeUnit.DAYS, Locale.forLanguageTag(language.text)).toJsonString())
90+
it.write(Configuration(comboBoxTaskID.value, sliderInterval.value.toLong(), ChronoUnit.MONTHS, Locale.forLanguageTag(language.text)).toJsonString())
9091
}
9192
success = Entrypoint.CONFIG_FILE.exists()
9293
close()

src/main/resources/views/SetupDialog.fxml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
<?import javafx.scene.layout.*?>
66
<?import javafx.scene.text.*?>
77

8-
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="300.0" prefWidth="500.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
8+
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="350.0" prefWidth="500.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
99
<center>
1010
<Accordion BorderPane.alignment="CENTER">
1111
<panes>
12-
<TitledPane text="Language">
12+
<TitledPane text="Language" expanded="true">
1313
<content>
1414
<BorderPane fx:id="bp_language" prefHeight="200.0" prefWidth="200.0">
1515
<left>
@@ -56,7 +56,7 @@
5656
</center></BorderPane>
5757
</content>
5858
</TitledPane>
59-
<TitledPane text="Settings">
59+
<TitledPane expanded="false" text="Settings">
6060
<content>
6161
<BorderPane prefHeight="150.0" prefWidth="200.0">
6262
<top>

0 commit comments

Comments
 (0)