Skip to content

Commit f5be5a8

Browse files
committed
LastRefresh now displays nicely
1 parent 23cc915 commit f5be5a8

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

app/src/main/java/com/jumptuck/recipebrowser2/recipelist/RecipeListFragment.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import com.jumptuck.recipebrowser2.settings.RecipeDeleteAllDialogBuilder
2020
import kotlinx.android.synthetic.main.activity_main.*
2121
import kotlinx.android.synthetic.main.custom_action_bar_layout.view.*
2222
import timber.log.Timber
23+
import java.text.SimpleDateFormat
24+
import java.util.*
25+
import kotlin.collections.ArrayList
2326

2427
class RecipeListFragment : Fragment() {
2528
lateinit var recipeListViewModel: RecipeListViewModel
@@ -122,9 +125,17 @@ class RecipeListFragment : Fragment() {
122125
/** Set last_refresh date in nav drawer header **/
123126
RecipeRepository.lastRefresh.observe(viewLifecycleOwner, Observer {
124127
it?.let {
128+
val timestamp = RecipeRepository.lastRefresh.value
129+
val stringTime: String
130+
if (timestamp == 0L) { stringTime = getString(R.string.last_refresh_never) }
131+
else {
132+
stringTime =
133+
SimpleDateFormat("MM/dd/yy hh:mma")
134+
.format(timestamp)
135+
}
125136
val navigationView = requireActivity().findViewById<NavigationView>(R.id.navView)
126137
navigationView
127-
.findViewById<TextView>(R.id.last_refresh).text = RecipeRepository.lastRefresh.value.toString()
138+
.findViewById<TextView>(R.id.last_refresh_value).text = stringTime
128139
}
129140
})
130141

app/src/main/res/layout/activity_main.xml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,21 @@
4545
android:layout_width="match_parent"
4646
android:layout_height="wrap_content"
4747
android:layout_gravity="bottom"
48-
android:clickable="true"
48+
android:paddingStart="16dp"
49+
android:paddingBottom="16dp"
4950
android:orientation="vertical">
5051

5152
<TextView
52-
android:id="@+id/last_refresh"
53+
android:id="@+id/last_refresh_title"
5354
android:layout_width="match_parent"
54-
android:layout_height="48dp"
55-
android:gravity="center"
56-
android:text="Last Refresh" />
55+
android:layout_height="22dp"
56+
android:gravity="start"
57+
android:text="@string/nav_drawer_footer_last_refresh" />
58+
<TextView
59+
android:id="@+id/last_refresh_value"
60+
android:layout_width="match_parent"
61+
android:layout_height="22dp"
62+
android:gravity="start" />
5763
</LinearLayout>
5864
</com.google.android.material.navigation.NavigationView>
5965

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
<string name="nav_header_icon_description">Pie slice icon</string>
5151
<string name="nav_header_title">Recipe\nBrowser</string>
5252
<string name="refresh_action_force">Force Refresh</string>
53+
<string name="nav_drawer_footer_last_refresh">Last Refresh:</string>
54+
<string name="last_refresh_never">Never</string>
5355

5456
<plurals name="numberOfRecipes">
5557
<item quantity="one">%d Recipe</item>

0 commit comments

Comments
 (0)