mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-03-24 23:09:02 +03:00
Enhance user experience when home servers do not support threads.
This commit is contained in:
parent
9b7e94ebab
commit
d24ba65b5b
5 changed files with 66 additions and 10 deletions
changelog.d
vector/src/main
java/im/vector/app/features
home/room
settings
res/values
1
changelog.d/5761.feature
Normal file
1
changelog.d/5761.feature
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Improve user experience when home servers do not yet support threads
|
|
@ -452,6 +452,10 @@ class MessageActionsViewModel @AssistedInject constructor(
|
||||||
actionPermissions: ActionPermissions): Boolean {
|
actionPermissions: ActionPermissions): Boolean {
|
||||||
// We let reply in thread visible even if threads are not enabled, with an enhanced flow to attract users
|
// We let reply in thread visible even if threads are not enabled, with an enhanced flow to attract users
|
||||||
// if (!vectorPreferences.areThreadMessagesEnabled()) return false
|
// if (!vectorPreferences.areThreadMessagesEnabled()) return false
|
||||||
|
// Disable beta prompt if the homeserver do not support threads
|
||||||
|
if (!vectorPreferences.areThreadMessagesEnabled() &&
|
||||||
|
!session.getHomeServerCapabilities().canUseThreading) return false
|
||||||
|
|
||||||
if (initialState.isFromThreadTimeline) return false
|
if (initialState.isFromThreadTimeline) return false
|
||||||
if (event.root.isThread()) return false
|
if (event.root.isThread()) return false
|
||||||
if (event.root.getClearType() != EventType.MESSAGE &&
|
if (event.root.getClearType() != EventType.MESSAGE &&
|
||||||
|
|
|
@ -18,6 +18,7 @@ package im.vector.app.features.home.room.threads
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.text.Spanned
|
import android.text.Spanned
|
||||||
|
import androidx.annotation.StringRes
|
||||||
import androidx.core.text.HtmlCompat
|
import androidx.core.text.HtmlCompat
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.resources.StringProvider
|
import im.vector.app.core.resources.StringProvider
|
||||||
|
@ -49,11 +50,17 @@ class ThreadsManager @Inject constructor(
|
||||||
/**
|
/**
|
||||||
* Generates and return an Html spanned string to be rendered especially in dialogs
|
* Generates and return an Html spanned string to be rendered especially in dialogs
|
||||||
*/
|
*/
|
||||||
fun getBetaEnableThreadsMessage(): Spanned {
|
private fun generateLearnMoreHtmlString(@StringRes messageId: Int): Spanned {
|
||||||
val learnMore = stringProvider.getString(R.string.action_learn_more)
|
val learnMore = stringProvider.getString(R.string.action_learn_more)
|
||||||
val learnMoreUrl = stringProvider.getString(R.string.threads_learn_more_url)
|
val learnMoreUrl = stringProvider.getString(R.string.threads_learn_more_url)
|
||||||
val href = "<a href='$learnMoreUrl'>$learnMore</a>.<br><br>"
|
val href = "<a href='$learnMoreUrl'>$learnMore</a>.<br><br>"
|
||||||
val message = stringProvider.getString(R.string.threads_beta_enable_notice_message, href)
|
val message = stringProvider.getString(messageId, href)
|
||||||
return HtmlCompat.fromHtml(message, HtmlCompat.FROM_HTML_MODE_LEGACY)
|
return HtmlCompat.fromHtml(message, HtmlCompat.FROM_HTML_MODE_LEGACY)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getBetaEnableThreadsMessage(): Spanned =
|
||||||
|
generateLearnMoreHtmlString(R.string.threads_beta_enable_notice_message)
|
||||||
|
|
||||||
|
fun getLabsEnableThreadsMessage(): Spanned =
|
||||||
|
generateLearnMoreHtmlString(R.string.threads_labs_enable_notice_message)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,18 +17,23 @@
|
||||||
package im.vector.app.features.settings
|
package im.vector.app.features.settings
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.text.method.LinkMovementMethod
|
||||||
|
import android.widget.TextView
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.preference.VectorSwitchPreference
|
import im.vector.app.core.preference.VectorSwitchPreference
|
||||||
import im.vector.app.features.MainActivity
|
import im.vector.app.features.MainActivity
|
||||||
import im.vector.app.features.MainActivityArgs
|
import im.vector.app.features.MainActivityArgs
|
||||||
import im.vector.app.features.analytics.plan.MobileScreen
|
import im.vector.app.features.analytics.plan.MobileScreen
|
||||||
|
import im.vector.app.features.home.room.threads.ThreadsManager
|
||||||
import org.matrix.android.sdk.api.settings.LightweightSettingsStorage
|
import org.matrix.android.sdk.api.settings.LightweightSettingsStorage
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class VectorSettingsLabsFragment @Inject constructor(
|
class VectorSettingsLabsFragment @Inject constructor(
|
||||||
private val vectorPreferences: VectorPreferences,
|
private val vectorPreferences: VectorPreferences,
|
||||||
private val lightweightSettingsStorage: LightweightSettingsStorage
|
private val lightweightSettingsStorage: LightweightSettingsStorage,
|
||||||
|
private val threadsManager: ThreadsManager
|
||||||
) : VectorSettingsBaseFragment() {
|
) : VectorSettingsBaseFragment() {
|
||||||
|
|
||||||
override var titleRes = R.string.room_settings_labs_pref_title
|
override var titleRes = R.string.room_settings_labs_pref_title
|
||||||
|
@ -46,15 +51,51 @@ class VectorSettingsLabsFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear cache
|
// clear cache
|
||||||
findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_LABS_ENABLE_THREAD_MESSAGES)?.let {
|
findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_LABS_ENABLE_THREAD_MESSAGES)?.let { vectorPref ->
|
||||||
it.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
vectorPref.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
||||||
// We should migrate threads only if threads are disabled
|
onThreadsPreferenceClickedInterceptor(vectorPref)
|
||||||
vectorPreferences.setShouldMigrateThreads(!vectorPreferences.areThreadMessagesEnabled())
|
|
||||||
lightweightSettingsStorage.setThreadMessagesEnabled(vectorPreferences.areThreadMessagesEnabled())
|
|
||||||
displayLoadingView()
|
|
||||||
MainActivity.restartApp(requireActivity(), MainActivityArgs(clearCache = true))
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Intercept the click to display a user friendly dialog when their homeserver do not support threads
|
||||||
|
*/
|
||||||
|
private fun onThreadsPreferenceClickedInterceptor(vectorSwitchPreference: VectorSwitchPreference) {
|
||||||
|
val userEnabledThreads = vectorPreferences.areThreadMessagesEnabled()
|
||||||
|
if (!session.getHomeServerCapabilities().canUseThreading && userEnabledThreads) {
|
||||||
|
activity?.let {
|
||||||
|
MaterialAlertDialogBuilder(it)
|
||||||
|
.setTitle(R.string.threads_labs_enable_notice_title)
|
||||||
|
.setMessage(threadsManager.getLabsEnableThreadsMessage())
|
||||||
|
.setCancelable(true)
|
||||||
|
.setNegativeButton(R.string.action_not_now) { _, _ ->
|
||||||
|
vectorSwitchPreference.isChecked = false
|
||||||
|
}
|
||||||
|
.setPositiveButton(R.string.action_try_it_out) { _, _ ->
|
||||||
|
onThreadsPreferenceClicked()
|
||||||
|
}
|
||||||
|
.show()
|
||||||
|
?.findViewById<TextView>(android.R.id.message)
|
||||||
|
?.apply {
|
||||||
|
linksClickable = true
|
||||||
|
movementMethod = LinkMovementMethod.getInstance()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
onThreadsPreferenceClicked()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Action when threads preference switch is actually clicked
|
||||||
|
*/
|
||||||
|
private fun onThreadsPreferenceClicked() {
|
||||||
|
// We should migrate threads only if threads are disabled
|
||||||
|
vectorPreferences.setShouldMigrateThreads(!vectorPreferences.areThreadMessagesEnabled())
|
||||||
|
lightweightSettingsStorage.setThreadMessagesEnabled(vectorPreferences.areThreadMessagesEnabled())
|
||||||
|
displayLoadingView()
|
||||||
|
MainActivity.restartApp(requireActivity(), MainActivityArgs(clearCache = true))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -739,6 +739,9 @@
|
||||||
<string name="threads_beta_enable_notice_title">Threads Beta</string>
|
<string name="threads_beta_enable_notice_title">Threads Beta</string>
|
||||||
<!-- %s will be replaced with action_learn_more string resource that will be clickable(url redirection) -->
|
<!-- %s will be replaced with action_learn_more string resource that will be clickable(url redirection) -->
|
||||||
<string name="threads_beta_enable_notice_message">Threads help keep your conversations on-topic and easy to track. %sEnabling threads will refresh the app. This may take longer for some accounts.</string>
|
<string name="threads_beta_enable_notice_message">Threads help keep your conversations on-topic and easy to track. %sEnabling threads will refresh the app. This may take longer for some accounts.</string>
|
||||||
|
<string name="threads_labs_enable_notice_title">Threads Beta</string>
|
||||||
|
<string name="threads_labs_enable_notice_message">Your homeserver does not currently support threads, so this feature may be unreliable. Some threaded messages may not be reliably available. %sDo you want to enable threads anyway?</string>
|
||||||
|
|
||||||
|
|
||||||
<!-- Search -->
|
<!-- Search -->
|
||||||
<string name="search_hint">Search</string>
|
<string name="search_hint">Search</string>
|
||||||
|
|
Loading…
Add table
Reference in a new issue