Warn about immediate deletion

This commit is contained in:
fgerber 2022-10-26 21:03:57 +02:00
parent 8b625b43ad
commit 91819dd4db
7 changed files with 34 additions and 10 deletions

View File

@ -226,6 +226,23 @@ class PostCreationActivity : BaseThemedWithoutBarActivity() {
}
}
override fun onBackPressed() {
val redraft = intent.getBooleanExtra(PhotoEditActivity.POST_REDRAFT, false)
if (redraft) {
val builder = AlertDialog.Builder(binding.root.context)
builder.apply {
setMessage(R.string.redraft_dialog_cancel)
setPositiveButton(android.R.string.ok) { _, _ ->
super.onBackPressed()
}
setNegativeButton(android.R.string.cancel) { _, _ -> }
show()
}
} else {
super.onBackPressed()
}
}
private val addPhotoResultContract = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == Activity.RESULT_OK && result.data?.clipData != null) {
result.data?.clipData?.let {

View File

@ -147,7 +147,7 @@ class PostCreationViewModel(application: Application, clipdata: ClipData? = null
clipData.getItemAt(i).let {
val sizeAndVideoPair: Pair<Long, Boolean> =
getSizeAndVideoValidate(it.uri, (previousList?.size ?: 0) + dataToAdd.size + 1)
dataToAdd.add(PhotoData(imageUri = it.uri, size = sizeAndVideoPair.first, video = sizeAndVideoPair.second, imageDescription = it.text.toString()))
dataToAdd.add(PhotoData(imageUri = it.uri, size = sizeAndVideoPair.first, video = sizeAndVideoPair.second, imageDescription = it.text?.toString()))
}
}
return previousList?.plus(dataToAdd)?.toMutableList() ?: mutableListOf()

View File

@ -82,6 +82,7 @@ class PhotoEditActivity : BaseThemedWithBarActivity() {
internal const val PICTURE_POSITION = "picture_position"
internal const val PICTURE_DESCRIPTION = "picture_description"
internal const val TEMP_FILES = "temp_files"
internal const val POST_REDRAFT = "post_redraft"
private var executor: ExecutorService = newSingleThreadExecutor()
private var future: Future<*>? = null

View File

@ -40,6 +40,7 @@ import com.karumi.dexter.listener.PermissionDeniedResponse
import com.karumi.dexter.listener.PermissionGrantedResponse
import com.karumi.dexter.listener.single.BasePermissionListener
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import okhttp3.*
import okio.BufferedSink
import okio.buffer
@ -468,13 +469,12 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
R.id.post_more_menu_redraft -> {
val builder = AlertDialog.Builder(binding.root.context)
builder.apply {
setMessage(R.string.redraft_dialog)
setMessage(R.string.redraft_dialog_launch)
setPositiveButton(android.R.string.ok) { _, _ ->
lifecycleScope.launch {
val user = db.userDao().getActiveUser()!!
status?.id?.let { id ->
try {
// Create new post creation activity
val intent = Intent(context, PostCreationActivity::class.java)
@ -558,10 +558,13 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
fromHtml(postDescription!!).toString()
)
}
intent.putExtra(
PhotoEditActivity.TEMP_FILES,
imageUris.map{ uri -> uri.toString() }.toTypedArray()
)
if (imageUris.isNotEmpty()) {
intent.putExtra(
PhotoEditActivity.TEMP_FILES,
imageUris.map{ uri -> uri.toString() }.toTypedArray()
)
}
intent.putExtra(PhotoEditActivity.POST_REDRAFT, true)
// Launch post creation activity
binding.root.context.startActivity(intent)
@ -628,7 +631,6 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
}
// Delete original post
// TODO: move to better place since this also deletes the post even if redraft is cancelled
deletePost(apiHolder.api ?: apiHolder.setToCurrentUser(), db)
}
}

View File

@ -249,7 +249,8 @@ For more info about Pixelfed, you can check here: https://pixelfed.org"</string>
<string name="something_went_wrong">Something went wrong…</string>
<string name="panda_pull_to_refresh_to_try_again">This panda is not happy. Pull to refresh to try again.</string>
<string name="redraft">Redraft</string>
<string name="redraft_dialog">Redrafting this post will allow you to edit the photo and its description, but it will delete all current comments and likes. Continue?</string>
<string name="redraft_dialog_launch">Redrafting this post will allow you to edit the photo and its description, but it will delete all current comments and likes. Continue?</string>
<string name="redraft_dialog_cancel">If you cancel this redraft, the original post will no longer be on your account. Continue without reposting?</string>
<string name="delete">Delete</string>
<string name="delete_dialog">Delete this post?</string>
<string name="language">Language</string>

View File

@ -7,7 +7,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.0.0-alpha05'
classpath 'com.android.tools.build:gradle:8.0.0-alpha06'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong

View File

@ -3498,6 +3498,9 @@
<artifact name="aapt2-8.0.0-alpha06-8841542-linux.jar">
<sha256 value="3e6c747be8625506466585c3a327e7145a77d84796f6ec387eb855f9d4bd572e" origin="Generated by Gradle"/>
</artifact>
<artifact name="aapt2-8.0.0-alpha06-8841542-osx.jar">
<sha256 value="14b13c019a48aba57dbf6c5d315a4cafe1e502c22d0179124d16e9f7dc847f64" origin="Generated by Gradle"/>
</artifact>
<artifact name="aapt2-8.0.0-alpha06-8841542.pom">
<sha256 value="b9f6acccffdb833c1203650356699098b9dd9d9b0012d86b73bced1455f352de" origin="Generated by Gradle"/>
</artifact>