mirror of
https://gitlab.shinice.net/pixeldroid/PixelDroid
synced 2025-01-27 05:54:50 +01:00
Merge branch 'description_crash' into 'master'
Fix crash when editing description without images Closes #287 See merge request pixeldroid/PixelDroid!324
This commit is contained in:
commit
23cd046ab1
@ -59,7 +59,6 @@ data class PhotoData(
|
||||
class PostCreationActivity : BaseActivity() {
|
||||
|
||||
private lateinit var accessToken: String
|
||||
private lateinit var pixelfedAPI: PixelfedAPI
|
||||
|
||||
private var user: UserDatabaseEntity? = null
|
||||
private lateinit var instance: InstanceDatabaseEntity
|
||||
@ -87,7 +86,6 @@ class PostCreationActivity : BaseActivity() {
|
||||
intent.clipData?.let { addPossibleImages(it) }
|
||||
|
||||
accessToken = user?.accessToken.orEmpty()
|
||||
pixelfedAPI = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db)
|
||||
|
||||
val carousel: ImageCarousel = binding.carousel
|
||||
carousel.addData(photoData.map { CarouselItem(it.imageUri) })
|
||||
@ -105,7 +103,7 @@ class PostCreationActivity : BaseActivity() {
|
||||
addPhoto()
|
||||
}
|
||||
carousel.updateDescriptionCallback = { position: Int, description: String ->
|
||||
photoData[position].imageDescription = description
|
||||
photoData.getOrNull(position)?.imageDescription = description
|
||||
}
|
||||
|
||||
// get the description and send the post
|
||||
@ -339,8 +337,8 @@ class PostCreationActivity : BaseActivity() {
|
||||
|
||||
val description = data.imageDescription?.let { MultipartBody.Part.createFormData("description", it) }
|
||||
|
||||
|
||||
val inter = pixelfedAPI.mediaUpload("Bearer $accessToken", description, requestBody.parts[0])
|
||||
val api = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db)
|
||||
val inter = api.mediaUpload("Bearer $accessToken", description, requestBody.parts[0])
|
||||
|
||||
postSub = inter
|
||||
.subscribeOn(Schedulers.io())
|
||||
@ -382,7 +380,9 @@ class PostCreationActivity : BaseActivity() {
|
||||
enableButton(false)
|
||||
lifecycleScope.launchWhenCreated {
|
||||
try {
|
||||
pixelfedAPI.postStatus(
|
||||
val api = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db)
|
||||
|
||||
api.postStatus(
|
||||
authorization = "Bearer $accessToken",
|
||||
statusText = description,
|
||||
media_ids = photoData.mapNotNull { it.uploadId }.toList()
|
||||
|
@ -96,8 +96,10 @@ class CarouselAdapter(
|
||||
}
|
||||
|
||||
fun updateDescription(position: Int, description: String) {
|
||||
dataList[position] = dataList[position].copy(caption = description)
|
||||
notifyItemChanged(position)
|
||||
dataList.getOrNull(position)?.apply {
|
||||
dataList[position] = copy(caption = description)
|
||||
notifyItemChanged(position)
|
||||
}
|
||||
}
|
||||
|
||||
fun addAll(dataList: List<CarouselItem>) {
|
||||
|
@ -44,7 +44,6 @@ class ImageCarousel(
|
||||
|
||||
private lateinit var recyclerView: RecyclerView
|
||||
private lateinit var tvCaption: TextView
|
||||
private lateinit var editTextMediaDescription: EditText
|
||||
private var snapHelper: SnapHelper = PagerSnapHelper()
|
||||
|
||||
var indicator: CircleIndicator2? = null
|
||||
@ -292,9 +291,9 @@ class ImageCarousel(
|
||||
|
||||
if(layoutCarousel){
|
||||
field = value
|
||||
if(value) editTextMediaDescription.setText(currentDescription)
|
||||
if(value) binding.editTextMediaDescription.setText(currentDescription)
|
||||
else {
|
||||
val description = editTextMediaDescription.text.toString()
|
||||
val description = binding.editTextMediaDescription.text.toString()
|
||||
currentDescription = description
|
||||
adapter?.updateDescription(currentPosition, description)
|
||||
updateDescriptionCallback?.invoke(currentPosition, description)
|
||||
@ -339,7 +338,6 @@ class ImageCarousel(
|
||||
|
||||
recyclerView = binding.recyclerView
|
||||
tvCaption = binding.tvCaption
|
||||
editTextMediaDescription = binding.editTextMediaDescription
|
||||
|
||||
recyclerView.setHasFixedSize(true)
|
||||
|
||||
|
@ -42,13 +42,14 @@
|
||||
android:id="@+id/editMediaDescriptionLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
android:background="#4D000000"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@+id/indicator"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_goneMarginBottom="8dp">
|
||||
app:layout_goneMarginBottom="8dp"
|
||||
tools:visibility="visible">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editTextMediaDescription"
|
||||
|
Loading…
x
Reference in New Issue
Block a user