Skip to content

Commit

Permalink
Implement showing pursuit/quest rewards (Closes #18)
Browse files Browse the repository at this point in the history
  • Loading branch information
russjr08 committed Dec 21, 2020
1 parent 203c8a4 commit 96b3299
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ class Destiny(ctx: Context): Interceptor {
* @return If the refresh token has been determined as "should be" valid.
*/
fun isRefreshValid(): Boolean {
// val refreshExpireDate = Date(prefs.getLong("refreshTokenExpires", 0))

val refreshExpireDate = LocalDateTime.parse(prefs.getString("refreshTokenExpires", Instant.EPOCH.toString()))

// return refreshExpireDate > LocalDateTime.now() TODO: Revisit refresh logic here, and in #refreshAccessToken()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.reactivex.schedulers.Schedulers
import org.json.JSONArray
import org.json.JSONObject
import xyz.omnicron.apps.android.dot.api.Destiny
import xyz.omnicron.apps.android.dot.database.DestinyDatabase
import java.text.SimpleDateFormat
import java.util.*

Expand Down Expand Up @@ -71,6 +72,7 @@ class DestinyCharacter(var membershipId: String,

this.pursuits = stripPursuitsWithZeroObjectives(this.pursuits)
this.pursuits = stripCompletedPursuits(this.pursuits)
this.pursuits = addRewardsToPursuits(this.pursuits, destinyApi.database)
subscriber.onComplete()
}).start()
}
Expand Down Expand Up @@ -143,6 +145,24 @@ class DestinyCharacter(var membershipId: String,

return cleanedPursuits
}

private fun addRewardsToPursuits(pursuits: ArrayList<DestinyPursuit>, database: DestinyDatabase): ArrayList<DestinyPursuit> {
val updatedPursuits = arrayListOf<DestinyPursuit>()

for(pursuit in pursuits) {
if(pursuit.databaseItem.rewards?.entries?.isNotEmpty() == true) {
for (reward in pursuit.databaseItem.rewards!!.entries) {
val rewardItemDefinition = database.getDestinyDatabaseItemFromHash(reward.itemHash.toInt(), "DestinyInventoryItemDefinition")
rewardItemDefinition?.let { item ->
pursuit.rewards.add(item)
}
}
}
updatedPursuits.add(pursuit)
}

return updatedPursuits
}
}

