diff --git a/app/src/main/java/com/isolaatti/posting/posts/presentation/CreatePostViewModel.kt b/app/src/main/java/com/isolaatti/posting/posts/presentation/CreatePostViewModel.kt index e9b2b7c..e208158 100644 --- a/app/src/main/java/com/isolaatti/posting/posts/presentation/CreatePostViewModel.kt +++ b/app/src/main/java/com/isolaatti/posting/posts/presentation/CreatePostViewModel.kt @@ -41,11 +41,9 @@ class CreatePostViewModel @Inject constructor( val validation: MutableLiveData = MutableLiveData(false) val error: MutableLiveData = MutableLiveData() - val sendingPost: MutableLiveData = MutableLiveData(false) + val sendingPost: MutableLiveData = MutableLiveData(null) val postToEdit: MutableLiveData = MutableLiveData() val liveContent: MutableLiveData = MutableLiveData() - var content: String = "" - set(value) {field = value; liveContent.value = value} // TODO remove this and use only liveContent private val _photos: MutableStateFlow> = MutableStateFlow(emptyList()) val photos: StateFlow> get() = _photos @@ -67,7 +65,7 @@ class CreatePostViewModel @Inject constructor( viewModelScope.launch { makePost( privacy = EditPostDto.PRIVACY_ISOLAATTI, - content = content, + content = liveContent.value ?: "", images = photos.value, audioId = audioId, squadId = null @@ -106,13 +104,13 @@ class CreatePostViewModel @Inject constructor( private fun sendEditDiscussion(postId: Long) { viewModelScope.launch { - editPost(postId, EditPostDto.PRIVACY_ISOLAATTI, content, audioId, null).onEach { + editPost(postId, EditPostDto.PRIVACY_ISOLAATTI, liveContent.value ?: "", audioId, null).onEach { when(it) { is Resource.Success -> { sendingPost.postValue(false) } is Resource.Error -> { - sendingPost.postValue(false) + sendingPost.postValue(null) error.postValue(it.errorType) } is Resource.Loading -> { @@ -139,8 +137,10 @@ class CreatePostViewModel @Inject constructor( loadPost(postId).onEach { postRes -> if(postRes is Resource.Success) { postRes.data?.let { - postToEdit.postValue(EditPostDto(PRIVACY_ISOLAATTI, content = it.textContent, postId = it.id)) - it.audio?.let { audio -> audioAttachment.postValue(audio) } + //postToEdit.postValue(EditPostDto(PRIVACY_ISOLAATTI, content = it.textContent, postId = it.id)) + //it.audio?.let { audio -> audioAttachment.postValue(audio) } + + liveContent.postValue(it.textContent) } } }.flowOn(Dispatchers.IO).launchIn(this) diff --git a/app/src/main/java/com/isolaatti/posting/posts/ui/CreatePostActivity.kt b/app/src/main/java/com/isolaatti/posting/posts/ui/CreatePostActivity.kt index 16d4a77..b4fd522 100644 --- a/app/src/main/java/com/isolaatti/posting/posts/ui/CreatePostActivity.kt +++ b/app/src/main/java/com/isolaatti/posting/posts/ui/CreatePostActivity.kt @@ -39,6 +39,7 @@ import androidx.compose.runtime.livedata.observeAsState import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester @@ -110,7 +111,7 @@ class CreatePostActivity : IsolaattiBaseActivity() { super.onCreate(savedInstanceState) setContent { - var text by remember { mutableStateOf("") } + val text by viewModel.liveContent.observeAsState("") val focusRequester = remember { FocusRequester() } val pictures by viewModel.photos.collectAsStateWithLifecycle() @@ -163,7 +164,7 @@ class CreatePostActivity : IsolaattiBaseActivity() { AlertDialog( onDismissRequest = {}, text = { - Row { + Row(verticalAlignment = Alignment.CenterVertically) { CircularProgressIndicator() Text( when(postingStep) { @@ -171,7 +172,8 @@ class CreatePostActivity : IsolaattiBaseActivity() { PostingSteps.UploadingPhotos -> getString(R.string.uploading_photos) PostingSteps.Finished -> "" PostingSteps.Unspecified -> "" - } + }, + modifier = Modifier.padding(4.dp) ) } }, @@ -181,12 +183,14 @@ class CreatePostActivity : IsolaattiBaseActivity() { }, confirmButton = {} ) + } else if(posting == false){ + finish() } Column(modifier = Modifier.padding(it).verticalScroll(scrollState)) { OutlinedTextField( value = text, - onValueChange = { - text = it + onValueChange = { textFieldValue -> + viewModel.liveContent.postValue(textFieldValue) }, modifier = Modifier .padding(horizontal = 8.dp) diff --git a/app/src/main/res/layout/post_layout.xml b/app/src/main/res/layout/post_layout.xml index 3bbdaae..f8eaa0f 100644 --- a/app/src/main/res/layout/post_layout.xml +++ b/app/src/main/res/layout/post_layout.xml @@ -73,15 +73,6 @@ android:layout_height="wrap_content" app:layout_constraintTop_toBottomOf="@id/post_header_container"/> - - + app:layout_constraintTop_toBottomOf="@id/audio"/> + + + + + app:layout_constraintTop_toBottomOf="@id/photos_view_pager">