package com.phlx.wool.ui.sync.activity;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.phlx.wool.BR;
import com.phlx.wool.R;
import com.phlx.wool.data.VMFactory;
import com.phlx.wool.databinding.ActivityDownloadBinding;
import com.phlx.wool.ui.base.BaseActivity;
import com.phlx.wool.ui.sync.vm.DownloadVM;

/**
 * <pre>
 *     author : lei
 *     e-mail : 18600395998@163.com
 *     time   : 2020/04/29
 *     desc   :
 *     version: 1.0
 * </pre>
 */
public class DownloadActivity extends BaseActivity<ActivityDownloadBinding, DownloadVM> {
    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_download;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }


    @Override
    public DownloadVM initViewModel() {
        VMFactory factory = VMFactory.getInstance(getApplication());
        return ViewModelProviders.of(this, factory).get(DownloadVM.class);
    }

    @Override
    public void initData() {
        super.initData();
        setSupportActionBar(binding.include.toolbar);
        viewModel.initToolbar();
    }

    @Override
    public void initViewObservable() {
        super.initViewObservable();
        viewModel.errorEvent.observe(this, new Observer<String>() {
            @Override
            public void onChanged(String s) {
                showTip(s);
            }
        });
    }

    private void showTip(String content) {
        new MaterialDialog.Builder(this).title("系统信息").content(content)
                .cancelable(false).canceledOnTouchOutside(false)
                .positiveText("退出").onPositive(new MaterialDialog.SingleButtonCallback() {
            @Override
            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                if (which == DialogAction.POSITIVE) {
                    dialog.dismiss();
                    finish();
                }
            }
        }).show();
    }


}
