mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 10:25:35 +03:00
Fix nullability issues.
This commit is contained in:
parent
e5482d48c0
commit
0a77d5014e
21 changed files with 57 additions and 53 deletions
|
@ -16,10 +16,8 @@
|
|||
|
||||
package im.vector.riotx.core.files
|
||||
|
||||
import android.app.DownloadManager
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.provider.MediaStore
|
||||
import androidx.annotation.WorkerThread
|
||||
import arrow.core.Try
|
||||
|
@ -57,23 +55,17 @@ fun addEntryToDownloadManager(context: Context,
|
|||
mimeType: String,
|
||||
title: String = file.name,
|
||||
description: String = file.name) {
|
||||
val downloadManager = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager?
|
||||
|
||||
try {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
val contentValues = ContentValues().apply {
|
||||
put(MediaStore.Downloads.TITLE, title)
|
||||
put(MediaStore.Downloads.DISPLAY_NAME, description)
|
||||
put(MediaStore.Downloads.MIME_TYPE, mimeType)
|
||||
put(MediaStore.Downloads.SIZE, file.length())
|
||||
val contentValues = ContentValues().apply {
|
||||
put(MediaStore.Downloads.TITLE, title)
|
||||
put(MediaStore.Downloads.DISPLAY_NAME, description)
|
||||
put(MediaStore.Downloads.MIME_TYPE, mimeType)
|
||||
put(MediaStore.Downloads.SIZE, file.length())
|
||||
}
|
||||
context.contentResolver.insert(MediaStore.Downloads.EXTERNAL_CONTENT_URI, contentValues)?.let { uri ->
|
||||
context.contentResolver.openOutputStream(uri)?.use { outputStream ->
|
||||
outputStream.sink().buffer().write(file.inputStream().use { it.readBytes() })
|
||||
}
|
||||
context.contentResolver.insert(MediaStore.Downloads.EXTERNAL_CONTENT_URI, contentValues)?.let { uri ->
|
||||
context.contentResolver.openOutputStream(uri)?.use { outputStream ->
|
||||
outputStream.sink().buffer().write(file.inputStream().use { it.readBytes() })
|
||||
}
|
||||
}
|
||||
} else {
|
||||
downloadManager?.addCompletedDownload(title, description, true, mimeType, file.absolutePath, file.length(), true)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "## addEntryToDownloadManager(): Exception")
|
||||
|
|
|
@ -95,7 +95,7 @@ class VectorGlideDataFetcher(private val activeSessionHolder: ActiveSessionHolde
|
|||
|
||||
override fun loadData(priority: Priority, callback: DataFetcher.DataCallback<in InputStream>) {
|
||||
Timber.v("Load data: $data")
|
||||
if (data.isLocalFile()) {
|
||||
if (data.isLocalFile() && data.url != null) {
|
||||
val initialFile = File(data.url)
|
||||
callback.onDataReady(FileInputStream(initialFile))
|
||||
return
|
||||
|
|
|
@ -333,7 +333,7 @@ class EllipsizingTextView @JvmOverloads constructor(context: Context, attrs: Att
|
|||
* @param workingText text to strip end punctuation from
|
||||
* @return Text without end punctuation.
|
||||
*/
|
||||
fun stripEndPunctuation(workingText: CharSequence?): String {
|
||||
fun stripEndPunctuation(workingText: CharSequence): String {
|
||||
return mEndPunctPattern!!.matcher(workingText).replaceFirst("")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -134,7 +134,7 @@ abstract class VectorBaseActivity : AppCompatActivity(), HasScreenInjector {
|
|||
restorables.forEach { it.onSaveInstanceState(outState) }
|
||||
}
|
||||
|
||||
override fun onRestoreInstanceState(savedInstanceState: Bundle?) {
|
||||
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
|
||||
restorables.forEach { it.onRestoreInstanceState(savedInstanceState) }
|
||||
super.onRestoreInstanceState(savedInstanceState)
|
||||
}
|
||||
|
|
|
@ -128,13 +128,13 @@ class CallService : VectorService() {
|
|||
* Display a call in progress notification.
|
||||
*/
|
||||
private fun displayCallInProgressNotification(intent: Intent) {
|
||||
val callId = intent.getStringExtra(EXTRA_CALL_ID)
|
||||
val callId = intent.getStringExtra(EXTRA_CALL_ID) ?: ""
|
||||
|
||||
val notification = notificationUtils.buildPendingCallNotification(
|
||||
intent.getBooleanExtra(EXTRA_IS_VIDEO, false),
|
||||
intent.getStringExtra(EXTRA_ROOM_NAME),
|
||||
intent.getStringExtra(EXTRA_ROOM_ID),
|
||||
intent.getStringExtra(EXTRA_MATRIX_ID),
|
||||
intent.getStringExtra(EXTRA_ROOM_NAME) ?: "",
|
||||
intent.getStringExtra(EXTRA_ROOM_ID) ?: "",
|
||||
intent.getStringExtra(EXTRA_MATRIX_ID) ?: "",
|
||||
callId)
|
||||
|
||||
startForeground(NOTIFICATION_ID, notification)
|
||||
|
|
|
@ -37,9 +37,10 @@ class Debouncer(private val handler: Handler) {
|
|||
|
||||
fun cancel(identifier: String) {
|
||||
if (runnables.containsKey(identifier)) {
|
||||
val old = runnables[identifier]
|
||||
handler.removeCallbacks(old)
|
||||
runnables.remove(identifier)
|
||||
runnables[identifier]?.let {
|
||||
handler.removeCallbacks(it)
|
||||
runnables.remove(identifier)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ private fun logAction(file: File): Boolean {
|
|||
*/
|
||||
private fun recursiveActionOnFile(file: File, action: ActionOnFile): Boolean {
|
||||
if (file.isDirectory) {
|
||||
file.list().forEach {
|
||||
file.list()?.forEach {
|
||||
val result = recursiveActionOnFile(File(file, it), action)
|
||||
|
||||
if (!result) {
|
||||
|
|
|
@ -35,8 +35,8 @@ object TextUtils {
|
|||
if (value < 1000) return value.toString() // deal with easy case
|
||||
|
||||
val e = suffixes.floorEntry(value)
|
||||
val divideBy = e.key
|
||||
val suffix = e.value
|
||||
val divideBy = e?.key
|
||||
val suffix = e?.value
|
||||
|
||||
val truncated = value / (divideBy!! / 10) // the number part of the output times 10
|
||||
val hasDecimal = truncated < 100 && truncated / 10.0 != (truncated / 10).toDouble()
|
||||
|
|
|
@ -43,7 +43,7 @@ class AttachmentsPreviewActivity : VectorBaseActivity(), ToolbarConfigurable {
|
|||
}
|
||||
|
||||
fun getOutput(intent: Intent): List<ContentAttachmentData> {
|
||||
return intent.getParcelableArrayListExtra(ATTACHMENTS_PREVIEW_RESULT)
|
||||
return intent.getParcelableArrayListExtra(ATTACHMENTS_PREVIEW_RESULT) ?: emptyList()
|
||||
}
|
||||
|
||||
fun getKeepOriginalSize(intent: Intent): Boolean {
|
||||
|
|
|
@ -153,7 +153,7 @@ class KeysBackupSetupActivity : SimpleFragmentActivity() {
|
|||
}
|
||||
|
||||
override fun onFailure(failure: Throwable) {
|
||||
toast(failure.localizedMessage)
|
||||
failure.localizedMessage?.let { toast(it) }
|
||||
hideWaitingView()
|
||||
}
|
||||
})
|
||||
|
|
|
@ -158,8 +158,8 @@ class SharedSecureStorageViewModel @AssistedInject constructor(
|
|||
@JvmStatic
|
||||
override fun create(viewModelContext: ViewModelContext, state: SharedSecureStorageViewState): SharedSecureStorageViewModel? {
|
||||
val activity: SharedSecureStorageActivity = viewModelContext.activity()
|
||||
val args: SharedSecureStorageActivity.Args = activity.intent.getParcelableExtra(MvRx.KEY_ARG)
|
||||
return activity.viewModelFactory.create(state, args)
|
||||
val args: SharedSecureStorageActivity.Args? = activity.intent.getParcelableExtra(MvRx.KEY_ARG)
|
||||
return args?.let { activity.viewModelFactory.create(state, it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -357,7 +357,9 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(
|
|||
}
|
||||
}
|
||||
} catch (failure: Throwable) {
|
||||
_viewEvents.post(VerificationBottomSheetViewEvents.ModalError(failure.localizedMessage))
|
||||
failure.localizedMessage?.let {
|
||||
_viewEvents.post(VerificationBottomSheetViewEvents.ModalError(it))
|
||||
}
|
||||
}
|
||||
}
|
||||
}.exhaustive
|
||||
|
|
|
@ -782,7 +782,7 @@ class RoomDetailFragment @Inject constructor(
|
|||
updateComposerText("")
|
||||
}
|
||||
is RoomDetailViewEvents.SlashCommandResultError -> {
|
||||
displayCommandError(sendMessageResult.throwable.localizedMessage)
|
||||
sendMessageResult.throwable.localizedMessage?.let { displayCommandError(it) }
|
||||
}
|
||||
is RoomDetailViewEvents.SlashCommandNotImplemented -> {
|
||||
displayCommandError(getString(R.string.not_implemented))
|
||||
|
|
|
@ -56,10 +56,17 @@ class ImageMediaViewerActivity : VectorBaseActivity() {
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(im.vector.riotx.R.layout.activity_image_media_viewer)
|
||||
mediaData = intent.getParcelableExtra(EXTRA_MEDIA_DATA)
|
||||
|
||||
if (intent.hasExtra(EXTRA_MEDIA_DATA)) {
|
||||
mediaData = intent.getParcelableExtra(EXTRA_MEDIA_DATA)!!
|
||||
} else {
|
||||
finish()
|
||||
}
|
||||
|
||||
intent.extras?.getString(EXTRA_SHARED_TRANSITION_NAME)?.let {
|
||||
ViewCompat.setTransitionName(imageTransitionView, it)
|
||||
}
|
||||
|
||||
if (mediaData.url.isNullOrEmpty()) {
|
||||
supportFinishAfterTransition()
|
||||
return
|
||||
|
|
|
@ -37,11 +37,14 @@ class VideoMediaViewerActivity : VectorBaseActivity() {
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(im.vector.riotx.R.layout.activity_video_media_viewer)
|
||||
val mediaData = intent.getParcelableExtra<VideoContentRenderer.Data>(EXTRA_MEDIA_DATA)
|
||||
|
||||
configureToolbar(videoMediaViewerToolbar, mediaData)
|
||||
imageContentRenderer.render(mediaData.thumbnailMediaData, ImageContentRenderer.Mode.FULL_SIZE, videoMediaViewerThumbnailView)
|
||||
videoContentRenderer.render(mediaData, videoMediaViewerThumbnailView, videoMediaViewerLoading, videoMediaViewerVideoView, videoMediaViewerErrorView)
|
||||
if (intent.hasExtra(EXTRA_MEDIA_DATA)) {
|
||||
val mediaData = intent.getParcelableExtra<VideoContentRenderer.Data>(EXTRA_MEDIA_DATA)!!
|
||||
|
||||
configureToolbar(videoMediaViewerToolbar, mediaData)
|
||||
imageContentRenderer.render(mediaData.thumbnailMediaData, ImageContentRenderer.Mode.FULL_SIZE, videoMediaViewerThumbnailView)
|
||||
videoContentRenderer.render(mediaData, videoMediaViewerThumbnailView, videoMediaViewerLoading, videoMediaViewerVideoView, videoMediaViewerErrorView)
|
||||
}
|
||||
}
|
||||
|
||||
private fun configureToolbar(toolbar: Toolbar, mediaData: VideoContentRenderer.Data) {
|
||||
|
|
|
@ -97,7 +97,7 @@ class NotificationBroadcastReceiver : BroadcastReceiver() {
|
|||
val message = getReplyMessage(intent)
|
||||
val roomId = intent.getStringExtra(KEY_ROOM_ID)
|
||||
|
||||
if (message.isNullOrBlank() || roomId.isBlank()) {
|
||||
if (message.isNullOrBlank() || roomId.isNullOrBlank()) {
|
||||
// ignore this event
|
||||
// Can this happen? should we update notification?
|
||||
return
|
||||
|
|
|
@ -65,7 +65,7 @@ class VectorFileLogger @Inject constructor(val context: Context, private val vec
|
|||
sFileHandler?.formatter = LogFormatter()
|
||||
sLogger.useParentHandlers = false
|
||||
sLogger.level = Level.ALL
|
||||
sLogger.addHandler(sFileHandler)
|
||||
sFileHandler?.let { sLogger.addHandler(it) }
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
Timber.e(e, "Failed to initialize FileLogger")
|
||||
|
|
|
@ -70,7 +70,7 @@ class RoomPreviewActivity : VectorBaseActivity(), ToolbarConfigurable {
|
|||
if (isFirstCreation()) {
|
||||
val args = intent.getParcelableExtra<RoomPreviewData>(ARG)
|
||||
|
||||
if (args.worldReadable) {
|
||||
if (args?.worldReadable == true) {
|
||||
// TODO Room preview: Note: M does not recommend to use /events anymore, so for now we just display the room preview
|
||||
// TODO the same way if it was not world readable
|
||||
addFragment(R.id.simpleFragmentContainer, RoomPreviewNoPreviewFragment::class.java, args)
|
||||
|
|
|
@ -59,9 +59,9 @@ object VectorLocale {
|
|||
val preferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
|
||||
if (preferences.contains(APPLICATION_LOCALE_LANGUAGE_KEY)) {
|
||||
applicationLocale = Locale(preferences.getString(APPLICATION_LOCALE_LANGUAGE_KEY, ""),
|
||||
preferences.getString(APPLICATION_LOCALE_COUNTRY_KEY, ""),
|
||||
preferences.getString(APPLICATION_LOCALE_VARIANT_KEY, "")
|
||||
applicationLocale = Locale(preferences.getString(APPLICATION_LOCALE_LANGUAGE_KEY, "")!!,
|
||||
preferences.getString(APPLICATION_LOCALE_COUNTRY_KEY, "")!!,
|
||||
preferences.getString(APPLICATION_LOCALE_VARIANT_KEY, "")!!
|
||||
)
|
||||
} else {
|
||||
applicationLocale = Locale.getDefault()
|
||||
|
|
|
@ -29,7 +29,6 @@ import im.vector.riotx.R
|
|||
import im.vector.riotx.features.homeserver.ServerUrlsRepository
|
||||
import im.vector.riotx.features.themes.ThemeUtils
|
||||
import timber.log.Timber
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
|
||||
class VectorPreferences @Inject constructor(private val context: Context) {
|
||||
|
@ -68,7 +67,7 @@ class VectorPreferences @Inject constructor(private val context: Context) {
|
|||
const val SETTINGS_ENCRYPTION_EXPORT_E2E_ROOM_KEYS_PREFERENCE_KEY = "SETTINGS_ENCRYPTION_EXPORT_E2E_ROOM_KEYS_PREFERENCE_KEY"
|
||||
const val SETTINGS_ENCRYPTION_IMPORT_E2E_ROOM_KEYS_PREFERENCE_KEY = "SETTINGS_ENCRYPTION_IMPORT_E2E_ROOM_KEYS_PREFERENCE_KEY"
|
||||
const val SETTINGS_ENCRYPTION_NEVER_SENT_TO_PREFERENCE_KEY = "SETTINGS_ENCRYPTION_NEVER_SENT_TO_PREFERENCE_KEY"
|
||||
const val SETTINGS_SHOW_DEVICES_LIST_PREFERENCE_KEY = "SETTINGS_SHOW_DEVICES_LIST_PREFERENCE_KEY"
|
||||
const val SETTINGS_SHOW_DEVICES_LIST_PREFERENCE_KEY = "SETTINGS_SHOW_DEVICES_LIST_PREFERENCE_KEY"
|
||||
|
||||
const val SETTINGS_SECURE_MESSAGE_RECOVERY_PREFERENCE_KEY = "SETTINGS_SECURE_MESSAGE_RECOVERY_PREFERENCE_KEY"
|
||||
|
||||
|
@ -427,11 +426,11 @@ class VectorPreferences @Inject constructor(private val context: Context) {
|
|||
val toneUri = getNotificationRingTone() ?: return null
|
||||
|
||||
try {
|
||||
val proj = arrayOf(MediaStore.Audio.Media.DATA)
|
||||
val proj = arrayOf(MediaStore.Audio.Media.DISPLAY_NAME)
|
||||
return context.contentResolver.query(toneUri, proj, null, null, null)?.use {
|
||||
val columnIndex = it.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA)
|
||||
val columnIndex = it.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME)
|
||||
it.moveToFirst()
|
||||
File(it.getString(columnIndex)).nameWithoutExtension
|
||||
it.getString(columnIndex)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "## getNotificationRingToneName() failed")
|
||||
|
|
|
@ -332,7 +332,7 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor(
|
|||
}
|
||||
|
||||
override fun onFailure(failure: Throwable) {
|
||||
appContext.toast(failure.localizedMessage)
|
||||
failure.localizedMessage?.let { appContext.toast(it) }
|
||||
hideLoadingView()
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue