<commit_before>package me.devsaki.hentoid.viewholders;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PorterDuff;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.annotation.DrawableRes;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.model.LazyHeaders;
import com.bumptech.glide.request.RequestOptions;
import com.mikepenz.fastadapter.FastAdapter;
import com.mikepenz.fastadapter.drag.IExtendedDraggable;
import com.mikepenz.fastadapter.items.AbstractItem;
import com.mikepenz.fastadapter.swipe.ISwipeable;
import com.mikepenz.fastadapter.utils.DragDropUtil;

import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;

import me.devsaki.hentoid.HentoidApp;
import me.devsaki.hentoid.R;
import me.devsaki.hentoid.activities.bundles.ContentItemBundle;
import me.devsaki.hentoid.database.domains.Attribute;
import me.devsaki.hentoid.database.domains.Content;
import me.devsaki.hentoid.database.domains.QueueRecord;
import me.devsaki.hentoid.enums.AttributeType;
import me.devsaki.hentoid.enums.StatusContent;
import me.devsaki.hentoid.services.ContentQueueManager;
import me.devsaki.hentoid.ui.BlinkAnimation;
import me.devsaki.hentoid.util.JsonHelper;
import me.devsaki.hentoid.util.LanguageHelper;
import me.devsaki.hentoid.util.ThemeHelper;
import me.devsaki.hentoid.util.network.HttpHelper;
import timber.log.Timber;

import static androidx.core.view.ViewCompat.requireViewById;
import static me.devsaki.hentoid.util.ImageHelper.tintBitmap;

public class ContentItem extends AbstractItem<ContentItem.ContentViewHolder> implements IExtendedDraggable, ISwipeable {

    private static final RequestOptions glideRequestOptions;

    @IntDef({ViewType.LIBRARY, ViewType.LIBRARY_EDIT, ViewType.QUEUE, ViewType.ERRORS})
    @Retention(RetentionPolicy.SOURCE)
    public @interface ViewType {
        int LIBRARY = 0;
        int LIBRARY_EDIT = 1;
        int QUEUE = 2;
        int ERRORS = 3;
    }

    private final Content content;
    private final @ViewType
    int viewType;
    private final boolean isEmpty;

    // Drag, drop & swipe
    private final ItemTouchHelper touchHelper;
    private int swipeDirection = 0;
    private boolean isSwipeable = true;
    private Runnable undoSwipeAction; // Action to run when hitting the "undo" button


    static {
        Context context = HentoidApp.getInstance();
        int tintColor = ThemeHelper.getColor(context, R.color.light_gray);

        Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_hentoid_trans);
        Drawable d = new BitmapDrawable(context.getResources(), tintBitmap(bmp, tintColor));

        glideRequestOptions = new RequestOptions()
                .centerInside()
                .error(d);
    }

    // Constructor for empty placeholder
    public ContentItem(@ViewType int viewType) {
        isEmpty = true;
        content = null;
        this.viewType = viewType;
        touchHelper = null;
        setIdentifier(generateIdForPlaceholder());
    }

    // Constructor for library and error item
    public ContentItem(Content content, @Nullable ItemTouchHelper touchHelper, @ViewType int viewType) {
        this.content = content;
        this.viewType = viewType;
        this.touchHelper = touchHelper;
        isEmpty = (null == content);
        if (content != null) setIdentifier(content.hashCode());
        else setIdentifier(generateIdForPlaceholder());
    }

    // Constructor for queued item
    public ContentItem(@NonNull QueueRecord record, ItemTouchHelper touchHelper) {
        content = record.content.getTarget();
        viewType = ViewType.QUEUE;
        this.touchHelper = touchHelper;
        isEmpty = (null == content);
//        setIdentifier(record.id);
        if (content != null) setIdentifier(content.hashCode());
        else setIdentifier(generateIdForPlaceholder());
    }
