Show if sync disabled
This commit is contained in:
@@ -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.mal.data.MALRepository
|
||||
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.utils.ext.getDisplayMessage
|
||||
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||
@@ -37,6 +38,9 @@ class ServicesSettingsFragment : BasePreferenceFragment(R.string.services) {
|
||||
@Inject
|
||||
lateinit var malRepository: MALRepository
|
||||
|
||||
@Inject
|
||||
lateinit var syncController: SyncController
|
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
addPreferencesFromResource(R.xml.pref_services)
|
||||
}
|
||||
@@ -143,7 +147,11 @@ class ServicesSettingsFragment : BasePreferenceFragment(R.string.services) {
|
||||
AccountManager.get(requireContext()).getAccountsByType(type).firstOrNull()
|
||||
}
|
||||
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 {
|
||||
val key = "last_sync_" + authority.substringAfterLast('.')
|
||||
val rawValue = am.getUserData(account, key) ?: return 0L
|
||||
|
||||
@@ -75,4 +75,4 @@ class SyncAccountAuthenticator(private val context: Context) : AbstractAccountAu
|
||||
account: Account?,
|
||||
features: Array<out String>?,
|
||||
): Bundle? = null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user