Skip to content

Commit

Permalink
Start adding horizontal days scrollbar in DailyReading
Browse files Browse the repository at this point in the history
  • Loading branch information
timbze committed Jul 31, 2022
1 parent cea74cf commit 6720488
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import net.bible.android.control.readingplan.ReadingPlanControl
import net.bible.android.control.search.SearchControl
import net.bible.android.control.speak.SpeakControl
import net.bible.android.control.versification.BibleTraverser
import net.bible.android.view.activity.readingplan.actionbar.ReadingPlanActionBarManager
import net.bible.android.view.activity.search.searchresultsactionbar.SearchResultsActionBarManager
import net.bible.android.view.activity.speak.actionbarbuttons.SpeakActionBarButton
import net.bible.android.view.activity.speak.actionbarbuttons.SpeakStopActionBarButton
Expand Down Expand Up @@ -73,6 +72,5 @@ interface ApplicationComponent {

fun speakActionBarButton(): SpeakActionBarButton
fun speakStopActionBarButton(): SpeakStopActionBarButton
fun readingPlanActionBarManager(): ReadingPlanActionBarManager
fun searchResultsActionBarManager(): SearchResultsActionBarManager
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 Martin Denham, Tuomas Airaksinen and the And Bible contributors.
* 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).
*
Expand Down Expand Up @@ -39,7 +39,6 @@ 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.actionbar.ReadingPlanActionBarManager
import net.bible.service.common.CommonUtils
import net.bible.service.readingplan.OneDaysReadingsDto

Expand All @@ -49,11 +48,7 @@ import java.util.Calendar

import javax.inject.Inject

