Fix some StrictMode warnings
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
package org.koitharu.kotatsu
|
package org.koitharu.kotatsu
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
|
import android.os.StrictMode
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
import androidx.room.Room
|
import androidx.room.Room
|
||||||
import androidx.room.RoomDatabase
|
|
||||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
|
||||||
import coil.Coil
|
import coil.Coil
|
||||||
import coil.ComponentRegistry
|
import coil.ComponentRegistry
|
||||||
import coil.ImageLoaderBuilder
|
import coil.ImageLoaderBuilder
|
||||||
@@ -24,6 +23,7 @@ import org.koitharu.kotatsu.core.local.PagesCache
|
|||||||
import org.koitharu.kotatsu.core.local.cookies.PersistentCookieJar
|
import org.koitharu.kotatsu.core.local.cookies.PersistentCookieJar
|
||||||
import org.koitharu.kotatsu.core.local.cookies.cache.SetCookieCache
|
import org.koitharu.kotatsu.core.local.cookies.cache.SetCookieCache
|
||||||
import org.koitharu.kotatsu.core.local.cookies.persistence.SharedPrefsCookiePersistor
|
import org.koitharu.kotatsu.core.local.cookies.persistence.SharedPrefsCookiePersistor
|
||||||
|
import org.koitharu.kotatsu.core.parser.LocalMangaRepository
|
||||||
import org.koitharu.kotatsu.core.parser.UserAgentInterceptor
|
import org.koitharu.kotatsu.core.parser.UserAgentInterceptor
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.domain.MangaLoaderContext
|
import org.koitharu.kotatsu.domain.MangaLoaderContext
|
||||||
@@ -46,6 +46,19 @@ class KotatsuApp : Application() {
|
|||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
if (BuildConfig.DEBUG) {
|
||||||
|
StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder()
|
||||||
|
.detectAll()
|
||||||
|
.penaltyLog()
|
||||||
|
.build())
|
||||||
|
StrictMode.setVmPolicy(StrictMode.VmPolicy.Builder()
|
||||||
|
.detectAll()
|
||||||
|
.setClassInstanceLimit(LocalMangaRepository::class.java, 1)
|
||||||
|
.setClassInstanceLimit(PagesCache::class.java, 1)
|
||||||
|
.setClassInstanceLimit(MangaLoaderContext::class.java, 1)
|
||||||
|
.penaltyLog()
|
||||||
|
.build())
|
||||||
|
}
|
||||||
initKoin()
|
initKoin()
|
||||||
initCoil()
|
initCoil()
|
||||||
Thread.setDefaultUncaughtExceptionHandler(AppCrashHandler(applicationContext))
|
Thread.setDefaultUncaughtExceptionHandler(AppCrashHandler(applicationContext))
|
||||||
@@ -75,7 +88,7 @@ class KotatsuApp : Application() {
|
|||||||
single {
|
single {
|
||||||
MangaLoaderContext()
|
MangaLoaderContext()
|
||||||
}
|
}
|
||||||
factory {
|
single {
|
||||||
AppSettings(applicationContext)
|
AppSettings(applicationContext)
|
||||||
}
|
}
|
||||||
single {
|
single {
|
||||||
|
|||||||
@@ -78,8 +78,7 @@ class LocalMangaRepository : MangaRepository, KoinComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("DefaultLocale")
|
@SuppressLint("DefaultLocale")
|
||||||
fun getFromFile(file: File): Manga {
|
fun getFromFile(file: File): Manga = ZipFile(file).use { zip ->
|
||||||
val zip = ZipFile(file)
|
|
||||||
val fileUri = file.toUri().toString()
|
val fileUri = file.toUri().toString()
|
||||||
val entry = zip.getEntry(MangaZip.INDEX_ENTRY)
|
val entry = zip.getEntry(MangaZip.INDEX_ENTRY)
|
||||||
val index = entry?.let(zip::readText)?.let(::MangaIndex)
|
val index = entry?.let(zip::readText)?.let(::MangaIndex)
|
||||||
@@ -105,7 +104,7 @@ class LocalMangaRepository : MangaRepository, KoinComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
val uriBuilder = file.toUri().buildUpon()
|
val uriBuilder = file.toUri().buildUpon()
|
||||||
return Manga(
|
Manga(
|
||||||
id = file.absolutePath.longHashCode(),
|
id = file.absolutePath.longHashCode(),
|
||||||
title = title,
|
title = title,
|
||||||
url = fileUri,
|
url = fileUri,
|
||||||
|
|||||||
@@ -5,9 +5,13 @@ import android.view.View
|
|||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import androidx.core.text.parseAsHtml
|
import androidx.core.text.parseAsHtml
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import coil.api.load
|
import coil.api.load
|
||||||
import com.google.android.material.chip.Chip
|
import com.google.android.material.chip.Chip
|
||||||
import kotlinx.android.synthetic.main.fragment_details.*
|
import kotlinx.android.synthetic.main.fragment_details.*
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import moxy.ktx.moxyPresenter
|
import moxy.ktx.moxyPresenter
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||||
@@ -73,13 +77,18 @@ class MangaDetailsFragment : BaseFragment(R.layout.fragment_details), MangaDetai
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
manga.url.toUri().toFileOrNull()?.let { f ->
|
manga.url.toUri().toFileOrNull()?.let { f ->
|
||||||
chips_tags.addChips(listOf(f)) {
|
lifecycleScope.launch {
|
||||||
create(
|
val size = withContext(Dispatchers.IO) {
|
||||||
text = FileSizeUtils.formatBytes(context, it.length()),
|
f.length()
|
||||||
iconRes = R.drawable.ic_chip_storage,
|
}
|
||||||
tag = it,
|
chips_tags.addChips(listOf(f)) {
|
||||||
onClickListener = this@MangaDetailsFragment
|
create(
|
||||||
)
|
text = FileSizeUtils.formatBytes(context, size),
|
||||||
|
iconRes = R.drawable.ic_chip_storage,
|
||||||
|
tag = it,
|
||||||
|
onClickListener = this@MangaDetailsFragment
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
imageView_favourite.setOnClickListener(this)
|
imageView_favourite.setOnClickListener(this)
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import org.koitharu.kotatsu.ui.settings.SettingsActivity
|
|||||||
import org.koitharu.kotatsu.ui.tracker.TrackWorker
|
import org.koitharu.kotatsu.ui.tracker.TrackWorker
|
||||||
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||||
import org.koitharu.kotatsu.utils.ext.resolveDp
|
import org.koitharu.kotatsu.utils.ext.resolveDp
|
||||||
|
import java.io.Closeable
|
||||||
|
|
||||||
class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedListener,
|
class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedListener,
|
||||||
SharedPreferences.OnSharedPreferenceChangeListener, MainView {
|
SharedPreferences.OnSharedPreferenceChangeListener, MainView {
|
||||||
@@ -45,6 +46,7 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
|
|||||||
|
|
||||||
private val settings by inject<AppSettings>()
|
private val settings by inject<AppSettings>()
|
||||||
private lateinit var drawerToggle: ActionBarDrawerToggle
|
private lateinit var drawerToggle: ActionBarDrawerToggle
|
||||||
|
private var closeable: Closeable? = null
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@@ -74,6 +76,7 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
closeable?.close()
|
||||||
settings.unsubscribe(this)
|
settings.unsubscribe(this)
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
@@ -92,7 +95,7 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
|
|||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
menuInflater.inflate(R.menu.opt_main, menu)
|
menuInflater.inflate(R.menu.opt_main, menu)
|
||||||
menu.findItem(R.id.action_search)?.let { menuItem ->
|
menu.findItem(R.id.action_search)?.let { menuItem ->
|
||||||
SearchHelper.setupSearchView(menuItem)
|
closeable = SearchHelper.setupSearchView(menuItem)
|
||||||
}
|
}
|
||||||
return super.onCreateOptionsMenu(menu)
|
return super.onCreateOptionsMenu(menu)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class MangaSuggestionsProvider : SearchRecentSuggestionsProvider() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun getItemsCount(context: Context) = getCursor(context)?.count ?: 0
|
fun getItemsCount(context: Context) = getCursor(context)?.use { it.count } ?: 0
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
private fun getCursor(context: Context): Cursor? {
|
private fun getCursor(context: Context): Cursor? {
|
||||||
|
|||||||
@@ -37,6 +37,11 @@ class SearchActivity : BaseActivity(), SearchView.OnQueryTextListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
searchView.suggestionsAdapter?.changeCursor(null) //close cursor
|
||||||
|
super.onDestroy()
|
||||||
|
}
|
||||||
|
|
||||||
override fun onQueryTextSubmit(query: String?): Boolean {
|
override fun onQueryTextSubmit(query: String?): Boolean {
|
||||||
return if (!query.isNullOrBlank()) {
|
return if (!query.isNullOrBlank()) {
|
||||||
title = query
|
title = query
|
||||||
|
|||||||
@@ -8,17 +8,20 @@ import androidx.appcompat.widget.SearchView
|
|||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.ui.search.global.GlobalSearchActivity
|
import org.koitharu.kotatsu.ui.search.global.GlobalSearchActivity
|
||||||
import org.koitharu.kotatsu.utils.ext.safe
|
import org.koitharu.kotatsu.utils.ext.safe
|
||||||
|
import java.io.Closeable
|
||||||
|
|
||||||
object SearchHelper {
|
object SearchHelper {
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun setupSearchView(menuItem: MenuItem) {
|
fun setupSearchView(menuItem: MenuItem): Closeable? {
|
||||||
val view = menuItem.actionView as? SearchView ?: return
|
val view = menuItem.actionView as? SearchView ?: return null
|
||||||
val context = view.context
|
val context = view.context
|
||||||
|
val adapter = MangaSuggestionsProvider.getSuggestionAdapter(context)
|
||||||
view.queryHint = context.getString(R.string.search_manga)
|
view.queryHint = context.getString(R.string.search_manga)
|
||||||
view.suggestionsAdapter = MangaSuggestionsProvider.getSuggestionAdapter(context)
|
view.suggestionsAdapter = adapter
|
||||||
view.setOnQueryTextListener(QueryListener(context))
|
view.setOnQueryTextListener(QueryListener(context))
|
||||||
view.setOnSuggestionListener(SuggestionListener(view))
|
view.setOnSuggestionListener(SuggestionListener(view))
|
||||||
|
return adapter?.cursor
|
||||||
}
|
}
|
||||||
|
|
||||||
private class QueryListener(private val context: Context) :
|
private class QueryListener(private val context: Context) :
|
||||||
|
|||||||
@@ -10,13 +10,14 @@ import org.jsoup.select.Elements
|
|||||||
|
|
||||||
fun Response.parseHtml(): Document {
|
fun Response.parseHtml(): Document {
|
||||||
try {
|
try {
|
||||||
val stream = body?.byteStream() ?: throw NullPointerException("Response body is null")
|
(body?.byteStream() ?: throw NullPointerException("Response body is null")).use { stream ->
|
||||||
val charset = body!!.contentType()?.charset()?.name()
|
val charset = body!!.contentType()?.charset()?.name()
|
||||||
return Jsoup.parse(
|
return Jsoup.parse(
|
||||||
stream,
|
stream,
|
||||||
charset,
|
charset,
|
||||||
request.url.toString()
|
request.url.toString()
|
||||||
)
|
)
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
closeQuietly()
|
closeQuietly()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ buildscript {
|
|||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:4.2.0-alpha02'
|
classpath 'com.android.tools.build:gradle:4.2.0-alpha03'
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
|
|||||||
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
|||||||
#Sat Jun 20 11:05:53 EEST 2020
|
#Wed Jul 01 18:26:34 EEST 2020
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip
|
||||||
|
|||||||
Reference in New Issue
Block a user