1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-22 22:57:29 +00:00

Add updated profile pic viewer, and view stories from profile.

This commit is contained in:
Ammar Githam 2020-09-06 18:25:27 +09:00
parent 6b0fe3ff78
commit 7e8fdda81b
12 changed files with 646 additions and 368 deletions

View File

@ -168,14 +168,14 @@
<!-- android:value=".activities.MainActivity" />--> <!-- android:value=".activities.MainActivity" />-->
<!--</activity>--> <!--</activity>-->
<activity <!--<activity-->
android:name=".activities.ProfilePicViewer" <!-- android:name=".activities.ProfilePicViewer"-->
android:parentActivityName=".activities.MainActivity"> <!-- android:parentActivityName=".activities.MainActivity">-->
<meta-data <!-- <meta-data-->
android:name="android.support.PARENT_ACTIVITY" <!-- android:name="android.support.PARENT_ACTIVITY"-->
android:value=".activities.MainActivity" /> <!-- android:value=".activities.MainActivity" />-->
</activity> <!--</activity>-->
<!--<activity--> <!--<activity-->
<!-- android:name=".activities.ProfileViewer"--> <!-- android:name=".activities.ProfileViewer"-->

View File

@ -1,211 +1,223 @@
package awais.instagrabber.activities; // package awais.instagrabber.activities;
//
import android.content.Intent; // import android.content.Intent;
import android.graphics.Bitmap; // import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable; // import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; // import android.graphics.drawable.Drawable;
import android.os.AsyncTask; // import android.os.AsyncTask;
import android.os.Bundle; // import android.os.Bundle;
import android.os.Environment; // import android.os.Environment;
import android.view.Menu; // import android.view.Menu;
import android.view.MenuItem; // import android.view.MenuItem;
import android.view.View; // import android.view.View;
import android.widget.Toast; // import android.widget.Toast;
//
import androidx.annotation.Nullable; // import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentManager; // import androidx.fragment.app.FragmentManager;
//
import com.bumptech.glide.Glide; // import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager; // import com.bumptech.glide.RequestManager;
import com.bumptech.glide.load.DataSource; // import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException; // import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener; // import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target; // import com.bumptech.glide.request.target.Target;
//
import java.io.File; // import java.io.File;
//
import awais.instagrabber.R; // import awais.instagrabber.R;
import awais.instagrabber.asyncs.DownloadAsync; // import awais.instagrabber.asyncs.DownloadAsync;
import awais.instagrabber.asyncs.ProfilePictureFetcher; // import awais.instagrabber.asyncs.ProfilePictureFetcher;
import awais.instagrabber.databinding.ActivityProfilepicBinding; // import awais.instagrabber.databinding.ActivityProfilepicBinding;
import awais.instagrabber.interfaces.FetchListener; // import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.models.HashtagModel; // import awais.instagrabber.models.HashtagModel;
import awais.instagrabber.models.LocationModel; // import awais.instagrabber.models.LocationModel;
import awais.instagrabber.models.ProfileModel; // import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.utils.Constants; // import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.Utils; // import awais.instagrabber.utils.Utils;
//
public final class ProfilePicViewer extends BaseLanguageActivity { // public final class ProfilePicViewer extends BaseLanguageActivity {
private ActivityProfilepicBinding profileBinding; // private ActivityProfilepicBinding profileBinding;
private ProfileModel profileModel; // private ProfileModel profileModel;
private HashtagModel hashtagModel; // private HashtagModel hashtagModel;
private LocationModel locationModel; // private LocationModel locationModel;
private MenuItem menuItemDownload; // private MenuItem menuItemDownload;
private String profilePicUrl; // private String profilePicUrl;
private FragmentManager fragmentManager; // private FragmentManager fragmentManager;
private FetchListener<String> fetchListener; // private FetchListener<String> fetchListener;
private boolean errorHandled = false; // private boolean errorHandled = false;
private boolean fallbackToProfile = false; // private boolean fallbackToProfile = false;
private boolean destroyed = false; // private boolean destroyed = false;
//
@Override // @Override
protected void onCreate(@Nullable final Bundle savedInstanceState) { // protected void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super.onCreate(savedInstanceState);
profileBinding = ActivityProfilepicBinding.inflate(getLayoutInflater()); // profileBinding = ActivityProfilepicBinding.inflate(getLayoutInflater());
setContentView(profileBinding.getRoot()); // 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
final Intent intent = getIntent(); // .hasExtra(Constants.EXTRAS_LOCATION))
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
|| ((profileModel = (ProfileModel) intent.getSerializableExtra(Constants.EXTRAS_PROFILE)) == null // && (hashtagModel = (HashtagModel) intent.getSerializableExtra(Constants.EXTRAS_HASHTAG)) == null
&& (hashtagModel = (HashtagModel) intent.getSerializableExtra(Constants.EXTRAS_HASHTAG)) == null // && (locationModel = (LocationModel) intent.getSerializableExtra(Constants.EXTRAS_LOCATION)) == null)) {
&& (locationModel = (LocationModel) intent.getSerializableExtra(Constants.EXTRAS_LOCATION)) == null)) { // Utils.errorFinish(this);
Utils.errorFinish(this); // return;
return; // }
} //
// fragmentManager = getSupportFragmentManager();
fragmentManager = getSupportFragmentManager(); //
// final String id = hashtagModel != null ? hashtagModel.getId() : (locationModel != null ? locationModel.getId() : profileModel.getId());
final String id = hashtagModel != null ? hashtagModel.getId() : (locationModel != null ? locationModel.getId() : profileModel.getId()); // final String username = hashtagModel != null
final String username = hashtagModel != null ? hashtagModel.getName() : (locationModel != null ? locationModel.getName() : profileModel.getUsername()); // ? hashtagModel.getName()
// : (locationModel != null ? locationModel.getName() : profileModel.getUsername());
profileBinding.toolbar.toolbar.setTitle(username); //
// // profileBinding.toolbar.toolbar.setTitle(username);
profileBinding.progressView.setVisibility(View.VISIBLE); //
profileBinding.imageViewer.setVisibility(View.VISIBLE); // profileBinding.progressView.setVisibility(View.VISIBLE);
// profileBinding.imageViewer.setVisibility(View.VISIBLE);
profileBinding.imageViewer.setZoomable(true); //
profileBinding.imageViewer.setZoomTransitionDuration(420); // // profileBinding.imageViewer.setZoomable(true);
profileBinding.imageViewer.setMaximumScale(7.2f); // // profileBinding.imageViewer.setZoomTransitionDuration(420);
// // profileBinding.imageViewer.setMaximumScale(7.2f);
fetchListener = profileUrl -> { //
profilePicUrl = profileUrl; // fetchListener = profileUrl -> {
// profilePicUrl = profileUrl;
if (!fallbackToProfile && Utils.isEmpty(profilePicUrl)) { //
fallbackToProfile = true; // if (!fallbackToProfile && Utils.isEmpty(profilePicUrl)) {
new ProfilePictureFetcher(username, id, fetchListener, profilePicUrl, (hashtagModel != null || locationModel != null)).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); // fallbackToProfile = true;
return; // 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 (errorHandled && fallbackToProfile || Utils.isEmpty(profilePicUrl))
if (destroyed == true) return; // profilePicUrl = hashtagModel != null
// ? hashtagModel.getSdProfilePic()
final RequestManager glideRequestManager = Glide.with(this); // : (locationModel != null ? locationModel.getSdProfilePic() : profileModel.getHdProfilePic());
//
glideRequestManager.load(profilePicUrl).addListener(new RequestListener<Drawable>() { // if (destroyed == true) return;
@Override //
public boolean onLoadFailed(@Nullable final GlideException e, final Object model, final Target<Drawable> target, final boolean isFirstResource) { // final RequestManager glideRequestManager = Glide.with(this);
fallbackToProfile = true; //
if (!errorHandled) { // glideRequestManager.load(profilePicUrl).addListener(new RequestListener<Drawable>() {
errorHandled = true; // @Override
new ProfilePictureFetcher(username, id, fetchListener, profilePicUrl, (hashtagModel != null || locationModel != null)) // public boolean onLoadFailed(@Nullable final GlideException e,
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); // final Object model,
} // final Target<Drawable> target,
profileBinding.progressView.setVisibility(View.GONE); // final boolean isFirstResource) {
return false; // fallbackToProfile = true;
} // if (!errorHandled) {
// errorHandled = true;
@Override // new ProfilePictureFetcher(username, id, fetchListener, profilePicUrl, (hashtagModel != null || locationModel != null))
public boolean onResourceReady(final Drawable resource, final Object model, final Target<Drawable> target, final DataSource dataSource, final boolean isFirstResource) { // .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if (menuItemDownload != null) menuItemDownload.setEnabled(true); // }
showImageInfo(); // profileBinding.progressView.setVisibility(View.GONE);
profileBinding.progressView.setVisibility(View.GONE); // return false;
return false; // }
} //
// @Override
private void showImageInfo() { // public boolean onResourceReady(final Drawable resource,
final Drawable drawable = profileBinding.imageViewer.getDrawable(); // final Object model,
if (drawable != null) { // final Target<Drawable> target,
final StringBuilder info = new StringBuilder(getString(R.string.profile_viewer_imageinfo, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight())); // final DataSource dataSource,
if (drawable instanceof BitmapDrawable) { // final boolean isFirstResource) {
final Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap(); // if (menuItemDownload != null) menuItemDownload.setEnabled(true);
if (bitmap != null) { // showImageInfo();
final String colorDepthPrefix = getString(R.string.profile_viewer_colordepth_prefix); // profileBinding.progressView.setVisibility(View.GONE);
switch (bitmap.getConfig()) { // return false;
case ALPHA_8: // }
info.append(colorDepthPrefix).append(" 8-bits(A)"); //
break; // private void showImageInfo() {
case RGB_565: // final Drawable drawable = profileBinding.imageViewer.getDrawable();
info.append(colorDepthPrefix).append(" 16-bits-A"); // if (drawable != null) {
break; // final StringBuilder info = new StringBuilder(
case ARGB_4444: // getString(R.string.profile_viewer_imageinfo, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()));
info.append(colorDepthPrefix).append(" 16-bits+A"); // if (drawable instanceof BitmapDrawable) {
break; // final Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
case ARGB_8888: // if (bitmap != null) {
info.append(colorDepthPrefix).append(" 32-bits+A"); // final String colorDepthPrefix = getString(R.string.profile_viewer_colordepth_prefix);
break; // switch (bitmap.getConfig()) {
case RGBA_F16: // case ALPHA_8:
info.append(colorDepthPrefix).append(" 64-bits+A"); // info.append(colorDepthPrefix).append(" 8-bits(A)");
break; // break;
case HARDWARE: // case RGB_565:
info.append(colorDepthPrefix).append(" auto"); // info.append(colorDepthPrefix).append(" 16-bits-A");
break; // break;
} // case ARGB_4444:
} // info.append(colorDepthPrefix).append(" 16-bits+A");
} // break;
profileBinding.imageInfo.setText(info); // case ARGB_8888:
profileBinding.imageInfo.setVisibility(View.VISIBLE); // info.append(colorDepthPrefix).append(" 32-bits+A");
} // break;
} // case RGBA_F16:
}).error(glideRequestManager.load(profilePicUrl)).into(profileBinding.imageViewer); // info.append(colorDepthPrefix).append(" 64-bits+A");
}; // break;
// case HARDWARE:
new ProfilePictureFetcher(username, id, fetchListener, profilePicUrl, (hashtagModel != null || locationModel != null)) // info.append(colorDepthPrefix).append(" auto");
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); // break;
} // }
// }
private void downloadProfilePicture() { // }
int error = 0; // // profileBinding.imageInfo.setText(info);
// // profileBinding.imageInfo.setVisibility(View.VISIBLE);
if (profileModel != null) { // }
final File dir = new File(Environment.getExternalStorageDirectory(), "Download"); // }
if (dir.exists() || dir.mkdirs()) { // }).error(glideRequestManager.load(profilePicUrl)).into(profileBinding.imageViewer);
// };
final File saveFile = new File(dir, profileModel.getUsername() + '_' + System.currentTimeMillis() //
+ Utils.getExtensionFromModel(profilePicUrl, profileModel)); // new ProfilePictureFetcher(username, id, fetchListener, profilePicUrl, (hashtagModel != null || locationModel != null))
// .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new DownloadAsync(this, // }
profilePicUrl, //
saveFile, // private void downloadProfilePicture() {
result -> { // int error = 0;
final int toastRes = result != null && result.exists() ? //
R.string.downloader_downloaded_in_folder : R.string.downloader_error_download_file; // if (profileModel != null) {
Toast.makeText(this, toastRes, Toast.LENGTH_SHORT).show(); // final File dir = new File(Environment.getExternalStorageDirectory(), "Download");
}).setItems(null, profileModel.getUsername()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); // if (dir.exists() || dir.mkdirs()) {
} else error = 1; //
} else error = 2; // final File saveFile = new File(dir, profileModel.getUsername() + '_' + System.currentTimeMillis()
// + Utils.getExtensionFromModel(profilePicUrl, profileModel));
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(); // new DownloadAsync(this,
} // profilePicUrl,
// saveFile,
@Override // result -> {
protected void onDestroy() { // final int toastRes = result != null && result.exists() ?
super.onDestroy(); // R.string.downloader_downloaded_in_folder : R.string.downloader_error_download_file;
getDelegate().onDestroy(); // Toast.makeText(this, toastRes, Toast.LENGTH_SHORT).show();
destroyed = true; // }).setItems(null, profileModel.getUsername()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} // } else error = 1;
// } else error = 2;
@Override //
public boolean onCreateOptionsMenu(final Menu menu) { // if (error == 1) Toast.makeText(this, R.string.downloader_error_creating_folder, Toast.LENGTH_SHORT).show();
getMenuInflater().inflate(R.menu.menu, menu); // else if (error == 2) Toast.makeText(this, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
// }
final MenuItem.OnMenuItemClickListener menuItemClickListener = item -> { //
if (item == menuItemDownload) { // @Override
downloadProfilePicture(); // protected void onDestroy() {
} // super.onDestroy();
return true; // getDelegate().onDestroy();
}; // destroyed = true;
// }
menu.findItem(R.id.action_search).setVisible(false); //
menuItemDownload = menu.findItem(R.id.action_download); // @Override
menuItemDownload.setVisible(true); // public boolean onCreateOptionsMenu(final Menu menu) {
menuItemDownload.setEnabled(false); // getMenuInflater().inflate(R.menu.menu, menu);
menuItemDownload.setOnMenuItemClickListener(menuItemClickListener); //
// final MenuItem.OnMenuItemClickListener menuItemClickListener = item -> {
return true; // 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;
// }
// }

View File

@ -34,7 +34,6 @@ import java.util.concurrent.atomic.AtomicReference;
import awais.instagrabber.BuildConfig; import awais.instagrabber.BuildConfig;
import awais.instagrabber.R; import awais.instagrabber.R;
import awais.instagrabber.activities.ProfilePicViewer;
import awais.instagrabber.interfaces.FetchListener; import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.utils.Utils; import awais.instagrabber.utils.Utils;
@ -76,10 +75,11 @@ public final class DownloadAsync extends AsyncTask<Void, Float, File> {
isChannelCreated = true; 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) 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) .setProgress(100, 0, false).setAutoCancel(false).setOnlyAlertOnce(true)
.setContentTitle(resources.getString(titleRes)); .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) .setWhen(System.currentTimeMillis()).setOngoing(false).setOnlyAlertOnce(false).setAutoCancel(true)
.setGroup(NOTIF_GROUP_NAME).setGroupSummary(true).setContentIntent( .setGroup(NOTIF_GROUP_NAME).setGroupSummary(true).setContentIntent(
PendingIntent.getActivity(context, 2020, new Intent(Intent.ACTION_VIEW, uri) 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)); .putExtra(Intent.EXTRA_STREAM, uri), PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT));
if (bitmap != null) if (bitmap != null)

