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