package io.github.droidkaigi.confsched2017.view.activity;

import android.content.Context;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;

import java.util.Locale;
import java.util.concurrent.TimeUnit;

import javax.inject.Inject;

import io.github.droidkaigi.confsched2017.R;
import io.github.droidkaigi.confsched2017.repository.sessions.MySessionsRepository;
import io.github.droidkaigi.confsched2017.repository.sessions.SessionsRepository;
import io.reactivex.Observable;
import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class SplashActivity extends BaseActivity {

    private static final String TAG = SplashActivity.class.getSimpleName();

    private static final int MINIMUM_LOADING_TIME = 1500;

    @Inject
    CompositeDisposable compositeDisposable;

    @Inject
    SessionsRepository sessionsRepository;

    @Inject
    MySessionsRepository mySessionsRepository;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getComponent().inject(this);
        DataBindingUtil.setContentView(this, R.layout.activity_splash);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            findViewById(android.R.id.content).setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        loadSessionsForCache();
    }

    @Override
    protected void onStop() {
        super.onStop();
        compositeDisposable.dispose();
    }

    private void loadSessionsForCache() {
        Disposable disposable = Single.zip(sessionsRepository.findAll(Locale.getDefault()),
                mySessionsRepository.findAll(),
                delaySingleSource(),
                (sessions, mySessions, obj) -> Observable.empty())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doFinally(() -> {
                    if (isFinishing()) return;
                    startActivity(MainActivity.createIntent(SplashActivity.this));
                })
                .subscribe();
        compositeDisposable.add(disposable);
    }

    private Single<Object> delaySingleSource() {
        return Single.create(e -> e.onSuccess(Observable.empty()))
                .observeOn(AndroidSchedulers.mainThread())
                .delay(MINIMUM_LOADING_TIME, TimeUnit.MILLISECONDS);
    }

}

@@ -2087,34 +2087,72 @@
         
-delay
 Single
-Source(
+.timer(MINIMUM_LOADING_TIME, TimeUnit.MILLISECONDS
 ),%0A     
@@ -2588,257 +2588,6 @@
  %7D%0A%0A
-    private Single%3CObject%3E delaySingleSource() %7B%0A        return Single.create(e -%3E e.onSuccess(Observable.empty()))%0A                .observeOn(AndroidSchedulers.mainThread())%0A                .delay(MINIMUM_LOADING_TIME, TimeUnit.MILLISECONDS);%0A    %7D%0A%0A
 %7D%0A

Change use Single.timer for delay