mirror of
https://github.com/oxen-io/session-android.git
synced 2023-12-14 02:53:01 +01:00
fbd1721eaf
* feat: Menu redesign * Add bottomsheet * Handle default peek height * Smooth out setting peek height * Move contacts prep to util * Dialog layout tweaks * Contact grouping tweaks * Add new message dialog * Add public key input delegate * Add create group dialog * Add join community dialog * Handle dialog back navigation * Enter community url tab tweaks * Scan QR code tab refactor * Scan qr code refactor * Direct and community tabs refactor * Add session id copy context menu item * Set dialog background colours * Set full dialog background colour * Minor tweaks * Add closed group contact search * Cleanup * Add content descriptions * Resize community chips * Fix new conversation screen paddings * Fix fade in/out of join community screen * Prevent creating conversation with empty public key * Resize and position create group loader * Fix back nav after creating direct message conversation * Fix inter-screen transitions * Fix new conversation background colours * Fix background colours * Rename contact list header for clarity * Bug fixes * Enable scrolling of Enter Session ID tab of the new message dialog * Minor refactor * Switch to child fragment manager * Fix member search on create group screen Co-authored-by: charles <charles@oxen.io>
92 lines
3.1 KiB
Kotlin
92 lines
3.1 KiB
Kotlin
package org.thoughtcrime.securesms.util
|
|
|
|
import android.Manifest
|
|
import android.content.pm.PackageManager
|
|
import android.os.Bundle
|
|
import android.view.LayoutInflater
|
|
import android.view.View
|
|
import android.view.ViewGroup
|
|
import androidx.core.content.ContextCompat
|
|
import androidx.fragment.app.Fragment
|
|
import com.tbruyelle.rxpermissions2.RxPermissions
|
|
import network.loki.messenger.R
|
|
import org.thoughtcrime.securesms.qr.ScanListener
|
|
|
|
class ScanQRCodeWrapperFragment : Fragment(), ScanQRCodePlaceholderFragmentDelegate, ScanListener {
|
|
|
|
companion object {
|
|
const val FRAGMENT_TAG = "ScanQRCodeWrapperFragment_FRAGMENT_TAG"
|
|
}
|
|
|
|
var delegate: ScanQRCodeWrapperFragmentDelegate? = null
|
|
var message: CharSequence = ""
|
|
var enabled: Boolean = true
|
|
set(value) {
|
|
val shouldUpdate = field != value // update if value changes (view appears or disappears)
|
|
field = value
|
|
if (shouldUpdate) {
|
|
update()
|
|
}
|
|
}
|
|
|
|
override fun setUserVisibleHint(isVisibleToUser: Boolean) {
|
|
super.setUserVisibleHint(isVisibleToUser)
|
|
enabled = isVisibleToUser
|
|
}
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
|
return inflater.inflate(R.layout.fragment_scan_qr_code_wrapper, container, false)
|
|
}
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
super.onViewCreated(view, savedInstanceState)
|
|
update()
|
|
}
|
|
|
|
private fun update() {
|
|
if (!this.isAdded) return
|
|
|
|
val fragment: Fragment
|
|
if (!enabled) {
|
|
val manager = childFragmentManager
|
|
manager.findFragmentByTag(FRAGMENT_TAG)?.let { existingFragment ->
|
|
// remove existing camera fragment (if switching back to other page)
|
|
manager.beginTransaction().remove(existingFragment).commit()
|
|
}
|
|
return
|
|
}
|
|
if (ContextCompat.checkSelfPermission(requireActivity(), Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {
|
|
val scanQRCodeFragment = ScanQRCodeFragment()
|
|
scanQRCodeFragment.scanListener = this
|
|
scanQRCodeFragment.message = message
|
|
fragment = scanQRCodeFragment
|
|
} else {
|
|
val scanQRCodePlaceholderFragment = ScanQRCodePlaceholderFragment()
|
|
scanQRCodePlaceholderFragment.delegate = this
|
|
fragment = scanQRCodePlaceholderFragment
|
|
}
|
|
val transaction = childFragmentManager.beginTransaction()
|
|
transaction.replace(R.id.fragmentContainer, fragment, FRAGMENT_TAG)
|
|
transaction.commit()
|
|
}
|
|
|
|
override fun requestCameraAccess() {
|
|
@SuppressWarnings("unused")
|
|
val unused = RxPermissions(this).request(Manifest.permission.CAMERA).subscribe { isGranted ->
|
|
if (isGranted) {
|
|
update()
|
|
}
|
|
}
|
|
}
|
|
|
|
override fun onQrDataFound(data: String) {
|
|
activity?.runOnUiThread {
|
|
delegate?.handleQRCodeScanned(data)
|
|
}
|
|
}
|
|
}
|
|
|
|
fun interface ScanQRCodeWrapperFragmentDelegate {
|
|
|
|
fun handleQRCodeScanned(string: String)
|
|
} |