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

@ -46,9 +46,10 @@ import javax.inject.Inject
class EtmBackgroundJobsFragment : EtmBaseFragment(), Injectable { class EtmBackgroundJobsFragment : EtmBaseFragment(), Injectable {
@Inject @Inject
lateinit var preferences : AppPreferences 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) { class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val uuid = view.findViewById<TextView>(R.id.etm_background_job_uuid) val uuid = view.findViewById<TextView>(R.id.etm_background_job_uuid)
@ -88,7 +89,6 @@ class EtmBackgroundJobsFragment : EtmBaseFragment(), Injectable {
View.GONE View.GONE
} }
} }
} }
private val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:MM:ssZ", Locale.getDefault()) private val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:MM:ssZ", Locale.getDefault())
@ -129,30 +129,32 @@ class EtmBackgroundJobsFragment : EtmBaseFragment(), Injectable {
} }
val logs = preferences.readLogEntry() val logs = preferences.readLogEntry()
val logsForThisWorker = logs.filter { BackgroundJobManagerImpl.parseTag(it.workerClass)?.second == info.workerClass } val logsForThisWorker =
if(logsForThisWorker.isNotEmpty()) { logs.filter { BackgroundJobManagerImpl.parseTag(it.workerClass)?.second == info.workerClass }
if (logsForThisWorker.isNotEmpty()) {
vh.executionTimesRow.visibility = View.VISIBLE 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" + var logText = "Worker Logs\n\n" +
"*** Does NOT differentiate between imitate or periodic kinds of Work! ***\n"+ "*** Does NOT differentiate between imitate or periodic kinds of Work! ***\n" +
"*** Times run in 48h: Times started (Times finished) ***\n" "*** Times run in 48h: Times started (Times finished) ***\n"
logsForThisWorker.forEach{ logsForThisWorker.forEach {
logText += "----------------------\n" logText += "----------------------\n"
logText += "Worker ${BackgroundJobManagerImpl.parseTag(it.workerClass)?.second}\n" logText += "Worker ${BackgroundJobManagerImpl.parseTag(it.workerClass)?.second}\n"
logText += if (it.started == null){ logText += if (it.started == null) {
"ENDED at\n${it.finished}\nWith result: ${it.result}\n" "ENDED at\n${it.finished}\nWith result: ${it.result}\n"
}else{ } else {
"STARTED at\n${it.started}\n" "STARTED at\n${it.started}\n"
} }
} }
vh.executionLog.text = logText vh.executionLog.text = logText
}else{ } else {
vh.executionLog.text = "Worker Logs\n\n" + vh.executionLog.text = "Worker Logs\n\n" +
"No Entries -> Maybe logging is not implemented for Worker or it has not run yet." "No Entries -> Maybe logging is not implemented for Worker or it has not run yet."
vh.executionCount.text = "0" vh.executionCount.text = "0"
vh.executionTimesRow.visibility = View.GONE vh.executionTimesRow.visibility = View.GONE
} }
} }
} }
@ -186,22 +188,27 @@ class EtmBackgroundJobsFragment : EtmBaseFragment(), Injectable {
vm.cancelAllJobs() vm.cancelAllJobs()
true true
} }
R.id.etm_background_jobs_prune -> { R.id.etm_background_jobs_prune -> {
vm.pruneJobs() vm.pruneJobs()
true true
} }
R.id.etm_background_jobs_start_test -> { R.id.etm_background_jobs_start_test -> {
vm.startTestJob(periodic = false) vm.startTestJob(periodic = false)
true true
} }
R.id.etm_background_jobs_schedule_test -> { R.id.etm_background_jobs_schedule_test -> {
vm.startTestJob(periodic = true) vm.startTestJob(periodic = true)
true true
} }
R.id.etm_background_jobs_cancel_test -> { R.id.etm_background_jobs_cancel_test -> {
vm.cancelTestJob() vm.cancelTestJob()
true true
} }
else -> super.onOptionsItemSelected(item) 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. * 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( class BackgroundJobFactory @Inject constructor(
private val logger: Logger, private val logger: Logger,
private val preferences: AppPreferences, private val preferences: AppPreferences,
@ -143,7 +143,7 @@ class BackgroundJobFactory @Inject constructor(
resources, resources,
arbitraryDataProvider, arbitraryDataProvider,
contentResolver, contentResolver,
accountManager, accountManager
) )
} }
@ -152,7 +152,7 @@ class BackgroundJobFactory @Inject constructor(
context, context,
params, params,
logger, logger,
contentResolver, contentResolver
) )
} }
@ -162,7 +162,7 @@ class BackgroundJobFactory @Inject constructor(
params, params,
contentResolver, contentResolver,
accountManager, accountManager,
preferences, preferences
) )
} }
@ -171,7 +171,7 @@ class BackgroundJobFactory @Inject constructor(
context, context,
params, params,
logger, logger,
contentResolver, contentResolver
) )
} }
@ -210,7 +210,7 @@ class BackgroundJobFactory @Inject constructor(
preferences, preferences,
clock, clock,
viewThemeUtils.get(), viewThemeUtils.get(),
syncedFolderProvider, syncedFolderProvider
) )
} }
@ -221,7 +221,7 @@ class BackgroundJobFactory @Inject constructor(
notificationManager, notificationManager,
accountManager, accountManager,
deckApi, deckApi,
viewThemeUtils.get(), viewThemeUtils.get()
) )
} }
@ -249,7 +249,7 @@ class BackgroundJobFactory @Inject constructor(
localBroadcastManager.get(), localBroadcastManager.get(),
backgroundJobManager.get(), backgroundJobManager.get(),
context, context,
params, params
) )
} }
@ -261,7 +261,7 @@ class BackgroundJobFactory @Inject constructor(
notificationManager = notificationManager, notificationManager = notificationManager,
userAccountManager = accountManager, userAccountManager = accountManager,
logger = logger, logger = logger,
params = params, params = params
) )
} }

