Fix share intent handling bugs
This commit is contained in:
parent
eac227085d
commit
c6f1e6d432
|
@ -311,7 +311,10 @@ class ChatActivity : ServiceBoundActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun scrollToBottom() {
|
private fun scrollToBottom() {
|
||||||
binding.recyclerChat.smoothScrollToPosition(chatAdapter.itemCount-1)
|
val target = chatAdapter.itemCount-1
|
||||||
|
if (target >= 0) {
|
||||||
|
binding.recyclerChat.smoothScrollToPosition(target)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
|
|
|
@ -8,7 +8,6 @@ import android.os.Bundle
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
|
||||||
import android.widget.AbsListView
|
import android.widget.AbsListView
|
||||||
import android.widget.AdapterView
|
import android.widget.AdapterView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
@ -117,33 +116,28 @@ class MainActivity : ServiceBoundActivity() {
|
||||||
}
|
}
|
||||||
setOnScrollListener(onSessionsScrollListener)
|
setOnScrollListener(onSessionsScrollListener)
|
||||||
}
|
}
|
||||||
if (openedToShareFile) {
|
offlineSessionAdapter = SessionAdapter(this)
|
||||||
binding.offlineSessions.visibility = View.GONE
|
binding.offlineSessions.apply {
|
||||||
binding.textOfflineSessions.visibility = View.GONE
|
adapter = offlineSessionAdapter
|
||||||
} else {
|
onItemClickListener = if (openedToShareFile) {
|
||||||
offlineSessionAdapter = SessionAdapter(this)
|
onSessionsItemClickSendFile
|
||||||
binding.offlineSessions.apply {
|
} else {
|
||||||
adapter = offlineSessionAdapter
|
AdapterView.OnItemClickListener { _, _, position, _ ->
|
||||||
onItemClickListener = if (openedToShareFile) {
|
if (isSelecting()) {
|
||||||
onSessionsItemClickSendFile
|
changeSelection(offlineSessionAdapter!!, position)
|
||||||
} else {
|
} else {
|
||||||
AdapterView.OnItemClickListener { _, _, position, _ ->
|
launchChatActivity(offlineSessionAdapter!!.getItem(position))
|
||||||
if (isSelecting()) {
|
|
||||||
changeSelection(offlineSessionAdapter!!, position)
|
|
||||||
} else {
|
|
||||||
launchChatActivity(offlineSessionAdapter!!.getItem(position))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onItemLongClickListener = AdapterView.OnItemLongClickListener { _, _, position, _ ->
|
|
||||||
changeSelection(offlineSessionAdapter!!, position)
|
|
||||||
true
|
|
||||||
}
|
|
||||||
setOnScrollListener(onSessionsScrollListener)
|
|
||||||
}
|
}
|
||||||
if (intent.action == NotificationBroadcastReceiver.ACTION_LOGOUT) {
|
onItemLongClickListener = AdapterView.OnItemLongClickListener { _, _, position, _ ->
|
||||||
askLogOut()
|
changeSelection(offlineSessionAdapter!!, position)
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
setOnScrollListener(onSessionsScrollListener)
|
||||||
|
}
|
||||||
|
if (intent.action == NotificationBroadcastReceiver.ACTION_LOGOUT) {
|
||||||
|
askLogOut()
|
||||||
}
|
}
|
||||||
serviceConnection = object : ServiceConnection {
|
serviceConnection = object : ServiceConnection {
|
||||||
override fun onServiceConnected(name: ComponentName?, service: IBinder) {
|
override fun onServiceConnected(name: ComponentName?, service: IBinder) {
|
||||||
|
@ -347,13 +341,15 @@ class MainActivity : ServiceBoundActivity() {
|
||||||
Toast.makeText(this, R.string.open_uri_failed, Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, R.string.open_uri_failed, Toast.LENGTH_SHORT).show()
|
||||||
} else {
|
} else {
|
||||||
val msg = if (uris!!.size == 1) {
|
val msg = if (uris!!.size == 1) {
|
||||||
val sendFile = FileUtils.openFileFromUri(this, uris!![0])
|
val result = FileUtils.openFileFromUri(this, uris!![0])
|
||||||
if (sendFile == null) {
|
if (result.file == null) {
|
||||||
Toast.makeText(this, R.string.open_uri_failed, Toast.LENGTH_SHORT).show()
|
if (!result.errorHandled) {
|
||||||
|
Toast.makeText(this, R.string.open_uri_failed, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
sendFile.inputStream.close()
|
result.file.inputStream.close()
|
||||||
getString(R.string.ask_send_single_file, sendFile.fileName, FileUtils.formatSize(sendFile.fileSize), session.name ?: session.ip)
|
getString(R.string.ask_send_single_file, result.file.fileName, FileUtils.formatSize(result.file.fileSize), session.name ?: session.ip)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
getString(R.string.ask_send_multiple_files, uris!!.size, session.name ?: session.ip)
|
getString(R.string.ask_send_multiple_files, uris!!.size, session.name ?: session.ip)
|
||||||
|
|
|
@ -159,7 +159,7 @@ class AIRAService : Service() {
|
||||||
val files = mutableListOf<SendFile>()
|
val files = mutableListOf<SendFile>()
|
||||||
var useLargeFileTransfer = false
|
var useLargeFileTransfer = false
|
||||||
for (uri in uris) {
|
for (uri in uris) {
|
||||||
FileUtils.openFileFromUri(this, uri)?.let { sendFile ->
|
FileUtils.openFileFromUri(this, uri).file?.let { sendFile ->
|
||||||
files.add(sendFile)
|
files.add(sendFile)
|
||||||
if (sendFile.fileSize > Constants.fileSizeLimit) {
|
if (sendFile.fileSize > Constants.fileSizeLimit) {
|
||||||
useLargeFileTransfer = true
|
useLargeFileTransfer = true
|
||||||
|
|
|
@ -2,6 +2,7 @@ package sushi.hardcore.aira.utils
|
||||||
|
|
||||||
import android.content.ContentValues
|
import android.content.ContentValues
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
|
@ -15,8 +16,8 @@ import java.io.OutputStream
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.math.pow
|
|
||||||
import kotlin.math.log10
|
import kotlin.math.log10
|
||||||
|
import kotlin.math.pow
|
||||||
|
|
||||||
object FileUtils {
|
object FileUtils {
|
||||||
private val units = arrayOf("B", "kB", "MB", "GB", "TB")
|
private val units = arrayOf("B", "kB", "MB", "GB", "TB")
|
||||||
|
@ -29,8 +30,16 @@ object FileUtils {
|
||||||
) + " " + units[digitGroups]
|
) + " " + units[digitGroups]
|
||||||
}
|
}
|
||||||
|
|
||||||
fun openFileFromUri(context: Context, uri: Uri): SendFile? {
|
class SendFileResult(val file: SendFile? = null, val errorHandled: Boolean = false)
|
||||||
|
|
||||||
|
fun openFileFromUri(context: Context, uri: Uri): SendFileResult {
|
||||||
var sendFile: SendFile? = null
|
var sendFile: SendFile? = null
|
||||||
|
try {
|
||||||
|
context.grantUriPermission(context.packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
|
} catch (e: SecurityException) {
|
||||||
|
Toast.makeText(context, e.localizedMessage, Toast.LENGTH_LONG).show()
|
||||||
|
return SendFileResult(sendFile, true)
|
||||||
|
}
|
||||||
val cursor = context.contentResolver.query(uri, null, null, null, null)
|
val cursor = context.contentResolver.query(uri, null, null, null, null)
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
if (cursor.moveToFirst()) {
|
if (cursor.moveToFirst()) {
|
||||||
|
@ -46,7 +55,7 @@ object FileUtils {
|
||||||
}
|
}
|
||||||
cursor.close()
|
cursor.close()
|
||||||
}
|
}
|
||||||
return sendFile
|
return SendFileResult(sendFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
class DownloadFile(val fileName: String, val outputStream: OutputStream?)
|
class DownloadFile(val fileName: String, val outputStream: OutputStream?)
|
||||||
|
|
Loading…
Reference in New Issue