Skip to content

Instantly share code, notes, and snippets.

fun generateImage(width: Int, height: Int): Bitmap {
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
val paint = Paint()
val path = generatePath()
canvas.drawPath(path, paint)
return bitmap
}
class CounterViewModelFactory(val name: String) : ViewModelProvider.Factory {
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
return CounterViewModel(name) as T
}
}
//inside activity
val viewModel: CounterViewModel by lazy {
ViewModelProvider(
MainActivity@ this,
@Marchuck
Marchuck / SomeFragment.kt
Created November 17, 2019 20:30
SomeFragment
class SomeFragment: Fragment(){
@Inject factory: AssistedViewModel.Factory
override fun onActivityCreated(savedInstanceState: Bundle?){
super.onActivityCreated(savedInstanceState)
val viewModel = factory.create(301)
...
}
@Marchuck
Marchuck / AssistedViewModel.kt
Last active December 9, 2019 20:43
AssistedViewModel
class AssistedViewModel @AssistedInject constructor(
private val dependency1: Dependency1,
private val dependency2: Dependency2,
...
@Assisted private val id: Int){
@AssistedInject.Factory
interface Factory{ fun create(id: Int) : AssistedViewModel }
}
@Marchuck
Marchuck / MyViewModel.kt
Created November 17, 2019 19:57
setter example
class MyViewModel @Inject constructor(private val dependency1: Dependency1,
private val dependency2: Dependency2,
...)
{
private var id: Int? = null
fun setupId(id: Int){
this.id = id
}
...
@Marchuck
Marchuck / MyViewModel.kt
Created November 17, 2019 19:40
MyViewModel.kt
class MyViewModel @Inject constructor(private val dependency1: Dependency1,
private val dependency2: Dependency2,
...
private val id: Int)//hold on Dagger! I will provide this on my own
{ ... }
# Built application files
*.apk
*.ap_
*.aab
# Files for the ART/Dalvik VM
*.dex
# Java class files
@Marchuck
Marchuck / ExampleTest.kt
Created October 15, 2019 07:32
testing LiveData
ExampleTest{
@BeforeEach
fun setUp() {
viewModel = SomeViewModel(...)
filtersObserver = viewModel.filtersLiveData.observeEvents()
}
@Test fun `test 1`(){
val expected = arrayListOf<Any>()
@Marchuck
Marchuck / AlertDialog.kt
Created October 11, 2019 11:18
AlertDialog.kt
fun Fragment.createAlertDialog() =
AlertDialog.Builder(ContextThemeWrapper(context, R.style.custom_dialog_style))
data class DialogAction(
var text: String,
var onClick: (() -> Unit)? = null
)
#!/usr/bin/env bash
#access token can be generated here(https://app.bitrise.io/me/profile#/security) and stored as secret
access_token=$BITRISE_API_ACCESS_TOKEN
app_slug="your-app-id" # the id of your app
build_slug=$BITRISE_BUILD_SLUG
bitrise_api_url="https://api.bitrise.io/v0.1"
the_url="$bitrise_api_url/apps/$app_slug/builds/$build_slug/artifacts"
artifacts_array=$(curl -s -H "Authorization: $access_token" $the_url)