From 6bfd9d07a931b6188fa673a41fd80150dde9316d Mon Sep 17 00:00:00 2001 From: fedrunov Date: Thu, 6 Jan 2022 17:11:23 +0100 Subject: [PATCH 1/2] Toolbar is added to a views with QR code scan --- changelog.d/4644.misc | 1 + .../CreateDirectRoomByQrCodeFragment.kt | 13 ++++ .../features/qrcode/QrCodeScannerFragment.kt | 12 ++++ .../features/usercode/ScanUserCodeFragment.kt | 4 ++ .../res/layout/fragment_qr_code_scanner.xml | 60 ++++++++++++++++++- .../fragment_qr_code_scanner_with_button.xml | 59 +++++++++++++++++- 6 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 changelog.d/4644.misc diff --git a/changelog.d/4644.misc b/changelog.d/4644.misc new file mode 100644 index 0000000000..faf3346f66 --- /dev/null +++ b/changelog.d/4644.misc @@ -0,0 +1 @@ +Toolbar is added to a views with QR code scan \ No newline at end of file diff --git a/vector/src/main/java/im/vector/app/features/createdirect/CreateDirectRoomByQrCodeFragment.kt b/vector/src/main/java/im/vector/app/features/createdirect/CreateDirectRoomByQrCodeFragment.kt index 5f089c6448..96401604f3 100644 --- a/vector/src/main/java/im/vector/app/features/createdirect/CreateDirectRoomByQrCodeFragment.kt +++ b/vector/src/main/java/im/vector/app/features/createdirect/CreateDirectRoomByQrCodeFragment.kt @@ -16,7 +16,9 @@ package im.vector.app.features.createdirect +import android.os.Bundle import android.view.LayoutInflater +import android.view.View import android.view.ViewGroup import android.widget.Toast import com.airbnb.mvrx.activityViewModel @@ -58,6 +60,17 @@ class CreateDirectRoomByQrCodeFragment @Inject constructor() : VectorBaseFragmen views.scannerView.startCamera() } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + setupToolbar(views.qrScannerToolbar) + + views.qrScannerClose.debouncedClicks { + requireActivity().onBackPressed() + } + views.qrScannerTitle.text = getString(R.string.add_by_qr_code) + } + override fun onResume() { super.onResume() view?.hideKeyboard() diff --git a/vector/src/main/java/im/vector/app/features/qrcode/QrCodeScannerFragment.kt b/vector/src/main/java/im/vector/app/features/qrcode/QrCodeScannerFragment.kt index 3a3841c026..95d3ce4a07 100644 --- a/vector/src/main/java/im/vector/app/features/qrcode/QrCodeScannerFragment.kt +++ b/vector/src/main/java/im/vector/app/features/qrcode/QrCodeScannerFragment.kt @@ -16,9 +16,12 @@ package im.vector.app.features.qrcode +import android.os.Bundle import android.view.LayoutInflater +import android.view.View import android.view.ViewGroup import com.google.zxing.Result +import im.vector.app.R import im.vector.app.core.platform.VectorBaseFragment import im.vector.app.databinding.FragmentQrCodeScannerBinding import me.dm7.barcodescanner.zxing.ZXingScannerView @@ -32,6 +35,15 @@ class QrCodeScannerFragment @Inject constructor() : return FragmentQrCodeScannerBinding.inflate(inflater, container, false) } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + views.qrScannerClose.debouncedClicks { + requireActivity().onBackPressed() + } + views.qrScannerTitle.text = getString(R.string.verification_scan_their_code) + } + override fun onResume() { super.onResume() // Register ourselves as a handler for scan results. diff --git a/vector/src/main/java/im/vector/app/features/usercode/ScanUserCodeFragment.kt b/vector/src/main/java/im/vector/app/features/usercode/ScanUserCodeFragment.kt index e70ffd0d76..389256871e 100644 --- a/vector/src/main/java/im/vector/app/features/usercode/ScanUserCodeFragment.kt +++ b/vector/src/main/java/im/vector/app/features/usercode/ScanUserCodeFragment.kt @@ -62,6 +62,10 @@ class ScanUserCodeFragment @Inject constructor() : views.userCodeOpenGalleryButton.debouncedClicks { MultiPicker.get(MultiPicker.IMAGE).single().startWith(pickImageActivityResultLauncher) } + + views.userCodeClose.debouncedClicks { + requireActivity().onBackPressed() + } } private val openCameraActivityResultLauncher = registerForPermissionsResult { allGranted, _ -> diff --git a/vector/src/main/res/layout/fragment_qr_code_scanner.xml b/vector/src/main/res/layout/fragment_qr_code_scanner.xml index 78003e7032..4e4813bf01 100644 --- a/vector/src/main/res/layout/fragment_qr_code_scanner.xml +++ b/vector/src/main/res/layout/fragment_qr_code_scanner.xml @@ -1,9 +1,67 @@ + + + + + + + + + + + + + + + + + app:layout_constraintTop_toBottomOf="@+id/appBarLayout" /> diff --git a/vector/src/main/res/layout/fragment_qr_code_scanner_with_button.xml b/vector/src/main/res/layout/fragment_qr_code_scanner_with_button.xml index 1a14404411..d337a3eb95 100644 --- a/vector/src/main/res/layout/fragment_qr_code_scanner_with_button.xml +++ b/vector/src/main/res/layout/fragment_qr_code_scanner_with_button.xml @@ -1,9 +1,66 @@ + + + + + + + + + + + + + + + + + app:layout_constraintTop_toBottomOf="@+id/appBarLayout" />