mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 21:55:48 +03:00
Fix spotless issues
Signed-off-by: Jonas Mayer <jonas.a.mayer@gmx.net>
This commit is contained in:
parent
5cc6322725
commit
885aa703e8
11 changed files with 63 additions and 58 deletions
|
@ -46,9 +46,10 @@ import javax.inject.Inject
|
|||
class EtmBackgroundJobsFragment : EtmBaseFragment(), Injectable {
|
||||
|
||||
@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) {
|
||||
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())
|
||||
|
@ -128,31 +128,33 @@ class EtmBackgroundJobsFragment : EtmBaseFragment(), Injectable {
|
|||
vh.progressEnabled = false
|
||||
}
|
||||
|
||||
val logs = preferences.readLogEntry()
|
||||
val logsForThisWorker = logs.filter { BackgroundJobManagerImpl.parseTag(it.workerClass)?.second == info.workerClass }
|
||||
if(logsForThisWorker.isNotEmpty()) {
|
||||
val logs = preferences.readLogEntry()
|
||||
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"+
|
||||
"*** Does NOT differentiate between imitate or periodic kinds of Work! ***\n" +
|
||||
"*** Times run in 48h: Times started (Times finished) ***\n"
|
||||
logsForThisWorker.forEach{
|
||||
logsForThisWorker.forEach {
|
||||
logText += "----------------------\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"
|
||||
}else{
|
||||
} else {
|
||||
"STARTED at\n${it.started}\n"
|
||||
}
|
||||
}
|
||||
vh.executionLog.text = logText
|
||||
}else{
|
||||
} else {
|
||||
vh.executionLog.text = "Worker Logs\n\n" +
|
||||
"No Entries -> Maybe logging is not implemented for Worker or it has not run yet."
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ interface BackgroundJobManager {
|
|||
*/
|
||||
val jobs: LiveData<List<JobInfo>>
|
||||
|
||||
fun logStartOfWorker(workerName : String?)
|
||||
fun logStartOfWorker(workerName: String?)
|
||||
|
||||
fun logEndOfWorker(workerName: String?, result: ListenableWorker.Result)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
@ -105,7 +104,7 @@ internal class BackgroundJobManagerImpl(
|
|||
const val DEFAULT_PERIODIC_JOB_INTERVAL_MINUTES = 15L
|
||||
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 {
|
||||
return if (user == null) {
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -161,40 +160,38 @@ internal class BackgroundJobManagerImpl(
|
|||
}
|
||||
}
|
||||
|
||||
fun deleteOldLogs(logEntries: MutableList<LogEntry>) : MutableList<LogEntry>{
|
||||
|
||||
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?) {
|
||||
override fun logStartOfWorker(workerName: String?) {
|
||||
val logs = deleteOldLogs(preferences.readLogEntry().toMutableList())
|
||||
|
||||
if (workerName == null) {
|
||||
logs.add(LogEntry(Date(), null, null, NOT_SET_VALUE))
|
||||
}else{
|
||||
} else {
|
||||
logs.add(LogEntry(Date(), null, null, workerName))
|
||||
}
|
||||
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())
|
||||
if (workerName == null) {
|
||||
logs.add(LogEntry(null,Date(),result.toString(), NOT_SET_VALUE))
|
||||
}else{
|
||||
logs.add(LogEntry(null,Date(),result.toString(),workerName))
|
||||
logs.add(LogEntry(null, Date(), result.toString(), NOT_SET_VALUE))
|
||||
} else {
|
||||
logs.add(LogEntry(null, Date(), result.toString(), workerName))
|
||||
}
|
||||
preferences.saveLogEntry(logs)
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ class ContentObserverWork(
|
|||
recheduleSelf()
|
||||
|
||||
val result = Result.success()
|
||||
backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class),result)
|
||||
backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class), result)
|
||||
return result
|
||||
}
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ class FilesSyncWork(
|
|||
// If we are in power save mode, better to postpone upload
|
||||
if (powerManagementService.isPowerSavingEnabled && !overridePowerSaving) {
|
||||
val result = Result.success()
|
||||
backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class),result)
|
||||
backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class), result)
|
||||
return result
|
||||
}
|
||||
val resources = context.resources
|
||||
|
@ -113,7 +113,7 @@ class FilesSyncWork(
|
|||
}
|
||||
}
|
||||
val result = Result.success()
|
||||
backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class),result)
|
||||
backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class), result)
|
||||
return result
|
||||
}
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ class FilesUploadWorker(
|
|||
Log_OC.w(TAG, "User was null for file upload worker")
|
||||
|
||||
val result = Result.failure()
|
||||
backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class),result)
|
||||
backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class), result)
|
||||
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")
|
||||
val result = Result.success()
|
||||
backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class),result)
|
||||
backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class), result)
|
||||
return result // user account is needed
|
||||
}
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ class HealthStatusWork(
|
|||
}
|
||||
|
||||
val result = Result.success()
|
||||
backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class),result)
|
||||
backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class), result)
|
||||
return result
|
||||
}
|
||||
|
||||
|
|
|
@ -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,11 +29,10 @@ 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 (
|
||||
data class LogEntry(
|
||||
val started: Date? = null,
|
||||
val finished: Date? = null,
|
||||
val result: String? = null,
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ class TestJob(
|
|||
}
|
||||
|
||||
val result = Result.success()
|
||||
backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class),result)
|
||||
backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class), result)
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue