Skip to content

Commit

Permalink
Days bar is showing for reading plan
Browse files Browse the repository at this point in the history
  • Loading branch information
timbze committed Aug 1, 2022
1 parent 6720488 commit 701760d
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import net.bible.android.control.event.passage.BeforeCurrentPageChangeEvent
import net.bible.android.control.page.CurrentPageManager
import net.bible.android.control.page.window.ActiveWindowPageManagerProvider
import net.bible.android.control.speak.SpeakControl
import net.bible.android.view.activity.readingplan.model.DayBarItem
import net.bible.service.common.CommonUtils
import net.bible.service.db.readingplan.ReadingPlanRepository
import net.bible.service.readingplan.OneDaysReadingsDto
Expand Down Expand Up @@ -90,6 +91,20 @@ class ReadingPlanControl @Inject constructor(
val currentPlansReadingList: List<OneDaysReadingsDto>
get() = readingPlanTextDao.getReadingList(currentPlanCode)

val currentPlansReadingDayBarItems: List<DayBarItem>
get() {
val planCurrentDay = currentPlanDay
return readingPlanTextDao.getReadingList(currentPlanCode).map {
DayBarItem(
it.day,
it.readingDate,
it.day == planCurrentDay,
false, // TODO add functionality
it.day < planCurrentDay
)
}
}

val currentPlanExists: Boolean get() = try {
readingPlanTextDao.getReading(currentPlanCode, 1)
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ import android.view.View
import android.widget.TableLayout
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.view.MenuCompat
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import net.bible.android.BibleApplication

import net.bible.android.activity.R
Expand All @@ -39,6 +42,7 @@ import net.bible.android.control.readingplan.ReadingStatus
import net.bible.android.view.activity.base.CustomTitlebarActivityBase
import net.bible.android.view.activity.base.Dialogs
import net.bible.android.view.activity.installzip.InstallZip
import net.bible.android.view.activity.readingplan.model.DayBarItem
import net.bible.service.common.CommonUtils
import net.bible.service.readingplan.OneDaysReadingsDto

Expand Down Expand Up @@ -199,6 +203,8 @@ class DailyReading : CustomTitlebarActivityBase() {
}
// end All

setupRecycler()

Log.i(TAG, "Finished displaying Reading view")
} catch (e: Exception) {
Log.e(TAG, "Error showing daily readings", e)
Expand All @@ -207,6 +213,18 @@ class DailyReading : CustomTitlebarActivityBase() {

}

private lateinit var viewAdapter: DailyReadingDayBarAdapter
private fun setupRecycler() {
val days = readingPlanControl.currentPlansReadingDayBarItems
viewAdapter = DailyReadingDayBarAdapter()
viewAdapter.submitList(days)
binding.daysRecycler.apply {
layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false)
adapter = viewAdapter
addItemDecoration(DividerItemDecoration(context, LinearLayoutManager.HORIZONTAL))
}
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.reading_plan, menu)
MenuCompat.setGroupDividerEnabled(menu, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,40 @@

package net.bible.android.view.activity.readingplan

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import net.bible.android.activity.R
import net.bible.android.activity.databinding.ReadingDayBarBoxBinding
import net.bible.android.view.activity.readingplan.model.DayBarItem
import net.bible.service.common.CommonUtils.getResourceColor
import java.text.SimpleDateFormat
import java.util.Locale

class DailyReadingDayBarAdapter : ListAdapter<DayBarItem, DailyReadingDayBarAdapter.ViewHolder>(DIFF_CALLBACK) {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
TODO("Not yet implemented")
val binding = ReadingDayBarBoxBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return ViewHolder(binding)
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
TODO("Not yet implemented")
val item = getItem(position) ?: return
holder.binding.apply {
dayNumberView.text = item.dayNumber.toString()
dateView.text = SimpleDateFormat("MMM dd", Locale.getDefault()).format(item.date)

boxContainer.setBackgroundColor(
if (item.dayActive)
getResourceColor(R.color.sync_on_green)
else if (item.dayReadComplete)
getResourceColor(R.color.grey_700)
else
getResourceColor(R.color.grey_500)
)
}
}

inner class ViewHolder(val binding: ReadingDayBarBoxBinding) : RecyclerView.ViewHolder(binding.root)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Copyright (c) 2022 Martin Denham, Tuomas Airaksinen and the And Bible contributors.
*
* This file is part of And Bible (http://github.com/AndBible/and-bible).
*
* And Bible is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* And Bible is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with And Bible.
* If not, see http://www.gnu.org/licenses/.
*
*/

package net.bible.android.view.activity.readingplan.model

import java.util.Date
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,17 @@ class OneDaysReadingsDto(val day: Int, private val readingsString: String?, val
private val dateBasedWithYear = SimpleDateFormat("MMM-d/yyyy", Locale.getDefault())

private var readingKeys: List<Key>? = null

private var _readingDate: Date? = null
/** reading date for date-based plan, else null
*/
var readingDate: Date? = null
var readingDate: Date
get() {
if (_readingDate == null)
_readingDate = calculateDate(readingPlanInfo.startDate ?: Date())
return _readingDate!!
}
set(value) { _readingDate = value }

init {
checkKeysGenerated()
Expand All @@ -55,22 +63,14 @@ class OneDaysReadingsDto(val day: Int, private val readingsString: String?, val
/** get a string representing the date this reading is planned for
*/
val readingDateString: String
get() {
val readingDate = readingDate
return if (readingDate != null) {
SimpleDateFormat.getDateInstance().format(readingDate)
} else {
var dateString = ""
val startDate = readingPlanInfo.startDate
if (startDate != null) {
val cal = Calendar.getInstance()
cal.time = startDate
cal.add(Calendar.DAY_OF_MONTH, day - 1)
dateString = SimpleDateFormat.getDateInstance().format(cal.time)
}
dateString
}
}
get() = SimpleDateFormat.getDateInstance().format(readingDate)

private fun calculateDate(startDate: Date): Date {
val cal = Calendar.getInstance()
cal.time = startDate
cal.add(Calendar.DAY_OF_MONTH, day - 1)
return cal.time
}

val readingsDesc: String
get() {
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/layout/reading_day_bar_box.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/box_container"
android:layout_width="55dp"
android:layout_height="50dp"
android:orientation="vertical">

<TextView
android:id="@+id/date_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
tools:text="Feb 13" />

<TextView
android:id="@+id/day_number_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
Expand Down

0 comments on commit 701760d

Please sign in to comment.