<commit_msg>External books are not delete-swipeable<commit_after>package me.devsaki.hentoid.viewholders;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PorterDuff;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.annotation.DrawableRes;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.model.LazyHeaders;
import com.bumptech.glide.request.RequestOptions;
import com.mikepenz.fastadapter.FastAdapter;
import com.mikepenz.fastadapter.drag.IExtendedDraggable;
import com.mikepenz.fastadapter.items.AbstractItem;
import com.mikepenz.fastadapter.swipe.ISwipeable;
import com.mikepenz.fastadapter.utils.DragDropUtil;

import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;

import me.devsaki.hentoid.HentoidApp;
import me.devsaki.hentoid.R;
import me.devsaki.hentoid.activities.bundles.ContentItemBundle;
import me.devsaki.hentoid.database.domains.Attribute;
import me.devsaki.hentoid.database.domains.Content;
import me.devsaki.hentoid.database.domains.QueueRecord;
import me.devsaki.hentoid.enums.AttributeType;
import me.devsaki.hentoid.enums.StatusContent;
import me.devsaki.hentoid.services.ContentQueueManager;
import me.devsaki.hentoid.ui.BlinkAnimation;
import me.devsaki.hentoid.util.JsonHelper;
import me.devsaki.hentoid.util.LanguageHelper;
import me.devsaki.hentoid.util.Preferences;
import me.devsaki.hentoid.util.ThemeHelper;
import me.devsaki.hentoid.util.network.HttpHelper;
import timber.log.Timber;

import static androidx.core.view.ViewCompat.requireViewById;
import static me.devsaki.hentoid.util.ImageHelper.tintBitmap;

public class ContentItem extends AbstractItem<ContentItem.ContentViewHolder> implements IExtendedDraggable, ISwipeable {

    private static final RequestOptions glideRequestOptions;

    @IntDef({ViewType.LIBRARY, ViewType.LIBRARY_EDIT, ViewType.QUEUE, ViewType.ERRORS})
    @Retention(RetentionPolicy.SOURCE)
    public @interface ViewType {
        int LIBRARY = 0;
        int LIBRARY_EDIT = 1;
        int QUEUE = 2;
        int ERRORS = 3;
    }

    private final Content content;
    private final @ViewType
    int viewType;
    private final boolean isEmpty;

    // Drag, drop & swipe
    private final ItemTouchHelper touchHelper;
    private int swipeDirection = 0;
    private boolean isSwipeable = true;
    private Runnable undoSwipeAction; // Action to run when hitting the "undo" button


    static {
        Context context = HentoidApp.getInstance();
        int tintColor = ThemeHelper.getColor(context, R.color.light_gray);

        Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_hentoid_trans);
        Drawable d = new BitmapDrawable(context.getResources(), tintBitmap(bmp, tintColor));

        glideRequestOptions = new RequestOptions()
                .centerInside()
                .error(d);
    }

    // Constructor for empty placeholder
    public ContentItem(@ViewType int viewType) {
        isEmpty = true;
        content = null;
        this.viewType = viewType;
        touchHelper = null;
        setIdentifier(generateIdForPlaceholder());
    }

    // Constructor for library and error item
    public ContentItem(Content content, @Nullable ItemTouchHelper touchHelper, @ViewType int viewType) {
        this.content = content;
        this.viewType = viewType;
        this.touchHelper = touchHelper;
        isEmpty = (null == content);
        isSwipeable = (content != null && (!content.getStatus().equals(StatusContent.EXTERNAL) || Preferences.isDeleteExternalLibrary()));
        if (content != null) setIdentifier(content.hashCode());
        else setIdentifier(generateIdForPlaceholder());
    }

    // Constructor for queued item
    public ContentItem(@NonNull QueueRecord record, ItemTouchHelper touchHelper) {
        content = record.content.getTarget();
        viewType = ViewType.QUEUE;
        this.touchHelper = touchHelper;
        isEmpty = (null == content);
//        setIdentifier(record.id);
        if (content != null) setIdentifier(content.hashCode());
        else setIdentifier(generateIdForPlaceholder());
    }

{'fraction_non_alphanumeric': 0.09426527014414601, 'fraction_numerical': 0.0010370216737529815, 'mean_word_length': 4.215792320173066, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1218269', 'n_tokens_mistral': 2877, 'n_tokens_neox': 2836, 'n_words': 575}