Compare commits
No commits in common. "e7e3db60b44b143230aabccd95034db6b137a9ee" and "490673052d71527f475ed60ec29075c68d2d0fbc" have entirely different histories.
e7e3db60b4
...
490673052d
@ -28,7 +28,9 @@
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<activity android:name=".ChatActivity"/>
|
||||
<activity
|
||||
android:name=".ChatActivity"
|
||||
android:windowSoftInputMode="adjustResize"/>
|
||||
<activity android:name=".MainActivity">
|
||||
<intent-filter android:label="@string/share_label">
|
||||
<action android:name="android.intent.action.SEND"/>
|
||||
|
@ -23,7 +23,6 @@ import sushi.hardcore.aira.databinding.DialogFingerprintsBinding
|
||||
import sushi.hardcore.aira.databinding.DialogInfoBinding
|
||||
import sushi.hardcore.aira.utils.FileUtils
|
||||
import sushi.hardcore.aira.utils.StringUtils
|
||||
import java.io.FileNotFoundException
|
||||
import java.util.*
|
||||
|
||||
class ChatActivity : AppCompatActivity() {
|
||||
@ -40,19 +39,15 @@ class ChatActivity : AppCompatActivity() {
|
||||
if (::airaService.isInitialized && uri != null) {
|
||||
contentResolver.query(uri, null, null, null, null)?.let { cursor ->
|
||||
if (cursor.moveToFirst()) {
|
||||
try {
|
||||
contentResolver.openInputStream(uri)?.let { inputStream ->
|
||||
val fileName = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME))
|
||||
val fileSize = cursor.getLong(cursor.getColumnIndex(OpenableColumns.SIZE))
|
||||
airaService.sendFileTo(sessionId, fileName, fileSize, inputStream)?.let { msg ->
|
||||
chatAdapter.newMessage(ChatItem(true, msg))
|
||||
}
|
||||
if (airaService.contacts.contains(sessionId)) {
|
||||
lastLoadedMessageOffset += 1
|
||||
}
|
||||
contentResolver.openInputStream(uri)?.let { inputStream ->
|
||||
val fileName = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME))
|
||||
val fileSize = cursor.getLong(cursor.getColumnIndex(OpenableColumns.SIZE))
|
||||
airaService.sendFileTo(sessionId, fileName, fileSize, inputStream)?.let { msg ->
|
||||
chatAdapter.newMessage(ChatItem(true, msg))
|
||||
}
|
||||
if (airaService.contacts.contains(sessionId)) {
|
||||
lastLoadedMessageOffset += 1
|
||||
}
|
||||
} catch (e: FileNotFoundException) {
|
||||
Toast.makeText(this, e.localizedMessage, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
cursor.close()
|
||||
@ -75,9 +70,7 @@ class ChatActivity : AppCompatActivity() {
|
||||
chatAdapter = ChatAdapter(this@ChatActivity, ::onClickSaveFile)
|
||||
binding.recyclerChat.apply {
|
||||
adapter = chatAdapter
|
||||
layoutManager = LinearLayoutManager(this@ChatActivity, LinearLayoutManager.VERTICAL, false).apply {
|
||||
stackFromEnd = true
|
||||
}
|
||||
layoutManager = LinearLayoutManager(this@ChatActivity, LinearLayoutManager.VERTICAL, false)
|
||||
addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||
fun loadMsgsIfNeeded(recyclerView: RecyclerView) {
|
||||
if (!recyclerView.canScrollVertically(-1) && ::airaService.isInitialized) {
|
||||
|
@ -10,7 +10,6 @@ import android.os.IBinder
|
||||
import android.provider.OpenableColumns
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.AbsListView
|
||||
import android.widget.AdapterView
|
||||
import android.widget.Toast
|
||||
@ -31,7 +30,7 @@ class MainActivity : AppCompatActivity() {
|
||||
private lateinit var binding: ActivityMainBinding
|
||||
private lateinit var airaService: AIRAService
|
||||
private lateinit var onlineSessionAdapter: SessionAdapter
|
||||
private var offlineSessionAdapter: SessionAdapter? = null
|
||||
private lateinit var offlineSessionAdapter: SessionAdapter
|
||||
private val onSessionsItemClick = AdapterView.OnItemClickListener { adapter, _, position, _ ->
|
||||
launchChatActivity(adapter.getItemAtPosition(position) as Session)
|
||||
}
|
||||
@ -56,7 +55,7 @@ class MainActivity : AppCompatActivity() {
|
||||
runOnUiThread {
|
||||
onlineSessionAdapter.remove(sessionId)?.let { session ->
|
||||
if (session.isContact) {
|
||||
offlineSessionAdapter?.add(session)
|
||||
offlineSessionAdapter.add(session)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -101,20 +100,15 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
setOnScrollListener(onSessionsScrollListener)
|
||||
}
|
||||
if (openedToShareFile) {
|
||||
binding.offlineSessions.visibility = View.GONE
|
||||
binding.textOfflineSessions.visibility = View.GONE
|
||||
} else {
|
||||
offlineSessionAdapter = SessionAdapter(this)
|
||||
binding.offlineSessions.apply {
|
||||
adapter = offlineSessionAdapter
|
||||
onItemClickListener = if (openedToShareFile) {
|
||||
offlineSessionAdapter = SessionAdapter(this)
|
||||
binding.offlineSessions.apply {
|
||||
adapter = offlineSessionAdapter
|
||||
onItemClickListener = if (openedToShareFile) {
|
||||
onSessionsItemClickSendFile
|
||||
} else {
|
||||
onSessionsItemClick
|
||||
}
|
||||
setOnScrollListener(onSessionsScrollListener)
|
||||
}
|
||||
setOnScrollListener(onSessionsScrollListener)
|
||||
}
|
||||
Intent(this, AIRAService::class.java).also { serviceIntent ->
|
||||
bindService(serviceIntent, object : ServiceConnection {
|
||||
@ -212,7 +206,7 @@ class MainActivity : AppCompatActivity() {
|
||||
airaService.isAppInBackground = false
|
||||
airaService.uiCallbacks = uiCallbacks //restoring callbacks
|
||||
onlineSessionAdapter.reset()
|
||||
offlineSessionAdapter?.reset()
|
||||
offlineSessionAdapter.reset()
|
||||
loadContacts()
|
||||
loadSessions()
|
||||
title = airaService.identityName
|
||||
@ -223,10 +217,8 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun loadContacts() {
|
||||
if (offlineSessionAdapter != null) {
|
||||
for ((sessionId, contact) in airaService.contacts) {
|
||||
offlineSessionAdapter!!.add(Session(sessionId, true, contact.verified, contact.seen, null, contact.name))
|
||||
}
|
||||
for ((sessionId, contact) in airaService.contacts) {
|
||||
offlineSessionAdapter.add(Session(sessionId, true, contact.verified, contact.seen, null, contact.name))
|
||||
}
|
||||
}
|
||||
|
||||
@ -243,7 +235,7 @@ class MainActivity : AppCompatActivity() {
|
||||
onlineSessionAdapter.add(Session(sessionId, false, false, seen, ip, airaService.savedNames[sessionId]))
|
||||
} else {
|
||||
onlineSessionAdapter.add(Session(sessionId, true, contact.verified, seen, ip, contact.name))
|
||||
offlineSessionAdapter?.remove(sessionId)
|
||||
offlineSessionAdapter.remove(sessionId)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,6 @@ import android.net.nsd.NsdServiceInfo
|
||||
import android.os.*
|
||||
import android.os.Process.THREAD_PRIORITY_BACKGROUND
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
@ -17,6 +16,7 @@ import sushi.hardcore.aira.*
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.net.*
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.channels.*
|
||||
|
||||
class AIRAService : Service() {
|
||||
@ -143,14 +143,10 @@ class AIRAService : Service() {
|
||||
return msg
|
||||
}
|
||||
} else {
|
||||
if (sendFileTransfers[sessionId] == null && receiveFileTransfers[sessionId] == null) {
|
||||
val fileTransfer = SendFileTransfer(fileName, fileSize, inputStream)
|
||||
sendFileTransfers[sessionId] = fileTransfer
|
||||
createFileTransferNotification(sessionId, fileTransfer)
|
||||
sendTo(sessionId, Protocol.askLargeFile(fileSize, fileName))
|
||||
} else {
|
||||
Toast.makeText(this, R.string.file_transfer_already_in_progress, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
val fileTransfer = SendFileTransfer(fileName, fileSize, inputStream)
|
||||
sendFileTransfers[sessionId] = fileTransfer
|
||||
createFileTransferNotification(sessionId, fileTransfer)
|
||||
sendTo(sessionId, Protocol.askLargeFile(fileSize, fileName))
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
@ -71,5 +71,4 @@
|
||||
<string name="remove_contact">Remove contact</string>
|
||||
<string name="details">Details</string>
|
||||
<string name="your_addresses">Your IP addresses:</string>
|
||||
<string name="file_transfer_already_in_progress">Another file transfer is already in progress</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user