srctree

Robin Linden parent 4934fca5 2a5e8e99
Apply experimental ktlint autofixes

inlinesplit
atox/src/androidTest/kotlin/IntegrationTest.kt added: 235, removed: 224, total 11
@@ -41,7 +41,7 @@ import org.junit.runner.RunWith
 
class InjectedActivityTestRule<T : Activity>(
activityClass: Class<T>,
private val listener: () -> Unit
private val listener: () -> Unit,
) : ActivityTestRule<T>(activityClass, false, true) {
override fun beforeActivityLaunched() {
super.beforeActivityLaunched()
@@ -71,8 +71,8 @@ class TestModule {
AndroidModule::class,
TestModule::class,
DaoModule::class,
ViewModelModule::class
]
ViewModelModule::class,
],
)
interface TestComponent : AppComponent {
@Component.Factory
 
atox/src/main/kotlin/ActionReceiver.kt added: 235, removed: 224, total 11
@@ -87,7 +87,7 @@ class ActionReceiver : BroadcastReceiver() {
notificationHelper.showMessageNotification(
Contact(pk.string(), tox.getName()),
input,
outgoing = true
outgoing = true,
)
return@launch
}
 
atox/src/main/kotlin/AutoAway.kt added: 235, removed: 224, total 11
@@ -23,7 +23,7 @@ class AutoAway @Inject constructor(
private val scope: CoroutineScope,
private val settings: Settings,
private val userManager: UserManager,
private val tox: Tox
private val tox: Tox,
) {
private var awayTimer = Timer()
private var autoAway = false
 
atox/src/main/kotlin/BootReceiver.kt added: 235, removed: 224, total 11
@@ -36,7 +36,7 @@ class BootReceiver : BroadcastReceiver() {
NavDeepLinkBuilder(context)
.setGraph(R.navigation.nav_graph)
.setDestination(R.id.contactListFragment)
.createPendingIntent()
.createPendingIntent(),
)
.setCategory(NotificationCompat.CATEGORY_STATUS)
.setSmallIcon(R.drawable.ic_notification)
 
atox/src/main/kotlin/MainActivity.kt added: 235, removed: 224, total 11
@@ -106,7 +106,7 @@ class MainActivity : AppCompatActivity() {
 
supportFragmentManager.findFragmentById(R.id.nav_host_fragment)?.findNavController()?.navigate(
R.id.addContactFragment,
bundleOf("toxId" to data.drop(SCHEME.length))
bundleOf("toxId" to data.drop(SCHEME.length)),
)
}
 
 
atox/src/main/kotlin/PendingIntentCompat.kt added: 235, removed: 224, total 11
@@ -15,7 +15,7 @@ object PendingIntentCompat {
requestCode: Int,
intent: Intent,
flags: Int,
mutable: Boolean = false
mutable: Boolean = false,
): PendingIntent =
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
PendingIntent.getBroadcast(context, requestCode, intent, flags)
 
atox/src/main/kotlin/di/AppComponent.kt added: 235, removed: 224, total 11
@@ -20,8 +20,8 @@ import ltd.evilcorp.atox.ToxService
AppModule::class,
DatabaseModule::class,
DaoModule::class,
ViewModelModule::class
]
ViewModelModule::class,
],
)
interface AppComponent {
@Component.Factory
 
atox/src/main/kotlin/di/ViewModelFactory.kt added: 235, removed: 224, total 11
@@ -13,7 +13,7 @@ import javax.inject.Singleton
@Suppress("UNCHECKED_CAST")
@Singleton
class ViewModelFactory @Inject constructor(
private val creators: Map<Class<out ViewModel>, @JvmSuppressWildcards Provider<ViewModel>>
private val creators: Map<Class<out ViewModel>, @JvmSuppressWildcards Provider<ViewModel>>,
) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
val creator = creators[modelClass] ?: creators.entries.first {
 
atox/src/main/kotlin/di/ViewModelModule.kt added: 235, removed: 224, total 11
@@ -24,7 +24,7 @@ import ltd.evilcorp.atox.ui.user_profile.UserProfileViewModel
@Target(
AnnotationTarget.FUNCTION,
AnnotationTarget.PROPERTY_GETTER,
AnnotationTarget.PROPERTY_SETTER
AnnotationTarget.PROPERTY_SETTER,
)
@Retention(AnnotationRetention.RUNTIME)
@MapKey
 
atox/src/main/kotlin/settings/Settings.kt added: 235, removed: 224, total 11
@@ -41,7 +41,7 @@ class Settings @Inject constructor(private val ctx: Context) {
 
var runAtStartup: Boolean
get() = ctx.packageManager.getComponentEnabledSetting(
ComponentName(ctx, BootReceiver::class.java)
ComponentName(ctx, BootReceiver::class.java),
) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED
set(runAtStartup) {
val state = if (runAtStartup) {
@@ -53,7 +53,7 @@ class Settings @Inject constructor(private val ctx: Context) {
ctx.packageManager.setComponentEnabledSetting(
ComponentName(ctx, BootReceiver::class.java),
state,
PackageManager.DONT_KILL_APP
PackageManager.DONT_KILL_APP,
)
}
 
 
atox/src/main/kotlin/tox/EventListenerCallbacks.kt added: 235, removed: 224, total 11
@@ -115,7 +115,7 @@ class EventListenerCallbacks @Inject constructor(
 
friendMessageHandler = { publicKey, type, _, msg ->
messageRepository.add(
Message(publicKey, msg, Sender.Received, type.toMessageType(), Int.MIN_VALUE, Date().time)
Message(publicKey, msg, Sender.Received, type.toMessageType(), Int.MIN_VALUE, Date().time),
)
 
if (chatManager.activeChat != publicKey) {
@@ -202,13 +202,13 @@ class EventListenerCallbacks @Inject constructor(
videoReceiveFrameHandler = { pk,
width, height,
y, u, v,
yStride, uStride, vStride ->
yStride, uStride, vStride, ->
Log.v(
TAG,
"videoReceiveFrame ${pk.fingerprint()}" +
"$width $height" +
"${y.size} ${u.size} ${v.size}" +
"$yStride $uStride $vStride"
"$yStride $uStride $vStride",
)
}
 
 
atox/src/main/kotlin/ui/AvatarFactory.kt added: 235, removed: 224, total 11
@@ -28,7 +28,7 @@ internal object AvatarFactory {
resources: Resources,
name: String,
publicKey: String,
size: Px = Px(resources.getDimension(R.dimen.default_avatar_size).toInt())
size: Px = Px(resources.getDimension(R.dimen.default_avatar_size).toInt()),
): Bitmap {
val defaultAvatarSize = resources.getDimension(R.dimen.default_avatar_size)
val textScale = size.px / defaultAvatarSize
 
atox/src/main/kotlin/ui/AvatarImageView.kt added: 235, removed: 224, total 11
@@ -31,13 +31,14 @@ class AvatarImageView @JvmOverloads constructor(context: Context, attrs: Attribu
private val statusIndicatorVisible: Boolean = context.theme.obtainStyledAttributes(
attrs,
R.styleable.AvatarImageView,
0, 0
0,
0,
).use { it.getBoolean(R.styleable.AvatarImageView_statusIndicatorVisible, true) }
 
private fun colorByContactStatus(context: Context, contact: Contact) =
if (contact.connectionStatus == ConnectionStatus.None)
if (contact.connectionStatus == ConnectionStatus.None) {
ContextCompat.getColor(context, R.color.statusOffline)
else colorFromStatus(context, contact.status)
} else colorFromStatus(context, contact.status)
 
private var name = ""
private var publicKey = ""
 
atox/src/main/kotlin/ui/BaseFragment.kt added: 235, removed: 224, total 11
@@ -12,7 +12,7 @@ import androidx.fragment.app.Fragment
import androidx.viewbinding.ViewBinding
 
abstract class BaseFragment<T : ViewBinding>(
private val inflate: (LayoutInflater, ViewGroup?, Boolean) -> T
private val inflate: (LayoutInflater, ViewGroup?, Boolean) -> T,
) : Fragment() {
private var _binding: T? = null
val binding get() = _binding!!
 
atox/src/main/kotlin/ui/NotificationHelper.kt added: 235, removed: 224, total 11
@@ -47,7 +47,7 @@ private const val CALL = "aTox calls"
 
@Singleton
class NotificationHelper @Inject constructor(
private val context: Context
private val context: Context,
) {
private val notifier = NotificationManagerCompat.from(context)
private val notifierOld = context.getSystemService<NotificationManager>()!!
@@ -111,8 +111,8 @@ class NotificationHelper @Inject constructor(
ImageRequest.Builder(context)
.data(contact.avatarUri)
.transformations(CircleCropTransformation())
.build()
).drawable?.toBitmap()
.build(),
).drawable?.toBitmap(),
)
} else null
 
@@ -129,7 +129,7 @@ class NotificationHelper @Inject constructor(
} ?: NotificationCompat.MessagingStyle(chatPartner)
 
style.messages.add(
NotificationCompat.MessagingStyle.Message(message, System.currentTimeMillis(), chatPartner)
NotificationCompat.MessagingStyle.Message(message, System.currentTimeMillis(), chatPartner),
)
 
notificationBuilder
@@ -152,16 +152,16 @@ class NotificationHelper @Inject constructor(
Intent(context, ActionReceiver::class.java).putExtra(KEY_CONTACT_PK, contact.publicKey),
PendingIntent.FLAG_UPDATE_CURRENT,
mutable = true,
)
),
)
.addRemoteInput(
RemoteInput.Builder(KEY_TEXT_REPLY)
.setLabel(context.getString(R.string.message))
.build()
.build(),
)
.setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_REPLY)
.setAllowGeneratedReplies(true)
.build()
.build(),
)
} else {
notificationBuilder.addAction(
@@ -169,10 +169,10 @@ class NotificationHelper @Inject constructor(
.Builder(
IconCompat.createWithResource(context, R.drawable.ic_send),
context.getString(R.string.reply),
deepLinkToChat(PublicKey(contact.publicKey), focusMessageBox = true)
deepLinkToChat(PublicKey(contact.publicKey), focusMessageBox = true),
)
.setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_REPLY)
.build()
.build(),
)
}
 
@@ -187,8 +187,8 @@ class NotificationHelper @Inject constructor(
.putExtra(KEY_CONTACT_PK, contact.publicKey)
.putExtra(KEY_ACTION, Action.MarkAsRead),
PendingIntent.FLAG_UPDATE_CURRENT,
)
).setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_MARK_AS_READ).build()
),
).setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_MARK_AS_READ).build(),
)
 
