Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions AnkiDroid/src/main/java/com/ichi2/anki/utils/ext/Context.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.ichi2.anki.utils.ext

import android.content.BroadcastReceiver
import android.content.Context
import android.content.res.TypedArray
import android.graphics.Bitmap
Expand All @@ -24,7 +23,6 @@ import android.util.AttributeSet
import androidx.annotation.AttrRes
import androidx.annotation.StyleRes
import com.ichi2.anki.CollectionHelper
import timber.log.Timber
import java.io.File
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
Expand All @@ -51,21 +49,6 @@ inline fun <T> Context.usingStyledAttributes(
return typedArray.block().also { typedArray.recycle() }
}

/**
* Unregisters a [BroadcastReceiver] from [Context] without throwing an [IllegalArgumentException]
* if the receiver wasn't registered.
*
* @param receiver [BroadcastReceiver] to unregister
* @see Context.unregisterReceiver
*/
fun Context.unregisterReceiverSilently(receiver: BroadcastReceiver) {
try {
unregisterReceiver(receiver)
} catch (e: IllegalArgumentException) {
Timber.d(e, "BroadcastReceiver was not previously registered")
}
}

/**
* Encapsulates the dimensions of a [Bitmap].
* Note: width and height might be set to -1 if there are errors when decoding the file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ import androidx.core.os.BundleCompat
import com.ichi2.anki.AnkiActivity
import com.ichi2.anki.R
import com.ichi2.anki.android.AnkiBroadcastReceiver
import com.ichi2.anki.common.utils.ext.unregisterReceiverSilently
import com.ichi2.anki.databinding.ActivityCardAnalysisWidgetConfigBinding
import com.ichi2.anki.dialogs.DeckSelectionDialog
import com.ichi2.anki.dialogs.DeckSelectionDialog.DeckSelectionListener
import com.ichi2.anki.isCollectionEmpty
import com.ichi2.anki.launchCatchingTask
import com.ichi2.anki.model.SelectableDeck
import com.ichi2.anki.showThemedToast
import com.ichi2.anki.utils.ext.unregisterReceiverSilently
import com.ichi2.anki.withProgress
import com.ichi2.widget.AppWidgetId.Companion.INVALID_APPWIDGET_ID
import com.ichi2.widget.AppWidgetId.Companion.getAppWidgetId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.google.android.material.snackbar.Snackbar
import com.ichi2.anki.AnkiActivity
import com.ichi2.anki.R
import com.ichi2.anki.android.AnkiBroadcastReceiver
import com.ichi2.anki.common.utils.ext.unregisterReceiverSilently
import com.ichi2.anki.databinding.WidgetDeckPickerConfigBinding
import com.ichi2.anki.dialogs.DeckSelectionDialog
import com.ichi2.anki.dialogs.DeckSelectionDialog.DeckSelectionListener
Expand All @@ -45,7 +46,6 @@ import com.ichi2.anki.showThemedToast
import com.ichi2.anki.snackbar.BaseSnackbarBuilderProvider
import com.ichi2.anki.snackbar.SnackbarBuilder
import com.ichi2.anki.snackbar.showSnackbar
import com.ichi2.anki.utils.ext.unregisterReceiverSilently
import com.ichi2.widget.AppWidgetId.Companion.INVALID_APPWIDGET_ID
import com.ichi2.widget.AppWidgetId.Companion.getAppWidgetId
import com.ichi2.widget.AppWidgetId.Companion.updateWidget
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2025 Brayan Oliveira <69634269+brayandso@users.noreply.github.com>
*
* This program 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.
*
* This program 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
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.ichi2.anki.common.utils.ext

import android.content.BroadcastReceiver
import android.content.Context
import timber.log.Timber

/**
* Unregisters a [BroadcastReceiver] from [Context] without throwing an [IllegalArgumentException]
* if the receiver wasn't registered.
*
* @param receiver [BroadcastReceiver] to unregister
* @see Context.unregisterReceiver
*/
fun Context.unregisterReceiverSilently(receiver: BroadcastReceiver) {
try {
unregisterReceiver(receiver)
} catch (e: IllegalArgumentException) {
Timber.d(e, "BroadcastReceiver was not previously registered")
}
}
Loading