1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-21 22:27:29 +00:00

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