improve composing statuses
This commit is contained in:
parent
a96abd1343
commit
99c1a3ec87
|
@ -4,21 +4,24 @@ import android.app.Activity
|
|||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.activity.viewModels
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import at.connyduck.pixelcat.R
|
||||
import at.connyduck.pixelcat.components.general.BaseActivity
|
||||
import at.connyduck.pixelcat.dagger.ViewModelFactory
|
||||
import at.connyduck.pixelcat.databinding.ActivityComposeBinding
|
||||
import at.connyduck.pixelcat.util.viewBinding
|
||||
import com.fxn.pix.Options
|
||||
import com.fxn.pix.Pix
|
||||
import com.fxn.utility.ImageQuality
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
||||
class ComposeActivity : BaseActivity() {
|
||||
class ComposeActivity : BaseActivity(), OnImageActionClickListener {
|
||||
|
||||
@Inject
|
||||
lateinit var viewModelFactory: ViewModelFactory
|
||||
|
@ -27,7 +30,7 @@ class ComposeActivity : BaseActivity() {
|
|||
|
||||
private val binding by viewBinding(ActivityComposeBinding::inflate)
|
||||
|
||||
private val adapter = ComposeImageAdapter()
|
||||
private val adapter = ComposeImageAdapter(this)
|
||||
|
||||
private lateinit var visibilityBottomSheet: BottomSheetBehavior<*>
|
||||
|
||||
|
@ -44,20 +47,28 @@ class ComposeActivity : BaseActivity() {
|
|||
insets.consumeSystemWindowInsets()
|
||||
}
|
||||
|
||||
if (viewModel.images.value.isNullOrEmpty()) {
|
||||
if (viewModel.imageLiveData.value.isNullOrEmpty()) {
|
||||
viewModel.addImage(intent.getStringExtra(EXTRA_MEDIA_URI)!!)
|
||||
}
|
||||
|
||||
setSupportActionBar(binding.composeToolBar)
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
binding.composeToolBar.setNavigationOnClickListener {
|
||||
onBackPressed()
|
||||
}
|
||||
|
||||
binding.composeImages.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)
|
||||
binding.composeImages.adapter = adapter
|
||||
|
||||
visibilityBottomSheet = BottomSheetBehavior.from(binding.composeVisibilityBottomSheet)
|
||||
visibilityBottomSheet.state = BottomSheetBehavior.STATE_HIDDEN
|
||||
|
||||
binding.composeShareButton.setOnClickListener {
|
||||
viewModel.sendStatus()
|
||||
lifecycleScope.launch {
|
||||
viewModel.sendStatus(
|
||||
caption = binding.composeCaptionInput.text?.toString().orEmpty(),
|
||||
sensitive = binding.composeNsfwSwitch.isChecked
|
||||
)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
binding.composeVisibilityButton.setOnClickListener {
|
||||
|
@ -73,7 +84,7 @@ class ComposeActivity : BaseActivity() {
|
|||
changeVisibility(VISIBILITY.FOLLOWERS_ONLY)
|
||||
}
|
||||
|
||||
viewModel.images.observe(
|
||||
viewModel.imageLiveData.observe(
|
||||
this,
|
||||
Observer {
|
||||
adapter.submitList(it)
|
||||
|
@ -99,14 +110,22 @@ class ComposeActivity : BaseActivity() {
|
|||
if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_CODE_PICK_MEDIA) {
|
||||
val returnValue =
|
||||
data?.getStringArrayListExtra(Pix.IMAGE_RESULTS)
|
||||
Log.e("Result", returnValue.toString())
|
||||
viewModel.addImage(returnValue?.first()!!)
|
||||
}
|
||||
}
|
||||
|
||||
private fun changeVisibility(visibility: VISIBILITY) {
|
||||
viewModel.setVisibility(visibility)
|
||||
visibilityBottomSheet.state = BottomSheetBehavior.STATE_COLLAPSED
|
||||
visibilityBottomSheet.state = BottomSheetBehavior.STATE_HIDDEN
|
||||
}
|
||||
|
||||
override fun onAddImage() {
|
||||
val options = Options.init()
|
||||
.setRequestCode(REQUEST_CODE_PICK_MEDIA)
|
||||
.setImageQuality(ImageQuality.HIGH)
|
||||
.setScreenOrientation(Options.SCREEN_ORIENTATION_PORTRAIT)
|
||||
|
||||
Pix.start(this, options)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -2,15 +2,23 @@ package at.connyduck.pixelcat.components.compose
|
|||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.setPadding
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import at.connyduck.pixelcat.R
|
||||
import at.connyduck.pixelcat.databinding.ItemComposeImageBinding
|
||||
import at.connyduck.sparkbutton.helpers.Utils
|
||||
import coil.api.load
|
||||
import java.io.File
|
||||
|
||||
class ComposeImageAdapter : ListAdapter<String, ComposeImageViewHolder>(
|
||||
interface OnImageActionClickListener {
|
||||
fun onAddImage()
|
||||
}
|
||||
|
||||
class ComposeImageAdapter(
|
||||
private val listener: OnImageActionClickListener
|
||||
) : ListAdapter<String, ComposeImageViewHolder>(
|
||||
object : DiffUtil.ItemCallback<String>() {
|
||||
override fun areItemsTheSame(old: String, new: String): Boolean {
|
||||
return old == new
|
||||
|
@ -32,13 +40,27 @@ class ComposeImageAdapter : ListAdapter<String, ComposeImageViewHolder>(
|
|||
|
||||
getItem(position)?.let { uri ->
|
||||
|
||||
if (uri == ADD_ITEM) {
|
||||
holder.binding.root.load(R.drawable.ic_plus_square_large)
|
||||
holder.binding.root.setPadding(Utils.dpToPx(holder.binding.root.context, 40))
|
||||
holder.binding.root.setOnClickListener {
|
||||
listener.onAddImage()
|
||||
}
|
||||
return
|
||||
} else {
|
||||
holder.binding.root.load(File(uri)) {
|
||||
placeholder(R.drawable.ic_cat)
|
||||
error(R.drawable.ic_message)
|
||||
}
|
||||
holder.binding.root.setOnClickListener {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val ADD_ITEM = "add_item"
|
||||
}
|
||||
}
|
||||
|
||||
class ComposeImageViewHolder(val binding: ItemComposeImageBinding) :
|
||||
RecyclerView.ViewHolder(binding.root)
|
||||
|
|
|
@ -4,9 +4,8 @@ import android.content.Context
|
|||
import androidx.core.content.ContextCompat
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import at.connyduck.pixelcat.components.compose.ComposeImageAdapter.Companion.ADD_ITEM
|
||||
import at.connyduck.pixelcat.db.AccountManager
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
||||
class ComposeViewModel @Inject constructor(
|
||||
|
@ -14,33 +13,41 @@ class ComposeViewModel @Inject constructor(
|
|||
val accountManager: AccountManager
|
||||
) : ViewModel() {
|
||||
|
||||
val images = MutableLiveData<List<String>>()
|
||||
private val images: MutableList<String> = mutableListOf()
|
||||
|
||||
val imageLiveData = MutableLiveData<List<String>>()
|
||||
|
||||
val visibility = MutableLiveData(VISIBILITY.PUBLIC)
|
||||
|
||||
fun addImage(imageUri: String) {
|
||||
|
||||
images.value = images.value.orEmpty() + imageUri
|
||||
images.add(imageUri)
|
||||
imageLiveData.value = if (images.size < MAX_IMAGE_COUNT) {
|
||||
images + ADD_ITEM
|
||||
} else {
|
||||
images
|
||||
}
|
||||
}
|
||||
|
||||
fun setVisibility(visibility: VISIBILITY) {
|
||||
this.visibility.value = visibility
|
||||
}
|
||||
|
||||
fun sendStatus() {
|
||||
suspend fun sendStatus(caption: String, sensitive: Boolean) {
|
||||
|
||||
viewModelScope.launch {
|
||||
val statusToSend = StatusToSend(
|
||||
accountId = accountManager.activeAccount()!!.id,
|
||||
text = "test",
|
||||
text = caption,
|
||||
visibility = visibility.value!!.serverName,
|
||||
sensitive = false,
|
||||
mediaUris = images.value!!
|
||||
sensitive = sensitive,
|
||||
mediaUris = images
|
||||
)
|
||||
|
||||
val intent = SendStatusService.sendStatusIntent(context, statusToSend)
|
||||
ContextCompat.startForegroundService(context, intent)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val MAX_IMAGE_COUNT = 4
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ package at.connyduck.pixelcat.components.main
|
|||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.widget.LinearLayout
|
||||
import androidx.activity.viewModels
|
||||
import at.connyduck.pixelcat.R
|
||||
|
@ -93,7 +92,6 @@ class MainActivity : BaseActivity() {
|
|||
if (resultCode == Activity.RESULT_OK && requestCode == 100) {
|
||||
val returnValue =
|
||||
data?.getStringArrayListExtra(Pix.IMAGE_RESULTS)
|
||||
Log.e("Result", returnValue.toString())
|
||||
|
||||
startActivity(ComposeActivity.newIntent(this, returnValue?.firstOrNull()!!))
|
||||
}
|
||||
|
|
|
@ -3,5 +3,5 @@
|
|||
<corners
|
||||
android:topLeftRadius="12dp"
|
||||
android:topRightRadius="12dp" />
|
||||
<solid android:color="#f0f" />
|
||||
<solid android:color="?attr/colorSurface" />
|
||||
</shape>
|
|
@ -0,0 +1,27 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="80dp"
|
||||
android:height="80dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M5,3L19,3A2,2 0,0 1,21 5L21,19A2,2 0,0 1,19 21L5,21A2,2 0,0 1,3 19L3,5A2,2 0,0 1,5 3z"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="1"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#777"
|
||||
android:strokeLineCap="round"/>
|
||||
<path
|
||||
android:pathData="M12,8L12,16"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="1"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#777"
|
||||
android:strokeLineCap="round"/>
|
||||
<path
|
||||
android:pathData="M8,12L16,12"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="1"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#777"
|
||||
android:strokeLineCap="round"/>
|
||||
</vector>
|
|
@ -28,6 +28,7 @@
|
|||
android:layout_gravity="end"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:text="@string/compose_action_share" />
|
||||
|
||||
</androidx.appcompat.widget.Toolbar>
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
@ -44,12 +45,13 @@
|
|||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/composeImages"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="200dp"
|
||||
android:layout_height="160dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:orientation="horizontal"
|
||||
app:layout_constraintTop_toBottomOf="@id/composeAppBar" />
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/composeDescriptionInputLayout"
|
||||
android:id="@+id/composeCaptionInputLayout"
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -60,11 +62,11 @@
|
|||
app:layout_constraintTop_toBottomOf="@+id/loginImageView">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/composeDescriptionInput"
|
||||
android:id="@+id/composeCaptionInput"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="10"
|
||||
android:inputType="text" />
|
||||
android:inputType="textMultiLine" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
|
@ -72,7 +74,8 @@
|
|||
android:id="@+id/composeNsfwSwitch"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="12dp"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:paddingVertical="12dp"
|
||||
android:text="@string/compose_contains_nsfw_media"
|
||||
android:textColor="?android:textColorSecondary" />
|
||||
|
||||
|
@ -80,7 +83,8 @@
|
|||
android:id="@+id/composeVisibilityButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="12dp"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:paddingVertical="12dp"
|
||||
tools:text="@string/compose_visibility" />
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -100,21 +104,24 @@
|
|||
android:id="@+id/composeVisibilityPublic"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="12dp"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:paddingVertical="12dp"
|
||||
android:text="@string/compose_visibility_public" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/composeVisibilityUnlisted"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="12dp"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:paddingVertical="12dp"
|
||||
android:text="@string/compose_visibility_unlisted" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/composeVisibilityFollowers"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="12dp"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:paddingVertical="12dp"
|
||||
android:text="@string/compose_visibility_followers_only" />
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="200dp"
|
||||
android:adjustViewBounds="true" />
|
||||
android:layout_width="160dp"
|
||||
android:layout_height="160dp" />
|
||||
|
|
Loading…
Reference in New Issue