From 173b8e8e0179ca850bfc065585e9fdd1f2f0b385 Mon Sep 17 00:00:00 2001
From: Matthieu <24-artectrex@users.noreply.shinice.net>
Date: Fri, 26 Mar 2021 19:54:04 +0100
Subject: [PATCH 1/3] allow follow requests
---
.../h/pixeldroid/profile/ProfileActivity.kt | 28 +++++++++++--------
app/src/main/res/values/strings.xml | 1 +
2 files changed, 17 insertions(+), 12 deletions(-)
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 753cc467..80ee5b17 100644
--- a/app/src/main/java/com/h/pixeldroid/profile/ProfileActivity.kt
+++ b/app/src/main/java/com/h/pixeldroid/profile/ProfileActivity.kt
@@ -1,18 +1,14 @@
package com.h.pixeldroid.profile
import android.content.Intent
-import android.graphics.Typeface
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.*
import androidx.annotation.StringRes
-import androidx.constraintlayout.motion.widget.MotionLayout
import androidx.core.content.ContextCompat
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.GridLayoutManager
-import androidx.recyclerview.widget.RecyclerView
-import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.h.pixeldroid.R
import com.h.pixeldroid.databinding.ActivityProfileBinding
import com.h.pixeldroid.posts.parseHTMLText
@@ -244,9 +240,9 @@ class ProfileActivity : BaseActivity() {
if(relationship != null){
if (relationship.following) {
- setOnClickUnfollow(account)
+ setOnClickUnfollow(account, true)
} else {
- setOnClickFollow(account)
+ setOnClickFollow(account, relationship.requested)
}
binding.followButton.visibility = View.VISIBLE
}
@@ -265,13 +261,17 @@ class ProfileActivity : BaseActivity() {
}
}
- private fun setOnClickFollow(account: Account) {
+ private fun setOnClickFollow(account: Account, requested: Boolean) {
binding.followButton.apply {
- setText(R.string.follow)
+ if(account.locked == true && requested) {
+ setText(R.string.follow_requested)
+ isEnabled = false
+ return
+ } else setText(R.string.follow)
setOnClickListener {
lifecycleScope.launchWhenResumed {
try {
- pixelfedAPI.follow(account.id.orEmpty(), "Bearer $accessToken")
+ val rel = pixelfedAPI.follow(account.id.orEmpty(), "Bearer $accessToken")
setOnClickUnfollow(account)
} catch (exception: IOException) {
Log.e("FOLLOW ERROR", exception.toString())
@@ -290,15 +290,19 @@ class ProfileActivity : BaseActivity() {
}
}
- private fun setOnClickUnfollow(account: Account) {
+ private fun setOnClickUnfollow(account: Account, follow: Boolean = false) {
binding.followButton.apply {
- setText(R.string.unfollow)
+ if(account.locked == true && !follow) {
+ setText(R.string.follow_requested)
+ isEnabled = false
+ return
+ } else setText(R.string.unfollow)
setOnClickListener {
lifecycleScope.launchWhenResumed {
try {
pixelfedAPI.unfollow(account.id.orEmpty(), "Bearer $accessToken")
- setOnClickFollow(account)
+ setOnClickFollow(account, false)
} catch (exception: IOException) {
Log.e("FOLLOW ERROR", exception.toString())
Toast.makeText(
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 7e6a5116..94801517 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -156,6 +156,7 @@ Following"
No Username
Follow
Unfollow
+ Follow Requested
Edit profile
Search
From 9f9d0e23bc3577edff7861b5516876ad7acee5dc Mon Sep 17 00:00:00 2001
From: Matthieu <24-artectrex@users.noreply.shinice.net>
Date: Sat, 27 Mar 2021 15:24:58 +0100
Subject: [PATCH 2/3] make json fields nullable, correct request logic
---
.../h/pixeldroid/profile/ProfileActivity.kt | 52 +++++++++++--------
.../utils/api/objects/Relationship.kt | 20 +++----
app/src/main/res/values/strings.xml | 1 +
3 files changed, 42 insertions(+), 31 deletions(-)
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
From 49630b2ad53384de986c10a799d75f4723ddae4d Mon Sep 17 00:00:00 2001
From: Matthieu <24-artectrex@users.noreply.shinice.net>
Date: Sat, 27 Mar 2021 15:27:26 +0100
Subject: [PATCH 3/3] move string
---
app/src/main/res/values/strings.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 37e497ed..9e01748b 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -153,6 +153,7 @@ For more info about Pixelfed, you can check here: https://pixelfed.org"
Follow
Unfollow
Follow Requested
+ Cancel the follow request?
Edit profile
Search
@@ -199,5 +200,4 @@ 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