mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-04-13 23:12:02 +02:00
change the Note ID type to Long
This commit is contained in:
parent
885170edfc
commit
99ee559836
@ -269,8 +269,8 @@ class MainActivity : SimpleActivity() {
|
||||
}
|
||||
|
||||
private fun getWantedNoteIndex(): Int {
|
||||
var wantedNoteId = intent.getIntExtra(OPEN_NOTE_ID, -1)
|
||||
if (wantedNoteId == -1) {
|
||||
var wantedNoteId = intent.getLongExtra(OPEN_NOTE_ID, -1)
|
||||
if (wantedNoteId == -1L) {
|
||||
wantedNoteId = config.currentNoteId
|
||||
}
|
||||
return getNoteIndexWithId(wantedNoteId)
|
||||
@ -289,7 +289,7 @@ class MainActivity : SimpleActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateSelectedNote(id: Int) {
|
||||
private fun updateSelectedNote(id: Long) {
|
||||
config.currentNoteId = id
|
||||
val index = getNoteIndexWithId(id)
|
||||
view_pager.currentItem = index
|
||||
@ -298,14 +298,14 @@ class MainActivity : SimpleActivity() {
|
||||
|
||||
private fun displayNewNoteDialog(value: String = "") {
|
||||
NewNoteDialog(this, dbHelper) {
|
||||
val newNote = Note(0, it, value, TYPE_NOTE)
|
||||
val newNote = Note(null, it, value, TYPE_NOTE)
|
||||
addNewNote(newNote)
|
||||
}
|
||||
}
|
||||
|
||||
private fun addNewNote(note: Note) {
|
||||
Thread {
|
||||
val id = notesDB.insertOrUpdate(note).toInt()
|
||||
val id = notesDB.insertOrUpdate(note)
|
||||
mNotes = notesDB.getNotes().toMutableList() as ArrayList<Note>
|
||||
showSaveButton = false
|
||||
runOnUiThread {
|
||||
@ -386,10 +386,11 @@ class MainActivity : SimpleActivity() {
|
||||
private fun openPath(path: String) {
|
||||
openFile(path, false) {
|
||||
var title = path.getFilenameFromPath()
|
||||
if (dbHelper.doesNoteTitleExist(title))
|
||||
if (dbHelper.doesNoteTitleExist(title)) {
|
||||
title += " (file)"
|
||||
}
|
||||
|
||||
val note = Note(0, title, "", TYPE_NOTE, path)
|
||||
val note = Note(null, title, "", TYPE_NOTE, path)
|
||||
addNewNote(note)
|
||||
}
|
||||
}
|
||||
@ -406,16 +407,11 @@ class MainActivity : SimpleActivity() {
|
||||
FilePickerDialog(this, pickFile = false, canAddShowHiddenButton = true) {
|
||||
openFolder(it) {
|
||||
ImportFolderDialog(this, it.path) {
|
||||
val noteId = it
|
||||
NotesHelper(this).getNotes {
|
||||
mNotes = it
|
||||
showSaveButton = false
|
||||
invalidateOptionsMenu()
|
||||
initViewPager()
|
||||
updateSelectedNote(noteId)
|
||||
view_pager.onGlobalLayout {
|
||||
mAdapter?.focusEditText(getNoteIndexWithId(noteId))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -623,7 +619,7 @@ class MainActivity : SimpleActivity() {
|
||||
mAdapter?.redo(view_pager.currentItem)
|
||||
}
|
||||
|
||||
private fun getNoteIndexWithId(id: Int): Int {
|
||||
private fun getNoteIndexWithId(id: Long): Int {
|
||||
for (i in 0 until mNotes.count()) {
|
||||
if (mNotes[i].id == id) {
|
||||
mCurrentNote = mNotes[i]
|
||||
|
@ -92,17 +92,17 @@ class WidgetConfigureActivity : SimpleActivity() {
|
||||
private fun showNoteSelector() {
|
||||
val items = ArrayList<RadioItem>()
|
||||
mNotes.forEach {
|
||||
items.add(RadioItem(it.id!!, it.title))
|
||||
items.add(RadioItem(it.id!!.toInt(), it.title))
|
||||
}
|
||||
|
||||
RadioGroupDialog(this, items, mCurrentNoteId) {
|
||||
val selectedId = it as Int
|
||||
updateCurrentNote(mNotes.first { it.id == selectedId })
|
||||
updateCurrentNote(mNotes.first { it.id!!.toInt() == selectedId })
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateCurrentNote(note: Note) {
|
||||
mCurrentNoteId = note.id!!
|
||||
mCurrentNoteId = note.id!!.toInt()
|
||||
notes_picker_value.text = note.title
|
||||
val sampleValue = if (note.value.isEmpty() || mIsCustomizingColors) getString(R.string.widget_config) else note.value
|
||||
notes_view.text = sampleValue
|
||||
|
@ -18,7 +18,7 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity
|
||||
override fun getItem(position: Int): NoteFragment {
|
||||
val bundle = Bundle()
|
||||
val id = notes[position].id
|
||||
bundle.putInt(NOTE_ID, id!!)
|
||||
bundle.putInt(NOTE_ID, id!!.toInt())
|
||||
|
||||
if (fragments.containsKey(position)) {
|
||||
return fragments[position]!!
|
||||
|
@ -51,7 +51,7 @@ abstract class NotesDatabase : RoomDatabase() {
|
||||
private fun insertFirstNote(context: Context) {
|
||||
Executors.newSingleThreadExecutor().execute {
|
||||
val generalNote = context.resources.getString(R.string.general_note)
|
||||
val note = Note(1, generalNote, "", TYPE_NOTE)
|
||||
val note = Note(null, generalNote, "", TYPE_NOTE)
|
||||
db!!.NotesDao().insertOrUpdate(note)
|
||||
}
|
||||
}
|
||||
|
@ -9,12 +9,13 @@ import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import com.simplemobiletools.notes.pro.R
|
||||
import com.simplemobiletools.notes.pro.activities.SimpleActivity
|
||||
import com.simplemobiletools.notes.pro.extensions.dbHelper
|
||||
import com.simplemobiletools.notes.pro.extensions.notesDB
|
||||
import com.simplemobiletools.notes.pro.helpers.TYPE_NOTE
|
||||
import com.simplemobiletools.notes.pro.models.Note
|
||||
import kotlinx.android.synthetic.main.dialog_import_folder.view.*
|
||||
import java.io.File
|
||||
|
||||
class ImportFolderDialog(val activity: SimpleActivity, val path: String, val callback: (id: Int) -> Unit) : AlertDialog.Builder(activity) {
|
||||
class ImportFolderDialog(val activity: SimpleActivity, val path: String, val callback: () -> Unit) : AlertDialog.Builder(activity) {
|
||||
private var dialog: AlertDialog
|
||||
|
||||
init {
|
||||
@ -37,7 +38,6 @@ class ImportFolderDialog(val activity: SimpleActivity, val path: String, val cal
|
||||
|
||||
private fun saveFolder(updateFilesOnEdit: Boolean) {
|
||||
val folder = File(path)
|
||||
var lastSavedNoteId = -1
|
||||
folder.listFiles { file ->
|
||||
val filename = file.path.getFilenameFromPath()
|
||||
when {
|
||||
@ -54,22 +54,21 @@ class ImportFolderDialog(val activity: SimpleActivity, val path: String, val cal
|
||||
|
||||
if (updateFilesOnEdit) {
|
||||
activity.handleSAFDialog(path) {
|
||||
lastSavedNoteId = saveNote(title, value, storePath)
|
||||
saveNote(title, value, storePath)
|
||||
}
|
||||
} else {
|
||||
lastSavedNoteId = saveNote(title, value, storePath)
|
||||
saveNote(title, value, storePath)
|
||||
}
|
||||
}
|
||||
|
||||
if (lastSavedNoteId != -1) {
|
||||
callback(lastSavedNoteId)
|
||||
}
|
||||
|
||||
callback()
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
private fun saveNote(title: String, value: String, path: String): Int {
|
||||
val note = Note(0, title, value, TYPE_NOTE, path)
|
||||
return activity.dbHelper.insertNote(note)
|
||||
private fun saveNote(title: String, value: String, path: String) {
|
||||
val note = Note(null, title, value, TYPE_NOTE, path)
|
||||
Thread {
|
||||
activity.notesDB.insertOrUpdate(note)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ class OpenFileDialog(val activity: SimpleActivity, val path: String, val callbac
|
||||
|
||||
private fun saveNote(storeContent: String, storePath: String) {
|
||||
val filename = path.getFilenameFromPath()
|
||||
val note = Note(0, filename, storeContent, TYPE_NOTE, storePath)
|
||||
val note = Note(null, filename, storeContent, TYPE_NOTE, storePath)
|
||||
callback(note)
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ import com.simplemobiletools.notes.pro.models.Note
|
||||
import kotlinx.android.synthetic.main.dialog_open_note.view.*
|
||||
import kotlinx.android.synthetic.main.open_note_item.view.*
|
||||
|
||||
class OpenNoteDialog(val activity: Activity, val callback: (checkedId: Int) -> Unit) {
|
||||
class OpenNoteDialog(val activity: Activity, val callback: (checkedId: Long) -> Unit) {
|
||||
private var dialog: AlertDialog? = null
|
||||
|
||||
init {
|
||||
@ -34,10 +34,10 @@ class OpenNoteDialog(val activity: Activity, val callback: (checkedId: Int) -> U
|
||||
open_note_item_radio_button.apply {
|
||||
text = note.title
|
||||
isChecked = note.id == activity.config.currentNoteId
|
||||
id = note.id!!
|
||||
id = note.id!!.toInt()
|
||||
|
||||
setOnClickListener {
|
||||
callback(id)
|
||||
callback(note.id!!)
|
||||
dialog?.dismiss()
|
||||
}
|
||||
}
|
||||
|
@ -45,13 +45,13 @@ class Config(context: Context) : BaseConfig(context) {
|
||||
get() = prefs.getInt(GRAVITY, GRAVITY_LEFT)
|
||||
set(size) = prefs.edit().putInt(GRAVITY, size).apply()
|
||||
|
||||
var currentNoteId: Int
|
||||
get() = prefs.getInt(CURRENT_NOTE_ID, 1)
|
||||
set(id) = prefs.edit().putInt(CURRENT_NOTE_ID, id).apply()
|
||||
var currentNoteId: Long
|
||||
get() = prefs.getLong(CURRENT_NOTE_ID, 1L)
|
||||
set(id) = prefs.edit().putLong(CURRENT_NOTE_ID, id).apply()
|
||||
|
||||
var widgetNoteId: Int
|
||||
get() = prefs.getInt(WIDGET_NOTE_ID, 1)
|
||||
set(id) = prefs.edit().putInt(WIDGET_NOTE_ID, id).apply()
|
||||
var widgetNoteId: Long
|
||||
get() = prefs.getLong(WIDGET_NOTE_ID, 1L)
|
||||
set(id) = prefs.edit().putLong(WIDGET_NOTE_ID, id).apply()
|
||||
|
||||
var placeCursorToEnd: Boolean
|
||||
get() = prefs.getBoolean(CURSOR_PLACEMENT, true)
|
||||
|
@ -7,6 +7,7 @@ import android.database.sqlite.SQLiteDatabase
|
||||
import android.database.sqlite.SQLiteDatabase.CONFLICT_IGNORE
|
||||
import android.database.sqlite.SQLiteOpenHelper
|
||||
import com.simplemobiletools.commons.extensions.getIntValue
|
||||
import com.simplemobiletools.commons.extensions.getLongValue
|
||||
import com.simplemobiletools.notes.pro.R
|
||||
import com.simplemobiletools.notes.pro.models.Note
|
||||
import com.simplemobiletools.notes.pro.models.Widget
|
||||
@ -52,11 +53,6 @@ class DBHelper private constructor(private val mContext: Context) : SQLiteOpenHe
|
||||
db.insert(NOTES_TABLE_NAME, null, values)
|
||||
}
|
||||
|
||||
fun insertNote(note: Note): Int {
|
||||
val values = fillNoteContentValues(note)
|
||||
return mDb.insertWithOnConflict(NOTES_TABLE_NAME, null, values, CONFLICT_IGNORE).toInt()
|
||||
}
|
||||
|
||||
fun insertWidget(widget: Widget): Int {
|
||||
val values = fillWidgetContentValues(widget)
|
||||
return mDb.insertWithOnConflict(WIDGETS_TABLE_NAME, null, values, CONFLICT_IGNORE).toInt()
|
||||
@ -78,7 +74,7 @@ class DBHelper private constructor(private val mContext: Context) : SQLiteOpenHe
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteNote(id: Int) {
|
||||
fun deleteNote(id: Long) {
|
||||
mDb.delete(NOTES_TABLE_NAME, "$COL_ID = $id", null)
|
||||
mDb.delete(WIDGETS_TABLE_NAME, "$COL_NOTE_ID = $id", null)
|
||||
}
|
||||
@ -96,7 +92,7 @@ class DBHelper private constructor(private val mContext: Context) : SQLiteOpenHe
|
||||
}
|
||||
}
|
||||
|
||||
fun getNoteId(path: String): Int {
|
||||
fun getNoteId(path: String): Long {
|
||||
val cols = arrayOf(COL_ID)
|
||||
val selection = "$COL_PATH = ?"
|
||||
val selectionArgs = arrayOf(path)
|
||||
@ -104,7 +100,7 @@ class DBHelper private constructor(private val mContext: Context) : SQLiteOpenHe
|
||||
try {
|
||||
cursor = mDb.query(NOTES_TABLE_NAME, cols, selection, selectionArgs, null, null, null)
|
||||
if (cursor?.moveToFirst() == true) {
|
||||
return cursor.getIntValue(COL_ID)
|
||||
return cursor.getLongValue(COL_ID)
|
||||
}
|
||||
} finally {
|
||||
cursor?.close()
|
||||
|
@ -9,7 +9,7 @@ import java.io.FileNotFoundException
|
||||
|
||||
@Entity(tableName = "notes", indices = [(Index(value = ["id"], unique = true))])
|
||||
data class Note(
|
||||
@PrimaryKey(autoGenerate = true) var id: Int?,
|
||||
@PrimaryKey(autoGenerate = true) var id: Long?,
|
||||
@ColumnInfo(name = "title") var title: String,
|
||||
@ColumnInfo(name = "value") var value: String,
|
||||
@ColumnInfo(name = "type") var type: Int,
|
||||
|
Loading…
x
Reference in New Issue
Block a user