View file

@ -36,7 +36,7 @@ interface BackgroundJobManager {
*/ */
val jobs: LiveData<List<JobInfo>> val jobs: LiveData<List<JobInfo>>
fun logStartOfWorker(workerName : String?) fun logStartOfWorker(workerName: String?)
fun logEndOfWorker(workerName: String?, result: ListenableWorker.Result) fun logEndOfWorker(workerName: String?, result: ListenableWorker.Result)

View file

@ -66,7 +66,6 @@ internal class BackgroundJobManagerImpl(
private val preferences: AppPreferences private val preferences: AppPreferences
) : BackgroundJobManager, Injectable { ) : BackgroundJobManager, Injectable {
companion object { companion object {
const val TAG_ALL = "*" // This tag allows us to retrieve list of all jobs run by Nextcloud client const val TAG_ALL = "*" // This tag allows us to retrieve list of all jobs run by Nextcloud client
@ -105,7 +104,7 @@ internal class BackgroundJobManagerImpl(
const val DEFAULT_PERIODIC_JOB_INTERVAL_MINUTES = 15L const val DEFAULT_PERIODIC_JOB_INTERVAL_MINUTES = 15L
const val DEFAULT_IMMEDIATE_JOB_DELAY_SEC = 3L const val DEFAULT_IMMEDIATE_JOB_DELAY_SEC = 3L
private const val KEEP_LOG_MILLIS = 1000 * 60 * 60 * 24 *3L private const val KEEP_LOG_MILLIS = 1000 * 60 * 60 * 24 * 3L
fun formatNameTag(name: String, user: User? = null): String { fun formatNameTag(name: String, user: User? = null): String {
return if (user == null) { return if (user == null) {
@ -130,11 +129,11 @@ internal class BackgroundJobManagerImpl(
} }
fun parseTimestamp(timestamp: String): Date { fun parseTimestamp(timestamp: String): Date {
try { return try {
val ms = timestamp.toLong() val ms = timestamp.toLong()
return Date(ms) Date(ms)
} catch (ex: NumberFormatException) { } catch (ex: NumberFormatException) {
return Date(0) Date(0)
} }
} }
@ -161,40 +160,38 @@ internal class BackgroundJobManagerImpl(
} }
} }
fun deleteOldLogs(logEntries: MutableList<LogEntry>) : MutableList<LogEntry>{ fun deleteOldLogs(logEntries: MutableList<LogEntry>): MutableList<LogEntry> {
logEntries.removeIf { logEntries.removeIf {
return@removeIf (it.started != null && return@removeIf (
Date(Date().time - KEEP_LOG_MILLIS).after(it.started)) || it.started != null &&
(it.finished != null && Date(Date().time - KEEP_LOG_MILLIS).after(it.started)
Date(Date().time - KEEP_LOG_MILLIS).after(it.finished)) ) ||
(
it.finished != null &&
Date(Date().time - KEEP_LOG_MILLIS).after(it.finished)
)
} }
return logEntries return logEntries
}
} }
override fun logStartOfWorker(workerName: String?) {
}
override fun logStartOfWorker(workerName : String?) {
val logs = deleteOldLogs(preferences.readLogEntry().toMutableList()) val logs = deleteOldLogs(preferences.readLogEntry().toMutableList())
if (workerName == null) { if (workerName == null) {
logs.add(LogEntry(Date(), null, null, NOT_SET_VALUE)) logs.add(LogEntry(Date(), null, null, NOT_SET_VALUE))
}else{ } else {
logs.add(LogEntry(Date(), null, null, workerName)) logs.add(LogEntry(Date(), null, null, workerName))
} }
preferences.saveLogEntry(logs) preferences.saveLogEntry(logs)
} }
override fun logEndOfWorker(workerName: String?, result: ListenableWorker.Result){ override fun logEndOfWorker(workerName: String?, result: ListenableWorker.Result) {
val logs = deleteOldLogs(preferences.readLogEntry().toMutableList()) val logs = deleteOldLogs(preferences.readLogEntry().toMutableList())
if (workerName == null) { if (workerName == null) {
logs.add(LogEntry(null,Date(),result.toString(), NOT_SET_VALUE)) logs.add(LogEntry(null, Date(), result.toString(), NOT_SET_VALUE))
}else{ } else {
logs.add(LogEntry(null,Date(),result.toString(),workerName)) logs.add(LogEntry(null, Date(), result.toString(), workerName))
} }
preferences.saveLogEntry(logs) preferences.saveLogEntry(logs)
} }

View file

@ -50,7 +50,7 @@ class ContentObserverWork(
recheduleSelf() recheduleSelf()
val result = Result.success() val result = Result.success()
backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class),result) backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class), result)
return result return result
} }

