Refresh name feature

This commit is contained in:
Matéo Duparc 2021-05-11 16:18:01 +02:00
parent 163637c710
commit d6a7d1466d
Signed by: hardcoresushi
GPG Key ID: 007F84120107191E
6 changed files with 39 additions and 30 deletions

View File

@ -148,7 +148,7 @@ class ChatActivity : ServiceBoundActivity() {
if (airaService.contacts.contains(sessionId)) { if (airaService.contacts.contains(sessionId)) {
lastLoadedMessageOffset += 1 lastLoadedMessageOffset += 1
} }
airaService.isAppInBackground !airaService.isAppInBackground
} else { } else {
false false
} }
@ -204,17 +204,15 @@ class ChatActivity : ServiceBoundActivity() {
override fun onCreateOptionsMenu(menu: Menu): Boolean { override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.chat_activity, menu) menuInflater.inflate(R.menu.chat_activity, menu)
val contact = airaService.contacts[sessionId] val contact = airaService.contacts[sessionId]
if (contact == null){ menu.findItem(R.id.delete_conversation).isVisible = contact != null
menu.findItem(R.id.delete_conversation).isVisible = false menu.findItem(R.id.set_as_contact).isVisible = contact == null
menu.findItem(R.id.set_as_contact).isVisible = true menu.findItem(R.id.remove_contact).isVisible = contact != null
menu.findItem(R.id.remove_contact).isVisible = false if (contact == null) {
menu.findItem(R.id.verify).isVisible = false menu.findItem(R.id.verify).isVisible = false
} else { } else {
menu.findItem(R.id.delete_conversation).isVisible = true
menu.findItem(R.id.set_as_contact).isVisible = false
menu.findItem(R.id.remove_contact).isVisible = true
menu.findItem(R.id.verify).isVisible = !contact.verified menu.findItem(R.id.verify).isVisible = !contact.verified
} }
menu.findItem(R.id.refresh_name).isEnabled = airaService.isOnline(sessionId)
return true return true
} }
@ -303,6 +301,10 @@ class ChatActivity : ServiceBoundActivity() {
.show() .show()
true true
} }
R.id.refresh_name -> {
airaService.sendTo(sessionId, Protocol.askName())
true
}
else -> super.onOptionsItemSelected(item) else -> super.onOptionsItemSelected(item)
} }
} }

View File

@ -421,7 +421,7 @@ class AIRAService : Service() {
override fun onCreate() { override fun onCreate() {
HandlerThread("", THREAD_PRIORITY_BACKGROUND).apply { HandlerThread("", THREAD_PRIORITY_BACKGROUND).apply {
start() start()
serviceHandler = object : Handler(looper){ serviceHandler = object : Handler(looper) {
override fun handleMessage(msg: Message) { override fun handleMessage(msg: Message) {
try { try {
when (msg.what) { when (msg.what) {
@ -438,15 +438,16 @@ class AIRAService : Service() {
} }
MESSAGE_CONNECT_TO -> { MESSAGE_CONNECT_TO -> {
msg.data.getString("ip")?.let { ip -> msg.data.getString("ip")?.let { ip ->
try { Thread {
val socket = SocketChannel.open() try {
if (socket.connect(InetSocketAddress(ip, Constants.port))) { val socket = SocketChannel.open()
handleNewSocket(socket, true) if (socket.connect(InetSocketAddress(ip, Constants.port))) {
handleNewSocket(socket, true)
}
} catch (e: ConnectException) {
Log.w("Connect failed", "$ip: "+e.message)
} }
} catch (e: ConnectException) { }.start()
Log.w("Connect failed", e.message.toString())
return
}
} }
} }
MESSAGE_CANCEL_FILE_TRANSFER -> { MESSAGE_CANCEL_FILE_TRANSFER -> {
@ -483,18 +484,18 @@ class AIRAService : Service() {
} }
} }
} }
val contactList = AIRADatabase.loadContacts() }
if (contactList == null) { val contactList = AIRADatabase.loadContacts()
contacts = HashMap(0) if (contactList == null) {
} else { contacts = HashMap(0)
contacts = HashMap(contactList.size) } else {
for (contact in contactList) { contacts = HashMap(contactList.size)
contacts[sessionCounter] = contact for (contact in contactList) {
if (!contact.seen) { contacts[sessionCounter] = contact
notSeen.add(sessionCounter) if (!contact.seen) {
} notSeen.add(sessionCounter)
sessionCounter++
} }
sessionCounter++
} }
} }
} }

View File

@ -32,4 +32,9 @@
android:icon="@drawable/ic_info" android:icon="@drawable/ic_info"
android:title="@string/details"/> android:title="@string/details"/>
<item
android:id="@+id/refresh_name"
app:showAsAction="never"
android:title="@string/refresh_name"/>
</menu> </menu>

View File

@ -80,4 +80,5 @@
<string name="identity">Identity</string> <string name="identity">Identity</string>
<string name="about">About</string> <string name="about">About</string>
<string name="version">AIRA version</string> <string name="version">AIRA version</string>
<string name="refresh_name">Refresh name</string>
</resources> </resources>

View File

@ -6,7 +6,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:4.1.3' classpath 'com.android.tools.build:gradle:4.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip