This file contains hidden or 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
fun TextView.setMaxLinesToEllipsize() = doOnPreDraw { | |
val numberOfCompletelyVisibleLines = (measuredHeight - paddingTop - paddingBottom) / lineHeight | |
maxLines = numberOfCompletelyVisibleLines | |
} |
This file contains hidden or 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
<?xml version="1.0" encoding="utf-8"?> | |
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<TextView | |
android:id="@+id/textView" | |
android:layout_width="200dp" | |
android:layout_height="100dp" |
This file contains hidden or 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
<?xml version="1.0" encoding="utf-8"?> | |
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<TextView | |
android:id="@+id/textView" | |
android:layout_width="200dp" | |
android:layout_height="100dp" |
This file contains hidden or 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
private val viewModel by lazy { | |
// this is what we had | |
//ViewModelProviders.of(this, injector.bestPostViewModelFactory()).get(BestPostViewModel::class.java) | |
// this is what we want now | |
val viewModelFactory = injector.with(BestPostModule(myIntFromView = 10)).bestPostViewModelFactory() | |
ViewModelProviders.of(this, viewModelFactory).get(BestPostViewModel::class.java) | |
} |
This file contains hidden or 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
@Singleton | |
@Component(modules = ...) | |
interface ApplicationComponent { | |
... | |
//fun bestPostViewModelFactory(): ViewModelFactory<BestPostViewModel> | |
fun with(postDetailsModule: BestPostModule): BestPostComponent | |
} |
This file contains hidden or 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
@Subcomponent(modules = [BestPostModule::class]) | |
interface BestPostComponent { | |
fun bestPostViewModelFactory(): ViewModelFactory<BestPostViewModel> | |
} | |
@Module | |
class BestPostModule(@get:Provides val myIntFromView: Int) |
This file contains hidden or 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
compileOnly 'com.squareup.inject:assisted-inject-annotations-dagger2:0.5.0' | |
kapt 'com.squareup.inject:assisted-inject-processor-dagger2:0.5.0' |
This file contains hidden or 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 BestPostViewModel @AssistedInject constructor( | |
... | |
@Assisted myIntFromView: Int | |
) : ViewModel() { | |
@AssistedInject.Factory | |
interface Factory { | |
fun create(myIntFromView: Int): BestPostViewModel | |
} |
This file contains hidden or 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
private val viewModel by viewModel(this) { | |
injector.bestPostViewModelFactory.create(myIntFromView = 10) | |
} |
This file contains hidden or 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
@Singleton | |
@Component(modules = [RetrofitModule::class, AssistedInjectModule::class]) | |
interface ApplicationComponent { | |
... | |
val bestPostViewModelFactory: BestPostViewModel.Factory | |
} | |
@AssistedModule | |
@Module(includes = [AssistedInject_AssistedInjectModule::class]) |