Skip to content

Commit

Permalink
1. 修复在拍摄界面中的横向图片列表中,快速连续(300毫秒以内)的删除多个图片会导致闪退问题
Browse files Browse the repository at this point in the history
  • Loading branch information
aaatttcccc committed Jun 2, 2022
1 parent 20586e1 commit f400277
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 6 deletions.
2 changes: 1 addition & 1 deletion UPDATE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 历史更新

## 1.1.59X
1.
1. 修复因为layout名字一样引起的一些闪退问题,现在都加了zjh以示区别

## 1.1.58X
1. 修复拍照界面拍照多张图片的时候,打开第一张图片,如果滑到第二张并且进行编辑后会导致乱序的问题。(感谢 @lacker159 修复并推送)
Expand Down
4 changes: 3 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ android {
signingConfig signingConfigs.release
}
}

dataBinding {
enabled = true
}
Expand Down Expand Up @@ -101,4 +100,7 @@ dependencies {
// https://github.com/zetbaitsu/Compressor 另一款压缩库
implementation 'id.zelory:compressor:2.1.1'

// 异常捕获 https://github.com/Ereza/CustomActivityOnCrash
api 'cat.ereza:customactivityoncrash:2.3.0'

}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<activity android:name=".phone.MainCustomCameraViewActivity" />

<activity android:name=".phone.MainSuperSimpleActivity" />
<activity android:name=".phone.ErrorActivity" />

<provider
android:name="androidx.core.content.FileProvider"
Expand Down
35 changes: 35 additions & 0 deletions app/src/main/java/com/zhongjh/cameraapp/MyApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

import android.app.Application;
import android.content.Context;

import androidx.multidex.MultiDex;

import com.tencent.bugly.crashreport.CrashReport;
import com.zhongjh.cameraapp.phone.ErrorActivity;
import com.zhongjh.cameraapp.phone.MainListActivity;

import cat.ereza.customactivityoncrash.config.CaocConfig;

/**
* @author zhongjh
Expand All @@ -23,6 +29,35 @@ protected void attachBaseContext(Context base) {

// 腾讯提交bug
MultiDex.install(base);
initCrash();
}

/**
* 异常奔溃后自动打开新的Activity,还可以选择重新启动
*/
private void initCrash() {
CaocConfig.Builder.create()
// 背景模式,开启沉浸式
.backgroundMode(CaocConfig.BACKGROUND_MODE_SILENT)
// 是否启动全局异常捕获
.enabled(true)
// 是否显示错误详细信息
.showErrorDetails(true)
// 是否显示重启按钮
.showRestartButton(true)
// 是否跟踪Activity
.trackActivities(true)
// 崩溃的间隔时间(毫秒)
.minTimeBetweenCrashesMs(2000)
// 错误图标
.errorDrawable(R.mipmap.ic_launcher)
// 重新启动后的activity
.restartActivity(MainListActivity.class)
// 崩溃后的错误监听
// .eventListener(new YourCustomEventListener())
// 崩溃后的错误activity
.errorActivity(ErrorActivity.class)
.apply();
}

}
48 changes: 48 additions & 0 deletions app/src/main/java/com/zhongjh/cameraapp/phone/ErrorActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.zhongjh.cameraapp.phone;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import com.zhongjh.cameraapp.R;
import com.zhongjh.cameraapp.databinding.ActivityErrorBinding;

import cat.ereza.customactivityoncrash.CustomActivityOnCrash;
import cat.ereza.customactivityoncrash.config.CaocConfig;

/**
* @author zhongjh
* @date 2022/6/2
*/
public class ErrorActivity extends AppCompatActivity {

ActivityErrorBinding mBinding;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_error);
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_error);
init();
}

@SuppressLint("SetTextI18n")
private void init() {
// 获取所有的信息
String errorDetails = CustomActivityOnCrash.getAllErrorDetailsFromIntent(this, getIntent());
// 获取堆栈跟踪信息
String stackTrace = CustomActivityOnCrash.getStackTraceFromIntent(getIntent());
// 获取错误报告的Log信息
String activityLog = CustomActivityOnCrash.getActivityLogFromIntent(getIntent());
// 获得配置信息
CaocConfig config = CustomActivityOnCrash.getConfigFromIntent(getIntent());
mBinding.tvError.setText(
"【errorDetails】\n" + errorDetails + "\n\n\n【stackTrace】\n" + stackTrace + "\n\n\n【activityLog】\n" + activityLog);
mBinding.tvError.setTextColor(Color.BLUE);
mBinding.btnRestart.setOnClickListener(v -> CustomActivityOnCrash.restartApplication(ErrorActivity.this, config));
}
}
44 changes: 44 additions & 0 deletions app/src/main/res/layout/activity_error.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<LinearLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".phone.ErrorActivity">

<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white">

<TextView
android:id="@+id/tvError"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.core.widget.NestedScrollView>

<Button
android:id="@+id/btnRestart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:text="重启" />

</LinearLayout>

</layout>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.zhongjh.albumcamerarecorder.R;
Expand All @@ -26,6 +27,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

import static com.zhongjh.albumcamerarecorder.album.model.SelectedItemCollection.COLLECTION_IMAGE;
import static com.zhongjh.albumcamerarecorder.album.model.SelectedItemCollection.STATE_COLLECTION_TYPE;
Expand All @@ -46,6 +48,11 @@ public class PhotoAdapter extends RecyclerView.Adapter<PhotoAdapter.PhotoViewHol
GlobalSpec mGlobalSpec;
List<BitmapData> mListData;

/**
* 记录当前删除事件的时间
*/
private long mLastDeleteTime;

// region 回调监听事件

private final PhotoAdapterListener mPhotoAdapterListener;
Expand Down Expand Up @@ -145,10 +152,29 @@ private void onClickListener(int position) {
* @param position 索引
*/
public void removePosition(int position) {
mPhotoAdapterListener.onDelete(position);
mListData.remove(position);
notifyItemRemoved(position);
notifyItemRangeChanged(position, getItemCount());
if (isDelete()) {
mPhotoAdapterListener.onDelete(position);
mListData.remove(position);
notifyItemRemoved(position);
notifyItemRangeChanged(position, getItemCount());
}
}

/**
* 根据两次删除时间判断是否能删除
* 两次删除操作之间不能低于500毫秒,因为在我们快速删除的时候,会出现问题IndexOutOfIndexException或者删除错乱的问题,
* 原因是notifyItemRangeChanged这个方法中开启了多线程,动画有250毫秒+120毫秒
* @return 是否能删除
*/
public boolean isDelete() {
boolean flag = false;
long curClickTime = System.currentTimeMillis();
int deleteDelayTime = 500;
if ((curClickTime - mLastDeleteTime) >= deleteDelayTime) {
flag = true;
}
mLastDeleteTime = curClickTime;
return flag;
}

@Override
Expand Down

0 comments on commit f400277

Please sign in to comment.