mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-12-23 05:16:58 +00:00
Move MediaService object to MediaRepository constructor parameter.
This commit is contained in:
parent
b2cbc18dbb
commit
58e0863de5
@ -103,6 +103,7 @@ class MainActivity : BaseLanguageActivity(), FragmentManager.OnBackStackChangedL
|
||||
isActivityCheckerServiceBound = false
|
||||
}
|
||||
}
|
||||
private val mediaRepository: MediaRepository by lazy { MediaRepository.getInstance() }
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@ -637,7 +638,7 @@ class MainActivity : BaseLanguageActivity(), FragmentManager.OnBackStackChangedL
|
||||
alertDialog.show()
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val media = if (isLoggedIn) MediaRepository.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()
|
||||
|
@ -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;
|
||||
mediaRepository = isLoggedIn ? MediaRepository.INSTANCE : null;
|
||||
mediaRepository = isLoggedIn ? MediaRepository.Companion.getInstance() : null;
|
||||
graphQLService = isLoggedIn ? null : GraphQLService.INSTANCE;
|
||||
// setHasOptionsMenu(true);
|
||||
}
|
||||
|
@ -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();
|
||||
mediaRepository = MediaRepository.INSTANCE;
|
||||
mediaRepository = MediaRepository.Companion.getInstance();
|
||||
newsService = NewsService.getInstance();
|
||||
}
|
||||
|
||||
|
@ -163,7 +163,7 @@ public class StoryViewerFragment extends Fragment {
|
||||
deviceId = settingsHelper.getString(Constants.DEVICE_UUID);
|
||||
fragmentActivity = (AppCompatActivity) requireActivity();
|
||||
storiesRepository = StoriesRepository.Companion.getInstance();
|
||||
mediaRepository = MediaRepository.INSTANCE;
|
||||
mediaRepository = MediaRepository.Companion.getInstance();
|
||||
directMessagesService = DirectMessagesService.INSTANCE;
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
@ -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);
|
||||
mediaRepository = MediaRepository.INSTANCE;
|
||||
mediaRepository = MediaRepository.Companion.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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;
|
||||
mediaRepository = isLoggedIn ? MediaRepository.INSTANCE : null;
|
||||
mediaRepository = isLoggedIn ? MediaRepository.Companion.getInstance() : null;
|
||||
userRepository = isLoggedIn ? UserRepository.Companion.getInstance() : null;
|
||||
graphQLService = isLoggedIn ? null : GraphQLService.INSTANCE;
|
||||
final Context context = getContext();
|
||||
|
@ -63,6 +63,7 @@ class ThreadManager(
|
||||
private val inboxManager: InboxManager = if (pending) DirectMessagesManager.pendingInboxManager else DirectMessagesManager.inboxManager
|
||||
private val threadIdOrUserIds: ThreadIdOrUserIds = of(threadId)
|
||||
private val friendshipRepository: FriendshipRepository by lazy { FriendshipRepository.getInstance() }
|
||||
private val mediaRepository: MediaRepository by lazy { MediaRepository.getInstance() }
|
||||
|
||||
val thread: LiveData<DirectThread?> by lazy {
|
||||
distinctUntilChanged(map(inboxManager.getInbox()) { inboxResource: Resource<DirectInbox?>? ->
|
||||
@ -453,7 +454,7 @@ class ThreadManager(
|
||||
"4",
|
||||
null
|
||||
)
|
||||
MediaRepository.uploadFinish(csrfToken, userId, deviceUuid, uploadFinishOptions)
|
||||
mediaRepository.uploadFinish(csrfToken, userId, deviceUuid, uploadFinishOptions)
|
||||
val broadcastResponse = DirectMessagesService.broadcastVoice(
|
||||
csrfToken,
|
||||
viewerId,
|
||||
@ -791,7 +792,7 @@ class ThreadManager(
|
||||
"2",
|
||||
VideoOptions(duration / 1000f, emptyList(), 0, false)
|
||||
)
|
||||
MediaRepository.uploadFinish(csrfToken, userId, deviceUuid, uploadFinishOptions)
|
||||
mediaRepository.uploadFinish(csrfToken, userId, deviceUuid, uploadFinishOptions)
|
||||
val broadcastResponse = DirectMessagesService.broadcastVideo(
|
||||
csrfToken,
|
||||
viewerId,
|
||||
|
@ -45,6 +45,7 @@ class PostViewV2ViewModel : ViewModel() {
|
||||
private val deviceUuid = Utils.settingsHelper.getString(Constants.DEVICE_UUID)
|
||||
private val csrfToken = getCsrfTokenFromCookie(cookie)
|
||||
private val viewerId = getUserIdFromCookie(cookie)
|
||||
private val mediaRepository: MediaRepository by lazy { MediaRepository.getInstance() }
|
||||
|
||||
lateinit var media: Media
|
||||
private set
|
||||
@ -135,7 +136,7 @@ class PostViewV2ViewModel : ViewModel() {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val mediaId = media.pk ?: return@launch
|
||||
val liked = MediaRepository.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 +155,7 @@ class PostViewV2ViewModel : ViewModel() {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val mediaId = media.pk ?: return@launch
|
||||
val unliked = MediaRepository.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 +204,7 @@ class PostViewV2ViewModel : ViewModel() {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val mediaId = media.pk ?: return@launch
|
||||
val saved = MediaRepository.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 +222,7 @@ class PostViewV2ViewModel : ViewModel() {
|
||||
}
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val mediaId = media.pk ?: return@launch
|
||||
val unsaved = MediaRepository.unsave(csrfToken!!, viewerId, deviceUuid, mediaId)
|
||||
val unsaved = mediaRepository.unsave(csrfToken!!, viewerId, deviceUuid, mediaId)
|
||||
getSaveUnsaveCallback(data, unsaved, false)
|
||||
}
|
||||
return data
|
||||
@ -251,7 +252,7 @@ class PostViewV2ViewModel : ViewModel() {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val postId = media.pk ?: return@launch
|
||||
val result = MediaRepository.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 +279,7 @@ class PostViewV2ViewModel : ViewModel() {
|
||||
}
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val result = MediaRepository.translate(pk, "1")
|
||||
val result = mediaRepository.translate(pk, "1")
|
||||
if (result.isBlank()) {
|
||||
data.postValue(error("", null))
|
||||
return@launch
|
||||
@ -315,7 +316,7 @@ class PostViewV2ViewModel : ViewModel() {
|
||||
}
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val response = MediaRepository.delete(csrfToken!!, viewerId, deviceUuid, mediaId, mediaType)
|
||||
val response = mediaRepository.delete(csrfToken!!, viewerId, deviceUuid, mediaId, mediaType)
|
||||
if (response == null) {
|
||||
data.postValue(success(Any()))
|
||||
return@launch
|
||||
|
@ -12,13 +12,7 @@ import awais.instagrabber.utils.retryContextString
|
||||
import awais.instagrabber.webservices.RetrofitFactory.retrofit
|
||||
import org.json.JSONObject
|
||||
|
||||
object MediaRepository {
|
||||
private val DELETABLE_ITEMS_TYPES = listOf(
|
||||
MediaItemType.MEDIA_TYPE_IMAGE,
|
||||
MediaItemType.MEDIA_TYPE_VIDEO,
|
||||
MediaItemType.MEDIA_TYPE_SLIDER
|
||||
)
|
||||
private val service: MediaService = retrofit.create(MediaService::class.java)
|
||||
class MediaRepository(private val service: MediaService) {
|
||||
|
||||
suspend fun fetch(
|
||||
mediaId: Long,
|
||||
@ -179,4 +173,22 @@ object MediaRepository {
|
||||
}
|
||||
return service.delete(postId, mediaType, signedForm)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@Volatile
|
||||
private var INSTANCE: MediaRepository? = null
|
||||
|
||||
private val DELETABLE_ITEMS_TYPES = listOf(
|
||||
MediaItemType.MEDIA_TYPE_IMAGE,
|
||||
MediaItemType.MEDIA_TYPE_VIDEO,
|
||||
MediaItemType.MEDIA_TYPE_SLIDER
|
||||
)
|
||||
|
||||
fun getInstance(): MediaRepository {
|
||||
return INSTANCE ?: synchronized(this) {
|
||||
val service: MediaService = retrofit.create(MediaService::class.java)
|
||||
MediaRepository(service).also { INSTANCE = it }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user