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 PersonageRepository( | |
private val api: RickNMortyApi | |
) { | |
override fun getPersonages(): Flow<PagingData<CharacterUi>> { | |
return Pager( | |
config = PagingConfig(pageSize = 20, maxSize = 500), | |
pagingSourceFactory = { PersonageDataSource(api) } | |
).flow | |
} |
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 PersonageDataSource( | |
private val api: RickNMortyApi | |
) : PagingSource<Int, CharacterUi>() { | |
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, CharacterUi> { | |
return try { | |
val result = api.getCharacters(params.key ?: STARTING_PAGE_INDEX).toCharacters() | |
Page( | |
data = result, | |
prevKey = params.key, | |
nextKey = params.key?.plus(1) ?: STARTING_PAGE_INDEX.plus(1) |
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
interface RickNMortyApi { | |
@GET("api/character/") | |
suspend fun getCharacters(@Query("page") page: Int): CharacterResult | |
} |
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
import androidx.recyclerview.widget.RecyclerView | |
import android.view.LayoutInflater | |
import android.view.View | |
import android.view.ViewGroup | |
import android.view.View.OnClickListener | |
import androidx.recyclerview.widget.DiffUtil | |
import androidx.recyclerview.widget.ListAdapter | |
class MyAdapter( | |
private val click: () -> Unit |
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
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME}#end | |
import androidx.recyclerview.widget.RecyclerView | |
import android.view.LayoutInflater | |
import android.view.View | |
import android.view.ViewGroup | |
import android.view.View.OnClickListener | |
import androidx.recyclerview.widget.DiffUtil | |
import androidx.recyclerview.widget.ListAdapter |
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
def paging_version = "3.0.0-alpha07" | |
implementation "androidx.paging: paging-runtime:$paging_version" |
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 FragmentB : Fragment() { | |
fun onViewCreated(...) { | |
... | |
... | |
view.setOnClickListener { | |
val uri = Uri.parse("myApp://fragmentD") | |
findNavController().navigate(uri) | |
} | |
} | |
} |
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
implementation project(":featureone") | |
implementation project(":featuretwo") | |
implementation project(":featurethree") |