mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 14:47:29 +00:00
Add updated profile pic viewer, and view stories from profile.
This commit is contained in:
parent
6b0fe3ff78
commit
7e8fdda81b
@ -168,14 +168,14 @@
|
||||
<!-- android:value=".activities.MainActivity" />-->
|
||||
<!--</activity>-->
|
||||
|
||||
<activity
|
||||
android:name=".activities.ProfilePicViewer"
|
||||
android:parentActivityName=".activities.MainActivity">
|
||||
<!--<activity-->
|
||||
<!-- android:name=".activities.ProfilePicViewer"-->
|
||||
<!-- android:parentActivityName=".activities.MainActivity">-->
|
||||
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".activities.MainActivity" />
|
||||
</activity>
|
||||
<!-- <meta-data-->
|
||||
<!-- android:name="android.support.PARENT_ACTIVITY"-->
|
||||
<!-- android:value=".activities.MainActivity" />-->
|
||||
<!--</activity>-->
|
||||
|
||||
<!--<activity-->
|
||||
<!-- android:name=".activities.ProfileViewer"-->
|
||||
|
@ -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;
|
||||
// }
|
||||
// }
|
@ -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;
|
||||
|
||||
@ -76,10 +75,11 @@ public final class DownloadAsync extends AsyncTask<Void, Float, File> {
|
||||
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)
|
||||
.setSmallIcon(R.mipmap.ic_launcher)
|
||||
.setContentText(shortCode == null ? username : shortCode).setOngoing(true)
|
||||
.setProgress(100, 0, false).setAutoCancel(false).setOnlyAlertOnce(true)
|
||||
.setContentTitle(resources.getString(titleRes));
|
||||
|
||||
@ -231,7 +231,8 @@ public final class DownloadAsync extends AsyncTask<Void, Float, File> {
|
||||
.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)
|
||||
|
@ -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,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());
|
||||
|
@ -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);
|
||||
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,7 +269,8 @@ public class StoryViewerFragment extends Fragment {
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
private void setupListeners() {
|
||||
final boolean hasFeedStories;
|
||||
final List<?> models;
|
||||
List<?> models = null;
|
||||
if (currentFeedStoryIndex > 0) {
|
||||
if (isHighlight) {
|
||||
final HighlightsViewModel highlightsViewModel = (HighlightsViewModel) viewModel;
|
||||
models = highlightsViewModel.getList().getValue();
|
||||
@ -279,7 +284,9 @@ public class StoryViewerFragment extends Fragment {
|
||||
// currentStoryMediaId = model.getStoryMediaId();
|
||||
// currentStoryUsername = model.getProfileModel().getUsername();
|
||||
}
|
||||
}
|
||||
hasFeedStories = models != null && !models.isEmpty();
|
||||
final List<?> finalModels = models;
|
||||
swipeEvent = isRightSwipe -> {
|
||||
final List<StoryModel> 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,7 +466,9 @@ public class StoryViewerFragment extends Fragment {
|
||||
if (menuDm != null) menuDm.setVisible(false);
|
||||
binding.imageViewer.setController(null);
|
||||
releasePlayer();
|
||||
String currentStoryMediaId;
|
||||
String currentStoryMediaId = null;
|
||||
String username = null;
|
||||
if (currentFeedStoryIndex >= 0) {
|
||||
if (isHighlight) {
|
||||
final HighlightsViewModel highlightsViewModel = (HighlightsViewModel) viewModel;
|
||||
final List<HighlightModel> models = highlightsViewModel.getList().getValue();
|
||||
@ -475,6 +484,10 @@ public class StoryViewerFragment extends Fragment {
|
||||
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);
|
||||
if (hasUsername) {
|
||||
@ -493,7 +506,14 @@ public class StoryViewerFragment extends Fragment {
|
||||
}
|
||||
}
|
||||
storiesViewModel.getList().setValue(Collections.emptyList());
|
||||
storiesService.getUserStory(currentStoryMediaId, null, false, false, false, isHighlight, new ServiceCallback<List<StoryModel>>() {
|
||||
if (currentStoryMediaId == null) return;
|
||||
storiesService.getUserStory(currentStoryMediaId,
|
||||
username,
|
||||
!isLoggedIn && settingsHelper.getBoolean(Constants.STORIESIG),
|
||||
false,
|
||||
false,
|
||||
isHighlight,
|
||||
new ServiceCallback<List<StoryModel>>() {
|
||||
@Override
|
||||
public void onSuccess(final List<StoryModel> storyModels) {
|
||||
fetching = false;
|
||||
|
@ -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));
|
||||
|
@ -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);
|
||||
|
@ -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>
|
43
app/src/main/res/layout/dialog_profilepic.xml
Normal file
43
app/src/main/res/layout/dialog_profilepic.xml
Normal file
@ -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>
|
@ -98,5 +98,13 @@
|
||||
<argument
|
||||
android:name="isHashtag"
|
||||
app:argType="boolean" />
|
||||
<argument
|
||||
android:name="profileId"
|
||||
app:argType="string"
|
||||
app:nullable="true" />
|
||||
<argument
|
||||
android:name="username"
|
||||
app:argType="string"
|
||||
app:nullable="true" />
|
||||
</fragment>
|
||||
</navigation>
|
@ -125,5 +125,13 @@
|
||||
<argument
|
||||
android:name="isHashtag"
|
||||
app:argType="boolean" />
|
||||
<argument
|
||||
android:name="profileId"
|
||||
app:argType="string"
|
||||
app:nullable="true" />
|
||||
<argument
|
||||
android:name="username"
|
||||
app:argType="string"
|
||||
app:nullable="true" />
|
||||
</fragment>
|
||||
</navigation>
|
Loading…
Reference in New Issue
Block a user