Pass existing description through to post submission activity

This commit is contained in:
fgerber 2022-11-02 17:38:55 +01:00
parent 6572f0018a
commit e40a774b1f
4 changed files with 18 additions and 2 deletions

View File

@ -93,6 +93,8 @@ class PostCreationActivity : BaseThemedWithoutBarActivity() {
)
}
model.setExistingDescription(intent.getStringExtra(PICTURE_DESCRIPTION))
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
model.uiState.collect { uiState ->

View File

@ -23,6 +23,7 @@ import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlinx.parcelize.Parcelize
import org.pixeldroid.app.R
import org.pixeldroid.app.posts.fromHtml
import org.pixeldroid.app.utils.PixelDroidApplication
import org.pixeldroid.app.utils.db.entities.InstanceDatabaseEntity
import org.pixeldroid.app.utils.di.PixelfedAPIHolder
@ -80,6 +81,7 @@ class PostCreationViewModel(application: Application, clipdata: ClipData? = null
it.value = clipdata?.let { it1 -> addPossibleImages(it1, mutableListOf()) }
}
}
private var existingDescription: String? = null
@Inject
lateinit var apiHolder: PixelfedAPIHolder
@ -92,7 +94,7 @@ class PostCreationViewModel(application: Application, clipdata: ClipData? = null
PreferenceManager.getDefaultSharedPreferences(application)
val initialDescription = sharedPreferences.getString("prefill_description", "") ?: ""
_uiState = MutableStateFlow(PostCreationActivityUiState(newPostDescriptionText = initialDescription))
_uiState = MutableStateFlow(PostCreationActivityUiState(newPostDescriptionText = existingDescription ?: initialDescription))
}
val uiState: StateFlow<PostCreationActivityUiState> = _uiState
@ -193,6 +195,10 @@ class PostCreationViewModel(application: Application, clipdata: ClipData? = null
photoData.value = photoData.value
}
fun setExistingDescription(description: String?) {
existingDescription = description
}
fun removeAt(currentPosition: Int) {
photoData.value?.removeAt(currentPosition)
_uiState.update {
@ -209,6 +215,7 @@ class PostCreationViewModel(application: Application, clipdata: ClipData? = null
fun nextStep(context: Context) {
val intent = Intent(context, PostSubmissionActivity::class.java)
intent.putExtra(PostSubmissionActivity.PHOTO_DATA, getPhotoData().value?.let { ArrayList(it) })
intent.putExtra(PostSubmissionActivity.PICTURE_DESCRIPTION, existingDescription)
ContextCompat.startActivity(context, intent, null)
}

View File

@ -69,6 +69,8 @@ class PostSubmissionActivity : BaseThemedWithoutBarActivity() {
}
model = _model
model.setExistingDescription(intent.getStringExtra(PICTURE_DESCRIPTION))
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
model.uiState.collect { uiState ->

View File

@ -62,6 +62,7 @@ class PostSubmissionViewModel(application: Application, photodata: ArrayList<Pho
}
}
}
private var existingDescription: String? = null
@Inject
lateinit var apiHolder: PixelfedAPIHolder
@ -74,7 +75,7 @@ class PostSubmissionViewModel(application: Application, photodata: ArrayList<Pho
PreferenceManager.getDefaultSharedPreferences(application)
val initialDescription = sharedPreferences.getString("prefill_description", "") ?: ""
_uiState = MutableStateFlow(PostSubmissionActivityUiState(newPostDescriptionText = initialDescription))
_uiState = MutableStateFlow(PostSubmissionActivityUiState(newPostDescriptionText = existingDescription ?: initialDescription))
}
val uiState: StateFlow<PostSubmissionActivityUiState> = _uiState
@ -288,6 +289,10 @@ class PostSubmissionViewModel(application: Application, photodata: ArrayList<Pho
_uiState.update { it.copy(newPostDescriptionText = text.toString()) }
}
fun setExistingDescription(description: String?) {
existingDescription = description
}
fun trackTempFile(file: File) {
tempFiles.add(file)
}