allow syncing note with content uris

This commit is contained in:
tibbi
2021-03-21 11:50:02 +01:00
parent 386767bd6f
commit 4f1bb56d00
5 changed files with 27 additions and 16 deletions

View File

@ -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 {