Styling ImageButtons & replace onStart with onResume in ServiceBoundActivity

This commit is contained in:
Matéo Duparc 2021-05-08 19:54:10 +02:00
parent 51ebfb22db
commit 26821632fd
Signed by: hardcoresushi
GPG Key ID: 007F84120107191E
11 changed files with 84 additions and 56 deletions

View File

@ -307,20 +307,28 @@ class ChatActivity : ServiceBoundActivity() {
} }
} }
override fun onStart() { override fun onResume() {
super.onStart() super.onResume()
if (isServiceInitialized()) { if (isServiceInitialized()) {
airaService.setSeen(sessionId, true) airaService.setSeen(sessionId, true)
} }
} }
override fun onPause() {
super.onPause()
lastLoadedMessageOffset = 0
}
private fun onClickSaveFile(fileName: String, rawUuid: ByteArray) { private fun onClickSaveFile(fileName: String, rawUuid: ByteArray) {
FileUtils.openFileForDownload(this, fileName)?.apply { val buffer = AIRADatabase.loadFile(rawUuid)
AIRADatabase.loadFile(rawUuid)?.let { if (buffer == null) {
write(it) Toast.makeText(this, R.string.loadFile_failed, Toast.LENGTH_SHORT).show()
} else {
FileUtils.openFileForDownload(this, fileName)?.apply {
write(buffer)
close()
Toast.makeText(this@ChatActivity, R.string.file_saved, Toast.LENGTH_SHORT).show() Toast.makeText(this@ChatActivity, R.string.file_saved, Toast.LENGTH_SHORT).show()
} }
close()
} }
} }
} }

View File

@ -21,7 +21,6 @@ import sushi.hardcore.aira.databinding.ActivityMainBinding
import sushi.hardcore.aira.databinding.DialogIpAddressesBinding import sushi.hardcore.aira.databinding.DialogIpAddressesBinding
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.lang.StringBuilder
import java.net.NetworkInterface import java.net.NetworkInterface
class MainActivity : ServiceBoundActivity() { class MainActivity : ServiceBoundActivity() {
@ -235,8 +234,8 @@ class MainActivity : ServiceBoundActivity() {
} }
} }
override fun onStop() { override fun onPause() {
super.onStop() super.onPause()
if (isServiceInitialized()) { if (isServiceInitialized()) {
airaService.isAppInBackground = true airaService.isAppInBackground = true
} }

View File

@ -1,5 +1,6 @@
package sushi.hardcore.aira package sushi.hardcore.aira
import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.ServiceConnection import android.content.ServiceConnection
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
@ -14,8 +15,8 @@ open class ServiceBoundActivity: AppCompatActivity() {
return ::airaService.isInitialized return ::airaService.isInitialized
} }
override fun onStop() { override fun onPause() {
super.onStop() super.onPause()
if (::airaService.isInitialized) { if (::airaService.isInitialized) {
airaService.isAppInBackground = true airaService.isAppInBackground = true
airaService.uiCallbacks = null airaService.uiCallbacks = null
@ -23,10 +24,11 @@ open class ServiceBoundActivity: AppCompatActivity() {
} }
} }
override fun onStart() { override fun onResume() {
super.onStart() super.onResume()
if (!::serviceIntent.isInitialized) { if (!::serviceIntent.isInitialized) {
serviceIntent = Intent(this, AIRAService::class.java) serviceIntent = Intent(this, AIRAService::class.java)
} }
bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE)
} }
} }

View File

