Improve event handling

This commit is contained in:
Phillip Thelen 2020-09-10 11:23:01 +02:00
parent b7e579fde9
commit 2aed223100
22 changed files with 139 additions and 88 deletions

View file

@ -132,7 +132,7 @@ dependencies {
implementation 'androidx.navigation:navigation-ui-ktx:2.3.0'
implementation "androidx.paging:paging-runtime-ktx:2.1.2"
implementation 'com.plattysoft.leonids:LeonidsLib:1.3.2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3'
implementation 'com.willowtreeapps:signinwithapplebutton:0.2'
@ -158,8 +158,8 @@ android {
multiDexEnabled true
resConfigs "en", "bg", "de", "en-rGB", "es", "fr", "hr-rHR", "in", "it", "iw", "ja", "ko", "lt", "nl", "pl", "pt-rBR", "pt-rPT", "ru", "tr", "zh", "zh-rTW"
versionCode 2519
versionName "2.8"
versionCode 2531
versionName "3.0"
}
viewBinding {
@ -267,6 +267,11 @@ android {
}
}
androidExtensions {
features = ['parcelize']
experimental = true
}
Properties props = new Properties()
def propFile = new File('signingrelease.properties')
if (propFile.canRead()) {

View file

@ -77,7 +77,7 @@
<com.habitrpg.android.habitica.ui.views.HabiticaProgressBar
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="13dp"
android:layout_height="@dimen/bar_size"
android:id="@+id/health_bar"
app:barForegroundColor="@color/hpColor"
app:barBackgroundColor="@color/window_background"/>
@ -95,7 +95,7 @@
<com.habitrpg.android.habitica.ui.views.HabiticaProgressBar
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="13dp"
android:layout_height="@dimen/bar_size"
android:id="@+id/experience_bar"
app:barForegroundColor="@color/xpColor"
app:barBackgroundColor="@color/window_background"/>
@ -113,7 +113,7 @@
<com.habitrpg.android.habitica.ui.views.HabiticaProgressBar
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="13dp"
android:layout_height="@dimen/bar_size"
android:id="@+id/mana_bar"
app:barForegroundColor="@color/mpColor"
app:barBackgroundColor="@color/window_background"/>

View file

@ -15,17 +15,21 @@
android:contentDescription="@string/gems"
android:layout_marginTop="20dp"/>
<FrameLayout
<LinearLayout
android:id="@+id/amount_text_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:gravity="center">
<ImageView
android:id="@+id/amount_background"
android:layout_width="wrap_content"
android:id="@+id/amount_background_right"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
android:layout_gravity="center"
android:scaleType="fitStart"
android:layout_marginEnd="8dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/gem_amount"
android:textColor="@color/blue_10"
@ -33,7 +37,15 @@
android:layout_gravity="center"
android:textSize="36sp"
tools:text="21" />
</FrameLayout>
<ImageView
android:id="@+id/amount_background_left"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:scaleType="fitEnd"
android:layout_marginStart="8dp"
/>
</LinearLayout>
<TextView
android:id="@+id/gems_text_view"

View file

@ -1,2 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources></resources>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="contributor_0">#E6E6E6</color>
<color name="contributor_1">#E62E84</color>
<color name="contributor_2">#E61C1C</color>
<color name="contributor_3">#E61017</color>
<color name="contributor_4">#E65C00</color>
<color name="contributor_5">#E69215</color>
<color name="contributor_6">#4CE6AD</color>
<color name="contributor_7">#25D5E6</color>
<color name="contributor_mod">#35ABE6</color>
<color name="contributor_staff">#8F50FF</color>
</resources>

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="tavern.nolikes.background">#121212</color>
<color name="tavern.somelikes.background">#333333</color>
<color name="tavern.userliked.background">@color/text_green</color>
<color name="tavern.nolikes.foreground">#4D4D4D</color>
<color name="tavern.somelikes.foreground">#000000</color>
<color name="tavern.userliked.foreground">#000000</color>
</resources>

View file

@ -1,2 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources></resources>

View file

@ -1,8 +0,0 @@
<resources>
<!--
Customize dimensions originally defined in res/values/dimens.xml (such as
screen margins) for sw600dp devices (e.g. 7" tablets) here.
-->
</resources>

View file

@ -1,2 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources></resources>

View file

@ -1,2 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources></resources>

View file

@ -113,7 +113,7 @@
<dimen name="content_inset">21dp</dimen>
<dimen name="header_border_spacing">16dp</dimen>
<dimen name="button_height">38dp</dimen>
<dimen name="button_height">53dp</dimen>
<dimen name="button_height_small">24dp</dimen>
<dimen name="alert_side_padding">26dp</dimen>
<dimen name="downwards_drop_shadow_height">16dp</dimen>

View file

@ -1096,12 +1096,11 @@
<string name="x_to_y">%s to %s</string>
<string name="how_it_works">How it works</string>
<string name="limitations">Limitations</string>
<string name="fall_promo_info_instructions">Between September 22nd and 30th, simply purchase any Gem bundle like usual and your account will be credited with the promotional amount of Gems. More Gems to spend, share, or save for any future releases!</string>
<string name="fall_promo_info_limitations">This promotion only applies during the limited time event. This event starts on September 22nd at 8:00 AM EDT (12:00 UTC) and will end September 30th at 8:00 PM EDT (00:00 UTC). The promo offer is only available when buying Gems for yourself.</string>
<string name="fall_promo_info_instructions">Between %s and %s, simply purchase any Gem bundle like usual and your account will be credited with the promotional amount of Gems. More Gems to spend, share, or save for any future releases!</string>
<string name="fall_promo_info_prompt">The Fall Gala is in full swing so we thought it was the perfect time to introduce our first ever Gem Sale! Now you will get more Gems with each purchase than ever before.</string>
<string name="view_gem_bundles">View Gem Bundles</string>
<string name="spooky_promo_info_instructions">Between October 29th and November 2nd, simply purchase any Gem bundle like usual and your account will be credited with the promotional amount of Gems. More Gems to spend, share, or save for any future releases!</string>
<string name="spooky_promo_info_limitations">This promotion only applies during the limited time event. This event starts on October 29th at 8:00 AM EDT (12:00 UTC) and will end November 2nd at 8:00 PM EDT (00:00 UTC). The promo offer is only available when buying Gems for yourself.</string>
<string name="spooky_promo_info_instructions">Between %s and %s, simply purchase any Gem bundle like usual and your account will be credited with the promotional amount of Gems. More Gems to spend, share, or save for any future releases!</string>
<string name="gems_promo_info_limitations">This promotion only applies during the limited time event. This event starts on %s (12:00 UTC) and will end %s (00:00 UTC). The promo offer is only available when buying Gems for yourself.</string>
<string name="spooky_promo_info_prompt">The Gem Sale is back to haunt the very end of this years Fall Gala! This is one last chance to get more Gems than ever, so stock up while it lasts!</string>
<string name="dark_mode">Dark Mode</string>
<string name="theme_mode">Theme Mode</string>

View file

@ -1,7 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="ChallengeName">
<item name="android:fontFamily" tools:targetApi="jelly_bean">@string/font_family_condensed
</item>
@ -17,5 +15,4 @@
<item name="android:textColor">#8a000000</item>
<item name="android:maxLines">1</item>
</style>
</resources>

View file

@ -3,6 +3,7 @@ package com.habitrpg.android.habitica.models
import com.facebook.internal.Mutable
import com.habitrpg.android.habitica.models.inventory.QuestProgress
import com.habitrpg.android.habitica.models.inventory.QuestRageStrike
import java.util.*
class WorldState {
@ -11,4 +12,7 @@ class WorldState {
var progress: QuestProgress? = null
var rageStrikes: MutableList<QuestRageStrike>? = null
var currentEventKey: String? = null
var currentEventStartDate: Date? = null
var currentEventEndDate: Date? = null
}

View file

@ -18,15 +18,13 @@ import com.habitrpg.android.habitica.ui.views.promo.PromoMenuView
import java.text.SimpleDateFormat
import java.util.*
class FallExtraGemsHabiticaPromotion: HabiticaPromotion() {
class FallExtraGemsHabiticaPromotion(startDate: Date?, endDate: Date?) : HabiticaPromotion() {
override val identifier: String
get() = "fall_extra_gems"
override val promoType: PromoType
get() = PromoType.GEMS_AMOUNT
override val startDate: Date
get() = DateUtils.createDate(2020, 9, 22)
override val endDate: Date
get() = DateUtils.createDate(2020, 9, 30)
override val startDate: Date = startDate ?: DateUtils.createDate(2020, 9, 22)
override val endDate: Date = endDate ?: DateUtils.createDate(2020, 9, 30)
override fun pillBackgroundDrawable(context: Context): Drawable {
return ContextCompat.getDrawable(context, R.drawable.fall_promo_pill_bg) ?: ShapeDrawable()
@ -95,13 +93,15 @@ class FallExtraGemsHabiticaPromotion: HabiticaPromotion() {
ContextCompat.getColor(context, R.color.green_50),
ContextCompat.getColor(context, R.color.brand_300)
).shuffled()
binding.amountBackground.background = BitmapDrawable(context.resources,
val drawable = BitmapDrawable(context.resources,
HabiticaIconsHelper.imageOfFallGemPromoBG(
colors[0],
colors[1],
colors[2],
colors[3]
))
binding.amountBackgroundLeft.background = drawable
binding.amountBackgroundRight.background = drawable
binding.gemAmount.setTextColor(Color.parseColor("#FEE2B6"))
binding.gemsTextView.setTextColor(Color.parseColor("#FEE2B6"))
binding.footerTextView.visibility = View.VISIBLE
@ -135,7 +135,8 @@ class FallExtraGemsHabiticaPromotion: HabiticaPromotion() {
fragment.binding?.promptButton?.setTextColor(ContextCompat.getColor(context, R.color.white))
fragment.binding?.promptButton?.setOnClickListener { MainNavigationController.navigate(R.id.gemPurchaseActivity) }
fragment.binding?.instructionDescriptionView?.setText(R.string.fall_promo_info_instructions)
fragment.binding?.limitationsDescriptionView?.setText(R.string.fall_promo_info_limitations)
fragment.binding?.instructionDescriptionView?.text = context.getString(R.string.fall_promo_info_instructions, formatter.format(startDate), formatter.format(endDate))
val limitationsFormatter = SimpleDateFormat.getDateTimeInstance()
fragment.binding?.limitationsDescriptionView?.text = context.getString(R.string.gems_promo_info_limitations, limitationsFormatter.format(startDate), limitationsFormatter.format(endDate))
}
}

View file

@ -36,10 +36,10 @@ abstract class HabiticaPromotion {
abstract fun configureInfoFragment(fragment: PromoInfoFragment)
}
fun getHabiticaPromotionFromKey(key: String): HabiticaPromotion? {
fun getHabiticaPromotionFromKey(key: String, startDate: Date?, endDate: Date?): HabiticaPromotion? {
return when (key) {
"fall_extra_gems" -> FallExtraGemsHabiticaPromotion()
"spooky_extra_gems" -> SpookyExtraGemsHabiticaPromotion()
"fall_extra_gems" -> FallExtraGemsHabiticaPromotion(startDate, endDate)
"spooky_extra_gems" -> SpookyExtraGemsHabiticaPromotion(startDate, endDate)
else -> null
}
}

View file

@ -18,15 +18,13 @@ import com.habitrpg.android.habitica.ui.views.promo.PromoMenuView
import java.text.SimpleDateFormat
import java.util.*
class SpookyExtraGemsHabiticaPromotion: HabiticaPromotion() {
class SpookyExtraGemsHabiticaPromotion(startDate: Date?, endDate: Date?) : HabiticaPromotion() {
override val identifier: String
get() = "spooky_extra_gems"
override val promoType: PromoType
get() = PromoType.GEMS_AMOUNT
override val startDate: Date
get() = DateUtils.createDate(2020, 10, 29)
override val endDate: Date
get() = DateUtils.createDate(2020, 11, 2)
override val startDate: Date = startDate ?: DateUtils.createDate(2020, 10, 29)
override val endDate: Date = endDate ?: DateUtils.createDate(2020, 11, 2)
override fun pillBackgroundDrawable(context: Context): Drawable {
return ContextCompat.getDrawable(context, R.drawable.spooky_promo_pill_bg) ?: ShapeDrawable()
@ -89,8 +87,10 @@ class SpookyExtraGemsHabiticaPromotion: HabiticaPromotion() {
val context = binding.root.context
binding.root.background = promoBackgroundDrawable(context)
binding.purchaseButton.background = buttonDrawable(context)
binding.amountBackground.background = BitmapDrawable(context.resources,
val drawable = BitmapDrawable(context.resources,
HabiticaIconsHelper.imageOfSpookyGemPromoBG())
binding.amountBackgroundLeft.background = drawable
binding.amountBackgroundRight.background = drawable
binding.gemAmount.setTextColor(Color.parseColor("#FEE2B6"))
binding.gemsTextView.setTextColor(Color.parseColor("#FEE2B6"))
binding.footerTextView.visibility = View.VISIBLE
@ -124,7 +124,7 @@ class SpookyExtraGemsHabiticaPromotion: HabiticaPromotion() {
fragment.binding?.promptButton?.setTextColor(ContextCompat.getColor(context, R.color.white))
fragment.binding?.promptButton?.setOnClickListener { MainNavigationController.navigate(R.id.gemPurchaseActivity) }
fragment.binding?.instructionDescriptionView?.setText(R.string.spooky_promo_info_instructions)
fragment.binding?.limitationsDescriptionView?.setText(R.string.spooky_promo_info_limitations)
}
fragment.binding?.instructionDescriptionView?.text = context.getString(R.string.spooky_promo_info_instructions, formatter.format(startDate), formatter.format(endDate))
val limitationsFormatter = SimpleDateFormat.getDateTimeInstance()
fragment.binding?.limitationsDescriptionView?.text = context.getString(R.string.gems_promo_info_limitations, limitationsFormatter.format(startDate), limitationsFormatter.format(endDate)) }
}

View file

@ -155,7 +155,7 @@ class ChatRecyclerViewHolder(itemView: View, private var userId: String, private
binding.messageWrapper.background = if ((name != null && msg.text?.contains("@$name") == true) || (username != null && msg.text?.contains(username) == true)) {
ContextCompat.getDrawable(context, R.drawable.layout_rounded_bg_brand_700)
} else {
ContextCompat.getDrawable(context, R.drawable.layout_rounded_bg)
ContextCompat.getDrawable(context, R.drawable.layout_rounded_bg_content)
}
binding.messageWrapper.setScaledPadding(context, 8, 8, 8, 8)

View file

@ -79,8 +79,8 @@ class ChatBarView : LinearLayout {
private var autocompleteAdapter: AutocompleteAdapter? = null
private fun setupView(context: Context) {
orientation = LinearLayout.VERTICAL
this.setBackgroundResource(R.color.white)
orientation = VERTICAL
this.setBackgroundResource(R.color.content_background)
HabiticaBaseApplication.userComponent?.inject(this)

View file

@ -44,8 +44,6 @@ class OldQuestProgressView : LinearLayout {
private fun setupView(context: Context) {
setWillNotDraw(false)
inflate(R.layout.quest_progress_old, true)
orientation = VERTICAL
setScaledPadding(context, 16, 16, 16, 16)

View file

@ -3,47 +3,56 @@ package com.habitrpg.android.habitica.utils
import com.google.gson.JsonDeserializationContext
import com.google.gson.JsonDeserializer
import com.google.gson.JsonElement
import com.habitrpg.android.habitica.extensions.getAsString
import com.habitrpg.android.habitica.models.WorldState
import com.habitrpg.android.habitica.models.inventory.QuestProgress
import com.habitrpg.android.habitica.models.inventory.QuestRageStrike
import java.lang.reflect.Type
import java.util.*
class WorldStateSerialization: JsonDeserializer<WorldState> {
override fun deserialize(json: JsonElement?, typeOfT: Type?, context: JsonDeserializationContext?): WorldState {
val worldBossObject = json?.asJsonObject?.get("worldBoss")?.asJsonObject
val state = WorldState()
if (worldBossObject == null) {
return state
}
if (worldBossObject.has("active") && !worldBossObject["active"].isJsonNull) {
state.worldBossActive = worldBossObject["active"].asBoolean
}
if (worldBossObject.has("key") && !worldBossObject["key"].isJsonNull) {
state.worldBossKey = worldBossObject["key"].asString
}
if (worldBossObject.has("progress")) {
val progress = QuestProgress()
val progressObj = worldBossObject.getAsJsonObject("progress")
if (progressObj.has("hp")) {
progress.hp = progressObj["hp"].asDouble
if (worldBossObject != null) {
if (worldBossObject.has("active") && !worldBossObject["active"].isJsonNull) {
state.worldBossActive = worldBossObject["active"].asBoolean
}
if (progressObj.has("rage")) {
progress.rage = progressObj["rage"].asDouble
if (worldBossObject.has("key") && !worldBossObject["key"].isJsonNull) {
state.worldBossKey = worldBossObject["key"].asString
}
state.progress = progress
}
if (worldBossObject.has("extra")) {
val extra = worldBossObject["extra"].asJsonObject
if (extra.has("worldDmg")) {
val worldDmg = extra["worldDmg"].asJsonObject
state.rageStrikes = mutableListOf()
worldDmg.entrySet().forEach { (key, value) ->
val strike = QuestRageStrike(key, value.asBoolean)
state.rageStrikes?.add(strike)
if (worldBossObject.has("progress")) {
val progress = QuestProgress()
val progressObj = worldBossObject.getAsJsonObject("progress")
if (progressObj.has("hp")) {
progress.hp = progressObj["hp"].asDouble
}
if (progressObj.has("rage")) {
progress.rage = progressObj["rage"].asDouble
}
state.progress = progress
}
if (worldBossObject.has("extra")) {
val extra = worldBossObject["extra"].asJsonObject
if (extra.has("worldDmg")) {
val worldDmg = extra["worldDmg"].asJsonObject
state.rageStrikes = mutableListOf()
worldDmg.entrySet().forEach { (key, value) ->
val strike = QuestRageStrike(key, value.asBoolean)
state.rageStrikes?.add(strike)
}
}
}
}
val event = json?.asJsonObject?.getAsJsonObject("currentEvent")
if (event != null) {
state.currentEventKey = event.getAsString("event")
state.currentEventStartDate = context?.deserialize(event.get("start"), Date::class.java)
state.currentEventEndDate = context?.deserialize(event.get("end"), Date::class.java)
}
return state
}

View file

@ -0,0 +1,20 @@
{
"version": 1,
"artifactType": {
"type": "APK",
"kind": "Directory"
},
"applicationId": "com.habitrpg.android.habitica",
"variantName": "staffRelease",
"elements": [
{
"type": "SINGLE",
"filters": [],
"properties": [],
"versionCode": 2523,
"versionName": "3.0",
"enabled": true,
"outputFile": "Habitica-staff-release.apk"
}
]
}