Skip to content

Commit

Permalink
Made some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aritra-tech committed Mar 9, 2024
1 parent c051300 commit 7e208ff
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,35 +62,35 @@ class LockMasterKeyFragment : Fragment() {

private fun clickHandlers() {
buttonLayout.setOnClickListener {
checkKeyViewModel.getMasterKey().observe(viewLifecycleOwner) { key ->
val inputMasterKey = binding.inputMasterKey.text.toString()
showProgress()
val encryption = Encryption.getDefault("Key", "Salt", ByteArray(16))
val correctMasterKey = encryption.decryptOrNull(key[0].password)
if (inputMasterKey.isEmpty() || inputMasterKey.isBlank()){
binding.apply {
inputMasterKeyHelperTV.text = getString(R.string.master_key_cannot_be_blank)
inputMasterKeyHelperTV.visibility = View.VISIBLE
}
stopProgress()
return@observe
} else {
if (inputMasterKey == correctMasterKey) {
lifecycleScope.launch(Dispatchers.Main) {
delay(1000L)
goToMainActivity()
}
}
else {
binding.apply {
inputMasterKeyHelperTV.text = getString(R.string.incorrect_password)
inputMasterKeyHelperTV.visibility = View.VISIBLE
}
stopProgress()
return@observe
}
}
}
// checkKeyViewModel.getMasterKey().observe(viewLifecycleOwner) { key ->
// val inputMasterKey = binding.inputMasterKey.text.toString()
// showProgress()
// val encryption = Encryption.getDefault("Key", "Salt", ByteArray(16))
// val correctMasterKey = encryption.decryptOrNull(key[0].password)
// if (inputMasterKey.isEmpty() || inputMasterKey.isBlank()){
// binding.apply {
// inputMasterKeyHelperTV.text = getString(R.string.master_key_cannot_be_blank)
// inputMasterKeyHelperTV.visibility = View.VISIBLE
// }
// stopProgress()
// return@observe
// } else {
// if (inputMasterKey == correctMasterKey) {
// lifecycleScope.launch(Dispatchers.Main) {
// delay(1000L)
// goToMainActivity()
// }
// }
// else {
// binding.apply {
// inputMasterKeyHelperTV.text = getString(R.string.incorrect_password)
// inputMasterKeyHelperTV.visibility = View.VISIBLE
// }
// stopProgress()
// return@observe
// }
// }
// }
}

binding.passwordToggle.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,60 +67,60 @@ class UpdateMasterKeyFragment : Fragment() {
}

private fun clickHandlers() {
buttonLayout.setOnClickListener {
updateKeyViewModel.getMasterKey().observe(viewLifecycleOwner) {masterKey ->

val oldMasterKey = binding.layoutOldMasterKey.text.toString()
val updatedMasterKey = binding.layoutMasterKey.text.toString()
val encryption = Encryption.getDefault("Key", "Salt", ByteArray(16))
val correctOldMasterKey = encryption.decryptOrNull(masterKey[0].password)
showProgress()

if (oldMasterKey.isEmpty() || oldMasterKey.isBlank()) {
binding.apply {
oldMasterKeyHelperTV.text = getString(R.string.old_master_key_cannot_be_blank)
oldMasterKeyHelperTV.visibility = View.VISIBLE
}
stopProgress()
}
else {
if (oldMasterKey!=correctOldMasterKey){
binding.apply {
oldMasterKeyHelperTV.text = getString(R.string.old_master_key_is_incorrect)
oldMasterKeyHelperTV.visibility = View.VISIBLE
}
stopProgress()
}
else {
if (updatedMasterKey.isBlank() || updatedMasterKey.isEmpty()) {
binding.apply {
updatedMasterKeyHelperTV.text = getString(R.string.master_key_cannot_be_blank)
updatedMasterKeyHelperTV.visibility = View.VISIBLE
}
stopProgress()
}
else {
if (updatedMasterKey.length <= 5) {
binding.apply {
updatedMasterKeyHelperTV.text = getString(R.string.at_least_6_letter_long)
updatedMasterKeyHelperTV.visibility = View.VISIBLE
}
stopProgress()
}
else {
lifecycleScope.launch(Dispatchers.Main) {
delay(800L)
updateKey()
Toast.makeText(requireContext(),"Successfully Updated the Master Key",Toast.LENGTH_SHORT).show()
goToSecurityFragment()
}
}
}
}
}

}
}
// buttonLayout.setOnClickListener {
// updateKeyViewModel.getMasterKey().observe(viewLifecycleOwner) {masterKey ->
//
// val oldMasterKey = binding.layoutOldMasterKey.text.toString()
// val updatedMasterKey = binding.layoutMasterKey.text.toString()
// val encryption = Encryption.getDefault("Key", "Salt", ByteArray(16))
// val correctOldMasterKey = encryption.decryptOrNull(masterKey[0].password)
// showProgress()
//
// if (oldMasterKey.isEmpty() || oldMasterKey.isBlank()) {
// binding.apply {
// oldMasterKeyHelperTV.text = getString(R.string.old_master_key_cannot_be_blank)
// oldMasterKeyHelperTV.visibility = View.VISIBLE
// }
// stopProgress()
// }
// else {
// if (oldMasterKey!=correctOldMasterKey){
// binding.apply {
// oldMasterKeyHelperTV.text = getString(R.string.old_master_key_is_incorrect)
// oldMasterKeyHelperTV.visibility = View.VISIBLE
// }
// stopProgress()
// }
// else {
// if (updatedMasterKey.isBlank() || updatedMasterKey.isEmpty()) {
// binding.apply {
// updatedMasterKeyHelperTV.text = getString(R.string.master_key_cannot_be_blank)
// updatedMasterKeyHelperTV.visibility = View.VISIBLE
// }
// stopProgress()
// }
// else {
// if (updatedMasterKey.length <= 5) {
// binding.apply {
// updatedMasterKeyHelperTV.text = getString(R.string.at_least_6_letter_long)
// updatedMasterKeyHelperTV.visibility = View.VISIBLE
// }
// stopProgress()
// }
// else {
// lifecycleScope.launch(Dispatchers.Main) {
// delay(800L)
// updateKey()
// Toast.makeText(requireContext(),"Successfully Updated the Master Key",Toast.LENGTH_SHORT).show()
// goToSecurityFragment()
// }
// }
// }
// }
// }
//
// }
// }
}

private fun goToSecurityFragment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,21 +267,21 @@ class HomeFragment : Fragment() {



viewModel = ViewModelProvider(this)[AccountViewModel::class.java]
viewModel.readAllData.observe(viewLifecycleOwner) { account ->


accountList.clear()
accountList.addAll(account)

accountAdapter.setData(account)
if (account.isEmpty()) {
binding.emptyList.visibility = View.VISIBLE
} else {
binding.emptyList.visibility = View.GONE
}

}
// viewModel = ViewModelProvider(this)[AccountViewModel::class.java]
// viewModel.getAccounts().observe(viewLifecycleOwner) { account ->
//
//
// accountList.clear()
// accountList.addAll(account)
//
// accountAdapter.setData(account)
// if (account.isEmpty()) {
// binding.emptyList.visibility = View.VISIBLE
// } else {
// binding.emptyList.visibility = View.GONE
// }
//
// }

// Moving to AddFragment
binding.fab.setOnClickListener {
Expand Down Expand Up @@ -387,16 +387,16 @@ class HomeFragment : Fragment() {
}


override fun onResume() {
super.onResume()
viewModel.readAllData.observe(viewLifecycleOwner) { account ->
accountAdapter.setData(account)
if (account.isEmpty()) {
binding.emptyList.visibility = View.VISIBLE
} else {
binding.emptyList.visibility = View.GONE
}

}
}
// override fun onResume() {
// super.onResume()
// viewModel.readAllData.observe(viewLifecycleOwner) { account ->
// accountAdapter.setData(account)
// if (account.isEmpty()) {
// binding.emptyList.visibility = View.VISIBLE
// } else {
// binding.emptyList.visibility = View.GONE
// }
//
// }
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.geekymusketeers.uncrack.databinding.ActivitySplashBinding
import com.geekymusketeers.uncrack.util.Util
import com.geekymusketeers.uncrack.ui.auth.MasterKeyActivity
import com.geekymusketeers.uncrack.viewModel.KeyViewModel
import com.geekymusketeers.uncrack.viewModel.ViewModelFactory
//import com.geekymusketeers.uncrack.viewModel.ViewModelFactory
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand All @@ -25,7 +25,7 @@ class SplashActivity : AppCompatActivity() {
lateinit var binding: ActivitySplashBinding
private var cancellationSignal: CancellationSignal? = null
private lateinit var biometricPrompt: BiometricPrompt
private val keyViewModel by viewModels<KeyViewModel> { ViewModelFactory() }
// private val keyViewModel by viewModels<KeyViewModel> { ViewModelFactory() }


override fun onCreate(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -60,28 +60,28 @@ class SplashActivity : AppCompatActivity() {
}

private fun handleMasterKey() {
keyViewModel.getMasterKey().observe(this) {
when {
it.isEmpty() -> {
CoroutineScope(Dispatchers.Main).launch {
delay(1000)
val intent = Intent(this@SplashActivity, MasterKeyActivity::class.java)
intent.putExtra("flow","createMasterKey")
startActivity(intent)
finish()
}
}
else -> {
CoroutineScope(Dispatchers.Main).launch {
delay(1000)
val intent = Intent(this@SplashActivity, MasterKeyActivity::class.java)
intent.putExtra("flow","askForMasterKey")
startActivity(intent)
finish()
}
}
}
}
// keyViewModel.getMasterKey().observe(this) {
// when {
// it.isEmpty() -> {
// CoroutineScope(Dispatchers.Main).launch {
// delay(1000)
// val intent = Intent(this@SplashActivity, MasterKeyActivity::class.java)
// intent.putExtra("flow","createMasterKey")
// startActivity(intent)
// finish()
// }
// }
// else -> {
// CoroutineScope(Dispatchers.Main).launch {
// delay(1000)
// val intent = Intent(this@SplashActivity, MasterKeyActivity::class.java)
// intent.putExtra("flow","askForMasterKey")
// startActivity(intent)
// finish()
// }
// }
// }
// }
}

private fun showDialog() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package com.geekymusketeers.uncrack.viewModel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewmodel.CreationExtras


class ViewModelFactory : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(modelClass: Class<T>, extras: CreationExtras): T =
with(modelClass) {
// Get the Application object from extras
val application = checkNotNull(extras[ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEY])
when {
isAssignableFrom(KeyViewModel::class.java) -> {
KeyViewModel(application)
}
else -> throw IllegalArgumentException("Unknown ViewModel class")
}
} as T
}
//package com.geekymusketeers.uncrack.viewModel
//
//import androidx.lifecycle.ViewModel
//import androidx.lifecycle.ViewModelProvider
//import androidx.lifecycle.viewmodel.CreationExtras
//
//
//class ViewModelFactory : ViewModelProvider.Factory {
// @Suppress("UNCHECKED_CAST")
// override fun <T : ViewModel> create(modelClass: Class<T>, extras: CreationExtras): T =
// with(modelClass) {
// // Get the Application object from extras
// val application = checkNotNull(extras[ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEY])
// when {
// isAssignableFrom(KeyViewModel::class.java) -> {
// KeyViewModel(application)
// }
// else -> throw IllegalArgumentException("Unknown ViewModel class")
// }
// } as T
//}

0 comments on commit 7e208ff

Please sign in to comment.