AppLinksFragment: Bring back market.android.com support

Apparently tons of applications still use the outdated way to open the store

Ref:
- https://developer.android.com/distribute/marketing-tools/linking-to-google-play
- https://www.androidauthority.com/android-market-google-play-different-787082/

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2023-09-18 01:45:54 +05:30
parent 53b50ec512
commit 29dc3692d2
5 changed files with 106 additions and 28 deletions

View File

@@ -20,10 +20,17 @@ class AppLinksFragment : Fragment(R.layout.fragment_app_links) {
private val binding get() = _binding!!
private val playStoreDomain = "play.google.com"
private val marketDomain = "market.android.com"
// AppLink buttons
private var buttons = mapOf(
playStoreDomain to binding.playStoreButton,
marketDomain to binding.marketButton
)
private val startForResult =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
if (isSAndAbove() && playStoreDomainVerified()) {
if (isSAndAbove() && buttons.keys.any { domainVerified(it) }) {
toast(R.string.app_link_enabled)
}
updateButtonState()
@@ -35,38 +42,45 @@ class AppLinksFragment : Fragment(R.layout.fragment_app_links) {
updateButtonState()
if (isSAndAbove()) {
binding.btnAction.setOnClickListener {
val intent = Intent(
ACTION_APP_OPEN_BY_DEFAULT_SETTINGS,
Uri.parse("package:${view.context.packageName}")
)
startForResult.launch(intent)
buttons.values.forEach {
it.setOnClickListener {
val intent = Intent(
ACTION_APP_OPEN_BY_DEFAULT_SETTINGS,
Uri.parse("package:${view.context.packageName}")
)
startForResult.launch(intent)
}
}
}
}
override fun onDestroyView() {
buttons = emptyMap()
_binding = null
super.onDestroyView()
}
private fun updateButtonState() {
if (isSAndAbove()) {
if (playStoreDomainVerified()) {
binding.btnAction.apply {
buttons.forEach { (domain, button) ->
if (domainVerified(domain)) {
button.apply {
text = getString(R.string.action_enabled)
isEnabled = false
}
}
}
} else {
buttons.forEach { (_, button) ->
button.apply {
text = getString(R.string.action_enabled)
isEnabled = false
}
}
} else {
binding.btnAction.apply {
text = getString(R.string.action_enabled)
isEnabled = false
}
}
}
private fun playStoreDomainVerified(): Boolean {
private fun domainVerified(domain: String): Boolean {
return if (isSAndAbove()) {
val domainVerificationManager = requireContext().getSystemService(
DomainVerificationManager::class.java
@@ -75,8 +89,8 @@ class AppLinksFragment : Fragment(R.layout.fragment_app_links) {
requireContext().packageName
)
val playStoreDomain = userState?.hostToStateMap?.filterKeys { it == playStoreDomain }
playStoreDomain?.values?.first() == DomainVerificationUserState.DOMAIN_STATE_SELECTED
val domainMap = userState?.hostToStateMap?.filterKeys { it == domain }
domainMap?.values?.first() == DomainVerificationUserState.DOMAIN_STATE_SELECTED
} else {
true
}

View File

@@ -90,7 +90,7 @@ class SplashFragment : BaseFragment(R.layout.fragment_splash) {
}
AuthState.Valid -> {
val packageName = requireArguments().getString("packageName") ?: ""
val packageName = getPackageName()
if (packageName.isBlank()) {
navigateToDefaultTab()
} else {
@@ -110,7 +110,7 @@ class SplashFragment : BaseFragment(R.layout.fragment_splash) {
}
AuthState.SignedIn -> {
val packageName = requireArguments().getString("packageName") ?: ""
val packageName = getPackageName()
if (packageName.isBlank()) {
navigateToDefaultTab()
} else {
@@ -216,4 +216,13 @@ class SplashFragment : BaseFragment(R.layout.fragment_splash) {
}
findNavController().navigate(directions)
}
private fun getPackageName(): String {
// Navigation component cannot handle market scheme as its missing a valid host
return if (activity?.intent != null && activity?.intent?.scheme == "market") {
requireActivity().intent.data!!.getQueryParameter("id") ?: ""
} else {
requireArguments().getString("packageName") ?: ""
}
}
}

View File

@@ -37,6 +37,7 @@
app:layout_constraintTop_toBottomOf="@+id/appCompatTextView2" />
<RelativeLayout
android:id="@+id/playStoreLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/margin_normal"
@@ -48,30 +49,30 @@
app:layout_constraintTop_toBottomOf="@+id/appCompatTextView">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/line1"
android:id="@+id/playStoreTitle"
style="@style/AuroraTextStyle.Subtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toStartOf="@id/btn_action"
android:layout_toStartOf="@id/playStoreButton"
android:text="@string/app_link_play_store"
android:textSize="18sp"
android:textStyle="bold" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/line2"
android:id="@+id/playStoreDesc"
style="@style/AuroraTextStyle.Line1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/line1"
android:layout_alignStart="@id/line1"
android:layout_alignEnd="@id/line1"
android:layout_below="@+id/playStoreTitle"
android:layout_alignStart="@id/playStoreTitle"
android:layout_alignEnd="@id/playStoreTitle"
android:layout_marginTop="@dimen/margin_xxsmall"
android:maxLines="5"
android:text="@string/google_play_store_desc" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_action"
style="@style/Widget.MaterialComponents.Button.TextButton.Dialog.Flush"
android:id="@+id/playStoreButton"
style="@style/Widget.Material3.Button.TextButton.Dialog.Flush"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
@@ -80,4 +81,48 @@
android:text="@string/action_enable" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/marketLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/margin_normal"
android:layout_marginVertical="@dimen/margin_large"
android:background="@drawable/bg_outlined_padded"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/playStoreLayout">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/marketTitle"
style="@style/AuroraTextStyle.Subtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toStartOf="@id/marketButton"
android:text="@string/app_link_android_market"
android:textSize="18sp"
android:textStyle="bold" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/marketDesc"
style="@style/AuroraTextStyle.Line1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/marketTitle"
android:layout_alignStart="@id/marketTitle"
android:layout_alignEnd="@id/marketTitle"
android:layout_marginTop="@dimen/margin_xxsmall"
android:maxLines="5"
android:text="@string/android_market_desc" />
<com.google.android.material.button.MaterialButton
android:id="@+id/marketButton"
style="@style/Widget.Material3.Button.TextButton.Dialog.Flush"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginStart="@dimen/margin_small"
android:text="@string/action_enable" />
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -315,6 +315,14 @@
android:name="packageName"
android:defaultValue=""
app:argType="string" />
<!-- Android Market (deprecated) -->
<deepLink
app:action="android.intent.action.VIEW"
app:uri="market:///details?id={packageName}" />
<deepLink
app:action="android.intent.action.VIEW"
app:uri="market.android.com/details?id={packageName}" />
<!-- Google Play (formerly Android Market) -->
<deepLink
app:action="android.intent.action.VIEW"
app:uri="play.google.com/store/apps/details?id={packageName}" />

View File

@@ -378,4 +378,6 @@
<string name="app_link_enabled">App link enabled!</string>
<string name="app_link_play_store" translatable="false">play.google.com</string>
<string name="google_play_store_desc">Google Play, also known as the Google Play Store and formerly Android Market.</string>
</resources>
<string name="app_link_android_market" translatable="false">market.android.com</string>
<string name="android_market_desc">Android Market was an online store offering software applications designed for Android devices, retired in 2017.</string>
</resources>