mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-12 07:14:47 +00:00
Minor dialog refactoring
This commit is contained in:
parent
a499548ecc
commit
f80c169a3a
11 changed files with 65 additions and 80 deletions
|
|
@ -26,6 +26,7 @@
|
|||
<color name="background_blue">@color/blue_50</color>
|
||||
<color name="background_teal">@color/teal_50</color>
|
||||
<color name="background_brand">@color/brand_200</color>
|
||||
<color name="background_brand_30">#4D4f2a93</color>
|
||||
|
||||
<color name="checkbox_fill">#40000000</color>
|
||||
<color name="checkbox_fill_inactive">#80000000</color>
|
||||
|
|
|
|||
|
|
@ -97,6 +97,7 @@
|
|||
<color name="background_blue">@color/blue_100</color>
|
||||
<color name="background_teal">@color/teal_100</color>
|
||||
<color name="background_brand">@color/brand_300</color>
|
||||
<color name="background_brand_30">#4D6033B5</color>
|
||||
|
||||
<color name="checkbox_fill">#50ffffff</color>
|
||||
<color name="checkbox_fill_inactive">#99FFFFFF</color>
|
||||
|
|
|
|||
|
|
@ -1359,6 +1359,9 @@
|
|||
<string name="pause_damage_2_description">Daily streaks and Habit counters will only count up while this is on</string>
|
||||
<string name="pause_damage_3_title">Your Quest progress will stay pending</string>
|
||||
<string name="pause_damage_3_description">Damage to a boss or found collection items will be stored until you resume damage</string>
|
||||
<string name="list">List</string>
|
||||
<string name="by_invite">By Invite</string>
|
||||
<string name="habiticans_looking_party">Here’s a list of Habiticans looking to join a Party</string>
|
||||
|
||||
<plurals name="you_x_others">
|
||||
<item quantity="zero">You</item>
|
||||
|
|
|
|||
|
|
@ -515,7 +515,7 @@
|
|||
<item name="android:windowIsFloating">true</item>
|
||||
<item name="android:windowContentOverlay">@null</item>
|
||||
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
|
||||
<item name="android:windowBackground">@color/transparent</item>
|
||||
<item name="android:windowBackground">@color/background_brand</item>
|
||||
<item name="android:colorBackgroundCacheHint">@null</item>
|
||||
</style>
|
||||
|
||||
|
|
|
|||
|
|
@ -41,8 +41,6 @@ class TavernFragment : BaseMainFragment<FragmentViewpagerBinding>() {
|
|||
): View? {
|
||||
this.usesTabLayout = true
|
||||
this.hidesToolbar = true
|
||||
this.tutorialStepIdentifier = "tavern"
|
||||
this.tutorialTexts = listOf(getString(R.string.tutorial_tavern))
|
||||
|
||||
return super.onCreateView(inflater, container, savedInstanceState)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ class StableViewModel(private val application: Application?, private val itemTyp
|
|||
_items.value = mapAnimals(animals, it)
|
||||
}
|
||||
viewModelScope.launchCatching {
|
||||
_ownedItems.value = inventoryRepository.getOwnedItems(true).firstOrNull()
|
||||
_ownedItems.value = inventoryRepository.getOwnedItems(true).firstOrNull() ?: emptyMap()
|
||||
}
|
||||
_mounts.value = if ("pets" == itemType) {
|
||||
inventoryRepository.getMounts().firstOrNull() ?: emptyList()
|
||||
|
|
|
|||
|
|
@ -13,15 +13,14 @@ import android.view.animation.AccelerateInterpolator
|
|||
import android.widget.Button
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.RelativeLayout
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.children
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.databinding.DialogHabiticaBaseBinding
|
||||
import com.habitrpg.android.habitica.extensions.inflate
|
||||
import com.habitrpg.android.habitica.ui.activities.BaseActivity
|
||||
import com.habitrpg.android.habitica.ui.views.login.LockableScrollView
|
||||
import com.habitrpg.common.habitica.extensions.dpToPx
|
||||
import com.habitrpg.common.habitica.extensions.layoutInflater
|
||||
import com.plattysoft.leonids.ParticleSystem
|
||||
|
|
@ -38,17 +37,11 @@ open class HabiticaAlertDialog(context: Context) : AlertDialog(context, R.style.
|
|||
updateButtonLayout()
|
||||
}
|
||||
var isCelebratory: Boolean = false
|
||||
private val view: RelativeLayout = LayoutInflater.from(context).inflate(R.layout.dialog_habitica_base, null) as RelativeLayout
|
||||
private val dialogWrapper: LinearLayout
|
||||
internal val dialogContainer: LinearLayout
|
||||
private var titleTextView: TextView
|
||||
private var messageTextView: TextView
|
||||
internal var contentView: ViewGroup
|
||||
private var scrollingSeparator: View
|
||||
internal var scrollView: LockableScrollView
|
||||
protected var buttonsWrapper: LinearLayout
|
||||
private var noticeTextView: TextView
|
||||
private var closeButton: Button
|
||||
private val binding = DialogHabiticaBaseBinding.inflate(LayoutInflater.from(context))
|
||||
val scrollView
|
||||
get() = binding.mainScrollView
|
||||
val contentView
|
||||
get() = binding.contentView
|
||||
|
||||
internal var additionalContentView: View? = null
|
||||
|
||||
|
|
@ -70,35 +63,25 @@ open class HabiticaAlertDialog(context: Context) : AlertDialog(context, R.style.
|
|||
var dialogWidth = 320
|
||||
set(value) {
|
||||
field = value
|
||||
val layoutParams = dialogWrapper.layoutParams
|
||||
val layoutParams = binding.dialogWrapper.layoutParams
|
||||
layoutParams.width = value
|
||||
dialogWrapper.layoutParams = layoutParams
|
||||
binding.dialogWrapper.layoutParams = layoutParams
|
||||
}
|
||||
|
||||
init {
|
||||
setView(view)
|
||||
dialogWrapper = view.findViewById(R.id.dialog_wrapper)
|
||||
dialogContainer = view.findViewById(R.id.dialog_container)
|
||||
titleTextView = view.findViewById(R.id.titleTextView)
|
||||
messageTextView = view.findViewById(R.id.messageTextView)
|
||||
contentView = view.findViewById(R.id.content_view)
|
||||
scrollingSeparator = view.findViewById(R.id.scrolling_separator)
|
||||
scrollView = view.findViewById(R.id.main_scroll_view)
|
||||
buttonsWrapper = view.findViewById(R.id.buttons_wrapper)
|
||||
noticeTextView = view.findViewById(R.id.notice_text_view)
|
||||
closeButton = view.findViewById(R.id.close_button)
|
||||
closeButton.setOnClickListener { dismiss() }
|
||||
dialogContainer.clipChildren = true
|
||||
dialogContainer.clipToOutline = true
|
||||
setView(binding.root)
|
||||
binding.closeButton.setOnClickListener { dismiss() }
|
||||
binding.dialogContainer.clipChildren = true
|
||||
binding.dialogContainer.clipToOutline = true
|
||||
}
|
||||
|
||||
override fun setTitle(title: CharSequence?) {
|
||||
if ((title?.length ?: 0) > 0) {
|
||||
titleTextView.visibility = View.VISIBLE
|
||||
binding.titleTextView.visibility = View.VISIBLE
|
||||
} else {
|
||||
titleTextView.visibility = View.GONE
|
||||
binding.titleTextView.visibility = View.GONE
|
||||
}
|
||||
titleTextView.text = title
|
||||
binding.titleTextView.text = title
|
||||
}
|
||||
|
||||
override fun setTitle(titleId: Int) {
|
||||
|
|
@ -107,12 +90,12 @@ open class HabiticaAlertDialog(context: Context) : AlertDialog(context, R.style.
|
|||
|
||||
override fun setMessage(message: CharSequence?) {
|
||||
if ((message?.length ?: 0) > 0) {
|
||||
messageTextView.visibility = View.VISIBLE
|
||||
binding.messageTextView.visibility = View.VISIBLE
|
||||
} else {
|
||||
messageTextView.visibility = View.GONE
|
||||
binding.messageTextView.visibility = View.GONE
|
||||
}
|
||||
messageTextView.text = message
|
||||
messageTextView.movementMethod = ScrollingMovementMethod()
|
||||
binding.messageTextView.text = message
|
||||
binding.messageTextView.movementMethod = ScrollingMovementMethod()
|
||||
}
|
||||
|
||||
fun setMessage(messageId: Int) {
|
||||
|
|
@ -121,11 +104,11 @@ open class HabiticaAlertDialog(context: Context) : AlertDialog(context, R.style.
|
|||
|
||||
fun setNotice(notice: CharSequence?) {
|
||||
if ((notice?.length ?: 0) > 0) {
|
||||
noticeTextView.visibility = View.VISIBLE
|
||||
binding.noticeTextView.visibility = View.VISIBLE
|
||||
} else {
|
||||
noticeTextView.visibility = View.GONE
|
||||
binding.noticeTextView.visibility = View.GONE
|
||||
}
|
||||
noticeTextView.text = notice
|
||||
binding.noticeTextView.text = notice
|
||||
}
|
||||
|
||||
fun setNotice(noticeID: Int) {
|
||||
|
|
@ -133,52 +116,52 @@ open class HabiticaAlertDialog(context: Context) : AlertDialog(context, R.style.
|
|||
}
|
||||
|
||||
fun setCustomHeaderView(customHeader: View) {
|
||||
dialogContainer.addView(customHeader, 0)
|
||||
dialogContainer.setPadding(0, 0, 0, dialogContainer.paddingBottom)
|
||||
binding.dialogContainer.addView(customHeader, 0)
|
||||
binding.dialogContainer.setPadding(0, 0, 0, binding.dialogContainer.paddingBottom)
|
||||
}
|
||||
|
||||
fun setAdditionalContentView(layoutResID: Int) {
|
||||
val inflater = context.layoutInflater
|
||||
setAdditionalContentView(inflater.inflate(layoutResID, view, false))
|
||||
setAdditionalContentView(inflater.inflate(layoutResID, binding.root, false))
|
||||
}
|
||||
|
||||
fun setAdditionalContentView(view: View?) {
|
||||
this.view.removeView(additionalContentView)
|
||||
binding.root.removeView(additionalContentView)
|
||||
additionalContentView = view
|
||||
this.contentView.addView(view)
|
||||
binding.contentView.addView(view)
|
||||
val layoutParams = view?.layoutParams
|
||||
layoutParams?.width = ViewGroup.LayoutParams.MATCH_PARENT
|
||||
layoutParams?.height = ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
view?.layoutParams = layoutParams
|
||||
contentView.forceLayout()
|
||||
binding.contentView.forceLayout()
|
||||
}
|
||||
|
||||
fun setAdditionalContentSidePadding(padding: Int) {
|
||||
contentView.setPadding(padding, 0, padding, contentView.paddingBottom)
|
||||
messageTextView.setPadding(padding, messageTextView.paddingTop, padding, messageTextView.paddingBottom)
|
||||
binding.contentView.setPadding(padding, 0, padding, binding.contentView.paddingBottom)
|
||||
binding.messageTextView.setPadding(padding, binding.messageTextView.paddingTop, padding, binding.messageTextView.paddingBottom)
|
||||
}
|
||||
|
||||
fun setExtraCloseButtonVisibility(visibility: Int) {
|
||||
closeButton.visibility = visibility
|
||||
binding.closeButton.visibility = visibility
|
||||
}
|
||||
|
||||
private fun updateButtonLayout() {
|
||||
if (isScrollingLayout || buttonAxis == LinearLayout.HORIZONTAL) {
|
||||
scrollingSeparator.visibility = View.VISIBLE
|
||||
buttonsWrapper.orientation = LinearLayout.HORIZONTAL
|
||||
binding.scrollingSeparator.visibility = View.VISIBLE
|
||||
binding.buttonsWrapper.orientation = LinearLayout.HORIZONTAL
|
||||
val padding = 16.dpToPx(context)
|
||||
buttonsWrapper.setPadding(padding, padding, padding, 0)
|
||||
dialogContainer.setPadding(0, dialogContainer.paddingTop, 0, padding)
|
||||
contentView.setPadding(contentView.paddingStart, 0, contentView.paddingEnd, 30.dpToPx(context))
|
||||
binding.buttonsWrapper.setPadding(padding, padding, padding, 0)
|
||||
binding.dialogContainer.setPadding(0, binding.dialogContainer.paddingTop, 0, padding)
|
||||
binding.contentView.setPadding(binding.contentView.paddingStart, 0, binding.contentView.paddingEnd, 30.dpToPx(context))
|
||||
} else {
|
||||
scrollingSeparator.visibility = View.GONE
|
||||
buttonsWrapper.orientation = LinearLayout.VERTICAL
|
||||
contentView.setPadding(contentView.paddingStart, 0, contentView.paddingEnd, 0)
|
||||
binding.scrollingSeparator.visibility = View.GONE
|
||||
binding.buttonsWrapper.orientation = LinearLayout.VERTICAL
|
||||
binding.contentView.setPadding(binding.contentView.paddingStart, 0, binding.contentView.paddingEnd, 0)
|
||||
val sidePadding = context.resources.getDimension(R.dimen.alert_side_padding).toInt()
|
||||
buttonsWrapper.setPadding(20.dpToPx(context), sidePadding, sidePadding, 0)
|
||||
dialogContainer.setPadding(0, dialogContainer.paddingTop, 0, 24.dpToPx(context))
|
||||
binding.buttonsWrapper.setPadding(20.dpToPx(context), sidePadding, sidePadding, 0)
|
||||
binding.dialogContainer.setPadding(0, binding.dialogContainer.paddingTop, 0, 24.dpToPx(context))
|
||||
}
|
||||
buttonsWrapper.children.forEach { configureButtonLayoutParams(it) }
|
||||
binding.buttonsWrapper.children.forEach { configureButtonLayoutParams(it) }
|
||||
}
|
||||
|
||||
fun getContentView(): View? = additionalContentView
|
||||
|
|
@ -202,12 +185,12 @@ open class HabiticaAlertDialog(context: Context) : AlertDialog(context, R.style.
|
|||
): Button {
|
||||
val button: Button = if (isPrimary) {
|
||||
if (isDestructive) {
|
||||
buttonsWrapper.inflate(R.layout.dialog_habitica_primary_destructive_button) as? Button
|
||||
binding.buttonsWrapper.inflate(R.layout.dialog_habitica_primary_destructive_button) as? Button
|
||||
} else {
|
||||
buttonsWrapper.inflate(R.layout.dialog_habitica_primary_button) as? Button
|
||||
binding.buttonsWrapper.inflate(R.layout.dialog_habitica_primary_button) as? Button
|
||||
}
|
||||
} else {
|
||||
val button = buttonsWrapper.inflate(R.layout.dialog_habitica_secondary_button) as? Button
|
||||
val button = binding.buttonsWrapper.inflate(R.layout.dialog_habitica_secondary_button) as? Button
|
||||
if (isDestructive) {
|
||||
button?.setTextColor(ContextCompat.getColor(context, R.color.text_red))
|
||||
}
|
||||
|
|
@ -223,7 +206,7 @@ open class HabiticaAlertDialog(context: Context) : AlertDialog(context, R.style.
|
|||
function: ((HabiticaAlertDialog, Int) -> Unit)? = null
|
||||
): View {
|
||||
val weakThis = WeakReference(this)
|
||||
val buttonIndex = buttonsWrapper.childCount
|
||||
val buttonIndex = binding.buttonsWrapper.childCount
|
||||
buttonView.setOnClickListener {
|
||||
weakThis.get()?.let { it1 ->
|
||||
if (function != null) {
|
||||
|
|
@ -235,7 +218,7 @@ open class HabiticaAlertDialog(context: Context) : AlertDialog(context, R.style.
|
|||
}
|
||||
}
|
||||
configureButtonLayoutParams(buttonView)
|
||||
buttonsWrapper.addView(buttonView)
|
||||
binding.buttonsWrapper.addView(buttonView)
|
||||
// for some reason the padding gets lost somewhere.
|
||||
buttonView.setPadding(24.dpToPx(context), 0, 24.dpToPx(context), 0)
|
||||
return buttonView
|
||||
|
|
@ -276,32 +259,32 @@ open class HabiticaAlertDialog(context: Context) : AlertDialog(context, R.style.
|
|||
super.onStart()
|
||||
|
||||
if (isCelebratory) {
|
||||
titleTextView.post {
|
||||
val confettiContainer = view.findViewById<RelativeLayout>(R.id.confetti_container)
|
||||
binding.titleTextView.post {
|
||||
val confettiContainer = binding.root.findViewById<RelativeLayout>(R.id.confetti_container)
|
||||
ParticleSystem(confettiContainer, 40, ContextCompat.getDrawable(context, R.drawable.confetti_blue), 6000)
|
||||
.setAcceleration(0.00010f, 90)
|
||||
.setRotationSpeed(144f)
|
||||
.setSpeedByComponentsRange(-0.15f, 0.15f, -0.1f, -0.4f)
|
||||
.setFadeOut(200, AccelerateInterpolator())
|
||||
.emitWithGravity(titleTextView, Gravity.BOTTOM, 10, 2000)
|
||||
.emitWithGravity(binding.titleTextView, Gravity.BOTTOM, 10, 2000)
|
||||
ParticleSystem(confettiContainer, 40, ContextCompat.getDrawable(context, R.drawable.confetti_red), 6000)
|
||||
.setAcceleration(0.00010f, 90)
|
||||
.setRotationSpeed(144f)
|
||||
.setSpeedByComponentsRange(-0.15f, 0.15f, -0.1f, -0.4f)
|
||||
.setFadeOut(200, AccelerateInterpolator())
|
||||
.emitWithGravity(titleTextView, Gravity.BOTTOM, 10, 2000)
|
||||
.emitWithGravity(binding.titleTextView, Gravity.BOTTOM, 10, 2000)
|
||||
ParticleSystem(confettiContainer, 40, ContextCompat.getDrawable(context, R.drawable.confetti_yellow), 6000)
|
||||
.setAcceleration(0.00010f, 90)
|
||||
.setRotationSpeed(144f)
|
||||
.setSpeedByComponentsRange(-0.15f, 0.15f, -0.1f, -0.4f)
|
||||
.setFadeOut(200, AccelerateInterpolator())
|
||||
.emitWithGravity(titleTextView, Gravity.BOTTOM, 10, 2000)
|
||||
.emitWithGravity(binding.titleTextView, Gravity.BOTTOM, 10, 2000)
|
||||
ParticleSystem(confettiContainer, 40, ContextCompat.getDrawable(context, R.drawable.confetti_purple), 6000)
|
||||
.setAcceleration(0.00010f, 90)
|
||||
.setRotationSpeed(144f)
|
||||
.setSpeedByComponentsRange(-0.15f, 0.15f, -0.1f, -0.4f)
|
||||
.setFadeOut(200, AccelerateInterpolator())
|
||||
.emitWithGravity(titleTextView, Gravity.BOTTOM, 10, 2000)
|
||||
.emitWithGravity(binding.titleTextView, Gravity.BOTTOM, 10, 2000)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ class QuestCompletedDialogContent : LinearLayout {
|
|||
binding.ownerRewardsList.visibility = View.GONE
|
||||
}
|
||||
|
||||
if (questContent.drop?.exp ?: 0 > 0) {
|
||||
if ((questContent.drop?.exp ?: 0) > 0) {
|
||||
val view = inflater?.inflate(R.layout.row_quest_reward_imageview, binding.rewardsList, false) as? ViewGroup
|
||||
val imageView = view?.findViewById<ImageView>(R.id.imageView)
|
||||
imageView?.scaleType = ImageView.ScaleType.CENTER
|
||||
|
|
@ -72,7 +72,7 @@ class QuestCompletedDialogContent : LinearLayout {
|
|||
binding.rewardsList.addView(view)
|
||||
}
|
||||
|
||||
if (questContent.drop?.gp ?: 0 > 0) {
|
||||
if ((questContent.drop?.gp ?: 0) > 0) {
|
||||
val view = inflater?.inflate(R.layout.row_quest_reward_imageview, binding.rewardsList, false) as? ViewGroup
|
||||
val imageView = view?.findViewById<ImageView>(R.id.imageView)
|
||||
imageView?.scaleType = ImageView.ScaleType.CENTER
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ abstract class InsufficientCurrencyDialog(context: Context) : HabiticaAlertDialo
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val inflater = LayoutInflater.from(context)
|
||||
val view = inflater.inflate(getLayoutID(), contentView, false)
|
||||
val view = inflater.inflate(getLayoutID(), null)
|
||||
setAdditionalContentView(view)
|
||||
|
||||
imageView = view.findViewById(R.id.imageView)
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@ class InsufficientGemsDialog(context: Context, var gemPrice: Int) : Insufficient
|
|||
addButton(R.string.see_other_options, true) { _, _ -> MainNavigationController.navigate(R.id.gemPurchaseActivity, bundleOf(Pair("openSubscription", false))) }
|
||||
addCloseButton()
|
||||
contentView.setPadding(0, 0, 0, 0)
|
||||
dialogContainer.setPadding(0, 0, 0, dialogContainer.paddingBottom)
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
|
|
|
|||
|
|
@ -250,7 +250,7 @@ class PurchaseDialog(context: Context, component: UserComponent?, val item: Shop
|
|||
pinTextView = customHeader.findViewById(R.id.pin_text)
|
||||
|
||||
addCloseButton()
|
||||
buyButton = addButton(layoutInflater.inflate(R.layout.dialog_purchase_shopitem_button, buttonsWrapper, false), autoDismiss = false) { _, _ ->
|
||||
buyButton = addButton(layoutInflater.inflate(R.layout.dialog_purchase_shopitem_button, null), autoDismiss = false) { _, _ ->
|
||||
onBuyButtonClicked()
|
||||
}
|
||||
priceLabel = buyButton.findViewById(R.id.priceLabel)
|
||||
|
|
@ -359,7 +359,7 @@ class PurchaseDialog(context: Context, component: UserComponent?, val item: Shop
|
|||
Pair("key", shopItem.key)
|
||||
)
|
||||
)
|
||||
HapticFeedbackManager.tap(contentView)
|
||||
HapticFeedbackManager.tap(buyButton)
|
||||
val snackbarText = arrayOf("")
|
||||
val observable: (suspend () -> Any?)
|
||||
if (shopIdentifier != null && shopIdentifier == Shop.TIME_TRAVELERS_SHOP || "mystery_set" == shopItem.purchaseType || shopItem.currency == "hourglasses") {
|
||||
|
|
|
|||
Loading…
Reference in a new issue