Skip to content

Commit

Permalink
Use data object in tutorials, remove deprecated empty Activity.onBa…
Browse files Browse the repository at this point in the history
…ckPressed
  • Loading branch information
Zhuinden committed Mar 6, 2023
1 parent 6ed84f3 commit 0975890
Show file tree
Hide file tree
Showing 36 changed files with 151 additions and 219 deletions.
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,27 +110,21 @@ class MainActivity : AppCompatActivity(), SimpleStateChanger.NavigationHandler {
override fun handleOnBackPressed() {
if (!Navigator.onBackPressed(this@MainActivity)) {
this.remove()
onBackPressed() // this is the only safe way to manually invoke onBackPressed when using `OnBackPressedDispatcher`
onBackPressed() // this is the reliable way to handle back for now
this@MainActivity.onBackPressedDispatcher.addCallback(this)
}
}
}

@Deprecated("Deprecated in Java")
@Suppress("RedundantModalityModifier", "deprecation")
final override fun onBackPressed() { // you cannot use `onBackPressed()` if you use `OnBackPressedDispatcher`
super.onBackPressed()
}

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

onBackPressedDispatcher.addCallback(backPressedCallback) // this is the reliable way to handle back for now

val binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)

fragmentStateChanger = DefaultFragmentStateChanger(supportFragmentManager, R.id.container)

onBackPressedDispatcher.addCallback(backPressedCallback) // this is required for `onBackPressedDispatcher` to work correctly

Navigator.configure()
.setStateChanger(SimpleStateChanger(this))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,26 @@ class MainActivity : AppCompatActivity(), SimpleStateChanger.NavigationHandler {
override fun handleOnBackPressed() {
if (!Navigator.onBackPressed(this@MainActivity)) {
this.remove()
onBackPressed() // this is the only safe way to manually invoke onBackPressed when using onBackPressedDispatcher`
onBackPressed() // this is the reliable way to handle back for now
this@MainActivity.onBackPressedDispatcher.addCallback(this)
}
}
}

@Deprecated("Deprecated in Java")
@Suppress("RedundantModalityModifier", "deprecation")
final override fun onBackPressed() { // you cannot use `onBackPressed()` if you use `OnBackPressedDispatcher`
super.onBackPressed()
}

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

setContentView(R.layout.main_activity)

onBackPressedDispatcher.addCallback(backPressedCallback) // this is the reliable way to handle back for now

val app = application as CustomApplication
val globalServices = app.globalServices

authenticationManager = globalServices.get()

fragmentStateChanger = FragmentStateChanger(supportFragmentManager, R.id.container)

onBackPressedDispatcher.addCallback(backPressedCallback) // this is required for `onBackPressedDispatcher` to work correctly

Navigator.configure()
.setStateChanger(SimpleStateChanger(this))
.setScopedServices(ServiceProvider())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,19 @@ class MainActivity : AppCompatActivity(), SimpleStateChanger.NavigationHandler {
override fun handleOnBackPressed() {
if (!Navigator.onBackPressed(this@MainActivity)) {
this.remove()
onBackPressed() // this is the only safe way to manually invoke onBackPressed when using onBackPressedDispatcher`
onBackPressed() // this is the reliable way to handle back for now
this@MainActivity.onBackPressedDispatcher.addCallback(this)
}
}
}

@Deprecated("Deprecated in Java")
@Suppress("RedundantModalityModifier", "deprecation")
final override fun onBackPressed() { // you cannot use `onBackPressed()` if you use `OnBackPressedDispatcher`
super.onBackPressed()
}


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

val binding = MainActivityBinding.inflate(layoutInflater)

onBackPressedDispatcher.addCallback(backPressedCallback) // this is the reliable way to handle back for now

setContentView(binding.root)