/** Allow user to enter search criteria
*
* @author Martin Denham [mjdenham at gmail dot com]
*/
class DailyReading : CustomTitlebarActivityBase(R.menu.reading_plan) {
class DailyReading : CustomTitlebarActivityBase() {

private lateinit var binding: ReadingPlanOneDayBinding

Expand All @@ -65,7 +60,6 @@ class DailyReading : CustomTitlebarActivityBase(R.menu.reading_plan) {
private lateinit var readingsDto: OneDaysReadingsDto

@Inject lateinit var readingPlanControl: ReadingPlanControl
@Inject lateinit var readingPlanActionBarManager: ReadingPlanActionBarManager

private var readingStatus: ReadingStatus? = null
private val getReadingStatus: ReadingStatus
Expand All @@ -86,8 +80,6 @@ class DailyReading : CustomTitlebarActivityBase(R.menu.reading_plan) {
binding = ReadingPlanOneDayBinding.inflate(layoutInflater)
setContentView(binding.root)

super.setActionBarManager(readingPlanActionBarManager)

if (!readingPlanControl.isReadingPlanSelected || !readingPlanControl.currentPlanExists) {
val intent = Intent(this, ReadingPlanSelectorList::class.java)
selectReadingPlan.launch(intent)
Expand Down Expand Up @@ -119,8 +111,6 @@ class DailyReading : CustomTitlebarActivityBase(R.menu.reading_plan) {

planCodeLoaded = readingPlanControl.currentPlanCode

readingPlanActionBarManager.updateButtons()

// get readings for chosen day
readingsDto = readingPlanControl.getDaysReading(dayLoaded)

Expand Down Expand Up @@ -218,10 +208,19 @@ class DailyReading : CustomTitlebarActivityBase(R.menu.reading_plan) {
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.reading_plan, menu)
MenuCompat.setGroupDividerEnabled(menu, true)
return super.onCreateOptionsMenu(menu)
}

override fun onPrepareOptionsMenu(menu: Menu): Boolean {
if (::readingsDto.isInitialized && readingsDto.isDateBasedPlan) {
menu.findItem(R.id.setCurrentDay).isVisible = false
menu.findItem(R.id.setStartDate).isVisible = false
}
return super.onPrepareOptionsMenu(menu)
}

/** user pressed read button by 1 reading
*/
private fun onRead(readingNo: Int) {
Expand Down Expand Up @@ -318,14 +317,6 @@ class DailyReading : CustomTitlebarActivityBase(R.menu.reading_plan) {
startActivity(intent)
}

override fun onPrepareOptionsMenu(menu: Menu): Boolean {
if (::readingsDto.isInitialized && readingsDto.isDateBasedPlan) {
menu.findItem(R.id.setCurrentDay).isVisible = false
menu.findItem(R.id.setStartDate).isVisible = false
}
return super.onPrepareOptionsMenu(menu)
}

/**
* on Click handlers
*/
Expand Down Expand Up @@ -397,7 +388,7 @@ class DailyReading : CustomTitlebarActivityBase(R.menu.reading_plan) {
else -> super.onOptionsItemSelected(item)
}

val importPlanLauncher = registerForActivityResult(ActivityResultContracts.GetContent()) { uriResult ->
private val importPlanLauncher = registerForActivityResult(ActivityResultContracts.GetContent()) { uriResult ->
Log.i(TAG, "Importing plan. Result uri is${if (uriResult != null) " not" else ""} null")
val uri = uriResult ?: return@registerForActivityResult

Expand Down Expand Up @@ -429,7 +420,7 @@ class DailyReading : CustomTitlebarActivityBase(R.menu.reading_plan) {
}
}

val installZipLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
private val installZipLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
// TODO load imported plan if result is OK
// still need to set up "InstallZip" to return reading plan fileName (code)
}
Expand Down Expand Up @@ -483,7 +474,7 @@ class DailyReading : CustomTitlebarActivityBase(R.menu.reading_plan) {
val planDescription: String
)

val PLAN = "net.bible.android.view.activity.readingplan.Plan"
val DAY = "net.bible.android.view.activity.readingplan.Day"
const val PLAN = "net.bible.android.view.activity.readingplan.Plan"
const val DAY = "net.bible.android.view.activity.readingplan.Day"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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

import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import net.bible.android.activity.databinding.ReadingDayBarBoxBinding
import net.bible.android.view.activity.readingplan.model.DayBarItem

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

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
TODO("Not yet implemented")
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
TODO("Not yet implemented")
}

inner class ViewHolder(val binding: ReadingDayBarBoxBinding) : RecyclerView.ViewHolder(binding.root)

companion object {
const val TAG = "DailyReadingDayBarAdapt"
val DIFF_CALLBACK: DiffUtil.ItemCallback<DayBarItem> = object: DiffUtil.ItemCallback<DayBarItem>() {
override fun areItemsTheSame(oldItem: DayBarItem, newItem: DayBarItem):Boolean {
// User properties may have changed if reloaded from the DB, but ID is fixed
return oldItem.dayNumber == newItem.dayNumber
}
override fun areContentsTheSame(oldItem: DayBarItem, newItem: DayBarItem):Boolean {
// NOTE: if you use equals, your object must properly override Object#equals()
// Incorrectly returning false here will result in too many animations.
return oldItem == newItem
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package net.bible.android.view.activity.readingplan.model

import java.util.Date

data class DayBarItem (
val dayNumber: Int,
val date: Date,
/** This day's readings are being shown in daily reading */
var dayActive: Boolean,
var dayReadPartial: Boolean,
var dayReadComplete: Boolean,
) {

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as DayBarItem

if (dayNumber != other.dayNumber) return false
if (date != other.date) return false
if (dayActive != other.dayActive) return false
if (dayReadPartial != other.dayReadPartial) return false
if (dayReadComplete != other.dayReadComplete) return false

return true
}
override fun hashCode(): Int {
var result = dayNumber
result = 31 * result + date.hashCode()
result = 31 * result + dayActive.hashCode()
result = 31 * result + dayReadPartial.hashCode()
result = 31 * result + dayReadComplete.hashCode()
return result
}
}
22 changes: 22 additions & 0 deletions app/src/main/res/layout/reading_day_bar_box.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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:layout_width="55dp"
android:layout_height="50dp"
android:orientation="vertical">

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

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textSize="18sp"
android:textStyle="bold"
tools:text="222" />

</androidx.appcompat.widget.LinearLayoutCompat>
20 changes: 15 additions & 5 deletions app/src/main/res/layout/reading_plan_one_day.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
@author Martin Denham [mjdenham at gmail dot com]
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:id="@+id/top_text"
android:orientation="vertical"
android:layout_width="fill_parent"
Expand Down Expand Up @@ -42,12 +43,21 @@
android:layout_width="wrap_content"/>
</LinearLayout>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/days_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/top_text"
android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/reading_day_bar_box" />

<!-- container for daily readings -->
<ScrollView
android:id="@+id/scroll_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/top_text"
android:layout_below="@id/days_recycler"
android:layout_marginStart="10dip"
android:layout_marginEnd="10dip"
android:layout_marginBottom="60dip">
Expand Down

0 comments on commit 6720488

Please sign in to comment.