diff --git a/app/src/main/java/com/gh/base/GHPushMessageReceiver.java b/app/src/main/java/com/gh/base/GHPushMessageReceiver.java index 7719932907..f590fb2503 100644 --- a/app/src/main/java/com/gh/base/GHPushMessageReceiver.java +++ b/app/src/main/java/com/gh/base/GHPushMessageReceiver.java @@ -35,7 +35,6 @@ import org.json.JSONException; import org.json.JSONObject; import java.io.File; -import java.io.IOException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; @@ -181,18 +180,11 @@ public class GHPushMessageReceiver extends PushMessageReceiver { } String url = jsonObject.getString("icon"); - String path = context.getCacheDir() + File.separator - + url.substring(url.lastIndexOf("/") + 1); - try { - int result = FileUtils.downloadFile(url, path); - if (result == -1) { - // 下载出错,使用光环logo - path = null; - } - } catch (IOException e) { + String path = context.getCacheDir() + File.separator + url.substring(url.lastIndexOf("/") + 1); + int result = FileUtils.downloadFile(url, path); + if (result != 200) { // 下载出错,使用光环logo path = null; - e.printStackTrace(); } if (remoteViews != null) { diff --git a/app/src/main/java/com/gh/base/GHUmengNotificationClickHandler.java b/app/src/main/java/com/gh/base/GHUmengNotificationClickHandler.java index 3780ed4580..45bbb7d8bd 100644 --- a/app/src/main/java/com/gh/base/GHUmengNotificationClickHandler.java +++ b/app/src/main/java/com/gh/base/GHUmengNotificationClickHandler.java @@ -7,7 +7,6 @@ import android.text.TextUtils; import com.gh.common.util.ClassUtils; import com.gh.common.util.RunningUtils; -import com.gh.common.util.Utils; import com.gh.gamecenter.MainActivity; import com.gh.gamecenter.SplashScreenActivity; import com.umeng.message.UmengNotificationClickHandler; diff --git a/app/src/main/java/com/gh/common/util/DataLogUtils.java b/app/src/main/java/com/gh/common/util/DataLogUtils.java index 94355e7ec0..abafd229cc 100644 --- a/app/src/main/java/com/gh/common/util/DataLogUtils.java +++ b/app/src/main/java/com/gh/common/util/DataLogUtils.java @@ -23,12 +23,10 @@ import rx.schedulers.Schedulers; */ public class DataLogUtils { - /** - * 上传日志 - */ + // 上传日志 public static void uploadLog(Context context, String topic, Map map) { String version = PackageUtils.getVersionName(context); - String user = DeviceUtils.getDeviceID(context); + String user = Installation.getUUID(context); String channel = (String) PackageUtils.getMetaData(context, context.getPackageName(), "TD_CHANNEL_ID"); map.put("version", version); map.put("user", user); diff --git a/app/src/main/java/com/gh/common/util/DeviceUtils.java b/app/src/main/java/com/gh/common/util/DeviceUtils.java deleted file mode 100644 index a9b759b0d5..0000000000 --- a/app/src/main/java/com/gh/common/util/DeviceUtils.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.gh.common.util; - -import android.content.Context; -import android.net.wifi.WifiManager; -import android.provider.Settings.Secure; -import android.telephony.TelephonyManager; -import android.text.TextUtils; - -import java.util.HashMap; -import java.util.Map; - -public class DeviceUtils { - - public synchronized static String getDeviceHeader(Context context) { - StringBuffer buffer = new StringBuffer(); - String imei = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId(); - if (!TextUtils.isEmpty(imei)) { - buffer.append("imei="); - buffer.append(imei); - } - String android_id = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); - if (!TextUtils.isEmpty(android_id)) { - if (buffer.length() != 0) { - buffer.append(","); - } - buffer.append("android_id="); - buffer.append(android_id); - } - WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); - String mac = wm.getConnectionInfo().getMacAddress(); - if (!TextUtils.isEmpty(mac)) { - if (buffer.length() != 0) { - buffer.append(","); - } - buffer.append("mac="); - buffer.append(mac); - } - return buffer.toString(); - } - - public synchronized static Map getDeviceParams(Context context) { - HashMap params = new HashMap(); - params.put("imei", ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId()); - params.put("android_id", Secure.getString(context.getContentResolver(), Secure.ANDROID_ID)); - WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); - params.put("mac", wm.getConnectionInfo().getMacAddress()); - return params; - } - - public synchronized static String getDeviceID(Context context) { - String imei = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId(); - if (!TextUtils.isEmpty(imei)) { - return imei; - } - String android_id = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); - if (!TextUtils.isEmpty(android_id)) { - return android_id; - } - return Installation.getUUID(context); - } - -} diff --git a/app/src/main/java/com/gh/common/util/FileUtils.java b/app/src/main/java/com/gh/common/util/FileUtils.java index 2efd2c3928..b169d10c1e 100644 --- a/app/src/main/java/com/gh/common/util/FileUtils.java +++ b/app/src/main/java/com/gh/common/util/FileUtils.java @@ -75,14 +75,6 @@ public class FileUtils { public static String getPlatformPicDir(Context context) { return checkDir(getDir(context, "PlatformPic")); } - - public static String getAdPicDir(Context context) { - return checkDir(getDir(context, "AdPic")); - } - - public static String getPicPath(Context context, String name) { - return checkDir(getDir(context, "Pic")) + File.separator + name; - } private static String checkDir(String dir) { File directory = new File(dir); @@ -119,10 +111,7 @@ public class FileUtils { public static boolean isEmptyFile(String path) { File file = new File(path); - if (file.exists() && file.length() != 0) { - return false; - } - return true; + return !(file.exists() && file.length() != 0); } public static boolean isMounted() { @@ -141,9 +130,7 @@ public class FileUtils { return context.getFilesDir().getAbsolutePath() + File.separator + dir; } - /* - * 返回剩余空间 单位MB - */ + // 返回剩余空间 单位MB @SuppressWarnings("deprecation") public static float getFreeSpaceByPath(String path) { StatFs statfs = new StatFs(path); @@ -173,8 +160,7 @@ public class FileUtils { } // 下载文件 - public static int downloadFile(String url, String savePath) - throws IOException { + public static int downloadFile(String url, String savePath) { DataInputStream dis = null; FileOutputStream fos = null; try { @@ -198,32 +184,36 @@ public class FileUtils { fos.write(buffer, 0, len); } fos.flush(); - fos.close(); - dis.close(); } return code; } catch (IOException e) { e.printStackTrace(); - return -1; } finally { if (fos != null) { - fos.close(); + try { + fos.close(); + } catch (IOException e) { + e.printStackTrace(); + } } if (dis != null) { - dis.close(); + try { + dis.close(); + } catch (IOException e) { + e.printStackTrace(); + } } } + return -1; } // 上传文件 public static JSONObject uploadFile(String url, String filePath, String token) { String end = "\r\n"; String twoHyphens = "--"; - String boundary = UUID.randomUUID().toString().replaceAll("-", "") - .substring(0, 16); + String boundary = UUID.randomUUID().toString().replaceAll("-", "").substring(0, 16); try { - HttpURLConnection connection = (HttpURLConnection) new URL(url) - .openConnection(); + HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); /* * Output to the connection. Default is false, set to true because * post method must write something to the connection @@ -240,8 +230,7 @@ public class FileUtils { // 设置请求属性 connection.setRequestProperty("Connection", "Keep-Alive"); connection.setRequestProperty("Charset", "UTF-8"); - connection.setRequestProperty("Content-Type", - "multipart/form-data;boundary=" + boundary); + connection.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary); if (token != null) { connection.setRequestProperty("TOKEN", token); } @@ -255,13 +244,11 @@ public class FileUtils { Utils.log("length = " + file.length()); } // 设置DataOutputStream,getOutputStream中默认调用connect() - DataOutputStream dos = new DataOutputStream( - connection.getOutputStream()); // output + DataOutputStream dos = new DataOutputStream(connection.getOutputStream()); // output // to the connection dos.writeBytes(twoHyphens + boundary + end); dos.writeBytes("Content-Disposition: form-data; " - + "name=\"Filedata\";filename=\"" + file.getName() + "\"" - + end); + + "name=\"Filedata\";filename=\"" + file.getName() + "\"" + end); dos.writeBytes(end); // 取得文件的FileInputStream FileInputStream fStream = new FileInputStream(file); diff --git a/app/src/main/java/com/gh/common/util/Installation.java b/app/src/main/java/com/gh/common/util/Installation.java index 51019b79b0..49c62f05d2 100644 --- a/app/src/main/java/com/gh/common/util/Installation.java +++ b/app/src/main/java/com/gh/common/util/Installation.java @@ -1,6 +1,9 @@ package com.gh.common.util; import android.content.Context; +import android.provider.Settings; +import android.telephony.TelephonyManager; +import android.text.TextUtils; import java.io.File; import java.io.FileOutputStream; @@ -15,6 +18,14 @@ public class Installation { private static String sID = null; public synchronized static String getUUID(Context context) { + String imei = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId(); + if (!TextUtils.isEmpty(imei)) { + return imei; + } + String android_id = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); + if (!TextUtils.isEmpty(android_id)) { + return android_id; + } if (sID == null) { File installation = new File(context.getFilesDir(), INSTALLATION); try { diff --git a/app/src/main/java/com/gh/common/util/LibaoUtils.java b/app/src/main/java/com/gh/common/util/LibaoUtils.java index 44353ed544..58126b6538 100644 --- a/app/src/main/java/com/gh/common/util/LibaoUtils.java +++ b/app/src/main/java/com/gh/common/util/LibaoUtils.java @@ -89,12 +89,9 @@ public class LibaoUtils { } @Override - public void onFailure(Throwable e) { - if (e instanceof HttpException) { - HttpException exception = (HttpException) e; - if (exception.code() == 401) { - getCunHaoXiang(context, false); - } + public void onFailure(HttpException e) { + if (e != null && e.code() == 401) { + getCunHaoXiang(context, false); } } }); @@ -117,13 +114,10 @@ public class LibaoUtils { } @Override - public void onFailure(Throwable e) { - if (e instanceof HttpException) { - HttpException exception = (HttpException) e; - if (exception.code() == 401) { - postLibaoLing(context, libaoId, false, listener); - return; - } + public void onFailure(HttpException e) { + if (e != null && e.code() == 401) { + postLibaoLing(context, libaoId, false, listener); + return; } listener.postFailed(e); } @@ -147,13 +141,10 @@ public class LibaoUtils { } @Override - public void onFailure(Throwable e) { - if (e instanceof HttpException) { - HttpException exception = (HttpException) e; - if (exception.code() == 401) { - postLibaoLing(context, libaoId, false, listener); - return; - } + public void onFailure(HttpException e) { + if (e != null && e.code() == 401) { + postLibaoLing(context, libaoId, false, listener); + return; } listener.postFailed(e); } @@ -177,13 +168,10 @@ public class LibaoUtils { } @Override - public void onFailure(Throwable e) { - if (e instanceof HttpException) { - HttpException exception = (HttpException) e; - if (exception.code() == 401) { - postLibaoLing(context, code, false, listener); - return; - } + public void onFailure(HttpException e) { + if (e != null && e.code() == 401) { + postLibaoLing(context, code, false, listener); + return; } listener.postFailed(e); } @@ -201,7 +189,7 @@ public class LibaoUtils { } @Override - public void onFailure(Throwable e) { + public void onFailure(HttpException e) { listener.postFailed(e); } }); diff --git a/app/src/main/java/com/gh/common/util/PlatformUtils.java b/app/src/main/java/com/gh/common/util/PlatformUtils.java index e8711ba775..a8e32105c0 100644 --- a/app/src/main/java/com/gh/common/util/PlatformUtils.java +++ b/app/src/main/java/com/gh/common/util/PlatformUtils.java @@ -23,6 +23,7 @@ import java.util.Properties; import java.util.Set; import de.greenrobot.event.EventBus; +import retrofit2.adapter.rxjava.HttpException; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; @@ -170,13 +171,9 @@ public class PlatformUtils { String savePath = FileUtils.getPlatformPicDir(context) + File.separator + url.substring(url.lastIndexOf("/") + 1); - try { - int code = FileUtils.downloadFile(url, savePath); - if (code == HttpURLConnection.HTTP_OK) { - success++; - } - } catch (IOException e) { - e.printStackTrace(); + int code = FileUtils.downloadFile(url, savePath); + if (code == HttpURLConnection.HTTP_OK) { + success++; } } if (success == urls.size()) { @@ -280,7 +277,7 @@ public class PlatformUtils { } @Override - public void onFailure(Throwable e) { + public void onFailure(HttpException e) { isUpdate = false; } }); diff --git a/app/src/main/java/com/gh/common/util/PostCommentUtils.java b/app/src/main/java/com/gh/common/util/PostCommentUtils.java index 97e56ef41a..b3711d7bc3 100644 --- a/app/src/main/java/com/gh/common/util/PostCommentUtils.java +++ b/app/src/main/java/com/gh/common/util/PostCommentUtils.java @@ -48,13 +48,10 @@ public class PostCommentUtils { } @Override - public void onFailure(Throwable e) { - if (e instanceof HttpException) { - HttpException exception = (HttpException) e; - if (exception.code() == 401) { - addCommentData(context, newsId, content, false, listener); - return; - } + public void onFailure(HttpException e) { + if (e != null && e.code() == 401) { + addCommentData(context, newsId, content, false, listener); + return; } if (listener != null){ listener.postFailed(e); @@ -83,13 +80,10 @@ public class PostCommentUtils { } @Override - public void onFailure(Throwable e) { - if (e instanceof HttpException) { - HttpException exception = (HttpException) e; - if (exception.code() == 401) { - addCommentVoto(context, commentId, false, listener); - return; - } + public void onFailure(HttpException e) { + if (e != null && e.code() == 401) { + addCommentVoto(context, commentId, false, listener); + return; } if (listener != null) { listener.postFailed(e); @@ -117,12 +111,10 @@ public class PostCommentUtils { } @Override - public void onFailure(Throwable e) { - if (e instanceof HttpException) { - if (((HttpException) e).code() == 401) { - addReportData(context, reportData, false, listener); - return; - } + public void onFailure(HttpException e) { + if (e != null && e.code() == 401) { + addReportData(context, reportData, false, listener); + return; } listener.postFailed(e); } diff --git a/app/src/main/java/com/gh/common/util/TokenUtils.java b/app/src/main/java/com/gh/common/util/TokenUtils.java index 5ec905beba..038e7d5c75 100644 --- a/app/src/main/java/com/gh/common/util/TokenUtils.java +++ b/app/src/main/java/com/gh/common/util/TokenUtils.java @@ -32,12 +32,12 @@ import okhttp3.MediaType; import okhttp3.RequestBody; import okhttp3.ResponseBody; import rx.Observable; -import rx.Subscriber; import rx.android.schedulers.AndroidSchedulers; -import rx.functions.Action1; import rx.functions.Func1; import rx.schedulers.Schedulers; +import static anetwork.channel.http.NetworkSdkSetting.context; + public class TokenUtils { // 注册设备 diff --git a/app/src/main/java/com/gh/gamecenter/GameDetailActivity.java b/app/src/main/java/com/gh/gamecenter/GameDetailActivity.java index d5a3a9c5c3..07e0aa73d3 100644 --- a/app/src/main/java/com/gh/gamecenter/GameDetailActivity.java +++ b/app/src/main/java/com/gh/gamecenter/GameDetailActivity.java @@ -24,6 +24,7 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; +import retrofit2.adapter.rxjava.HttpException; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action1; import rx.schedulers.Schedulers; @@ -181,7 +182,7 @@ public class GameDetailActivity extends BaseDetailActivity implements View.OnCli } @Override - public void onFailure(Throwable e) { + public void onFailure(HttpException e) { reuse_no_connection.setVisibility(View.VISIBLE); } }); diff --git a/app/src/main/java/com/gh/gamecenter/LibaoDetailActivity.java b/app/src/main/java/com/gh/gamecenter/LibaoDetailActivity.java index 85d8d5e9e8..e31f493147 100644 --- a/app/src/main/java/com/gh/gamecenter/LibaoDetailActivity.java +++ b/app/src/main/java/com/gh/gamecenter/LibaoDetailActivity.java @@ -12,6 +12,7 @@ import com.gh.gamecenter.entity.LibaoEntity; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; +import retrofit2.adapter.rxjava.HttpException; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; @@ -83,7 +84,7 @@ public class LibaoDetailActivity extends BaseDetailActivity { } @Override - public void onFailure(Throwable e) { + public void onFailure(HttpException e) { detail_rv_show.setVisibility(View.GONE); reuse_ll_loading.setVisibility(View.GONE); detail_ll_bottom.setVisibility(View.GONE); diff --git a/app/src/main/java/com/gh/gamecenter/MainActivity.java b/app/src/main/java/com/gh/gamecenter/MainActivity.java index e156a4842c..8e95669309 100644 --- a/app/src/main/java/com/gh/gamecenter/MainActivity.java +++ b/app/src/main/java/com/gh/gamecenter/MainActivity.java @@ -87,6 +87,7 @@ import de.greenrobot.event.EventBus; import okhttp3.MediaType; import okhttp3.RequestBody; import okhttp3.ResponseBody; +import retrofit2.adapter.rxjava.HttpException; import rx.Observable; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action1; @@ -598,7 +599,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene } @Override - public void onFailure(Throwable e) { + public void onFailure(HttpException e) { latch.countDown(); } }); diff --git a/app/src/main/java/com/gh/gamecenter/MessageDetailActivity.java b/app/src/main/java/com/gh/gamecenter/MessageDetailActivity.java index 613fdc9a9d..ad1841c49e 100644 --- a/app/src/main/java/com/gh/gamecenter/MessageDetailActivity.java +++ b/app/src/main/java/com/gh/gamecenter/MessageDetailActivity.java @@ -253,7 +253,7 @@ public class MessageDetailActivity extends BaseActivity implements MessageDetail } @Override - public void onFailure(Throwable e) { + public void onFailure(HttpException e) { showNoConnection(true); } }); diff --git a/app/src/main/java/com/gh/gamecenter/NewsDetailActivity.java b/app/src/main/java/com/gh/gamecenter/NewsDetailActivity.java index 5f9e57e6d3..fe966b680a 100644 --- a/app/src/main/java/com/gh/gamecenter/NewsDetailActivity.java +++ b/app/src/main/java/com/gh/gamecenter/NewsDetailActivity.java @@ -57,6 +57,7 @@ import java.util.concurrent.TimeUnit; import butterknife.BindView; import butterknife.ButterKnife; +import retrofit2.adapter.rxjava.HttpException; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action1; import rx.schedulers.Schedulers; @@ -388,7 +389,7 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener } @Override - public void onFailure(Throwable e) { + public void onFailure(HttpException e) { detail_rv_show.setVisibility(View.GONE); reuse_ll_loading.setVisibility(View.GONE); detail_ll_bottom.setVisibility(View.GONE); diff --git a/app/src/main/java/com/gh/gamecenter/NewsSearchActivity.java b/app/src/main/java/com/gh/gamecenter/NewsSearchActivity.java index 81badb762e..0f56e8aabe 100644 --- a/app/src/main/java/com/gh/gamecenter/NewsSearchActivity.java +++ b/app/src/main/java/com/gh/gamecenter/NewsSearchActivity.java @@ -35,6 +35,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import retrofit2.adapter.rxjava.HttpException; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Func1; import rx.schedulers.Schedulers; @@ -206,7 +207,7 @@ public class NewsSearchActivity extends BaseActivity { } @Override - public void onFailure(Throwable e) { + public void onFailure(HttpException e) { if (page == 1) { reuse_no_connection.setVisibility(View.VISIBLE); gamedetail_news_ll_loading.setVisibility(View.GONE); diff --git a/app/src/main/java/com/gh/gamecenter/SubjectActivity.java b/app/src/main/java/com/gh/gamecenter/SubjectActivity.java index e867fbeb03..ced2f5da10 100644 --- a/app/src/main/java/com/gh/gamecenter/SubjectActivity.java +++ b/app/src/main/java/com/gh/gamecenter/SubjectActivity.java @@ -30,6 +30,7 @@ import java.io.IOException; import java.util.ArrayList; import okhttp3.ResponseBody; +import retrofit2.adapter.rxjava.HttpException; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; @@ -121,23 +122,15 @@ public class SubjectActivity extends BaseActivity { .subscribe(new Response(){ @Override public void onResponse(ResponseBody response) { - super.onResponse(response); actionbar_tv_title = (TextView) findViewById(R.id.actionbar_tv_title); try { - JSONObject jsonObject = new JSONObject(response.string().toString()); + JSONObject jsonObject = new JSONObject(response.string()); actionbar_tv_title.setText(jsonObject.getString("name")); - } catch (IOException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (IOException | JSONException e) { e.printStackTrace(); } } - - @Override - public void onFailure(Throwable e) { - super.onFailure(e); - } }); } diff --git a/app/src/main/java/com/gh/gamecenter/SuggestionActivity.java b/app/src/main/java/com/gh/gamecenter/SuggestionActivity.java index 4228f27627..4fb00bfd85 100644 --- a/app/src/main/java/com/gh/gamecenter/SuggestionActivity.java +++ b/app/src/main/java/com/gh/gamecenter/SuggestionActivity.java @@ -31,6 +31,7 @@ import java.util.regex.Pattern; import okhttp3.MediaType; import okhttp3.RequestBody; +import retrofit2.adapter.rxjava.HttpException; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; @@ -227,7 +228,7 @@ public class SuggestionActivity extends BaseActivity implements OnClickListener } @Override - public void onFailure(Throwable e) { + public void onFailure(HttpException e) { isShowing = false; dialog.dismiss(); diff --git a/app/src/main/java/com/gh/gamecenter/adapter/GameNewsAdapter.java b/app/src/main/java/com/gh/gamecenter/adapter/GameNewsAdapter.java index 4a6526d0f3..9ad7865bb2 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/GameNewsAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/GameNewsAdapter.java @@ -30,6 +30,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import retrofit2.adapter.rxjava.HttpException; import rx.Observable; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Func1; @@ -130,7 +131,7 @@ public class GameNewsAdapter extends RecyclerView.Adapter { } @Override - public void onFailure(Throwable e) { + public void onFailure(HttpException e) { isLoading = false; isNetworkError = true; } diff --git a/app/src/main/java/com/gh/gamecenter/adapter/LibaoDetailAdapter.java b/app/src/main/java/com/gh/gamecenter/adapter/LibaoDetailAdapter.java index e98df41755..0c857f07f3 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/LibaoDetailAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/LibaoDetailAdapter.java @@ -31,6 +31,7 @@ import com.gh.gamecenter.retrofit.RetrofitManager; import java.text.SimpleDateFormat; import java.util.List; +import retrofit2.adapter.rxjava.HttpException; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; @@ -70,15 +71,13 @@ public class LibaoDetailAdapter extends RecyclerView.Adapter() { @Override public void onResponse(LibaoDetailEntity response) { - super.onResponse(response); mLibaoDetailEntity = response; mCallBackListener.loadDone(); notifyDataSetChanged(); } @Override - public void onFailure(Throwable e) { - super.onFailure(e); + public void onFailure(HttpException e) { mCallBackListener.loadEmpty(); } }); diff --git a/app/src/main/java/com/gh/gamecenter/adapter/MessageDetailAdapter.java b/app/src/main/java/com/gh/gamecenter/adapter/MessageDetailAdapter.java index 4fd724a647..65bf0a4dba 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/MessageDetailAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/MessageDetailAdapter.java @@ -151,7 +151,7 @@ public class MessageDetailAdapter extends RecyclerView.Adapter>(){ @Override public void onResponse(List response) { - super.onResponse(response); if (response.size() != 0) { mNewsList.addAll(response); if (mNewsList.size() <= 20) { @@ -110,8 +110,7 @@ public class StrategyAdapter extends RecyclerView.Adapter response) { - super.onResponse(response); progressBar.setVisibility(View.GONE); if (response.size() < subjectEntity.getData().size()) { Utils.toast(context, "数据异常"); @@ -1184,8 +1184,7 @@ public class GameFragmentAdapter extends RecyclerView.Adapter>(){ @Override public void onResponse(List response) { - super.onResponse(response); getLibaoStatus(response); } - - @Override - public void onFailure(Throwable e) { - super.onFailure(e); - - } }); } @@ -264,7 +258,7 @@ public class GameDetailAdapter extends RecyclerView.Adapter { } @Override - public void onFailure(Throwable e) { + public void onFailure(HttpException e) { if (listener != null) { listener.loadDone(); } diff --git a/app/src/main/java/com/gh/gamecenter/libao/Libao1FragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/libao/Libao1FragmentAdapter.java index 1f8aca14f3..14ae8aad22 100644 --- a/app/src/main/java/com/gh/gamecenter/libao/Libao1FragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/libao/Libao1FragmentAdapter.java @@ -30,6 +30,7 @@ import com.gh.gamecenter.retrofit.RetrofitManager; import java.util.ArrayList; import java.util.List; +import retrofit2.adapter.rxjava.HttpException; import rx.Observable; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Func1; @@ -102,7 +103,6 @@ public class Libao1FragmentAdapter extends RecyclerView.Adapter>(){ @Override public void onResponse(List response) { - super.onResponse(response); mLibaoList.addAll(response); notifyDataSetChanged(); @@ -124,8 +124,7 @@ public class Libao1FragmentAdapter extends RecyclerView.Adapter>() { @Override public void onResponse(List response) { - super.onResponse(response); mLibaoList.addAll(response); mCallBackListener.loadDone(); isLoading = false; @@ -187,15 +186,11 @@ public class Libao2FragmentAdapter extends RecyclerView.Adapter>() { @Override public void onResponse(List response) { - super.onResponse(response); mLibaoList.addAll(response); isLoading = false; @@ -240,8 +234,7 @@ public class Libao2FragmentAdapter extends RecyclerView.Adapter map) { String version = PackageUtils.getVersionName(mContext); - String user = DeviceUtils.getDeviceID(mContext); + String user = Installation.getUUID(mContext); String channel = (String) PackageUtils.getMetaData(mContext, mContext.getPackageName(), "TD_CHANNEL_ID"); map.put("version", version); @@ -204,7 +205,7 @@ public class DataCollectionManager { final List ids = new ArrayList<>(); String version = PackageUtils.getVersionName(mContext); - String user = DeviceUtils.getDeviceID(mContext); + String user = Installation.getUUID(mContext); String channel = (String) PackageUtils.getMetaData(mContext, mContext.getPackageName(), "TD_CHANNEL_ID"); @@ -270,7 +271,7 @@ public class DataCollectionManager { } @Override - public void onFailure(Throwable e) { + public void onFailure(HttpException e) { isUploading = false; } }); diff --git a/app/src/main/java/com/gh/gamecenter/manager/UpdateManager.java b/app/src/main/java/com/gh/gamecenter/manager/UpdateManager.java index 4b0a39d792..a731be7b09 100644 --- a/app/src/main/java/com/gh/gamecenter/manager/UpdateManager.java +++ b/app/src/main/java/com/gh/gamecenter/manager/UpdateManager.java @@ -153,18 +153,15 @@ public class UpdateManager { } @Override - public void onFailure(Throwable e) { + public void onFailure(HttpException e) { isChecking = false; if (loadingDialog != null) { loadingDialog.dismiss(); } if (!isCheck) { - if (e instanceof HttpException) { - HttpException exception = (HttpException) e; - if (exception.code() == 304) { - Toast.makeText(context, "您的光环助手已是最新版本", Toast.LENGTH_SHORT).show(); - return; - } + if (e != null && e.code() == 304) { + Toast.makeText(context, "您的光环助手已是最新版本", Toast.LENGTH_SHORT).show(); + return; } Toast.makeText(context, "检查更新失败", Toast.LENGTH_SHORT).show(); diff --git a/app/src/main/java/com/gh/gamecenter/news/News1FragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/news/News1FragmentAdapter.java index 7638546aa8..994301d228 100644 --- a/app/src/main/java/com/gh/gamecenter/news/News1FragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/news/News1FragmentAdapter.java @@ -223,14 +223,11 @@ public class News1FragmentAdapter extends RecyclerView.Adapter>() { @Override public void onResponse(List response) { - super.onResponse(response); if (response.size() >= 3) { commentList = response; isHotComment = true; @@ -122,8 +121,7 @@ public class NewsDetailAdapter extends RecyclerView.Adapter { } @Override - public void onFailure(Throwable e) { - super.onFailure(e); + public void onFailure(HttpException e) { getNewsComment(); } }); @@ -137,18 +135,12 @@ public class NewsDetailAdapter extends RecyclerView.Adapter { .subscribe(new Response>() { @Override public void onResponse(List response) { - super.onResponse(response); if (response.size() >= 1) { isHotComment = false; commentList = response; notifyDataSetChanged(); } } - - @Override - public void onFailure(Throwable e) { - super.onFailure(e); - } }); } @@ -168,7 +160,7 @@ public class NewsDetailAdapter extends RecyclerView.Adapter { } @Override - public void onFailure(Throwable e) { + public void onFailure(HttpException e) { listener.loadError(); } }); @@ -203,7 +195,7 @@ public class NewsDetailAdapter extends RecyclerView.Adapter { } @Override - public void onFailure(Throwable e) { + public void onFailure(HttpException e) { getNewsHotComment(); } }); diff --git a/app/src/main/java/com/gh/gamecenter/personal/PersonalFragment.java b/app/src/main/java/com/gh/gamecenter/personal/PersonalFragment.java index 1c1bf67c82..fd1e2791d2 100644 --- a/app/src/main/java/com/gh/gamecenter/personal/PersonalFragment.java +++ b/app/src/main/java/com/gh/gamecenter/personal/PersonalFragment.java @@ -397,16 +397,15 @@ public class PersonalFragment extends Fragment implements View.OnClickListener, } @Override - public void onFailure(Throwable e) { - if (e instanceof HttpException) { - HttpException exception = (HttpException) e; - if (exception.code() == 401) { + public void onFailure(HttpException e) { + if (e != null) { + if (e.code() == 401) { modifyNickname(waitDialog, nickname, false); return; } - if (exception.code() == 403) { + if (e.code() == 403) { try { - JSONObject response = new JSONObject(new String(exception.response().errorBody().bytes())); + JSONObject response = new JSONObject(new String(e.response().errorBody().bytes())); String detail = response.getString("detail"); if ("too long".equals(detail)) { Toast.makeText(getActivity(), "昵称太长", Toast.LENGTH_SHORT).show(); @@ -424,9 +423,8 @@ public class PersonalFragment extends Fragment implements View.OnClickListener, Toast.makeText(getActivity(), "修改失败", Toast.LENGTH_SHORT).show(); } } - } else { - Toast.makeText(getActivity(), "修改失败", Toast.LENGTH_SHORT).show(); } + Toast.makeText(getActivity(), "修改失败", Toast.LENGTH_SHORT).show(); waitDialog.dismiss(); } }); diff --git a/app/src/main/java/com/gh/gamecenter/retrofit/Response.java b/app/src/main/java/com/gh/gamecenter/retrofit/Response.java index 98e25589a4..77308b09e1 100644 --- a/app/src/main/java/com/gh/gamecenter/retrofit/Response.java +++ b/app/src/main/java/com/gh/gamecenter/retrofit/Response.java @@ -1,5 +1,6 @@ package com.gh.gamecenter.retrofit; +import retrofit2.adapter.rxjava.HttpException; import rx.Subscriber; /** @@ -20,7 +21,11 @@ public class Response extends Subscriber { @Override public void onError(Throwable e) { - onFailure(e); + if (e instanceof HttpException) { + onFailure((HttpException) e); + } else { + onFailure(null); + } } @Override @@ -32,7 +37,7 @@ public class Response extends Subscriber { } - public void onFailure(Throwable e) { + public void onFailure(HttpException e) { } diff --git a/app/src/main/java/com/gh/gamecenter/search/SearchGameDetailFragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/search/SearchGameDetailFragmentAdapter.java index d221ae9ccd..f1f66a86e1 100644 --- a/app/src/main/java/com/gh/gamecenter/search/SearchGameDetailFragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/search/SearchGameDetailFragmentAdapter.java @@ -30,6 +30,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import retrofit2.adapter.rxjava.HttpException; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; @@ -86,7 +87,7 @@ public class SearchGameDetailFragmentAdapter extends RecyclerView.Adapter