diff --git a/app/src/main/java/com/h/pixeldroid/profile/ProfileActivity.kt b/app/src/main/java/com/h/pixeldroid/profile/ProfileActivity.kt
index 88d88d13..357a80c8 100644
--- a/app/src/main/java/com/h/pixeldroid/profile/ProfileActivity.kt
+++ b/app/src/main/java/com/h/pixeldroid/profile/ProfileActivity.kt
@@ -7,6 +7,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.*
+import androidx.appcompat.app.AlertDialog
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.content.ContextCompat
import androidx.lifecycle.ViewModel
@@ -239,10 +240,10 @@ class ProfileActivity : BaseActivity() {
).firstOrNull()
if(relationship != null){
- if (relationship.following) {
- setOnClickUnfollow(account, true)
+ if (relationship.following == true || relationship.requested == true) {
+ setOnClickUnfollow(account, relationship.requested == true)
} else {
- setOnClickFollow(account, relationship.requested)
+ setOnClickFollow(account)
}
binding.followButton.visibility = View.VISIBLE
}
@@ -261,18 +262,15 @@ class ProfileActivity : BaseActivity() {
}
}
- private fun setOnClickFollow(account: Account, requested: Boolean) {
+ private fun setOnClickFollow(account: Account) {
binding.followButton.apply {
- if(account.locked == true && requested) {
- setText(R.string.follow_requested)
- isEnabled = false
- return
- } else setText(R.string.follow)
+ setText(R.string.follow)
setOnClickListener {
lifecycleScope.launchWhenResumed {
try {
val rel = pixelfedAPI.follow(account.id.orEmpty(), "Bearer $accessToken")
- setOnClickUnfollow(account)
+ if(rel.following == true) setOnClickUnfollow(account, rel.requested == true)
+ else setOnClickFollow(account)
} catch (exception: IOException) {
Log.e("FOLLOW ERROR", exception.toString())
Toast.makeText(
@@ -290,33 +288,45 @@ class ProfileActivity : BaseActivity() {
}
}
- private fun setOnClickUnfollow(account: Account, follow: Boolean = false) {
+ private fun setOnClickUnfollow(account: Account, requested: Boolean) {
binding.followButton.apply {
- if(account.locked == true && !follow) {
+ if(account.locked == true && requested) {
setText(R.string.follow_requested)
- isEnabled = false
- return
} else setText(R.string.unfollow)
- setOnClickListener {
+
+ fun unfollow() {
lifecycleScope.launchWhenResumed {
try {
- pixelfedAPI.unfollow(account.id.orEmpty(), "Bearer $accessToken")
- setOnClickFollow(account, false)
+ val rel = pixelfedAPI.unfollow(account.id.orEmpty(), "Bearer $accessToken")
+ if(rel.following == false && rel.requested == false) setOnClickFollow(account)
+ else setOnClickUnfollow(account, rel.requested == true)
} catch (exception: IOException) {
Log.e("FOLLOW ERROR", exception.toString())
Toast.makeText(
- applicationContext, getString(R.string.unfollow_error),
- Toast.LENGTH_SHORT
+ applicationContext, getString(R.string.unfollow_error),
+ Toast.LENGTH_SHORT
).show()
} catch (exception: HttpException) {
Toast.makeText(
- applicationContext, getString(R.string.unfollow_error),
- Toast.LENGTH_SHORT
+ applicationContext, getString(R.string.unfollow_error),
+ Toast.LENGTH_SHORT
).show()
}
}
}
+
+ setOnClickListener {
+ if(account.locked == true && requested){
+ AlertDialog.Builder(context)
+ .setMessage(R.string.dialog_message_cancel_follow_request)
+ .setPositiveButton(android.R.string.ok) { _, _ ->
+ unfollow()
+ }
+ .setNegativeButton(android.R.string.cancel){_, _ -> }
+ .show()
+ } else unfollow()
+ }
}
}
}
diff --git a/app/src/main/java/com/h/pixeldroid/utils/api/objects/Relationship.kt b/app/src/main/java/com/h/pixeldroid/utils/api/objects/Relationship.kt
index 82e4f951..e13d6449 100644
--- a/app/src/main/java/com/h/pixeldroid/utils/api/objects/Relationship.kt
+++ b/app/src/main/java/com/h/pixeldroid/utils/api/objects/Relationship.kt
@@ -5,14 +5,14 @@ import java.io.Serializable
data class Relationship(
// Required atributes
val id: String,
- val following: Boolean,
- val requested: Boolean,
- val endorsed: Boolean,
- val followed_by: Boolean,
- val muting: Boolean,
- val muting_notifications: Boolean,
- val showing_reblogs: Boolean,
- val blocking: Boolean,
- val domain_blocking: Boolean,
- val blocked_by: Boolean
+ val following: Boolean?,
+ val requested: Boolean?,
+ val endorsed: Boolean?,
+ val followed_by: Boolean?,
+ val muting: Boolean?,
+ val muting_notifications: Boolean?,
+ val showing_reblogs: Boolean?,
+ val blocking: Boolean?,
+ val domain_blocking: Boolean?,
+ val blocked_by: Boolean?
) : Serializable
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 1267c31e..37e497ed 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -199,4 +199,5 @@ For more info about Pixelfed, you can check here: https://pixelfed.org"
Image showing a red panda, Pixelfed\'s mascot, using a phone
Could not delete the post, error %1$d
Could not delete the post, check your connection?
+ Cancel the follow request?
\ No newline at end of file