Move post deletion to ensure download is complete before
This commit is contained in:
parent
20d38d3fa8
commit
79c2f2a391
@ -10,6 +10,7 @@ import android.graphics.drawable.AnimatedVectorDrawable
|
|||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.location.GnssAntennaInfo.Listener
|
import android.location.GnssAntennaInfo.Listener
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.text.method.LinkMovementMethod
|
import android.text.method.LinkMovementMethod
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
@ -18,6 +19,7 @@ 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
|
||||||
@ -40,6 +42,7 @@ import com.karumi.dexter.listener.PermissionDeniedResponse
|
|||||||
import com.karumi.dexter.listener.PermissionGrantedResponse
|
import com.karumi.dexter.listener.PermissionGrantedResponse
|
||||||
import com.karumi.dexter.listener.single.BasePermissionListener
|
import com.karumi.dexter.listener.single.BasePermissionListener
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import okhttp3.*
|
import okhttp3.*
|
||||||
import okio.BufferedSink
|
import okio.BufferedSink
|
||||||
import okio.buffer
|
import okio.buffer
|
||||||
@ -506,6 +509,13 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
|
|||||||
// Wait for all outstanding downloads to finish
|
// Wait for all outstanding downloads to finish
|
||||||
if (counter.incrementAndGet() == imageUris.size) {
|
if (counter.incrementAndGet() == imageUris.size) {
|
||||||
if (allFilesExist(imageNames)) {
|
if (allFilesExist(imageNames)) {
|
||||||
|
// Delete original post
|
||||||
|
Handler(Looper.getMainLooper()).post {
|
||||||
|
runBlocking {
|
||||||
|
deletePost(apiHolder.api ?: apiHolder.setToCurrentUser(), db)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val counterInt = counter.get()
|
val counterInt = counter.get()
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
binding.root.context,
|
binding.root.context,
|
||||||
@ -574,6 +584,7 @@ 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) {
|
||||||
@ -587,7 +598,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,
|
||||||
@ -615,6 +626,7 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
|
|||||||
continuation()
|
continuation()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
continuation()
|
continuation()
|
||||||
}
|
}
|
||||||
@ -636,13 +648,6 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
|
|||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete original post
|
|
||||||
deletePost(
|
|
||||||
apiHolder.api ?: apiHolder.setToCurrentUser(),
|
|
||||||
db
|
|
||||||
)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setNegativeButton(android.R.string.cancel) { _, _ -> }
|
setNegativeButton(android.R.string.cancel) { _, _ -> }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user