mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-18 16:03:12 +00:00
add comment and deal with some warnings in code that will likely be removed
This commit is contained in:
parent
42ee6639b0
commit
11655eea26
6 changed files with 130 additions and 167 deletions
|
@ -84,17 +84,17 @@ class ActionBatch {
|
|||
return
|
||||
}
|
||||
DebugLogUtils.l("Enabling word list")
|
||||
val db: SQLiteDatabase = MetadataDbHelper.Companion.getDb(context, mClientId)
|
||||
val values: ContentValues = MetadataDbHelper.Companion.getContentValuesByWordListId(db,
|
||||
val db: SQLiteDatabase = MetadataDbHelper.getDb(context, mClientId)
|
||||
val values: ContentValues = MetadataDbHelper.getContentValuesByWordListId(db,
|
||||
mWordList.mId, mWordList.mVersion)!!
|
||||
val status = values.getAsInteger(MetadataDbHelper.Companion.STATUS_COLUMN)
|
||||
if (MetadataDbHelper.Companion.STATUS_DISABLED != status
|
||||
&& MetadataDbHelper.Companion.STATUS_DELETING != status) {
|
||||
val status = values.getAsInteger(MetadataDbHelper.STATUS_COLUMN)
|
||||
if (MetadataDbHelper.STATUS_DISABLED != status
|
||||
&& MetadataDbHelper.STATUS_DELETING != status) {
|
||||
Log.e(TAG, "Unexpected state of the word list '" + mWordList.mId + " : " + status
|
||||
+ " for an enable action. Cancelling")
|
||||
return
|
||||
}
|
||||
MetadataDbHelper.Companion.markEntryAsEnabled(db, mWordList.mId, mWordList.mVersion)
|
||||
MetadataDbHelper.markEntryAsEnabled(db, mWordList.mId, mWordList.mVersion)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
@ -122,14 +122,14 @@ class ActionBatch {
|
|||
return
|
||||
}
|
||||
DebugLogUtils.l("Disabling word list : $mWordList")
|
||||
val db: SQLiteDatabase = MetadataDbHelper.Companion.getDb(context, mClientId)
|
||||
val values: ContentValues = MetadataDbHelper.Companion.getContentValuesByWordListId(db,
|
||||
val db: SQLiteDatabase = MetadataDbHelper.getDb(context, mClientId)
|
||||
val values: ContentValues = MetadataDbHelper.getContentValuesByWordListId(db,
|
||||
mWordList.mId, mWordList.mVersion)!!
|
||||
val status = values.getAsInteger(MetadataDbHelper.Companion.STATUS_COLUMN)
|
||||
if (MetadataDbHelper.Companion.STATUS_INSTALLED == status) { // Disabling an installed word list
|
||||
MetadataDbHelper.Companion.markEntryAsDisabled(db, mWordList.mId, mWordList.mVersion)
|
||||
val status = values.getAsInteger(MetadataDbHelper.STATUS_COLUMN)
|
||||
if (MetadataDbHelper.STATUS_INSTALLED == status) { // Disabling an installed word list
|
||||
MetadataDbHelper.markEntryAsDisabled(db, mWordList.mId, mWordList.mVersion)
|
||||
} else {
|
||||
if (MetadataDbHelper.Companion.STATUS_DOWNLOADING != status) {
|
||||
if (MetadataDbHelper.STATUS_DOWNLOADING != status) {
|
||||
Log.e(TAG, "Unexpected state of the word list '" + mWordList.mId + "' : "
|
||||
+ status + " for a disable action. Fall back to marking as available.")
|
||||
}
|
||||
|
@ -162,8 +162,8 @@ class ActionBatch {
|
|||
Log.e(TAG, "MakeAvailableAction with a null word list!")
|
||||
return
|
||||
}
|
||||
val db: SQLiteDatabase = MetadataDbHelper.Companion.getDb(context, mClientId)
|
||||
if (null != MetadataDbHelper.Companion.getContentValuesByWordListId(db,
|
||||
val db: SQLiteDatabase = MetadataDbHelper.getDb(context, mClientId)
|
||||
if (null != MetadataDbHelper.getContentValuesByWordListId(db,
|
||||
mWordList.mId, mWordList.mVersion)) {
|
||||
Log.e(TAG, "Unexpected state of the word list '" + mWordList.mId + "' "
|
||||
+ " for a makeavailable action. Marking as available anyway.")
|
||||
|
@ -171,8 +171,8 @@ class ActionBatch {
|
|||
DebugLogUtils.l("Making word list available : $mWordList")
|
||||
// If mLocalFilename is null, then it's a remote file that hasn't been downloaded
|
||||
// yet, so we set the local filename to the empty string.
|
||||
val values: ContentValues = MetadataDbHelper.Companion.makeContentValues(0,
|
||||
MetadataDbHelper.Companion.TYPE_BULK, MetadataDbHelper.Companion.STATUS_AVAILABLE,
|
||||
val values: ContentValues = MetadataDbHelper.makeContentValues(0,
|
||||
MetadataDbHelper.TYPE_BULK, MetadataDbHelper.STATUS_AVAILABLE,
|
||||
mWordList.mId, mWordList.mLocale, mWordList.mDescription,
|
||||
mWordList.mLocalFilename ?: "",
|
||||
mWordList.mRemoteFilename, mWordList.mLastUpdate, mWordList.mRawChecksum,
|
||||
|
@ -180,7 +180,7 @@ class ActionBatch {
|
|||
mWordList.mVersion, mWordList.mFormatVersion)
|
||||
PrivateLog.log("Insert 'available' record for " + mWordList.mDescription
|
||||
+ " and locale " + mWordList.mLocale)
|
||||
db.insert(MetadataDbHelper.Companion.METADATA_TABLE_NAME, null, values)
|
||||
db.insert(MetadataDbHelper.METADATA_TABLE_NAME, null, values)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
@ -214,8 +214,8 @@ class ActionBatch {
|
|||
Log.e(TAG, "MarkPreInstalledAction with a null word list!")
|
||||
return
|
||||
}
|
||||
val db: SQLiteDatabase = MetadataDbHelper.Companion.getDb(context, mClientId)
|
||||
if (null != MetadataDbHelper.Companion.getContentValuesByWordListId(db,
|
||||
val db: SQLiteDatabase = MetadataDbHelper.getDb(context, mClientId)
|
||||
if (null != MetadataDbHelper.getContentValuesByWordListId(db,
|
||||
mWordList.mId, mWordList.mVersion)) {
|
||||
Log.e(TAG, "Unexpected state of the word list '" + mWordList.mId + "' "
|
||||
+ " for a markpreinstalled action. Marking as preinstalled anyway.")
|
||||
|
@ -224,8 +224,8 @@ class ActionBatch {
|
|||
// This word list is pre-installed : we don't have its file. We should reset
|
||||
// the local file name to the empty string so that we don't try to open it
|
||||
// accidentally. The remote filename may be set by the application if it so wishes.
|
||||
val values: ContentValues = MetadataDbHelper.Companion.makeContentValues(0,
|
||||
MetadataDbHelper.Companion.TYPE_BULK, MetadataDbHelper.Companion.STATUS_INSTALLED,
|
||||
val values: ContentValues = MetadataDbHelper.makeContentValues(0,
|
||||
MetadataDbHelper.TYPE_BULK, MetadataDbHelper.STATUS_INSTALLED,
|
||||
mWordList.mId, mWordList.mLocale, mWordList.mDescription,
|
||||
if (TextUtils.isEmpty(mWordList.mLocalFilename)) "" else mWordList.mLocalFilename,
|
||||
mWordList.mRemoteFilename, mWordList.mLastUpdate,
|
||||
|
@ -233,7 +233,7 @@ class ActionBatch {
|
|||
mWordList.mFileSize, mWordList.mVersion, mWordList.mFormatVersion)
|
||||
PrivateLog.log("Insert 'preinstalled' record for " + mWordList.mDescription
|
||||
+ " and locale " + mWordList.mLocale)
|
||||
db.insert(MetadataDbHelper.Companion.METADATA_TABLE_NAME, null, values)
|
||||
db.insert(MetadataDbHelper.METADATA_TABLE_NAME, null, values)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
@ -259,28 +259,28 @@ class ActionBatch {
|
|||
Log.e(TAG, "UpdateDataAction with a null word list!")
|
||||
return
|
||||
}
|
||||
val db: SQLiteDatabase = MetadataDbHelper.Companion.getDb(context, mClientId)
|
||||
val oldValues: ContentValues = MetadataDbHelper.Companion.getContentValuesByWordListId(db,
|
||||
val db: SQLiteDatabase = MetadataDbHelper.getDb(context, mClientId)
|
||||
val oldValues: ContentValues = MetadataDbHelper.getContentValuesByWordListId(db,
|
||||
mWordList.mId, mWordList.mVersion)!!
|
||||
if (null == oldValues) {
|
||||
Log.e(TAG, "Trying to update data about a non-existing word list. Bailing out.")
|
||||
return
|
||||
}
|
||||
DebugLogUtils.l("Updating data about a word list : $mWordList")
|
||||
val values: ContentValues = MetadataDbHelper.Companion.makeContentValues(
|
||||
oldValues.getAsInteger(MetadataDbHelper.Companion.PENDINGID_COLUMN),
|
||||
oldValues.getAsInteger(MetadataDbHelper.Companion.TYPE_COLUMN),
|
||||
oldValues.getAsInteger(MetadataDbHelper.Companion.STATUS_COLUMN),
|
||||
val values: ContentValues = MetadataDbHelper.makeContentValues(
|
||||
oldValues.getAsInteger(MetadataDbHelper.PENDINGID_COLUMN),
|
||||
oldValues.getAsInteger(MetadataDbHelper.TYPE_COLUMN),
|
||||
oldValues.getAsInteger(MetadataDbHelper.STATUS_COLUMN),
|
||||
mWordList.mId, mWordList.mLocale, mWordList.mDescription,
|
||||
oldValues.getAsString(MetadataDbHelper.Companion.LOCAL_FILENAME_COLUMN),
|
||||
oldValues.getAsString(MetadataDbHelper.LOCAL_FILENAME_COLUMN),
|
||||
mWordList.mRemoteFilename, mWordList.mLastUpdate, mWordList.mRawChecksum,
|
||||
mWordList.mChecksum, mWordList.mRetryCount, mWordList.mFileSize,
|
||||
mWordList.mVersion, mWordList.mFormatVersion)
|
||||
PrivateLog.log("Updating record for " + mWordList.mDescription
|
||||
+ " and locale " + mWordList.mLocale)
|
||||
db.update(MetadataDbHelper.Companion.METADATA_TABLE_NAME, values,
|
||||
MetadataDbHelper.Companion.WORDLISTID_COLUMN + " = ? AND "
|
||||
+ MetadataDbHelper.Companion.VERSION_COLUMN + " = ?", arrayOf(mWordList.mId, Integer.toString(mWordList.mVersion)))
|
||||
db.update(MetadataDbHelper.METADATA_TABLE_NAME, values,
|
||||
MetadataDbHelper.WORDLISTID_COLUMN + " = ? AND "
|
||||
+ MetadataDbHelper.VERSION_COLUMN + " = ?", arrayOf(mWordList.mId, Integer.toString(mWordList.mVersion)))
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
@ -314,34 +314,34 @@ class ActionBatch {
|
|||
return
|
||||
}
|
||||
DebugLogUtils.l("Trying to remove word list : $mWordList")
|
||||
val db: SQLiteDatabase = MetadataDbHelper.Companion.getDb(context, mClientId)
|
||||
val values: ContentValues = MetadataDbHelper.Companion.getContentValuesByWordListId(db,
|
||||
val db: SQLiteDatabase = MetadataDbHelper.getDb(context, mClientId)
|
||||
val values: ContentValues = MetadataDbHelper.getContentValuesByWordListId(db,
|
||||
mWordList.mId, mWordList.mVersion)!!
|
||||
if (null == values) {
|
||||
Log.e(TAG, "Trying to update the metadata of a non-existing wordlist. Cancelling.")
|
||||
return
|
||||
}
|
||||
val status = values.getAsInteger(MetadataDbHelper.Companion.STATUS_COLUMN)
|
||||
if (mHasNewerVersion && MetadataDbHelper.Companion.STATUS_AVAILABLE != status) { // If we have a newer version of this word list, we should be here ONLY if it was
|
||||
val status = values.getAsInteger(MetadataDbHelper.STATUS_COLUMN)
|
||||
if (mHasNewerVersion && MetadataDbHelper.STATUS_AVAILABLE != status) { // If we have a newer version of this word list, we should be here ONLY if it was
|
||||
// not installed - else we should be upgrading it.
|
||||
Log.e(TAG, "Unexpected status for forgetting a word list info : " + status
|
||||
+ ", removing URL to prevent re-download")
|
||||
}
|
||||
if (MetadataDbHelper.Companion.STATUS_INSTALLED == status || MetadataDbHelper.Companion.STATUS_DISABLED == status || MetadataDbHelper.Companion.STATUS_DELETING == status) { // If it is installed or disabled, we need to mark it as deleted so that LatinIME
|
||||
if (MetadataDbHelper.STATUS_INSTALLED == status || MetadataDbHelper.STATUS_DISABLED == status || MetadataDbHelper.STATUS_DELETING == status) { // If it is installed or disabled, we need to mark it as deleted so that LatinIME
|
||||
// will remove it next time it enquires for dictionaries.
|
||||
// If it is deleting and we don't have a new version, then we have to wait until
|
||||
// LatinIME actually has deleted it before we can remove its metadata.
|
||||
// In both cases, remove the URI from the database since it is not supposed to
|
||||
// be accessible any more.
|
||||
values.put(MetadataDbHelper.Companion.REMOTE_FILENAME_COLUMN, "")
|
||||
values.put(MetadataDbHelper.Companion.STATUS_COLUMN, MetadataDbHelper.Companion.STATUS_DELETING)
|
||||
db.update(MetadataDbHelper.Companion.METADATA_TABLE_NAME, values,
|
||||
MetadataDbHelper.Companion.WORDLISTID_COLUMN + " = ? AND "
|
||||
+ MetadataDbHelper.Companion.VERSION_COLUMN + " = ?", arrayOf(mWordList.mId, Integer.toString(mWordList.mVersion)))
|
||||
values.put(MetadataDbHelper.REMOTE_FILENAME_COLUMN, "")
|
||||
values.put(MetadataDbHelper.STATUS_COLUMN, MetadataDbHelper.STATUS_DELETING)
|
||||
db.update(MetadataDbHelper.METADATA_TABLE_NAME, values,
|
||||
MetadataDbHelper.WORDLISTID_COLUMN + " = ? AND "
|
||||
+ MetadataDbHelper.VERSION_COLUMN + " = ?", arrayOf(mWordList.mId, Integer.toString(mWordList.mVersion)))
|
||||
} else { // If it's AVAILABLE or DOWNLOADING or even UNKNOWN, delete the entry.
|
||||
db.delete(MetadataDbHelper.Companion.METADATA_TABLE_NAME,
|
||||
MetadataDbHelper.Companion.WORDLISTID_COLUMN + " = ? AND "
|
||||
+ MetadataDbHelper.Companion.VERSION_COLUMN + " = ?", arrayOf(mWordList.mId, Integer.toString(mWordList.mVersion)))
|
||||
db.delete(MetadataDbHelper.METADATA_TABLE_NAME,
|
||||
MetadataDbHelper.WORDLISTID_COLUMN + " = ? AND "
|
||||
+ MetadataDbHelper.VERSION_COLUMN + " = ?", arrayOf(mWordList.mId, Integer.toString(mWordList.mVersion)))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -382,18 +382,18 @@ class ActionBatch {
|
|||
return
|
||||
}
|
||||
DebugLogUtils.l("Trying to delete word list : $mWordList")
|
||||
val db: SQLiteDatabase = MetadataDbHelper.Companion.getDb(context, mClientId)
|
||||
val values: ContentValues = MetadataDbHelper.Companion.getContentValuesByWordListId(db,
|
||||
val db: SQLiteDatabase = MetadataDbHelper.getDb(context, mClientId)
|
||||
val values: ContentValues = MetadataDbHelper.getContentValuesByWordListId(db,
|
||||
mWordList.mId, mWordList.mVersion)!!
|
||||
if (null == values) {
|
||||
Log.e(TAG, "Trying to set a non-existing wordlist for removal. Cancelling.")
|
||||
return
|
||||
}
|
||||
val status = values.getAsInteger(MetadataDbHelper.Companion.STATUS_COLUMN)
|
||||
if (MetadataDbHelper.Companion.STATUS_DISABLED != status) {
|
||||
val status = values.getAsInteger(MetadataDbHelper.STATUS_COLUMN)
|
||||
if (MetadataDbHelper.STATUS_DISABLED != status) {
|
||||
Log.e(TAG, "Unexpected status for deleting a word list info : $status")
|
||||
}
|
||||
MetadataDbHelper.Companion.markEntryAsDeleting(db, mWordList.mId, mWordList.mVersion)
|
||||
MetadataDbHelper.markEntryAsDeleting(db, mWordList.mId, mWordList.mVersion)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
@ -424,28 +424,28 @@ class ActionBatch {
|
|||
return
|
||||
}
|
||||
DebugLogUtils.l("Trying to delete word list : $mWordList")
|
||||
val db: SQLiteDatabase = MetadataDbHelper.Companion.getDb(context, mClientId)
|
||||
val values: ContentValues = MetadataDbHelper.Companion.getContentValuesByWordListId(db,
|
||||
val db: SQLiteDatabase = MetadataDbHelper.getDb(context, mClientId)
|
||||
val values: ContentValues = MetadataDbHelper.getContentValuesByWordListId(db,
|
||||
mWordList.mId, mWordList.mVersion)!!
|
||||
if (null == values) {
|
||||
Log.e(TAG, "Trying to set a non-existing wordlist for removal. Cancelling.")
|
||||
return
|
||||
}
|
||||
val status = values.getAsInteger(MetadataDbHelper.Companion.STATUS_COLUMN)
|
||||
if (MetadataDbHelper.Companion.STATUS_DELETING != status) {
|
||||
val status = values.getAsInteger(MetadataDbHelper.STATUS_COLUMN)
|
||||
if (MetadataDbHelper.STATUS_DELETING != status) {
|
||||
Log.e(TAG, "Unexpected status for finish-deleting a word list info : $status")
|
||||
}
|
||||
val remoteFilename = values.getAsString(MetadataDbHelper.Companion.REMOTE_FILENAME_COLUMN)
|
||||
val remoteFilename = values.getAsString(MetadataDbHelper.REMOTE_FILENAME_COLUMN)
|
||||
// If there isn't a remote filename any more, then we don't know where to get the file
|
||||
// from any more, so we remove the entry entirely. As a matter of fact, if the file was
|
||||
// marked DELETING but disappeared from the metadata on the server, it ended up
|
||||
// this way.
|
||||
if (TextUtils.isEmpty(remoteFilename)) {
|
||||
db.delete(MetadataDbHelper.Companion.METADATA_TABLE_NAME,
|
||||
MetadataDbHelper.Companion.WORDLISTID_COLUMN + " = ? AND "
|
||||
+ MetadataDbHelper.Companion.VERSION_COLUMN + " = ?", arrayOf(mWordList.mId, Integer.toString(mWordList.mVersion)))
|
||||
db.delete(MetadataDbHelper.METADATA_TABLE_NAME,
|
||||
MetadataDbHelper.WORDLISTID_COLUMN + " = ? AND "
|
||||
+ MetadataDbHelper.VERSION_COLUMN + " = ?", arrayOf(mWordList.mId, Integer.toString(mWordList.mVersion)))
|
||||
} else {
|
||||
MetadataDbHelper.Companion.markEntryAsAvailable(db, mWordList.mId, mWordList.mVersion)
|
||||
MetadataDbHelper.markEntryAsAvailable(db, mWordList.mId, mWordList.mVersion)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
package org.dslul.openboard.inputmethod.dictionarypack
|
||||
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Immutable class to hold the address of an asset.
|
||||
* As opposed to a normal file, an asset is usually represented as a contiguous byte array in
|
||||
* the package file. Open it correctly thus requires the name of the package it is in, but
|
||||
* also the offset in the file and the length of this data. This class encapsulates these three.
|
||||
*/
|
||||
internal class AssetFileAddress(val mFilename: String, val mOffset: Long, val mLength: Long) {
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Makes an AssetFileAddress. This may return null.
|
||||
*
|
||||
* @param filename the filename.
|
||||
* @return the address, or null if the file does not exist or the parameters are not valid.
|
||||
*/
|
||||
fun makeFromFileName(filename: String?): AssetFileAddress? {
|
||||
if (null == filename) return null
|
||||
val f = File(filename)
|
||||
return if (!f.isFile) null else AssetFileAddress(filename, 0L, f.length())
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an AssetFileAddress. This may return null.
|
||||
*
|
||||
* @param filename the filename.
|
||||
* @param offset the offset.
|
||||
* @param length the length.
|
||||
* @return the address, or null if the file does not exist or the parameters are not valid.
|
||||
*/
|
||||
fun makeFromFileNameAndOffset(filename: String?,
|
||||
offset: Long, length: Long): AssetFileAddress? {
|
||||
if (null == filename) return null
|
||||
val f = File(filename)
|
||||
return if (!f.isFile) null else AssetFileAddress(filename, offset, length)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -25,6 +25,7 @@ import java.util.*
|
|||
* This class is a ContentProvider exposing all available dictionary data as managed by
|
||||
* the dictionary pack.
|
||||
*/
|
||||
@Suppress("deprecation")
|
||||
class DictionaryProvider : ContentProvider() {
|
||||
companion object {
|
||||
private val TAG = DictionaryProvider::class.java.simpleName
|
||||
|
@ -97,7 +98,7 @@ class DictionaryProvider : ContentProvider() {
|
|||
val mWordLists: Array<WordListInfo>
|
||||
|
||||
override fun getColumnNames(): Array<String> {
|
||||
return Companion.columnNames
|
||||
return columnNames
|
||||
}
|
||||
|
||||
override fun getCount(): Int {
|
||||
|
@ -139,8 +140,8 @@ class DictionaryProvider : ContentProvider() {
|
|||
|
||||
companion object {
|
||||
// Column names for the cursor returned by this content provider.
|
||||
private val columnNames = arrayOf<String>(MetadataDbHelper.Companion.WORDLISTID_COLUMN,
|
||||
MetadataDbHelper.Companion.LOCALE_COLUMN, MetadataDbHelper.Companion.RAW_CHECKSUM_COLUMN)
|
||||
private val columnNames = arrayOf<String>(MetadataDbHelper.WORDLISTID_COLUMN,
|
||||
MetadataDbHelper.LOCALE_COLUMN, MetadataDbHelper.RAW_CHECKSUM_COLUMN)
|
||||
}
|
||||
|
||||
// Note : the cursor also uses mPos, which is defined in AbstractCursor.
|
||||
|
@ -196,7 +197,7 @@ class DictionaryProvider : ContentProvider() {
|
|||
val match = matchUri(uri)
|
||||
return when (match) {
|
||||
DICTIONARY_V1_WHOLE_LIST, DICTIONARY_V2_WHOLE_LIST -> {
|
||||
val c: Cursor = MetadataDbHelper.Companion.queryDictionaries(context, clientId)
|
||||
val c: Cursor = MetadataDbHelper.queryDictionaries(context, clientId)
|
||||
DebugLogUtils.l("List of dictionaries with count", c.count)
|
||||
PrivateLog.log("Returned a list of " + c.count + " items")
|
||||
c
|
||||
|
@ -204,7 +205,7 @@ class DictionaryProvider : ContentProvider() {
|
|||
DICTIONARY_V2_DICT_INFO -> {
|
||||
// In protocol version 2, we return null if the client is unknown. Otherwise
|
||||
// we behave exactly like for protocol 1.
|
||||
if (!MetadataDbHelper.Companion.isClientKnown(context, clientId)) return null
|
||||
if (!MetadataDbHelper.isClientKnown(context, clientId)) return null
|
||||
val locale = uri.lastPathSegment
|
||||
val dictFiles = getDictionaryWordListsForLocale(clientId, locale)
|
||||
// TODO: pass clientId to the following function
|
||||
|
@ -240,8 +241,8 @@ class DictionaryProvider : ContentProvider() {
|
|||
wordlistId: String?): ContentValues? {
|
||||
val context = context
|
||||
if (TextUtils.isEmpty(wordlistId)) return null
|
||||
val db: SQLiteDatabase = MetadataDbHelper.Companion.getDb(context, clientId)
|
||||
return MetadataDbHelper.Companion.getInstalledOrDeletingWordListContentValuesByWordListId(
|
||||
val db: SQLiteDatabase = MetadataDbHelper.getDb(context, clientId)
|
||||
return MetadataDbHelper.getInstalledOrDeletingWordListContentValuesByWordListId(
|
||||
db, wordlistId)
|
||||
}
|
||||
|
||||
|
@ -267,15 +268,15 @@ class DictionaryProvider : ContentProvider() {
|
|||
val clientId = getClientId(uri)
|
||||
val wordList = getWordlistMetadataForWordlistId(clientId, wordlistId) ?: return null
|
||||
try {
|
||||
val status = wordList.getAsInteger(MetadataDbHelper.Companion.STATUS_COLUMN)
|
||||
if (MetadataDbHelper.Companion.STATUS_DELETING == status) { // This will return an empty file (R.raw.empty points at an empty dictionary)
|
||||
val status = wordList.getAsInteger(MetadataDbHelper.STATUS_COLUMN)
|
||||
if (MetadataDbHelper.STATUS_DELETING == status) { // This will return an empty file (R.raw.empty points at an empty dictionary)
|
||||
// This is how we "delete" the files. It allows Android Keyboard to fake deleting
|
||||
// a default dictionary - which is actually in its assets and can't be really
|
||||
// deleted.
|
||||
return context!!.resources.openRawResourceFd(
|
||||
R.raw.empty)
|
||||
}
|
||||
val localFilename = wordList.getAsString(MetadataDbHelper.Companion.LOCAL_FILENAME_COLUMN)
|
||||
val localFilename = wordList.getAsString(MetadataDbHelper.LOCAL_FILENAME_COLUMN)
|
||||
val f = context!!.getFileStreamPath(localFilename)
|
||||
val pfd = ParcelFileDescriptor.open(f, ParcelFileDescriptor.MODE_READ_ONLY)
|
||||
return AssetFileDescriptor(pfd, 0, pfd.statSize)
|
||||
|
@ -300,15 +301,15 @@ class DictionaryProvider : ContentProvider() {
|
|||
private fun getDictionaryWordListsForLocale(clientId: String?,
|
||||
locale: String?): Collection<WordListInfo> {
|
||||
val context = context
|
||||
val results: Cursor = MetadataDbHelper.Companion.queryInstalledOrDeletingOrAvailableDictionaryMetadata(context,
|
||||
val results: Cursor = MetadataDbHelper.queryInstalledOrDeletingOrAvailableDictionaryMetadata(context,
|
||||
clientId)
|
||||
return try {
|
||||
val dicts = HashMap<String, WordListInfo>()
|
||||
val idIndex = results.getColumnIndex(MetadataDbHelper.Companion.WORDLISTID_COLUMN)
|
||||
val localeIndex = results.getColumnIndex(MetadataDbHelper.Companion.LOCALE_COLUMN)
|
||||
val localFileNameIndex = results.getColumnIndex(MetadataDbHelper.Companion.LOCAL_FILENAME_COLUMN)
|
||||
val rawChecksumIndex = results.getColumnIndex(MetadataDbHelper.Companion.RAW_CHECKSUM_COLUMN)
|
||||
val statusIndex = results.getColumnIndex(MetadataDbHelper.Companion.STATUS_COLUMN)
|
||||
val idIndex = results.getColumnIndex(MetadataDbHelper.WORDLISTID_COLUMN)
|
||||
val localeIndex = results.getColumnIndex(MetadataDbHelper.LOCALE_COLUMN)
|
||||
val localFileNameIndex = results.getColumnIndex(MetadataDbHelper.LOCAL_FILENAME_COLUMN)
|
||||
val rawChecksumIndex = results.getColumnIndex(MetadataDbHelper.RAW_CHECKSUM_COLUMN)
|
||||
val statusIndex = results.getColumnIndex(MetadataDbHelper.STATUS_COLUMN)
|
||||
if (results.moveToFirst()) {
|
||||
do {
|
||||
val wordListId = results.getString(idIndex)
|
||||
|
@ -334,7 +335,7 @@ class DictionaryProvider : ContentProvider() {
|
|||
// Skip this wordlist and go to the next.
|
||||
continue
|
||||
}
|
||||
if (MetadataDbHelper.Companion.STATUS_INSTALLED == wordListStatus) { // If the file does not exist, it has been deleted and the IME should
|
||||
if (MetadataDbHelper.STATUS_INSTALLED == wordListStatus) { // If the file does not exist, it has been deleted and the IME should
|
||||
// already have it. Do not return it. However, this only applies if the
|
||||
// word list is INSTALLED, for if it is DELETING we should return it always
|
||||
// so that Android Keyboard can perform the actual deletion.
|
||||
|
@ -373,7 +374,7 @@ class DictionaryProvider : ContentProvider() {
|
|||
return deleteDataFile(uri)
|
||||
}
|
||||
return if (DICTIONARY_V2_METADATA == match) {
|
||||
if (MetadataDbHelper.Companion.deleteClient(context, getClientId(uri))) {
|
||||
if (MetadataDbHelper.deleteClient(context, getClientId(uri))) {
|
||||
1
|
||||
} else 0
|
||||
} else 0
|
||||
|
@ -384,8 +385,8 @@ class DictionaryProvider : ContentProvider() {
|
|||
val wordlistId = uri.lastPathSegment
|
||||
val clientId = getClientId(uri)
|
||||
val wordList = getWordlistMetadataForWordlistId(clientId, wordlistId) ?: return 0
|
||||
val status = wordList.getAsInteger(MetadataDbHelper.Companion.STATUS_COLUMN)
|
||||
val version = wordList.getAsInteger(MetadataDbHelper.Companion.VERSION_COLUMN)
|
||||
val status = wordList.getAsInteger(MetadataDbHelper.STATUS_COLUMN)
|
||||
val version = wordList.getAsInteger(MetadataDbHelper.VERSION_COLUMN)
|
||||
return 0
|
||||
}
|
||||
|
||||
|
@ -398,7 +399,7 @@ class DictionaryProvider : ContentProvider() {
|
|||
*/
|
||||
@Throws(UnsupportedOperationException::class)
|
||||
override fun insert(uri: Uri, values: ContentValues?): Uri? {
|
||||
if (null == uri || null == values) return null // Should never happen but let's be safe
|
||||
if (null == values) return null // Should never happen but let's be safe
|
||||
PrivateLog.log("Insert, uri = $uri")
|
||||
val clientId = getClientId(uri)
|
||||
when (matchUri(uri)) {
|
||||
|
@ -407,10 +408,10 @@ class DictionaryProvider : ContentProvider() {
|
|||
// is reserved for internal use.
|
||||
// The metadata URI may not be null, but it may be empty if the client does not
|
||||
// want the dictionary pack to update the metadata automatically.
|
||||
MetadataDbHelper.Companion.updateClientInfo(context, clientId, values)
|
||||
MetadataDbHelper.updateClientInfo(context, clientId, values)
|
||||
DICTIONARY_V2_DICT_INFO -> try {
|
||||
val newDictionaryMetadata: WordListMetadata = WordListMetadata.Companion.createFromContentValues(
|
||||
MetadataDbHelper.Companion.completeWithDefaultValues(values))
|
||||
val newDictionaryMetadata: WordListMetadata = WordListMetadata.createFromContentValues(
|
||||
MetadataDbHelper.completeWithDefaultValues(values))
|
||||
MarkPreInstalledAction(clientId, newDictionaryMetadata)
|
||||
.execute(context)
|
||||
} catch (e: BadFormatException) {
|
||||
|
|
|
@ -18,6 +18,11 @@ import java.util.*
|
|||
/**
|
||||
* Preference screen.
|
||||
*/
|
||||
// keep the fragment for now, as it may contain something useful on dictionary management, but
|
||||
// suppress warnings
|
||||
// todo: check this fragment, take what could be useful, and remove the fragment
|
||||
// same for WordListPreference and WordListMetadata
|
||||
@Suppress("deprecation")
|
||||
class DictionarySettingsFragment
|
||||
/**
|
||||
* Empty constructor for fragment generation.
|
||||
|
@ -149,12 +154,12 @@ class DictionarySettingsFragment
|
|||
}
|
||||
val systemLocaleString = Locale.getDefault().toString()
|
||||
val prefMap = TreeMap<String, WordListPreference>()
|
||||
val idIndex = cursor.getColumnIndex(MetadataDbHelper.Companion.WORDLISTID_COLUMN)
|
||||
val versionIndex = cursor.getColumnIndex(MetadataDbHelper.Companion.VERSION_COLUMN)
|
||||
val localeIndex = cursor.getColumnIndex(MetadataDbHelper.Companion.LOCALE_COLUMN)
|
||||
val descriptionIndex = cursor.getColumnIndex(MetadataDbHelper.Companion.DESCRIPTION_COLUMN)
|
||||
val statusIndex = cursor.getColumnIndex(MetadataDbHelper.Companion.STATUS_COLUMN)
|
||||
val filesizeIndex = cursor.getColumnIndex(MetadataDbHelper.Companion.FILESIZE_COLUMN)
|
||||
val idIndex = cursor.getColumnIndex(MetadataDbHelper.WORDLISTID_COLUMN)
|
||||
val versionIndex = cursor.getColumnIndex(MetadataDbHelper.VERSION_COLUMN)
|
||||
val localeIndex = cursor.getColumnIndex(MetadataDbHelper.LOCALE_COLUMN)
|
||||
val descriptionIndex = cursor.getColumnIndex(MetadataDbHelper.DESCRIPTION_COLUMN)
|
||||
val statusIndex = cursor.getColumnIndex(MetadataDbHelper.STATUS_COLUMN)
|
||||
val filesizeIndex = cursor.getColumnIndex(MetadataDbHelper.FILESIZE_COLUMN)
|
||||
do {
|
||||
val wordlistId = cursor.getString(idIndex)
|
||||
val version = cursor.getInt(versionIndex)
|
||||
|
@ -202,7 +207,7 @@ class DictionarySettingsFragment
|
|||
private val TAG = DictionarySettingsFragment::class.java.simpleName
|
||||
private const val DICT_LIST_ID = "list"
|
||||
const val DICT_SETTINGS_FRAGMENT_CLIENT_ID_ARGUMENT = "clientId"
|
||||
private const val MENU_UPDATE_NOW = Menu.FIRST
|
||||
// private const val MENU_UPDATE_NOW = Menu.FIRST
|
||||
private fun createErrorMessage(activity: Activity?, messageResource: Int): Preference {
|
||||
val message = Preference(activity)
|
||||
message.setTitle(messageResource)
|
||||
|
|
|
@ -51,20 +51,20 @@ class WordListMetadata // In milliseconds
|
|||
* If this lacks any required field, IllegalArgumentException is thrown.
|
||||
*/
|
||||
fun createFromContentValues(values: ContentValues): WordListMetadata {
|
||||
val id = values.getAsString(MetadataDbHelper.Companion.WORDLISTID_COLUMN)
|
||||
val type = values.getAsInteger(MetadataDbHelper.Companion.TYPE_COLUMN)
|
||||
val description = values.getAsString(MetadataDbHelper.Companion.DESCRIPTION_COLUMN)
|
||||
val lastUpdate = values.getAsLong(MetadataDbHelper.Companion.DATE_COLUMN)
|
||||
val fileSize = values.getAsLong(MetadataDbHelper.Companion.FILESIZE_COLUMN)
|
||||
val rawChecksum = values.getAsString(MetadataDbHelper.Companion.RAW_CHECKSUM_COLUMN)
|
||||
val checksum = values.getAsString(MetadataDbHelper.Companion.CHECKSUM_COLUMN)
|
||||
val retryCount = values.getAsInteger(MetadataDbHelper.Companion.RETRY_COUNT_COLUMN)
|
||||
val localFilename = values.getAsString(MetadataDbHelper.Companion.LOCAL_FILENAME_COLUMN)
|
||||
val remoteFilename = values.getAsString(MetadataDbHelper.Companion.REMOTE_FILENAME_COLUMN)
|
||||
val version = values.getAsInteger(MetadataDbHelper.Companion.VERSION_COLUMN)
|
||||
val formatVersion = values.getAsInteger(MetadataDbHelper.Companion.FORMATVERSION_COLUMN)
|
||||
val flags = values.getAsInteger(MetadataDbHelper.Companion.FLAGS_COLUMN)
|
||||
val locale = values.getAsString(MetadataDbHelper.Companion.LOCALE_COLUMN)
|
||||
val id = values.getAsString(MetadataDbHelper.WORDLISTID_COLUMN)
|
||||
val type = values.getAsInteger(MetadataDbHelper.TYPE_COLUMN)
|
||||
val description = values.getAsString(MetadataDbHelper.DESCRIPTION_COLUMN)
|
||||
val lastUpdate = values.getAsLong(MetadataDbHelper.DATE_COLUMN)
|
||||
val fileSize = values.getAsLong(MetadataDbHelper.FILESIZE_COLUMN)
|
||||
val rawChecksum = values.getAsString(MetadataDbHelper.RAW_CHECKSUM_COLUMN)
|
||||
val checksum = values.getAsString(MetadataDbHelper.CHECKSUM_COLUMN)
|
||||
val retryCount = values.getAsInteger(MetadataDbHelper.RETRY_COUNT_COLUMN)
|
||||
val localFilename = values.getAsString(MetadataDbHelper.LOCAL_FILENAME_COLUMN)
|
||||
val remoteFilename = values.getAsString(MetadataDbHelper.REMOTE_FILENAME_COLUMN)
|
||||
val version = values.getAsInteger(MetadataDbHelper.VERSION_COLUMN)
|
||||
val formatVersion = values.getAsInteger(MetadataDbHelper.FORMATVERSION_COLUMN)
|
||||
val flags = values.getAsInteger(MetadataDbHelper.FLAGS_COLUMN)
|
||||
val locale = values.getAsString(MetadataDbHelper.LOCALE_COLUMN)
|
||||
require(!(null == id || null == type || null == description || null == lastUpdate || null == fileSize || null == checksum || null == localFilename || null == remoteFilename || null == version || null == formatVersion || null == flags || null == locale))
|
||||
return WordListMetadata(id, type, description, lastUpdate, fileSize, rawChecksum,
|
||||
checksum, retryCount, localFilename, remoteFilename, version, formatVersion,
|
||||
|
|
|
@ -16,6 +16,7 @@ import java.util.*
|
|||
* pack. Upon being pressed, it displays a menu to allow the user to install, disable,
|
||||
* enable or delete it as appropriate for the current state of the word list.
|
||||
*/
|
||||
@Suppress("deprecation")
|
||||
class WordListPreference(context: Context?,
|
||||
private val mInterfaceState: DictionaryListInterfaceState, // The id of the client for which this preference is.
|
||||
private val mClientId: String?,
|
||||
|
@ -51,10 +52,10 @@ class WordListPreference(context: Context?,
|
|||
private fun getSummary(status: Int): String {
|
||||
val context = context
|
||||
return when (status) {
|
||||
MetadataDbHelper.Companion.STATUS_DELETING, MetadataDbHelper.Companion.STATUS_AVAILABLE -> context.getString(R.string.dictionary_available)
|
||||
MetadataDbHelper.Companion.STATUS_DOWNLOADING -> context.getString(R.string.dictionary_downloading)
|
||||
MetadataDbHelper.Companion.STATUS_INSTALLED -> context.getString(R.string.dictionary_installed)
|
||||
MetadataDbHelper.Companion.STATUS_DISABLED -> context.getString(R.string.dictionary_disabled)
|
||||
MetadataDbHelper.STATUS_DELETING, MetadataDbHelper.STATUS_AVAILABLE -> context.getString(R.string.dictionary_available)
|
||||
MetadataDbHelper.STATUS_DOWNLOADING -> context.getString(R.string.dictionary_downloading)
|
||||
MetadataDbHelper.STATUS_INSTALLED -> context.getString(R.string.dictionary_installed)
|
||||
MetadataDbHelper.STATUS_DISABLED -> context.getString(R.string.dictionary_disabled)
|
||||
else -> NO_STATUS_MESSAGE
|
||||
}
|
||||
}
|
||||
|
@ -63,11 +64,11 @@ class WordListPreference(context: Context?,
|
|||
val context = context
|
||||
val prefs = CommonPreferences.getCommonPreferences(context)
|
||||
CommonPreferences.disable(prefs, mWordlistId)
|
||||
if (MetadataDbHelper.Companion.STATUS_DOWNLOADING == mStatus) {
|
||||
setStatus(MetadataDbHelper.Companion.STATUS_AVAILABLE)
|
||||
} else if (MetadataDbHelper.Companion.STATUS_INSTALLED == mStatus) { // Interface-wise, we should no longer be able to come here. However, this is still
|
||||
if (MetadataDbHelper.STATUS_DOWNLOADING == mStatus) {
|
||||
setStatus(MetadataDbHelper.STATUS_AVAILABLE)
|
||||
} else if (MetadataDbHelper.STATUS_INSTALLED == mStatus) { // Interface-wise, we should no longer be able to come here. However, this is still
|
||||
// the right thing to do if we do come here.
|
||||
setStatus(MetadataDbHelper.Companion.STATUS_DISABLED)
|
||||
setStatus(MetadataDbHelper.STATUS_DISABLED)
|
||||
} else {
|
||||
Log.e(TAG, "Unexpected state of the word list for disabling $mStatus")
|
||||
}
|
||||
|
@ -77,15 +78,15 @@ class WordListPreference(context: Context?,
|
|||
val context = context
|
||||
val prefs = CommonPreferences.getCommonPreferences(context)
|
||||
CommonPreferences.enable(prefs, mWordlistId)
|
||||
if (MetadataDbHelper.Companion.STATUS_AVAILABLE == mStatus) {
|
||||
setStatus(MetadataDbHelper.Companion.STATUS_DOWNLOADING)
|
||||
} else if (MetadataDbHelper.Companion.STATUS_DISABLED == mStatus
|
||||
|| MetadataDbHelper.Companion.STATUS_DELETING == mStatus) { // If the status is DELETING, it means Android Keyboard
|
||||
if (MetadataDbHelper.STATUS_AVAILABLE == mStatus) {
|
||||
setStatus(MetadataDbHelper.STATUS_DOWNLOADING)
|
||||
} else if (MetadataDbHelper.STATUS_DISABLED == mStatus
|
||||
|| MetadataDbHelper.STATUS_DELETING == mStatus) { // If the status is DELETING, it means Android Keyboard
|
||||
// has not deleted the word list yet, so we can safely
|
||||
// turn it to 'installed'. The status DISABLED is still supported internally to
|
||||
// avoid breaking older installations and all but there should not be a way to
|
||||
// disable a word list through the interface any more.
|
||||
setStatus(MetadataDbHelper.Companion.STATUS_INSTALLED)
|
||||
setStatus(MetadataDbHelper.STATUS_INSTALLED)
|
||||
} else {
|
||||
Log.e(TAG, "Unexpected state of the word list for enabling $mStatus")
|
||||
}
|
||||
|
@ -95,7 +96,7 @@ class WordListPreference(context: Context?,
|
|||
val context = context
|
||||
val prefs = CommonPreferences.getCommonPreferences(context)
|
||||
CommonPreferences.disable(prefs, mWordlistId)
|
||||
setStatus(MetadataDbHelper.Companion.STATUS_DELETING)
|
||||
setStatus(MetadataDbHelper.STATUS_DELETING)
|
||||
}
|
||||
|
||||
override fun onBindView(view: View) {
|
||||
|
@ -115,21 +116,19 @@ class WordListPreference(context: Context?,
|
|||
mInterfaceState.setOpen(mWordlistId, mStatus)
|
||||
}
|
||||
} else { // The button is closed.
|
||||
buttonSwitcher.setStatusAndUpdateVisuals(ButtonSwitcher.Companion.STATUS_NO_BUTTON)
|
||||
buttonSwitcher.setStatusAndUpdateVisuals(ButtonSwitcher.STATUS_NO_BUTTON)
|
||||
}
|
||||
buttonSwitcher.setInternalOnClickListener(View.OnClickListener { onActionButtonClicked() })
|
||||
view.setOnClickListener { v -> onWordListClicked(v) }
|
||||
}
|
||||
|
||||
fun onWordListClicked(v: View) { // Note : v is the preference view
|
||||
val parent = v.parent as? ListView ?: return
|
||||
val listView = v.parent as? ListView ?: return
|
||||
// Just in case something changed in the framework, test for the concrete class
|
||||
val listView = parent
|
||||
val indexToOpen: Int
|
||||
// Close all first, we'll open back any item that needs to be open.
|
||||
val wasOpen = mInterfaceState.isOpen(mWordlistId)
|
||||
mInterfaceState.closeAll()
|
||||
indexToOpen = if (wasOpen) { // This button being shown. Take note that we don't want to open any button in the
|
||||
val indexToOpen = if (wasOpen) { // This button being shown. Take note that we don't want to open any button in the
|
||||
// loop below.
|
||||
-1
|
||||
} else { // This button was not being shown. Open it, and remember the index of this
|
||||
|
@ -171,12 +170,12 @@ class WordListPreference(context: Context?,
|
|||
private const val ACTION_DELETE_DICT = 3
|
||||
// The table below needs to be kept in sync with MetadataDbHelper.STATUS_* since it uses
|
||||
// the values as indices.
|
||||
private val sStatusActionList = arrayOf(intArrayOf(), intArrayOf(ButtonSwitcher.Companion.STATUS_INSTALL, ACTION_ENABLE_DICT), intArrayOf(ButtonSwitcher.Companion.STATUS_CANCEL, ACTION_DISABLE_DICT), intArrayOf(ButtonSwitcher.Companion.STATUS_DELETE, ACTION_DELETE_DICT), intArrayOf(ButtonSwitcher.Companion.STATUS_DELETE, ACTION_DELETE_DICT), intArrayOf(ButtonSwitcher.Companion.STATUS_INSTALL, ACTION_ENABLE_DICT))
|
||||
private val sStatusActionList = arrayOf(intArrayOf(), intArrayOf(ButtonSwitcher.STATUS_INSTALL, ACTION_ENABLE_DICT), intArrayOf(ButtonSwitcher.Companion.STATUS_CANCEL, ACTION_DISABLE_DICT), intArrayOf(ButtonSwitcher.Companion.STATUS_DELETE, ACTION_DELETE_DICT), intArrayOf(ButtonSwitcher.Companion.STATUS_DELETE, ACTION_DELETE_DICT), intArrayOf(ButtonSwitcher.Companion.STATUS_INSTALL, ACTION_ENABLE_DICT))
|
||||
|
||||
fun getButtonSwitcherStatus(status: Int): Int {
|
||||
if (status >= sStatusActionList.size) {
|
||||
Log.e(TAG, "Unknown status $status")
|
||||
return ButtonSwitcher.Companion.STATUS_NO_BUTTON
|
||||
return ButtonSwitcher.STATUS_NO_BUTTON
|
||||
}
|
||||
return sStatusActionList[status][0]
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue