Skip to content

Commit

Permalink
Use material dialogs everywhere (#247)
Browse files Browse the repository at this point in the history
This should address a number of theme-related issues.

Related: https://ebce-lyrasis.atlassian.net/browse/PP-651
Related: https://ebce-lyrasis.atlassian.net/browse/PP-650
  • Loading branch information
io7m authored Oct 27, 2023
1 parent 9603061 commit 08f8376
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 41 deletions.
14 changes: 13 additions & 1 deletion simplified-lcp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
dependencies {
implementation(libs.androidx.activity)
implementation(libs.androidx.activity.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.appcompat.resources)
implementation(libs.androidx.cardview)
implementation(libs.androidx.collection)
implementation(libs.androidx.constraintlayout)
implementation(libs.kotlinx.coroutines)
implementation(libs.androidx.constraintlayout.core)
implementation(libs.androidx.coordinatorlayout)
implementation(libs.androidx.drawerlayout)
implementation(libs.androidx.lifecycle.common)
implementation(libs.androidx.savedstate)
implementation(libs.google.material)
implementation(libs.kotlin.reflect)
implementation(libs.kotlin.stdlib)
implementation(libs.kotlinx.coroutines)
implementation(libs.palace.drm.core)
implementation(libs.r2.lcp)
implementation(libs.r2.shared)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.nypl.simplified.lcp

import android.app.AlertDialog
import android.content.Context
import android.view.LayoutInflater
import android.widget.TextView
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.librarysimplified.lcp.R
Expand Down Expand Up @@ -71,7 +71,7 @@ class LCPContentProtectionProvider : ContentProtectionProvider {
val inputPassphrase = view.findViewById<TextView>(R.id.inputPassphrase)

return suspendCoroutine { cont ->
AlertDialog.Builder(context).apply {
MaterialAlertDialogBuilder(context).apply {
setTitle(R.string.dialog_manual_passphrase_title)
setMessage(hint)
setPositiveButton(R.string.dialog_manual_passphrase_done) { dialog, _ ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.librarysimplified.main

import android.content.Context
import androidx.annotation.UiThread
import androidx.appcompat.app.AlertDialog
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import org.librarysimplified.services.api.ServiceDirectoryType
import org.nypl.drm.core.AdobeAdeptExecutorType
import org.nypl.simplified.adobe.extensions.AdobeDRMServices
Expand All @@ -26,7 +26,7 @@ object MainAdobeWarnings {
val drmService = services.optionalService(AdobeAdeptExecutorType::class.java)
if (drmService == null) {
if (AdobeDRMServices.isIntendedToBePresent(context)) {
AlertDialog.Builder(context)
MaterialAlertDialogBuilder(context)
.setMessage(R.string.bootAdobeDRMFailed)
.create()
.show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import android.widget.ImageView
import android.widget.ProgressBar
import android.widget.TextView
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AlertDialog
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import androidx.appcompat.widget.SwitchCompat
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.app.ActivityCompat
Expand Down Expand Up @@ -503,7 +503,7 @@ class AccountDetailFragment : Fragment(R.layout.account) {
} catch (e: Exception) {
this.logger.error("unable to start activity: ", e)
val context = this.requireContext()
AlertDialog.Builder(context)
MaterialAlertDialogBuilder(context)
.setMessage(context.getString(R.string.accountReportFailed, supportUrl))
.create()
.show()
Expand Down Expand Up @@ -964,7 +964,7 @@ class AccountDetailFragment : Fragment(R.layout.account) {
} catch (e: Exception) {
this.logger.error("unable to start activity: ", e)
val context = this.requireContext()
AlertDialog.Builder(context)
MaterialAlertDialogBuilder(context)
.setMessage(context.getString(R.string.accountPasswordResetFailed, supportUrl))
.create()
.show()
Expand Down Expand Up @@ -1104,7 +1104,7 @@ class AccountDetailFragment : Fragment(R.layout.account) {

private fun onAgeCheckboxClicked(): (View) -> Unit = {
val isOver13 = this.viewModel.isOver13
AlertDialog.Builder(this.requireContext())
MaterialAlertDialogBuilder(this.requireContext())
.setTitle(R.string.accountCOPPADeleteBooks)
.setMessage(R.string.accountCOPPADeleteBooksConfirm)
.setNegativeButton(R.string.accountCancel) { _, _ ->
Expand Down Expand Up @@ -1173,14 +1173,14 @@ class AccountDetailFragment : Fragment(R.layout.account) {
}

private fun showErrorGettingLocationDialog() {
AlertDialog.Builder(requireContext())
MaterialAlertDialogBuilder(requireContext())
.setMessage(getString(R.string.accountCardCreatorLocationFailed))
.create()
.show()
}

private fun showLocationDisclaimerDialog() {
AlertDialog.Builder(requireContext())
MaterialAlertDialogBuilder(requireContext())
.setMessage(R.string.accountCardCreatorDialogPermissionsMessage)
.setPositiveButton(android.R.string.ok) { _, _ -> requestLocationPermissions() }
.setNegativeButton(R.string.accountCardCreatorDialogCancel) { dialog, _ -> dialog?.dismiss() }
Expand All @@ -1189,7 +1189,7 @@ class AccountDetailFragment : Fragment(R.layout.account) {
}

private fun showSettingsDialog() {
AlertDialog.Builder(requireContext())
MaterialAlertDialogBuilder(requireContext())
.setMessage(R.string.accountCardCreatorDialogOpenSettingsMessage)
.setPositiveButton(R.string.accountCardCreatorDialogOpenSettings) { _, _ ->
openAppSettings()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import androidx.appcompat.app.AlertDialog
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
Expand Down Expand Up @@ -75,7 +75,7 @@ class AccountListFragment : Fragment(R.layout.account_list) {

private fun onAccountDeleteClicked(account: AccountType) {
val context = this.requireContext()
AlertDialog.Builder(context)
MaterialAlertDialogBuilder(context)
.setTitle(R.string.accountsDeleteConfirmTitle)
.setMessage(
context.getString(
Expand Down Expand Up @@ -197,7 +197,7 @@ class AccountListFragment : Fragment(R.layout.account_list) {
}

private fun showAccountDeletionFailedDialog(accountEvent: AccountEventDeletionFailed) {
AlertDialog.Builder(this.requireContext())
MaterialAlertDialogBuilder(this.requireContext())
.setTitle(R.string.accountsDeletionFailed)
.setMessage(R.string.accountsDeletionFailedMessage)
.setPositiveButton(R.string.accountsDetails) { _, _ ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.nypl.simplified.ui.accounts

import com.google.android.material.dialog.MaterialAlertDialogBuilder
import android.annotation.SuppressLint
import android.content.Context
import android.location.LocationManager
Expand Down Expand Up @@ -275,7 +276,7 @@ class AccountListRegistryFragment : Fragment(R.layout.account_list_registry) {

if (this.errorDialog == null) {
val newDialog =
AlertDialog.Builder(this.requireActivity())
MaterialAlertDialogBuilder(this.requireActivity())
.setTitle(R.string.accountCreationFailed)
.setMessage(R.string.accountCreationFailedMessage)
.setPositiveButton(R.string.accountsDetails) { dialog, _ ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.os.Bundle
import android.view.View
import android.webkit.WebView
import android.widget.ProgressBar
import androidx.appcompat.app.AlertDialog
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
Expand Down Expand Up @@ -122,7 +122,7 @@ class AccountSAML20Fragment : Fragment(R.layout.account_saml20) {

private fun onSAMLEventFailed(event: AccountSAML20InternalEvent.Failed) {
val newDialog =
AlertDialog.Builder(this.requireActivity())
MaterialAlertDialogBuilder(this.requireActivity())
.setTitle(R.string.accountCreationFailed)
.setMessage(R.string.accountCreationFailedMessage)
.setPositiveButton(R.string.accountsDetails) { dialog, _ ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.librarysimplified.ui.catalog

import android.app.Dialog
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
Expand Down Expand Up @@ -55,7 +56,7 @@ class AgeGateDialog : DialogFragment(), AdapterView.OnItemSelectedListener {
}

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = AlertDialog.Builder(requireContext())
val dialog = MaterialAlertDialogBuilder(requireContext())
.setTitle(getString(R.string.ageVerification))
.setPositiveButton(R.string.catalogDone) { _, _ ->
val selection = birthYearSpinner.selectedItem.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.ProgressBar
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
Expand Down Expand Up @@ -660,7 +660,7 @@ class CatalogBookDetailFragment : Fragment(R.layout.book_detail) {
}

private fun onBookStatusReachedLoanLimit() {
AlertDialog.Builder(requireContext())
MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.bookReachedLoanLimitDialogTitle)
.setMessage(R.string.bookReachedLoanLimitDialogMessage)
.setPositiveButton(R.string.bookReachedLoanLimitDialogButton) { dialog, _ ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import android.widget.RadioButton
import android.widget.RadioGroup
import android.widget.Space
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import androidx.appcompat.widget.AppCompatTextView
import androidx.appcompat.widget.SearchView
import androidx.core.os.bundleOf
Expand Down Expand Up @@ -794,7 +794,7 @@ class CatalogFeedFragment : Fragment(R.layout.feed), AgeGateDialog.BirthYearSele
val checkedItem = choices.indexOfFirst { it.isActive }

// Build the dialog
val alertBuilder = AlertDialog.Builder(this.requireContext())
val alertBuilder = MaterialAlertDialogBuilder(this.requireContext())
alertBuilder.setTitle(groupName)
alertBuilder.setSingleChoiceItems(names, checkedItem) { dialog, checked ->
val selected = choices[checked]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import android.widget.Button
import android.widget.ImageView
import android.widget.ProgressBar
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import androidx.recyclerview.widget.RecyclerView
import com.google.common.base.Preconditions
import com.google.common.util.concurrent.FluentFuture
Expand Down Expand Up @@ -363,7 +363,7 @@ class CatalogPagedViewHolder(
}

private fun onBookStatusReachedLoanLimit() {
AlertDialog.Builder(context)
MaterialAlertDialogBuilder(context)
.setTitle(R.string.bookReachedLoanLimitDialogTitle)
.setMessage(R.string.bookReachedLoanLimitDialogMessage)
.setPositiveButton(R.string.bookReachedLoanLimitDialogButton) { dialog, _ ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.nypl.simplified.ui.settings

import android.app.AlertDialog
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import android.graphics.Color
import android.os.Bundle
import android.view.View
Expand Down Expand Up @@ -344,7 +344,7 @@ class SettingsDebugFragment : Fragment(R.layout.settings_debug) {
message.append(context.cacheDir?.isDirectory ?: false)
message.append("\n")

AlertDialog.Builder(context)
MaterialAlertDialogBuilder(context)
.setTitle("Cache Directory")
.setMessage(message.toString())
.show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import android.os.Bundle
import android.widget.ImageView
import android.widget.Toast
import androidx.annotation.StringRes
import androidx.appcompat.app.AlertDialog
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.app.TxContextWrappingDelegate
Expand Down Expand Up @@ -773,7 +773,7 @@ class AudioBookPlayerActivity :
}

private fun loanReturnShowDialog() {
val alert = AlertDialog.Builder(this)
val alert = MaterialAlertDialogBuilder(this)
alert.setTitle(R.string.audio_book_player_return_title)
alert.setMessage(R.string.audio_book_player_return_question)
alert.setNegativeButton(R.string.audio_book_player_do_keep) { dialog, _ ->
Expand Down Expand Up @@ -875,9 +875,7 @@ class AudioBookPlayerActivity :
*/

this.uiThread.runOnUIThread {
this.supportActionBar?.setTitle(
org.librarysimplified.audiobook.views.R.string.audiobook_player_toc_title
)
this.supportActionBar?.setTitle(R.string.audio_book_player_toc_title)

val fragment = PlayerTOCFragment.newInstance()

Expand Down Expand Up @@ -1049,7 +1047,7 @@ class AudioBookPlayerActivity :
this.log.error("error: {}: ", title, failure)

this.uiThread.runOnUIThread {
AlertDialog.Builder(context)
MaterialAlertDialogBuilder(context)
.setTitle(title)
.setMessage(failure.localizedMessage)
.setOnDismissListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
<string name="audio_book_player_error_engine_open">Unable to initialize audio engine</string>
<string name="audio_book_player_return_question">Would you like to return it?</string>
<string name="audio_book_player_return_title">Your Audiobook Has Finished</string>
<string name="audio_book_player_toc_title">Table Of Contents</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import android.os.Bundle
import android.webkit.WebView
import android.widget.Toast
import androidx.annotation.StringRes
import androidx.appcompat.app.AlertDialog
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.app.TxContextWrappingDelegate
Expand Down Expand Up @@ -392,7 +392,7 @@ class Reader2Activity : AppCompatActivity(R.layout.reader2) {
localLastReadBookmark: SR2Bookmark,
serverLastReadBookmark: SR2Bookmark
) {
AlertDialog.Builder(this)
MaterialAlertDialogBuilder(this)
.setTitle(R.string.reader_position_title)
.setMessage(R.string.reader_position_message)
.setNegativeButton(R.string.reader_position_move) { dialog, _ ->
Expand Down Expand Up @@ -617,7 +617,7 @@ class Reader2Activity : AppCompatActivity(R.layout.reader2) {
exception
}

AlertDialog.Builder(this)
MaterialAlertDialogBuilder(this)
.setTitle(R.string.bookOpenFailedTitle)
.setMessage(
this.getString(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import android.webkit.JavascriptInterface
import android.webkit.WebView
import android.widget.FrameLayout
import android.widget.ProgressBar
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.common.util.concurrent.MoreExecutors
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
Expand Down Expand Up @@ -194,7 +194,7 @@ class PdfReaderActivity : AppCompatActivity() {
params: PdfReaderParameters,
isSavedInstanceStateNull: Boolean
) {
AlertDialog.Builder(this)
MaterialAlertDialogBuilder(this)
.setTitle(R.string.viewer_position_title)
.setMessage(R.string.viewer_position_message)
.setNegativeButton(R.string.viewer_position_move) { dialog, _ ->
Expand Down Expand Up @@ -421,7 +421,7 @@ class PdfReaderActivity : AppCompatActivity() {
this.log.error("error: {}: ", title, failure)

this.uiThread.runOnUIThread {
AlertDialog.Builder(context)
MaterialAlertDialogBuilder(context)
.setTitle(title)
.setMessage(failure.localizedMessage)
.setOnDismissListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import android.os.Bundle
import android.widget.FrameLayout
import android.widget.ProgressBar
import androidx.activity.viewModels
import androidx.appcompat.app.AlertDialog
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.app.TxContextWrappingDelegate
Expand Down Expand Up @@ -208,7 +208,7 @@ class BookPreviewActivity : AppCompatActivity(R.layout.activity_book_preview) {
}

private fun handlePreviewDownloadFailed() {
AlertDialog.Builder(this)
MaterialAlertDialogBuilder(this)
.setTitle(R.string.bookPreviewFailedTitle)
.setMessage(R.string.bookPreviewFailedMessage)
.setOnDismissListener { this.onBackPressed() }
Expand Down

0 comments on commit 08f8376

Please sign in to comment.