Skip to content

Instantly share code, notes, and snippets.

View mitchtabian's full-sized avatar
🎞️
Building stuff

Mitch Tabian mitchtabian

🎞️
Building stuff
View GitHub Profile
@mitchtabian
mitchtabian / CacheDataSourceImpl.kt
Created July 3, 2020 18:06
Hilt @provides to provide interface instance that you own
class CacheDataSourceImpl
constructor(
private val blogDao: BlogDao,
private val cacheMapper: CacheMapper
): CacheDataSource{
override suspend fun insert(blog: Blog): Long {
return blogDao.insert(cacheMapper.mapToEntity(blog))
}
@mitchtabian
mitchtabian / AbstractCacheModule.kt
Created July 3, 2020 18:05
Hilt @BINDS to provide interface instance that you own
@Module
@InstallIn(ApplicationComponent::class)
abstract class AbstractCacheModule{
@Singleton
@Binds
abstract fun bindCacheDataSource(
cacheDataSourceImpl: CacheDataSourceImpl
): CacheDataSource
}
@mitchtabian
mitchtabian / AndroidManifest.xml
Last active October 21, 2020 12:01
Enable Fragment constructor injection for instrumentation tests when using Hilt. This is a modified version of https://github.com/android/architecture-samples/blob/dev-hilt/app/src/androidTest/java/com/example/android/architecture/blueprints/todoapp/HiltExt.kt
<!-- **NOTE** This must be in /debug/ -->
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.codingwithmitch.daggerhiltplayground">
<application>
<activity
android:name="com.codingwithmitch.daggerhiltplayground.HiltTestActivity"
android:exported="false" />
</application>
@mitchtabian
mitchtabian / consumer.dart
Last active June 18, 2020 21:12
Example using Consumer with Provider
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../models/product.dart';
import '../providers/product_provider.dart';
import '../screens/product_detail_screen.dart';
import '../styles.dart';
class ProductItem extends StatelessWidget {
class Product {
final String id;
final String title;
final String description;
final double price;
final String imageUrl;
bool isFavorite;
Product({
@mitchtabian
mitchtabian / tabs_screen.dart
Created June 17, 2020 18:11
Flutter bottom tabs
class TabsScreen extends StatefulWidget {
@override
_TabsScreenState createState() => _TabsScreenState();
}
class _TabsScreenState extends State<TabsScreen> {
final List<Map<String, Object>> _pages = [
{"page": CategoriesScreen(), "title": "Categories"},
@mitchtabian
mitchtabian / tabs_screen.dart
Created June 17, 2020 17:55
Top tabs with flutter
class TabsScreen extends StatefulWidget {
@override
_TabsScreenState createState() => _TabsScreenState();
}
class _TabsScreenState extends State<TabsScreen> {
static const NUM_TABS = 2;
@Test
fun updateNote_success_confirmNetworkAndCacheUpdated() = runBlocking {
val randomNote = noteCacheDataSource.searchNotes("", "", 1)
.get(0)
// bug fix start
val updatedNote = Note(
id = randomNote.id,
title = UUID.randomUUID().toString(),
body = UUID.randomUUID().toString(),
@Test
fun deleteNetworkNotes_confirmCacheSync() = runBlocking {
// select some notes to be deleted from cache
val networkNotes = noteNetworkDataSource.getAllNotes()
val notesToDelete: ArrayList<Note> = ArrayList()
for(note in networkNotes){
notesToDelete.add(note)
noteNetworkDataSource.deleteNote(note.id) // delete from notes node
noteNetworkDataSource.insertDeletedNote(note) // insert into deletes node
package com.codingwithmitch.cleannotes.di
import com.codingwithmitch.cleannotes.business.data.NoteDataFactory
import com.codingwithmitch.cleannotes.business.data.cache.FakeNoteCacheDataSourceImpl
import com.codingwithmitch.cleannotes.business.data.cache.abstraction.NoteCacheDataSource
import com.codingwithmitch.cleannotes.business.data.network.FakeNoteNetworkDataSourceImpl
import com.codingwithmitch.cleannotes.business.data.network.abstraction.NoteNetworkDataSource
import com.codingwithmitch.cleannotes.business.domain.model.Note
import com.codingwithmitch.cleannotes.business.domain.model.NoteFactory
import com.codingwithmitch.cleannotes.business.domain.util.DateUtil