1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-12-23 05:16:58 +00:00

Interchange MediaService and MediaRepository names.

This commit is contained in:
Ammar Githam 2021-06-12 09:53:38 +09:00
parent 02cb1f5db5
commit b2cbc18dbb
10 changed files with 44 additions and 44 deletions

View File

@ -59,7 +59,7 @@ import awais.instagrabber.utils.emoji.EmojiParser
import awais.instagrabber.viewmodels.AppStateViewModel
import awais.instagrabber.viewmodels.DirectInboxViewModel
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.ScrollingViewBehavior
import com.google.android.material.appbar.CollapsingToolbarLayout
@ -637,7 +637,7 @@ class MainActivity : BaseLanguageActivity(), FragmentManager.OnBackStackChangedL
alertDialog.show()
lifecycleScope.launch(Dispatchers.IO) {
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) {
if (media == null) {
Toast.makeText(applicationContext, R.string.post_not_found, Toast.LENGTH_SHORT).show()

View File

@ -31,7 +31,7 @@ import awais.instagrabber.utils.CookieUtils;
import awais.instagrabber.utils.CoroutineUtilsKt;
import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.webservices.GraphQLService;
import awais.instagrabber.webservices.MediaService;
import awais.instagrabber.webservices.MediaRepository;
import awais.instagrabber.webservices.ServiceCallback;
import kotlinx.coroutines.Dispatchers;
@ -42,7 +42,7 @@ public final class LikesViewerFragment extends BottomSheetDialogFragment impleme
private FragmentLikesBinding binding;
private RecyclerLazyLoader lazyLoader;
private MediaService mediaService;
private MediaRepository mediaRepository;
private GraphQLService graphQLService;
private boolean isLoggedIn;
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 csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie);
if (csrfToken == null) return;
mediaService = isLoggedIn ? MediaService.INSTANCE : null;
mediaRepository = isLoggedIn ? MediaRepository.INSTANCE : null;
graphQLService = isLoggedIn ? null : GraphQLService.INSTANCE;
// setHasOptionsMenu(true);
}
@ -147,7 +147,7 @@ public final class LikesViewerFragment extends BottomSheetDialogFragment impleme
}), Dispatchers.getIO())
);
} else {
mediaService.fetchLikes(
mediaRepository.fetchLikes(
postId,
isComment,
CoroutineUtilsKt.getContinuation((users, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {

View File

@ -45,7 +45,7 @@ import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.utils.Utils;
import awais.instagrabber.viewmodels.NotificationViewModel;
import awais.instagrabber.webservices.FriendshipRepository;
import awais.instagrabber.webservices.MediaService;
import awais.instagrabber.webservices.MediaRepository;
import awais.instagrabber.webservices.NewsService;
import awais.instagrabber.webservices.ServiceCallback;
import kotlinx.coroutines.Dispatchers;
@ -61,7 +61,7 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
private boolean shouldRefresh = true;
private NotificationViewModel notificationViewModel;
private FriendshipRepository friendshipRepository;
private MediaService mediaService;
private MediaRepository mediaRepository;
private NewsService newsService;
private String csrfToken, deviceUuid;
private String type;
@ -108,7 +108,7 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
.setView(R.layout.dialog_opening_post)
.create();
alertDialog.show();
mediaService.fetch(
mediaRepository.fetch(
mediaId,
CoroutineUtilsKt.getContinuation((media, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
if (throwable != null) {
@ -229,7 +229,7 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
deviceUuid = Utils.settingsHelper.getString(Constants.DEVICE_UUID);
csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie);
friendshipRepository = FriendshipRepository.Companion.getInstance();
mediaService = MediaService.INSTANCE;
mediaRepository = MediaRepository.INSTANCE;
newsService = NewsService.getInstance();
}

View File

@ -99,7 +99,7 @@ import awais.instagrabber.viewmodels.FeedStoriesViewModel;
import awais.instagrabber.viewmodels.HighlightsViewModel;
import awais.instagrabber.viewmodels.StoriesViewModel;
import awais.instagrabber.webservices.DirectMessagesService;
import awais.instagrabber.webservices.MediaService;
import awais.instagrabber.webservices.MediaRepository;
import awais.instagrabber.webservices.ServiceCallback;
import awais.instagrabber.webservices.StoriesRepository;
import kotlinx.coroutines.Dispatchers;
@ -123,7 +123,7 @@ public class StoryViewerFragment extends Fragment {
private SwipeEvent swipeEvent;
private GestureDetectorCompat gestureDetector;
private StoriesRepository storiesRepository;
private MediaService mediaService;
private MediaRepository mediaRepository;
private StoryModel currentStory;
private int slidePos;
private int lastSlidePos;
@ -163,7 +163,7 @@ public class StoryViewerFragment extends Fragment {
deviceId = settingsHelper.getString(Constants.DEVICE_UUID);
fragmentActivity = (AppCompatActivity) requireActivity();
storiesRepository = StoriesRepository.Companion.getInstance();
mediaService = MediaService.INSTANCE;
mediaRepository = MediaRepository.INSTANCE;
directMessagesService = DirectMessagesService.INSTANCE;
setHasOptionsMenu(true);
}
@ -476,7 +476,7 @@ public class StoryViewerFragment extends Fragment {
.setView(R.layout.dialog_opening_post)
.create();
alertDialog.show();
mediaService.fetch(
mediaRepository.fetch(
Long.parseLong(mediaId),
CoroutineUtilsKt.getContinuation((media, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
if (throwable != null) {

View File

@ -35,7 +35,7 @@ import awais.instagrabber.utils.CoroutineUtilsKt;
import awais.instagrabber.utils.Utils;
import awais.instagrabber.viewmodels.TopicClusterViewModel;
import awais.instagrabber.webservices.DiscoverService;
import awais.instagrabber.webservices.MediaService;
import awais.instagrabber.webservices.MediaRepository;
import awais.instagrabber.webservices.ServiceCallback;
import kotlinx.coroutines.Dispatchers;
@ -48,7 +48,7 @@ public class DiscoverFragment extends Fragment implements SwipeRefreshLayout.OnR
private TopicClusterViewModel topicClusterViewModel;
private boolean shouldRefresh = true;
private DiscoverService discoverService;
private MediaService mediaService;
private MediaRepository mediaRepository;
@Override
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 csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie);
// final long userId = CookieUtils.getUserIdFromCookie(cookie);
mediaService = MediaService.INSTANCE;
mediaRepository = MediaRepository.INSTANCE;
}
@Override
@ -113,7 +113,7 @@ public class DiscoverFragment extends Fragment implements SwipeRefreshLayout.OnR
alertDialog.show();
final String pk = coverMedia.getPk();
if (pk == null) return;
mediaService.fetch(
mediaRepository.fetch(
Long.parseLong(pk),
CoroutineUtilsKt.getContinuation((media, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
if (throwable != null) {

View File

@ -94,7 +94,7 @@ import awais.instagrabber.viewmodels.ProfileFragmentViewModelFactory;
import awais.instagrabber.webservices.DirectMessagesService;
import awais.instagrabber.webservices.FriendshipRepository;
import awais.instagrabber.webservices.GraphQLService;
import awais.instagrabber.webservices.MediaService;
import awais.instagrabber.webservices.MediaRepository;
import awais.instagrabber.webservices.ServiceCallback;
import awais.instagrabber.webservices.StoriesRepository;
import awais.instagrabber.webservices.UserRepository;
@ -120,7 +120,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
private Handler usernameSettingHandler;
private FriendshipRepository friendshipRepository;
private StoriesRepository storiesRepository;
private MediaService mediaService;
private MediaRepository mediaRepository;
private UserRepository userRepository;
private GraphQLService graphQLService;
private DirectMessagesService directMessagesService;
@ -336,7 +336,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
friendshipRepository = isLoggedIn ? FriendshipRepository.Companion.getInstance() : null;
directMessagesService = isLoggedIn ? DirectMessagesService.INSTANCE : null;
storiesRepository = isLoggedIn ? StoriesRepository.Companion.getInstance() : null;
mediaService = isLoggedIn ? MediaService.INSTANCE : null;
mediaRepository = isLoggedIn ? MediaRepository.INSTANCE : null;
userRepository = isLoggedIn ? UserRepository.Companion.getInstance() : null;
graphQLService = isLoggedIn ? null : GraphQLService.INSTANCE;
final Context context = getContext();
@ -865,7 +865,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
Utils.copyText(context, biography);
break;
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(() -> {
if (throwable != null) {
Log.e(TAG, "Error translating bio", throwable);

View File

@ -32,7 +32,7 @@ import awais.instagrabber.utils.TextUtils.isEmpty
import awais.instagrabber.utils.extensions.TAG
import awais.instagrabber.webservices.DirectMessagesService
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.Iterables
import kotlinx.coroutines.CoroutineScope
@ -453,7 +453,7 @@ class ThreadManager(
"4",
null
)
MediaService.uploadFinish(csrfToken, userId, deviceUuid, uploadFinishOptions)
MediaRepository.uploadFinish(csrfToken, userId, deviceUuid, uploadFinishOptions)
val broadcastResponse = DirectMessagesService.broadcastVoice(
csrfToken,
viewerId,
@ -791,7 +791,7 @@ class ThreadManager(
"2",
VideoOptions(duration / 1000f, emptyList(), 0, false)
)
MediaService.uploadFinish(csrfToken, userId, deviceUuid, uploadFinishOptions)
MediaRepository.uploadFinish(csrfToken, userId, deviceUuid, uploadFinishOptions)
val broadcastResponse = DirectMessagesService.broadcastVideo(
csrfToken,
viewerId,

View File

@ -4,7 +4,7 @@ import awais.instagrabber.repositories.responses.LikersResponse
import awais.instagrabber.repositories.responses.MediaInfoResponse
import retrofit2.http.*
interface MediaRepository {
interface MediaService {
@GET("/api/v1/media/{mediaId}/info/")
suspend fun fetch(@Path("mediaId") mediaId: Long): MediaInfoResponse

View File

@ -22,7 +22,7 @@ import awais.instagrabber.utils.Utils
import awais.instagrabber.utils.extensions.TAG
import awais.instagrabber.utils.getCsrfTokenFromCookie
import awais.instagrabber.utils.getUserIdFromCookie
import awais.instagrabber.webservices.MediaService
import awais.instagrabber.webservices.MediaRepository
import com.google.common.collect.ImmutableList
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@ -135,7 +135,7 @@ class PostViewV2ViewModel : ViewModel() {
viewModelScope.launch(Dispatchers.IO) {
try {
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)
} catch (e: Exception) {
data.postValue(error(e.message, null))
@ -154,7 +154,7 @@ class PostViewV2ViewModel : ViewModel() {
viewModelScope.launch(Dispatchers.IO) {
try {
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)
} catch (e: Exception) {
data.postValue(error(e.message, null))
@ -203,7 +203,7 @@ class PostViewV2ViewModel : ViewModel() {
viewModelScope.launch(Dispatchers.IO) {
try {
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)
} catch (e: Exception) {
data.postValue(error(e.message, null))
@ -221,7 +221,7 @@ class PostViewV2ViewModel : ViewModel() {
}
viewModelScope.launch(Dispatchers.IO) {
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)
}
return data
@ -251,7 +251,7 @@ class PostViewV2ViewModel : ViewModel() {
viewModelScope.launch(Dispatchers.IO) {
try {
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) {
data.postValue(success(""))
media.setPostCaption(caption)
@ -278,7 +278,7 @@ class PostViewV2ViewModel : ViewModel() {
}
viewModelScope.launch(Dispatchers.IO) {
try {
val result = MediaService.translate(pk, "1")
val result = MediaRepository.translate(pk, "1")
if (result.isBlank()) {
data.postValue(error("", null))
return@launch
@ -315,7 +315,7 @@ class PostViewV2ViewModel : ViewModel() {
}
viewModelScope.launch(Dispatchers.IO) {
try {
val response = MediaService.delete(csrfToken!!, viewerId, deviceUuid, mediaId, mediaType)
val response = MediaRepository.delete(csrfToken!!, viewerId, deviceUuid, mediaId, mediaType)
if (response == null) {
data.postValue(success(Any()))
return@launch

View File

@ -1,7 +1,7 @@
package awais.instagrabber.webservices
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.UploadFinishOptions
import awais.instagrabber.repositories.responses.Media
@ -12,18 +12,18 @@ import awais.instagrabber.utils.retryContextString
import awais.instagrabber.webservices.RetrofitFactory.retrofit
import org.json.JSONObject
object MediaService {
object MediaRepository {
private val DELETABLE_ITEMS_TYPES = listOf(
MediaItemType.MEDIA_TYPE_IMAGE,
MediaItemType.MEDIA_TYPE_VIDEO,
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(
mediaId: Long,
): Media? {
val response = repository.fetch(mediaId)
val response = service.fetch(mediaId)
return if (response.items.isNullOrEmpty()) {
null
} else response.items[0]
@ -77,7 +77,7 @@ object MediaService {
}
// there also exists "removed_collection_ids" which can be used with "save" and "unsave"
val signedForm = Utils.sign(form)
val response = repository.action(action, mediaId, signedForm)
val response = service.action(action, mediaId, signedForm)
val jsonObject = JSONObject(response)
val status = jsonObject.optString("status")
return status == "ok"
@ -99,7 +99,7 @@ object MediaService {
"caption_text" to newCaption,
)
val signedForm = Utils.sign(form)
val response = repository.editCaption(postId, signedForm)
val response = service.editCaption(postId, signedForm)
val jsonObject = JSONObject(response)
val status = jsonObject.optString("status")
return status == "ok"
@ -109,7 +109,7 @@ object MediaService {
mediaId: String,
isComment: Boolean,
): 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
}
@ -121,7 +121,7 @@ object MediaService {
"id" to id,
"type" to type,
)
val response = repository.translate(form)
val response = service.translate(form)
val jsonObject = JSONObject(response)
return jsonObject.optString("translation")
}
@ -152,7 +152,7 @@ object MediaService {
}
val queryMap = if (options.videoOptions != null) mapOf("video" to "1") else emptyMap()
val signedForm = Utils.sign(form)
return repository.uploadFinish(retryContextString, queryMap, signedForm)
return service.uploadFinish(retryContextString, queryMap, signedForm)
}
suspend fun delete(
@ -177,6 +177,6 @@ object MediaService {
MediaItemType.MEDIA_TYPE_SLIDER -> "CAROUSEL"
else -> return null
}
return repository.delete(postId, mediaType, signedForm)
return service.delete(postId, mediaType, signedForm)
}
}