Account for NSFW status in redraft
This commit is contained in:
parent
8ed13cdf2e
commit
e5ff66a83e
@ -48,6 +48,7 @@ class PostCreationActivity : BaseThemedWithoutBarActivity() {
|
|||||||
internal const val PICTURE_DESCRIPTION = "picture_description"
|
internal const val PICTURE_DESCRIPTION = "picture_description"
|
||||||
internal const val TEMP_FILES = "temp_files"
|
internal const val TEMP_FILES = "temp_files"
|
||||||
internal const val POST_REDRAFT = "post_redraft"
|
internal const val POST_REDRAFT = "post_redraft"
|
||||||
|
internal const val POST_NSFW = "post_nsfw"
|
||||||
}
|
}
|
||||||
|
|
||||||
private var user: UserDatabaseEntity? = null
|
private var user: UserDatabaseEntity? = null
|
||||||
@ -94,6 +95,7 @@ class PostCreationActivity : BaseThemedWithoutBarActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model.setExistingDescription(intent.getStringExtra(PICTURE_DESCRIPTION))
|
model.setExistingDescription(intent.getStringExtra(PICTURE_DESCRIPTION))
|
||||||
|
model.setExistingNSFW(intent.getBooleanExtra(POST_NSFW, false))
|
||||||
|
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||||
|
@ -82,6 +82,7 @@ class PostCreationViewModel(application: Application, clipdata: ClipData? = null
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
private var existingDescription: String? = null
|
private var existingDescription: String? = null
|
||||||
|
private var existingNSFW: Boolean = false
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var apiHolder: PixelfedAPIHolder
|
lateinit var apiHolder: PixelfedAPIHolder
|
||||||
@ -199,6 +200,10 @@ class PostCreationViewModel(application: Application, clipdata: ClipData? = null
|
|||||||
existingDescription = description
|
existingDescription = description
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setExistingNSFW(sensitive: Boolean) {
|
||||||
|
existingNSFW = sensitive
|
||||||
|
}
|
||||||
|
|
||||||
fun removeAt(currentPosition: Int) {
|
fun removeAt(currentPosition: Int) {
|
||||||
photoData.value?.removeAt(currentPosition)
|
photoData.value?.removeAt(currentPosition)
|
||||||
_uiState.update {
|
_uiState.update {
|
||||||
@ -216,6 +221,7 @@ class PostCreationViewModel(application: Application, clipdata: ClipData? = null
|
|||||||
val intent = Intent(context, PostSubmissionActivity::class.java)
|
val intent = Intent(context, PostSubmissionActivity::class.java)
|
||||||
intent.putExtra(PostSubmissionActivity.PHOTO_DATA, getPhotoData().value?.let { ArrayList(it) })
|
intent.putExtra(PostSubmissionActivity.PHOTO_DATA, getPhotoData().value?.let { ArrayList(it) })
|
||||||
intent.putExtra(PostSubmissionActivity.PICTURE_DESCRIPTION, existingDescription)
|
intent.putExtra(PostSubmissionActivity.PICTURE_DESCRIPTION, existingDescription)
|
||||||
|
intent.putExtra(PostSubmissionActivity.POST_NSFW, existingNSFW)
|
||||||
ContextCompat.startActivity(context, intent, null)
|
ContextCompat.startActivity(context, intent, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,8 @@ class PostSubmissionActivity : BaseThemedWithoutBarActivity() {
|
|||||||
companion object {
|
companion object {
|
||||||
internal const val PICTURE_DESCRIPTION = "picture_description"
|
internal const val PICTURE_DESCRIPTION = "picture_description"
|
||||||
internal const val PHOTO_DATA = "photo_data"
|
internal const val PHOTO_DATA = "photo_data"
|
||||||
}
|
internal const val POST_NSFW = "post_nsfw"
|
||||||
|
}
|
||||||
|
|
||||||
private lateinit var accounts: List<UserDatabaseEntity>
|
private lateinit var accounts: List<UserDatabaseEntity>
|
||||||
private var selectedAccount: Int = -1
|
private var selectedAccount: Int = -1
|
||||||
@ -71,6 +72,10 @@ class PostSubmissionActivity : BaseThemedWithoutBarActivity() {
|
|||||||
|
|
||||||
model.setExistingDescription(intent.getStringExtra(PICTURE_DESCRIPTION))
|
model.setExistingDescription(intent.getStringExtra(PICTURE_DESCRIPTION))
|
||||||
|
|
||||||
|
val sensitive = intent.getBooleanExtra(POST_NSFW, false)
|
||||||
|
model.updateNSFW(sensitive)
|
||||||
|
binding.nsfwSwitch.isChecked = sensitive
|
||||||
|
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||||
model.uiState.collect { uiState ->
|
model.uiState.collect { uiState ->
|
||||||
@ -115,7 +120,6 @@ class PostSubmissionActivity : BaseThemedWithoutBarActivity() {
|
|||||||
existingDescription ?: model.uiState.value.newPostDescriptionText
|
existingDescription ?: model.uiState.value.newPostDescriptionText
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
binding.postTextInputLayout.counterMaxLength = instance.maxStatusChars
|
binding.postTextInputLayout.counterMaxLength = instance.maxStatusChars
|
||||||
|
|
||||||
setSquareImageFromURL(View(applicationContext), photoData!![0].imageUri.toString(), binding.postPreview)
|
setSquareImageFromURL(View(applicationContext), photoData!![0].imageUri.toString(), binding.postPreview)
|
||||||
|
@ -236,7 +236,7 @@ class PostSubmissionViewModel(application: Application, photodata: ArrayList<Pho
|
|||||||
val description = uiState.value.newPostDescriptionText
|
val description = uiState.value.newPostDescriptionText
|
||||||
|
|
||||||
//TODO investigate why this works but booleans don't
|
//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 ->
|
_uiState.update { currentUiState ->
|
||||||
currentUiState.copy(
|
currentUiState.copy(
|
||||||
|
@ -8,7 +8,6 @@ import android.content.Intent
|
|||||||
import android.graphics.Typeface
|
import android.graphics.Typeface
|
||||||
import android.graphics.drawable.AnimatedVectorDrawable
|
import android.graphics.drawable.AnimatedVectorDrawable
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.location.GnssAntennaInfo.Listener
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
@ -19,7 +18,6 @@ import android.view.Menu
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.*
|
import android.widget.*
|
||||||
import androidx.annotation.UiThread
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.view.WindowCompat
|
import androidx.core.view.WindowCompat
|
||||||
@ -486,6 +484,7 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
|
|||||||
val imageNames: MutableList<String> = mutableListOf()
|
val imageNames: MutableList<String> = mutableListOf()
|
||||||
val imageDescriptions: MutableList<String> =
|
val imageDescriptions: MutableList<String> =
|
||||||
mutableListOf()
|
mutableListOf()
|
||||||
|
val postNSFW = status?.sensitive
|
||||||
|
|
||||||
for (currentAttachment in postAttachments) {
|
for (currentAttachment in postAttachments) {
|
||||||
val imageUri = currentAttachment.url ?: ""
|
val imageUri = currentAttachment.url ?: ""
|
||||||
@ -569,6 +568,10 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
|
|||||||
PostCreationActivity.POST_REDRAFT,
|
PostCreationActivity.POST_REDRAFT,
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
|
intent.putExtra(
|
||||||
|
PostCreationActivity.POST_NSFW,
|
||||||
|
postNSFW
|
||||||
|
)
|
||||||
|
|
||||||
// Launch post creation activity
|
// Launch post creation activity
|
||||||
binding.root.context.startActivity(intent)
|
binding.root.context.startActivity(intent)
|
||||||
@ -584,7 +587,6 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
|
|||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
}
|
}
|
||||||
val okHttpClient = OkHttpClient()
|
|
||||||
|
|
||||||
// Iterate through all pictures of the original post
|
// Iterate through all pictures of the original post
|
||||||
for (currentAttachment in postAttachments) {
|
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?)
|
// Check whether image is in cache directory already (maybe rather do so using Glide in the future?)
|
||||||
if (!downloadedFile.exists()) {
|
if (!downloadedFile.exists()) {
|
||||||
okHttpClient.newCall(downloadRequest)
|
OkHttpClient().newCall(downloadRequest)
|
||||||
.enqueue(object : Callback {
|
.enqueue(object : Callback {
|
||||||
override fun onFailure(
|
override fun onFailure(
|
||||||
call: Call,
|
call: Call,
|
||||||
@ -626,7 +628,6 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
|
|||||||
continuation()
|
continuation()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
continuation()
|
continuation()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user