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

Interchange GraphQLService and GraphQLRepository names.

This commit is contained in:
Ammar Githam 2021-06-12 12:34:50 +09:00
parent 2a0295e325
commit 69b685ae0d
12 changed files with 53 additions and 53 deletions

View File

@ -58,7 +58,7 @@ import awais.instagrabber.utils.TextUtils.shortcodeToId
import awais.instagrabber.utils.emoji.EmojiParser import awais.instagrabber.utils.emoji.EmojiParser
import awais.instagrabber.viewmodels.AppStateViewModel import awais.instagrabber.viewmodels.AppStateViewModel
import awais.instagrabber.viewmodels.DirectInboxViewModel import awais.instagrabber.viewmodels.DirectInboxViewModel
import awais.instagrabber.webservices.GraphQLService import awais.instagrabber.webservices.GraphQLRepository
import awais.instagrabber.webservices.MediaRepository import awais.instagrabber.webservices.MediaRepository
import com.google.android.material.appbar.AppBarLayout import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.appbar.AppBarLayout.ScrollingViewBehavior import com.google.android.material.appbar.AppBarLayout.ScrollingViewBehavior
@ -638,7 +638,7 @@ class MainActivity : BaseLanguageActivity(), FragmentManager.OnBackStackChangedL
alertDialog.show() alertDialog.show()
lifecycleScope.launch(Dispatchers.IO) { lifecycleScope.launch(Dispatchers.IO) {
try { try {
val media = if (isLoggedIn) mediaRepository.fetch(shortcodeToId(shortCode)) else GraphQLService.fetchPost(shortCode) val media = if (isLoggedIn) mediaRepository.fetch(shortcodeToId(shortCode)) else GraphQLRepository.fetchPost(shortCode)
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
if (media == null) { if (media == null) {
Toast.makeText(applicationContext, R.string.post_not_found, Toast.LENGTH_SHORT).show() Toast.makeText(applicationContext, R.string.post_not_found, Toast.LENGTH_SHORT).show()

View File

@ -8,14 +8,14 @@ import awais.instagrabber.repositories.responses.Hashtag;
import awais.instagrabber.repositories.responses.Media; import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.PostsFetchResponse; import awais.instagrabber.repositories.responses.PostsFetchResponse;
import awais.instagrabber.utils.CoroutineUtilsKt; import awais.instagrabber.utils.CoroutineUtilsKt;
import awais.instagrabber.webservices.GraphQLService; import awais.instagrabber.webservices.GraphQLRepository;
import awais.instagrabber.webservices.ServiceCallback; import awais.instagrabber.webservices.ServiceCallback;
import awais.instagrabber.webservices.TagsService; import awais.instagrabber.webservices.TagsService;
import kotlinx.coroutines.Dispatchers; import kotlinx.coroutines.Dispatchers;
public class HashtagPostFetchService implements PostFetcher.PostFetchService { public class HashtagPostFetchService implements PostFetcher.PostFetchService {
private final TagsService tagsService; private final TagsService tagsService;
private final GraphQLService graphQLService; private final GraphQLRepository graphQLRepository;
private final Hashtag hashtagModel; private final Hashtag hashtagModel;
private String nextMaxId; private String nextMaxId;
private boolean moreAvailable; private boolean moreAvailable;
@ -25,7 +25,7 @@ public class HashtagPostFetchService implements PostFetcher.PostFetchService {
this.hashtagModel = hashtagModel; this.hashtagModel = hashtagModel;
this.isLoggedIn = isLoggedIn; this.isLoggedIn = isLoggedIn;
tagsService = isLoggedIn ? TagsService.getInstance() : null; tagsService = isLoggedIn ? TagsService.getInstance() : null;
graphQLService = isLoggedIn ? null : GraphQLService.INSTANCE; graphQLRepository = isLoggedIn ? null : GraphQLRepository.INSTANCE;
} }
@Override @Override
@ -50,7 +50,7 @@ public class HashtagPostFetchService implements PostFetcher.PostFetchService {
} }
}; };
if (isLoggedIn) tagsService.fetchPosts(hashtagModel.getName().toLowerCase(), nextMaxId, cb); if (isLoggedIn) tagsService.fetchPosts(hashtagModel.getName().toLowerCase(), nextMaxId, cb);
else graphQLService.fetchHashtagPosts( else graphQLRepository.fetchHashtagPosts(
hashtagModel.getName().toLowerCase(), hashtagModel.getName().toLowerCase(),
nextMaxId, nextMaxId,
CoroutineUtilsKt.getContinuation((postsFetchResponse, throwable) -> { CoroutineUtilsKt.getContinuation((postsFetchResponse, throwable) -> {

View File

@ -8,14 +8,14 @@ import awais.instagrabber.repositories.responses.Location;
import awais.instagrabber.repositories.responses.Media; import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.PostsFetchResponse; import awais.instagrabber.repositories.responses.PostsFetchResponse;
import awais.instagrabber.utils.CoroutineUtilsKt; import awais.instagrabber.utils.CoroutineUtilsKt;
import awais.instagrabber.webservices.GraphQLService; import awais.instagrabber.webservices.GraphQLRepository;
import awais.instagrabber.webservices.LocationService; import awais.instagrabber.webservices.LocationService;
import awais.instagrabber.webservices.ServiceCallback; import awais.instagrabber.webservices.ServiceCallback;
import kotlinx.coroutines.Dispatchers; import kotlinx.coroutines.Dispatchers;
public class LocationPostFetchService implements PostFetcher.PostFetchService { public class LocationPostFetchService implements PostFetcher.PostFetchService {
private final LocationService locationService; private final LocationService locationService;
private final GraphQLService graphQLService; private final GraphQLRepository graphQLRepository;
private final Location locationModel; private final Location locationModel;
private String nextMaxId; private String nextMaxId;
private boolean moreAvailable; private boolean moreAvailable;
@ -25,7 +25,7 @@ public class LocationPostFetchService implements PostFetcher.PostFetchService {
this.locationModel = locationModel; this.locationModel = locationModel;
this.isLoggedIn = isLoggedIn; this.isLoggedIn = isLoggedIn;
locationService = isLoggedIn ? LocationService.getInstance() : null; locationService = isLoggedIn ? LocationService.getInstance() : null;
graphQLService = isLoggedIn ? null : GraphQLService.INSTANCE; graphQLRepository = isLoggedIn ? null : GraphQLRepository.INSTANCE;
} }
@Override @Override
@ -50,7 +50,7 @@ public class LocationPostFetchService implements PostFetcher.PostFetchService {
} }
}; };
if (isLoggedIn) locationService.fetchPosts(locationModel.getPk(), nextMaxId, cb); if (isLoggedIn) locationService.fetchPosts(locationModel.getPk(), nextMaxId, cb);
else graphQLService.fetchLocationPosts( else graphQLRepository.fetchLocationPosts(
locationModel.getPk(), locationModel.getPk(),
nextMaxId, nextMaxId,
CoroutineUtilsKt.getContinuation((postsFetchResponse, throwable) -> { CoroutineUtilsKt.getContinuation((postsFetchResponse, throwable) -> {

View File

@ -8,7 +8,7 @@ import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.PostsFetchResponse; import awais.instagrabber.repositories.responses.PostsFetchResponse;
import awais.instagrabber.repositories.responses.User; import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.utils.CoroutineUtilsKt; import awais.instagrabber.utils.CoroutineUtilsKt;
import awais.instagrabber.webservices.GraphQLService; import awais.instagrabber.webservices.GraphQLRepository;
import awais.instagrabber.webservices.ProfileService; import awais.instagrabber.webservices.ProfileService;
import awais.instagrabber.webservices.ServiceCallback; import awais.instagrabber.webservices.ServiceCallback;
import kotlinx.coroutines.Dispatchers; import kotlinx.coroutines.Dispatchers;
@ -16,7 +16,7 @@ import kotlinx.coroutines.Dispatchers;
public class ProfilePostFetchService implements PostFetcher.PostFetchService { public class ProfilePostFetchService implements PostFetcher.PostFetchService {
private static final String TAG = "ProfilePostFetchService"; private static final String TAG = "ProfilePostFetchService";
private final ProfileService profileService; private final ProfileService profileService;
private final GraphQLService graphQLService; private final GraphQLRepository graphQLRepository;
private final User profileModel; private final User profileModel;
private final boolean isLoggedIn; private final boolean isLoggedIn;
private String nextMaxId; private String nextMaxId;
@ -25,7 +25,7 @@ public class ProfilePostFetchService implements PostFetcher.PostFetchService {
public ProfilePostFetchService(final User profileModel, final boolean isLoggedIn) { public ProfilePostFetchService(final User profileModel, final boolean isLoggedIn) {
this.profileModel = profileModel; this.profileModel = profileModel;
this.isLoggedIn = isLoggedIn; this.isLoggedIn = isLoggedIn;
graphQLService = isLoggedIn ? null : GraphQLService.INSTANCE; graphQLRepository = isLoggedIn ? null : GraphQLRepository.INSTANCE;
profileService = isLoggedIn ? ProfileService.getInstance() : null; profileService = isLoggedIn ? ProfileService.getInstance() : null;
} }
@ -51,7 +51,7 @@ public class ProfilePostFetchService implements PostFetcher.PostFetchService {
} }
}; };
if (isLoggedIn) profileService.fetchPosts(profileModel.getPk(), nextMaxId, cb); if (isLoggedIn) profileService.fetchPosts(profileModel.getPk(), nextMaxId, cb);
else graphQLService.fetchProfilePosts( else graphQLRepository.fetchProfilePosts(
profileModel.getPk(), profileModel.getPk(),
30, 30,
nextMaxId, nextMaxId,

View File

@ -8,14 +8,14 @@ import awais.instagrabber.models.enums.PostItemType;
import awais.instagrabber.repositories.responses.Media; import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.PostsFetchResponse; import awais.instagrabber.repositories.responses.PostsFetchResponse;
import awais.instagrabber.utils.CoroutineUtilsKt; import awais.instagrabber.utils.CoroutineUtilsKt;
import awais.instagrabber.webservices.GraphQLService; import awais.instagrabber.webservices.GraphQLRepository;
import awais.instagrabber.webservices.ProfileService; import awais.instagrabber.webservices.ProfileService;
import awais.instagrabber.webservices.ServiceCallback; import awais.instagrabber.webservices.ServiceCallback;
import kotlinx.coroutines.Dispatchers; import kotlinx.coroutines.Dispatchers;
public class SavedPostFetchService implements PostFetcher.PostFetchService { public class SavedPostFetchService implements PostFetcher.PostFetchService {
private final ProfileService profileService; private final ProfileService profileService;
private final GraphQLService graphQLService; private final GraphQLRepository graphQLRepository;
private final long profileId; private final long profileId;
private final PostItemType type; private final PostItemType type;
private final boolean isLoggedIn; private final boolean isLoggedIn;
@ -29,7 +29,7 @@ public class SavedPostFetchService implements PostFetcher.PostFetchService {
this.type = type; this.type = type;
this.isLoggedIn = isLoggedIn; this.isLoggedIn = isLoggedIn;
this.collectionId = collectionId; this.collectionId = collectionId;
graphQLService = isLoggedIn ? null : GraphQLService.INSTANCE; graphQLRepository = isLoggedIn ? null : GraphQLRepository.INSTANCE;
profileService = isLoggedIn ? ProfileService.getInstance() : null; profileService = isLoggedIn ? ProfileService.getInstance() : null;
} }
@ -60,7 +60,7 @@ public class SavedPostFetchService implements PostFetcher.PostFetchService {
break; break;
case TAGGED: case TAGGED:
if (isLoggedIn) profileService.fetchTagged(profileId, nextMaxId, callback); if (isLoggedIn) profileService.fetchTagged(profileId, nextMaxId, callback);
else graphQLService.fetchTaggedPosts( else graphQLRepository.fetchTaggedPosts(
profileId, profileId,
30, 30,
nextMaxId, nextMaxId,

View File

@ -67,7 +67,7 @@ import awais.instagrabber.utils.CoroutineUtilsKt;
import awais.instagrabber.utils.DownloadUtils; import awais.instagrabber.utils.DownloadUtils;
import awais.instagrabber.utils.TextUtils; import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.utils.Utils; import awais.instagrabber.utils.Utils;
import awais.instagrabber.webservices.GraphQLService; import awais.instagrabber.webservices.GraphQLRepository;
import awais.instagrabber.webservices.ServiceCallback; import awais.instagrabber.webservices.ServiceCallback;
import awais.instagrabber.webservices.StoriesRepository; import awais.instagrabber.webservices.StoriesRepository;
import awais.instagrabber.webservices.TagsService; import awais.instagrabber.webservices.TagsService;
@ -96,7 +96,7 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
private StoriesRepository storiesRepository; private StoriesRepository storiesRepository;
private boolean isLoggedIn; private boolean isLoggedIn;
private TagsService tagsService; private TagsService tagsService;
private GraphQLService graphQLService; private GraphQLRepository graphQLRepository;
private boolean storiesFetching; private boolean storiesFetching;
private Set<Media> selectedFeedModels; private Set<Media> selectedFeedModels;
private Media downloadFeedModel; private Media downloadFeedModel;
@ -218,7 +218,7 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
if (TextUtils.isEmpty(user.getUsername())) { if (TextUtils.isEmpty(user.getUsername())) {
// this only happens for anons // this only happens for anons
opening = true; opening = true;
graphQLService.fetchPost(feedModel.getCode(), CoroutineUtilsKt.getContinuation((media, throwable) -> { graphQLRepository.fetchPost(feedModel.getCode(), CoroutineUtilsKt.getContinuation((media, throwable) -> {
opening = false; opening = false;
if (throwable != null) { if (throwable != null) {
Log.e(TAG, "Error", throwable); Log.e(TAG, "Error", throwable);
@ -299,7 +299,7 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) > 0; isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) > 0;
tagsService = isLoggedIn ? TagsService.getInstance() : null; tagsService = isLoggedIn ? TagsService.getInstance() : null;
storiesRepository = isLoggedIn ? StoriesRepository.Companion.getInstance() : null; storiesRepository = isLoggedIn ? StoriesRepository.Companion.getInstance() : null;
graphQLService = isLoggedIn ? null : GraphQLService.INSTANCE; graphQLRepository = isLoggedIn ? null : GraphQLRepository.INSTANCE;
setHasOptionsMenu(true); setHasOptionsMenu(true);
} }
@ -380,7 +380,7 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
private void fetchHashtagModel() { private void fetchHashtagModel() {
binding.swipeRefreshLayout.setRefreshing(true); binding.swipeRefreshLayout.setRefreshing(true);
if (isLoggedIn) tagsService.fetch(hashtag, cb); if (isLoggedIn) tagsService.fetch(hashtag, cb);
else graphQLService.fetchTag(hashtag, CoroutineUtilsKt.getContinuation((hashtag1, throwable) -> { else graphQLRepository.fetchTag(hashtag, CoroutineUtilsKt.getContinuation((hashtag1, throwable) -> {
if (throwable != null) { if (throwable != null) {
cb.onFailure(throwable); cb.onFailure(throwable);
return; return;

View File

@ -30,7 +30,7 @@ import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.CookieUtils; import awais.instagrabber.utils.CookieUtils;
import awais.instagrabber.utils.CoroutineUtilsKt; import awais.instagrabber.utils.CoroutineUtilsKt;
import awais.instagrabber.utils.TextUtils; import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.webservices.GraphQLService; import awais.instagrabber.webservices.GraphQLRepository;
import awais.instagrabber.webservices.MediaRepository; import awais.instagrabber.webservices.MediaRepository;
import awais.instagrabber.webservices.ServiceCallback; import awais.instagrabber.webservices.ServiceCallback;
import kotlinx.coroutines.Dispatchers; import kotlinx.coroutines.Dispatchers;
@ -43,7 +43,7 @@ public final class LikesViewerFragment extends BottomSheetDialogFragment impleme
private FragmentLikesBinding binding; private FragmentLikesBinding binding;
private RecyclerLazyLoader lazyLoader; private RecyclerLazyLoader lazyLoader;
private MediaRepository mediaRepository; private MediaRepository mediaRepository;
private GraphQLService graphQLService; private GraphQLRepository graphQLRepository;
private boolean isLoggedIn; private boolean isLoggedIn;
private String postId, endCursor; private String postId, endCursor;
private boolean isComment; private boolean isComment;
@ -113,7 +113,7 @@ public final class LikesViewerFragment extends BottomSheetDialogFragment impleme
final String csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie); final String csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie);
if (csrfToken == null) return; if (csrfToken == null) return;
mediaRepository = isLoggedIn ? MediaRepository.Companion.getInstance() : null; mediaRepository = isLoggedIn ? MediaRepository.Companion.getInstance() : null;
graphQLService = isLoggedIn ? null : GraphQLService.INSTANCE; graphQLRepository = isLoggedIn ? null : GraphQLRepository.INSTANCE;
// setHasOptionsMenu(true); // setHasOptionsMenu(true);
} }
@ -135,7 +135,7 @@ public final class LikesViewerFragment extends BottomSheetDialogFragment impleme
public void onRefresh() { public void onRefresh() {
if (isComment && !isLoggedIn) { if (isComment && !isLoggedIn) {
lazyLoader.resetState(); lazyLoader.resetState();
graphQLService.fetchCommentLikers( graphQLRepository.fetchCommentLikers(
postId, postId,
null, null,
CoroutineUtilsKt.getContinuation((response, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> { CoroutineUtilsKt.getContinuation((response, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
@ -175,7 +175,7 @@ public final class LikesViewerFragment extends BottomSheetDialogFragment impleme
binding.rvLikes.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.HORIZONTAL)); binding.rvLikes.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.HORIZONTAL));
lazyLoader = new RecyclerLazyLoader(layoutManager, (page, totalItemsCount) -> { lazyLoader = new RecyclerLazyLoader(layoutManager, (page, totalItemsCount) -> {
if (!TextUtils.isEmpty(endCursor)) { if (!TextUtils.isEmpty(endCursor)) {
graphQLService.fetchCommentLikers( graphQLRepository.fetchCommentLikers(
postId, postId,
endCursor, endCursor,
CoroutineUtilsKt.getContinuation((response, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> { CoroutineUtilsKt.getContinuation((response, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {

View File

@ -63,7 +63,7 @@ import awais.instagrabber.utils.CoroutineUtilsKt;
import awais.instagrabber.utils.DownloadUtils; import awais.instagrabber.utils.DownloadUtils;
import awais.instagrabber.utils.TextUtils; import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.utils.Utils; import awais.instagrabber.utils.Utils;
import awais.instagrabber.webservices.GraphQLService; import awais.instagrabber.webservices.GraphQLRepository;
import awais.instagrabber.webservices.LocationService; import awais.instagrabber.webservices.LocationService;
import awais.instagrabber.webservices.ServiceCallback; import awais.instagrabber.webservices.ServiceCallback;
import awais.instagrabber.webservices.StoriesRepository; import awais.instagrabber.webservices.StoriesRepository;
@ -88,7 +88,7 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
private Location locationModel; private Location locationModel;
private ActionMode actionMode; private ActionMode actionMode;
private StoriesRepository storiesRepository; private StoriesRepository storiesRepository;
private GraphQLService graphQLService; private GraphQLRepository graphQLRepository;
private LocationService locationService; private LocationService locationService;
private boolean isLoggedIn; private boolean isLoggedIn;
private boolean storiesFetching; private boolean storiesFetching;
@ -208,7 +208,7 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
if (user == null) return; if (user == null) return;
if (TextUtils.isEmpty(user.getUsername())) { if (TextUtils.isEmpty(user.getUsername())) {
opening = true; opening = true;
graphQLService.fetchPost( graphQLRepository.fetchPost(
feedModel.getCode(), feedModel.getCode(),
CoroutineUtilsKt.getContinuation((media, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> { CoroutineUtilsKt.getContinuation((media, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
opening = false; opening = false;
@ -292,7 +292,7 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) > 0; isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) > 0;
locationService = isLoggedIn ? LocationService.getInstance() : null; locationService = isLoggedIn ? LocationService.getInstance() : null;
storiesRepository = StoriesRepository.Companion.getInstance(); storiesRepository = StoriesRepository.Companion.getInstance();
graphQLService = isLoggedIn ? null : GraphQLService.INSTANCE; graphQLRepository = isLoggedIn ? null : GraphQLRepository.INSTANCE;
setHasOptionsMenu(true); setHasOptionsMenu(true);
} }
@ -400,7 +400,7 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
private void fetchLocationModel() { private void fetchLocationModel() {
binding.swipeRefreshLayout.setRefreshing(true); binding.swipeRefreshLayout.setRefreshing(true);
if (isLoggedIn) locationService.fetch(locationId, cb); if (isLoggedIn) locationService.fetch(locationId, cb);
else graphQLService.fetchLocation( else graphQLRepository.fetchLocation(
locationId, locationId,
CoroutineUtilsKt.getContinuation((location, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> { CoroutineUtilsKt.getContinuation((location, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
if (throwable != null) { if (throwable != null) {

View File

@ -93,7 +93,7 @@ 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.FriendshipRepository; import awais.instagrabber.webservices.FriendshipRepository;
import awais.instagrabber.webservices.GraphQLService; import awais.instagrabber.webservices.GraphQLRepository;
import awais.instagrabber.webservices.MediaRepository; import awais.instagrabber.webservices.MediaRepository;
import awais.instagrabber.webservices.ServiceCallback; import awais.instagrabber.webservices.ServiceCallback;
import awais.instagrabber.webservices.StoriesRepository; import awais.instagrabber.webservices.StoriesRepository;
@ -122,7 +122,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
private StoriesRepository storiesRepository; private StoriesRepository storiesRepository;
private MediaRepository mediaRepository; private MediaRepository mediaRepository;
private UserRepository userRepository; private UserRepository userRepository;
private GraphQLService graphQLService; private GraphQLRepository graphQLRepository;
private DirectMessagesService directMessagesService; private DirectMessagesService directMessagesService;
private boolean shouldRefresh = true; private boolean shouldRefresh = true;
private boolean hasStories = false; private boolean hasStories = false;
@ -338,7 +338,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
storiesRepository = isLoggedIn ? StoriesRepository.Companion.getInstance() : null; storiesRepository = isLoggedIn ? StoriesRepository.Companion.getInstance() : null;
mediaRepository = isLoggedIn ? MediaRepository.Companion.getInstance() : null; mediaRepository = isLoggedIn ? MediaRepository.Companion.getInstance() : null;
userRepository = isLoggedIn ? UserRepository.Companion.getInstance() : null; userRepository = isLoggedIn ? UserRepository.Companion.getInstance() : null;
graphQLService = isLoggedIn ? null : GraphQLService.INSTANCE; graphQLRepository = isLoggedIn ? null : GraphQLRepository.INSTANCE;
final Context context = getContext(); final Context context = getContext();
if (context == null) return; if (context == null) return;
accountRepository = AccountRepository.getInstance(AccountDataSource.getInstance(context)); accountRepository = AccountRepository.getInstance(AccountDataSource.getInstance(context));
@ -669,7 +669,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
); );
return; return;
} }
graphQLService.fetchUser( graphQLRepository.fetchUser(
usernameTemp, usernameTemp,
CoroutineUtilsKt.getContinuation((user, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> { CoroutineUtilsKt.getContinuation((user, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
if (throwable != null) { if (throwable != null) {

View File

@ -4,7 +4,7 @@ import retrofit2.http.GET
import retrofit2.http.Path import retrofit2.http.Path
import retrofit2.http.QueryMap import retrofit2.http.QueryMap
interface GraphQLRepository { interface GraphQLService {
@GET("/graphql/query/") @GET("/graphql/query/")
suspend fun fetch(@QueryMap(encoded = true) queryParams: Map<String, String>): String suspend fun fetch(@QueryMap(encoded = true) queryParams: Map<String, String>): String

View File

@ -33,7 +33,7 @@ import awais.instagrabber.utils.CookieUtils;
import awais.instagrabber.utils.CoroutineUtilsKt; import awais.instagrabber.utils.CoroutineUtilsKt;
import awais.instagrabber.utils.Utils; import awais.instagrabber.utils.Utils;
import awais.instagrabber.webservices.CommentService; import awais.instagrabber.webservices.CommentService;
import awais.instagrabber.webservices.GraphQLService; import awais.instagrabber.webservices.GraphQLRepository;
import awais.instagrabber.webservices.ServiceCallback; import awais.instagrabber.webservices.ServiceCallback;
import kotlin.coroutines.Continuation; import kotlin.coroutines.Continuation;
import kotlinx.coroutines.Dispatchers; import kotlinx.coroutines.Dispatchers;
@ -48,7 +48,7 @@ public class CommentsViewerViewModel extends ViewModel {
private final MutableLiveData<Resource<List<Comment>>> rootList = new MutableLiveData<>(); private final MutableLiveData<Resource<List<Comment>>> rootList = new MutableLiveData<>();
private final MutableLiveData<Integer> rootCount = new MutableLiveData<>(0); private final MutableLiveData<Integer> rootCount = new MutableLiveData<>(0);
private final MutableLiveData<Resource<List<Comment>>> replyList = new MutableLiveData<>(); private final MutableLiveData<Resource<List<Comment>>> replyList = new MutableLiveData<>();
private final GraphQLService graphQLService; private final GraphQLRepository graphQLRepository;
private String shortCode; private String shortCode;
private String postId; private String postId;
@ -121,7 +121,7 @@ public class CommentsViewerViewModel extends ViewModel {
}; };
public CommentsViewerViewModel() { public CommentsViewerViewModel() {
graphQLService = GraphQLService.INSTANCE; graphQLRepository = GraphQLRepository.INSTANCE;
final String cookie = settingsHelper.getString(Constants.COOKIE); final String cookie = settingsHelper.getString(Constants.COOKIE);
final String deviceUuid = Utils.settingsHelper.getString(Constants.DEVICE_UUID); final String deviceUuid = Utils.settingsHelper.getString(Constants.DEVICE_UUID);
final String csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie); final String csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie);
@ -173,7 +173,7 @@ public class CommentsViewerViewModel extends ViewModel {
commentService.fetchComments(postId, rootCursor, ccb); commentService.fetchComments(postId, rootCursor, ccb);
return; return;
} }
graphQLService.fetchComments( graphQLRepository.fetchComments(
shortCode, shortCode,
true, true,
rootCursor, rootCursor,
@ -202,7 +202,7 @@ public class CommentsViewerViewModel extends ViewModel {
commentService.fetchChildComments(postId, commentId, repliesCursor, rcb); commentService.fetchChildComments(postId, commentId, repliesCursor, rcb);
return; return;
} }
graphQLService.fetchComments(commentId, false, repliesCursor, enqueueRequest(false, commentId, rcb)); graphQLRepository.fetchComments(commentId, false, repliesCursor, enqueueRequest(false, commentId, rcb));
} }
private Continuation<String> enqueueRequest(final boolean root, private Continuation<String> enqueueRequest(final boolean root,

View File

@ -2,7 +2,7 @@ package awais.instagrabber.webservices
import android.util.Log import android.util.Log
import awais.instagrabber.models.enums.FollowingType import awais.instagrabber.models.enums.FollowingType
import awais.instagrabber.repositories.GraphQLRepository import awais.instagrabber.repositories.GraphQLService
import awais.instagrabber.repositories.responses.* import awais.instagrabber.repositories.responses.*
import awais.instagrabber.utils.Constants import awais.instagrabber.utils.Constants
import awais.instagrabber.utils.ResponseBodyUtils import awais.instagrabber.utils.ResponseBodyUtils
@ -12,8 +12,8 @@ import org.json.JSONException
import org.json.JSONObject import org.json.JSONObject
import java.util.* import java.util.*
object GraphQLService { object GraphQLRepository {
private val repository: GraphQLRepository = retrofitWeb.create(GraphQLRepository::class.java) private val service: GraphQLService = retrofitWeb.create(GraphQLService::class.java)
// TODO convert string response to a response class // TODO convert string response to a response class
private suspend fun fetch( private suspend fun fetch(
@ -27,7 +27,7 @@ object GraphQLService {
"query_hash" to queryHash, "query_hash" to queryHash,
"variables" to variables, "variables" to variables,
) )
val response = repository.fetch(queryMap) val response = service.fetch(queryMap)
return parsePostResponse(response, arg1, arg2, backup) return parsePostResponse(response, arg1, arg2, backup)
} }
@ -134,7 +134,7 @@ object GraphQLService {
"query_hash" to "5f0b1f6281e72053cbc07909c8d154ae", "query_hash" to "5f0b1f6281e72053cbc07909c8d154ae",
"variables" to "{\"comment_id\":\"" + commentId + "\"," + "\"first\":30," + "\"after\":\"" + (endCursor ?: "") + "\"}" "variables" to "{\"comment_id\":\"" + commentId + "\"," + "\"first\":30," + "\"after\":\"" + (endCursor ?: "") + "\"}"
) )
val response = repository.fetch(queryMap) val response = service.fetch(queryMap)
val body = JSONObject(response) val body = JSONObject(response)
val status = body.getString("status") val status = body.getString("status")
val data = body.getJSONObject("data").getJSONObject("comment").getJSONObject("edge_liked_by") val data = body.getJSONObject("data").getJSONObject("comment").getJSONObject("edge_liked_by")
@ -171,14 +171,14 @@ object GraphQLService {
"query_hash" to if (root) "bc3296d1ce80a24b1b6e40b1e72903f5" else "51fdd02b67508306ad4484ff574a0b62", "query_hash" to if (root) "bc3296d1ce80a24b1b6e40b1e72903f5" else "51fdd02b67508306ad4484ff574a0b62",
"variables" to JSONObject(variables).toString() "variables" to JSONObject(variables).toString()
) )
return repository.fetch(queryMap) return service.fetch(queryMap)
} }
// TODO convert string response to a response class // TODO convert string response to a response class
suspend fun fetchUser( suspend fun fetchUser(
username: String, username: String,
): User { ): User {
val response = repository.getUser(username) val response = service.getUser(username)
val body = JSONObject(response) val body = JSONObject(response)
val userJson = body.getJSONObject("graphql").getJSONObject(Constants.EXTRAS_USER) val userJson = body.getJSONObject("graphql").getJSONObject(Constants.EXTRAS_USER)
val isPrivate = userJson.getBoolean("is_private") val isPrivate = userJson.getBoolean("is_private")
@ -220,7 +220,7 @@ object GraphQLService {
suspend fun fetchPost( suspend fun fetchPost(
shortcode: String, shortcode: String,
): Media { ): Media {
val response = repository.getPost(shortcode) val response = service.getPost(shortcode)
val body = JSONObject(response) val body = JSONObject(response)
val media = body.getJSONObject("graphql").getJSONObject("shortcode_media") val media = body.getJSONObject("graphql").getJSONObject("shortcode_media")
return ResponseBodyUtils.parseGraphQLItem(media, null) return ResponseBodyUtils.parseGraphQLItem(media, null)
@ -230,7 +230,7 @@ object GraphQLService {
suspend fun fetchTag( suspend fun fetchTag(
tag: String, tag: String,
): Hashtag { ): Hashtag {
val response = repository.getTag(tag) val response = service.getTag(tag)
val body = JSONObject(response) val body = JSONObject(response)
.getJSONObject("graphql") .getJSONObject("graphql")
.getJSONObject(Constants.EXTRAS_HASHTAG) .getJSONObject(Constants.EXTRAS_HASHTAG)
@ -247,7 +247,7 @@ object GraphQLService {
suspend fun fetchLocation( suspend fun fetchLocation(
locationId: Long, locationId: Long,
): Location { ): Location {
val response = repository.getLocation(locationId) val response = service.getLocation(locationId)
val body = JSONObject(response) val body = JSONObject(response)
.getJSONObject("graphql") .getJSONObject("graphql")
.getJSONObject(Constants.EXTRAS_LOCATION) .getJSONObject(Constants.EXTRAS_LOCATION)