diff --git a/app/build.gradle b/app/build.gradle index a54947b2..02c57fe8 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,7 +10,7 @@ android { targetSdkVersion 29 versionCode 27 - versionName '16.6-a3' + versionName '16.6-a4' multiDexEnabled true diff --git a/app/src/main/java/awais/instagrabber/activities/DirectMessagesUserInbox.java b/app/src/main/java/awais/instagrabber/activities/DirectMessagesUserInbox.java index 2fe38652..6625727d 100755 --- a/app/src/main/java/awais/instagrabber/activities/DirectMessagesUserInbox.java +++ b/app/src/main/java/awais/instagrabber/activities/DirectMessagesUserInbox.java @@ -1,6 +1,7 @@ package awais.instagrabber.activities; import android.content.Intent; +import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; @@ -14,6 +15,7 @@ import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import awais.instagrabber.R; @@ -30,6 +32,7 @@ import awais.instagrabber.models.direct_messages.DirectItemModel; import awais.instagrabber.models.direct_messages.DirectItemModel.DirectItemMediaModel; import awais.instagrabber.models.direct_messages.InboxThreadModel; import awais.instagrabber.models.enums.DirectItemType; +import awais.instagrabber.models.enums.DownloadMethod; import awais.instagrabber.models.enums.MediaItemType; import awais.instagrabber.models.enums.UserInboxDirection; import awais.instagrabber.utils.Constants; @@ -48,7 +51,7 @@ public final class DirectMessagesUserInbox extends AppCompatActivity { @Override public void onResult(final InboxThreadModel result) { - if (result == null && "MINCURSOR".equals(endCursor) || "MAXCURSOR".equals(endCursor) || Utils.isEmpty(endCursor)) + if (result == null && ("MINCURSOR".equals(endCursor) || "MAXCURSOR".equals(endCursor) || Utils.isEmpty(endCursor))) Toast.makeText(DirectMessagesUserInbox.this, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); if (result != null) { @@ -97,29 +100,41 @@ public final class DirectMessagesUserInbox extends AppCompatActivity { } })); - dmsBinding.rvDirectMessages.setAdapter(messageItemsAdapter = new MessageItemsAdapter(directItemModels, users, v -> { - // todo do something with clicked message + messageItemsAdapter = new MessageItemsAdapter(directItemModels, users, v -> { Object tag = v.getTag(); if (tag instanceof DirectItemModel) { directItemModel = (DirectItemModel) tag; final String username = getUser(directItemModel.getUserId()).getUsername(); final DirectItemType itemType = directItemModel.getItemType(); - switch(itemType) { + switch (itemType) { + case LINK: + Intent linkIntent = new Intent(Intent.ACTION_VIEW); + linkIntent.setData(Uri.parse(directItemModel.getLinkModel().getLinkContext().getLinkUrl())); + startActivity(linkIntent); + break; case MEDIA_SHARE: startActivity(new Intent(this, PostViewer.class) .putExtra(Constants.EXTRAS_POST, new PostModel(directItemModel.getMediaModel().getCode()))); break; - /*case STORY_SHARE: - startActivity(new Intent(this, StoryViewer.class) - .putExtra(Constants.EXTRAS_USERNAME, directItemModel.getReelShare().getReelOwnerName()) - .putExtra(Constants.EXTRAS_STORIES, new StoryModel( + case MEDIA: + Utils.dmDownload(this, username, DownloadMethod.DOWNLOAD_DIRECT, Collections.singletonList(directItemModel.getMediaModel())); + Toast.makeText(v.getContext(), R.string.downloader_downloading_media, Toast.LENGTH_SHORT).show(); + break; + case REEL_SHARE: + case STORY_SHARE: + if (directItemModel.getReelShare() != null) + startActivity(new Intent(this, StoryViewer.class) + .putExtra(Constants.EXTRAS_USERNAME, directItemModel.getReelShare().getReelOwnerName()) + /*.putExtra(Constants.EXTRAS_STORIES, new StoryModel( directItemModel.getReelShare().getReelId(), directItemModel.getReelShare().getMedia() - )) - ); - break;*/ + ))*/ + ); + break; case TEXT: - searchUsername(username); + Utils.copyText(v.getContext(), directItemModel.getText()); + Toast.makeText(v.getContext(), R.string.clipboard_copied, Toast.LENGTH_SHORT).show(); + break; } /* @@ -127,9 +142,13 @@ public final class DirectMessagesUserInbox extends AppCompatActivity { .putExtra(Constants.EXTRAS_POST, new PostModel(tag.toString()))); */ } - }, (view, text, isHashtag) -> { - // todo mention click stuff - })); + }, + (view, text, isHashtag) -> { + }); + + dmsBinding.rvDirectMessages.setAdapter( + messageItemsAdapter + ); new UserInboxFetcher(threadModel.getThreadId(), UserInboxDirection.OLDER, null, fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } diff --git a/app/src/main/java/awais/instagrabber/adapters/MessageItemsAdapter.java b/app/src/main/java/awais/instagrabber/adapters/MessageItemsAdapter.java index 92bd29a4..46fb17c6 100755 --- a/app/src/main/java/awais/instagrabber/adapters/MessageItemsAdapter.java +++ b/app/src/main/java/awais/instagrabber/adapters/MessageItemsAdapter.java @@ -168,10 +168,6 @@ public final class MessageItemsAdapter extends RecyclerView.Adapter { - Utils.copyText(v.getContext(), holder.tvMessage.getText()); - Toast.makeText(v.getContext(), R.string.clipboard_copied, Toast.LENGTH_SHORT).show(); - }); break; case LINK: { diff --git a/app/src/main/java/awais/instagrabber/utils/Utils.java b/app/src/main/java/awais/instagrabber/utils/Utils.java index dc19f6b2..3fa5a87c 100755 --- a/app/src/main/java/awais/instagrabber/utils/Utils.java +++ b/app/src/main/java/awais/instagrabber/utils/Utils.java @@ -872,6 +872,51 @@ public final class Utils { Toast.makeText(context, R.string.error_creating_folders, Toast.LENGTH_SHORT).show(); } + public static void dmDownload(@NonNull final Context context, @Nullable final String username, final DownloadMethod method, + final List itemsToDownload) { + if (settingsHelper == null) settingsHelper = new SettingsHelper(context); + + if (itemsToDownload == null || itemsToDownload.size() < 1) return; + + if (ContextCompat.checkSelfPermission(context, Utils.PERMS[0]) == PackageManager.PERMISSION_GRANTED) + dmDownloadImpl(context, username, method, itemsToDownload); + else if (context instanceof Activity) + ActivityCompat.requestPermissions((Activity) context, Utils.PERMS, 8020); + } + + private static void dmDownloadImpl(@NonNull final Context context, @Nullable final String username, + final DownloadMethod method, final List itemsToDownload) { + File dir = new File(Environment.getExternalStorageDirectory(), "Download"); + + if (settingsHelper.getBoolean(FOLDER_SAVE_TO)) { + final String customPath = settingsHelper.getString(FOLDER_PATH); + if (!Utils.isEmpty(customPath)) dir = new File(customPath); + } + + if (settingsHelper.getBoolean(Constants.DOWNLOAD_USER_FOLDER) && !isEmpty(username)) + dir = new File(dir, username); + + if (dir.exists() || dir.mkdirs()) { + final Main main = method != DownloadMethod.DOWNLOAD_FEED && context instanceof Main ? (Main) context : null; + + final int itemsToDownloadSize = itemsToDownload.size(); + + final File finalDir = dir; + for (int i = itemsToDownloadSize - 1; i >= 0; i--) { + final DirectItemMediaModel selectedItem = itemsToDownload.get(i); + + if (main == null) { + new DownloadAsync(context, + selectedItem.getThumbUrl(), + getDownloadSaveFileDm(finalDir, selectedItem, ""), + null).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + + } + } + } else + Toast.makeText(context, R.string.error_creating_folders, Toast.LENGTH_SHORT).show(); + } + @NonNull private static File getDownloadSaveFile(final File finalDir, @NonNull final BasePostModel model, final String sliderPrefix) { final String displayUrl = model.getDisplayUrl(); @@ -879,6 +924,13 @@ public final class Utils { getExtensionFromModel(displayUrl, model)); } + @NonNull + private static File getDownloadSaveFileDm(final File finalDir, @NonNull final DirectItemMediaModel model, final String sliderPrefix) { + final String displayUrl = model.getThumbUrl(); + return new File(finalDir, model.getId() + sliderPrefix + + getExtensionFromModel(displayUrl, model)); + } + @NonNull public static String getExtensionFromModel(@NonNull final String url, final Object model) { final String extension; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 48107655..76977ce0 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -140,6 +140,7 @@ Download started Download completed Downloading post + Downloading media Downloading profile picture File downloaded in Downloads folder!