diff --git a/app/src/main/java/me/devsaki/hentoid/fragments/library/LibraryTransformDialogFragment.kt b/app/src/main/java/me/devsaki/hentoid/fragments/library/LibraryTransformDialogFragment.kt index 03cab9e67..8300ad811 100644 --- a/app/src/main/java/me/devsaki/hentoid/fragments/library/LibraryTransformDialogFragment.kt +++ b/app/src/main/java/me/devsaki/hentoid/fragments/library/LibraryTransformDialogFragment.kt @@ -27,6 +27,8 @@ import com.bumptech.glide.load.Transformation import com.bumptech.glide.load.resource.bitmap.CenterInside import com.bumptech.glide.request.RequestOptions import com.google.android.material.textfield.TextInputLayout +import com.mikepenz.fastadapter.FastAdapter +import com.mikepenz.fastadapter.adapters.ItemAdapter import com.squareup.moshi.Moshi import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import kotlinx.coroutines.Dispatchers @@ -40,11 +42,13 @@ import me.devsaki.hentoid.database.ObjectBoxDAO import me.devsaki.hentoid.database.domains.Content import me.devsaki.hentoid.databinding.DialogLibraryTransformBinding import me.devsaki.hentoid.enums.PictureEncoder +import me.devsaki.hentoid.enums.Site import me.devsaki.hentoid.util.Settings import me.devsaki.hentoid.util.ThemeHelper import me.devsaki.hentoid.util.file.FileHelper import me.devsaki.hentoid.util.image.ImageHelper import me.devsaki.hentoid.util.image.ImageTransform +import me.devsaki.hentoid.viewholders.DrawerItem import me.devsaki.hentoid.workers.TransformWorker import okio.use import timber.log.Timber @@ -73,6 +77,8 @@ class LibraryTransformDialogFragment : DialogFragment() { private var pageIndex = 0 private var maxPages = -1 private val glideRequestOptions: RequestOptions + private val itemAdapter = ItemAdapter() + private val fastAdapter = FastAdapter.with(itemAdapter) init { val context: Context = HentoidApp.getInstance() @@ -241,24 +247,52 @@ class LibraryTransformDialogFragment : DialogFragment() { && (Settings.transcodeEncoderAll == PictureEncoder.JPEG.value || Settings.transcodeEncoderAll == PictureEncoder.WEBP_LOSSY.value))) if (isAiUpscale) encoderQuality.isVisible = false if (applyValues) encoderQuality.editText?.setText(Settings.transcodeQuality.toString()) - encoderWarning.isVisible = ( + + // Warning list + warningsList.adapter = fastAdapter + + val encoderWarning = ( (0 == transcodeMethod.index && (Settings.transcodeEncoderAll == PictureEncoder.WEBP_LOSSY.value || Settings.transcodeEncoderAll == PictureEncoder.WEBP_LOSSLESS.value)) || (1 == transcodeMethod.index && (Settings.transcodeEncoderLossy == PictureEncoder.WEBP_LOSSY.value || Settings.transcodeEncoderLossless == PictureEncoder.WEBP_LOSSLESS.value)) ) - encoderWarningIcon.isVisible = encoderWarning.isVisible // Check if content contains transformed pages already + var retransformWarning = false content?.apply { - val transformedCount = imageList.count { i -> i.isTransformed } - if (transformedCount > 0) { - binding.retransformWarning.text = resources.getString( - R.string.retransform_warning, - transformedCount - ) - binding.retransformWarning.isVisible = true - binding.retransformWarningIcon.isVisible = true - } + retransformWarning = imageList.count { i -> i.isTransformed } > 0 } + + if (encoderWarning || retransformWarning || isAiUpscale) { + itemAdapter.clear() + if (encoderWarning) itemAdapter.add( + DrawerItem( + resources.getString(R.string.encoder_warning), + R.drawable.ic_warning, + Content.getWebActivityClass(Site.NONE), + 1, + true + ) + ) + if (retransformWarning) itemAdapter.add( + DrawerItem( + resources.getString(R.string.retransform_warning), + R.drawable.ic_warning, + Content.getWebActivityClass(Site.NONE), + 2, + true + ) + ) + if (isAiUpscale) itemAdapter.add( + DrawerItem( + resources.getString(R.string.ai_rescale_warning), + R.drawable.ic_warning, + Content.getWebActivityClass(Site.NONE), + 2, + true + ) + ) + warningsList.isVisible = true + } else warningsList.isVisible = false } } diff --git a/app/src/main/java/me/devsaki/hentoid/viewholders/DrawerItem.kt b/app/src/main/java/me/devsaki/hentoid/viewholders/DrawerItem.kt index 891eea7e0..706980041 100644 --- a/app/src/main/java/me/devsaki/hentoid/viewholders/DrawerItem.kt +++ b/app/src/main/java/me/devsaki/hentoid/viewholders/DrawerItem.kt @@ -1,6 +1,7 @@ package me.devsaki.hentoid.viewholders import android.graphics.PorterDuff +import android.graphics.Typeface import android.view.View import android.widget.ImageView import android.widget.TextView @@ -17,7 +18,8 @@ class DrawerItem( val label: String, val icon: Int, val activityClass: Class, - uniqueId: Long + uniqueId: Long, + val italicFont: Boolean = false ) : AbstractItem() { @@ -52,6 +54,9 @@ class DrawerItem( ) } else alert.visibility = View.GONE title.text = String.format("%s%s", item.label, if (item.flagNew) " *" else "") + + if (item.italicFont) title.setTypeface(null, Typeface.ITALIC) + else title.setTypeface(null, Typeface.NORMAL) } override fun unbindView(item: DrawerItem) { diff --git a/app/src/main/java/me/devsaki/hentoid/workers/data/TransformData.java b/app/src/main/java/me/devsaki/hentoid/workers/data/TransformData.java deleted file mode 100644 index 4bedc2234..000000000 --- a/app/src/main/java/me/devsaki/hentoid/workers/data/TransformData.java +++ /dev/null @@ -1,68 +0,0 @@ -package me.devsaki.hentoid.workers.data; - -import android.net.Uri; - -import androidx.work.Data; - -import javax.annotation.Nonnull; - -import me.devsaki.hentoid.util.Preferences; -import me.devsaki.hentoid.util.StringHelper; - -/** - * Helper class to transfer data from any Activity to {@link me.devsaki.hentoid.workers.DownloadsImportWorker} - * through a Data object - *

- * Use Builder class to set data; use Parser class to get data - */ -public class TransformData { - private static final String KEY_FILE_URI = "file_uri"; - private static final String KEY_QUEUE_POSITION = "queue_position"; - private static final String KEY_IMPORT_AS_STREAMED = "as_streamed"; - - private TransformData() { - throw new UnsupportedOperationException(); - } - - public static final class Builder { - - private final Data.Builder builder = new Data.Builder(); - - public void setFileUri(Uri data) { - builder.putString(KEY_FILE_URI, data.toString()); - } - - public void setQueuePosition(int data) { - builder.putInt(KEY_QUEUE_POSITION, data); - } - - public void setImportAsStreamed(boolean data) { - builder.putBoolean(KEY_IMPORT_AS_STREAMED, data); - } - - public Data getData() { - return builder.build(); - } - } - - public static final class Parser { - - private final Data data; - - public Parser(@Nonnull Data data) { - this.data = data; - } - - public String getFileUri() { - return StringHelper.protect(data.getString(KEY_FILE_URI)); - } - - public int getQueuePosition() { - return data.getInt(KEY_QUEUE_POSITION, Preferences.Default.QUEUE_NEW_DOWNLOADS_POSITION); - } - - public boolean getImportAsStreamed() { - return data.getBoolean(KEY_IMPORT_AS_STREAMED, false); - } - } -} diff --git a/app/src/main/res/layout/dialog_library_transform.xml b/app/src/main/res/layout/dialog_library_transform.xml index b93bd233f..38a08330f 100644 --- a/app/src/main/res/layout/dialog_library_transform.xml +++ b/app/src/main/res/layout/dialog_library_transform.xml @@ -13,37 +13,6 @@ android:clipToPadding="false" android:padding="16dp"> - - - - + app:layout_constraintTop_toTopOf="parent" /> - - - + app:layout_constraintTop_toBottomOf="@id/warnings_list" /> Max % of screen dimensions Absolute max dimensions % of original image dimensions - AI upscale (Real-CUGAN 2x) + AI upscale 2x % of screen dimensions Max height (mangas) Max width (manhwas, webtoons) @@ -939,6 +939,7 @@ Quality WEBP format is limited to 16383 pixels in width and height. Larger pictures will automatically be encoded to PNG or JPG. %d pages have already been transformed. Transforming them multiple times may result in noticeable quality loss.\nWe advise redownloading original images and transforming them one single time. + Upscaling pictures with AI will use your GPU intensively. The whole operation may take a few minutes. Preview Transform Transformation unsupported