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