Show file name on saving

This commit is contained in:
Matéo Duparc 2021-06-20 16:12:01 +02:00
parent f7418cf9c2
commit 335e786f79
Signed by: hardcoresushi
GPG Key ID: 007F84120107191E
5 changed files with 11 additions and 9 deletions

View File

@ -365,10 +365,11 @@ class ChatActivity : ServiceBoundActivity() {
if (buffer == null) {
Toast.makeText(this, R.string.loadFile_failed, Toast.LENGTH_SHORT).show()
} else {
FileUtils.openFileForDownload(this, fileName)?.apply {
val file = FileUtils.openFileForDownload(this, fileName)
file.outputStream?.apply {
write(buffer)
close()
Toast.makeText(this@ChatActivity, R.string.file_saved, Toast.LENGTH_SHORT).show()
Toast.makeText(this@ChatActivity, getString(R.string.file_saved, file.fileName), Toast.LENGTH_SHORT).show()
}
}
}

View File

@ -633,7 +633,7 @@ class AIRAService : Service() {
receiveFileTransfers[sessionId]?.let { filesReceiver ->
val file = filesReceiver.files[filesReceiver.index]
if (file.outputStream == null) {
val outputStream = FileUtils.openFileForDownload(this, file.fileName)
val outputStream = FileUtils.openFileForDownload(this, file.fileName).outputStream
if (outputStream == null) {
cancelFileTransfer(sessionId)
} else {

View File

@ -1,6 +1,5 @@
package sushi.hardcore.aira.utils
import android.content.ContentResolver
import android.content.ContentValues
import android.content.Context
import android.net.Uri
@ -9,7 +8,6 @@ import android.provider.MediaStore
import android.provider.OpenableColumns
import android.webkit.MimeTypeMap
import android.widget.Toast
import sushi.hardcore.aira.background_service.ReceiveFile
import sushi.hardcore.aira.background_service.SendFile
import java.io.File
import java.io.FileNotFoundException
@ -51,7 +49,9 @@ object FileUtils {
return sendFile
}
fun openFileForDownload(context: Context, fileName: String): OutputStream? {
class DownloadFile(val fileName: String, val outputStream: OutputStream?)
fun openFileForDownload(context: Context, fileName: String): DownloadFile {
val fileExtension = fileName.substringAfterLast(".")
val dateExtension = SimpleDateFormat("yyyyMMddHHmmss", Locale.getDefault()).format(Date())
val datedFilename = if (fileName.contains(".")) {
@ -60,7 +60,7 @@ object FileUtils {
} else {
fileName + "_" + dateExtension
}
return if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
val outputStream = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
context.contentResolver.insert(
MediaStore.Downloads.EXTERNAL_CONTENT_URI,
ContentValues().apply {
@ -75,5 +75,6 @@ object FileUtils {
@Suppress("Deprecation")
File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), File(datedFilename).name).outputStream()
}
return DownloadFile(datedFilename, outputStream)
}
}

View File

@ -54,7 +54,7 @@
android:hint="@string/message_hint"
android:autofillHints="message"
style="@style/EditText"
android:inputType="textShortMessage|textAutoCorrect|textCapSentences"
android:inputType="textMultiLine|textShortMessage|textAutoCorrect|textCapSentences"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/bottom_image_trust_level"

View File

@ -14,7 +14,7 @@
<string name="login">Login</string>
<string name="add_peer_ip">Add peer by IP</string>
<string name="unknown">Unknown</string>
<string name="file_saved">File saved !</string>
<string name="file_saved">File saved to %s !</string>
<string name="enter_password">Enter your password:</string>
<string name="yes">Yes</string>
<string name="no">No</string>