diff --git a/app/src/main/java/com/mylloon/mobidl/MainActivity.kt b/app/src/main/java/com/mylloon/mobidl/MainActivity.kt index a861ec6..de405a2 100644 --- a/app/src/main/java/com/mylloon/mobidl/MainActivity.kt +++ b/app/src/main/java/com/mylloon/mobidl/MainActivity.kt @@ -27,6 +27,8 @@ import com.google.gson.Gson import com.google.gson.reflect.TypeToken import kotlinx.coroutines.* import java.util.* +import android.text.method.ScrollingMovementMethod +import android.util.DisplayMetrics class MainActivity : AppCompatActivity() { @@ -409,16 +411,28 @@ class MainActivity : AppCompatActivity() { @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) { val infoApp: MutableMap - val links: MutableMap> + var links: MutableMap> = mutableMapOf() + var errorHappen = false runBlocking { infoApp = Scraper().parseInfos(link) - links = Scraper().parseDownloadLinks(infoApp["downloadLinks"]!!) + try { + 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) : RecyclerView.Adapter() { @@ -456,16 +470,22 @@ class MainActivity : AppCompatActivity() { } } } - findViewById(R.id.textViewAppName).text = appMobilismInfos!!["title"] + val title = findViewById(R.id.textViewAppName) + title.text = appMobilismInfos!!["title"] + title.setOnClickListener { startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://forum.mobilism.org$link"))) } findViewById(R.id.textViewAppAuthor).text = appMobilismInfos!!["author"] findViewById(R.id.textViewAppDate).text = appMobilismInfos!!["date"] - findViewById(R.id.textViewAppChangelogs).text = infoApp["changelogs"] + val changelogs = findViewById(R.id.textViewAppChangelogs) + changelogs.text = infoApp["changelogs"] + changelogs.movementMethod = ScrollingMovementMethod() val listDownloads = mutableListOf() + val recyclerViewAppDownloads: RecyclerView = + findViewById(R.id.recyclerViewAppDownloads) // get recyclerview + recyclerViewAppDownloads.layoutManager = LinearLayoutManager(this) + val displayMetrics = DisplayMetrics() + recyclerViewAppDownloads.layoutParams.height = displayMetrics.heightPixels / 3 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}" } diff --git a/app/src/main/java/com/mylloon/mobidl/Scraper.kt b/app/src/main/java/com/mylloon/mobidl/Scraper.kt index f8f4565..efc82f6 100644 --- a/app/src/main/java/com/mylloon/mobidl/Scraper.kt +++ b/app/src/main/java/com/mylloon/mobidl/Scraper.kt @@ -196,7 +196,7 @@ class Scraper( "No changelog found." } elements["downloadLinks"] = try { - htmlPage = htmlPage.replace(Regex("Download Instructions:(.*?)?
(.*?)?
"), "Download Instructions:
?
(.*|[\s\S]*)

Trouble downloading|""").findAll( diff --git a/app/src/main/res/layout/activity_app_infos.xml b/app/src/main/res/layout/activity_app_infos.xml index ebf18e9..7d479c3 100644 --- a/app/src/main/res/layout/activity_app_infos.xml +++ b/app/src/main/res/layout/activity_app_infos.xml @@ -57,10 +57,11 @@ + app:layout_constraintVertical_bias="0.036" /> \ No newline at end of file diff --git a/app/src/main/res/values-fr-rFR/strings.xml b/app/src/main/res/values-fr-rFR/strings.xml index c9d8976..c26345c 100644 --- a/app/src/main/res/values-fr-rFR/strings.xml +++ b/app/src/main/res/values-fr-rFR/strings.xml @@ -31,4 +31,5 @@ Aucune URL n\'a été trouvé pour ce post Changements Téléchargements + Aucun lien trouvé \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fe23a52..571171d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -40,4 +40,5 @@ Changelogs Downloads + No link found \ No newline at end of file