Browse Source
Add updated profile pic viewer, and view stories from profile.
renovate/org.robolectric-robolectric-4.x
Add updated profile pic viewer, and view stories from profile.
renovate/org.robolectric-robolectric-4.x
Ammar Githam
4 years ago
12 changed files with 646 additions and 368 deletions
-
14app/src/main/AndroidManifest.xml
-
434app/src/main/java/awais/instagrabber/activities/ProfilePicViewer.java
-
9app/src/main/java/awais/instagrabber/asyncs/DownloadAsync.java
-
199app/src/main/java/awais/instagrabber/dialogs/ProfilePicDialogFragment.java
-
14app/src/main/java/awais/instagrabber/fragments/CommentsViewerFragment.java
-
42app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java
-
6app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java
-
74app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java
-
37app/src/main/res/layout/activity_profilepic.xml
-
43app/src/main/res/layout/dialog_profilepic.xml
-
8app/src/main/res/navigation/feed_nav_graph.xml
-
8app/src/main/res/navigation/profile_nav_graph.xml
@ -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<String> 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<Drawable>() { |
|
||||
@Override |
|
||||
public boolean onLoadFailed(@Nullable final GlideException e, final Object model, final Target<Drawable> 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<Drawable> 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; |
|
||||
} |
|
||||
} |
|
||||
|
// 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<String> 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<Drawable>() { |
||||
|
// @Override |
||||
|
// public boolean onLoadFailed(@Nullable final GlideException e, |
||||
|
// final Object model, |
||||
|
// final Target<Drawable> 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<Drawable> 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; |
||||
|
// } |
||||
|
// } |
@ -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<String> 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<ImageInfo>() { |
||||
|
@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); |
||||
|
// } |
||||
|
// } |
||||
|
} |
@ -1,37 +0,0 @@ |
|||||
<?xml version="1.0" encoding="utf-8"?> |
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
||||
xmlns:tools="http://schemas.android.com/tools" |
|
||||
android:layout_width="match_parent" |
|
||||
android:layout_height="match_parent" |
|
||||
android:orientation="vertical" |
|
||||
tools:context=".activities.ProfilePicViewer"> |
|
||||
|
|
||||
<include |
|
||||
android:id="@+id/toolbar" |
|
||||
layout="@layout/layout_include_toolbar" /> |
|
||||
|
|
||||
<FrameLayout |
|
||||
android:layout_width="match_parent" |
|
||||
android:layout_height="match_parent"> |
|
||||
|
|
||||
<com.github.chrisbanes.photoview.PhotoView |
|
||||
android:id="@+id/imageViewer" |
|
||||
android:layout_width="match_parent" |
|
||||
android:layout_height="match_parent" /> |
|
||||
|
|
||||
<androidx.appcompat.widget.AppCompatTextView |
|
||||
android:id="@+id/imageInfo" |
|
||||
android:layout_width="wrap_content" |
|
||||
android:layout_height="wrap_content" |
|
||||
android:layout_gravity="end" |
|
||||
android:background="#40000000" |
|
||||
android:padding="8dp" |
|
||||
android:visibility="gone" /> |
|
||||
|
|
||||
<ProgressBar |
|
||||
android:id="@+id/progressView" |
|
||||
android:layout_width="96dp" |
|
||||
android:layout_height="96dp" |
|
||||
android:layout_gravity="center" /> |
|
||||
</FrameLayout> |
|
||||
</LinearLayout> |
|
@ -0,0 +1,43 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
|
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
|
xmlns:tools="http://schemas.android.com/tools" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="match_parent" |
||||
|
android:background="@color/semi_transparent_black"> |
||||
|
|
||||
|
<awais.instagrabber.customviews.drawee.ZoomableDraweeView |
||||
|
android:id="@+id/imageViewer" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="match_parent" /> |
||||
|
|
||||
|
<!--<androidx.appcompat.widget.AppCompatTextView--> |
||||
|
<!-- android:id="@+id/imageInfo"--> |
||||
|
<!-- android:layout_width="wrap_content"--> |
||||
|
<!-- android:layout_height="wrap_content"--> |
||||
|
<!-- android:background="@android:color/black"--> |
||||
|
<!-- android:padding="8dp"--> |
||||
|
<!-- android:text="Test text"--> |
||||
|
<!-- android:textColor="@android:color/white"--> |
||||
|
<!-- android:visibility="visible"--> |
||||
|
<!-- tools:visibility="visible" />--> |
||||
|
|
||||
|
<ProgressBar |
||||
|
android:id="@+id/progressView" |
||||
|
style="@android:style/Widget.DeviceDefault.Light.ProgressBar.Large" |
||||
|
android:layout_width="wrap_content" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:layout_gravity="center" |
||||
|
android:background="@android:color/transparent" /> |
||||
|
|
||||
|
<Button |
||||
|
android:id="@+id/download" |
||||
|
style="@style/Widget.MaterialComponents.Button.TextButton" |
||||
|
android:layout_width="wrap_content" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:layout_gravity="bottom|end" |
||||
|
android:text="@string/action_download" |
||||
|
android:visibility="gone" |
||||
|
app:icon="@drawable/ic_download" |
||||
|
tools:visibility="visible" /> |
||||
|
</FrameLayout> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue