From 7e8fdda81b300c6d21e95f4ecebd6107bc202580 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Sun, 6 Sep 2020 18:25:27 +0900 Subject: [PATCH] Add updated profile pic viewer, and view stories from profile. --- app/src/main/AndroidManifest.xml | 14 +- .../activities/ProfilePicViewer.java | 434 +++++++++--------- .../instagrabber/asyncs/DownloadAsync.java | 39 +- .../dialogs/ProfilePicDialogFragment.java | 199 ++++++++ .../fragments/CommentsViewerFragment.java | 14 +- .../fragments/StoryViewerFragment.java | 138 +++--- .../fragments/main/FeedFragment.java | 6 +- .../fragments/main/ProfileFragment.java | 74 +-- .../main/res/layout/activity_profilepic.xml | 37 -- app/src/main/res/layout/dialog_profilepic.xml | 43 ++ .../main/res/navigation/feed_nav_graph.xml | 8 + .../main/res/navigation/profile_nav_graph.xml | 8 + 12 files changed, 646 insertions(+), 368 deletions(-) create mode 100644 app/src/main/java/awais/instagrabber/dialogs/ProfilePicDialogFragment.java delete mode 100755 app/src/main/res/layout/activity_profilepic.xml create mode 100644 app/src/main/res/layout/dialog_profilepic.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c4838e6d..8ab7c6db 100755 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -168,14 +168,14 @@ - + + + - - + + + + diff --git a/app/src/main/java/awais/instagrabber/activities/ProfilePicViewer.java b/app/src/main/java/awais/instagrabber/activities/ProfilePicViewer.java index afdcaab5..414226b3 100755 --- a/app/src/main/java/awais/instagrabber/activities/ProfilePicViewer.java +++ b/app/src/main/java/awais/instagrabber/activities/ProfilePicViewer.java @@ -1,211 +1,223 @@ -package awais.instagrabber.activities; - -import android.content.Intent; -import android.graphics.Bitmap; -import android.graphics.drawable.BitmapDrawable; -import android.graphics.drawable.Drawable; -import android.os.AsyncTask; -import android.os.Bundle; -import android.os.Environment; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.widget.Toast; - -import androidx.annotation.Nullable; -import androidx.fragment.app.FragmentManager; - -import com.bumptech.glide.Glide; -import com.bumptech.glide.RequestManager; -import com.bumptech.glide.load.DataSource; -import com.bumptech.glide.load.engine.GlideException; -import com.bumptech.glide.request.RequestListener; -import com.bumptech.glide.request.target.Target; - -import java.io.File; - -import awais.instagrabber.R; -import awais.instagrabber.asyncs.DownloadAsync; -import awais.instagrabber.asyncs.ProfilePictureFetcher; -import awais.instagrabber.databinding.ActivityProfilepicBinding; -import awais.instagrabber.interfaces.FetchListener; -import awais.instagrabber.models.HashtagModel; -import awais.instagrabber.models.LocationModel; -import awais.instagrabber.models.ProfileModel; -import awais.instagrabber.utils.Constants; -import awais.instagrabber.utils.Utils; - -public final class ProfilePicViewer extends BaseLanguageActivity { - private ActivityProfilepicBinding profileBinding; - private ProfileModel profileModel; - private HashtagModel hashtagModel; - private LocationModel locationModel; - private MenuItem menuItemDownload; - private String profilePicUrl; - private FragmentManager fragmentManager; - private FetchListener fetchListener; - private boolean errorHandled = false; - private boolean fallbackToProfile = false; - private boolean destroyed = false; - - @Override - protected void onCreate(@Nullable final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - profileBinding = ActivityProfilepicBinding.inflate(getLayoutInflater()); - setContentView(profileBinding.getRoot()); - - setSupportActionBar(profileBinding.toolbar.toolbar); - - final Intent intent = getIntent(); - if (intent == null || (!intent.hasExtra(Constants.EXTRAS_PROFILE) && !intent.hasExtra(Constants.EXTRAS_HASHTAG) && !intent.hasExtra(Constants.EXTRAS_LOCATION)) - || ((profileModel = (ProfileModel) intent.getSerializableExtra(Constants.EXTRAS_PROFILE)) == null - && (hashtagModel = (HashtagModel) intent.getSerializableExtra(Constants.EXTRAS_HASHTAG)) == null - && (locationModel = (LocationModel) intent.getSerializableExtra(Constants.EXTRAS_LOCATION)) == null)) { - Utils.errorFinish(this); - return; - } - - fragmentManager = getSupportFragmentManager(); - - final String id = hashtagModel != null ? hashtagModel.getId() : (locationModel != null ? locationModel.getId() : profileModel.getId()); - final String username = hashtagModel != null ? hashtagModel.getName() : (locationModel != null ? locationModel.getName() : profileModel.getUsername()); - - profileBinding.toolbar.toolbar.setTitle(username); - - profileBinding.progressView.setVisibility(View.VISIBLE); - profileBinding.imageViewer.setVisibility(View.VISIBLE); - - profileBinding.imageViewer.setZoomable(true); - profileBinding.imageViewer.setZoomTransitionDuration(420); - profileBinding.imageViewer.setMaximumScale(7.2f); - - fetchListener = profileUrl -> { - profilePicUrl = profileUrl; - - if (!fallbackToProfile && Utils.isEmpty(profilePicUrl)) { - fallbackToProfile = true; - new ProfilePictureFetcher(username, id, fetchListener, profilePicUrl, (hashtagModel != null || locationModel != null)).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - return; - } - - if (errorHandled && fallbackToProfile || Utils.isEmpty(profilePicUrl)) - profilePicUrl = hashtagModel != null ? hashtagModel.getSdProfilePic() : (locationModel != null ? locationModel.getSdProfilePic() : profileModel.getHdProfilePic()); - - if (destroyed == true) return; - - final RequestManager glideRequestManager = Glide.with(this); - - glideRequestManager.load(profilePicUrl).addListener(new RequestListener() { - @Override - public boolean onLoadFailed(@Nullable final GlideException e, final Object model, final Target target, final boolean isFirstResource) { - fallbackToProfile = true; - if (!errorHandled) { - errorHandled = true; - new ProfilePictureFetcher(username, id, fetchListener, profilePicUrl, (hashtagModel != null || locationModel != null)) - .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - profileBinding.progressView.setVisibility(View.GONE); - return false; - } - - @Override - public boolean onResourceReady(final Drawable resource, final Object model, final Target target, final DataSource dataSource, final boolean isFirstResource) { - if (menuItemDownload != null) menuItemDownload.setEnabled(true); - showImageInfo(); - profileBinding.progressView.setVisibility(View.GONE); - return false; - } - - 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); - } - } - }).error(glideRequestManager.load(profilePicUrl)).into(profileBinding.imageViewer); - }; - - new ProfilePictureFetcher(username, id, fetchListener, profilePicUrl, (hashtagModel != null || locationModel != null)) - .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - - private void downloadProfilePicture() { - int error = 0; - - if (profileModel != null) { - final File dir = new File(Environment.getExternalStorageDirectory(), "Download"); - if (dir.exists() || dir.mkdirs()) { - - final File saveFile = new File(dir, profileModel.getUsername() + '_' + System.currentTimeMillis() - + Utils.getExtensionFromModel(profilePicUrl, profileModel)); - - new DownloadAsync(this, - profilePicUrl, - saveFile, - result -> { - final int toastRes = result != null && result.exists() ? - R.string.downloader_downloaded_in_folder : R.string.downloader_error_download_file; - Toast.makeText(this, toastRes, Toast.LENGTH_SHORT).show(); - }).setItems(null, profileModel.getUsername()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } else error = 1; - } else error = 2; - - if (error == 1) Toast.makeText(this, R.string.downloader_error_creating_folder, Toast.LENGTH_SHORT).show(); - else if (error == 2) Toast.makeText(this, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - getDelegate().onDestroy(); - destroyed = true; - } - - @Override - public boolean onCreateOptionsMenu(final Menu menu) { - getMenuInflater().inflate(R.menu.menu, menu); - - final MenuItem.OnMenuItemClickListener menuItemClickListener = item -> { - if (item == menuItemDownload) { - downloadProfilePicture(); - } - return true; - }; - - menu.findItem(R.id.action_search).setVisible(false); - menuItemDownload = menu.findItem(R.id.action_download); - menuItemDownload.setVisible(true); - menuItemDownload.setEnabled(false); - menuItemDownload.setOnMenuItemClickListener(menuItemClickListener); - - return true; - } -} \ No newline at end of file +// package awais.instagrabber.activities; +// +// import android.content.Intent; +// import android.graphics.Bitmap; +// import android.graphics.drawable.BitmapDrawable; +// import android.graphics.drawable.Drawable; +// import android.os.AsyncTask; +// import android.os.Bundle; +// import android.os.Environment; +// import android.view.Menu; +// import android.view.MenuItem; +// import android.view.View; +// import android.widget.Toast; +// +// import androidx.annotation.Nullable; +// import androidx.fragment.app.FragmentManager; +// +// import com.bumptech.glide.Glide; +// import com.bumptech.glide.RequestManager; +// import com.bumptech.glide.load.DataSource; +// import com.bumptech.glide.load.engine.GlideException; +// import com.bumptech.glide.request.RequestListener; +// import com.bumptech.glide.request.target.Target; +// +// import java.io.File; +// +// import awais.instagrabber.R; +// import awais.instagrabber.asyncs.DownloadAsync; +// import awais.instagrabber.asyncs.ProfilePictureFetcher; +// import awais.instagrabber.databinding.ActivityProfilepicBinding; +// import awais.instagrabber.interfaces.FetchListener; +// import awais.instagrabber.models.HashtagModel; +// import awais.instagrabber.models.LocationModel; +// import awais.instagrabber.models.ProfileModel; +// import awais.instagrabber.utils.Constants; +// import awais.instagrabber.utils.Utils; +// +// public final class ProfilePicViewer extends BaseLanguageActivity { +// private ActivityProfilepicBinding profileBinding; +// private ProfileModel profileModel; +// private HashtagModel hashtagModel; +// private LocationModel locationModel; +// private MenuItem menuItemDownload; +// private String profilePicUrl; +// private FragmentManager fragmentManager; +// private FetchListener fetchListener; +// private boolean errorHandled = false; +// private boolean fallbackToProfile = false; +// private boolean destroyed = false; +// +// @Override +// protected void onCreate(@Nullable final Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// profileBinding = ActivityProfilepicBinding.inflate(getLayoutInflater()); +// setContentView(profileBinding.getRoot()); +// +// final Intent intent = getIntent(); +// if (intent == null || (!intent.hasExtra(Constants.EXTRAS_PROFILE) && !intent.hasExtra(Constants.EXTRAS_HASHTAG) && !intent +// .hasExtra(Constants.EXTRAS_LOCATION)) +// || ((profileModel = (ProfileModel) intent.getSerializableExtra(Constants.EXTRAS_PROFILE)) == null +// && (hashtagModel = (HashtagModel) intent.getSerializableExtra(Constants.EXTRAS_HASHTAG)) == null +// && (locationModel = (LocationModel) intent.getSerializableExtra(Constants.EXTRAS_LOCATION)) == null)) { +// Utils.errorFinish(this); +// return; +// } +// +// fragmentManager = getSupportFragmentManager(); +// +// final String id = hashtagModel != null ? hashtagModel.getId() : (locationModel != null ? locationModel.getId() : profileModel.getId()); +// final String username = hashtagModel != null +// ? hashtagModel.getName() +// : (locationModel != null ? locationModel.getName() : profileModel.getUsername()); +// +// // profileBinding.toolbar.toolbar.setTitle(username); +// +// profileBinding.progressView.setVisibility(View.VISIBLE); +// profileBinding.imageViewer.setVisibility(View.VISIBLE); +// +// // profileBinding.imageViewer.setZoomable(true); +// // profileBinding.imageViewer.setZoomTransitionDuration(420); +// // profileBinding.imageViewer.setMaximumScale(7.2f); +// +// fetchListener = profileUrl -> { +// profilePicUrl = profileUrl; +// +// if (!fallbackToProfile && Utils.isEmpty(profilePicUrl)) { +// fallbackToProfile = true; +// new ProfilePictureFetcher(username, id, fetchListener, profilePicUrl, (hashtagModel != null || locationModel != null)) +// .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// return; +// } +// +// if (errorHandled && fallbackToProfile || Utils.isEmpty(profilePicUrl)) +// profilePicUrl = hashtagModel != null +// ? hashtagModel.getSdProfilePic() +// : (locationModel != null ? locationModel.getSdProfilePic() : profileModel.getHdProfilePic()); +// +// if (destroyed == true) return; +// +// final RequestManager glideRequestManager = Glide.with(this); +// +// glideRequestManager.load(profilePicUrl).addListener(new RequestListener() { +// @Override +// public boolean onLoadFailed(@Nullable final GlideException e, +// final Object model, +// final Target target, +// final boolean isFirstResource) { +// fallbackToProfile = true; +// if (!errorHandled) { +// errorHandled = true; +// new ProfilePictureFetcher(username, id, fetchListener, profilePicUrl, (hashtagModel != null || locationModel != null)) +// .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// } +// profileBinding.progressView.setVisibility(View.GONE); +// return false; +// } +// +// @Override +// public boolean onResourceReady(final Drawable resource, +// final Object model, +// final Target target, +// final DataSource dataSource, +// final boolean isFirstResource) { +// if (menuItemDownload != null) menuItemDownload.setEnabled(true); +// showImageInfo(); +// profileBinding.progressView.setVisibility(View.GONE); +// return false; +// } +// +// 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); +// } +// } +// }).error(glideRequestManager.load(profilePicUrl)).into(profileBinding.imageViewer); +// }; +// +// new ProfilePictureFetcher(username, id, fetchListener, profilePicUrl, (hashtagModel != null || locationModel != null)) +// .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// } +// +// private void downloadProfilePicture() { +// int error = 0; +// +// if (profileModel != null) { +// final File dir = new File(Environment.getExternalStorageDirectory(), "Download"); +// if (dir.exists() || dir.mkdirs()) { +// +// final File saveFile = new File(dir, profileModel.getUsername() + '_' + System.currentTimeMillis() +// + Utils.getExtensionFromModel(profilePicUrl, profileModel)); +// +// new DownloadAsync(this, +// profilePicUrl, +// saveFile, +// result -> { +// final int toastRes = result != null && result.exists() ? +// R.string.downloader_downloaded_in_folder : R.string.downloader_error_download_file; +// Toast.makeText(this, toastRes, Toast.LENGTH_SHORT).show(); +// }).setItems(null, profileModel.getUsername()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// } else error = 1; +// } else error = 2; +// +// if (error == 1) Toast.makeText(this, R.string.downloader_error_creating_folder, Toast.LENGTH_SHORT).show(); +// else if (error == 2) Toast.makeText(this, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); +// } +// +// @Override +// protected void onDestroy() { +// super.onDestroy(); +// getDelegate().onDestroy(); +// destroyed = true; +// } +// +// @Override +// public boolean onCreateOptionsMenu(final Menu menu) { +// getMenuInflater().inflate(R.menu.menu, menu); +// +// final MenuItem.OnMenuItemClickListener menuItemClickListener = item -> { +// if (item == menuItemDownload) { +// downloadProfilePicture(); +// } +// return true; +// }; +// +// menu.findItem(R.id.action_search).setVisible(false); +// menuItemDownload = menu.findItem(R.id.action_download); +// menuItemDownload.setVisible(true); +// menuItemDownload.setEnabled(false); +// menuItemDownload.setOnMenuItemClickListener(menuItemClickListener); +// +// return true; +// } +// } \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/asyncs/DownloadAsync.java b/app/src/main/java/awais/instagrabber/asyncs/DownloadAsync.java index 35b07ddc..3bb32a43 100755 --- a/app/src/main/java/awais/instagrabber/asyncs/DownloadAsync.java +++ b/app/src/main/java/awais/instagrabber/asyncs/DownloadAsync.java @@ -34,7 +34,6 @@ import java.util.concurrent.atomic.AtomicReference; import awais.instagrabber.BuildConfig; import awais.instagrabber.R; -import awais.instagrabber.activities.ProfilePicViewer; import awais.instagrabber.interfaces.FetchListener; import awais.instagrabber.utils.Utils; @@ -72,16 +71,17 @@ public final class DownloadAsync extends AsyncTask { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !isChannelCreated) { notificationManager.createNotificationChannel(new NotificationChannel(CHANNEL_ID, - CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH)); + CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH)); isChannelCreated = true; } - @StringRes final int titleRes = context instanceof ProfilePicViewer ? R.string.downloader_downloading_pfp : R.string.downloader_downloading_post; + @StringRes final int titleRes = R.string.downloader_downloading_post; downloadNotif = new NotificationCompat.Builder(context, 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)); + .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.notify(currentNotifId, downloadNotif.build()); } @@ -99,7 +99,7 @@ public final class DownloadAsync extends AsyncTask { try { final URLConnection urlConnection = new URL(url).openConnection(); final long fileSize = Build.VERSION.SDK_INT >= 24 ? urlConnection.getContentLengthLong() : - urlConnection.getContentLength(); + urlConnection.getContentLength(); float totalRead = 0; try (final BufferedInputStream bis = new BufferedInputStream(urlConnection.getInputStream()); @@ -152,12 +152,12 @@ public final class DownloadAsync extends AsyncTask { } 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", lastNotifId), - new Pair<>("downloadNotif", downloadNotif), - new Pair<>("currentNotifId", currentNotifId), - new Pair<>("notificationManager", notificationManager)); + new Pair<>("context", context.get()), + new Pair<>("resources", resources), + new Pair<>("lastNotifId", lastNotifId), + new Pair<>("downloadNotif", downloadNotif), + new Pair<>("currentNotifId", currentNotifId), + new Pair<>("notificationManager", notificationManager)); if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e); } return null; @@ -182,8 +182,8 @@ public final class DownloadAsync extends AsyncTask { final Context context = this.context.get(); context.sendBroadcast(Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT ? - new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.fromFile(Environment.getExternalStorageDirectory())) : - new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(result.getAbsoluteFile())) + new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.fromFile(Environment.getExternalStorageDirectory())) : + new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(result.getAbsoluteFile())) ); MediaScannerConnection.scanFile(context, new String[]{result.getAbsolutePath()}, null, null); @@ -228,15 +228,16 @@ public final class DownloadAsync extends AsyncTask { 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( + .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) + .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); + .setLargeIcon(bitmap).setBadgeIconType(NotificationCompat.BADGE_ICON_SMALL); notificationManager.cancel(currentNotifId); notificationManager.notify(currentNotifId + 1, downloadNotif.build()); diff --git a/app/src/main/java/awais/instagrabber/dialogs/ProfilePicDialogFragment.java b/app/src/main/java/awais/instagrabber/dialogs/ProfilePicDialogFragment.java new file mode 100644 index 00000000..ce8af721 --- /dev/null +++ b/app/src/main/java/awais/instagrabber/dialogs/ProfilePicDialogFragment.java @@ -0,0 +1,199 @@ +package awais.instagrabber.dialogs; + +import android.app.Dialog; +import android.content.pm.PackageManager; +import android.graphics.Color; +import android.graphics.drawable.Animatable; +import android.graphics.drawable.ColorDrawable; +import android.os.AsyncTask; +import android.os.Bundle; +import android.os.Environment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.Window; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.core.content.ContextCompat; +import androidx.fragment.app.DialogFragment; + +import com.facebook.drawee.backends.pipeline.Fresco; +import com.facebook.drawee.controller.BaseControllerListener; +import com.facebook.drawee.interfaces.DraweeController; +import com.facebook.imagepipeline.image.ImageInfo; + +import java.io.File; + +import awais.instagrabber.R; +import awais.instagrabber.asyncs.DownloadAsync; +import awais.instagrabber.asyncs.ProfilePictureFetcher; +import awais.instagrabber.databinding.DialogProfilepicBinding; +import awais.instagrabber.interfaces.FetchListener; +import awais.instagrabber.utils.Utils; + +public class ProfilePicDialogFragment extends DialogFragment { + private static final String TAG = "ProfilePicDlgFragment"; + + private final String id; + private final String name; + private final String fallbackUrl; + + private DialogProfilepicBinding binding; + private String url; + private boolean fallbackToProfile; + private FetchListener fetchListener; + private boolean errorHandled; + private boolean isHashtag; + private boolean destroyed; + + public ProfilePicDialogFragment(final String id, final String name, final String fallbackUrl) { + this.id = id; + this.name = name; + this.fallbackUrl = fallbackUrl; + } + + @Override + public View onCreateView(@NonNull final LayoutInflater inflater, + final ViewGroup container, + final Bundle savedInstanceState) { + binding = DialogProfilepicBinding.inflate(inflater, container, false); + return binding.getRoot(); + } + + @NonNull + @Override + public Dialog onCreateDialog(final Bundle savedInstanceState) { + final Dialog dialog = super.onCreateDialog(savedInstanceState); + dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); + return dialog; + } + + @Override + public void onStart() { + super.onStart(); + final Dialog dialog = getDialog(); + if (dialog == null) return; + final Window window = dialog.getWindow(); + if (window == null) return; + window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); + int width = ViewGroup.LayoutParams.MATCH_PARENT; + int height = ViewGroup.LayoutParams.MATCH_PARENT; + window.setLayout(width, height); + } + + @Override + public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + init(); + fetchPhoto(); + } + + private void init() { + binding.download.setOnClickListener(v -> { + if (ContextCompat.checkSelfPermission(requireContext(), Utils.PERMS[0]) == PackageManager.PERMISSION_GRANTED) { + downloadProfilePicture(); + return; + } + requestPermissions(Utils.PERMS, 8020); + }); + } + + @Override + public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); + if (requestCode == 8020 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + downloadProfilePicture(); + } + } + + private void fetchPhoto() { + fetchListener = profileUrl -> { + url = profileUrl; + if (Utils.isEmpty(url)) { + url = fallbackUrl; + } + final DraweeController controller = Fresco + .newDraweeControllerBuilder() + .setUri(url) + .setOldController(binding.imageViewer.getController()) + .setControllerListener(new BaseControllerListener() { + @Override + public void onFailure(final String id, final Throwable throwable) { + super.onFailure(id, throwable); + binding.download.setVisibility(View.GONE); + binding.progressView.setVisibility(View.GONE); + } + + @Override + public void onFinalImageSet(final String id, + final ImageInfo imageInfo, + final Animatable animatable) { + super.onFinalImageSet(id, imageInfo, animatable); + binding.download.setVisibility(View.VISIBLE); + binding.progressView.setVisibility(View.GONE); + } + }) + .build(); + binding.imageViewer.setController(controller); + }; + new ProfilePictureFetcher(name, id, fetchListener, url, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + + private void downloadProfilePicture() { + if (url == null) return; + final File dir = new File(Environment.getExternalStorageDirectory(), "Download"); + if (dir.exists() || dir.mkdirs()) { + final File saveFile = new File(dir, name + '_' + System.currentTimeMillis() + ".jpg"); + new DownloadAsync(requireContext(), + url, + saveFile, + result -> { + final int toastRes = result != null && result.exists() ? + R.string.downloader_downloaded_in_folder : R.string.downloader_error_download_file; + Toast.makeText(requireContext(), toastRes, Toast.LENGTH_SHORT).show(); + }) + .setItems(null, name) + .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + return; + } + Toast.makeText(requireContext(), 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); + // } + // } +} diff --git a/app/src/main/java/awais/instagrabber/fragments/CommentsViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/CommentsViewerFragment.java index bc5753fe..37fb410a 100644 --- a/app/src/main/java/awais/instagrabber/fragments/CommentsViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/CommentsViewerFragment.java @@ -1,7 +1,6 @@ package awais.instagrabber.fragments; import android.content.DialogInterface; -import android.content.Intent; import android.content.res.Resources; import android.os.AsyncTask; import android.os.Bundle; @@ -28,15 +27,17 @@ import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.SearchView; import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentTransaction; import androidx.navigation.NavDirections; import androidx.navigation.fragment.NavHostFragment; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import awais.instagrabber.R; -import awais.instagrabber.activities.ProfilePicViewer; import awais.instagrabber.adapters.CommentsAdapter; import awais.instagrabber.asyncs.CommentsFetcher; import awais.instagrabber.databinding.FragmentCommentsBinding; +import awais.instagrabber.dialogs.ProfilePicDialogFragment; import awais.instagrabber.interfaces.MentionClickListener; import awais.instagrabber.models.CommentModel; import awais.instagrabber.models.ProfileModel; @@ -181,7 +182,14 @@ public final class CommentsViewerFragment extends Fragment implements SwipeRefre openProfile(profileModel.getUsername()); break; case 1: // view profile pic - startActivity(new Intent(requireContext(), ProfilePicViewer.class).putExtra(Constants.EXTRAS_PROFILE, profileModel)); + final FragmentManager fragmentManager = getParentFragmentManager(); + final ProfilePicDialogFragment fragment = new ProfilePicDialogFragment(profileModel.getId(), + profileModel.getUsername(), + profileModel.getHdProfilePic()); + final FragmentTransaction ft = fragmentManager.beginTransaction(); + ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) + .add(fragment, "profilePicDialog") + .commit(); break; case 2: // copy username Utils.copyText(requireContext(), profileModel.getUsername()); diff --git a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java index 2d407b30..fe2d177e 100644 --- a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java @@ -70,9 +70,6 @@ import awais.instagrabber.asyncs.VoteAction; import awais.instagrabber.asyncs.direct_messages.DirectThreadBroadcaster; import awais.instagrabber.customviews.helpers.SwipeGestureListener; import awais.instagrabber.databinding.ActivityStoryViewerBinding; -import awais.instagrabber.viewmodels.FeedStoriesViewModel; -import awais.instagrabber.viewmodels.HighlightsViewModel; -import awais.instagrabber.viewmodels.StoriesViewModel; import awais.instagrabber.interfaces.SwipeEvent; import awais.instagrabber.models.FeedStoryModel; import awais.instagrabber.models.HighlightModel; @@ -85,6 +82,9 @@ import awais.instagrabber.services.ServiceCallback; import awais.instagrabber.services.StoriesService; import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Utils; +import awais.instagrabber.viewmodels.FeedStoriesViewModel; +import awais.instagrabber.viewmodels.HighlightsViewModel; +import awais.instagrabber.viewmodels.StoriesViewModel; import awaisomereport.LogCollector; import static awais.instagrabber.customviews.helpers.SwipeGestureListener.SWIPE_THRESHOLD; @@ -123,11 +123,12 @@ public class StoryViewerFragment extends Fragment { private int currentFeedStoryIndex; private StoriesViewModel storiesViewModel; private boolean shouldRefresh = true; - - private final String cookie = settingsHelper.getString(Constants.COOKIE); private StoryViewerFragmentArgs fragmentArgs; private ViewModel viewModel; private boolean isHighlight; + private boolean isLoggedIn; + + private final String cookie = settingsHelper.getString(Constants.COOKIE); @Override public void onCreate(@Nullable final Bundle savedInstanceState) { @@ -235,14 +236,17 @@ public class StoryViewerFragment extends Fragment { } private void init() { + isLoggedIn = !Utils.isEmpty(cookie) && Utils.getUserIdFromCookie(cookie) != null; if (getArguments() == null) return; fragmentArgs = StoryViewerFragmentArgs.fromBundle(getArguments()); currentFeedStoryIndex = fragmentArgs.getFeedStoryIndex(); highlight = fragmentArgs.getHighlight(); isHighlight = !Utils.isEmpty(highlight); - viewModel = isHighlight - ? new ViewModelProvider(fragmentActivity).get(HighlightsViewModel.class) - : new ViewModelProvider(fragmentActivity).get(FeedStoriesViewModel.class); + if (currentFeedStoryIndex >= 0) { + viewModel = isHighlight + ? new ViewModelProvider(fragmentActivity).get(HighlightsViewModel.class) + : new ViewModelProvider(fragmentActivity).get(FeedStoriesViewModel.class); + } // feedStoryModels = feedStoriesViewModel.getList().getValue(); // feedStoryModels == null || feedStoryModels.isEmpty() || setupStories(); @@ -265,21 +269,24 @@ public class StoryViewerFragment extends Fragment { @SuppressLint("ClickableViewAccessibility") private void setupListeners() { final boolean hasFeedStories; - final List models; - if (isHighlight) { - final HighlightsViewModel highlightsViewModel = (HighlightsViewModel) viewModel; - models = highlightsViewModel.getList().getValue(); - // final HighlightModel model = models.get(currentFeedStoryIndex); - // currentStoryMediaId = model.getId(); - // currentStoryUsername = model.getTitle(); - } else { - final FeedStoriesViewModel feedStoriesViewModel = (FeedStoriesViewModel) viewModel; - models = feedStoriesViewModel.getList().getValue(); - // final FeedStoryModel model = models.get(currentFeedStoryIndex); - // currentStoryMediaId = model.getStoryMediaId(); - // currentStoryUsername = model.getProfileModel().getUsername(); + List models = null; + if (currentFeedStoryIndex > 0) { + if (isHighlight) { + final HighlightsViewModel highlightsViewModel = (HighlightsViewModel) viewModel; + models = highlightsViewModel.getList().getValue(); + // final HighlightModel model = models.get(currentFeedStoryIndex); + // currentStoryMediaId = model.getId(); + // currentStoryUsername = model.getTitle(); + } else { + final FeedStoriesViewModel feedStoriesViewModel = (FeedStoriesViewModel) viewModel; + models = feedStoriesViewModel.getList().getValue(); + // final FeedStoryModel model = models.get(currentFeedStoryIndex); + // currentStoryMediaId = model.getStoryMediaId(); + // currentStoryUsername = model.getProfileModel().getUsername(); + } } hasFeedStories = models != null && !models.isEmpty(); + final List finalModels = models; swipeEvent = isRightSwipe -> { final List storyModels = storiesViewModel.getList().getValue(); final int storiesLen = storyModels == null ? 0 : storyModels.size(); @@ -292,13 +299,13 @@ public class StoryViewerFragment extends Fragment { if (settingsHelper.getBoolean(MARK_AS_SEEN)) { new SeenAction(cookie, currentStory).execute(); } - if ((isRightSwipe && index == 0) || (isLeftSwipe && index == models.size() - 1)) { + if ((isRightSwipe && index == 0) || (isLeftSwipe && index == finalModels.size() - 1)) { Toast.makeText(requireContext(), R.string.no_more_stories, Toast.LENGTH_SHORT).show(); return; } final Object feedStoryModel = isRightSwipe - ? models.get(index - 1) - : models.size() == index + 1 ? null : models.get(index + 1); + ? finalModels.get(index - 1) + : finalModels.size() == index + 1 ? null : finalModels.get(index + 1); if (feedStoryModel != null) { if (fetching) { Toast.makeText(requireContext(), R.string.be_patient, Toast.LENGTH_SHORT).show(); @@ -459,21 +466,27 @@ public class StoryViewerFragment extends Fragment { if (menuDm != null) menuDm.setVisible(false); binding.imageViewer.setController(null); releasePlayer(); - String currentStoryMediaId; - if (isHighlight) { - final HighlightsViewModel highlightsViewModel = (HighlightsViewModel) viewModel; - final List models = highlightsViewModel.getList().getValue(); - if (models == null) return; - final HighlightModel model = models.get(currentFeedStoryIndex); - currentStoryMediaId = model.getId(); - currentStoryUsername = model.getTitle(); - } else { - final FeedStoriesViewModel feedStoriesViewModel = (FeedStoriesViewModel) viewModel; - final List models = feedStoriesViewModel.getList().getValue(); - if (models == null) return; - final FeedStoryModel model = models.get(currentFeedStoryIndex); - currentStoryMediaId = model.getStoryMediaId(); - currentStoryUsername = model.getProfileModel().getUsername(); + String currentStoryMediaId = null; + String username = null; + if (currentFeedStoryIndex >= 0) { + if (isHighlight) { + final HighlightsViewModel highlightsViewModel = (HighlightsViewModel) viewModel; + final List models = highlightsViewModel.getList().getValue(); + if (models == null) return; + final HighlightModel model = models.get(currentFeedStoryIndex); + currentStoryMediaId = model.getId(); + currentStoryUsername = model.getTitle(); + } else { + final FeedStoriesViewModel feedStoriesViewModel = (FeedStoriesViewModel) viewModel; + final List models = feedStoriesViewModel.getList().getValue(); + if (models == null) return; + final FeedStoryModel model = models.get(currentFeedStoryIndex); + currentStoryMediaId = model.getStoryMediaId(); + currentStoryUsername = model.getProfileModel().getUsername(); + } + } else if (!Utils.isEmpty(fragmentArgs.getProfileId()) && !Utils.isEmpty(fragmentArgs.getUsername())) { + currentStoryMediaId = fragmentArgs.getProfileId(); + username = fragmentArgs.getUsername(); } isHashtag = fragmentArgs.getIsHashtag(); final boolean hasUsername = !Utils.isEmpty(currentStoryUsername); @@ -493,27 +506,34 @@ public class StoryViewerFragment extends Fragment { } } storiesViewModel.getList().setValue(Collections.emptyList()); - storiesService.getUserStory(currentStoryMediaId, null, false, false, false, isHighlight, new ServiceCallback>() { - @Override - public void onSuccess(final List storyModels) { - fetching = false; - if (storyModels == null || storyModels.isEmpty()) { - storiesViewModel.getList().setValue(Collections.emptyList()); - currentStory = null; - binding.storiesList.setVisibility(View.GONE); - return; - } - binding.storiesList.setVisibility(View.VISIBLE); - storiesViewModel.getList().setValue(storyModels); - currentStory = storyModels.get(0); - refreshStory(); - } + if (currentStoryMediaId == null) return; + storiesService.getUserStory(currentStoryMediaId, + username, + !isLoggedIn && settingsHelper.getBoolean(Constants.STORIESIG), + false, + false, + isHighlight, + new ServiceCallback>() { + @Override + public void onSuccess(final List storyModels) { + fetching = false; + if (storyModels == null || storyModels.isEmpty()) { + storiesViewModel.getList().setValue(Collections.emptyList()); + currentStory = null; + binding.storiesList.setVisibility(View.GONE); + return; + } + binding.storiesList.setVisibility(View.VISIBLE); + storiesViewModel.getList().setValue(storyModels); + currentStory = storyModels.get(0); + refreshStory(); + } - @Override - public void onFailure(final Throwable t) { - Log.e(TAG, "Error", t); - } - }); + @Override + public void onFailure(final Throwable t) { + Log.e(TAG, "Error", t); + } + }); } private void refreshStory() { diff --git a/app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java b/app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java index d338e208..1d6ab846 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java @@ -44,8 +44,6 @@ import awais.instagrabber.customviews.RamboTextView; import awais.instagrabber.customviews.helpers.RecyclerLazyLoader; import awais.instagrabber.customviews.helpers.VideoAwareRecyclerScroller; import awais.instagrabber.databinding.FragmentFeedBinding; -import awais.instagrabber.viewmodels.FeedStoriesViewModel; -import awais.instagrabber.viewmodels.FeedViewModel; import awais.instagrabber.interfaces.FetchListener; import awais.instagrabber.interfaces.MentionClickListener; import awais.instagrabber.models.BasePostModel; @@ -60,6 +58,8 @@ import awais.instagrabber.services.ServiceCallback; import awais.instagrabber.services.StoriesService; import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Utils; +import awais.instagrabber.viewmodels.FeedStoriesViewModel; +import awais.instagrabber.viewmodels.FeedViewModel; import static awais.instagrabber.utils.Utils.settingsHelper; @@ -363,7 +363,7 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre private void setupFeedStories() { feedStoriesViewModel = new ViewModelProvider(fragmentActivity).get(FeedStoriesViewModel.class); final FeedStoriesAdapter feedStoriesAdapter = new FeedStoriesAdapter((model, position) -> { - final NavDirections action = FeedFragmentDirections.actionFeedFragmentToStoryViewerFragment(position, null, false); + final NavDirections action = FeedFragmentDirections.actionFeedFragmentToStoryViewerFragment(position, null, false, null, null); NavHostFragment.findNavController(this).navigate(action); }); binding.feedStoriesRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), RecyclerView.HORIZONTAL, false)); diff --git a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java index f7d99b17..be6152ae 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java @@ -1,5 +1,6 @@ package awais.instagrabber.fragments.main; +import android.content.DialogInterface; import android.content.res.ColorStateList; import android.graphics.Typeface; import android.os.AsyncTask; @@ -25,10 +26,13 @@ import androidx.activity.OnBackPressedDispatcher; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; +import androidx.appcompat.app.AlertDialog; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.content.ContextCompat; import androidx.core.view.ViewCompat; import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentTransaction; import androidx.lifecycle.ViewModelProvider; import androidx.navigation.NavDirections; import androidx.navigation.fragment.NavHostFragment; @@ -57,8 +61,7 @@ import awais.instagrabber.customviews.helpers.GridAutofitLayoutManager; import awais.instagrabber.customviews.helpers.GridSpacingItemDecoration; import awais.instagrabber.customviews.helpers.RecyclerLazyLoader; import awais.instagrabber.databinding.FragmentProfileBinding; -import awais.instagrabber.viewmodels.HighlightsViewModel; -import awais.instagrabber.viewmodels.PostsViewModel; +import awais.instagrabber.dialogs.ProfilePicDialogFragment; import awais.instagrabber.interfaces.FetchListener; import awais.instagrabber.interfaces.MentionClickListener; import awais.instagrabber.models.PostModel; @@ -73,6 +76,8 @@ import awais.instagrabber.services.ServiceCallback; import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.DataBox; import awais.instagrabber.utils.Utils; +import awais.instagrabber.viewmodels.HighlightsViewModel; +import awais.instagrabber.viewmodels.PostsViewModel; import awaisomereport.LogCollector; import static awais.instagrabber.utils.Utils.logCollector; @@ -354,7 +359,6 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe binding.mainProfileImage.setStoriesBorder(); } }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - new HighlightsFetcher(profileId, !isLoggedIn && settingsHelper.getBoolean(Constants.STORIESIG), result -> { @@ -533,7 +537,6 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe // final boolean isSelf = isLoggedIn && profileModel != null && userIdFromCookie != null && userIdFromCookie // .equals(profileModel.getId()); final String favorite = Utils.dataBox.getFavorite(username); - binding.btnFollow.setOnClickListener(v -> { if (!isLoggedIn) { if (favorite != null && v == binding.btnFollow) { @@ -586,7 +589,6 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe }); } }); - binding.btnRestrict.setOnClickListener(v -> { if (!isLoggedIn) return; final String action = profileModel.getRestricted() ? "Unrestrict" : "Restrict"; @@ -663,16 +665,48 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe PostItemType.LIKED); NavHostFragment.findNavController(this).navigate(action); }); - binding.btnTagged.setOnClickListener(v -> { - // startActivity(new Intent(requireContext(), SavedViewerFragment.class) - // .putExtra(Constants.EXTRAS_INDEX, "%" + profileModel.getId()) - // .putExtra(Constants.EXTRAS_USER, username)); final NavDirections action = ProfileFragmentDirections.actionProfileFragmentToSavedViewerFragment(profileModel.getUsername(), profileModel.getId(), PostItemType.TAGGED); NavHostFragment.findNavController(this).navigate(action); }); + binding.mainProfileImage.setOnClickListener(v -> { + if (storyModels == null || storyModels.length <= 0) { + // show profile pic + showProfilePicDialog(); + return; + } + // show dialog + final String[] options = {getString(R.string.view_pfp), getString(R.string.show_stories)}; + final DialogInterface.OnClickListener profileDialogListener = (dialog, which) -> { + if (which == AlertDialog.BUTTON_NEUTRAL) { + dialog.dismiss(); + return; + } + if (which == 1) { + // show stories + final NavDirections action = ProfileFragmentDirections + .actionProfileFragmentToStoryViewerFragment(-1, null, false, profileModel.getId(), username); + NavHostFragment.findNavController(this).navigate(action); + return; + } + showProfilePicDialog(); + }; + new AlertDialog.Builder(requireContext()) + .setItems(options, profileDialogListener) + .setNeutralButton(R.string.cancel, null) + .show(); + }); + } + + private void showProfilePicDialog() { + final FragmentManager fragmentManager = getParentFragmentManager(); + final ProfilePicDialogFragment fragment = new ProfilePicDialogFragment(profileModel.getId(), username, profileModel.getHdProfilePic()); + final FragmentTransaction ft = fragmentManager.beginTransaction(); + ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) + .add(fragment, "profilePicDialog") + .commit(); } private void setUsernameDelayed() { @@ -742,27 +776,9 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe private void setupHighlights() { highlightsViewModel = new ViewModelProvider(fragmentActivity).get(HighlightsViewModel.class); highlightsAdapter = new HighlightsAdapter((model, position) -> { - final NavDirections action = ProfileFragmentDirections.actionProfileFragmentToStoryViewerFragment(position, model.getTitle(), false); + final NavDirections action = ProfileFragmentDirections + .actionProfileFragmentToStoryViewerFragment(position, model.getTitle(), false, null, null); NavHostFragment.findNavController(this).navigate(action); - // new iStoryStatusFetcher( - // model.getId(), - // null, - // false, - // false, - // !isLoggedIn && Utils.settingsHelper.getBoolean(Constants.STORIESIG), - // true, - // result -> { - // if (result == null || result.length <= 0) { - // Toast.makeText(requireContext(), R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); - // return; - // } - // feedStoriesViewModel.getHighlights().postValue(Arrays.asList(result)); - // // startActivity(new Intent(ProfileViewer.this, StoryViewer.class) - // // .putExtra(Constants.EXTRAS_USERNAME, userQuery.replace("@", "")) - // // .putExtra(Constants.EXTRAS_HIGHLIGHT, highlightModel.getTitle()) - // // .putExtra(Constants.EXTRAS_STORIES, result) - // // ); - // }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }); final RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(requireContext(), RecyclerView.HORIZONTAL, false); binding.highlightsList.setLayoutManager(layoutManager); diff --git a/app/src/main/res/layout/activity_profilepic.xml b/app/src/main/res/layout/activity_profilepic.xml deleted file mode 100755 index a667d5f1..00000000 --- a/app/src/main/res/layout/activity_profilepic.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_profilepic.xml b/app/src/main/res/layout/dialog_profilepic.xml new file mode 100644 index 00000000..0b5a4000 --- /dev/null +++ b/app/src/main/res/layout/dialog_profilepic.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + +