Don't show offline contacts when opened to share file

This commit is contained in:
Matéo Duparc 2021-05-04 20:52:24 +02:00
parent 490673052d
commit 58804bef67
Signed by: hardcoresushi
GPG Key ID: 007F84120107191E

View File

@ -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)
} }
} }