Skip to content

Commit

Permalink
Fixed some crashes.
Browse files Browse the repository at this point in the history
  • Loading branch information
hwki committed Oct 5, 2021
1 parent 5980156 commit 77c25c5
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 6 deletions.
4 changes: 2 additions & 2 deletions bitcoin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
applicationId "com.brentpanther.bitcoinwidget"
minSdk 23
targetSdk 31
versionCode 280
versionName "8.1"
versionCode 281
versionName "8.1.1"

javaCompileOptions {
annotationProcessorOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class WidgetApplication : Application() {
val widgetProviders = listOf(WidgetProvider::class.java, ValueWidgetProvider::class.java)

fun getWidgetType(widgetId: Int): WidgetType {
return when (AppWidgetManager.getInstance(this).getAppWidgetInfo(widgetId).provider.className) {
val widgetInfo = AppWidgetManager.getInstance(this).getAppWidgetInfo(widgetId)
?: return WidgetType.PRICE
return when (widgetInfo.provider.className) {
WidgetProvider::class.qualifiedName -> WidgetType.PRICE
ValueWidgetProvider::class.qualifiedName -> WidgetType.VALUE
else -> throw IllegalArgumentException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ abstract class WidgetDatabase : RoomDatabase() {
}
}

private val MIGRATION_2_3 = object : Migration(2, 3) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE Widget ADD COLUMN useInverse INTEGER NOT NULL DEFAULT 0")
}
}

@Volatile
private var INSTANCE: WidgetDatabase? = null

Expand All @@ -39,6 +45,7 @@ abstract class WidgetDatabase : RoomDatabase() {
context.applicationContext, WidgetDatabase::class.java, "widgetdb"
).addCallback(callback)
.addMigrations(MIGRATION_1_2)
.addMigrations(MIGRATION_2_3)
.build()
INSTANCE = instance
instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.content.res.Configuration
import android.graphics.RectF
import android.os.Build
import android.util.Log
import android.util.TypedValue
import android.widget.TextView
import com.brentpanther.bitcoinwidget.Coin
Expand Down Expand Up @@ -107,7 +108,12 @@ open class SolidPriceWidgetDisplayStrategy(context: Context, widget: Widget, wid
val price = if (widget.lastValue == null) {
appContext.getString(R.string.placeholder_price)
} else {
formatPriceString(widget.lastValue)
try {
formatPriceString(widget.lastValue)
} catch (e: NumberFormatException) {
Log.e(TAG, "Error formatting price: ${widget.lastValue}")
widget.lastValue ?: ""
}
}
val config = getConfig()
val adjustSize = config.consistentSize || Build.VERSION.SDK_INT < Build.VERSION_CODES.O
Expand Down Expand Up @@ -142,4 +148,8 @@ open class SolidPriceWidgetDisplayStrategy(context: Context, widget: Widget, wid
widgetPresenter.setTextViewTextSize(R.id.price, TypedValue.COMPLEX_UNIT_PX, size.toFloat())
}

companion object {
private val TAG = SolidPriceWidgetDisplayStrategy::class.java.simpleName
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.brentpanther.bitcoinwidget.strategy.display
import android.content.Context
import android.graphics.RectF
import android.os.Build
import android.util.Log
import com.brentpanther.bitcoinwidget.R
import com.brentpanther.bitcoinwidget.WidgetApplication.Companion.dpToPx
import com.brentpanther.bitcoinwidget.db.Widget
Expand Down Expand Up @@ -56,7 +57,12 @@ class SolidValueWidgetDisplayStrategy(context: Context, widget: Widget, widgetPr
widgetPresenter.show(R.id.coin_layout, R.id.coinLabel)
var amount = ""
if (widget.showAmountLabel) {
amount = DecimalFormat("#.#####").format(widget.amountHeld)
amount = try {
DecimalFormat("#.#####").format(widget.amountHeld)
} catch (e : Exception) {
Log.e(TAG, "Error formatting amount: ${widget.amountHeld}", e)
widget.amountHeld.toString()
}
}
if (widget.showCoinLabel) {
amount += " " + widget.coinName()
Expand All @@ -65,5 +71,7 @@ class SolidValueWidgetDisplayStrategy(context: Context, widget: Widget, widgetPr
widgetPresenter.setTextViewText(R.id.coinLabel, amount)
}


companion object {
private val TAG = SolidValueWidgetDisplayStrategy::class.java.simpleName
}
}
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/281.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed some crashes.

0 comments on commit 77c25c5

Please sign in to comment.