mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 06:37:30 +00:00
Move FriendService object to FriendshipRepository constructor parameter.
This commit is contained in:
parent
0126fca36d
commit
e1532eb4b8
@ -167,7 +167,7 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
|
||||
@Override
|
||||
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
friendshipRepository = FriendshipRepository.INSTANCE;
|
||||
friendshipRepository = FriendshipRepository.Companion.getInstance();
|
||||
fragmentActivity = (AppCompatActivity) getActivity();
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
@ -228,7 +228,7 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
|
||||
userId = CookieUtils.getUserIdFromCookie(cookie);
|
||||
deviceUuid = Utils.settingsHelper.getString(Constants.DEVICE_UUID);
|
||||
csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie);
|
||||
friendshipRepository = FriendshipRepository.INSTANCE;
|
||||
friendshipRepository = FriendshipRepository.Companion.getInstance();
|
||||
mediaService = MediaService.INSTANCE;
|
||||
newsService = NewsService.getInstance();
|
||||
}
|
||||
|
@ -333,7 +333,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
||||
deviceUuid = Utils.settingsHelper.getString(Constants.DEVICE_UUID);
|
||||
csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie);
|
||||
fragmentActivity = (MainActivity) requireActivity();
|
||||
friendshipRepository = isLoggedIn ? FriendshipRepository.INSTANCE : null;
|
||||
friendshipRepository = isLoggedIn ? FriendshipRepository.Companion.getInstance() : null;
|
||||
directMessagesService = isLoggedIn ? DirectMessagesService.INSTANCE : null;
|
||||
storiesService = isLoggedIn ? StoriesService.INSTANCE : null;
|
||||
mediaService = isLoggedIn ? MediaService.INSTANCE : null;
|
||||
|
@ -62,6 +62,7 @@ class ThreadManager(
|
||||
val pendingRequests: LiveData<DirectThreadParticipantRequestsResponse?> = _pendingRequests
|
||||
private val inboxManager: InboxManager = if (pending) DirectMessagesManager.pendingInboxManager else DirectMessagesManager.inboxManager
|
||||
private val threadIdOrUserIds: ThreadIdOrUserIds = of(threadId)
|
||||
private val friendshipRepository: FriendshipRepository by lazy { FriendshipRepository.getInstance() }
|
||||
|
||||
val thread: LiveData<DirectThread?> by lazy {
|
||||
distinctUntilChanged(map(inboxManager.getInbox()) { inboxResource: Resource<DirectInbox?>? ->
|
||||
@ -1151,7 +1152,7 @@ class ThreadManager(
|
||||
val data = MutableLiveData<Resource<Any?>>()
|
||||
scope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
FriendshipRepository.changeBlock(csrfToken, viewerId, deviceUuid, false, user.pk)
|
||||
friendshipRepository.changeBlock(csrfToken, viewerId, deviceUuid, false, user.pk)
|
||||
refreshChats(scope)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "onFailure: ", e)
|
||||
@ -1165,7 +1166,7 @@ class ThreadManager(
|
||||
val data = MutableLiveData<Resource<Any?>>()
|
||||
scope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
FriendshipRepository.changeBlock(csrfToken, viewerId, deviceUuid, true, user.pk)
|
||||
friendshipRepository.changeBlock(csrfToken, viewerId, deviceUuid, true, user.pk)
|
||||
refreshChats(scope)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "onFailure: ", e)
|
||||
@ -1179,7 +1180,7 @@ class ThreadManager(
|
||||
val data = MutableLiveData<Resource<Any?>>()
|
||||
scope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
FriendshipRepository.toggleRestrict(csrfToken, deviceUuid, user.pk, true)
|
||||
friendshipRepository.toggleRestrict(csrfToken, deviceUuid, user.pk, true)
|
||||
refreshChats(scope)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "onFailure: ", e)
|
||||
@ -1193,7 +1194,7 @@ class ThreadManager(
|
||||
val data = MutableLiveData<Resource<Any?>>()
|
||||
scope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
FriendshipRepository.toggleRestrict(csrfToken, deviceUuid, user.pk, false)
|
||||
friendshipRepository.toggleRestrict(csrfToken, deviceUuid, user.pk, false)
|
||||
refreshChats(scope)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "onFailure: ", e)
|
||||
|
@ -11,8 +11,7 @@ import org.json.JSONArray
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
|
||||
object FriendshipRepository {
|
||||
private val service: FriendshipService = retrofit.create(FriendshipService::class.java)
|
||||
class FriendshipRepository(private val service: FriendshipService) {
|
||||
|
||||
suspend fun follow(
|
||||
csrfToken: String,
|
||||
@ -34,9 +33,7 @@ object FriendshipRepository {
|
||||
deviceUuid: String,
|
||||
unblock: Boolean,
|
||||
targetUserId: Long,
|
||||
): FriendshipChangeResponse {
|
||||
return change(csrfToken, userId, deviceUuid, if (unblock) "unblock" else "block", targetUserId)
|
||||
}
|
||||
): FriendshipChangeResponse = change(csrfToken, userId, deviceUuid, if (unblock) "unblock" else "block", targetUserId)
|
||||
|
||||
suspend fun toggleRestrict(
|
||||
csrfToken: String,
|
||||
@ -144,12 +141,26 @@ object FriendshipRepository {
|
||||
val followModels = mutableListOf<FollowModel>()
|
||||
for (i in 0 until items.length()) {
|
||||
val itemJson = items.optJSONObject(i) ?: continue
|
||||
val followModel = FollowModel(itemJson.getString("pk"),
|
||||
val followModel = FollowModel(
|
||||
itemJson.getString("pk"),
|
||||
itemJson.getString("username"),
|
||||
itemJson.optString("full_name"),
|
||||
itemJson.getString("profile_pic_url"))
|
||||
itemJson.getString("profile_pic_url")
|
||||
)
|
||||
followModels.add(followModel)
|
||||
}
|
||||
return followModels
|
||||
}
|
||||
|
||||
companion object {
|
||||
@Volatile
|
||||
private var INSTANCE: FriendshipRepository? = null
|
||||
|
||||
fun getInstance(): FriendshipRepository {
|
||||
return INSTANCE ?: synchronized(this) {
|
||||
val service: FriendshipService = retrofit.create(FriendshipService::class.java)
|
||||
FriendshipRepository(service).also { INSTANCE = it }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user