code review and lint fixes

This commit is contained in:
NIkita Fedrunov 2022-01-28 10:10:26 +01:00
parent b6eb27f8a1
commit f56991f077
8 changed files with 29 additions and 23 deletions

View file

@ -46,9 +46,9 @@ import im.vector.app.core.utils.registerForPermissionsResult
import im.vector.app.features.analytics.plan.Screen import im.vector.app.features.analytics.plan.Screen
import im.vector.app.features.contactsbook.ContactsBookFragment import im.vector.app.features.contactsbook.ContactsBookFragment
import im.vector.app.features.qrcode.QrCodeScannerEvents import im.vector.app.features.qrcode.QrCodeScannerEvents
import im.vector.app.features.qrcode.QrCodeScannerFragment
import im.vector.app.features.qrcode.QrCodeScannerViewModel import im.vector.app.features.qrcode.QrCodeScannerViewModel
import im.vector.app.features.qrcode.QrScannerArgs import im.vector.app.features.qrcode.QrScannerArgs
import im.vector.app.features.qrcode.QrCodeScannerFragment
import im.vector.app.features.userdirectory.UserListFragment import im.vector.app.features.userdirectory.UserListFragment
import im.vector.app.features.userdirectory.UserListFragmentArgs import im.vector.app.features.userdirectory.UserListFragmentArgs
import im.vector.app.features.userdirectory.UserListSharedAction import im.vector.app.features.userdirectory.UserListSharedAction
@ -111,7 +111,7 @@ class CreateDirectRoomActivity : SimpleFragmentActivity() {
Toast.makeText(this, R.string.cannot_dm_self, Toast.LENGTH_SHORT).show() Toast.makeText(this, R.string.cannot_dm_self, Toast.LENGTH_SHORT).show()
finish() finish()
} }
} }.exhaustive
} }
qrViewModel.observeViewEvents { qrViewModel.observeViewEvents {
@ -123,7 +123,8 @@ class CreateDirectRoomActivity : SimpleFragmentActivity() {
Toast.makeText(this, R.string.qr_code_not_scanned, Toast.LENGTH_SHORT).show() Toast.makeText(this, R.string.qr_code_not_scanned, Toast.LENGTH_SHORT).show()
finish() finish()
} }
} else -> Unit
}.exhaustive
} }
} }

View file

@ -16,10 +16,9 @@
package im.vector.app.features.createdirect package im.vector.app.features.createdirect
import com.airbnb.mvrx.Async
import im.vector.app.core.platform.VectorViewEvents import im.vector.app.core.platform.VectorViewEvents
sealed class CreateDirectRoomViewEvents : VectorViewEvents { sealed class CreateDirectRoomViewEvents : VectorViewEvents {
object InvalidCode: CreateDirectRoomViewEvents() object InvalidCode : CreateDirectRoomViewEvents()
object DmSelf: CreateDirectRoomViewEvents() object DmSelf : CreateDirectRoomViewEvents()
} }

View file

