mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 19:56:32 +00:00
Begin using viewbinding
This commit is contained in:
parent
ef6050876b
commit
b5aef0527d
16 changed files with 123 additions and 219 deletions
|
|
@ -158,6 +158,11 @@ android {
|
||||||
lintOptions {
|
lintOptions {
|
||||||
abortOnError false
|
abortOnError false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
viewBinding {
|
||||||
|
enabled true
|
||||||
|
}
|
||||||
|
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
release
|
release
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,99 +43,11 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<LinearLayout
|
<include
|
||||||
android:id="@+id/avatar_with_bars"
|
android:id="@+id/avatar_with_bars"
|
||||||
|
layout="@layout/avatar_with_bars"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content" />
|
||||||
android:layout_marginTop="5dp"
|
|
||||||
android:adjustViewBounds="true"
|
|
||||||
android:background="@color/transparent"
|
|
||||||
android:focusable="true"
|
|
||||||
android:focusableInTouchMode="true"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
|
|
||||||
<com.habitrpg.android.habitica.ui.AvatarView
|
|
||||||
android:id="@+id/avatarView"
|
|
||||||
android:layout_width="@dimen/avatar_header_width"
|
|
||||||
android:layout_height="@dimen/avatar_header_height"
|
|
||||||
android:layout_gravity="center_vertical"
|
|
||||||
android:layout_marginEnd="16dp"
|
|
||||||
app:showBackground="true"
|
|
||||||
app:showMount="true"
|
|
||||||
app:showPet="true" />
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<com.habitrpg.android.habitica.ui.views.ValueBar
|
|
||||||
android:id="@+id/hpBar"
|
|
||||||
layout="@layout/value_bar"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginBottom="@dimen/header_bar_spacing"
|
|
||||||
app:barForegroundColor="@color/hpColor"
|
|
||||||
app:lightBackground="true"
|
|
||||||
app:description="@string/HP_default" />
|
|
||||||
|
|
||||||
<com.habitrpg.android.habitica.ui.views.ValueBar
|
|
||||||
android:id="@+id/xpBar"
|
|
||||||
layout="@layout/value_bar"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginBottom="@dimen/header_bar_spacing"
|
|
||||||
app:barForegroundColor="@color/xpColor"
|
|
||||||
app:lightBackground="true"
|
|
||||||
app:description="@string/XP_default" />
|
|
||||||
|
|
||||||
<com.habitrpg.android.habitica.ui.views.ValueBar
|
|
||||||
android:id="@+id/mpBar"
|
|
||||||
layout="@layout/value_bar"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
app:barForegroundColor="@color/mpColor"
|
|
||||||
app:lightBackground="true"
|
|
||||||
app:description="@string/MP_default" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/lvl_tv"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="36dp"
|
|
||||||
android:drawablePadding="6dp"
|
|
||||||
android:gravity="center"
|
|
||||||
android:textSize="14sp" />
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/buffImageView"
|
|
||||||
android:layout_width="15dp"
|
|
||||||
android:layout_height="15dp"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:layout_marginStart="8dp"
|
|
||||||
tools:srcCompat="@tools:sample/avatars" />
|
|
||||||
|
|
||||||
<View
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
android:layout_weight="1" />
|
|
||||||
|
|
||||||
<com.habitrpg.android.habitica.ui.views.CurrencyViews
|
|
||||||
android:id="@+id/currencyView"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content" />
|
|
||||||
</LinearLayout>
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/profile_blurb"
|
android:id="@+id/profile_blurb"
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,7 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:padding="@dimen/spacing_large"
|
android:padding="@dimen/spacing_large"
|
||||||
android:id="@+id/login.linear.layout"
|
android:id="@+id/login_linear_layout"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:background="@color/transparent">
|
android:background="@color/transparent">
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,7 @@
|
||||||
the container. -->
|
the container. -->
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/navigation_drawer"
|
android:id="@+id/navigation_drawer"
|
||||||
android:name="com.habitrpg.android.habitica.ui.fragments.NavigationDrawerFragment"
|
class="com.habitrpg.android.habitica.ui.fragments.NavigationDrawerFragment"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_gravity="start"
|
android:layout_gravity="start"
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:id="@+id/chat.refresh.layout"
|
android:id="@+id/chat_refresh_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@
|
||||||
android:layout_marginRight="26dp"/>
|
android:layout_marginRight="26dp"/>
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/subscribe.listitem1.box"
|
android:id="@+id/subscribe_listitem1_box"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
style="@style/subscriptionBox">
|
style="@style/subscriptionBox">
|
||||||
|
|
@ -104,13 +104,13 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:srcCompat="@drawable/ic_keyboard_arrow_down_black_24dp"
|
app:srcCompat="@drawable/ic_keyboard_arrow_down_black_24dp"
|
||||||
android:id="@+id/subscribe.listitem1.expand"
|
android:id="@+id/subscribe_listitem1_expand"
|
||||||
android:layout_gravity="end"/>
|
android:layout_gravity="end"/>
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/subscribe.listitem1.description"
|
android:id="@+id/subscribe_listitem1_description"
|
||||||
android:text="@string/subscribe_listitem1_description"
|
android:text="@string/subscribe_listitem1_description"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
@ -118,7 +118,7 @@
|
||||||
android:visibility="gone"/>
|
android:visibility="gone"/>
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/subscribe.listitem2.box"
|
android:id="@+id/subscribe_listitem2_box"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
style="@style/subscriptionBox">
|
style="@style/subscriptionBox">
|
||||||
|
|
@ -133,12 +133,12 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:srcCompat="@drawable/ic_keyboard_arrow_down_black_24dp"
|
app:srcCompat="@drawable/ic_keyboard_arrow_down_black_24dp"
|
||||||
android:id="@+id/subscribe.listitem2.expand"
|
android:id="@+id/subscribe_listitem2_expand"
|
||||||
android:layout_gravity="end"/>
|
android:layout_gravity="end"/>
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/subscribe.listitem2.description"
|
android:id="@+id/subscribe_listitem2_description"
|
||||||
android:text="@string/subscribe_listitem2_description"
|
android:text="@string/subscribe_listitem2_description"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
@ -146,7 +146,7 @@
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/subscribe.listitem3.box"
|
android:id="@+id/subscribe_listitem3_box"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
style="@style/subscriptionBox">
|
style="@style/subscriptionBox">
|
||||||
|
|
@ -161,12 +161,12 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:srcCompat="@drawable/ic_keyboard_arrow_down_black_24dp"
|
app:srcCompat="@drawable/ic_keyboard_arrow_down_black_24dp"
|
||||||
android:id="@+id/subscribe.listitem3.expand"
|
android:id="@+id/subscribe_listitem3_expand"
|
||||||
android:layout_gravity="end"/>
|
android:layout_gravity="end"/>
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/subscribe.listitem3.description"
|
android:id="@+id/subscribe_listitem3_description"
|
||||||
android:text="@string/subscribe_listitem3_description"
|
android:text="@string/subscribe_listitem3_description"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
@ -174,7 +174,7 @@
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/subscribe.listitem4.box"
|
android:id="@+id/subscribe_listitem4_box"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
style="@style/subscriptionBox"
|
style="@style/subscriptionBox"
|
||||||
|
|
@ -189,12 +189,12 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:srcCompat="@drawable/ic_keyboard_arrow_down_black_24dp"
|
app:srcCompat="@drawable/ic_keyboard_arrow_down_black_24dp"
|
||||||
android:id="@+id/subscribe.listitem4.expand"
|
android:id="@+id/subscribe_listitem4_expand"
|
||||||
android:layout_gravity="end"/>
|
android:layout_gravity="end"/>
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/subscribe.listitem4.description"
|
android:id="@+id/subscribe_listitem4_description"
|
||||||
android:text="@string/subscribe_listitem4_description"
|
android:text="@string/subscribe_listitem4_description"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@
|
||||||
app:hintTextAppearance="@style/TextAppearance.AppCompat">
|
app:hintTextAppearance="@style/TextAppearance.AppCompat">
|
||||||
|
|
||||||
<net.pherth.android.emoji_library.EmojiEditText
|
<net.pherth.android.emoji_library.EmojiEditText
|
||||||
android:id="@+id/edit.new.message.text"
|
android:id="@+id/edit_new_message_text"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="5dp"
|
android:layout_margin="5dp"
|
||||||
|
|
|
||||||
|
|
@ -6,19 +6,16 @@ import android.graphics.drawable.BitmapDrawable
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.ImageView
|
|
||||||
import android.widget.TextView
|
|
||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
import com.habitrpg.android.habitica.R
|
import com.habitrpg.android.habitica.R
|
||||||
import com.habitrpg.android.habitica.data.UserRepository
|
import com.habitrpg.android.habitica.data.UserRepository
|
||||||
|
import com.habitrpg.android.habitica.databinding.AvatarWithBarsBinding
|
||||||
import com.habitrpg.android.habitica.events.BoughtGemsEvent
|
import com.habitrpg.android.habitica.events.BoughtGemsEvent
|
||||||
import com.habitrpg.android.habitica.helpers.HealthFormatter
|
import com.habitrpg.android.habitica.helpers.HealthFormatter
|
||||||
import com.habitrpg.android.habitica.helpers.MainNavigationController
|
import com.habitrpg.android.habitica.helpers.MainNavigationController
|
||||||
import com.habitrpg.android.habitica.models.Avatar
|
import com.habitrpg.android.habitica.models.Avatar
|
||||||
import com.habitrpg.android.habitica.models.user.Stats
|
import com.habitrpg.android.habitica.models.user.Stats
|
||||||
import com.habitrpg.android.habitica.models.user.User
|
import com.habitrpg.android.habitica.models.user.User
|
||||||
import com.habitrpg.android.habitica.ui.helpers.bindView
|
|
||||||
import com.habitrpg.android.habitica.ui.views.CurrencyViews
|
|
||||||
import com.habitrpg.android.habitica.ui.views.HabiticaIconsHelper
|
import com.habitrpg.android.habitica.ui.views.HabiticaIconsHelper
|
||||||
import com.habitrpg.android.habitica.ui.views.ValueBar
|
import com.habitrpg.android.habitica.ui.views.ValueBar
|
||||||
import io.reactivex.disposables.Disposable
|
import io.reactivex.disposables.Disposable
|
||||||
|
|
@ -26,14 +23,7 @@ import org.greenrobot.eventbus.Subscribe
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.math.floor
|
import kotlin.math.floor
|
||||||
|
|
||||||
class AvatarWithBarsViewModel(private val context: Context, view: View, userRepository: UserRepository? = null) {
|
class AvatarWithBarsViewModel(private val context: Context, private val binding: AvatarWithBarsBinding, userRepository: UserRepository? = null) {
|
||||||
private val hpBar: ValueBar by bindView(view, R.id.hpBar)
|
|
||||||
private val xpBar: ValueBar by bindView(view, R.id.xpBar)
|
|
||||||
private val mpBar: ValueBar by bindView(view, R.id.mpBar)
|
|
||||||
private val avatarView: AvatarView by bindView(view, R.id.avatarView)
|
|
||||||
private val lvlText: TextView by bindView(view, R.id.lvl_tv)
|
|
||||||
private val currencyView: CurrencyViews by bindView(view, R.id.currencyView)
|
|
||||||
private val buffImageView: ImageView by bindView(view, R.id.buffImageView)
|
|
||||||
private var userObject: Avatar? = null
|
private var userObject: Avatar? = null
|
||||||
|
|
||||||
private var cachedMaxHealth: Int = 0
|
private var cachedMaxHealth: Int = 0
|
||||||
|
|
@ -43,10 +33,10 @@ class AvatarWithBarsViewModel(private val context: Context, view: View, userRepo
|
||||||
private var disposable: Disposable? = null
|
private var disposable: Disposable? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
hpBar.setIcon(HabiticaIconsHelper.imageOfHeartLightBg())
|
binding.hpBar.setIcon(HabiticaIconsHelper.imageOfHeartLightBg())
|
||||||
xpBar.setIcon(HabiticaIconsHelper.imageOfExperience())
|
binding.xpBar.setIcon(HabiticaIconsHelper.imageOfExperience())
|
||||||
mpBar.setIcon(HabiticaIconsHelper.imageOfMagic())
|
binding.mpBar.setIcon(HabiticaIconsHelper.imageOfMagic())
|
||||||
buffImageView.setImageBitmap(HabiticaIconsHelper.imageOfBuffIconDark())
|
|
||||||
setHpBarData(0f, 50)
|
setHpBarData(0f, 50)
|
||||||
setXpBarData(0f, 1)
|
setXpBarData(0f, 1)
|
||||||
setMpBarData(0f, 1)
|
setMpBarData(0f, 1)
|
||||||
|
|
@ -64,19 +54,19 @@ class AvatarWithBarsViewModel(private val context: Context, view: View, userRepo
|
||||||
|
|
||||||
var userClass = ""
|
var userClass = ""
|
||||||
|
|
||||||
avatarView.setAvatar(user)
|
binding.avatarView.setAvatar(user)
|
||||||
|
|
||||||
if (stats.habitClass != null) {
|
if (stats.habitClass != null) {
|
||||||
userClass = stats.getTranslatedClassName(context)
|
userClass = stats.getTranslatedClassName(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
mpBar.visibility = if (stats.habitClass == null || stats.lvl ?: 0 < 10 || user.preferences?.disableClasses == true) View.GONE else View.VISIBLE
|
binding.mpBar.visibility = if (stats.habitClass == null || stats.lvl ?: 0 < 10 || user.preferences?.disableClasses == true) View.GONE else View.VISIBLE
|
||||||
|
|
||||||
if (!user.hasClass()) {
|
if (!user.hasClass()) {
|
||||||
lvlText.text = context.getString(R.string.user_level, stats.lvl)
|
binding.lvlTv.text = context.getString(R.string.user_level, stats.lvl)
|
||||||
lvlText.setCompoundDrawables(null, null, null, null)
|
binding.lvlTv.setCompoundDrawables(null, null, null, null)
|
||||||
} else {
|
} else {
|
||||||
lvlText.text = context.getString(R.string.user_level_with_class, stats.lvl, userClass.substring(0, 1).toUpperCase(Locale.getDefault()) + userClass.substring(1))
|
binding.lvlTv.text = context.getString(R.string.user_level_with_class, stats.lvl, userClass.substring(0, 1).toUpperCase(Locale.getDefault()) + userClass.substring(1))
|
||||||
var drawable: Drawable? = null
|
var drawable: Drawable? = null
|
||||||
when (stats.habitClass) {
|
when (stats.habitClass) {
|
||||||
Stats.WARRIOR -> drawable = BitmapDrawable(context.resources, HabiticaIconsHelper.imageOfWarriorDarkBg())
|
Stats.WARRIOR -> drawable = BitmapDrawable(context.resources, HabiticaIconsHelper.imageOfWarriorDarkBg())
|
||||||
|
|
@ -85,7 +75,7 @@ class AvatarWithBarsViewModel(private val context: Context, view: View, userRepo
|
||||||
Stats.HEALER -> drawable = BitmapDrawable(context.resources, HabiticaIconsHelper.imageOfHealerDarkBg())
|
Stats.HEALER -> drawable = BitmapDrawable(context.resources, HabiticaIconsHelper.imageOfHealerDarkBg())
|
||||||
}
|
}
|
||||||
drawable?.setBounds(0, 0, drawable.minimumWidth, drawable.minimumHeight)
|
drawable?.setBounds(0, 0, drawable.minimumWidth, drawable.minimumHeight)
|
||||||
lvlText.setCompoundDrawables(drawable, null, null, null)
|
binding.lvlTv.setCompoundDrawables(drawable, null, null, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
setHpBarData(stats.hp?.toFloat() ?: 0.toFloat(), stats.maxHealth ?: 0)
|
setHpBarData(stats.hp?.toFloat() ?: 0.toFloat(), stats.maxHealth ?: 0)
|
||||||
|
|
@ -93,19 +83,19 @@ class AvatarWithBarsViewModel(private val context: Context, view: View, userRepo
|
||||||
setMpBarData(stats.mp?.toFloat() ?: 0.toFloat(), stats.maxMP ?: 0)
|
setMpBarData(stats.mp?.toFloat() ?: 0.toFloat(), stats.maxMP ?: 0)
|
||||||
|
|
||||||
if (!stats.isBuffed) {
|
if (!stats.isBuffed) {
|
||||||
buffImageView.visibility = View.GONE
|
binding.buffImageView.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
currencyView.gold = stats.gp ?: 0.0
|
binding.currencyView.gold = stats.gp ?: 0.0
|
||||||
if (user is User) {
|
if (user is User) {
|
||||||
currencyView.hourglasses = user.getHourglassCount()?.toDouble() ?: 0.0
|
binding.currencyView.hourglasses = user.hourglassCount.toDouble()
|
||||||
currencyView.gems = user.gemCount.toDouble()
|
binding.currencyView.gems = user.gemCount.toDouble()
|
||||||
}
|
}
|
||||||
|
|
||||||
currencyView.setOnClickListener {
|
binding.currencyView.setOnClickListener {
|
||||||
MainNavigationController.navigate(R.id.gemPurchaseActivity, bundleOf(Pair("openSubscription", false)))
|
MainNavigationController.navigate(R.id.gemPurchaseActivity, bundleOf(Pair("openSubscription", false)))
|
||||||
}
|
}
|
||||||
avatarView.setOnClickListener {
|
binding.avatarView.setOnClickListener {
|
||||||
MainNavigationController.navigate(R.id.avatarOverviewFragment)
|
MainNavigationController.navigate(R.id.avatarOverviewFragment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -114,34 +104,34 @@ class AvatarWithBarsViewModel(private val context: Context, view: View, userRepo
|
||||||
if (valueMax != 0) {
|
if (valueMax != 0) {
|
||||||
cachedMaxHealth = valueMax
|
cachedMaxHealth = valueMax
|
||||||
}
|
}
|
||||||
hpBar.set(HealthFormatter.format(value.toDouble()), cachedMaxHealth.toDouble())
|
binding.hpBar.set(HealthFormatter.format(value.toDouble()), cachedMaxHealth.toDouble())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setXpBarData(value: Float, valueMax: Int) {
|
private fun setXpBarData(value: Float, valueMax: Int) {
|
||||||
if (valueMax != 0) {
|
if (valueMax != 0) {
|
||||||
cachedMaxExp = valueMax
|
cachedMaxExp = valueMax
|
||||||
}
|
}
|
||||||
xpBar.set(floor(value.toDouble()), cachedMaxExp.toDouble())
|
binding.xpBar.set(floor(value.toDouble()), cachedMaxExp.toDouble())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setMpBarData(value: Float, valueMax: Int) {
|
private fun setMpBarData(value: Float, valueMax: Int) {
|
||||||
if (valueMax != 0) {
|
if (valueMax != 0) {
|
||||||
cachedMaxMana = valueMax
|
cachedMaxMana = valueMax
|
||||||
}
|
}
|
||||||
mpBar.set(floor(value.toDouble()), cachedMaxMana.toDouble())
|
binding.mpBar.set(floor(value.toDouble()), cachedMaxMana.toDouble())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
fun onEvent(gemsEvent: BoughtGemsEvent) {
|
fun onEvent(gemsEvent: BoughtGemsEvent) {
|
||||||
var gems = userObject?.gemCount ?: 0
|
var gems = userObject?.gemCount ?: 0
|
||||||
gems += gemsEvent.NewGemsToAdd
|
gems += gemsEvent.NewGemsToAdd
|
||||||
currencyView.gems = gems.toDouble()
|
binding.currencyView.gems = gems.toDouble()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun valueBarLabelsToBlack() {
|
fun valueBarLabelsToBlack() {
|
||||||
hpBar.setLightBackground(true)
|
binding.hpBar.setLightBackground(true)
|
||||||
xpBar.setLightBackground(true)
|
binding.xpBar.setLightBackground(true)
|
||||||
mpBar.setLightBackground(true)
|
binding.mpBar.setLightBackground(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,11 @@
|
||||||
package com.habitrpg.android.habitica.ui.activities
|
package com.habitrpg.android.habitica.ui.activities
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
import androidx.appcompat.widget.Toolbar
|
import androidx.appcompat.widget.Toolbar
|
||||||
|
|
@ -29,6 +32,10 @@ abstract class BaseActivity : AppCompatActivity() {
|
||||||
|
|
||||||
protected abstract fun getLayoutResId(): Int
|
protected abstract fun getLayoutResId(): Int
|
||||||
|
|
||||||
|
open fun getContentView(): View {
|
||||||
|
return (getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater).inflate(getLayoutResId(), null)
|
||||||
|
}
|
||||||
|
|
||||||
protected var compositeSubscription = CompositeDisposable()
|
protected var compositeSubscription = CompositeDisposable()
|
||||||
|
|
||||||
private val habiticaApplication: HabiticaApplication
|
private val habiticaApplication: HabiticaApplication
|
||||||
|
|
@ -49,11 +56,11 @@ abstract class BaseActivity : AppCompatActivity() {
|
||||||
resources.updateConfiguration(configuration, resources.displayMetrics)
|
resources.updateConfiguration(configuration, resources.displayMetrics)
|
||||||
loadTheme(sharedPreferences)
|
loadTheme(sharedPreferences)
|
||||||
|
|
||||||
delegate.setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
delegate.localNightMode = AppCompatDelegate.MODE_NIGHT_NO
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
habiticaApplication
|
habiticaApplication
|
||||||
injectActivity(HabiticaBaseApplication.userComponent)
|
injectActivity(HabiticaBaseApplication.userComponent)
|
||||||
setContentView(getLayoutResId())
|
setContentView(getContentView())
|
||||||
compositeSubscription = CompositeDisposable()
|
compositeSubscription = CompositeDisposable()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ import com.habitrpg.android.habitica.components.UserComponent
|
||||||
import com.habitrpg.android.habitica.data.ApiClient
|
import com.habitrpg.android.habitica.data.ApiClient
|
||||||
import com.habitrpg.android.habitica.data.InventoryRepository
|
import com.habitrpg.android.habitica.data.InventoryRepository
|
||||||
import com.habitrpg.android.habitica.data.SocialRepository
|
import com.habitrpg.android.habitica.data.SocialRepository
|
||||||
|
import com.habitrpg.android.habitica.data.UserRepository
|
||||||
|
import com.habitrpg.android.habitica.databinding.ActivityFullProfileBinding
|
||||||
import com.habitrpg.android.habitica.helpers.MainNavigationController
|
import com.habitrpg.android.habitica.helpers.MainNavigationController
|
||||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
||||||
import com.habitrpg.android.habitica.helpers.UserStatComputer
|
import com.habitrpg.android.habitica.helpers.UserStatComputer
|
||||||
|
|
@ -54,18 +56,18 @@ class FullProfileActivity : BaseActivity() {
|
||||||
lateinit var apiClient: ApiClient
|
lateinit var apiClient: ApiClient
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var socialRepository: SocialRepository
|
lateinit var socialRepository: SocialRepository
|
||||||
|
@Inject
|
||||||
|
lateinit var userRepository: UserRepository
|
||||||
|
|
||||||
private val toolbar: Toolbar by bindView(R.id.toolbar)
|
private val toolbar: Toolbar by bindView(R.id.toolbar)
|
||||||
private val profileImage: SimpleDraweeView by bindView(R.id.profile_image)
|
private val profileImage: SimpleDraweeView by bindView(R.id.profile_image)
|
||||||
private val blurbTextView: TextView by bindView(R.id.profile_blurb)
|
private val blurbTextView: TextView by bindView(R.id.profile_blurb)
|
||||||
private val avatarView: AvatarView by bindView(R.id.avatarView)
|
|
||||||
private val attributesCardView: androidx.cardview.widget.CardView by bindView(R.id.profile_attributes_card)
|
private val attributesCardView: androidx.cardview.widget.CardView by bindView(R.id.profile_attributes_card)
|
||||||
private val attributesTableLayout: TableLayout by bindView(R.id.attributes_table)
|
private val attributesTableLayout: TableLayout by bindView(R.id.attributes_table)
|
||||||
private val attributesCollapseIcon: AppCompatImageView by bindView(R.id.attributes_collapse_icon)
|
private val attributesCollapseIcon: AppCompatImageView by bindView(R.id.attributes_collapse_icon)
|
||||||
private val equipmentTableLayout: TableLayout by bindView(R.id.equipment_table)
|
private val equipmentTableLayout: TableLayout by bindView(R.id.equipment_table)
|
||||||
private val costumeTableLayout: TableLayout by bindView(R.id.costume_table)
|
private val costumeTableLayout: TableLayout by bindView(R.id.costume_table)
|
||||||
private val costumeCard: androidx.cardview.widget.CardView by bindView(R.id.profile_costume_card)
|
private val costumeCard: androidx.cardview.widget.CardView by bindView(R.id.profile_costume_card)
|
||||||
private val avatarWithStatsView: View by bindView(R.id.avatar_with_bars)
|
|
||||||
private val scrollView: NestedScrollView by bindView(R.id.fullprofile_scrollview)
|
private val scrollView: NestedScrollView by bindView(R.id.fullprofile_scrollview)
|
||||||
private val petsFoundCount: TextView by bindView(R.id.profile_pets_found_count)
|
private val petsFoundCount: TextView by bindView(R.id.profile_pets_found_count)
|
||||||
private val mountsTamedCount: TextView by bindView(R.id.profile_mounts_tamed_count)
|
private val mountsTamedCount: TextView by bindView(R.id.profile_mounts_tamed_count)
|
||||||
|
|
@ -84,7 +86,6 @@ class FullProfileActivity : BaseActivity() {
|
||||||
private var userID = ""
|
private var userID = ""
|
||||||
private var username: String? = null
|
private var username: String? = null
|
||||||
private var userDisplayName: String? = null
|
private var userDisplayName: String? = null
|
||||||
private var avatarWithBars: AvatarWithBarsViewModel? = null
|
|
||||||
private var attributeStrSum = 0f
|
private var attributeStrSum = 0f
|
||||||
private var attributeIntSum = 0f
|
private var attributeIntSum = 0f
|
||||||
private var attributeConSum = 0f
|
private var attributeConSum = 0f
|
||||||
|
|
@ -92,6 +93,8 @@ class FullProfileActivity : BaseActivity() {
|
||||||
private var attributeDetailsHidden = true
|
private var attributeDetailsHidden = true
|
||||||
private val attributeRows = ArrayList<TableRow>()
|
private val attributeRows = ArrayList<TableRow>()
|
||||||
private val dateFormatter = SimpleDateFormat.getDateInstance()
|
private val dateFormatter = SimpleDateFormat.getDateInstance()
|
||||||
|
private var avatarWithBars: AvatarWithBarsViewModel? = null
|
||||||
|
lateinit private var binding: ActivityFullProfileBinding
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
@ -105,16 +108,14 @@ class FullProfileActivity : BaseActivity() {
|
||||||
setTitle(R.string.profile_loading_data)
|
setTitle(R.string.profile_loading_data)
|
||||||
|
|
||||||
compositeSubscription.add(socialRepository.getMember(this.userID).subscribe(Consumer { this.updateView(it) }, RxErrorHandler.handleEmptyError()))
|
compositeSubscription.add(socialRepository.getMember(this.userID).subscribe(Consumer { this.updateView(it) }, RxErrorHandler.handleEmptyError()))
|
||||||
|
avatarWithBars = AvatarWithBarsViewModel(this, binding.avatarWithBars)
|
||||||
avatarWithBars?.valueBarLabelsToBlack()
|
avatarWithBars?.valueBarLabelsToBlack()
|
||||||
|
|
||||||
avatarWithStatsView.setBackgroundColor(ContextCompat.getColor(this, R.color.transparent))
|
binding.avatarWithBars.root.setBackgroundColor(ContextCompat.getColor(this, R.color.transparent))
|
||||||
|
|
||||||
attributeRows.clear()
|
attributeRows.clear()
|
||||||
attributesCardView.setOnClickListener { toggleAttributeDetails() }
|
attributesCardView.setOnClickListener { toggleAttributeDetails() }
|
||||||
|
|
||||||
avatarWithBars = AvatarWithBarsViewModel(this, avatarWithStatsView)
|
|
||||||
|
|
||||||
sendMessageButton.setOnClickListener { showSendMessageToUserDialog() }
|
sendMessageButton.setOnClickListener { showSendMessageToUserDialog() }
|
||||||
giftGemsButton.setOnClickListener { MainNavigationController.navigate(R.id.giftGemsActivity, bundleOf(Pair("userID", userID), Pair("username", null))) }
|
giftGemsButton.setOnClickListener { MainNavigationController.navigate(R.id.giftGemsActivity, bundleOf(Pair("userID", userID), Pair("username", null))) }
|
||||||
giftSubscriptionButton.setOnClickListener { MainNavigationController.navigate(R.id.giftSubscriptionActivity, bundleOf(Pair("userID", userID), Pair("username", null))) }
|
giftSubscriptionButton.setOnClickListener { MainNavigationController.navigate(R.id.giftSubscriptionActivity, bundleOf(Pair("userID", userID), Pair("username", null))) }
|
||||||
|
|
@ -213,7 +214,6 @@ class FullProfileActivity : BaseActivity() {
|
||||||
user.authentication?.timestamps?.lastLoggedIn?.let { lastLoginView.text = dateFormatter.format(it) }
|
user.authentication?.timestamps?.lastLoggedIn?.let { lastLoginView.text = dateFormatter.format(it) }
|
||||||
totalCheckinsView.text = user.loginIncentives.toString()
|
totalCheckinsView.text = user.loginIncentives.toString()
|
||||||
|
|
||||||
avatarView.setAvatar(user)
|
|
||||||
avatarWithBars?.updateData(user)
|
avatarWithBars?.updateData(user)
|
||||||
|
|
||||||
compositeSubscription.add(loadItemDataByOutfit(user.equipped).subscribe(Consumer { gear -> this.gotGear(gear, user) }, RxErrorHandler.handleEmptyError()))
|
compositeSubscription.add(loadItemDataByOutfit(user.equipped).subscribe(Consumer { gear -> this.gotGear(gear, user) }, RxErrorHandler.handleEmptyError()))
|
||||||
|
|
@ -465,6 +465,11 @@ class FullProfileActivity : BaseActivity() {
|
||||||
return R.layout.activity_full_profile
|
return R.layout.activity_full_profile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getContentView(): View {
|
||||||
|
binding = ActivityFullProfileBinding.inflate(layoutInflater)
|
||||||
|
return binding.root
|
||||||
|
}
|
||||||
|
|
||||||
override fun injectActivity(component: UserComponent?) {
|
override fun injectActivity(component: UserComponent?) {
|
||||||
component?.inject(this)
|
component?.inject(this)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,16 +19,12 @@ import android.view.*
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.appcompat.app.ActionBarDrawerToggle
|
import androidx.appcompat.app.ActionBarDrawerToggle
|
||||||
import androidx.appcompat.widget.Toolbar
|
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.content.FileProvider
|
import androidx.core.content.FileProvider
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import androidx.lifecycle.ViewModelProviders
|
import androidx.lifecycle.ViewModelProviders
|
||||||
import androidx.navigation.findNavController
|
import androidx.navigation.findNavController
|
||||||
import com.facebook.drawee.view.SimpleDraweeView
|
import com.facebook.drawee.view.SimpleDraweeView
|
||||||
import com.google.android.material.appbar.AppBarLayout
|
|
||||||
import com.google.android.material.appbar.CollapsingToolbarLayout
|
|
||||||
import com.google.android.material.tabs.TabLayout
|
|
||||||
import com.google.firebase.analytics.FirebaseAnalytics
|
import com.google.firebase.analytics.FirebaseAnalytics
|
||||||
import com.google.firebase.perf.FirebasePerformance
|
import com.google.firebase.perf.FirebasePerformance
|
||||||
import com.habitrpg.android.habitica.HabiticaBaseApplication
|
import com.habitrpg.android.habitica.HabiticaBaseApplication
|
||||||
|
|
@ -37,6 +33,7 @@ import com.habitrpg.android.habitica.api.HostConfig
|
||||||
import com.habitrpg.android.habitica.api.MaintenanceApiService
|
import com.habitrpg.android.habitica.api.MaintenanceApiService
|
||||||
import com.habitrpg.android.habitica.components.UserComponent
|
import com.habitrpg.android.habitica.components.UserComponent
|
||||||
import com.habitrpg.android.habitica.data.*
|
import com.habitrpg.android.habitica.data.*
|
||||||
|
import com.habitrpg.android.habitica.databinding.ActivityMainBinding
|
||||||
import com.habitrpg.android.habitica.events.*
|
import com.habitrpg.android.habitica.events.*
|
||||||
import com.habitrpg.android.habitica.events.commands.FeedCommand
|
import com.habitrpg.android.habitica.events.commands.FeedCommand
|
||||||
import com.habitrpg.android.habitica.extensions.DateUtils
|
import com.habitrpg.android.habitica.extensions.DateUtils
|
||||||
|
|
@ -60,8 +57,6 @@ import com.habitrpg.android.habitica.ui.AvatarWithBarsViewModel
|
||||||
import com.habitrpg.android.habitica.ui.TutorialView
|
import com.habitrpg.android.habitica.ui.TutorialView
|
||||||
import com.habitrpg.android.habitica.ui.fragments.NavigationDrawerFragment
|
import com.habitrpg.android.habitica.ui.fragments.NavigationDrawerFragment
|
||||||
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils
|
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils
|
||||||
import com.habitrpg.android.habitica.ui.helpers.bindOptionalView
|
|
||||||
import com.habitrpg.android.habitica.ui.helpers.bindView
|
|
||||||
import com.habitrpg.android.habitica.ui.viewmodels.NotificationsViewModel
|
import com.habitrpg.android.habitica.ui.viewmodels.NotificationsViewModel
|
||||||
import com.habitrpg.android.habitica.ui.views.HabiticaIconsHelper
|
import com.habitrpg.android.habitica.ui.views.HabiticaIconsHelper
|
||||||
import com.habitrpg.android.habitica.ui.views.HabiticaSnackbar
|
import com.habitrpg.android.habitica.ui.views.HabiticaSnackbar
|
||||||
|
|
@ -69,7 +64,6 @@ import com.habitrpg.android.habitica.ui.views.HabiticaSnackbar.SnackbarDisplayTy
|
||||||
import com.habitrpg.android.habitica.ui.views.ValueBar
|
import com.habitrpg.android.habitica.ui.views.ValueBar
|
||||||
import com.habitrpg.android.habitica.ui.views.dialogs.AchievementDialog
|
import com.habitrpg.android.habitica.ui.views.dialogs.AchievementDialog
|
||||||
import com.habitrpg.android.habitica.ui.views.dialogs.HabiticaAlertDialog
|
import com.habitrpg.android.habitica.ui.views.dialogs.HabiticaAlertDialog
|
||||||
import com.habitrpg.android.habitica.ui.views.navigation.HabiticaBottomNavigationView
|
|
||||||
import com.habitrpg.android.habitica.ui.views.yesterdailies.YesterdailyDialog
|
import com.habitrpg.android.habitica.ui.views.yesterdailies.YesterdailyDialog
|
||||||
import com.habitrpg.android.habitica.userpicture.BitmapUtils
|
import com.habitrpg.android.habitica.userpicture.BitmapUtils
|
||||||
import com.habitrpg.android.habitica.widget.AvatarStatsWidgetProvider
|
import com.habitrpg.android.habitica.widget.AvatarStatsWidgetProvider
|
||||||
|
|
@ -121,21 +115,13 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
|
||||||
@Inject
|
@Inject
|
||||||
internal lateinit var appConfigManager: AppConfigManager
|
internal lateinit var appConfigManager: AppConfigManager
|
||||||
|
|
||||||
val snackbarContainer: ViewGroup by bindView(R.id.snackbar_container)
|
lateinit var binding: ActivityMainBinding
|
||||||
internal val bottomNavigation: HabiticaBottomNavigationView by bindView(R.id.bottom_navigation)
|
|
||||||
|
|
||||||
private val appBar: AppBarLayout by bindView(R.id.appbar)
|
val snackbarContainer: ViewGroup
|
||||||
internal val toolbar: Toolbar by bindView(R.id.toolbar)
|
get() = binding.snackbarContainer
|
||||||
internal val toolbarAccessoryContainer: FrameLayout by bindView(R.id.toolbar_accessory_container)
|
|
||||||
private val toolbarTitleTextView: TextView by bindView(R.id.toolbar_title)
|
|
||||||
private val collapsingToolbar: CollapsingToolbarLayout by bindView(R.id.collapsing_toolbar)
|
|
||||||
internal val detailTabs: TabLayout? by bindOptionalView(R.id.detail_tabs)
|
|
||||||
val avatarWithBars: View by bindView(R.id.avatar_with_bars)
|
|
||||||
private val overlayLayout: ViewGroup by bindView(R.id.overlayFrameLayout)
|
|
||||||
|
|
||||||
private val connectionIssueTextView: TextView by bindView(R.id.connection_issue_textview)
|
|
||||||
var user: User? = null
|
var user: User? = null
|
||||||
|
|
||||||
|
|
||||||
private var avatarInHeader: AvatarWithBarsViewModel? = null
|
private var avatarInHeader: AvatarWithBarsViewModel? = null
|
||||||
private var notificationsViewModel: NotificationsViewModel? = null
|
private var notificationsViewModel: NotificationsViewModel? = null
|
||||||
private var faintDialog: HabiticaAlertDialog? = null
|
private var faintDialog: HabiticaAlertDialog? = null
|
||||||
|
|
@ -152,29 +138,34 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
|
||||||
get() = user?.id ?: ""
|
get() = user?.id ?: ""
|
||||||
|
|
||||||
val isAppBarExpanded: Boolean
|
val isAppBarExpanded: Boolean
|
||||||
get() = appBar.height - appBar.bottom == 0
|
get() = binding.appbar.height - binding.appbar.bottom == 0
|
||||||
|
|
||||||
|
|
||||||
override fun getLayoutResId(): Int {
|
override fun getLayoutResId(): Int {
|
||||||
return R.layout.activity_main
|
return R.layout.activity_main
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getContentView(): View {
|
||||||
|
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||||
|
return binding.root
|
||||||
|
}
|
||||||
|
|
||||||
private var launchTrace: com.google.firebase.perf.metrics.Trace? = null
|
private var launchTrace: com.google.firebase.perf.metrics.Trace? = null
|
||||||
|
|
||||||
@SuppressLint("ObsoleteSdkInt")
|
@SuppressLint("ObsoleteSdkInt")
|
||||||
public override fun onCreate(savedInstanceState: Bundle?) {
|
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
launchTrace = FirebasePerformance.getInstance().newTrace("MainActivityLaunch")
|
launchTrace = FirebasePerformance.getInstance().newTrace("MainActivityLaunch")
|
||||||
launchTrace?.start()
|
launchTrace?.start()
|
||||||
|
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
|
||||||
if (!HabiticaBaseApplication.checkUserAuthentication(this, hostConfig)) {
|
if (!HabiticaBaseApplication.checkUserAuthentication(this, hostConfig)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
setupToolbar(toolbar)
|
setupToolbar(binding.toolbar)
|
||||||
|
|
||||||
avatarInHeader = AvatarWithBarsViewModel(this, avatarWithBars, userRepository)
|
avatarInHeader = AvatarWithBarsViewModel(this, binding.avatarWithBars, userRepository)
|
||||||
sideAvatarView = AvatarView(this, showBackground = true, showMount = false, showPet = false)
|
sideAvatarView = AvatarView(this, showBackground = true, showMount = false, showPet = false)
|
||||||
|
|
||||||
compositeSubscription.add(userRepository.getUser()
|
compositeSubscription.add(userRepository.getUser()
|
||||||
|
|
@ -213,10 +204,10 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
|
||||||
|
|
||||||
val navigationController = findNavController(R.id.nav_host_fragment)
|
val navigationController = findNavController(R.id.nav_host_fragment)
|
||||||
navigationController.addOnDestinationChangedListener { _, destination, _ ->
|
navigationController.addOnDestinationChangedListener { _, destination, _ ->
|
||||||
if (destination.label.isNullOrEmpty() ) {
|
if (destination.label.isNullOrEmpty() && user?.isValid == true) {
|
||||||
toolbarTitleTextView.text = user?.profile?.name
|
binding.toolbarTitle.text = user?.profile?.name
|
||||||
} else if (user?.isValid == true && user?.profile != null) {
|
} else if (user?.isValid == true && user?.profile != null) {
|
||||||
toolbarTitleTextView.text = destination.label
|
binding.toolbarTitle.text = destination.label
|
||||||
}
|
}
|
||||||
drawerFragment?.setSelection(destination.id, null, false)
|
drawerFragment?.setSelection(destination.id, null, false)
|
||||||
}
|
}
|
||||||
|
|
@ -239,9 +230,9 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupBottomnavigationLayoutListener() {
|
private fun setupBottomnavigationLayoutListener() {
|
||||||
bottomNavigation.viewTreeObserver.addOnGlobalLayoutListener {
|
binding.bottomNavigation.viewTreeObserver.addOnGlobalLayoutListener {
|
||||||
if (bottomNavigation.visibility == View.VISIBLE) {
|
if (binding.bottomNavigation.visibility == View.VISIBLE) {
|
||||||
snackbarContainer.setPadding(0, 0, 0, bottomNavigation.barHeight + 12.dpToPx(this))
|
snackbarContainer.setPadding(0, 0, 0, binding.bottomNavigation.barHeight + 12.dpToPx(this))
|
||||||
} else {
|
} else {
|
||||||
snackbarContainer.setPadding(0, 0, 0, 0)
|
snackbarContainer.setPadding(0, 0, 0, 0)
|
||||||
}
|
}
|
||||||
|
|
@ -530,7 +521,7 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
|
||||||
view.setTutorialText(text)
|
view.setTutorialText(text)
|
||||||
view.onReaction = this
|
view.onReaction = this
|
||||||
view.setCanBeDeferred(canBeDeferred)
|
view.setCanBeDeferred(canBeDeferred)
|
||||||
this.overlayLayout.addView(view)
|
binding.overlayFrameLayout.addView(view)
|
||||||
|
|
||||||
val additionalData = HashMap<String, Any>()
|
val additionalData = HashMap<String, Any>()
|
||||||
additionalData["eventLabel"] = step.identifier + "-android"
|
additionalData["eventLabel"] = step.identifier + "-android"
|
||||||
|
|
@ -546,7 +537,7 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
|
||||||
view.setTutorialTexts(texts)
|
view.setTutorialTexts(texts)
|
||||||
view.onReaction = this
|
view.onReaction = this
|
||||||
view.setCanBeDeferred(canBeDeferred)
|
view.setCanBeDeferred(canBeDeferred)
|
||||||
this.overlayLayout.addView(view)
|
binding.overlayFrameLayout.addView(view)
|
||||||
|
|
||||||
val additionalData = HashMap<String, Any>()
|
val additionalData = HashMap<String, Any>()
|
||||||
additionalData["eventLabel"] = step.identifier + "-android"
|
additionalData["eventLabel"] = step.identifier + "-android"
|
||||||
|
|
@ -561,7 +552,7 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
|
||||||
updateData[path] = true
|
updateData[path] = true
|
||||||
compositeSubscription.add(userRepository.updateUser(user, updateData)
|
compositeSubscription.add(userRepository.updateUser(user, updateData)
|
||||||
.subscribe(Consumer { }, RxErrorHandler.handleEmptyError()))
|
.subscribe(Consumer { }, RxErrorHandler.handleEmptyError()))
|
||||||
this.overlayLayout.removeView(this.activeTutorialView)
|
binding.overlayFrameLayout.removeView(this.activeTutorialView)
|
||||||
this.removeActiveTutorialView()
|
this.removeActiveTutorialView()
|
||||||
|
|
||||||
val additionalData = HashMap<String, Any>()
|
val additionalData = HashMap<String, Any>()
|
||||||
|
|
@ -578,7 +569,7 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
|
||||||
|
|
||||||
private fun removeActiveTutorialView() {
|
private fun removeActiveTutorialView() {
|
||||||
if (this.activeTutorialView != null) {
|
if (this.activeTutorialView != null) {
|
||||||
this.overlayLayout.removeView(this.activeTutorialView)
|
binding.overlayFrameLayout.removeView(this.activeTutorialView)
|
||||||
this.activeTutorialView = null
|
this.activeTutorialView = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -703,11 +694,11 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
|
||||||
super.onEvent(event)
|
super.onEvent(event)
|
||||||
} else {
|
} else {
|
||||||
connectionIssueHandler?.removeCallbacksAndMessages(null)
|
connectionIssueHandler?.removeCallbacksAndMessages(null)
|
||||||
connectionIssueTextView.visibility = View.VISIBLE
|
binding.connectionIssueTextview.visibility = View.VISIBLE
|
||||||
connectionIssueTextView.text = event.message
|
binding.connectionIssueTextview.text = event.message
|
||||||
connectionIssueHandler = Handler()
|
connectionIssueHandler = Handler()
|
||||||
connectionIssueHandler?.postDelayed({
|
connectionIssueHandler?.postDelayed({
|
||||||
connectionIssueTextView.visibility = View.GONE
|
binding.connectionIssueTextview.visibility = View.GONE
|
||||||
}, 5000)
|
}, 5000)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,18 +4,16 @@ import android.content.Context
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.TextView
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.facebook.drawee.view.SimpleDraweeView
|
|
||||||
import com.habitrpg.android.habitica.R
|
import com.habitrpg.android.habitica.R
|
||||||
|
import com.habitrpg.android.habitica.databinding.ItemItemBinding
|
||||||
import com.habitrpg.android.habitica.events.commands.FeedCommand
|
import com.habitrpg.android.habitica.events.commands.FeedCommand
|
||||||
import com.habitrpg.android.habitica.extensions.inflate
|
import com.habitrpg.android.habitica.extensions.layoutInflater
|
||||||
import com.habitrpg.android.habitica.models.inventory.*
|
import com.habitrpg.android.habitica.models.inventory.*
|
||||||
import com.habitrpg.android.habitica.models.user.OwnedItem
|
import com.habitrpg.android.habitica.models.user.OwnedItem
|
||||||
import com.habitrpg.android.habitica.models.user.OwnedPet
|
import com.habitrpg.android.habitica.models.user.OwnedPet
|
||||||
import com.habitrpg.android.habitica.ui.fragments.inventory.items.ItemRecyclerFragment
|
import com.habitrpg.android.habitica.ui.fragments.inventory.items.ItemRecyclerFragment
|
||||||
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils
|
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils
|
||||||
import com.habitrpg.android.habitica.ui.helpers.bindView
|
|
||||||
import com.habitrpg.android.habitica.ui.menu.BottomSheetMenu
|
import com.habitrpg.android.habitica.ui.menu.BottomSheetMenu
|
||||||
import com.habitrpg.android.habitica.ui.menu.BottomSheetMenuItem
|
import com.habitrpg.android.habitica.ui.menu.BottomSheetMenuItem
|
||||||
import com.habitrpg.android.habitica.ui.views.dialogs.DetailDialog
|
import com.habitrpg.android.habitica.ui.views.dialogs.DetailDialog
|
||||||
|
|
@ -29,7 +27,7 @@ import org.greenrobot.eventbus.EventBus
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class ItemRecyclerAdapter(data: OrderedRealmCollection<OwnedItem>?, autoUpdate: Boolean) : RealmRecyclerViewAdapter<OwnedItem, ItemRecyclerAdapter.ItemViewHolder>(data, autoUpdate) {
|
class ItemRecyclerAdapter(data: OrderedRealmCollection<OwnedItem>?, autoUpdate: Boolean, val context: Context) : RealmRecyclerViewAdapter<OwnedItem, ItemRecyclerAdapter.ItemViewHolder>(data, autoUpdate) {
|
||||||
|
|
||||||
var isHatching: Boolean = false
|
var isHatching: Boolean = false
|
||||||
var isFeeding: Boolean = false
|
var isFeeding: Boolean = false
|
||||||
|
|
@ -38,7 +36,6 @@ class ItemRecyclerAdapter(data: OrderedRealmCollection<OwnedItem>?, autoUpdate:
|
||||||
var fragment: ItemRecyclerFragment? = null
|
var fragment: ItemRecyclerFragment? = null
|
||||||
private var existingPets: RealmResults<Pet>? = null
|
private var existingPets: RealmResults<Pet>? = null
|
||||||
private var ownedPets: Map<String, OwnedPet>? = null
|
private var ownedPets: Map<String, OwnedPet>? = null
|
||||||
var context: Context? = null
|
|
||||||
var items: Map<String, Item>? = null
|
var items: Map<String, Item>? = null
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
|
|
@ -66,7 +63,7 @@ class ItemRecyclerAdapter(data: OrderedRealmCollection<OwnedItem>?, autoUpdate:
|
||||||
val hatchPetEvents = hatchPetSubject.toFlowable(BackpressureStrategy.DROP)
|
val hatchPetEvents = hatchPetSubject.toFlowable(BackpressureStrategy.DROP)
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {
|
||||||
return ItemViewHolder(parent.inflate(R.layout.item_item))
|
return ItemViewHolder(ItemItemBinding.inflate(context?.layoutInflater, parent, false))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {
|
||||||
|
|
@ -86,14 +83,10 @@ class ItemRecyclerAdapter(data: OrderedRealmCollection<OwnedItem>?, autoUpdate:
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), View.OnClickListener {
|
inner class ItemViewHolder(val binding: ItemItemBinding) : RecyclerView.ViewHolder(binding.root), View.OnClickListener {
|
||||||
var ownedItem: OwnedItem? = null
|
var ownedItem: OwnedItem? = null
|
||||||
var item: Item? = null
|
var item: Item? = null
|
||||||
|
|
||||||
private val titleTextView: TextView by bindView(R.id.titleTextView)
|
|
||||||
private val ownedTextView: TextView by bindView(R.id.ownedTextView)
|
|
||||||
private val imageView: SimpleDraweeView by bindView(R.id.imageView)
|
|
||||||
|
|
||||||
var resources: Resources = itemView.resources
|
var resources: Resources = itemView.resources
|
||||||
|
|
||||||
private val canHatch: Boolean
|
private val canHatch: Boolean
|
||||||
|
|
@ -114,8 +107,8 @@ class ItemRecyclerAdapter(data: OrderedRealmCollection<OwnedItem>?, autoUpdate:
|
||||||
fun bind(ownedItem: OwnedItem, item: Item?) {
|
fun bind(ownedItem: OwnedItem, item: Item?) {
|
||||||
this.ownedItem = ownedItem
|
this.ownedItem = ownedItem
|
||||||
this.item = item
|
this.item = item
|
||||||
titleTextView.text = item?.text
|
binding.titleTextView.text = item?.text
|
||||||
ownedTextView.text = ownedItem.numberOwned.toString()
|
binding.ownedTextView.text = ownedItem.numberOwned.toString()
|
||||||
|
|
||||||
var disabled = false
|
var disabled = false
|
||||||
val imageName: String?
|
val imageName: String?
|
||||||
|
|
@ -138,15 +131,15 @@ class ItemRecyclerAdapter(data: OrderedRealmCollection<OwnedItem>?, autoUpdate:
|
||||||
disabled = !this.canHatch
|
disabled = !this.canHatch
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DataBindingUtils.loadImage(imageView, imageName)
|
DataBindingUtils.loadImage(binding.imageView, imageName)
|
||||||
|
|
||||||
var alpha = 1.0f
|
var alpha = 1.0f
|
||||||
if (disabled) {
|
if (disabled) {
|
||||||
alpha = 0.3f
|
alpha = 0.3f
|
||||||
}
|
}
|
||||||
imageView.alpha = alpha
|
binding.imageView.alpha = alpha
|
||||||
titleTextView.alpha = alpha
|
binding.titleTextView.alpha = alpha
|
||||||
ownedTextView.alpha = alpha
|
binding.ownedTextView.alpha = alpha
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onClick(v: View) {
|
override fun onClick(v: View) {
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,10 @@ abstract class BaseMainFragment : BaseFragment() {
|
||||||
lateinit var soundManager: SoundManager
|
lateinit var soundManager: SoundManager
|
||||||
|
|
||||||
open val activity get() = getActivity() as? MainActivity
|
open val activity get() = getActivity() as? MainActivity
|
||||||
val tabLayout get() = activity?.detailTabs
|
val tabLayout get() = activity?.binding?.detailTabs
|
||||||
val collapsingToolbar get() = activity?.toolbar
|
val collapsingToolbar get() = activity?.binding?.toolbar
|
||||||
val toolbarAccessoryContainer get() = activity?.toolbarAccessoryContainer
|
val toolbarAccessoryContainer get() = activity?.binding?.toolbarAccessoryContainer
|
||||||
val bottomNavigation get() = activity?.bottomNavigation
|
val bottomNavigation get() = activity?.binding?.bottomNavigation
|
||||||
var usesTabLayout: Boolean = false
|
var usesTabLayout: Boolean = false
|
||||||
var hidesToolbar: Boolean = false
|
var hidesToolbar: Boolean = false
|
||||||
var usesBottomNavigation = false
|
var usesBottomNavigation = false
|
||||||
|
|
@ -85,11 +85,11 @@ abstract class BaseMainFragment : BaseFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun hideToolbar() {
|
private fun hideToolbar() {
|
||||||
activity?.avatarWithBars?.visibility = View.GONE
|
activity?.binding?.avatarWithBars?.root?.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showToolbar() {
|
private fun showToolbar() {
|
||||||
activity?.avatarWithBars?.visibility = View.VISIBLE
|
activity?.binding?.avatarWithBars?.root?.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun disableToolbarScrolling() {
|
private fun disableToolbarScrolling() {
|
||||||
|
|
|
||||||
|
|
@ -80,11 +80,12 @@ class ItemRecyclerFragment : BaseFragment() {
|
||||||
|
|
||||||
adapter = recyclerView?.adapter as? ItemRecyclerAdapter
|
adapter = recyclerView?.adapter as? ItemRecyclerAdapter
|
||||||
if (adapter == null) {
|
if (adapter == null) {
|
||||||
adapter = ItemRecyclerAdapter(null, true)
|
context?.let {
|
||||||
adapter?.context = this.activity
|
adapter = ItemRecyclerAdapter(null, true, context)
|
||||||
adapter?.isHatching = this.isHatching
|
adapter?.isHatching = this.isHatching
|
||||||
adapter?.isFeeding = this.isFeeding
|
adapter?.isFeeding = this.isFeeding
|
||||||
adapter?.fragment = this
|
adapter?.fragment = this
|
||||||
|
}
|
||||||
if (this.hatchingItem != null) {
|
if (this.hatchingItem != null) {
|
||||||
adapter?.hatchingItem = this.hatchingItem
|
adapter?.hatchingItem = this.hatchingItem
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ buildscript {
|
||||||
maven { url "https://plugins.gradle.org/m2/" }
|
maven { url "https://plugins.gradle.org/m2/" }
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.5.1'
|
classpath 'com.android.tools.build:gradle:3.6.0-beta02'
|
||||||
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
|
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
|
||||||
classpath 'com.google.gms:google-services:4.3.2'
|
classpath 'com.google.gms:google-services:4.3.2'
|
||||||
classpath "io.realm:realm-gradle-plugin:5.15.0"
|
classpath "io.realm:realm-gradle-plugin:5.15.0"
|
||||||
|
|
|
||||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
|
|
@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue