diff --git a/app/src/main/java/ani/dantotsu/parsers/ExtensionTestItem.kt b/app/src/main/java/ani/dantotsu/parsers/ExtensionTestItem.kt index 6a5f375315..073c466c70 100644 --- a/app/src/main/java/ani/dantotsu/parsers/ExtensionTestItem.kt +++ b/app/src/main/java/ani/dantotsu/parsers/ExtensionTestItem.kt @@ -1,5 +1,6 @@ package ani.dantotsu.parsers +import android.annotation.SuppressLint import android.content.Context import android.view.View import androidx.core.view.isVisible @@ -17,16 +18,16 @@ class ExtensionTestItem( private var extensionType: String, private var testType: String, private var extension: BaseParser, - private var searchString: String = "Chainsaw Man" + private var searchString: String ) : BindableItem() { private lateinit var binding: ItemExtensionTestBinding private lateinit var context: Context private var job: Job? = null private var isRunning = false private var pingResult: Triple? = null - private var searchResultSize: Int? = null - private var episodeResultSize: Int? = null - private var serverResultSize: Int? = null + private var searchResultData: TestResult = TestResult() + private var episodeResultData: TestResult = TestResult() + private var serverResultData: TestResult = TestResult() override fun bind(viewBinding: ItemExtensionTestBinding, position: Int) { binding = viewBinding @@ -36,6 +37,7 @@ class ExtensionTestItem( binding.extensionLoading.isVisible = isRunning hideAllResults() + println(searchString) pingResult() searchResult() episodeResult() @@ -65,9 +67,9 @@ class ExtensionTestItem( fun startTest() { pingResult = null - searchResultSize = null - episodeResultSize = null - serverResultSize = null + searchResultData = TestResult() + episodeResultData = TestResult() + serverResultData = TestResult() isRunning = true hideAllResults() job?.cancel() @@ -101,26 +103,32 @@ class ExtensionTestItem( done() return } + val searchStart = System.currentTimeMillis() val searchResult = extension.search(searchString) - searchResultSize = searchResult.size + searchResultData.time = (System.currentTimeMillis() - searchStart).toInt() + searchResultData.size = searchResult.size withContext(Dispatchers.Main) { searchResult() } - if (searchResultSize == 0 || testType == "basic") { + if (searchResultData.size == 0 || testType == "basic") { done() return } + val episodeResultTime = System.currentTimeMillis() val episodeResult = extension.loadEpisodes("", null, searchResult.first().sAnime!!) - episodeResultSize = episodeResult.size + episodeResultData.time = (System.currentTimeMillis() - episodeResultTime).toInt() + episodeResultData.size = episodeResult.size withContext(Dispatchers.Main) { episodeResult() } - if (episodeResultSize == 0) { + if (episodeResultData.size == 0) { done() return } + val serverResultTime = System.currentTimeMillis() val serverResult = extension.loadVideoServers("", null, episodeResult.first().sEpisode!!) - serverResultSize = serverResult.size + serverResultData.time = (System.currentTimeMillis() - serverResultTime).toInt() + serverResultData.size = serverResult.size withContext(Dispatchers.Main) { serverResult() } @@ -137,26 +145,32 @@ class ExtensionTestItem( done() return } + val searchStart = System.currentTimeMillis() val searchResult = extension.search(searchString) - searchResultSize = searchResult.size + searchResultData.time = (System.currentTimeMillis() - searchStart).toInt() + searchResultData.size = searchResult.size withContext(Dispatchers.Main) { searchResult() } - if (searchResultSize == 0 || testType == "basic") { + if (searchResultData.size == 0 || testType == "basic") { done() return } + val episodeResultStart = System.currentTimeMillis() val chapterResult = extension.loadChapters("", null, searchResult.first().sManga!!) - episodeResultSize = chapterResult.size + episodeResultData.time = (System.currentTimeMillis() - episodeResultStart).toInt() + episodeResultData.size = chapterResult.size withContext(Dispatchers.Main) { episodeResult() } - if (episodeResultSize == 0) { + if (episodeResultData.size == 0) { done() return } + val serverResultStart = System.currentTimeMillis() val serverResult = extension.loadImages("", chapterResult.first().sChapter) - serverResultSize = serverResult.size + serverResultData.time = (System.currentTimeMillis() - serverResultStart).toInt() + serverResultData.size = serverResult.size withContext(Dispatchers.Main) { serverResult() } @@ -172,17 +186,21 @@ class ExtensionTestItem( done() return } + val searchStart = System.currentTimeMillis() val searchResult = extension.search(searchString) - searchResultSize = searchResult.size + searchResultData.time = (System.currentTimeMillis() - searchStart).toInt() + searchResultData.size = searchResult.size withContext(Dispatchers.Main) { searchResult() } - if (searchResultSize == 0 || testType == "basic") { + if (searchResultData.size == 0 || testType == "basic") { done() return } + val chapterResultTime = System.currentTimeMillis() val chapterResult = extension.loadBook(searchResult.first().link, null) - episodeResultSize = chapterResult.links.size + episodeResultData.time = (System.currentTimeMillis() - chapterResultTime).toInt() + episodeResultData.size = chapterResult.links.size withContext(Dispatchers.Main) { episodeResult() serverResult() @@ -236,9 +254,10 @@ class ExtensionTestItem( ) } + @SuppressLint("SetTextI18n") private fun searchResult() { if (::binding.isInitialized.not()) return - if (searchResultSize == null) { + if (searchResultData.time == 0) { binding.searchResultText.isVisible = false return } @@ -246,7 +265,7 @@ class ExtensionTestItem( context.getThemeColor(com.google.android.material.R.attr.colorPrimary) ) binding.searchResultText.isVisible = true - if (searchResultSize == 0) { + if (searchResultData.size == 0) { val text = context.getString(R.string.title_search_test, context.getString(R.string.no_results_found)) binding.searchResultText.text = text @@ -259,16 +278,17 @@ class ExtensionTestItem( return } val text = context.getString(R.string.title_search_test, - context.getString(R.string.results_found, searchResultSize.toString())) - binding.searchResultText.text = text + context.getString(R.string.results_found, searchResultData.size.toString())) + binding.searchResultText.text = text + "\n${searchResultData.time}ms" binding.searchResultText.setCompoundDrawablesWithIntrinsicBounds( R.drawable.ic_circle_check, 0, 0, 0 ) } + @SuppressLint("SetTextI18n") private fun episodeResult() { if (::binding.isInitialized.not()) return - if (episodeResultSize == null) { + if (episodeResultData.time == 0) { binding.episodeResultText.isVisible = false return } @@ -276,7 +296,7 @@ class ExtensionTestItem( context.getThemeColor(com.google.android.material.R.attr.colorPrimary) ) binding.episodeResultText.isVisible = true - if (episodeResultSize == 0) { + if (episodeResultData.size == 0) { val text = when(extensionType) { "anime" -> context.getString(R.string.episode_search_test, context.getString(R.string.no_results_found)) @@ -296,18 +316,19 @@ class ExtensionTestItem( } val text = when(extensionType) { "anime" -> context.getString(R.string.episode_search_test, - context.getString(R.string.results_found, episodeResultSize.toString())) + context.getString(R.string.results_found, episodeResultData.size.toString())) "manga" -> context.getString(R.string.chapter_search_test, - context.getString(R.string.results_found, episodeResultSize.toString())) + context.getString(R.string.results_found, episodeResultData.size.toString())) else -> context.getString(R.string.book_search_test, - context.getString(R.string.results_found, episodeResultSize.toString())) + context.getString(R.string.results_found, episodeResultData.size.toString())) } - binding.episodeResultText.text = text + binding.episodeResultText.text = text + "\n${episodeResultData.time}ms" binding.episodeResultText.setCompoundDrawablesWithIntrinsicBounds( R.drawable.ic_circle_check, 0, 0, 0 ) } + @SuppressLint("SetTextI18n") private fun serverResult() { if (::binding.isInitialized.not()) return if (extensionType == "novel") { @@ -318,7 +339,7 @@ class ExtensionTestItem( ) return } - if (serverResultSize == null) { + if (serverResultData.time == 0) { binding.serverResultText.isVisible = false return } @@ -326,7 +347,7 @@ class ExtensionTestItem( context.getThemeColor(com.google.android.material.R.attr.colorPrimary) ) binding.serverResultText.isVisible = true - if (serverResultSize == 0) { + if (serverResultData.size == 0) { val text = when(extensionType) { "anime" -> context.getString(R.string.video_search_test, context.getString(R.string.no_results_found)) @@ -335,7 +356,7 @@ class ExtensionTestItem( else -> context.getString(R.string.book_search_test, context.getString(R.string.no_results_found)) } - binding.serverResultText.text = text + binding.serverResultText.text = text + "\n${serverResultData.time}ms" binding.serverResultText.setCompoundDrawablesWithIntrinsicBounds( R.drawable.ic_circle_cancel, 0, 0, 0 ) @@ -346,11 +367,11 @@ class ExtensionTestItem( } val text = when(extensionType) { "anime" -> context.getString(R.string.video_search_test, - context.getString(R.string.results_found, serverResultSize.toString())) + context.getString(R.string.results_found, serverResultData.size.toString())) "manga" -> context.getString(R.string.image_search_test, - context.getString(R.string.results_found, serverResultSize.toString())) + context.getString(R.string.results_found, serverResultData.size.toString())) else -> context.getString(R.string.book_search_test, - context.getString(R.string.results_found, serverResultSize.toString())) + context.getString(R.string.results_found, serverResultData.size.toString())) } binding.serverResultText.text = text binding.serverResultText.setCompoundDrawablesWithIntrinsicBounds( @@ -358,4 +379,8 @@ class ExtensionTestItem( ) } + data class TestResult( + var size: Int = 0, + var time: Int = 0, + ) } \ No newline at end of file diff --git a/app/src/main/java/ani/dantotsu/parsers/ExtensionTestSettingsBottomDialog.kt b/app/src/main/java/ani/dantotsu/parsers/ExtensionTestSettingsBottomDialog.kt index fcedad3f2d..1b7777eabf 100644 --- a/app/src/main/java/ani/dantotsu/parsers/ExtensionTestSettingsBottomDialog.kt +++ b/app/src/main/java/ani/dantotsu/parsers/ExtensionTestSettingsBottomDialog.kt @@ -5,6 +5,7 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.core.widget.addTextChangedListener import androidx.recyclerview.widget.LinearLayoutManager import ani.dantotsu.BottomSheetDialogFragment import ani.dantotsu.databinding.BottomSheetExtensionTestSettingsBinding @@ -39,6 +40,26 @@ class ExtensionTestSettingsBottomDialog : BottomSheetDialogFragment() { LinearLayoutManager.VERTICAL, false ) + binding.searchViewText.setText(searchQuery) + binding.searchViewText.addTextChangedListener { + searchQuery = it.toString() + } + binding.extensionTypeRadioGroup.check( + when (extensionType) { + "anime" -> binding.animeRadioButton.id + "manga" -> binding.mangaRadioButton.id + "novel" -> binding.novelsRadioButton.id + else -> binding.animeRadioButton.id + } + ) + binding.testTypeRadioGroup.check( + when (testType) { + "ping" -> binding.pingRadioButton.id + "basic" -> binding.basicRadioButton.id + "full" -> binding.fullRadioButton.id + else -> binding.pingRadioButton.id + } + ) binding.animeRadioButton.setOnCheckedChangeListener { _, b -> if (b) { extensionType = "anime" @@ -112,6 +133,7 @@ class ExtensionTestSettingsBottomDialog : BottomSheetDialogFragment() { var extensionType = "anime" var testType = "ping" + var searchQuery = "Chainsaw Man" var extensionsToTest: MutableList = mutableListOf() } } \ No newline at end of file diff --git a/app/src/main/java/ani/dantotsu/parsers/ParserTestActivity.kt b/app/src/main/java/ani/dantotsu/parsers/ParserTestActivity.kt index 7be91fe280..7d7f67f531 100644 --- a/app/src/main/java/ani/dantotsu/parsers/ParserTestActivity.kt +++ b/app/src/main/java/ani/dantotsu/parsers/ParserTestActivity.kt @@ -66,7 +66,8 @@ class ParserTestActivity : AppCompatActivity() { ExtensionTestItem( "anime", ExtensionTestSettingsBottomDialog.testType, - it + it, + ExtensionTestSettingsBottomDialog.searchQuery ) ) } @@ -81,7 +82,8 @@ class ParserTestActivity : AppCompatActivity() { ExtensionTestItem( "manga", ExtensionTestSettingsBottomDialog.testType, - it + it, + ExtensionTestSettingsBottomDialog.searchQuery ) ) } @@ -96,7 +98,8 @@ class ParserTestActivity : AppCompatActivity() { ExtensionTestItem( "novel", ExtensionTestSettingsBottomDialog.testType, - it + it, + ExtensionTestSettingsBottomDialog.searchQuery ) ) } diff --git a/app/src/main/res/layout/bottom_sheet_extension_test_settings.xml b/app/src/main/res/layout/bottom_sheet_extension_test_settings.xml index bacd922a9b..55df828e61 100644 --- a/app/src/main/res/layout/bottom_sheet_extension_test_settings.xml +++ b/app/src/main/res/layout/bottom_sheet_extension_test_settings.xml @@ -3,6 +3,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" xmlns:tools="http://schemas.android.com/tools" + xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_marginVertical="16dp" android:orientation="vertical"> @@ -16,6 +17,7 @@ android:textSize="16sp" /> @@ -57,6 +59,7 @@ android:textSize="16sp" /> @@ -87,6 +90,52 @@ + + + + + + + Book Search Test: %1$s Failed to fix Running Fixes… + Test Search