diff --git a/app/build.gradle b/app/build.gradle index 3f6193b0..e48b4001 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -61,7 +61,7 @@ android { ]) // 调试模式下只保留一种架构的 so 库,提升打包速度 ndk { - abiFilters 'armeabi-v7a' + abiFilters 'armeabi-v7a','x86_64' } } @@ -95,7 +95,7 @@ android { // armeabi:万金油架构平台(占用率:0%) // armeabi-v7a:曾经主流的架构平台(占用率:10%) // arm64-v8a:目前主流架构平台(占用率:95%) - abiFilters 'armeabi-v7a', 'arm64-v8a' + abiFilters 'armeabi-v7a', 'arm64-v8a','x86_64' } } } @@ -139,16 +139,16 @@ dependencies { implementation project(':library:umeng') // 权限请求框架:https://github.com/getActivity/XXPermissions - implementation 'com.github.getActivity:XXPermissions:12.3' + implementation 'com.github.getActivity:XXPermissions:20.0' // 标题栏框架:https://github.com/getActivity/TitleBar - implementation 'com.github.getActivity:TitleBar:9.2' + implementation 'com.github.getActivity:TitleBar:10.5' - // 吐司框架:https://github.com/getActivity/ToastUtils - implementation 'com.github.getActivity:ToastUtils:9.5' + // 吐司框架:https://github.com/getActivity/Toaster + implementation 'com.github.getActivity:Toaster:12.6' // 网络请求框架:https://github.com/getActivity/EasyHttp - implementation 'com.github.getActivity:EasyHttp:10.2' + implementation 'com.github.getActivity:EasyHttp:13.0' // OkHttp 框架:https://github.com/square/okhttp // noinspection GradleDependency implementation 'com.squareup.okhttp3:okhttp:3.12.13' @@ -159,7 +159,7 @@ dependencies { implementation 'com.github.getActivity:GsonFactory:5.2' // Shape 框架:https://github.com/getActivity/ShapeView - implementation 'com.github.getActivity:ShapeView:6.0' + implementation 'com.github.getActivity:ShapeView:9.3' // AOP 插件库:https://mvnrepository.com/artifact/org.aspectj/aspectjrt implementation 'org.aspectj:aspectjrt:1.9.6' @@ -170,7 +170,7 @@ dependencies { annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0' // 沉浸式框架:https://github.com/gyf-dev/ImmersionBar - implementation 'com.gyf.immersionbar:immersionbar:3.0.0' + implementation 'com.geyifeng.immersionbar:immersionbar:3.2.2' // 手势 ImageView:https://github.com/Baseflow/PhotoView implementation 'com.github.Baseflow:PhotoView:2.3.0' @@ -194,7 +194,7 @@ dependencies { implementation 'me.relex:circleindicator:2.1.6' // 腾讯 MMKV:https://github.com/Tencent/MMKV - implementation 'com.tencent:mmkv-static:1.2.10' + implementation 'com.tencent:mmkv:2.0.2' // 内存泄漏监测框架:https://github.com/square/leakcanary debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7' diff --git a/app/src/main/java/com/hjq/demo/action/TitleBarAction.java b/app/src/main/java/com/hjq/demo/action/TitleBarAction.java index 65c7d732..3e60dcfb 100644 --- a/app/src/main/java/com/hjq/demo/action/TitleBarAction.java +++ b/app/src/main/java/com/hjq/demo/action/TitleBarAction.java @@ -24,26 +24,26 @@ public interface TitleBarAction extends OnTitleBarListener { /** * 左项被点击 * - * @param view 被点击的左项View + * @param titleBar 被点击的左项View */ @Override - default void onLeftClick(View view) {} + default void onLeftClick(TitleBar titleBar) {} /** * 标题被点击 * - * @param view 被点击的标题View + * @param titleBar 被点击的标题View */ @Override - default void onTitleClick(View view) {} + default void onTitleClick(TitleBar titleBar) {} /** * 右项被点击 * - * @param view 被点击的右项View + * @param titleBar 被点击的右项View */ @Override - default void onRightClick(View view) {} + default void onRightClick(TitleBar titleBar) {} /** * 设置标题栏的标题 diff --git a/app/src/main/java/com/hjq/demo/action/ToastAction.java b/app/src/main/java/com/hjq/demo/action/ToastAction.java index 7f1bccc7..778e36f4 100644 --- a/app/src/main/java/com/hjq/demo/action/ToastAction.java +++ b/app/src/main/java/com/hjq/demo/action/ToastAction.java @@ -2,7 +2,8 @@ import androidx.annotation.StringRes; -import com.hjq.toast.ToastUtils; +import com.hjq.toast.Toaster; + /** * author : Android 轮子哥 @@ -13,14 +14,14 @@ public interface ToastAction { default void toast(CharSequence text) { - ToastUtils.show(text); + Toaster.show(text); } default void toast(@StringRes int id) { - ToastUtils.show(id); + Toaster.show(id); } default void toast(Object object) { - ToastUtils.show(object); + Toaster.show(object); } } \ No newline at end of file diff --git a/app/src/main/java/com/hjq/demo/aop/CheckNetAspect.java b/app/src/main/java/com/hjq/demo/aop/CheckNetAspect.java index 1740ac6d..85e7466c 100644 --- a/app/src/main/java/com/hjq/demo/aop/CheckNetAspect.java +++ b/app/src/main/java/com/hjq/demo/aop/CheckNetAspect.java @@ -8,7 +8,8 @@ import com.hjq.demo.R; import com.hjq.demo.manager.ActivityManager; -import com.hjq.toast.ToastUtils; + +import com.hjq.toast.Toaster; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; @@ -42,7 +43,7 @@ public void aroundJoinPoint(ProceedingJoinPoint joinPoint, CheckNet checkNet) th NetworkInfo info = manager.getActiveNetworkInfo(); // 判断网络是否连接 if (info == null || !info.isConnected()) { - ToastUtils.show(R.string.common_network_hint); + Toaster.show(R.string.common_network_hint); return; } } diff --git a/app/src/main/java/com/hjq/demo/app/AppActivity.java b/app/src/main/java/com/hjq/demo/app/AppActivity.java index 0669b74a..936504da 100644 --- a/app/src/main/java/com/hjq/demo/app/AppActivity.java +++ b/app/src/main/java/com/hjq/demo/app/AppActivity.java @@ -17,6 +17,7 @@ import com.hjq.demo.action.ToastAction; import com.hjq.demo.http.model.HttpData; import com.hjq.demo.ui.dialog.WaitDialog; +import com.hjq.http.config.IRequestApi; import com.hjq.http.listener.OnHttpListener; import okhttp3.Call; @@ -178,7 +179,7 @@ public TitleBar getTitleBar() { } @Override - public void onLeftClick(View view) { + public void onLeftClick(TitleBar titleBar) { onBackPressed(); } @@ -194,33 +195,29 @@ public void finish() { overridePendingTransition(R.anim.left_in_activity, R.anim.left_out_activity); } - /** - * {@link OnHttpListener} - */ + @Override + public void onHttpStart(@NonNull IRequestApi api) { + showDialog(); + } - @Override - public void onStart(Call call) { - showDialog(); - } + @Override + public void onHttpSuccess(@NonNull Object result) { + if (result instanceof HttpData) { + toast(((HttpData) result).getMessage()); + } + } - @Override - public void onSucceed(Object result) { - if (result instanceof HttpData) { - toast(((HttpData) result).getMessage()); - } - } + @Override + public void onHttpFail(@NonNull Throwable throwable) { + toast(throwable.getMessage()); + } - @Override - public void onFail(Exception e) { - toast(e.getMessage()); - } - - @Override - public void onEnd(Call call) { - hideDialog(); - } + @Override + public void onHttpEnd(@NonNull IRequestApi api) { + hideDialog(); + } - @Override + @Override protected void onDestroy() { super.onDestroy(); if (isShowDialog()) { diff --git a/app/src/main/java/com/hjq/demo/app/AppApplication.java b/app/src/main/java/com/hjq/demo/app/AppApplication.java index 8662e829..e1c27e32 100644 --- a/app/src/main/java/com/hjq/demo/app/AppApplication.java +++ b/app/src/main/java/com/hjq/demo/app/AppApplication.java @@ -33,14 +33,18 @@ import com.hjq.http.config.IRequestInterceptor; import com.hjq.http.model.HttpHeaders; import com.hjq.http.model.HttpParams; +import com.hjq.http.request.HttpRequest; import com.hjq.permissions.XXPermissions; -import com.hjq.toast.ToastUtils; + +import com.hjq.toast.Toaster; import com.hjq.umeng.UmengClient; import com.scwang.smart.refresh.layout.SmartRefreshLayout; import com.tencent.bugly.crashreport.CrashReport; import com.tencent.mmkv.MMKV; import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; import timber.log.Timber; /** @@ -104,11 +108,9 @@ public static void initSdk(Application application) { }); // 初始化吐司 - ToastUtils.init(application, new ToastStyle()); - // 设置调试模式 - ToastUtils.setDebugMode(AppConfig.isDebug()); - // 设置 Toast 拦截器 - ToastUtils.setInterceptor(new ToastLogInterceptor()); + Toaster.init(application); + // 设置 Toast 拦截器(全局生效) + Toaster.setInterceptor(new ToastLogInterceptor()); // 本地异常捕捉 CrashHandler.register(application); @@ -138,14 +140,26 @@ public static void initSdk(Application application) { .setHandler(new RequestHandler(application)) // 设置请求重试次数 .setRetryCount(1) - .setInterceptor((api, params, headers) -> { - // 添加全局请求头 - headers.put("token", "66666666666"); - headers.put("deviceOaid", UmengClient.getDeviceOaid()); - headers.put("versionName", AppConfig.getVersionName()); - headers.put("versionCode", String.valueOf(AppConfig.getVersionCode())); - // 添加全局请求参数 - // params.put("6666666", "6666666"); + .setInterceptor(new IRequestInterceptor() { + @Override + public void interceptArguments(@NonNull HttpRequest httpRequest, @NonNull HttpParams params, @NonNull HttpHeaders headers) { + // 请求参数拦截 + IRequestInterceptor.super.interceptArguments(httpRequest, params, headers); + } + + @NonNull + @Override + public Request interceptRequest(@NonNull HttpRequest httpRequest, @NonNull Request request) { + // 请求拦截 + return IRequestInterceptor.super.interceptRequest(httpRequest, request); + } + + @NonNull + @Override + public Response interceptResponse(HttpRequest httpRequest, Response response) { + // 响应拦截 + return IRequestInterceptor.super.interceptResponse(httpRequest, response); + } }) .into(); @@ -177,7 +191,7 @@ public void onLost(@NonNull Network network) { return; } - ToastUtils.show(R.string.common_network_error); + Toaster.show(R.string.common_network_error); } }); } diff --git a/app/src/main/java/com/hjq/demo/app/AppFragment.java b/app/src/main/java/com/hjq/demo/app/AppFragment.java index d2ceeea4..9a9aa629 100644 --- a/app/src/main/java/com/hjq/demo/app/AppFragment.java +++ b/app/src/main/java/com/hjq/demo/app/AppFragment.java @@ -1,8 +1,11 @@ package com.hjq.demo.app; +import androidx.annotation.NonNull; + import com.hjq.base.BaseFragment; import com.hjq.demo.action.ToastAction; import com.hjq.demo.http.model.HttpData; +import com.hjq.http.config.IRequestApi; import com.hjq.http.listener.OnHttpListener; import okhttp3.Call; @@ -49,30 +52,26 @@ public void hideDialog() { activity.hideDialog(); } - /** - * {@link OnHttpListener} - */ - - @Override - public void onStart(Call call) { - showDialog(); - } + @Override + public void onHttpStart(@NonNull IRequestApi api) { + showDialog(); + } - @Override - public void onSucceed(Object result) { - if (!(result instanceof HttpData)) { - return; - } - toast(((HttpData) result).getMessage()); - } + @Override + public void onHttpSuccess(@NonNull Object result) { + if (!(result instanceof HttpData)) { + return; + } + toast(((HttpData) result).getMessage()); + } - @Override - public void onFail(Exception e) { - toast(e.getMessage()); - } + @Override + public void onHttpFail(@NonNull Throwable throwable) { + toast(throwable.getMessage()); + } - @Override - public void onEnd(Call call) { - hideDialog(); - } + @Override + public void onHttpEnd(@NonNull IRequestApi api) { + hideDialog(); + } } \ No newline at end of file diff --git a/app/src/main/java/com/hjq/demo/http/model/RequestHandler.java b/app/src/main/java/com/hjq/demo/http/model/RequestHandler.java index 0326dcdd..e605b41d 100644 --- a/app/src/main/java/com/hjq/demo/http/model/RequestHandler.java +++ b/app/src/main/java/com/hjq/demo/http/model/RequestHandler.java @@ -6,6 +6,8 @@ import android.net.ConnectivityManager; import android.net.NetworkInfo; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.lifecycle.LifecycleOwner; import com.google.gson.JsonSyntaxException; @@ -14,17 +16,15 @@ import com.hjq.demo.ui.activity.LoginActivity; import com.hjq.gson.factory.GsonFactory; import com.hjq.http.EasyLog; -import com.hjq.http.config.IRequestApi; import com.hjq.http.config.IRequestHandler; import com.hjq.http.exception.CancelException; import com.hjq.http.exception.DataException; import com.hjq.http.exception.HttpException; import com.hjq.http.exception.NetworkException; import com.hjq.http.exception.ResponseException; -import com.hjq.http.exception.ResultException; import com.hjq.http.exception.ServerException; import com.hjq.http.exception.TimeoutException; -import com.hjq.http.exception.TokenException; +import com.hjq.http.request.HttpRequest; import com.tencent.mmkv.MMKV; import org.json.JSONArray; @@ -58,7 +58,7 @@ public RequestHandler(Application application) { } @Override - public Object requestSucceed(LifecycleOwner lifecycle, IRequestApi api, Response response, Type type) throws Exception { + public Object requestSuccess(@NonNull HttpRequest httpRequest, @NonNull Response response, @NonNull Type type) throws Throwable { if (Response.class.equals(type)) { return response; @@ -91,7 +91,7 @@ public Object requestSucceed(LifecycleOwner lifecycle, IRequestApi api, Response } // 打印这个 Json 或者文本 - EasyLog.json(text); + EasyLog.printJson(httpRequest,text); if (String.class.equals(type)) { return text; @@ -134,20 +134,20 @@ public Object requestSucceed(LifecycleOwner lifecycle, IRequestApi api, Response if (model.isTokenFailure()) { // 代表登录失效,需要重新登录 - throw new TokenException(mApplication.getString(R.string.http_token_error)); + throw new HttpException(mApplication.getString(R.string.http_token_error)); } // 代表执行失败 - throw new ResultException(model.getMessage(), model); + throw new HttpException(model.getMessage()); } return result; } @Override - public Exception requestFail(LifecycleOwner lifecycle, IRequestApi api, Exception e) { + public Throwable requestFail(@NonNull HttpRequest httpRequest, @NonNull Throwable e) { // 判断这个异常是不是自己抛的 if (e instanceof HttpException) { - if (e instanceof TokenException) { + if (e.getMessage().equals(mApplication.getString(R.string.http_token_error))) { // 登录信息失效,跳转到登录页 Application application = ActivityManager.getInstance().getApplication(); Intent intent = new Intent(application, LoginActivity.class); @@ -183,31 +183,32 @@ public Exception requestFail(LifecycleOwner lifecycle, IRequestApi api, Exceptio return new HttpException(e.getMessage(), e); } - @Override - public Object readCache(LifecycleOwner lifecycle, IRequestApi api, Type type) { - String cacheKey = GsonFactory.getSingletonGson().toJson(api); + + @Override + public Object readCache(@NonNull HttpRequest httpRequest, @NonNull Type type, long cacheTime) throws Throwable{ + String cacheKey = GsonFactory.getSingletonGson().toJson(httpRequest.getRequestApi()); String cacheValue = mMmkv.getString(cacheKey, null); if (cacheValue == null || "".equals(cacheValue) || "{}".equals(cacheValue)) { return null; } - EasyLog.print("---------- cacheKey ----------"); - EasyLog.json(cacheKey); - EasyLog.print("---------- cacheValue ----------"); - EasyLog.json(cacheValue); + EasyLog.printLog(httpRequest,"---------- cacheKey ----------"); + EasyLog.printJson(httpRequest,cacheKey); + EasyLog.printLog(httpRequest,"---------- cacheValue ----------"); + EasyLog.printJson(httpRequest,cacheValue); return GsonFactory.getSingletonGson().fromJson(cacheValue, type); } - @Override - public boolean writeCache(LifecycleOwner lifecycle, IRequestApi api, Response response, Object result) { - String cacheKey = GsonFactory.getSingletonGson().toJson(api); + @Override + public boolean writeCache(@NonNull HttpRequest httpRequest, @NonNull Response response, @NonNull Object result) throws Throwable { + String cacheKey = GsonFactory.getSingletonGson().toJson(httpRequest.getRequestApi()); String cacheValue = GsonFactory.getSingletonGson().toJson(result); if (cacheValue == null || "".equals(cacheValue) || "{}".equals(cacheValue)) { return false; } - EasyLog.print("---------- cacheKey ----------"); - EasyLog.json(cacheKey); - EasyLog.print("---------- cacheValue ----------"); - EasyLog.json(cacheValue); + EasyLog.printLog(httpRequest,"---------- cacheKey ----------"); + EasyLog.printJson(httpRequest,cacheKey); + EasyLog.printLog(httpRequest,"---------- cacheValue ----------"); + EasyLog.printJson(httpRequest,cacheValue); return mMmkv.putString(cacheKey, cacheValue).commit(); } } \ No newline at end of file diff --git a/app/src/main/java/com/hjq/demo/http/model/RequestServer.java b/app/src/main/java/com/hjq/demo/http/model/RequestServer.java index 9e3eca09..6670e1a6 100644 --- a/app/src/main/java/com/hjq/demo/http/model/RequestServer.java +++ b/app/src/main/java/com/hjq/demo/http/model/RequestServer.java @@ -1,8 +1,11 @@ package com.hjq.demo.http.model; +import androidx.annotation.NonNull; + import com.hjq.demo.other.AppConfig; +import com.hjq.http.config.IRequestBodyStrategy; import com.hjq.http.config.IRequestServer; -import com.hjq.http.model.BodyType; +import com.hjq.http.model.RequestBodyType; /** * author : Android 轮子哥 @@ -17,14 +20,9 @@ public String getHost() { return AppConfig.getHostUrl(); } - @Override - public String getPath() { - return "api/"; - } - - @Override - public BodyType getType() { - // 以表单的形式提交参数 - return BodyType.FORM; - } + @NonNull + @Override + public IRequestBodyStrategy getBodyType() { + return RequestBodyType.JSON; + } } \ No newline at end of file diff --git a/app/src/main/java/com/hjq/demo/other/PermissionCallback.java b/app/src/main/java/com/hjq/demo/other/PermissionCallback.java index 66d3d656..83f7d70b 100644 --- a/app/src/main/java/com/hjq/demo/other/PermissionCallback.java +++ b/app/src/main/java/com/hjq/demo/other/PermissionCallback.java @@ -10,7 +10,8 @@ import com.hjq.permissions.OnPermissionCallback; import com.hjq.permissions.Permission; import com.hjq.permissions.XXPermissions; -import com.hjq.toast.ToastUtils; +import com.hjq.toast.Toaster; + import java.util.ArrayList; import java.util.List; @@ -31,11 +32,11 @@ public void onDenied(List permissions, boolean never) { } if (permissions.size() == 1 && Permission.ACCESS_BACKGROUND_LOCATION.equals(permissions.get(0))) { - ToastUtils.show(R.string.common_permission_fail_4); + Toaster.show(R.string.common_permission_fail_4); return; } - ToastUtils.show(R.string.common_permission_fail_1); + Toaster.show(R.string.common_permission_fail_1); } /** diff --git a/app/src/main/java/com/hjq/demo/other/TitleBarStyle.java b/app/src/main/java/com/hjq/demo/other/TitleBarStyle.java index 5a5954ef..772a7c86 100644 --- a/app/src/main/java/com/hjq/demo/other/TitleBarStyle.java +++ b/app/src/main/java/com/hjq/demo/other/TitleBarStyle.java @@ -56,10 +56,7 @@ public Drawable getRightTitleBackground(Context context) { return null; } - @Override - public int getChildHorizontalPadding(Context context) { - return (int) context.getResources().getDimension(R.dimen.dp_12); - } + @Override public int getChildVerticalPadding(Context context) { diff --git a/app/src/main/java/com/hjq/demo/other/ToastLogInterceptor.java b/app/src/main/java/com/hjq/demo/other/ToastLogInterceptor.java index 46dfcadf..8b3bf2ba 100644 --- a/app/src/main/java/com/hjq/demo/other/ToastLogInterceptor.java +++ b/app/src/main/java/com/hjq/demo/other/ToastLogInterceptor.java @@ -2,7 +2,9 @@ import com.hjq.demo.action.ToastAction; -import com.hjq.toast.ToastUtils; + +import com.hjq.toast.ToastParams; +import com.hjq.toast.Toaster; import com.hjq.toast.config.IToastInterceptor; import timber.log.Timber; @@ -16,7 +18,7 @@ public final class ToastLogInterceptor implements IToastInterceptor { @Override - public boolean intercept(CharSequence text) { + public boolean intercept(ToastParams params) { if (AppConfig.isLogEnable()) { // 获取调用的堆栈信息 StackTraceElement[] stackTrace = new Throwable().getStackTrace(); @@ -26,13 +28,13 @@ public boolean intercept(CharSequence text) { int lineNumber = stackTrace[i].getLineNumber(); // 获取类的全路径 String className = stackTrace[i].getClassName(); - if (lineNumber <= 0 || className.startsWith(ToastUtils.class.getName()) || + if (lineNumber <= 0 || className.startsWith(Toaster.class.getName()) || className.startsWith(ToastAction.class.getName())) { continue; } Timber.tag("ToastUtils"); - Timber.i("(" + stackTrace[i].getFileName() + ":" + lineNumber + ") " + text.toString()); + Timber.i("(" + stackTrace[i].getFileName() + ":" + lineNumber + ") " + params.toString()); break; } } diff --git a/app/src/main/java/com/hjq/demo/ui/activity/BrowserActivity.java b/app/src/main/java/com/hjq/demo/ui/activity/BrowserActivity.java index 5662873d..2eb603b0 100644 --- a/app/src/main/java/com/hjq/demo/ui/activity/BrowserActivity.java +++ b/app/src/main/java/com/hjq/demo/ui/activity/BrowserActivity.java @@ -13,6 +13,7 @@ import androidx.annotation.NonNull; +import com.hjq.bar.TitleBar; import com.hjq.demo.R; import com.hjq.demo.action.StatusAction; import com.hjq.demo.aop.CheckNet; @@ -87,7 +88,7 @@ public StatusLayout getStatusLayout() { } @Override - public void onLeftClick(View view) { + public void onLeftClick(TitleBar titleBar) { finish(); } diff --git a/app/src/main/java/com/hjq/demo/ui/activity/DialogActivity.java b/app/src/main/java/com/hjq/demo/ui/activity/DialogActivity.java index 860bcb0a..03c074e8 100644 --- a/app/src/main/java/com/hjq/demo/ui/activity/DialogActivity.java +++ b/app/src/main/java/com/hjq/demo/ui/activity/DialogActivity.java @@ -7,6 +7,7 @@ import androidx.annotation.Nullable; +import com.hjq.bar.TitleBar; import com.hjq.base.BaseDialog; import com.hjq.demo.R; import com.hjq.demo.aop.SingleClick; @@ -511,14 +512,14 @@ public void onCancel(BaseDialog dialog) { } @Override - public void onRightClick(View view) { + public void onRightClick(TitleBar titleBar) { // 菜单弹窗 new ListPopup.Builder(this) .setList("选择拍照", "选取相册") .addOnShowListener(popupWindow -> toast("PopupWindow 显示了")) .addOnDismissListener(popupWindow -> toast("PopupWindow 销毁了")) .setListener((ListPopup.OnListener) (popupWindow, position, s) -> toast("点击了:" + s)) - .showAsDropDown(view); + .showAsDropDown(titleBar.getRightView()); } @Override diff --git a/app/src/main/java/com/hjq/demo/ui/activity/ImageSelectActivity.java b/app/src/main/java/com/hjq/demo/ui/activity/ImageSelectActivity.java index 9aaef71e..e14e6e4f 100644 --- a/app/src/main/java/com/hjq/demo/ui/activity/ImageSelectActivity.java +++ b/app/src/main/java/com/hjq/demo/ui/activity/ImageSelectActivity.java @@ -12,6 +12,7 @@ import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; +import com.hjq.bar.TitleBar; import com.hjq.base.BaseActivity; import com.hjq.base.BaseAdapter; import com.hjq.demo.R; @@ -173,7 +174,7 @@ public StatusLayout getStatusLayout() { @SingleClick @Override - public void onRightClick(View view) { + public void onRightClick(TitleBar titleBar) { if (mAllImage.isEmpty()) { return; } diff --git a/app/src/main/java/com/hjq/demo/ui/activity/LoginActivity.java b/app/src/main/java/com/hjq/demo/ui/activity/LoginActivity.java index 59d18998..209b2c26 100644 --- a/app/src/main/java/com/hjq/demo/ui/activity/LoginActivity.java +++ b/app/src/main/java/com/hjq/demo/ui/activity/LoginActivity.java @@ -19,6 +19,7 @@ import androidx.annotation.Nullable; import com.gyf.immersionbar.ImmersionBar; +import com.hjq.bar.TitleBar; import com.hjq.demo.R; import com.hjq.demo.aop.Log; import com.hjq.demo.aop.SingleClick; @@ -32,7 +33,8 @@ import com.hjq.demo.wxapi.WXEntryActivity; import com.hjq.http.EasyConfig; import com.hjq.http.EasyHttp; -import com.hjq.http.listener.HttpCallback; +import com.hjq.http.config.IRequestApi; +import com.hjq.http.listener.OnHttpListener; import com.hjq.umeng.Platform; import com.hjq.umeng.UmengClient; import com.hjq.umeng.UmengLogin; @@ -139,7 +141,7 @@ protected void initData() { } @Override - public void onRightClick(View view) { + public void onRightClick(TitleBar titleBar) { // 跳转到注册界面 RegisterActivity.start(this, mPhoneView.getText().toString(), mPasswordView.getText().toString(), (phone, password) -> { @@ -187,38 +189,39 @@ public void onClick(View view) { .api(new LoginApi() .setPhone(mPhoneView.getText().toString()) .setPassword(mPasswordView.getText().toString())) - .request(new HttpCallback>(this) { - - @Override - public void onStart(Call call) { - mCommitView.showProgress(); - } - - @Override - public void onEnd(Call call) {} - - @Override - public void onSucceed(HttpData data) { - // 更新 Token - EasyConfig.getInstance() - .addParam("token", data.getData().getToken()); - postDelayed(() -> { - mCommitView.showSucceed(); - postDelayed(() -> { - // 跳转到首页 - HomeActivity.start(getContext(), MineFragment.class); - finish(); - }, 1000); - }, 1000); - } - - @Override - public void onFail(Exception e) { - super.onFail(e); - postDelayed(() -> { - mCommitView.showError(3000); - }, 1000); - } + .request(new OnHttpListener>() { + + @Override + public void onHttpStart(@NonNull IRequestApi api) { + mCommitView.showProgress(); + } + + @Override + public void onHttpEnd(@NonNull IRequestApi api) { + OnHttpListener.super.onHttpEnd(api); + } + + @Override + public void onHttpSuccess(@NonNull HttpData result) { + // 更新 Token + EasyConfig.getInstance() + .addParam("token", result.getData().getToken()); + postDelayed(() -> { + mCommitView.showSucceed(); + postDelayed(() -> { + // 跳转到首页 + HomeActivity.start(getContext(), MineFragment.class); + finish(); + }, 1000); + }, 1000); + } + + @Override + public void onHttpFail(@NonNull Throwable throwable) { + postDelayed(() -> { + mCommitView.showError(3000); + }, 1000); + } }); return; } diff --git a/app/src/main/java/com/hjq/demo/ui/activity/PasswordForgetActivity.java b/app/src/main/java/com/hjq/demo/ui/activity/PasswordForgetActivity.java index 2f21e6d0..31dcfe28 100644 --- a/app/src/main/java/com/hjq/demo/ui/activity/PasswordForgetActivity.java +++ b/app/src/main/java/com/hjq/demo/ui/activity/PasswordForgetActivity.java @@ -8,6 +8,8 @@ import android.widget.EditText; import android.widget.TextView; +import androidx.annotation.NonNull; + import com.hjq.demo.R; import com.hjq.demo.aop.SingleClick; import com.hjq.demo.app.AppActivity; @@ -16,7 +18,7 @@ import com.hjq.demo.http.model.HttpData; import com.hjq.demo.manager.InputTextManager; import com.hjq.http.EasyHttp; -import com.hjq.http.listener.HttpCallback; +import com.hjq.http.listener.OnHttpListener; import com.hjq.widget.view.CountdownView; /** @@ -84,13 +86,18 @@ public void onClick(View view) { EasyHttp.post(this) .api(new GetCodeApi() .setPhone(mPhoneView.getText().toString())) - .request(new HttpCallback>(this) { + .request(new OnHttpListener>() { + + @Override + public void onHttpSuccess(@NonNull HttpData result) { + toast(R.string.common_code_send_hint); + mCountdownView.start(); + } + + @Override + public void onHttpFail(@NonNull Throwable throwable) { - @Override - public void onSucceed(HttpData data) { - toast(R.string.common_code_send_hint); - mCountdownView.start(); - } + } }); } else if (view == mCommitView) { @@ -117,13 +124,19 @@ public void onSucceed(HttpData data) { .api(new VerifyCodeApi() .setPhone(mPhoneView.getText().toString()) .setCode(mCodeView.getText().toString())) - .request(new HttpCallback>(this) { + .request(new OnHttpListener>() { + + + @Override + public void onHttpSuccess(@NonNull HttpData result) { + PasswordResetActivity.start(getActivity(), mPhoneView.getText().toString(), mCodeView.getText().toString()); + finish(); + } + + @Override + public void onHttpFail(@NonNull Throwable throwable) { - @Override - public void onSucceed(HttpData data) { - PasswordResetActivity.start(getActivity(), mPhoneView.getText().toString(), mCodeView.getText().toString()); - finish(); - } + } }); } } diff --git a/app/src/main/java/com/hjq/demo/ui/activity/PasswordResetActivity.java b/app/src/main/java/com/hjq/demo/ui/activity/PasswordResetActivity.java index e7b86943..0a7ee660 100644 --- a/app/src/main/java/com/hjq/demo/ui/activity/PasswordResetActivity.java +++ b/app/src/main/java/com/hjq/demo/ui/activity/PasswordResetActivity.java @@ -11,6 +11,8 @@ import android.widget.EditText; import android.widget.TextView; +import androidx.annotation.NonNull; + import com.hjq.demo.R; import com.hjq.demo.aop.Log; import com.hjq.demo.aop.SingleClick; @@ -20,7 +22,7 @@ import com.hjq.demo.manager.InputTextManager; import com.hjq.demo.ui.dialog.TipsDialog; import com.hjq.http.EasyHttp; -import com.hjq.http.listener.HttpCallback; +import com.hjq.http.listener.OnHttpListener; /** * author : Android 轮子哥 @@ -113,17 +115,22 @@ public void onClick(View view) { .setPhone(mPhoneNumber) .setCode(mVerifyCode) .setPassword(mFirstPassword.getText().toString())) - .request(new HttpCallback>(this) { - - @Override - public void onSucceed(HttpData data) { - new TipsDialog.Builder(getActivity()) - .setIcon(TipsDialog.ICON_FINISH) - .setMessage(R.string.password_reset_success) - .setDuration(2000) - .addOnDismissListener(dialog -> finish()) - .show(); - } + .request(new OnHttpListener>() { + + @Override + public void onHttpSuccess(@NonNull HttpData result) { + new TipsDialog.Builder(getActivity()) + .setIcon(TipsDialog.ICON_FINISH) + .setMessage(R.string.password_reset_success) + .setDuration(2000) + .addOnDismissListener(dialog -> finish()) + .show(); + } + + @Override + public void onHttpFail(@NonNull Throwable throwable) { + + } }); } } diff --git a/app/src/main/java/com/hjq/demo/ui/activity/PersonalDataActivity.java b/app/src/main/java/com/hjq/demo/ui/activity/PersonalDataActivity.java index 79ec574f..aa3ef42b 100644 --- a/app/src/main/java/com/hjq/demo/ui/activity/PersonalDataActivity.java +++ b/app/src/main/java/com/hjq/demo/ui/activity/PersonalDataActivity.java @@ -6,6 +6,8 @@ import android.view.ViewGroup; import android.widget.ImageView; +import androidx.annotation.NonNull; + import com.bumptech.glide.load.MultiTransformation; import com.bumptech.glide.load.resource.bitmap.CenterCrop; import com.bumptech.glide.load.resource.bitmap.CircleCrop; @@ -18,7 +20,7 @@ import com.hjq.demo.ui.dialog.AddressDialog; import com.hjq.demo.ui.dialog.InputDialog; import com.hjq.http.EasyHttp; -import com.hjq.http.listener.HttpCallback; +import com.hjq.http.listener.OnHttpListener; import com.hjq.http.model.FileContentResolver; import com.hjq.widget.layout.SettingBar; @@ -187,19 +189,24 @@ private void updateCropImage(File file, boolean deleteFile) { EasyHttp.post(this) .api(new UpdateImageApi() .setImage(file)) - .request(new HttpCallback>(this) { - - @Override - public void onSucceed(HttpData data) { - mAvatarUrl = Uri.parse(data.getData()); - GlideApp.with(getActivity()) - .load(mAvatarUrl) - .transform(new MultiTransformation<>(new CenterCrop(), new CircleCrop())) - .into(mAvatarView); - if (deleteFile) { - file.delete(); - } - } + .request(new OnHttpListener>() { + + @Override + public void onHttpSuccess(@NonNull HttpData result) { + mAvatarUrl = Uri.parse(result.getData()); + GlideApp.with(getActivity()) + .load(mAvatarUrl) + .transform(new MultiTransformation<>(new CenterCrop(), new CircleCrop())) + .into(mAvatarView); + if (deleteFile) { + file.delete(); + } + } + + @Override + public void onHttpFail(@NonNull Throwable throwable) { + + } }); } } \ No newline at end of file diff --git a/app/src/main/java/com/hjq/demo/ui/activity/PhoneResetActivity.java b/app/src/main/java/com/hjq/demo/ui/activity/PhoneResetActivity.java index e218ea51..f4457340 100644 --- a/app/src/main/java/com/hjq/demo/ui/activity/PhoneResetActivity.java +++ b/app/src/main/java/com/hjq/demo/ui/activity/PhoneResetActivity.java @@ -11,6 +11,8 @@ import android.widget.EditText; import android.widget.TextView; +import androidx.annotation.NonNull; + import com.hjq.demo.R; import com.hjq.demo.aop.Log; import com.hjq.demo.aop.SingleClick; @@ -21,8 +23,9 @@ import com.hjq.demo.manager.InputTextManager; import com.hjq.demo.ui.dialog.TipsDialog; import com.hjq.http.EasyHttp; -import com.hjq.http.listener.HttpCallback; -import com.hjq.toast.ToastUtils; + +import com.hjq.http.listener.OnHttpListener; +import com.hjq.toast.Toaster; import com.hjq.widget.view.CountdownView; /** @@ -103,13 +106,18 @@ public void onClick(View view) { EasyHttp.post(this) .api(new GetCodeApi() .setPhone(mPhoneView.getText().toString())) - .request(new HttpCallback>(this) { + .request(new OnHttpListener>() { + + @Override + public void onHttpSuccess(@NonNull HttpData result) { + toast(R.string.common_code_send_hint); + mCountdownView.start(); + } + + @Override + public void onHttpFail(@NonNull Throwable throwable) { - @Override - public void onSucceed(HttpData data) { - toast(R.string.common_code_send_hint); - mCountdownView.start(); - } + } }); } else if (view == mCommitView) { @@ -120,7 +128,7 @@ public void onSucceed(HttpData data) { } if (mCodeView.getText().toString().length() != getResources().getInteger(R.integer.sms_code_length)) { - ToastUtils.show(R.string.common_code_error_hint); + Toaster.show(R.string.common_code_error_hint); return; } @@ -143,17 +151,22 @@ public void onSucceed(HttpData data) { .setPreCode(mVerifyCode) .setPhone(mPhoneView.getText().toString()) .setCode(mCodeView.getText().toString())) - .request(new HttpCallback>(this) { - - @Override - public void onSucceed(HttpData data) { - new TipsDialog.Builder(getActivity()) - .setIcon(TipsDialog.ICON_FINISH) - .setMessage(R.string.phone_reset_commit_succeed) - .setDuration(2000) - .addOnDismissListener(dialog -> finish()) - .show(); - } + .request(new OnHttpListener>() { + + @Override + public void onHttpSuccess(@NonNull HttpData result) { + new TipsDialog.Builder(getActivity()) + .setIcon(TipsDialog.ICON_FINISH) + .setMessage(R.string.phone_reset_commit_succeed) + .setDuration(2000) + .addOnDismissListener(dialog -> finish()) + .show(); + } + + @Override + public void onHttpFail(@NonNull Throwable throwable) { + + } }); } } diff --git a/app/src/main/java/com/hjq/demo/ui/activity/RegisterActivity.java b/app/src/main/java/com/hjq/demo/ui/activity/RegisterActivity.java index 657c9fb0..b3698f1a 100644 --- a/app/src/main/java/com/hjq/demo/ui/activity/RegisterActivity.java +++ b/app/src/main/java/com/hjq/demo/ui/activity/RegisterActivity.java @@ -21,7 +21,8 @@ import com.hjq.demo.http.model.HttpData; import com.hjq.demo.manager.InputTextManager; import com.hjq.http.EasyHttp; -import com.hjq.http.listener.HttpCallback; +import com.hjq.http.config.IRequestApi; +import com.hjq.http.listener.OnHttpListener; import com.hjq.widget.view.CountdownView; import com.hjq.widget.view.SubmitButton; @@ -126,19 +127,18 @@ public void onClick(View view) { EasyHttp.post(this) .api(new GetCodeApi() .setPhone(mPhoneView.getText().toString())) - .request(new HttpCallback>(this) { - - @Override - public void onSucceed(HttpData data) { - toast(R.string.common_code_send_hint); - mCountdownView.start(); - } - - @Override - public void onFail(Exception e) { - super.onFail(e); - mCountdownView.start(); - } + .request(new OnHttpListener>() { + + @Override + public void onHttpSuccess(@NonNull HttpData result) { + toast(R.string.common_code_send_hint); + mCountdownView.start(); + } + + @Override + public void onHttpFail(@NonNull Throwable throwable) { + mCountdownView.start(); + } }); } else if (view == mCommitView) { if (mPhoneView.getText().toString().length() != 11) { @@ -186,36 +186,37 @@ public void onFail(Exception e) { .setPhone(mPhoneView.getText().toString()) .setCode(mCodeView.getText().toString()) .setPassword(mFirstPassword.getText().toString())) - .request(new HttpCallback>(this) { - - @Override - public void onStart(Call call) { - mCommitView.showProgress(); - } - - @Override - public void onEnd(Call call) {} - - @Override - public void onSucceed(HttpData data) { - postDelayed(() -> { - mCommitView.showSucceed(); - postDelayed(() -> { - setResult(RESULT_OK, new Intent() - .putExtra(INTENT_KEY_PHONE, mPhoneView.getText().toString()) - .putExtra(INTENT_KEY_PASSWORD, mFirstPassword.getText().toString())); - finish(); - }, 1000); - }, 1000); - } - - @Override - public void onFail(Exception e) { - super.onFail(e); - postDelayed(() -> { - mCommitView.showError(3000); - }, 1000); - } + .request(new OnHttpListener>() { + + @Override + public void onHttpStart(@NonNull IRequestApi api) { + mCommitView.showProgress(); + } + + @Override + public void onHttpEnd(@NonNull IRequestApi api) { + OnHttpListener.super.onHttpEnd(api); + } + + @Override + public void onHttpSuccess(@NonNull HttpData result) { + postDelayed(() -> { + mCommitView.showSucceed(); + postDelayed(() -> { + setResult(RESULT_OK, new Intent() + .putExtra(INTENT_KEY_PHONE, mPhoneView.getText().toString()) + .putExtra(INTENT_KEY_PASSWORD, mFirstPassword.getText().toString())); + finish(); + }, 1000); + }, 1000); + } + + @Override + public void onHttpFail(@NonNull Throwable throwable) { + postDelayed(() -> { + mCommitView.showError(3000); + }, 1000); + } }); } } @@ -243,7 +244,7 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { return false; } - /** + /** * 注册监听 */ public interface OnRegisterListener { diff --git a/app/src/main/java/com/hjq/demo/ui/activity/SettingActivity.java b/app/src/main/java/com/hjq/demo/ui/activity/SettingActivity.java index f903db7c..2a0ac42a 100644 --- a/app/src/main/java/com/hjq/demo/ui/activity/SettingActivity.java +++ b/app/src/main/java/com/hjq/demo/ui/activity/SettingActivity.java @@ -3,6 +3,8 @@ import android.view.Gravity; import android.view.View; +import androidx.annotation.NonNull; + import com.hjq.base.BaseDialog; import com.hjq.demo.R; import com.hjq.demo.aop.SingleClick; @@ -18,7 +20,7 @@ import com.hjq.demo.ui.dialog.SafeDialog; import com.hjq.demo.ui.dialog.UpdateDialog; import com.hjq.http.EasyHttp; -import com.hjq.http.listener.HttpCallback; +import com.hjq.http.listener.OnHttpListener; import com.hjq.widget.layout.SettingBar; import com.hjq.widget.view.SwitchButton; @@ -153,16 +155,7 @@ public void onClick(View view) { // 退出登录 EasyHttp.post(this) .api(new LogoutApi()) - .request(new HttpCallback>(this) { - - @Override - public void onSucceed(HttpData data) { - startActivity(LoginActivity.class); - // 进行内存优化,销毁除登录页之外的所有界面 - ActivityManager.getInstance().finishAllActivities(LoginActivity.class); - } - }); - + .request(this); } } @@ -174,4 +167,16 @@ public void onSucceed(HttpData data) { public void onCheckedChanged(SwitchButton button, boolean checked) { toast(checked); } + + @Override + public void onHttpSuccess(@NonNull Object result) { + startActivity(LoginActivity.class); + // 进行内存优化,销毁除登录页之外的所有界面 + ActivityManager.getInstance().finishAllActivities(LoginActivity.class); + } + + @Override + public void onHttpFail(@NonNull Throwable throwable) { + + } } \ No newline at end of file diff --git a/app/src/main/java/com/hjq/demo/ui/activity/SplashActivity.java b/app/src/main/java/com/hjq/demo/ui/activity/SplashActivity.java index 29344b86..8766142a 100644 --- a/app/src/main/java/com/hjq/demo/ui/activity/SplashActivity.java +++ b/app/src/main/java/com/hjq/demo/ui/activity/SplashActivity.java @@ -16,7 +16,7 @@ import com.hjq.demo.http.model.HttpData; import com.hjq.demo.other.AppConfig; import com.hjq.http.EasyHttp; -import com.hjq.http.listener.HttpCallback; +import com.hjq.http.listener.OnHttpListener; import com.hjq.widget.view.SlantedTextView; /** @@ -66,12 +66,16 @@ protected void initData() { // 刷新用户信息 EasyHttp.post(this) .api(new UserInfoApi()) - .request(new HttpCallback>(this) { + .request(new OnHttpListener>() { + @Override + public void onHttpSuccess(@NonNull HttpData result) { - @Override - public void onSucceed(HttpData data) { + } - } + @Override + public void onHttpFail(@NonNull Throwable throwable) { + + } }); } @@ -113,4 +117,14 @@ protected void onDestroy() { // 所以如果需要在此处释放对象资源需要先对这个对象进行判空,否则可能会导致空指针异常 super.onDestroy(); } + + @Override + public void onHttpSuccess(@NonNull Object result) { + + } + + @Override + public void onHttpFail(@NonNull Throwable throwable) { + + } } \ No newline at end of file diff --git a/app/src/main/java/com/hjq/demo/ui/activity/VideoSelectActivity.java b/app/src/main/java/com/hjq/demo/ui/activity/VideoSelectActivity.java index c5909648..02449498 100644 --- a/app/src/main/java/com/hjq/demo/ui/activity/VideoSelectActivity.java +++ b/app/src/main/java/com/hjq/demo/ui/activity/VideoSelectActivity.java @@ -17,6 +17,7 @@ import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; +import com.hjq.bar.TitleBar; import com.hjq.base.BaseActivity; import com.hjq.base.BaseAdapter; import com.hjq.demo.R; @@ -179,7 +180,7 @@ public StatusLayout getStatusLayout() { @SingleClick @Override - public void onRightClick(View view) { + public void onRightClick(TitleBar titleBar) { if (mAllVideo.isEmpty()) { return; } diff --git a/app/src/main/java/com/hjq/demo/ui/dialog/SafeDialog.java b/app/src/main/java/com/hjq/demo/ui/dialog/SafeDialog.java index bb047a83..3012f502 100644 --- a/app/src/main/java/com/hjq/demo/ui/dialog/SafeDialog.java +++ b/app/src/main/java/com/hjq/demo/ui/dialog/SafeDialog.java @@ -5,6 +5,7 @@ import android.widget.EditText; import android.widget.TextView; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.hjq.base.BaseDialog; @@ -15,7 +16,8 @@ import com.hjq.demo.http.model.HttpData; import com.hjq.http.EasyHttp; import com.hjq.http.listener.OnHttpListener; -import com.hjq.toast.ToastUtils; + +import com.hjq.toast.Toaster; import com.hjq.widget.view.CountdownView; /** @@ -69,7 +71,7 @@ public void onClick(View view) { int viewId = view.getId(); if (viewId == R.id.cv_safe_countdown) { if (true) { - ToastUtils.show(R.string.common_code_send_hint); + Toaster.show(R.string.common_code_send_hint); mCountdownView.start(); setCancelable(false); return; @@ -81,21 +83,21 @@ public void onClick(View view) { .setPhone(mPhoneNumber)) .request(new OnHttpListener>() { - @Override - public void onSucceed(HttpData data) { - ToastUtils.show(R.string.common_code_send_hint); - mCountdownView.start(); - setCancelable(false); - } - - @Override - public void onFail(Exception e) { - ToastUtils.show(e.getMessage()); - } + @Override + public void onHttpSuccess(@NonNull HttpData result) { + Toaster.show(R.string.common_code_send_hint); + mCountdownView.start(); + setCancelable(false); + } + + @Override + public void onHttpFail(@NonNull Throwable throwable) { + Toaster.show(throwable.getMessage()); + } }); } else if (viewId == R.id.tv_ui_confirm) { if (mCodeView.getText().toString().length() != getResources().getInteger(R.integer.sms_code_length)) { - ToastUtils.show(R.string.common_code_error_hint); + Toaster.show(R.string.common_code_error_hint); return; } @@ -115,19 +117,19 @@ public void onFail(Exception e) { .setCode(mCodeView.getText().toString())) .request(new OnHttpListener>() { - @Override - public void onSucceed(HttpData data) { - autoDismiss(); - if (mListener == null) { - return; - } - mListener.onConfirm(getDialog(), mPhoneNumber, mCodeView.getText().toString()); - } - - @Override - public void onFail(Exception e) { - ToastUtils.show(e.getMessage()); - } + @Override + public void onHttpSuccess(@NonNull HttpData result) { + autoDismiss(); + if (mListener == null) { + return; + } + mListener.onConfirm(getDialog(), mPhoneNumber, mCodeView.getText().toString()); + } + + @Override + public void onHttpFail(@NonNull Throwable throwable) { + Toaster.show(throwable.getMessage()); + } }); } else if (viewId == R.id.tv_ui_cancel) { autoDismiss(); diff --git a/app/src/main/java/com/hjq/demo/ui/dialog/SelectDialog.java b/app/src/main/java/com/hjq/demo/ui/dialog/SelectDialog.java index a5c1ad1f..0a6c013c 100644 --- a/app/src/main/java/com/hjq/demo/ui/dialog/SelectDialog.java +++ b/app/src/main/java/com/hjq/demo/ui/dialog/SelectDialog.java @@ -18,7 +18,8 @@ import com.hjq.demo.R; import com.hjq.demo.aop.SingleClick; import com.hjq.demo.app.AppAdapter; -import com.hjq.toast.ToastUtils; +import com.hjq.toast.Toaster; + import java.util.ArrayList; import java.util.Arrays; @@ -126,7 +127,7 @@ public void onClick(View view) { } mListener.onSelected(getDialog(), data); } else { - ToastUtils.show(String.format(getString(R.string.select_min_hint), mAdapter.getMinSelect())); + Toaster.show(String.format(getString(R.string.select_min_hint), mAdapter.getMinSelect())); } } else if (viewId == R.id.tv_ui_cancel) { autoDismiss(); @@ -251,7 +252,7 @@ public void onItemClick(RecyclerView recyclerView, View itemView, int position) mSelectSet.put(position, getItem(position)); notifyItemChanged(position); } else { - ToastUtils.show(String.format(getString(R.string.select_max_hint), mMaxSelect)); + Toaster.show(String.format(getString(R.string.select_max_hint), mMaxSelect)); } } } diff --git a/app/src/main/java/com/hjq/demo/ui/dialog/ShareDialog.java b/app/src/main/java/com/hjq/demo/ui/dialog/ShareDialog.java index 634253fd..d8f80a0e 100644 --- a/app/src/main/java/com/hjq/demo/ui/dialog/ShareDialog.java +++ b/app/src/main/java/com/hjq/demo/ui/dialog/ShareDialog.java @@ -19,7 +19,8 @@ import com.hjq.base.BaseDialog; import com.hjq.demo.R; import com.hjq.demo.app.AppAdapter; -import com.hjq.toast.ToastUtils; + +import com.hjq.toast.Toaster; import com.hjq.umeng.Platform; import com.hjq.umeng.UmengClient; import com.hjq.umeng.UmengShare; @@ -173,7 +174,7 @@ public void onItemClick(RecyclerView recyclerView, View itemView, int position) if (mShareAction.getShareContent().getShareType() == ShareContent.WEB_STYLE) { // 复制到剪贴板 getSystemService(ClipboardManager.class).setPrimaryClip(ClipData.newPlainText("url", mShareAction.getShareContent().mMedia.toUrl())); - ToastUtils.show(R.string.share_platform_copy_hint); + Toaster.show(R.string.share_platform_copy_hint); } } dismiss(); diff --git a/app/src/main/java/com/hjq/demo/ui/dialog/UpdateDialog.java b/app/src/main/java/com/hjq/demo/ui/dialog/UpdateDialog.java index d70c7ddb..bd564936 100644 --- a/app/src/main/java/com/hjq/demo/ui/dialog/UpdateDialog.java +++ b/app/src/main/java/com/hjq/demo/ui/dialog/UpdateDialog.java @@ -14,6 +14,7 @@ import android.widget.ProgressBar; import android.widget.TextView; +import androidx.annotation.NonNull; import androidx.core.app.NotificationCompat; import androidx.core.content.FileProvider; @@ -196,81 +197,80 @@ private void downloadApk() { .md5(mFileMd5) .listener(new OnDownloadListener() { - @Override - public void onStart(File file) { - // 标记为下载中 - mDownloading = true; - // 标记成未下载完成 - mDownloadComplete = false; - // 后台更新 - mCloseView.setVisibility(View.GONE); - // 显示进度条 - mProgressView.setVisibility(View.VISIBLE); - mUpdateView.setText(R.string.update_status_start); - } - - @Override - public void onProgress(File file, int progress) { - mUpdateView.setText(String.format(getString(R.string.update_status_running), progress)); - mProgressView.setProgress(progress); - // 更新下载通知 - notificationManager.notify(notificationId, notificationBuilder - // 设置通知的文本 - .setContentText(String.format(getString(R.string.update_status_running), progress)) - // 设置下载的进度 - .setProgress(100, progress, false) - // 设置点击通知后是否自动消失 - .setAutoCancel(false) - // 是否正在交互中 - .setOngoing(true) - // 重新创建新的通知对象 - .build()); - } - - @Override - public void onComplete(File file) { - // 显示下载成功通知 - notificationManager.notify(notificationId, notificationBuilder - // 设置通知的文本 - .setContentText(String.format(getString(R.string.update_status_successful), 100)) - // 设置下载的进度 - .setProgress(100, 100, false) - // 设置通知点击之后的意图 - .setContentIntent(PendingIntent.getActivity(getContext(), 1, getInstallIntent(), Intent.FILL_IN_ACTION)) - // 设置点击通知后是否自动消失 - .setAutoCancel(true) - // 是否正在交互中 - .setOngoing(false) - .build()); - mUpdateView.setText(R.string.update_status_successful); - // 标记成下载完成 - mDownloadComplete = true; - // 安装 Apk - installApk(); - } - - @SuppressWarnings("ResultOfMethodCallIgnored") - @Override - public void onError(File file, Exception e) { - // 清除通知 - notificationManager.cancel(notificationId); - mUpdateView.setText(R.string.update_status_failed); - // 删除下载的文件 - file.delete(); - } - - @Override - public void onEnd(File file) { - // 更新进度条 - mProgressView.setProgress(0); - mProgressView.setVisibility(View.GONE); - // 标记当前不是下载中 - mDownloading = false; - // 如果当前不是强制更新,对话框就恢复成可取消状态 - if (!mForceUpdate) { - setCancelable(true); - } - } + @Override + public void onDownloadProgressChange(@NonNull File file, int progress) { + mUpdateView.setText(String.format(getString(R.string.update_status_running), progress)); + mProgressView.setProgress(progress); + // 更新下载通知 + notificationManager.notify(notificationId, notificationBuilder + // 设置通知的文本 + .setContentText(String.format(getString(R.string.update_status_running), progress)) + // 设置下载的进度 + .setProgress(100, progress, false) + // 设置点击通知后是否自动消失 + .setAutoCancel(false) + // 是否正在交互中 + .setOngoing(true) + // 重新创建新的通知对象 + .build()); + } + + @Override + public void onDownloadSuccess(@NonNull File file) { + // 显示下载成功通知 + notificationManager.notify(notificationId, notificationBuilder + // 设置通知的文本 + .setContentText(String.format(getString(R.string.update_status_successful), 100)) + // 设置下载的进度 + .setProgress(100, 100, false) + // 设置通知点击之后的意图 + .setContentIntent(PendingIntent.getActivity(getContext(), 1, getInstallIntent(), Intent.FILL_IN_ACTION)) + // 设置点击通知后是否自动消失 + .setAutoCancel(true) + // 是否正在交互中 + .setOngoing(false) + .build()); + mUpdateView.setText(R.string.update_status_successful); + // 标记成下载完成 + mDownloadComplete = true; + // 安装 Apk + installApk(); + } + + @Override + public void onDownloadFail(@NonNull File file, @NonNull Throwable throwable) { + // 清除通知 + notificationManager.cancel(notificationId); + mUpdateView.setText(R.string.update_status_failed); + // 删除下载的文件 + file.delete(); + } + + @Override + public void onDownloadStart(@NonNull File file) { + // 标记为下载中 + mDownloading = true; + // 标记成未下载完成 + mDownloadComplete = false; + // 后台更新 + mCloseView.setVisibility(View.GONE); + // 显示进度条 + mProgressView.setVisibility(View.VISIBLE); + mUpdateView.setText(R.string.update_status_start); + } + + @Override + public void onDownloadEnd(@NonNull File file) { + // 更新进度条 + mProgressView.setProgress(0); + mProgressView.setVisibility(View.GONE); + // 标记当前不是下载中 + mDownloading = false; + // 如果当前不是强制更新,对话框就恢复成可取消状态 + if (!mForceUpdate) { + setCancelable(true); + } + } }).start(); } diff --git a/app/src/main/res/layout/address_dialog.xml b/app/src/main/res/layout/address_dialog.xml index 18ee76c2..b98e2610 100644 --- a/app/src/main/res/layout/address_dialog.xml +++ b/app/src/main/res/layout/address_dialog.xml @@ -6,10 +6,10 @@ android:layout_height="wrap_content" android:layout_gravity="bottom" android:orientation="vertical" - app:shape="rectangle" + app:shape_type="rectangle" app:shape_solidColor="@color/white" - app:shape_topLeftRadius="@dimen/dp_20" - app:shape_topRightRadius="@dimen/dp_20" + app:shape_radiusInTopLeft="@dimen/dp_20" + app:shape_radiusInTopRight="@dimen/dp_20" tools:context=".ui.dialog.AddressDialog"> + app:shape_textStartColor="@color/common_button_pressed_color" /> diff --git a/app/src/main/res/layout/share_dialog.xml b/app/src/main/res/layout/share_dialog.xml index 8dd66944..62c75f7a 100644 --- a/app/src/main/res/layout/share_dialog.xml +++ b/app/src/main/res/layout/share_dialog.xml @@ -7,10 +7,10 @@ android:layout_gravity="bottom" android:background="@color/white" android:orientation="vertical" - app:shape="rectangle" + app:shape_type="rectangle" app:shape_solidColor="@color/white" - app:shape_topLeftRadius="@dimen/dp_20" - app:shape_topRightRadius="@dimen/dp_20" + app:shape_radiusInTopLeft="@dimen/dp_20" + app:shape_radiusInTopRight="@dimen/dp_20" tools:context=".ui.dialog.ShareDialog"> \ No newline at end of file diff --git a/app/src/main/res/layout/widget_player_view.xml b/app/src/main/res/layout/widget_player_view.xml index 0d6618e8..d18487f5 100644 --- a/app/src/main/res/layout/widget_player_view.xml +++ b/app/src/main/res/layout/widget_player_view.xml @@ -27,11 +27,7 @@ android:layout_gravity="top" android:orientation="horizontal" android:visibility="invisible" - app:shape="rectangle" - app:shape_angle="270" - app:shape_centerColor="@color/black20" - app:shape_endColor="@color/transparent" - app:shape_startColor="#AA000000" + app:shape_type="rectangle" tools:visibility="visible">