package com.playground.android_architect_playground.pages.logdetailspage;

import android.arch.lifecycle.LifecycleRegistry;
import android.arch.lifecycle.LifecycleRegistryOwner;
import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;

import com.playground.android_architect_playground.R;
import com.playground.android_architect_playground.database.dao.LogDao;
import com.playground.android_architect_playground.database.entitiy.LogRecord;
import com.playground.android_architect_playground.logger.LogLifecycleObserver;
import com.playground.android_architect_playground.pages.logdetailspage.model.LogDetailViewModel;
import com.playground.android_architect_playground.pages.logdetailspage.presenter.LogDetailsPresenter;
import com.playground.android_architect_playground.pages.logdetailspage.view.LogDetailsCallback;
import com.playground.android_architect_playground.pages.logdetailspage.view.LogDetailsView;

import java.util.List;
import java.util.concurrent.Callable;

import javax.inject.Inject;

import dagger.android.support.DaggerAppCompatActivity;
import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.observers.DisposableSingleObserver;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by petnagy on 2017. 07. 02..
 */

public class LogDetailsActivity extends DaggerAppCompatActivity implements LifecycleRegistryOwner, LogDetailsCallback {

    @Inject
    LogLifecycleObserver logger;

    @Inject
    LifecycleRegistry lifecycleRegistry;

    @Inject
    LogDetailsView view;

    @Inject
    LogDetailsPresenter presenter;

    @Inject
    LogDao logDao;

    private LogDetailViewModel model;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.log_details_activity);
        getLifecycle().addObserver(view);
        getLifecycle().addObserver(logger);
    }

    @Override
    protected void onResume() {
        super.onResume();
        model = ViewModelProviders.of(this).get(LogDetailViewModel.class);
        model.getLogRecords(logDao).observe(this, new Observer<List<LogRecord>>() {
            @Override
            public void onChanged(@Nullable List<LogRecord> logRecords) {
                presenter.showLogRecords(logRecords);
                Log.d("Logger", "load data from model");
            }
        });
    }

    @Override
    public LifecycleRegistry getLifecycle() {
        return lifecycleRegistry;
    }

    public static Intent launchIntent(Context context) {
        return new Intent(context, LogDetailsActivity.class);
    }

    @Override
    public void onFilterChanged(final String filter) {
        model.setFilterValue(filter, logDao);
    }
}

@@ -1123,46 +1123,8 @@
 ist;
-%0Aimport java.util.concurrent.Callable;
 %0A%0Aim
@@ -1208,234 +1208,8 @@
 ity;
-%0Aimport io.reactivex.Single;%0Aimport io.reactivex.android.schedulers.AndroidSchedulers;%0Aimport io.reactivex.annotations.NonNull;%0Aimport io.reactivex.observers.DisposableSingleObserver;%0Aimport io.reactivex.schedulers.Schedulers;
 %0A%0A/*

Simplify with unused imports