package com.gh.common.util; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.text.TextUtils; import com.gh.common.avoidcallback.Callback; import com.gh.gamecenter.LoginActivity; import com.gh.gamecenter.manager.UserManager; import com.lightgame.utils.Utils; import org.jetbrains.annotations.Nullable; /** * Created by khy on 28/06/17. */ public class CheckLoginUtils { public static void checkLogin(final Context context, String entrance, OnLoginListener listener) { if (!isLogin()) { if (listener != null) Utils.toast(context, "需要登录"); LogUtils.login("dialog", null, entrance); LogUtils.login("activity", null, entrance); if (NetworkUtils.isOpenMobileData(context)) { QuickLoginHelper.startLogin(context, entrance); } else { // 有可能App未启动 Bundle bundle = new Bundle(); bundle.putString(EntranceUtils.KEY_ENTRANCE, entrance); bundle.putString(EntranceUtils.KEY_TO, LoginActivity.class.getName()); EntranceUtils.jumpActivity(context, bundle); } } else { if (listener != null) { listener.onLogin(); } } } public static void checkLogin(final Context context, Bundle nextToBundle, boolean isTriggerNextStep, String entrance, OnLoginListener listener) { if (!isLogin()) { if (listener != null) Utils.toast(context, "需要登录"); LogUtils.login("dialog", null, entrance); LogUtils.login("activity", null, entrance); // 有可能App未启动 Bundle bundle = new Bundle(); bundle.putString(EntranceUtils.KEY_ENTRANCE, entrance); bundle.putString(EntranceUtils.KEY_TO, LoginActivity.class.getName()); EntranceUtils.jumpActivity(context, nextToBundle, bundle, (resultCode, data) -> { if (isTriggerNextStep && listener != null && isLogin()) { listener.onLogin(); } }); } else { if (listener != null) { listener.onLogin(); } } } public static boolean isLogin() { return !TextUtils.isEmpty(UserManager.getInstance().getToken()); } public interface OnLoginListener { void onLogin(); } }