Show if sync disabled

pull/340/head
Koitharu 3 years ago
parent 32b1ee9e7b
commit 745f0adf5b
No known key found for this signature in database
GPG Key ID: 8E861F8CE6E7CE27

@ -19,6 +19,7 @@ import org.koitharu.kotatsu.scrobbling.common.domain.model.ScrobblerService
import org.koitharu.kotatsu.scrobbling.common.ui.config.ScrobblerConfigActivity import org.koitharu.kotatsu.scrobbling.common.ui.config.ScrobblerConfigActivity
import org.koitharu.kotatsu.scrobbling.mal.data.MALRepository import org.koitharu.kotatsu.scrobbling.mal.data.MALRepository
import org.koitharu.kotatsu.scrobbling.shikimori.data.ShikimoriRepository import org.koitharu.kotatsu.scrobbling.shikimori.data.ShikimoriRepository
import org.koitharu.kotatsu.sync.domain.SyncController
import org.koitharu.kotatsu.sync.ui.SyncSettingsIntent import org.koitharu.kotatsu.sync.ui.SyncSettingsIntent
import org.koitharu.kotatsu.utils.ext.getDisplayMessage import org.koitharu.kotatsu.utils.ext.getDisplayMessage
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
@ -37,6 +38,9 @@ class ServicesSettingsFragment : BasePreferenceFragment(R.string.services) {
@Inject @Inject
lateinit var malRepository: MALRepository lateinit var malRepository: MALRepository
@Inject
lateinit var syncController: SyncController
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.pref_services) addPreferencesFromResource(R.xml.pref_services)
} }
@ -143,7 +147,11 @@ class ServicesSettingsFragment : BasePreferenceFragment(R.string.services) {
AccountManager.get(requireContext()).getAccountsByType(type).firstOrNull() AccountManager.get(requireContext()).getAccountsByType(type).firstOrNull()
} }
findPreference<Preference>(AppSettings.KEY_SYNC)?.run { findPreference<Preference>(AppSettings.KEY_SYNC)?.run {
summary = account?.name ?: getString(R.string.sync_title) summary = when {
account == null -> getString(R.string.sync_title)
syncController.isEnabled(account) -> account.name
else -> getString(R.string.disabled)
}
} }
} }
} }

@ -49,6 +49,16 @@ class SyncController @Inject constructor(
) )
} }
fun isEnabled(account: Account): Boolean {
return ContentResolver.getMasterSyncAutomatically() && (ContentResolver.getSyncAutomatically(
account,
authorityFavourites,
) || ContentResolver.getSyncAutomatically(
account,
authorityHistory,
))
}
fun getLastSync(account: Account, authority: String): Long { fun getLastSync(account: Account, authority: String): Long {
val key = "last_sync_" + authority.substringAfterLast('.') val key = "last_sync_" + authority.substringAfterLast('.')
val rawValue = am.getUserData(account, key) ?: return 0L val rawValue = am.getUserData(account, key) ?: return 0L

Loading…
Cancel
Save