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
/* Place this code in your JS file */ | |
jQuery(document).ready(function($){ | |
// browser window scroll (in pixels) after which the "back to top" link is shown | |
var offset = 300, | |
//browser window scroll (in pixels) after which the "back to top" link opacity is reduced | |
offset_opacity = 1200, | |
//duration of the top scrolling animation (in ms) | |
scroll_top_duration = 3500, | |
//grab the "back to top" link | |
$back_to_top = $('.cd-top'); |
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 UserListActivity : AppCompatActivity() { | |
@Inject internal lateinit var viewModelFactory: ViewModelProvider.Factory | |
private lateinit var userListViewModel: UserListViewModel | |
private lateinit var swipeRefreshLayout: SwipeRefreshLayout | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) |
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 UserListViewModel @Inject constructor(private val userRepository: UserRepository) : ViewModel() { | |
private val reloadTrigger = MutableLiveData<Boolean>() | |
private val users: LiveData<List<UserModel>> = Transformations.switchMap(reloadTrigger) { | |
userRepository.getUsers() | |
} | |
init { | |
refreshUsers() | |
} |
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
// DON'T DO THIS | |
class UserListActivity : AppCompatActivity() { | |
@Inject internal lateinit var viewModelFactory: ViewModelProvider.Factory | |
private lateinit var userListViewModel: UserListViewModel | |
private lateinit var swipeRefreshLayout: SwipeRefreshLayout | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) |
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 UserListViewModel @Inject constructor(private val userRepository: UserRepository) : ViewModel() { | |
init { | |
} | |
// DON'T DO THIS | |
fun getUsers(): LiveData<List<UserModel>> { | |
return userRepository.getUsers() | |
} |
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 UserDetailViewModel @Inject constructor( | |
private val userRepository: UserRepository | |
) : ViewModel() { | |
private lateinit var userId: String | |
private val reloadTrigger = MutableLiveData<Boolean>() | |
private val userDetail: LiveData<UserDetailModel> = Transformations.switchMap(reloadTrigger) { | |
userRepository.getUserDetail(userId, reloadTrigger.value!!) | |
} |
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
const val ARGUMENT_USER_ID = "ARGUMENT_USER_ID" | |
class UserDetailActivity : AppCompatActivity() { | |
@Inject | |
internal lateinit var viewModelFactory: ViewModelProvider.Factory | |
private lateinit var userDetailViewModel: UserDetailViewModel | |
override fun onCreate(savedInstanceState: Bundle?) { | |
// ... |
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 level gradle file | |
dependencies { | |
/* Dagger 2 - Assisted Inject */ | |
compileOnly 'com.squareup.inject:assisted-inject-annotations-dagger2:0.3.3' | |
kapt 'com.squareup.inject:assisted-inject-processor-dagger2:0.3.3' | |
} |
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 UserDetailViewModel @AssistedInject constructor( | |
private val userRepository: UserRepository, | |
@Assisted private val userId: Int | |
) : ViewModel() { | |
private val reloadTrigger = MutableLiveData<Boolean>() | |
private val userDetail: LiveData<UserDetailModel> = Transformations.switchMap(reloadTrigger) { | |
userRepository.getUserDetail(userId.toString(), reloadTrigger.value!!) | |
} | |
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
@Component(modules = [AssistedInjectModule::class]) | |
@Singleton | |
interface ApplicationComponent { | |
// ... | |
@Component.Builder | |
interface Builder { | |
@BindsInstance | |
fun application(application: Application): Builder | |
fun build(): AppComponent |
OlderNewer