diff --git a/app/src/main/java/com/mylloon/mobidl/MainActivity.kt b/app/src/main/java/com/mylloon/mobidl/MainActivity.kt index ec803b7..a861ec6 100644 --- a/app/src/main/java/com/mylloon/mobidl/MainActivity.kt +++ b/app/src/main/java/com/mylloon/mobidl/MainActivity.kt @@ -142,7 +142,7 @@ class MainActivity : AppCompatActivity() { override fun onCreateViewHolder( parent: ViewGroup, - viewType: Int + viewType: Int, ): ViewHolder { // add viewHolder to the main page val itemView = LayoutInflater.from(parent.context) .inflate(R.layout.list_item_view, parent, false) @@ -252,7 +252,7 @@ class MainActivity : AppCompatActivity() { password: String, app: String, captchaID: String? = null, - captchaResponse: String? = null + captchaResponse: String? = null, ) { if (ContextCompat.checkSelfPermission(this@MainActivity, Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED @@ -362,7 +362,8 @@ class MainActivity : AppCompatActivity() { setContentView(R.layout.activity_app_list) // display list of app version page if (!settingsButtonVisible) toggleSettingsButtonVisibility() // check if the settings button isn't already showed and show it if necessary inAppList = true - class Adapter(private val values: List) : RecyclerView.Adapter() { + class Adapter(private val values: List) : + RecyclerView.Adapter() { override fun getItemCount() = values.size override fun onCreateViewHolder( @@ -385,17 +386,22 @@ class MainActivity : AppCompatActivity() { button = itemView?.findViewById(R.id.text_list_item_app_list) button?.setOnClickListener { inAppList = false - appMobilismInfos = listInfos!![Regex("""\d+""").findAll(button?.text.toString()).map { it.groupValues[0] }.toList()[0].toInt() - 1] + appMobilismInfos = + listInfos!![Regex("""\d+""").findAll(button?.text.toString()) + .map { it.groupValues[0] }.toList()[0].toInt() - 1] showAppInfoPage() } } } } - val recyclerViewAppList: RecyclerView = findViewById(R.id.recyclerViewAppList) // get recyclerview + + val recyclerViewAppList: RecyclerView = + findViewById(R.id.recyclerViewAppList) // get recyclerview recyclerViewAppList.layoutManager = LinearLayoutManager(this) val listInfosNames = mutableListOf() for (i in listInfos!!.indices) { // get all apps name - val tmp = "${i + 1} - ${listInfos!![i]["title"]} (${listInfos!![i]["author"]})\n${listInfos!![i]["date"]}" + val tmp = + "${i + 1} - ${listInfos!![i]["title"]} (${listInfos!![i]["author"]})\n${listInfos!![i]["date"]}" listInfosNames += tmp } recyclerViewAppList.adapter = Adapter(listInfosNames) @@ -414,7 +420,8 @@ class MainActivity : AppCompatActivity() { infoApp = Scraper().parseInfos(link) links = Scraper().parseDownloadLinks(infoApp["downloadLinks"]!!) } - class Adapter(private val values: List) : RecyclerView.Adapter() { + class Adapter(private val values: List) : + RecyclerView.Adapter() { override fun getItemCount() = values.size override fun onCreateViewHolder( @@ -440,7 +447,8 @@ class MainActivity : AppCompatActivity() { startActivity( Intent( Intent.ACTION_VIEW, Uri.parse( - links[splitText[0]]!![splitText[1].replace("\\s".toRegex(), "").toInt() - 1] + links[splitText[0]]!![splitText[1].replace("\\s".toRegex(), + "").toInt() - 1] ) ) ) @@ -455,14 +463,16 @@ class MainActivity : AppCompatActivity() { val listDownloads = mutableListOf() for (arch in links.keys) { - val recyclerViewAppDownloads: RecyclerView = findViewById(R.id.recyclerViewAppDownloads) // get recyclerview + val recyclerViewAppDownloads: RecyclerView = + findViewById(R.id.recyclerViewAppDownloads) // get recyclerview recyclerViewAppDownloads.layoutManager = LinearLayoutManager(this) for ((count, _) in links[arch]!!.withIndex()) { listDownloads += "$arch - ${count + 1}" } recyclerViewAppDownloads.adapter = Adapter(listDownloads) } - } else Toast.makeText(instance, "${getString(R.string.noURL)}...", Toast.LENGTH_SHORT).show() + } else Toast.makeText(instance, "${getString(R.string.noURL)}...", Toast.LENGTH_SHORT) + .show() } @SuppressLint("SetTextI18n") diff --git a/app/src/main/java/com/mylloon/mobidl/Scraper.kt b/app/src/main/java/com/mylloon/mobidl/Scraper.kt index 5cf4378..f8f4565 100644 --- a/app/src/main/java/com/mylloon/mobidl/Scraper.kt +++ b/app/src/main/java/com/mylloon/mobidl/Scraper.kt @@ -11,7 +11,7 @@ class Scraper( private var password: String? = null, // can be null if parsing a post private var app: String? = null, // can be null if parsing a post private var captchaID: String? = null, // can be null if no captcha - private var captchaResponse: String? = null // can be null if no captcha + private var captchaResponse: String? = null, // can be null if no captcha ) { private var url: String = "https://forum.mobilism.org" @@ -181,25 +181,36 @@ class Scraper( // elements["downloadLinks"] = null // } elements["changelogs"] = try { - var tmp = Regex("""What's New: ?
(.*)

T""").findAll(htmlPage) - .map { it.groupValues[1] }.toList()[0] - if (tmp.length < 2) { // if result none, trying other method - tmp = Regex("""What's New: ?
(.*)

T""").findAll(htmlPage) + var tmp = + Regex("""What's New: ?
(.*)

T""").findAll( + htmlPage) .map { it.groupValues[1] }.toList()[0] + if (tmp.length < 2) { // if result none, trying other method + tmp = + Regex("""What's New: ?
(.*)

T""").findAll( + htmlPage) + .map { it.groupValues[1] }.toList()[0] } tmp.replace(Regex("""
\n?"""), "\n") // convert newline html to \n } catch (e: Exception) { "No changelog found." } elements["downloadLinks"] = try { - htmlPage = htmlPage.replace(Regex("Download Instructions:
(.*?)?

?
(.*|[\s\S]*)

Trouble downloading|""").findAll(htmlPage) - .map { it.groupValues[1] }.toList()[0] - if (tmp.length < 2) { // if result none, trying other method - tmp = Regex("""Download Instructions: ?
(.*|[\s\S]*)""").findAll(htmlPage) + htmlPage = htmlPage.replace(Regex("Download Instructions:(.*?)?

?
(.*|[\s\S]*)

Trouble downloading|""").findAll( + htmlPage) .map { it.groupValues[1] }.toList()[0] + if (tmp.length < 2) { // if result none, trying other method + tmp = + Regex("""Download Instructions: ?
(.*|[\s\S]*)""").findAll( + htmlPage) + .map { it.groupValues[1] }.toList()[0] } - tmp = tmp.replace(Regex("""\n|||">(\S*)"""), "") // remove html garbage + tmp = + tmp.replace(Regex("""\n|||">(\S*)"""), + "") // remove html garbage tmp = tmp.replace(Regex("""
\n?"""), "\n") // convert newline html to \n tmp = tmp.replace(Regex("""Mirrors(?!:)|Mirror(?!s)(?!:)"""), "Mirror:") // add ":" var finalTmp = "" @@ -212,7 +223,7 @@ class Scraper( } fun parseDownloadLinks(links: String): MutableMap> { - val downloadLinks = links.split("\n").filter { it != ""} + val downloadLinks = links.split("\n").filter { it != "" } val categoryDL = mutableMapOf>() var inCategory: String? = null val noCategoryString = "No Category" @@ -229,12 +240,14 @@ class Scraper( tempCategoryDL.clear() } var previous = "" - if (("Mirror" in downloadLink) and (inCategory != null)) previous = " of $inCategory" + if (("Mirror" in downloadLink) and (inCategory != null)) previous = + " of $inCategory" inCategory = "${downloadLink.replace(":", "")}$previous" // first category } } if (tempCategoryDL.isNotEmpty()) categoryDL[inCategory!!] = tempCategoryDL - if (tempNoCategoryDL.isNotEmpty()) categoryDL[noCategoryString] = tempNoCategoryDL else categoryDL.remove(noCategoryString) + if (tempNoCategoryDL.isNotEmpty()) categoryDL[noCategoryString] = + tempNoCategoryDL else categoryDL.remove(noCategoryString) return categoryDL }