Skip to content

Commit

Permalink
🐛
Browse files Browse the repository at this point in the history
[Fix]
- `ActivityNotFoundException`
  • Loading branch information
rosuH committed Dec 18, 2022
1 parent 17d8d0f commit 9218918
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 32 deletions.
9 changes: 1 addition & 8 deletions app/src/main/java/me/rosuh/easywatermark/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,7 @@ class MainActivity : AppCompatActivity() {
}
val btnStore = findViewById<Button>(R.id.btn_store).apply {
setOnClickListener {
try {
startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("market://details?id=me.rosuh.easywatermark")
)
)
} catch (e: Exception) {
openLink(Uri.parse("market://details?id=me.rosuh.easywatermark")) {
Toast.makeText(this@MainActivity, R.string.store_not_found, Toast.LENGTH_SHORT)
.show()
}
Expand Down
26 changes: 6 additions & 20 deletions app/src/main/java/me/rosuh/easywatermark/ui/about/AboutActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,7 @@ class AboutActivity : AppCompatActivity() {
}
tvVersionValue.text = BuildConfig.VERSION_NAME
tvRating.setOnClickListener {
kotlin.runCatching {
startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("market://details?id=me.rosuh.easywatermark")
)
)
}
openLink(Uri.parse("market://details?id=me.rosuh.easywatermark"))
}
tvFeedBack.setOnClickListener {
openLink("https://github.com/rosuH/EasyWatermark/issues/new")
Expand All @@ -95,20 +88,10 @@ class AboutActivity : AppCompatActivity() {
}
}
tvPrivacyCn.setOnClickListener {
val browserIntent =
Intent(
Intent.ACTION_VIEW,
Uri.parse("https://github.com/rosuH/EasyWatermark/blob/master/PrivacyPolicy_zh-CN.md")
)
kotlin.runCatching { startActivity(browserIntent) }
openLink(Uri.parse("https://github.com/rosuH/EasyWatermark/blob/master/PrivacyPolicy_zh-CN.md"))
}
tvPrivacyEng.setOnClickListener {
val browserIntent =
Intent(
Intent.ACTION_VIEW,
Uri.parse("https://github.com/rosuH/EasyWatermark/blob/master/PrivacyPolicy.md")
)
kotlin.runCatching { startActivity(browserIntent) }
openLink(Uri.parse("https://github.com/rosuH/EasyWatermark/blob/master/PrivacyPolicy.md"))
}
civAvatar.setOnClickListener {
openLink("https://github.com/rosuH")
Expand Down Expand Up @@ -147,6 +130,7 @@ class AboutActivity : AppCompatActivity() {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
applyPaletteForSupportNight(it)
}

it == null -> {
binding.clContainer.children
.plus(binding.tvTitle)
Expand All @@ -165,9 +149,11 @@ class AboutActivity : AppCompatActivity() {
}
return@observe
}

Build.VERSION.SDK_INT >= Build.VERSION_CODES.M -> {
applyPaletteForSupportLightStatusIcon(it)
}

else -> {
applyPaletteForNoMatterWhoYouAre(it)
}
Expand Down
17 changes: 13 additions & 4 deletions app/src/main/java/me/rosuh/easywatermark/utils/ktx/ActivityKtx.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@ import androidx.fragment.app.*
import androidx.viewbinding.ViewBinding
import me.rosuh.easywatermark.R

fun Activity.openLink(url: String) {
val i = Intent(Intent.ACTION_VIEW)
i.data = Uri.parse(url)
startActivity(i)
fun Activity.openLink(url: String, failedCallback: (() -> Unit)? = null) {
openLink(Uri.parse(url), failedCallback)
}

fun Activity.openLink(uri: Uri, failedCallback: (() -> Unit)? = null) {
try {
val i = Intent(Intent.ACTION_VIEW)
i.data = uri
startActivity(i)
} catch (e: Exception) {
e.printStackTrace()
failedCallback?.invoke()
}
}

inline fun <reified VB : ViewBinding> Activity.inflate() = lazy {
Expand Down

0 comments on commit 9218918

Please sign in to comment.