View file

@ -81,7 +81,7 @@ class FilesSyncWork(
// If we are in power save mode, better to postpone upload // If we are in power save mode, better to postpone upload
if (powerManagementService.isPowerSavingEnabled && !overridePowerSaving) { if (powerManagementService.isPowerSavingEnabled && !overridePowerSaving) {
val result = Result.success() val result = Result.success()
backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class),result) backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class), result)
return result return result
} }
val resources = context.resources val resources = context.resources
@ -113,7 +113,7 @@ class FilesSyncWork(
} }
} }
val result = Result.success() val result = Result.success()
backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class),result) backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class), result)
return result return result
} }

View file

@ -88,7 +88,7 @@ class FilesUploadWorker(
Log_OC.w(TAG, "User was null for file upload worker") Log_OC.w(TAG, "User was null for file upload worker")
val result = Result.failure() val result = Result.failure()
backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class),result) backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class), result)
return result // user account is needed return result // user account is needed
} }
@ -107,7 +107,7 @@ class FilesUploadWorker(
Log_OC.d(TAG, "No more pending uploads for account $accountName, stopping work") Log_OC.d(TAG, "No more pending uploads for account $accountName, stopping work")
val result = Result.success() val result = Result.success()
backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class),result) backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class), result)
return result // user account is needed return result // user account is needed
} }

View file

@ -96,7 +96,7 @@ class HealthStatusWork(
} }
val result = Result.success() val result = Result.success()
backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class),result) backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class), result)
return result return result
} }

View file

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

View file

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

View file

@ -48,7 +48,7 @@ class TestJob(
} }
val result = Result.success() val result = Result.success()
backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class),result) backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class), result)
return result return result
} }
} }