srctree

Robin Linden parent 1f180f52 2ef65cc3
Update ktlint

Other than moving a comment in ExportManager.kt and renaming theFileTransfer.kt progress markers, this was performed by ktlint --format.

inlinesplit
.github/workflows/ci.yaml added: 163, removed: 236, total 0
@@ -5,7 +5,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- run: curl -sSLO https://github.com/pinterest/ktlint/releases/download/0.50.0/ktlint && chmod a+x ktlint
- run: curl -sSLO https://github.com/pinterest/ktlint/releases/download/1.0.0/ktlint && chmod a+x ktlint
- run: ./ktlint --code-style=android_studio
 
gradle-wrapper-validation:
 
atox/src/main/kotlin/Extensions.kt added: 163, removed: 236, total 0
@@ -18,12 +18,10 @@ val Fragment.vmFactory: ViewModelFactory
 
class NoSuchArgumentException(arg: String) : Exception("No such argument: $arg")
 
fun Fragment.requireStringArg(key: String) =
arguments?.getString(key) ?: throw NoSuchArgumentException(key)
fun Fragment.requireStringArg(key: String) = arguments?.getString(key) ?: throw NoSuchArgumentException(key)
 
fun String.truncated(length: Int): String =
if (this.length > length) {
this.take(length - 1) + "…"
} else {
this
}
fun String.truncated(length: Int): String = if (this.length > length) {
this.take(length - 1) + "…"
} else {
this
}
 
atox/src/main/kotlin/PendingIntentCompat.kt added: 163, removed: 236, total 0
@@ -16,18 +16,17 @@ object PendingIntentCompat {
intent: Intent,
flags: Int,
mutable: Boolean = false,
): PendingIntent =
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
PendingIntent.getBroadcast(context, requestCode, intent, flags)
} else {
val mutabilityFlag =
if (mutable) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) PendingIntent.FLAG_MUTABLE else 0
} else {
PendingIntent.FLAG_IMMUTABLE
}
PendingIntent.getBroadcast(context, requestCode, intent, flags or mutabilityFlag)
}
): PendingIntent = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
PendingIntent.getBroadcast(context, requestCode, intent, flags)
} else {
val mutabilityFlag =
if (mutable) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) PendingIntent.FLAG_MUTABLE else 0
} else {
PendingIntent.FLAG_IMMUTABLE
}
PendingIntent.getBroadcast(context, requestCode, intent, flags or mutabilityFlag)
}
 
fun getActivity(context: Context, requestCode: Int, intent: Intent, flags: Int): PendingIntent =
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
 
atox/src/main/kotlin/tox/BootstrapNodeRegistryImpl.kt added: 163, removed: 236, total 0
@@ -47,6 +47,5 @@ class BootstrapNodeRegistryImpl @Inject constructor(
}
}
 
override fun get(n: Int): List<BootstrapNode> =
nodes.asSequence().shuffled().take(n).toList()
override fun get(n: Int): List<BootstrapNode> = nodes.asSequence().shuffled().take(n).toList()
}
 
atox/src/main/kotlin/tox/EventListenerCallbacks.kt added: 163, removed: 236, total 0
@@ -71,11 +71,10 @@ class EventListenerCallbacks @Inject constructor(
private var audioPlayer: AudioPlayer? = null
private val scope = CoroutineScope(Dispatchers.Default)
 
private suspend fun tryGetContact(pk: String, tag: String) =
contactRepository.get(pk).firstOrNull().let {
if (it == null) Log.e(TAG, "$tag -> unable to get contact for ${pk.fingerprint()}")
it
}
private suspend fun tryGetContact(pk: String, tag: String) = contactRepository.get(pk).firstOrNull().let {
if (it == null) Log.e(TAG, "$tag -> unable to get contact for ${pk.fingerprint()}")
it
}
 
private fun notifyMessage(contact: Contact, message: String) =
notificationHelper.showMessageNotification(contact, message, silent = tox.getStatus() == UserStatus.Busy)
 
atox/src/main/kotlin/tox/ToxStarter.kt added: 163, removed: 236, total 0
@@ -80,6 +80,5 @@ class ToxStarter @Inject constructor(
}
}
 
