Skip to content

Instantly share code, notes, and snippets.

View ericntd's full-sized avatar

Eric Nguyen ericntd

View GitHub Profile
@ericntd
ericntd / lazy-discover.md
Created April 6, 2023 20:32
Faster app start scop 3 - Lazy discover

DiscoverFeedMainInteractor

@Override
  protected void didBecomeActive() {
    super.didBecomeActive();
    discoverBagelRefreshStream = BehaviorSubject.create();
    discoverManager.addGiveTakeItemEventListener(this);
    /*
    If something goes wrong witht the download of GiveTakes & RisingGiveTakes,
    discoverMatchRepository.getGiveTakesDownloaded() will never return
@ericntd
ericntd / Chats.md
Last active April 4, 2023 18:35
App start scope 3 - lazy chats

GetBagelConnectionUseCase

operator fun invoke(): Flowable<List<ConnectionHolder>> {
        return Flowables.zip(
            subscriptionRepository.getActiveSubscription(),
            likesYouMatchCountRepository.getLocalCount()
        )
        .firstOrError()
        .map { pair ->
            val result = mutableListOf<ConnectionHolder>()
@ericntd
ericntd / ManagerSync.md
Created April 4, 2023 12:58
App start scope 3 - ManagerSync
private void startSyncRunnable(QueuedSync queuedSync) {
    //...

    featureFlagRepository.refresh(true)
            .subscribe(() -> {
              if (featureFlagRepository.isEnabled(FeatureConstants.FASTER_APP_START)) {
                long startTime = System.currentTimeMillis();
                List<Completable> completableList = new ArrayList<>();
                completableList.add(priceRepository.refresh());
@ericntd
ericntd / QnaDao_Impl.java
Created January 12, 2023 21:33
Room @relation auto-generated code
@Override
public Flow<List<QuestionWithRelations>> readMcqAnswers1() {
final String _sql = "SELECT * FROM question";
final RoomSQLiteQuery _statement = RoomSQLiteQuery.acquire(_sql, 0);
return CoroutinesRoom.createFlow(__db, false, new String[]{"option","answer","question"}, new Callable<List<QuestionWithRelations>>() {
@Override
public List<QuestionWithRelations> call() throws Exception {
final Cursor _cursor = DBUtil.query(__db, _statement, true, null);
try {
final int _cursorIndexOfId = CursorUtil.getColumnIndexOrThrow(_cursor, "question_id");
@ericntd
ericntd / late-injection-constructor-input-stream.md
Created January 18, 2022 16:26
Late injection through constructor input streams
class MatchPresentationLogics(
    private val bagel: Bagel,
    private val banState: Observable<BanState>
) {
   init {
       banState.subscribe {
           // do what's necessary
       }
 }
@ericntd
ericntd / DependencyHolderExample.kt
Created January 6, 2022 20:18
Dependency instead of Module example
@DependencyHolder
class CatDependencyHolder {
@Provides
@AppScope
fun retrofit(): Retrofit {
return Retrofit.Builder()
.baseUrl(BuildConfig.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build()
@ericntd
ericntd / RequestDependencyExample.kt
Created January 6, 2022 20:17
RequestDependency instead of Inject example
class MainActivity : AppCompatActivity(), MainView {
@RequestDependency
lateinit var presenter: MainPresenter
@ericntd
ericntd / ContributeExample.kt
Created January 6, 2022 20:15
Contribute instead of Inject example
@AppScope
class CatRepository @Contribute constructor(private val api: CatApi) {
fun getCat(): Single<CatResponse> {
return api.getCat()
.subscribeOn(Schedulers.io())
}
}
@ericntd
ericntd / InjectorExample.kt
Created January 6, 2022 20:13
Injector instead of Component example
@Injector(modules = [CatDependencyHolder::class, ContextDependencyHolder::class])
@AppScope
interface MyAppInjector {
// aka. plus
fun plusMainActivityInjector(mainActivityDependencyHolder: MainActivityInjector.MainActivityDependencyHolder): MainActivityInjector
}
@ericntd
ericntd / AppScopeExample.kt
Created January 6, 2022 20:11
AppScope example
@DependencyHolder
class CatDependencyHolder {
@Provides
@AppScope
fun retrofit(): Retrofit {
return Retrofit.Builder()
.baseUrl(BuildConfig.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build()