mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-12-22 21:16:57 +00:00
downloader fix
This commit is contained in:
parent
bb8f189784
commit
6f120fffd4
@ -277,8 +277,7 @@ public final class PostViewer extends BaseLanguageActivity {
|
||||
resources = getResources();
|
||||
|
||||
viewerBinding.topPanel.title.setMovementMethod(new LinkMovementMethod());
|
||||
viewerBinding.topPanel.title.setMentionClickListener((view, text, isHashtag) ->
|
||||
onClickListener.onClick(viewerBinding.topPanel.ivProfilePic));
|
||||
viewerBinding.topPanel.title.setMentionClickListener((view, text, isHashtag) -> searchUsername(text));
|
||||
viewerBinding.topPanel.ivProfilePic.setOnClickListener(onClickListener);
|
||||
|
||||
viewerBinding.ivToggleFullScreen.setOnClickListener(onClickListener);
|
||||
|
@ -1,6 +1,7 @@
|
||||
package awais.instagrabber.activities;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
@ -15,6 +16,7 @@ import android.text.style.RelativeSizeSpan;
|
||||
import android.text.style.StyleSpan;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -67,6 +69,7 @@ import awais.instagrabber.models.LocationModel;
|
||||
import awais.instagrabber.models.PostModel;
|
||||
import awais.instagrabber.models.ProfileModel;
|
||||
import awais.instagrabber.models.StoryModel;
|
||||
import awais.instagrabber.models.enums.DownloadMethod;
|
||||
import awais.instagrabber.models.enums.ItemGetType;
|
||||
import awais.instagrabber.utils.Constants;
|
||||
import awais.instagrabber.utils.DataBox;
|
||||
@ -136,10 +139,7 @@ public final class ProfileViewer extends BaseLanguageActivity implements SwipeRe
|
||||
private final MentionClickListener mentionClickListener = new MentionClickListener() {
|
||||
@Override
|
||||
public void onClick(final RamboTextView view, final String text, final boolean isHashtag) {
|
||||
new AlertDialog.Builder(ProfileViewer.this).setMessage(isHashtag ? R.string.comment_view_mention_hash_search : R.string.comment_view_mention_user_search)
|
||||
.setTitle(text).setNegativeButton(R.string.cancel, null).setPositiveButton(R.string.ok, (dialog, which) -> {
|
||||
//if (scanHack != null) scanHack.onResult(text);
|
||||
}).show();
|
||||
startActivity(new Intent(getApplicationContext(), ProfileViewer.class).putExtra(Constants.EXTRAS_USERNAME, text));
|
||||
}
|
||||
};
|
||||
public final HighlightsAdapter highlightsAdapter = new HighlightsAdapter(null, new View.OnClickListener() {
|
||||
@ -214,7 +214,7 @@ public final class ProfileViewer extends BaseLanguageActivity implements SwipeRe
|
||||
else startActivity(new Intent(ProfileViewer.this, PostViewer.class)
|
||||
.putExtra(Constants.EXTRAS_INDEX, postModel.getPosition())
|
||||
.putExtra(Constants.EXTRAS_POST, postModel)
|
||||
//.putExtra(Constants.EXTRAS_USER, userQuery)
|
||||
.putExtra(Constants.EXTRAS_USER, userQuery)
|
||||
.putExtra(Constants.EXTRAS_TYPE, ItemGetType.MAIN_ITEMS));
|
||||
}
|
||||
}, v -> { // long click listener
|
||||
@ -708,6 +708,22 @@ public final class ProfileViewer extends BaseLanguageActivity implements SwipeRe
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(final Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.saved, menu);
|
||||
|
||||
downloadAction = menu.findItem(R.id.downloadAction);
|
||||
downloadAction.setVisible(false);
|
||||
|
||||
downloadAction.setOnMenuItemClickListener(item -> {
|
||||
if (selectedItems.size() > 0) {
|
||||
Utils.batchDownload(this, userQuery, DownloadMethod.DOWNLOAD_MAIN, selectedItems);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
private void toggleSelection(final PostModel postModel) {
|
||||
if (postModel != null && postsAdapter != null) {
|
||||
if (postModel.isSelected()) selectedItems.remove(postModel);
|
||||
@ -725,16 +741,11 @@ public final class ProfileViewer extends BaseLanguageActivity implements SwipeRe
|
||||
if (downloadAction != null) downloadAction.setVisible(postsAdapter.isSelecting);
|
||||
}
|
||||
|
||||
public boolean isSelectionCleared() {
|
||||
if (postsAdapter != null && postsAdapter.isSelecting) {
|
||||
for (final PostModel postModel : selectedItems) postModel.setSelected(false);
|
||||
selectedItems.clear();
|
||||
postsAdapter.isSelecting = false;
|
||||
postsAdapter.notifyDataSetChanged();
|
||||
if (downloadAction != null) downloadAction.setVisible(false);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@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 && selectedItems.size() > 0)
|
||||
Utils.batchDownload(this, userQuery, DownloadMethod.DOWNLOAD_MAIN, selectedItems);
|
||||
}
|
||||
|
||||
public void deselectSelection(final BasePostModel postModel) {
|
||||
@ -745,17 +756,6 @@ public final class ProfileViewer extends BaseLanguageActivity implements SwipeRe
|
||||
}
|
||||
}
|
||||
|
||||
public static int indexOfIntArray(Object[] array, Object key) {
|
||||
int returnvalue = -1;
|
||||
for (int i = 0; i < array.length; ++i) {
|
||||
if (key == array[i]) {
|
||||
returnvalue = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return returnvalue;
|
||||
}
|
||||
|
||||
class MyTask extends AsyncTask<Void, Bitmap, Void> {
|
||||
private Bitmap mIcon_val;
|
||||
|
||||
|
@ -122,7 +122,7 @@ public final class StoryViewer extends BaseLanguageActivity {
|
||||
return;
|
||||
}
|
||||
|
||||
username = intent.getStringExtra(Constants.EXTRAS_USERNAME);
|
||||
username = intent.getStringExtra(Constants.EXTRAS_USERNAME).replace("@", "");
|
||||
final String highlight = intent.getStringExtra(Constants.EXTRAS_HIGHLIGHT);
|
||||
final boolean hasUsername = !Utils.isEmpty(username);
|
||||
final boolean hasHighlight = !Utils.isEmpty(highlight);
|
||||
|
@ -65,6 +65,7 @@ import javax.crypto.spec.SecretKeySpec;
|
||||
import awais.instagrabber.BuildConfig;
|
||||
import awais.instagrabber.R;
|
||||
import awais.instagrabber.activities.Main;
|
||||
import awais.instagrabber.activities.ProfileViewer;
|
||||
import awais.instagrabber.activities.SavedViewer;
|
||||
import awais.instagrabber.asyncs.DownloadAsync;
|
||||
import awais.instagrabber.asyncs.PostFetcher;
|
||||
@ -926,6 +927,7 @@ public final class Utils {
|
||||
|
||||
if (dir.exists() || dir.mkdirs()) {
|
||||
final Main main = method != DownloadMethod.DOWNLOAD_FEED && context instanceof Main ? (Main) context : null;
|
||||
final ProfileViewer pv = method == DownloadMethod.DOWNLOAD_MAIN && context instanceof ProfileViewer ? (ProfileViewer) context : null;
|
||||
final SavedViewer saved = method == DownloadMethod.DOWNLOAD_SAVED && context instanceof SavedViewer ? (SavedViewer) context : null;
|
||||
|
||||
final int itemsToDownloadSize = itemsToDownload.size();
|
||||
@ -934,34 +936,12 @@ public final class Utils {
|
||||
for (int i = itemsToDownloadSize - 1; i >= 0; i--) {
|
||||
final BasePostModel selectedItem = itemsToDownload.get(i);
|
||||
|
||||
if (main == null && saved == null) {
|
||||
if (main == null && saved == null && pv == null) {
|
||||
new DownloadAsync(context,
|
||||
selectedItem.getDisplayUrl(),
|
||||
getDownloadSaveFile(finalDir, selectedItem, ""),
|
||||
null).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
||||
} else if (saved != null) {
|
||||
new PostFetcher(selectedItem.getShortCode(), result -> {
|
||||
if (result != null) {
|
||||
final int resultsSize = result.length;
|
||||
final boolean multiResult = resultsSize > 1;
|
||||
|
||||
for (int j = 0; j < resultsSize; j++) {
|
||||
final BasePostModel model = result[j];
|
||||
final File saveFile = getDownloadSaveFile(finalDir, model, multiResult ? "_slide_" + (j + 1) : "");
|
||||
|
||||
new DownloadAsync(context,
|
||||
model.getDisplayUrl(),
|
||||
saveFile,
|
||||
file -> {
|
||||
model.setDownloaded(true);
|
||||
saved.deselectSelection(selectedItem);
|
||||
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
} else {
|
||||
saved.deselectSelection(selectedItem);
|
||||
}
|
||||
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} else {
|
||||
new PostFetcher(selectedItem.getShortCode(), result -> {
|
||||
if (result != null) {
|
||||
@ -977,11 +957,15 @@ public final class Utils {
|
||||
saveFile,
|
||||
file -> {
|
||||
model.setDownloaded(true);
|
||||
main.mainHelper.deselectSelection(selectedItem);
|
||||
if (saved != null) saved.deselectSelection(selectedItem);
|
||||
else if (main != null) main.mainHelper.deselectSelection(selectedItem);
|
||||
else if (pv != null) pv.deselectSelection(selectedItem);
|
||||
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
} else {
|
||||
main.mainHelper.deselectSelection(selectedItem);
|
||||
if (saved != null) saved.deselectSelection(selectedItem);
|
||||
else if (main != null) main.mainHelper.deselectSelection(selectedItem);
|
||||
else if (pv != null) pv.deselectSelection(selectedItem);
|
||||
}
|
||||
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user