package com.unis.model.login_log;

import android.os.AsyncTask;

import com.unis.model.room.MyDB;
import com.xyxsbj.mylibrary.tool.LogTool;

import java.lang.ref.WeakReference;

/**
 * 获取第一条登录记录
 * 创建人: mQ
 * 创建时间: 2021/2/7 11:05
 */
public class LoginLogFirstTask extends AsyncTask<Void, Void, LogFirst> {

    // 弱引用
    private WeakReference<LoginLogFirstCallback> mCallback;

    public LoginLogFirstTask(LoginLogFirstCallback callback) {
        mCallback = new WeakReference<>(callback);
    }

    @Override
    protected LogFirst doInBackground(Void... voids) {
        LogTool.i("获取第一条登录记录");
        // 获取第一条登录记录
        return MyDB.get().loginDao().getFirst();
    }

    @Override
    protected void onPostExecute(LogFirst loginLog) {
        super.onPostExecute(loginLog);
        LoginLogFirstCallback callback = mCallback.get();
        if (callback != null) {
            callback.onLogFirstListener(loginLog);
        }
    }


    public interface LoginLogFirstCallback {
        void onLogFirstListener(LogFirst loginLog);
    }
}
