mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 06:37:30 +00:00
Interchange MediaService and MediaRepository names.
This commit is contained in:
parent
02cb1f5db5
commit
b2cbc18dbb
@ -59,7 +59,7 @@ 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.GraphQLService
|
||||||
import awais.instagrabber.webservices.MediaService
|
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
|
||||||
import com.google.android.material.appbar.CollapsingToolbarLayout
|
import com.google.android.material.appbar.CollapsingToolbarLayout
|
||||||
@ -637,7 +637,7 @@ class MainActivity : BaseLanguageActivity(), FragmentManager.OnBackStackChangedL
|
|||||||
alertDialog.show()
|
alertDialog.show()
|
||||||
lifecycleScope.launch(Dispatchers.IO) {
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
val media = if (isLoggedIn) MediaService.fetch(shortcodeToId(shortCode)) else GraphQLService.fetchPost(shortCode)
|
val media = if (isLoggedIn) MediaRepository.fetch(shortcodeToId(shortCode)) else GraphQLService.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()
|
||||||
|
@ -31,7 +31,7 @@ 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.GraphQLService;
|
||||||
import awais.instagrabber.webservices.MediaService;
|
import awais.instagrabber.webservices.MediaRepository;
|
||||||
import awais.instagrabber.webservices.ServiceCallback;
|
import awais.instagrabber.webservices.ServiceCallback;
|
||||||
import kotlinx.coroutines.Dispatchers;
|
import kotlinx.coroutines.Dispatchers;
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ public final class LikesViewerFragment extends BottomSheetDialogFragment impleme
|
|||||||
|
|
||||||
private FragmentLikesBinding binding;
|
private FragmentLikesBinding binding;
|
||||||
private RecyclerLazyLoader lazyLoader;
|
private RecyclerLazyLoader lazyLoader;
|
||||||
private MediaService mediaService;
|
private MediaRepository mediaRepository;
|
||||||
private GraphQLService graphQLService;
|
private GraphQLService graphQLService;
|
||||||
private boolean isLoggedIn;
|
private boolean isLoggedIn;
|
||||||
private String postId, endCursor;
|
private String postId, endCursor;
|
||||||
@ -112,7 +112,7 @@ public final class LikesViewerFragment extends BottomSheetDialogFragment impleme
|
|||||||
// final String deviceUuid = settingsHelper.getString(Constants.DEVICE_UUID);
|
// final String deviceUuid = settingsHelper.getString(Constants.DEVICE_UUID);
|
||||||
final String csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie);
|
final String csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie);
|
||||||
if (csrfToken == null) return;
|
if (csrfToken == null) return;
|
||||||
mediaService = isLoggedIn ? MediaService.INSTANCE : null;
|
mediaRepository = isLoggedIn ? MediaRepository.INSTANCE : null;
|
||||||
graphQLService = isLoggedIn ? null : GraphQLService.INSTANCE;
|
graphQLService = isLoggedIn ? null : GraphQLService.INSTANCE;
|
||||||
// setHasOptionsMenu(true);
|
// setHasOptionsMenu(true);
|
||||||
}
|
}
|
||||||
@ -147,7 +147,7 @@ public final class LikesViewerFragment extends BottomSheetDialogFragment impleme
|
|||||||
}), Dispatchers.getIO())
|
}), Dispatchers.getIO())
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
mediaService.fetchLikes(
|
mediaRepository.fetchLikes(
|
||||||
postId,
|
postId,
|
||||||
isComment,
|
isComment,
|
||||||
CoroutineUtilsKt.getContinuation((users, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
|
CoroutineUtilsKt.getContinuation((users, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
|
||||||
|
@ -45,7 +45,7 @@ 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.FriendshipRepository;
|
import awais.instagrabber.webservices.FriendshipRepository;
|
||||||
import awais.instagrabber.webservices.MediaService;
|
import awais.instagrabber.webservices.MediaRepository;
|
||||||
import awais.instagrabber.webservices.NewsService;
|
import awais.instagrabber.webservices.NewsService;
|
||||||
import awais.instagrabber.webservices.ServiceCallback;
|
import awais.instagrabber.webservices.ServiceCallback;
|
||||||
import kotlinx.coroutines.Dispatchers;
|
import kotlinx.coroutines.Dispatchers;
|
||||||
@ -61,7 +61,7 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
|
|||||||
private boolean shouldRefresh = true;
|
private boolean shouldRefresh = true;
|
||||||
private NotificationViewModel notificationViewModel;
|
private NotificationViewModel notificationViewModel;
|
||||||
private FriendshipRepository friendshipRepository;
|
private FriendshipRepository friendshipRepository;
|
||||||
private MediaService mediaService;
|
private MediaRepository mediaRepository;
|
||||||
private NewsService newsService;
|
private NewsService newsService;
|
||||||
private String csrfToken, deviceUuid;
|
private String csrfToken, deviceUuid;
|
||||||
private String type;
|
private String type;
|
||||||
@ -108,7 +108,7 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
|
|||||||
.setView(R.layout.dialog_opening_post)
|
.setView(R.layout.dialog_opening_post)
|
||||||
.create();
|
.create();
|
||||||
alertDialog.show();
|
alertDialog.show();
|
||||||
mediaService.fetch(
|
mediaRepository.fetch(
|
||||||
mediaId,
|
mediaId,
|
||||||
CoroutineUtilsKt.getContinuation((media, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
|
CoroutineUtilsKt.getContinuation((media, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
@ -229,7 +229,7 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
|
|||||||
deviceUuid = Utils.settingsHelper.getString(Constants.DEVICE_UUID);
|
deviceUuid = Utils.settingsHelper.getString(Constants.DEVICE_UUID);
|
||||||
csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie);
|
csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie);
|
||||||
friendshipRepository = FriendshipRepository.Companion.getInstance();
|
friendshipRepository = FriendshipRepository.Companion.getInstance();
|
||||||
mediaService = MediaService.INSTANCE;
|
mediaRepository = MediaRepository.INSTANCE;
|
||||||
newsService = NewsService.getInstance();
|
newsService = NewsService.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ import awais.instagrabber.viewmodels.FeedStoriesViewModel;
|
|||||||
import awais.instagrabber.viewmodels.HighlightsViewModel;
|
import awais.instagrabber.viewmodels.HighlightsViewModel;
|
||||||
import awais.instagrabber.viewmodels.StoriesViewModel;
|
import awais.instagrabber.viewmodels.StoriesViewModel;
|
||||||
import awais.instagrabber.webservices.DirectMessagesService;
|
import awais.instagrabber.webservices.DirectMessagesService;
|
||||||
import awais.instagrabber.webservices.MediaService;
|
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;
|
||||||
import kotlinx.coroutines.Dispatchers;
|
import kotlinx.coroutines.Dispatchers;
|
||||||
@ -123,7 +123,7 @@ public class StoryViewerFragment extends Fragment {
|
|||||||
private SwipeEvent swipeEvent;
|
private SwipeEvent swipeEvent;
|
||||||
private GestureDetectorCompat gestureDetector;
|
private GestureDetectorCompat gestureDetector;
|
||||||
private StoriesRepository storiesRepository;
|
private StoriesRepository storiesRepository;
|
||||||
private MediaService mediaService;
|
private MediaRepository mediaRepository;
|
||||||
private StoryModel currentStory;
|
private StoryModel currentStory;
|
||||||
private int slidePos;
|
private int slidePos;
|
||||||
private int lastSlidePos;
|
private int lastSlidePos;
|
||||||
@ -163,7 +163,7 @@ public class StoryViewerFragment extends Fragment {
|
|||||||
deviceId = settingsHelper.getString(Constants.DEVICE_UUID);
|
deviceId = settingsHelper.getString(Constants.DEVICE_UUID);
|
||||||
fragmentActivity = (AppCompatActivity) requireActivity();
|
fragmentActivity = (AppCompatActivity) requireActivity();
|
||||||
storiesRepository = StoriesRepository.Companion.getInstance();
|
storiesRepository = StoriesRepository.Companion.getInstance();
|
||||||
mediaService = MediaService.INSTANCE;
|
mediaRepository = MediaRepository.INSTANCE;
|
||||||
directMessagesService = DirectMessagesService.INSTANCE;
|
directMessagesService = DirectMessagesService.INSTANCE;
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
}
|
}
|
||||||
@ -476,7 +476,7 @@ public class StoryViewerFragment extends Fragment {
|
|||||||
.setView(R.layout.dialog_opening_post)
|
.setView(R.layout.dialog_opening_post)
|
||||||
.create();
|
.create();
|
||||||
alertDialog.show();
|
alertDialog.show();
|
||||||
mediaService.fetch(
|
mediaRepository.fetch(
|
||||||
Long.parseLong(mediaId),
|
Long.parseLong(mediaId),
|
||||||
CoroutineUtilsKt.getContinuation((media, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
|
CoroutineUtilsKt.getContinuation((media, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
|
@ -35,7 +35,7 @@ import awais.instagrabber.utils.CoroutineUtilsKt;
|
|||||||
import awais.instagrabber.utils.Utils;
|
import awais.instagrabber.utils.Utils;
|
||||||
import awais.instagrabber.viewmodels.TopicClusterViewModel;
|
import awais.instagrabber.viewmodels.TopicClusterViewModel;
|
||||||
import awais.instagrabber.webservices.DiscoverService;
|
import awais.instagrabber.webservices.DiscoverService;
|
||||||
import awais.instagrabber.webservices.MediaService;
|
import awais.instagrabber.webservices.MediaRepository;
|
||||||
import awais.instagrabber.webservices.ServiceCallback;
|
import awais.instagrabber.webservices.ServiceCallback;
|
||||||
import kotlinx.coroutines.Dispatchers;
|
import kotlinx.coroutines.Dispatchers;
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ public class DiscoverFragment extends Fragment implements SwipeRefreshLayout.OnR
|
|||||||
private TopicClusterViewModel topicClusterViewModel;
|
private TopicClusterViewModel topicClusterViewModel;
|
||||||
private boolean shouldRefresh = true;
|
private boolean shouldRefresh = true;
|
||||||
private DiscoverService discoverService;
|
private DiscoverService discoverService;
|
||||||
private MediaService mediaService;
|
private MediaRepository mediaRepository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
||||||
@ -59,7 +59,7 @@ public class DiscoverFragment extends Fragment implements SwipeRefreshLayout.OnR
|
|||||||
// final String cookie = Utils.settingsHelper.getString(Constants.COOKIE);
|
// final String cookie = Utils.settingsHelper.getString(Constants.COOKIE);
|
||||||
// final String csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie);
|
// final String csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie);
|
||||||
// final long userId = CookieUtils.getUserIdFromCookie(cookie);
|
// final long userId = CookieUtils.getUserIdFromCookie(cookie);
|
||||||
mediaService = MediaService.INSTANCE;
|
mediaRepository = MediaRepository.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -113,7 +113,7 @@ public class DiscoverFragment extends Fragment implements SwipeRefreshLayout.OnR
|
|||||||
alertDialog.show();
|
alertDialog.show();
|
||||||
final String pk = coverMedia.getPk();
|
final String pk = coverMedia.getPk();
|
||||||
if (pk == null) return;
|
if (pk == null) return;
|
||||||
mediaService.fetch(
|
mediaRepository.fetch(
|
||||||
Long.parseLong(pk),
|
Long.parseLong(pk),
|
||||||
CoroutineUtilsKt.getContinuation((media, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
|
CoroutineUtilsKt.getContinuation((media, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
|
@ -94,7 +94,7 @@ 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.GraphQLService;
|
||||||
import awais.instagrabber.webservices.MediaService;
|
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;
|
||||||
import awais.instagrabber.webservices.UserRepository;
|
import awais.instagrabber.webservices.UserRepository;
|
||||||
@ -120,7 +120,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
private Handler usernameSettingHandler;
|
private Handler usernameSettingHandler;
|
||||||
private FriendshipRepository friendshipRepository;
|
private FriendshipRepository friendshipRepository;
|
||||||
private StoriesRepository storiesRepository;
|
private StoriesRepository storiesRepository;
|
||||||
private MediaService mediaService;
|
private MediaRepository mediaRepository;
|
||||||
private UserRepository userRepository;
|
private UserRepository userRepository;
|
||||||
private GraphQLService graphQLService;
|
private GraphQLService graphQLService;
|
||||||
private DirectMessagesService directMessagesService;
|
private DirectMessagesService directMessagesService;
|
||||||
@ -336,7 +336,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
friendshipRepository = isLoggedIn ? FriendshipRepository.Companion.getInstance() : null;
|
friendshipRepository = isLoggedIn ? FriendshipRepository.Companion.getInstance() : null;
|
||||||
directMessagesService = isLoggedIn ? DirectMessagesService.INSTANCE : null;
|
directMessagesService = isLoggedIn ? DirectMessagesService.INSTANCE : null;
|
||||||
storiesRepository = isLoggedIn ? StoriesRepository.Companion.getInstance() : null;
|
storiesRepository = isLoggedIn ? StoriesRepository.Companion.getInstance() : null;
|
||||||
mediaService = isLoggedIn ? MediaService.INSTANCE : null;
|
mediaRepository = isLoggedIn ? MediaRepository.INSTANCE : null;
|
||||||
userRepository = isLoggedIn ? UserRepository.Companion.getInstance() : null;
|
userRepository = isLoggedIn ? UserRepository.Companion.getInstance() : null;
|
||||||
graphQLService = isLoggedIn ? null : GraphQLService.INSTANCE;
|
graphQLService = isLoggedIn ? null : GraphQLService.INSTANCE;
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
@ -865,7 +865,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
Utils.copyText(context, biography);
|
Utils.copyText(context, biography);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
mediaService.translate(String.valueOf(profileModel.getPk()), "3", CoroutineUtilsKt.getContinuation(
|
mediaRepository.translate(String.valueOf(profileModel.getPk()), "3", CoroutineUtilsKt.getContinuation(
|
||||||
(result, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
|
(result, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
Log.e(TAG, "Error translating bio", throwable);
|
Log.e(TAG, "Error translating bio", throwable);
|
||||||
|
@ -32,7 +32,7 @@ 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.FriendshipRepository
|
import awais.instagrabber.webservices.FriendshipRepository
|
||||||
import awais.instagrabber.webservices.MediaService
|
import awais.instagrabber.webservices.MediaRepository
|
||||||
import com.google.common.collect.ImmutableList
|
import com.google.common.collect.ImmutableList
|
||||||
import com.google.common.collect.Iterables
|
import com.google.common.collect.Iterables
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
@ -453,7 +453,7 @@ class ThreadManager(
|
|||||||
"4",
|
"4",
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
MediaService.uploadFinish(csrfToken, userId, deviceUuid, uploadFinishOptions)
|
MediaRepository.uploadFinish(csrfToken, userId, deviceUuid, uploadFinishOptions)
|
||||||
val broadcastResponse = DirectMessagesService.broadcastVoice(
|
val broadcastResponse = DirectMessagesService.broadcastVoice(
|
||||||
csrfToken,
|
csrfToken,
|
||||||
viewerId,
|
viewerId,
|
||||||
@ -791,7 +791,7 @@ class ThreadManager(
|
|||||||
"2",
|
"2",
|
||||||
VideoOptions(duration / 1000f, emptyList(), 0, false)
|
VideoOptions(duration / 1000f, emptyList(), 0, false)
|
||||||
)
|
)
|
||||||
MediaService.uploadFinish(csrfToken, userId, deviceUuid, uploadFinishOptions)
|
MediaRepository.uploadFinish(csrfToken, userId, deviceUuid, uploadFinishOptions)
|
||||||
val broadcastResponse = DirectMessagesService.broadcastVideo(
|
val broadcastResponse = DirectMessagesService.broadcastVideo(
|
||||||
csrfToken,
|
csrfToken,
|
||||||
viewerId,
|
viewerId,
|
||||||
|
@ -4,7 +4,7 @@ import awais.instagrabber.repositories.responses.LikersResponse
|
|||||||
import awais.instagrabber.repositories.responses.MediaInfoResponse
|
import awais.instagrabber.repositories.responses.MediaInfoResponse
|
||||||
import retrofit2.http.*
|
import retrofit2.http.*
|
||||||
|
|
||||||
interface MediaRepository {
|
interface MediaService {
|
||||||
@GET("/api/v1/media/{mediaId}/info/")
|
@GET("/api/v1/media/{mediaId}/info/")
|
||||||
suspend fun fetch(@Path("mediaId") mediaId: Long): MediaInfoResponse
|
suspend fun fetch(@Path("mediaId") mediaId: Long): MediaInfoResponse
|
||||||
|
|
@ -22,7 +22,7 @@ import awais.instagrabber.utils.Utils
|
|||||||
import awais.instagrabber.utils.extensions.TAG
|
import awais.instagrabber.utils.extensions.TAG
|
||||||
import awais.instagrabber.utils.getCsrfTokenFromCookie
|
import awais.instagrabber.utils.getCsrfTokenFromCookie
|
||||||
import awais.instagrabber.utils.getUserIdFromCookie
|
import awais.instagrabber.utils.getUserIdFromCookie
|
||||||
import awais.instagrabber.webservices.MediaService
|
import awais.instagrabber.webservices.MediaRepository
|
||||||
import com.google.common.collect.ImmutableList
|
import com.google.common.collect.ImmutableList
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@ -135,7 +135,7 @@ class PostViewV2ViewModel : ViewModel() {
|
|||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
val mediaId = media.pk ?: return@launch
|
val mediaId = media.pk ?: return@launch
|
||||||
val liked = MediaService.like(csrfToken!!, viewerId, deviceUuid, mediaId)
|
val liked = MediaRepository.like(csrfToken!!, viewerId, deviceUuid, mediaId)
|
||||||
updateMediaLikeUnlike(data, liked)
|
updateMediaLikeUnlike(data, liked)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
data.postValue(error(e.message, null))
|
data.postValue(error(e.message, null))
|
||||||
@ -154,7 +154,7 @@ class PostViewV2ViewModel : ViewModel() {
|
|||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
val mediaId = media.pk ?: return@launch
|
val mediaId = media.pk ?: return@launch
|
||||||
val unliked = MediaService.unlike(csrfToken!!, viewerId, deviceUuid, mediaId)
|
val unliked = MediaRepository.unlike(csrfToken!!, viewerId, deviceUuid, mediaId)
|
||||||
updateMediaLikeUnlike(data, unliked)
|
updateMediaLikeUnlike(data, unliked)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
data.postValue(error(e.message, null))
|
data.postValue(error(e.message, null))
|
||||||
@ -203,7 +203,7 @@ class PostViewV2ViewModel : ViewModel() {
|
|||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
val mediaId = media.pk ?: return@launch
|
val mediaId = media.pk ?: return@launch
|
||||||
val saved = MediaService.save(csrfToken!!, viewerId, deviceUuid, mediaId, collection)
|
val saved = MediaRepository.save(csrfToken!!, viewerId, deviceUuid, mediaId, collection)
|
||||||
getSaveUnsaveCallback(data, saved, ignoreSaveState)
|
getSaveUnsaveCallback(data, saved, ignoreSaveState)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
data.postValue(error(e.message, null))
|
data.postValue(error(e.message, null))
|
||||||
@ -221,7 +221,7 @@ class PostViewV2ViewModel : ViewModel() {
|
|||||||
}
|
}
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
val mediaId = media.pk ?: return@launch
|
val mediaId = media.pk ?: return@launch
|
||||||
val unsaved = MediaService.unsave(csrfToken!!, viewerId, deviceUuid, mediaId)
|
val unsaved = MediaRepository.unsave(csrfToken!!, viewerId, deviceUuid, mediaId)
|
||||||
getSaveUnsaveCallback(data, unsaved, false)
|
getSaveUnsaveCallback(data, unsaved, false)
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
@ -251,7 +251,7 @@ class PostViewV2ViewModel : ViewModel() {
|
|||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
val postId = media.pk ?: return@launch
|
val postId = media.pk ?: return@launch
|
||||||
val result = MediaService.editCaption(csrfToken!!, viewerId, deviceUuid, postId, caption)
|
val result = MediaRepository.editCaption(csrfToken!!, viewerId, deviceUuid, postId, caption)
|
||||||
if (result) {
|
if (result) {
|
||||||
data.postValue(success(""))
|
data.postValue(success(""))
|
||||||
media.setPostCaption(caption)
|
media.setPostCaption(caption)
|
||||||
@ -278,7 +278,7 @@ class PostViewV2ViewModel : ViewModel() {
|
|||||||
}
|
}
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
val result = MediaService.translate(pk, "1")
|
val result = MediaRepository.translate(pk, "1")
|
||||||
if (result.isBlank()) {
|
if (result.isBlank()) {
|
||||||
data.postValue(error("", null))
|
data.postValue(error("", null))
|
||||||
return@launch
|
return@launch
|
||||||
@ -315,7 +315,7 @@ class PostViewV2ViewModel : ViewModel() {
|
|||||||
}
|
}
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
val response = MediaService.delete(csrfToken!!, viewerId, deviceUuid, mediaId, mediaType)
|
val response = MediaRepository.delete(csrfToken!!, viewerId, deviceUuid, mediaId, mediaType)
|
||||||
if (response == null) {
|
if (response == null) {
|
||||||
data.postValue(success(Any()))
|
data.postValue(success(Any()))
|
||||||
return@launch
|
return@launch
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package awais.instagrabber.webservices
|
package awais.instagrabber.webservices
|
||||||
|
|
||||||
import awais.instagrabber.models.enums.MediaItemType
|
import awais.instagrabber.models.enums.MediaItemType
|
||||||
import awais.instagrabber.repositories.MediaRepository
|
import awais.instagrabber.repositories.MediaService
|
||||||
import awais.instagrabber.repositories.requests.Clip
|
import awais.instagrabber.repositories.requests.Clip
|
||||||
import awais.instagrabber.repositories.requests.UploadFinishOptions
|
import awais.instagrabber.repositories.requests.UploadFinishOptions
|
||||||
import awais.instagrabber.repositories.responses.Media
|
import awais.instagrabber.repositories.responses.Media
|
||||||
@ -12,18 +12,18 @@ import awais.instagrabber.utils.retryContextString
|
|||||||
import awais.instagrabber.webservices.RetrofitFactory.retrofit
|
import awais.instagrabber.webservices.RetrofitFactory.retrofit
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
|
||||||
object MediaService {
|
object MediaRepository {
|
||||||
private val DELETABLE_ITEMS_TYPES = listOf(
|
private val DELETABLE_ITEMS_TYPES = listOf(
|
||||||
MediaItemType.MEDIA_TYPE_IMAGE,
|
MediaItemType.MEDIA_TYPE_IMAGE,
|
||||||
MediaItemType.MEDIA_TYPE_VIDEO,
|
MediaItemType.MEDIA_TYPE_VIDEO,
|
||||||
MediaItemType.MEDIA_TYPE_SLIDER
|
MediaItemType.MEDIA_TYPE_SLIDER
|
||||||
)
|
)
|
||||||
private val repository: MediaRepository = retrofit.create(MediaRepository::class.java)
|
private val service: MediaService = retrofit.create(MediaService::class.java)
|
||||||
|
|
||||||
suspend fun fetch(
|
suspend fun fetch(
|
||||||
mediaId: Long,
|
mediaId: Long,
|
||||||
): Media? {
|
): Media? {
|
||||||
val response = repository.fetch(mediaId)
|
val response = service.fetch(mediaId)
|
||||||
return if (response.items.isNullOrEmpty()) {
|
return if (response.items.isNullOrEmpty()) {
|
||||||
null
|
null
|
||||||
} else response.items[0]
|
} else response.items[0]
|
||||||
@ -77,7 +77,7 @@ object MediaService {
|
|||||||
}
|
}
|
||||||
// there also exists "removed_collection_ids" which can be used with "save" and "unsave"
|
// there also exists "removed_collection_ids" which can be used with "save" and "unsave"
|
||||||
val signedForm = Utils.sign(form)
|
val signedForm = Utils.sign(form)
|
||||||
val response = repository.action(action, mediaId, signedForm)
|
val response = service.action(action, mediaId, signedForm)
|
||||||
val jsonObject = JSONObject(response)
|
val jsonObject = JSONObject(response)
|
||||||
val status = jsonObject.optString("status")
|
val status = jsonObject.optString("status")
|
||||||
return status == "ok"
|
return status == "ok"
|
||||||
@ -99,7 +99,7 @@ object MediaService {
|
|||||||
"caption_text" to newCaption,
|
"caption_text" to newCaption,
|
||||||
)
|
)
|
||||||
val signedForm = Utils.sign(form)
|
val signedForm = Utils.sign(form)
|
||||||
val response = repository.editCaption(postId, signedForm)
|
val response = service.editCaption(postId, signedForm)
|
||||||
val jsonObject = JSONObject(response)
|
val jsonObject = JSONObject(response)
|
||||||
val status = jsonObject.optString("status")
|
val status = jsonObject.optString("status")
|
||||||
return status == "ok"
|
return status == "ok"
|
||||||
@ -109,7 +109,7 @@ object MediaService {
|
|||||||
mediaId: String,
|
mediaId: String,
|
||||||
isComment: Boolean,
|
isComment: Boolean,
|
||||||
): List<User> {
|
): List<User> {
|
||||||
val response = repository.fetchLikes(mediaId, if (isComment) "comment_likers" else "likers")
|
val response = service.fetchLikes(mediaId, if (isComment) "comment_likers" else "likers")
|
||||||
return response.users
|
return response.users
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ object MediaService {
|
|||||||
"id" to id,
|
"id" to id,
|
||||||
"type" to type,
|
"type" to type,
|
||||||
)
|
)
|
||||||
val response = repository.translate(form)
|
val response = service.translate(form)
|
||||||
val jsonObject = JSONObject(response)
|
val jsonObject = JSONObject(response)
|
||||||
return jsonObject.optString("translation")
|
return jsonObject.optString("translation")
|
||||||
}
|
}
|
||||||
@ -152,7 +152,7 @@ object MediaService {
|
|||||||
}
|
}
|
||||||
val queryMap = if (options.videoOptions != null) mapOf("video" to "1") else emptyMap()
|
val queryMap = if (options.videoOptions != null) mapOf("video" to "1") else emptyMap()
|
||||||
val signedForm = Utils.sign(form)
|
val signedForm = Utils.sign(form)
|
||||||
return repository.uploadFinish(retryContextString, queryMap, signedForm)
|
return service.uploadFinish(retryContextString, queryMap, signedForm)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun delete(
|
suspend fun delete(
|
||||||
@ -177,6 +177,6 @@ object MediaService {
|
|||||||
MediaItemType.MEDIA_TYPE_SLIDER -> "CAROUSEL"
|
MediaItemType.MEDIA_TYPE_SLIDER -> "CAROUSEL"
|
||||||
else -> return null
|
else -> return null
|
||||||
}
|
}
|
||||||
return repository.delete(postId, mediaType, signedForm)
|
return service.delete(postId, mediaType, signedForm)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user