Fix minor issues and crashes

This commit is contained in:
Phillip Thelen 2022-05-13 14:00:34 +02:00
parent 54cfa46d25
commit d882328398
6 changed files with 31 additions and 12 deletions

View file

@ -759,7 +759,7 @@
<string name="special_items">Özel eşyalar</string>
<string name="leave_keep_tasks">Ayrıl &amp; Görevleri Koru</string>
<string name="create_task_title">Bir Görev Oluştur</string>
<string name="percent_completed">%%d% Tamamlandı</string>
<string name="percent_completed">%d%% Tamamlandı</string>
<string name="lets_get_started">Haydi başlayalım</string>
<string name="your_progress">Senin İlerlemen</string>
<string name="delete_checklist_entry">Sil…</string>

View file

@ -222,7 +222,7 @@ class ApiClientImpl(
@Suppress("DEPRECATION")
if (SocketException::class.java.isAssignableFrom(throwableClass) || SSLException::class.java.isAssignableFrom(throwableClass)) {
this.showConnectionProblemDialog(R.string.internal_error_api)
} else if (throwableClass == SocketTimeoutException::class.java || UnknownHostException::class.java == throwableClass) {
} else if (throwableClass == SocketTimeoutException::class.java || UnknownHostException::class.java == throwableClass || IOException::class.java == throwableClass) {
this.showConnectionProblemDialog(R.string.network_error_no_network_body)
} else if (throwableClass == retrofit2.adapter.rxjava3.HttpException::class.java) {
val error = throwable as HttpException

View file

@ -39,6 +39,14 @@ enum class AdType {
FAINT -> "ca-app-pub-5911973472413421/1738504765"
}
}
val cooldownTime: Date?
get() {
return when (this) {
SPELL -> Date(Date().time + 1.toDuration(DurationUnit.HOURS).inWholeMilliseconds)
else -> null
}
}
}
fun String.md5(): String? {
@ -83,10 +91,18 @@ class AdHandler(val activity: Activity, val type: AdType, val rewardAction: (Boo
return nextAdAllowedDate(type)?.after(Date()) == true
}
fun setNextAllowedDate(type: AdType, date: Date) {
nextAdAllowed[type] = date
sharedPreferences.edit {
putLong("nextAd${type.name}", date.time)
fun setNextAllowedDate(type: AdType) {
val date = type.cooldownTime
if (date != null) {
nextAdAllowed[type] = date
sharedPreferences.edit {
putLong("nextAd${type.name}", date.time)
}
} else {
nextAdAllowed.remove(type)
sharedPreferences.edit {
remove("nextAd${type.name}")
}
}
}
@ -203,7 +219,7 @@ class AdHandler(val activity: Activity, val type: AdType, val rewardAction: (Boo
}
if (rewardedAd != null) {
rewardedAd?.show(activity, this)
setNextAllowedDate(type, Date(Date().time + 1.toDuration(DurationUnit.HOURS).inWholeMilliseconds))
setNextAllowedDate(type)
} else {
Log.d(TAG, "The rewarded ad wasn't ready yet.")
}

View file

@ -86,7 +86,8 @@ class ArmoireActivity: BaseActivity() {
it.armoire["dropKey"] ?: "",
it.armoire["dropText"] ?: "",
it.armoire["value"] ?: "")
binding.adButton.updateForAdType(AdType.ARMOIRE, lifecycleScope)
binding.adButton.state = AdButton.State.UNAVAILABLE
binding.adButton.visibility = View.INVISIBLE
hasAnimatedChanges = false
gold = null
}, RxErrorHandler.handleEmptyError()))
@ -214,7 +215,7 @@ class ArmoireActivity: BaseActivity() {
}
}
fun showDropRateDialog() {
private fun showDropRateDialog() {
val dialog = HabiticaBottomSheetDialog(this)
dialog.setContentView(R.layout.armoire_drop_rate_dialog)
dialog.show()

View file

@ -70,7 +70,9 @@ class EquipmentOverviewFragment : BaseMainFragment<FragmentEquipmentOverviewBind
private fun updateOutfit(view: EquipmentOverviewView?, outfit: Outfit?) {
if (outfit?.weapon?.isNotEmpty() == true) {
viewModel.getGear(outfit.weapon) {
view?.updateData(outfit, it.twoHanded)
if (it.isValid) {
view?.updateData(outfit, it.twoHanded)
}
}
} else {
view?.updateData(outfit)

View file

@ -25,7 +25,7 @@ class AdButton @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null
) : LinearLayout(context, attrs) {
var state: State = State.LOADING
var state: State = State.READY
set(value) {
field = value
updateViews()
@ -61,7 +61,7 @@ class AdButton @JvmOverloads constructor(
binding.currencyView.setTextColor(ContextCompat.getColor(context, R.color.white))
binding.currencyView.value = 0.0
gravity = Gravity.CENTER
state = State.LOADING
state = State.READY
}
private fun updateViews() {