🆕 Adding Download page
This commit is contained in:
parent
3d7e96c03a
commit
702b5e3dae
4 changed files with 120 additions and 22 deletions
|
@ -350,9 +350,9 @@ class MainActivity : AppCompatActivity() {
|
|||
"${returns.size} ${getString(R.string.gotResults)} !",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
listInfos = returns
|
||||
showAppListPage()
|
||||
}
|
||||
listInfos = returns
|
||||
showAppListPage()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -401,29 +401,66 @@ class MainActivity : AppCompatActivity() {
|
|||
recyclerViewAppList.adapter = Adapter(listInfosNames)
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
private fun showAppInfoPage() {
|
||||
setContentView(R.layout.activity_app_infos) // display app info detailed page
|
||||
if (!settingsButtonVisible) toggleSettingsButtonVisibility() // check if the settings button isn't already showed and show it if necessary
|
||||
inAppInfo = true
|
||||
val link = appMobilismInfos!!["link"]
|
||||
if (link != null) {
|
||||
runBlocking { // GlobalScope.launch {
|
||||
val infoApp = Scraper().parseInfos(link)
|
||||
findViewById<TextView>(R.id.textViewAppName).text = appMobilismInfos!!["title"]
|
||||
findViewById<TextView>(R.id.textViewAppAuthor).text = appMobilismInfos!!["author"]
|
||||
findViewById<TextView>(R.id.textViewAppDate).text = appMobilismInfos!!["date"]
|
||||
findViewById<TextView>(R.id.textViewAppChangelogs).text = infoApp["changelogs"]
|
||||
val infoApp: MutableMap<String, String?>
|
||||
val links: MutableMap<String, List<String>>
|
||||
runBlocking {
|
||||
infoApp = Scraper().parseInfos(link)
|
||||
links = Scraper().parseDownloadLinks(infoApp["downloadLinks"]!!)
|
||||
}
|
||||
class Adapter(private val values: List<String>) : RecyclerView.Adapter<Adapter.ViewHolder>() {
|
||||
override fun getItemCount() = values.size
|
||||
|
||||
////////////////////////
|
||||
override fun onCreateViewHolder(
|
||||
parent: ViewGroup,
|
||||
viewType: Int,
|
||||
): ViewHolder { // add viewHolder to the parent page
|
||||
val itemView = LayoutInflater.from(parent.context)
|
||||
.inflate(R.layout.list_item_view_app_download, parent, false)
|
||||
return ViewHolder(itemView)
|
||||
}
|
||||
|
||||
println("\n")
|
||||
println("Title: ${appMobilismInfos!!["title"]}\n")
|
||||
println("Author: ${appMobilismInfos!!["author"]}\n")
|
||||
println("Date of release: ${appMobilismInfos!!["date"]}\n")
|
||||
println("Changelogs: \n${infoApp["changelogs"]}\n")
|
||||
println("Download links: \n${infoApp["downloadLinks"]}")
|
||||
println("\n\n---\n")
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
holder.button?.text = values[position]
|
||||
}
|
||||
|
||||
inner class ViewHolder(itemView: View?) : RecyclerView.ViewHolder(itemView!!) {
|
||||
var button: Button? = null
|
||||
|
||||
init {
|
||||
button = itemView?.findViewById(R.id.download_button)
|
||||
button?.setOnClickListener {
|
||||
val splitText = button?.text.toString().split(Regex(" - "))
|
||||
startActivity(
|
||||
Intent(
|
||||
Intent.ACTION_VIEW, Uri.parse(
|
||||
links[splitText[0]]!![splitText[1].replace("\\s".toRegex(), "").toInt() - 1]
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
findViewById<TextView>(R.id.textViewAppName).text = appMobilismInfos!!["title"]
|
||||
findViewById<TextView>(R.id.textViewAppAuthor).text = appMobilismInfos!!["author"]
|
||||
findViewById<TextView>(R.id.textViewAppDate).text = appMobilismInfos!!["date"]
|
||||
findViewById<TextView>(R.id.textViewAppChangelogs).text = infoApp["changelogs"]
|
||||
|
||||
val listDownloads = mutableListOf<String>()
|
||||
for (arch in links.keys) {
|
||||
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()
|
||||
}
|
||||
|
|
|
@ -181,10 +181,10 @@ class Scraper(
|
|||
// elements["downloadLinks"] = null
|
||||
// }
|
||||
elements["changelogs"] = try {
|
||||
val tmp = Regex("""What's New:</span> ?<br />(.*)<br /><br /><span style="c|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
|
||||
Regex("""What's New:</span> ?<br />(.*)<br /><br /><span style="font-weight: bold">T""").findAll(htmlPage)
|
||||
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
|
||||
|
@ -192,21 +192,51 @@ class Scraper(
|
|||
"No changelog found."
|
||||
}
|
||||
elements["downloadLinks"] = try {
|
||||
htmlPage = htmlPage.replace(Regex("Download Instructions:</span>(.*)?<br /><s"), "Download Instructions:</span><br /><s")
|
||||
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
|
||||
Regex("""Download Instructions:</span> ?<br />(.*|[\s\S]*)</a></div>""").findAll(htmlPage)
|
||||
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("""<br />\n?"""), "\n") // convert newline html to \n
|
||||
tmp = tmp.replace(Regex("""Mirrors(?!:)|Mirror(?!s)(?!:)"""), "Mirror:") // add ":"
|
||||
tmp.split("""">""")[0]
|
||||
var finalTmp = ""
|
||||
for (i in tmp.split("\n")) finalTmp += i.split(">")[0] + "\n"
|
||||
finalTmp.replace("\"", "")
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
return elements
|
||||
}
|
||||
|
||||
fun parseDownloadLinks(links: String): MutableMap<String, List<String>> {
|
||||
val downloadLinks = links.split("\n").filter { it != ""}
|
||||
val categoryDL = mutableMapOf<String, List<String>>()
|
||||
var inCategory: String? = null
|
||||
val noCategoryString = "No Category"
|
||||
val tempNoCategoryDL = mutableListOf<String>()
|
||||
val tempCategoryDL = mutableListOf<String>()
|
||||
categoryDL[noCategoryString] = listOf("") // init the no category at index 0 of the map
|
||||
for (downloadLink in downloadLinks) {
|
||||
if (("http" in downloadLink) or ("www." in downloadLink)) { // lien
|
||||
if (inCategory != null) tempCategoryDL.add(downloadLink) // if the link is inside a category
|
||||
else tempNoCategoryDL.add(downloadLink) // else he don't have category
|
||||
} else { // else it's a category
|
||||
if ((inCategory != null) && (tempCategoryDL.size > 0)) { // already in category?
|
||||
categoryDL[inCategory] = tempCategoryDL.toMutableList()
|
||||
tempCategoryDL.clear()
|
||||
}
|
||||
var previous = ""
|
||||
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)
|
||||
|
||||
return categoryDL
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
<TextView
|
||||
android:id="@+id/textViewAppChangelogs"
|
||||
android:layout_width="334dp"
|
||||
android:layout_height="230dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:fontFamily="monospace"
|
||||
android:textAlignment="viewStart"
|
||||
|
@ -81,4 +81,16 @@
|
|||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textViewAppChangelogs" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recyclerViewAppDownloads"
|
||||
android:layout_width="334dp"
|
||||
android:layout_height="524dp"
|
||||
android:layout_marginTop="12dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.493"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textViewAppDownloadsTitle"
|
||||
app:layout_constraintVertical_bias="0.125" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
19
app/src/main/res/layout/list_item_view_app_download.xml
Normal file
19
app/src/main/res/layout/list_item_view_app_download.xml
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_layout_app_list"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:paddingTop="5dp"
|
||||
android:paddingBottom="5dp"
|
||||
android:paddingStart="5dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/download_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</LinearLayout>
|
Reference in a new issue