Fix lint warnings

This commit is contained in:
Koitharu
2023-05-12 13:15:41 +03:00
parent f3a8eb3216
commit f368277d73
23 changed files with 67 additions and 40 deletions

View File

@@ -83,7 +83,7 @@ dependencies {
}
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.8.21'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.core:core-ktx:1.10.0'
@@ -140,14 +140,14 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.json:json:20230227'
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4'
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.0'
androidTestImplementation 'androidx.test:runner:1.5.2'
androidTestImplementation 'androidx.test:rules:1.5.0'
androidTestImplementation 'androidx.test:core-ktx:1.5.0'
androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.5'
androidTestImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4'
androidTestImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.0'
androidTestImplementation 'androidx.room:room-testing:2.5.1'
androidTestImplementation 'com.squareup.moshi:moshi-kotlin:1.14.0'

View File

@@ -1,4 +1,5 @@
-optimizationpasses 8
-dontobfuscate
-assumenosideeffects class kotlin.jvm.internal.Intrinsics {
public static void checkExpressionValueIsNotNull(...);
public static void checkNotNullExpressionValue(...);

View File

@@ -163,10 +163,6 @@
</activity>
<service
android:name="org.koitharu.kotatsu.download.ui.service.DownloadService"
android:foregroundServiceType="dataSync"
android:stopWithTask="false" />
<service android:name="org.koitharu.kotatsu.local.ui.LocalChaptersRemoveService" />
<service
android:name="org.koitharu.kotatsu.widget.shelf.ShelfWidgetService"
@@ -241,7 +237,13 @@
<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
tools:node="remove" />
android:exported="false"
tools:node="remove">
<meta-data
android:name="androidx.work.WorkManagerInitializer"
android:value="androidx.startup"
tools:node="remove" />
</provider>
<receiver
android:name="org.koitharu.kotatsu.widget.shelf.ShelfWidgetProvider"

View File

@@ -10,9 +10,7 @@ import com.google.android.material.floatingactionbutton.ExtendedFloatingActionBu
open class ShrinkOnScrollBehavior : Behavior<ExtendedFloatingActionButton> {
@Suppress("unused")
constructor() : super()
@Suppress("unused")
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
override fun onStartNestedScroll(

View File

@@ -1,7 +1,10 @@
package org.koitharu.kotatsu.core.db.entity
import org.koitharu.kotatsu.core.model.MangaSource
import org.koitharu.kotatsu.parsers.model.*
import org.koitharu.kotatsu.parsers.model.Manga
import org.koitharu.kotatsu.parsers.model.MangaState
import org.koitharu.kotatsu.parsers.model.MangaTag
import org.koitharu.kotatsu.parsers.model.SortOrder
import org.koitharu.kotatsu.parsers.util.mapToSet
import org.koitharu.kotatsu.parsers.util.toTitleCase
import org.koitharu.kotatsu.utils.ext.longHashCode
@@ -66,7 +69,6 @@ fun SortOrder(name: String, fallback: SortOrder): SortOrder = runCatching {
SortOrder.valueOf(name)
}.getOrDefault(fallback)
@Suppress("FunctionName")
fun MangaState(name: String): MangaState? = runCatching {
MangaState.valueOf(name)
}.getOrNull()

View File

@@ -11,6 +11,7 @@ import androidx.annotation.VisibleForTesting
import androidx.core.content.pm.ShortcutInfoCompat
import androidx.core.content.pm.ShortcutManagerCompat
import androidx.core.graphics.drawable.IconCompat
import androidx.core.graphics.drawable.toBitmap
import androidx.room.InvalidationTracker
import coil.ImageLoader
import coil.request.ImageRequest
@@ -27,9 +28,9 @@ import org.koitharu.kotatsu.core.prefs.AppSettings
import org.koitharu.kotatsu.history.domain.HistoryRepository
import org.koitharu.kotatsu.parsers.model.Manga
import org.koitharu.kotatsu.reader.ui.ReaderActivity
import org.koitharu.kotatsu.utils.ext.getDrawableOrThrow
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
import org.koitharu.kotatsu.utils.ext.requireBitmap
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
import javax.inject.Inject
import javax.inject.Singleton
@@ -92,6 +93,14 @@ class ShortcutsUpdater @Inject constructor(
return manager.maxShortcutCountPerActivity > 0
}
fun notifyMangaOpened(mangaId: Long) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) {
return
}
val manager = context.getSystemService(Context.SHORTCUT_SERVICE) as ShortcutManager
manager.reportShortcutUsed(mangaId.toString())
}
@RequiresApi(Build.VERSION_CODES.N_MR1)
private suspend fun updateShortcutsImpl() = runCatchingCancellable {
val manager = context.getSystemService(Context.SHORTCUT_SERVICE) as ShortcutManager
@@ -122,7 +131,7 @@ class ShortcutsUpdater @Inject constructor(
.precision(Precision.EXACT)
.scale(Scale.FILL)
.build(),
).requireBitmap()
).getDrawableOrThrow().toBitmap()
}.fold(
onSuccess = { IconCompat.createWithAdaptiveBitmap(it) },
onFailure = { IconCompat.createWithResource(context, R.drawable.ic_shortcut_default) },

View File

@@ -1,5 +1,6 @@
package org.koitharu.kotatsu.reader.ui
import android.annotation.SuppressLint
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
@@ -179,6 +180,7 @@ class ReaderInfoBarView @JvmOverloads constructor(
}
}
@SuppressLint("DiscouragedApi")
private fun getSystemUiDimensionOffset(name: String, fallback: Int = 0): Int = runCatching {
val manager = context.packageManager
val resources = manager.getResourcesForApplication("com.android.systemui")

View File

@@ -19,6 +19,8 @@ import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.launchIn
@@ -34,6 +36,7 @@ import org.koitharu.kotatsu.base.domain.MangaIntent
import org.koitharu.kotatsu.base.ui.BaseViewModel
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
import org.koitharu.kotatsu.bookmarks.domain.BookmarksRepository
import org.koitharu.kotatsu.core.os.ShortcutsUpdater
import org.koitharu.kotatsu.core.parser.MangaRepository
import org.koitharu.kotatsu.core.prefs.AppSettings
import org.koitharu.kotatsu.core.prefs.ReaderMode
@@ -75,6 +78,7 @@ class ReaderViewModel @Inject constructor(
private val pageSaveHelper: PageSaveHelper,
private val pageLoader: PageLoader,
private val chaptersLoader: ChaptersLoader,
private val shortcutsUpdater: ShortcutsUpdater,
) : BaseViewModel() {
private val intent = MangaIntent(savedStateHandle)
@@ -149,6 +153,10 @@ class ReaderViewModel @Inject constructor(
.onEach { key ->
if (key == AppSettings.KEY_READER_SLIDER) notifyStateChanged()
}.launchIn(viewModelScope + Dispatchers.Default)
launchJob(Dispatchers.Default) {
val mangaId = mangaData.filterNotNull().first().id
shortcutsUpdater.notifyMangaOpened(mangaId)
}
}
fun reload() {

View File

@@ -33,7 +33,9 @@ open class PageHolder(
binding.ssiv.bindToLifecycle(owner)
binding.ssiv.isEagerLoadingEnabled = !isLowRamDevice(context)
binding.ssiv.addOnImageEventListener(delegate)
@Suppress("LeakingThis")
bindingInfo.buttonRetry.setOnClickListener(this)
@Suppress("LeakingThis")
bindingInfo.buttonErrorDetails.setOnClickListener(this)
binding.textViewNumber.isVisible = settings.isPagesNumbersEnabled
}

View File

@@ -241,6 +241,7 @@ class AniListRepository(
descriptionHtml = json.getString("description"),
)
@Suppress("FunctionName")
private fun AniListUser(json: JSONObject) = ScrobblerUser(
id = json.getLong("id"),
nickname = json.getString("name"),

View File

@@ -200,6 +200,7 @@ class MALRepository(
descriptionHtml = json.getString("synopsis"),
)
@Suppress("FunctionName")
private fun MALUser(json: JSONObject) = ScrobblerUser(
id = json.getLong("id"),
nickname = json.getString("name"),

View File

@@ -207,6 +207,7 @@ class ShikimoriRepository(
descriptionHtml = json.getString("description_html"),
)
@Suppress("FunctionName")
private fun ShikimoriUser(json: JSONObject) = ScrobblerUser(
id = json.getLong("id"),
nickname = json.getString("nickname"),

View File

@@ -66,7 +66,7 @@ fun View.hasGlobalPoint(x: Int, y: Int): Boolean {
fun View.measureHeight(): Int {
val vh = height
return if (vh == 0) {
measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED)
measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED)
measuredHeight
} else vh
}
@@ -74,7 +74,7 @@ fun View.measureHeight(): Int {
fun View.measureWidth(): Int {
val vw = width
return if (vw == 0) {
measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED)
measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED)
measuredWidth
} else vw
}
@@ -178,7 +178,6 @@ val View.parents: Sequence<ViewParent>
}
}
@Suppress("unused")
fun View.measureDimension(desiredSize: Int, measureSpec: Int): Int {
var result: Int
val specMode = MeasureSpec.getMode(measureSpec)

View File

@@ -4,6 +4,7 @@ import android.content.Context
import android.content.Intent
import android.widget.RemoteViews
import android.widget.RemoteViewsService
import androidx.core.graphics.drawable.toBitmap
import coil.ImageLoader
import coil.executeBlocking
import coil.request.ImageRequest
@@ -15,7 +16,7 @@ import org.koitharu.kotatsu.base.domain.MangaIntent
import org.koitharu.kotatsu.history.domain.HistoryRepository
import org.koitharu.kotatsu.parsers.model.Manga
import org.koitharu.kotatsu.parsers.util.replaceWith
import org.koitharu.kotatsu.utils.ext.requireBitmap
import org.koitharu.kotatsu.utils.ext.getDrawableOrThrow
class RecentListFactory(
private val context: Context,
@@ -56,7 +57,7 @@ class RecentListFactory(
.tag(item.source)
.transformations(transformation)
.build(),
).requireBitmap()
).getDrawableOrThrow().toBitmap()
}.onSuccess { cover ->
views.setImageViewBitmap(R.id.imageView_cover, cover)
}.onFailure {

View File

@@ -4,6 +4,7 @@ import android.content.Context
import android.content.Intent
import android.widget.RemoteViews
import android.widget.RemoteViewsService
import androidx.core.graphics.drawable.toBitmap
import coil.ImageLoader
import coil.executeBlocking
import coil.request.ImageRequest
@@ -16,7 +17,7 @@ import org.koitharu.kotatsu.core.prefs.AppWidgetConfig
import org.koitharu.kotatsu.favourites.domain.FavouritesRepository
import org.koitharu.kotatsu.parsers.model.Manga
import org.koitharu.kotatsu.parsers.util.replaceWith
import org.koitharu.kotatsu.utils.ext.requireBitmap
import org.koitharu.kotatsu.utils.ext.getDrawableOrThrow
class ShelfListFactory(
private val context: Context,
@@ -67,7 +68,7 @@ class ShelfListFactory(
.tag(item.source)
.transformations(transformation)
.build(),
).requireBitmap()
).getDrawableOrThrow().toBitmap()
}.onSuccess { cover ->
views.setImageViewBitmap(R.id.imageView_cover, cover)
}.onFailure {

View File

@@ -83,6 +83,7 @@
android:paddingHorizontal="@dimen/margin_normal"
android:singleLine="true"
android:textAppearance="?textAppearanceTitleMedium"
tools:ignore="InconsistentLayout"
tools:text="@string/chapter_d_of_d" />
<TextView

View File

@@ -83,6 +83,7 @@
app:layout_behavior="org.koitharu.kotatsu.main.ui.MainActionButtonBehavior"
app:layout_dodgeInsetEdges="bottom"
app:layout_insetEdge="bottom"
tools:ignore="InconsistentLayout"
tools:visibility="visible" />
<org.koitharu.kotatsu.base.ui.widgets.SlidingBottomNavigationView

View File

@@ -24,6 +24,7 @@
android:scrollIndicators="top|bottom"
android:scrollbars="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:ignore="UnusedAttribute"
tools:listitem="@layout/item_source_locale" />
</LinearLayout>

View File

@@ -92,5 +92,5 @@
android:singleLine="true"
android:textAppearance="?attr/textAppearanceBodySmall"
android:textColor="?android:attr/textColorPrimary"
tools:text="@string/theme_name_mint" />
tools:text="@string/theme_name_miku" />
</LinearLayout>

View File

@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
@@ -46,4 +45,4 @@
tools:text="@string/try_again"
tools:visibility="visible" />
</LinearLayout>
</LinearLayout>

View File

@@ -31,16 +31,16 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="mail@mail.com"
android:textAppearance="?textAppearanceBodyLarge" />
android:textAppearance="?textAppearanceBodyLarge"
tools:text="mail@mail.com" />
<TextView
android:id="@+id/last_checked"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Last checked: 6:00 PM"
android:textAppearance="?textAppearanceBodySmall" />
android:textAppearance="?textAppearanceBodySmall"
tools:text="Last checked: 6:00 PM" />
</LinearLayout>

View File

@@ -26,4 +26,11 @@
<locale android:name="uk" />
<locale android:name="zh-CN" />
<locale android:name="zh-TW" />
<locale android:name="fil" />
<locale android:name="hi" />
<locale android:name="kk" />
<locale android:name="ko" />
<locale android:name="ne" />
<locale android:name="nn" />
<locale android:name="vi" />
</locale-config>

View File

@@ -4,8 +4,8 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.0.0'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.20'
classpath 'com.android.tools.build:gradle:8.0.1'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.21'
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.45'
}
}
@@ -20,16 +20,6 @@ allprojects {
}
}
String currentBranch() {
def branchName = ""
try {
branchName = "git rev-parse --abbrev-ref HEAD".execute().text.trim()
} catch (ignored) {
println "Git not found"
}
return branchName
}
task clean(type: Delete) {
delete rootProject.buildDir
}