improved interactions tab settings

This commit is contained in:
Mariotaku Lee 2017-05-11 13:33:53 +08:00
parent cc91209578
commit 8b416bd364
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
3 changed files with 24 additions and 12 deletions

View File

@ -56,7 +56,8 @@ open class BooleanExtraConfiguration(
checkBox = view.findViewById(android.R.id.checkbox) as CheckBox
checkBox.visibility = View.VISIBLE
checkBox.isChecked = defaultValue.createBoolean(context)
view.setOnClickListener { checkBox.toggle() }
value = defaultValue.createBoolean(context)
}
}

View File

@ -19,6 +19,7 @@
package org.mariotaku.twidere.model.tab.impl
import android.accounts.AccountManager
import android.content.Context
import android.view.View
import android.widget.CheckBox
@ -97,14 +98,18 @@ class InteractionsTabConfiguration : TabConfiguration() {
val titleView = view.findViewById(android.R.id.title) as TextView
val summaryView = view.findViewById(android.R.id.summary) as TextView
var requiresOfficial = false
var requiresStreaming = false
var interactionsAvailable = false
if (account == null || account.dummy) {
requiresOfficial = AccountUtils.hasOfficialKeyAccount(context)
val am = AccountManager.get(context)
val accounts = AccountUtils.getAllAccountDetails(am, false)
interactionsAvailable = accounts.any { it.supportsInteractions }
requiresStreaming = accounts.all { it.requiresStreaming }
} else when (account.type) {
AccountType.TWITTER -> {
requiresOfficial = true
interactionsAvailable = account.isOfficial(context)
interactionsAvailable = true
requiresStreaming = !account.isOfficial(context)
}
AccountType.MASTODON -> {
interactionsAvailable = true
@ -117,12 +122,12 @@ class InteractionsTabConfiguration : TabConfiguration() {
checkBox.isEnabled = interactionsAvailable
if (interactionsAvailable) {
checkBox.isChecked = valueBackup
summaryView.visibility = View.GONE
} else if (requiresOfficial) {
valueBackup = checkBox.isChecked
checkBox.isChecked = true
summaryView.setText(R.string.summary_interactions_official_required)
summaryView.visibility = View.VISIBLE
if (requiresStreaming) {
summaryView.setText(R.string.summary_interactions_streaming_required)
summaryView.visibility = View.VISIBLE
} else {
summaryView.visibility = View.GONE
}
} else {
valueBackup = checkBox.isChecked
checkBox.isChecked = true
@ -151,6 +156,12 @@ class InteractionsTabConfiguration : TabConfiguration() {
}
}
private val AccountDetails.supportsInteractions: Boolean
get() = type == AccountType.TWITTER || type == AccountType.MASTODON
private val AccountDetails.requiresStreaming: Boolean
get() = !isOfficial(context)
}
}

View File

@ -1120,7 +1120,7 @@
<string name="subscribers">Subscriber</string>
<string name="summary_interactions_account_not_supported">Account not supported</string>
<string name="summary_interactions_official_required">Only available with official keys</string>
<string name="summary_interactions_streaming_required">Full interactions available only when streaming enabled</string>
<string name="swipe_down_to_refresh">Swipe down to refresh</string>