@ -24,12 +24,13 @@ import androidx.activity.result.ActivityResultLauncher
import com.airbnb.mvrx.viewModel import com.airbnb.mvrx.viewModel
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.extensions.exhaustive
import im.vector.app.core.extensions.replaceFragment import im.vector.app.core.extensions.replaceFragment
import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.core.platform.VectorBaseActivity
import im.vector.app.databinding.ActivitySimpleBinding import im.vector.app.databinding.ActivitySimpleBinding
@AndroidEntryPoint @AndroidEntryPoint
class QrCodeScannerActivity(): VectorBaseActivity<ActivitySimpleBinding>() { class QrCodeScannerActivity() : VectorBaseActivity<ActivitySimpleBinding>() {
override fun getBinding() = ActivitySimpleBinding.inflate(layoutInflater) override fun getBinding() = ActivitySimpleBinding.inflate(layoutInflater)
@ -49,7 +50,8 @@ class QrCodeScannerActivity(): VectorBaseActivity<ActivitySimpleBinding>() {
Toast.makeText(this, R.string.qr_code_not_scanned, Toast.LENGTH_SHORT).show() Toast.makeText(this, R.string.qr_code_not_scanned, Toast.LENGTH_SHORT).show()
finish() finish()
} }
} else -> Unit
}.exhaustive
} }
if (isFirstCreation()) { if (isFirstCreation()) {
@ -66,7 +68,6 @@ class QrCodeScannerActivity(): VectorBaseActivity<ActivitySimpleBinding>() {
finish() finish()
} }
companion object { companion object {
private const val EXTRA_OUT_TEXT = "EXTRA_OUT_TEXT" private const val EXTRA_OUT_TEXT = "EXTRA_OUT_TEXT"
private const val EXTRA_OUT_IS_QR_CODE = "EXTRA_OUT_IS_QR_CODE" private const val EXTRA_OUT_IS_QR_CODE = "EXTRA_OUT_IS_QR_CODE"

View file

@ -19,7 +19,7 @@ package im.vector.app.features.qrcode
import im.vector.app.core.platform.VectorViewEvents import im.vector.app.core.platform.VectorViewEvents
sealed class QrCodeScannerEvents : VectorViewEvents { sealed class QrCodeScannerEvents : VectorViewEvents {
data class CodeParsed(val result: String, val isQrCode: Boolean): QrCodeScannerEvents() data class CodeParsed(val result: String, val isQrCode: Boolean) : QrCodeScannerEvents()
object ParseFailed: QrCodeScannerEvents() object ParseFailed : QrCodeScannerEvents()
object SwitchMode: QrCodeScannerEvents() object SwitchMode : QrCodeScannerEvents()
} }

View file

@ -53,7 +53,7 @@ data class QrScannerArgs(
@StringRes val titleRes: Int @StringRes val titleRes: Int
) : Parcelable ) : Parcelable
open class QrCodeScannerFragment @Inject constructor(): VectorBaseFragment<FragmentQrCodeScannerBinding>(), ZXingScannerView.ResultHandler { open class QrCodeScannerFragment @Inject constructor() : VectorBaseFragment<FragmentQrCodeScannerBinding>(), ZXingScannerView.ResultHandler {
private val qrViewModel: QrCodeScannerViewModel by activityViewModel() private val qrViewModel: QrCodeScannerViewModel by activityViewModel()
private val scannerArgs: QrScannerArgs? by args() private val scannerArgs: QrScannerArgs? by args()

View file

@ -40,11 +40,12 @@ class QrCodeScannerViewModel @AssistedInject constructor(
companion object : MavericksViewModelFactory<QrCodeScannerViewModel, VectorDummyViewState> by hiltMavericksViewModelFactory() companion object : MavericksViewModelFactory<QrCodeScannerViewModel, VectorDummyViewState> by hiltMavericksViewModelFactory()
override fun handle(action: QrCodeScannerAction) { override fun handle(action: QrCodeScannerAction) {
_viewEvents.post(
when (action) { when (action) {
is QrCodeScannerAction.CodeDecoded -> _viewEvents.post(QrCodeScannerEvents.CodeParsed(action.result, action.isQrCode)) is QrCodeScannerAction.CodeDecoded -> QrCodeScannerEvents.CodeParsed(action.result, action.isQrCode)
is QrCodeScannerAction.SwitchMode -> _viewEvents.post(QrCodeScannerEvents.SwitchMode) is QrCodeScannerAction.SwitchMode -> QrCodeScannerEvents.SwitchMode
is QrCodeScannerAction.ScanFailed -> _viewEvents.post(QrCodeScannerEvents.ParseFailed) is QrCodeScannerAction.ScanFailed -> QrCodeScannerEvents.ParseFailed
}.exhaustive }.exhaustive
)
} }
} }

View file

@ -127,7 +127,7 @@ class UserCodeActivity : VectorBaseActivity<ActivitySimpleBinding>(),
Toast.makeText(this, R.string.qr_code_not_scanned, Toast.LENGTH_SHORT).show() Toast.makeText(this, R.string.qr_code_not_scanned, Toast.LENGTH_SHORT).show()
finish() finish()
} }
} }.exhaustive
} }
} }

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
@ -29,6 +30,7 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/appBarLayout" /> app:layout_constraintTop_toBottomOf="@id/appBarLayout" />
<!-- TODO In the future we could add a toggle to switch the flash, and other possible settings -->
<Button <Button
android:id="@+id/userCodeMyCodeButton" android:id="@+id/userCodeMyCodeButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -39,7 +41,8 @@
android:visibility="gone" android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" /> app:layout_constraintStart_toStartOf="parent"
tools:visibility="visible" />
<Button <Button
android:id="@+id/userCodeOpenGalleryButton" android:id="@+id/userCodeOpenGalleryButton"
@ -65,6 +68,7 @@
app:layout_constraintBottom_toBottomOf="@id/userCodeMyCodeButton" app:layout_constraintBottom_toBottomOf="@id/userCodeMyCodeButton"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintEnd_toStartOf="@id/userCodeMyCodeButton" app:layout_constraintEnd_toStartOf="@id/userCodeMyCodeButton"
app:layout_constraintTop_toTopOf="@id/userCodeMyCodeButton" /> app:layout_constraintTop_toTopOf="@id/userCodeMyCodeButton"
tools:visibility="visible" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>