Skip to content
This repository has been archived by the owner on May 17, 2023. It is now read-only.

Commit

Permalink
Open View Entry screen if there's only one entry on Throwback date
Browse files Browse the repository at this point in the history
Otherwise will open the Throwback Entries screen
Also bumps version number
  • Loading branch information
Marc committed Jun 30, 2019
1 parent f6614ba commit a37af2a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Expand Up @@ -14,8 +14,8 @@ android {
applicationId "com.marcdonald.hibi"
minSdkVersion 23
targetSdkVersion 28
versionCode 29
versionName "1.2.0"
versionCode 30
versionName "1.2.1"
setProperty("archivesBaseName", "Hibi-v$versionName")
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Expand Up @@ -10,6 +10,7 @@ import androidx.constraintlayout.widget.ConstraintLayout
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import androidx.navigation.NavDirections
import androidx.navigation.Navigation
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
Expand Down Expand Up @@ -87,8 +88,14 @@ class ThrowbackFragment : Fragment(), KodeinAware {
})
}

private fun onItemClick(day: Int, month: Int, year: Int) {
val action = ThrowbackFragmentDirections.throwbackEntriesAction(day, month, year)
private fun onItemClick(amountOfOtherEntries: Int, entryId: Int, day: Int, month: Int, year: Int) {
val action: NavDirections
if(amountOfOtherEntries == 0) {
action = ThrowbackFragmentDirections.viewEntryAction()
action.entryId = entryId
} else {
action = ThrowbackFragmentDirections.throwbackEntriesAction(day, month, year)
}
Navigation.findNavController(requireParentFragment().requireView()).navigate(action)
}
}
Expand Up @@ -9,7 +9,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.marcdonald.hibi.R

class ThrowbackRecyclerAdapter(private val context: Context,
private val onClick: (day: Int, month: Int, year: Int) -> Unit)
private val onClick: (amountOfEntriesOnDay: Int, entryId: Int, day: Int, month: Int, year: Int) -> Unit)
: RecyclerView.Adapter<ThrowbackRecyclerViewHolder>() {

private val inflater: LayoutInflater = LayoutInflater.from(context)
Expand All @@ -18,7 +18,13 @@ class ThrowbackRecyclerAdapter(private val context: Context,

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ThrowbackRecyclerViewHolder {
val view = inflater.inflate(R.layout.item_throwback, parent, false)
return ThrowbackRecyclerViewHolder(view, onClick)
return ThrowbackRecyclerViewHolder(view, ::onViewHolderClick)
}

private fun onViewHolderClick(adapterPosition: Int) {
val item = items[adapterPosition]
val itemEntry = item.entryDisplayItem.entry
onClick(item.amountOfOtherEntries, itemEntry.id, itemEntry.day, itemEntry.month, itemEntry.year)
}

override fun getItemCount(): Int {
Expand Down
Expand Up @@ -17,7 +17,7 @@ import com.marcdonald.hibi.internal.utils.formatTimeForDisplay
import java.util.*

class ThrowbackRecyclerViewHolder(itemView: View,
onClick: (day: Int, month: Int, year: Int) -> Unit)
onClick: (adapterPosition: Int) -> Unit)
: RecyclerView.ViewHolder(itemView) {

// <editor-fold desc="UI Components">
Expand All @@ -38,9 +38,7 @@ class ThrowbackRecyclerViewHolder(itemView: View,

init {
itemView.findViewById<LinearLayout>(R.id.lin_throwback).setOnClickListener {
displayedItem?.let { item ->
onClick(item.entryDisplayItem.entry.day, item.entryDisplayItem.entry.month, item.entryDisplayItem.entry.year)
}
onClick(adapterPosition)
}
}

Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/navigation/main_navigation.xml
Expand Up @@ -213,6 +213,18 @@
android:name="year"
app:argType="integer" />
</action>
<action
android:id="@+id/view_entry_action"
app:destination="@id/destination_view_entry"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim">
<argument
android:name="entryId"
app:argType="integer"
android:defaultValue="0" />
</action>
</fragment>
<!--endregion-->

Expand Down

0 comments on commit a37af2a

Please sign in to comment.