Skip to content

Instantly share code, notes, and snippets.

View deividasstr's full-sized avatar
💭
I may be slow to respond.

Deividas Strioga deividasstr

💭
I may be slow to respond.
View GitHub Profile
class FactsViewModel
@Inject constructor(private val getRandomFactUseCase: GetRandomFactUseCase) : BaseViewModel() {
companion object {
const val FIRST_FACT = 0L
}
val fact = MutableLiveData<FactUi>()
init {
getFact(FIRST_FACT)
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?) {
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
class DateTimeHandler {
fun currentEpochSecs(): Long = Instant.now(Clock.systemDefaultZone()).epochSecond
fun currentLocalDate(): LocalDate = LocalDate.now(ZoneId.systemDefault())
...
}
class GetAllConsumedSweetsUseCase(private val repo: ConsumedSweetsRepo) :
SingleUseCase<List<ConsumedSweet>> {
override fun execute(): Single<List<ConsumedSweet>> {
return repo.getAllConsumedSweets()
}
}
data class ConsumedSweet(
val id: Long = 0,
val sweetId: Long,
val g: Long,
val date: Long,
val sweet: Sweet)
@deividasstr
deividasstr / FactRepo.kt
Created September 20, 2018 13:00
FactRepo
interface FactRepo {
fun getRandomFact(currentFactId: Long): Single<Fact>
fun downloadAllFactsAndSave(): Completable
}
@deividasstr
deividasstr / CompletableUseCaseWithParameter.kt
Last active September 25, 2018 13:52
CompletableUseCaseWithParameter
interface CompletableUseCaseWithParameter<P> {
fun execute(parameter: P): Completable
}
@deividasstr
deividasstr / MeasurementUnit.kt
Created September 20, 2018 10:52
MeasurementUnit
enum class MeasurementUnit {
GRAM {
override val ratioWithGrams: Int = 1
},
OUNCE {
override val ratioWithGrams: Int = 28
};
abstract val ratioWithGrams: Int
}
@deividasstr
deividasstr / pagedlistWithObjectBox.java
Last active May 15, 2018 14:05
Android architecture component PagedList with ObjextBox db, java
//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());