mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-14 02:01:56 +00:00
start adding world boss progress to tavern
This commit is contained in:
parent
f376cdb2ce
commit
7022dc1c69
19 changed files with 325 additions and 169 deletions
6
Habitica/res/drawable/layout_rounded_bg_white_15.xml
Normal file
6
Habitica/res/drawable/layout_rounded_bg_white_15.xml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="@color/white_15_alpha" />
|
||||
<corners android:radius="@dimen/rounded_button_radius"/>
|
||||
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
|
||||
</shape>
|
||||
|
|
@ -17,7 +17,8 @@
|
|||
<com.habitrpg.android.habitica.ui.views.CollapsibleSectionView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:title="@string/check_into_inn">
|
||||
app:title="@string/check_into_inn"
|
||||
app:identifier="tavernInn">
|
||||
<Button
|
||||
android:id="@+id/innButton"
|
||||
android:layout_width="match_parent"
|
||||
|
|
@ -32,9 +33,22 @@
|
|||
android:layout_marginTop="@dimen/spacing_large"/>
|
||||
</com.habitrpg.android.habitica.ui.views.CollapsibleSectionView>
|
||||
<com.habitrpg.android.habitica.ui.views.CollapsibleSectionView
|
||||
android:id="@+id/worldBossSection"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:title="@string/community_guidelines">
|
||||
app:title="@string/world_boss"
|
||||
app:identifier="tavernWorldBoss"
|
||||
android:visibility="gone">
|
||||
<com.habitrpg.android.habitica.ui.views.social.QuestProgressView
|
||||
android:id="@+id/questProgressView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</com.habitrpg.android.habitica.ui.views.CollapsibleSectionView>
|
||||
<com.habitrpg.android.habitica.ui.views.CollapsibleSectionView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:title="@string/community_guidelines"
|
||||
app:identifier="tavernGuidelines">
|
||||
<Button
|
||||
android:id="@+id/guidelinesButton"
|
||||
android:layout_width="match_parent"
|
||||
|
|
@ -51,7 +65,8 @@
|
|||
<com.habitrpg.android.habitica.ui.views.CollapsibleSectionView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:title="@string/helpful_links">
|
||||
app:title="@string/helpful_links"
|
||||
app:identifier="tavernLinks">
|
||||
<Button
|
||||
android:id="@+id/faqButton"
|
||||
android:layout_width="match_parent"
|
||||
|
|
@ -72,13 +87,15 @@
|
|||
android:id="@+id/moderatorsView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:title="@string/staff_moderators">
|
||||
app:title="@string/staff_moderators"
|
||||
app:identifier="tavernModerators">
|
||||
</com.habitrpg.android.habitica.ui.views.CollapsibleSectionView>
|
||||
<com.habitrpg.android.habitica.ui.views.CollapsibleSectionView
|
||||
android:id="@+id/playerTiersView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:title="@string/player_tiers">
|
||||
app:title="@string/player_tiers"
|
||||
app:identifier="tavernTiers">
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
|||
|
|
@ -5,22 +5,91 @@
|
|||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/spacing_large"
|
||||
android:paddingBottom="@dimen/spacing_large"
|
||||
android:paddingLeft="@dimen/spacing_large"
|
||||
android:paddingRight="@dimen/spacing_large">
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/boss_art"/>
|
||||
<ImageView
|
||||
android:id="@+id/caretView"
|
||||
android:layout_width="18dp"
|
||||
android:layout_height="18dp" />
|
||||
</LinearLayout>
|
||||
<ImageView
|
||||
android:id="@+id/questImageView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView
|
||||
android:id="@+id/boss_name_view"
|
||||
android:id="@+id/bossNameView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="Quest Boss"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginBottom="@dimen/spacing_small"/>
|
||||
android:layout_marginBottom="@dimen/spacing_small"
|
||||
android:paddingLeft="@dimen/spacing_large"
|
||||
android:paddingRight="@dimen/spacing_large"/>
|
||||
<com.habitrpg.android.habitica.ui.views.ValueBar
|
||||
android:id="@+id/boss_health_view"
|
||||
android:id="@+id/bossHealthView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:barForegroundColor="@color/red_100"
|
||||
app:lightBackground="true" />
|
||||
<LinearLayout
|
||||
android:id="@+id/collection_container"
|
||||
app:lightBackground="true"
|
||||
android:paddingLeft="@dimen/spacing_large"
|
||||
android:paddingRight="@dimen/spacing_large" />
|
||||
<TextView
|
||||
android:id="@+id/rageMeterView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"/>
|
||||
tools:text="Boss Rage"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginBottom="@dimen/spacing_small"
|
||||
android:layout_marginTop="@dimen/spacing_large"
|
||||
android:paddingLeft="@dimen/spacing_large"
|
||||
android:paddingRight="@dimen/spacing_large"/>
|
||||
<com.habitrpg.android.habitica.ui.views.ValueBar
|
||||
android:id="@+id/bossRageView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:barForegroundColor="@color/orange_100"
|
||||
app:lightBackground="true"
|
||||
android:paddingLeft="@dimen/spacing_large"
|
||||
android:paddingRight="@dimen/spacing_large" />
|
||||
<LinearLayout
|
||||
android:id="@+id/collectionContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="@dimen/spacing_large"
|
||||
android:paddingRight="@dimen/spacing_large"/>
|
||||
<TextView
|
||||
android:id="@+id/rageStrikeDescriptionView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="Rage Strikes: 1/3"
|
||||
android:background="@drawable/layout_rounded_bg_white_15"
|
||||
android:gravity="center"
|
||||
android:paddingTop="@dimen/spacing_small"
|
||||
android:paddingBottom="@dimen/spacing_small"
|
||||
android:textColor="@color/orange_500"
|
||||
android:paddingLeft="@dimen/spacing_large"
|
||||
android:paddingRight="@dimen/spacing_large"/>
|
||||
<com.habitrpg.android.habitica.ui.views.CollapsibleSectionView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:title="@string/world_boss_description"
|
||||
app:identifier="questDescription"
|
||||
android:paddingLeft="@dimen/spacing_large"
|
||||
android:paddingRight="@dimen/spacing_large">
|
||||
<TextView
|
||||
android:id="@+id/questDescription"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</com.habitrpg.android.habitica.ui.views.CollapsibleSectionView>
|
||||
</LinearLayout>
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
<attr name="statsColor" format="color" />
|
||||
<attr name="statsTitle" format="string" />
|
||||
<attr name="title" format="string" />
|
||||
<attr name="identifier" format="string" />
|
||||
<attr name="hasLightBackground" format="boolean" />
|
||||
<declare-styleable name="AvatarView">
|
||||
<attr name="showBackground" format="boolean" />
|
||||
|
|
@ -68,5 +69,6 @@
|
|||
</declare-styleable>
|
||||
<declare-styleable name="CollapsibleSectionView">
|
||||
<attr name="title" />
|
||||
<attr name="identifier" />
|
||||
</declare-styleable>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -736,4 +736,8 @@
|
|||
<string name="tiers_descriptions">The colored usernames you see in chat represent a person’s contributor tier. The higher the tier, the more the person has contributed to habitica through art, code, the community, or more!</string>
|
||||
<string name="navigation_drawer_open">Open navigation drawer</string>
|
||||
<string name="navigation_drawer_close">Close navigation drawer</string>
|
||||
<string name="world_boss">World Boss</string>
|
||||
<string name="world_boss_art">Boss Art</string>
|
||||
<string name="boss_art">Boss Art</string>
|
||||
<string name="world_boss_description">World Boss Description</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import java.util.Map;
|
|||
|
||||
import io.realm.RealmResults;
|
||||
import rx.Observable;
|
||||
import rx.functions.Func1;
|
||||
|
||||
|
||||
public class SocialRepositoryImpl extends BaseRepositoryImpl<SocialLocalRepository> implements SocialRepository {
|
||||
|
|
@ -103,7 +104,7 @@ public class SocialRepositoryImpl extends BaseRepositoryImpl<SocialLocalReposito
|
|||
@Override
|
||||
public Observable<Group> retrieveGroup(String id) {
|
||||
Observable<Group> observable = apiClient.getGroup(id);
|
||||
if (!"party".equals(id)) {
|
||||
if (!"party".equals(id) && localRepository.doesGroupExist(id)) {
|
||||
observable = observable.withLatestFrom(localRepository.getGroup(id)
|
||||
.first(), (newGroup, oldGroup) -> {
|
||||
newGroup.isMember = oldGroup.isMember;
|
||||
|
|
|
|||
|
|
@ -35,4 +35,6 @@ public interface SocialLocalRepository extends BaseLocalRepository {
|
|||
void setQuestActivity(Group party, boolean active);
|
||||
|
||||
void saveChatMessages(String groupId, List<ChatMessage> chatMessages);
|
||||
|
||||
boolean doesGroupExist(String id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -191,4 +191,10 @@ public class RealmSocialLocalRepository extends RealmBaseLocalRepository impleme
|
|||
.filter(messages -> messages.isLoaded() && messages.isValid() && !messages.isEmpty())
|
||||
.map(messages -> messages.first());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesGroupExist(String id) {
|
||||
Group party = realm.where(Group.class).equalTo("id", id).findFirst();
|
||||
return party != null && party.isValid();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +0,0 @@
|
|||
package com.habitrpg.android.habitica.models.inventory;
|
||||
|
||||
|
||||
import io.realm.RealmObject;
|
||||
import io.realm.annotations.PrimaryKey;
|
||||
|
||||
public class QuestBoss extends RealmObject {
|
||||
|
||||
@PrimaryKey
|
||||
private String key;
|
||||
public String name;
|
||||
public int hp;
|
||||
public float str;
|
||||
|
||||
public QuestBossRage rage;
|
||||
|
||||
public boolean hasRage() {
|
||||
return rage != null && rage.value != 0;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
if (rage != null) {
|
||||
rage.key = key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package com.habitrpg.android.habitica.models.inventory
|
||||
|
||||
|
||||
import io.realm.RealmObject
|
||||
import io.realm.annotations.PrimaryKey
|
||||
|
||||
open class QuestBoss : RealmObject() {
|
||||
|
||||
@PrimaryKey
|
||||
var key: String? = null
|
||||
set(value) {
|
||||
field = value
|
||||
rage?.key = key
|
||||
}
|
||||
var name: String? = null
|
||||
var hp: Int = 0
|
||||
var str: Float = 0.toFloat()
|
||||
|
||||
var rage: QuestBossRage? = null
|
||||
|
||||
fun hasRage(): Boolean {
|
||||
return rage?.value != 0.0
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
package com.habitrpg.android.habitica.models.inventory;
|
||||
|
||||
import io.realm.RealmObject;
|
||||
import io.realm.annotations.PrimaryKey;
|
||||
|
||||
public class QuestBossRage extends RealmObject {
|
||||
|
||||
@PrimaryKey
|
||||
public String key;
|
||||
|
||||
public String title;
|
||||
|
||||
public String description;
|
||||
|
||||
public double value;
|
||||
|
||||
public String tavern;
|
||||
|
||||
public String stables;
|
||||
|
||||
public String market;
|
||||
|
||||
public QuestBossRage() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.habitrpg.android.habitica.models.inventory
|
||||
|
||||
import io.realm.RealmObject
|
||||
import io.realm.annotations.PrimaryKey
|
||||
|
||||
open class QuestBossRage : RealmObject() {
|
||||
|
||||
@PrimaryKey
|
||||
var key: String? = null
|
||||
|
||||
var title: String? = null
|
||||
|
||||
var description: String? = null
|
||||
|
||||
var value: Double = 0.toDouble()
|
||||
var tavern: String? = null
|
||||
var stables: String? = null
|
||||
var market: String? = null
|
||||
}
|
||||
|
|
@ -16,7 +16,9 @@ public class QuestContent extends RealmObject implements Item {
|
|||
private int lvl;
|
||||
private boolean canBuy;
|
||||
private String category;
|
||||
@Nullable
|
||||
private QuestBoss boss;
|
||||
@Nullable
|
||||
private QuestDrops drop;
|
||||
|
||||
RealmList<QuestCollect> collect;
|
||||
|
|
|
|||
|
|
@ -4,12 +4,16 @@ import com.google.gson.annotations.SerializedName;
|
|||
import com.habitrpg.android.habitica.models.inventory.Quest;
|
||||
import com.habitrpg.android.habitica.models.user.User;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import io.realm.RealmList;
|
||||
import io.realm.RealmObject;
|
||||
import io.realm.annotations.PrimaryKey;
|
||||
|
||||
public class Group extends RealmObject {
|
||||
|
||||
public static final String TAVERN_ID = "00000000-0000-4000-A000-000000000000";
|
||||
|
||||
@SerializedName("_id")
|
||||
@PrimaryKey
|
||||
public String id;
|
||||
|
|
|
|||
|
|
@ -5,8 +5,10 @@ import android.graphics.Bitmap
|
|||
import android.graphics.Shader
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.util.Log
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
|
|
@ -32,9 +34,12 @@ import com.facebook.drawee.backends.pipeline.Fresco
|
|||
import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber
|
||||
import com.facebook.imagepipeline.image.CloseableImage
|
||||
import com.facebook.imagepipeline.request.ImageRequestBuilder
|
||||
import com.habitrpg.android.habitica.data.InventoryRepository
|
||||
import com.habitrpg.android.habitica.data.SocialRepository
|
||||
import com.habitrpg.android.habitica.events.commands.OpenMenuItemCommand
|
||||
import com.habitrpg.android.habitica.helpers.RemoteConfigManager
|
||||
import com.habitrpg.android.habitica.models.members.PlayerTier
|
||||
import com.habitrpg.android.habitica.models.social.Group
|
||||
import com.habitrpg.android.habitica.ui.fragments.NavigationDrawerFragment
|
||||
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils
|
||||
import com.habitrpg.android.habitica.ui.views.social.UsernameLabel
|
||||
|
|
@ -49,6 +54,10 @@ class TavernDetailFragment : BaseFragment() {
|
|||
|
||||
@Inject
|
||||
lateinit var userRepository: UserRepository
|
||||
@Inject
|
||||
lateinit var socialRepository: SocialRepository
|
||||
@Inject
|
||||
lateinit var inventoryRepository: InventoryRepository
|
||||
@field:[Inject Named(AppModule.NAMED_USER_ID)]
|
||||
lateinit var userId: String
|
||||
@Inject
|
||||
|
|
@ -99,7 +108,13 @@ class TavernDetailFragment : BaseFragment() {
|
|||
drawable.tileModeX = Shader.TileMode.REPEAT
|
||||
Observable.just(drawable)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(Action1 { backgroundView.background = it }, RxErrorHandler.handleEmptyError())
|
||||
.subscribe(Action1 {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
backgroundView.background = it
|
||||
} else {
|
||||
backgroundView.setBackgroundDrawable(it)
|
||||
}
|
||||
}, RxErrorHandler.handleEmptyError())
|
||||
dataSource.close()
|
||||
}
|
||||
}
|
||||
|
|
@ -107,6 +122,23 @@ class TavernDetailFragment : BaseFragment() {
|
|||
|
||||
addPlayerTiers()
|
||||
bindButtons()
|
||||
|
||||
compositeSubscription.add(socialRepository.getGroup(Group.TAVERN_ID)
|
||||
.doOnNext({ worldBossSection.visibility = if (it.quest.active) View.VISIBLE else View.GONE })
|
||||
.filter { it.quest.active }
|
||||
.doOnNext({ questProgressView.progress = it.quest.progress})
|
||||
.flatMap { inventoryRepository.getQuestContent(it.quest.key) }
|
||||
.subscribe(Action1 {
|
||||
questProgressView.quest = it
|
||||
}, RxErrorHandler.handleEmptyError()))
|
||||
socialRepository.retrieveGroup(Group.TAVERN_ID).subscribe(Action1 { }, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
userRepository.close()
|
||||
socialRepository.close()
|
||||
inventoryRepository.close()
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
private fun bindButtons() {
|
||||
|
|
|
|||
|
|
@ -43,14 +43,6 @@ class TavernFragment : BaseMainFragment() {
|
|||
super.onViewCreated(view, savedInstanceState)
|
||||
setViewPagerAdapter()
|
||||
viewPager.currentItem = 0
|
||||
compositeSubscription.add(socialRepository.getGroup("habitrpg")?.subscribe(Action1 { group ->
|
||||
this@TavernFragment.tavern = group
|
||||
if (group.quest != null && group.quest.key != null && this@TavernFragment.isAdded) {
|
||||
this@TavernFragment.viewPager.adapter?.notifyDataSetChanged()
|
||||
this@TavernFragment.tabLayout?.visibility = View.VISIBLE
|
||||
this@TavernFragment.tabLayout?.setupWithViewPager(this@TavernFragment.viewPager)
|
||||
}
|
||||
}, RxErrorHandler.handleEmptyError()))
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
|
|
@ -81,7 +73,7 @@ class TavernFragment : BaseMainFragment() {
|
|||
tavernDetailFragment
|
||||
}
|
||||
1 -> {
|
||||
chatListFragment.configure("habitrpg", user, true)
|
||||
chatListFragment.configure(Group.TAVERN_ID, user, true)
|
||||
chatListFragment
|
||||
}
|
||||
else -> Fragment()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.habitrpg.android.habitica.ui.views
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
|
|
@ -10,18 +11,12 @@ import android.widget.TextView
|
|||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.extensions.bindView
|
||||
|
||||
|
||||
/**
|
||||
* Created by phillip on 29.01.18.
|
||||
*/
|
||||
|
||||
|
||||
class CollapsibleSectionView(context: Context?, attrs: AttributeSet?) : LinearLayout(context, attrs) {
|
||||
|
||||
private val titleView: LinearLayout by bindView(R.id.title_view)
|
||||
private val titleLabel: TextView by bindView(R.id.titleTextView)
|
||||
private val caretView: ImageView by bindView(R.id.caretView)
|
||||
|
||||
private var preferences: SharedPreferences? = null
|
||||
private val padding = context?.resources?.getDimension(R.dimen.spacing_large)?.toInt() ?: 0
|
||||
|
||||
var title: CharSequence
|
||||
|
|
@ -44,7 +39,10 @@ class CollapsibleSectionView(context: Context?, attrs: AttributeSet?) : LinearLa
|
|||
|
||||
var caretColor: Int = 0
|
||||
|
||||
var identifier: String? = null
|
||||
|
||||
private fun showViews() {
|
||||
updatePreferences()
|
||||
setCaretImage()
|
||||
setPadding(0, 0, 0, padding)
|
||||
(2 until childCount)
|
||||
|
|
@ -53,6 +51,7 @@ class CollapsibleSectionView(context: Context?, attrs: AttributeSet?) : LinearLa
|
|||
}
|
||||
|
||||
private fun hideViews() {
|
||||
updatePreferences()
|
||||
setCaretImage()
|
||||
setPadding(0, 0, 0, 0)
|
||||
(2 until childCount)
|
||||
|
|
@ -62,6 +61,15 @@ class CollapsibleSectionView(context: Context?, attrs: AttributeSet?) : LinearLa
|
|||
}
|
||||
}
|
||||
|
||||
private fun updatePreferences() {
|
||||
if (identifier == null) {
|
||||
return
|
||||
}
|
||||
val editPreferences = preferences?.edit()
|
||||
editPreferences?.putBoolean(identifier, isCollapsed)
|
||||
editPreferences?.apply()
|
||||
}
|
||||
|
||||
private fun setCaretImage() {
|
||||
caretView.setImageBitmap(HabiticaIconsHelper.imageOfCaret(caretColor, isCollapsed))
|
||||
}
|
||||
|
|
@ -77,8 +85,8 @@ class CollapsibleSectionView(context: Context?, attrs: AttributeSet?) : LinearLa
|
|||
}
|
||||
|
||||
override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
|
||||
super.onLayout(changed, l, t, r, b)
|
||||
setChildMargins()
|
||||
super.onLayout(changed, l, t, r, b)
|
||||
}
|
||||
|
||||
init {
|
||||
|
|
@ -96,7 +104,16 @@ class CollapsibleSectionView(context: Context?, attrs: AttributeSet?) : LinearLa
|
|||
R.styleable.CollapsibleSectionView,
|
||||
0, 0)
|
||||
title = attributes?.getString(R.styleable.CollapsibleSectionView_title) ?: ""
|
||||
identifier = attributes?.getString(R.styleable.CollapsibleSectionView_identifier)
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
setCaretImage()
|
||||
setChildMargins()
|
||||
preferences = context.getSharedPreferences("collapsible_sections", 0)
|
||||
if (identifier != null && preferences?.getBoolean(identifier, false) == true) {
|
||||
isCollapsed = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,85 +0,0 @@
|
|||
package com.habitrpg.android.habitica.ui.views.social;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.models.inventory.QuestCollect;
|
||||
import com.habitrpg.android.habitica.models.inventory.QuestContent;
|
||||
import com.habitrpg.android.habitica.models.inventory.QuestProgress;
|
||||
import com.habitrpg.android.habitica.models.inventory.QuestProgressCollect;
|
||||
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils;
|
||||
import com.habitrpg.android.habitica.ui.views.ValueBar;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class QuestProgressView extends LinearLayout {
|
||||
|
||||
@BindView(R.id.boss_name_view)
|
||||
TextView bossNameView;
|
||||
@BindView(R.id.boss_health_view)
|
||||
ValueBar bossHealthView;
|
||||
@BindView(R.id.collection_container)
|
||||
ViewGroup collectionContainer;
|
||||
|
||||
public QuestProgressView(@NonNull Context context) {
|
||||
super(context);
|
||||
setupView(context);
|
||||
}
|
||||
|
||||
public QuestProgressView(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setupView(context);
|
||||
}
|
||||
|
||||
private void setupView(Context context) {
|
||||
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
inflater.inflate(R.layout.quest_progress, this);
|
||||
|
||||
ButterKnife.bind(this, this);
|
||||
}
|
||||
|
||||
public void setData(QuestContent quest, QuestProgress progress) {
|
||||
collectionContainer.removeAllViews();
|
||||
if (quest.isBossQuest()) {
|
||||
bossNameView.setText(quest.getBoss().name);
|
||||
if (progress != null) {
|
||||
bossHealthView.set(progress.hp, quest.getBoss().hp);
|
||||
}
|
||||
bossNameView.setVisibility(View.VISIBLE);
|
||||
bossHealthView.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
bossNameView.setVisibility(View.GONE);
|
||||
bossHealthView.setVisibility(View.GONE);
|
||||
|
||||
if (progress != null) {
|
||||
LayoutInflater inflater = LayoutInflater.from(getContext());
|
||||
for (QuestProgressCollect collect : progress.collect) {
|
||||
QuestCollect contentCollect = quest.getCollectWithKey(collect.key);
|
||||
if (contentCollect == null) {
|
||||
continue;
|
||||
}
|
||||
View view = inflater.inflate(R.layout.quest_collect, collectionContainer, false);
|
||||
SimpleDraweeView iconView = (SimpleDraweeView) view.findViewById(R.id.icon_view);
|
||||
TextView nameView = (TextView) view.findViewById(R.id.name_view);
|
||||
ValueBar valueView = (ValueBar) view.findViewById(R.id.value_view);
|
||||
DataBindingUtils.INSTANCE.loadImage(iconView, "quest_" + quest.getKey() + "_" + collect.key);
|
||||
nameView.setText(contentCollect.text);
|
||||
valueView.set(collect.count, contentCollect.count);
|
||||
|
||||
collectionContainer.addView(view);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
package com.habitrpg.android.habitica.ui.views.social
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import com.facebook.drawee.view.SimpleDraweeView
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.extensions.bindView
|
||||
import com.habitrpg.android.habitica.models.inventory.QuestContent
|
||||
import com.habitrpg.android.habitica.models.inventory.QuestProgress
|
||||
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils
|
||||
import com.habitrpg.android.habitica.ui.views.ValueBar
|
||||
|
||||
class QuestProgressView : LinearLayout {
|
||||
|
||||
private val bossNameView: TextView by bindView(R.id.bossNameView)
|
||||
private val bossHealthView: ValueBar by bindView(R.id.bossHealthView)
|
||||
private val rageMeterView: TextView by bindView(R.id.rageMeterView)
|
||||
private val bossRageView: ValueBar by bindView(R.id.bossRageView)
|
||||
private val collectionContainer: ViewGroup by bindView(R.id.collectionContainer)
|
||||
|
||||
var quest: QuestContent? = null
|
||||
set(value) {
|
||||
field = value
|
||||
configure()
|
||||
}
|
||||
var progress: QuestProgress? = null
|
||||
set(value) {
|
||||
field = value
|
||||
configure()
|
||||
}
|
||||
|
||||
constructor(context: Context) : super(context) {
|
||||
setupView(context)
|
||||
}
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
|
||||
setupView(context)
|
||||
}
|
||||
|
||||
private fun setupView(context: Context) {
|
||||
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
inflater.inflate(R.layout.quest_progress, this)
|
||||
}
|
||||
|
||||
fun setData(quest: QuestContent, progress: QuestProgress?) {
|
||||
}
|
||||
|
||||
private fun configure() {
|
||||
val quest = this.quest
|
||||
val progress = this.progress
|
||||
if (quest == null || progress == null) {
|
||||
return
|
||||
}
|
||||
collectionContainer.removeAllViews()
|
||||
if (quest.isBossQuest) {
|
||||
bossNameView.text = quest.boss.name
|
||||
bossNameView.visibility = View.VISIBLE
|
||||
bossHealthView.visibility = View.VISIBLE
|
||||
bossHealthView.set(progress.hp, quest.boss?.hp?.toDouble() ?: 0.0)
|
||||
|
||||
if (quest.boss.hasRage()) {
|
||||
rageMeterView.visibility = View.VISIBLE
|
||||
bossRageView.visibility = View.VISIBLE
|
||||
rageMeterView.text = quest.boss.rage?.title
|
||||
bossRageView.set(progress.rage, quest.boss?.rage?.value ?: 0.0)
|
||||
} else {
|
||||
rageMeterView.visibility = View.GONE
|
||||
bossRageView.visibility = View.GONE
|
||||
}
|
||||
} else {
|
||||
bossNameView.visibility = View.GONE
|
||||
bossHealthView.visibility = View.GONE
|
||||
rageMeterView.visibility = View.GONE
|
||||
bossRageView.visibility = View.GONE
|
||||
|
||||
val inflater = LayoutInflater.from(context)
|
||||
for (collect in progress.collect) {
|
||||
val contentCollect = quest.getCollectWithKey(collect.key) ?: continue
|
||||
val view = inflater.inflate(R.layout.quest_collect, collectionContainer, false)
|
||||
val iconView = view.findViewById<View>(R.id.icon_view) as SimpleDraweeView
|
||||
val nameView = view.findViewById<View>(R.id.name_view) as TextView
|
||||
val valueView = view.findViewById<View>(R.id.value_view) as ValueBar
|
||||
DataBindingUtils.loadImage(iconView, "quest_" + quest.key + "_" + collect.key)
|
||||
nameView.text = contentCollect.text
|
||||
valueView.set(collect.count.toDouble(), contentCollect.count.toDouble())
|
||||
|
||||
collectionContainer.addView(view)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue