Skip to content

Commit 48c6560

Browse files
committed
移除界面侧滑功能及补充相关文档
修复 DialogManager 内存泄漏的问题 修复 Android 11 无法使用意图的问题 修复 Bugly 上报 Lottie 资源异常的问题 优化 SettingBar 自定义控件的代码逻辑
1 parent c1dcac5 commit 48c6560

25 files changed

+128
-136
lines changed

AndroidProject.apk

-4.28 KB
Binary file not shown.

HelpDoc.md

+33-21
Large diffs are not rendered by default.

app/build.gradle

-4
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,6 @@ dependencies {
182182
implementation 'com.scwang.smart:refresh-layout-kernel:2.0.3'
183183
implementation 'com.scwang.smart:refresh-header-material:2.0.3'
184184

185-
// 侧滑框架:https://github.com/luckybilly/SmartSwipe
186-
implementation 'com.billy.android:smart-swipe:1.1.2'
187-
implementation 'com.billy.android:smart-swipe-x:1.1.0'
188-
189185
// 日志打印框架:https://github.com/JakeWharton/timber
190186
implementation 'com.jakewharton.timber:timber:4.7.1'
191187

app/src/main/AndroidManifest.xml

+35-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
xmlns:tools="http://schemas.android.com/tools"
55
package="com.hjq.demo">
66

7-
<!-- 联网权限 -->
8-
<uses-permission android:name="android.permission.INTERNET" />
9-
10-
<!-- 网络状态 -->
7+
<!-- 网络相关 -->
118
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
129
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
10+
<uses-permission android:name="android.permission.INTERNET" />
1311

1412
<!-- 外部存储 -->
1513
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
@@ -206,4 +204,37 @@
206204

207205
</application>
208206

207+
<!-- Android 11 软件包可见性适配:https://www.jianshu.com/p/d1ccd425c4ce -->
208+
<queries>
209+
<!-- 拍照意图:MediaStore.ACTION_IMAGE_CAPTURE -->
210+
<intent>
211+
<action android:name="android.media.action.IMAGE_CAPTURE" />
212+
</intent>
213+
214+
<!-- 拍摄意图:MediaStore.ACTION_VIDEO_CAPTURE -->
215+
<intent>
216+
<action android:name="android.media.action.VIDEO_CAPTURE" />
217+
</intent>
218+
219+
<!-- 图片裁剪意图 -->
220+
<intent>
221+
<action android:name="com.android.camera.action.CROP" />
222+
</intent>
223+
224+
<!-- 打电话意图:Intent.ACTION_DIAL -->
225+
<intent>
226+
<action android:name="android.intent.action.DIAL" />
227+
</intent>
228+
229+
<!-- 分享意图:Intent.ACTION_SEND -->
230+
<intent>
231+
<action android:name="android.intent.action.SEND" />
232+
</intent>
233+
234+
<!-- 调起其他页面意图:Intent.ACTION_VIEW -->
235+
<intent>
236+
<action android:name="android.intent.action.VIEW" />
237+
</intent>
238+
</queries>
239+
209240
</manifest>

app/src/main/java/com/hjq/demo/action/StatusAction.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ default void showLoading(@RawRes int id) {
4747
*/
4848
default void showComplete() {
4949
StatusLayout layout = getStatusLayout();
50-
if (layout != null && layout.isShow()) {
51-
layout.hide();
50+
if (layout == null || !layout.isShow()) {
51+
return;
5252
}
53+
layout.hide();
5354
}
5455

5556
/**

app/src/main/java/com/hjq/demo/action/SwipeAction.java

-18
This file was deleted.

app/src/main/java/com/hjq/demo/app/AppActivity.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import com.hjq.base.BaseActivity;
1414
import com.hjq.base.BaseDialog;
1515
import com.hjq.demo.R;
16-
import com.hjq.demo.action.SwipeAction;
1716
import com.hjq.demo.action.TitleBarAction;
1817
import com.hjq.demo.action.ToastAction;
1918
import com.hjq.demo.http.model.HttpData;
@@ -29,8 +28,7 @@
2928
* desc : 业务 Activity 基类
3029
*/
3130
public abstract class AppActivity extends BaseActivity
32-
implements ToastAction, TitleBarAction,
33-
SwipeAction, OnHttpListener<Object> {
31+
implements ToastAction, TitleBarAction, OnHttpListener<Object> {
3432

3533
/** 标题栏对象 */
3634
private TitleBar mTitleBar;

app/src/main/java/com/hjq/demo/app/AppApplication.java

+1-11
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616
import androidx.lifecycle.Lifecycle;
1717
import androidx.lifecycle.LifecycleOwner;
1818

19-
import com.billy.android.swipe.SmartSwipeBack;
2019
import com.hjq.bar.TitleBar;
2120
import com.hjq.bar.initializer.LightBarInitializer;
2221
import com.hjq.demo.R;
23-
import com.hjq.demo.action.SwipeAction;
2422
import com.hjq.demo.aop.DebugLog;
2523
import com.hjq.demo.http.glide.GlideApp;
2624
import com.hjq.demo.http.model.RequestHandler;
@@ -76,7 +74,7 @@ public void onTrimMemory(int level) {
7674
* 初始化一些第三方框架
7775
*/
7876
public static void initSdk(Application application) {
79-
// 设置权限请求调试模式
77+
// 设置调试模式
8078
XXPermissions.setDebugMode(AppConfig.isDebug());
8179

8280
// 初始化吐司
@@ -161,14 +159,6 @@ protected TextView createTextView(Context context) {
161159
// 启用配置
162160
.into();
163161

164-
// Activity 侧滑返回
165-
SmartSwipeBack.activitySlidingBack(application, activity -> {
166-
if (activity instanceof SwipeAction) {
167-
return ((SwipeAction) activity).isSwipeEnable();
168-
}
169-
return true;
170-
});
171-
172162
// 初始化日志打印
173163
if (AppConfig.isLogEnable()) {
174164
Timber.plant(new DebugLoggerTree());

app/src/main/java/com/hjq/demo/manager/DialogManager.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,12 @@ public void onDismiss(BaseDialog dialog) {
8484
*/
8585

8686
@Override
87-
public void onStateChanged(@NonNull LifecycleOwner source, @NonNull Lifecycle.Event event) {
87+
public void onStateChanged(@NonNull LifecycleOwner lifecycleOwner, @NonNull Lifecycle.Event event) {
8888
if (event != Lifecycle.Event.ON_DESTROY) {
8989
return;
9090
}
91-
source.getLifecycle().removeObserver(this);
91+
DIALOG_MANAGER.remove(lifecycleOwner);
92+
lifecycleOwner.getLifecycle().removeObserver(this);
9293
clearShow();
9394
}
9495
}

app/src/main/java/com/hjq/demo/manager/InputTextManager.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,9 @@ public interface OnInputTextListener {
306306

307307
/**
308308
* 输入发生了变化
309+
*
309310
* @return 返回按钮的 Enabled 状态
310311
*/
311-
boolean onInputChange(InputTextManager helper);
312+
boolean onInputChange(InputTextManager manager);
312313
}
313314
}

app/src/main/java/com/hjq/demo/ui/activity/CameraActivity.java

-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ protected void initData() {
8080
}
8181
if (XXPermissions.isGrantedPermission(this, new String[]{Permission.MANAGE_EXTERNAL_STORAGE, Permission.CAMERA})
8282
&& intent.resolveActivity(getPackageManager()) != null) {
83-
8483
File file = getSerializable(IntentKey.FILE);
8584
if (file == null) {
8685
toast(R.string.camera_image_error);

app/src/main/java/com/hjq/demo/ui/activity/CrashActivity.java

-5
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,6 @@ public void onClick(View view) {
239239
}
240240
}
241241

242-
@Override
243-
public boolean isSwipeEnable() {
244-
return false;
245-
}
246-
247242
@Override
248243
public void onBackPressed() {
249244
// 按返回键重启应用

app/src/main/java/com/hjq/demo/ui/activity/GuideActivity.java

-5
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ protected void initData() {
4949
mIndicatorView.setViewPager(mViewPager);
5050
}
5151

52-
@Override
53-
public boolean isSwipeEnable() {
54-
return false;
55-
}
56-
5752
@SingleClick
5853
@Override
5954
public void onClick(View view) {

app/src/main/java/com/hjq/demo/ui/activity/HomeActivity.java

-5
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,4 @@ protected void onDestroy() {
156156
mViewPager.setAdapter(null);
157157
mBottomNavigationView.setOnNavigationItemSelectedListener(null);
158158
}
159-
160-
@Override
161-
public boolean isSwipeEnable() {
162-
return false;
163-
}
164159
}

app/src/main/java/com/hjq/demo/ui/activity/ImagePreviewActivity.java

-5
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,6 @@ public boolean isStatusBarDarkFont() {
138138
return false;
139139
}
140140

141-
@Override
142-
public boolean isSwipeEnable() {
143-
return false;
144-
}
145-
146141
/**
147142
* {@link ViewPager.OnPageChangeListener}
148143
*/

app/src/main/java/com/hjq/demo/ui/activity/LoginActivity.java

-5
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,4 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
359359
}
360360
return false;
361361
}
362-
363-
@Override
364-
public boolean isSwipeEnable() {
365-
return false;
366-
}
367362
}

app/src/main/java/com/hjq/demo/ui/activity/RegisterActivity.java

-5
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,6 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
240240
return false;
241241
}
242242

243-
@Override
244-
public boolean isSwipeEnable() {
245-
return false;
246-
}
247-
248243
/**
249244
* 注册监听
250245
*/

app/src/main/java/com/hjq/demo/ui/activity/SplashActivity.java

-5
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@ public void onBackPressed() {
9090
//super.onBackPressed();
9191
}
9292

93-
@Override
94-
public boolean isSwipeEnable() {
95-
return false;
96-
}
97-
9893
@Override
9994
protected void initActivity() {
10095
// 问题及方案:https://www.cnblogs.com/net168/p/5722752.html

app/src/main/java/com/hjq/demo/ui/activity/VideoPlayActivity.java

+1-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import com.gyf.immersionbar.BarHide;
1212
import com.gyf.immersionbar.ImmersionBar;
1313
import com.hjq.demo.R;
14-
import com.hjq.demo.action.SwipeAction;
1514
import com.hjq.demo.app.AppActivity;
1615
import com.hjq.demo.other.IntentKey;
1716
import com.hjq.demo.widget.PlayerView;
@@ -25,7 +24,7 @@
2524
* desc : 视频播放界面
2625
*/
2726
public final class VideoPlayActivity extends AppActivity
28-
implements SwipeAction, PlayerView.onPlayListener {
27+
implements PlayerView.onPlayListener {
2928

3029
private PlayerView mPlayerView;
3130
private VideoPlayActivity.Builder mBuilder;
@@ -90,11 +89,6 @@ protected ImmersionBar createStatusBarConfig() {
9089
.hideBar(BarHide.FLAG_HIDE_BAR);
9190
}
9291

93-
@Override
94-
public boolean isSwipeEnable() {
95-
return false;
96-
}
97-
9892
/**
9993
* 播放参数构建
10094
*/

app/src/main/java/com/hjq/demo/ui/dialog/UpdateDialog.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ private void downloadApk() {
155155
String channelId = "";
156156
// 适配 Android 8.0 通知渠道新特性
157157
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
158-
NotificationChannel channel = new NotificationChannel(getString(R.string.update_notification_channel_id), getString(R.string.update_notification_channel_name), NotificationManager.IMPORTANCE_HIGH);
158+
NotificationChannel channel = new NotificationChannel(getString(R.string.update_notification_channel_id), getString(R.string.update_notification_channel_name), NotificationManager.IMPORTANCE_LOW);
159159
channel.enableLights(false);
160160
channel.enableVibration(false);
161161
channel.setVibrationPattern(new long[]{0});
@@ -165,6 +165,7 @@ private void downloadApk() {
165165
}
166166

167167
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getContext(), channelId)
168+
// 设置通知时间
168169
.setWhen(System.currentTimeMillis())
169170
// 设置通知标题
170171
.setContentTitle(getString(R.string.app_name))
@@ -174,7 +175,9 @@ private void downloadApk() {
174175
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.launcher_ic))
175176
// 设置通知静音
176177
.setDefaults(NotificationCompat.FLAG_ONLY_ALERT_ONCE)
178+
// 设置震动频率
177179
.setVibrate(new long[]{0})
180+
// 设置声音文件
178181
.setSound(null)
179182
// 设置通知的优先级
180183
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
@@ -204,6 +207,8 @@ public void onStart(File file) {
204207

205208
@Override
206209
public void onProgress(File file, int progress) {
210+
mUpdateView.setText(String.format(getString(R.string.update_status_running), progress));
211+
mProgressView.setProgress(progress);
207212
// 更新下载通知
208213
notificationManager.notify(notificationId, notificationBuilder
209214
// 设置通知的文本
@@ -212,10 +217,10 @@ public void onProgress(File file, int progress) {
212217
.setProgress(100, progress, false)
213218
// 设置点击通知后是否自动消失
214219
.setAutoCancel(false)
220+
// 是否正在交互中
221+
.setOngoing(true)
215222
// 重新创建新的通知对象
216223
.build());
217-
mUpdateView.setText(String.format(getString(R.string.update_status_running), progress));
218-
mProgressView.setProgress(progress);
219224
}
220225

221226
@Override
@@ -230,6 +235,8 @@ public void onComplete(File file) {
230235
.setContentIntent(PendingIntent.getActivity(getContext(), 1, getInstallIntent(), Intent.FILL_IN_ACTION))
231236
// 设置点击通知后是否自动消失
232237
.setAutoCancel(true)
238+
// 是否正在交互中
239+
.setOngoing(false)
233240
.build());
234241
mUpdateView.setText(R.string.update_status_successful);
235242
// 标记成下载完成

0 commit comments

Comments
 (0)