View File

@ -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);
// }
// }
}

View File

@ -1,7 +1,6 @@
package awais.instagrabber.fragments; package awais.instagrabber.fragments;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
@ -28,15 +27,17 @@ import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SearchView; import androidx.appcompat.widget.SearchView;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.navigation.NavDirections; import androidx.navigation.NavDirections;
import androidx.navigation.fragment.NavHostFragment; import androidx.navigation.fragment.NavHostFragment;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import awais.instagrabber.R; import awais.instagrabber.R;
import awais.instagrabber.activities.ProfilePicViewer;
import awais.instagrabber.adapters.CommentsAdapter; import awais.instagrabber.adapters.CommentsAdapter;
import awais.instagrabber.asyncs.CommentsFetcher; import awais.instagrabber.asyncs.CommentsFetcher;
import awais.instagrabber.databinding.FragmentCommentsBinding; import awais.instagrabber.databinding.FragmentCommentsBinding;
import awais.instagrabber.dialogs.ProfilePicDialogFragment;
import awais.instagrabber.interfaces.MentionClickListener; import awais.instagrabber.interfaces.MentionClickListener;
import awais.instagrabber.models.CommentModel; import awais.instagrabber.models.CommentModel;
import awais.instagrabber.models.ProfileModel; import awais.instagrabber.models.ProfileModel;
@ -181,7 +182,14 @@ public final class CommentsViewerFragment extends Fragment implements SwipeRefre
openProfile(profileModel.getUsername()); openProfile(profileModel.getUsername());
break; break;
case 1: // view profile pic 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; break;
case 2: // copy username case 2: // copy username
Utils.copyText(requireContext(), profileModel.getUsername()); Utils.copyText(requireContext(), profileModel.getUsername());