enum class DestinyRace(val id: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class DestinyPursuit(databaseItem: DestinyDatabaseItem,
) : DestinyItem(databaseItem, instanceId, quantity, bucketHash) {

val objectives = arrayListOf<DestinyObjectiveData>()
val rewards = arrayListOf<DestinyDatabaseItem>()

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package xyz.omnicron.apps.android.dot.database
import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import com.beust.klaxon.Json
import com.beust.klaxon.Klaxon
import java.util.logging.Level
import java.util.logging.Logger
Expand Down Expand Up @@ -91,11 +92,21 @@ class DestinyDatabaseCache {
}

class DestinyDatabaseItem(
var displayProperties: DisplayProperties,
var hash: Long,
var redacted: Boolean,
var itemTypeDisplayName: String,
var itemTypeAndTierDisplayName: String
var displayProperties: DisplayProperties?,
var hash: Long?,
var redacted: Boolean?,
var itemTypeDisplayName: String?,
var itemTypeAndTierDisplayName: String?,
@Json("value") var rewards: DestinyDatabaseRewards? = null
)

class DestinyDatabaseRewards(
@Json(name = "itemValue") var entries: Array<DestinyDatabaseRewardEntry> = emptyArray()
)

class DestinyDatabaseRewardEntry(
var itemHash: Long = 0,
var quantity: Int = 0
)

class DestinyDatabaseObjective(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package xyz.omnicron.apps.android.dot.ui.objectives

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.squareup.picasso.Picasso
import xyz.omnicron.apps.android.dot.R
import xyz.omnicron.apps.android.dot.database.DestinyDatabaseItem
import xyz.omnicron.apps.android.dot.databinding.RewardsListItemBinding

class RewardsAdapter: RecyclerView.Adapter<RewardsAdapter.RewardsHolder>() {

private var rewards = arrayListOf<DestinyDatabaseItem>()

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RewardsHolder {
val inflatedView = LayoutInflater.from(parent.context).inflate(R.layout.rewards_list_item, parent, false)
return RewardsHolder(inflatedView)
}

override fun onBindViewHolder(holder: RewardsHolder, position: Int) {
holder.bindReward(rewards[position], holder.itemView.context)
}

override fun getItemCount(): Int = rewards.size

fun setRewards(rewards: ArrayList<DestinyDatabaseItem>) {
this.rewards = rewards
}

class RewardsHolder(private val baseView: View): RecyclerView.ViewHolder(baseView) {

private val binding = RewardsListItemBinding.bind(baseView)

fun bindReward(reward: DestinyDatabaseItem, ctx: Context) {
binding.rewardDescription.text = reward.displayProperties?.name
Picasso.with(ctx).load("https://bungie.net${reward.displayProperties!!.icon}").into(binding.rewardImage)
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import xyz.omnicron.apps.android.dot.R
import xyz.omnicron.apps.android.dot.api.models.DestinyPursuit
import xyz.omnicron.apps.android.dot.inflate
import xyz.omnicron.apps.android.dot.ui.objectives.ObjectivesAdapter
import xyz.omnicron.apps.android.dot.ui.objectives.RewardsAdapter
import java.util.*

class PursuitsAdapter: RecyclerView.Adapter<PursuitsAdapter.PursuitHolder>() {
Expand Down Expand Up @@ -94,11 +95,12 @@ class PursuitsAdapter: RecyclerView.Adapter<PursuitsAdapter.PursuitHolder>() {
val pursuitTypeText: TextView = this.itemView.findViewById(R.id.pursuitTypeText)
val pursuitIcon: ImageView = this.itemView.findViewById(R.id.objective_icon)
val objectivesRecyclerView: RecyclerView = this.itemView.findViewById(R.id.objectivesHolder)
val rewardsRecyclerView: RecyclerView = this.itemView.findViewById(R.id.rewardsHolder)
val pursuitHeader: LinearLayout = this.itemView.findViewById(R.id.pursuitHeader)
val expirationText: TextView = this.itemView.findViewById(R.id.expiration_label)

pursuitTitleText.text = pursuit.databaseItem.displayProperties.name
pursuitDescriptionText.text = pursuit.databaseItem.displayProperties.description
pursuitTitleText.text = pursuit.databaseItem.displayProperties!!.name
pursuitDescriptionText.text = pursuit.databaseItem.displayProperties!!.description
pursuitTypeText.text = pursuit.databaseItem.itemTypeAndTierDisplayName

// Expiration display handling
Expand All @@ -109,7 +111,7 @@ class PursuitsAdapter: RecyclerView.Adapter<PursuitsAdapter.PursuitHolder>() {
expirationText.visibility = View.GONE
}

val typeAndTierBreakdown = pursuit.databaseItem.itemTypeAndTierDisplayName.split(" ")
val typeAndTierBreakdown = pursuit.databaseItem.itemTypeAndTierDisplayName!!.split(" ")
when(typeAndTierBreakdown[0]) {
"Common" -> {
pursuitHeader.setBackgroundColor(pursuitHeader.resources.getColor(R.color.pursuit_common_background))
Expand All @@ -133,17 +135,27 @@ class PursuitsAdapter: RecyclerView.Adapter<PursuitsAdapter.PursuitHolder>() {
}
}

Picasso.with(ctx).load("https://bungie.net${pursuit.databaseItem.displayProperties.icon}").into(pursuitIcon)
Picasso.with(ctx).load("https://bungie.net${pursuit.databaseItem.displayProperties!!.icon}").into(pursuitIcon)

val objectivesLayoutManager = LinearLayoutManager(ctx, RecyclerView.VERTICAL, false)
val rewardsLayoutManager = LinearLayoutManager(ctx, RecyclerView.VERTICAL, false)

val layoutManager = LinearLayoutManager(ctx, RecyclerView.VERTICAL, false)
objectivesRecyclerView.apply {
this.layoutManager = layoutManager
this.layoutManager = objectivesLayoutManager
val adapter = ObjectivesAdapter()
this.adapter = adapter
adapter.setObjectivesList(pursuit.objectives)
adapter.notifyDataSetChanged()
}

rewardsRecyclerView.apply {
this.layoutManager = rewardsLayoutManager
val adapter = RewardsAdapter()
this.adapter = adapter
adapter.setRewards(pursuit.rewards)
adapter.notifyDataSetChanged()
}

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProviders
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.google.android.material.progressindicator.ProgressIndicator
import com.google.android.material.progressindicator.LinearProgressIndicator
import com.google.android.material.snackbar.Snackbar
import com.leinardi.android.speeddial.SpeedDialActionItem
import com.leinardi.android.speeddial.SpeedDialView
Expand All @@ -39,7 +39,7 @@ class PursuitsFragment : Fragment(), IPursuitsView {

private lateinit var characterFab: SpeedDialView
private lateinit var nothingLayout: LinearLayout
private lateinit var refreshProgressBar: ProgressIndicator
private lateinit var refreshProgressBar: LinearProgressIndicator

private lateinit var selectedCharacterId: String

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion app/src/main/res/layout/pursuit_card.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="@string/pursuitDescriptionPlaceholder" />
tools:text="@string/pursuitDescriptionPlaceholder" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/objectivesHolder"
Expand All @@ -88,6 +88,14 @@
android:layout_height="wrap_content"
tools:ignore="MissingConstraints" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rewardsHolder"
tools:itemCount="2"
android:layout_marginBottom="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="MissingConstraints" />

<TextView
android:id="@+id/expiration_label"
android:layout_width="match_parent"
Expand Down
34 changes: 34 additions & 0 deletions app/src/main/res/layout/rewards_list_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="wrap_content">

<LinearLayout
android:orientation="horizontal"
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
android:id="@+id/rewardImage"
android:contentDescription="@string/pursuit_reward_description"
tools:src="@drawable/reward_example_experience"
android:layout_width="32dp"
android:layout_height="32dp" />

<TextView
android:id="@+id/rewardDescription"
tools:text = "Test Item Entry"
android:textStyle="bold"
android:textColor="#FFFFFF"
tools:textColor="#000000"
android:layout_marginStart="15dp"
android:layout_gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</LinearLayout>

</LinearLayout>
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@
<string name="pursuitDescriptionPlaceholder">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Bibendum enim facilisis gravida neque convallis a cras. Commodo quis imperdiet massa tincidunt nunc pulvinar. Quis eleifend quam adipiscing vitae proin sagittis nisl rhoncus. Pretium quam vulputate dignissim suspendisse in est ante.</string>
<string name="desc_feedback_icon">Feedback Icon</string>
<string name="item_feedback_text">Submit Feedback</string>
<string name="pursuit_reward_description">Pursuit Reward Description</string>

</resources>
</resources>

0 comments on commit 96b3299

Please sign in to comment.