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

restore dm button on profiles

This commit is contained in:
Austin Huang 2021-03-16 20:04:53 -04:00
parent 9bf72b2781
commit a55def53c5
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
14 changed files with 58 additions and 42 deletions

View File

@ -71,6 +71,7 @@ import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.models.IntentModel;
import awais.instagrabber.models.SuggestionModel;
import awais.instagrabber.models.enums.SuggestionType;
import awais.instagrabber.repositories.responses.directmessages.DirectThread;
import awais.instagrabber.services.ActivityCheckerService;
import awais.instagrabber.services.DMSyncAlarmReceiver;
import awais.instagrabber.utils.AppExecutors;
@ -573,10 +574,10 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage
private void showThread(@NonNull final Intent intent) {
final String threadId = intent.getStringExtra(Constants.DM_THREAD_ACTION_EXTRA_THREAD_ID);
final String threadTitle = intent.getStringExtra(Constants.DM_THREAD_ACTION_EXTRA_THREAD_TITLE);
navigateToThread(threadId, threadTitle);
navigateToThread(threadId, threadTitle, null);
}
public void navigateToThread(final String threadId, final String threadTitle) {
public void navigateToThread(final String threadId, final String threadTitle, final DirectThread backup) {
if (threadId == null || threadTitle == null) return;
currentNavControllerLiveData.observe(this, new Observer<NavController>() {
@Override
@ -590,7 +591,7 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage
// need handler.post() to wait for the fragment manager to be ready to navigate
new Handler().post(() -> {
final DirectMessageInboxFragmentDirections.ActionInboxToThread action = DirectMessageInboxFragmentDirections
.actionInboxToThread(threadId, threadTitle);
.actionInboxToThread(threadId, threadTitle, backup);
navController.navigate(action);
});
return;
@ -603,7 +604,7 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage
@Nullable final Bundle arguments) {
if (destination.getId() == R.id.directMessagesInboxFragment) {
final DirectMessageInboxFragmentDirections.ActionInboxToThread action = DirectMessageInboxFragmentDirections
.actionInboxToThread(threadId, threadTitle);
.actionInboxToThread(threadId, threadTitle, backup);
controller.navigate(action);
controller.removeOnDestinationChangedListener(this);
}

View File

@ -254,7 +254,7 @@ public class DirectMessageInboxFragment extends Fragment implements SwipeRefresh
navigating = true;
if (isAdded()) {
final DirectMessageInboxFragmentDirections.ActionInboxToThread directions = DirectMessageInboxFragmentDirections
.actionInboxToThread(thread.getThreadId(), thread.getThreadTitle());
.actionInboxToThread(thread.getThreadId(), thread.getThreadTitle(), thread);
NavHostFragment.findNavController(this).navigate(directions);
}
navigating = false;

View File

@ -79,6 +79,7 @@ public class DirectMessageSettingsFragment extends Fragment implements ConfirmDi
final AppStateViewModel appStateViewModel = new ViewModelProvider(fragmentActivity).get(AppStateViewModel.class);
viewModel = new ViewModelProvider(this, new DirectSettingsViewModelFactory(fragmentActivity.getApplication(),
args.getThreadId(),
args.getBackup(),
args.getPending(),
appStateViewModel.getCurrentUser()))
.get(DirectSettingsViewModel.class);

View File

@ -327,6 +327,7 @@ public class DirectMessageThreadFragment extends Fragment implements DirectReact
final DirectMessageThreadFragmentArgs fragmentArgs = DirectMessageThreadFragmentArgs.fromBundle(arguments);
viewModel = new ViewModelProvider(this, new DirectThreadViewModelFactory(fragmentActivity.getApplication(),
fragmentArgs.getThreadId(),
fragmentArgs.getBackup(),
fragmentArgs.getPending(),
appStateViewModel.getCurrentUser()))
.get(DirectThreadViewModel.class);
@ -376,7 +377,7 @@ public class DirectMessageThreadFragment extends Fragment implements DirectReact
final int itemId = item.getItemId();
if (itemId == R.id.info) {
final DirectMessageThreadFragmentDirections.ActionThreadToSettings directions = DirectMessageThreadFragmentDirections
.actionThreadToSettings(viewModel.getThreadId(), null);
.actionThreadToSettings(viewModel.getThreadId(), null, null);
final Boolean pending = viewModel.isPending().getValue();
directions.setPending(pending == null ? false : pending);
NavHostFragment.findNavController(this).navigate(directions);

View File

@ -163,7 +163,7 @@ public class DirectPendingInboxFragment extends Fragment implements SwipeRefresh
navigating = true;
if (isAdded()) {
final DirectPendingInboxFragmentDirections.ActionPendingInboxToThread directions = DirectPendingInboxFragmentDirections
.actionPendingInboxToThread(thread.getThreadId(), thread.getThreadTitle());
.actionPendingInboxToThread(thread.getThreadId(), thread.getThreadTitle(), thread);
directions.setPending(true);
NavHostFragment.findNavController(this).navigate(directions);
}

View File

@ -56,6 +56,7 @@ import awais.instagrabber.R;
import awais.instagrabber.activities.MainActivity;
import awais.instagrabber.adapters.FeedAdapterV2;
import awais.instagrabber.adapters.HighlightsAdapter;
import awais.instagrabber.asyncs.CreateThreadAction;
import awais.instagrabber.asyncs.ProfileFetcher;
import awais.instagrabber.asyncs.ProfilePostFetchService;
import awais.instagrabber.asyncs.UsernameFetcher;
@ -911,19 +912,18 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
private void setupButtons(final long profileId, final long myId) {
profileDetailsBinding.btnTagged.setVisibility(isReallyPrivate() ? View.GONE : View.VISIBLE);
profileDetailsBinding.btnDM.setVisibility(View.GONE); // temporary measure
if (isLoggedIn) {
if (Objects.equals(profileId, myId)) {
profileDetailsBinding.btnTagged.setVisibility(View.VISIBLE);
profileDetailsBinding.btnSaved.setVisibility(View.VISIBLE);
profileDetailsBinding.btnLiked.setVisibility(View.VISIBLE);
// profileDetailsBinding.btnDM.setVisibility(View.GONE);
profileDetailsBinding.btnDM.setVisibility(View.GONE);
profileDetailsBinding.btnSaved.setText(R.string.saved);
return;
}
profileDetailsBinding.btnSaved.setVisibility(View.GONE);
profileDetailsBinding.btnLiked.setVisibility(View.GONE);
// profileDetailsBinding.btnDM.setVisibility(View.VISIBLE);
profileDetailsBinding.btnDM.setVisibility(View.VISIBLE);
profileDetailsBinding.btnFollow.setVisibility(View.VISIBLE);
final Context context = getContext();
if (context == null) return;
@ -1081,27 +1081,18 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
PostItemType.TAGGED);
NavHostFragment.findNavController(this).navigate(action);
});
// profileDetailsBinding.btnDM.setOnClickListener(v -> {
// profileDetailsBinding.btnDM.setEnabled(false);
// new CreateThreadAction(cookie, profileModel.getPk(), thread -> {
// if (thread == null) {
// Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
// profileDetailsBinding.btnDM.setEnabled(true);
// return;
// }
// if (isAdded()) {
// final Bundle bundle = new Bundle();
// bundle.putString("threadId", thread.getThreadId());
// bundle.putString("title", thread.getThreadTitle());
// if (isAdded()) {
// final NavDirections action = ProfileFragmentDirections
// .actionProfileFragmentToDMThreadFragment(thread.getThreadId(), profileModel.getUsername());
// NavHostFragment.findNavController(this).navigate(action);
// }
// }
// profileDetailsBinding.btnDM.setEnabled(true);
// }).execute();
// });
profileDetailsBinding.btnDM.setOnClickListener(v -> {
profileDetailsBinding.btnDM.setEnabled(false);
new CreateThreadAction(cookie, profileModel.getPk(), thread -> {
if (thread == null) {
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
profileDetailsBinding.btnDM.setEnabled(true);
return;
}
fragmentActivity.navigateToThread(thread.getThreadId(), profileModel.getUsername(), thread);
profileDetailsBinding.btnDM.setEnabled(true);
}).execute();
});
profileDetailsBinding.mainProfileImage.setOnClickListener(v -> {
if (!hasStories) {
// show profile pic

View File

@ -74,8 +74,9 @@ public final class DirectMessagesManager {
public ThreadManager getThreadManager(@NonNull final String threadId,
final boolean pending,
final DirectThread backup,
@NonNull final User currentUser,
@NonNull final ContentResolver contentResolver) {
return ThreadManager.getInstance(threadId, pending, currentUser, contentResolver);
return ThreadManager.getInstance(threadId, pending, backup, currentUser, contentResolver);
}
}

View File

@ -122,6 +122,7 @@ public final class ThreadManager {
public static ThreadManager getInstance(@NonNull final String threadId,
final boolean pending,
final DirectThread backup,
@NonNull final User currentUser,
@NonNull final ContentResolver contentResolver) {
ThreadManager instance = INSTANCE_MAP.get(threadId);
@ -129,7 +130,7 @@ public final class ThreadManager {
synchronized (LOCK) {
instance = INSTANCE_MAP.get(threadId);
if (instance == null) {
instance = new ThreadManager(threadId, pending, currentUser, contentResolver);
instance = new ThreadManager(threadId, pending, backup, currentUser, contentResolver);
INSTANCE_MAP.put(threadId, instance);
}
}
@ -143,6 +144,7 @@ public final class ThreadManager {
private ThreadManager(@NonNull final String threadId,
final boolean pending,
final DirectThread backup,
@NonNull final User currentUser,
@NonNull final ContentResolver contentResolver) {
final DirectMessagesManager messagesManager = DirectMessagesManager.getInstance();
@ -161,17 +163,17 @@ public final class ThreadManager {
service = DirectMessagesService.getInstance(csrfToken, viewerId, deviceUuid);
mediaService = MediaService.getInstance(deviceUuid, csrfToken, viewerId);
friendshipService = FriendshipService.getInstance(deviceUuid, csrfToken, viewerId);
setupTransformations();
setupTransformations(backup);
// fetchChats();
}
public void moveFromPending() {
final DirectMessagesManager messagesManager = DirectMessagesManager.getInstance();
this.inboxManager = messagesManager.getInboxManager();
setupTransformations();
setupTransformations(null);
}
private void setupTransformations() {
private void setupTransformations(final DirectThread backup) {
// Transformations
thread = distinctUntilChanged(map(inboxManager.getInbox(), inboxResource -> {
if (inboxResource == null) {
@ -185,7 +187,7 @@ public final class ThreadManager {
final DirectThread thread = threads.stream()
.filter(t -> t.getThreadId().equals(threadId))
.findFirst()
.orElse(null);
.orElse(backup);
if (thread != null) {
cursor = thread.getOldestCursor();
hasOlder = thread.hasOlder();

View File

@ -45,6 +45,7 @@ public class DirectSettingsViewModel extends AndroidViewModel {
public DirectSettingsViewModel(final Application application,
@NonNull final String threadId,
final DirectThread backup,
final boolean pending,
@NonNull final User currentUser) {
super(application);
@ -58,7 +59,7 @@ public class DirectSettingsViewModel extends AndroidViewModel {
final ContentResolver contentResolver = application.getContentResolver();
resources = getApplication().getResources();
final DirectMessagesManager messagesManager = DirectMessagesManager.getInstance();
threadManager = messagesManager.getThreadManager(threadId, pending, currentUser, contentResolver);
threadManager = messagesManager.getThreadManager(threadId, pending, backup, currentUser, contentResolver);
}
@NonNull

View File

@ -53,6 +53,7 @@ public class DirectThreadViewModel extends AndroidViewModel {
public DirectThreadViewModel(@NonNull final Application application,
@NonNull final String threadId,
final DirectThread backup,
final boolean pending,
@NonNull final User currentUser) {
super(application);
@ -69,7 +70,7 @@ public class DirectThreadViewModel extends AndroidViewModel {
contentResolver = application.getContentResolver();
recordingsDir = DirectoryUtils.getOutputMediaDirectory(application, "Recordings");
final DirectMessagesManager messagesManager = DirectMessagesManager.getInstance();
threadManager = messagesManager.getThreadManager(threadId, pending, currentUser, contentResolver);
threadManager = messagesManager.getThreadManager(threadId, pending, backup, currentUser, contentResolver);
threadManager.fetchPendingRequests();
}

View File

@ -7,21 +7,25 @@ import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.repositories.responses.directmessages.DirectThread;
import awais.instagrabber.viewmodels.DirectSettingsViewModel;
public class DirectSettingsViewModelFactory implements ViewModelProvider.Factory {
private final Application application;
private final String threadId;
private final DirectThread backup;
private final boolean pending;
private final User currentUser;
public DirectSettingsViewModelFactory(@NonNull final Application application,
@NonNull final String threadId,
@NonNull final DirectThread backup,
final boolean pending,
@NonNull final User currentUser) {
this.application = application;
this.threadId = threadId;
this.backup = backup;
this.pending = pending;
this.currentUser = currentUser;
}
@ -30,6 +34,6 @@ public class DirectSettingsViewModelFactory implements ViewModelProvider.Factory
@Override
public <T extends ViewModel> T create(@NonNull final Class<T> modelClass) {
//noinspection unchecked
return (T) new DirectSettingsViewModel(application, threadId, pending, currentUser);
return (T) new DirectSettingsViewModel(application, threadId, backup, pending, currentUser);
}
}

View File

@ -7,21 +7,25 @@ import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.repositories.responses.directmessages.DirectThread;
import awais.instagrabber.viewmodels.DirectThreadViewModel;
public class DirectThreadViewModelFactory implements ViewModelProvider.Factory {
private final Application application;
private final String threadId;
private final DirectThread backup;
private final boolean pending;
private final User currentUser;
public DirectThreadViewModelFactory(@NonNull final Application application,
@NonNull final String threadId,
final DirectThread backup,
final boolean pending,
@NonNull final User currentUser) {
this.application = application;
this.threadId = threadId;
this.backup = backup;
this.pending = pending;
this.currentUser = currentUser;
}
@ -30,6 +34,6 @@ public class DirectThreadViewModelFactory implements ViewModelProvider.Factory {
@Override
public <T extends ViewModel> T create(@NonNull final Class<T> modelClass) {
//noinspection unchecked
return (T) new DirectThreadViewModel(application, threadId, pending, currentUser);
return (T) new DirectThreadViewModel(application, threadId, backup, pending, currentUser);
}
}

View File

@ -108,7 +108,7 @@ public class DirectMessagesService extends BaseService {
final String cursor) {
final ImmutableMap.Builder<String, Object> queryMapBuilder = ImmutableMap.<String, Object>builder()
.put("visual_message_return_type", "unseen")
.put("limit", 10)
.put("limit", 20)
.put("direction", "older");
if (!TextUtils.isEmpty(cursor)) {
queryMapBuilder.put("cursor", cursor);

View File

@ -122,6 +122,10 @@
android:name="pending"
android:defaultValue="false"
app:argType="boolean" />
<argument
android:name="backup"
app:nullable="true"
app:argType="awais.instagrabber.repositories.responses.directmessages.DirectThread" />
<action
android:id="@+id/action_thread_to_settings"
app:destination="@id/directMessagesSettingsFragment" />
@ -152,6 +156,11 @@
android:defaultValue="false"
app:argType="boolean" />
<argument
android:name="backup"
app:nullable="true"
app:argType="awais.instagrabber.repositories.responses.directmessages.DirectThread" />
<action
android:id="@+id/action_settings_to_inbox"
app:destination="@id/directMessagesInboxFragment"