|
|
@@ -12,6 +12,7 @@ import androidx.annotation.NonNull;
|
|
|
import androidx.cardview.widget.CardView;
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
|
+import com.dar.nbook.BLoginActivity;
|
|
|
import com.dar.nbook.GalleryActivity;
|
|
|
import com.dar.nbook.MainActivity;
|
|
|
import com.dar.nbook.R;
|
|
|
@@ -22,9 +23,11 @@ import com.dar.nbook.api.enums.Language;
|
|
|
import com.dar.nbook.async.database.Queries;
|
|
|
import com.dar.nbook.components.activities.BaseActivity;
|
|
|
import com.dar.nbook.settings.Global;
|
|
|
+import com.dar.nbook.settings.Login;
|
|
|
import com.dar.nbook.settings.TagV2;
|
|
|
import com.dar.nbook.utility.ImageDownloadUtility;
|
|
|
import com.dar.nbook.utility.LogUtility;
|
|
|
+import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
|
|
import com.google.android.material.snackbar.Snackbar;
|
|
|
|
|
|
import java.io.File;
|
|
|
@@ -41,12 +44,12 @@ public class ListAdapter extends RecyclerView.Adapter<GenericAdapter.ViewHolder>
|
|
|
|
|
|
public ListAdapter(BaseActivity cont) {
|
|
|
this.context = cont;
|
|
|
- this.mDataset = new ArrayList<SimpleGallery>(){
|
|
|
+ this.mDataset = new ArrayList<SimpleGallery>() {
|
|
|
@Override
|
|
|
public SimpleGallery get(int index) {
|
|
|
try {
|
|
|
return super.get(index);
|
|
|
- }catch (ArrayIndexOutOfBoundsException ignore){
|
|
|
+ } catch (ArrayIndexOutOfBoundsException ignore) {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
@@ -114,7 +117,7 @@ public class ListAdapter extends RecyclerView.Adapter<GenericAdapter.ViewHolder>
|
|
|
context.startActivity(intent);*/
|
|
|
if (context instanceof MainActivity)
|
|
|
((MainActivity) context).setIdOpenedGallery(ent.getId());
|
|
|
- downloadGallery(ent);
|
|
|
+ downloadGallery(ent, holderPos);
|
|
|
holder.overlay.setVisibility((queryString != null && ent.hasIgnoredTags(queryString)) ? View.VISIBLE : View.GONE);
|
|
|
});
|
|
|
holder.overlay.setOnClickListener(v -> holder.overlay.setVisibility(View.GONE));
|
|
|
@@ -130,6 +133,7 @@ public class ListAdapter extends RecyclerView.Adapter<GenericAdapter.ViewHolder>
|
|
|
statuses.put(ent.getId(), statusColor);
|
|
|
}
|
|
|
holder.title.setBackgroundColor(statusColor);
|
|
|
+ holder.progress.setVisibility(ent.isLoading() ? View.VISIBLE : View.GONE);
|
|
|
}
|
|
|
|
|
|
public void updateColor(int id) {
|
|
|
@@ -137,7 +141,7 @@ public class ListAdapter extends RecyclerView.Adapter<GenericAdapter.ViewHolder>
|
|
|
int position = -1;
|
|
|
statuses.put(id, Queries.StatusMangaTable.getStatus(id).color);
|
|
|
for (int i = 0; i < mDataset.size(); i++) {
|
|
|
- SimpleGallery gallery= mDataset.get(i);
|
|
|
+ SimpleGallery gallery = mDataset.get(i);
|
|
|
if (gallery != null && gallery.getId() == id) {
|
|
|
position = id;
|
|
|
break;
|
|
|
@@ -146,18 +150,33 @@ public class ListAdapter extends RecyclerView.Adapter<GenericAdapter.ViewHolder>
|
|
|
if (position >= 0) notifyItemChanged(position);
|
|
|
}
|
|
|
|
|
|
- private void downloadGallery(final SimpleGallery ent) {
|
|
|
+ private void downloadGallery(final SimpleGallery ent, int pos) {
|
|
|
+ if (!Login.isNLogged(context)) {
|
|
|
+ MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(context);
|
|
|
+ builder.setTitle(R.string.login_required);
|
|
|
+ builder.setMessage(R.string.login_required_message);
|
|
|
+ builder.setPositiveButton(R.string.login, (dialog, which) -> {
|
|
|
+ Intent intent = new Intent(context, BLoginActivity.class);
|
|
|
+ context.startActivity(intent);
|
|
|
+ });
|
|
|
+ builder.setNegativeButton(R.string.cancel, null);
|
|
|
+ builder.show();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ent.setLoading(true);
|
|
|
+ notifyItemChanged(pos);
|
|
|
InspectorV3.galleryInspector(context, ent.getId(), new InspectorV3.DefaultInspectorResponse() {
|
|
|
@Override
|
|
|
public void onFailure(Exception e) {
|
|
|
super.onFailure(e);
|
|
|
+ ent.setLoading(false);
|
|
|
File file = Global.findGalleryFolder(context, ent.getId());
|
|
|
if (file != null) {
|
|
|
LocalAdapter.startGallery(context, file);
|
|
|
} else if (context.getMasterLayout() != null) {
|
|
|
context.runOnUiThread(() -> {
|
|
|
Snackbar snackbar = Snackbar.make(context.getMasterLayout(), R.string.unable_to_connect_to_the_site, Snackbar.LENGTH_SHORT);
|
|
|
- snackbar.setAction(R.string.retry, v -> downloadGallery(ent));
|
|
|
+ snackbar.setAction(R.string.retry, v -> downloadGallery(ent, pos));
|
|
|
snackbar.show();
|
|
|
}
|
|
|
);
|
|
|
@@ -166,6 +185,8 @@ public class ListAdapter extends RecyclerView.Adapter<GenericAdapter.ViewHolder>
|
|
|
|
|
|
@Override
|
|
|
public void onSuccess(List<GenericGallery> galleries) {
|
|
|
+ ent.setLoading(false);
|
|
|
+ notifyItemChanged(pos);
|
|
|
if (galleries.size() != 1) {
|
|
|
if (context.getMasterLayout() != null) {
|
|
|
context.runOnUiThread(() ->
|