mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-16 12:00:03 +03:00
Pin: polish a bit and clean code
This commit is contained in:
parent
bb066b7c65
commit
06bd353d44
16 changed files with 39 additions and 145 deletions
|
@ -164,7 +164,7 @@ Formatter\.formatShortFileSize===1
|
|||
# android\.text\.TextUtils
|
||||
|
||||
### This is not a rule, but a warning: the number of "enum class" has changed. For Json classes, it is mandatory that they have `@JsonClass(generateAdapter = false)`. If it is ok, change the value in file forbidden_strings_in_code.txt
|
||||
enum class===74
|
||||
enum class===76
|
||||
|
||||
### Do not import temporary legacy classes
|
||||
import im.vector.matrix.android.internal.legacy.riot===3
|
||||
|
|
|
@ -36,7 +36,6 @@ import im.vector.riotx.core.utils.allGranted
|
|||
import im.vector.riotx.core.utils.checkPermissions
|
||||
import im.vector.riotx.core.utils.toast
|
||||
import im.vector.riotx.features.debug.sas.DebugSasEmojiActivity
|
||||
import im.vector.riotx.features.pin.PinActivity
|
||||
import im.vector.riotx.features.qrcode.QrCodeScannerActivity
|
||||
import kotlinx.android.synthetic.debug.activity_debug_menu.*
|
||||
import timber.log.Timber
|
||||
|
@ -82,11 +81,6 @@ class DebugMenuActivity : VectorBaseActivity() {
|
|||
startActivity(Intent(this, DebugSasEmojiActivity::class.java))
|
||||
}
|
||||
|
||||
@OnClick(R.id.debug_open_pin_code)
|
||||
fun openPinCode() {
|
||||
//startActivity(PinActivity.newIntent(this))
|
||||
}
|
||||
|
||||
@OnClick(R.id.debug_test_notification)
|
||||
fun testNotification() {
|
||||
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
|
|
|
@ -61,13 +61,6 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:text="Crash the app" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/debug_open_pin_code"
|
||||
style="@style/VectorButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Open pin code screen" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/debug_scan_qr_code"
|
||||
style="@style/VectorButtonStyle"
|
||||
|
|
|
@ -35,7 +35,6 @@ import com.gabrielittner.threetenbp.LazyThreeTen
|
|||
import im.vector.matrix.android.api.Matrix
|
||||
import im.vector.matrix.android.api.MatrixConfiguration
|
||||
import im.vector.matrix.android.api.auth.AuthenticationService
|
||||
import im.vector.matrix.android.api.extensions.orFalse
|
||||
import im.vector.matrix.android.api.legacy.LegacySessionImporter
|
||||
import im.vector.riotx.core.di.ActiveSessionHolder
|
||||
import im.vector.riotx.core.di.DaggerVectorComponent
|
||||
|
@ -48,7 +47,6 @@ import im.vector.riotx.features.disclaimer.doNotShowDisclaimerDialog
|
|||
import im.vector.riotx.features.lifecycle.VectorActivityLifecycleCallbacks
|
||||
import im.vector.riotx.features.notifications.NotificationDrawerManager
|
||||
import im.vector.riotx.features.notifications.NotificationUtils
|
||||
import im.vector.riotx.features.pin.PinCodeStore
|
||||
import im.vector.riotx.features.pin.PinLocker
|
||||
import im.vector.riotx.features.popup.PopupAlertManager
|
||||
import im.vector.riotx.features.rageshake.VectorUncaughtExceptionHandler
|
||||
|
|
|
@ -203,7 +203,7 @@ abstract class VectorBaseActivity : AppCompatActivity(), HasScreenInjector {
|
|||
}
|
||||
})
|
||||
pinLocker.getLiveState().observeNotNull(this) {
|
||||
if(this@VectorBaseActivity !is UnlockedActivity && it == PinLocker.State.LOCKED){
|
||||
if (this@VectorBaseActivity !is UnlockedActivity && it == PinLocker.State.LOCKED) {
|
||||
navigator.openPinCode(this, PinMode.AUTH)
|
||||
}
|
||||
}
|
||||
|
@ -305,9 +305,6 @@ abstract class VectorBaseActivity : AppCompatActivity(), HasScreenInjector {
|
|||
Activity.RESULT_OK -> {
|
||||
pinLocker.unlock()
|
||||
}
|
||||
PinActivity.PIN_RESULT_CODE_FORGOT -> {
|
||||
pinLocker.block()
|
||||
}
|
||||
else -> {
|
||||
pinLocker.block()
|
||||
moveTaskToBack(true)
|
||||
|
|
|
@ -35,6 +35,9 @@ import im.vector.riotx.features.home.HomeActivity
|
|||
import im.vector.riotx.features.home.ShortcutsHandler
|
||||
import im.vector.riotx.features.login.LoginActivity
|
||||
import im.vector.riotx.features.notifications.NotificationDrawerManager
|
||||
import im.vector.riotx.features.pin.PinCodeStore
|
||||
import im.vector.riotx.features.pin.PinLocker
|
||||
import im.vector.riotx.features.pin.UnlockedActivity
|
||||
import im.vector.riotx.features.settings.VectorPreferences
|
||||
import im.vector.riotx.features.signout.hard.SignedOutActivity
|
||||
import im.vector.riotx.features.signout.soft.SoftLogoutActivity
|
||||
|
@ -61,7 +64,7 @@ data class MainActivityArgs(
|
|||
* This Activity, when started with argument, is also doing some cleanup when user disconnects,
|
||||
* clears cache, is logged out, or is soft logged out
|
||||
*/
|
||||
class MainActivity : VectorBaseActivity() {
|
||||
class MainActivity : VectorBaseActivity(), UnlockedActivity {
|
||||
|
||||
companion object {
|
||||
private const val EXTRA_ARGS = "EXTRA_ARGS"
|
||||
|
@ -84,6 +87,8 @@ class MainActivity : VectorBaseActivity() {
|
|||
@Inject lateinit var vectorPreferences: VectorPreferences
|
||||
@Inject lateinit var uiStateRepository: UiStateRepository
|
||||
@Inject lateinit var shortcutsHandler: ShortcutsHandler
|
||||
@Inject lateinit var pinCodeStore: PinCodeStore
|
||||
@Inject lateinit var pinLocker: PinLocker
|
||||
|
||||
override fun injectWith(injector: ScreenComponent) {
|
||||
injector.inject(this)
|
||||
|
@ -181,6 +186,8 @@ class MainActivity : VectorBaseActivity() {
|
|||
if (clearPreferences) {
|
||||
vectorPreferences.clearPreferences()
|
||||
uiStateRepository.reset()
|
||||
pinLocker.unlock()
|
||||
pinCodeStore.deleteEncodedPin()
|
||||
}
|
||||
withContext(Dispatchers.IO) {
|
||||
// On BG thread
|
||||
|
|
|
@ -44,13 +44,14 @@ import im.vector.riotx.features.home.HomeActivity
|
|||
import im.vector.riotx.features.login.terms.LoginTermsFragment
|
||||
import im.vector.riotx.features.login.terms.LoginTermsFragmentArgument
|
||||
import im.vector.riotx.features.login.terms.toLocalizedLoginTerms
|
||||
import im.vector.riotx.features.pin.UnlockedActivity
|
||||
import kotlinx.android.synthetic.main.activity_login.*
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* The LoginActivity manages the fragment navigation and also display the loading View
|
||||
*/
|
||||
open class LoginActivity : VectorBaseActivity(), ToolbarConfigurable {
|
||||
open class LoginActivity : VectorBaseActivity(), ToolbarConfigurable, UnlockedActivity {
|
||||
|
||||
private val loginViewModel: LoginViewModel by viewModel()
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ import im.vector.riotx.features.call.service.CallHeadsUpActionReceiver
|
|||
import im.vector.riotx.features.home.HomeActivity
|
||||
import im.vector.riotx.features.home.room.detail.RoomDetailActivity
|
||||
import im.vector.riotx.features.home.room.detail.RoomDetailArgs
|
||||
import im.vector.riotx.features.pin.PinLocker
|
||||
import im.vector.riotx.features.settings.VectorPreferences
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
@ -59,6 +60,7 @@ import kotlin.random.Random
|
|||
@Singleton
|
||||
class NotificationUtils @Inject constructor(private val context: Context,
|
||||
private val stringProvider: StringProvider,
|
||||
private val pinLocker: PinLocker,
|
||||
private val vectorPreferences: VectorPreferences) {
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.riotx.features.pin
|
||||
|
||||
import im.vector.riotx.core.platform.VectorViewModelAction
|
||||
|
||||
sealed class PinAction : VectorViewModelAction
|
|
@ -30,7 +30,6 @@ class PinActivity : VectorBaseActivity(), ToolbarConfigurable, UnlockedActivity
|
|||
companion object {
|
||||
|
||||
const val PIN_REQUEST_CODE = 17890
|
||||
const val PIN_RESULT_CODE_FORGOT = 17891
|
||||
|
||||
fun newIntent(context: Context, args: PinArgs): Intent {
|
||||
return Intent(context, PinActivity::class.java).apply {
|
||||
|
|
|
@ -24,16 +24,15 @@ import android.widget.Toast
|
|||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.airbnb.mvrx.args
|
||||
import com.airbnb.mvrx.fragmentViewModel
|
||||
import com.airbnb.mvrx.withState
|
||||
import com.beautycoder.pflockscreen.PFFLockScreenConfiguration
|
||||
import com.beautycoder.pflockscreen.fragments.PFLockScreenFragment
|
||||
import im.vector.riotx.R
|
||||
import im.vector.riotx.core.extensions.replaceFragment
|
||||
import im.vector.riotx.core.platform.VectorBaseFragment
|
||||
import im.vector.riotx.features.MainActivity
|
||||
import im.vector.riotx.features.MainActivityArgs
|
||||
import kotlinx.android.parcel.Parcelize
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
@Parcelize
|
||||
|
@ -42,11 +41,9 @@ data class PinArgs(
|
|||
) : Parcelable
|
||||
|
||||
class PinFragment @Inject constructor(
|
||||
private val pinCodeStore: PinCodeStore,
|
||||
private val viewModelFactory: PinViewModel.Factory
|
||||
) : VectorBaseFragment(), PinViewModel.Factory by viewModelFactory {
|
||||
private val pinCodeStore: PinCodeStore
|
||||
) : VectorBaseFragment() {
|
||||
|
||||
private val viewModel: PinViewModel by fragmentViewModel()
|
||||
private val fragmentArgs: PinArgs by args()
|
||||
|
||||
override fun getLayoutResId() = R.layout.fragment_pin
|
||||
|
@ -140,7 +137,6 @@ class PinFragment @Inject constructor(
|
|||
}
|
||||
|
||||
override fun onFingerprintSuccessful() {
|
||||
Toast.makeText(requireContext(), "Pin successful", Toast.LENGTH_LONG).show()
|
||||
vectorBaseActivity.setResult(Activity.RESULT_OK)
|
||||
vectorBaseActivity.finish()
|
||||
}
|
||||
|
@ -149,7 +145,6 @@ class PinFragment @Inject constructor(
|
|||
}
|
||||
|
||||
override fun onCodeInputSuccessful() {
|
||||
Toast.makeText(requireContext(), "Pin successful", Toast.LENGTH_LONG).show()
|
||||
vectorBaseActivity.setResult(Activity.RESULT_OK)
|
||||
vectorBaseActivity.finish()
|
||||
}
|
||||
|
@ -161,23 +156,14 @@ class PinFragment @Inject constructor(
|
|||
AlertDialog.Builder(requireContext())
|
||||
.setTitle(getString(R.string.auth_pin_reset_title))
|
||||
.setMessage(getString(R.string.auth_pin_reset_content))
|
||||
.setPositiveButton(getString(R.string.auth_pin_reset_title)) { _, _ ->
|
||||
lifecycleScope.launch {
|
||||
pinCodeStore.deleteEncodedPin()
|
||||
vectorBaseActivity.setResult(PinActivity.PIN_RESULT_CODE_FORGOT)
|
||||
vectorBaseActivity.finish()
|
||||
}
|
||||
.setPositiveButton(getString(R.string.auth_pin_new_pin_action)) { _, _ ->
|
||||
launchResetPinFlow()
|
||||
}
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.show()
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
// Clear your view, unsubscribe...
|
||||
}
|
||||
|
||||
override fun invalidate() = withState(viewModel) { state ->
|
||||
Timber.v("Invalidate $state")
|
||||
private fun launchResetPinFlow() {
|
||||
MainActivity.restartApp(requireActivity(), MainActivityArgs(clearCredentials = true))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.riotx.features.pin
|
||||
|
||||
import com.airbnb.mvrx.ActivityViewModelContext
|
||||
import com.airbnb.mvrx.FragmentViewModelContext
|
||||
import com.airbnb.mvrx.MvRxViewModelFactory
|
||||
import com.airbnb.mvrx.ViewModelContext
|
||||
import com.squareup.inject.assisted.Assisted
|
||||
import com.squareup.inject.assisted.AssistedInject
|
||||
import im.vector.riotx.core.platform.EmptyViewEvents
|
||||
import im.vector.riotx.core.platform.VectorViewModel
|
||||
import timber.log.Timber
|
||||
|
||||
class PinViewModel @AssistedInject constructor(@Assisted initialState: PinViewState)
|
||||
: VectorViewModel<PinViewState, PinAction, EmptyViewEvents>(initialState) {
|
||||
|
||||
@AssistedInject.Factory
|
||||
interface Factory {
|
||||
fun create(initialState: PinViewState): PinViewModel
|
||||
}
|
||||
|
||||
companion object : MvRxViewModelFactory<PinViewModel, PinViewState> {
|
||||
|
||||
@JvmStatic
|
||||
override fun create(viewModelContext: ViewModelContext, state: PinViewState): PinViewModel? {
|
||||
val factory = when (viewModelContext) {
|
||||
is FragmentViewModelContext -> viewModelContext.fragment as? Factory
|
||||
is ActivityViewModelContext -> viewModelContext.activity as? Factory
|
||||
}
|
||||
return factory?.create(state) ?: error("You should let your activity/fragment implements Factory interface")
|
||||
}
|
||||
}
|
||||
|
||||
override fun handle(action: PinAction) {
|
||||
Timber.v("$action not handled by viewModel")
|
||||
}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.riotx.features.pin
|
||||
|
||||
import com.airbnb.mvrx.MvRxState
|
||||
|
||||
data class PinViewState(val mode: PinMode) : MvRxState {
|
||||
|
||||
constructor(args: PinArgs) : this(mode = args.pinMode)
|
||||
}
|
13
vector/src/main/res/drawable/bg_pin_key.xml
Normal file
13
vector/src/main/res/drawable/bg_pin_key.xml
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="?attr/colorControlHighlight">
|
||||
<item
|
||||
android:gravity="center">
|
||||
<shape android:shape="oval">
|
||||
<solid android:color="#44FFFFFF" />
|
||||
<size
|
||||
android:width="70dp"
|
||||
android:height="70dp" />
|
||||
</shape>
|
||||
</item>
|
||||
</ripple>
|
|
@ -2578,6 +2578,7 @@ Not all features in Riot are implemented in Element yet. Main missing (and comin
|
|||
<string name="auth_pin_title">Enter your PIN</string>
|
||||
<string name="auth_pin_forgot">Forgot PIN?</string>
|
||||
<string name="auth_pin_reset_title">Reset pin</string>
|
||||
<string name="auth_pin_new_pin_action">New pin</string>
|
||||
<string name="auth_pin_reset_content">To reset your PIN, you\'ll need to re-login and create a new one.</string>
|
||||
<string name="settings_security_pin_code_title">Enable PIN</string>
|
||||
<string name="settings_security_pin_code_summary">If you want to reset your PIN, tap Forgot PIN to logout and reset.</string>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<style name="PinCodeKeyButtonStyle">
|
||||
<item name="android:textColor">?riotx_text_primary</item>
|
||||
<item name="android:textSize">18sp</item>
|
||||
<item name="background">@drawable/touch_selector_pf</item>
|
||||
<item name="android:background">@drawable/bg_pin_key</item>
|
||||
</style>
|
||||
|
||||
<style name="PinCodeDotsViewStyle">
|
||||
|
@ -24,13 +24,13 @@
|
|||
<style name="PinCodeDeleteButtonStyle">
|
||||
<item name="android:src">@drawable/delete_lockscreen_pf</item>
|
||||
<item name="android:tint">?riotx_text_primary</item>
|
||||
<item name="background">@drawable/touch_selector_pf</item>
|
||||
<item name="background">@drawable/bg_pin_key</item>
|
||||
</style>
|
||||
|
||||
<style name="PinCodeFingerprintButtonStyle">
|
||||
<item name="android:src">@drawable/fingerprint_lockscreen_pf</item>
|
||||
<item name="android:tint">?riotx_text_primary</item>
|
||||
<item name="background">@drawable/touch_selector_pf</item>
|
||||
<item name="background">@drawable/bg_pin_key</item>
|
||||
</style>
|
||||
|
||||
<style name="PinCodeTitleStyle">
|
||||
|
|
Loading…
Add table
Reference in a new issue