From f6a9c51b86ef25a5ac77a15a44a1789006733e09 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sat, 11 Jan 2020 10:10:22 +0300 Subject: [PATCH] AccountActivity: implement subscribing --- .../keylesspalace/tusky/AccountActivity.kt | 29 +++++++++++++++++-- .../keylesspalace/tusky/appstore/Events.kt | 2 +- .../tusky/viewmodel/AccountViewModel.kt | 16 ++++++++-- .../drawable/ic_notifications_active_24dp.xml | 13 +++++++++ app/src/main/res/layout/activity_account.xml | 22 +++++++++++++- 5 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 app/src/main/res/drawable/ic_notifications_active_24dp.xml diff --git a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt index 4fdaa1ed..40f55a0a 100644 --- a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt @@ -83,6 +83,7 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI private var blocking: Boolean = false private var muting: Boolean = false private var showingReblogs: Boolean = false + private var subscribing: Boolean = false private var loadedAccount: Account? = null private var animateAvatar: Boolean = false @@ -185,7 +186,6 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI poorTabView.isPressed = true accountTabLayout.postDelayed({ poorTabView.isPressed = false }, 300) } - } /** @@ -390,7 +390,6 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI accountFieldAdapter.emojis = account.emojis ?: emptyList() accountFieldAdapter.notifyDataSetChanged() - accountLockedImageView.visible(account.locked) accountBadgeTextView.visible(account.bot) accountAdminTextView.visible(account.pleroma?.isAdmin ?: false) @@ -554,6 +553,15 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI showingReblogs = relation.showingReblogs accountFollowsYouTextView.visible(relation.followedBy) + + // because subscribing is Pleroma extension, enable it __only__ when we have non-null subscribing field + if(!viewModel.isSelf && followState == FollowState.FOLLOWING && relation.subscribing != null) { + accountSubscribeButton.show() + accountSubscribeButton.setOnClickListener { + viewModel.changeSubscribingState() + } + subscribing = relation.subscribing + } updateButtons() } @@ -578,6 +586,7 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI accountFollowButton.setText(R.string.action_unfollow) } } + updateSubscribeButton() } private fun updateMuteButton() { @@ -587,7 +596,19 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI accountMuteButton.hide() } } - + + private fun updateSubscribeButton() { + if(followState != FollowState.FOLLOWING) { + accountSubscribeButton.hide() + } + + if(subscribing) { + accountSubscribeButton.setIconResource(R.drawable.ic_notifications_active_24dp) + } else { + accountSubscribeButton.setIconResource(R.drawable.ic_notifications_24dp) + } + } + private fun updateButtons() { invalidateOptionsMenu() @@ -599,6 +620,7 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI if (blocking || viewModel.isSelf) { accountFloatingActionButton.hide() accountMuteButton.hide() + accountSubscribeButton.hide() } else { accountFloatingActionButton.show() if (muting) @@ -612,6 +634,7 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI accountFloatingActionButton.hide() accountFollowButton.hide() accountMuteButton.hide() + accountSubscribeButton.hide() } } diff --git a/app/src/main/java/com/keylesspalace/tusky/appstore/Events.kt b/app/src/main/java/com/keylesspalace/tusky/appstore/Events.kt index 7bdc17e6..6c82d16f 100644 --- a/app/src/main/java/com/keylesspalace/tusky/appstore/Events.kt +++ b/app/src/main/java/com/keylesspalace/tusky/appstore/Events.kt @@ -18,4 +18,4 @@ data class ProfileEditedEvent(val newProfileData: Account) : Dispatchable data class PreferenceChangedEvent(val preferenceKey: String) : Dispatchable data class MainTabsChangedEvent(val newTabs: List) : Dispatchable data class PollVoteEvent(val statusId: String, val poll: Poll) : Dispatchable -data class DomainMuteEvent(val instance: String): Dispatchable \ No newline at end of file +data class DomainMuteEvent(val instance: String): Dispatchable diff --git a/app/src/main/java/com/keylesspalace/tusky/viewmodel/AccountViewModel.kt b/app/src/main/java/com/keylesspalace/tusky/viewmodel/AccountViewModel.kt index ad90cacc..371beb97 100644 --- a/app/src/main/java/com/keylesspalace/tusky/viewmodel/AccountViewModel.kt +++ b/app/src/main/java/com/keylesspalace/tusky/viewmodel/AccountViewModel.kt @@ -155,6 +155,14 @@ class AccountViewModel @Inject constructor( changeRelationship(RelationShipAction.MUTE) } } + + fun changeSubscribingState() { + if (relationshipData.value?.data?.subscribing == true) { + changeRelationship(RelationShipAction.UNSUBSCRIBE) + } else { + changeRelationship(RelationShipAction.SUBSCRIBE) + } + } fun muteDomain(instance: String) { mastodonApi.blockDomain(instance).enqueue(object: Callback { @@ -200,6 +208,8 @@ class AccountViewModel @Inject constructor( RelationShipAction.UNBLOCK -> relation.copy(blocking = false) RelationShipAction.MUTE -> relation.copy(muting = true) RelationShipAction.UNMUTE -> relation.copy(muting = false) + RelationShipAction.SUBSCRIBE -> relation.copy(subscribing = true) + RelationShipAction.UNSUBSCRIBE -> relation.copy(subscribing = false) } relationshipData.postValue(Loading(newRelation)) } @@ -237,6 +247,8 @@ class AccountViewModel @Inject constructor( RelationShipAction.UNBLOCK -> mastodonApi.unblockAccount(accountId) RelationShipAction.MUTE -> mastodonApi.muteAccount(accountId) RelationShipAction.UNMUTE -> mastodonApi.unmuteAccount(accountId) + RelationShipAction.SUBSCRIBE -> mastodonApi.subscribeAccount(accountId) + RelationShipAction.UNSUBSCRIBE -> mastodonApi.unsubscribeAccount(accountId) } call.enqueue(callback) @@ -274,10 +286,10 @@ class AccountViewModel @Inject constructor( } enum class RelationShipAction { - FOLLOW, UNFOLLOW, BLOCK, UNBLOCK, MUTE, UNMUTE + FOLLOW, UNFOLLOW, BLOCK, UNBLOCK, MUTE, UNMUTE, SUBSCRIBE, UNSUBSCRIBE } companion object { const val TAG = "AccountViewModel" } -} \ No newline at end of file +} diff --git a/app/src/main/res/drawable/ic_notifications_active_24dp.xml b/app/src/main/res/drawable/ic_notifications_active_24dp.xml new file mode 100644 index 00000000..9a60daac --- /dev/null +++ b/app/src/main/res/drawable/ic_notifications_active_24dp.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_account.xml b/app/src/main/res/layout/activity_account.xml index c5d739b8..32389202 100644 --- a/app/src/main/res/layout/activity_account.xml +++ b/app/src/main/res/layout/activity_account.xml @@ -71,6 +71,26 @@ app:layout_constraintStart_toEndOf="@id/accountMuteButton" app:layout_constraintTop_toTopOf="parent" tools:text="Follow Requested" /> + +