package com.phlx.anchorcollect.ui.setting;

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.anchorcollect.R;
import com.phlx.anchorcollect.data.VMFactory;
import com.phlx.anchorcollect.databinding.ActivitySyncBinding;
import com.phlx.anchorcollect.ui.base.BaseActivity;

import me.tatarka.bindingcollectionadapter2.BR;

public class SyncActivity extends BaseActivity<ActivitySyncBinding,SyncVM> {
    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_sync;
    }

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

    @Override
    public void initParam() {
        super.initParam();
    }

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

    @Override
    public void initData() {
        super.initData();
    }

    @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();
    }
}
