Skip to content

Commit

Permalink
1.修复部分手机登录注册返回主页后闪退的bug
Browse files Browse the repository at this point in the history
2.暂时去掉侧滑功能
3.添加全局捕捉异常库
4.修复Bugly上的bug
  • Loading branch information
hegj committed Sep 11, 2019
1 parent 1c321ed commit 00cee9a
Show file tree
Hide file tree
Showing 27 changed files with 513 additions and 542 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ dependencies {
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0"
//项目用到的库大部分封装在里面 具体在 config.gradle
implementation rootProject.ext.customLibs

implementation 'cn.simonlee.widget:swipeback:1.0.15'
}
repositories {
mavenCentral()
Expand Down
615 changes: 249 additions & 366 deletions app/priguardMapping.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/release/output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":3,"versionName":"1.0.3","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":4,"versionName":"1.0.3","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
10 changes: 9 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,18 @@
android:label="开源项目"
android:launchMode="singleTask"
android:screenOrientation="portrait" />
<activity
android:name=".mvp.ui.activity.error.ErrorActivity"
android:label="错误界面"
android:process =":error_activity"
android:launchMode="singleTask"
android:screenOrientation="portrait" />
<activity
android:name="com.tencent.bugly.beta.ui.BetaActivity"
android:configChanges="keyboardHidden|orientation|screenSize|locale"
android:theme="@android:style/Theme.Translucent" /> <!-- Arms 配置 -->
android:theme="@android:style/Theme.Translucent" />

<!-- Arms 配置 -->
<meta-data
android:name="design_width_in_dp"
android:value="375" />
Expand Down
26 changes: 18 additions & 8 deletions app/src/main/java/me/hegj/wandroid/app/AppLifecyclesImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ import android.app.Application
import android.content.Context
import androidx.multidex.MultiDex
import butterknife.ButterKnife
import com.billy.android.swipe.*
import com.billy.android.swipe.SwipeConsumer.DIRECTION_LEFT
import com.billy.android.swipe.listener.SimpleSwipeListener
import cat.ereza.customactivityoncrash.config.CaocConfig
import com.jess.arms.base.delegate.AppLifecycles
import com.jess.arms.integration.cache.IntelligentCache
import com.jess.arms.utils.ArmsUtils
Expand All @@ -33,12 +31,12 @@ import com.tencent.bugly.Bugly
import com.tencent.bugly.crashreport.CrashReport.UserStrategy
import com.tencent.mmkv.MMKV
import me.hegj.wandroid.BuildConfig
import me.hegj.wandroid.R
import me.hegj.wandroid.app.utils.HttpUtils
import me.hegj.wandroid.app.utils.sliding.MyActivitySlidingBackConsumer
import me.hegj.wandroid.app.weight.loadCallBack.EmptyCallback
import me.hegj.wandroid.app.weight.loadCallBack.ErrorCallback
import me.hegj.wandroid.app.weight.loadCallBack.LoadingCallback
import me.hegj.wandroid.mvp.ui.activity.MainActivity
import me.hegj.wandroid.mvp.ui.activity.error.ErrorActivity
import me.hegj.wandroid.mvp.ui.activity.start.SplashActivity


Expand All @@ -58,7 +56,7 @@ class AppLifecyclesImpl : AppLifecycles {

override fun onCreate(application: Application) {
//初始化 SmartSwipeBack
SmartSwipeBack.activityBack(application, { activity ->
/* SmartSwipeBack.activityBack(application, { activity ->
MyActivitySlidingBackConsumer(activity)
.setRelativeMoveFactor(0.5f)
.setScrimColor(-0x80000000)
Expand All @@ -74,7 +72,7 @@ class AppLifecyclesImpl : AppLifecycles {
})
}, {
it !is MainActivity || it is SplashActivity//禁止主Activity滑动返回
})
})*/

//初始化MMKV
MMKV.initialize(application.filesDir.absolutePath + "/mmkv")
Expand All @@ -93,7 +91,6 @@ class AppLifecyclesImpl : AppLifecycles {
.addCallback(EmptyCallback())//
.setDefaultCallback(SuccessCallback::class.java)//设置默认加载状态页
.commit()

//初始化Bugly
val context = application.applicationContext
// 获取当前包名
Expand All @@ -105,6 +102,19 @@ class AppLifecyclesImpl : AppLifecycles {
strategy.isUploadProcess = processName == null || processName == packageName
// 初始化Bugly
Bugly.init(context, "5a5f6366fc", BuildConfig.DEBUG)

CaocConfig.Builder.create()
.backgroundMode(CaocConfig.BACKGROUND_MODE_SILENT) //default: CaocConfig.BACKGROUND_MODE_SHOW_CUSTOM
.enabled(true)//是否启用CustomActivityOnCrash崩溃拦截机制 必须启用!不然集成这个库干啥???
.showErrorDetails(false) //是否必须显示包含错误详细信息的按钮 default: true
.showRestartButton(false) //是否必须显示“重新启动应用程序”按钮或“关闭应用程序”按钮default: true
.logErrorOnRestart(false) //是否必须重新堆栈堆栈跟踪 default: true
.trackActivities(true) //是否必须跟踪用户访问的活动及其生命周期调用 default: false
.minTimeBetweenCrashesMs(2000) //应用程序崩溃之间必须经过的时间 default: 3000
.restartActivity(SplashActivity::class.java) // 重启的activity
.errorActivity(ErrorActivity::class.java) //发生错误跳转的activity
.eventListener(null) //允许你指定事件侦听器,以便在库显示错误活动 default: null
.apply()
}

override fun onTerminate(application: Application) {
Expand Down
5 changes: 1 addition & 4 deletions app/src/main/java/me/hegj/wandroid/mvp/ui/BaseActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ import com.jess.arms.utils.ThirdViewUtil.convertAutoView
import com.trello.rxlifecycle2.android.ActivityEvent
import io.reactivex.subjects.BehaviorSubject
import io.reactivex.subjects.Subject
import me.hegj.wandroid.app.event.SettingChangeEvent
import me.hegj.wandroid.app.utils.SettingUtil
import me.hegj.wandroid.app.utils.ShowUtils
import me.hegj.wandroid.app.utils.StatusBarUtil
import me.yokeyword.fragmentation.SupportActivity
import org.greenrobot.eventbus.Subscribe
import javax.inject.Inject

abstract class BaseActivity<P : IPresenter> : SupportActivity(), IActivity, ActivityLifecycleable, IView {
Expand All @@ -36,7 +34,6 @@ abstract class BaseActivity<P : IPresenter> : SupportActivity(), IActivity, Acti
@Inject
@JvmField
var mPresenter: P? = null//如果当前页面逻辑简单, Presenter 可以为 null

@Synchronized
override fun provideCache(): Cache<String, Any> {
if (mCache == null) {
Expand Down Expand Up @@ -120,7 +117,6 @@ abstract class BaseActivity<P : IPresenter> : SupportActivity(), IActivity, Acti
}



override fun showLoading() {
ShowUtils.showLoading(this)
}
Expand All @@ -133,4 +129,5 @@ abstract class BaseActivity<P : IPresenter> : SupportActivity(), IActivity, Acti
ShowUtils.showDialog(this, message)
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package me.hegj.wandroid.mvp.ui.activity.error

import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.os.Bundle
import cat.ereza.customactivityoncrash.CustomActivityOnCrash
import com.jess.arms.di.component.AppComponent
import com.jess.arms.mvp.IPresenter
import kotlinx.android.synthetic.main.activity_error.*
import kotlinx.android.synthetic.main.include_toolbar.*
import me.hegj.wandroid.R
import me.hegj.wandroid.app.utils.ShowUtils
import me.hegj.wandroid.mvp.ui.BaseActivity


class ErrorActivity : BaseActivity<IPresenter>() {
override fun setupActivityComponent(appComponent: AppComponent) {
}

override fun initView(savedInstanceState: Bundle?): Int {
return R.layout.activity_error
}

override fun initData(savedInstanceState: Bundle?) {
toolbar.run {
setSupportActionBar(this)
title = "发生错误"
}

val config = CustomActivityOnCrash.getConfigFromIntent(intent)
error_restart.setOnClickListener {
config?.run {
CustomActivityOnCrash.restartApplication(this@ErrorActivity, this)
}
}
error_sendError.setOnClickListener {
//获取剪贴板管理器:
val cm = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
// 创建普通字符型ClipData
val mClipData = ClipData.newPlainText("Label", CustomActivityOnCrash.getStackTraceFromIntent(intent))
// 将ClipData内容放到系统剪贴板里。
cm.primaryClip = mClipData
ShowUtils.showToast(this, "已复制错误日志到粘贴板")
ShowUtils.showDialog(this, "扣 扣:824868922\n\n微 信:hgj840\n\n邮 箱:[email protected]", "联系我")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class HomeFragment : BaseFragment<HomePresenter>(), HomeContract.View {
val view = LayoutInflater.from(_mActivity).inflate(R.layout.include_banner, null).apply {
banner.run {
setAdapter(BGABanner.Adapter<ImageView, BannerResponse> { _: BGABanner, view: ImageView, banner: BannerResponse?, i: Int ->
ArmsUtils.obtainAppComponentFromContext(_mActivity).imageLoader().loadImage(_mActivity,
ArmsUtils.obtainAppComponentFromContext(_mActivity).imageLoader().loadImage(_mActivity.applicationContext,
ImageConfigImpl
.builder()
.url(banner?.imagePath)
Expand Down Expand Up @@ -293,27 +293,22 @@ class HomeFragment : BaseFragment<HomePresenter>(), HomeContract.View {
@Subscribe
fun freshLogin(event: LoginFreshEvent) {
//如果是登录了, 当前界面的数据与账户收藏集合id匹配的值需要设置已经收藏
GlobalScope.launch{
async{
if (event.login) {
event.collectIds.forEach {
for (item in adapter.data) {
if (item.id == it.toInt()) {
item.collect = true
break
}
}
}
} else {
//退出了,把所有的收藏全部变为未收藏
for (item in adapter.data) {
item.collect = false
if (event.login) {
event.collectIds.forEach {
for (item in adapter.data) {
if (item.id == it.toInt()) {
item.collect = true
break
}
}
}.run {
adapter.notifyDataSetChanged()
}
} else {
//退出了,把所有的收藏全部变为未收藏
for (item in adapter.data) {
item.collect = false
}
}
adapter.notifyDataSetChanged()
}

/**
Expand All @@ -322,7 +317,7 @@ class HomeFragment : BaseFragment<HomePresenter>(), HomeContract.View {
@Subscribe
fun collectChange(event: CollectEvent) {
//使用协程做耗时操作
GlobalScope.launch{
GlobalScope.launch {
async {
var indexResult = -1
for (index in adapter.data.indices) {
Expand All @@ -334,7 +329,7 @@ class HomeFragment : BaseFragment<HomePresenter>(), HomeContract.View {
}
indexResult
}.run {
if(await()!=-1){
if (await() != -1) {
adapter.notifyItemChanged(await())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.view.Menu
import android.view.View
import android.widget.ImageView
import androidx.appcompat.widget.SearchView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.LinearLayoutManager
import com.afollestad.materialdialogs.MaterialDialog
import com.google.gson.Gson
Expand Down Expand Up @@ -70,7 +71,7 @@ class SearchActivity : BaseActivity<SearchPresenter>(), SearchContract.View {
MaterialDialog(this).show {
title(text = "温馨提示")
message(text = "确定清空搜索历史吗?")
positiveButton(text = "清空"){
positiveButton(text = "清空") {
historyData.clear()
adapter.setNewData(historyData)
CacheUtil.setSearchHistoryData(Gson().toJson(historyData))
Expand All @@ -84,14 +85,14 @@ class SearchActivity : BaseActivity<SearchPresenter>(), SearchContract.View {
if (historyData.contains(name)) {
//当搜索历史中包含该数据时 删除添加
historyData.remove(name)
}else if(historyData.size>=10){
historyData.removeAt(historyData.size-1)
} else if (historyData.size >= 10) {
historyData.removeAt(historyData.size - 1)
}
historyData.add(0,name)
historyData.add(0, name)
this@SearchActivity.adapter.setNewData(historyData)
CacheUtil.setSearchHistoryData(Gson().toJson(historyData))
launchActivity(Intent(this@SearchActivity,SearchResultActivity::class.java).apply {
putExtra("searchKey",name)
launchActivity(Intent(this@SearchActivity, SearchResultActivity::class.java).apply {
putExtra("searchKey", name)
})
false
}
Expand All @@ -107,8 +108,8 @@ class SearchActivity : BaseActivity<SearchPresenter>(), SearchContract.View {
}
//点击了搜索历史的某一个
setOnItemClickListener { adapter, view, position ->
launchActivity(Intent(this@SearchActivity,SearchResultActivity::class.java).apply {
putExtra("searchKey",historyData[position])
launchActivity(Intent(this@SearchActivity, SearchResultActivity::class.java).apply {
putExtra("searchKey", historyData[position])
})
}
}
Expand Down Expand Up @@ -136,14 +137,14 @@ class SearchActivity : BaseActivity<SearchPresenter>(), SearchContract.View {
if (historyData.contains(it)) {
//当搜索历史中包含该数据时 删除
historyData.remove(it)
}else if(historyData.size>=10){
} else if (historyData.size >= 10) {
//如果集合的size 有10个以上了,删除最后一个
historyData.removeAt(historyData.size-1)
historyData.removeAt(historyData.size - 1)
}
launchActivity(Intent(this@SearchActivity,SearchResultActivity::class.java).apply {
putExtra("searchKey",it)
launchActivity(Intent(this@SearchActivity, SearchResultActivity::class.java).apply {
putExtra("searchKey", it)
})
historyData.add(0,it)//添加新数据到第一条
historyData.add(0, it)//添加新数据到第一条
this@SearchActivity.adapter.setNewData(historyData)//刷新适配器
CacheUtil.setSearchHistoryData(Gson().toJson(historyData))//保存到本地
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,27 +226,22 @@ class SearchResultActivity : BaseActivity<SearchResultPresenter>(), SearchResult
@Subscribe
fun freshLogin(event: LoginFreshEvent) {
//如果是登录了, 当前界面的数据与账户收藏集合id匹配的值需要设置已经收藏
GlobalScope.launch {
async {
if (event.login) {
event.collectIds.forEach {
for (item in ariticleAdapter.data) {
if (item.id == it.toInt()) {
item.collect = true
break
}
}
}
} else {
//退出了,把所有的收藏全部变为未收藏
for (item in ariticleAdapter.data) {
item.collect = false
if (event.login) {
event.collectIds.forEach {
for (item in ariticleAdapter.data) {
if (item.id == it.toInt()) {
item.collect = true
break
}
}
}.run {
ariticleAdapter.notifyDataSetChanged()
}
} else {
//退出了,把所有的收藏全部变为未收藏
for (item in ariticleAdapter.data) {
item.collect = false
}
}
ariticleAdapter.notifyDataSetChanged()
}

/**
Expand Down
Loading

0 comments on commit 00cee9a

Please sign in to comment.