OnboardingFragment: Add new app links fragment

Request users Android S and above to enable play.google.com as a supported link
manually

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2023-08-21 15:25:36 +05:30
parent 004c3dd65c
commit e02347ec85
5 changed files with 185 additions and 7 deletions

View File

@@ -0,0 +1,86 @@
package com.aurora.store.view.ui.onboarding
import android.content.Intent
import android.content.pm.verify.domain.DomainVerificationManager
import android.content.pm.verify.domain.DomainVerificationUserState
import android.net.Uri
import android.os.Bundle
import android.provider.Settings.ACTION_APP_OPEN_BY_DEFAULT_SETTINGS
import android.view.View
import androidx.activity.result.contract.ActivityResultContracts
import androidx.fragment.app.Fragment
import com.aurora.extensions.isSAndAbove
import com.aurora.extensions.toast
import com.aurora.store.R
import com.aurora.store.databinding.FragmentAppLinksBinding
class AppLinksFragment : Fragment(R.layout.fragment_app_links) {
private var _binding: FragmentAppLinksBinding? = null
private val binding: FragmentAppLinksBinding
get() = _binding!!
private val playStoreDomain = "play.google.com"
private val startForResult =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
if (isSAndAbove() && playStoreDomainVerified()) {
toast(R.string.app_link_enabled)
}
updateButtonState()
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
_binding = FragmentAppLinksBinding.bind(view)
updateButtonState()
if (isSAndAbove()) {
binding.btnAction.setOnClickListener {
val intent = Intent(
ACTION_APP_OPEN_BY_DEFAULT_SETTINGS,
Uri.parse("package:${view.context.packageName}")
)
startForResult.launch(intent)
}
}
}
override fun onDestroyView() {
_binding = null
super.onDestroyView()
}
private fun updateButtonState() {
if (isSAndAbove()) {
if (playStoreDomainVerified()) {
binding.btnAction.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 {
return if (isSAndAbove()) {
val domainVerificationManager = requireContext().getSystemService(
DomainVerificationManager::class.java
)
val userState = domainVerificationManager.getDomainVerificationUserState(
requireContext().packageName
)
val playStoreDomain = userState?.hostToStateMap?.filterKeys { it == playStoreDomain }
playStoreDomain?.values?.first() == DomainVerificationUserState.DOMAIN_STATE_SELECTED
} else {
true
}
}
}

View File

@@ -117,8 +117,8 @@ class OnboardingFragment : Fragment(R.layout.fragment_onboarding) {
fun refreshButtonState() {
binding.btnBackward.isEnabled = lastPosition != 0
binding.btnForward.isEnabled = lastPosition != 4
if (lastPosition == 4) {
binding.btnForward.isEnabled = lastPosition != 5
if (lastPosition == 5) {
binding.btnForward.text = getString(R.string.action_finish)
binding.btnForward.isEnabled = true
binding.btnForward.setOnClickListener {
@@ -175,13 +175,14 @@ class OnboardingFragment : Fragment(R.layout.fragment_onboarding) {
1 -> return InstallerFragment()
2 -> return ThemeFragment()
3 -> return AccentFragment()
4 -> return PermissionsFragment()
4 -> return AppLinksFragment()
5 -> return PermissionsFragment()
}
return Fragment()
}
override fun getItemCount(): Int {
return 5
return 6
}
}
}

View File

@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".view.ui.onboarding.AppLinksFragment">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/appCompatTextView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_small"
android:includeFontPadding="true"
android:paddingStart="@dimen/padding_normal"
android:paddingEnd="@dimen/padding_normal"
android:text="@string/app_links_title"
android:textAlignment="textStart"
android:textColor="?colorAccent"
android:textSize="42sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/appCompatTextView"
style="@style/AuroraTextStyle.Subtitle.Alt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="@dimen/margin_small"
android:paddingStart="@dimen/padding_normal"
android:paddingEnd="@dimen/padding_normal"
android:text="@string/app_links_desc"
android:textAlignment="textStart"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/appCompatTextView2" />
<RelativeLayout
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/appCompatTextView">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/line1"
style="@style/AuroraTextStyle.Subtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toStartOf="@id/btn_action"
android:text="@string/app_link_play_store"
android:textSize="18sp"
android:textStyle="bold" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/line2"
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_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: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

@@ -57,6 +57,6 @@
android:padding="@dimen/padding_normal"
android:scrollbars="none"
app:itemSpacing="@dimen/margin_small"
tools:listitem="@layout/view_installer" />
tools:listitem="@layout/view_permission" />
</LinearLayout>
</LinearLayout>

View File

@@ -18,7 +18,8 @@
~ You should have received a copy of the GNU General Public License
~ along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
~
--><resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="about_bhim">"BHIM - UPI"</string>
<string name="about_bhim_summary">"Donate via UPI"</string>
<string name="about_bitcoin_bch">"Bitcoin Cash"</string>
@@ -371,4 +372,11 @@
<string name="app_language">App Language</string>
<string name="pref_ui_layout">Layout</string>
<string name="pref_ui_layout_tab">Select default tab</string>
<string name="app_links_title">App Links</string>
<string name="app_links_desc">Aurora store can open supported links</string>
<string name="action_enable">Enable</string>
<string name="action_enabled">Enabled</string>
<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>