save a draft while you are typing the post
This commit is contained in:
@@ -111,6 +111,7 @@ private object PrefKeys {
|
|||||||
const val LOGIN_WITH_EXTERNAL_SIGNER = "login_with_external_signer"
|
const val LOGIN_WITH_EXTERNAL_SIGNER = "login_with_external_signer"
|
||||||
const val AUTOMATICALLY_SHOW_PROFILE_PICTURE = "automatically_show_profile_picture"
|
const val AUTOMATICALLY_SHOW_PROFILE_PICTURE = "automatically_show_profile_picture"
|
||||||
const val SIGNER_PACKAGE_NAME = "signer_package_name"
|
const val SIGNER_PACKAGE_NAME = "signer_package_name"
|
||||||
|
const val NEW_POST_DRAFT = "draft_new_post"
|
||||||
|
|
||||||
const val ALL_ACCOUNT_INFO = "all_saved_accounts_info"
|
const val ALL_ACCOUNT_INFO = "all_saved_accounts_info"
|
||||||
const val SHARED_SETTINGS = "shared_settings"
|
const val SHARED_SETTINGS = "shared_settings"
|
||||||
@@ -458,6 +459,30 @@ object LocalPreferences {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun saveDraft(
|
||||||
|
message: String,
|
||||||
|
account: Account,
|
||||||
|
) {
|
||||||
|
val prefs = encryptedPreferences(account.keyPair.pubKey.toNpub())
|
||||||
|
with(prefs.edit()) {
|
||||||
|
putString(PrefKeys.NEW_POST_DRAFT, message)
|
||||||
|
apply()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun loadDraft(account: Account): String? {
|
||||||
|
val prefs = encryptedPreferences(account.keyPair.pubKey.toNpub())
|
||||||
|
return prefs.getString(PrefKeys.NEW_POST_DRAFT, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun clearDraft(account: Account) {
|
||||||
|
val prefs = encryptedPreferences(account.keyPair.pubKey.toNpub())
|
||||||
|
with(prefs.edit()) {
|
||||||
|
remove(PrefKeys.NEW_POST_DRAFT)
|
||||||
|
apply()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun innerLoadCurrentAccountFromEncryptedStorage(npub: String?): Account? =
|
suspend fun innerLoadCurrentAccountFromEncryptedStorage(npub: String?): Account? =
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
checkNotInMainThread()
|
checkNotInMainThread()
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import androidx.compose.ui.text.input.TextFieldValue
|
|||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.fonfon.kgeohash.toGeoHash
|
import com.fonfon.kgeohash.toGeoHash
|
||||||
|
import com.vitorpamplona.amethyst.LocalPreferences
|
||||||
import com.vitorpamplona.amethyst.model.Account
|
import com.vitorpamplona.amethyst.model.Account
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
@@ -213,6 +214,14 @@ open class NewPostViewModel() : ViewModel() {
|
|||||||
zapRaiserAmount = null
|
zapRaiserAmount = null
|
||||||
forwardZapTo = Split()
|
forwardZapTo = Split()
|
||||||
forwardZapToEditting = TextFieldValue("")
|
forwardZapToEditting = TextFieldValue("")
|
||||||
|
|
||||||
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
|
val draft = loadDraft()
|
||||||
|
if (draft != null) {
|
||||||
|
message = TextFieldValue(draft)
|
||||||
|
updateMessage(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sendPost(relayList: List<Relay>? = null) {
|
fun sendPost(relayList: List<Relay>? = null) {
|
||||||
@@ -535,6 +544,10 @@ open class NewPostViewModel() : ViewModel() {
|
|||||||
userSuggestionAnchor = null
|
userSuggestionAnchor = null
|
||||||
userSuggestionsMainMessage = null
|
userSuggestionsMainMessage = null
|
||||||
|
|
||||||
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
|
clearDraft()
|
||||||
|
}
|
||||||
|
|
||||||
NostrSearchEventOrUserDataSource.clear()
|
NostrSearchEventOrUserDataSource.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -550,7 +563,24 @@ open class NewPostViewModel() : ViewModel() {
|
|||||||
pTags = pTags?.filter { it != userToRemove }
|
pTags = pTags?.filter { it != userToRemove }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open fun saveDraft(message: String) {
|
||||||
|
account?.let { LocalPreferences.saveDraft(message, it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
open fun loadDraft(): String? {
|
||||||
|
account?.let { return LocalPreferences.loadDraft(it) }
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
open fun clearDraft() {
|
||||||
|
account?.let { LocalPreferences.clearDraft(it) }
|
||||||
|
}
|
||||||
|
|
||||||
open fun updateMessage(it: TextFieldValue) {
|
open fun updateMessage(it: TextFieldValue) {
|
||||||
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
|
saveDraft(it.text)
|
||||||
|
}
|
||||||
message = it
|
message = it
|
||||||
urlPreview = findUrlInMessage()
|
urlPreview = findUrlInMessage()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user