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