1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-22 14:47:29 +00:00

Interchange FriendshipService and FriendshipRepository names.

This commit is contained in:
Ammar Githam 2021-06-10 16:16:41 +09:00
parent ed8ca2da02
commit 0126fca36d
6 changed files with 40 additions and 40 deletions

View File

@ -33,7 +33,7 @@ import awais.instagrabber.repositories.responses.FriendshipListFetchResponse;
import awais.instagrabber.utils.AppExecutors; import awais.instagrabber.utils.AppExecutors;
import awais.instagrabber.utils.CoroutineUtilsKt; import awais.instagrabber.utils.CoroutineUtilsKt;
import awais.instagrabber.utils.TextUtils; import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.webservices.FriendshipService; import awais.instagrabber.webservices.FriendshipRepository;
import awais.instagrabber.webservices.ServiceCallback; import awais.instagrabber.webservices.ServiceCallback;
import kotlinx.coroutines.Dispatchers; import kotlinx.coroutines.Dispatchers;
import thoughtbot.expandableadapter.ExpandableGroup; import thoughtbot.expandableadapter.ExpandableGroup;
@ -60,7 +60,7 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
private View.OnClickListener clickListener; private View.OnClickListener clickListener;
private FragmentFollowersViewerBinding binding; private FragmentFollowersViewerBinding binding;
private SwipeRefreshLayout root; private SwipeRefreshLayout root;
private FriendshipService friendshipService; private FriendshipRepository friendshipRepository;
private AppCompatActivity fragmentActivity; private AppCompatActivity fragmentActivity;
final ServiceCallback<FriendshipListFetchResponse> followingFetchCb = new ServiceCallback<FriendshipListFetchResponse>() { final ServiceCallback<FriendshipListFetchResponse> followingFetchCb = new ServiceCallback<FriendshipListFetchResponse>() {
@ -71,7 +71,7 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
if (!isFollowersList) followModels.addAll(result.getItems()); if (!isFollowersList) followModels.addAll(result.getItems());
if (result.isMoreAvailable()) { if (result.isMoreAvailable()) {
endCursor = result.getNextMaxId(); endCursor = result.getNextMaxId();
friendshipService.getList( friendshipRepository.getList(
false, false,
profileId, profileId,
endCursor, endCursor,
@ -85,7 +85,7 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
); );
} else if (followersModels.size() == 0) { } else if (followersModels.size() == 0) {
if (!isFollowersList) moreAvailable = false; if (!isFollowersList) moreAvailable = false;
friendshipService.getList( friendshipRepository.getList(
true, true,
profileId, profileId,
null, null,
@ -121,7 +121,7 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
if (isFollowersList) followModels.addAll(result.getItems()); if (isFollowersList) followModels.addAll(result.getItems());
if (result.isMoreAvailable()) { if (result.isMoreAvailable()) {
endCursor = result.getNextMaxId(); endCursor = result.getNextMaxId();
friendshipService.getList( friendshipRepository.getList(
true, true,
profileId, profileId,
endCursor, endCursor,
@ -135,7 +135,7 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
); );
} else if (followingModels.size() == 0) { } else if (followingModels.size() == 0) {
if (isFollowersList) moreAvailable = false; if (isFollowersList) moreAvailable = false;
friendshipService.getList( friendshipRepository.getList(
false, false,
profileId, profileId,
null, null,
@ -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);
friendshipService = FriendshipService.INSTANCE; friendshipRepository = FriendshipRepository.INSTANCE;
fragmentActivity = (AppCompatActivity) getActivity(); fragmentActivity = (AppCompatActivity) getActivity();
setHasOptionsMenu(true); setHasOptionsMenu(true);
} }
@ -289,7 +289,7 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
if (!TextUtils.isEmpty(endCursor) && !searching) { if (!TextUtils.isEmpty(endCursor) && !searching) {
binding.swipeRefreshLayout.setRefreshing(true); binding.swipeRefreshLayout.setRefreshing(true);
layoutManager.setStackFromEnd(true); layoutManager.setStackFromEnd(true);
friendshipService.getList( friendshipRepository.getList(
isFollowersList, isFollowersList,
profileId, profileId,
endCursor, endCursor,
@ -308,7 +308,7 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
binding.rvFollow.setLayoutManager(layoutManager); binding.rvFollow.setLayoutManager(layoutManager);
if (moreAvailable) { if (moreAvailable) {
binding.swipeRefreshLayout.setRefreshing(true); binding.swipeRefreshLayout.setRefreshing(true);
friendshipService.getList( friendshipRepository.getList(
isFollowersList, isFollowersList,
profileId, profileId,
endCursor, endCursor,
@ -335,7 +335,7 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
if (moreAvailable) { if (moreAvailable) {
binding.swipeRefreshLayout.setRefreshing(true); binding.swipeRefreshLayout.setRefreshing(true);
Toast.makeText(getContext(), R.string.follower_start_compare, Toast.LENGTH_LONG).show(); Toast.makeText(getContext(), R.string.follower_start_compare, Toast.LENGTH_LONG).show();
friendshipService.getList( friendshipRepository.getList(
isFollowersList, isFollowersList,
profileId, profileId,
endCursor, endCursor,
@ -351,7 +351,7 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
} else if (followersModels.size() == 0 || followingModels.size() == 0) { } else if (followersModels.size() == 0 || followingModels.size() == 0) {
binding.swipeRefreshLayout.setRefreshing(true); binding.swipeRefreshLayout.setRefreshing(true);
Toast.makeText(getContext(), R.string.follower_start_compare, Toast.LENGTH_LONG).show(); Toast.makeText(getContext(), R.string.follower_start_compare, Toast.LENGTH_LONG).show();
friendshipService.getList( friendshipRepository.getList(
!isFollowersList, !isFollowersList,
profileId, profileId,
null, null,

View File

@ -44,7 +44,7 @@ import awais.instagrabber.utils.CoroutineUtilsKt;
import awais.instagrabber.utils.TextUtils; import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.utils.Utils; import awais.instagrabber.utils.Utils;
import awais.instagrabber.viewmodels.NotificationViewModel; import awais.instagrabber.viewmodels.NotificationViewModel;
import awais.instagrabber.webservices.FriendshipService; import awais.instagrabber.webservices.FriendshipRepository;
import awais.instagrabber.webservices.MediaService; import awais.instagrabber.webservices.MediaService;
import awais.instagrabber.webservices.NewsService; import awais.instagrabber.webservices.NewsService;
import awais.instagrabber.webservices.ServiceCallback; import awais.instagrabber.webservices.ServiceCallback;
@ -60,7 +60,7 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
private SwipeRefreshLayout root; private SwipeRefreshLayout root;
private boolean shouldRefresh = true; private boolean shouldRefresh = true;
private NotificationViewModel notificationViewModel; private NotificationViewModel notificationViewModel;
private FriendshipService friendshipService; private FriendshipRepository friendshipRepository;
private MediaService mediaService; private MediaService mediaService;
private NewsService newsService; private NewsService newsService;
private String csrfToken, deviceUuid; private String csrfToken, deviceUuid;
@ -168,7 +168,7 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
break; break;
case 1: case 1:
if (model.getType() == NotificationType.REQUEST) { if (model.getType() == NotificationType.REQUEST) {
friendshipService.approve( friendshipRepository.approve(
csrfToken, csrfToken,
userId, userId,
deviceUuid, deviceUuid,
@ -189,7 +189,7 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
clickListener.onPreviewClick(model); clickListener.onPreviewClick(model);
break; break;
case 2: case 2:
friendshipService.ignore( friendshipRepository.ignore(
csrfToken, csrfToken,
userId, userId,
deviceUuid, deviceUuid,
@ -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);
friendshipService = FriendshipService.INSTANCE; friendshipRepository = FriendshipRepository.INSTANCE;
mediaService = MediaService.INSTANCE; mediaService = MediaService.INSTANCE;
newsService = NewsService.getInstance(); newsService = NewsService.getInstance();
} }

View File

@ -92,7 +92,7 @@ import awais.instagrabber.viewmodels.HighlightsViewModel;
import awais.instagrabber.viewmodels.ProfileFragmentViewModel; import awais.instagrabber.viewmodels.ProfileFragmentViewModel;
import awais.instagrabber.viewmodels.ProfileFragmentViewModelFactory; import awais.instagrabber.viewmodels.ProfileFragmentViewModelFactory;
import awais.instagrabber.webservices.DirectMessagesService; import awais.instagrabber.webservices.DirectMessagesService;
import awais.instagrabber.webservices.FriendshipService; import awais.instagrabber.webservices.FriendshipRepository;
import awais.instagrabber.webservices.GraphQLService; import awais.instagrabber.webservices.GraphQLService;
import awais.instagrabber.webservices.MediaService; import awais.instagrabber.webservices.MediaService;
import awais.instagrabber.webservices.ServiceCallback; import awais.instagrabber.webservices.ServiceCallback;
@ -118,7 +118,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
private User profileModel; private User profileModel;
private ActionMode actionMode; private ActionMode actionMode;
private Handler usernameSettingHandler; private Handler usernameSettingHandler;
private FriendshipService friendshipService; private FriendshipRepository friendshipRepository;
private StoriesService storiesService; private StoriesService storiesService;
private MediaService mediaService; private MediaService mediaService;
private UserRepository userRepository; private UserRepository userRepository;
@ -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();
friendshipService = isLoggedIn ? FriendshipService.INSTANCE : null; friendshipRepository = isLoggedIn ? FriendshipRepository.INSTANCE : 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;
@ -453,7 +453,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
if (item.getItemId() == R.id.restrict) { if (item.getItemId() == R.id.restrict) {
if (!isLoggedIn) return false; if (!isLoggedIn) return false;
final String action = profileModel.getFriendshipStatus().isRestricted() ? "Unrestrict" : "Restrict"; final String action = profileModel.getFriendshipStatus().isRestricted() ? "Unrestrict" : "Restrict";
friendshipService.toggleRestrict( friendshipRepository.toggleRestrict(
csrfToken, csrfToken,
deviceUuid, deviceUuid,
profileModel.getPk(), profileModel.getPk(),
@ -472,7 +472,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
if (item.getItemId() == R.id.block) { if (item.getItemId() == R.id.block) {
if (!isLoggedIn) return false; if (!isLoggedIn) return false;
// changeCb // changeCb
friendshipService.changeBlock( friendshipRepository.changeBlock(
csrfToken, csrfToken,
myId, myId,
deviceUuid, deviceUuid,
@ -499,7 +499,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
if (item.getItemId() == R.id.mute_stories) { if (item.getItemId() == R.id.mute_stories) {
if (!isLoggedIn) return false; if (!isLoggedIn) return false;
final String action = profileModel.getFriendshipStatus().isMutingReel() ? "Unmute stories" : "Mute stories"; final String action = profileModel.getFriendshipStatus().isMutingReel() ? "Unmute stories" : "Mute stories";
friendshipService.changeMute( friendshipRepository.changeMute(
csrfToken, csrfToken,
myId, myId,
deviceUuid, deviceUuid,
@ -519,7 +519,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
if (item.getItemId() == R.id.mute_posts) { if (item.getItemId() == R.id.mute_posts) {
if (!isLoggedIn) return false; if (!isLoggedIn) return false;
final String action = profileModel.getFriendshipStatus().getMuting() ? "Unmute stories" : "Mute stories"; final String action = profileModel.getFriendshipStatus().getMuting() ? "Unmute stories" : "Mute stories";
friendshipService.changeMute( friendshipRepository.changeMute(
csrfToken, csrfToken,
myId, myId,
deviceUuid, deviceUuid,
@ -538,7 +538,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
} }
if (item.getItemId() == R.id.remove_follower) { if (item.getItemId() == R.id.remove_follower) {
if (!isLoggedIn) return false; if (!isLoggedIn) return false;
friendshipService.removeFollower( friendshipRepository.removeFollower(
csrfToken, csrfToken,
myId, myId,
deviceUuid, deviceUuid,
@ -1085,7 +1085,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
new AlertDialog.Builder(context) new AlertDialog.Builder(context)
.setTitle(R.string.priv_acc) .setTitle(R.string.priv_acc)
.setMessage(R.string.priv_acc_confirm) .setMessage(R.string.priv_acc_confirm)
.setPositiveButton(R.string.confirm, (d, w) -> friendshipService.unfollow( .setPositiveButton(R.string.confirm, (d, w) -> friendshipRepository.unfollow(
csrfToken, csrfToken,
myId, myId,
deviceUuid, deviceUuid,
@ -1101,7 +1101,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.show(); .show();
} else if (profileModel.getFriendshipStatus().getFollowing() || profileModel.getFriendshipStatus().getOutgoingRequest()) { } else if (profileModel.getFriendshipStatus().getFollowing() || profileModel.getFriendshipStatus().getOutgoingRequest()) {
friendshipService.unfollow( friendshipRepository.unfollow(
csrfToken, csrfToken,
myId, myId,
deviceUuid, deviceUuid,
@ -1115,7 +1115,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
}), Dispatchers.getIO()) }), Dispatchers.getIO())
); );
} else { } else {
friendshipService.follow( friendshipRepository.follow(
csrfToken, csrfToken,
myId, myId,
deviceUuid, deviceUuid,

View File

@ -31,7 +31,7 @@ import awais.instagrabber.utils.MediaUtils.VideoInfo
import awais.instagrabber.utils.TextUtils.isEmpty import awais.instagrabber.utils.TextUtils.isEmpty
import awais.instagrabber.utils.extensions.TAG import awais.instagrabber.utils.extensions.TAG
import awais.instagrabber.webservices.DirectMessagesService import awais.instagrabber.webservices.DirectMessagesService
import awais.instagrabber.webservices.FriendshipService import awais.instagrabber.webservices.FriendshipRepository
import awais.instagrabber.webservices.MediaService import awais.instagrabber.webservices.MediaService
import com.google.common.collect.ImmutableList import com.google.common.collect.ImmutableList
import com.google.common.collect.Iterables import com.google.common.collect.Iterables
@ -1151,7 +1151,7 @@ class ThreadManager(
val data = MutableLiveData<Resource<Any?>>() val data = MutableLiveData<Resource<Any?>>()
scope.launch(Dispatchers.IO) { scope.launch(Dispatchers.IO) {
try { try {
FriendshipService.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 +1165,7 @@ class ThreadManager(
val data = MutableLiveData<Resource<Any?>>() val data = MutableLiveData<Resource<Any?>>()
scope.launch(Dispatchers.IO) { scope.launch(Dispatchers.IO) {
try { try {
FriendshipService.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 +1179,7 @@ class ThreadManager(
val data = MutableLiveData<Resource<Any?>>() val data = MutableLiveData<Resource<Any?>>()
scope.launch(Dispatchers.IO) { scope.launch(Dispatchers.IO) {
try { try {
FriendshipService.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 +1193,7 @@ class ThreadManager(
val data = MutableLiveData<Resource<Any?>>() val data = MutableLiveData<Resource<Any?>>()
scope.launch(Dispatchers.IO) { scope.launch(Dispatchers.IO) {
try { try {
FriendshipService.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)

View File

@ -4,7 +4,7 @@ import awais.instagrabber.repositories.responses.FriendshipChangeResponse
import awais.instagrabber.repositories.responses.FriendshipRestrictResponse import awais.instagrabber.repositories.responses.FriendshipRestrictResponse
import retrofit2.http.* import retrofit2.http.*
interface FriendshipRepository { interface FriendshipService {
@FormUrlEncoded @FormUrlEncoded
@POST("/api/v1/friendships/{action}/{id}/") @POST("/api/v1/friendships/{action}/{id}/")
suspend fun change( suspend fun change(

View File

@ -1,7 +1,7 @@
package awais.instagrabber.webservices package awais.instagrabber.webservices
import awais.instagrabber.models.FollowModel import awais.instagrabber.models.FollowModel
import awais.instagrabber.repositories.FriendshipRepository import awais.instagrabber.repositories.FriendshipService
import awais.instagrabber.repositories.responses.FriendshipChangeResponse import awais.instagrabber.repositories.responses.FriendshipChangeResponse
import awais.instagrabber.repositories.responses.FriendshipListFetchResponse import awais.instagrabber.repositories.responses.FriendshipListFetchResponse
import awais.instagrabber.repositories.responses.FriendshipRestrictResponse import awais.instagrabber.repositories.responses.FriendshipRestrictResponse
@ -11,8 +11,8 @@ import org.json.JSONArray
import org.json.JSONException import org.json.JSONException
import org.json.JSONObject import org.json.JSONObject
object FriendshipService { object FriendshipRepository {
private val repository: FriendshipRepository = retrofit.create(FriendshipRepository::class.java) private val service: FriendshipService = retrofit.create(FriendshipService::class.java)
suspend fun follow( suspend fun follow(
csrfToken: String, csrfToken: String,
@ -50,7 +50,7 @@ object FriendshipService {
"target_user_id" to targetUserId.toString(), "target_user_id" to targetUserId.toString(),
) )
val action = if (restrict) "restrict" else "unrestrict" val action = if (restrict) "restrict" else "unrestrict"
return repository.toggleRestrict(action, form) return service.toggleRestrict(action, form)
} }
suspend fun approve( suspend fun approve(
@ -89,7 +89,7 @@ object FriendshipService {
"user_id" to targetUserId, "user_id" to targetUserId,
) )
val signedForm = Utils.sign(form) val signedForm = Utils.sign(form)
return repository.change(action, targetUserId, signedForm) return service.change(action, targetUserId, signedForm)
} }
suspend fun changeMute( suspend fun changeMute(
@ -106,7 +106,7 @@ object FriendshipService {
"_uuid" to deviceUuid, "_uuid" to deviceUuid,
(if (story) "target_reel_author_id" else "target_posts_author_id") to targetUserId.toString(), (if (story) "target_reel_author_id" else "target_posts_author_id") to targetUserId.toString(),
) )
return repository.changeMute( return service.changeMute(
if (unmute) "unmute_posts_or_story_from_follow" else "mute_posts_or_story_from_follow", if (unmute) "unmute_posts_or_story_from_follow" else "mute_posts_or_story_from_follow",
form form
) )
@ -118,7 +118,7 @@ object FriendshipService {
maxId: String?, maxId: String?,
): FriendshipListFetchResponse { ): FriendshipListFetchResponse {
val queryMap = if (maxId != null) mapOf("max_id" to maxId) else emptyMap() val queryMap = if (maxId != null) mapOf("max_id" to maxId) else emptyMap()
val response = repository.getList(targetUserId, if (follower) "followers" else "following", queryMap) val response = service.getList(targetUserId, if (follower) "followers" else "following", queryMap)
return parseListResponse(response) return parseListResponse(response)
} }