notifier.notify(contact.publicKey.hashCode(), notificationBuilder.build())
@@ -204,7 +204,7 @@ class NotificationHelper @Inject constructor(
NavDeepLinkBuilder(context)
.setGraph(R.navigation.nav_graph)
.setDestination(R.id.contactListFragment)
.createPendingIntent()
.createPendingIntent(),
)
.setAutoCancel(true)
.setSilent(silent)
@@ -224,8 +224,8 @@ class NotificationHelper @Inject constructor(
.setContentText(
context.getString(
R.string.in_call_with,
contact.name.ifEmpty { context.getString(R.string.contact_default_name) }
)
contact.name.ifEmpty { context.getString(R.string.contact_default_name) },
),
)
.setUsesChronometer(true)
.setWhen(System.currentTimeMillis())
@@ -234,7 +234,7 @@ class NotificationHelper @Inject constructor(
.setGraph(R.navigation.nav_graph)
.addDestination(R.id.chatFragment, bundleOf(CONTACT_PUBLIC_KEY to contact.publicKey))
.addDestination(R.id.callFragment, bundleOf(CONTACT_PUBLIC_KEY to contact.publicKey))
.createPendingIntent()
.createPendingIntent(),
)
.addAction(
NotificationCompat.Action
@@ -247,10 +247,10 @@ class NotificationHelper @Inject constructor(
Intent(context, ActionReceiver::class.java)
.putExtra(KEY_CONTACT_PK, contact.publicKey)
.putExtra(KEY_ACTION, Action.CallEnd),
PendingIntent.FLAG_UPDATE_CURRENT
)
PendingIntent.FLAG_UPDATE_CURRENT,
),
)
.build()
.build(),
)
.setOngoing(true)
.setSilent(true)
@@ -276,11 +276,11 @@ class NotificationHelper @Inject constructor(
Intent(context, ActionReceiver::class.java)
.putExtra(KEY_CONTACT_PK, c.publicKey)
.putExtra(KEY_ACTION, Action.CallAccept),
PendingIntent.FLAG_UPDATE_CURRENT
)
PendingIntent.FLAG_UPDATE_CURRENT,
),
)
.setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_CALL)
.build()
.build(),
)
.addAction(
NotificationCompat.Action
@@ -293,10 +293,10 @@ class NotificationHelper @Inject constructor(
Intent(context, ActionReceiver::class.java)
.putExtra(KEY_CONTACT_PK, c.publicKey)
.putExtra(KEY_ACTION, Action.CallReject),
PendingIntent.FLAG_UPDATE_CURRENT
)
PendingIntent.FLAG_UPDATE_CURRENT,
),
)
.build()
.build(),
)
.setDeleteIntent(
PendingIntentCompat.getBroadcast(
@@ -305,8 +305,8 @@ class NotificationHelper @Inject constructor(
Intent(context, ActionReceiver::class.java)
.putExtra(KEY_CONTACT_PK, c.publicKey)
.putExtra(KEY_ACTION, Action.CallIgnore),
PendingIntent.FLAG_UPDATE_CURRENT
)
PendingIntent.FLAG_UPDATE_CURRENT,
),
)
.setSound(RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE))
.setSilent(status == UserStatus.Busy)
@@ -325,7 +325,7 @@ class NotificationHelper @Inject constructor(
bundleOf(
CONTACT_PUBLIC_KEY to publicKey.string(),
FOCUS_ON_MESSAGE_BOX to focusMessageBox,
)
),
)
.createPendingIntent()
}
 
