Skip to content

Commit

Permalink
feat: test ms response
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelonion committed May 20, 2024
1 parent 10df198 commit fe1a7af
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 39 deletions.
97 changes: 61 additions & 36 deletions app/src/main/java/ani/dantotsu/parsers/ExtensionTestItem.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<ItemExtensionTestBinding>() {
private lateinit var binding: ItemExtensionTestBinding
private lateinit var context: Context
private var job: Job? = null
private var isRunning = false
private var pingResult: Triple<Int, Int?, String>? = 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
Expand All @@ -36,6 +37,7 @@ class ExtensionTestItem(
binding.extensionLoading.isVisible = isRunning
hideAllResults()

println(searchString)
pingResult()
searchResult()
episodeResult()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
}
Expand All @@ -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()
}
Expand All @@ -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()
Expand Down Expand Up @@ -236,17 +254,18 @@ class ExtensionTestItem(
)
}

@SuppressLint("SetTextI18n")
private fun searchResult() {
if (::binding.isInitialized.not()) return
if (searchResultSize == null) {
if (searchResultData.time == 0) {
binding.searchResultText.isVisible = false
return
}
binding.searchResultText.setTextColor(
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
Expand All @@ -259,24 +278,25 @@ 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
}
binding.episodeResultText.setTextColor(
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))
Expand All @@ -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") {
Expand All @@ -318,15 +339,15 @@ class ExtensionTestItem(
)
return
}
if (serverResultSize == null) {
if (serverResultData.time == 0) {
binding.serverResultText.isVisible = false
return
}
binding.serverResultText.setTextColor(
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))
Expand All @@ -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
)
Expand All @@ -346,16 +367,20 @@ 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(
R.drawable.ic_circle_check, 0, 0, 0
)
}

data class TestResult(
var size: Int = 0,
var time: Int = 0,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -112,6 +133,7 @@ class ExtensionTestSettingsBottomDialog : BottomSheetDialogFragment() {

var extensionType = "anime"
var testType = "ping"
var searchQuery = "Chainsaw Man"
var extensionsToTest: MutableList<String> = mutableListOf()
}
}
9 changes: 6 additions & 3 deletions app/src/main/java/ani/dantotsu/parsers/ParserTestActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class ParserTestActivity : AppCompatActivity() {
ExtensionTestItem(
"anime",
ExtensionTestSettingsBottomDialog.testType,
it
it,
ExtensionTestSettingsBottomDialog.searchQuery
)
)
}
Expand All @@ -81,7 +82,8 @@ class ParserTestActivity : AppCompatActivity() {
ExtensionTestItem(
"manga",
ExtensionTestSettingsBottomDialog.testType,
it
it,
ExtensionTestSettingsBottomDialog.searchQuery
)
)
}
Expand All @@ -96,7 +98,8 @@ class ParserTestActivity : AppCompatActivity() {
ExtensionTestItem(
"novel",
ExtensionTestSettingsBottomDialog.testType,
it
it,
ExtensionTestSettingsBottomDialog.searchQuery
)
)
}
Expand Down
Loading

0 comments on commit fe1a7af

Please sign in to comment.