Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update compileSdkVersion to 33 #17842

Closed
wants to merge 14 commits into from
Prev Previous commit
Next Next commit
Update deprecated onBackPressed usage
  • Loading branch information
irfano committed Jan 28, 2023
commit 9446c7fc4850e88dd72647ab639d39090ff03bc4
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.wordpress.android.ui

import android.os.Bundle
import android.view.MenuItem
import androidx.activity.addCallback
import org.wordpress.android.R
import org.wordpress.android.analytics.AnalyticsTracker.Stat.INSTALL_JETPACK_CANCELLED
import org.wordpress.android.databinding.JetpackRemoteInstallActivityBinding
Expand All @@ -21,21 +22,20 @@ class JetpackRemoteInstallActivity : LocaleAwareActivity() {
it.setDisplayHomeAsUpEnabled(true)
it.setTitle(R.string.jetpack)
}

onBackPressedDispatcher.addCallback {
trackWithSource(
INSTALL_JETPACK_CANCELLED,
intent.getSerializableExtra(TRACKING_SOURCE_KEY) as JetpackConnectionSource
)
}
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
onBackPressedDispatcher.onBackPressed()
return true
}
return super.onOptionsItemSelected(item)
}

override fun onBackPressed() {
trackWithSource(
INSTALL_JETPACK_CANCELLED,
intent.getSerializableExtra(TRACKING_SOURCE_KEY) as JetpackConnectionSource
)
super.onBackPressed()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ActivityLogDetailActivity : LocaleAwareActivity() {

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
onBackPressedDispatcher.onBackPressed()
return true
}
return super.onOptionsItemSelected(item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class ActivityLogListActivity : LocaleAwareActivity(), ScrollableViewInitialized

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
onBackPressedDispatcher.onBackPressed()
return true
}
return super.onOptionsItemSelected(item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ class BloggingPromptsListActivity : LocaleAwareActivity() {
setContent {
AppTheme {
val uiState by viewModel.uiStateFlow.collectAsState()
BloggingPromptsListScreen(uiState, ::onBackPressed, viewModel::onPromptListItemClicked)
BloggingPromptsListScreen(
uiState,
{ onBackPressedDispatcher.onBackPressed() },
viewModel::onPromptListItemClicked
)
}
}
observeActions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class UnifiedCommentsActivity : LocaleAwareActivity() {

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
onBackPressedDispatcher.onBackPressed()
return true
}
return super.onOptionsItemSelected(item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DebugSettingsActivity : LocaleAwareActivity() {

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
onBackPressedDispatcher.onBackPressed()
return true
}
return super.onOptionsItemSelected(item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DebugCookiesActivity : LocaleAwareActivity() {

override fun onOptionsItemSelected(item: MenuItem) = when (item.itemId) {
android.R.id.home -> {
onBackPressed()
onBackPressedDispatcher.onBackPressed()
true
}
else -> super.onOptionsItemSelected(item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class DomainRegistrationActivity : LocaleAwareActivity(), ScrollableViewInitiali

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
onBackPressedDispatcher.onBackPressed()
return true
}
return super.onOptionsItemSelected(item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DomainsDashboardActivity : LocaleAwareActivity() {

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
onBackPressedDispatcher.onBackPressed()
return true
}
return super.onOptionsItemSelected(item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class EngagedPeopleListActivity : LocaleAwareActivity() {

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
onBackPressedDispatcher.onBackPressed()
return true
}
return super.onOptionsItemSelected(item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.activity.addCallback
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.fragment.app.DialogFragment
Expand Down Expand Up @@ -32,9 +33,12 @@ abstract class FeatureIntroductionDialogFragment : DialogFragment() {

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog =
object : Dialog(requireContext(), theme) {
override fun onBackPressed() {
viewModel.onBackButtonClick()
super.onBackPressed()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner) {
viewModel.onBackButtonClick()
}
}
}.apply {
setStatusBarAsSurfaceColor()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.wordpress.android.ui.history

import android.os.Bundle
import androidx.activity.addCallback
import org.wordpress.android.R
import org.wordpress.android.analytics.AnalyticsTracker
import org.wordpress.android.analytics.AnalyticsTracker.Stat
Expand All @@ -21,6 +22,8 @@ class HistoryDetailActivity : LocaleAwareActivity() {
}
supportActionBar?.setDisplayHomeAsUpEnabled(true)

onBackPressedDispatcher.addCallback(this) { AnalyticsTracker.track(Stat.REVISIONS_DETAIL_CANCELLED) }

val extras = requireNotNull(intent.extras)
val revision = extras.getParcelable<Revision>(HistoryDetailContainerFragment.EXTRA_CURRENT_REVISION)
val previousRevisionsIds =
Expand All @@ -44,9 +47,4 @@ class HistoryDetailActivity : LocaleAwareActivity() {
finish()
return true
}

override fun onBackPressed() {
AnalyticsTracker.track(Stat.REVISIONS_DETAIL_CANCELLED)
super.onBackPressed()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class BackupDownloadActivity : LocaleAwareActivity() {

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == id.home) {
onBackPressed()
onBackPressedDispatcher.onBackPressed()
return true
}
return super.onOptionsItemSelected(item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class RestoreActivity : LocaleAwareActivity() {

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
onBackPressedDispatcher.onBackPressed()
return true
}
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class ScanActivity : AppCompatActivity(), ScrollableViewInitializedListener {

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
onBackPressedDispatcher.onBackPressed()
return true
} else if (item.itemId == R.id.menu_scan_history) {
// todo malinjir is it worth introducing a vm?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ThreatDetailsActivity : AppCompatActivity() {

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
onBackPressedDispatcher.onBackPressed()
return true
}
return super.onOptionsItemSelected(item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class ScanHistoryFragment : Fragment(R.layout.scan_history_fragment), MenuProvid

override fun onMenuItemSelected(menuItem: MenuItem) = when (menuItem.itemId) {
android.R.id.home -> {
requireActivity().onBackPressed()
requireActivity().onBackPressedDispatcher.onBackPressed()
true
}
else -> false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class MeActivity : LocaleAwareActivity() {

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
onBackPressedDispatcher.onBackPressed()
return true
}
return super.onOptionsItemSelected(item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class PageParentFragment : Fragment(R.layout.page_parent_fragment), MenuProvider

override fun onMenuItemSelected(menuItem: MenuItem) = when (menuItem.itemId) {
android.R.id.home -> {
activity?.onBackPressed()
activity?.onBackPressedDispatcher?.onBackPressed()
true
}
R.id.save_parent -> {
Expand All @@ -87,7 +87,7 @@ class PageParentFragment : Fragment(R.layout.page_parent_fragment), MenuProvider
result.putExtra(EXTRA_PAGE_REMOTE_ID_KEY, pageId)
result.putExtra(EXTRA_PAGE_PARENT_ID_KEY, viewModel.currentParent.id)
activity?.setResult(Activity.RESULT_OK, result)
activity?.onBackPressed()
activity?.onBackPressedDispatcher?.onBackPressed()
}

private fun PageParentFragmentBinding.initializeSearchView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class PagesActivity : LocaleAwareActivity(),

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
onBackPressedDispatcher.onBackPressed()
return true
}
return super.onOptionsItemSelected(item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CategoryDetailActivity : LocaleAwareActivity() {

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
onBackPressedDispatcher.onBackPressed()
return true
}
return super.onOptionsItemSelected(item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CategoriesListActivity : LocaleAwareActivity() {

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
onBackPressedDispatcher.onBackPressed()
return true
}
return super.onOptionsItemSelected(item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class NotificationsSettingsActivity : LocaleAwareActivity(), MainSwitchToolbarLi
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
android.R.id.home -> {
onBackPressed()
onBackPressedDispatcher.onBackPressed()
return true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ReaderInterestsActivity : LocaleAwareActivity() {

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
onBackPressedDispatcher.onBackPressed()
return true
}
return super.onOptionsItemSelected(item)
Expand Down
Loading