Fix spotless issues

Signed-off-by: Jonas Mayer <jonas.a.mayer@gmx.net>
This commit is contained in:
Jonas Mayer 2023-12-19 14:25:45 +01:00 committed by Jonas Mayer
parent 5cc6322725
commit 885aa703e8
11 changed files with 63 additions and 58 deletions

View file

@ -48,7 +48,8 @@ class EtmBackgroundJobsFragment : EtmBaseFragment(), Injectable {
@Inject
lateinit var preferences: AppPreferences
class Adapter(private val inflater: LayoutInflater, private val preferences: AppPreferences) : RecyclerView.Adapter<Adapter.ViewHolder>(){
class Adapter(private val inflater: LayoutInflater, private val preferences: AppPreferences) :
RecyclerView.Adapter<Adapter.ViewHolder>() {
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val uuid = view.findViewById<TextView>(R.id.etm_background_job_uuid)
@ -88,7 +89,6 @@ class EtmBackgroundJobsFragment : EtmBaseFragment(), Injectable {
View.GONE
}
}
}
private val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:MM:ssZ", Locale.getDefault())
@ -129,10 +129,13 @@ class EtmBackgroundJobsFragment : EtmBaseFragment(), Injectable {
}
val logs = preferences.readLogEntry()
val logsForThisWorker = logs.filter { BackgroundJobManagerImpl.parseTag(it.workerClass)?.second == info.workerClass }
val logsForThisWorker =
logs.filter { BackgroundJobManagerImpl.parseTag(it.workerClass)?.second == info.workerClass }
if (logsForThisWorker.isNotEmpty()) {
vh.executionTimesRow.visibility = View.VISIBLE
vh.executionCount.text = logsForThisWorker.filter { it.started != null }.size.toString() + " (${logsForThisWorker.filter { it.finished != null }.size})"
vh.executionCount.text =
"${logsForThisWorker.filter { it.started != null }.size} " +
"(${logsForThisWorker.filter { it.finished != null }.size})"
var logText = "Worker Logs\n\n" +
"*** Does NOT differentiate between imitate or periodic kinds of Work! ***\n" +
"*** Times run in 48h: Times started (Times finished) ***\n"
@ -152,7 +155,6 @@ class EtmBackgroundJobsFragment : EtmBaseFragment(), Injectable {
vh.executionCount.text = "0"
vh.executionTimesRow.visibility = View.GONE
}
}
}
@ -186,22 +188,27 @@ class EtmBackgroundJobsFragment : EtmBaseFragment(), Injectable {
vm.cancelAllJobs()
true
}
R.id.etm_background_jobs_prune -> {
vm.pruneJobs()
true
}
R.id.etm_background_jobs_start_test -> {
vm.startTestJob(periodic = false)
true
}
R.id.etm_background_jobs_schedule_test -> {
vm.startTestJob(periodic = true)
true
}
R.id.etm_background_jobs_cancel_test -> {
vm.cancelTestJob()
true
}
else -> super.onOptionsItemSelected(item)
}
}

View file

@ -51,7 +51,7 @@ import javax.inject.Provider
*
* This class is doing too many things and should be split up into smaller factories.
*/
@Suppress("LongParameterList") // satisfied by DI
@Suppress("LongParameterList", "TooManyFunctions") // satisfied by DI
class BackgroundJobFactory @Inject constructor(
private val logger: Logger,
private val preferences: AppPreferences,
@ -143,7 +143,7 @@ class BackgroundJobFactory @Inject constructor(
resources,
arbitraryDataProvider,
contentResolver,
accountManager,
accountManager
)
}
@ -152,7 +152,7 @@ class BackgroundJobFactory @Inject constructor(
context,
params,
logger,
contentResolver,
contentResolver
)
}
@ -162,7 +162,7 @@ class BackgroundJobFactory @Inject constructor(
params,
contentResolver,
accountManager,
preferences,
preferences
)
}
@ -171,7 +171,7 @@ class BackgroundJobFactory @Inject constructor(
context,
params,
logger,
contentResolver,
contentResolver
)
}
@ -210,7 +210,7 @@ class BackgroundJobFactory @Inject constructor(
preferences,
clock,
viewThemeUtils.get(),
syncedFolderProvider,
syncedFolderProvider
)
}
@ -221,7 +221,7 @@ class BackgroundJobFactory @Inject constructor(
notificationManager,
accountManager,
deckApi,
viewThemeUtils.get(),
viewThemeUtils.get()
)
}
@ -249,7 +249,7 @@ class BackgroundJobFactory @Inject constructor(
localBroadcastManager.get(),
backgroundJobManager.get(),
context,
params,
params
)
}
@ -261,7 +261,7 @@ class BackgroundJobFactory @Inject constructor(
notificationManager = notificationManager,
userAccountManager = accountManager,
logger = logger,
params = params,
params = params
)
}

View file

@ -66,7 +66,6 @@ internal class BackgroundJobManagerImpl(
private val preferences: AppPreferences
) : BackgroundJobManager, Injectable {
companion object {
const val TAG_ALL = "*" // This tag allows us to retrieve list of all jobs run by Nextcloud client
@ -130,11 +129,11 @@ internal class BackgroundJobManagerImpl(
}
fun parseTimestamp(timestamp: String): Date {
try {
return try {
val ms = timestamp.toLong()
return Date(ms)
Date(ms)
} catch (ex: NumberFormatException) {
return Date(0)
Date(0)
}
}
@ -162,19 +161,18 @@ internal class BackgroundJobManagerImpl(
}
fun deleteOldLogs(logEntries: MutableList<LogEntry>): MutableList<LogEntry> {
logEntries.removeIf {
return@removeIf (it.started != null &&
Date(Date().time - KEEP_LOG_MILLIS).after(it.started)) ||
(it.finished != null &&
Date(Date().time - KEEP_LOG_MILLIS).after(it.finished))
return@removeIf (
it.started != null &&
Date(Date().time - KEEP_LOG_MILLIS).after(it.started)
) ||
(
it.finished != null &&
Date(Date().time - KEEP_LOG_MILLIS).after(it.finished)
)
}
return logEntries
}
}
override fun logStartOfWorker(workerName: String?) {
@ -189,7 +187,6 @@ internal class BackgroundJobManagerImpl(
}
override fun logEndOfWorker(workerName: String?, result: ListenableWorker.Result) {
val logs = deleteOldLogs(preferences.readLogEntry().toMutableList())
if (workerName == null) {
logs.add(LogEntry(null, Date(), result.toString(), NOT_SET_VALUE))

View file

@ -19,8 +19,6 @@
*/
package com.nextcloud.client.jobs
import androidx.work.ListenableWorker
import com.google.common.util.concurrent.ListenableFuture
import java.util.Date
import java.util.UUID
@ -31,10 +29,9 @@ data class JobInfo(
val user: String = "",
val workerClass: String = "",
val started: Date = Date(0),
val progress: Int = 0,
val progress: Int = 0
)
data class LogEntry(
val started: Date? = null,
val finished: Date? = null,

View file

@ -51,7 +51,11 @@ class JobsModule {
@Provides
@Singleton
fun backgroundJobManager(workManager: WorkManager, clock: Clock, preferences: AppPreferences): BackgroundJobManager {
fun backgroundJobManager(
workManager: WorkManager,
clock: Clock,
preferences: AppPreferences
): BackgroundJobManager {
return BackgroundJobManagerImpl(workManager, clock, preferences)
}
}