mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-04 14:17:30 +00:00
Add download dialog
This commit is contained in:
parent
3393166b51
commit
4579f2b37e
@ -216,7 +216,7 @@ public final class FeedAdapterV2 extends ListAdapter<FeedModel, RecyclerView.Vie
|
|||||||
|
|
||||||
void onCommentsClick(final FeedModel feedModel);
|
void onCommentsClick(final FeedModel feedModel);
|
||||||
|
|
||||||
void onDownloadClick(final FeedModel feedModel);
|
void onDownloadClick(final FeedModel feedModel, final int childPosition);
|
||||||
|
|
||||||
void onEmailClick(final String emailId);
|
void onEmailClick(final String emailId);
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ public class FeedItemCallbackAdapter implements FeedAdapterV2.FeedItemCallback {
|
|||||||
public void onCommentsClick(final FeedModel feedModel) {}
|
public void onCommentsClick(final FeedModel feedModel) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDownloadClick(final FeedModel feedModel) {}
|
public void onDownloadClick(final FeedModel feedModel, final int childPosition) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEmailClick(final String emailId) {}
|
public void onEmailClick(final String emailId) {}
|
||||||
|
@ -13,6 +13,7 @@ import awais.instagrabber.databinding.ItemFeedBottomBinding;
|
|||||||
import awais.instagrabber.databinding.ItemFeedTopBinding;
|
import awais.instagrabber.databinding.ItemFeedTopBinding;
|
||||||
import awais.instagrabber.models.FeedModel;
|
import awais.instagrabber.models.FeedModel;
|
||||||
import awais.instagrabber.models.ProfileModel;
|
import awais.instagrabber.models.ProfileModel;
|
||||||
|
import awais.instagrabber.models.enums.MediaItemType;
|
||||||
import awais.instagrabber.utils.TextUtils;
|
import awais.instagrabber.utils.TextUtils;
|
||||||
|
|
||||||
import static android.text.TextUtils.TruncateAt.END;
|
import static android.text.TextUtils.TruncateAt.END;
|
||||||
@ -43,7 +44,9 @@ public abstract class FeedItemViewHolder extends RecyclerView.ViewHolder {
|
|||||||
bottomBinding.tvPostDate.setText(feedModel.getPostDate());
|
bottomBinding.tvPostDate.setText(feedModel.getPostDate());
|
||||||
setupComments(feedModel);
|
setupComments(feedModel);
|
||||||
setupCaption(feedModel);
|
setupCaption(feedModel);
|
||||||
bottomBinding.btnDownload.setOnClickListener(v -> feedItemCallback.onDownloadClick(feedModel));
|
if (feedModel.getItemType() != MediaItemType.MEDIA_TYPE_SLIDER) {
|
||||||
|
bottomBinding.btnDownload.setOnClickListener(v -> feedItemCallback.onDownloadClick(feedModel, -1));
|
||||||
|
}
|
||||||
bindItem(feedModel);
|
bindItem(feedModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@ import awais.instagrabber.adapters.SliderItemsAdapter;
|
|||||||
import awais.instagrabber.databinding.ItemFeedSliderBinding;
|
import awais.instagrabber.databinding.ItemFeedSliderBinding;
|
||||||
import awais.instagrabber.models.FeedModel;
|
import awais.instagrabber.models.FeedModel;
|
||||||
import awais.instagrabber.models.PostChild;
|
import awais.instagrabber.models.PostChild;
|
||||||
import awais.instagrabber.models.enums.MediaItemType;
|
|
||||||
import awais.instagrabber.utils.Constants;
|
import awais.instagrabber.utils.Constants;
|
||||||
import awais.instagrabber.utils.NumberUtils;
|
import awais.instagrabber.utils.NumberUtils;
|
||||||
import awais.instagrabber.utils.Utils;
|
import awais.instagrabber.utils.Utils;
|
||||||
@ -86,66 +85,36 @@ public class FeedSliderViewHolder extends FeedItemViewHolder {
|
|||||||
final String text = (position + 1) + "/" + sliderItemLen;
|
final String text = (position + 1) + "/" + sliderItemLen;
|
||||||
binding.mediaCounter.setText(text);
|
binding.mediaCounter.setText(text);
|
||||||
setDimensions(binding.mediaList, sliderItems.get(position));
|
setDimensions(binding.mediaList, sliderItems.get(position));
|
||||||
|
binding.itemFeedBottom.btnDownload.setOnClickListener(v -> feedItemCallback.onDownloadClick(feedModel, position));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
setDimensions(binding.mediaList, sliderItems.get(0));
|
setDimensions(binding.mediaList, sliderItems.get(0));
|
||||||
|
binding.itemFeedBottom.btnDownload.setOnClickListener(v -> feedItemCallback.onDownloadClick(feedModel, 0));
|
||||||
// binding.mediaList.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
|
|
||||||
// private int prevPos = 0;
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void onPageSelected(final int position) {
|
|
||||||
// ViewerPostModel sliderItem = sliderItems.get(prevPos);
|
|
||||||
// if (sliderItem != null) {
|
|
||||||
// sliderItem.setSelected(false);
|
|
||||||
// if (sliderItem.getItemType() == MediaItemType.MEDIA_TYPE_VIDEO) {
|
|
||||||
// // stop playing prev video
|
|
||||||
// final ViewSwitcher prevChild = (ViewSwitcher) binding.mediaList.getChildAt(prevPos);
|
|
||||||
// if (prevChild == null || prevChild.getTag() == null || !(prevChild.getTag() instanceof SimpleExoPlayer)) {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// ((SimpleExoPlayer) prevChild.getTag()).setPlayWhenReady(false);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// sliderItem = sliderItems.get(position);
|
|
||||||
// if (sliderItem == null) return;
|
|
||||||
// sliderItem.setSelected(true);
|
|
||||||
// final String text = (position + 1) + "/" + sliderItemLen;
|
|
||||||
// binding.mediaCounter.setText(text);
|
|
||||||
// prevPos = position;
|
|
||||||
// if (sliderItem.getItemType() == MediaItemType.MEDIA_TYPE_VIDEO) {
|
|
||||||
// binding.itemFeedBottom.btnMute.setVisibility(View.VISIBLE);
|
|
||||||
// if (shouldAutoPlay) {
|
|
||||||
// autoPlay(position);
|
|
||||||
// }
|
|
||||||
// } else binding.itemFeedBottom.btnMute.setVisibility(View.GONE);
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
adapter.submitList(sliderItems);
|
adapter.submitList(sliderItems);
|
||||||
final View.OnClickListener muteClickListener = v -> {
|
// final View.OnClickListener muteClickListener = v -> {
|
||||||
final int currentItem = binding.mediaList.getCurrentItem();
|
// final int currentItem = binding.mediaList.getCurrentItem();
|
||||||
if (currentItem < 0 || currentItem >= binding.mediaList.getChildCount()) {
|
// if (currentItem < 0 || currentItem >= binding.mediaList.getChildCount()) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
final PostChild sliderItem = sliderItems.get(currentItem);
|
// final PostChild sliderItem = sliderItems.get(currentItem);
|
||||||
if (sliderItem.getItemType() != MediaItemType.MEDIA_TYPE_VIDEO) {
|
// if (sliderItem.getItemType() != MediaItemType.MEDIA_TYPE_VIDEO) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
final View currentView = binding.mediaList.getChildAt(currentItem);
|
// final View currentView = binding.mediaList.getChildAt(currentItem);
|
||||||
if (!(currentView instanceof ViewSwitcher)) {
|
// if (!(currentView instanceof ViewSwitcher)) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
final ViewSwitcher viewSwitcher = (ViewSwitcher) currentView;
|
// final ViewSwitcher viewSwitcher = (ViewSwitcher) currentView;
|
||||||
final Object tag = viewSwitcher.getTag();
|
// final Object tag = viewSwitcher.getTag();
|
||||||
if (!(tag instanceof SimpleExoPlayer)) {
|
// if (!(tag instanceof SimpleExoPlayer)) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
final SimpleExoPlayer player = (SimpleExoPlayer) tag;
|
// final SimpleExoPlayer player = (SimpleExoPlayer) tag;
|
||||||
final float intVol = player.getVolume() == 0f ? 1f : 0f;
|
// final float intVol = player.getVolume() == 0f ? 1f : 0f;
|
||||||
player.setVolume(intVol);
|
// player.setVolume(intVol);
|
||||||
// binding.itemFeedBottom.btnMute.setImageResource(intVol == 0f ? R.drawable.ic_volume_up_24 : R.drawable.ic_volume_off_24);
|
// // binding.itemFeedBottom.btnMute.setImageResource(intVol == 0f ? R.drawable.ic_volume_up_24 : R.drawable.ic_volume_off_24);
|
||||||
// Utils.sessionVolumeFull = intVol == 1f;
|
// // Utils.sessionVolumeFull = intVol == 1f;
|
||||||
};
|
// };
|
||||||
// final PostChild firstItem = sliderItems.get(0);
|
// final PostChild firstItem = sliderItems.get(0);
|
||||||
// if (firstItem.getItemType() == MediaItemType.MEDIA_TYPE_VIDEO) {
|
// if (firstItem.getItemType() == MediaItemType.MEDIA_TYPE_VIDEO) {
|
||||||
// binding.itemFeedBottom.btnMute.setVisibility(View.VISIBLE);
|
// binding.itemFeedBottom.btnMute.setVisibility(View.VISIBLE);
|
||||||
|
@ -1,310 +0,0 @@
|
|||||||
// package awais.instagrabber.asyncs;
|
|
||||||
//
|
|
||||||
// import android.content.ContentResolver;
|
|
||||||
// import android.content.Context;
|
|
||||||
// import android.content.Intent;
|
|
||||||
// import android.graphics.Bitmap;
|
|
||||||
// import android.graphics.BitmapFactory;
|
|
||||||
// import android.media.MediaMetadataRetriever;
|
|
||||||
// import android.media.MediaScannerConnection;
|
|
||||||
// import android.net.Uri;
|
|
||||||
// import android.os.AsyncTask;
|
|
||||||
// import android.os.Build;
|
|
||||||
// import android.util.Log;
|
|
||||||
//
|
|
||||||
// import androidx.annotation.NonNull;
|
|
||||||
// import androidx.annotation.Nullable;
|
|
||||||
// import androidx.core.content.FileProvider;
|
|
||||||
//
|
|
||||||
// import java.io.BufferedInputStream;
|
|
||||||
// import java.io.File;
|
|
||||||
// import java.io.FileOutputStream;
|
|
||||||
// import java.io.InputStream;
|
|
||||||
// import java.net.URL;
|
|
||||||
// import java.net.URLConnection;
|
|
||||||
// import java.util.HashMap;
|
|
||||||
// import java.util.Map;
|
|
||||||
//
|
|
||||||
// import awais.instagrabber.BuildConfig;
|
|
||||||
// import awais.instagrabber.R;
|
|
||||||
// import awais.instagrabber.utils.Utils;
|
|
||||||
//
|
|
||||||
// import static awais.instagrabber.utils.Utils.logCollector;
|
|
||||||
// import static awaisomereport.LogCollector.LogFile;
|
|
||||||
//
|
|
||||||
// public final class DownloadV2AsyncTask extends AsyncTask<Void, Float, File> {
|
|
||||||
// private static final String TAG = "DownloadAsync";
|
|
||||||
//
|
|
||||||
// // private final int currentNotificationId;
|
|
||||||
// // private final int initialNotificationId;
|
|
||||||
// // private final File outFile;
|
|
||||||
// // private final String url;
|
|
||||||
// // private final FetchListener<File> fetchListener;
|
|
||||||
// // private final NotificationCompat.Builder downloadNotif;
|
|
||||||
// private String shortCode, username;
|
|
||||||
// // private final NotificationManagerCompat notificationManager;
|
|
||||||
//
|
|
||||||
// public DownloadV2AsyncTask(@NonNull final Context context) {
|
|
||||||
// // this.shortCode = this.username = resources.getString(R.string.downloader_started);
|
|
||||||
//
|
|
||||||
// // @StringRes final int titleRes = R.string.downloader_downloading_post;
|
|
||||||
// // downloadNotif = new NotificationCompat.Builder(context, Constants.DOWNLOAD_CHANNEL_ID)
|
|
||||||
// // .setCategory(NotificationCompat.CATEGORY_STATUS)
|
|
||||||
// // .setSmallIcon(R.mipmap.ic_launcher)
|
|
||||||
// // .setContentText(shortCode == null ? username : shortCode)
|
|
||||||
// // .setOngoing(true)
|
|
||||||
// // .setProgress(100, 0, false)
|
|
||||||
// // .setAutoCancel(false)
|
|
||||||
// // .setOnlyAlertOnce(true)
|
|
||||||
// // .setContentTitle(resources.getString(titleRes));
|
|
||||||
// //
|
|
||||||
// // notificationManager = NotificationManagerCompat.from(context.getApplicationContext());
|
|
||||||
// // notificationManager.notify(currentNotificationId, downloadNotif.build());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // public DownloadV2AsyncTask setItems(final String shortCode, final String username) {
|
|
||||||
// // this.shortCode = shortCode;
|
|
||||||
// // this.username = username;
|
|
||||||
// // if (downloadNotif != null) downloadNotif.setContentText(this.shortCode == null ? this.username : this.shortCode);
|
|
||||||
// // return this;
|
|
||||||
// // }
|
|
||||||
//
|
|
||||||
// @Nullable
|
|
||||||
// @Override
|
|
||||||
// protected File doInBackground(final Void... voids) {
|
|
||||||
// try {
|
|
||||||
// final URLConnection urlConnection = new URL(url).openConnection();
|
|
||||||
// final long fileSize = Build.VERSION.SDK_INT >= 24 ? urlConnection.getContentLengthLong() :
|
|
||||||
// urlConnection.getContentLength();
|
|
||||||
// float totalRead = 0;
|
|
||||||
//
|
|
||||||
// try (final BufferedInputStream bis = new BufferedInputStream(urlConnection.getInputStream());
|
|
||||||
// final FileOutputStream fos = new FileOutputStream(outFile)) {
|
|
||||||
// final byte[] buffer = new byte[0x2000];
|
|
||||||
//
|
|
||||||
// int count;
|
|
||||||
// boolean deletedIPTC = false;
|
|
||||||
// while ((count = bis.read(buffer, 0, 0x2000)) != -1) {
|
|
||||||
// totalRead = totalRead + count;
|
|
||||||
//
|
|
||||||
// if (!deletedIPTC) {
|
|
||||||
// int iptcStart = -1;
|
|
||||||
// int fbmdStart = -1;
|
|
||||||
// int fbmdBytesLen = -1;
|
|
||||||
//
|
|
||||||
// for (int i = 0; i < buffer.length; ++i) {
|
|
||||||
// if (buffer[i] == (byte) 0xFF && buffer[i + 1] == (byte) 0xED)
|
|
||||||
// iptcStart = i;
|
|
||||||
// else if (buffer[i] == (byte) 'F' && buffer[i + 1] == (byte) 'B'
|
|
||||||
// && buffer[i + 2] == (byte) 'M' && buffer[i + 3] == (byte) 'D') {
|
|
||||||
// fbmdStart = i;
|
|
||||||
// fbmdBytesLen = buffer[i - 10] << 24 | (buffer[i - 9] & 0xFF) << 16 |
|
|
||||||
// (buffer[i - 8] & 0xFF) << 8 | (buffer[i - 7] & 0xFF) |
|
|
||||||
// (buffer[i - 6] & 0xFF);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (iptcStart != -1 && fbmdStart != -1 && fbmdBytesLen != -1) {
|
|
||||||
// final int fbmdDataLen = (iptcStart + (fbmdStart - iptcStart) + (fbmdBytesLen - iptcStart)) - 4;
|
|
||||||
//
|
|
||||||
// fos.write(buffer, 0, iptcStart);
|
|
||||||
// fos.write(buffer, fbmdDataLen + iptcStart, count - fbmdDataLen - iptcStart);
|
|
||||||
//
|
|
||||||
// publishProgress(totalRead * 100f / fileSize);
|
|
||||||
//
|
|
||||||
// deletedIPTC = true;
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// fos.write(buffer, 0, count);
|
|
||||||
// publishProgress(totalRead * 100f / fileSize);
|
|
||||||
// }
|
|
||||||
// fos.flush();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return outFile;
|
|
||||||
// } catch (final Exception e) {
|
|
||||||
// // if (logCollector != null)
|
|
||||||
// // logCollector.appendException(e, LogFile.ASYNC_DOWNLOADER, "doInBackground",
|
|
||||||
// // new Pair<>("context", context.get()),
|
|
||||||
// // new Pair<>("resources", resources),
|
|
||||||
// // new Pair<>("lastNotifId", initialNotificationId),
|
|
||||||
// // new Pair<>("downloadNotif", downloadNotif),
|
|
||||||
// // new Pair<>("currentNotifId", currentNotificationId),
|
|
||||||
// // new Pair<>("notificationManager", notificationManager));
|
|
||||||
// if (BuildConfig.DEBUG) Log.e(TAG, "", e);
|
|
||||||
// }
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// protected void onPreExecute() {
|
|
||||||
// // if (fetchListener != null) fetchListener.doBefore();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// protected void onProgressUpdate(@NonNull final Float... values) {
|
|
||||||
// // if (downloadNotif != null) {
|
|
||||||
// // downloadNotif.setProgress(100, values[0].intValue(), false);
|
|
||||||
// // notificationManager.notify(currentNotificationId, downloadNotif.build());
|
|
||||||
// // }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// protected void onPostExecute(final File result) {
|
|
||||||
// if (result != null) {
|
|
||||||
// // final Context context = this.context.get();
|
|
||||||
// // context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(result.getAbsoluteFile())));
|
|
||||||
// // MediaScannerConnection.scanFile(context, new String[]{result.getAbsolutePath()}, null, null);
|
|
||||||
// //
|
|
||||||
// // // if (notificationManager != null) {
|
|
||||||
// // final Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".provider", result);
|
|
||||||
// //
|
|
||||||
// // final ContentResolver contentResolver = context.getContentResolver();
|
|
||||||
// // Bitmap bitmap = null;
|
|
||||||
// // if (Utils.isImage(uri, contentResolver)) {
|
|
||||||
// // try (final InputStream inputStream = contentResolver.openInputStream(uri)) {
|
|
||||||
// // bitmap = BitmapFactory.decodeStream(inputStream);
|
|
||||||
// // } catch (final Exception e) {
|
|
||||||
// // if (logCollector != null)
|
|
||||||
// // logCollector.appendException(e, LogFile.ASYNC_DOWNLOADER, "onPostExecute::bitmap_1");
|
|
||||||
// // if (BuildConfig.DEBUG) Log.e(TAG, "", e);
|
|
||||||
// // }
|
|
||||||
// // }
|
|
||||||
// //
|
|
||||||
// // if (bitmap == null) {
|
|
||||||
// // final MediaMetadataRetriever retriever = new MediaMetadataRetriever();
|
|
||||||
// // try {
|
|
||||||
// // try {
|
|
||||||
// // retriever.setDataSource(context, uri);
|
|
||||||
// // } catch (final Exception e) {
|
|
||||||
// // retriever.setDataSource(result.getAbsolutePath());
|
|
||||||
// // }
|
|
||||||
// // bitmap = retriever.getFrameAtTime();
|
|
||||||
// // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
|
|
||||||
// // try {
|
|
||||||
// // retriever.close();
|
|
||||||
// // } catch (final Exception e) {
|
|
||||||
// // if (logCollector != null)
|
|
||||||
// // logCollector.appendException(e, LogFile.ASYNC_DOWNLOADER, "onPostExecute::bitmap_2");
|
|
||||||
// // }
|
|
||||||
// // } catch (final Exception e) {
|
|
||||||
// // if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e);
|
|
||||||
// // if (logCollector != null)
|
|
||||||
// // logCollector.appendException(e, LogFile.ASYNC_DOWNLOADER, "onPostExecute::bitmap_3");
|
|
||||||
// // }
|
|
||||||
// // }
|
|
||||||
//
|
|
||||||
// // final String downloadComplete = resources.getString(R.string.downloader_complete);
|
|
||||||
//
|
|
||||||
// // downloadNotif.setContentText(null).setContentTitle(downloadComplete).setProgress(0, 0, false)
|
|
||||||
// // .setWhen(System.currentTimeMillis()).setOngoing(false).setOnlyAlertOnce(false).setAutoCancel(true)
|
|
||||||
// // .setGroup(NOTIF_GROUP_NAME).setGroupSummary(true).setContentIntent(
|
|
||||||
// // PendingIntent.getActivity(context, 2020, new Intent(Intent.ACTION_VIEW, uri)
|
|
||||||
// // .addFlags(
|
|
||||||
// // Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_FROM_BACKGROUND | Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
|
|
||||||
// // .putExtra(Intent.EXTRA_STREAM, uri), PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT));
|
|
||||||
// //
|
|
||||||
// // if (bitmap != null)
|
|
||||||
// // downloadNotif.setStyle(new NotificationCompat.BigPictureStyle().setBigContentTitle(downloadComplete).bigPicture(bitmap))
|
|
||||||
// // .setLargeIcon(bitmap).setBadgeIconType(NotificationCompat.BADGE_ICON_SMALL);
|
|
||||||
// //
|
|
||||||
// // notificationManager.cancel(currentNotificationId);
|
|
||||||
// // notificationManager.notify(currentNotificationId + 1, downloadNotif.build());
|
|
||||||
// // }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // if (fetchListener != null) fetchListener.onResult(result);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public static class DownloadOptions {
|
|
||||||
// private final Map<String, File> urlToFileMap;
|
|
||||||
// private final Map<String, DownloadCallback> callbackMap;
|
|
||||||
// private final boolean showNotification;
|
|
||||||
//
|
|
||||||
// public static class Builder {
|
|
||||||
// private Map<String, File> urlToFileMap;
|
|
||||||
// private Map<String, DownloadCallback> callbackMap;
|
|
||||||
// private boolean showNotification;
|
|
||||||
//
|
|
||||||
// public Builder setUrlToFileMap(@NonNull final Map<String, File> urlToFileMap) {
|
|
||||||
// this.urlToFileMap = urlToFileMap;
|
|
||||||
// return this;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public Builder setCallbackMap(@NonNull final Map<String, DownloadCallback> callbackMap) {
|
|
||||||
// this.callbackMap = callbackMap;
|
|
||||||
// return this;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public Builder addUrl(@NonNull final String url, @NonNull final File file) {
|
|
||||||
// if (urlToFileMap == null) {
|
|
||||||
// urlToFileMap = new HashMap<>();
|
|
||||||
// }
|
|
||||||
// urlToFileMap.put(url, file);
|
|
||||||
// return this;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public Builder addUrl(@NonNull final String url,
|
|
||||||
// @NonNull final File file,
|
|
||||||
// @NonNull final DownloadCallback callback) {
|
|
||||||
// if (urlToFileMap == null) {
|
|
||||||
// urlToFileMap = new HashMap<>();
|
|
||||||
// }
|
|
||||||
// if (callbackMap == null) {
|
|
||||||
// callbackMap = new HashMap<>();
|
|
||||||
// }
|
|
||||||
// urlToFileMap.put(url, file);
|
|
||||||
// callbackMap.put(url, callback);
|
|
||||||
// return this;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public Builder setShowNotification(final boolean showNotification) {
|
|
||||||
// this.showNotification = showNotification;
|
|
||||||
// return this;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public DownloadOptions build() {
|
|
||||||
// return new DownloadOptions(
|
|
||||||
// urlToFileMap,
|
|
||||||
// callbackMap,
|
|
||||||
// showNotification
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public Builder builder() {
|
|
||||||
// return new Builder();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private DownloadOptions(final Map<String, File> urlToFileMap,
|
|
||||||
// final Map<String, DownloadCallback> callbackMap,
|
|
||||||
// final boolean showNotification) {
|
|
||||||
// this.urlToFileMap = urlToFileMap;
|
|
||||||
// this.callbackMap = callbackMap;
|
|
||||||
// this.showNotification = showNotification;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public Map<String, File> getUrlToFileMap() {
|
|
||||||
// return urlToFileMap;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public Map<String, DownloadCallback> getCallbackMap() {
|
|
||||||
// return callbackMap;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public boolean isShowNotification() {
|
|
||||||
// return showNotification;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public interface DownloadCallback {
|
|
||||||
// void onDownloadStart();
|
|
||||||
//
|
|
||||||
// void onDownloadProgress();
|
|
||||||
//
|
|
||||||
// void onDownloadComplete();
|
|
||||||
// }
|
|
||||||
// }
|
|
@ -28,7 +28,6 @@ import com.facebook.imagepipeline.image.ImageInfo;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import awais.instagrabber.R;
|
import awais.instagrabber.R;
|
||||||
import awais.instagrabber.asyncs.DownloadAsync;
|
|
||||||
import awais.instagrabber.asyncs.ProfilePictureFetcher;
|
import awais.instagrabber.asyncs.ProfilePictureFetcher;
|
||||||
import awais.instagrabber.databinding.DialogProfilepicBinding;
|
import awais.instagrabber.databinding.DialogProfilepicBinding;
|
||||||
import awais.instagrabber.interfaces.FetchListener;
|
import awais.instagrabber.interfaces.FetchListener;
|
||||||
@ -147,54 +146,9 @@ public class ProfilePicDialogFragment extends DialogFragment {
|
|||||||
if (context == null) return;
|
if (context == null) return;
|
||||||
if (dir.exists() || dir.mkdirs()) {
|
if (dir.exists() || dir.mkdirs()) {
|
||||||
final File saveFile = new File(dir, name + '_' + System.currentTimeMillis() + ".jpg");
|
final File saveFile = new File(dir, name + '_' + System.currentTimeMillis() + ".jpg");
|
||||||
new DownloadAsync(context,
|
DownloadUtils.download(context, url, saveFile.getAbsolutePath());
|
||||||
url,
|
|
||||||
saveFile,
|
|
||||||
result -> {
|
|
||||||
final int toastRes = result != null && result.exists() ?
|
|
||||||
R.string.downloader_downloaded_in_folder : R.string.downloader_error_download_file;
|
|
||||||
Toast.makeText(context, toastRes, Toast.LENGTH_SHORT).show();
|
|
||||||
})
|
|
||||||
.setItems(null, name)
|
|
||||||
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Toast.makeText(context, R.string.downloader_error_creating_folder, Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, R.string.downloader_error_creating_folder, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
// private void showImageInfo() {
|
|
||||||
// final Drawable drawable = profileBinding.imageViewer.getDrawable();
|
|
||||||
// if (drawable != null) {
|
|
||||||
// final StringBuilder info = new StringBuilder(
|
|
||||||
// getString(R.string.profile_viewer_imageinfo, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()));
|
|
||||||
// if (drawable instanceof BitmapDrawable) {
|
|
||||||
// final Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
|
|
||||||
// if (bitmap != null) {
|
|
||||||
// final String colorDepthPrefix = getString(R.string.profile_viewer_colordepth_prefix);
|
|
||||||
// switch (bitmap.getConfig()) {
|
|
||||||
// case ALPHA_8:
|
|
||||||
// info.append(colorDepthPrefix).append(" 8-bits(A)");
|
|
||||||
// break;
|
|
||||||
// case RGB_565:
|
|
||||||
// info.append(colorDepthPrefix).append(" 16-bits-A");
|
|
||||||
// break;
|
|
||||||
// case ARGB_4444:
|
|
||||||
// info.append(colorDepthPrefix).append(" 16-bits+A");
|
|
||||||
// break;
|
|
||||||
// case ARGB_8888:
|
|
||||||
// info.append(colorDepthPrefix).append(" 32-bits+A");
|
|
||||||
// break;
|
|
||||||
// case RGBA_F16:
|
|
||||||
// info.append(colorDepthPrefix).append(" 64-bits+A");
|
|
||||||
// break;
|
|
||||||
// case HARDWARE:
|
|
||||||
// info.append(colorDepthPrefix).append(" auto");
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// profileBinding.imageInfo.setText(info);
|
|
||||||
// profileBinding.imageInfo.setVisibility(View.VISIBLE);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
@ -91,6 +91,7 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
private boolean storiesFetching;
|
private boolean storiesFetching;
|
||||||
private Set<FeedModel> selectedFeedModels;
|
private Set<FeedModel> selectedFeedModels;
|
||||||
private FeedModel downloadFeedModel;
|
private FeedModel downloadFeedModel;
|
||||||
|
private int downloadChildPosition = -1;
|
||||||
|
|
||||||
private final OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(false) {
|
private final OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(false) {
|
||||||
@Override
|
@Override
|
||||||
@ -145,14 +146,15 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDownloadClick(final FeedModel feedModel) {
|
public void onDownloadClick(final FeedModel feedModel, final int childPosition) {
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
if (context == null) return;
|
if (context == null) return;
|
||||||
if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
|
if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
|
||||||
showDownloadDialog(feedModel);
|
DownloadUtils.showDownloadDialog(context, feedModel, childPosition);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
downloadFeedModel = feedModel;
|
downloadFeedModel = feedModel;
|
||||||
|
downloadChildPosition = childPosition;
|
||||||
requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE);
|
requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,15 +306,16 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
|
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
|
||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
final boolean granted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
|
final boolean granted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
|
||||||
|
final Context context = getContext();
|
||||||
|
if (context == null) return;
|
||||||
if (requestCode == STORAGE_PERM_REQUEST_CODE && granted) {
|
if (requestCode == STORAGE_PERM_REQUEST_CODE && granted) {
|
||||||
if (downloadFeedModel == null) return;
|
if (downloadFeedModel == null) return;
|
||||||
showDownloadDialog(downloadFeedModel);
|
DownloadUtils.showDownloadDialog(context, downloadFeedModel, downloadChildPosition);
|
||||||
downloadFeedModel = null;
|
downloadFeedModel = null;
|
||||||
|
downloadChildPosition = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (requestCode == STORAGE_PERM_REQUEST_CODE_FOR_SELECTION && granted) {
|
if (requestCode == STORAGE_PERM_REQUEST_CODE_FOR_SELECTION && granted) {
|
||||||
final Context context = getContext();
|
|
||||||
if (context == null) return;
|
|
||||||
DownloadUtils.download(context, ImmutableList.copyOf(selectedFeedModels));
|
DownloadUtils.download(context, ImmutableList.copyOf(selectedFeedModels));
|
||||||
binding.posts.endSelection();
|
binding.posts.endSelection();
|
||||||
}
|
}
|
||||||
@ -529,48 +532,6 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
binding.swipeRefreshLayout.setRefreshing(binding.posts.isFetching() || storiesFetching);
|
binding.swipeRefreshLayout.setRefreshing(binding.posts.isFetching() || storiesFetching);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showDownloadDialog(final FeedModel feedModel) {
|
|
||||||
final Context context = getContext();
|
|
||||||
if (context == null) return;
|
|
||||||
DownloadUtils.download(context, feedModel);
|
|
||||||
// switch (feedModel.getItemType()) {
|
|
||||||
// case MEDIA_TYPE_IMAGE:
|
|
||||||
// case MEDIA_TYPE_VIDEO:
|
|
||||||
// break;
|
|
||||||
// case MEDIA_TYPE_SLIDER:
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// final List<ViewerPostModel> postModelsToDownload = new ArrayList<>();
|
|
||||||
// // if (!session) {
|
|
||||||
// final DialogInterface.OnClickListener clickListener = (dialog, which) -> {
|
|
||||||
// if (which == DialogInterface.BUTTON_NEGATIVE) {
|
|
||||||
// postModelsToDownload.addAll(postModels);
|
|
||||||
// } else if (which == DialogInterface.BUTTON_POSITIVE) {
|
|
||||||
// postModelsToDownload.add(postModels.get(childPosition));
|
|
||||||
// } else {
|
|
||||||
// session = true;
|
|
||||||
// postModelsToDownload.add(postModels.get(childPosition));
|
|
||||||
// }
|
|
||||||
// if (postModelsToDownload.size() > 0) {
|
|
||||||
// DownloadUtils.batchDownload(context,
|
|
||||||
// username,
|
|
||||||
// DownloadMethod.DOWNLOAD_POST_VIEWER,
|
|
||||||
// postModelsToDownload);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// new AlertDialog.Builder(context)
|
|
||||||
// .setTitle(R.string.post_viewer_download_dialog_title)
|
|
||||||
// .setMessage(R.string.post_viewer_download_message)
|
|
||||||
// .setNeutralButton(R.string.post_viewer_download_session, clickListener)
|
|
||||||
// .setPositiveButton(R.string.post_viewer_download_current, clickListener)
|
|
||||||
// .setNegativeButton(R.string.post_viewer_download_album, clickListener).show();
|
|
||||||
// } else {
|
|
||||||
// DownloadUtils.batchDownload(context,
|
|
||||||
// username,
|
|
||||||
// DownloadMethod.DOWNLOAD_POST_VIEWER,
|
|
||||||
// Collections.singletonList(postModels.get(childPosition)));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void navigateToProfile(final String username) {
|
private void navigateToProfile(final String username) {
|
||||||
final NavController navController = NavHostFragment.findNavController(this);
|
final NavController navController = NavHostFragment.findNavController(this);
|
||||||
final Bundle bundle = new Bundle();
|
final Bundle bundle = new Bundle();
|
||||||
|
@ -90,6 +90,7 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
|
|||||||
private boolean storiesFetching;
|
private boolean storiesFetching;
|
||||||
private Set<FeedModel> selectedFeedModels;
|
private Set<FeedModel> selectedFeedModels;
|
||||||
private FeedModel downloadFeedModel;
|
private FeedModel downloadFeedModel;
|
||||||
|
private int downloadChildPosition = -1;
|
||||||
|
|
||||||
private final OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(false) {
|
private final OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(false) {
|
||||||
@Override
|
@Override
|
||||||
@ -143,13 +144,15 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDownloadClick(final FeedModel feedModel) {
|
public void onDownloadClick(final FeedModel feedModel, final int childPosition) {
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
if (context == null) return;
|
if (context == null) return;
|
||||||
if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
|
if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
|
||||||
showDownloadDialog(feedModel);
|
DownloadUtils.showDownloadDialog(context, feedModel, childPosition);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
downloadFeedModel = feedModel;
|
||||||
|
downloadChildPosition = childPosition;
|
||||||
requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE);
|
requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,15 +305,16 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
|
|||||||
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
|
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
|
||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
final boolean granted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
|
final boolean granted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
|
||||||
|
final Context context = getContext();
|
||||||
|
if (context == null) return;
|
||||||
if (requestCode == STORAGE_PERM_REQUEST_CODE && granted) {
|
if (requestCode == STORAGE_PERM_REQUEST_CODE && granted) {
|
||||||
if (downloadFeedModel == null) return;
|
if (downloadFeedModel == null) return;
|
||||||
showDownloadDialog(downloadFeedModel);
|
DownloadUtils.showDownloadDialog(context, downloadFeedModel, downloadChildPosition);
|
||||||
downloadFeedModel = null;
|
downloadFeedModel = null;
|
||||||
|
downloadChildPosition = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (requestCode == STORAGE_PERM_REQUEST_CODE_FOR_SELECTION && granted) {
|
if (requestCode == STORAGE_PERM_REQUEST_CODE_FOR_SELECTION && granted) {
|
||||||
final Context context = getContext();
|
|
||||||
if (context == null) return;
|
|
||||||
DownloadUtils.download(context, ImmutableList.copyOf(selectedFeedModels));
|
DownloadUtils.download(context, ImmutableList.copyOf(selectedFeedModels));
|
||||||
binding.posts.endSelection();
|
binding.posts.endSelection();
|
||||||
}
|
}
|
||||||
@ -505,48 +509,6 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
|
|||||||
binding.swipeRefreshLayout.setRefreshing(binding.posts.isFetching() || storiesFetching);
|
binding.swipeRefreshLayout.setRefreshing(binding.posts.isFetching() || storiesFetching);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showDownloadDialog(final FeedModel feedModel) {
|
|
||||||
final Context context = getContext();
|
|
||||||
if (context == null) return;
|
|
||||||
DownloadUtils.download(context, feedModel);
|
|
||||||
// switch (feedModel.getItemType()) {
|
|
||||||
// case MEDIA_TYPE_IMAGE:
|
|
||||||
// case MEDIA_TYPE_VIDEO:
|
|
||||||
// break;
|
|
||||||
// case MEDIA_TYPE_SLIDER:
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// final List<ViewerPostModel> postModelsToDownload = new ArrayList<>();
|
|
||||||
// // if (!session) {
|
|
||||||
// final DialogInterface.OnClickListener clickListener = (dialog, which) -> {
|
|
||||||
// if (which == DialogInterface.BUTTON_NEGATIVE) {
|
|
||||||
// postModelsToDownload.addAll(postModels);
|
|
||||||
// } else if (which == DialogInterface.BUTTON_POSITIVE) {
|
|
||||||
// postModelsToDownload.add(postModels.get(childPosition));
|
|
||||||
// } else {
|
|
||||||
// session = true;
|
|
||||||
// postModelsToDownload.add(postModels.get(childPosition));
|
|
||||||
// }
|
|
||||||
// if (postModelsToDownload.size() > 0) {
|
|
||||||
// DownloadUtils.batchDownload(context,
|
|
||||||
// username,
|
|
||||||
// DownloadMethod.DOWNLOAD_POST_VIEWER,
|
|
||||||
// postModelsToDownload);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// new AlertDialog.Builder(context)
|
|
||||||
// .setTitle(R.string.post_viewer_download_dialog_title)
|
|
||||||
// .setMessage(R.string.post_viewer_download_message)
|
|
||||||
// .setNeutralButton(R.string.post_viewer_download_session, clickListener)
|
|
||||||
// .setPositiveButton(R.string.post_viewer_download_current, clickListener)
|
|
||||||
// .setNegativeButton(R.string.post_viewer_download_album, clickListener).show();
|
|
||||||
// } else {
|
|
||||||
// DownloadUtils.batchDownload(context,
|
|
||||||
// username,
|
|
||||||
// DownloadMethod.DOWNLOAD_POST_VIEWER,
|
|
||||||
// Collections.singletonList(postModels.get(childPosition)));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void navigateToProfile(final String username) {
|
private void navigateToProfile(final String username) {
|
||||||
final NavController navController = NavHostFragment.findNavController(this);
|
final NavController navController = NavHostFragment.findNavController(this);
|
||||||
final Bundle bundle = new Bundle();
|
final Bundle bundle = new Bundle();
|
||||||
|
@ -104,7 +104,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
|
|||||||
private boolean wasControlsVisible;
|
private boolean wasControlsVisible;
|
||||||
private boolean wasPaused;
|
private boolean wasPaused;
|
||||||
private int captionState = BottomSheetBehavior.STATE_HIDDEN;
|
private int captionState = BottomSheetBehavior.STATE_HIDDEN;
|
||||||
private int sliderPosition;
|
private int sliderPosition = -1;
|
||||||
|
|
||||||
private final VerticalDragHelper.OnVerticalDragListener onVerticalDragListener = new VerticalDragHelper.OnVerticalDragListener() {
|
private final VerticalDragHelper.OnVerticalDragListener onVerticalDragListener = new VerticalDragHelper.OnVerticalDragListener() {
|
||||||
|
|
||||||
@ -522,7 +522,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
|
|||||||
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
|
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
|
||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
if (requestCode == STORAGE_PERM_REQUEST_CODE && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
if (requestCode == STORAGE_PERM_REQUEST_CODE && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
showDownloadDialog();
|
DownloadUtils.showDownloadDialog(context, feedModel, sliderPosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -560,7 +560,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
|
|||||||
private void setupDownload() {
|
private void setupDownload() {
|
||||||
binding.download.setOnClickListener(v -> {
|
binding.download.setOnClickListener(v -> {
|
||||||
if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
|
if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
|
||||||
showDownloadDialog();
|
DownloadUtils.showDownloadDialog(context, feedModel, sliderPosition);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE);
|
requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE);
|
||||||
@ -1210,46 +1210,6 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showDownloadDialog() {
|
|
||||||
DownloadUtils.download(context, feedModel);
|
|
||||||
// switch (feedModel.getItemType()) {
|
|
||||||
// case MEDIA_TYPE_IMAGE:
|
|
||||||
// case MEDIA_TYPE_VIDEO:
|
|
||||||
// break;
|
|
||||||
// case MEDIA_TYPE_SLIDER:
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// final List<ViewerPostModel> postModelsToDownload = new ArrayList<>();
|
|
||||||
// // if (!session) {
|
|
||||||
// final DialogInterface.OnClickListener clickListener = (dialog, which) -> {
|
|
||||||
// if (which == DialogInterface.BUTTON_NEGATIVE) {
|
|
||||||
// postModelsToDownload.addAll(postModels);
|
|
||||||
// } else if (which == DialogInterface.BUTTON_POSITIVE) {
|
|
||||||
// postModelsToDownload.add(postModels.get(childPosition));
|
|
||||||
// } else {
|
|
||||||
// session = true;
|
|
||||||
// postModelsToDownload.add(postModels.get(childPosition));
|
|
||||||
// }
|
|
||||||
// if (postModelsToDownload.size() > 0) {
|
|
||||||
// DownloadUtils.batchDownload(context,
|
|
||||||
// username,
|
|
||||||
// DownloadMethod.DOWNLOAD_POST_VIEWER,
|
|
||||||
// postModelsToDownload);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// new AlertDialog.Builder(context)
|
|
||||||
// .setTitle(R.string.post_viewer_download_dialog_title)
|
|
||||||
// .setMessage(R.string.post_viewer_download_message)
|
|
||||||
// .setNeutralButton(R.string.post_viewer_download_session, clickListener)
|
|
||||||
// .setPositiveButton(R.string.post_viewer_download_current, clickListener)
|
|
||||||
// .setNegativeButton(R.string.post_viewer_download_album, clickListener).show();
|
|
||||||
// } else {
|
|
||||||
// DownloadUtils.batchDownload(context,
|
|
||||||
// username,
|
|
||||||
// DownloadMethod.DOWNLOAD_POST_VIEWER,
|
|
||||||
// Collections.singletonList(postModels.get(childPosition)));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void animateY(final View v,
|
private void animateY(final View v,
|
||||||
final float finalY,
|
final float finalY,
|
||||||
final int duration,
|
final int duration,
|
||||||
|
@ -61,6 +61,7 @@ public final class SavedViewerFragment extends Fragment implements SwipeRefreshL
|
|||||||
private String profileId;
|
private String profileId;
|
||||||
private Set<FeedModel> selectedFeedModels;
|
private Set<FeedModel> selectedFeedModels;
|
||||||
private FeedModel downloadFeedModel;
|
private FeedModel downloadFeedModel;
|
||||||
|
private int downloadChildPosition = -1;
|
||||||
|
|
||||||
private final OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(false) {
|
private final OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(false) {
|
||||||
@Override
|
@Override
|
||||||
@ -114,13 +115,15 @@ public final class SavedViewerFragment extends Fragment implements SwipeRefreshL
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDownloadClick(final FeedModel feedModel) {
|
public void onDownloadClick(final FeedModel feedModel, final int childPosition) {
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
if (context == null) return;
|
if (context == null) return;
|
||||||
if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
|
if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
|
||||||
showDownloadDialog(feedModel);
|
DownloadUtils.showDownloadDialog(context, feedModel, childPosition);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
downloadFeedModel = feedModel;
|
||||||
|
downloadChildPosition = childPosition;
|
||||||
requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE);
|
requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,15 +345,16 @@ public final class SavedViewerFragment extends Fragment implements SwipeRefreshL
|
|||||||
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
|
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
|
||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
final boolean granted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
|
final boolean granted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
|
||||||
|
final Context context = getContext();
|
||||||
|
if (context == null) return;
|
||||||
if (requestCode == STORAGE_PERM_REQUEST_CODE && granted) {
|
if (requestCode == STORAGE_PERM_REQUEST_CODE && granted) {
|
||||||
if (downloadFeedModel == null) return;
|
if (downloadFeedModel == null) return;
|
||||||
showDownloadDialog(downloadFeedModel);
|
DownloadUtils.showDownloadDialog(context, downloadFeedModel, downloadChildPosition);
|
||||||
downloadFeedModel = null;
|
downloadFeedModel = null;
|
||||||
|
downloadChildPosition = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (requestCode == STORAGE_PERM_REQUEST_CODE_FOR_SELECTION && granted) {
|
if (requestCode == STORAGE_PERM_REQUEST_CODE_FOR_SELECTION && granted) {
|
||||||
final Context context = getContext();
|
|
||||||
if (context == null) return;
|
|
||||||
DownloadUtils.download(context, ImmutableList.copyOf(selectedFeedModels));
|
DownloadUtils.download(context, ImmutableList.copyOf(selectedFeedModels));
|
||||||
binding.posts.endSelection();
|
binding.posts.endSelection();
|
||||||
}
|
}
|
||||||
@ -380,48 +384,6 @@ public final class SavedViewerFragment extends Fragment implements SwipeRefreshL
|
|||||||
binding.swipeRefreshLayout.setRefreshing(binding.posts.isFetching());
|
binding.swipeRefreshLayout.setRefreshing(binding.posts.isFetching());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showDownloadDialog(final FeedModel feedModel) {
|
|
||||||
final Context context = getContext();
|
|
||||||
if (context == null) return;
|
|
||||||
DownloadUtils.download(context, feedModel);
|
|
||||||
// switch (feedModel.getItemType()) {
|
|
||||||
// case MEDIA_TYPE_IMAGE:
|
|
||||||
// case MEDIA_TYPE_VIDEO:
|
|
||||||
// break;
|
|
||||||
// case MEDIA_TYPE_SLIDER:
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// final List<ViewerPostModel> postModelsToDownload = new ArrayList<>();
|
|
||||||
// // if (!session) {
|
|
||||||
// final DialogInterface.OnClickListener clickListener = (dialog, which) -> {
|
|
||||||
// if (which == DialogInterface.BUTTON_NEGATIVE) {
|
|
||||||
// postModelsToDownload.addAll(postModels);
|
|
||||||
// } else if (which == DialogInterface.BUTTON_POSITIVE) {
|
|
||||||
// postModelsToDownload.add(postModels.get(childPosition));
|
|
||||||
// } else {
|
|
||||||
// session = true;
|
|
||||||
// postModelsToDownload.add(postModels.get(childPosition));
|
|
||||||
// }
|
|
||||||
// if (postModelsToDownload.size() > 0) {
|
|
||||||
// DownloadUtils.batchDownload(context,
|
|
||||||
// username,
|
|
||||||
// DownloadMethod.DOWNLOAD_POST_VIEWER,
|
|
||||||
// postModelsToDownload);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// new AlertDialog.Builder(context)
|
|
||||||
// .setTitle(R.string.post_viewer_download_dialog_title)
|
|
||||||
// .setMessage(R.string.post_viewer_download_message)
|
|
||||||
// .setNeutralButton(R.string.post_viewer_download_session, clickListener)
|
|
||||||
// .setPositiveButton(R.string.post_viewer_download_current, clickListener)
|
|
||||||
// .setNegativeButton(R.string.post_viewer_download_album, clickListener).show();
|
|
||||||
// } else {
|
|
||||||
// DownloadUtils.batchDownload(context,
|
|
||||||
// username,
|
|
||||||
// DownloadMethod.DOWNLOAD_POST_VIEWER,
|
|
||||||
// Collections.singletonList(postModels.get(childPosition)));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void navigateToProfile(final String username) {
|
private void navigateToProfile(final String username) {
|
||||||
final NavController navController = NavHostFragment.findNavController(this);
|
final NavController navController = NavHostFragment.findNavController(this);
|
||||||
final Bundle bundle = new Bundle();
|
final Bundle bundle = new Bundle();
|
||||||
|
@ -74,6 +74,7 @@ public class TopicPostsFragment extends Fragment implements SwipeRefreshLayout.O
|
|||||||
private ActionMode actionMode;
|
private ActionMode actionMode;
|
||||||
private Set<FeedModel> selectedFeedModels;
|
private Set<FeedModel> selectedFeedModels;
|
||||||
private FeedModel downloadFeedModel;
|
private FeedModel downloadFeedModel;
|
||||||
|
private int downloadChildPosition = -1;
|
||||||
|
|
||||||
private final OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(false) {
|
private final OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(false) {
|
||||||
@Override
|
@Override
|
||||||
@ -127,13 +128,15 @@ public class TopicPostsFragment extends Fragment implements SwipeRefreshLayout.O
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDownloadClick(final FeedModel feedModel) {
|
public void onDownloadClick(final FeedModel feedModel, final int childPosition) {
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
if (context == null) return;
|
if (context == null) return;
|
||||||
if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
|
if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
|
||||||
showDownloadDialog(feedModel);
|
DownloadUtils.showDownloadDialog(context, feedModel, childPosition);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
downloadFeedModel = feedModel;
|
||||||
|
downloadChildPosition = -1;
|
||||||
requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE);
|
requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,15 +305,16 @@ public class TopicPostsFragment extends Fragment implements SwipeRefreshLayout.O
|
|||||||
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
|
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
|
||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
final boolean granted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
|
final boolean granted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
|
||||||
|
final Context context = getContext();
|
||||||
|
if (context == null) return;
|
||||||
if (requestCode == STORAGE_PERM_REQUEST_CODE && granted) {
|
if (requestCode == STORAGE_PERM_REQUEST_CODE && granted) {
|
||||||
if (downloadFeedModel == null) return;
|
if (downloadFeedModel == null) return;
|
||||||
showDownloadDialog(downloadFeedModel);
|
DownloadUtils.showDownloadDialog(context, downloadFeedModel, downloadChildPosition);
|
||||||
downloadFeedModel = null;
|
downloadFeedModel = null;
|
||||||
|
downloadChildPosition = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (requestCode == STORAGE_PERM_REQUEST_CODE_FOR_SELECTION && granted) {
|
if (requestCode == STORAGE_PERM_REQUEST_CODE_FOR_SELECTION && granted) {
|
||||||
final Context context = getContext();
|
|
||||||
if (context == null) return;
|
|
||||||
DownloadUtils.download(context, ImmutableList.copyOf(selectedFeedModels));
|
DownloadUtils.download(context, ImmutableList.copyOf(selectedFeedModels));
|
||||||
binding.posts.endSelection();
|
binding.posts.endSelection();
|
||||||
}
|
}
|
||||||
@ -408,48 +412,6 @@ public class TopicPostsFragment extends Fragment implements SwipeRefreshLayout.O
|
|||||||
binding.swipeRefreshLayout.setRefreshing(binding.posts.isFetching());
|
binding.swipeRefreshLayout.setRefreshing(binding.posts.isFetching());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showDownloadDialog(final FeedModel feedModel) {
|
|
||||||
final Context context = getContext();
|
|
||||||
if (context == null) return;
|
|
||||||
DownloadUtils.download(context, feedModel);
|
|
||||||
// switch (feedModel.getItemType()) {
|
|
||||||
// case MEDIA_TYPE_IMAGE:
|
|
||||||
// case MEDIA_TYPE_VIDEO:
|
|
||||||
// break;
|
|
||||||
// case MEDIA_TYPE_SLIDER:
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// final List<ViewerPostModel> postModelsToDownload = new ArrayList<>();
|
|
||||||
// // if (!session) {
|
|
||||||
// final DialogInterface.OnClickListener clickListener = (dialog, which) -> {
|
|
||||||
// if (which == DialogInterface.BUTTON_NEGATIVE) {
|
|
||||||
// postModelsToDownload.addAll(postModels);
|
|
||||||
// } else if (which == DialogInterface.BUTTON_POSITIVE) {
|
|
||||||
// postModelsToDownload.add(postModels.get(childPosition));
|
|
||||||
// } else {
|
|
||||||
// session = true;
|
|
||||||
// postModelsToDownload.add(postModels.get(childPosition));
|
|
||||||
// }
|
|
||||||
// if (postModelsToDownload.size() > 0) {
|
|
||||||
// DownloadUtils.batchDownload(context,
|
|
||||||
// username,
|
|
||||||
// DownloadMethod.DOWNLOAD_POST_VIEWER,
|
|
||||||
// postModelsToDownload);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// new AlertDialog.Builder(context)
|
|
||||||
// .setTitle(R.string.post_viewer_download_dialog_title)
|
|
||||||
// .setMessage(R.string.post_viewer_download_message)
|
|
||||||
// .setNeutralButton(R.string.post_viewer_download_session, clickListener)
|
|
||||||
// .setPositiveButton(R.string.post_viewer_download_current, clickListener)
|
|
||||||
// .setNegativeButton(R.string.post_viewer_download_album, clickListener).show();
|
|
||||||
// } else {
|
|
||||||
// DownloadUtils.batchDownload(context,
|
|
||||||
// username,
|
|
||||||
// DownloadMethod.DOWNLOAD_POST_VIEWER,
|
|
||||||
// Collections.singletonList(postModels.get(childPosition)));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void navigateToProfile(final String username) {
|
private void navigateToProfile(final String username) {
|
||||||
final NavController navController = NavHostFragment.findNavController(this);
|
final NavController navController = NavHostFragment.findNavController(this);
|
||||||
final Bundle bundle = new Bundle();
|
final Bundle bundle = new Bundle();
|
||||||
|
@ -71,6 +71,7 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||||||
private ActionMode actionMode;
|
private ActionMode actionMode;
|
||||||
private Set<FeedModel> selectedFeedModels;
|
private Set<FeedModel> selectedFeedModels;
|
||||||
private FeedModel downloadFeedModel;
|
private FeedModel downloadFeedModel;
|
||||||
|
private int downloadChildPosition = -1;
|
||||||
|
|
||||||
private final FeedAdapterV2.FeedItemCallback feedItemCallback = new FeedAdapterV2.FeedItemCallback() {
|
private final FeedAdapterV2.FeedItemCallback feedItemCallback = new FeedAdapterV2.FeedItemCallback() {
|
||||||
@Override
|
@Override
|
||||||
@ -94,14 +95,15 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDownloadClick(final FeedModel feedModel) {
|
public void onDownloadClick(final FeedModel feedModel, final int childPosition) {
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
if (context == null) return;
|
if (context == null) return;
|
||||||
if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
|
if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
|
||||||
showDownloadDialog(feedModel);
|
DownloadUtils.showDownloadDialog(context, feedModel, childPosition);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
downloadFeedModel = feedModel;
|
downloadFeedModel = feedModel;
|
||||||
|
downloadChildPosition = childPosition;
|
||||||
requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE);
|
requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,14 +305,16 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||||||
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
|
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
|
||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
final boolean granted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
|
final boolean granted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
|
||||||
|
final Context context = getContext();
|
||||||
|
if (context == null) return;
|
||||||
if (requestCode == STORAGE_PERM_REQUEST_CODE && granted) {
|
if (requestCode == STORAGE_PERM_REQUEST_CODE && granted) {
|
||||||
if (downloadFeedModel == null) return;
|
if (downloadFeedModel == null) return;
|
||||||
showDownloadDialog(downloadFeedModel);
|
DownloadUtils.showDownloadDialog(context, downloadFeedModel, downloadChildPosition);
|
||||||
|
downloadFeedModel = null;
|
||||||
|
downloadChildPosition = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (requestCode == STORAGE_PERM_REQUEST_CODE_FOR_SELECTION && granted) {
|
if (requestCode == STORAGE_PERM_REQUEST_CODE_FOR_SELECTION && granted) {
|
||||||
final Context context = getContext();
|
|
||||||
if (context == null) return;
|
|
||||||
DownloadUtils.download(context, ImmutableList.copyOf(selectedFeedModels));
|
DownloadUtils.download(context, ImmutableList.copyOf(selectedFeedModels));
|
||||||
binding.feedRecyclerView.endSelection();
|
binding.feedRecyclerView.endSelection();
|
||||||
}
|
}
|
||||||
@ -370,48 +374,6 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showDownloadDialog(@NonNull final FeedModel feedModel) {
|
|
||||||
final Context context = getContext();
|
|
||||||
if (context == null) return;
|
|
||||||
DownloadUtils.download(context, feedModel);
|
|
||||||
// switch (feedModel.getItemType()) {
|
|
||||||
// case MEDIA_TYPE_IMAGE:
|
|
||||||
// case MEDIA_TYPE_VIDEO:
|
|
||||||
// break;
|
|
||||||
// case MEDIA_TYPE_SLIDER:
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// final List<ViewerPostModel> postModelsToDownload = new ArrayList<>();
|
|
||||||
// // if (!session) {
|
|
||||||
// final DialogInterface.OnClickListener clickListener = (dialog, which) -> {
|
|
||||||
// if (which == DialogInterface.BUTTON_NEGATIVE) {
|
|
||||||
// postModelsToDownload.addAll(postModels);
|
|
||||||
// } else if (which == DialogInterface.BUTTON_POSITIVE) {
|
|
||||||
// postModelsToDownload.add(postModels.get(childPosition));
|
|
||||||
// } else {
|
|
||||||
// session = true;
|
|
||||||
// postModelsToDownload.add(postModels.get(childPosition));
|
|
||||||
// }
|
|
||||||
// if (postModelsToDownload.size() > 0) {
|
|
||||||
// DownloadUtils.batchDownload(context,
|
|
||||||
// username,
|
|
||||||
// DownloadMethod.DOWNLOAD_POST_VIEWER,
|
|
||||||
// postModelsToDownload);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// new AlertDialog.Builder(context)
|
|
||||||
// .setTitle(R.string.post_viewer_download_dialog_title)
|
|
||||||
// .setMessage(R.string.post_viewer_download_message)
|
|
||||||
// .setNeutralButton(R.string.post_viewer_download_session, clickListener)
|
|
||||||
// .setPositiveButton(R.string.post_viewer_download_current, clickListener)
|
|
||||||
// .setNegativeButton(R.string.post_viewer_download_album, clickListener).show();
|
|
||||||
// } else {
|
|
||||||
// DownloadUtils.batchDownload(context,
|
|
||||||
// username,
|
|
||||||
// DownloadMethod.DOWNLOAD_POST_VIEWER,
|
|
||||||
// Collections.singletonList(postModels.get(childPosition)));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showPostsLayoutPreferences() {
|
private void showPostsLayoutPreferences() {
|
||||||
final PostsLayoutPreferencesDialogFragment fragment = new PostsLayoutPreferencesDialogFragment(
|
final PostsLayoutPreferencesDialogFragment fragment = new PostsLayoutPreferencesDialogFragment(
|
||||||
Constants.PREF_POSTS_LAYOUT,
|
Constants.PREF_POSTS_LAYOUT,
|
||||||
|
@ -4,7 +4,6 @@ import android.content.Context;
|
|||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
import android.graphics.drawable.Animatable;
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@ -43,9 +42,6 @@ import androidx.recyclerview.widget.LinearLayoutManager;
|
|||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||||
|
|
||||||
import com.facebook.drawee.controller.BaseControllerListener;
|
|
||||||
import com.facebook.drawee.controller.ControllerListener;
|
|
||||||
import com.facebook.imagepipeline.image.ImageInfo;
|
|
||||||
import com.google.android.material.snackbar.BaseTransientBottomBar;
|
import com.google.android.material.snackbar.BaseTransientBottomBar;
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
@ -123,6 +119,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
private boolean postsSetupDone = false;
|
private boolean postsSetupDone = false;
|
||||||
private Set<FeedModel> selectedFeedModels;
|
private Set<FeedModel> selectedFeedModels;
|
||||||
private FeedModel downloadFeedModel;
|
private FeedModel downloadFeedModel;
|
||||||
|
private int downloadChildPosition = -1;
|
||||||
|
|
||||||
private final Runnable usernameSettingRunnable = () -> {
|
private final Runnable usernameSettingRunnable = () -> {
|
||||||
final ActionBar actionBar = fragmentActivity.getSupportActionBar();
|
final ActionBar actionBar = fragmentActivity.getSupportActionBar();
|
||||||
@ -204,14 +201,15 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDownloadClick(final FeedModel feedModel) {
|
public void onDownloadClick(final FeedModel feedModel, final int childPosition) {
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
if (context == null) return;
|
if (context == null) return;
|
||||||
if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
|
if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
|
||||||
showDownloadDialog(feedModel);
|
DownloadUtils.showDownloadDialog(context, feedModel, childPosition);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
downloadFeedModel = feedModel;
|
downloadFeedModel = feedModel;
|
||||||
|
downloadChildPosition = childPosition;
|
||||||
requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE);
|
requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -457,15 +455,16 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
|
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
|
||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
final boolean granted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
|
final boolean granted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
|
||||||
|
final Context context = getContext();
|
||||||
|
if (context == null) return;
|
||||||
if (requestCode == STORAGE_PERM_REQUEST_CODE && granted) {
|
if (requestCode == STORAGE_PERM_REQUEST_CODE && granted) {
|
||||||
if (downloadFeedModel == null) return;
|
if (downloadFeedModel == null) return;
|
||||||
showDownloadDialog(downloadFeedModel);
|
DownloadUtils.showDownloadDialog(context, downloadFeedModel, downloadChildPosition);
|
||||||
downloadFeedModel = null;
|
downloadFeedModel = null;
|
||||||
|
downloadChildPosition = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (requestCode == STORAGE_PERM_REQUEST_CODE_FOR_SELECTION && granted) {
|
if (requestCode == STORAGE_PERM_REQUEST_CODE_FOR_SELECTION && granted) {
|
||||||
final Context context = getContext();
|
|
||||||
if (context == null) return;
|
|
||||||
DownloadUtils.download(context, ImmutableList.copyOf(selectedFeedModels));
|
DownloadUtils.download(context, ImmutableList.copyOf(selectedFeedModels));
|
||||||
binding.postsRecyclerView.endSelection();
|
binding.postsRecyclerView.endSelection();
|
||||||
}
|
}
|
||||||
@ -567,12 +566,12 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
} else {
|
} else {
|
||||||
binding.favCb.setVisibility(View.GONE);
|
binding.favCb.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
final ControllerListener<ImageInfo> listener = new BaseControllerListener<ImageInfo>() {
|
// final ControllerListener<ImageInfo> listener = new BaseControllerListener<ImageInfo>() {
|
||||||
@Override
|
// @Override
|
||||||
public void onFinalImageSet(final String id, final ImageInfo imageInfo, final Animatable animatable) {
|
// public void onFinalImageSet(final String id, final ImageInfo imageInfo, final Animatable animatable) {
|
||||||
startPostponedEnterTransition();
|
// startPostponedEnterTransition();
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
binding.mainProfileImage.setImageURI(profileModel.getHdProfilePic());
|
binding.mainProfileImage.setImageURI(profileModel.getHdProfilePic());
|
||||||
|
|
||||||
final long followersCount = profileModel.getFollowersCount();
|
final long followersCount = profileModel.getFollowersCount();
|
||||||
@ -751,8 +750,6 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
private void setupCommonListeners() {
|
private void setupCommonListeners() {
|
||||||
|
|
||||||
final String userIdFromCookie = CookieUtils.getUserIdFromCookie(cookie);
|
final String userIdFromCookie = CookieUtils.getUserIdFromCookie(cookie);
|
||||||
// final boolean isSelf = isLoggedIn && profileModel != null && userIdFromCookie != null && userIdFromCookie
|
|
||||||
// .equals(profileModel.getId());
|
|
||||||
binding.btnFollow.setOnClickListener(v -> {
|
binding.btnFollow.setOnClickListener(v -> {
|
||||||
if (profileModel.getFollowing() || profileModel.getRequested()) {
|
if (profileModel.getFollowing() || profileModel.getRequested()) {
|
||||||
friendshipService.unfollow(
|
friendshipService.unfollow(
|
||||||
@ -808,12 +805,10 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
PostItemType.TAGGED);
|
PostItemType.TAGGED);
|
||||||
NavHostFragment.findNavController(this).navigate(action);
|
NavHostFragment.findNavController(this).navigate(action);
|
||||||
});
|
});
|
||||||
binding.btnDM.setOnClickListener(v -> {
|
binding.btnDM.setOnClickListener(v -> new CreateThreadAction(cookie, profileModel.getId(), threadId -> {
|
||||||
new CreateThreadAction(cookie, profileModel.getId(), threadId -> {
|
final NavDirections action = ProfileFragmentDirections.actionProfileFragmentToDMThreadFragment(threadId, profileModel.getUsername());
|
||||||
final NavDirections action = ProfileFragmentDirections.actionProfileFragmentToDMThreadFragment(threadId, profileModel.getUsername());
|
NavHostFragment.findNavController(this).navigate(action);
|
||||||
NavHostFragment.findNavController(this).navigate(action);
|
}).execute());
|
||||||
}).execute();
|
|
||||||
});
|
|
||||||
binding.mainProfileImage.setOnClickListener(v -> {
|
binding.mainProfileImage.setOnClickListener(v -> {
|
||||||
if (!hasStories) {
|
if (!hasStories) {
|
||||||
// show profile pic
|
// show profile pic
|
||||||
@ -986,48 +981,6 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
navController.navigate(R.id.action_global_profileFragment, bundle);
|
navController.navigate(R.id.action_global_profileFragment, bundle);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showDownloadDialog(final FeedModel feedModel) {
|
|
||||||
final Context context = getContext();
|
|
||||||
if (context == null) return;
|
|
||||||
DownloadUtils.download(context, feedModel);
|
|
||||||
// switch (feedModel.getItemType()) {
|
|
||||||
// case MEDIA_TYPE_IMAGE:
|
|
||||||
// case MEDIA_TYPE_VIDEO:
|
|
||||||
// break;
|
|
||||||
// case MEDIA_TYPE_SLIDER:
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// final List<ViewerPostModel> postModelsToDownload = new ArrayList<>();
|
|
||||||
// // if (!session) {
|
|
||||||
// final DialogInterface.OnClickListener clickListener = (dialog, which) -> {
|
|
||||||
// if (which == DialogInterface.BUTTON_NEGATIVE) {
|
|
||||||
// postModelsToDownload.addAll(postModels);
|
|
||||||
// } else if (which == DialogInterface.BUTTON_POSITIVE) {
|
|
||||||
// postModelsToDownload.add(postModels.get(childPosition));
|
|
||||||
// } else {
|
|
||||||
// session = true;
|
|
||||||
// postModelsToDownload.add(postModels.get(childPosition));
|
|
||||||
// }
|
|
||||||
// if (postModelsToDownload.size() > 0) {
|
|
||||||
// DownloadUtils.batchDownload(context,
|
|
||||||
// username,
|
|
||||||
// DownloadMethod.DOWNLOAD_POST_VIEWER,
|
|
||||||
// postModelsToDownload);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// new AlertDialog.Builder(context)
|
|
||||||
// .setTitle(R.string.post_viewer_download_dialog_title)
|
|
||||||
// .setMessage(R.string.post_viewer_download_message)
|
|
||||||
// .setNeutralButton(R.string.post_viewer_download_session, clickListener)
|
|
||||||
// .setPositiveButton(R.string.post_viewer_download_current, clickListener)
|
|
||||||
// .setNegativeButton(R.string.post_viewer_download_album, clickListener).show();
|
|
||||||
// } else {
|
|
||||||
// DownloadUtils.batchDownload(context,
|
|
||||||
// username,
|
|
||||||
// DownloadMethod.DOWNLOAD_POST_VIEWER,
|
|
||||||
// Collections.singletonList(postModels.get(childPosition)));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showPostsLayoutPreferences() {
|
private void showPostsLayoutPreferences() {
|
||||||
final PostsLayoutPreferencesDialogFragment fragment = new PostsLayoutPreferencesDialogFragment(
|
final PostsLayoutPreferencesDialogFragment fragment = new PostsLayoutPreferencesDialogFragment(
|
||||||
Constants.PREF_PROFILE_POSTS_LAYOUT,
|
Constants.PREF_PROFILE_POSTS_LAYOUT,
|
||||||
|
@ -3,6 +3,7 @@ package awais.instagrabber.utils;
|
|||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
@ -13,6 +14,7 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.work.Constraints;
|
import androidx.work.Constraints;
|
||||||
@ -275,7 +277,9 @@ public final class DownloadUtils {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void checkExistence(final File downloadDir, final File customDir, final boolean isSlider,
|
public static void checkExistence(final File downloadDir,
|
||||||
|
final File customDir,
|
||||||
|
final boolean isSlider,
|
||||||
@NonNull final BasePostModel model) {
|
@NonNull final BasePostModel model) {
|
||||||
boolean exists = false;
|
boolean exists = false;
|
||||||
|
|
||||||
@ -311,6 +315,38 @@ public final class DownloadUtils {
|
|||||||
model.setDownloaded(exists);
|
model.setDownloaded(exists);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void showDownloadDialog(@NonNull Context context,
|
||||||
|
@NonNull final FeedModel feedModel,
|
||||||
|
final int childPosition) {
|
||||||
|
if (childPosition >= 0) {
|
||||||
|
final DialogInterface.OnClickListener clickListener = (dialog, which) -> {
|
||||||
|
switch (which) {
|
||||||
|
case 0:
|
||||||
|
DownloadUtils.download(context, feedModel, childPosition);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
DownloadUtils.download(context, feedModel);
|
||||||
|
break;
|
||||||
|
case DialogInterface.BUTTON_NEGATIVE:
|
||||||
|
default:
|
||||||
|
dialog.dismiss();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
final String[] items = new String[]{
|
||||||
|
context.getString(R.string.post_viewer_download_current),
|
||||||
|
context.getString(R.string.post_viewer_download_album),
|
||||||
|
};
|
||||||
|
new AlertDialog.Builder(context)
|
||||||
|
.setTitle(R.string.post_viewer_download_dialog_title)
|
||||||
|
.setItems(items, clickListener)
|
||||||
|
.setNegativeButton(R.string.cancel, null)
|
||||||
|
.show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DownloadUtils.download(context, feedModel);
|
||||||
|
}
|
||||||
|
|
||||||
public static void download(@NonNull final Context context,
|
public static void download(@NonNull final Context context,
|
||||||
@NonNull final FeedModel feedModel) {
|
@NonNull final FeedModel feedModel) {
|
||||||
download(context, feedModel, -1);
|
download(context, feedModel, -1);
|
||||||
@ -345,6 +381,9 @@ public final class DownloadUtils {
|
|||||||
case MEDIA_TYPE_SLIDER:
|
case MEDIA_TYPE_SLIDER:
|
||||||
final List<PostChild> sliderItems = feedModel.getSliderItems();
|
final List<PostChild> sliderItems = feedModel.getSliderItems();
|
||||||
for (int i = 0; i < sliderItems.size(); i++) {
|
for (int i = 0; i < sliderItems.size(); i++) {
|
||||||
|
if (childPositionIfSingle >= 0 && feedModels.size() == 1 && i != childPositionIfSingle) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
final PostChild child = sliderItems.get(i);
|
final PostChild child = sliderItems.get(i);
|
||||||
final String url = child.getDisplayUrl();
|
final String url = child.getDisplayUrl();
|
||||||
final File file = getDownloadChildSaveFile(downloadDir, feedModel.getPostId(), i + 1, url);
|
final File file = getDownloadChildSaveFile(downloadDir, feedModel.getPostId(), i + 1, url);
|
||||||
@ -357,6 +396,13 @@ public final class DownloadUtils {
|
|||||||
download(context, map);
|
download(context, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void download(final Context context,
|
||||||
|
final String url,
|
||||||
|
final String filePath) {
|
||||||
|
if (context == null || url == null || filePath == null) return;
|
||||||
|
download(context, Collections.singletonMap(url, filePath));
|
||||||
|
}
|
||||||
|
|
||||||
private static void download(final Context context, final Map<String, String> urlFilePathMap) {
|
private static void download(final Context context, final Map<String, String> urlFilePathMap) {
|
||||||
final Constraints constraints = new Constraints.Builder()
|
final Constraints constraints = new Constraints.Builder()
|
||||||
.setRequiredNetworkType(NetworkType.CONNECTED)
|
.setRequiredNetworkType(NetworkType.CONNECTED)
|
||||||
|
Loading…
Reference in New Issue
Block a user