💫 Fix Layout bug + Handle Crash bug
This commit is contained in:
parent
391d888908
commit
d46282db17
5 changed files with 40 additions and 17 deletions
|
@ -27,6 +27,8 @@ import com.google.gson.Gson
|
||||||
import com.google.gson.reflect.TypeToken
|
import com.google.gson.reflect.TypeToken
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import android.text.method.ScrollingMovementMethod
|
||||||
|
import android.util.DisplayMetrics
|
||||||
|
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
@ -409,16 +411,28 @@ class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n")
|
@SuppressLint("SetTextI18n")
|
||||||
private fun showAppInfoPage() {
|
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"]
|
val link = appMobilismInfos!!["link"]
|
||||||
if (link != null) {
|
if (link != null) {
|
||||||
val infoApp: MutableMap<String, String?>
|
val infoApp: MutableMap<String, String?>
|
||||||
val links: MutableMap<String, List<String>>
|
var links: MutableMap<String, List<String>> = mutableMapOf()
|
||||||
|
var errorHappen = false
|
||||||
runBlocking {
|
runBlocking {
|
||||||
infoApp = Scraper().parseInfos(link)
|
infoApp = Scraper().parseInfos(link)
|
||||||
|
try {
|
||||||
links = Scraper().parseDownloadLinks(infoApp["downloadLinks"]!!)
|
links = Scraper().parseDownloadLinks(infoApp["downloadLinks"]!!)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Toast.makeText(
|
||||||
|
instance,
|
||||||
|
"${getString(R.string.noLinkFound)}...",
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
errorHappen = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (errorHappen) return else {
|
||||||
|
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
|
||||||
}
|
}
|
||||||
class Adapter(private val values: List<String>) :
|
class Adapter(private val values: List<String>) :
|
||||||
RecyclerView.Adapter<Adapter.ViewHolder>() {
|
RecyclerView.Adapter<Adapter.ViewHolder>() {
|
||||||
|
@ -456,16 +470,22 @@ class MainActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
findViewById<TextView>(R.id.textViewAppName).text = appMobilismInfos!!["title"]
|
val title = findViewById<TextView>(R.id.textViewAppName)
|
||||||
|
title.text = appMobilismInfos!!["title"]
|
||||||
|
title.setOnClickListener { startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://forum.mobilism.org$link"))) }
|
||||||
findViewById<TextView>(R.id.textViewAppAuthor).text = appMobilismInfos!!["author"]
|
findViewById<TextView>(R.id.textViewAppAuthor).text = appMobilismInfos!!["author"]
|
||||||
findViewById<TextView>(R.id.textViewAppDate).text = appMobilismInfos!!["date"]
|
findViewById<TextView>(R.id.textViewAppDate).text = appMobilismInfos!!["date"]
|
||||||
findViewById<TextView>(R.id.textViewAppChangelogs).text = infoApp["changelogs"]
|
val changelogs = findViewById<TextView>(R.id.textViewAppChangelogs)
|
||||||
|
changelogs.text = infoApp["changelogs"]
|
||||||
|
changelogs.movementMethod = ScrollingMovementMethod()
|
||||||
|
|
||||||
val listDownloads = mutableListOf<String>()
|
val listDownloads = mutableListOf<String>()
|
||||||
for (arch in links.keys) {
|
|
||||||
val recyclerViewAppDownloads: RecyclerView =
|
val recyclerViewAppDownloads: RecyclerView =
|
||||||
findViewById(R.id.recyclerViewAppDownloads) // get recyclerview
|
findViewById(R.id.recyclerViewAppDownloads) // get recyclerview
|
||||||
recyclerViewAppDownloads.layoutManager = LinearLayoutManager(this)
|
recyclerViewAppDownloads.layoutManager = LinearLayoutManager(this)
|
||||||
|
val displayMetrics = DisplayMetrics()
|
||||||
|
recyclerViewAppDownloads.layoutParams.height = displayMetrics.heightPixels / 3
|
||||||
|
for (arch in links.keys) {
|
||||||
for ((count, _) in links[arch]!!.withIndex()) {
|
for ((count, _) in links[arch]!!.withIndex()) {
|
||||||
listDownloads += "$arch - ${count + 1}"
|
listDownloads += "$arch - ${count + 1}"
|
||||||
}
|
}
|
||||||
|
|
|
@ -196,7 +196,7 @@ class Scraper(
|
||||||
"No changelog found."
|
"No changelog found."
|
||||||
}
|
}
|
||||||
elements["downloadLinks"] = try {
|
elements["downloadLinks"] = try {
|
||||||
htmlPage = htmlPage.replace(Regex("Download Instructions:</span>(.*?)?<br /><s"),
|
htmlPage = htmlPage.replace(Regex("Download Instructions:</span>(.*?)?<br />"),
|
||||||
"Download Instructions:</span><br /><s")
|
"Download Instructions:</span><br /><s")
|
||||||
var tmp =
|
var tmp =
|
||||||
Regex("""Download Instructions:</span> ?<br />(.*|[\s\S]*)<br /><br />Trouble downloading|</a></div>""").findAll(
|
Regex("""Download Instructions:</span> ?<br />(.*|[\s\S]*)<br /><br />Trouble downloading|</a></div>""").findAll(
|
||||||
|
|
|
@ -57,10 +57,11 @@
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textViewAppChangelogs"
|
android:id="@+id/textViewAppChangelogs"
|
||||||
android:layout_width="334dp"
|
android:layout_width="337dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="183dp"
|
||||||
android:layout_marginTop="12dp"
|
android:layout_marginTop="12dp"
|
||||||
android:fontFamily="monospace"
|
android:fontFamily="monospace"
|
||||||
|
android:scrollbars="vertical"
|
||||||
android:textAlignment="viewStart"
|
android:textAlignment="viewStart"
|
||||||
android:textSize="16sp"
|
android:textSize="16sp"
|
||||||
android:textStyle="italic"
|
android:textStyle="italic"
|
||||||
|
@ -83,14 +84,14 @@
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/recyclerViewAppDownloads"
|
android:id="@+id/recyclerViewAppDownloads"
|
||||||
android:layout_width="334dp"
|
android:layout_width="350dp"
|
||||||
android:layout_height="524dp"
|
android:layout_height="262dp"
|
||||||
android:layout_marginTop="12dp"
|
android:layout_marginTop="12dp"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintHorizontal_bias="0.493"
|
app:layout_constraintHorizontal_bias="0.491"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/textViewAppDownloadsTitle"
|
app:layout_constraintTop_toBottomOf="@+id/textViewAppDownloadsTitle"
|
||||||
app:layout_constraintVertical_bias="0.125" />
|
app:layout_constraintVertical_bias="0.036" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -31,4 +31,5 @@
|
||||||
<string name="noURL">Aucune URL n\'a été trouvé pour ce post</string>
|
<string name="noURL">Aucune URL n\'a été trouvé pour ce post</string>
|
||||||
<string name="changelogs">Changements</string>
|
<string name="changelogs">Changements</string>
|
||||||
<string name="downloads">Téléchargements</string>
|
<string name="downloads">Téléchargements</string>
|
||||||
|
<string name="noLinkFound">Aucun lien trouvé</string>
|
||||||
</resources>
|
</resources>
|
|
@ -40,4 +40,5 @@
|
||||||
<!-- App Infos -->
|
<!-- App Infos -->
|
||||||
<string name="changelogs">Changelogs</string>
|
<string name="changelogs">Changelogs</string>
|
||||||
<string name="downloads">Downloads</string>
|
<string name="downloads">Downloads</string>
|
||||||
|
<string name="noLinkFound">No link found</string>
|
||||||
</resources>
|
</resources>
|
Reference in a new issue