1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-22 06:37:30 +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.CoroutineUtilsKt;
import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.webservices.FriendshipService;
import awais.instagrabber.webservices.FriendshipRepository;
import awais.instagrabber.webservices.ServiceCallback;
import kotlinx.coroutines.Dispatchers;
import thoughtbot.expandableadapter.ExpandableGroup;
@ -60,7 +60,7 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
private View.OnClickListener clickListener;
private FragmentFollowersViewerBinding binding;
private SwipeRefreshLayout root;
private FriendshipService friendshipService;
private FriendshipRepository friendshipRepository;
private AppCompatActivity fragmentActivity;
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 (result.isMoreAvailable()) {
endCursor = result.getNextMaxId();
friendshipService.getList(
friendshipRepository.getList(
false,
profileId,
endCursor,
@ -85,7 +85,7 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
);
} else if (followersModels.size() == 0) {
if (!isFollowersList) moreAvailable = false;
friendshipService.getList(
friendshipRepository.getList(
true,
profileId,
null,
@ -121,7 +121,7 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
if (isFollowersList) followModels.addAll(result.getItems());
if (result.isMoreAvailable()) {
endCursor = result.getNextMaxId();
friendshipService.getList(
friendshipRepository.getList(
true,
profileId,
endCursor,
@ -135,7 +135,7 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
);
} else if (followingModels.size() == 0) {
if (isFollowersList) moreAvailable = false;
friendshipService.getList(
friendshipRepository.getList(
false,
profileId,
null,
@ -167,7 +167,7 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
@Override
public void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
friendshipService = FriendshipService.INSTANCE;
friendshipRepository = FriendshipRepository.INSTANCE;
fragmentActivity = (AppCompatActivity) getActivity();
setHasOptionsMenu(true);
}
@ -289,7 +289,7 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
if (!TextUtils.isEmpty(endCursor) && !searching) {
binding.swipeRefreshLayout.setRefreshing(true);
layoutManager.setStackFromEnd(true);
friendshipService.getList(
friendshipRepository.getList(
isFollowersList,
profileId,
endCursor,
@ -308,7 +308,7 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
binding.rvFollow.setLayoutManager(layoutManager);
if (moreAvailable) {
binding.swipeRefreshLayout.setRefreshing(true);
friendshipService.getList(
friendshipRepository.getList(
isFollowersList,
profileId,
endCursor,
@ -335,7 +335,7 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
if (moreAvailable) {
binding.swipeRefreshLayout.setRefreshing(true);
Toast.makeText(getContext(), R.string.follower_start_compare, Toast.LENGTH_LONG).show();
friendshipService.getList(
friendshipRepository.getList(
isFollowersList,
profileId,
endCursor,
@ -351,7 +351,7 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
} else if (followersModels.size() == 0 || followingModels.size() == 0) {
binding.swipeRefreshLayout.setRefreshing(true);
Toast.makeText(getContext(), R.string.follower_start_compare, Toast.LENGTH_LONG).show();
friendshipService.getList(
friendshipRepository.getList(
!isFollowersList,
profileId,
null,

View File

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

View File

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

View File

@ -31,7 +31,7 @@ import awais.instagrabber.utils.MediaUtils.VideoInfo
import awais.instagrabber.utils.TextUtils.isEmpty
import awais.instagrabber.utils.extensions.TAG
import awais.instagrabber.webservices.DirectMessagesService
import awais.instagrabber.webservices.FriendshipService
import awais.instagrabber.webservices.FriendshipRepository
import awais.instagrabber.webservices.MediaService
import com.google.common.collect.ImmutableList
import com.google.common.collect.Iterables
@ -1151,7 +1151,7 @@ class ThreadManager(
val data = MutableLiveData<Resource<Any?>>()
scope.launch(Dispatchers.IO) {
try {
FriendshipService.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 +1165,7 @@ class ThreadManager(
val data = MutableLiveData<Resource<Any?>>()
scope.launch(Dispatchers.IO) {
try {
FriendshipService.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 +1179,7 @@ class ThreadManager(
val data = MutableLiveData<Resource<Any?>>()
scope.launch(Dispatchers.IO) {
try {
FriendshipService.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 +1193,7 @@ class ThreadManager(
val data = MutableLiveData<Resource<Any?>>()
scope.launch(Dispatchers.IO) {
try {
FriendshipService.toggleRestrict(csrfToken, deviceUuid, user.pk, false)
FriendshipRepository.toggleRestrict(csrfToken, deviceUuid, user.pk, false)
refreshChats(scope)
} catch (e: Exception) {
Log.e(TAG, "onFailure: ", e)

View File

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

View File

@ -1,7 +1,7 @@
package awais.instagrabber.webservices
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.FriendshipListFetchResponse
import awais.instagrabber.repositories.responses.FriendshipRestrictResponse
@ -11,8 +11,8 @@ import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject
object FriendshipService {
private val repository: FriendshipRepository = retrofit.create(FriendshipRepository::class.java)
object FriendshipRepository {
private val service: FriendshipService = retrofit.create(FriendshipService::class.java)
suspend fun follow(
csrfToken: String,
@ -50,7 +50,7 @@ object FriendshipService {
"target_user_id" to targetUserId.toString(),
)
val action = if (restrict) "restrict" else "unrestrict"
return repository.toggleRestrict(action, form)
return service.toggleRestrict(action, form)
}
suspend fun approve(
@ -89,7 +89,7 @@ object FriendshipService {
"user_id" to targetUserId,
)
val signedForm = Utils.sign(form)
return repository.change(action, targetUserId, signedForm)
return service.change(action, targetUserId, signedForm)
}
suspend fun changeMute(
@ -106,7 +106,7 @@ object FriendshipService {
"_uuid" to deviceUuid,
(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",
form
)
@ -118,7 +118,7 @@ object FriendshipService {
maxId: String?,
): FriendshipListFetchResponse {
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)
}