Skip to content

Commit

Permalink
Transform : Refactor warnings UI + Ai upscale warning
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbWatershed committed Aug 17, 2023
1 parent 6dfcb4b commit 0f2df5a
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -73,6 +77,8 @@ class LibraryTransformDialogFragment : DialogFragment() {
private var pageIndex = 0
private var maxPages = -1
private val glideRequestOptions: RequestOptions
private val itemAdapter = ItemAdapter<DrawerItem>()
private val fastAdapter = FastAdapter.with(itemAdapter)

init {
val context: Context = HentoidApp.getInstance()
Expand Down Expand Up @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -17,7 +18,8 @@ class DrawerItem(
val label: String,
val icon: Int,
val activityClass: Class<out AppCompatActivity>,
uniqueId: Long
uniqueId: Long,
val italicFont: Boolean = false
) :
AbstractItem<DrawerItem.ViewHolder>() {

Expand Down Expand Up @@ -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) {
Expand Down

This file was deleted.

73 changes: 14 additions & 59 deletions app/src/main/res/layout/dialog_library_transform.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,14 @@
android:clipToPadding="false"
android:padding="16dp">

<TextView
android:id="@+id/retransform_warning"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="@color/white_opacity_25"
android:paddingStart="56dp"
android:paddingTop="8dp"
android:paddingEnd="8dp"
android:paddingBottom="8dp"
android:text="@string/retransform_warning"
android:textStyle="italic"
android:visibility="gone"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible" />

<ImageView
android:id="@+id/retransform_warning_icon"
android:layout_width="56dp"
android:layout_height="56dp"
android:adjustViewBounds="true"
android:padding="8dp"
android:src="@drawable/ic_warning"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@id/retransform_warning"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/retransform_warning"
app:tint="@color/white_opacity_87"
tools:ignore="ContentDescription"
tools:visibility="visible" />

<TextView
android:id="@+id/resize_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/transform_resizing"
android:textSize="@dimen/text_header_6"
android:textStyle="bold"
app:layout_constraintTop_toBottomOf="@id/retransform_warning" />
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/resize_switch"
Expand Down Expand Up @@ -205,35 +174,22 @@

</com.google.android.material.textfield.TextInputLayout>

<TextView
android:id="@+id/encoder_warning"
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/warnings_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="@color/white_opacity_25"
android:paddingStart="56dp"
android:paddingTop="8dp"
android:paddingEnd="8dp"
android:paddingBottom="8dp"
android:text="@string/encoder_warning"
android:textStyle="italic"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="@id/encoder_quality"
tools:visibility="visible" />

<ImageView
android:id="@+id/encoder_warning_icon"
android:layout_width="56dp"
android:layout_height="56dp"
android:adjustViewBounds="true"
android:clipToPadding="false"
android:fadeScrollbars="false"
android:padding="8dp"
android:src="@drawable/ic_warning"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbars="vertical"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@id/encoder_warning"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/encoder_warning"
app:tint="@color/white_opacity_87"
tools:ignore="ContentDescription"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/encoder_quality"
app:maxHeight="120dp"
tools:layout_height="120dp"
tools:listitem="@layout/item_drawer"
tools:visibility="visible" />

<TextView
Expand All @@ -244,9 +200,8 @@
android:text="@string/preview"
android:textSize="@dimen/text_header_6"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@id/preview_progress"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/encoder_warning" />
app:layout_constraintTop_toBottomOf="@id/warnings_list" />

<ProgressBar
android:id="@+id/preview_progress"
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@
<string name="resize_method_1">Max % of screen dimensions</string>
<string name="resize_method_2">Absolute max dimensions</string>
<string name="resize_method_3">% of original image dimensions</string>
<string name="resize_method_4">AI upscale (Real-CUGAN 2x)</string>
<string name="resize_method_4">AI upscale 2x</string>
<string name="resize_method_1_prompt">% of screen dimensions</string>
<string name="resize_method_2_prompt_max_height">Max height (mangas)</string>
<string name="resize_method_2_prompt_max_width">Max width (manhwas, webtoons)</string>
Expand All @@ -939,6 +939,7 @@
<string name="encoder_quality">Quality</string>
<string name="encoder_warning">WEBP format is limited to 16383 pixels in width and height. Larger pictures will automatically be encoded to PNG or JPG.</string>
<string name="retransform_warning">%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.</string>
<string name="ai_rescale_warning">Upscaling pictures with AI will use your GPU intensively. The whole operation may take a few minutes.</string>
<string name="preview">Preview</string>
<string name="transform">Transform</string>
<string name="transform_unsupported">Transformation unsupported</string>
Expand Down

0 comments on commit 0f2df5a

Please sign in to comment.