atox/src/main/kotlin/ui/ReceiveShareDialog.kt added: 235, removed: 224, total 11
@@ -22,7 +22,7 @@ class ReceiveShareDialog(
ctx: Context,
private var contacts: List<Contact>,
private val sharePreview: String,
private val contactSelectedFunc: (Contact) -> Unit
private val contactSelectedFunc: (Contact) -> Unit,
) : Dialog(ctx, R.style.DialogSlideAnimation) {
private var _binding: DialogReceiveShareBinding? = null
private val binding get() = _binding!!
 
atox/src/main/kotlin/ui/StatusDialog.kt added: 235, removed: 224, total 11
@@ -22,7 +22,7 @@ private const val TRANSITION_TIME = 250
class StatusDialog(
ctx: Context,
private var activeStatus: UserStatus,
private val setStatusFunc: (UserStatus) -> Unit
private val setStatusFunc: (UserStatus) -> Unit,
) : Dialog(ctx, R.style.DialogSlideAnimation) {
@Inject
lateinit var userManager: UserManager
 
atox/src/main/kotlin/ui/addcontact/AddContactFragment.kt added: 235, removed: 224, total 11
@@ -73,7 +73,7 @@ class AddContactFragment : BaseFragment<FragmentAddContactBinding>(FragmentAddCo
toxId.error = when (ToxIdValidator.validate(input)) {
ToxIdValidator.Result.INCORRECT_LENGTH -> getString(
R.string.tox_id_error_length,
s?.toString()?.length ?: 0
s?.toString()?.length ?: 0,
)
ToxIdValidator.Result.INVALID_CHECKSUM -> getString(R.string.tox_id_error_checksum)
ToxIdValidator.Result.NOT_HEX -> getString(R.string.tox_id_error_hex)
@@ -96,10 +96,11 @@ class AddContactFragment : BaseFragment<FragmentAddContactBinding>(FragmentAddCo
 
message.doAfterTextChanged { s ->
val content = s?.toString() ?: ""
message.error = if (content.isNotEmpty())
message.error = if (content.isNotEmpty()) {
null
else
} else {
getString(R.string.add_contact_message_error_empty)
}
 
messageValid = message.error == null
add.isEnabled = isAddAllowed()
@@ -120,7 +121,7 @@ class AddContactFragment : BaseFragment<FragmentAddContactBinding>(FragmentAddCo
putExtra("SCAN_FORMATS", "QR_CODE")
putExtra("SCAN_ORIENTATION_LOCKED", false)
putExtra("BEEP_ENABLED", false)
}
},
)
} catch (e: ActivityNotFoundException) {
val uri = Uri.parse("https://f-droid.org/en/packages/com.google.zxing.client.android/")
 
atox/src/main/kotlin/ui/addcontact/AddContactViewModel.kt added: 235, removed: 224, total 11
@@ -18,7 +18,7 @@ import ltd.evilcorp.domain.tox.ToxSaveStatus
class AddContactViewModel @Inject constructor(
private val contactManager: ContactManager,
private val tox: Tox,
private val toxStarter: ToxStarter
private val toxStarter: ToxStarter,
) : ViewModel() {
val toxId by lazy { tox.toxId }
val contacts: LiveData<List<Contact>> = contactManager.getAll().asLiveData()
 
atox/src/main/kotlin/ui/call/CallFragment.kt added: 235, removed: 224, total 11
@@ -31,7 +31,7 @@ class CallFragment : BaseFragment<FragmentCallBinding>(FragmentCallBinding::infl
private val vm: CallViewModel by viewModels { vmFactory }
 
private val requestPermissionLauncher = registerForActivityResult(
ActivityResultContracts.RequestPermission()
ActivityResultContracts.RequestPermission(),
) { granted ->
if (granted) {
vm.startSendingAudio()
 
atox/src/main/kotlin/ui/call/CallViewModel.kt added: 235, removed: 224, total 11
@@ -24,7 +24,7 @@ class CallViewModel @Inject constructor(
private val callManager: CallManager,
private val notificationHelper: NotificationHelper,
private val contactManager: ContactManager,
private val proximityScreenOff: ProximityScreenOff
private val proximityScreenOff: ProximityScreenOff,
) : ViewModel() {
private var publicKey = PublicKey("")
 
 
atox/src/main/kotlin/ui/chat/ChatAdapter.kt added: 235, removed: 224, total 11
@@ -56,7 +56,7 @@ private fun inflateView(type: ChatItemType, inflater: LayoutInflater): View =
ChatItemType.SentFileTransfer, ChatItemType.ReceivedFileTransfer -> R.layout.chat_filetransfer
},
null,
true
true,
)
 
private enum class ChatItemType {
@@ -94,7 +94,7 @@ private class FileTransferViewHolder(row: View) {
 
class ChatAdapter(
private val inflater: LayoutInflater,
private val resources: Resources
private val resources: Resources,
) : BaseAdapter() {
var messages: List<Message> = listOf()
var fileTransfers: List<FileTransfer> = listOf()
@@ -123,7 +123,8 @@ class ChatAdapter(
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View =
when (val type = types[getItemViewType(position)]) {
ChatItemType.ReceivedMessage, ChatItemType.SentMessage,
ChatItemType.ReceivedAction, ChatItemType.SentAction -> {
ChatItemType.ReceivedAction, ChatItemType.SentAction,
-> {
val message = messages[position]
val view: View
val vh: MessageViewHolder
@@ -198,7 +199,7 @@ class ChatAdapter(
vh.imagePreview.load(fileTransfer.destination) {
// Make sure fts with the same destination have unique caches.
memoryCacheKey(
(fileTransfer.destination.hashCode() * SOME_PRIME + fileTransfer.id.hashCode()).toString()
(fileTransfer.destination.hashCode() * SOME_PRIME + fileTransfer.id.hashCode()).toString(),
)
precision(Precision.INEXACT)
size(
 
atox/src/main/kotlin/ui/chat/ChatFragment.kt added: 235, removed: 224, total 11
@@ -111,7 +111,7 @@ class ChatFragment : BaseFragment<FragmentChatBinding>(FragmentChatBinding::infl
 
override fun onStart(
animation: WindowInsetsAnimationCompat,
bounds: WindowInsetsAnimationCompat.BoundsCompat
bounds: WindowInsetsAnimationCompat.BoundsCompat,
): WindowInsetsAnimationCompat.BoundsCompat {
val pos = IntArray(2)
outgoingMessage.getLocationInWindow(pos)
@@ -125,7 +125,7 @@ class ChatFragment : BaseFragment<FragmentChatBinding>(FragmentChatBinding::infl
 
override fun onProgress(
insets: WindowInsetsCompat,
runningAnimations: MutableList<WindowInsetsAnimationCompat>
runningAnimations: MutableList<WindowInsetsAnimationCompat>,
): WindowInsetsCompat {
val animation = runningAnimations[0]
val offset = lerp((startBottom - endBottom).toFloat(), 0f, animation.interpolatedFraction)
@@ -133,7 +133,7 @@ class ChatFragment : BaseFragment<FragmentChatBinding>(FragmentChatBinding::infl
bottomBar.translationY = offset
return insets
}
}
},
)
 
toolbar.setNavigationIcon(R.drawable.ic_back)
@@ -168,7 +168,7 @@ class ChatFragment : BaseFragment<FragmentChatBinding>(FragmentChatBinding::infl
WindowInsetsControllerCompat(requireActivity().window, view).hide(WindowInsetsCompat.Type.ime())
findNavController().navigate(
R.id.action_chatFragment_to_contactProfileFragment,
bundleOf(CONTACT_PUBLIC_KEY to contactPubKey)
bundleOf(CONTACT_PUBLIC_KEY to contactPubKey),
)
}
 
@@ -269,7 +269,7 @@ class ChatFragment : BaseFragment<FragmentChatBinding>(FragmentChatBinding::infl
val uri = FileProvider.getUriForFile(
requireContext(),
"${BuildConfig.APPLICATION_ID}.fileprovider",
File(Uri.parse(ft.destination).path!!)
File(Uri.parse(ft.destination).path!!),
)
val shareIntent = Intent(Intent.ACTION_VIEW).apply {
putExtra(Intent.EXTRA_TITLE, ft.fileName)
@@ -283,7 +283,7 @@ class ChatFragment : BaseFragment<FragmentChatBinding>(FragmentChatBinding::infl
Toast.makeText(
requireContext(),
getString(R.string.mimetype_handler_not_found, contentType),
Toast.LENGTH_LONG
Toast.LENGTH_LONG,
).show()
}
}
@@ -325,7 +325,7 @@ class ChatFragment : BaseFragment<FragmentChatBinding>(FragmentChatBinding::infl
override fun onCreateContextMenu(
menu: ContextMenu,
v: View,
menuInfo: ContextMenu.ContextMenuInfo?
menuInfo: ContextMenu.ContextMenuInfo?,
) = binding.run {
super.onCreateContextMenu(menu, v, menuInfo)
v.dispatchTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_CANCEL, 0f, 0f, 0))
@@ -369,8 +369,8 @@ class ChatFragment : BaseFragment<FragmentChatBinding>(FragmentChatBinding::infl
.setMessage(
getString(
R.string.delete_message_confirm,
message.message.truncated(MAX_CONFIRM_DELETE_STRING_LENGTH)
)
message.message.truncated(MAX_CONFIRM_DELETE_STRING_LENGTH),
),
)
.setPositiveButton(R.string.delete) { _, _ ->
viewModel.delete(message)
@@ -407,7 +407,7 @@ class ChatFragment : BaseFragment<FragmentChatBinding>(FragmentChatBinding::infl
ContextCompat.getColor(
requireContext(),
if (attach.isEnabled) R.color.colorPrimary else android.R.color.darker_gray,
)
),
)
}
 
@@ -415,7 +415,7 @@ class ChatFragment : BaseFragment<FragmentChatBinding>(FragmentChatBinding::infl
view?.let { WindowInsetsControllerCompat(requireActivity().window, it).hide(WindowInsetsCompat.Type.ime()) }
findNavController().navigate(
R.id.action_chatFragment_to_callFragment,
bundleOf(CONTACT_PUBLIC_KEY to contactPubKey)
bundleOf(CONTACT_PUBLIC_KEY to contactPubKey),
)
}
}
 
atox/src/main/kotlin/ui/contactlist/ContactAdapter.kt added: 235, removed: 224, total 11
@@ -29,7 +29,7 @@ private val types = ContactListItemType.values()
 
class ContactAdapter(
private val inflater: LayoutInflater,
private val context: Context
private val context: Context,
) : BaseAdapter() {
var friendRequests: List<FriendRequest> = listOf()
var contacts: List<Contact> = listOf()
@@ -102,7 +102,7 @@ class ContactAdapter(
draftMessage.isNotEmpty() -> {
vh.statusMessage.text = context.getString(R.string.draft_message, draftMessage)
vh.statusMessage.setTextColor(
ContextCompat.getColor(context, R.color.colorAccent)
ContextCompat.getColor(context, R.color.colorAccent),
)
}
else -> {
 
atox/src/main/kotlin/ui/contactlist/ContactListFragment.kt added: 235, removed: 224, total 11
@@ -168,7 +168,7 @@ class ContactListFragment :
drawerLayout,
toolbar,
R.string.navigation_drawer_open,
R.string.navigation_drawer_close
R.string.navigation_drawer_close,
)
drawerLayout.addDrawerListener(toggle)
toggle.syncState()
@@ -206,7 +206,7 @@ class ContactListFragment :
override fun onCreateContextMenu(
menu: ContextMenu,
v: View,
menuInfo: ContextMenu.ContextMenuInfo?
menuInfo: ContextMenu.ContextMenuInfo?,
) {
super.onCreateContextMenu(menu, v, menuInfo)
 
@@ -257,8 +257,8 @@ class ContactListFragment :
.setMessage(
getString(
R.string.contact_list_delete_contact_confirm,
contact.name.truncated(MAX_CONFIRM_DELETE_STRING_LENGTH)
)
contact.name.truncated(MAX_CONFIRM_DELETE_STRING_LENGTH),
),
)
.setPositiveButton(R.string.delete) { _, _ ->
viewModel.deleteContact(PublicKey(contact.publicKey))
@@ -311,7 +311,8 @@ class ContactListFragment :
if (!viewModel.isToxRunning()) {
when (val status = viewModel.tryLoadTox(null)) {
ToxSaveStatus.BadProxyHost, ToxSaveStatus.BadProxyPort,
ToxSaveStatus.BadProxyType, ToxSaveStatus.ProxyNotFound -> {
ToxSaveStatus.BadProxyType, ToxSaveStatus.ProxyNotFound,
-> {
Toast.makeText(requireContext(), getString(R.string.warn_proxy_broken), Toast.LENGTH_LONG).show()
findNavController().navigate(R.id.action_contactListFragment_to_settingsFragment)
}
@@ -375,16 +376,16 @@ class ContactListFragment :
 
private fun openChat(contact: Contact) = findNavController().navigate(
R.id.action_contactListFragment_to_chatFragment,
bundleOf(CONTACT_PUBLIC_KEY to contact.publicKey)
bundleOf(CONTACT_PUBLIC_KEY to contact.publicKey),
)
 
private fun openFriendRequest(friendRequest: FriendRequest) = findNavController().navigate(
R.id.action_contactListFragment_to_friendRequestFragment,
bundleOf(FRIEND_REQUEST_PUBLIC_KEY to friendRequest.publicKey)
bundleOf(FRIEND_REQUEST_PUBLIC_KEY to friendRequest.publicKey),
)
 
private fun openProfile(contact: Contact) = findNavController().navigate(
R.id.action_contactListFragment_to_contactProfileFragment,
bundleOf(CONTACT_PUBLIC_KEY to contact.publicKey)
bundleOf(CONTACT_PUBLIC_KEY to contact.publicKey),
)
}
 
atox/src/main/kotlin/ui/contactlist/ContactListViewModel.kt added: 235, removed: 224, total 11
@@ -52,7 +52,7 @@ class ContactListViewModel @Inject constructor(
private val tox: Tox,
private val toxStarter: ToxStarter,
private val settings: Settings,
userManager: UserManager
userManager: UserManager,
) : ViewModel() {
val publicKey by lazy { tox.publicKey }
 
@@ -92,7 +92,7 @@ class ContactListViewModel @Inject constructor(
Toast.makeText(
context,
context.getString(R.string.tox_save_export_failure, context.getString(R.string.file_not_found)),
Toast.LENGTH_LONG
Toast.LENGTH_LONG,
).show()
}
return@launch
 
atox/src/main/kotlin/ui/create_profile/CreateProfileFragment.kt added: 235, removed: 224, total 11
@@ -58,7 +58,7 @@ class CreateProfileFragment : BaseFragment<FragmentProfileBinding>(FragmentProfi
Toast.makeText(
requireContext(),
getString(R.string.incorrect_password),
Toast.LENGTH_LONG
Toast.LENGTH_LONG,
).show()
}
}
@@ -68,7 +68,7 @@ class CreateProfileFragment : BaseFragment<FragmentProfileBinding>(FragmentProfi
else -> Toast.makeText(
requireContext(),
resources.getString(R.string.import_tox_save_failed, startStatus.name),
Toast.LENGTH_LONG
Toast.LENGTH_LONG,
).show()
}
}
@@ -93,7 +93,7 @@ class CreateProfileFragment : BaseFragment<FragmentProfileBinding>(FragmentProfi
val user = User(
publicKey = viewModel.publicKey.string(),
name = if (username.text.isNotEmpty()) username.text.toString() else getString(R.string.name_default),
statusMessage = getString(R.string.status_message_default)
statusMessage = getString(R.string.status_message_default),
)
viewModel.create(user)
 
 
atox/src/main/kotlin/ui/create_profile/CreateProfileViewModel.kt added: 235, removed: 224, total 11
@@ -19,7 +19,7 @@ class CreateProfileViewModel @Inject constructor(
private val resolver: ContentResolver,
private val userManager: UserManager,
private val tox: Tox,
private val toxStarter: ToxStarter
private val toxStarter: ToxStarter,
) : ViewModel() {
val publicKey: PublicKey by lazy { tox.publicKey }
 
 
atox/src/main/kotlin/ui/friend_request/FriendRequestViewModel.kt added: 235, removed: 224, total 11
@@ -13,7 +13,7 @@ import ltd.evilcorp.domain.feature.FriendRequestManager
import ltd.evilcorp.domain.tox.PublicKey
 
class FriendRequestViewModel @Inject constructor(
private val friendRequests: FriendRequestManager
private val friendRequests: FriendRequestManager,
) : ViewModel() {
fun byId(pk: PublicKey): LiveData<FriendRequest> = friendRequests.get(pk).asLiveData()
fun accept(request: FriendRequest) = friendRequests.accept(request)
 
atox/src/main/kotlin/ui/settings/SettingsFragment.kt added: 235, removed: 224, total 11
@@ -73,7 +73,7 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding>(FragmentSettingsB
Toast.makeText(
requireContext(),
getString(R.string.warn_node_json_import_failed),
Toast.LENGTH_LONG
Toast.LENGTH_LONG,
).show()
}
}
@@ -105,8 +105,9 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding>(FragmentSettingsB
}
 
theme.adapter = ArrayAdapter.createFromResource(
requireContext(), R.array.pref_theme_options,
android.R.layout.simple_spinner_item
requireContext(),
R.array.pref_theme_options,
android.R.layout.simple_spinner_item,
).apply { setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) }
 
theme.setSelection(vm.getTheme())
@@ -135,8 +136,9 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding>(FragmentSettingsB
}
 
settingFtAutoAccept.adapter = ArrayAdapter.createFromResource(
requireContext(), R.array.pref_ft_auto_accept_options,
android.R.layout.simple_spinner_item
requireContext(),
R.array.pref_ft_auto_accept_options,
android.R.layout.simple_spinner_item,
).apply { setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) }
 
settingFtAutoAccept.setSelection(vm.getFtAutoAccept().ordinal)
@@ -157,7 +159,9 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding>(FragmentSettingsB
settingsUdpEnabled.setOnClickListener { vm.setUdpEnabled(settingsUdpEnabled.isChecked) }
 
proxyType.adapter = ArrayAdapter.createFromResource(
requireContext(), R.array.pref_proxy_type_options, android.R.layout.simple_spinner_item
requireContext(),
R.array.pref_proxy_type_options,
android.R.layout.simple_spinner_item,
).apply { setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) }
 
proxyType.setSelection(vm.getProxyType().ordinal)
@@ -257,8 +261,9 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding>(FragmentSettingsB
}
 
settingBootstrapNodes.adapter = ArrayAdapter.createFromResource(
requireContext(), R.array.pref_bootstrap_node_options,
android.R.layout.simple_spinner_item
requireContext(),
R.array.pref_bootstrap_node_options,
android.R.layout.simple_spinner_item,
).apply { setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) }
 
settingBootstrapNodes.setSelection(vm.getBootstrapNodeSource().ordinal)
@@ -282,7 +287,7 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding>(FragmentSettingsB
if (settingDisableScreenshots.isChecked) {
requireActivity().window.setFlags(
WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE
WindowManager.LayoutParams.FLAG_SECURE,
)
} else {
requireActivity().window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
 
atox/src/main/kotlin/ui/settings/SettingsViewModel.kt added: 235, removed: 224, total 11
@@ -133,7 +133,8 @@ class SettingsViewModel @Inject constructor(
checkProxyJob?.cancel(null)
checkProxyJob = viewModelScope.launch(Dispatchers.IO) {
val saveStatus = testToxSave(
SaveOptions(saveData = null, getUdpEnabled(), getProxyType(), getProxyAddress(), getProxyPort()), null
SaveOptions(saveData = null, getUdpEnabled(), getProxyType(), getProxyAddress(), getProxyPort()),
null,
)
 
val proxyStatus = when (saveStatus) {
 
atox/src/main/kotlin/ui/user_profile/UserProfileFragment.kt added: 235, removed: 224, total 11
@@ -147,7 +147,7 @@ class UserProfileFragment : BaseFragment<FragmentUserProfileBinding>(FragmentUse
when (v.id) {
R.id.profile_share_id -> requireActivity().menuInflater.inflate(
R.menu.user_profile_share_id_context_menu,
menu
menu,
)
}
}
@@ -222,14 +222,14 @@ class UserProfileFragment : BaseFragment<FragmentUserProfileBinding>(FragmentUse
Bitmap.createBitmap(
bmpQr.width + 2 * padding.px,
bmpQr.height + 2 * padding.px,
Bitmap.Config.RGB_565
Bitmap.Config.RGB_565,
)
val canvas = Canvas(bmpQrWithPadding)
canvas.drawPaint(
Paint().apply {
color = Color.WHITE
style = Paint.Style.FILL
}
},
)
canvas.drawBitmap(bmpQr, padding.px.toFloat(), padding.px.toFloat(), null)
 
 
atox/src/main/kotlin/ui/user_profile/UserProfileViewModel.kt added: 235, removed: 224, total 11
@@ -15,7 +15,7 @@ import ltd.evilcorp.domain.tox.Tox
 
class UserProfileViewModel @Inject constructor(
private val userManager: UserManager,
private val tox: Tox
private val tox: Tox,
) : ViewModel() {
val publicKey by lazy { tox.publicKey }
val toxId by lazy { tox.toxId }
 
core/build.gradle.kts added: 235, removed: 224, total 11
@@ -25,7 +25,7 @@ android {
javaCompileOptions {
annotationProcessorOptions {
arguments.putAll(
mapOf("room.schemaLocation" to "$projectDir/schemas")
mapOf("room.schemaLocation" to "$projectDir/schemas"),
)
}
}
 
core/src/androidTest/kotlin/db/ContactDaoTest.kt added: 235, removed: 224, total 11
@@ -40,7 +40,7 @@ class ContactDaoTest {
typing = true,
avatarUri = "uri",
hasUnreadMessages = true,
draftMessage = "i made this"
draftMessage = "i made this",
)
 
private val second = first.copy(publicKey = "5678")
@@ -101,7 +101,7 @@ class ContactDaoTest {
assertNotEquals(first, dao.load(first.publicKey).first())
assertEquals(
first.copy(typing = false, connectionStatus = ConnectionStatus.None),
dao.load(first.publicKey).first()
dao.load(first.publicKey).first(),
)
}
 
 
core/src/androidTest/kotlin/db/DatabaseMigrationTest.kt added: 235, removed: 224, total 11
@@ -33,7 +33,7 @@ class DatabaseMigrationTest {
val helper: MigrationTestHelper = MigrationTestHelper(
InstrumentationRegistry.getInstrumentation(),
Database::class.java.canonicalName,
FrameworkSQLiteOpenHelperFactory()
FrameworkSQLiteOpenHelperFactory(),
)
 
private val ft = FileTransfer(
@@ -43,7 +43,7 @@ class DatabaseMigrationTest {
9876,
"bird.png2",
false,
FtNotStarted
FtNotStarted,
)
 
private val msg = Message(
@@ -52,7 +52,7 @@ class DatabaseMigrationTest {
Sender.Sent,
MessageType.Normal,
99,
12L
12L,
)
 
private val contact = Contact(
@@ -63,7 +63,7 @@ class DatabaseMigrationTest {
UserStatus.Busy,
ConnectionStatus.TCP,
true,
"file:///home/robin/fantastic_bird.png"
"file:///home/robin/fantastic_bird.png",
)
 
@Test
@@ -80,7 +80,7 @@ class DatabaseMigrationTest {
${connectionStatus.ordinal},
${typing.toInt()},
'$avatarUri')
""".trimIndent()
""".trimIndent(),
)
}
 
@@ -127,7 +127,7 @@ class DatabaseMigrationTest {
${sender.ordinal},
$correlationId,
$timestamp)
""".trimIndent()
""".trimIndent(),
)
}
 
@@ -175,7 +175,7 @@ class DatabaseMigrationTest {
'$fileName',
${outgoing.toInt()},
$progress)
""".trimIndent()
""".trimIndent(),
)
}
 
@@ -215,7 +215,7 @@ class DatabaseMigrationTest {
${typing.toInt()},
'$avatarUri',
${hasUnreadMessages.toInt()})
""".trimIndent()
""".trimIndent(),
)
}
 
@@ -266,7 +266,7 @@ class DatabaseMigrationTest {
${connectionStatus.ordinal},
${typing.toInt()},
'$avatarUri')
""".trimIndent()
""".trimIndent(),
)
}
with(msg) {
@@ -278,7 +278,7 @@ class DatabaseMigrationTest {
${sender.ordinal},
$correlationId,
$timestamp)
""".trimIndent()
""".trimIndent(),
)
}
with(ft) {
@@ -291,7 +291,7 @@ class DatabaseMigrationTest {
'$fileName',
${outgoing.toInt()},
$progress)
""".trimIndent()
""".trimIndent(),
)
}
 
 
core/src/main/kotlin/db/ContactDao.kt added: 235, removed: 224, total 11
@@ -38,7 +38,7 @@ interface ContactDao {
@Query("UPDATE contacts SET connection_status = :status, typing = :typing")
fun resetTransientData(
status: ConnectionStatus = ConnectionStatus.None,
typing: Boolean = false
typing: Boolean = false,
)
 
@Query("UPDATE contacts SET name = :name WHERE public_key = :publicKey")
 
core/src/main/kotlin/db/Database.kt added: 235, removed: 224, total 11
@@ -15,7 +15,7 @@ import ltd.evilcorp.core.vo.User
 
@Database(
entities = [Contact::class, FileTransfer::class, FriendRequest::class, Message::class, User::class],
version = 5
version = 5,
)
@TypeConverters(Converters::class)
abstract class Database : RoomDatabase() {
 
core/src/main/kotlin/db/Migration.kt added: 235, removed: 224, total 11
@@ -9,13 +9,13 @@ import androidx.sqlite.db.SupportSQLiteDatabase
 
val MIGRATION_1_2 = object : Migration(1, 2) {
override fun migrate(db: SupportSQLiteDatabase) = db.execSQL(
"ALTER TABLE contacts ADD COLUMN has_unread_messages INTEGER NOT NULL DEFAULT 0"
"ALTER TABLE contacts ADD COLUMN has_unread_messages INTEGER NOT NULL DEFAULT 0",
)
}
 
val MIGRATION_2_3 = object : Migration(2, 3) {
override fun migrate(db: SupportSQLiteDatabase) = db.execSQL(
"ALTER TABLE messages ADD COLUMN type INTEGER NOT NULL DEFAULT 0"
"ALTER TABLE messages ADD COLUMN type INTEGER NOT NULL DEFAULT 0",
)
}
 
@@ -33,14 +33,14 @@ val MIGRATION_3_4 = object : Migration(3, 4) {
'destination' TEXT NOT NULL,
'outgoing' INTEGER NOT NULL,
'progress' INTEGER NOT NULL)
""".trimIndent()
""".trimIndent(),
)
}
}
 
val MIGRATION_4_5 = object : Migration(4, 5) {
override fun migrate(db: SupportSQLiteDatabase) = db.execSQL(
"ALTER TABLE contacts ADD COLUMN draft_message TEXT NOT NULL DEFAULT ''"
"ALTER TABLE contacts ADD COLUMN draft_message TEXT NOT NULL DEFAULT ''",
)
}
 
 
core/src/main/kotlin/repository/ContactRepository.kt added: 235, removed: 224, total 11
@@ -14,7 +14,7 @@ import ltd.evilcorp.core.vo.UserStatus
 
@Singleton
class ContactRepository @Inject internal constructor(
private val dao: ContactDao
private val dao: ContactDao,
) {
fun exists(publicKey: String): Boolean = dao.exists(publicKey)
fun add(contact: Contact) = dao.save(contact)
 
core/src/main/kotlin/repository/FileTransferRepository.kt added: 235, removed: 224, total 11
@@ -12,7 +12,7 @@ import ltd.evilcorp.core.vo.FileTransfer
 
@Singleton
class FileTransferRepository @Inject internal constructor(
private val dao: FileTransferDao
private val dao: FileTransferDao,
) {
fun add(ft: FileTransfer): Long =
dao.save(ft)
 
core/src/main/kotlin/repository/FriendRequestRepository.kt added: 235, removed: 224, total 11
@@ -12,7 +12,7 @@ import ltd.evilcorp.core.vo.FriendRequest
 
@Singleton
class FriendRequestRepository @Inject internal constructor(
private val friendRequestDao: FriendRequestDao
private val friendRequestDao: FriendRequestDao,
) {
fun add(friendRequest: FriendRequest) =
friendRequestDao.save(friendRequest)
 
core/src/main/kotlin/repository/UserRepository.kt added: 235, removed: 224, total 11
@@ -14,7 +14,7 @@ import ltd.evilcorp.core.vo.UserStatus
 
@Singleton
class UserRepository @Inject internal constructor(
private val userDao: UserDao
private val userDao: UserDao,
) {
fun exists(publicKey: String): Boolean =
userDao.exists(publicKey)
 
core/src/main/kotlin/vo/FileTransfer.kt added: 235, removed: 224, total 11
@@ -42,7 +42,7 @@ data class FileTransfer(
var progress: Long = FtNotStarted,
 
@ColumnInfo(name = "destination")
var destination: String = ""
var destination: String = "",
) {
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "id")
 
core/src/main/kotlin/vo/FriendRequest.kt added: 235, removed: 224, total 11
@@ -15,5 +15,5 @@ data class FriendRequest(
val publicKey: String,
 
@ColumnInfo(name = "message")
val message: String = ""
val message: String = "",
)
 
core/src/main/kotlin/vo/Message.kt added: 235, removed: 224, total 11
@@ -37,7 +37,7 @@ data class Message(
var correlationId: Int,
 
@ColumnInfo(name = "timestamp")
var timestamp: Long = 0
var timestamp: Long = 0,
) {
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "id")
 
core/src/main/kotlin/vo/User.kt added: 235, removed: 224, total 11
@@ -27,5 +27,5 @@ data class User(
var connectionStatus: ConnectionStatus = ConnectionStatus.None,
 
@ColumnInfo(name = "password")
var password: String = ""
var password: String = "",
)
 
domain/src/main/kotlin/av/AudioPlayer.kt added: 235, removed: 224, total 11
@@ -27,7 +27,7 @@ class AudioPlayer(sampleRate: Int, channels: Int) {
intToChannel(channels),
AudioFormat.ENCODING_PCM_16BIT,
minBufferSize,
AudioTrack.MODE_STREAM
AudioTrack.MODE_STREAM,
)
} else {
AudioTrack.Builder()
@@ -36,12 +36,12 @@ class AudioPlayer(sampleRate: Int, channels: Int) {
.setEncoding(AudioFormat.ENCODING_PCM_16BIT)
.setSampleRate(sampleRate)
.setChannelMask(intToChannel(channels))
.build()
.build(),
)
.setAudioAttributes(
AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION)
.build()
.build(),
)
.setBufferSizeInBytes(minBufferSize)
.build()
 
domain/src/main/kotlin/feature/ChatManager.kt added: 235, removed: 224, total 11
@@ -45,7 +45,7 @@ class ChatManager @Inject constructor(
private val scope: CoroutineScope,
private val contactRepository: ContactRepository,
private val messageRepository: MessageRepository,
private val tox: Tox
private val tox: Tox,
) {
var activeChat = ""
set(value) {
@@ -76,7 +76,7 @@ class ChatManager @Inject constructor(
Sender.Sent,
type,
tox.sendMessage(publicKey, msgs.first(), type),
)
),
)
}
 
 
domain/src/main/kotlin/feature/ContactManager.kt added: 235, removed: 224, total 11
@@ -16,7 +16,7 @@ import ltd.evilcorp.domain.tox.ToxID
class ContactManager @Inject constructor(
private val scope: CoroutineScope,
private val contactRepository: ContactRepository,
private val tox: Tox
private val tox: Tox,
) {
fun get(publicKey: PublicKey) = contactRepository.get(publicKey.string())
fun getAll() = contactRepository.getAll()
 
domain/src/main/kotlin/feature/FileTransferManager.kt added: 235, removed: 224, total 11
@@ -52,7 +52,7 @@ class FileTransferManager @Inject constructor(
private val contactRepository: ContactRepository,
private val messageRepository: MessageRepository,
private val fileTransferRepository: FileTransferRepository,
private val tox: Tox
private val tox: Tox,
) {
private val fileTransfers: MutableList<FileTransfer> = mutableListOf()
 
@@ -92,7 +92,7 @@ class FileTransferManager @Inject constructor(
FileKind.Data.ordinal -> {
val id = fileTransferRepository.add(ft).toInt()
messageRepository.add(
Message(ft.publicKey, ft.fileName, Sender.Received, MessageType.FileTransfer, id, Date().time)
Message(ft.publicKey, ft.fileName, Sender.Received, MessageType.FileTransfer, id, Date().time),
)
fileTransfers.add(ft.copy().apply { this.id = id })
id
@@ -232,11 +232,11 @@ class FileTransferManager @Inject constructor(
name,
true,
FtNotStarted,
file.toString()
file.toString(),
)
val id = fileTransferRepository.add(ft).toInt()
messageRepository.add(
Message(ft.publicKey, ft.fileName, Sender.Sent, MessageType.FileTransfer, id, Date().time)
Message(ft.publicKey, ft.fileName, Sender.Sent, MessageType.FileTransfer, id, Date().time),
)
fileTransfers.add(ft.copy().apply { this.id = id })
}
 
domain/src/main/kotlin/feature/FriendRequestManager.kt added: 235, removed: 224, total 11
@@ -19,7 +19,7 @@ class FriendRequestManager @Inject constructor(
private val scope: CoroutineScope,
private val contactRepository: ContactRepository,
private val friendRequestRepository: FriendRequestRepository,
private val tox: Tox
private val tox: Tox,
) {
fun getAll(): Flow<List<FriendRequest>> = friendRequestRepository.getAll()
fun get(id: PublicKey): Flow<FriendRequest> = friendRequestRepository.get(id.string())
 
domain/src/main/kotlin/feature/UserManager.kt added: 235, removed: 224, total 11
@@ -16,7 +16,7 @@ import ltd.evilcorp.domain.tox.Tox
class UserManager @Inject constructor(
private val scope: CoroutineScope,
private val userRepository: UserRepository,
private val tox: Tox
private val tox: Tox,
) {
fun get(publicKey: PublicKey) = userRepository.get(publicKey.string())
 
 
domain/src/main/kotlin/tox/BootstrapNodeJsonParser.kt added: 235, removed: 224, total 11
@@ -31,8 +31,8 @@ class BootstrapNodeJsonParser @Inject constructor() {
BootstrapNode(
address = jsonNode.getString("ipv4"),
port = jsonNode.getInt("port"),
publicKey = PublicKey(jsonNode.getString("public_key"))
)
publicKey = PublicKey(jsonNode.getString("public_key")),
),
)
}
 
 
domain/src/main/kotlin/tox/Tox.kt added: 235, removed: 224, total 11
@@ -147,7 +147,7 @@ class Tox @Inject constructor(
tox.getSaveData()
} else {
ToxCryptoImpl.encrypt(tox.getSaveData(), passkey)
}
},
)
}
}
 
domain/src/main/kotlin/tox/ToxAvEventListener.kt added: 235, removed: 224, total 11
@@ -23,7 +23,7 @@ typealias VideoReceiveFrameHandler = (
v: ByteArray,
yStride: Int,
uStride: Int,
vStride: Int
vStride: Int,
) -> Unit
 
typealias AudioReceiveFrameHandler = (pk: String, pcm: ShortArray, channels: Int, samplingRate: Int) -> Unit
@@ -52,7 +52,7 @@ class ToxAvEventListener @Inject constructor() : ToxAvEventListener<Unit> {
height: Int,
yStride: Int,
uStride: Int,
vStride: Int
vStride: Int,
): Option<Tuple3<ByteArray, ByteArray, ByteArray>> = Option.empty()
 
override fun videoReceiveFrame(
@@ -65,12 +65,12 @@ class ToxAvEventListener @Inject constructor() : ToxAvEventListener<Unit> {
yStride: Int,
uStride: Int,
vStride: Int,
s: Unit?
s: Unit?,
) = videoReceiveFrameHandler(
keyFor(friendNo),
width, height,
y, u, v,
yStride, uStride, vStride
yStride, uStride, vStride,
)
 
override fun callState(friendNo: Int, callState: EnumSet<ToxavFriendCallState>, s: Unit?) =
@@ -81,7 +81,7 @@ class ToxAvEventListener @Inject constructor() : ToxAvEventListener<Unit> {
pcm: ShortArray,
channels: Int,
samplingRate: Int,
s: Unit?
s: Unit?,
) = audioReceiveFrameHandler(keyFor(friendNo), pcm, channels, samplingRate)
 
override fun audioBitRate(friendNo: Int, bitRate: Int, s: Unit?) =
 
domain/src/main/kotlin/tox/ToxEventListener.kt added: 235, removed: 224, total 11
@@ -24,7 +24,7 @@ typealias FriendMessageHandler = (
publicKey: String,
messageType: ToxMessageType,
timeDelta: Int,
message: String
message: String,
) -> Unit
typealias FriendNameHandler = (publicKey: String, newName: String) -> Unit
typealias FileRecvChunkHandler = (publicKey: String, fileNo: Int, position: Long, data: ByteArray) -> Unit
@@ -82,7 +82,7 @@ class ToxEventListener @Inject constructor() : ToxCoreEventListener<Unit> {
type: ToxMessageType,
timeDelta: Int,
message: ByteArray,
s: Unit?
s: Unit?,
) = friendMessageHandler(keyFor(friendNo), type, timeDelta, String(message))
 
override fun friendName(friendNo: Int, newName: ByteArray, s: Unit?) =
@@ -93,7 +93,7 @@ class ToxEventListener @Inject constructor() : ToxCoreEventListener<Unit> {
fileNo: Int,
position: Long,
data: ByteArray,
s: Unit?
s: Unit?,
) = fileRecvChunkHandler(keyFor(friendNo), fileNo, position, data)
 
override fun fileRecv(
@@ -102,7 +102,7 @@ class ToxEventListener @Inject constructor() : ToxCoreEventListener<Unit> {
kind: Int,
fileSize: Long,
filename: ByteArray,
s: Unit?
s: Unit?,
) = fileRecvHandler(keyFor(friendNo), fileNo, kind, fileSize, String(filename))
 
override fun friendLossyPacket(friendNo: Int, data: ByteArray, s: Unit?) =
@@ -119,6 +119,6 @@ class ToxEventListener @Inject constructor() : ToxCoreEventListener<Unit> {
fileNo: Int,
position: Long,
length: Int,
s: Unit?
s: Unit?,
) = fileChunkRequestHandler(keyFor(friendNo), fileNo, position, length)
}
 
domain/src/main/kotlin/tox/ToxUtil.kt added: 235, removed: 224, total 11
@@ -35,7 +35,7 @@ fun SaveOptions.toToxOptions(): ToxOptions = ToxOptions(
0,
0,
if (saveData == null) SaveDataOptions.`None$`() else SaveDataOptions.ToxSave(saveData),
true
true,
)
 
fun UserStatus.toToxType(): ToxUserStatus = when (this) {
 
domain/src/main/kotlin/tox/ToxWrapper.kt added: 235, removed: 224, total 11
@@ -36,12 +36,12 @@ enum class CustomPacketError {
class ToxWrapper(
private val eventListener: ToxEventListener,
private val avEventListener: ToxAvEventListener,
options: SaveOptions
options: SaveOptions,
) {
private val tox: ToxCoreImpl =
ToxCoreImpl(
options.toToxOptions()
.also { Log.i(TAG, "Starting Tox with options $it") }
.also { Log.i(TAG, "Starting Tox with options $it") },
)
private val av: ToxAvImpl = ToxAvImpl(tox)
 
@@ -99,7 +99,8 @@ class ToxWrapper(
tox.friendList.find { PublicKey.fromBytes(tox.getFriendPublicKey(it)) == pk }?.let { friend ->
tox.deleteFriend(friend)
} ?: Log.e(
TAG, "Tried to delete nonexistent contact, this can happen if the database is out of sync with the Tox save"
TAG,
"Tried to delete nonexistent contact, this can happen if the database is out of sync with the Tox save",
)
 
updateContactMapping()
@@ -117,7 +118,7 @@ class ToxWrapper(
contactByKey(publicKey),
type.toToxType(),
0,
message.toByteArray()
message.toByteArray(),
)
 
fun acceptFriendRequest(pk: PublicKey) = try {
 
domain/src/test/kotlin/tox/ToxUtilTest.kt added: 235, removed: 224, total 11
@@ -81,7 +81,7 @@ class ToxUtilTest {
 
val keyBytes = byteArrayOf(
0x76, 0x51, 0x84, 0x06, 0xF6, 0xA9, 0xF2, 0x21, 0x7E, 0x8D, 0xC4, 0x87, 0xCC, 0x78, 0x3C, 0x25,
0xCC, 0x16, 0xA1, 0x5E, 0xB3, 0x6F, 0xF3, 0x2E, 0x33, 0x5A, 0x23, 0x53, 0x42, 0xC4, 0x8A, 0x39
0xCC, 0x16, 0xA1, 0x5E, 0xB3, 0x6F, 0xF3, 0x2E, 0x33, 0x5A, 0x23, 0x53, 0x42, 0xC4, 0x8A, 0x39,
)
 
assertEquals(keyBytes.size, keyString.hexToBytes().size)
@@ -97,7 +97,7 @@ class ToxUtilTest {
val keyString = "76518406F6A9F2217E8DC487CC783C25CC16A15EB36FF32E335A235342C48A39"
assertArrayEquals(
keyString.uppercase().hexToBytes(),
keyString.lowercase().hexToBytes()
keyString.lowercase().hexToBytes(),
)
}
}