Skip to content

Instantly share code, notes, and snippets.

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

juliuscanute

💭
I may be slow to respond.
View GitHub Profile
@juliuscanute
juliuscanute / WordListFragment.kt
Created July 10, 2019 00:29
Word List Fragment
class WordListFragment : Fragment() {
//...
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
mainActivityViewModel.words.observe(this, Observer {
meaningAdapter.submitList(it)
})
//...
}
//...
@juliuscanute
juliuscanute / MainActivityViewModel.kt
Created July 10, 2019 00:41
View Model Main Activity
class MainActivityViewModel(//...) :
ViewModel() {
//...
val words: MediatorLiveData<PagedList<Meaning>> = MediatorLiveData()
//...
private fun addAllWordsAndRemoveSearch() {
removeSearchObserver()
if (!mapOfLiveData.containsKey(ALL)) {
mapOfLiveData[ALL] = LivePagedListBuilder(dataSourceFactory, config).build()
@juliuscanute
juliuscanute / DictionaryAllWordsDataSource.kt
Created July 10, 2019 00:49
Dictionary All Words Data Source
class DictionaryAllWordsDataSource(//...) :
PositionalDataSource<Meaning>() {
//...
override fun loadRange(params: LoadRangeParams, callback: LoadRangeCallback<Meaning>) {
//...
val startPage = (params.startPosition / PAGE_SIZE) + 1
if (totalPages >= startPage) {
val words = getWordsFromPage(startPage, startPage)
if (words.isEmpty()) throw NoDataException()
callback.onResult(words)
class DictionaryAllWordsDataSourceFactory(
private val repository: Repository,
private val networkState: MutableLiveData<Event<NetworkMessage>>
) :
DataSource.Factory<Int, Meaning>() {
override fun create(): DataSource<Int, Meaning> {
return DictionaryAllWordsDataSource(repository, networkState)
}
}
@juliuscanute
juliuscanute / build.gradle
Last active July 10, 2019 05:10
Retrofit Dependencies
{
//...
//Backend Services Libraries
implementation 'com.squareup.retrofit2:retrofit:2.2.0'
implementation 'com.squareup.retrofit2:converter-moshi:2.2.0'
//...
}
@juliuscanute
juliuscanute / build.gradle
Created July 10, 2019 05:14
Paging Dependency
{
//...
//Paging Dependency
implementation 'androidx.paging:paging-runtime:2.1.0'
//...
}
@juliuscanute
juliuscanute / AuthorizationInterceptor.kt
Last active April 16, 2020 21:48
[Koin Dependencies] #koin #dependencies #module #interceptor #api #dispatcher #ui #instrumentation #test #espresso
class AuthorizationInterceptor : Interceptor, KoinComponent {
// 2
private val petFinderService: PetFinderService by inject()
private var token = Token()
@Throws(IOException::class)
override fun intercept(chain: Interceptor.Chain): Response {
var mainResponse = chain.proceed(chain.request())
val mainRequest = chain.request()
if ((mainResponse.code() == 401 || mainResponse.code() == 403) && !
mainResponse.request().url().url().toString().contains("oauth2/token")) {
@juliuscanute
juliuscanute / leptonrc
Created August 10, 2019 08:24
[Enable Dark Mode in Lepton] #leptonrc
#~/.leptonrc
{
"theme": "dark"
}
@juliuscanute
juliuscanute / class_example_inheritance.dart
Last active August 10, 2019 08:33
[Creating a class in Dart with Inheritance]#class #dart #inheritance
class $1 extends $2 {
}
//$1 - Class Name
//$2 - Super Class Name
class MyWidget extends StatelessWidget {
}
@juliuscanute
juliuscanute / example_class_constructor.dart
Last active August 10, 2019 08:33
[Creating a constructor within a class] #dart #class #constructor
const $1({p1,p2,...,pn}): assert(condition(p1)),super(p1);
//$1 - Enclosing Class Name.
//p1...pn - Parameters to pass to the constructor.
const MyWidget({Key key,
@required this.name,
@required this.color,
@required this.iconLocation,
}) : assert(name != null),
assert(color != null),