Merge branch 'follow_requests' into 'master'
Private accounts and follow requests Closes #279 See merge request pixeldroid/PixelDroid!321
This commit is contained in:
commit
d8a6aaa4b7
|
@ -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
|
||||
|
@ -37,7 +38,6 @@ import com.h.pixeldroid.utils.api.objects.Status
|
|||
import com.h.pixeldroid.utils.db.entities.UserDatabaseEntity
|
||||
import com.h.pixeldroid.utils.openUrl
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.launch
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
|
@ -240,8 +240,8 @@ class ProfileActivity : BaseActivity() {
|
|||
).firstOrNull()
|
||||
|
||||
if(relationship != null){
|
||||
if (relationship.following) {
|
||||
setOnClickUnfollow(account)
|
||||
if (relationship.following == true || relationship.requested == true) {
|
||||
setOnClickUnfollow(account, relationship.requested == true)
|
||||
} else {
|
||||
setOnClickFollow(account)
|
||||
}
|
||||
|
@ -268,8 +268,9 @@ class ProfileActivity : BaseActivity() {
|
|||
setOnClickListener {
|
||||
lifecycleScope.launchWhenResumed {
|
||||
try {
|
||||
pixelfedAPI.follow(account.id.orEmpty(), "Bearer $accessToken")
|
||||
setOnClickUnfollow(account)
|
||||
val rel = pixelfedAPI.follow(account.id.orEmpty(), "Bearer $accessToken")
|
||||
if(rel.following == true) setOnClickUnfollow(account, rel.requested == true)
|
||||
else setOnClickFollow(account)
|
||||
} catch (exception: IOException) {
|
||||
Log.e("FOLLOW ERROR", exception.toString())
|
||||
Toast.makeText(
|
||||
|
@ -287,15 +288,19 @@ class ProfileActivity : BaseActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun setOnClickUnfollow(account: Account) {
|
||||
private fun setOnClickUnfollow(account: Account, requested: Boolean) {
|
||||
binding.followButton.apply {
|
||||
setText(R.string.unfollow)
|
||||
if(account.locked == true && requested) {
|
||||
setText(R.string.follow_requested)
|
||||
} else setText(R.string.unfollow)
|
||||
|
||||
setOnClickListener {
|
||||
|
||||
fun unfollow() {
|
||||
lifecycleScope.launchWhenResumed {
|
||||
try {
|
||||
pixelfedAPI.unfollow(account.id.orEmpty(), "Bearer $accessToken")
|
||||
setOnClickFollow(account)
|
||||
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(
|
||||
|
@ -310,6 +315,18 @@ class ProfileActivity : BaseActivity() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -152,6 +152,8 @@ For more info about Pixelfed, you can check here: https://pixelfed.org"</string>
|
|||
<string name="no_username">No Username</string>
|
||||
<string name="follow">Follow</string>
|
||||
<string name="unfollow">Unfollow</string>
|
||||
<string name="follow_requested">Follow Requested</string>
|
||||
<string name="dialog_message_cancel_follow_request">Cancel the follow request?</string>
|
||||
<string name="edit_profile">Edit profile</string>
|
||||
<!-- Search page -->
|
||||
<string name="search">Search</string>
|
||||
|
|
Loading…
Reference in New Issue