View File

@ -70,9 +70,6 @@ import awais.instagrabber.asyncs.VoteAction;
import awais.instagrabber.asyncs.direct_messages.DirectThreadBroadcaster; import awais.instagrabber.asyncs.direct_messages.DirectThreadBroadcaster;
import awais.instagrabber.customviews.helpers.SwipeGestureListener; import awais.instagrabber.customviews.helpers.SwipeGestureListener;
import awais.instagrabber.databinding.ActivityStoryViewerBinding; 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.interfaces.SwipeEvent;
import awais.instagrabber.models.FeedStoryModel; import awais.instagrabber.models.FeedStoryModel;
import awais.instagrabber.models.HighlightModel; import awais.instagrabber.models.HighlightModel;
@ -85,6 +82,9 @@ import awais.instagrabber.services.ServiceCallback;
import awais.instagrabber.services.StoriesService; import awais.instagrabber.services.StoriesService;
import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.Utils; import awais.instagrabber.utils.Utils;
import awais.instagrabber.viewmodels.FeedStoriesViewModel;
import awais.instagrabber.viewmodels.HighlightsViewModel;
import awais.instagrabber.viewmodels.StoriesViewModel;
import awaisomereport.LogCollector; import awaisomereport.LogCollector;
import static awais.instagrabber.customviews.helpers.SwipeGestureListener.SWIPE_THRESHOLD; import static awais.instagrabber.customviews.helpers.SwipeGestureListener.SWIPE_THRESHOLD;
@ -123,11 +123,12 @@ public class StoryViewerFragment extends Fragment {
private int currentFeedStoryIndex; private int currentFeedStoryIndex;
private StoriesViewModel storiesViewModel; private StoriesViewModel storiesViewModel;
private boolean shouldRefresh = true; private boolean shouldRefresh = true;
private final String cookie = settingsHelper.getString(Constants.COOKIE);
private StoryViewerFragmentArgs fragmentArgs; private StoryViewerFragmentArgs fragmentArgs;
private ViewModel viewModel; private ViewModel viewModel;
private boolean isHighlight; private boolean isHighlight;
private boolean isLoggedIn;
private final String cookie = settingsHelper.getString(Constants.COOKIE);
@Override @Override
public void onCreate(@Nullable final Bundle savedInstanceState) { public void onCreate(@Nullable final Bundle savedInstanceState) {
@ -235,14 +236,17 @@ public class StoryViewerFragment extends Fragment {
} }
private void init() { private void init() {
isLoggedIn = !Utils.isEmpty(cookie) && Utils.getUserIdFromCookie(cookie) != null;
if (getArguments() == null) return; if (getArguments() == null) return;
fragmentArgs = StoryViewerFragmentArgs.fromBundle(getArguments()); fragmentArgs = StoryViewerFragmentArgs.fromBundle(getArguments());
currentFeedStoryIndex = fragmentArgs.getFeedStoryIndex(); currentFeedStoryIndex = fragmentArgs.getFeedStoryIndex();
highlight = fragmentArgs.getHighlight(); highlight = fragmentArgs.getHighlight();
isHighlight = !Utils.isEmpty(highlight); isHighlight = !Utils.isEmpty(highlight);
if (currentFeedStoryIndex >= 0) {
viewModel = isHighlight viewModel = isHighlight
? new ViewModelProvider(fragmentActivity).get(HighlightsViewModel.class) ? new ViewModelProvider(fragmentActivity).get(HighlightsViewModel.class)
: new ViewModelProvider(fragmentActivity).get(FeedStoriesViewModel.class); : new ViewModelProvider(fragmentActivity).get(FeedStoriesViewModel.class);
}
// feedStoryModels = feedStoriesViewModel.getList().getValue(); // feedStoryModels = feedStoriesViewModel.getList().getValue();
// feedStoryModels == null || feedStoryModels.isEmpty() || // feedStoryModels == null || feedStoryModels.isEmpty() ||
setupStories(); setupStories();
@ -265,7 +269,8 @@ public class StoryViewerFragment extends Fragment {
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
private void setupListeners() { private void setupListeners() {
final boolean hasFeedStories; final boolean hasFeedStories;
final List<?> models; List<?> models = null;
if (currentFeedStoryIndex > 0) {
if (isHighlight) { if (isHighlight) {
final HighlightsViewModel highlightsViewModel = (HighlightsViewModel) viewModel; final HighlightsViewModel highlightsViewModel = (HighlightsViewModel) viewModel;
models = highlightsViewModel.getList().getValue(); models = highlightsViewModel.getList().getValue();
@ -279,7 +284,9 @@ public class StoryViewerFragment extends Fragment {
// currentStoryMediaId = model.getStoryMediaId(); // currentStoryMediaId = model.getStoryMediaId();
// currentStoryUsername = model.getProfileModel().getUsername(); // currentStoryUsername = model.getProfileModel().getUsername();
} }
}
hasFeedStories = models != null && !models.isEmpty(); hasFeedStories = models != null && !models.isEmpty();
final List<?> finalModels = models;
swipeEvent = isRightSwipe -> { swipeEvent = isRightSwipe -> {
final List<StoryModel> storyModels = storiesViewModel.getList().getValue(); final List<StoryModel> storyModels = storiesViewModel.getList().getValue();
final int storiesLen = storyModels == null ? 0 : storyModels.size(); final int storiesLen = storyModels == null ? 0 : storyModels.size();
@ -292,13 +299,13 @@ public class StoryViewerFragment extends Fragment {
if (settingsHelper.getBoolean(MARK_AS_SEEN)) { if (settingsHelper.getBoolean(MARK_AS_SEEN)) {
new SeenAction(cookie, currentStory).execute(); 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(); Toast.makeText(requireContext(), R.string.no_more_stories, Toast.LENGTH_SHORT).show();
return; return;
} }
final Object feedStoryModel = isRightSwipe final Object feedStoryModel = isRightSwipe
? models.get(index - 1) ? finalModels.get(index - 1)
: models.size() == index + 1 ? null : models.get(index + 1); : finalModels.size() == index + 1 ? null : finalModels.get(index + 1);
if (feedStoryModel != null) { if (feedStoryModel != null) {
if (fetching) { if (fetching) {
Toast.makeText(requireContext(), R.string.be_patient, Toast.LENGTH_SHORT).show(); 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); if (menuDm != null) menuDm.setVisible(false);
binding.imageViewer.setController(null); binding.imageViewer.setController(null);
releasePlayer(); releasePlayer();
String currentStoryMediaId; String currentStoryMediaId = null;
String username = null;
if (currentFeedStoryIndex >= 0) {
if (isHighlight) { if (isHighlight) {
final HighlightsViewModel highlightsViewModel = (HighlightsViewModel) viewModel; final HighlightsViewModel highlightsViewModel = (HighlightsViewModel) viewModel;
final List<HighlightModel> models = highlightsViewModel.getList().getValue(); final List<HighlightModel> models = highlightsViewModel.getList().getValue();
@ -475,6 +484,10 @@ public class StoryViewerFragment extends Fragment {
currentStoryMediaId = model.getStoryMediaId(); currentStoryMediaId = model.getStoryMediaId();
currentStoryUsername = model.getProfileModel().getUsername(); currentStoryUsername = model.getProfileModel().getUsername();
} }
} else if (!Utils.isEmpty(fragmentArgs.getProfileId()) && !Utils.isEmpty(fragmentArgs.getUsername())) {
currentStoryMediaId = fragmentArgs.getProfileId();
username = fragmentArgs.getUsername();
}
isHashtag = fragmentArgs.getIsHashtag(); isHashtag = fragmentArgs.getIsHashtag();
final boolean hasUsername = !Utils.isEmpty(currentStoryUsername); final boolean hasUsername = !Utils.isEmpty(currentStoryUsername);
if (hasUsername) { if (hasUsername) {
@ -493,7 +506,14 @@ public class StoryViewerFragment extends Fragment {
} }
} }
storiesViewModel.getList().setValue(Collections.emptyList()); 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 @Override
public void onSuccess(final List<StoryModel> storyModels) { public void onSuccess(final List<StoryModel> storyModels) {
fetching = false; fetching = false;

View File

@ -44,8 +44,6 @@ import awais.instagrabber.customviews.RamboTextView;
import awais.instagrabber.customviews.helpers.RecyclerLazyLoader; import awais.instagrabber.customviews.helpers.RecyclerLazyLoader;
import awais.instagrabber.customviews.helpers.VideoAwareRecyclerScroller; import awais.instagrabber.customviews.helpers.VideoAwareRecyclerScroller;
import awais.instagrabber.databinding.FragmentFeedBinding; import awais.instagrabber.databinding.FragmentFeedBinding;
import awais.instagrabber.viewmodels.FeedStoriesViewModel;
import awais.instagrabber.viewmodels.FeedViewModel;
import awais.instagrabber.interfaces.FetchListener; import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.interfaces.MentionClickListener; import awais.instagrabber.interfaces.MentionClickListener;
import awais.instagrabber.models.BasePostModel; import awais.instagrabber.models.BasePostModel;
@ -60,6 +58,8 @@ import awais.instagrabber.services.ServiceCallback;
import awais.instagrabber.services.StoriesService; import awais.instagrabber.services.StoriesService;
import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.Utils; import awais.instagrabber.utils.Utils;
import awais.instagrabber.viewmodels.FeedStoriesViewModel;
import awais.instagrabber.viewmodels.FeedViewModel;
import static awais.instagrabber.utils.Utils.settingsHelper; import static awais.instagrabber.utils.Utils.settingsHelper;
@ -363,7 +363,7 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
private void setupFeedStories() { private void setupFeedStories() {
feedStoriesViewModel = new ViewModelProvider(fragmentActivity).get(FeedStoriesViewModel.class); feedStoriesViewModel = new ViewModelProvider(fragmentActivity).get(FeedStoriesViewModel.class);
final FeedStoriesAdapter feedStoriesAdapter = new FeedStoriesAdapter((model, position) -> { 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); NavHostFragment.findNavController(this).navigate(action);
}); });
binding.feedStoriesRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), RecyclerView.HORIZONTAL, false)); binding.feedStoriesRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), RecyclerView.HORIZONTAL, false));

View File

@ -1,5 +1,6 @@
package awais.instagrabber.fragments.main; package awais.instagrabber.fragments.main;
import android.content.DialogInterface;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.os.AsyncTask; import android.os.AsyncTask;
@ -25,10 +26,13 @@ import androidx.activity.OnBackPressedDispatcher;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.core.view.ViewCompat; import androidx.core.view.ViewCompat;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.NavDirections; import androidx.navigation.NavDirections;
import androidx.navigation.fragment.NavHostFragment; 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.GridSpacingItemDecoration;
import awais.instagrabber.customviews.helpers.RecyclerLazyLoader; import awais.instagrabber.customviews.helpers.RecyclerLazyLoader;
import awais.instagrabber.databinding.FragmentProfileBinding; import awais.instagrabber.databinding.FragmentProfileBinding;
import awais.instagrabber.viewmodels.HighlightsViewModel; import awais.instagrabber.dialogs.ProfilePicDialogFragment;
import awais.instagrabber.viewmodels.PostsViewModel;
import awais.instagrabber.interfaces.FetchListener; import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.interfaces.MentionClickListener; import awais.instagrabber.interfaces.MentionClickListener;
import awais.instagrabber.models.PostModel; import awais.instagrabber.models.PostModel;
@ -73,6 +76,8 @@ import awais.instagrabber.services.ServiceCallback;
import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.DataBox; import awais.instagrabber.utils.DataBox;
import awais.instagrabber.utils.Utils; import awais.instagrabber.utils.Utils;
import awais.instagrabber.viewmodels.HighlightsViewModel;
import awais.instagrabber.viewmodels.PostsViewModel;
import awaisomereport.LogCollector; import awaisomereport.LogCollector;
import static awais.instagrabber.utils.Utils.logCollector; import static awais.instagrabber.utils.Utils.logCollector;
@ -354,7 +359,6 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
binding.mainProfileImage.setStoriesBorder(); binding.mainProfileImage.setStoriesBorder();
} }
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new HighlightsFetcher(profileId, new HighlightsFetcher(profileId,
!isLoggedIn && settingsHelper.getBoolean(Constants.STORIESIG), !isLoggedIn && settingsHelper.getBoolean(Constants.STORIESIG),
result -> { result -> {
@ -533,7 +537,6 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
// final boolean isSelf = isLoggedIn && profileModel != null && userIdFromCookie != null && userIdFromCookie // final boolean isSelf = isLoggedIn && profileModel != null && userIdFromCookie != null && userIdFromCookie
// .equals(profileModel.getId()); // .equals(profileModel.getId());
final String favorite = Utils.dataBox.getFavorite(username); final String favorite = Utils.dataBox.getFavorite(username);
binding.btnFollow.setOnClickListener(v -> { binding.btnFollow.setOnClickListener(v -> {
if (!isLoggedIn) { if (!isLoggedIn) {
if (favorite != null && v == binding.btnFollow) { if (favorite != null && v == binding.btnFollow) {
@ -586,7 +589,6 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
}); });
} }
}); });
binding.btnRestrict.setOnClickListener(v -> { binding.btnRestrict.setOnClickListener(v -> {
if (!isLoggedIn) return; if (!isLoggedIn) return;
final String action = profileModel.getRestricted() ? "Unrestrict" : "Restrict"; final String action = profileModel.getRestricted() ? "Unrestrict" : "Restrict";
@ -663,16 +665,48 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
PostItemType.LIKED); PostItemType.LIKED);
NavHostFragment.findNavController(this).navigate(action); NavHostFragment.findNavController(this).navigate(action);
}); });
binding.btnTagged.setOnClickListener(v -> { 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(), final NavDirections action = ProfileFragmentDirections.actionProfileFragmentToSavedViewerFragment(profileModel.getUsername(),
profileModel.getId(), profileModel.getId(),
PostItemType.TAGGED); PostItemType.TAGGED);
NavHostFragment.findNavController(this).navigate(action); 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() { private void setUsernameDelayed() {
@ -742,27 +776,9 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
private void setupHighlights() { private void setupHighlights() {
highlightsViewModel = new ViewModelProvider(fragmentActivity).get(HighlightsViewModel.class); highlightsViewModel = new ViewModelProvider(fragmentActivity).get(HighlightsViewModel.class);
highlightsAdapter = new HighlightsAdapter((model, position) -> { 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); 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); final RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(requireContext(), RecyclerView.HORIZONTAL, false);
binding.highlightsList.setLayoutManager(layoutManager); binding.highlightsList.setLayoutManager(layoutManager);

View File

@ -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>

View 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>

View File

@ -98,5 +98,13 @@
<argument <argument
android:name="isHashtag" android:name="isHashtag"
app:argType="boolean" /> app:argType="boolean" />
<argument
android:name="profileId"
app:argType="string"
app:nullable="true" />
<argument
android:name="username"
app:argType="string"
app:nullable="true" />
</fragment> </fragment>
</navigation> </navigation>

View File

@ -125,5 +125,13 @@
<argument <argument
android:name="isHashtag" android:name="isHashtag"
app:argType="boolean" /> app:argType="boolean" />
<argument
android:name="profileId"
app:argType="string"
app:nullable="true" />
<argument
android:name="username"
app:argType="string"
app:nullable="true" />
</fragment> </fragment>
</navigation> </navigation>