@ -282,35 +282,37 @@ class AIRAService : Service() {
try { try {
val session = Session(socket, outgoing) val session = Session(socket, outgoing)
if (session.doHandshake()) { if (session.doHandshake()) {
var isActuallyNewSession = true synchronized(this) {
for (s in sessions.values) { var isActuallyNewSession = true
if (s.peerPublicKey.contentEquals(session.peerPublicKey)) { for (s in sessions.values) {
isActuallyNewSession = false if (s.peerPublicKey.contentEquals(session.peerPublicKey)) {
} isActuallyNewSession = false
}
if (isActuallyNewSession && !session.peerPublicKey.contentEquals(AIRADatabase.getIdentityPublicKey())) {
var sessionId: Int? = null
for ((i, contact) in contacts) {
if (contact.publicKey.contentEquals(session.peerPublicKey)){
sessions[i] = session
sessionId = i
} }
} }
if (sessionId == null) { if (isActuallyNewSession && !session.peerPublicKey.contentEquals(AIRADatabase.getIdentityPublicKey())) {
sessions[sessionCounter] = session var sessionId: Int? = null
savedMsgs[sessionCounter] = mutableListOf() for ((i, contact) in contacts) {
sessionId = sessionCounter if (contact.publicKey.contentEquals(session.peerPublicKey)){
sessionCounter++ sessions[i] = session
sessionId = i
}
}
if (sessionId == null) {
sessions[sessionCounter] = session
savedMsgs[sessionCounter] = mutableListOf()
sessionId = sessionCounter
sessionCounter++
}
session.configureBlocking(false)
val key = session.register(selector, SelectionKey.OP_READ)
sessionIdByKey[key] = sessionId
uiCallbacks?.onNewSession(sessionId, session.ip)
if (!isContact(sessionId)) {
session.encryptAndSend(Protocol.askName())
}
} else {
session.close()
} }
session.configureBlocking(false)
val key = session.register(selector, SelectionKey.OP_READ)
sessionIdByKey[key] = sessionId
uiCallbacks?.onNewSession(sessionId, session.ip)
if (!isContact(sessionId)) {
session.encryptAndSend(Protocol.askName())
}
} else {
session.close()
} }
} else { } else {
session.close() session.close()

View File

@ -24,10 +24,13 @@
<ImageButton <ImageButton
android:id="@+id/button_attach" android:id="@+id/button_attach"
android:layout_width="wrap_content" android:layout_width="@dimen/image_button_size"
android:layout_height="wrap_content" android:layout_height="@dimen/image_button_size"
android:src="@drawable/ic_attach_file" android:src="@drawable/ic_attach_file"
style="@style/ImageButton"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/image_trust_level" /> app:layout_constraintEnd_toStartOf="@id/image_trust_level" />
<ImageView <ImageView
@ -37,22 +40,27 @@
android:src="@drawable/ic_warning" android:src="@drawable/ic_warning"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/button_attach"
app:layout_constraintEnd_toStartOf="@id/edit_message"/> app:layout_constraintEnd_toStartOf="@id/edit_message"/>
<EditText <EditText
android:id="@+id/edit_message" android:id="@+id/edit_message"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/button_send" app:layout_constraintStart_toEndOf="@id/image_trust_level"
app:layout_constraintStart_toStartOf="@id/button_attach"/> app:layout_constraintEnd_toStartOf="@+id/button_send"/>
<ImageButton <ImageButton
android:id="@+id/button_send" android:id="@+id/button_send"
android:layout_width="wrap_content" android:layout_width="@dimen/image_button_size"
android:layout_height="wrap_content" android:layout_height="@dimen/image_button_size"
android:src="@drawable/ic_send" android:src="@drawable/ic_send"
style="@style/ImageButton"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/edit_message"
app:layout_constraintEnd_toEndOf="parent" /> app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -56,7 +56,6 @@
android:maxLines="1" android:maxLines="1"
android:imeOptions="actionGo" android:imeOptions="actionGo"
android:hint="@string/add_peer_ip" android:hint="@string/add_peer_ip"
android:layout_marginEnd="10dp"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
@ -64,11 +63,10 @@
<ImageButton <ImageButton
android:id="@+id/button_show_ip" android:id="@+id/button_show_ip"
android:layout_width="30dp" android:layout_width="@dimen/image_button_size"
android:layout_height="30dp" android:layout_height="@dimen/image_button_size"
android:src="@drawable/ic_info" android:src="@drawable/ic_info"
android:scaleType="fitXY" style="@style/ImageButton"
android:background="#00000000"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/edit_peer_ip" app:layout_constraintStart_toEndOf="@id/edit_peer_ip"

View File

@ -11,15 +11,15 @@
android:orientation="horizontal" android:orientation="horizontal"
android:gravity="center" android:gravity="center"
style="@style/Bubble" style="@style/Bubble"
android:paddingTop="5dp" android:paddingStart="6dp"
android:paddingBottom="5dp"> android:paddingVertical="5dp">
<ImageButton <ImageButton
android:id="@+id/button_save" android:id="@+id/button_save"
android:layout_width="wrap_content" android:layout_width="@dimen/image_button_size"
android:layout_height="wrap_content" android:layout_height="@dimen/image_button_size"
android:layout_marginEnd="5dp" android:src="@drawable/ic_save"
android:src="@drawable/ic_save"/> style="@style/ImageButton"/>
<TextView <TextView
android:id="@+id/text_filename" android:id="@+id/text_filename"

View File

@ -10,4 +10,5 @@
<color name="textLink">#3845A3</color> <color name="textLink">#3845A3</color>
<color name="messageTextColor">#ffffff</color> <color name="messageTextColor">#ffffff</color>
<color name="itemSelected">#66666666</color> <color name="itemSelected">#66666666</color>
<color name="transparent">#00000000</color>
</resources> </resources>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="image_button_size">30dp</dimen>
</resources>

View File

@ -75,4 +75,5 @@
<string name="file_transfer_already_in_progress">Another file transfer is already in progress</string> <string name="file_transfer_already_in_progress">Another file transfer is already in progress</string>
<string name="settings">Settings</string> <string name="settings">Settings</string>
<string name="log_out">Log out</string> <string name="log_out">Log out</string>
<string name="loadFile_failed">File extraction failed</string>
</resources> </resources>

View File

@ -13,6 +13,11 @@
<item name="android:paddingStart">15dp</item> <item name="android:paddingStart">15dp</item>
<item name="android:paddingEnd">15dp</item> <item name="android:paddingEnd">15dp</item>
</style> </style>
<style name="ImageButton" parent="Widget.AppCompat.ImageButton">
<item name="android:background">@color/transparent</item>
<item name="android:scaleType">fitXY</item>
<item name="android:layout_margin">5dp</item>
</style>
<style name="Theme.AIRA.NoActionBar"> <style name="Theme.AIRA.NoActionBar">
<item name="windowActionBar">false</item> <item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item> <item name="windowNoTitle">true</item>