private fun tryLoadSave(): ByteArray? =
saveManager.run { list().firstOrNull()?.let { load(PublicKey(it)) } }
private fun tryLoadSave(): ByteArray? = saveManager.run { list().firstOrNull()?.let { load(PublicKey(it)) } }
}
 
atox/src/main/kotlin/ui/NotificationHelper.kt added: 163, removed: 236, total 0
@@ -256,8 +256,7 @@ class NotificationHelper @Inject constructor(
notifier.notify(friendRequest.publicKey.hashCode(), notificationBuilder.build())
}
 
fun dismissCallNotification(pk: PublicKey) =
notifier.cancel(pk.string().hashCode() + CALL.hashCode())
fun dismissCallNotification(pk: PublicKey) = notifier.cancel(pk.string().hashCode() + CALL.hashCode())
 
fun showOngoingCallNotification(contact: Contact) {
if (ActivityCompat.checkSelfPermission(
 
atox/src/main/kotlin/ui/chat/ChatAdapter.kt added: 163, removed: 236, total 0
@@ -43,18 +43,17 @@ private fun FileTransfer.isImage() = try {
false
}
 
private fun inflateView(type: ChatItemType, inflater: LayoutInflater): View =
inflater.inflate(
when (type) {
ChatItemType.SentMessage -> R.layout.chat_message_sent
ChatItemType.ReceivedMessage -> R.layout.chat_message_received
ChatItemType.SentAction -> R.layout.chat_action_sent
ChatItemType.ReceivedAction -> R.layout.chat_action_received
ChatItemType.SentFileTransfer, ChatItemType.ReceivedFileTransfer -> R.layout.chat_filetransfer
},
null,
true,
)
private fun inflateView(type: ChatItemType, inflater: LayoutInflater): View = inflater.inflate(
when (type) {
ChatItemType.SentMessage -> R.layout.chat_message_sent
ChatItemType.ReceivedMessage -> R.layout.chat_message_received
ChatItemType.SentAction -> R.layout.chat_action_sent
ChatItemType.ReceivedAction -> R.layout.chat_action_received
ChatItemType.SentFileTransfer, ChatItemType.ReceivedFileTransfer -> R.layout.chat_filetransfer
},
null,
true,
)
 
private enum class ChatItemType {
ReceivedMessage,
 
atox/src/main/kotlin/ui/chat/ChatFragment.kt added: 163, removed: 236, total 0
@@ -351,11 +351,7 @@ class ChatFragment : BaseFragment<FragmentChatBinding>(FragmentChatBinding::infl
super.onResume()
}
 
override fun onCreateContextMenu(
menu: ContextMenu,
v: View,
menuInfo: ContextMenu.ContextMenuInfo?,
) = binding.run {
override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo?) = binding.run {
super.onCreateContextMenu(menu, v, menuInfo)
v.dispatchTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_CANCEL, 0f, 0f, 0))
val inflater = requireActivity().menuInflater
@@ -364,7 +360,10 @@ class ChatFragment : BaseFragment<FragmentChatBinding>(FragmentChatBinding::infl
val info = menuInfo as AdapterView.AdapterContextMenuInfo
val message = messages.adapter.getItem(info.position) as Message
when (message.type) {
MessageType.Action, MessageType.Normal -> inflater.inflate(R.menu.chat_message_context_menu, menu)
MessageType.Action, MessageType.Normal -> inflater.inflate(
R.menu.chat_message_context_menu,
menu,
)
MessageType.FileTransfer -> {
inflater.inflate(R.menu.ft_message_context_menu, menu)
val ft = fts.find { it.id == message.correlationId } ?: return
 
atox/src/main/kotlin/ui/contactlist/ContactListFragment.kt added: 163, removed: 236, total 0
@@ -56,8 +56,7 @@ import ltd.evilcorp.domain.tox.ToxSaveStatus
const val ARG_SHARE = "share"
private const val MAX_CONFIRM_DELETE_STRING_LENGTH = 32
 
private fun User.online(): Boolean =
connectionStatus != ConnectionStatus.None
private fun User.online(): Boolean = connectionStatus != ConnectionStatus.None
 
class ContactListFragment :
BaseFragment<FragmentContactListBinding>(FragmentContactListBinding::inflate),
@@ -206,11 +205,7 @@ class ContactListFragment :
super.onDestroyView()
}
 
override fun onCreateContextMenu(
menu: ContextMenu,
v: View,
menuInfo: ContextMenu.ContextMenuInfo?,
) {
override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo?) {
super.onCreateContextMenu(menu, v, menuInfo)
 
val inflater: MenuInflater = requireActivity().menuInflater
 
atox/src/main/kotlin/ui/contactlist/ContactListViewModel.kt added: 163, removed: 236, total 0
@@ -115,6 +115,5 @@ class ContactListViewModel @Inject constructor(
}
}
 
fun onShareText(what: String, to: Contact) =
chatManager.sendMessage(PublicKey(to.publicKey), what)
fun onShareText(what: String, to: Contact) = chatManager.sendMessage(PublicKey(to.publicKey), what)
}
 
atox/src/main/kotlin/ui/settings/SettingsViewModel.kt added: 163, removed: 236, total 0
@@ -185,11 +185,9 @@ class SettingsViewModel @Inject constructor(
}
}
 
fun isCurrentPassword(maybeCurrentPassword: String) =
tox.password == maybeCurrentPassword.ifEmpty { null }
fun isCurrentPassword(maybeCurrentPassword: String) = tox.password == maybeCurrentPassword.ifEmpty { null }
 
fun setPassword(newPassword: String) =
tox.changePassword(newPassword.ifEmpty { null })
fun setPassword(newPassword: String) = tox.changePassword(newPassword.ifEmpty { null })
 
fun getBootstrapNodeSource(): BootstrapNodeSource = settings.bootstrapNodeSource
fun setBootstrapNodeSource(source: BootstrapNodeSource) {
 
atox/src/main/kotlin/ui/userprofile/UserProfileFragment.kt added: 163, removed: 236, total 0
@@ -236,9 +236,8 @@ class UserProfileFragment : BaseFragment<FragmentUserProfileBinding>(FragmentUse
return bmpQrWithPadding
}
 
private suspend fun getQrForSharing(): Uri =
withContext(Dispatchers.IO) {
val bmp = asQr(vm.toxId, qrCodeSharedImageSize, qrCodeSharedImagePadding)
saveQrForSharing(bmp)
}
private suspend fun getQrForSharing(): Uri = withContext(Dispatchers.IO) {
val bmp = asQr(vm.toxId, qrCodeSharedImageSize, qrCodeSharedImagePadding)
saveQrForSharing(bmp)
}
}
 
core/src/androidTest/kotlin/db/DatabaseMigrationTest.kt added: 163, removed: 236, total 0
@@ -12,9 +12,9 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import ltd.evilcorp.core.vo.ConnectionStatus
import ltd.evilcorp.core.vo.Contact
import ltd.evilcorp.core.vo.FT_NOT_STARTED
import ltd.evilcorp.core.vo.FileKind
import ltd.evilcorp.core.vo.FileTransfer
import ltd.evilcorp.core.vo.FtNotStarted
import ltd.evilcorp.core.vo.Message
import ltd.evilcorp.core.vo.MessageType
import ltd.evilcorp.core.vo.Sender
@@ -43,7 +43,7 @@ class DatabaseMigrationTest {
9876,
"bird.png2",
false,
FtNotStarted,
FT_NOT_STARTED,
)
 
private val msg = Message(
 
core/src/main/kotlin/db/ContactDao.kt added: 163, removed: 236, total 0
@@ -36,10 +36,7 @@ interface ContactDao {
fun loadAll(): Flow<List<Contact>>
 
@Query("UPDATE contacts SET connection_status = :status, typing = :typing")
fun resetTransientData(
status: ConnectionStatus = ConnectionStatus.None,
typing: Boolean = false,
)
fun resetTransientData(status: ConnectionStatus = ConnectionStatus.None, typing: Boolean = false)
 
@Query("UPDATE contacts SET name = :name WHERE public_key = :publicKey")
fun setName(publicKey: String, name: String)
 
core/src/main/kotlin/db/FileTransferDao.kt added: 163, removed: 236, total 0
@@ -9,8 +9,8 @@ import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import kotlinx.coroutines.flow.Flow
import ltd.evilcorp.core.vo.FT_REJECTED
import ltd.evilcorp.core.vo.FileTransfer
import ltd.evilcorp.core.vo.FtRejected
 
@Dao
interface FileTransferDao {
@@ -27,11 +27,11 @@ interface FileTransferDao {
fun load(id: Int): Flow<FileTransfer>
 
@Query("UPDATE file_transfers SET progress = :progress WHERE id == :id AND progress != :rejected")
fun updateProgress(id: Int, progress: Long, rejected: Long = FtRejected)
fun updateProgress(id: Int, progress: Long, rejected: Long = FT_REJECTED)
 
@Query("UPDATE file_transfers SET destination = :destination WHERE id == :id")
fun setDestination(id: Int, destination: String)
 
@Query("UPDATE file_transfers SET progress = :progress WHERE progress < file_size")
fun resetTransientData(progress: Long = FtRejected)
fun resetTransientData(progress: Long = FT_REJECTED)
}
 
core/src/main/kotlin/repository/FileTransferRepository.kt added: 163, removed: 236, total 0
@@ -14,23 +14,17 @@ import ltd.evilcorp.core.vo.FileTransfer
class FileTransferRepository @Inject internal constructor(
private val dao: FileTransferDao,
) {
fun add(ft: FileTransfer): Long =
dao.save(ft)
fun add(ft: FileTransfer): Long = dao.save(ft)
 
fun delete(id: Int) =
dao.delete(id)
fun delete(id: Int) = dao.delete(id)
 
fun get(publicKey: String): Flow<List<FileTransfer>> =
dao.load(publicKey)
fun get(publicKey: String): Flow<List<FileTransfer>> = dao.load(publicKey)
 
fun get(id: Int): Flow<FileTransfer> =
dao.load(id)
fun get(id: Int): Flow<FileTransfer> = dao.load(id)
 
fun setDestination(id: Int, destination: String) =
dao.setDestination(id, destination)
fun setDestination(id: Int, destination: String) = dao.setDestination(id, destination)
 
fun updateProgress(id: Int, progress: Long) =
dao.updateProgress(id, progress)
fun updateProgress(id: Int, progress: Long) = dao.updateProgress(id, progress)
 
fun resetTransientData() = dao.resetTransientData()
}
 
core/src/main/kotlin/repository/FriendRequestRepository.kt added: 163, removed: 236, total 0
@@ -14,15 +14,11 @@ import ltd.evilcorp.core.vo.FriendRequest
class FriendRequestRepository @Inject internal constructor(
private val friendRequestDao: FriendRequestDao,
) {
fun add(friendRequest: FriendRequest) =
friendRequestDao.save(friendRequest)
fun add(friendRequest: FriendRequest) = friendRequestDao.save(friendRequest)
 
fun delete(friendRequest: FriendRequest) =
friendRequestDao.delete(friendRequest)
fun delete(friendRequest: FriendRequest) = friendRequestDao.delete(friendRequest)
 
fun getAll(): Flow<List<FriendRequest>> =
friendRequestDao.loadAll()
fun getAll(): Flow<List<FriendRequest>> = friendRequestDao.loadAll()
 
fun get(publicKey: String): Flow<FriendRequest> =
friendRequestDao.load(publicKey)
fun get(publicKey: String): Flow<FriendRequest> = friendRequestDao.load(publicKey)
}
 
core/src/main/kotlin/repository/MessageRepository.kt added: 163, removed: 236, total 0
@@ -21,20 +21,15 @@ class MessageRepository @Inject internal constructor(
contactRepository.setLastMessage(message.publicKey, Date().time)
}
 
fun get(conversation: String): Flow<List<Message>> =
messageDao.load(conversation)
fun get(conversation: String): Flow<List<Message>> = messageDao.load(conversation)
 
fun getPending(conversation: String): List<Message> =
messageDao.loadPending(conversation)
fun getPending(conversation: String): List<Message> = messageDao.loadPending(conversation)
 
fun setCorrelationId(id: Long, correlationId: Int) =
messageDao.setCorrelationId(id, correlationId)
fun setCorrelationId(id: Long, correlationId: Int) = messageDao.setCorrelationId(id, correlationId)
 
fun delete(conversation: String) =
messageDao.delete(conversation)
fun delete(conversation: String) = messageDao.delete(conversation)
 
fun deleteMessage(id: Long) =
messageDao.deleteMessage(id)
fun deleteMessage(id: Long) = messageDao.deleteMessage(id)
 
fun setReceipt(conversation: String, correlationId: Int, timestamp: Long) =
messageDao.setReceipt(conversation, correlationId, timestamp)
 
core/src/main/kotlin/repository/UserRepository.kt added: 163, removed: 236, total 0
@@ -16,20 +16,15 @@ import ltd.evilcorp.core.vo.UserStatus
class UserRepository @Inject constructor(
private val userDao: UserDao,
) {
fun exists(publicKey: String): Boolean =
userDao.exists(publicKey)
fun exists(publicKey: String): Boolean = userDao.exists(publicKey)
 
fun add(user: User) =
userDao.save(user)
fun add(user: User) = userDao.save(user)
 
fun update(user: User) =
userDao.update(user)
fun update(user: User) = userDao.update(user)
 
fun get(publicKey: String): Flow<User> =
userDao.load(publicKey)
fun get(publicKey: String): Flow<User> = userDao.load(publicKey)
 
fun updateName(publicKey: String, name: String) =
userDao.updateName(publicKey, name)
fun updateName(publicKey: String, name: String) = userDao.updateName(publicKey, name)
 
fun updateStatusMessage(publicKey: String, statusMessage: String) =
userDao.updateStatusMessage(publicKey, statusMessage)
@@ -37,6 +32,5 @@ class UserRepository @Inject constructor(
fun updateConnection(publicKey: String, connectionStatus: ConnectionStatus) =
userDao.updateConnection(publicKey, connectionStatus)
 
fun updateStatus(publicKey: String, status: UserStatus) =
userDao.updateStatus(publicKey, status)
fun updateStatus(publicKey: String, status: UserStatus) = userDao.updateStatus(publicKey, status)
}
 
core/src/main/kotlin/vo/FileTransfer.kt added: 163, removed: 236, total 0
@@ -14,9 +14,9 @@ enum class FileKind {
}
 
// Since the progress can't be negative, I'm reusing that part for some markers.
const val FtStarted = 0L
const val FtNotStarted = -1L
const val FtRejected = -2L
const val FT_STARTED = 0L
const val FT_NOT_STARTED = -1L
const val FT_REJECTED = -2L
 
@Entity(tableName = "file_transfers")
data class FileTransfer(
@@ -39,7 +39,7 @@ data class FileTransfer(
val outgoing: Boolean,
 
@ColumnInfo(name = "progress")
var progress: Long = FtNotStarted,
var progress: Long = FT_NOT_STARTED,
 
@ColumnInfo(name = "destination")
var destination: String = "",
@@ -50,5 +50,5 @@ data class FileTransfer(
}
 
fun FileTransfer.isComplete() = progress >= fileSize
fun FileTransfer.isStarted() = progress >= FtStarted
fun FileTransfer.isRejected() = progress == FtRejected
fun FileTransfer.isStarted() = progress >= FT_STARTED
fun FileTransfer.isRejected() = progress == FT_REJECTED
 
domain/src/main/kotlin/feature/CallManager.kt added: 163, removed: 236, total 0
@@ -112,7 +112,9 @@ class CallManager @Inject constructor(
 
var speakerphoneOn: Boolean
get() = audioManager?.isSpeakerphoneOn ?: false
set(value) { audioManager?.isSpeakerphoneOn = value }
set(value) {
audioManager?.isSpeakerphoneOn = value
}
 
private fun startAudioSender(recorder: AudioCapture, to: PublicKey) {
scope.launch {
 
domain/src/main/kotlin/feature/ChatManager.kt added: 163, removed: 236, total 0
@@ -59,29 +59,28 @@ class ChatManager @Inject constructor(
 
fun messagesFor(publicKey: PublicKey) = messageRepository.get(publicKey.string())
 
fun sendMessage(publicKey: PublicKey, message: String, type: MessageType = MessageType.Normal) =
scope.launch {
if (contactRepository.get(publicKey.string()).first().connectionStatus == ConnectionStatus.None) {
queueMessage(publicKey, message, type)
return@launch
}
 
val msgs = message.chunked(MAX_MESSAGE_LENGTH)
while (msgs.size > 1) {
tox.sendMessage(publicKey, msgs.removeFirst(), type)
}
 
messageRepository.add(
Message(
publicKey.string(),
message,
Sender.Sent,
type,
tox.sendMessage(publicKey, msgs.first(), type),
),
)
fun sendMessage(publicKey: PublicKey, message: String, type: MessageType = MessageType.Normal) = scope.launch {
if (contactRepository.get(publicKey.string()).first().connectionStatus == ConnectionStatus.None) {
queueMessage(publicKey, message, type)
return@launch
}
 
val msgs = message.chunked(MAX_MESSAGE_LENGTH)
while (msgs.size > 1) {
tox.sendMessage(publicKey, msgs.removeFirst(), type)
}
 
messageRepository.add(
Message(
publicKey.string(),
message,
Sender.Sent,
type,
tox.sendMessage(publicKey, msgs.first(), type),
),
)
}
 
private fun queueMessage(publicKey: PublicKey, message: String, type: MessageType) =
messageRepository.add(Message(publicKey.string(), message, Sender.Sent, type, Int.MIN_VALUE))
 
 
domain/src/main/kotlin/feature/ExportManager.kt added: 163, removed: 236, total 0
@@ -17,10 +17,10 @@ import ltd.evilcorp.core.vo.Message
class ExportManager @Inject constructor(
private val messageRepository: MessageRepository,
) {
 
// TODO @Akito: Increment version programmatically on major changes.
private fun List<Message>.generateExportMessages(): ExportMessages {
return ExportMessages(
version = 1, // TODO @Akito: Increment version programmatically on major changes.
version = 1,
timestamp = SimpleDateFormat(
"""yyyy-MM-dd'T'HH-mm-ss""",
Locale.getDefault(),
@@ -36,10 +36,9 @@ class ExportManager @Inject constructor(
messageRepository.get(publicKey).first()
}
 
fun generateExportMessagesJString(publicKey: String): String =
generateExportMessagesJString(
getMessages(publicKey),
)
fun generateExportMessagesJString(publicKey: String): String = generateExportMessagesJString(
getMessages(publicKey),
)
}
 
data class ExportMessages(
 
domain/src/main/kotlin/feature/FileTransferManager.kt added: 163, removed: 236, total 0
@@ -24,11 +24,11 @@ import kotlinx.coroutines.launch
import ltd.evilcorp.core.repository.ContactRepository
import ltd.evilcorp.core.repository.FileTransferRepository
import ltd.evilcorp.core.repository.MessageRepository
import ltd.evilcorp.core.vo.FT_NOT_STARTED
import ltd.evilcorp.core.vo.FT_REJECTED
import ltd.evilcorp.core.vo.FT_STARTED
import ltd.evilcorp.core.vo.FileKind
import ltd.evilcorp.core.vo.FileTransfer
import ltd.evilcorp.core.vo.FtNotStarted
import ltd.evilcorp.core.vo.FtRejected
import ltd.evilcorp.core.vo.FtStarted
import ltd.evilcorp.core.vo.Message
import ltd.evilcorp.core.vo.MessageType
import ltd.evilcorp.core.vo.Sender
@@ -75,7 +75,7 @@ class FileTransferManager @Inject constructor(
fun resetForContact(pk: String) {
Log.i(TAG, "Clearing fts for contact ${pk.fingerprint()}")
fileTransfers.filter { it.publicKey == pk }.kForEach { ft ->
setProgress(ft, FtRejected)
setProgress(ft, FT_REJECTED)
fileTransfers.remove(ft)
if (ft.outgoing) {
val uri = Uri.parse(ft.destination)
@@ -144,7 +144,7 @@ class FileTransferManager @Inject constructor(
 
RandomAccessFile(file, "rwd").use { it.setLength(ft.fileSize) }
setDestination(ft, Uri.fromFile(file))
setProgress(ft, FtStarted)
setProgress(ft, FT_STARTED)
tox.startFileTransfer(PublicKey(ft.publicKey), ft.fileNumber)
}
 
@@ -157,7 +157,7 @@ class FileTransferManager @Inject constructor(
fun reject(ft: FileTransfer) {
Log.i(TAG, "Reject ${ft.fileNumber} for ${ft.publicKey.fingerprint()}")
fileTransfers.remove(ft)
setProgress(ft, FtRejected)
setProgress(ft, FT_REJECTED)
tox.stopFileTransfer(PublicKey(ft.publicKey), ft.fileNumber)
val uri = Uri.parse(ft.destination)
if (ft.outgoing) {
@@ -231,7 +231,7 @@ class FileTransferManager @Inject constructor(
size,
name,
true,
FtNotStarted,
FT_NOT_STARTED,
file.toString(),
)
val id = fileTransferRepository.add(ft).toInt()
@@ -279,8 +279,8 @@ class FileTransferManager @Inject constructor(
return
}
 
if (fileStatus == ToxFileControl.RESUME && ft.progress == FtNotStarted) {
ft.progress = FtStarted
if (fileStatus == ToxFileControl.RESUME && ft.progress == FT_NOT_STARTED) {
ft.progress = FT_STARTED
} else if (fileStatus == ToxFileControl.CANCEL) {
Log.i(TAG, "Friend canceled ft ${pk.fingerprint()} $fileNo")
reject(ft)
 
domain/src/main/kotlin/tox/Tox.kt added: 163, removed: 236, total 0
@@ -174,8 +174,7 @@ class Tox @Inject constructor(
fun sendFile(pk: PublicKey, fileKind: FileKind, fileSize: Long, fileName: String) =
tox.sendFile(pk, fileKind, fileSize, fileName)
 
fun sendFileChunk(pk: PublicKey, fileNo: Int, pos: Long, data: ByteArray) =
tox.sendFileChunk(pk, fileNo, pos, data)
fun sendFileChunk(pk: PublicKey, fileNo: Int, pos: Long, data: ByteArray) = tox.sendFileChunk(pk, fileNo, pos, data)
 
fun getName() = tox.getName()
fun setName(name: String) {
 
domain/src/main/kotlin/tox/ToxAvEventListener.kt added: 163, removed: 236, total 0
@@ -39,14 +39,12 @@ class ToxAvEventListener @Inject constructor() : ToxAvEventListener<Unit> {
var audioReceiveFrameHandler: AudioReceiveFrameHandler = { _, _, _, _ -> }
var audioBitRateHandler: AudioBitRateHandler = { _, _ -> }
 
private fun keyFor(friendNo: Int) =
contactMapping.find { it.second == friendNo }!!.first.string()
private fun keyFor(friendNo: Int) = contactMapping.find { it.second == friendNo }!!.first.string()
 
override fun call(friendNo: Int, audioEnabled: Boolean, videoEnabled: Boolean, s: Unit?) =
callHandler(keyFor(friendNo), audioEnabled, videoEnabled)
 
override fun videoBitRate(friendNo: Int, bitRate: Int, s: Unit?) =
videoBitRateHandler(keyFor(friendNo), bitRate)
override fun videoBitRate(friendNo: Int, bitRate: Int, s: Unit?) = videoBitRateHandler(keyFor(friendNo), bitRate)
 
override fun videoFrameCachedYUV(
height: Int,
@@ -76,14 +74,8 @@ class ToxAvEventListener @Inject constructor() : ToxAvEventListener<Unit> {
override fun callState(friendNo: Int, callState: EnumSet<ToxavFriendCallState>, s: Unit?) =
callStateHandler(keyFor(friendNo), callState)
 
override fun audioReceiveFrame(
friendNo: Int,
pcm: ShortArray,
channels: Int,
samplingRate: Int,
s: Unit?,
) = audioReceiveFrameHandler(keyFor(friendNo), pcm, channels, samplingRate)
override fun audioReceiveFrame(friendNo: Int, pcm: ShortArray, channels: Int, samplingRate: Int, s: Unit?) =
audioReceiveFrameHandler(keyFor(friendNo), pcm, channels, samplingRate)
 
override fun audioBitRate(friendNo: Int, bitRate: Int, s: Unit?) =
audioBitRateHandler(keyFor(friendNo), bitRate)
override fun audioBitRate(friendNo: Int, bitRate: Int, s: Unit?) = audioBitRateHandler(keyFor(friendNo), bitRate)
}
 
domain/src/main/kotlin/tox/ToxEventListener.kt added: 163, removed: 236, total 0
@@ -53,8 +53,7 @@ class ToxEventListener @Inject constructor() : ToxCoreEventListener<Unit> {
var friendTypingHandler: FriendTypingHandler = { _, _ -> }
var fileChunkRequestHandler: FileChunkRequestHandler = { _, _, _, _ -> }
 
private fun keyFor(friendNo: Int) =
contactMapping.find { it.second == friendNo }!!.first.string()
private fun keyFor(friendNo: Int) = contactMapping.find { it.second == friendNo }!!.first.string()
 
override fun friendLosslessPacket(friendNo: Int, data: ByteArray, s: Unit?) =
friendLosslessPacketHandler(keyFor(friendNo), data)
@@ -77,33 +76,17 @@ class ToxEventListener @Inject constructor() : ToxCoreEventListener<Unit> {
override fun friendRequest(publicKey: ByteArray, timeDelta: Int, message: ByteArray, s: Unit?) =
friendRequestHandler(publicKey.bytesToHex(), timeDelta, String(message))
 
override fun friendMessage(
friendNo: Int,
type: ToxMessageType,
timeDelta: Int,
message: ByteArray,
s: Unit?,
) = friendMessageHandler(keyFor(friendNo), type, timeDelta, String(message))
override fun friendMessage(friendNo: Int, type: ToxMessageType, timeDelta: Int, message: ByteArray, s: Unit?) =
friendMessageHandler(keyFor(friendNo), type, timeDelta, String(message))
 
override fun friendName(friendNo: Int, newName: ByteArray, s: Unit?) =
friendNameHandler(keyFor(friendNo), String(newName))
 
override fun fileRecvChunk(
friendNo: Int,
fileNo: Int,
position: Long,
data: ByteArray,
s: Unit?,
) = fileRecvChunkHandler(keyFor(friendNo), fileNo, position, data)
override fun fileRecvChunk(friendNo: Int, fileNo: Int, position: Long, data: ByteArray, s: Unit?) =
fileRecvChunkHandler(keyFor(friendNo), fileNo, position, data)
 
override fun fileRecv(
friendNo: Int,
fileNo: Int,
kind: Int,
fileSize: Long,
filename: ByteArray,
s: Unit?,
) = fileRecvHandler(keyFor(friendNo), fileNo, kind, fileSize, String(filename))
override fun fileRecv(friendNo: Int, fileNo: Int, kind: Int, fileSize: Long, filename: ByteArray, s: Unit?) =
fileRecvHandler(keyFor(friendNo), fileNo, kind, fileSize, String(filename))
 
override fun friendLossyPacket(friendNo: Int, data: ByteArray, s: Unit?) =
friendLossyPacketHandler(keyFor(friendNo), data)
@@ -114,11 +97,6 @@ class ToxEventListener @Inject constructor() : ToxCoreEventListener<Unit> {
override fun friendTyping(friendNo: Int, isTyping: Boolean, s: Unit?) =
friendTypingHandler(keyFor(friendNo), isTyping)
 
override fun fileChunkRequest(
friendNo: Int,
fileNo: Int,
position: Long,
length: Int,
s: Unit?,
) = fileChunkRequestHandler(keyFor(friendNo), fileNo, position, length)
override fun fileChunkRequest(friendNo: Int, fileNo: Int, position: Long, length: Int, s: Unit?) =
fileChunkRequestHandler(keyFor(friendNo), fileNo, position, length)
}