Commit 6ae24f86 by gao.chao

代码整理

parent dbd4a432
...@@ -40,7 +40,7 @@ public abstract class BaseStartActivity<T extends BaseActivity, T1 extends BaseA ...@@ -40,7 +40,7 @@ public abstract class BaseStartActivity<T extends BaseActivity, T1 extends BaseA
gotoActivityAndFinish(getLoginActivity()); gotoActivityAndFinish(getLoginActivity());
} else { } else {
// 有本地缓存 免登录 直接到首页 // 有本地缓存 免登录 直接到首页
UserManager.getUserInfo(); UserManager.INSTANCE.getUserInfo();
gotoActivityAndFinish(getMainActivity()); gotoActivityAndFinish(getMainActivity());
} }
} }
......
package com.mayi.demo.page; package com.mayi.demo.page
import android.text.TextUtils; import android.text.TextUtils
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON
import com.mayi.fastdevelop.comnon.Key; import com.mayi.fastdevelop.comnon.Key
import com.mayi.fastdevelop.util.SpUtil; import com.mayi.fastdevelop.util.SpUtil
public class UserManager { object UserManager {
private static UserInfo userInfo; private var userInfo: UserInfo? = null
/** /**
* 获取本地的用户信息 * 获取本地的用户信息
* *
* @return 用户信息 * @return 用户信息
*/ */
public static UserInfo getUserInfo() { fun getUserInfo(): UserInfo? {
if (userInfo == null) { if (userInfo == null) {
synchronized (UserManager.class) { synchronized(UserManager::class.java) {
if (userInfo == null) { if (userInfo == null) {
String s = SpUtil.get(Key.USER_INFO, ""); val s = SpUtil.get(Key.USER_INFO, "")
if (!TextUtils.isEmpty(s)) { if (!TextUtils.isEmpty(s)) {
userInfo = JSON.parseObject(s, UserInfo.class); userInfo = JSON.parseObject(s, UserInfo::class.java)
} }
} }
} }
} }
return userInfo; return userInfo
} }
/** /**
...@@ -34,11 +34,11 @@ public class UserManager { ...@@ -34,11 +34,11 @@ public class UserManager {
* *
* @param json * @param json
*/ */
public static void setUserInfo(String json) { fun setUserInfo(json: String) {
if (!TextUtils.isEmpty(json)) { if (!TextUtils.isEmpty(json)) {
synchronized (UserManager.class) { synchronized(UserManager::class.java) {
SpUtil.set(Key.USER_INFO, json); SpUtil.set(Key.USER_INFO, json)
userInfo = JSON.parseObject(json, UserInfo.class); userInfo = JSON.parseObject(json, UserInfo::class.java)
} }
} }
} }
...@@ -48,11 +48,11 @@ public class UserManager { ...@@ -48,11 +48,11 @@ public class UserManager {
* *
* @param userInfo * @param userInfo
*/ */
public static void setUserInfo(UserInfo userInfo) { fun setUserInfo(userInfo: UserInfo?) {
if (userInfo != null) { if (userInfo != null) {
synchronized (UserManager.class) { synchronized(UserManager::class.java) {
SpUtil.set(Key.USER_INFO, JSON.toJSONString(userInfo)); SpUtil.set(Key.USER_INFO, JSON.toJSONString(userInfo))
UserManager.userInfo = userInfo; UserManager.userInfo = userInfo
} }
} }
} }
...@@ -60,10 +60,10 @@ public class UserManager { ...@@ -60,10 +60,10 @@ public class UserManager {
/** /**
* 清除用户信息 * 清除用户信息
*/ */
public static void clearUserInfo() { fun clearUserInfo() {
synchronized (UserManager.class) { synchronized(UserManager::class.java) {
SpUtil.set(Key.USER_INFO, null); SpUtil.set(Key.USER_INFO, null)
userInfo = null; userInfo = null
} }
} }
} }
package com.mayi.fastdevelop.base;
import android.app.Dialog;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import com.mayi.fastdevelop.R;
import com.mayi.fastdevelop.util.LogUtils;
import com.mayi.fastdevelop.util.ToastUtil;
import com.mayi.fastdevelop.view.LoadingDialog;
public class BaseDialogFragment extends DialogFragment {
private String TAG = getClass().getSimpleName();
public void logI(String msg) {
LogUtils.i(TAG + " " + msg);
}
public void showToast(String msg) {
ToastUtil.show(getContext(), msg);
}
private Dialog dialog;
public void showLoading() {
if (dialog == null) {
dialog = LoadingDialog.init(getContext()).setCanTouchOutsideCancel(true).show();
} else {
dialog.setCanceledOnTouchOutside(true);
dialog.setCancelable(true);
dialog.show();
}
}
public void showLoading(boolean canTouchOutsideCancel) {
if (dialog == null) {
dialog = LoadingDialog.init(getContext()).setCanTouchOutsideCancel(canTouchOutsideCancel).show();
} else {
dialog.setCanceledOnTouchOutside(canTouchOutsideCancel);
dialog.setCancelable(canTouchOutsideCancel);
dialog.show();
}
}
public void dismssLoading() {
if (dialog != null) {
dialog.dismiss();
}
}
@Override
public void onDestroyView() {
dismssLoading();
super.onDestroyView();
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(STYLE_NORMAL, R.style.Dialog_FullScreen);
}
}
<resources> <resources>
<style name="Dialog.FullScreen" parent="Theme.AppCompat.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@color/transparent</item>
<item name="android:windowIsFloating">false</item>
</style>
<style name="AppThemeLaunch" parent="AppTheme"> <style name="AppThemeLaunch" parent="AppTheme">
<item name="android:windowBackground">@mipmap/bg_launch</item> <item name="android:windowBackground">@mipmap/bg_launch</item>
<item name="android:windowFullscreen">false</item> <item name="android:windowFullscreen">false</item>
<item name="android:windowNoTitle">true</item> <item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item> <item name="android:windowActionBar">false</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style> </style>
<!-- Base application theme. --> <!-- Base application theme. -->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment