share profile (unfinished)

This commit is contained in:
Austin Huang 2021-06-24 13:01:23 -04:00
parent 38cc804a3f
commit 3032a388f0
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
2 changed files with 42 additions and 28 deletions

View File

@ -35,6 +35,7 @@ import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Observer; import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.NavBackStackEntry;
import androidx.navigation.NavController; import androidx.navigation.NavController;
import androidx.navigation.NavDirections; import androidx.navigation.NavDirections;
import androidx.navigation.fragment.NavHostFragment; import androidx.navigation.fragment.NavHostFragment;
@ -53,6 +54,7 @@ import java.util.Objects;
import java.util.Set; import java.util.Set;
import awais.instagrabber.R; import awais.instagrabber.R;
import awais.instagrabber.UserSearchNavGraphDirections;
import awais.instagrabber.activities.MainActivity; import awais.instagrabber.activities.MainActivity;
import awais.instagrabber.adapters.FeedAdapterV2; import awais.instagrabber.adapters.FeedAdapterV2;
import awais.instagrabber.adapters.HighlightsAdapter; import awais.instagrabber.adapters.HighlightsAdapter;
@ -67,6 +69,8 @@ import awais.instagrabber.db.repositories.FavoriteRepository;
import awais.instagrabber.dialogs.PostsLayoutPreferencesDialogFragment; 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.fragments.UserSearchFragment;
import awais.instagrabber.fragments.UserSearchFragmentDirections;
import awais.instagrabber.managers.DirectMessagesManager; import awais.instagrabber.managers.DirectMessagesManager;
import awais.instagrabber.managers.InboxManager; import awais.instagrabber.managers.InboxManager;
import awais.instagrabber.models.HighlightModel; import awais.instagrabber.models.HighlightModel;
@ -126,8 +130,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
private HighlightsViewModel highlightsViewModel; private HighlightsViewModel highlightsViewModel;
private MenuItem blockMenuItem, restrictMenuItem, chainingMenuItem; private MenuItem blockMenuItem, restrictMenuItem, chainingMenuItem;
private MenuItem muteStoriesMenuItem, mutePostsMenuItem, removeFollowerMenuItem; private MenuItem muteStoriesMenuItem, mutePostsMenuItem, removeFollowerMenuItem;
private MenuItem shareLinkMenuItem; private MenuItem shareLinkMenuItem, shareDmMenuItem;
// private MenuItem shareDmMenuItem;
private boolean accountIsUpdated = false; private boolean accountIsUpdated = false;
private boolean postsSetupDone = false; private boolean postsSetupDone = false;
private Set<Media> selectedFeedModels; private Set<Media> selectedFeedModels;
@ -141,7 +144,6 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
private ProfileFragmentViewModel viewModel; private ProfileFragmentViewModel viewModel;
private String csrfToken; private String csrfToken;
private String deviceUuid; private String deviceUuid;
private MutableLiveData<Object> backStackSavedStateCollectionLiveData;
private MutableLiveData<Object> backStackSavedStateResultLiveData; private MutableLiveData<Object> backStackSavedStateResultLiveData;
private final ServiceCallback<FriendshipChangeResponse> changeCb = new ServiceCallback<FriendshipChangeResponse>() { private final ServiceCallback<FriendshipChangeResponse> changeCb = new ServiceCallback<FriendshipChangeResponse>() {
@ -334,7 +336,6 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
} }
} }
// clear result // clear result
backStackSavedStateCollectionLiveData.postValue(null);
backStackSavedStateResultLiveData.postValue(null); backStackSavedStateResultLiveData.postValue(null);
}; };
@ -466,10 +467,10 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
if (shareLinkMenuItem != null) { if (shareLinkMenuItem != null) {
shareLinkMenuItem.setVisible(profileModel != null && !TextUtils.isEmpty(profileModel.getUsername())); shareLinkMenuItem.setVisible(profileModel != null && !TextUtils.isEmpty(profileModel.getUsername()));
} }
// shareDmMenuItem = menu.findItem(R.id.share_dm); shareDmMenuItem = menu.findItem(R.id.share_dm);
// if (shareDmMenuItem != null) { if (shareDmMenuItem != null) {
// shareDmMenuItem.setVisible(profileModel != null && profileModel.getPk() != 0L); shareDmMenuItem.setVisible(profileModel != null && profileModel.getPk() != 0L);
// } }
} }
@Override @Override
@ -582,21 +583,20 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
startActivity(Intent.createChooser(sharingIntent, null)); startActivity(Intent.createChooser(sharingIntent, null));
return true; return true;
} else if (itemId == R.id.share_dm) { } else if (itemId == R.id.share_dm) {
// final UserSearchNavGraphDirections.ActionGlobalUserSearch actionGlobalUserSearch = UserSearchFragmentDirections final UserSearchNavGraphDirections.ActionGlobalUserSearch actionGlobalUserSearch = UserSearchFragmentDirections
// .actionGlobalUserSearch() .actionGlobalUserSearch()
// .setTitle(getString(R.string.share)) .setTitle(getString(R.string.share))
// .setActionLabel(getString(R.string.send)) .setActionLabel(getString(R.string.send))
// .setShowGroups(true) .setShowGroups(true)
// .setMultiple(true) .setMultiple(true)
// .setSearchMode(UserSearchFragment.SearchMode.RAVEN); .setSearchMode(UserSearchFragment.SearchMode.RAVEN);
// final NavController navController = NavHostFragment.findNavController(ProfileFragment.this); final NavController navController = NavHostFragment.findNavController(ProfileFragment.this);
// try { try {
// navController.navigate(actionGlobalUserSearch); navController.navigate(actionGlobalUserSearch);
// } catch (Exception e) { } catch (Exception e) {
// Log.e(TAG, "setupShare: ", e); Log.e(TAG, "setupShare: ", e);
// } }
// return true; return true;
return false;
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
@ -608,6 +608,17 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
fetchProfileDetails(); fetchProfileDetails();
} }
@Override
public void onResume() {
super.onResume();
final NavController navController = NavHostFragment.findNavController(this);
final NavBackStackEntry backStackEntry = navController.getCurrentBackStackEntry();
if (backStackEntry != null) {
backStackSavedStateResultLiveData = backStackEntry.getSavedStateHandle().getLiveData("result");
backStackSavedStateResultLiveData.observe(getViewLifecycleOwner(), backStackSavedStateObserver);
}
}
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
@ -1061,9 +1072,9 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
if (shareLinkMenuItem != null) { if (shareLinkMenuItem != null) {
shareLinkMenuItem.setVisible(!TextUtils.isEmpty(profileModel.getUsername())); shareLinkMenuItem.setVisible(!TextUtils.isEmpty(profileModel.getUsername()));
} }
// if (shareDmMenuItem != null) { if (shareDmMenuItem != null) {
// shareDmMenuItem.setVisible(profileModel.getPk() != 0L); shareDmMenuItem.setVisible(profileModel.getPk() != 0L);
// } }
} }
} }

