Skip to content

Instantly share code, notes, and snippets.

View takahirom's full-sized avatar

Takahiro Menju takahirom

View GitHub Profile
@Composable
fun MySwitch() {
​// I have a State in Compose's MutableState
​val checked = remember { mutableStateOf(false) }
​Switch(
​// Observe the State by accessing the value property
​checked = checked.value,
​onCheckedChange = {
checked.value = it
​}
# You will need to take full responsibility for your action.
# only once
brew install mitmproxy
ifconfig|grep 192.168 |awk '{print $2}'|xargs -IIPADDRESS adb shell settings put global http_proxy IPADDRESS:8083
mitmweb -p 8083
adb shell am start -a android.intent.action.VIEW -d "http://mitm.it"
# download and install pem
# each time you want to do mitm
@takahirom
takahirom / EventBus.kt
Last active June 9, 2022 10:21
EventBus by Kotlin coroutine
import kotlinx.coroutines.experimental.channels.BroadcastChannel
import kotlinx.coroutines.experimental.channels.ConflatedBroadcastChannel
import kotlinx.coroutines.experimental.channels.ReceiveChannel
import kotlinx.coroutines.experimental.channels.filter
import kotlinx.coroutines.experimental.channels.map
import kotlinx.coroutines.experimental.launch
import javax.inject.Inject
import javax.inject.Singleton
@takahirom
takahirom / OneOffEventForSnackbar.kt
Created June 2, 2022 23:41
One-off event for snackbar message
// ---- User side (Write every time) ----
val scaffoldState = rememberScaffoldState()
val viewModel = hiltViewModel<FooViewModel>()
SnackbarMessageEffect(
scaffoldState = scaffoldState,
messageStateHolder = viewModel
)
Scaffold(scaffoldState = scaffoldState) {
...
// ----UI Layer----
// -UI Layer(UI element)-
@AndroidEntryPoint
class ArticlesActivity : AppCompatActivity() {
// UI 1. ✅ You shouldn't store or keep in memory any application
// data or state in your app components
lateinit var binding: ActivityArticlesBinding
private val articlesViewModel by viewModels<ArticlesViewModel>()
@Stable
data class UiModel(val articles: Articles)
@Composable
fun Composable2(uiModel: UiModel) {
Text(text = "Hello $uiModel!")
}
data class Articles(val articles: List<Article>)
data class Article(val title: String)
@takahirom
takahirom / Composables.kt
Created March 27, 2022 07:40
app module
@Composable
fun Composable1(articles: Articles) {
Text(text = "Hello $articles!")
}
@Stable
data class UiModel(val articles: Articles)
@Composable
fun Composable2(uiModel: UiModel) {
class HogeActivity {
val featureFlags = FeatureFlags()
@OptIn(AmazingFeature::class)
fun onClick() {
if (featureFlags.isAmazingFeaturesEnabled()) {
brokenAmazingFeatures()
}
}
}
@RequiresOptIn(message = "AmazingFeature should be checked")
@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY)
annotation class AmazingFeature
@AmazingFeature
fun brokenAmazingFeature() {
TODO("aaaaa")
}