V3.0 10-12汇总, 优化我的关注和登录页面

This commit is contained in:
kehaoyuan
2017-10-13 16:54:37 +08:00
parent dfe087e702
commit dc535ddb38
16 changed files with 80 additions and 98 deletions

View File

@ -4,6 +4,7 @@ import android.app.Application;
import com.facebook.stetho.Stetho;
import com.facebook.stetho.okhttp3.StethoInterceptor;
import com.lightgame.utils.Utils;
import com.squareup.leakcanary.LeakCanary;
import okhttp3.OkHttpClient;
@ -34,11 +35,33 @@ public class Injection {
}
public static OkHttpClient.Builder provideRetrofitBuilder() {
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
@Override
public void log(String message) {
//分段打印retrofit日志
if (message.startsWith("{") || message.startsWith("["))
if (message.length() > 4000) {
for (int i = 0; i < message.length(); i += 4000) {
if (i + 4000 < message.length())
Utils.log("OkHttp_Body::" + i, message.substring(i, i + 4000));
else
Utils.log("OkHttp_Body::" + i, message.substring(i, message.length()));
}
} else
Utils.log("OkHttp_Body::", message);
}
});
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder builder = new OkHttpClient.Builder();
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BASIC);
builder.addNetworkInterceptor(interceptor);
builder.addNetworkInterceptor(new StethoInterceptor());
if (BuildConfig.DEBUG) {
builder.addNetworkInterceptor(loggingInterceptor);
}
return builder;
}

View File

@ -42,7 +42,7 @@ public class AppUncaughtHandler implements UncaughtExceptionHandler {
@Override
public void run() {
Looper.prepare();
Utils.toastLong(mContext.getApplicationContext(), "\"光环助手\"发生错误");
Utils.toast(mContext.getApplicationContext(), "\"光环助手\"发生错误");
Looper.loop();
}
});

View File

