mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 14:47:29 +00:00
open on giphy & download voice; close #792
This commit is contained in:
parent
ac9b5385d2
commit
22a927e9e7
@ -543,6 +543,15 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder imple
|
||||
if (thread.getInputMode() != 1 && messageDirection == MessageDirection.OUTGOING) {
|
||||
builder.add(new DirectItemContextMenu.MenuItem(R.id.unsend, R.string.dms_inbox_unsend));
|
||||
}
|
||||
final DirectItemType itemType = item.getItemType();
|
||||
switch (itemType) {
|
||||
case ANIMATED_MEDIA:
|
||||
builder.add(new DirectItemContextMenu.MenuItem(R.id.detail, R.string.dms_inbox_giphy));
|
||||
break;
|
||||
case VOICE_MEDIA:
|
||||
builder.add(new DirectItemContextMenu.MenuItem(R.id.detail, R.string.action_download));
|
||||
break;
|
||||
}
|
||||
final boolean showReactions = thread.getInputMode() != 1 && allowReaction();
|
||||
final ImmutableList<DirectItemContextMenu.MenuItem> menuItems = builder.build();
|
||||
if (!showReactions && menuItems.isEmpty()) return;
|
||||
|
@ -30,6 +30,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MediatorLiveData;
|
||||
@ -57,6 +58,7 @@ import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import awais.instagrabber.ProfileNavGraphDirections;
|
||||
import awais.instagrabber.R;
|
||||
@ -86,6 +88,7 @@ import awais.instagrabber.fragments.PostViewV2Fragment;
|
||||
import awais.instagrabber.fragments.UserSearchFragment;
|
||||
import awais.instagrabber.fragments.UserSearchFragmentDirections;
|
||||
import awais.instagrabber.models.Resource;
|
||||
import awais.instagrabber.models.enums.DirectItemType;
|
||||
import awais.instagrabber.models.enums.MediaItemType;
|
||||
import awais.instagrabber.repositories.requests.StoryViewerOptions;
|
||||
import awais.instagrabber.repositories.responses.Media;
|
||||
@ -97,6 +100,7 @@ import awais.instagrabber.repositories.responses.directmessages.DirectItemVisual
|
||||
import awais.instagrabber.repositories.responses.directmessages.DirectThread;
|
||||
import awais.instagrabber.repositories.responses.directmessages.RankedRecipient;
|
||||
import awais.instagrabber.utils.AppExecutors;
|
||||
import awais.instagrabber.utils.DownloadUtils;
|
||||
import awais.instagrabber.utils.PermissionUtils;
|
||||
import awais.instagrabber.utils.ResponseBodyUtils;
|
||||
import awais.instagrabber.utils.TextUtils;
|
||||
@ -121,6 +125,7 @@ public class DirectMessageThreadFragment extends Fragment implements DirectReact
|
||||
private ConstraintLayout root;
|
||||
private boolean shouldRefresh = true;
|
||||
private List<DirectItemOrHeader> itemOrHeaders;
|
||||
private List<User> users;
|
||||
private FragmentDirectMessagesThreadBinding binding;
|
||||
private Tooltip tooltip;
|
||||
private float initialSendX;
|
||||
@ -258,6 +263,19 @@ public class DirectMessageThreadFragment extends Fragment implements DirectReact
|
||||
final NavController navController = NavHostFragment.findNavController(DirectMessageThreadFragment.this);
|
||||
navController.navigate(actionGlobalUserSearch);
|
||||
}
|
||||
if (itemId == R.id.detail) {
|
||||
final Context context = getContext();
|
||||
if (context == null) return;
|
||||
final DirectItemType itemType = item.getItemType();
|
||||
switch (itemType) {
|
||||
case ANIMATED_MEDIA:
|
||||
Utils.openURL(context, "https://giphy.com/gifs/" + item.getAnimatedMedia().getId());
|
||||
break;
|
||||
case VOICE_MEDIA:
|
||||
downloadItem(item.getVoiceMedia() == null ? null : item.getVoiceMedia().getMedia(), context);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
private final DirectItemLongClickListener directItemLongClickListener = position -> {
|
||||
@ -906,6 +924,7 @@ public class DirectMessageThreadFragment extends Fragment implements DirectReact
|
||||
itemsAdapter.setStateRestorationPolicy(RecyclerView.Adapter.StateRestorationPolicy.PREVENT_WHEN_EMPTY);
|
||||
binding.chats.setAdapter(itemsAdapter);
|
||||
registerDataObserver();
|
||||
users = thread.getUsers();
|
||||
final List<DirectItem> items = viewModel.getItems().getValue();
|
||||
if (items != null && itemsAdapter.getItems() != items) {
|
||||
submitItemsToAdapter(items);
|
||||
@ -1230,25 +1249,19 @@ public class DirectMessageThreadFragment extends Fragment implements DirectReact
|
||||
appExecutors.mainThread().execute(prevTitleRunnable, 1000);
|
||||
}
|
||||
|
||||
// private void downloadItem(final Context context) {
|
||||
// final DirectUser user = getUser(directItemModel.getUserId());
|
||||
// final DirectItemMediaModel selectedItem = directItemModel.getItemType() == DirectItemType.MEDIA
|
||||
// ? (DirectItemMediaModel) directItemModel.getMediaModel()
|
||||
// : ((DirectItemRavenMediaModel) directItemModel.getMediaModel()).getMedia();
|
||||
// final String url = selectedItem.getMediaType() == MediaItemType.MEDIA_TYPE_VIDEO
|
||||
// ? selectedItem.getVideoUrl()
|
||||
// : selectedItem.getThumbUrl();
|
||||
// if (url == null) {
|
||||
// Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
|
||||
// } else {
|
||||
// if (ContextCompat.checkSelfPermission(context, DownloadUtils.PERMS[0]) == PackageManager.PERMISSION_GRANTED) {
|
||||
// DownloadUtils.dmDownload(context, user != null ? user.getUsername() : "", selectedItem.getId(), url);
|
||||
// } else {
|
||||
// requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE);
|
||||
// }
|
||||
// Toast.makeText(context, R.string.downloader_downloading_media, Toast.LENGTH_SHORT).show();
|
||||
// }
|
||||
// }
|
||||
// currently ONLY for voice
|
||||
private void downloadItem(final Media media, final Context context) {
|
||||
if (media == null) {
|
||||
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
if (ContextCompat.checkSelfPermission(context, DownloadUtils.PERMS[0]) == PackageManager.PERMISSION_GRANTED) {
|
||||
DownloadUtils.download(context, media);
|
||||
} else {
|
||||
requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE);
|
||||
}
|
||||
Toast.makeText(context, R.string.downloader_downloading_media, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
// private void sendText(final String text, final String itemId, final boolean delete) {
|
||||
// DirectThreadBroadcaster.TextBroadcastOptions textOptions = null;
|
||||
@ -1339,14 +1352,14 @@ public class DirectMessageThreadFragment extends Fragment implements DirectReact
|
||||
// broadcaster.execute(broadcastOptions);
|
||||
// }
|
||||
|
||||
// @NonNull
|
||||
// private DirectUser getUser(final long userId) {
|
||||
// for (final DirectUser user : users) {
|
||||
// if (userId != user.getPk()) continue;
|
||||
// return user;
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
@NonNull
|
||||
private User getUser(final long userId) {
|
||||
for (final User user : users) {
|
||||
if (userId != user.getPk()) continue;
|
||||
return user;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// private void searchUsername(final String text) {
|
||||
// final Bundle bundle = new Bundle();
|
||||
|
@ -39,6 +39,7 @@ import java.util.regex.Pattern;
|
||||
import awais.instagrabber.R;
|
||||
import awais.instagrabber.models.StoryModel;
|
||||
import awais.instagrabber.models.enums.MediaItemType;
|
||||
import awais.instagrabber.repositories.responses.Audio;
|
||||
import awais.instagrabber.repositories.responses.Media;
|
||||
import awais.instagrabber.repositories.responses.User;
|
||||
import awais.instagrabber.repositories.responses.VideoVersion;
|
||||
@ -89,17 +90,17 @@ public final class DownloadUtils {
|
||||
return dir;
|
||||
}
|
||||
|
||||
public static void dmDownload(@NonNull final Context context,
|
||||
@Nullable final String username,
|
||||
final String modelId,
|
||||
final String url) {
|
||||
if (url == null) return;
|
||||
if (ContextCompat.checkSelfPermission(context, PERMS[0]) == PackageManager.PERMISSION_GRANTED) {
|
||||
dmDownloadImpl(context, username, modelId, url);
|
||||
} else if (context instanceof Activity) {
|
||||
ActivityCompat.requestPermissions((Activity) context, PERMS, 8020);
|
||||
}
|
||||
}
|
||||
// public static void dmDownload(@NonNull final Context context,
|
||||
// @Nullable final String username,
|
||||
// final String modelId,
|
||||
// final String url) {
|
||||
// if (url == null) return;
|
||||
// if (ContextCompat.checkSelfPermission(context, PERMS[0]) == PackageManager.PERMISSION_GRANTED) {
|
||||
// dmDownloadImpl(context, username, modelId, url);
|
||||
// } else if (context instanceof Activity) {
|
||||
// ActivityCompat.requestPermissions((Activity) context, PERMS, 8020);
|
||||
// }
|
||||
// }
|
||||
|
||||
private static void dmDownloadImpl(@NonNull final Context context,
|
||||
@Nullable final String username,
|
||||
@ -303,6 +304,17 @@ public final class DownloadUtils {
|
||||
map.put(url, file.getAbsolutePath());
|
||||
break;
|
||||
}
|
||||
case MEDIA_TYPE_VOICE: {
|
||||
final String url = getUrlOfType(media);
|
||||
String fileName = media.getId();
|
||||
final User user = media.getUser();
|
||||
if (user != null) {
|
||||
fileName = user.getUsername() + "_" + fileName;
|
||||
}
|
||||
final File file = getDownloadSaveFile(downloadDir, fileName, url);
|
||||
map.put(url, file.getAbsolutePath());
|
||||
break;
|
||||
}
|
||||
case MEDIA_TYPE_SLIDER:
|
||||
final List<Media> sliderItems = media.getCarouselMedia();
|
||||
for (int i = 0; i < sliderItems.size(); i++) {
|
||||
@ -338,6 +350,14 @@ public final class DownloadUtils {
|
||||
}
|
||||
return url;
|
||||
}
|
||||
case MEDIA_TYPE_VOICE: {
|
||||
final Audio audio = media.getAudio();
|
||||
String url = null;
|
||||
if (audio != null) {
|
||||
url = audio.getAudioSrc();
|
||||
}
|
||||
return url;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -3,5 +3,6 @@
|
||||
<item name="reply" type="id" />
|
||||
<item name="unsend" type="id" />
|
||||
<item name="forward" type="id" />
|
||||
<item name="detail" type="id" />
|
||||
<item name="pending_requests" type="id" />
|
||||
</resources>
|
@ -180,6 +180,7 @@
|
||||
<string name="dms_inbox_unlike">Unlike message</string>
|
||||
<string name="dms_inbox_unsend">Unsend message</string>
|
||||
<string name="dms_inbox_author">View author profile</string>
|
||||
<string name="dms_inbox_giphy">View on GIPHY</string>
|
||||
<string name="dms_inbox_shared_post">%s shared a post by @%s</string>
|
||||
<string name="dms_inbox_shared_image">%s shared an image</string>
|
||||
<string name="dms_inbox_shared_video">%s shared a video</string>
|
||||
|
Loading…
Reference in New Issue
Block a user