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