fragmentStateChanger = DefaultFragmentStateChanger(supportFragmentManager, R.id.step9Root)
Expand All @@ -51,8 +46,6 @@ class MainActivity : AppCompatActivity(), SimpleStateChanger.NavigationHandler {

authenticationManager = globalServices.get()

onBackPressedDispatcher.addCallback(backPressedCallback) // this is required for `onBackPressedDispatcher` to work correctly

Navigator.configure()
.setStateChanger(SimpleStateChanger(this))
.setScopedServices(ServiceProvider())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,24 @@ class MainActivity : AppCompatActivity(), SimpleStateChanger.NavigationHandler {
private lateinit var snackbarTextEmitter: SnackbarTextEmitter
private lateinit var binding: MainActivityBinding


@Suppress("DEPRECATION")
private val backPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if (!Navigator.onBackPressed(this@MainActivity)) {
this.remove()
onBackPressed() // this is the only safe way to manually invoke onBackPressed when using onBackPressedDispatcher`
onBackPressed() // this is the reliable way to handle back for now
this@MainActivity.onBackPressedDispatcher.addCallback(this)
}
}
}

@Deprecated("Deprecated in Java")
@Suppress("RedundantModalityModifier", "deprecation")
final override fun onBackPressed() { // you cannot use `onBackPressed()` if you use `OnBackPressedDispatcher`
super.onBackPressed()
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = MainActivityBinding.inflate(layoutInflater)
setContentView(binding.root)

onBackPressedDispatcher.addCallback(backPressedCallback) // this is the reliable way to handle back for now

val app = application as CustomApplication
val globalServices = app.globalServices

Expand Down Expand Up @@ -77,8 +72,6 @@ class MainActivity : AppCompatActivity(), SimpleStateChanger.NavigationHandler {
showSnackbar(binding.root, getString(textRes))
}

onBackPressedDispatcher.addCallback(backPressedCallback) // this is required for `onBackPressedDispatcher` to work correctly

Navigator.configure()
.setStateChanger(SimpleStateChanger(this))
.setGlobalServices(globalServices)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class MainActivity
public void handleOnBackPressed() {
if(!Navigator.onBackPressed(MainActivity.this)) {
this.remove();
onBackPressed(); // this is the only safe way to manually invoke onBackPressed when using onBackPressedDispatcher`
onBackPressed(); // this is the reliable way to handle back for now
MainActivity.this.getOnBackPressedDispatcher().addCallback(this);
}
}
Expand Down Expand Up @@ -71,7 +71,7 @@ protected void onCreate(Bundle savedInstanceState) {
fragmentStateChanger = new DefaultFragmentStateChanger(getSupportFragmentManager(),
R.id.container);

getOnBackPressedDispatcher().addCallback(backPressedCallback); // this is required for `onBackPressedDispatcher` to work correctly
getOnBackPressedDispatcher().addCallback(backPressedCallback); // this is the reliable way to handle back for now

Navigator.configure()
.setStateChanger(new SimpleStateChanger(this))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class MainActivity
public void handleOnBackPressed() {
if(!Navigator.onBackPressed(MainActivity.this)) {
this.remove();
onBackPressed(); // this is the only safe way to manually invoke onBackPressed when using onBackPressedDispatcher`
onBackPressed(); // this is the reliable way to handle back for now
MainActivity.this.getOnBackPressedDispatcher().addCallback(this);
}
}
Expand Down Expand Up @@ -59,7 +59,7 @@ protected void onCreate(Bundle savedInstanceState) {
return false;
});

getOnBackPressedDispatcher().addCallback(backPressedCallback); // this is required for `onBackPressedDispatcher` to work correctly
getOnBackPressedDispatcher().addCallback(backPressedCallback); // this is the reliable way to handle back for now

Navigator.install(this, binding.container, History.single(HomeKey.create()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,20 @@ class MainActivity : AppCompatActivity(), SimpleStateChanger.NavigationHandler {
override fun handleOnBackPressed() {
if (!Navigator.onBackPressed(this@MainActivity)) {
this.remove()
onBackPressed() // this is the only safe way to manually invoke onBackPressed when using onBackPressedDispatcher`
onBackPressed() // this is the reliable way to handle back for now
this@MainActivity.onBackPressedDispatcher.addCallback(this)
}
}
}

@Deprecated("Deprecated in Java")
@Suppress("RedundantModalityModifier", "deprecation")
final override fun onBackPressed() { // you cannot use `onBackPressed()` if you use `OnBackPressedDispatcher`
super.onBackPressed()
}

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

val binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)

onBackPressedDispatcher.addCallback(backPressedCallback) // this is the reliable way to handle back for now

binding.navigation.setOnNavigationItemSelectedListener { item ->
val destination = when (item.itemId) {
R.id.navigation_home -> HomeKey
Expand All @@ -61,8 +57,6 @@ class MainActivity : AppCompatActivity(), SimpleStateChanger.NavigationHandler {

fragmentStateChanger = DefaultFragmentStateChanger(supportFragmentManager, R.id.container)

onBackPressedDispatcher.addCallback(backPressedCallback) // this is required for `onBackPressedDispatcher` to work correctly

Navigator.configure()
.setStateChanger(SimpleStateChanger(this))
.install(this, binding.container, History.single(HomeKey))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,20 @@ class MainActivity : AppCompatActivity() {
override fun handleOnBackPressed() {
if (!Navigator.onBackPressed(this@MainActivity)) {
this.remove()
onBackPressed() // this is the only safe way to manually invoke onBackPressed when using onBackPressedDispatcher`
onBackPressed() // this is the reliable way to handle back for now
this@MainActivity.onBackPressedDispatcher.addCallback(this)
}
}
}

@Deprecated("Deprecated in Java")
@Suppress("RedundantModalityModifier", "deprecation")
final override fun onBackPressed() { // you cannot use `onBackPressed()` if you use `OnBackPressedDispatcher`
super.onBackPressed()
}

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

val binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)

onBackPressedDispatcher.addCallback(backPressedCallback) // this is the reliable way to handle back for now

binding.navigation.setOnNavigationItemSelectedListener { item ->
when (item.itemId) {
R.id.navigation_home -> {
Expand All @@ -55,8 +51,6 @@ class MainActivity : AppCompatActivity() {
false
}

onBackPressedDispatcher.addCallback(backPressedCallback) // this is required for `onBackPressedDispatcher` to work correctly

Navigator.install(this, binding.container, History.single(HomeKey))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,12 @@ class MainActivity : AppCompatActivity(), SimpleStateChanger.NavigationHandler {
override fun handleOnBackPressed() {
if (!Navigator.onBackPressed(this@MainActivity)) {
this.remove()
onBackPressed() // this is the only safe way to manually invoke onBackPressed when using onBackPressedDispatcher`
onBackPressed() // this is the reliable way to handle back for now
this@MainActivity.onBackPressedDispatcher.addCallback(this)
}
}
}

@Deprecated("Deprecated in Java")
@Suppress("RedundantModalityModifier", "deprecation")
final override fun onBackPressed() { // you cannot use `onBackPressed()` if you use `OnBackPressedDispatcher`
super.onBackPressed()
}

private lateinit var fragmentStateChanger: DefaultFragmentStateChanger

override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -38,9 +32,9 @@ class MainActivity : AppCompatActivity(), SimpleStateChanger.NavigationHandler {
val binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)

fragmentStateChanger = DefaultFragmentStateChanger(supportFragmentManager, R.id.container)
onBackPressedDispatcher.addCallback(backPressedCallback) // this is the reliable way to handle back for now

onBackPressedDispatcher.addCallback(backPressedCallback) // this is required for `onBackPressedDispatcher` to work correctly
fragmentStateChanger = DefaultFragmentStateChanger(supportFragmentManager, R.id.container)

Navigator.configure()
.setStateChanger(SimpleStateChanger(this))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,12 @@ class MainActivity : AppCompatActivity(), SimpleStateChanger.NavigationHandler {

if (!backstack.goBack()) {
this.remove()
onBackPressed() // this is the only safe way to manually invoke onBackPressed when using onBackPressedDispatcher`
onBackPressed() // this is the reliable way to handle back for now
this@MainActivity.onBackPressedDispatcher.addCallback(this)
}
}
}

@Deprecated("Deprecated in Java")
@Suppress("RedundantModalityModifier", "deprecation")
final override fun onBackPressed() { // you cannot use `onBackPressed()` if you use `OnBackPressedDispatcher`
super.onBackPressed()
}

lateinit var multistack: Multistack

private var isAnimating: Boolean = false
Expand Down Expand Up @@ -66,6 +60,8 @@ class MainActivity : AppCompatActivity(), SimpleStateChanger.NavigationHandler {

setContentView(R.layout.activity_main)

onBackPressedDispatcher.addCallback(backPressedCallback) // this is the reliable way to handle back for now

multistackFragmentStateChanger = MultistackFragmentStateChanger(R.id.root, supportFragmentManager)

findViewById<View>(R.id.bbn_item1).setOnClickListener {
Expand All @@ -84,8 +80,6 @@ class MainActivity : AppCompatActivity(), SimpleStateChanger.NavigationHandler {
multistack.setSelectedStack(StackType.values()[3].name)
}

onBackPressedDispatcher.addCallback(backPressedCallback) // this is required for `onBackPressedDispatcher` to work correctly

multistack.setStateChanger(SimpleStateChanger(this))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,12 @@ class MainActivity : AppCompatActivity(), MultistackViewStateChanger.AnimationSt

if (!backstack.goBack()) {
this.remove()
onBackPressed() // this is the only safe way to manually invoke onBackPressed when using onBackPressedDispatcher`
onBackPressed() // this is the reliable way to handle back for now
this@MainActivity.onBackPressedDispatcher.addCallback(this)
}
}
}

@Deprecated("Deprecated in Java")
@Suppress("RedundantModalityModifier", "deprecation")
final override fun onBackPressed() { // you cannot use `onBackPressed()` if you use `OnBackPressedDispatcher`
super.onBackPressed()
}


lateinit var multistack: Multistack

private var isAnimating: Boolean = false
Expand Down Expand Up @@ -70,6 +63,8 @@ class MainActivity : AppCompatActivity(), MultistackViewStateChanger.AnimationSt

setContentView(R.layout.activity_main)

onBackPressedDispatcher.addCallback(backPressedCallback) // this is the reliable way to handle back for now

multistackViewStateChanger = MultistackViewStateChanger(this, multistack, findViewById(R.id.container), this)

findViewById<View>(R.id.bbn_item1).setOnClickListener {
Expand All @@ -88,8 +83,6 @@ class MainActivity : AppCompatActivity(), MultistackViewStateChanger.AnimationSt
multistack.setSelectedStack(StackType.values()[3].name)
}

onBackPressedDispatcher.addCallback(backPressedCallback) // this is required for `onBackPressedDispatcher` to work correctly

multistack.setStateChanger(AsyncStateChanger(this))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,21 @@ class MainActivity : AppCompatActivity(), SimpleStateChanger.NavigationHandler {
override fun handleOnBackPressed() {
if (!Navigator.onBackPressed(this@MainActivity)) {
this.remove()
onBackPressed() // this is the only safe way to manually invoke onBackPressed when using onBackPressedDispatcher`
onBackPressed() // this is the reliable way to handle back for now
this@MainActivity.onBackPressedDispatcher.addCallback(this)
}
}
}

@Deprecated("Deprecated in Java")
@Suppress("RedundantModalityModifier", "deprecation")
final override fun onBackPressed() { // you cannot use `onBackPressed()` if you use `OnBackPressedDispatcher`
super.onBackPressed()
}


private lateinit var fragmentStateChanger: DefaultFragmentStateChanger

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

fragmentStateChanger = DefaultFragmentStateChanger(supportFragmentManager, R.id.container)
onBackPressedDispatcher.addCallback(backPressedCallback) // this is the reliable way to handle back for now

onBackPressedDispatcher.addCallback(backPressedCallback) // this is required for `onBackPressedDispatcher` to work correctly
fragmentStateChanger = DefaultFragmentStateChanger(supportFragmentManager, R.id.container)

Navigator.configure()
.setScopedServices(DefaultServiceProvider())
Expand Down
Loading

0 comments on commit 0975890

Please sign in to comment.