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.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.*
|
import android.widget.*
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.content.res.AppCompatResources
|
import androidx.appcompat.content.res.AppCompatResources
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.lifecycle.ViewModel
|
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.db.entities.UserDatabaseEntity
|
||||||
import com.h.pixeldroid.utils.openUrl
|
import com.h.pixeldroid.utils.openUrl
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
@ -240,8 +240,8 @@ class ProfileActivity : BaseActivity() {
|
|||||||
).firstOrNull()
|
).firstOrNull()
|
||||||
|
|
||||||
if(relationship != null){
|
if(relationship != null){
|
||||||
if (relationship.following) {
|
if (relationship.following == true || relationship.requested == true) {
|
||||||
setOnClickUnfollow(account)
|
setOnClickUnfollow(account, relationship.requested == true)
|
||||||
} else {
|
} else {
|
||||||
setOnClickFollow(account)
|
setOnClickFollow(account)
|
||||||
}
|
}
|
||||||
@ -268,8 +268,9 @@ class ProfileActivity : BaseActivity() {
|
|||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
lifecycleScope.launchWhenResumed {
|
lifecycleScope.launchWhenResumed {
|
||||||
try {
|
try {
|
||||||
pixelfedAPI.follow(account.id.orEmpty(), "Bearer $accessToken")
|
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) {
|
} catch (exception: IOException) {
|
||||||
Log.e("FOLLOW ERROR", exception.toString())
|
Log.e("FOLLOW ERROR", exception.toString())
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
@ -287,29 +288,45 @@ class ProfileActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setOnClickUnfollow(account: Account) {
|
private fun setOnClickUnfollow(account: Account, requested: Boolean) {
|
||||||
binding.followButton.apply {
|
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 {
|
lifecycleScope.launchWhenResumed {
|
||||||
try {
|
try {
|
||||||
pixelfedAPI.unfollow(account.id.orEmpty(), "Bearer $accessToken")
|
val rel = pixelfedAPI.unfollow(account.id.orEmpty(), "Bearer $accessToken")
|
||||||
setOnClickFollow(account)
|
if(rel.following == false && rel.requested == false) setOnClickFollow(account)
|
||||||
|
else setOnClickUnfollow(account, rel.requested == true)
|
||||||
} catch (exception: IOException) {
|
} catch (exception: IOException) {
|
||||||
Log.e("FOLLOW ERROR", exception.toString())
|
Log.e("FOLLOW ERROR", exception.toString())
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
applicationContext, getString(R.string.unfollow_error),
|
applicationContext, getString(R.string.unfollow_error),
|
||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
} catch (exception: HttpException) {
|
} catch (exception: HttpException) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
applicationContext, getString(R.string.unfollow_error),
|
applicationContext, getString(R.string.unfollow_error),
|
||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
).show()
|
).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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,14 +5,14 @@ import java.io.Serializable
|
|||||||
data class Relationship(
|
data class Relationship(
|
||||||
// Required atributes
|
// Required atributes
|
||||||
val id: String,
|
val id: String,
|
||||||
val following: Boolean,
|
val following: Boolean?,
|
||||||
val requested: Boolean,
|
val requested: Boolean?,
|
||||||
val endorsed: Boolean,
|
val endorsed: Boolean?,
|
||||||
val followed_by: Boolean,
|
val followed_by: Boolean?,
|
||||||
val muting: Boolean,
|
val muting: Boolean?,
|
||||||
val muting_notifications: Boolean,
|
val muting_notifications: Boolean?,
|
||||||
val showing_reblogs: Boolean,
|
val showing_reblogs: Boolean?,
|
||||||
val blocking: Boolean,
|
val blocking: Boolean?,
|
||||||
val domain_blocking: Boolean,
|
val domain_blocking: Boolean?,
|
||||||
val blocked_by: Boolean
|
val blocked_by: Boolean?
|
||||||
) : Serializable
|
) : 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="no_username">No Username</string>
|
||||||
<string name="follow">Follow</string>
|
<string name="follow">Follow</string>
|
||||||
<string name="unfollow">Unfollow</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>
|
<string name="edit_profile">Edit profile</string>
|
||||||
<!-- Search page -->
|
<!-- Search page -->
|
||||||
<string name="search">Search</string>
|
<string name="search">Search</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user