@ -7,18 +7,14 @@ import android.view.View;
import com.gh.gamecenter.R;
import com.lightgame.BaseAppCompatActivity;
import com.lightgame.ToolbarContainer;
import com.lightgame.ToolbarController;
import com.readystatesoftware.systembartint.SystemBarTintManager;
/**
* Created by csheng on 15-10-12.
*/
@ToolbarContainer
public abstract class BaseAppCompatToolBarActivity extends BaseAppCompatActivity implements ToolbarController {
public abstract class BaseAppCompatToolBarActivity extends BaseAppCompatActivity {
private Toolbar mToolbar;
private SystemBarTintManager mTintManager;
@Override
@ -47,23 +43,4 @@ public abstract class BaseAppCompatToolBarActivity extends BaseAppCompatActivity
protected abstract boolean onNavigationIconClicked();
@Override
public void setNavigationTitle(int res) {
if (mToolbar != null) {
mToolbar.setTitle(res);
}
}
@Override
public void setNavigationTitle(CharSequence res) {
if (mToolbar != null) {
mToolbar.setTitle(res);
}
}
@Override
public Toolbar getToolBar() {
return mToolbar;
}
}

View File

@ -3,9 +3,7 @@ package com.gh.base.fragment;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v4.app.Fragment;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -14,7 +12,6 @@ import com.gh.base.OnListClickListener;
import com.gh.base.OnRequestCallBackListener;
import com.gh.common.util.EntranceUtils;
import com.gh.gamecenter.eventbus.EBMiPush;
import com.lightgame.ToolbarController;
import com.lightgame.utils.RuntimeUtils;
import com.lightgame.utils.Utils;
@ -32,7 +29,7 @@ import rx.schedulers.Schedulers;
* Fragment 基类
*/
public abstract class BaseFragment<T> extends Fragment implements OnRequestCallBackListener<T>,
View.OnClickListener, ToolbarController, OnListClickListener{
View.OnClickListener, OnListClickListener{
// TODO private view
protected View view;
@ -70,28 +67,6 @@ public abstract class BaseFragment<T> extends Fragment implements OnRequestCallB
RuntimeUtils.getInstance().runOnUiThread(runnable, delayMillis);
}
@Override
public void setNavigationTitle(@StringRes int res) {
if (getActivity() instanceof ToolbarController) {
((ToolbarController) getActivity()).setNavigationTitle(res);
}
}
@Override
public void setNavigationTitle(CharSequence res) {
if (getActivity() instanceof ToolbarController) {
((ToolbarController) getActivity()).setNavigationTitle(res);
}
}
@Override
public Toolbar getToolBar() {
if (getActivity() instanceof ToolbarController) {
return ((ToolbarController) getActivity()).getToolBar();
}
return null;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

View File

@ -235,12 +235,12 @@ public class GetLoginDataUtils {
@Override
public void cancel() {
Utils.toastLong(mContext, "取消授权");
Utils.toast(mContext, "取消授权");
}
@Override
public void onFailure(WbConnectErrorMessage errorMessage) {
Utils.toastLong(mContext, "微博登录需要客户端支持,请先安装微博");
Utils.toast(mContext, "微博登录需要客户端支持,请先安装微博");
}
}

View File

@ -262,7 +262,7 @@ public class LibaoUtils {
if (status.equals("repeatLing")) {
DialogUtils.showWarningDialog(context, "礼包刷新提醒"
, "礼包每天0点刷新换新区或者换新角色需要继续领取礼包的童鞋请于明天0点之后回来即可[再领一个]"
, "知道了", null, null, null);
, null, "知道了", null, null);
} else {
libaoLing(context, libaoBtn, libaoEntity, adapter, isInstallRequired, null, entrance);
}

View File

@ -219,9 +219,13 @@ public class LoginUtils {
LoginUtils.cleanUserData(context);
} else {
Utils.toast(context, context.getString(R.string.login_failure_hint));
if (loginTag.equals(LoginTag.qq)) {
GetLoginDataUtils.getInstance(context).QQLogout();
if (loginTag.equals(LoginTag.phone)) {
outputErrorHint(context, code);
} else {
if (loginTag.equals(LoginTag.qq)) {
GetLoginDataUtils.getInstance(context).QQLogout();
}
Utils.toast(context, context.getString(R.string.login_failure_hint));
}
}
} catch (Exception e1) {

View File

@ -32,6 +32,8 @@ import com.gh.gamecenter.personal.PersonalFragment;
import com.kyleduo.switchbutton.SwitchButton;
import com.lightgame.download.FileUtils;
import com.lightgame.utils.Utils;
import com.tencent.bugly.beta.Beta;
import com.tencent.bugly.beta.UpgradeInfo;
import org.greenrobot.eventbus.EventBus;
@ -259,6 +261,18 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
fontSize();
break;
case setting_rl_about:
if (BuildConfig.DEBUG) {
Beta.checkUpgrade(); // 手动检查热补丁
mSettingLoginType.postDelayed(new Runnable() {
@Override
public void run() {
UpgradeInfo upgradeInfo = Beta.getUpgradeInfo();
if (upgradeInfo != null) {
toast("补丁包大小:" + upgradeInfo.fileSize);
}
}
}, 5000);
}
startActivity(AboutActivity.getIntent(this));
break;
case R.id.setting_rl_concerngame:

View File

@ -92,15 +92,19 @@ public class ConcernRecommendAdapter extends BaseRecyclerAdapter<ConcernViewHold
.subscribe(new Response<List<GameEntity>>() {
@Override
public void onResponse(List<GameEntity> response) {
for (GameEntity gameEntity : response) {
ApkActiveUtils.filterHideApk(gameEntity);
for (int i = 0, size = mRecommendGameList.size(); i < size; i++) { // 过滤已安装游戏(init() 已经获取)
if (gameEntity.getId().equals(mRecommendGameList.get(i).getId())) {
break;
} else if (i + 1 == size) {
mRecommendGameList.add(gameEntity);
if (mRecommendGameList != null && mRecommendGameList.size() > 0) {
for (GameEntity gameEntity : response) {
ApkActiveUtils.filterHideApk(gameEntity);
for (int i = 0, size = mRecommendGameList.size(); i < size; i++) { // 过滤已安装游戏(init() 已经获取)
if (gameEntity.getId().equals(mRecommendGameList.get(i).getId())) {
break;
} else if (i + 1 == size) {
mRecommendGameList.add(gameEntity);
}
}
}
} else {
mRecommendGameList.addAll(response);
}
if (mConcernGameList != null) { // 过滤已关注的游戏

View File

@ -75,12 +75,6 @@ public class LibaoFragment extends BaseFragment_ViewPager_Checkable {
setHasOptionsMenu(true);
}
@Override
public void onResume() {
super.onResume();
setNavigationTitle(R.string.personal_libao);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);

View File

@ -17,6 +17,7 @@ import android.widget.TextView;
import com.gh.base.fragment.BaseFragment;
import com.gh.common.util.DialogUtils;
import com.gh.common.util.GetLoginDataUtils;
import com.gh.common.util.LoginUtils;
import com.gh.common.util.PatternUtils;
import com.gh.gamecenter.R;
@ -38,7 +39,7 @@ import butterknife.BindView;
*/
public abstract class BaseLoginFragment extends BaseFragment implements LoginUtils.onCaptchaCallBackListener
,LoginUtils.onLoginCallBackListener, View.OnClickListener {
, LoginUtils.onLoginCallBackListener, GetLoginDataUtils.OnLoginDataListener, View.OnClickListener {
@BindView(R.id.login_phone_et)
EditText mLoginPhoneEt;
@ -157,7 +158,7 @@ public abstract class BaseLoginFragment extends BaseFragment implements LoginUti
} else {
phone = LoginUtils.LoginTag.phone;
}
LoginUtils.login(getActivity(), new JSONObject(params), phone, this);
OnLoginData(new JSONObject(params), phone);
}
@ -178,6 +179,13 @@ public abstract class BaseLoginFragment extends BaseFragment implements LoginUti
}
}
/**
* {@link LoginFragment#OnLoginData}
*/
@Override
public void OnLoginData(JSONObject content, LoginUtils.LoginTag loginTag) {
}
@Override
public void onLogin(UserInfoEntity entity, LoginUtils.LoginTag loginTag) { // 登录成功
Utils.log("======登录成功" + entity.getIcon() + "==" + entity.getName());

View File

@ -19,7 +19,7 @@ import butterknife.OnClick;
* Created by khy on 14/08/17.
*/
public class LoginFragment extends BaseLoginFragment implements GetLoginDataUtils.OnLoginDataListener {
public class LoginFragment extends BaseLoginFragment {
@BindView(R.id.login_qq_btn)
LinearLayout mLoginQqBtn;

View File

@ -7,14 +7,12 @@ import com.gh.gamecenter.Injection;
import com.gh.gamecenter.retrofit.service.ApiService;
import com.gh.gamecenter.retrofit.service.DataService;
import com.gh.gamecenter.retrofit.service.UserseaService;
import com.lightgame.utils.Utils;
import java.io.File;
import java.util.concurrent.TimeUnit;
import okhttp3.Cache;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
@ -40,28 +38,11 @@ public class RetrofitManager {
}
private RetrofitManager(Context context) {
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
@Override
public void log(String message) {
//分段打印retrofit日志
if(message.length() > 4000) {
for(int i=0;i<message.length();i+=4000){
if(i+4000<message.length())
Utils.log("RetrofitLog::"+i,message.substring(i, i+4000));
else
Utils.log("RetrofitLog::"+i,message.substring(i, message.length()));
}
} else
Utils.log("RetrofitLog::",message);
}
});
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
final Cache cache = new Cache(new File(OkHttpCache.getCachePath(context)), 10 * 1024 * 1024); // 10Mb
final OkHttpClient okHttpClient = Injection.provideRetrofitBuilder()
.addInterceptor(new OkHttpCacheInterceptor(context))
.addInterceptor(new OkHttpRetryInterceptor(context))
.addInterceptor(loggingInterceptor)
.addNetworkInterceptor(new OkHttpNetworkInterceptor(context))
.connectTimeout(8, TimeUnit.SECONDS)
.cache(cache)

View File

@ -55,14 +55,14 @@ public interface UserseaService {
* 刷新accessToken
*/
@Headers({"Content-Type: application/json", "Accept: application/json"})
@POST("refresh")
@POST("tokens/refresh")
Observable<LoginResponseEntity> refreshToken(@Body RequestBody body);
/**
* 修改用户信息
*/
@Headers({"Content-Type: application/json", "Accept: application/json"})
@PATCH("meta")
@PATCH("users/meta")
Observable<ResponseBody> changeUserInfo(@Body RequestBody body);
/**

View File

@ -90,6 +90,8 @@
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_marginBottom = "8dp"
android:paddingBottom="15dp"
android:paddingTop="15dp"
android:layout_marginLeft = "8dp"
android:layout_marginRight = "8dp"
android:background = "@drawable/reuse_listview_item_style"

View File

@ -88,7 +88,7 @@
android:layout_height = "wrap_content"
android:layout_marginTop = "14dp"
android:text = "@string/QQ"
android:textSize="15sp"
android:textSize="14sp"
android:textColor = "@color/title" />
</LinearLayout >
@ -128,7 +128,7 @@
android:layout_height = "wrap_content"
android:layout_marginTop = "14dp"
android:text = "@string/wechat"
android:textSize="15sp"
android:textSize="14sp"
android:textColor = "@color/title" />
</LinearLayout >
@ -169,7 +169,7 @@
android:layout_height = "wrap_content"
android:layout_marginTop = "14dp"
android:text = "@string/sina_weibo"
android:textSize="15sp"
android:textSize="14sp"
android:textColor = "@color/title" />
</LinearLayout >
</LinearLayout >