package lt.markmerkk.interactors

import lt.markmerkk.UserSettings

/**
 * @author mariusmerkevicius
 * @since 2016-08-13
 */
class AutoUpdateInteractorImpl(
        private val userSettings: UserSettings
) : AutoUpdateInteractor {

    override fun notifyUpdateComplete(lastUpdateMillis: Long) {
        userSettings.lastUpdate = lastUpdateMillis
    }

    override fun isAutoUpdateTimeoutHit(now: Long): Boolean {
        if (userSettings.autoUpdateMinutes == -1) return false // no update
        if (userSettings.lastUpdate < 0) return true // never updated

        val timeout = userSettings.autoUpdateMinutes * 1000 * 60
        val updateGap = now - userSettings.lastUpdate
        return updateGap >= timeout
    }

}
package lt.markmerkk.interactors

import lt.markmerkk.UserSettings
import org.slf4j.LoggerFactory

/**
 * @author mariusmerkevicius
 * @since 2016-08-13
 */
class AutoUpdateInteractorImpl(
        private val userSettings: UserSettings
) : AutoUpdateInteractor {

    override fun notifyUpdateComplete(lastUpdateMillis: Long) {
        userSettings.lastUpdate = lastUpdateMillis
    }

    override fun isAutoUpdateTimeoutHit(now: Long): Boolean {
        logger.debug("Check if update is necessary...")
        if (userSettings.autoUpdateMinutes == -1) {
            logger.debug("Auto update disabled")
            return false
        }
        if (userSettings.lastUpdate < 0) {
            logger.debug("Update was never done, executing...")
            return true
        }

        val timeout = userSettings.autoUpdateMinutes * 1000 * 60
        val updateGap = now - userSettings.lastUpdate
        logger.debug("Timeout set to ${userSettings.autoUpdateMinutes}")
        return updateGap >= timeout
    }

    companion object {
        val logger = LoggerFactory.getLogger(AutoUpdateInteractorImpl::class.java)!!
    }

}
Add auto update logging for more debug data
Add auto update logging for more debug data

marius-m/wt4,marius-m/wt4,marius-m/wt4,marius-m/wt4