package com.sunzee.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.google.gson.Gson;
import com.sunzee.R;
import com.sunzee.base.MvpActivity;
import com.sunzee.model.EmailResult;
import com.sunzee.mvp.main.MainPresenter;
import com.sunzee.mvp.main.MainView;

import java.util.HashMap;
import java.util.Map;

/**
 * 由Activity/Fragment实现View里方法，包含一个Presenter的引用
 */
public class MainActivity extends MvpActivity<MainPresenter> implements MainView {
    private TextView text;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        text = findViewById(R.id.text);
        initToolBarAsHome(getString(R.string.title));

    }

    @Override
    protected MainPresenter createPresenter() {
        return new MainPresenter(this);
    }

    @Override
    public void getDataSuccess(HashMap model) {
        text.setText(model.toString());
    }
    @Override
    public void getDataSuccess(EmailResult model) {
        Gson gson = new Gson();

        text.setText( gson.toJson(model));
    }

    @Override
    public void getDataFail(String msg) {
        toastShow(getString(R.string.net_error));

    }


    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.button0:
//                loadDataByRetrofit();
                break;
            case R.id.button1:
                Map<String,String> param = new HashMap<String,String>();
                param.put("toEmail","845717887@qq.com");
                param.put("subject","test");
                param.put("content","你好22");
                mvpPresenter.testEmail(param);
                break;
            case R.id.button2:
                //请求接口
                mvpPresenter.getOrderStatus("4011107220190603145412");
                break;
        }
    }



}
