Skip to content

Commit

Permalink
移除界面侧滑功能及补充相关文档
Browse files Browse the repository at this point in the history
修复 DialogManager 内存泄漏的问题
修复 Android 11 无法使用意图的问题
修复 Bugly 上报 Lottie 资源异常的问题
优化 SettingBar 自定义控件的代码逻辑
  • Loading branch information
getActivity committed Feb 27, 2021
1 parent c1dcac5 commit 48c6560
Show file tree
Hide file tree
Showing 25 changed files with 128 additions and 136 deletions.
Binary file modified AndroidProject.apk
Binary file not shown.
54 changes: 33 additions & 21 deletions HelpDoc.md

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,6 @@ dependencies {
implementation 'com.scwang.smart:refresh-layout-kernel:2.0.3'
implementation 'com.scwang.smart:refresh-header-material:2.0.3'

// 侧滑框架:https://github.com/luckybilly/SmartSwipe
implementation 'com.billy.android:smart-swipe:1.1.2'
implementation 'com.billy.android:smart-swipe-x:1.1.0'

// 日志打印框架:https://github.com/JakeWharton/timber
implementation 'com.jakewharton.timber:timber:4.7.1'

Expand Down
39 changes: 35 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
xmlns:tools="http://schemas.android.com/tools"
package="com.hjq.demo">

<!-- 联网权限 -->
<uses-permission android:name="android.permission.INTERNET" />

<!-- 网络状态 -->
<!-- 网络相关 -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

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

</application>

<!-- Android 11 软件包可见性适配:https://www.jianshu.com/p/d1ccd425c4ce -->
<queries>
<!-- 拍照意图:MediaStore.ACTION_IMAGE_CAPTURE -->
<intent>
<action android:name="android.media.action.IMAGE_CAPTURE" />
</intent>

<!-- 拍摄意图:MediaStore.ACTION_VIDEO_CAPTURE -->
<intent>
<action android:name="android.media.action.VIDEO_CAPTURE" />
</intent>

<!-- 图片裁剪意图 -->
<intent>
<action android:name="com.android.camera.action.CROP" />
</intent>

<!-- 打电话意图:Intent.ACTION_DIAL -->
<intent>
<action android:name="android.intent.action.DIAL" />
</intent>

<!-- 分享意图:Intent.ACTION_SEND -->
<intent>
<action android:name="android.intent.action.SEND" />
</intent>

<!-- 调起其他页面意图:Intent.ACTION_VIEW -->
<intent>
<action android:name="android.intent.action.VIEW" />
</intent>
</queries>

</manifest>
5 changes: 3 additions & 2 deletions app/src/main/java/com/hjq/demo/action/StatusAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ default void showLoading(@RawRes int id) {
*/
default void showComplete() {
StatusLayout layout = getStatusLayout();
if (layout != null && layout.isShow()) {
layout.hide();
if (layout == null || !layout.isShow()) {
return;
}
layout.hide();
}

/**
Expand Down
18 changes: 0 additions & 18 deletions app/src/main/java/com/hjq/demo/action/SwipeAction.java

This file was deleted.

4 changes: 1 addition & 3 deletions app/src/main/java/com/hjq/demo/app/AppActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.hjq.base.BaseActivity;
import com.hjq.base.BaseDialog;
import com.hjq.demo.R;
import com.hjq.demo.action.SwipeAction;
import com.hjq.demo.action.TitleBarAction;
import com.hjq.demo.action.ToastAction;
import com.hjq.demo.http.model.HttpData;
Expand All @@ -29,8 +28,7 @@
* desc : 业务 Activity 基类
*/
public abstract class AppActivity extends BaseActivity
implements ToastAction, TitleBarAction,
SwipeAction, OnHttpListener<Object> {
implements ToastAction, TitleBarAction, OnHttpListener<Object> {

/** 标题栏对象 */
private TitleBar mTitleBar;
Expand Down
12 changes: 1 addition & 11 deletions app/src/main/java/com/hjq/demo/app/AppApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleOwner;

import com.billy.android.swipe.SmartSwipeBack;
import com.hjq.bar.TitleBar;
import com.hjq.bar.initializer.LightBarInitializer;
import com.hjq.demo.R;
import com.hjq.demo.action.SwipeAction;
import com.hjq.demo.aop.DebugLog;
import com.hjq.demo.http.glide.GlideApp;
import com.hjq.demo.http.model.RequestHandler;
Expand Down Expand Up @@ -76,7 +74,7 @@ public void onTrimMemory(int level) {
* 初始化一些第三方框架
*/
public static void initSdk(Application application) {
// 设置权限请求调试模式
// 设置调试模式
XXPermissions.setDebugMode(AppConfig.isDebug());

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

// Activity 侧滑返回
SmartSwipeBack.activitySlidingBack(application, activity -> {
if (activity instanceof SwipeAction) {
return ((SwipeAction) activity).isSwipeEnable();
}
return true;
});

// 初始化日志打印
if (AppConfig.isLogEnable()) {
Timber.plant(new DebugLoggerTree());
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/hjq/demo/manager/DialogManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ public void onDismiss(BaseDialog dialog) {
*/

@Override
public void onStateChanged(@NonNull LifecycleOwner source, @NonNull Lifecycle.Event event) {
public void onStateChanged(@NonNull LifecycleOwner lifecycleOwner, @NonNull Lifecycle.Event event) {
if (event != Lifecycle.Event.ON_DESTROY) {
return;
}
source.getLifecycle().removeObserver(this);
DIALOG_MANAGER.remove(lifecycleOwner);
lifecycleOwner.getLifecycle().removeObserver(this);
clearShow();
}
}
3 changes: 2 additions & 1 deletion app/src/main/java/com/hjq/demo/manager/InputTextManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,9 @@ public interface OnInputTextListener {

/**
* 输入发生了变化
*
* @return 返回按钮的 Enabled 状态
*/
boolean onInputChange(InputTextManager helper);
boolean onInputChange(InputTextManager manager);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ protected void initData() {
}
if (XXPermissions.isGrantedPermission(this, new String[]{Permission.MANAGE_EXTERNAL_STORAGE, Permission.CAMERA})
&& intent.resolveActivity(getPackageManager()) != null) {

File file = getSerializable(IntentKey.FILE);
if (file == null) {
toast(R.string.camera_image_error);
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/java/com/hjq/demo/ui/activity/CrashActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,6 @@ public void onClick(View view) {
}
}

@Override
public boolean isSwipeEnable() {
return false;
}

@Override
public void onBackPressed() {
// 按返回键重启应用
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/java/com/hjq/demo/ui/activity/GuideActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ protected void initData() {
mIndicatorView.setViewPager(mViewPager);
}

@Override
public boolean isSwipeEnable() {
return false;
}

@SingleClick
@Override
public void onClick(View view) {
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/java/com/hjq/demo/ui/activity/HomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,4 @@ protected void onDestroy() {
mViewPager.setAdapter(null);
mBottomNavigationView.setOnNavigationItemSelectedListener(null);
}

@Override
public boolean isSwipeEnable() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,6 @@ public boolean isStatusBarDarkFont() {
return false;
}

@Override
public boolean isSwipeEnable() {
return false;
}

/**
* {@link ViewPager.OnPageChangeListener}
*/
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/java/com/hjq/demo/ui/activity/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,4 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
}
return false;
}

@Override
public boolean isSwipeEnable() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,6 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
return false;
}

@Override
public boolean isSwipeEnable() {
return false;
}

/**
* 注册监听
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,6 @@ public void onBackPressed() {
//super.onBackPressed();
}

@Override
public boolean isSwipeEnable() {
return false;
}

@Override
protected void initActivity() {
// 问题及方案:https://www.cnblogs.com/net168/p/5722752.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.gyf.immersionbar.BarHide;
import com.gyf.immersionbar.ImmersionBar;
import com.hjq.demo.R;
import com.hjq.demo.action.SwipeAction;
import com.hjq.demo.app.AppActivity;
import com.hjq.demo.other.IntentKey;
import com.hjq.demo.widget.PlayerView;
Expand All @@ -25,7 +24,7 @@
* desc : 视频播放界面
*/
public final class VideoPlayActivity extends AppActivity
implements SwipeAction, PlayerView.onPlayListener {
implements PlayerView.onPlayListener {

private PlayerView mPlayerView;
private VideoPlayActivity.Builder mBuilder;
Expand Down Expand Up @@ -90,11 +89,6 @@ protected ImmersionBar createStatusBarConfig() {
.hideBar(BarHide.FLAG_HIDE_BAR);
}

@Override
public boolean isSwipeEnable() {
return false;
}

/**
* 播放参数构建
*/
Expand Down
13 changes: 10 additions & 3 deletions app/src/main/java/com/hjq/demo/ui/dialog/UpdateDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private void downloadApk() {
String channelId = "";
// 适配 Android 8.0 通知渠道新特性
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(getString(R.string.update_notification_channel_id), getString(R.string.update_notification_channel_name), NotificationManager.IMPORTANCE_HIGH);
NotificationChannel channel = new NotificationChannel(getString(R.string.update_notification_channel_id), getString(R.string.update_notification_channel_name), NotificationManager.IMPORTANCE_LOW);
channel.enableLights(false);
channel.enableVibration(false);
channel.setVibrationPattern(new long[]{0});
Expand All @@ -165,6 +165,7 @@ private void downloadApk() {
}

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

@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
// 设置通知的文本
Expand All @@ -212,10 +217,10 @@ public void onProgress(File file, int progress) {
.setProgress(100, progress, false)
// 设置点击通知后是否自动消失
.setAutoCancel(false)
// 是否正在交互中
.setOngoing(true)
// 重新创建新的通知对象
.build());
mUpdateView.setText(String.format(getString(R.string.update_status_running), progress));
mProgressView.setProgress(progress);
}

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

0 comments on commit 48c6560

Please sign in to comment.