diff --git a/app/src/main/java/xyz/omnicron/apps/android/dot/api/Destiny.kt b/app/src/main/java/xyz/omnicron/apps/android/dot/api/Destiny.kt index 8478d70..67a5715 100644 --- a/app/src/main/java/xyz/omnicron/apps/android/dot/api/Destiny.kt +++ b/app/src/main/java/xyz/omnicron/apps/android/dot/api/Destiny.kt @@ -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() diff --git a/app/src/main/java/xyz/omnicron/apps/android/dot/api/models/DestinyCharacter.kt b/app/src/main/java/xyz/omnicron/apps/android/dot/api/models/DestinyCharacter.kt index 27c8840..6776c8b 100644 --- a/app/src/main/java/xyz/omnicron/apps/android/dot/api/models/DestinyCharacter.kt +++ b/app/src/main/java/xyz/omnicron/apps/android/dot/api/models/DestinyCharacter.kt @@ -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.* @@ -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() } @@ -143,6 +145,24 @@ class DestinyCharacter(var membershipId: String, return cleanedPursuits } + + private fun addRewardsToPursuits(pursuits: ArrayList, database: DestinyDatabase): ArrayList { + val updatedPursuits = arrayListOf() + + 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) { diff --git a/app/src/main/java/xyz/omnicron/apps/android/dot/api/models/DestinyItem.kt b/app/src/main/java/xyz/omnicron/apps/android/dot/api/models/DestinyItem.kt index 5d3eb67..f3f1323 100644 --- a/app/src/main/java/xyz/omnicron/apps/android/dot/api/models/DestinyItem.kt +++ b/app/src/main/java/xyz/omnicron/apps/android/dot/api/models/DestinyItem.kt @@ -20,6 +20,7 @@ class DestinyPursuit(databaseItem: DestinyDatabaseItem, ) : DestinyItem(databaseItem, instanceId, quantity, bucketHash) { val objectives = arrayListOf() + val rewards = arrayListOf() } diff --git a/app/src/main/java/xyz/omnicron/apps/android/dot/database/DestinyDatabase.kt b/app/src/main/java/xyz/omnicron/apps/android/dot/database/DestinyDatabase.kt index dd026b8..d33f134 100644 --- a/app/src/main/java/xyz/omnicron/apps/android/dot/database/DestinyDatabase.kt +++ b/app/src/main/java/xyz/omnicron/apps/android/dot/database/DestinyDatabase.kt @@ -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 @@ -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 = emptyArray() +) + +class DestinyDatabaseRewardEntry( + var itemHash: Long = 0, + var quantity: Int = 0 ) class DestinyDatabaseObjective( diff --git a/app/src/main/java/xyz/omnicron/apps/android/dot/ui/objectives/RewardsAdapter.kt b/app/src/main/java/xyz/omnicron/apps/android/dot/ui/objectives/RewardsAdapter.kt new file mode 100644 index 0000000..c8002c4 --- /dev/null +++ b/app/src/main/java/xyz/omnicron/apps/android/dot/ui/objectives/RewardsAdapter.kt @@ -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() { + + private var rewards = arrayListOf() + + 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) { + 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) + } + + } +} \ No newline at end of file diff --git a/app/src/main/java/xyz/omnicron/apps/android/dot/ui/pursuits/PursuitsAdapter.kt b/app/src/main/java/xyz/omnicron/apps/android/dot/ui/pursuits/PursuitsAdapter.kt index be7bd9b..cbb6b40 100644 --- a/app/src/main/java/xyz/omnicron/apps/android/dot/ui/pursuits/PursuitsAdapter.kt +++ b/app/src/main/java/xyz/omnicron/apps/android/dot/ui/pursuits/PursuitsAdapter.kt @@ -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() { @@ -94,11 +95,12 @@ class PursuitsAdapter: RecyclerView.Adapter() { 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 @@ -109,7 +111,7 @@ class PursuitsAdapter: RecyclerView.Adapter() { 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)) @@ -133,17 +135,27 @@ class PursuitsAdapter: RecyclerView.Adapter() { } } - 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() + } + } } diff --git a/app/src/main/java/xyz/omnicron/apps/android/dot/ui/pursuits/PursuitsFragment.kt b/app/src/main/java/xyz/omnicron/apps/android/dot/ui/pursuits/PursuitsFragment.kt index fb2cbaa..873d9f1 100644 --- a/app/src/main/java/xyz/omnicron/apps/android/dot/ui/pursuits/PursuitsFragment.kt +++ b/app/src/main/java/xyz/omnicron/apps/android/dot/ui/pursuits/PursuitsFragment.kt @@ -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 @@ -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 diff --git a/app/src/main/res/drawable/reward_example_experience.png b/app/src/main/res/drawable/reward_example_experience.png new file mode 100644 index 0000000..28d2cd4 Binary files /dev/null and b/app/src/main/res/drawable/reward_example_experience.png differ diff --git a/app/src/main/res/layout/pursuit_card.xml b/app/src/main/res/layout/pursuit_card.xml index d28d303..713df80 100644 --- a/app/src/main/res/layout/pursuit_card.xml +++ b/app/src/main/res/layout/pursuit_card.xml @@ -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" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 438bc13..b3ec7e5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -45,5 +45,6 @@ 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. Feedback Icon Submit Feedback + Pursuit Reward Description - + \ No newline at end of file