Allow users to copy Subscription ID to clipboard.
This commit is contained in:
parent
08ac99b4c1
commit
3f1abe05fc
4 changed files with 27 additions and 6 deletions
|
@ -90,6 +90,7 @@ class ClickPreferenceViewHolder(itemView: View) : PreferenceViewHolder<ClickPref
|
||||||
override fun bind(model: ClickPreference) {
|
override fun bind(model: ClickPreference) {
|
||||||
super.bind(model)
|
super.bind(model)
|
||||||
itemView.setOnClickListener { model.onClick() }
|
itemView.setOnClickListener { model.onClick() }
|
||||||
|
itemView.setOnLongClickListener { model.onLongClick?.invoke() ?: false }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.components.settings.app
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.fragment.app.viewModels
|
import androidx.fragment.app.viewModels
|
||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
import org.thoughtcrime.securesms.R
|
import org.thoughtcrime.securesms.R
|
||||||
|
@ -22,6 +23,7 @@ import org.thoughtcrime.securesms.phonenumbers.PhoneNumberFormatter
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient
|
import org.thoughtcrime.securesms.recipients.Recipient
|
||||||
import org.thoughtcrime.securesms.util.FeatureFlags
|
import org.thoughtcrime.securesms.util.FeatureFlags
|
||||||
import org.thoughtcrime.securesms.util.PlayServicesUtil
|
import org.thoughtcrime.securesms.util.PlayServicesUtil
|
||||||
|
import org.thoughtcrime.securesms.util.Util
|
||||||
import org.thoughtcrime.securesms.util.adapter.mapping.LayoutFactory
|
import org.thoughtcrime.securesms.util.adapter.mapping.LayoutFactory
|
||||||
import org.thoughtcrime.securesms.util.adapter.mapping.MappingViewHolder
|
import org.thoughtcrime.securesms.util.adapter.mapping.MappingViewHolder
|
||||||
import org.thoughtcrime.securesms.util.navigation.safeNavigate
|
import org.thoughtcrime.securesms.util.navigation.safeNavigate
|
||||||
|
@ -162,7 +164,8 @@ class AppSettingsFragment : DSLSettingsFragment(R.string.text_secure_normal__men
|
||||||
} else {
|
} else {
|
||||||
findNavController().safeNavigate(AppSettingsFragmentDirections.actionAppSettingsFragmentToSubscribeFragment())
|
findNavController().safeNavigate(AppSettingsFragmentDirections.actionAppSettingsFragmentToSubscribeFragment())
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
onLongClick = this@AppSettingsFragment::copySubscriberIdToClipboard
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
clickPref(
|
clickPref(
|
||||||
|
@ -170,7 +173,8 @@ class AppSettingsFragment : DSLSettingsFragment(R.string.text_secure_normal__men
|
||||||
icon = DSLSettingsIcon.from(R.drawable.ic_boost_24),
|
icon = DSLSettingsIcon.from(R.drawable.ic_boost_24),
|
||||||
onClick = {
|
onClick = {
|
||||||
findNavController().safeNavigate(AppSettingsFragmentDirections.actionAppSettingsFragmentToBoostsFragment())
|
findNavController().safeNavigate(AppSettingsFragmentDirections.actionAppSettingsFragmentToBoostsFragment())
|
||||||
}
|
},
|
||||||
|
onLongClick = this@AppSettingsFragment::copySubscriberIdToClipboard
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
externalLinkPref(
|
externalLinkPref(
|
||||||
|
@ -193,13 +197,25 @@ class AppSettingsFragment : DSLSettingsFragment(R.string.text_secure_normal__men
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun copySubscriberIdToClipboard(): Boolean {
|
||||||
|
val subscriber = SignalStore.donationsValues().getSubscriber()
|
||||||
|
return if (subscriber == null) {
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
Toast.makeText(requireContext(), R.string.AppSettingsFragment__copied_subscriber_id_to_clipboard, Toast.LENGTH_LONG).show()
|
||||||
|
Util.copyToClipboard(requireContext(), subscriber.subscriberId.serialize())
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class SubscriptionPreference(
|
private class SubscriptionPreference(
|
||||||
override val title: DSLSettingsText,
|
override val title: DSLSettingsText,
|
||||||
override val summary: DSLSettingsText? = null,
|
override val summary: DSLSettingsText? = null,
|
||||||
override val icon: DSLSettingsIcon? = null,
|
override val icon: DSLSettingsIcon? = null,
|
||||||
override val isEnabled: Boolean = true,
|
override val isEnabled: Boolean = true,
|
||||||
val isActive: Boolean = false,
|
val isActive: Boolean = false,
|
||||||
val onClick: (Boolean) -> Unit
|
val onClick: (Boolean) -> Unit,
|
||||||
|
val onLongClick: () -> Boolean
|
||||||
) : PreferenceModel<SubscriptionPreference>() {
|
) : PreferenceModel<SubscriptionPreference>() {
|
||||||
override fun areItemsTheSame(newItem: SubscriptionPreference): Boolean {
|
override fun areItemsTheSame(newItem: SubscriptionPreference): Boolean {
|
||||||
return true
|
return true
|
||||||
|
@ -214,6 +230,7 @@ class AppSettingsFragment : DSLSettingsFragment(R.string.text_secure_normal__men
|
||||||
override fun bind(model: SubscriptionPreference) {
|
override fun bind(model: SubscriptionPreference) {
|
||||||
super.bind(model)
|
super.bind(model)
|
||||||
itemView.setOnClickListener { model.onClick(model.isActive) }
|
itemView.setOnClickListener { model.onClick(model.isActive) }
|
||||||
|
itemView.setOnLongClickListener { model.onLongClick() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,9 +96,10 @@ class DSLConfiguration {
|
||||||
summary: DSLSettingsText? = null,
|
summary: DSLSettingsText? = null,
|
||||||
icon: DSLSettingsIcon? = null,
|
icon: DSLSettingsIcon? = null,
|
||||||
isEnabled: Boolean = true,
|
isEnabled: Boolean = true,
|
||||||
onClick: () -> Unit
|
onClick: () -> Unit,
|
||||||
|
onLongClick: (() -> Boolean)? = null
|
||||||
) {
|
) {
|
||||||
val preference = ClickPreference(title, summary, icon, isEnabled, onClick)
|
val preference = ClickPreference(title, summary, icon, isEnabled, onClick, onLongClick)
|
||||||
children.add(preference)
|
children.add(preference)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,7 +270,8 @@ class ClickPreference(
|
||||||
override val summary: DSLSettingsText? = null,
|
override val summary: DSLSettingsText? = null,
|
||||||
override val icon: DSLSettingsIcon? = null,
|
override val icon: DSLSettingsIcon? = null,
|
||||||
override val isEnabled: Boolean = true,
|
override val isEnabled: Boolean = true,
|
||||||
val onClick: () -> Unit
|
val onClick: () -> Unit,
|
||||||
|
val onLongClick: (() -> Boolean)? = null
|
||||||
) : PreferenceModel<ClickPreference>()
|
) : PreferenceModel<ClickPreference>()
|
||||||
|
|
||||||
class LongClickPreference(
|
class LongClickPreference(
|
||||||
|
|
|
@ -3691,6 +3691,7 @@
|
||||||
|
|
||||||
<!-- AppSettingsFragment -->
|
<!-- AppSettingsFragment -->
|
||||||
<string name="AppSettingsFragment__invite_your_friends">Invite your friends</string>
|
<string name="AppSettingsFragment__invite_your_friends">Invite your friends</string>
|
||||||
|
<string name="AppSettingsFragment__copied_subscriber_id_to_clipboard">Copied subscriber id to clipboard</string>
|
||||||
|
|
||||||
<!-- AccountSettingsFragment -->
|
<!-- AccountSettingsFragment -->
|
||||||
<string name="AccountSettingsFragment__account">Account</string>
|
<string name="AccountSettingsFragment__account">Account</string>
|
||||||
|
|
Loading…
Add table
Reference in a new issue