mirror of
https://github.com/KokaKiwi/BarInsta
synced 2026-03-05 20:11:36 +00:00
separated profile view activity
This commit is contained in:
parent
e02ef0aa09
commit
392b3f6510
26 changed files with 1131 additions and 274 deletions
|
|
@ -13,13 +13,11 @@ import android.view.inputmethod.InputMethodManager;
|
|||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.SearchView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
|
|
@ -39,8 +37,6 @@ import awais.instagrabber.models.ProfileModel;
|
|||
import awais.instagrabber.utils.Constants;
|
||||
import awais.instagrabber.utils.Utils;
|
||||
|
||||
import static awais.instagrabber.utils.Utils.settingsHelper;
|
||||
|
||||
public final class CommentsViewer extends BaseLanguageActivity implements SwipeRefreshLayout.OnRefreshListener {
|
||||
private CommentsAdapter commentsAdapter;
|
||||
private CommentModel commentModel;
|
||||
|
|
@ -117,7 +113,7 @@ public final class CommentsViewer extends BaseLanguageActivity implements SwipeR
|
|||
if (which == 0) {
|
||||
searchUsername(profileModel.getUsername());
|
||||
} else if (which == 1) {
|
||||
startActivity(new Intent(this, ProfileViewer.class).putExtra(Constants.EXTRAS_PROFILE, profileModel));
|
||||
startActivity(new Intent(this, ProfilePicViewer.class).putExtra(Constants.EXTRAS_PROFILE, profileModel));
|
||||
} else if (which == 2) {
|
||||
Utils.copyText(this, profileModel.getUsername());
|
||||
} else if (which == 3) {
|
||||
|
|
@ -211,11 +207,10 @@ public final class CommentsViewer extends BaseLanguageActivity implements SwipeR
|
|||
};
|
||||
|
||||
private void searchUsername(final String text) {
|
||||
if (Main.scanHack != null) {
|
||||
Main.scanHack.onResult(text);
|
||||
setResult(6969);
|
||||
finish();
|
||||
}
|
||||
startActivity(
|
||||
new Intent(getApplicationContext(), ProfileViewer.class)
|
||||
.putExtra(Constants.EXTRAS_USERNAME, text)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -77,8 +77,10 @@ public final class FollowViewer extends BaseLanguageActivity implements SwipeRef
|
|||
final Object tag = v.getTag();
|
||||
if (tag instanceof FollowModel) {
|
||||
model = (FollowModel) tag;
|
||||
Main.scanHack.onResult(model.getUsername());
|
||||
finish();
|
||||
startActivity(
|
||||
new Intent(getApplicationContext(), ProfileViewer.class)
|
||||
.putExtra(Constants.EXTRAS_USERNAME, model.getUsername())
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ public final class Main extends BaseLanguageActivity {
|
|||
profileDialogListener = (dialog, which) -> {
|
||||
final Intent intent;
|
||||
if (which == 0 || storyModels == null || storyModels.length < 1) {
|
||||
intent = new Intent(this, ProfileViewer.class).putExtra(
|
||||
intent = new Intent(this, ProfilePicViewer.class).putExtra(
|
||||
((hashtagModel != null) ? Constants.EXTRAS_HASHTAG : (locationModel != null ? Constants.EXTRAS_LOCATION : Constants.EXTRAS_PROFILE)),
|
||||
((hashtagModel != null) ? hashtagModel : (locationModel != null ? locationModel : profileModel)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ public final class PostViewer extends BaseLanguageActivity {
|
|||
if (which == 0) {
|
||||
searchUsername(username);
|
||||
} else if (profileModel != null && which == 1) {
|
||||
startActivity(new Intent(this, ProfileViewer.class)
|
||||
startActivity(new Intent(this, ProfilePicViewer.class)
|
||||
.putExtra(Constants.EXTRAS_PROFILE, profileModel));
|
||||
}
|
||||
};
|
||||
|
|
@ -432,13 +432,10 @@ public final class PostViewer extends BaseLanguageActivity {
|
|||
}
|
||||
|
||||
private void searchUsername(final String text) {
|
||||
if (Main.scanHack != null) {
|
||||
Main.scanHack.onResult(text);
|
||||
setResult(6969);
|
||||
Intent intent = new Intent(getApplicationContext(), Main.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
startActivity(intent);
|
||||
}
|
||||
startActivity(
|
||||
new Intent(getApplicationContext(), ProfileViewer.class)
|
||||
.putExtra(Constants.EXTRAS_USERNAME, text)
|
||||
);
|
||||
}
|
||||
|
||||
private void setupVideo() {
|
||||
|
|
|
|||
214
app/src/main/java/awais/instagrabber/activities/ProfilePicViewer.java
Executable file
214
app/src/main/java/awais/instagrabber/activities/ProfilePicViewer.java
Executable file
|
|
@ -0,0 +1,214 @@
|
|||
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);
|
||||
} else {
|
||||
glideRequestManager.load(profilePicUrl).into(profileBinding.imageViewer);
|
||||
showImageInfo();
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}).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;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -527,13 +527,10 @@ public final class StoryViewer extends BaseLanguageActivity {
|
|||
}
|
||||
|
||||
private void searchUsername(final String text) {
|
||||
if (Main.scanHack != null) {
|
||||
Main.scanHack.onResult(text);
|
||||
setResult(6969);
|
||||
Intent intent = new Intent(getApplicationContext(), Main.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
startActivity(intent);
|
||||
}
|
||||
startActivity(
|
||||
new Intent(getApplicationContext(), ProfileViewer.class)
|
||||
.putExtra(Constants.EXTRAS_USERNAME, text)
|
||||
);
|
||||
}
|
||||
|
||||
private void releasePlayer() {
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||
|
||||
import awais.instagrabber.BuildConfig;
|
||||
import awais.instagrabber.R;
|
||||
import awais.instagrabber.activities.ProfileViewer;
|
||||
import awais.instagrabber.activities.ProfilePicViewer;
|
||||
import awais.instagrabber.interfaces.FetchListener;
|
||||
import awais.instagrabber.utils.Utils;
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ public final class DownloadAsync extends AsyncTask<Void, Float, File> {
|
|||
isChannelCreated = true;
|
||||
}
|
||||
|
||||
@StringRes final int titleRes = context instanceof ProfileViewer ? R.string.downloader_downloading_pfp : R.string.downloader_downloading_post;
|
||||
@StringRes final int titleRes = context instanceof ProfilePicViewer ? R.string.downloader_downloading_pfp : 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)
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public final class AboutDialog extends BottomSheetDialogFragment {
|
|||
else if (v == btnMatrix) {
|
||||
intent.setData(Uri.parse("https://matrix.to/#/#instagrabber:matrix.org"));
|
||||
} else
|
||||
intent.setData(Uri.parse("https://github.com/austinhuang0131/instagrabber/"));
|
||||
intent.setData(Uri.parse("https://instagrabber.austinhuang.me"));
|
||||
startActivity(intent);
|
||||
};
|
||||
btnProject.setOnClickListener(onClickListener);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue