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
@Dao | |
interface PostDao { | |
@Insert(onConflict = OnConflictStrategy.IGNORE) | |
fun insert(post: Post): Long | |
@Update(onConflict = OnConflictStrategy.REPLACE) | |
fun update(post: Post) | |
@Transaction | |
fun upsert(post: Post) { |
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 PostBoundaryCallback : PagedList.BoundaryCallback<Post>(), KoinComponent { | |
private val remoteDataSource: PostApiService by inject() | |
private val localDataSource: PostDao by inject() | |
private val httpClient: OkHttpClient by inject() | |
private val gson: Gson by inject() | |
private var nextPageUrl: String? = null | |
override fun onZeroItemsLoaded() { |
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 PostRepository { | |
fun fetchFeeds(): Completable | |
fun getFeeds(): Observable<List<Post>> | |
} | |
class PostRepositoryImpl : PostRepository { | |
private val remoteDataSource: PostApiService by inject() | |
private val localDataSource: PostDao by inject() |
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 PostApiService { | |
@GET("/feed") | |
fun getFeed(): Single<Response<List<Post>>> | |
} | |
@Dao | |
interface PostDao { | |
@Insert(onConflict = OnConflictStrategy.IGNORE) | |
fun insert(post: Post): Long |
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
@Entity | |
data class Post( | |
@PrimaryKey | |
@SerializedName("id") | |
val id: String, | |
@SerializedName("sender") | |
@ColumnInfo | |
val sender: String?, | |
@SerializedName("caption") | |
@ColumnInfo |
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 Location( | |
val name: String, | |
val lat: Double, | |
val lng: Double | |
) | |
enum class PostType { | |
TEXT, | |
PHOTO, | |
VIDEO, |
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 FeedViewModel : ViewModel(), KoinComponent { | |
private val repo: PostRepository by inject() | |
fun getFeeds(): Observable<PagedList<Post>> = repo.getFeeds() | |
} | |
class FeedActivity : BaseActivity() { | |
private lateinit var list: RecyclerView | |
private val adapter = FeedAdapter() | |
private val viewModel by viewModel<FeedViewModel>() |
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 PostRepository { | |
fun getFeeds(): Observable<PagedList<Post>> | |
} | |
class PostRepositoryImpl : PostRepository { | |
override fun getFeeds(): Observable<PagedList<Post>> { | |
val dataSource = PostPagingDataSourceFactory() | |
val pagedListConfig = PagedList.Config.Builder() | |
.setPageSize(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
class PostPagingDataSource : PageKeyedDataSource<String, Post>(), KoinComponent { | |
private val api: PostApiService by inject() | |
private val httpClient: OkHttpClient by inject() | |
private val gson: Gson by inject() | |
override fun loadInitial( | |
params: LoadInitialParams<String>, | |
callback: LoadInitialCallback<String, Post> | |
) { |
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 Post( | |
@SerializedName("id") | |
val id: String, | |
@SerializedName("sender") | |
val sender: String?, | |
@SerializedName("caption") | |
val caption: String?, | |
@SerializedName("media") | |
val media: String?, | |
@SerializedName("timestamp") |