Skip to content
Snippets Groups Projects
Commit f0b32c77 authored by Taras's avatar Taras
Browse files

Remove base fullscreen

parent 3de063ce
No related branches found
No related tags found
No related merge requests found
package org.futo.circles.core.fragment
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import androidx.appcompat.app.AppCompatDialogFragment
import androidx.viewbinding.ViewBinding
import com.google.android.material.appbar.MaterialToolbar
import org.futo.circles.R
import org.futo.circles.extensions.onBackPressed
abstract class BaseFullscreenDialogFragment(
private val inflate: (LayoutInflater, ViewGroup?, Boolean) -> ViewBinding
) : AppCompatDialogFragment() {
private var _binding: ViewBinding? = null
protected open val toolbarId = R.id.toolbar
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(STYLE_NO_FRAME, R.style.Theme_Circles)
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View? {
_binding = inflate.invoke(inflater, container, false)
dialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
return _binding?.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setupToolbar()
}
protected fun getBinding() = _binding
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
private fun setupToolbar() {
view?.findViewById<MaterialToolbar>(toolbarId)?.let {
it.setNavigationOnClickListener { onBackPressed() }
it.navigationContentDescription = getString(R.string.back)
}
}
}
\ No newline at end of file
package org.futo.circles.core.fragment
import android.view.View
import androidx.fragment.app.Fragment
import org.futo.circles.extensions.setEnabledViews
interface HasLoadingState {
val fragment: Fragment
fun startLoading(button: LoadingButton) {
currentLoadingButton = button
currentLoadingButton?.setIsLoading(true)
fragment.setEnabledViews(false, alwaysDisabledViews)
}
fun stopLoading() {
currentLoadingButton?.setIsLoading(false)
currentLoadingButton = null
fragment.setEnabledViews(true, alwaysDisabledViews)
}
fun setAlwaysDisabledViews(views: List<View>) {
alwaysDisabledViews = views
}
companion object {
private var currentLoadingButton: LoadingButton? = null
private var alwaysDisabledViews: List<View> = mutableListOf()
}
}
\ No newline at end of file
package org.futo.circles.core.fragment
import android.content.Context
import androidx.activity.OnBackPressedCallback
import androidx.annotation.LayoutRes
import androidx.fragment.app.Fragment
interface BackPressOwner {
fun onChildBackPress(callback: OnBackPressedCallback)
}
abstract class ParentBackPressOwnerFragment(@LayoutRes contentLayoutId: Int) :
Fragment(contentLayoutId) {
override fun onAttach(context: Context) {
super.onAttach(context)
val parent = (parentFragment?.parentFragment as? BackPressOwner) ?: return
activity?.onBackPressedDispatcher?.addCallback(this,
object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
parent.onChildBackPress(this)
}
})
}
}
package org.futo.circles.feature.settings.active_sessions
import android.content.Context
import org.futo.circles.R
import org.futo.circles.provider.MatrixSessionProvider
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.crypto.crosssigning.MASTER_KEY_SSSS_NAME
import org.matrix.android.sdk.api.session.crypto.crosssigning.SELF_SIGNING_KEY_SSSS_NAME
import org.matrix.android.sdk.api.session.crypto.crosssigning.USER_SIGNING_KEY_SSSS_NAME
import org.matrix.android.sdk.api.session.crypto.crosssigning.isVerified
import org.matrix.android.sdk.api.session.securestorage.KeyInfoResult
import org.matrix.android.sdk.api.session.securestorage.KeyRef
import org.matrix.android.sdk.api.session.securestorage.SsssKeySpec
import org.matrix.android.sdk.api.util.awaitCallback
class CrossSigningDataSource(private val context: Context) {
suspend fun initCrossSigningIfNeed(keySpec: SsssKeySpec) {
val session = MatrixSessionProvider.currentSession ?: throw IllegalArgumentException(
context.getString(R.string.session_is_not_created)
)
val crossSigningService = session.cryptoService().crossSigningService()
try {
session.sharedSecretStorageService().getSecret(MASTER_KEY_SSSS_NAME, null, keySpec)
} catch (ignore: Throwable) {
awaitCallback { crossSigningService.initializeCrossSigning(null, it) }
storeKeys(session, keySpec)
}
}
suspend fun configureCrossSigning(keySpec: SsssKeySpec) {
val session = MatrixSessionProvider.currentSession ?: throw IllegalArgumentException(
context.getString(R.string.session_is_not_created)
)
val keyId = (session.sharedSecretStorageService()
.getDefaultKey() as? KeyInfoResult.Success)?.keyInfo?.id
initCrossSigningIfNeed(keySpec)
val ssssService = session.sharedSecretStorageService()
val mskPrivateKey =
ssssService.getSecret(MASTER_KEY_SSSS_NAME, keyId, keySpec)
val uskPrivateKey =
ssssService.getSecret(USER_SIGNING_KEY_SSSS_NAME, keyId, keySpec)
val sskPrivateKey =
ssssService.getSecret(SELF_SIGNING_KEY_SSSS_NAME, keyId, keySpec)
val trustResult =
session.cryptoService().crossSigningService().checkTrustFromPrivateKeys(
mskPrivateKey, uskPrivateKey, sskPrivateKey
)
if (trustResult.isVerified()) {
awaitCallback {
session.sessionParams.deviceId?.let { deviceId ->
session.cryptoService().crossSigningService().trustDevice(deviceId, it)
}
}
}
}
private suspend fun storeKeys(session: Session, keySpec: SsssKeySpec) {
val xKeys = session.cryptoService().crossSigningService().getCrossSigningPrivateKeys()
val mskPrivateKey = xKeys?.master
?: throw IllegalArgumentException(context.getString(R.string.key_is_missing))
val sskPrivateKey = xKeys.selfSigned
?: throw IllegalArgumentException(context.getString(R.string.key_is_missing))
val uskPrivateKey = xKeys.user
?: throw IllegalArgumentException(context.getString(R.string.key_is_missing))
val keyId = (session.sharedSecretStorageService()
.getDefaultKey() as? KeyInfoResult.Success)?.keyInfo?.id
session.sharedSecretStorageService().storeSecret(
MASTER_KEY_SSSS_NAME,
mskPrivateKey,
listOf(KeyRef(keyId, keySpec))
)
session.sharedSecretStorageService().storeSecret(
USER_SIGNING_KEY_SSSS_NAME,
uskPrivateKey,
listOf(KeyRef(keyId, keySpec))
)
session.sharedSecretStorageService().storeSecret(
SELF_SIGNING_KEY_SSSS_NAME,
sskPrivateKey,
listOf(KeyRef(keyId, keySpec))
)
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment