This commit is contained in:
erik-everardo 2025-01-18 18:10:04 -06:00
parent 571b893fcd
commit 031722920a
3 changed files with 30 additions and 24 deletions

View File

@ -41,11 +41,9 @@ class CreatePostViewModel @Inject constructor(
val validation: MutableLiveData<Boolean> = MutableLiveData(false) val validation: MutableLiveData<Boolean> = MutableLiveData(false)
val error: MutableLiveData<Resource.Error.ErrorType?> = MutableLiveData() val error: MutableLiveData<Resource.Error.ErrorType?> = MutableLiveData()
val sendingPost: MutableLiveData<Boolean> = MutableLiveData(false) val sendingPost: MutableLiveData<Boolean?> = MutableLiveData(null)
val postToEdit: MutableLiveData<EditPostDto> = MutableLiveData() val postToEdit: MutableLiveData<EditPostDto> = MutableLiveData()
val liveContent: MutableLiveData<String> = MutableLiveData() val liveContent: MutableLiveData<String> = MutableLiveData()
var content: String = ""
set(value) {field = value; liveContent.value = value} // TODO remove this and use only liveContent
private val _photos: MutableStateFlow<List<Uri>> = MutableStateFlow(emptyList()) private val _photos: MutableStateFlow<List<Uri>> = MutableStateFlow(emptyList())
val photos: StateFlow<List<Uri>> get() = _photos val photos: StateFlow<List<Uri>> get() = _photos
@ -67,7 +65,7 @@ class CreatePostViewModel @Inject constructor(
viewModelScope.launch { viewModelScope.launch {
makePost( makePost(
privacy = EditPostDto.PRIVACY_ISOLAATTI, privacy = EditPostDto.PRIVACY_ISOLAATTI,
content = content, content = liveContent.value ?: "",
images = photos.value, images = photos.value,
audioId = audioId, audioId = audioId,
squadId = null squadId = null
@ -106,13 +104,13 @@ class CreatePostViewModel @Inject constructor(
private fun sendEditDiscussion(postId: Long) { private fun sendEditDiscussion(postId: Long) {
viewModelScope.launch { viewModelScope.launch {
editPost(postId, EditPostDto.PRIVACY_ISOLAATTI, content, audioId, null).onEach { editPost(postId, EditPostDto.PRIVACY_ISOLAATTI, liveContent.value ?: "", audioId, null).onEach {
when(it) { when(it) {
is Resource.Success -> { is Resource.Success -> {
sendingPost.postValue(false) sendingPost.postValue(false)
} }
is Resource.Error -> { is Resource.Error -> {
sendingPost.postValue(false) sendingPost.postValue(null)
error.postValue(it.errorType) error.postValue(it.errorType)
} }
is Resource.Loading -> { is Resource.Loading -> {
@ -139,8 +137,10 @@ class CreatePostViewModel @Inject constructor(
loadPost(postId).onEach { postRes -> loadPost(postId).onEach { postRes ->
if(postRes is Resource.Success) { if(postRes is Resource.Success) {
postRes.data?.let { postRes.data?.let {
postToEdit.postValue(EditPostDto(PRIVACY_ISOLAATTI, content = it.textContent, postId = it.id)) //postToEdit.postValue(EditPostDto(PRIVACY_ISOLAATTI, content = it.textContent, postId = it.id))
it.audio?.let { audio -> audioAttachment.postValue(audio) } //it.audio?.let { audio -> audioAttachment.postValue(audio) }
liveContent.postValue(it.textContent)
} }
} }
}.flowOn(Dispatchers.IO).launchIn(this) }.flowOn(Dispatchers.IO).launchIn(this)

View File

@ -39,6 +39,7 @@ import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.focus.focusRequester
@ -110,7 +111,7 @@ class CreatePostActivity : IsolaattiBaseActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContent { setContent {
var text by remember { mutableStateOf("") } val text by viewModel.liveContent.observeAsState("")
val focusRequester = remember { FocusRequester() } val focusRequester = remember { FocusRequester() }
val pictures by viewModel.photos.collectAsStateWithLifecycle() val pictures by viewModel.photos.collectAsStateWithLifecycle()
@ -163,7 +164,7 @@ class CreatePostActivity : IsolaattiBaseActivity() {
AlertDialog( AlertDialog(
onDismissRequest = {}, onDismissRequest = {},
text = { text = {
Row { Row(verticalAlignment = Alignment.CenterVertically) {
CircularProgressIndicator() CircularProgressIndicator()
Text( Text(
when(postingStep) { when(postingStep) {
@ -171,7 +172,8 @@ class CreatePostActivity : IsolaattiBaseActivity() {
PostingSteps.UploadingPhotos -> getString(R.string.uploading_photos) PostingSteps.UploadingPhotos -> getString(R.string.uploading_photos)
PostingSteps.Finished -> "" PostingSteps.Finished -> ""
PostingSteps.Unspecified -> "" PostingSteps.Unspecified -> ""
} },
modifier = Modifier.padding(4.dp)
) )
} }
}, },
@ -181,12 +183,14 @@ class CreatePostActivity : IsolaattiBaseActivity() {
}, },
confirmButton = {} confirmButton = {}
) )
} else if(posting == false){
finish()
} }
Column(modifier = Modifier.padding(it).verticalScroll(scrollState)) { Column(modifier = Modifier.padding(it).verticalScroll(scrollState)) {
OutlinedTextField( OutlinedTextField(
value = text, value = text,
onValueChange = { onValueChange = { textFieldValue ->
text = it viewModel.liveContent.postValue(textFieldValue)
}, },
modifier = Modifier modifier = Modifier
.padding(horizontal = 8.dp) .padding(horizontal = 8.dp)

View File

@ -73,15 +73,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/post_header_container"/> app:layout_constraintTop_toBottomOf="@id/post_header_container"/>
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/photos_view_pager"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/audio"
app:layout_constraintDimensionRatio="H,1:1"
android:visibility="gone"
tools:visibility="visible"/>
<TextView <TextView
android:id="@+id/post_content" android:id="@+id/post_content"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -92,14 +83,25 @@
android:textSize="16sp" android:textSize="16sp"
tools:text="Hola" tools:text="Hola"
android:fontFamily="sans-serif" android:fontFamily="sans-serif"
app:layout_constraintTop_toBottomOf="@id/photos_view_pager"/> app:layout_constraintTop_toBottomOf="@id/audio"/>
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/photos_view_pager"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/post_content"
app:layout_constraintDimensionRatio="H,1:1"
android:visibility="gone"
tools:visibility="visible"/>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:gravity="start" android:gravity="start"
app:layout_constraintTop_toBottomOf="@id/post_content"> app:layout_constraintTop_toBottomOf="@id/photos_view_pager">
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/like_button" android:id="@+id/like_button"