kopia lustrzana https://github.com/ryukoposting/Signal-Android
Add become a sustainer bottom sheet.
rodzic
2df303cde7
commit
306875478e
|
@ -0,0 +1,77 @@
|
||||||
|
package org.thoughtcrime.securesms.badges.self.none
|
||||||
|
|
||||||
|
import androidx.fragment.app.FragmentManager
|
||||||
|
import androidx.fragment.app.viewModels
|
||||||
|
import org.signal.core.util.DimensionUnit
|
||||||
|
import org.thoughtcrime.securesms.R
|
||||||
|
import org.thoughtcrime.securesms.badges.models.BadgePreview
|
||||||
|
import org.thoughtcrime.securesms.components.settings.DSLConfiguration
|
||||||
|
import org.thoughtcrime.securesms.components.settings.DSLSettingsAdapter
|
||||||
|
import org.thoughtcrime.securesms.components.settings.DSLSettingsBottomSheetFragment
|
||||||
|
import org.thoughtcrime.securesms.components.settings.DSLSettingsText
|
||||||
|
import org.thoughtcrime.securesms.components.settings.app.AppSettingsActivity
|
||||||
|
import org.thoughtcrime.securesms.components.settings.app.subscription.SubscriptionsRepository
|
||||||
|
import org.thoughtcrime.securesms.components.settings.configure
|
||||||
|
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
|
||||||
|
import org.thoughtcrime.securesms.util.BottomSheetUtil
|
||||||
|
|
||||||
|
class BecomeASustainerFragment : DSLSettingsBottomSheetFragment() {
|
||||||
|
|
||||||
|
private val viewModel: BecomeASustainerViewModel by viewModels(
|
||||||
|
factoryProducer = {
|
||||||
|
BecomeASustainerViewModel.Factory(SubscriptionsRepository(ApplicationDependencies.getDonationsService()))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
override fun bindAdapter(adapter: DSLSettingsAdapter) {
|
||||||
|
BadgePreview.register(adapter)
|
||||||
|
|
||||||
|
viewModel.state.observe(viewLifecycleOwner) {
|
||||||
|
adapter.submitList(getConfiguration(it).toMappingModelList())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getConfiguration(state: BecomeASustainerState): DSLConfiguration {
|
||||||
|
return configure {
|
||||||
|
customPref(BadgePreview.Model(badge = state.badge))
|
||||||
|
|
||||||
|
sectionHeaderPref(
|
||||||
|
title = DSLSettingsText.from(
|
||||||
|
R.string.BecomeASustainerFragment__get_badges,
|
||||||
|
DSLSettingsText.CenterModifier,
|
||||||
|
DSLSettingsText.Title2BoldModifier
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
space(DimensionUnit.DP.toPixels(8f).toInt())
|
||||||
|
|
||||||
|
noPadTextPref(
|
||||||
|
title = DSLSettingsText.from(
|
||||||
|
R.string.BecomeASustainerFragment__signal_is_a_non_profit,
|
||||||
|
DSLSettingsText.CenterModifier
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
space(DimensionUnit.DP.toPixels(77f).toInt())
|
||||||
|
|
||||||
|
primaryButton(
|
||||||
|
text = DSLSettingsText.from(
|
||||||
|
R.string.BecomeASustainerMegaphone__become_a_sustainer
|
||||||
|
),
|
||||||
|
onClick = {
|
||||||
|
requireActivity().finish()
|
||||||
|
requireActivity().startActivity(AppSettingsActivity.subscriptions(requireContext()))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
space(DimensionUnit.DP.toPixels(8f).toInt())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@JvmStatic
|
||||||
|
fun show(fragmentManager: FragmentManager) {
|
||||||
|
BecomeASustainerFragment().show(fragmentManager, BottomSheetUtil.STANDARD_BOTTOM_SHEET_FRAGMENT_TAG)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package org.thoughtcrime.securesms.badges.self.none
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.badges.models.Badge
|
||||||
|
|
||||||
|
data class BecomeASustainerState(
|
||||||
|
val badge: Badge? = null
|
||||||
|
)
|
|
@ -0,0 +1,45 @@
|
||||||
|
package org.thoughtcrime.securesms.badges.self.none
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||||
|
import io.reactivex.rxjava3.kotlin.plusAssign
|
||||||
|
import io.reactivex.rxjava3.kotlin.subscribeBy
|
||||||
|
import org.signal.core.util.logging.Log
|
||||||
|
import org.thoughtcrime.securesms.components.settings.app.subscription.SubscriptionsRepository
|
||||||
|
import org.thoughtcrime.securesms.util.livedata.Store
|
||||||
|
|
||||||
|
class BecomeASustainerViewModel(subscriptionsRepository: SubscriptionsRepository) : ViewModel() {
|
||||||
|
|
||||||
|
private val store = Store(BecomeASustainerState())
|
||||||
|
|
||||||
|
val state: LiveData<BecomeASustainerState> = store.stateLiveData
|
||||||
|
|
||||||
|
private val disposables = CompositeDisposable()
|
||||||
|
|
||||||
|
init {
|
||||||
|
disposables += subscriptionsRepository.getSubscriptions().subscribeBy(
|
||||||
|
onError = { Log.w(TAG, "Could not load subscriptions.") },
|
||||||
|
onSuccess = { subscriptions ->
|
||||||
|
store.update {
|
||||||
|
it.copy(badge = subscriptions.firstOrNull()?.badge)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCleared() {
|
||||||
|
disposables.clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val TAG = Log.tag(BecomeASustainerViewModel::class.java)
|
||||||
|
}
|
||||||
|
|
||||||
|
class Factory(private val subscriptionsRepository: SubscriptionsRepository) : ViewModelProvider.Factory {
|
||||||
|
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
|
||||||
|
return modelClass.cast(BecomeASustainerViewModel(subscriptionsRepository))!!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,10 +29,12 @@ import org.thoughtcrime.securesms.avatar.Avatars;
|
||||||
import org.thoughtcrime.securesms.avatar.picker.AvatarPickerFragment;
|
import org.thoughtcrime.securesms.avatar.picker.AvatarPickerFragment;
|
||||||
import org.thoughtcrime.securesms.badges.BadgeImageView;
|
import org.thoughtcrime.securesms.badges.BadgeImageView;
|
||||||
import org.thoughtcrime.securesms.badges.models.Badge;
|
import org.thoughtcrime.securesms.badges.models.Badge;
|
||||||
|
import org.thoughtcrime.securesms.badges.self.none.BecomeASustainerFragment;
|
||||||
import org.thoughtcrime.securesms.components.emoji.EmojiUtil;
|
import org.thoughtcrime.securesms.components.emoji.EmojiUtil;
|
||||||
import org.thoughtcrime.securesms.mediasend.Media;
|
import org.thoughtcrime.securesms.mediasend.Media;
|
||||||
import org.thoughtcrime.securesms.profiles.ProfileName;
|
import org.thoughtcrime.securesms.profiles.ProfileName;
|
||||||
import org.thoughtcrime.securesms.profiles.manage.ManageProfileViewModel.AvatarState;
|
import org.thoughtcrime.securesms.profiles.manage.ManageProfileViewModel.AvatarState;
|
||||||
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
import org.thoughtcrime.securesms.util.FeatureFlags;
|
import org.thoughtcrime.securesms.util.FeatureFlags;
|
||||||
import org.thoughtcrime.securesms.util.NameUtil;
|
import org.thoughtcrime.securesms.util.NameUtil;
|
||||||
import org.thoughtcrime.securesms.util.views.SimpleProgressDialog;
|
import org.thoughtcrime.securesms.util.views.SimpleProgressDialog;
|
||||||
|
@ -118,7 +120,11 @@ public class ManageProfileFragment extends LoggingFragment {
|
||||||
|
|
||||||
if (FeatureFlags.donorBadges()) {
|
if (FeatureFlags.donorBadges()) {
|
||||||
badgesContainer.setOnClickListener(v -> {
|
badgesContainer.setOnClickListener(v -> {
|
||||||
|
if (Recipient.self().getBadges().isEmpty()) {
|
||||||
|
BecomeASustainerFragment.show(getParentFragmentManager());
|
||||||
|
} else {
|
||||||
Navigation.findNavController(v).navigate(ManageProfileFragmentDirections.actionManageProfileFragmentToBadgeManageFragment());
|
Navigation.findNavController(v).navigate(ManageProfileFragmentDirections.actionManageProfileFragmentToBadgeManageFragment());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
badgesContainer.setVisibility(View.GONE);
|
badgesContainer.setVisibility(View.GONE);
|
||||||
|
|
|
@ -3971,6 +3971,9 @@
|
||||||
<string name="SubscribeThanksForYourSupportBottomSheetDialogFragment__done">Done</string>
|
<string name="SubscribeThanksForYourSupportBottomSheetDialogFragment__done">Done</string>
|
||||||
<string name="ThanksForYourSupportBottomSheetFragment__when_you_have_more">When you have more than one badge, you can choose one to feature for others to see on your profile.</string>
|
<string name="ThanksForYourSupportBottomSheetFragment__when_you_have_more">When you have more than one badge, you can choose one to feature for others to see on your profile.</string>
|
||||||
|
|
||||||
|
<string name="BecomeASustainerFragment__get_badges">Get badges for your profile by supporting Signal.</string>
|
||||||
|
<string name="BecomeASustainerFragment__signal_is_a_non_profit">Signal is a nonprofit with no advertisers or investors, supported only by people like you.</string>
|
||||||
|
|
||||||
<string name="ManageDonationsFragment__my_support">My support</string>
|
<string name="ManageDonationsFragment__my_support">My support</string>
|
||||||
<string name="ManageDonationsFragment__manage_subscription">Manage subscription</string>
|
<string name="ManageDonationsFragment__manage_subscription">Manage subscription</string>
|
||||||
<string name="ManageDonationsFragment__badges">Badges</string>
|
<string name="ManageDonationsFragment__badges">Badges</string>
|
||||||
|
|
Ładowanie…
Reference in New Issue