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 FactsViewModel | |
| @Inject constructor(private val getRandomFactUseCase: GetRandomFactUseCase) : BaseViewModel() { | |
| companion object { | |
| const val FIRST_FACT = 0L | |
| } | |
| val fact = MutableLiveData<FactUi>() | |
| init { | |
| getFact(FIRST_FACT) |
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 FactsFragment : BaseFragment<FragmentFactsBinding, FactsViewModel>() { | |
| // Bounce down animation distance | |
| private val halfScreenHeight: Float by lazy { | |
| context?.resources?.displayMetrics?.heightPixels?.div(2f)!! | |
| } | |
| private lateinit var springAnimation: SpringAnimation | |
| override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
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
| abstract class BaseFragment<VB : ViewDataBinding, VM : BaseViewModel> : DaggerFragment() { | |
| abstract fun getViewModelClass(): Class<VM> | |
| abstract fun layoutId(): Int | |
| @Inject | |
| lateinit var viewModelFactory: ViewModelProvider.Factory | |
| protected lateinit var binding: VB | |
| protected lateinit var viewModel: VM |
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 DateTimeHandler { | |
| fun currentEpochSecs(): Long = Instant.now(Clock.systemDefaultZone()).epochSecond | |
| fun currentLocalDate(): LocalDate = LocalDate.now(ZoneId.systemDefault()) | |
| ... | |
| } |
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 GetAllConsumedSweetsUseCase(private val repo: ConsumedSweetsRepo) : | |
| SingleUseCase<List<ConsumedSweet>> { | |
| override fun execute(): Single<List<ConsumedSweet>> { | |
| return repo.getAllConsumedSweets() | |
| } | |
| } |
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
| data class ConsumedSweet( | |
| val id: Long = 0, | |
| val sweetId: Long, | |
| val g: Long, | |
| val date: Long, | |
| val sweet: Sweet) |
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
| interface FactRepo { | |
| fun getRandomFact(currentFactId: Long): Single<Fact> | |
| fun downloadAllFactsAndSave(): Completable | |
| } |
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
| interface CompletableUseCaseWithParameter<P> { | |
| fun execute(parameter: P): Completable | |
| } |
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
| enum class MeasurementUnit { | |
| GRAM { | |
| override val ratioWithGrams: Int = 1 | |
| }, | |
| OUNCE { | |
| override val ratioWithGrams: Int = 28 | |
| }; | |
| abstract val ratioWithGrams: 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
| //Constructing the PagedList (in viewModel for example) | |
| private static final int INITIAL_LOAD_KEY = 0; | |
| private static final int PAGE_SIZE = 15; | |
| private static final int PREFETCH_DISTANCE = 5; | |
| final MutableLiveData<PagedList<Item>> itemList = new MutableLiveData<>(); | |
| public void load(Executor uiExecutor, Executor threadPoolExecutor) { | |
| Box<Item> db = DataBase.getInstance(getContext()); |