diff --git a/app/src/main/java/net/bible/android/control/ApplicationComponent.kt b/app/src/main/java/net/bible/android/control/ApplicationComponent.kt index 7483294da3..8a62d383f5 100644 --- a/app/src/main/java/net/bible/android/control/ApplicationComponent.kt +++ b/app/src/main/java/net/bible/android/control/ApplicationComponent.kt @@ -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 @@ -73,6 +72,5 @@ interface ApplicationComponent { fun speakActionBarButton(): SpeakActionBarButton fun speakStopActionBarButton(): SpeakStopActionBarButton - fun readingPlanActionBarManager(): ReadingPlanActionBarManager fun searchResultsActionBarManager(): SearchResultsActionBarManager } diff --git a/app/src/main/java/net/bible/android/view/activity/readingplan/DailyReading.kt b/app/src/main/java/net/bible/android/view/activity/readingplan/DailyReading.kt index 48470fe13a..499b78c92b 100644 --- a/app/src/main/java/net/bible/android/view/activity/readingplan/DailyReading.kt +++ b/app/src/main/java/net/bible/android/view/activity/readingplan/DailyReading.kt @@ -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). * @@ -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 @@ -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 @@ -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 @@ -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) @@ -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) @@ -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) { @@ -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 */ @@ -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 @@ -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) } @@ -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" } } diff --git a/app/src/main/java/net/bible/android/view/activity/readingplan/DailyReadingDayBarAdapter.kt b/app/src/main/java/net/bible/android/view/activity/readingplan/DailyReadingDayBarAdapter.kt new file mode 100644 index 0000000000..916e2465fb --- /dev/null +++ b/app/src/main/java/net/bible/android/view/activity/readingplan/DailyReadingDayBarAdapter.kt @@ -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(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 = object: DiffUtil.ItemCallback() { + 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 + } + } + } +} diff --git a/app/src/main/java/net/bible/android/view/activity/readingplan/model/DayBarItem.kt b/app/src/main/java/net/bible/android/view/activity/readingplan/model/DayBarItem.kt new file mode 100644 index 0000000000..12b73a98b2 --- /dev/null +++ b/app/src/main/java/net/bible/android/view/activity/readingplan/model/DayBarItem.kt @@ -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 + } +} diff --git a/app/src/main/res/layout/reading_day_bar_box.xml b/app/src/main/res/layout/reading_day_bar_box.xml new file mode 100644 index 0000000000..c843738734 --- /dev/null +++ b/app/src/main/res/layout/reading_day_bar_box.xml @@ -0,0 +1,22 @@ + + + + + + + + diff --git a/app/src/main/res/layout/reading_plan_one_day.xml b/app/src/main/res/layout/reading_plan_one_day.xml index ae5bcef551..c7da15a67b 100644 --- a/app/src/main/res/layout/reading_plan_one_day.xml +++ b/app/src/main/res/layout/reading_plan_one_day.xml @@ -4,10 +4,11 @@ @author Martin Denham [mjdenham at gmail dot com] --> + 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"> + +