Skip to content

Commit

Permalink
fix: 修复软件详情页面崩溃
Browse files Browse the repository at this point in the history
修复软件详情页面因无法获取到 app 对象导致的崩溃
  • Loading branch information
xz-dev committed Nov 3, 2020
1 parent 37f91b2 commit 4f132c5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ android {
applicationId "net.xzos.upgradeall"
minSdkVersion 21
targetSdkVersion 30
versionCode 50
versionName "0.1.4.22"
versionCode 51
versionName "0.1.4.24"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
kapt {
arguments {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.xzos.upgradeall.ui.activity.detail

import android.content.Context
import android.content.Intent
import android.content.res.ColorStateList
import android.os.Bundle
import android.os.NetworkOnMainThreadException
Expand Down Expand Up @@ -44,6 +46,7 @@ class AppDetailActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_app_detail)
bundleApp?.run { app = this } ?: onBackPressed()
initView()
}

Expand All @@ -55,7 +58,6 @@ class AppDetailActivity : BaseActivity() {

supportActionBar?.setDisplayHomeAsUpEnabled(true)

bundleApp?.run { app = this }
initUi()

ib_edit.setOnClickListener {
Expand Down Expand Up @@ -249,11 +251,11 @@ class AppDetailActivity : BaseActivity() {
}

companion object {
internal var bundleApp: App? = null
get() {
val app = field
field = null
return app
}
private var bundleApp: App? = null

fun startActivity(context: Context, app: App) {
bundleApp = app
context.startActivity(Intent(context, AppDetailActivity::class.java))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.xzos.upgradeall.ui.viewmodels.adapters

import android.content.Intent
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -50,8 +49,7 @@ class AppListItemAdapter(
if (holder.adapterPosition == RecyclerView.NO_POSITION) return@setOnClickListener
when (val baseApp = mItemCardViewList.getByHolder(holder).extraData.app) {
is App -> {
AppDetailActivity.bundleApp = baseApp
it.context.startActivity(Intent(it.context, AppDetailActivity::class.java))
AppDetailActivity.startActivity(it.context, baseApp)
}
is Applications -> {
ApplicationsFragment.bundleApplications = baseApp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.xzos.upgradeall.ui.viewmodels.adapters

import android.content.Intent
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -30,10 +29,7 @@ class ApplicationsItemAdapter(
if (holder.adapterPosition == NO_POSITION) return@setOnClickListener
val app = mItemCardViewList.getByHolder(holder).extraData.app
if (app is App) {
AppDetailActivity.bundleApp = app
with(holder.itemCardView.context) {
startActivity(Intent(this, AppDetailActivity::class.java))
}
AppDetailActivity.startActivity(holder.itemCardView.context, app)
}
}
holder.itemCardView.setOnLongClickListener { view ->
Expand Down

0 comments on commit 4f132c5

Please sign in to comment.