Skip to content

Commit

Permalink
Merge pull request #290 from hushenghao/master
Browse files Browse the repository at this point in the history
  • Loading branch information
jahirfiquitiva committed Feb 13, 2022
2 parents 6b4c93f + 0c4c4f7 commit 143de0d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 4 additions & 0 deletions app/src/main/res/values/home_setup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,21 @@
<string-array name="home_list_titles">
<item>IconShowcase</item>
<item>An App</item>
<item>An App</item>
</string-array>
<string-array name="home_list_descriptions">
<item>It is the old version of this awesome dashboard</item>
<item>This is an app</item>
<item>This is market url</item>
</string-array>
<string-array name="home_list_icons">
<item>ic_na_launcher</item>
<item>ic_na_launcher</item>
<item>ic_na_launcher</item>
</string-array>
<string-array name="home_list_links">
<item>https://github.com/jahirfiquitiva/Blueprint</item>
<item>https://play.google.com/store/apps/details?id=com.android.settings</item>
<item>market://details?id=com.example.package</item>
</string-array>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dev.jahir.blueprint.data.viewmodels

import android.app.Application
import android.content.Intent
import android.net.Uri
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.MutableLiveData
Expand Down Expand Up @@ -63,19 +64,21 @@ class HomeViewModel(application: Application) : AndroidViewModel(application) {
titles.mapIndexed { i, s -> DefHomeItem(s, descriptions[i], icons[i], urls[i]) }
.distinctBy { it.url }
.map {
val isAnApp =
it.url.lower().startsWith(PLAY_STORE_LINK_PREFIX) ||
it.url.lower().startsWith("market://details?id=")
val isMarketUrl = it.url.lower().startsWith("market://details?id=")
val isAnApp = isMarketUrl || it.url.lower().startsWith(PLAY_STORE_LINK_PREFIX)
var isInstalled = false
var intent: Intent? = null
if (isAnApp) {
val packageName = it.url.substring(it.url.lastIndexOf("=") + 1)
try {
val packageName = it.url.substring(it.url.lastIndexOf("=") + 1)
isInstalled = context.isAppInstalled(packageName)
intent =
context.packageManager.getLaunchIntentForPackage(packageName)
} catch (e: Exception) {
}
if (intent == null && isMarketUrl) {
intent = Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$packageName"))
}
}
val openIcon = if (isAnApp)
if (isInstalled) R.drawable.ic_open_app else R.drawable.ic_download
Expand Down

0 comments on commit 143de0d

Please sign in to comment.