Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/src/main/java/org/thoughtcrime/securesms/DeviceModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import network.loki.messenger.BuildConfig
import org.session.libsession.utilities.Device
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object DeviceModule {
@Provides
@Singleton
fun provides() = BuildConfig.DEVICE
fun provides(): Device = BuildConfig.DEVICE
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
Expand Down Expand Up @@ -43,9 +44,9 @@ class DisappearingMessagesViewModel @AssistedInject constructor(
showDebugOptions = showDebugOptions
)
)
val state = _state.asStateFlow()
val state: StateFlow<State> = _state.asStateFlow()

val uiState = _state
val uiState: StateFlow<UiState> = _state
.map(State::toUiState)
.stateIn(viewModelScope, SharingStarted.Eagerly, UiState())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ import org.session.libsignal.utilities.IdPrefix
import org.session.libsignal.utilities.Log
import org.thoughtcrime.securesms.InputbarViewModel
import org.thoughtcrime.securesms.audio.AudioPlaybackManager
import org.thoughtcrime.securesms.audio.model.AudioPlaybackState
import org.thoughtcrime.securesms.auth.LoginStateRepository
import org.thoughtcrime.securesms.database.AttachmentDatabase
import org.thoughtcrime.securesms.database.BlindMappingRepository
Expand Down Expand Up @@ -183,7 +184,8 @@ class ConversationViewModel @AssistedInject constructor(
private val _dialogsState = MutableStateFlow(DialogsState())
val dialogsState: StateFlow<DialogsState> = _dialogsState

val audioPlaybackState = audioPlaybackManager.playbackState
val audioPlaybackState: StateFlow<AudioPlaybackState> = audioPlaybackManager.playbackState


val threadIdFlow: StateFlow<Long?> =
storage.getThreadId(address)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ class MessageDetailsViewModel @AssistedInject constructor(
attachmentDownloadHandlerFactory: AttachmentDownloadHandler.Factory,
) : ViewModel() {
private val state = MutableStateFlow(MessageDetailsState())
val stateFlow = state.asStateFlow()
val stateFlow: StateFlow<MessageDetailsState> = state.asStateFlow()

private val event = Channel<Event>()
val eventFlow = event.receiveAsFlow()
val eventFlow: Flow<Event> = event.receiveAsFlow()

private val _dialogState: MutableStateFlow<DialogsState> = MutableStateFlow(DialogsState())
val dialogState: StateFlow<DialogsState> = _dialogState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class InputBar @JvmOverloads constructor(
binding.inputBarEditText.setText(text, type)
}

var voiceRecorderState = VoiceRecorderState.Idle
var voiceRecorderState: VoiceRecorderState = VoiceRecorderState.Idle

@Inject
lateinit var recipientRepository: RecipientRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AttachmentControlView: LinearLayout {
// endregion
@Inject lateinit var storage: StorageProtocol

val separator = ""
val separator: String = ""

// region Updating
private fun getAttachmentData(attachmentType: AttachmentType, messageTotalAttachment: Int): Pair<Int, Int> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class VisibleMessageView : FrameLayout {
private var onDoubleTap: (() -> Unit)? = null
private var isOutgoing: Boolean = false

var isMessageSelected = false
var isMessageSelected: Boolean = false
set(value) {
field = value
handleIsSelectedChanged()
Expand All @@ -117,8 +117,8 @@ class VisibleMessageView : FrameLayout {
val messageContentView: VisibleMessageContentView get() = binding.messageContentView.root

// Prevent button spam
val MINIMUM_DURATION_BETWEEN_CLICKS_ON_SAME_VIEW_MS = 500L
var lastClickTimestampMS = 0L
val MINIMUM_DURATION_BETWEEN_CLICKS_ON_SAME_VIEW_MS: Long = 500L
var lastClickTimestampMS: Long = 0L

companion object {
const val swipeToReplyThreshold = 64.0f // dp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,5 @@ abstract class AppBindings {
class ToasterModule {
@Provides
@Singleton
fun provideToaster(@ApplicationContext context: Context) = (context as org.thoughtcrime.securesms.ApplicationContext)
fun provideToaster(@ApplicationContext context: Context): org.thoughtcrime.securesms.ApplicationContext = (context as org.thoughtcrime.securesms.ApplicationContext)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ object CallModule {

@Provides
@Singleton
fun provideAudioManagerCompat(@ApplicationContext context: Context) = AudioManagerCompat.create(context)
fun provideAudioManagerCompat(@ApplicationContext context: Context): AudioManagerCompat = AudioManagerCompat.create(context)

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,60 +51,60 @@ object DatabaseModule {

@Provides
@Singleton
fun provideMediaDatbase(@ApplicationContext context: Context, openHelper: Provider<SQLCipherOpenHelper>) = MediaDatabase(context, openHelper)
fun provideMediaDatbase(@ApplicationContext context: Context, openHelper: Provider<SQLCipherOpenHelper>): MediaDatabase = MediaDatabase(context, openHelper)


@Provides
@Singleton
fun provideDraftDatabase(@ApplicationContext context: Context, openHelper: Provider<SQLCipherOpenHelper>) = DraftDatabase(context, openHelper)
fun provideDraftDatabase(@ApplicationContext context: Context, openHelper: Provider<SQLCipherOpenHelper>): DraftDatabase = DraftDatabase(context, openHelper)


@Provides
@Singleton
fun providePushDatabase(@ApplicationContext context: Context, openHelper: Provider<SQLCipherOpenHelper>) = PushDatabase(context,openHelper)
fun providePushDatabase(@ApplicationContext context: Context, openHelper: Provider<SQLCipherOpenHelper>): PushDatabase = PushDatabase(context,openHelper)

@Provides
@Singleton
fun provideGroupDatabase(@ApplicationContext context: Context, openHelper: Provider<SQLCipherOpenHelper>, loginStateRepository: LoginStateRepository)
fun provideGroupDatabase(@ApplicationContext context: Context, openHelper: Provider<SQLCipherOpenHelper>, loginStateRepository: LoginStateRepository): GroupDatabase
= GroupDatabase(context,openHelper, loginStateRepository)

@Provides
@Singleton
fun provideGroupReceiptDatabase(@ApplicationContext context: Context, openHelper: Provider<SQLCipherOpenHelper>) = GroupReceiptDatabase(context,openHelper)
fun provideGroupReceiptDatabase(@ApplicationContext context: Context, openHelper: Provider<SQLCipherOpenHelper>): GroupReceiptDatabase = GroupReceiptDatabase(context,openHelper)

@Provides
@Singleton
fun searchDatabase(@ApplicationContext context: Context, openHelper: Provider<SQLCipherOpenHelper>) = SearchDatabase(context,openHelper)
fun searchDatabase(@ApplicationContext context: Context, openHelper: Provider<SQLCipherOpenHelper>): SearchDatabase = SearchDatabase(context,openHelper)

@Provides
@Singleton
fun provideLokiApiDatabase(@ApplicationContext context: Context, openHelper: Provider<SQLCipherOpenHelper>) = LokiAPIDatabase(context,openHelper)
fun provideLokiApiDatabase(@ApplicationContext context: Context, openHelper: Provider<SQLCipherOpenHelper>): LokiAPIDatabase = LokiAPIDatabase(context,openHelper)

@Provides
@Singleton
fun provideLokiMessageDatabase(@ApplicationContext context: Context, openHelper: Provider<SQLCipherOpenHelper>) = LokiMessageDatabase(context,openHelper)
fun provideLokiMessageDatabase(@ApplicationContext context: Context, openHelper: Provider<SQLCipherOpenHelper>): LokiMessageDatabase = LokiMessageDatabase(context,openHelper)


@Provides
@Singleton
fun provideLokiBackupFilesDatabase(@ApplicationContext context: Context, openHelper: Provider<SQLCipherOpenHelper>) = LokiBackupFilesDatabase(context,openHelper)
fun provideLokiBackupFilesDatabase(@ApplicationContext context: Context, openHelper: Provider<SQLCipherOpenHelper>): LokiBackupFilesDatabase = LokiBackupFilesDatabase(context,openHelper)


@Provides
@Singleton
fun provideGroupMemberDatabase(@ApplicationContext context: Context, openHelper: Provider<SQLCipherOpenHelper>) = GroupMemberDatabase(context, openHelper)
fun provideGroupMemberDatabase(@ApplicationContext context: Context, openHelper: Provider<SQLCipherOpenHelper>): GroupMemberDatabase = GroupMemberDatabase(context, openHelper)

@Provides
@Singleton
fun provideReactionDatabase(@ApplicationContext context: Context, openHelper: Provider<SQLCipherOpenHelper>) = ReactionDatabase(context, openHelper)
fun provideReactionDatabase(@ApplicationContext context: Context, openHelper: Provider<SQLCipherOpenHelper>): ReactionDatabase = ReactionDatabase(context, openHelper)

@Provides
@Singleton
fun provideEmojiSearchDatabase(@ApplicationContext context: Context, openHelper: Provider<SQLCipherOpenHelper>) = EmojiSearchDatabase(context, openHelper)
fun provideEmojiSearchDatabase(@ApplicationContext context: Context, openHelper: Provider<SQLCipherOpenHelper>): EmojiSearchDatabase = EmojiSearchDatabase(context, openHelper)

@Provides
@Singleton
fun provideExpirationConfigurationDatabase(@ApplicationContext context: Context, openHelper: Provider<SQLCipherOpenHelper>) = ExpirationConfigurationDatabase(context, openHelper)
fun provideExpirationConfigurationDatabase(@ApplicationContext context: Context, openHelper: Provider<SQLCipherOpenHelper>): ExpirationConfigurationDatabase = ExpirationConfigurationDatabase(context, openHelper)

@Provides
@Singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ class GroupManagerV2Impl @Inject constructor(
}
}

override suspend fun respondToInvitation(groupId: AccountId, approved: Boolean) =
override suspend fun respondToInvitation(groupId: AccountId, approved: Boolean): Unit? =
scope.launchAndWait(groupId, "Respond to invitation") {
val group = requireNotNull(
configFactory.withUserConfigs { it.userGroups.getClosedGroup(groupId.hexString) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import org.session.libsession.utilities.recipients.displayName
import org.session.libsignal.utilities.AccountId
import org.session.libsignal.utilities.Log
import org.thoughtcrime.securesms.audio.AudioPlaybackManager
import org.thoughtcrime.securesms.audio.model.AudioPlaybackState
import org.thoughtcrime.securesms.auth.LoginStateRepository
import org.thoughtcrime.securesms.database.RecipientRepository
import org.thoughtcrime.securesms.database.ThreadDatabase
Expand Down Expand Up @@ -112,7 +113,7 @@ class HomeViewModel @Inject constructor(
)
val uiEvents: SharedFlow<UiEvent> = _uiEvents

val audioPlaybackState = audioPlaybackManager.playbackState
val audioPlaybackState: StateFlow<AudioPlaybackState> = audioPlaybackManager.playbackState

/**
* A [StateFlow] that emits the list of threads and the typing status of each thread.
Expand Down Expand Up @@ -285,7 +286,7 @@ class HomeViewModel @Inject constructor(
.distinctUntilChanged()


fun tryReload() = manualReloadTrigger.tryEmit(Unit)
fun tryReload(): Boolean = manualReloadTrigger.tryEmit(Unit)

fun onSearchClicked() {
mutableIsSearchOpen.value = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
Expand All @@ -33,7 +35,7 @@ class NewMessageViewModel @Inject constructor(
private val HELP_URL : String = "https://getsession.org/account-ids"

private val _state = MutableStateFlow(State())
val state = _state.asStateFlow()
val state: StateFlow<State> = _state.asStateFlow()

private val _success = MutableSharedFlow<Success>()
val success get() = _success
Expand All @@ -42,7 +44,7 @@ class NewMessageViewModel @Inject constructor(
extraBufferCapacity = 1,
onBufferOverflow = BufferOverflow.DROP_OLDEST
)
val qrErrors = _qrErrors.asSharedFlow()
val qrErrors: SharedFlow<String> = _qrErrors.asSharedFlow()

private var loadOnsJob: Job? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.mapNotNull
Expand All @@ -32,13 +35,13 @@ internal class LoadAccountViewModel @Inject constructor(
private val application: Application
): AndroidViewModel(application) {
private val state = MutableStateFlow(State())
val stateFlow = state.asStateFlow()
val stateFlow: StateFlow<State> = state.asStateFlow()

private val _events = MutableSharedFlow<LoadAccountEvent>()
val events = _events.asSharedFlow()
val events: SharedFlow<LoadAccountEvent> = _events.asSharedFlow()

private val _qrErrors = MutableSharedFlow<Throwable>(extraBufferCapacity = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST)
val qrErrors = _qrErrors.asSharedFlow()
val qrErrors: Flow<String> = _qrErrors.asSharedFlow()
.mapNotNull { application.getString(R.string.qrNotRecoveryPassword) }

private val codec by lazy { MnemonicCodec { MnemonicUtilities.loadFileContents(getApplication(), it) } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.buffer
Expand Down Expand Up @@ -58,10 +60,10 @@ internal class LoadingViewModel @Inject constructor(
private val state = MutableStateFlow(State.LOADING)

private val _progress = MutableStateFlow(0f)
val progress = _progress.asStateFlow()
val progress: StateFlow<Float> = _progress.asStateFlow()

private val _events = MutableSharedFlow<Event>()
val events = _events.asSharedFlow()
val events: SharedFlow<Event> = _events.asSharedFlow()

init {
viewModelScope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
Expand All @@ -31,10 +33,10 @@ class PickDisplayNameViewModel @AssistedInject constructor(
private val isCreateAccount = !loadFailed

private val _states = MutableStateFlow(if (loadFailed) pickNewNameState() else State())
val states = _states.asStateFlow()
val states: StateFlow<State> = _states.asStateFlow()

private val _events = MutableSharedFlow<Event>()
val events = _events.asSharedFlow()
val events: SharedFlow<Event> = _events.asSharedFlow()

fun onContinue() {
_states.update { it.copy(displayName = it.displayName.trim()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class SettingsViewModel @Inject constructor(
return Phrase.from(context, R.string.updateVersion).put(VERSION_KEY, versionDetails).format()
}

fun hasAvatar() = selfRecipient.value.avatar != null
fun hasAvatar(): Boolean = selfRecipient.value.avatar != null

fun createTempFile(): File? {
try {
Expand All @@ -199,7 +199,7 @@ class SettingsViewModel @Inject constructor(
return tempFile
}

fun getTempFile() = tempFile
fun getTempFile(): File? = tempFile

fun onAvatarPicked(result: CropImageView.CropResult) {
when {
Expand Down Expand Up @@ -381,10 +381,10 @@ class SettingsViewModel @Inject constructor(

fun hasNetworkConnection(): Boolean = connectivity.networkAvailable.value

fun isAnimated(uri: Uri) = proStatusManager.isPostPro() // block animated avatars prior to pro
fun isAnimated(uri: Uri): Boolean = proStatusManager.isPostPro() // block animated avatars prior to pro
&& AnimatedImageUtils.isAnimated(context, uri)

fun isAnimated(rawImageData: ByteArray) = proStatusManager.isPostPro() // block animated avatars prior to pro
fun isAnimated(rawImageData: ByteArray): Boolean = proStatusManager.isPostPro() // block animated avatars prior to pro
&& AnimatedImageUtils.isAnimated(rawImageData)

private fun showAnimatedProCTA() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class RecoveryPasswordViewModel @Inject constructor(
.map { it?.seeded?.seed?.data?.toHexString() }
.stateIn(viewModelScope, SharingStarted.Eagerly, null)

val mnemonic = seed.filterNotNull()
val mnemonic: StateFlow<String> = seed.filterNotNull()
.map {
MnemonicCodec {
MnemonicUtilities.loadFileContents(application, it)
Expand Down
Loading