Skip to content

Commit

Permalink
Improve background handling
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipthelen committed Jan 15, 2020
1 parent b65a360 commit 614546d
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
7 changes: 6 additions & 1 deletion Habitica/res/navigation/navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@
<fragment
android:id="@+id/shopsFragment"
android:name="com.habitrpg.android.habitica.ui.fragments.inventory.shops.ShopsFragment"
android:label="@string/sidebar_shops" />
android:label="@string/sidebar_shops" >
<argument
android:name="selectedTab"
app:argType="integer"
android:defaultValue="0" />
</fragment>
<fragment
android:id="@+id/avatarOverviewFragment"
android:name="com.habitrpg.android.habitica.ui.fragments.inventory.customization.AvatarOverviewFragment"
Expand Down
4 changes: 2 additions & 2 deletions Habitica/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,11 @@
</style>

<style name="AlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">@color/brand_100</item>
<item name="colorAccent">@color/brand_400</item>
</style>

<style name="HabiticaAlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">@color/brand_100</item>
<item name="colorAccent">@color/brand_400</item>
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class CustomizationRecyclerViewAdapter : androidx.recyclerview.widget.RecyclerVi
val dialog = HabiticaAlertDialog(itemView.context)
dialog.setMessage(R.string.purchase_from_timetravel_shop)
dialog.addButton(R.string.go_shopping, true) { _, _ ->
MainNavigationController.navigate(R.id.shopsFragment)
MainNavigationController.navigate(R.id.shopsFragment, bundleOf(Pair("selectedTab", 3)))
}
dialog.addButton(R.string.reward_dialog_dismiss, false)
dialog.show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ class ShopsFragment : BaseMainFragment() {
setViewPagerAdapter()
toolbarAccessoryContainer?.addView(currencyView)

arguments?.let {
val args = ShopsFragmentArgs.fromBundle(it)
if (args.selectedTab > 0) {
viewPager.currentItem = args.selectedTab
}
}

compositeSubscription.add(userRepository.getUser().subscribe(Consumer { updateCurrencyView(it) }, RxErrorHandler.handleEmptyError()))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class PurchaseDialog(context: Context, component: UserComponent?, val item: Shop
val gemsLeft = if (shopItem.limitedNumberLeft != null) shopItem.limitedNumberLeft else 0
if ((gemsLeft == 0 && shopItem.purchaseType == "gems") || shopItem.canAfford(user, false)) {
val observable: Flowable<Any>
if (shopIdentifier != null && shopIdentifier == Shop.TIME_TRAVELERS_SHOP || "mystery_set" == shopItem.purchaseType) {
if (shopIdentifier != null && shopIdentifier == Shop.TIME_TRAVELERS_SHOP || "mystery_set" == shopItem.purchaseType || shopItem.currency == "hourglasses") {
observable = if (shopItem.purchaseType == "gear") {
inventoryRepository.purchaseMysterySet(shopItem.key)
} else {
Expand Down Expand Up @@ -253,7 +253,7 @@ class PurchaseDialog(context: Context, component: UserComponent?, val item: Shop
.flatMap { userRepository.retrieveUser(withTasks = false, forced = true) }
.flatMap { inventoryRepository.retrieveInAppRewards() }
.subscribe({
if (item.isTypeGear) {
if (item.isTypeGear || item.currency == "hourglasses") {
EventBus.getDefault().post(GearPurchasedEvent(item))
}
}) { throwable ->
Expand All @@ -280,9 +280,9 @@ class PurchaseDialog(context: Context, component: UserComponent?, val item: Shop

private fun setBuyButtonEnabled(enabled: Boolean) {
if (enabled) {
buyButton.alpha = 0.5f
} else {
buyButton.alpha = 1.0f
} else {
buyButton.alpha = 0.5f
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import android.widget.TextView
import com.facebook.drawee.backends.pipeline.Fresco
import com.facebook.drawee.view.SimpleDraweeView
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.extensions.dpToPx
import com.habitrpg.android.habitica.models.inventory.QuestContent
import com.habitrpg.android.habitica.models.shops.ShopItem
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils
import com.habitrpg.android.habitica.ui.helpers.bindView


abstract class PurchaseDialogContent : LinearLayout {

private val imageView: SimpleDraweeView by bindView(R.id.imageView)
Expand Down Expand Up @@ -43,6 +45,10 @@ abstract class PurchaseDialogContent : LinearLayout {
.setAutoPlayAnimations(true)
.build()
imageView.controller = controller
val params = imageView.layoutParams
params.height = 147.dpToPx(context)
params.width = 140.dpToPx(context)
imageView.layoutParams = params
} else {
DataBindingUtils.loadImage(imageView, item.imageName)
}
Expand Down

0 comments on commit 614546d

Please sign in to comment.