mirror of
https://github.com/ankidroid/Anki-Android.git
synced 2024-09-20 20:03:05 +02:00
refactor: Kotlin - fix nullability
This is before converting 'Utils.java' **Collection:** * setUserFlag * genCards * cardCount * emptyCardReport * updateFieldCache **BaseSched:** * remFromDyn **Anki2Importer:** * _writeDstMedia
This commit is contained in:
parent
14cdd72f34
commit
8ce99c0e2b
@ -757,19 +757,19 @@ open class Collection(
|
||||
*/
|
||||
@KotlinCleanup("Check CollectionTask<Int?, Int> - should be fine")
|
||||
@KotlinCleanup("change to ArrayList!")
|
||||
fun genCards(nids: kotlin.collections.Collection<Long?>?, model: Model): ArrayList<Long>? {
|
||||
fun genCards(nids: kotlin.collections.Collection<Long>, model: Model): ArrayList<Long>? {
|
||||
return genCards<CollectionTask<Int?, Int>>(Utils.collection2Array(nids), model)
|
||||
}
|
||||
|
||||
fun <T> genCards(
|
||||
nids: kotlin.collections.Collection<Long?>?,
|
||||
nids: kotlin.collections.Collection<Long>,
|
||||
model: Model,
|
||||
task: T?
|
||||
): ArrayList<Long>? where T : ProgressSender<Int?>?, T : CancelListener? {
|
||||
return genCards(Utils.collection2Array(nids), model, task)
|
||||
}
|
||||
|
||||
fun genCards(nids: kotlin.collections.Collection<Long?>?, mid: NoteTypeId): ArrayList<Long>? {
|
||||
fun genCards(nids: kotlin.collections.Collection<Long>, mid: NoteTypeId): ArrayList<Long>? {
|
||||
return genCards(nids, models.get(mid)!!)
|
||||
}
|
||||
|
||||
@ -789,7 +789,7 @@ open class Collection(
|
||||
*/
|
||||
@JvmOverloads
|
||||
fun <T> genCards(
|
||||
nids: LongArray?,
|
||||
nids: LongArray,
|
||||
model: Model,
|
||||
task: T? = null
|
||||
): ArrayList<Long>? where T : ProgressSender<Int?>?, T : CancelListener? {
|
||||
@ -1036,11 +1036,11 @@ open class Collection(
|
||||
}
|
||||
|
||||
// NOT IN LIBANKI //
|
||||
fun cardCount(vararg dids: Long?): Int {
|
||||
fun cardCount(vararg dids: Long): Int {
|
||||
return db.queryScalar("SELECT count() FROM cards WHERE did IN " + Utils.ids2str(dids))
|
||||
}
|
||||
|
||||
fun isEmptyDeck(vararg dids: Long?): Boolean {
|
||||
fun isEmptyDeck(vararg dids: Long): Boolean {
|
||||
return cardCount(*dids) == 0
|
||||
}
|
||||
|
||||
@ -1080,7 +1080,7 @@ open class Collection(
|
||||
return rem
|
||||
}
|
||||
|
||||
fun emptyCardReport(cids: List<Long>?): String {
|
||||
fun emptyCardReport(cids: List<Long>): String {
|
||||
val rep = StringBuilder()
|
||||
db.query(
|
||||
"select group_concat(ord+1), count(), flds from cards c, notes n " +
|
||||
@ -1122,7 +1122,7 @@ open class Collection(
|
||||
/** Update field checksums and sort cache, after find&replace, etc.
|
||||
* @param nids
|
||||
*/
|
||||
fun updateFieldCache(nids: kotlin.collections.Collection<Long>?) {
|
||||
fun updateFieldCache(nids: kotlin.collections.Collection<Long>) {
|
||||
val snids = Utils.ids2str(nids)
|
||||
updateFieldCache(snids)
|
||||
}
|
||||
@ -1130,7 +1130,7 @@ open class Collection(
|
||||
/** Update field checksums and sort cache, after find&replace, etc.
|
||||
* @param nids
|
||||
*/
|
||||
fun updateFieldCache(nids: LongArray?) {
|
||||
fun updateFieldCache(nids: LongArray) {
|
||||
val snids = Utils.ids2str(nids)
|
||||
updateFieldCache(snids)
|
||||
}
|
||||
@ -2307,7 +2307,7 @@ open class Collection(
|
||||
/**
|
||||
* Card Flags *****************************************************************************************************
|
||||
*/
|
||||
fun setUserFlag(flag: Int, cids: List<Long>?) {
|
||||
fun setUserFlag(flag: Int, cids: List<Long>) {
|
||||
assert(0 <= flag && flag <= 7)
|
||||
db.execute(
|
||||
"update cards set flags = (flags & ~?) | ?, usn=?, mod=? where id in " + Utils.ids2str(
|
||||
|
@ -719,7 +719,7 @@ open class Anki2Importer(col: Collection?, file: String) : Importer(col!!, file)
|
||||
return _mediaData(fname, dst.media.dir())
|
||||
}
|
||||
|
||||
private fun _writeDstMedia(fname: String?, data: BufferedInputStream) {
|
||||
private fun _writeDstMedia(fname: String, data: BufferedInputStream) {
|
||||
try {
|
||||
val path = File(dst.media.dir(), Utils.nfcNormalized(fname)).absolutePath
|
||||
Utils.writeToFile(data, path)
|
||||
|
@ -11,10 +11,7 @@ import com.ichi2.libanki.*
|
||||
import com.ichi2.libanki.template.ParsedNode
|
||||
import com.ichi2.libanki.utils.StringUtils
|
||||
import com.ichi2.libanki.utils.TimeManager
|
||||
import com.ichi2.utils.Assert
|
||||
import com.ichi2.utils.HashUtil
|
||||
import com.ichi2.utils.HtmlUtils
|
||||
import com.ichi2.utils.JSONObject
|
||||
import com.ichi2.utils.*
|
||||
|
||||
// Ported from https://github.com/ankitects/anki/blob/50fdf9b03dec33c99a501f332306f378db5eb4ea/pylib/anki/importing/noteimp.py
|
||||
// Aside from 9f676dbe0b2ad9b87a3bf89d7735b4253abd440e, which allows empty notes.
|
||||
@ -37,6 +34,7 @@ open class NoteImporter(col: com.ichi2.libanki.Collection, file: String) : Impor
|
||||
|
||||
/** _nextID in python */
|
||||
private var mNextId: Long = 0
|
||||
@KotlinCleanup("maybe lateinit/nonnull")
|
||||
private var mIds: ArrayList<Long>? = null
|
||||
private var mEmptyNotes = false
|
||||
private var mUpdateCount = 0
|
||||
@ -210,9 +208,9 @@ open class NoteImporter(col: com.ichi2.libanki.Collection, file: String) : Impor
|
||||
addNew(_new)
|
||||
addUpdates(updates)
|
||||
// make sure to update sflds, etc
|
||||
mCol.updateFieldCache(mIds)
|
||||
mCol.updateFieldCache(mIds!!)
|
||||
// generate cards
|
||||
if (mCol.genCards(mIds, mModel)!!.isNotEmpty()) {
|
||||
if (mCol.genCards(mIds!!, mModel)!!.isNotEmpty()) {
|
||||
this.log.add(0, getString(R.string.note_importer_empty_cards_found))
|
||||
}
|
||||
|
||||
|
@ -388,7 +388,7 @@ abstract class BaseSched(val col: Collection) {
|
||||
"end)"
|
||||
}
|
||||
|
||||
fun remFromDyn(cids: Iterable<Long>?) {
|
||||
fun remFromDyn(cids: Iterable<Long>) {
|
||||
emptyDyn("id IN " + Utils.ids2str(cids) + " AND odid")
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user