From a23b79c661fcedcd3567428f267ac5d492b8eaeb Mon Sep 17 00:00:00 2001 From: timbze Date: Mon, 14 Feb 2022 11:08:11 -0600 Subject: [PATCH] Remove ReadingPlan action bar classes that will no longer be needed --- .../actionbar/ReadingPlanActionBarManager.kt | 84 -------- .../ReadingPlanBibleActionBarButton.kt | 38 ---- .../ReadingPlanCommentaryActionBarButton.kt | 47 ---- .../ReadingPlanDictionaryActionBarButton.kt | 43 ---- .../ReadingPlanPauseActionBarButton.kt | 41 ---- .../ReadingPlanQuickDocumentChangeButton.kt | 41 ---- .../ReadingPlanStopActionBarButton.kt | 42 ---- .../readingplan/actionbar/ReadingPlanTitle.kt | 202 ------------------ 8 files changed, 538 deletions(-) delete mode 100644 app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanActionBarManager.kt delete mode 100644 app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanBibleActionBarButton.kt delete mode 100644 app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanCommentaryActionBarButton.kt delete mode 100644 app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanDictionaryActionBarButton.kt delete mode 100644 app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanPauseActionBarButton.kt delete mode 100644 app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanQuickDocumentChangeButton.kt delete mode 100644 app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanStopActionBarButton.kt delete mode 100644 app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanTitle.kt diff --git a/app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanActionBarManager.kt b/app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanActionBarManager.kt deleted file mode 100644 index 3608fa8824..0000000000 --- a/app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanActionBarManager.kt +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2020 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.actionbar - -import android.app.Activity -import androidx.appcompat.app.ActionBar -import android.view.Menu - -import net.bible.android.control.ApplicationScope -import net.bible.android.control.event.ABEventBus -import net.bible.android.view.activity.base.CurrentActivityHolder -import net.bible.android.view.activity.base.actionbar.ActionBarManager -import net.bible.android.view.activity.base.actionbar.DefaultActionBarManager -import net.bible.service.device.speak.event.SpeakEvent - -import javax.inject.Inject - -/** - * @author Martin Denham [mjdenham at gmail dot com] - */ -@ApplicationScope -class ReadingPlanActionBarManager @Inject -constructor( - private val readingPlanTitle: ReadingPlanTitle, - private val pauseActionBarButton: ReadingPlanPauseActionBarButton, - private val stopActionBarButton: ReadingPlanStopActionBarButton, - private val bibleActionBarButton: ReadingPlanBibleActionBarButton, - private val commentaryActionBarButton: ReadingPlanCommentaryActionBarButton, - private val dictionaryActionBarButton: ReadingPlanDictionaryActionBarButton -) : DefaultActionBarManager(), ActionBarManager { - - init { - ABEventBus.getDefault().register(this) - } - - fun onEvent(e: SpeakEvent) { - updateButtons() - } - - override fun prepareOptionsMenu(activity: Activity, menu: Menu, actionBar: ActionBar) { - super.prepareOptionsMenu(activity, menu, actionBar) - - readingPlanTitle.addToBar(actionBar, activity) - - // order is important to keep bible, cmtry, ... in same place on right - stopActionBarButton.addToMenu(menu) - pauseActionBarButton.addToMenu(menu) - - dictionaryActionBarButton.addToMenu(menu) - commentaryActionBarButton.addToMenu(menu) - bibleActionBarButton.addToMenu(menu) - } - - override fun updateButtons() { - super.updateButtons() - - CurrentActivityHolder.getInstance().runOnUiThread { - readingPlanTitle.update() - - bibleActionBarButton.update() - commentaryActionBarButton.update() - dictionaryActionBarButton.update() - - pauseActionBarButton.update() - stopActionBarButton.update() - } - } -} diff --git a/app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanBibleActionBarButton.kt b/app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanBibleActionBarButton.kt deleted file mode 100644 index 582e48631d..0000000000 --- a/app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanBibleActionBarButton.kt +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2020 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.actionbar - -import net.bible.android.control.ApplicationScope - -import org.crosswire.jsword.book.Book - -import javax.inject.Inject - -/** Quick change bible toolbar button - * - * @author Martin Denham [mjdenham at gmail dot com] - */ -@ApplicationScope -class ReadingPlanBibleActionBarButton @Inject -constructor() : ReadingPlanQuickDocumentChangeButton() { - - override fun getSuggestedDocument(): Book? { - return currentPageManager.currentBible.currentDocument - } -} diff --git a/app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanCommentaryActionBarButton.kt b/app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanCommentaryActionBarButton.kt deleted file mode 100644 index 9a697078b3..0000000000 --- a/app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanCommentaryActionBarButton.kt +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2020 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.actionbar - -import net.bible.android.control.ApplicationScope - -import org.crosswire.jsword.book.Book - -import javax.inject.Inject - -/** - * @author Martin Denham [mjdenham at gmail dot com] - */ -@ApplicationScope -class ReadingPlanCommentaryActionBarButton @Inject -constructor() : ReadingPlanQuickDocumentChangeButton() { - - - override fun getSuggestedDocument(): Book? { - return currentPageManager.currentCommentary.currentDocument - } - - /** - * Portrait actionbar is a bit squashed if speak controls are displayed so hide commentary - */ - override fun canShow(): Boolean { - return super.canShow() && (isWide || !isSpeakMode) - } - - -} diff --git a/app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanDictionaryActionBarButton.kt b/app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanDictionaryActionBarButton.kt deleted file mode 100644 index 9f4670ab1a..0000000000 --- a/app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanDictionaryActionBarButton.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2020 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.actionbar - -import net.bible.android.control.ApplicationScope -import net.bible.android.control.page.window.ActiveWindowPageManagerProvider - -import org.crosswire.jsword.book.Book - -import javax.inject.Inject - -/** - * @author Martin Denham [mjdenham at gmail dot com] - */ -@ApplicationScope -class ReadingPlanDictionaryActionBarButton @Inject -constructor(activeWindowPageManagerProvider: ActiveWindowPageManagerProvider) : ReadingPlanQuickDocumentChangeButton() { - - override fun getSuggestedDocument(): Book? { - return currentPageManager.currentDictionary.currentDocument - } - - /** return true if Strongs are relevant to this doc & screen */ - override fun canShow(): Boolean { - return super.canShow() && isWide - } -} diff --git a/app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanPauseActionBarButton.kt b/app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanPauseActionBarButton.kt deleted file mode 100644 index a6f335ebf0..0000000000 --- a/app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanPauseActionBarButton.kt +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2020 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.actionbar - -import net.bible.android.control.ApplicationScope -import net.bible.android.control.document.DocumentControl -import net.bible.android.control.speak.SpeakControl -import net.bible.android.view.activity.speak.actionbarbuttons.SpeakActionBarButton - -import javax.inject.Inject - -/** - * @author Martin Denham [mjdenham at gmail dot com] - */ -@ApplicationScope -class ReadingPlanPauseActionBarButton @Inject -constructor(speakControl: SpeakControl, documentControl: DocumentControl) : SpeakActionBarButton(speakControl, documentControl) { - - /** - * do not show if nothing is being said. If speaking then allow pause and vice-versa - */ - public override fun canShow(): Boolean { - return super.canShow() && isSpeakMode - } -} diff --git a/app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanQuickDocumentChangeButton.kt b/app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanQuickDocumentChangeButton.kt deleted file mode 100644 index 9dbc78e0ac..0000000000 --- a/app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanQuickDocumentChangeButton.kt +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2020 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.actionbar - -import android.view.MenuItem - -import net.bible.android.view.activity.base.CurrentActivityHolder -import net.bible.android.view.activity.base.actionbar.QuickDocumentChangeToolbarButton - -/** - * @author Martin Denham [mjdenham at gmail dot com] - */ -abstract class ReadingPlanQuickDocumentChangeButton : QuickDocumentChangeToolbarButton() { - - override fun onMenuItemClick(arg0: MenuItem): Boolean { - val isHandled = super.onMenuItemClick(arg0) - // exit the Daily Reading page, returning up to the Document page display to see the bible - CurrentActivityHolder.getInstance().currentActivity.apply { - isIntegrateWithHistoryManager = true - finish() - } - - return isHandled - } -} diff --git a/app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanStopActionBarButton.kt b/app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanStopActionBarButton.kt deleted file mode 100644 index 281517d14d..0000000000 --- a/app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanStopActionBarButton.kt +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2020 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.actionbar - -import net.bible.android.control.ApplicationScope -import net.bible.android.control.speak.SpeakControl -import net.bible.android.view.activity.speak.actionbarbuttons.SpeakStopActionBarButton - -import javax.inject.Inject - -/** - * Button to stop Speak when viewing Reading Plan. Visible when speaking. - * - * @author Martin Denham [mjdenham at gmail dot com] - */ -@ApplicationScope -class ReadingPlanStopActionBarButton @Inject -constructor(speakControl: SpeakControl) : SpeakStopActionBarButton(speakControl) { - - /** - * do not show if nothing is being said. If speaking then allow pause and vice-versa - */ - public override fun canShow(): Boolean { - return super.canShow() && isSpeakMode - } -} diff --git a/app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanTitle.kt b/app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanTitle.kt deleted file mode 100644 index 10dff3c76b..0000000000 --- a/app/src/main/java/net/bible/android/view/activity/readingplan/actionbar/ReadingPlanTitle.kt +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright (c) 2020 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.actionbar - -import android.app.Activity -import android.content.Intent -import android.content.res.Configuration -import androidx.appcompat.app.ActionBar -import androidx.appcompat.widget.Toolbar -import android.util.Log -import android.view.View -import android.view.ViewGroup -import android.widget.ImageButton -import android.widget.TextView - -import net.bible.android.activity.R -import net.bible.android.control.ApplicationScope -import net.bible.android.control.readingplan.ReadingPlanControl -import net.bible.android.view.activity.base.CurrentActivityHolder -import net.bible.android.view.activity.readingplan.DailyReading -import net.bible.android.view.activity.readingplan.DailyReadingList -import net.bible.android.view.activity.readingplan.ReadingPlanSelectorList -import net.bible.service.common.TitleSplitter - -import org.apache.commons.lang3.ArrayUtils -import javax.inject.Inject - -/** - * Show current verse/key and document on left of actionBar - * - * @author Martin Denham [mjdenham at gmail dot com] - */ - - - -@ApplicationScope -class ReadingPlanTitle @Inject -constructor(private val readingPlanControl: ReadingPlanControl) { - - - private lateinit var actionBar: ActionBar - private lateinit var activity: Activity - private set - - private lateinit var documentTitle: TextView - private lateinit var documentSubtitle: TextView - private lateinit var pageTitle: TextView - private lateinit var pageSubtitle: TextView - - private val twoPageTitleParts: Array - get() { - return try { - unsplitIfLandscape(pageTitleParts) - } catch (e: Exception) { - Log.e(TAG, "Error getting reading plan title", e) - arrayOf("", "") - } - - } - - private val twoDocumentTitleParts: Array - get() { - return try { - unsplitIfLandscape(documentTitleParts) - } catch (e: Exception) { - Log.e(TAG, "Error getting reading plan title", e) - arrayOf("", "") - } - - } - - fun addToBar(actionBar: ActionBar, activity: Activity) { - this.actionBar = actionBar - this.activity = activity - - actionBar.setCustomView(R.layout.reading_plan_title) - val homeButton: ImageButton = actionBar.customView.findViewById(R.id.homeButton) - homeButton.visibility = View.GONE - - documentTitle = actionBar.customView.findViewById(R.id.documentTitle) - documentSubtitle = actionBar.customView.findViewById(R.id.documentSubtitle) - pageTitle = actionBar.customView.findViewById(R.id.pageTitle) - pageSubtitle = actionBar.customView.findViewById(R.id.pageSubtitle) - - - // clicking document title shows document selector - val documentTitleContainer = actionBar.customView.findViewById(R.id.documentTitleContainer) - documentTitleContainer.setOnClickListener { onDocumentTitleClick() } - - // clicking page title shows appropriate key selector - val pageTitleContainer = actionBar.customView.findViewById(R.id.pageTitleContainer) - pageTitleContainer.setOnClickListener { onPageTitleClick() } - - actionBar.displayOptions = ActionBar.DISPLAY_SHOW_CUSTOM or ActionBar.DISPLAY_SHOW_HOME - - update(true) - - // remove a small amount of extra padding at the left of the actionbar see: http://stackoverflow.com/questions/27354812/android-remove-left-margin-from-actionbars-custom-layout - val toolbar = actionBar.customView.parent - if (toolbar is Toolbar) { - toolbar.setContentInsetsAbsolute(0, 0) - } - } - - - fun update() { - // update everything if called externally - update(true) - } - - private fun update(everything: Boolean) { - if (!::pageTitle.isInitialized || !::pageSubtitle.isInitialized) return - - CurrentActivityHolder.getInstance().runOnUiThread { - // always update verse number - val pageParts = twoPageTitleParts - if (pageParts.isNotEmpty()) pageTitle.text = pageParts[0] - if (pageParts.size > 1) pageSubtitle.text = pageParts[1] - pageSubtitle.visibility = if (pageParts.size > 1) View.VISIBLE else View.GONE - - // don't always need to redisplay document name - if (everything && ::documentTitle.isInitialized && ::documentSubtitle.isInitialized) { - val documentParts = twoDocumentTitleParts - if (documentParts.isNotEmpty()) documentTitle.text = documentParts[0] - if (documentParts.size > 1) documentSubtitle.text = documentParts[1] - documentSubtitle.visibility = if (documentParts.size > 1) View.VISIBLE else View.GONE - } - } - } - - private fun getTwoTitleParts(title: String, lastAreMoreSignificant: Boolean): Array { - var parts: Array? = titleSplitter.split(title) - parts = reduceTo2Parts(parts, lastAreMoreSignificant) - return parts - } - - private fun reduceTo2Parts(parts: Array?, lastAreMoreSignificant: Boolean): Array { - // return the last 2 parts as only show 2 and last are normally most significant - return if (lastAreMoreSignificant) { - ArrayUtils.subarray(parts, parts!!.size - 2, parts.size) - } else { - ArrayUtils.subarray(parts, 0, 2) - } - } - - private fun unsplitIfLandscape(parts: Array): Array { - // un-split if in landscape because landscape actionBar has more width but less height - return if (::activity.isInitialized && activity.resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) { - arrayOf(parts.joinToString(" ")) - } else - parts - } - - private val documentTitleParts: Array - get() { - val title = readingPlanControl.shortTitle - return getTwoTitleParts(title, false) - } - - private val pageTitleParts: Array - get() { - // get the current day loaded for the page title, not the current plan day - val planDayDesc = readingPlanControl.getDaysReading((activity as DailyReading).dayLoaded).dayDesc - return getTwoTitleParts(planDayDesc, true) - } - - private fun onDocumentTitleClick() { - val readingPlanActivity = activity as DailyReading - val docHandlerIntent = Intent(readingPlanActivity, ReadingPlanSelectorList::class.java) - readingPlanActivity.selectReadingPlan.launch(docHandlerIntent) - } - - private fun onPageTitleClick() { - val readingPlanActivity = activity as DailyReading - val pageHandlerIntent = Intent(readingPlanActivity, DailyReadingList::class.java) - readingPlanActivity.selectReadingDay.launch(pageHandlerIntent) - } - - companion object { - - private val titleSplitter = TitleSplitter() - - private const val TAG = "Title" - } - -}