This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | |
super.onActivityResult(requestCode, resultCode, data) | |
if (resultCode == Activity.RESULT_OK && requestCode == ReusableActivityRouter.REUSABLE_ACTIVITY_REQUEST_CODE) { | |
val resultExtra = data?.getParcelableExtra<ReusableResultExtra>(ReusableActivityRouter.REUSABLE_ACTIVITY_RESULT_KEY) | |
resultExtra?.run { | |
Toast.makeText(this@MainActivity, | |
"Reusable closed activity: $screenType\n" + | |
"Inputted text: $inputtedText", | |
Toast.LENGTH_LONG).show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
companion object { | |
const val REUSABLE_ACTIVITY_RESULT_KEY = "reusable_activity_result_key" | |
} | |
fun setResult(screenType: ReusableScreenType, inputtedText: String?) { | |
val resultIntent = Intent().apply { | |
putExtra( | |
REUSABLE_ACTIVITY_RESULT_KEY, ReusableResultExtra( | |
inputtedText, | |
screenType | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Parcelize | |
data class ReusableResultExtra( | |
val inputtedText: String?, | |
val screenType: ReusableScreenType | |
) : Parcelable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
activity.finish() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val title = MutableLiveData<String>() | |
val description = MutableLiveData<String>() | |
val buttonText = MutableLiveData<String>() | |
private var viewType: ReusableScreenType? = null | |
fun load( | |
title: String, | |
description: String, | |
buttonText: String, | |
viewType: ReusableScreenType? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val extra = intent.getParcelableExtra<ReusableActivityExtra>( | |
ReusableActivityRouter.REUSABLE_ACTIVITY_EXTRA | |
) | |
requireNotNull(extra).run { | |
viewModel.load( | |
title, | |
description, | |
buttonText, | |
viewType | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ReusableViewModel(private val router: ReusableActivityRouter) : ViewModel() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ReusableActivity : AppCompatActivity() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Parcelize | |
data class ReusableActivityExtra( | |
val title: String, | |
val description: String, | |
val buttonText: String, | |
val viewType: ReusableScreenType? = null | |
) : Parcelable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum class ReusableScreenType { | |
WELCOME, | |
ACCEPT_TERMS | |
} |
NewerOlder