package com.yeshi.makemoney.video.app.utils;
|
|
import android.content.Context;
|
import android.content.SharedPreferences;
|
|
import com.google.gson.Gson;
|
import com.google.gson.GsonBuilder;
|
import com.yeshi.makemoney.video.app.MyApplication;
|
import com.yeshi.makemoney.video.app.entity.user.UserInfo;
|
import com.demo.lib.common.util.common.StringUtils;
|
|
import org.apache.http.client.protocol.ClientContextConfigurer;
|
|
import androidx.annotation.Nullable;
|
import io.flutter.plugin.common.MethodChannel;
|
|
import static android.content.Context.MODE_PRIVATE;
|
|
public class UserUtil {
|
|
private static Gson gson = new GsonBuilder().serializeNulls().create();
|
|
|
/**
|
* 是否同意了用户协议
|
*
|
* @param context
|
* @return
|
*/
|
public static boolean isAgreeUserProtocol(Context context) {
|
SharedPreferences sp = context.getSharedPreferences("user", MODE_PRIVATE);
|
String protocol = sp.getString("protocol-agree", "");
|
return !StringUtils.isEmpty(protocol);
|
}
|
|
|
/**
|
* 同意用户协议
|
*
|
* @param context
|
*/
|
public static void agreeUserProtocol(Context context) {
|
SharedPreferences sp = context.getSharedPreferences("user", MODE_PRIVATE);
|
SharedPreferences.Editor editor = sp.edit();
|
editor.putString("protocol-agree", "1");
|
editor.commit();
|
}
|
|
|
/**
|
* 是否登录
|
*
|
* @param context
|
* @return
|
*/
|
public static boolean isLogin(Context context) {
|
if (getUser(context) != null) {
|
return true;
|
}
|
return false;
|
}
|
|
/**
|
* 获取用户信息
|
*
|
* @param context
|
* @return
|
*/
|
public static UserInfo getUser(Context context) {
|
SharedPreferences sharedPreferences = context.getSharedPreferences("flutter", MODE_PRIVATE);
|
String userStr = sharedPreferences.getString("user_info", null);
|
if (StringUtils.isEmpty(userStr)) {
|
return null;
|
}
|
return new Gson().fromJson(userStr, UserInfo.class);
|
}
|
|
/**
|
* 获取用户ID
|
*
|
* @param context
|
* @return
|
*/
|
public static String getUid(Context context) {
|
UserInfo user = getUser(context);
|
if (user == null) {
|
return null;
|
}
|
return user.getId();
|
}
|
|
|
}
|