allow follow requests

This commit is contained in:
Matthieu 2021-03-26 19:54:04 +01:00
parent 34446fc9de
commit 173b8e8e01
2 changed files with 17 additions and 12 deletions

View File

@ -1,18 +1,14 @@
package com.h.pixeldroid.profile package com.h.pixeldroid.profile
import android.content.Intent import android.content.Intent
import android.graphics.Typeface
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
import android.view.View import android.view.View
import android.widget.* import android.widget.*
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.constraintlayout.motion.widget.MotionLayout
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.h.pixeldroid.R import com.h.pixeldroid.R
import com.h.pixeldroid.databinding.ActivityProfileBinding import com.h.pixeldroid.databinding.ActivityProfileBinding
import com.h.pixeldroid.posts.parseHTMLText import com.h.pixeldroid.posts.parseHTMLText
@ -244,9 +240,9 @@ class ProfileActivity : BaseActivity() {
if(relationship != null){ if(relationship != null){
if (relationship.following) { if (relationship.following) {
setOnClickUnfollow(account) setOnClickUnfollow(account, true)
} else { } else {
setOnClickFollow(account) setOnClickFollow(account, relationship.requested)
} }
binding.followButton.visibility = View.VISIBLE 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 { 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 { 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) setOnClickUnfollow(account)
} catch (exception: IOException) { } catch (exception: IOException) {
Log.e("FOLLOW ERROR", exception.toString()) 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 { 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 { setOnClickListener {
lifecycleScope.launchWhenResumed { lifecycleScope.launchWhenResumed {
try { try {
pixelfedAPI.unfollow(account.id.orEmpty(), "Bearer $accessToken") pixelfedAPI.unfollow(account.id.orEmpty(), "Bearer $accessToken")
setOnClickFollow(account) setOnClickFollow(account, false)
} catch (exception: IOException) { } catch (exception: IOException) {
Log.e("FOLLOW ERROR", exception.toString()) Log.e("FOLLOW ERROR", exception.toString())
Toast.makeText( Toast.makeText(

View File

@ -156,6 +156,7 @@ Following"</item>
<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="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>