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
@Composable | |
fun ClickableLinkRow(url: String) { | |
val customTabs = LocalCustomTabs.current | |
Row( | |
modifier = Modifier | |
.clickable { customTabs.launch(url) } | |
) { | |
... | |
} |
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
@AndroidEntryPoint | |
class MainActivity { | |
@Inject | |
lateinit var customTabs: CustomTabs | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContent { |
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 LocalCustomTabs = staticCompositionLocalOf<CustomTabs> { | |
error("CompositionLocal LocalCustomTabs not present") | |
} |
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
// MainActivity.onCreate | |
setContent { | |
First(customTabs) | |
} | |
// Module :first | |
@Composable | |
fun First(customTabs: CustomTabs) { | |
Second(customTabs) | |
} |
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
@AndroidEntryPoint | |
class MainActivity { | |
@Inject | |
lateinit var customTabs: CustomTabs | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
... | |
} |
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
@Module | |
@InstallIn(ActivityComponent::class) | |
interface CustomTabsModule { | |
@Binds | |
@ActivityScoped | |
fun bindCustomTabs(impl: CustomTabsImpl): CustomTabs | |
} |
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
interface CustomTabs { | |
fun launch(url: String) | |
} | |
class CustomTabsImpl @Inject constructor( | |
@ActivityContext private val context: Context | |
) : CustomTabs { | |
fun launch(url: String) { | |
// The implementation goes here |
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
@Inherited | |
@Target(CLASS) | |
@Retention(RUNTIME) | |
annotation class EnumWithDefault( | |
val value: String = "UNKNOWN" | |
) | |
@EnumWithDefault // Defaults to UNKNOWN | |
enum class Example { | |
FIRST, SECOND, UNKNOWN |
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 MyActivity : AppCompatActivity() { | |
private val myActionCall = prepareCall(MyContract()) { result -> | |
Log.i("MyActivity", "Obtained result: $result") | |
} | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
... | |
button.setOnClickListener { |
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 MyContract : ActivityResultContract<Int, String>() { | |
companion object { | |
const val ACTION = "com.myapp.action.MY_ACTION" | |
const val INPUT_INT = "input_int" | |
const val OUTPUT_STRING = "output_string" | |
} | |
override fun createIntent(input: Int): Intent { | |
return Intent(ACTION) |
NewerOlder