Improved visibility
This commit is contained in:
parent
4ad4ddc731
commit
f2b8f571ff
2 changed files with 47 additions and 24 deletions
|
@ -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<String>) : RecyclerView.Adapter<Adapter.ViewHolder>() {
|
||||
class Adapter(private val values: List<String>) :
|
||||
RecyclerView.Adapter<Adapter.ViewHolder>() {
|
||||
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<String>()
|
||||
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<String>) : RecyclerView.Adapter<Adapter.ViewHolder>() {
|
||||
class Adapter(private val values: List<String>) :
|
||||
RecyclerView.Adapter<Adapter.ViewHolder>() {
|
||||
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<String>()
|
||||
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")
|
||||
|
|
|
@ -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:</span> ?<br />(.*)<br /><br /><span style="c|font-weight: bold">T""").findAll(htmlPage)
|
||||
.map { it.groupValues[1] }.toList()[0]
|
||||
if (tmp.length < 2) { // if result none, trying other method
|
||||
tmp = Regex("""What's New:</span> ?<br />(.*)<br /><br /><span style="font-weight: bold">T""").findAll(htmlPage)
|
||||
var tmp =
|
||||
Regex("""What's New:</span> ?<br />(.*)<br /><br /><span style="c|font-weight: bold">T""").findAll(
|
||||
htmlPage)
|
||||
.map { it.groupValues[1] }.toList()[0]
|
||||
if (tmp.length < 2) { // if result none, trying other method
|
||||
tmp =
|
||||
Regex("""What's New:</span> ?<br />(.*)<br /><br /><span style="font-weight: bold">T""").findAll(
|
||||
htmlPage)
|
||||
.map { it.groupValues[1] }.toList()[0]
|
||||
}
|
||||
tmp.replace(Regex("""<br />\n?"""), "\n") // convert newline html to \n
|
||||
} catch (e: Exception) {
|
||||
"No changelog found."
|
||||
}
|
||||
elements["downloadLinks"] = try {
|
||||
htmlPage = htmlPage.replace(Regex("Download Instructions:</span>(.*?)?<br /><s"), "Download Instructions:</span><br /><s")
|
||||
var tmp = Regex("""Download Instructions:</span> ?<br />(.*|[\s\S]*)<br /><br />Trouble downloading|</a></div>""").findAll(htmlPage)
|
||||
.map { it.groupValues[1] }.toList()[0]
|
||||
if (tmp.length < 2) { // if result none, trying other method
|
||||
tmp = Regex("""Download Instructions:</span> ?<br />(.*|[\s\S]*)</a></div>""").findAll(htmlPage)
|
||||
htmlPage = htmlPage.replace(Regex("Download Instructions:</span>(.*?)?<br /><s"),
|
||||
"Download Instructions:</span><br /><s")
|
||||
var tmp =
|
||||
Regex("""Download Instructions:</span> ?<br />(.*|[\s\S]*)<br /><br />Trouble downloading|</a></div>""").findAll(
|
||||
htmlPage)
|
||||
.map { it.groupValues[1] }.toList()[0]
|
||||
if (tmp.length < 2) { // if result none, trying other method
|
||||
tmp =
|
||||
Regex("""Download Instructions:</span> ?<br />(.*|[\s\S]*)</a></div>""").findAll(
|
||||
htmlPage)
|
||||
.map { it.groupValues[1] }.toList()[0]
|
||||
}
|
||||
tmp = tmp.replace(Regex("""\n|<a class="postlink" href="|\(Closed Filehost\) ?|<span style="font-weight: bold">|</span>|">(\S*)</a>"""), "") // remove html garbage
|
||||
tmp =
|
||||
tmp.replace(Regex("""\n|<a class="postlink" href="|\(Closed Filehost\) ?|<span style="font-weight: bold">|</span>|">(\S*)</a>"""),
|
||||
"") // remove html garbage
|
||||
tmp = tmp.replace(Regex("""<br />\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<String, List<String>> {
|
||||
val downloadLinks = links.split("\n").filter { it != ""}
|
||||
val downloadLinks = links.split("\n").filter { it != "" }
|
||||
val categoryDL = mutableMapOf<String, List<String>>()
|
||||
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
|
||||
}
|
||||
|
|
Reference in a new issue