mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 14:47:29 +00:00
Handle new created threads using inbox manager
This commit is contained in:
parent
737931821e
commit
6f67dadb31
@ -72,7 +72,6 @@ import awais.instagrabber.interfaces.FetchListener;
|
|||||||
import awais.instagrabber.models.IntentModel;
|
import awais.instagrabber.models.IntentModel;
|
||||||
import awais.instagrabber.models.SuggestionModel;
|
import awais.instagrabber.models.SuggestionModel;
|
||||||
import awais.instagrabber.models.enums.SuggestionType;
|
import awais.instagrabber.models.enums.SuggestionType;
|
||||||
import awais.instagrabber.repositories.responses.directmessages.DirectThread;
|
|
||||||
import awais.instagrabber.services.ActivityCheckerService;
|
import awais.instagrabber.services.ActivityCheckerService;
|
||||||
import awais.instagrabber.services.DMSyncAlarmReceiver;
|
import awais.instagrabber.services.DMSyncAlarmReceiver;
|
||||||
import awais.instagrabber.utils.AppExecutors;
|
import awais.instagrabber.utils.AppExecutors;
|
||||||
@ -251,7 +250,17 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
if (isTaskRoot() && isBackStackEmpty) {
|
int currentNavControllerBackStack = 2;
|
||||||
|
if (currentNavControllerLiveData != null) {
|
||||||
|
final NavController navController = currentNavControllerLiveData.getValue();
|
||||||
|
if (navController != null) {
|
||||||
|
@SuppressLint("RestrictedApi") final Deque<NavBackStackEntry> backStack = navController.getBackStack();
|
||||||
|
if (backStack != null) {
|
||||||
|
currentNavControllerBackStack = backStack.size();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isTaskRoot() && isBackStackEmpty && currentNavControllerBackStack == 2) {
|
||||||
finishAfterTransition();
|
finishAfterTransition();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -577,10 +586,10 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage
|
|||||||
private void showThread(@NonNull final Intent intent) {
|
private void showThread(@NonNull final Intent intent) {
|
||||||
final String threadId = intent.getStringExtra(Constants.DM_THREAD_ACTION_EXTRA_THREAD_ID);
|
final String threadId = intent.getStringExtra(Constants.DM_THREAD_ACTION_EXTRA_THREAD_ID);
|
||||||
final String threadTitle = intent.getStringExtra(Constants.DM_THREAD_ACTION_EXTRA_THREAD_TITLE);
|
final String threadTitle = intent.getStringExtra(Constants.DM_THREAD_ACTION_EXTRA_THREAD_TITLE);
|
||||||
navigateToThread(threadId, threadTitle, null);
|
navigateToThread(threadId, threadTitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void navigateToThread(final String threadId, final String threadTitle, final DirectThread backup) {
|
public void navigateToThread(final String threadId, final String threadTitle) {
|
||||||
if (threadId == null || threadTitle == null) return;
|
if (threadId == null || threadTitle == null) return;
|
||||||
currentNavControllerLiveData.observe(this, new Observer<NavController>() {
|
currentNavControllerLiveData.observe(this, new Observer<NavController>() {
|
||||||
@Override
|
@Override
|
||||||
@ -594,7 +603,7 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage
|
|||||||
// need handler.post() to wait for the fragment manager to be ready to navigate
|
// need handler.post() to wait for the fragment manager to be ready to navigate
|
||||||
new Handler().post(() -> {
|
new Handler().post(() -> {
|
||||||
final DirectMessageInboxFragmentDirections.ActionInboxToThread action = DirectMessageInboxFragmentDirections
|
final DirectMessageInboxFragmentDirections.ActionInboxToThread action = DirectMessageInboxFragmentDirections
|
||||||
.actionInboxToThread(threadId, threadTitle, backup);
|
.actionInboxToThread(threadId, threadTitle);
|
||||||
navController.navigate(action);
|
navController.navigate(action);
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
@ -607,7 +616,7 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage
|
|||||||
@Nullable final Bundle arguments) {
|
@Nullable final Bundle arguments) {
|
||||||
if (destination.getId() == R.id.directMessagesInboxFragment) {
|
if (destination.getId() == R.id.directMessagesInboxFragment) {
|
||||||
final DirectMessageInboxFragmentDirections.ActionInboxToThread action = DirectMessageInboxFragmentDirections
|
final DirectMessageInboxFragmentDirections.ActionInboxToThread action = DirectMessageInboxFragmentDirections
|
||||||
.actionInboxToThread(threadId, threadTitle, backup);
|
.actionInboxToThread(threadId, threadTitle);
|
||||||
controller.navigate(action);
|
controller.navigate(action);
|
||||||
controller.removeOnDestinationChangedListener(this);
|
controller.removeOnDestinationChangedListener(this);
|
||||||
}
|
}
|
||||||
|
@ -257,7 +257,7 @@ public class DirectMessageInboxFragment extends Fragment implements SwipeRefresh
|
|||||||
navigating = true;
|
navigating = true;
|
||||||
if (isAdded()) {
|
if (isAdded()) {
|
||||||
final DirectMessageInboxFragmentDirections.ActionInboxToThread directions = DirectMessageInboxFragmentDirections
|
final DirectMessageInboxFragmentDirections.ActionInboxToThread directions = DirectMessageInboxFragmentDirections
|
||||||
.actionInboxToThread(thread.getThreadId(), thread.getThreadTitle(), thread);
|
.actionInboxToThread(thread.getThreadId(), thread.getThreadTitle());
|
||||||
NavHostFragment.findNavController(this).navigate(directions);
|
NavHostFragment.findNavController(this).navigate(directions);
|
||||||
}
|
}
|
||||||
navigating = false;
|
navigating = false;
|
||||||
|
@ -81,7 +81,6 @@ public class DirectMessageSettingsFragment extends Fragment implements ConfirmDi
|
|||||||
final AppStateViewModel appStateViewModel = new ViewModelProvider(fragmentActivity).get(AppStateViewModel.class);
|
final AppStateViewModel appStateViewModel = new ViewModelProvider(fragmentActivity).get(AppStateViewModel.class);
|
||||||
viewModel = new ViewModelProvider(this, new DirectSettingsViewModelFactory(fragmentActivity.getApplication(),
|
viewModel = new ViewModelProvider(this, new DirectSettingsViewModelFactory(fragmentActivity.getApplication(),
|
||||||
args.getThreadId(),
|
args.getThreadId(),
|
||||||
args.getBackup(),
|
|
||||||
args.getPending(),
|
args.getPending(),
|
||||||
appStateViewModel.getCurrentUser()))
|
appStateViewModel.getCurrentUser()))
|
||||||
.get(DirectSettingsViewModel.class);
|
.get(DirectSettingsViewModel.class);
|
||||||
@ -350,8 +349,7 @@ public class DirectMessageSettingsFragment extends Fragment implements ConfirmDi
|
|||||||
(position, user, selected) -> {
|
(position, user, selected) -> {
|
||||||
if (!TextUtils.isEmpty(user.getFbId())) {
|
if (!TextUtils.isEmpty(user.getFbId())) {
|
||||||
Utils.openURL(context, "https://facebook.com/" + user.getFbId());
|
Utils.openURL(context, "https://facebook.com/" + user.getFbId());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
final ProfileNavGraphDirections.ActionGlobalProfileFragment directions = ProfileNavGraphDirections
|
final ProfileNavGraphDirections.ActionGlobalProfileFragment directions = ProfileNavGraphDirections
|
||||||
.actionGlobalProfileFragment()
|
.actionGlobalProfileFragment()
|
||||||
.setUsername("@" + user.getUsername());
|
.setUsername("@" + user.getUsername());
|
||||||
|
@ -329,7 +329,6 @@ public class DirectMessageThreadFragment extends Fragment implements DirectReact
|
|||||||
final DirectMessageThreadFragmentArgs fragmentArgs = DirectMessageThreadFragmentArgs.fromBundle(arguments);
|
final DirectMessageThreadFragmentArgs fragmentArgs = DirectMessageThreadFragmentArgs.fromBundle(arguments);
|
||||||
viewModel = new ViewModelProvider(this, new DirectThreadViewModelFactory(fragmentActivity.getApplication(),
|
viewModel = new ViewModelProvider(this, new DirectThreadViewModelFactory(fragmentActivity.getApplication(),
|
||||||
fragmentArgs.getThreadId(),
|
fragmentArgs.getThreadId(),
|
||||||
fragmentArgs.getBackup(),
|
|
||||||
fragmentArgs.getPending(),
|
fragmentArgs.getPending(),
|
||||||
appStateViewModel.getCurrentUser()))
|
appStateViewModel.getCurrentUser()))
|
||||||
.get(DirectThreadViewModel.class);
|
.get(DirectThreadViewModel.class);
|
||||||
@ -379,7 +378,7 @@ public class DirectMessageThreadFragment extends Fragment implements DirectReact
|
|||||||
final int itemId = item.getItemId();
|
final int itemId = item.getItemId();
|
||||||
if (itemId == R.id.info) {
|
if (itemId == R.id.info) {
|
||||||
final DirectMessageThreadFragmentDirections.ActionThreadToSettings directions = DirectMessageThreadFragmentDirections
|
final DirectMessageThreadFragmentDirections.ActionThreadToSettings directions = DirectMessageThreadFragmentDirections
|
||||||
.actionThreadToSettings(viewModel.getThreadId(), null, null);
|
.actionThreadToSettings(viewModel.getThreadId(), null);
|
||||||
final Boolean pending = viewModel.isPending().getValue();
|
final Boolean pending = viewModel.isPending().getValue();
|
||||||
directions.setPending(pending == null ? false : pending);
|
directions.setPending(pending == null ? false : pending);
|
||||||
NavHostFragment.findNavController(this).navigate(directions);
|
NavHostFragment.findNavController(this).navigate(directions);
|
||||||
@ -464,6 +463,12 @@ public class DirectMessageThreadFragment extends Fragment implements DirectReact
|
|||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
viewModel.deleteThreadIfRequired();
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressLint("UnsafeExperimentalUsageError")
|
@SuppressLint("UnsafeExperimentalUsageError")
|
||||||
private void cleanup() {
|
private void cleanup() {
|
||||||
if (prevTitleRunnable != null) {
|
if (prevTitleRunnable != null) {
|
||||||
|
@ -163,7 +163,7 @@ public class DirectPendingInboxFragment extends Fragment implements SwipeRefresh
|
|||||||
navigating = true;
|
navigating = true;
|
||||||
if (isAdded()) {
|
if (isAdded()) {
|
||||||
final DirectPendingInboxFragmentDirections.ActionPendingInboxToThread directions = DirectPendingInboxFragmentDirections
|
final DirectPendingInboxFragmentDirections.ActionPendingInboxToThread directions = DirectPendingInboxFragmentDirections
|
||||||
.actionPendingInboxToThread(thread.getThreadId(), thread.getThreadTitle(), thread);
|
.actionPendingInboxToThread(thread.getThreadId(), thread.getThreadTitle());
|
||||||
directions.setPending(true);
|
directions.setPending(true);
|
||||||
NavHostFragment.findNavController(this).navigate(directions);
|
NavHostFragment.findNavController(this).navigate(directions);
|
||||||
}
|
}
|
||||||
|
@ -74,6 +74,8 @@ import awais.instagrabber.dialogs.PostsLayoutPreferencesDialogFragment;
|
|||||||
import awais.instagrabber.dialogs.ProfilePicDialogFragment;
|
import awais.instagrabber.dialogs.ProfilePicDialogFragment;
|
||||||
import awais.instagrabber.fragments.PostViewV2Fragment;
|
import awais.instagrabber.fragments.PostViewV2Fragment;
|
||||||
import awais.instagrabber.interfaces.FetchListener;
|
import awais.instagrabber.interfaces.FetchListener;
|
||||||
|
import awais.instagrabber.managers.DirectMessagesManager;
|
||||||
|
import awais.instagrabber.managers.InboxManager;
|
||||||
import awais.instagrabber.models.HighlightModel;
|
import awais.instagrabber.models.HighlightModel;
|
||||||
import awais.instagrabber.models.PostsLayoutPreferences;
|
import awais.instagrabber.models.PostsLayoutPreferences;
|
||||||
import awais.instagrabber.models.StoryModel;
|
import awais.instagrabber.models.StoryModel;
|
||||||
@ -1073,7 +1075,12 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
profileDetailsBinding.btnDM.setEnabled(true);
|
profileDetailsBinding.btnDM.setEnabled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fragmentActivity.navigateToThread(thread.getThreadId(), profileModel.getUsername(), thread);
|
final InboxManager inboxManager = DirectMessagesManager.getInstance().getInboxManager();
|
||||||
|
if (!inboxManager.containsThread(thread.getThreadId())) {
|
||||||
|
thread.setTemp(true);
|
||||||
|
inboxManager.addThread(thread, 0);
|
||||||
|
}
|
||||||
|
fragmentActivity.navigateToThread(thread.getThreadId(), profileModel.getUsername());
|
||||||
profileDetailsBinding.btnDM.setEnabled(true);
|
profileDetailsBinding.btnDM.setEnabled(true);
|
||||||
}).execute();
|
}).execute();
|
||||||
});
|
});
|
||||||
|
@ -74,9 +74,8 @@ public final class DirectMessagesManager {
|
|||||||
|
|
||||||
public ThreadManager getThreadManager(@NonNull final String threadId,
|
public ThreadManager getThreadManager(@NonNull final String threadId,
|
||||||
final boolean pending,
|
final boolean pending,
|
||||||
final DirectThread backup,
|
|
||||||
@NonNull final User currentUser,
|
@NonNull final User currentUser,
|
||||||
@NonNull final ContentResolver contentResolver) {
|
@NonNull final ContentResolver contentResolver) {
|
||||||
return ThreadManager.getInstance(threadId, pending, backup, currentUser, contentResolver);
|
return ThreadManager.getInstance(threadId, pending, currentUser, contentResolver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ import java.util.Collections;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -357,4 +358,15 @@ public final class InboxManager {
|
|||||||
public void setPendingRequestsTotal(final int total) {
|
public void setPendingRequestsTotal(final int total) {
|
||||||
pendingRequestsTotal.postValue(total);
|
pendingRequestsTotal.postValue(total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean containsThread(final String threadId) {
|
||||||
|
if (threadId == null) return false;
|
||||||
|
synchronized (this.inbox) {
|
||||||
|
final DirectInbox currentDirectInbox = getCurrentDirectInbox();
|
||||||
|
if (currentDirectInbox == null) return false;
|
||||||
|
final List<DirectThread> threads = currentDirectInbox.getThreads();
|
||||||
|
if (threads == null) return false;
|
||||||
|
return threads.stream().anyMatch(thread -> Objects.equals(thread.getThreadId(), threadId));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,6 @@ public final class ThreadManager {
|
|||||||
|
|
||||||
public static ThreadManager getInstance(@NonNull final String threadId,
|
public static ThreadManager getInstance(@NonNull final String threadId,
|
||||||
final boolean pending,
|
final boolean pending,
|
||||||
final DirectThread backup,
|
|
||||||
@NonNull final User currentUser,
|
@NonNull final User currentUser,
|
||||||
@NonNull final ContentResolver contentResolver) {
|
@NonNull final ContentResolver contentResolver) {
|
||||||
ThreadManager instance = INSTANCE_MAP.get(threadId);
|
ThreadManager instance = INSTANCE_MAP.get(threadId);
|
||||||
@ -131,7 +130,7 @@ public final class ThreadManager {
|
|||||||
synchronized (LOCK) {
|
synchronized (LOCK) {
|
||||||
instance = INSTANCE_MAP.get(threadId);
|
instance = INSTANCE_MAP.get(threadId);
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
instance = new ThreadManager(threadId, pending, backup, currentUser, contentResolver);
|
instance = new ThreadManager(threadId, pending, currentUser, contentResolver);
|
||||||
INSTANCE_MAP.put(threadId, instance);
|
INSTANCE_MAP.put(threadId, instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -145,7 +144,6 @@ public final class ThreadManager {
|
|||||||
|
|
||||||
private ThreadManager(@NonNull final String threadId,
|
private ThreadManager(@NonNull final String threadId,
|
||||||
final boolean pending,
|
final boolean pending,
|
||||||
final DirectThread backup,
|
|
||||||
@NonNull final User currentUser,
|
@NonNull final User currentUser,
|
||||||
@NonNull final ContentResolver contentResolver) {
|
@NonNull final ContentResolver contentResolver) {
|
||||||
final DirectMessagesManager messagesManager = DirectMessagesManager.getInstance();
|
final DirectMessagesManager messagesManager = DirectMessagesManager.getInstance();
|
||||||
@ -164,17 +162,17 @@ public final class ThreadManager {
|
|||||||
service = DirectMessagesService.getInstance(csrfToken, viewerId, deviceUuid);
|
service = DirectMessagesService.getInstance(csrfToken, viewerId, deviceUuid);
|
||||||
mediaService = MediaService.getInstance(deviceUuid, csrfToken, viewerId);
|
mediaService = MediaService.getInstance(deviceUuid, csrfToken, viewerId);
|
||||||
friendshipService = FriendshipService.getInstance(deviceUuid, csrfToken, viewerId);
|
friendshipService = FriendshipService.getInstance(deviceUuid, csrfToken, viewerId);
|
||||||
setupTransformations(backup);
|
setupTransformations();
|
||||||
// fetchChats();
|
// fetchChats();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void moveFromPending() {
|
public void moveFromPending() {
|
||||||
final DirectMessagesManager messagesManager = DirectMessagesManager.getInstance();
|
final DirectMessagesManager messagesManager = DirectMessagesManager.getInstance();
|
||||||
this.inboxManager = messagesManager.getInboxManager();
|
this.inboxManager = messagesManager.getInboxManager();
|
||||||
setupTransformations(null);
|
setupTransformations();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupTransformations(final DirectThread backup) {
|
private void setupTransformations() {
|
||||||
// Transformations
|
// Transformations
|
||||||
thread = distinctUntilChanged(map(inboxManager.getInbox(), inboxResource -> {
|
thread = distinctUntilChanged(map(inboxManager.getInbox(), inboxResource -> {
|
||||||
if (inboxResource == null) {
|
if (inboxResource == null) {
|
||||||
@ -188,7 +186,7 @@ public final class ThreadManager {
|
|||||||
final DirectThread thread = threads.stream()
|
final DirectThread thread = threads.stream()
|
||||||
.filter(t -> t.getThreadId().equals(threadId))
|
.filter(t -> t.getThreadId().equals(threadId))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(backup);
|
.orElse(null);
|
||||||
if (thread != null) {
|
if (thread != null) {
|
||||||
cursor = thread.getOldestCursor();
|
cursor = thread.getOldestCursor();
|
||||||
hasOlder = thread.hasOlder();
|
hasOlder = thread.hasOlder();
|
||||||
|
@ -45,6 +45,7 @@ public class DirectThread implements Serializable, Cloneable {
|
|||||||
private boolean approvalRequiredForNewMembers;
|
private boolean approvalRequiredForNewMembers;
|
||||||
private int inputMode;
|
private int inputMode;
|
||||||
private final List<ThreadContext> threadContextItems;
|
private final List<ThreadContext> threadContextItems;
|
||||||
|
private boolean isTemp;
|
||||||
|
|
||||||
public DirectThread(final String threadId,
|
public DirectThread(final String threadId,
|
||||||
final String threadV2Id,
|
final String threadV2Id,
|
||||||
@ -292,6 +293,14 @@ public class DirectThread implements Serializable, Cloneable {
|
|||||||
return threadContextItems;
|
return threadContextItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isTemp() {
|
||||||
|
return isTemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTemp(final boolean isTemp) {
|
||||||
|
this.isTemp = isTemp;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public DirectItem getFirstDirectItem() {
|
public DirectItem getFirstDirectItem() {
|
||||||
DirectItem firstItem = null;
|
DirectItem firstItem = null;
|
||||||
|
@ -45,7 +45,6 @@ public class DirectSettingsViewModel extends AndroidViewModel {
|
|||||||
|
|
||||||
public DirectSettingsViewModel(final Application application,
|
public DirectSettingsViewModel(final Application application,
|
||||||
@NonNull final String threadId,
|
@NonNull final String threadId,
|
||||||
final DirectThread backup,
|
|
||||||
final boolean pending,
|
final boolean pending,
|
||||||
@NonNull final User currentUser) {
|
@NonNull final User currentUser) {
|
||||||
super(application);
|
super(application);
|
||||||
@ -59,7 +58,7 @@ public class DirectSettingsViewModel extends AndroidViewModel {
|
|||||||
final ContentResolver contentResolver = application.getContentResolver();
|
final ContentResolver contentResolver = application.getContentResolver();
|
||||||
resources = getApplication().getResources();
|
resources = getApplication().getResources();
|
||||||
final DirectMessagesManager messagesManager = DirectMessagesManager.getInstance();
|
final DirectMessagesManager messagesManager = DirectMessagesManager.getInstance();
|
||||||
threadManager = messagesManager.getThreadManager(threadId, pending, backup, currentUser, contentResolver);
|
threadManager = messagesManager.getThreadManager(threadId, pending, currentUser, contentResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
@ -23,6 +23,7 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
import awais.instagrabber.customviews.emoji.Emoji;
|
import awais.instagrabber.customviews.emoji.Emoji;
|
||||||
import awais.instagrabber.managers.DirectMessagesManager;
|
import awais.instagrabber.managers.DirectMessagesManager;
|
||||||
|
import awais.instagrabber.managers.InboxManager;
|
||||||
import awais.instagrabber.managers.ThreadManager;
|
import awais.instagrabber.managers.ThreadManager;
|
||||||
import awais.instagrabber.models.Resource;
|
import awais.instagrabber.models.Resource;
|
||||||
import awais.instagrabber.repositories.responses.User;
|
import awais.instagrabber.repositories.responses.User;
|
||||||
@ -57,7 +58,6 @@ public class DirectThreadViewModel extends AndroidViewModel {
|
|||||||
|
|
||||||
public DirectThreadViewModel(@NonNull final Application application,
|
public DirectThreadViewModel(@NonNull final Application application,
|
||||||
@NonNull final String threadId,
|
@NonNull final String threadId,
|
||||||
final DirectThread backup,
|
|
||||||
final boolean pending,
|
final boolean pending,
|
||||||
@NonNull final User currentUser) {
|
@NonNull final User currentUser) {
|
||||||
super(application);
|
super(application);
|
||||||
@ -74,7 +74,7 @@ public class DirectThreadViewModel extends AndroidViewModel {
|
|||||||
contentResolver = application.getContentResolver();
|
contentResolver = application.getContentResolver();
|
||||||
recordingsDir = DirectoryUtils.getOutputMediaDirectory(application, "Recordings");
|
recordingsDir = DirectoryUtils.getOutputMediaDirectory(application, "Recordings");
|
||||||
final DirectMessagesManager messagesManager = DirectMessagesManager.getInstance();
|
final DirectMessagesManager messagesManager = DirectMessagesManager.getInstance();
|
||||||
threadManager = messagesManager.getThreadManager(threadId, pending, backup, currentUser, contentResolver);
|
threadManager = messagesManager.getThreadManager(threadId, pending, currentUser, contentResolver);
|
||||||
threadManager.fetchPendingRequests();
|
threadManager.fetchPendingRequests();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,4 +302,13 @@ public class DirectThreadViewModel extends AndroidViewModel {
|
|||||||
}
|
}
|
||||||
threadManager.markAsSeen(directItem);
|
threadManager.markAsSeen(directItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteThreadIfRequired() {
|
||||||
|
final DirectThread thread = getThread().getValue();
|
||||||
|
if (thread == null) return;
|
||||||
|
if (thread.isTemp() && (thread.getItems() == null || thread.getItems().isEmpty())) {
|
||||||
|
final InboxManager inboxManager = DirectMessagesManager.getInstance().getInboxManager();
|
||||||
|
inboxManager.removeThread(threadId);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,25 +7,21 @@ import androidx.lifecycle.ViewModel;
|
|||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
import awais.instagrabber.repositories.responses.User;
|
import awais.instagrabber.repositories.responses.User;
|
||||||
import awais.instagrabber.repositories.responses.directmessages.DirectThread;
|
|
||||||
import awais.instagrabber.viewmodels.DirectSettingsViewModel;
|
import awais.instagrabber.viewmodels.DirectSettingsViewModel;
|
||||||
|
|
||||||
public class DirectSettingsViewModelFactory implements ViewModelProvider.Factory {
|
public class DirectSettingsViewModelFactory implements ViewModelProvider.Factory {
|
||||||
|
|
||||||
private final Application application;
|
private final Application application;
|
||||||
private final String threadId;
|
private final String threadId;
|
||||||
private final DirectThread backup;
|
|
||||||
private final boolean pending;
|
private final boolean pending;
|
||||||
private final User currentUser;
|
private final User currentUser;
|
||||||
|
|
||||||
public DirectSettingsViewModelFactory(@NonNull final Application application,
|
public DirectSettingsViewModelFactory(@NonNull final Application application,
|
||||||
@NonNull final String threadId,
|
@NonNull final String threadId,
|
||||||
@NonNull final DirectThread backup,
|
|
||||||
final boolean pending,
|
final boolean pending,
|
||||||
@NonNull final User currentUser) {
|
@NonNull final User currentUser) {
|
||||||
this.application = application;
|
this.application = application;
|
||||||
this.threadId = threadId;
|
this.threadId = threadId;
|
||||||
this.backup = backup;
|
|
||||||
this.pending = pending;
|
this.pending = pending;
|
||||||
this.currentUser = currentUser;
|
this.currentUser = currentUser;
|
||||||
}
|
}
|
||||||
@ -34,6 +30,6 @@ public class DirectSettingsViewModelFactory implements ViewModelProvider.Factory
|
|||||||
@Override
|
@Override
|
||||||
public <T extends ViewModel> T create(@NonNull final Class<T> modelClass) {
|
public <T extends ViewModel> T create(@NonNull final Class<T> modelClass) {
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
return (T) new DirectSettingsViewModel(application, threadId, backup, pending, currentUser);
|
return (T) new DirectSettingsViewModel(application, threadId, pending, currentUser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,25 +7,21 @@ import androidx.lifecycle.ViewModel;
|
|||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
import awais.instagrabber.repositories.responses.User;
|
import awais.instagrabber.repositories.responses.User;
|
||||||
import awais.instagrabber.repositories.responses.directmessages.DirectThread;
|
|
||||||
import awais.instagrabber.viewmodels.DirectThreadViewModel;
|
import awais.instagrabber.viewmodels.DirectThreadViewModel;
|
||||||
|
|
||||||
public class DirectThreadViewModelFactory implements ViewModelProvider.Factory {
|
public class DirectThreadViewModelFactory implements ViewModelProvider.Factory {
|
||||||
|
|
||||||
private final Application application;
|
private final Application application;
|
||||||
private final String threadId;
|
private final String threadId;
|
||||||
private final DirectThread backup;
|
|
||||||
private final boolean pending;
|
private final boolean pending;
|
||||||
private final User currentUser;
|
private final User currentUser;
|
||||||
|
|
||||||
public DirectThreadViewModelFactory(@NonNull final Application application,
|
public DirectThreadViewModelFactory(@NonNull final Application application,
|
||||||
@NonNull final String threadId,
|
@NonNull final String threadId,
|
||||||
final DirectThread backup,
|
|
||||||
final boolean pending,
|
final boolean pending,
|
||||||
@NonNull final User currentUser) {
|
@NonNull final User currentUser) {
|
||||||
this.application = application;
|
this.application = application;
|
||||||
this.threadId = threadId;
|
this.threadId = threadId;
|
||||||
this.backup = backup;
|
|
||||||
this.pending = pending;
|
this.pending = pending;
|
||||||
this.currentUser = currentUser;
|
this.currentUser = currentUser;
|
||||||
}
|
}
|
||||||
@ -34,6 +30,6 @@ public class DirectThreadViewModelFactory implements ViewModelProvider.Factory {
|
|||||||
@Override
|
@Override
|
||||||
public <T extends ViewModel> T create(@NonNull final Class<T> modelClass) {
|
public <T extends ViewModel> T create(@NonNull final Class<T> modelClass) {
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
return (T) new DirectThreadViewModel(application, threadId, backup, pending, currentUser);
|
return (T) new DirectThreadViewModel(application, threadId, pending, currentUser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,10 +122,6 @@
|
|||||||
android:name="pending"
|
android:name="pending"
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
app:argType="boolean" />
|
app:argType="boolean" />
|
||||||
<argument
|
|
||||||
android:name="backup"
|
|
||||||
app:nullable="true"
|
|
||||||
app:argType="awais.instagrabber.repositories.responses.directmessages.DirectThread" />
|
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_thread_to_settings"
|
android:id="@+id/action_thread_to_settings"
|
||||||
app:destination="@id/directMessagesSettingsFragment" />
|
app:destination="@id/directMessagesSettingsFragment" />
|
||||||
@ -156,11 +152,6 @@
|
|||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
app:argType="boolean" />
|
app:argType="boolean" />
|
||||||
|
|
||||||
<argument
|
|
||||||
android:name="backup"
|
|
||||||
app:nullable="true"
|
|
||||||
app:argType="awais.instagrabber.repositories.responses.directmessages.DirectThread" />
|
|
||||||
|
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_settings_to_inbox"
|
android:id="@+id/action_settings_to_inbox"
|
||||||
app:destination="@id/directMessagesInboxFragment"
|
app:destination="@id/directMessagesInboxFragment"
|
||||||
|
Loading…
Reference in New Issue
Block a user