forked from ankidroid/Anki-Android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup the DeckRenameException in libanki
Changes: - extract the DeckRenameException.getLocalizedName() method to a top level function in the anki package where it was used. This enables to further decouple the libanki package from android.* dependencies. - various cleanups to fix code style/improve syntax
- Loading branch information
Showing
4 changed files
with
23 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 11 additions & 22 deletions
33
AnkiDroid/src/main/java/com/ichi2/libanki/backend/exception/DeckRenameException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,30 @@ | ||
//noinspection MissingCopyrightHeader #8659 | ||
package com.ichi2.libanki.backend.exception | ||
|
||
import android.content.res.Resources | ||
import com.ichi2.anki.R | ||
|
||
class DeckRenameException | ||
(private val errorCode: Int) : Exception() { | ||
class DeckRenameException(val errorCode: Int) : Exception() { | ||
// region only if FILTERED_NOSUBDECKS | ||
private var mFilteredAncestorName: String? = null | ||
private var mDeckName: String? = null | ||
private var filteredAncestorName: String? = null | ||
private var deckName: String? = null | ||
// endregion | ||
|
||
override val message: String? | ||
get() = if (errorCode == FILTERED_NOSUBDECKS) { | ||
"Deck $mDeckName has filtered ancestor $mFilteredAncestorName" | ||
"Deck $deckName has filtered ancestor $filteredAncestorName" | ||
} else { | ||
super.message | ||
} | ||
|
||
fun getLocalizedMessage(res: Resources): String { | ||
return when (errorCode) { | ||
ALREADY_EXISTS -> res.getString(R.string.decks_rename_exists) | ||
FILTERED_NOSUBDECKS -> res.getString(R.string.decks_rename_filtered_nosubdecks) | ||
else -> "" | ||
} | ||
} | ||
|
||
companion object { | ||
const val ALREADY_EXISTS = 0 | ||
private const val FILTERED_NOSUBDECKS = 1 | ||
const val FILTERED_NOSUBDECKS = 1 | ||
|
||
/** Generates a {@link com.ichi2.libanki.backend.exception.DeckRenameException} with additional information in the message */ | ||
fun filteredAncestor(deckName: String?, filteredAncestorName: String?): DeckRenameException { | ||
val ex = DeckRenameException(FILTERED_NOSUBDECKS) | ||
ex.mFilteredAncestorName = filteredAncestorName | ||
ex.mDeckName = deckName | ||
return ex | ||
fun filteredAncestor( | ||
deckName: String?, | ||
filteredAncestorName: String? | ||
): DeckRenameException = DeckRenameException(FILTERED_NOSUBDECKS).apply { | ||
this.filteredAncestorName = filteredAncestorName | ||
this.deckName = deckName | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters