Account for NSFW status in redraft

This commit is contained in:
fgerber 2022-11-03 13:22:18 +01:00 committed by Fred
parent 79c2f2a391
commit 2e558017f2
5 changed files with 21 additions and 8 deletions

View File

@ -48,6 +48,7 @@ class PostCreationActivity : BaseThemedWithoutBarActivity() {
internal const val PICTURE_DESCRIPTION = "picture_description"
internal const val TEMP_FILES = "temp_files"
internal const val POST_REDRAFT = "post_redraft"
internal const val POST_NSFW = "post_nsfw"
}
private var user: UserDatabaseEntity? = null
@ -94,6 +95,7 @@ class PostCreationActivity : BaseThemedWithoutBarActivity() {
}
model.setExistingDescription(intent.getStringExtra(PICTURE_DESCRIPTION))
model.setExistingNSFW(intent.getBooleanExtra(POST_NSFW, false))
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {

View File

@ -82,6 +82,7 @@ class PostCreationViewModel(application: Application, clipdata: ClipData? = null
}
}
private var existingDescription: String? = null
private var existingNSFW: Boolean = false
@Inject
lateinit var apiHolder: PixelfedAPIHolder
@ -199,6 +200,10 @@ class PostCreationViewModel(application: Application, clipdata: ClipData? = null
existingDescription = description
}
fun setExistingNSFW(sensitive: Boolean) {
existingNSFW = sensitive
}
fun removeAt(currentPosition: Int) {
photoData.value?.removeAt(currentPosition)
_uiState.update {
@ -216,6 +221,7 @@ class PostCreationViewModel(application: Application, clipdata: ClipData? = null
val intent = Intent(context, PostSubmissionActivity::class.java)
intent.putExtra(PostSubmissionActivity.PHOTO_DATA, getPhotoData().value?.let { ArrayList(it) })
intent.putExtra(PostSubmissionActivity.PICTURE_DESCRIPTION, existingDescription)
intent.putExtra(PostSubmissionActivity.POST_NSFW, existingNSFW)
ContextCompat.startActivity(context, intent, null)
}

View File

@ -29,7 +29,8 @@ class PostSubmissionActivity : BaseThemedWithoutBarActivity() {
companion object {
internal const val PICTURE_DESCRIPTION = "picture_description"
internal const val PHOTO_DATA = "photo_data"
}
internal const val POST_NSFW = "post_nsfw"
}
private lateinit var accounts: List<UserDatabaseEntity>
private var selectedAccount: Int = -1
@ -71,6 +72,10 @@ class PostSubmissionActivity : BaseThemedWithoutBarActivity() {
model.setExistingDescription(intent.getStringExtra(PICTURE_DESCRIPTION))
val sensitive = intent.getBooleanExtra(POST_NSFW, false)
model.updateNSFW(sensitive)
binding.nsfwSwitch.isChecked = sensitive
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
model.uiState.collect { uiState ->
@ -115,7 +120,6 @@ class PostSubmissionActivity : BaseThemedWithoutBarActivity() {
existingDescription ?: model.uiState.value.newPostDescriptionText
)
binding.postTextInputLayout.counterMaxLength = instance.maxStatusChars
setSquareImageFromURL(View(applicationContext), photoData!![0].imageUri.toString(), binding.postPreview)

View File

@ -236,7 +236,7 @@ class PostSubmissionViewModel(application: Application, photodata: ArrayList<Pho
val description = uiState.value.newPostDescriptionText
//TODO investigate why this works but booleans don't
val nsfw = if(uiState.value.nsfw) 1 else 0
val nsfw = if (uiState.value.nsfw) 1 else 0
_uiState.update { currentUiState ->
currentUiState.copy(

View File

@ -8,7 +8,6 @@ import android.content.Intent
import android.graphics.Typeface
import android.graphics.drawable.AnimatedVectorDrawable
import android.graphics.drawable.Drawable
import android.location.GnssAntennaInfo.Listener
import android.net.Uri
import android.os.Handler
import android.os.Looper
@ -19,7 +18,6 @@ import android.view.Menu
import android.view.View
import android.view.ViewGroup
import android.widget.*
import androidx.annotation.UiThread
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.core.view.WindowCompat
@ -486,6 +484,7 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
val imageNames: MutableList<String> = mutableListOf()
val imageDescriptions: MutableList<String> =
mutableListOf()
val postNSFW = status?.sensitive
for (currentAttachment in postAttachments) {
val imageUri = currentAttachment.url ?: ""
@ -569,6 +568,10 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
PostCreationActivity.POST_REDRAFT,
true
)
intent.putExtra(
PostCreationActivity.POST_NSFW,
postNSFW
)
// Launch post creation activity
binding.root.context.startActivity(intent)
@ -584,7 +587,6 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
Toast.LENGTH_SHORT
).show()
}
val okHttpClient = OkHttpClient()
// Iterate through all pictures of the original post
for (currentAttachment in postAttachments) {
@ -598,7 +600,7 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
// Check whether image is in cache directory already (maybe rather do so using Glide in the future?)
if (!downloadedFile.exists()) {
okHttpClient.newCall(downloadRequest)
OkHttpClient().newCall(downloadRequest)
.enqueue(object : Callback {
override fun onFailure(
call: Call,
@ -626,7 +628,6 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
continuation()
}
})
} else {
continuation()
}