cambio de diseño y correciones menores en pantalla para subir imagen
This commit is contained in:
parent
b0fa733992
commit
6e92dbb3c4
@ -25,7 +25,7 @@ class ImageMakerViewModel @Inject constructor(private val imagesRepository: Imag
|
||||
return
|
||||
}
|
||||
viewModelScope.launch {
|
||||
imagesRepository.uploadImage(name!!, imageUri!!, null).onEach {
|
||||
imagesRepository.uploadImage(name!!.trim(), imageUri!!, null).onEach {
|
||||
image.postValue(it)
|
||||
}.flowOn(Dispatchers.IO).launchIn(this)
|
||||
}
|
||||
|
||||
@ -4,9 +4,11 @@ import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.activity.viewModels
|
||||
import androidx.core.widget.doOnTextChanged
|
||||
import coil.load
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.isolaatti.R
|
||||
import com.isolaatti.common.IsolaattiBaseActivity
|
||||
import com.isolaatti.databinding.ActivityImageMakerBinding
|
||||
@ -25,24 +27,36 @@ class ImageMakerActivity : IsolaattiBaseActivity() {
|
||||
setContentView(binding.root)
|
||||
viewModel.imageUri = intent.data
|
||||
binding.imagePreview.load(intent.data)
|
||||
|
||||
onBackPressedDispatcher.addCallback(onBackPressedCallback)
|
||||
setupListeners()
|
||||
setupObservers()
|
||||
}
|
||||
|
||||
private val onBackPressedCallback = object: OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
showExitConfirmationDialog()
|
||||
}
|
||||
}
|
||||
|
||||
private fun showExitConfirmationDialog() {
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setTitle(R.string.discard_image)
|
||||
.setPositiveButton(R.string.yes_discard_image) {_, _ ->
|
||||
finish()
|
||||
}.setNegativeButton(R.string.no, null)
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun setupListeners() {
|
||||
binding.materialToolbar.setOnMenuItemClickListener {
|
||||
when(it.itemId) {
|
||||
R.id.upload_picture_item -> {
|
||||
binding.uploadPhotoFab.setOnClickListener {
|
||||
viewModel.uploadPicture()
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
binding.textImageName.editText?.doOnTextChanged { text, _, _, _ ->
|
||||
viewModel.name = text.toString()
|
||||
}
|
||||
binding.toolbar.setNavigationOnClickListener {
|
||||
showExitConfirmationDialog()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupObservers() {
|
||||
@ -50,9 +64,12 @@ class ImageMakerActivity : IsolaattiBaseActivity() {
|
||||
when(it) {
|
||||
is Resource.Error -> {
|
||||
errorViewModel.error.value = it.errorType
|
||||
binding.progressBarLoading.visibility = View.GONE
|
||||
binding.textImageName.isEnabled = true
|
||||
}
|
||||
is Resource.Loading -> {
|
||||
binding.progressBarLoading.visibility = View.VISIBLE
|
||||
binding.textImageName.isEnabled = false
|
||||
}
|
||||
is Resource.Success -> {
|
||||
binding.progressBarLoading.visibility = View.GONE
|
||||
|
||||
@ -4,31 +4,43 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.google.android.material.appbar.MaterialToolbar
|
||||
android:id="@+id/materialToolbar"
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:navigationIcon="@drawable/baseline_arrow_back_24"
|
||||
app:title="@string/upload_a_picture"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:menu="@menu/image_maker_menu"/>
|
||||
app:navigationIcon="@drawable/baseline_close_24"
|
||||
android:background="@color/translucent_purple"
|
||||
app:title="@string/upload_photo"
|
||||
android:translationZ="2dp"/>
|
||||
|
||||
<com.ortiz.touchview.TouchImageView
|
||||
android:id="@+id/image_preview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:background="@color/translucent_purple"
|
||||
android:translationZ="2dp">
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/textImageName"
|
||||
style="?attr/textInputOutlinedStyle"
|
||||
android:layout_width="match_parent"
|
||||
style="?attr/textInputFilledDenseStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="32dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:hint="@string/picture_name"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/materialToolbar">
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/upload_photo_fab"
|
||||
app:layout_constraintStart_toStartOf="parent">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:layout_width="match_parent"
|
||||
@ -36,26 +48,29 @@
|
||||
android:maxLines="1" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image_preview"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_margin="32dp"
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/upload_photo_fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/baseline_check_24"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginBottom="32dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textImageName" />
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progress_bar_loading"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/materialToolbar"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/upload_photo_fab"
|
||||
app:layout_constraintEnd_toEndOf="@+id/upload_photo_fab"
|
||||
app:layout_constraintStart_toStartOf="@+id/upload_photo_fab"
|
||||
app:layout_constraintTop_toTopOf="@+id/upload_photo_fab"
|
||||
tools:visibility="visible" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@ -122,4 +122,6 @@
|
||||
<string name="selected_images_count">Images selected: %d</string>
|
||||
<string name="picture_name">Picture name</string>
|
||||
<string name="audio_options">Audio options</string>
|
||||
<string name="yes_discard_image">Yes, discard image</string>
|
||||
<string name="discard_image">Discard image?</string>
|
||||
</resources>
|
||||
Loading…
x
Reference in New Issue
Block a user