WIP
This commit is contained in:
parent
571b893fcd
commit
031722920a
@ -41,11 +41,9 @@ class CreatePostViewModel @Inject constructor(
|
||||
|
||||
val validation: MutableLiveData<Boolean> = MutableLiveData(false)
|
||||
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 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())
|
||||
val photos: StateFlow<List<Uri>> 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)
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -73,15 +73,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
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
|
||||
android:id="@+id/post_content"
|
||||
android:layout_width="match_parent"
|
||||
@ -92,14 +83,25 @@
|
||||
android:textSize="16sp"
|
||||
tools:text="Hola"
|
||||
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
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:gravity="start"
|
||||
app:layout_constraintTop_toBottomOf="@id/post_content">
|
||||
app:layout_constraintTop_toBottomOf="@id/photos_view_pager">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/like_button"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user