diff --git a/app/src/main/java/com/gh/common/util/LoginUtils.java b/app/src/main/java/com/gh/common/util/LoginUtils.java index 2249a6dc63..7b5b75951f 100644 --- a/app/src/main/java/com/gh/common/util/LoginUtils.java +++ b/app/src/main/java/com/gh/common/util/LoginUtils.java @@ -184,15 +184,14 @@ public class LoginUtils { } saveLoginToken(context, response); - if (loginTag == LoginTag.oldUserPhone) { - SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); - String syncDeviceID = sp.getString("syncDeviceID", null); - if (!TextUtils.isEmpty(syncDeviceID)) { - syncUserData(context, syncDeviceID, listener, loginTag); - return; - } + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); + String syncDeviceID = sp.getString("syncDeviceID", null); + if (!loginTag.equals(LoginTag.refresh) && !TextUtils.isEmpty(syncDeviceID)) { + syncUserData(context, syncDeviceID, listener, loginTag); + sp.edit().putString("syncDeviceID", null).apply(); // 清空 + } else { + getUserData(context, listener, loginTag); } - getUserData(context, listener, loginTag); } @Override @@ -216,6 +215,7 @@ public class LoginUtils { Utils.toast(context, context.getString(R.string.login_failure_hint)); } } catch (Exception e1) { + Utils.toast(context, context.getString(R.string.login_failure_hint)); e1.printStackTrace(); } cleanUserData(context); @@ -223,41 +223,25 @@ public class LoginUtils { }); } - private static void syncUserData(final Context context, String syncDeviceID - , final onLoginCallBackListener listener, final LoginTag loginTag) { + private static void syncUserData(final Context context, String syncDeviceID, + final onLoginCallBackListener listener, + final LoginTag loginTag) { + + String loginType; + if (LoginTag.phone.equals(loginTag)) { + loginType = "mobile"; + } else { + loginType = loginTag.toString(); + } HashMap map = new HashMap<>(); map.put("device_id", syncDeviceID); + map.put("login_type", loginType); RequestBody body = RequestBody.create(MediaType.parse("application/json"), new JSONObject(map).toString()); RetrofitManager.getInstance(context).getApi().syncUserData(body) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response() { - @Override - public void onResponse(ResponseBody response) { - super.onResponse(response); - getUserData(context, listener, loginTag); - } - - @Override - public void onFailure(HttpException e) { - super.onFailure(e); -// if (e == null) { -// Utils.toast(context, "请检查网络是否可用"); -// return; -// } -// try { -// ResponseBody responseBody = e.response().errorBody(); -// String string = responseBody.string(); -// JSONObject content = new JSONObject(string); -// int code = content.getInt("code"); -// outputErrorHint(context, code); -// } catch (Exception e1) { -// e1.printStackTrace(); -// } - getUserData(context, listener, loginTag); - } - }); + .subscribe(userInfoResponse(context, loginTag, listener)); } // 注销登录 @@ -282,19 +266,6 @@ public class LoginUtils { super.onFailure(e); cleanUserData(context); listener.onCompleted(); -// if (e == null) { -// Utils.toast(context, "请检查网络是否可用"); -// return; -// } -// try { -// ResponseBody responseBody = e.response().errorBody(); -// String string = responseBody.string(); -// JSONObject content = new JSONObject(string); -// int code = content.getInt("code"); -// outputErrorHint(context, code); -// } catch (Exception e1) { -// e1.printStackTrace(); -// } } }); } @@ -334,43 +305,50 @@ public class LoginUtils { } } + private static Response userInfoResponse(final Context context, + final LoginTag loginTag, + final onLoginCallBackListener listener) { + return new Response() { + @Override + public void onResponse(UserInfoEntity response) { + super.onResponse(response); + + saveUserInfo(context, response); + if (listener != null) { + listener.onLogin(response, loginTag); + } + + if (loginTag != null && !LoginTag.refresh.equals(loginTag)) { + Utils.toast(context, "登录成功"); + } + } + + @Override + public void onFailure(HttpException e) { + super.onFailure(e); + if (listener != null) { + listener.onLoginFailure(); + } + if (loginTag != null) { + Utils.toast(context, context.getString(R.string.login_failure_hint)); + } + if (loginTag != null && loginTag.equals(LoginTag.qq)) { + GetLoginDataUtils.getInstance(context).QQLogout(); + } + cleanUserData(context); + } + }; + } + // 获取用户信息 public static void getUserData(final Context context, final onLoginCallBackListener listener, final LoginTag loginTag) { + RetrofitManager.getInstance(context) .getApi() .getUserInfo() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response() { - @Override - public void onResponse(UserInfoEntity response) { - super.onResponse(response); - - saveUserInfo(context, response); - if (listener != null) { - listener.onLogin(response, loginTag); - } - - if (loginTag != null && !LoginUtils.LoginTag.refresh.equals(loginTag)) { - Utils.toast(context, "登录成功"); - } - } - - @Override - public void onFailure(HttpException e) { - super.onFailure(e); - if (listener != null) { - listener.onLoginFailure(); - } - if (loginTag != null) { - Utils.toast(context, context.getString(R.string.login_failure_hint)); - } - if (loginTag != null && loginTag.equals(LoginTag.qq)) { - GetLoginDataUtils.getInstance(context).QQLogout(); - } - cleanUserData(context); - } - }); + .subscribe(userInfoResponse(context, loginTag, listener)); } // 获取本地缓存用户信息 @@ -677,6 +655,7 @@ public class LoginUtils { // 登录回调 public interface onLoginCallBackListener { void onLogin(UserInfoEntity entity, LoginTag loginTag); + void onLoginFailure(); } } diff --git a/app/src/main/java/com/gh/gamecenter/FileReceiverActivity.java b/app/src/main/java/com/gh/gamecenter/FileReceiverActivity.java index 21eca58e80..c5f9debd9b 100644 --- a/app/src/main/java/com/gh/gamecenter/FileReceiverActivity.java +++ b/app/src/main/java/com/gh/gamecenter/FileReceiverActivity.java @@ -26,6 +26,7 @@ import com.gh.common.util.DialogUtils; import com.gh.common.util.PackageUtils; import com.gh.common.util.StringUtils; import com.gh.common.util.UserIconUtils; +import com.gh.common.view.VerticalItemDecoration; import com.gh.gamecenter.adapter.FileReceiverAdapter; import com.gh.gamecenter.adapter.FileReceiverAdapter.OnReceiverCancelListener; import com.gh.gamecenter.eventbus.EBDownloadChanged; @@ -272,6 +273,7 @@ public class FileReceiverActivity extends BaseActivity implements OnReceiverCanc mFileReceiverAdapter = new FileReceiverAdapter(this, this, mFileInfos); mReceiverRv.setLayoutManager(new LinearLayoutManager(this)); + mReceiverRv.addItemDecoration(new VerticalItemDecoration(this, 8, true)); mReceiverRv.setAdapter(mFileReceiverAdapter); diff --git a/app/src/main/java/com/gh/gamecenter/FileSenderActivity.java b/app/src/main/java/com/gh/gamecenter/FileSenderActivity.java index fc8c6e36ea..dace8f6383 100644 --- a/app/src/main/java/com/gh/gamecenter/FileSenderActivity.java +++ b/app/src/main/java/com/gh/gamecenter/FileSenderActivity.java @@ -18,16 +18,17 @@ import android.widget.RelativeLayout; import android.widget.TextView; import com.facebook.drawee.view.SimpleDraweeView; -import com.halo.assistant.HaloApp; import com.gh.base.BaseActivity; import com.gh.common.util.DialogUtils; import com.gh.common.util.UserIconUtils; -import com.lightgame.utils.Utils; +import com.gh.common.view.VerticalItemDecoration; import com.gh.gamecenter.adapter.FileSenderAdapter; import com.gh.gamecenter.kuaichuan.Constant; import com.gh.gamecenter.kuaichuan.FileInfo; import com.gh.gamecenter.kuaichuan.FileSender; import com.gh.gamecenter.kuaichuan.WifiMgr; +import com.halo.assistant.HaloApp; +import com.lightgame.utils.Utils; import org.json.JSONObject; @@ -182,6 +183,7 @@ public class FileSenderActivity extends BaseActivity implements FileSenderAdapte mFileSenderList = new ArrayList<>(); mSenderAdapter = new FileSenderAdapter(this, this, mFileInfos); mSenderRv.setLayoutManager(new LinearLayoutManager(this)); + mSenderRv.addItemDecoration(new VerticalItemDecoration(this, 8, true)); mSenderRv.setAdapter(mSenderAdapter); init(); diff --git a/app/src/main/java/com/gh/gamecenter/entity/ApkEntity.kt b/app/src/main/java/com/gh/gamecenter/entity/ApkEntity.kt index c944d6f0ab..23d10c9298 100644 --- a/app/src/main/java/com/gh/gamecenter/entity/ApkEntity.kt +++ b/app/src/main/java/com/gh/gamecenter/entity/ApkEntity.kt @@ -28,6 +28,7 @@ class ApkEntity : Parcelable { var order: Int = 0 + @SerializedName("active") var isActive = true fun getPlatform(): String? { diff --git a/app/src/main/java/com/gh/gamecenter/entity/GameEntity.kt b/app/src/main/java/com/gh/gamecenter/entity/GameEntity.kt index 2c0d97b577..5bed33f544 100644 --- a/app/src/main/java/com/gh/gamecenter/entity/GameEntity.kt +++ b/app/src/main/java/com/gh/gamecenter/entity/GameEntity.kt @@ -3,7 +3,6 @@ package com.gh.gamecenter.entity import android.os.Parcel import android.os.Parcelable import android.support.v4.util.ArrayMap -import com.gh.common.util.AppDebugConfig import com.google.gson.annotations.SerializedName import com.lightgame.download.DownloadEntity import java.util.* @@ -51,7 +50,6 @@ class GameEntity : Parcelable { @SerializedName("libao_exists") var isLibaoExists: Boolean = false - var isActive: Boolean = false @SerializedName("server_type") var serverType: String? = null @@ -60,8 +58,6 @@ class GameEntity : Parcelable { var kaifuTimeHint: Long? = null - var isShowTop: Boolean = false - //TODO 处理getapk.get(0)的问题,蛋疼 fun getApk(): ArrayList { if (apk == null) { @@ -144,11 +140,9 @@ class GameEntity : Parcelable { dest.writeByte(if (this.isNewsExists) 1.toByte() else 0.toByte()) dest.writeString(this.downloadOffText) dest.writeByte(if (this.isLibaoExists) 1.toByte() else 0.toByte()) - dest.writeByte(if (this.isActive) 1.toByte() else 0.toByte()) dest.writeString(this.serverType) dest.writeParcelable(this.serverEntity, flags) dest.writeValue(this.kaifuTimeHint) - dest.writeByte(if (this.isShowTop) 1.toByte() else 0.toByte()) } constructor() @@ -178,11 +172,9 @@ class GameEntity : Parcelable { this.isNewsExists = `in`.readByte().toInt() != 0 this.downloadOffText = `in`.readString() this.isLibaoExists = `in`.readByte().toInt() != 0 - this.isActive = `in`.readByte().toInt() != 0 this.serverType = `in`.readString() this.serverEntity = `in`.readParcelable(KaiFuServerEntity::class.java.classLoader) this.kaifuTimeHint = `in`.readValue(Long::class.java.classLoader) as Long? - this.isShowTop = `in`.readByte().toInt() != 0 } companion object { diff --git a/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java b/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java index 61c29fc5d1..10335343f4 100644 --- a/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java +++ b/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java @@ -423,7 +423,7 @@ public interface ApiService { */ @Headers({"Content-Type: application/json", "Accept: application/json"}) @POST("user/sync") - Observable syncUserData(@Body RequestBody body); + Observable syncUserData(@Body RequestBody body); /** * 获取用户信息(头像/用户名) diff --git a/gradle.properties b/gradle.properties index 5228b75f57..8907d95496 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,7 +19,7 @@ org.gradle.parallel=true # channel packages channel_file=channel.txt -PATCH_VERSION_NAME=3.0.1 +PATCH_VERSION_NAME=3.0.0 # Third-party keys DEBUG_UMENG_APPKEY=58e5b0b9c62dca35a00005e6