🆕 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)} !",
|
"${returns.size} ${getString(R.string.gotResults)} !",
|
||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
|
listInfos = returns
|
||||||
|
showAppListPage()
|
||||||
}
|
}
|
||||||
listInfos = returns
|
|
||||||
showAppListPage()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -401,29 +401,66 @@ class MainActivity : AppCompatActivity() {
|
||||||
recyclerViewAppList.adapter = Adapter(listInfosNames)
|
recyclerViewAppList.adapter = Adapter(listInfosNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
private fun showAppInfoPage() {
|
private fun showAppInfoPage() {
|
||||||
setContentView(R.layout.activity_app_infos) // display app info detailed page
|
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
|
if (!settingsButtonVisible) toggleSettingsButtonVisibility() // check if the settings button isn't already showed and show it if necessary
|
||||||
inAppInfo = true
|
inAppInfo = true
|
||||||
val link = appMobilismInfos!!["link"]
|
val link = appMobilismInfos!!["link"]
|
||||||
if (link != null) {
|
if (link != null) {
|
||||||
runBlocking { // GlobalScope.launch {
|
val infoApp: MutableMap<String, String?>
|
||||||
val infoApp = Scraper().parseInfos(link)
|
val links: MutableMap<String, List<String>>
|
||||||
findViewById<TextView>(R.id.textViewAppName).text = appMobilismInfos!!["title"]
|
runBlocking {
|
||||||
findViewById<TextView>(R.id.textViewAppAuthor).text = appMobilismInfos!!["author"]
|
infoApp = Scraper().parseInfos(link)
|
||||||
findViewById<TextView>(R.id.textViewAppDate).text = appMobilismInfos!!["date"]
|
links = Scraper().parseDownloadLinks(infoApp["downloadLinks"]!!)
|
||||||
findViewById<TextView>(R.id.textViewAppChangelogs).text = infoApp["changelogs"]
|
}
|
||||||
|
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")
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
println("Title: ${appMobilismInfos!!["title"]}\n")
|
holder.button?.text = values[position]
|
||||||
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")
|
|
||||||
|
|
||||||
|
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()
|
} else Toast.makeText(instance, "${getString(R.string.noURL)}...", Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,10 +181,10 @@ class Scraper(
|
||||||
// elements["downloadLinks"] = null
|
// elements["downloadLinks"] = null
|
||||||
// }
|
// }
|
||||||
elements["changelogs"] = try {
|
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]
|
.map { it.groupValues[1] }.toList()[0]
|
||||||
if (tmp.length < 2) { // if result none, trying other method
|
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]
|
.map { it.groupValues[1] }.toList()[0]
|
||||||
}
|
}
|
||||||
tmp.replace(Regex("""<br />\n?"""), "\n") // convert newline html to \n
|
tmp.replace(Regex("""<br />\n?"""), "\n") // convert newline html to \n
|
||||||
|
@ -192,21 +192,51 @@ class Scraper(
|
||||||
"No changelog found."
|
"No changelog found."
|
||||||
}
|
}
|
||||||
elements["downloadLinks"] = try {
|
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)
|
var tmp = Regex("""Download Instructions:</span> ?<br />(.*|[\s\S]*)<br /><br />Trouble downloading|</a></div>""").findAll(htmlPage)
|
||||||
.map { it.groupValues[1] }.toList()[0]
|
.map { it.groupValues[1] }.toList()[0]
|
||||||
if (tmp.length < 2) { // if result none, trying other method
|
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]
|
.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("""<br />\n?"""), "\n") // convert newline html to \n
|
||||||
tmp = tmp.replace(Regex("""Mirrors(?!:)|Mirror(?!s)(?!:)"""), "Mirror:") // add ":"
|
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) {
|
} catch (e: Exception) {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
return elements
|
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
|
<TextView
|
||||||
android:id="@+id/textViewAppChangelogs"
|
android:id="@+id/textViewAppChangelogs"
|
||||||
android:layout_width="334dp"
|
android:layout_width="334dp"
|
||||||
android:layout_height="230dp"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="12dp"
|
android:layout_marginTop="12dp"
|
||||||
android:fontFamily="monospace"
|
android:fontFamily="monospace"
|
||||||
android:textAlignment="viewStart"
|
android:textAlignment="viewStart"
|
||||||
|
@ -81,4 +81,16 @@
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/textViewAppChangelogs" />
|
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>
|
</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