Skip to content

Commit fcd5ca7

Browse files
committed
Extract IAP layout setup, legal links, and product prices into LicenseContentViewBinder
1 parent 118d467 commit fcd5ca7

3 files changed

Lines changed: 42 additions & 45 deletions

File tree

presentation/src/main/java/org/cryptomator/presentation/ui/activity/LicenseCheckActivity.kt

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -87,34 +87,23 @@ class LicenseCheckActivity : BaseActivity<ActivityLicenseCheckBinding>(ActivityL
8787

8888
private fun setupIapView() {
8989
supportActionBar?.title = getString(R.string.screen_license_check_title_full_version)
90-
binding.licenseContent.licenseEntryGroup.visibility = View.GONE
91-
binding.licenseContent.btnPurchase.visibility = View.GONE
92-
binding.licenseContent.purchaseOptionsGroup.visibility = View.VISIBLE
93-
binding.licenseContent.tvRestorePurchase.visibility = View.VISIBLE
94-
binding.licenseContent.legalLinksGroup.visibility = View.VISIBLE
90+
licenseContentViewBinder.bindInitialIapLayout()
91+
licenseContentViewBinder.bindLegalLinks()
9592

9693
binding.licenseContent.btnTrial.setOnClickListener {
9794
licenseEnforcer.startTrial()
9895
updatePurchaseState()
9996
}
100-
binding.licenseContent.btnSubscription.isEnabled = false
10197
binding.licenseContent.btnSubscription.setOnClickListener {
10298
(application as CryptomatorApp).launchPurchaseFlow(WeakReference(this), ProductInfo.PRODUCT_YEARLY_SUBSCRIPTION)
10399
}
104-
binding.licenseContent.btnLifetime.isEnabled = false
105100
binding.licenseContent.btnLifetime.setOnClickListener {
106101
(application as CryptomatorApp).launchPurchaseFlow(WeakReference(this), ProductInfo.PRODUCT_FULL_VERSION)
107102
}
108103
binding.licenseContent.tvRestorePurchase.setOnClickListener {
109104
(application as CryptomatorApp).restorePurchases()
110105
Toast.makeText(this, getString(R.string.screen_license_check_restore_purchase), Toast.LENGTH_SHORT).show()
111106
}
112-
binding.licenseContent.tvTerms.setOnClickListener {
113-
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://cryptomator.org/terms/")))
114-
}
115-
binding.licenseContent.tvPrivacy.setOnClickListener {
116-
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://cryptomator.org/privacy/")))
117-
}
118107
}
119108

120109
private fun setupLicenseEntryView() {
@@ -137,14 +126,7 @@ class LicenseCheckActivity : BaseActivity<ActivityLicenseCheckBinding>(ActivityL
137126
(application as CryptomatorApp).queryProductDetails { products ->
138127
val prices = products.resolveProductPrices()
139128
runOnUiThread {
140-
if (prices.subscriptionPrice != null) {
141-
binding.licenseContent.btnSubscription.text = prices.subscriptionPrice
142-
binding.licenseContent.btnSubscription.isEnabled = true
143-
}
144-
if (prices.lifetimePrice != null) {
145-
binding.licenseContent.btnLifetime.text = prices.lifetimePrice
146-
binding.licenseContent.btnLifetime.isEnabled = true
147-
}
129+
licenseContentViewBinder.bindProductPrices(prices.subscriptionPrice, prices.lifetimePrice)
148130
}
149131
}
150132
}

presentation/src/main/java/org/cryptomator/presentation/ui/fragment/WelcomeLicenseFragment.kt

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package org.cryptomator.presentation.ui.fragment
22

3-
import android.content.Intent
4-
import android.net.Uri
53
import android.os.Handler
64
import android.os.Looper
75
import android.text.Editable
@@ -55,25 +53,13 @@ class WelcomeLicenseFragment : BaseFragment<FragmentWelcomeLicenseBinding>(Fragm
5553
}
5654

5755
private fun setupIapUi() {
58-
binding.licenseContent.licenseEntryGroup.visibility = View.GONE
59-
binding.licenseContent.btnPurchase.visibility = View.GONE
60-
binding.licenseContent.tvLicenseLink.visibility = View.GONE
61-
binding.licenseContent.purchaseOptionsGroup.visibility = View.VISIBLE
62-
binding.licenseContent.tvRestorePurchase.visibility = View.VISIBLE
63-
binding.licenseContent.legalLinksGroup.visibility = View.VISIBLE
56+
licenseContentViewBinder.bindInitialIapLayout()
57+
licenseContentViewBinder.bindLegalLinks()
6458

6559
binding.licenseContent.btnTrial.setOnClickListener { listener?.onStartTrial() }
66-
binding.licenseContent.btnSubscription.isEnabled = false
6760
binding.licenseContent.btnSubscription.setOnClickListener { listener?.onPurchaseSubscription() }
68-
binding.licenseContent.btnLifetime.isEnabled = false
6961
binding.licenseContent.btnLifetime.setOnClickListener { listener?.onPurchaseLifetime() }
7062
binding.licenseContent.tvRestorePurchase.setOnClickListener { listener?.onRestorePurchases() }
71-
binding.licenseContent.tvTerms.setOnClickListener {
72-
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://cryptomator.org/terms/")))
73-
}
74-
binding.licenseContent.tvPrivacy.setOnClickListener {
75-
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://cryptomator.org/privacy/")))
76-
}
7763
}
7864

7965
private fun setupLicenseEntryUi() {
@@ -112,14 +98,7 @@ class WelcomeLicenseFragment : BaseFragment<FragmentWelcomeLicenseBinding>(Fragm
11298

11399
fun updateProductPrices(subscriptionPrice: String, lifetimePrice: String) {
114100
if (!isAdded) return
115-
if (subscriptionPrice.isNotEmpty()) {
116-
binding.licenseContent.btnSubscription.text = subscriptionPrice
117-
binding.licenseContent.btnSubscription.isEnabled = true
118-
}
119-
if (lifetimePrice.isNotEmpty()) {
120-
binding.licenseContent.btnLifetime.text = lifetimePrice
121-
binding.licenseContent.btnLifetime.isEnabled = true
122-
}
101+
licenseContentViewBinder.bindProductPrices(subscriptionPrice, lifetimePrice)
123102
}
124103

125104
fun prefillLicense(license: String) {

presentation/src/main/java/org/cryptomator/presentation/ui/layout/LicenseContentViewBinder.kt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.cryptomator.presentation.ui.layout
22

3+
import android.content.Intent
4+
import android.net.Uri
35
import android.view.View
46
import org.cryptomator.presentation.R
57
import org.cryptomator.presentation.databinding.ViewLicenseCheckContentBinding
@@ -12,6 +14,40 @@ class LicenseContentViewBinder(
1214

1315
private val context get() = binding.root.context
1416

17+
/** Sets the initial visibility state and button defaults for IAP mode. */
18+
fun bindInitialIapLayout() {
19+
binding.licenseEntryGroup.visibility = View.GONE
20+
binding.btnPurchase.visibility = View.GONE
21+
binding.tvLicenseLink.visibility = View.GONE
22+
binding.purchaseOptionsGroup.visibility = View.VISIBLE
23+
binding.tvRestorePurchase.visibility = View.VISIBLE
24+
binding.legalLinksGroup.visibility = View.VISIBLE
25+
binding.btnSubscription.isEnabled = false
26+
binding.btnLifetime.isEnabled = false
27+
}
28+
29+
/** Sets click listeners on Terms and Privacy links. */
30+
fun bindLegalLinks() {
31+
binding.tvTerms.setOnClickListener {
32+
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://cryptomator.org/terms/")))
33+
}
34+
binding.tvPrivacy.setOnClickListener {
35+
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://cryptomator.org/privacy/")))
36+
}
37+
}
38+
39+
/** Updates subscription and lifetime button text and enabled state from resolved prices. */
40+
fun bindProductPrices(subscriptionPrice: String?, lifetimePrice: String?) {
41+
if (!subscriptionPrice.isNullOrEmpty()) {
42+
binding.btnSubscription.text = subscriptionPrice
43+
binding.btnSubscription.isEnabled = true
44+
}
45+
if (!lifetimePrice.isNullOrEmpty()) {
46+
binding.btnLifetime.text = lifetimePrice
47+
binding.btnLifetime.isEnabled = true
48+
}
49+
}
50+
1551
/** Updates purchase-related view visibility based on license state. */
1652
fun bindPurchaseState(unlocked: Boolean, hasPaidLicense: Boolean) {
1753
if (isIapFlavor) {

0 commit comments

Comments
 (0)