Skip to content

Commit

Permalink
MBL-1673 [Android 15] Update Views to be compatible with edge to edge…
Browse files Browse the repository at this point in the history
… enforcement (#2131)

* Manage edge to edege

- Created utility to manage edge to edge on different screens
- fixed composable screens
- fixed other screens with the utility

* Manage edge to edge in all the screens

- Manage edge to edge behavior for all the screens
- modify solution

* Fix last screens

* Fix ktlint tests

* fix KTLint
  • Loading branch information
jlplks authored Oct 3, 2024
1 parent c28b488 commit 38c93ea
Show file tree
Hide file tree
Showing 61 changed files with 1,735 additions and 1,128 deletions.
88 changes: 70 additions & 18 deletions app/src/main/java/com/kickstarter/ui/activities/AccountActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.kickstarter.libs.utils.extensions.getEnvironment
import com.kickstarter.libs.utils.extensions.getPaymentMethodsIntent
import com.kickstarter.ui.extensions.setUpConnectivityStatusCheck
import com.kickstarter.ui.extensions.showSnackbar
import com.kickstarter.utils.WindowInsetsUtil
import com.kickstarter.viewmodels.AccountViewModel
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
Expand Down Expand Up @@ -59,7 +60,6 @@ class AccountActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

disposables = CompositeDisposable()

val env = this.getEnvironment()?.let { env ->
Expand All @@ -68,7 +68,10 @@ class AccountActivity : AppCompatActivity() {
}

binding = ActivityAccountBinding.inflate(layoutInflater)

WindowInsetsUtil.manageEdgeToEdge(
window,
binding.root,
)
setContentView(binding.root)

setUpConnectivityStatusCheck(lifecycle)
Expand All @@ -84,7 +87,11 @@ class AccountActivity : AppCompatActivity() {
this.viewModel.outputs.email()
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
binding.createPasswordTextView.text = this.ksString.format(getString(R.string.Youre_connected_via_Facebook_email_Create_a_password_for_this_account), "email", it)
binding.createPasswordTextView.text = this.ksString.format(
getString(R.string.Youre_connected_via_Facebook_email_Create_a_password_for_this_account),
"email",
it
)
}
.addToDisposable(disposables)

Expand Down Expand Up @@ -113,14 +120,53 @@ class AccountActivity : AppCompatActivity() {

this.viewModel.outputs.success()
.observeOn(AndroidSchedulers.mainThread())
.subscribe { showSnackbar(binding.accountContainer, R.string.Got_it_your_changes_have_been_saved) }
.subscribe {
showSnackbar(
binding.accountContainer,
R.string.Got_it_your_changes_have_been_saved
)
}
.addToDisposable(disposables)

binding.createPasswordRow.setOnClickListener { startActivity(Intent(this, CreatePasswordActivity::class.java)) }
binding.changeEmailRow.setOnClickListener { startActivity(Intent(this, ChangeEmailActivity::class.java)) }
binding.changePasswordRow.setOnClickListener { startActivity(Intent(this, ChangePasswordActivity::class.java)) }
binding.paymentMethodsRow.setOnClickListener { startActivity(Intent().getPaymentMethodsIntent(this)) }
binding.privacyRow.setOnClickListener { startActivity(Intent(this, PrivacyActivity::class.java)) }
binding.createPasswordRow.setOnClickListener {
startActivity(
Intent(
this,
CreatePasswordActivity::class.java
)
)
}
binding.changeEmailRow.setOnClickListener {
startActivity(
Intent(
this,
ChangeEmailActivity::class.java
)
)
}
binding.changePasswordRow.setOnClickListener {
startActivity(
Intent(
this,
ChangePasswordActivity::class.java
)
)
}
binding.paymentMethodsRow.setOnClickListener {
startActivity(
Intent().getPaymentMethodsIntent(
this
)
)
}
binding.privacyRow.setOnClickListener {
startActivity(
Intent(
this,
PrivacyActivity::class.java
)
)
}
}

override fun onDestroy() {
Expand Down Expand Up @@ -186,17 +232,23 @@ class AccountActivity : AppCompatActivity() {
arrayAdapter.setDropDownViewResource(R.layout.item_spinner_dropdown)
binding.currencySpinner.adapter = arrayAdapter

binding.currencySpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onNothingSelected(parent: AdapterView<*>?) {}

override fun onItemSelected(parent: AdapterView<*>?, view: View?, postion: Int, id: Long) {
currentCurrencySelection?.let {
if (supportedCurrencies.indexOf(it) != postion) {
newCurrencySelection = supportedCurrencies[postion]
lazyFollowingOptOutConfirmationDialog().show()
binding.currencySpinner.onItemSelectedListener =
object : AdapterView.OnItemSelectedListener {
override fun onNothingSelected(parent: AdapterView<*>?) {}

override fun onItemSelected(
parent: AdapterView<*>?,
view: View?,
postion: Int,
id: Long
) {
currentCurrencySelection?.let {
if (supportedCurrencies.indexOf(it) != postion) {
newCurrencySelection = supportedCurrencies[postion]
lazyFollowingOptOutConfirmationDialog().show()
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.kickstarter.ui.data.LoginReason
import com.kickstarter.ui.extensions.finishWithAnimation
import com.kickstarter.ui.extensions.setUpConnectivityStatusCheck
import com.kickstarter.ui.extensions.startActivityWithTransition
import com.kickstarter.utils.WindowInsetsUtil
import com.kickstarter.viewmodels.ActivityFeedViewModel.ActivityFeedViewModel
import com.kickstarter.viewmodels.ActivityFeedViewModel.Factory
import io.reactivex.android.schedulers.AndroidSchedulers
Expand All @@ -36,7 +37,6 @@ class ActivityFeedActivity : AppCompatActivity() {
private var currentUser: CurrentUserTypeV2? = null
private var recyclerViewPaginator: RecyclerViewPaginatorV2? = null
private lateinit var binding: ActivityFeedLayoutBinding

private lateinit var viewModelFactory: Factory
private val viewModel: ActivityFeedViewModel by viewModels {
viewModelFactory
Expand All @@ -47,7 +47,10 @@ class ActivityFeedActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityFeedLayoutBinding.inflate(layoutInflater)

WindowInsetsUtil.manageEdgeToEdge(
window,
binding.root,
)
setContentView(binding.root)

setUpConnectivityStatusCheck(lifecycle)
Expand All @@ -65,7 +68,11 @@ class ActivityFeedActivity : AppCompatActivity() {

binding.recyclerView.layoutManager = LinearLayoutManager(this@ActivityFeedActivity)

recyclerViewPaginator = RecyclerViewPaginatorV2(binding.recyclerView, { viewModel.inputs.nextPage() }, viewModel.outputs.isFetchingActivities())
recyclerViewPaginator = RecyclerViewPaginatorV2(
binding.recyclerView,
{ viewModel.inputs.nextPage() },
viewModel.outputs.isFetchingActivities()
)

binding.activityFeedSwipeRefreshLayout.setOnRefreshListener {
viewModel.outputs.isFetchingActivities()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.kickstarter.libs.utils.extensions.getEnvironment
import com.kickstarter.ui.extensions.onChange
import com.kickstarter.ui.extensions.setUpConnectivityStatusCheck
import com.kickstarter.ui.extensions.showSnackbar
import com.kickstarter.utils.WindowInsetsUtil
import com.kickstarter.viewmodels.ChangeEmailViewModel
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
Expand All @@ -41,7 +42,10 @@ class ChangeEmailActivity : AppCompatActivity() {
}

binding = ActivityChangeEmailBinding.inflate(layoutInflater)

WindowInsetsUtil.manageEdgeToEdge(
window,
binding.root,
)
setContentView(binding.root)
setSupportActionBar(binding.changeEmailActivityToolbar.changeEmailToolbar)

Expand All @@ -62,7 +66,10 @@ class ChangeEmailActivity : AppCompatActivity() {
this.viewModel.outputs.emailErrorIsVisible()
.observeOn(AndroidSchedulers.mainThread())
.filter { it }
.subscribe { binding.newEmailContainer.error = getString(R.string.Email_must_be_a_valid_email_address) }
.subscribe {
binding.newEmailContainer.error =
getString(R.string.Email_must_be_a_valid_email_address)
}
.addToDisposable(disposables)

this.viewModel.outputs.emailErrorIsVisible()
Expand Down Expand Up @@ -124,7 +131,14 @@ class ChangeEmailActivity : AppCompatActivity() {

this.viewModel.outputs.warningTextColor()
.observeOn(AndroidSchedulers.mainThread())
.subscribe { binding.emailWarningTextView.setTextColor(ContextCompat.getColor(this@ChangeEmailActivity, it)) }
.subscribe {
binding.emailWarningTextView.setTextColor(
ContextCompat.getColor(
this@ChangeEmailActivity,
it
)
)
}
.addToDisposable(disposables)

this.viewModel.outputs.verificationEmailButtonText()
Expand All @@ -142,6 +156,7 @@ class ChangeEmailActivity : AppCompatActivity() {
imm.hideSoftInputFromWindow(binding.newEmail.windowToken, 0)
true
}

else -> super.onOptionsItemSelected(item)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.kickstarter.ui.extensions.finishWithAnimation
import com.kickstarter.ui.extensions.hideKeyboard
import com.kickstarter.ui.extensions.setUpConnectivityStatusCheck
import com.kickstarter.ui.views.OnCommentComposerViewClickedListener
import com.kickstarter.utils.WindowInsetsUtil
import com.kickstarter.viewmodels.CommentsViewModel.CommentsViewModel
import com.kickstarter.viewmodels.CommentsViewModel.Factory
import io.reactivex.disposables.CompositeDisposable
Expand All @@ -55,7 +56,12 @@ class CommentsActivity :
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityCommentsLayoutBinding.inflate(layoutInflater)
WindowInsetsUtil.manageEdgeToEdge(
window,
binding.root
)
val view: View = binding.root

setContentView(view)

setUpConnectivityStatusCheck(lifecycle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.kickstarter.libs.utils.extensions.getEnvironment
import com.kickstarter.models.Project
import com.kickstarter.ui.IntentKey
import com.kickstarter.ui.extensions.finishWithAnimation
import com.kickstarter.utils.WindowInsetsUtil
import com.kickstarter.viewmodels.CreatorBioViewModel.CreatorBioViewModel
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
Expand All @@ -28,7 +29,10 @@ class CreatorBioActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityCreatorBioBinding.inflate(layoutInflater)

WindowInsetsUtil.manageEdgeToEdge(
window,
binding.root
)
this.getEnvironment()?.let { env ->
viewModelFactory = CreatorBioViewModel.Factory(env, intent = intent)
env
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.kickstarter.ui.extensions.showSuccessSnackBar
import com.kickstarter.ui.fragments.ConsentManagementDialogFragment
import com.kickstarter.ui.fragments.DiscoveryFragment
import com.kickstarter.ui.fragments.DiscoveryFragment.Companion.newInstance
import com.kickstarter.utils.WindowInsetsUtil
import com.kickstarter.viewmodels.DiscoveryViewModel
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
Expand All @@ -54,14 +55,22 @@ class DiscoveryActivity : BaseActivity<DiscoveryViewModel.ViewModel>() {

super.onCreate(savedInstanceState)
binding = DiscoveryLayoutBinding.inflate(layoutInflater)
WindowInsetsUtil.manageEdgeToEdge(
window,
binding.root
)
setContentView(binding.root)
environment()

// TODO: Replace with compose implementation
val nightModeFlags = this.resources?.configuration?.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK)
val nightModeFlags =
this.resources?.configuration?.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK)
viewModel.setDarkTheme(
when (nightModeFlags) {
Configuration.UI_MODE_NIGHT_YES -> { true }
Configuration.UI_MODE_NIGHT_YES -> {
true
}

else -> false
}
)
Expand All @@ -70,7 +79,8 @@ class DiscoveryActivity : BaseActivity<DiscoveryViewModel.ViewModel>() {
activateFeatureFlags(environment())
}

val requestPermissionLauncher = registerForActivityResult(ActivityResultContracts.RequestPermission()) {}
val requestPermissionLauncher =
registerForActivityResult(ActivityResultContracts.RequestPermission()) {}

internalTools = environment().internalTools()

Expand Down Expand Up @@ -137,7 +147,10 @@ class DiscoveryActivity : BaseActivity<DiscoveryViewModel.ViewModel>() {
.subscribe {
consentManagementDialogFragment = ConsentManagementDialogFragment()
consentManagementDialogFragment.isCancelable = false
consentManagementDialogFragment.show(supportFragmentManager, "consentManagementDialogFragment")
consentManagementDialogFragment.show(
supportFragmentManager,
"consentManagementDialogFragment"
)
}

viewModel.outputs.clearPages()
Expand Down Expand Up @@ -217,12 +230,22 @@ class DiscoveryActivity : BaseActivity<DiscoveryViewModel.ViewModel>() {
viewModel.outputs.showSuccessMessage()
.compose(bindToLifecycle())
.compose(Transformers.observeForUI())
.subscribe { this@DiscoveryActivity.showSuccessSnackBar(binding.discoveryAnchorView, it) }
.subscribe {
this@DiscoveryActivity.showSuccessSnackBar(
binding.discoveryAnchorView,
it
)
}

viewModel.outputs.showErrorMessage()
.compose(bindToLifecycle())
.compose(Transformers.observeForUI())
.subscribe { this@DiscoveryActivity.showErrorSnackBar(binding.discoveryAnchorView, it ?: "") }
.subscribe {
this@DiscoveryActivity.showErrorSnackBar(
binding.discoveryAnchorView,
it ?: ""
)
}
}

private fun activateFeatureFlags(environment: Environment) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.kickstarter.models.User
import com.kickstarter.ui.extensions.loadCircleImage
import com.kickstarter.ui.extensions.setUpConnectivityStatusCheck
import com.kickstarter.ui.extensions.showSnackbar
import com.kickstarter.utils.WindowInsetsUtil
import com.kickstarter.viewmodels.EditProfileViewModel
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
Expand All @@ -32,7 +33,10 @@ class EditProfileActivity : ComponentActivity() {
}

binding = ActivityEditProfileBinding.inflate(layoutInflater)

WindowInsetsUtil.manageEdgeToEdge(
window,
binding.root,
)
setContentView(binding.root)
setUpConnectivityStatusCheck(lifecycle)

Expand Down Expand Up @@ -76,6 +80,9 @@ class EditProfileActivity : ComponentActivity() {
}

private fun displayPreferences(user: User) {
SwitchCompatUtils.setCheckedWithoutAnimation(binding.privateProfileSwitch, user.showPublicProfile().isFalse())
SwitchCompatUtils.setCheckedWithoutAnimation(
binding.privateProfileSwitch,
user.showPublicProfile().isFalse()
)
}
}
Loading

0 comments on commit 38c93ea

Please sign in to comment.