Merge branch 'dev' of gitlab.ghzhushou.com:halo/assistant-android into dev

# Conflicts:
#	app/src/main/java/com/gh/base/AppController.java
This commit is contained in:
kehaoyuan
2017-09-04 10:54:35 +08:00
17 changed files with 190 additions and 581 deletions

View File

@ -16,10 +16,10 @@ import com.gh.common.util.DataUtils;
import com.gh.common.util.StringUtils;
import com.gh.common.util.TokenUtils;
import com.gh.gamecenter.BuildConfig;
import com.gh.gamecenter.Injection;
import com.leon.channel.helper.ChannelReaderUtil;
import com.lightgame.config.CommonDebug;
import com.lightgame.utils.Utils;
import com.squareup.leakcanary.LeakCanary;
import com.umeng.message.IUmengRegisterCallback;
import com.umeng.message.PushAgent;
import com.umeng.message.UTrack;
@ -83,22 +83,12 @@ public class AppController extends MultiDexApplication {
public void onCreate() {
super.onCreate();
if (LeakCanary.isInAnalyzerProcess(this)) {
// This process is dedicated to LeakCanary for heap analysis.
// You should not init your app in this process.
if (!Injection.appInit(this)) {
return;
}
LeakCanary.install(this);
// Normal app init code...
mInstance = this;
//TODO 强烈不建议开发阶段开启这个Handler必须处理错误
// if (!BuildConfig.DEBUG) {
AppUncaughtHandler appUncaughtHandler = new AppUncaughtHandler(this);
Thread.setDefaultUncaughtExceptionHandler(appUncaughtHandler);
// }
mChannel = ChannelReaderUtil.getChannel(this);
if (TextUtils.isEmpty(mChannel)) {
//默认用Android Studio run时并没有写入channel magic number到apk包里面所以需要fallback
@ -216,7 +206,7 @@ public class AppController extends MultiDexApplication {
EventBus.builder().addIndex(new EventBusIndex()).installDefaultEventBus();
// AppTrafficUtils.appTraffic(this); //流量统计
}
}
private boolean shouldInit() {
ActivityManager am = ((ActivityManager) getSystemService(Context.ACTIVITY_SERVICE));

View File

@ -79,9 +79,9 @@ class GameEntity : Parcelable {
}
fun setEntryMap(entryMap: ArrayMap<String, DownloadEntity>?) {
if (AppDebugConfig.IS_DEBUG) {
AppDebugConfig.logMethodWithParams(this, entryMap)
}
// if (AppDebugConfig.IS_DEBUG) {
// AppDebugConfig.logMethodWithParams(this, entryMap)
// }
if (entryMap != null) {
this.entryMap = entryMap
}

View File

@ -4,16 +4,13 @@ import android.content.Context;
import com.gh.base.AppController;
import com.gh.common.constant.Config;
import com.gh.gamecenter.BuildConfig;
import com.gh.gamecenter.Injection;
import java.io.File;
import java.util.concurrent.TimeUnit;
import okhttp3.Cache;
import okhttp3.OkHttpClient;
import okhttp3.OkHttpClient.Builder;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.logging.HttpLoggingInterceptor.Level;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
@ -33,88 +30,37 @@ public class RetrofitManager {
private LibaoService mLibaoService;
private MessageService mMessageService;
private UserseaService mUserseaService;
private Context mContext;
public static <T> T provideService(OkHttpClient client, String url, Class<T> serviceCls) {
return new Retrofit.Builder()
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.baseUrl(url).build().create(serviceCls);
}
private RetrofitManager() {
mContext = AppController.getInstance().getApplicationContext();
final Cache cache = new Cache(new File(OkHttpCache.getCachePath(mContext)), 10 * 1024 * 1024); // 10Mb
final Context context = AppController.getInstance().getApplicationContext();
final Builder builder = new OkHttpClient.Builder();
if (BuildConfig.DEBUG) {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(Level.BASIC);
builder.addNetworkInterceptor(interceptor);
// builder.addNetworkInterceptor(new StethoInterceptor());
}
final Cache cache = new Cache(new File(OkHttpCache.getCachePath(context)), 10 * 1024 * 1024); // 10Mb
final OkHttpClient okHttpClient = builder
.addInterceptor(new OkHttpCacheInterceptor(mContext))
.addInterceptor(new OkHttpRetryInterceptor(mContext))
.addNetworkInterceptor(new OkHttpNetworkInterceptor(mContext))
final OkHttpClient okHttpClient = Injection.provideRetrofitBuilder()
.addInterceptor(new OkHttpCacheInterceptor(context))
.addInterceptor(new OkHttpRetryInterceptor(context))
.addNetworkInterceptor(new OkHttpNetworkInterceptor(context))
.connectTimeout(8, TimeUnit.SECONDS)
.cache(cache)
.build();
mApiService = new Retrofit.Builder()
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.baseUrl(Config.API_HOST)
.build()
.create(ApiService.class);
mApiService = provideService(okHttpClient, Config.API_HOST, ApiService.class);
mDataService = provideService(okHttpClient, Config.DATA_HOST, DataService.class);
mCommentService = provideService(okHttpClient, Config.COMMENT_HOST, CommentService.class);
mUserService = provideService(okHttpClient, Config.USER_HOST, UserService.class);
mLibaoService = provideService(okHttpClient, Config.LIBAO_HOST, LibaoService.class);
mMessageService = provideService(okHttpClient, Config.MESSAGE_HOST, MessageService.class);
mUserseaService = provideService(okHttpClient, Config.USERSEA_HOST, UserseaService.class);
mDataService = new Retrofit.Builder()
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.baseUrl(Config.DATA_HOST)
.build()
.create(DataService.class);
mCommentService = new Retrofit.Builder()
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.baseUrl(Config.COMMENT_HOST)
.build()
.create(CommentService.class);
mUserService = new Retrofit.Builder()
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.baseUrl(Config.USER_HOST)
.build()
.create(UserService.class);
mLibaoService = new Retrofit.Builder()
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.baseUrl(Config.LIBAO_HOST)
.build()
.create(LibaoService.class);
mMessageService = new Retrofit.Builder()
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.baseUrl(Config.MESSAGE_HOST)
.build()
.create(MessageService.class);
mUserseaService = new Retrofit.Builder()
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.baseUrl(Config.USERSEA_HOST)
.build()
.create(UserseaService.class);
}
public static ApiService getApi() {
return getInstance().mApiService;
}
public static RetrofitManager getInstance() {
@ -128,6 +74,10 @@ public class RetrofitManager {
return sInstance;
}
public static ApiService getApi() {
return getInstance().mApiService;
}
public static DataService getData() {
return getInstance().mDataService;
}