mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-06-05 17:00:23 +02:00
allow syncing note with content uris
This commit is contained in:
@ -1,11 +1,12 @@
|
||||
package com.simplemobiletools.notes.pro.models
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.Index
|
||||
import androidx.room.PrimaryKey
|
||||
import java.io.File
|
||||
import java.io.FileNotFoundException
|
||||
|
||||
@Entity(tableName = "notes", indices = [(Index(value = ["id"], unique = true))])
|
||||
data class Note(
|
||||
@ -15,11 +16,16 @@ data class Note(
|
||||
@ColumnInfo(name = "type") var type: Int,
|
||||
@ColumnInfo(name = "path") var path: String = "") {
|
||||
|
||||
fun getNoteStoredValue(): String? {
|
||||
fun getNoteStoredValue(context: Context): String? {
|
||||
return if (path.isNotEmpty()) {
|
||||
try {
|
||||
File(path).readText()
|
||||
} catch (e: FileNotFoundException) {
|
||||
if (path.startsWith("content://")) {
|
||||
val inputStream = context.contentResolver.openInputStream(Uri.parse(path))
|
||||
inputStream?.bufferedReader().use { it!!.readText() }
|
||||
} else {
|
||||
File(path).readText()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user