Styling ImageButtons & replace onStart with onResume in ServiceBoundActivity
This commit is contained in:
parent
51ebfb22db
commit
26821632fd
@ -307,20 +307,28 @@ class ChatActivity : ServiceBoundActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (isServiceInitialized()) {
|
||||
airaService.setSeen(sessionId, true)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
lastLoadedMessageOffset = 0
|
||||
}
|
||||
|
||||
private fun onClickSaveFile(fileName: String, rawUuid: ByteArray) {
|
||||
FileUtils.openFileForDownload(this, fileName)?.apply {
|
||||
AIRADatabase.loadFile(rawUuid)?.let {
|
||||
write(it)
|
||||
val buffer = AIRADatabase.loadFile(rawUuid)
|
||||
if (buffer == null) {
|
||||
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()
|
||||
}
|
||||
close()
|
||||
}
|
||||
}
|
||||
}
|
@ -21,7 +21,6 @@ import sushi.hardcore.aira.databinding.ActivityMainBinding
|
||||
import sushi.hardcore.aira.databinding.DialogIpAddressesBinding
|
||||
import sushi.hardcore.aira.utils.FileUtils
|
||||
import sushi.hardcore.aira.utils.StringUtils
|
||||
import java.lang.StringBuilder
|
||||
import java.net.NetworkInterface
|
||||
|
||||
class MainActivity : ServiceBoundActivity() {
|
||||
@ -235,8 +234,8 @@ class MainActivity : ServiceBoundActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
if (isServiceInitialized()) {
|
||||
airaService.isAppInBackground = true
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package sushi.hardcore.aira
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.ServiceConnection
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
@ -14,8 +15,8 @@ open class ServiceBoundActivity: AppCompatActivity() {
|
||||
return ::airaService.isInitialized
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
if (::airaService.isInitialized) {
|
||||
airaService.isAppInBackground = true
|
||||
airaService.uiCallbacks = null
|
||||
@ -23,10 +24,11 @@ open class ServiceBoundActivity: AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (!::serviceIntent.isInitialized) {
|
||||
serviceIntent = Intent(this, AIRAService::class.java)
|
||||
}
|
||||
bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE)
|
||||
}
|
||||
}
|
@ -282,35 +282,37 @@ class AIRAService : Service() {
|
||||
try {
|
||||
val session = Session(socket, outgoing)
|
||||
if (session.doHandshake()) {
|
||||
var isActuallyNewSession = true
|
||||
for (s in sessions.values) {
|
||||
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
|
||||
synchronized(this) {
|
||||
var isActuallyNewSession = true
|
||||
for (s in sessions.values) {
|
||||
if (s.peerPublicKey.contentEquals(session.peerPublicKey)) {
|
||||
isActuallyNewSession = false
|
||||
}
|
||||
}
|
||||
if (sessionId == null) {
|
||||
sessions[sessionCounter] = session
|
||||
savedMsgs[sessionCounter] = mutableListOf()
|
||||
sessionId = sessionCounter
|
||||
sessionCounter++
|
||||
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) {
|
||||
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 {
|
||||
session.close()
|
||||
|
@ -24,10 +24,13 @@
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/button_attach"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="@dimen/image_button_size"
|
||||
android:layout_height="@dimen/image_button_size"
|
||||
android:src="@drawable/ic_attach_file"
|
||||
style="@style/ImageButton"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/image_trust_level" />
|
||||
|
||||
<ImageView
|
||||
@ -37,22 +40,27 @@
|
||||
android:src="@drawable/ic_warning"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/button_attach"
|
||||
app:layout_constraintEnd_toStartOf="@id/edit_message"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/edit_message"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/button_send"
|
||||
app:layout_constraintStart_toStartOf="@id/button_attach"/>
|
||||
app:layout_constraintStart_toEndOf="@id/image_trust_level"
|
||||
app:layout_constraintEnd_toStartOf="@+id/button_send"/>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/button_send"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="@dimen/image_button_size"
|
||||
android:layout_height="@dimen/image_button_size"
|
||||
android:src="@drawable/ic_send"
|
||||
style="@style/ImageButton"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/edit_message"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
@ -56,7 +56,6 @@
|
||||
android:maxLines="1"
|
||||
android:imeOptions="actionGo"
|
||||
android:hint="@string/add_peer_ip"
|
||||
android:layout_marginEnd="10dp"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
@ -64,11 +63,10 @@
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/button_show_ip"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_width="@dimen/image_button_size"
|
||||
android:layout_height="@dimen/image_button_size"
|
||||
android:src="@drawable/ic_info"
|
||||
android:scaleType="fitXY"
|
||||
android:background="#00000000"
|
||||
style="@style/ImageButton"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/edit_peer_ip"
|
||||
|
@ -11,15 +11,15 @@
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center"
|
||||
style="@style/Bubble"
|
||||
android:paddingTop="5dp"
|
||||
android:paddingBottom="5dp">
|
||||
android:paddingStart="6dp"
|
||||
android:paddingVertical="5dp">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/button_save"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:src="@drawable/ic_save"/>
|
||||
android:layout_width="@dimen/image_button_size"
|
||||
android:layout_height="@dimen/image_button_size"
|
||||
android:src="@drawable/ic_save"
|
||||
style="@style/ImageButton"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_filename"
|
||||
|
@ -10,4 +10,5 @@
|
||||
<color name="textLink">#3845A3</color>
|
||||
<color name="messageTextColor">#ffffff</color>
|
||||
<color name="itemSelected">#66666666</color>
|
||||
<color name="transparent">#00000000</color>
|
||||
</resources>
|
4
app/src/main/res/values/dimens.xml
Normal file
4
app/src/main/res/values/dimens.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<dimen name="image_button_size">30dp</dimen>
|
||||
</resources>
|
@ -75,4 +75,5 @@
|
||||
<string name="file_transfer_already_in_progress">Another file transfer is already in progress</string>
|
||||
<string name="settings">Settings</string>
|
||||
<string name="log_out">Log out</string>
|
||||
<string name="loadFile_failed">File extraction failed</string>
|
||||
</resources>
|
||||
|
@ -13,6 +13,11 @@
|
||||
<item name="android:paddingStart">15dp</item>
|
||||
<item name="android:paddingEnd">15dp</item>
|
||||
</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">
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
|
Loading…
Reference in New Issue
Block a user