View File

@ -11,6 +11,7 @@ import awais.instagrabber.managers.DirectMessagesManager
import awais.instagrabber.models.HighlightModel import awais.instagrabber.models.HighlightModel
import awais.instagrabber.models.Resource import awais.instagrabber.models.Resource
import awais.instagrabber.models.StoryModel import awais.instagrabber.models.StoryModel
import awais.instagrabber.models.enums.BroadcastItemType
import awais.instagrabber.models.enums.FavoriteType import awais.instagrabber.models.enums.FavoriteType
import awais.instagrabber.repositories.requests.StoryViewerOptions import awais.instagrabber.repositories.requests.StoryViewerOptions
import awais.instagrabber.repositories.responses.User import awais.instagrabber.repositories.responses.User
@ -212,14 +213,16 @@ class ProfileFragmentViewModel(
if (messageManager == null) { if (messageManager == null) {
messageManager = DirectMessagesManager messageManager = DirectMessagesManager
} }
// messageManager?.sendMedia(result, mediaId, BroadcastItemType.PROFILE, viewModelScope) val mediaId = profile.value?.data?.pk ?: return
messageManager?.sendMedia(result, mediaId.toString(10), BroadcastItemType.PROFILE, viewModelScope)
} }
fun shareDm(recipients: Set<RankedRecipient>) { fun shareDm(recipients: Set<RankedRecipient>) {
if (messageManager == null) { if (messageManager == null) {
messageManager = DirectMessagesManager messageManager = DirectMessagesManager
} }
// messageManager?.sendMedia(recipients, mediaId, BroadcastItemType.PROFILE, viewModelScope) val mediaId = profile.value?.data?.pk ?: return
messageManager?.sendMedia(recipients, mediaId.toString(10), BroadcastItemType.PROFILE, viewModelScope)
} }
} }