diff options
| author | Harsh Shandilya <me@msfjarvis.dev> | 2021-05-15 12:56:49 +0530 |
|---|---|---|
| committer | Harsh Shandilya <me@msfjarvis.dev> | 2021-05-15 15:40:20 +0530 |
| commit | 7e2eb2425e7b9b6ccb37b7b89f19de3fa7a20c44 (patch) | |
| tree | 6b8a9557ac51b5fab5d2ad7611084cf0de6c57cf /app/src/main/java/dev/msfjarvis/aps/ui/passwords | |
| parent | 2fcb285e276594842798be6990b92ba09e733f49 (diff) | |
| download | HardenedPass-7e2eb2425e7b9b6ccb37b7b89f19de3fa7a20c44.tar.gz HardenedPass-7e2eb2425e7b9b6ccb37b7b89f19de3fa7a20c44.zip | |
all: reformat with Spotless again
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app/src/main/java/dev/msfjarvis/aps/ui/passwords')
| -rw-r--r-- | app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordFragment.kt | 70 | ||||
| -rw-r--r-- | app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordStore.kt | 71 |
2 files changed, 106 insertions, 35 deletions
diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordFragment.kt b/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordFragment.kt index 3740404a..541a3f9e 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordFragment.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordFragment.kt @@ -77,8 +77,12 @@ class PasswordFragment : Fragment(R.layout.password_recycler_view) { super.onViewCreated(view, savedInstanceState) settings = requireContext().sharedPrefs initializePasswordList() - binding.fab.setOnClickListener { ItemCreationBottomSheet().show(childFragmentManager, "BOTTOM_SHEET") } - childFragmentManager.setFragmentResultListener(ITEM_CREATION_REQUEST_KEY, viewLifecycleOwner) { _, bundle -> + binding.fab.setOnClickListener { + ItemCreationBottomSheet().show(childFragmentManager, "BOTTOM_SHEET") + } + childFragmentManager.setFragmentResultListener(ITEM_CREATION_REQUEST_KEY, viewLifecycleOwner) { + _, + bundle -> when (bundle.getString(ACTION_KEY)) { ACTION_FOLDER -> requireStore().createFolder() ACTION_PASSWORD -> requireStore().createPassword() @@ -88,7 +92,8 @@ class PasswordFragment : Fragment(R.layout.password_recycler_view) { private fun initializePasswordList() { val gitDir = File(PasswordRepository.getRepositoryDirectory(), ".git") - val hasGitDir = gitDir.exists() && gitDir.isDirectory && (gitDir.listFiles()?.isNotEmpty() == true) + val hasGitDir = + gitDir.exists() && gitDir.isDirectory && (gitDir.listFiles()?.isNotEmpty() == true) binding.swipeRefresher.setOnRefreshListener { if (!hasGitDir) { requireStore().refreshPasswordList() @@ -118,7 +123,9 @@ class PasswordFragment : Fragment(R.layout.password_recycler_view) { binding.swipeRefresher.isRefreshing = false refreshPasswordList() }, - failure = { err -> promptOnErrorHandler(err) { binding.swipeRefresher.isRefreshing = false } }, + failure = { err -> + promptOnErrorHandler(err) { binding.swipeRefresher.isRefreshing = false } + }, ) } } @@ -135,10 +142,16 @@ class PasswordFragment : Fragment(R.layout.password_recycler_view) { binding.swipeRefresher.isEnabled = selection.isEmpty if (actionMode == null) - actionMode = requireStore().startSupportActionMode(actionModeCallback) ?: return@onSelectionChanged + actionMode = + requireStore().startSupportActionMode(actionModeCallback) ?: return@onSelectionChanged if (!selection.isEmpty) { - actionMode!!.title = resources.getQuantityString(R.plurals.delete_title, selection.size(), selection.size()) + actionMode!!.title = + resources.getQuantityString( + R.plurals.delete_title, + selection.size(), + selection.size() + ) actionMode!!.invalidate() } else { actionMode!!.finish() @@ -171,14 +184,18 @@ class PasswordFragment : Fragment(R.layout.password_recycler_view) { recyclerView.scrollToPosition(0) } scrollTarget != null -> { - scrollTarget?.let { recyclerView.scrollToPosition(recyclerAdapter.getPositionForFile(it)) } + scrollTarget?.let { + recyclerView.scrollToPosition(recyclerAdapter.getPositionForFile(it)) + } scrollTarget = null } else -> { // When the result is not filtered and there is a saved scroll position for // it, // we try to restore it. - recyclerViewStateToRestore?.let { recyclerView.layoutManager!!.onRestoreInstanceState(it) } + recyclerViewStateToRestore?.let { + recyclerView.layoutManager!!.onRestoreInstanceState(it) + } recyclerViewStateToRestore = null } } @@ -201,7 +218,8 @@ class PasswordFragment : Fragment(R.layout.password_recycler_view) { // but may be called multiple times if the mode is invalidated. override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean { val selectedItems = recyclerAdapter.getSelectedItems() - menu.findItem(R.id.menu_edit_password).isVisible = selectedItems.all { it.type == PasswordItem.TYPE_CATEGORY } + menu.findItem(R.id.menu_edit_password).isVisible = + selectedItems.all { it.type == PasswordItem.TYPE_CATEGORY } menu.findItem(R.id.menu_pin_password).isVisible = selectedItems.size == 1 && selectedItems[0].type == PasswordItem.TYPE_PASSWORD return true @@ -227,7 +245,10 @@ class PasswordFragment : Fragment(R.layout.password_recycler_view) { } R.id.menu_pin_password -> { val passwordItem = recyclerAdapter.getSelectedItems()[0] - shortcutHandler.addPinnedShortcut(passwordItem, passwordItem.createAuthEnabledIntent(requireContext())) + shortcutHandler.addPinnedShortcut( + passwordItem, + passwordItem.createAuthEnabledIntent(requireContext()) + ) false } else -> false @@ -244,7 +265,8 @@ class PasswordFragment : Fragment(R.layout.password_recycler_view) { private fun animateFab(show: Boolean) = with(binding.fab) { - val animation = AnimationUtils.loadAnimation(context, if (show) R.anim.scale_up else R.anim.scale_down) + val animation = + AnimationUtils.loadAnimation(context, if (show) R.anim.scale_up else R.anim.scale_down) animation.setAnimationListener( object : Animation.AnimationListener { override fun onAnimationRepeat(animation: Animation?) {} @@ -258,7 +280,11 @@ class PasswordFragment : Fragment(R.layout.password_recycler_view) { } } ) - animate().rotationBy(if (show) -90f else 90f).setStartDelay(if (show) 100 else 0).setDuration(100).start() + animate() + .rotationBy(if (show) -90f else 90f) + .setStartDelay(if (show) 100 else 0) + .setDuration(100) + .start() startAnimation(animation) } } @@ -269,10 +295,15 @@ class PasswordFragment : Fragment(R.layout.password_recycler_view) { listener = object : OnFragmentInteractionListener { override fun onFragmentInteraction(item: PasswordItem) { - if (settings.getString(PreferenceKeys.SORT_ORDER) == PasswordSortOrder.RECENTLY_USED.name) { + if (settings.getString(PreferenceKeys.SORT_ORDER) == + PasswordSortOrder.RECENTLY_USED.name + ) { // save the time when password was used - val preferences = context.getSharedPreferences("recent_password_history", Context.MODE_PRIVATE) - preferences.edit { putString(item.file.absolutePath.base64(), System.currentTimeMillis().toString()) } + val preferences = + context.getSharedPreferences("recent_password_history", Context.MODE_PRIVATE) + preferences.edit { + putString(item.file.absolutePath.base64(), System.currentTimeMillis().toString()) + } } if (item.type == PasswordItem.TYPE_CATEGORY) { @@ -287,7 +318,9 @@ class PasswordFragment : Fragment(R.layout.password_recycler_view) { } } } - .onFailure { throw ClassCastException("$context must implement OnFragmentInteractionListener") } + .onFailure { + throw ClassCastException("$context must implement OnFragmentInteractionListener") + } } private fun requireStore() = requireActivity() as PasswordStore @@ -322,7 +355,10 @@ class PasswordFragment : Fragment(R.layout.password_recycler_view) { fun navigateTo(file: File) { requireStore().clearSearch() - model.navigateTo(file, recyclerViewState = binding.passRecycler.layoutManager!!.onSaveInstanceState()) + model.navigateTo( + file, + recyclerViewState = binding.passRecycler.layoutManager!!.onSaveInstanceState() + ) requireStore().supportActionBar?.setDisplayHomeAsUpEnabled(true) } diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordStore.kt b/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordStore.kt index 8ab69552..b2591a92 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordStore.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordStore.kt @@ -82,7 +82,9 @@ class PasswordStore : BaseGitActivity() { } private val storagePermissionRequest = - registerForActivityResult(RequestPermission()) { granted -> if (granted) checkLocalRepository() } + registerForActivityResult(RequestPermission()) { granted -> + if (granted) checkLocalRepository() + } private val directorySelectAction = registerForActivityResult(StartActivityForResult()) { result -> @@ -128,7 +130,13 @@ class PasswordStore : BaseGitActivity() { withContext(Dispatchers.Main) { MaterialAlertDialogBuilder(this@PasswordStore) .setTitle(resources.getString(R.string.password_exists_title)) - .setMessage(resources.getString(R.string.password_exists_message, destinationLongName, sourceLongName)) + .setMessage( + resources.getString( + R.string.password_exists_message, + destinationLongName, + sourceLongName + ) + ) .setPositiveButton(R.string.dialog_ok) { _, _ -> launch(Dispatchers.IO) { moveFile(source, destinationFile) } } @@ -143,11 +151,16 @@ class PasswordStore : BaseGitActivity() { 1 -> { val source = File(filesToMove[0]) val basename = source.nameWithoutExtension - val sourceLongName = getLongName(requireNotNull(source.parent), repositoryPath, basename) + val sourceLongName = + getLongName(requireNotNull(source.parent), repositoryPath, basename) val destinationLongName = getLongName(target.absolutePath, repositoryPath, basename) withContext(Dispatchers.Main) { commitChange( - resources.getString(R.string.git_commit_move_text, sourceLongName, destinationLongName), + resources.getString( + R.string.git_commit_move_text, + sourceLongName, + destinationLongName + ), ) } } @@ -168,8 +181,8 @@ class PasswordStore : BaseGitActivity() { override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean { // open search view on search key, or Ctr+F - if ((keyCode == KeyEvent.KEYCODE_SEARCH || keyCode == KeyEvent.KEYCODE_F && event.isCtrlPressed) && - !searchItem.isActionViewExpanded + if ((keyCode == KeyEvent.KEYCODE_SEARCH || + keyCode == KeyEvent.KEYCODE_F && event.isCtrlPressed) && !searchItem.isActionViewExpanded ) { searchItem.expandActionView() return true @@ -202,7 +215,9 @@ class PasswordStore : BaseGitActivity() { model.currentDir.observe(this) { dir -> val basePath = PasswordRepository.getRepositoryDirectory().absoluteFile - supportActionBar!!.apply { if (dir != basePath) title = dir.name else setTitle(R.string.app_name) } + supportActionBar!!.apply { + if (dir != basePath) title = dir.name else setTitle(R.string.app_name) + } } } @@ -253,7 +268,8 @@ class PasswordStore : BaseGitActivity() { val filter = s.trim() // List the contents of the current directory if the user enters a blank // search term. - if (filter.isEmpty()) model.navigateTo(newDirectory = model.currentDir.value!!, pushPreviousLocation = false) + if (filter.isEmpty()) + model.navigateTo(newDirectory = model.currentDir.value!!, pushPreviousLocation = false) else model.search(filter) return true } @@ -288,7 +304,9 @@ class PasswordStore : BaseGitActivity() { .setPositiveButton(resources.getString(R.string.dialog_ok), null) when (id) { R.id.user_pref -> { - runCatching { startActivity(Intent(this, SettingsActivity::class.java)) }.onFailure { e -> e.printStackTrace() } + runCatching { startActivity(Intent(this, SettingsActivity::class.java)) }.onFailure { e -> + e.printStackTrace() + } } R.id.git_push -> { if (!PasswordRepository.isInitialized) { @@ -372,7 +390,8 @@ class PasswordStore : BaseGitActivity() { if (localDir != null && settings.getBoolean(PreferenceKeys.REPOSITORY_INITIALIZED, false)) { d { "Check, dir: ${localDir.absolutePath}" } // do not push the fragment if we already have it - if (getPasswordFragment() == null || settings.getBoolean(PreferenceKeys.REPO_CHANGED, false)) { + if (getPasswordFragment() == null || settings.getBoolean(PreferenceKeys.REPO_CHANGED, false) + ) { settings.edit { putBoolean(PreferenceKeys.REPO_CHANGED, false) } val args = Bundle() args.putString(REQUEST_ARG_PATH, PasswordRepository.getRepositoryDirectory().absolutePath) @@ -403,7 +422,9 @@ class PasswordStore : BaseGitActivity() { fun decryptPassword(item: PasswordItem) { val authDecryptIntent = item.createAuthEnabledIntent(this) val decryptIntent = - (authDecryptIntent.clone() as Intent).setComponent(ComponentName(this, DecryptActivity::class.java)) + (authDecryptIntent.clone() as Intent).setComponent( + ComponentName(this, DecryptActivity::class.java) + ) startActivity(decryptIntent) @@ -439,7 +460,9 @@ class PasswordStore : BaseGitActivity() { fun deletePasswords(selectedItems: List<PasswordItem>) { var size = 0 - selectedItems.forEach { if (it.file.isFile) size++ else size += it.file.listFilesRecursively().size } + selectedItems.forEach { + if (it.file.isFile) size++ else size += it.file.listFilesRecursively().size + } if (size == 0) { selectedItems.map { item -> item.file.deleteRecursively() } refreshPasswordList() @@ -497,7 +520,10 @@ class PasswordStore : BaseGitActivity() { * @see [CategoryRenameError] * @see [isInsideRepository] */ - private fun renameCategory(oldCategory: PasswordItem, error: CategoryRenameError = CategoryRenameError.None) { + private fun renameCategory( + oldCategory: PasswordItem, + error: CategoryRenameError = CategoryRenameError.None + ) { val view = layoutInflater.inflate(R.layout.folder_dialog_fragment, null) val newCategoryEditText = view.findViewById<TextInputEditText>(R.id.folder_name_text) @@ -513,16 +539,19 @@ class PasswordStore : BaseGitActivity() { .setPositiveButton(R.string.dialog_ok) { _, _ -> val newCategory = File("${oldCategory.file.parent}/${newCategoryEditText.text}") when { - newCategoryEditText.text.isNullOrBlank() -> renameCategory(oldCategory, CategoryRenameError.EmptyField) + newCategoryEditText.text.isNullOrBlank() -> + renameCategory(oldCategory, CategoryRenameError.EmptyField) newCategory.exists() -> renameCategory(oldCategory, CategoryRenameError.CategoryExists) - !newCategory.isInsideRepository() -> renameCategory(oldCategory, CategoryRenameError.DestinationOutsideRepo) + !newCategory.isInsideRepository() -> + renameCategory(oldCategory, CategoryRenameError.DestinationOutsideRepo) else -> lifecycleScope.launch(Dispatchers.IO) { moveFile(oldCategory.file, newCategory) // associate the new category with the last category's timestamp in // history - val preference = getSharedPreferences("recent_password_history", Context.MODE_PRIVATE) + val preference = + getSharedPreferences("recent_password_history", Context.MODE_PRIVATE) val timestamp = preference.getString(oldCategory.file.absolutePath.base64()) if (timestamp != null) { preference.edit { @@ -533,7 +562,11 @@ class PasswordStore : BaseGitActivity() { withContext(Dispatchers.Main) { commitChange( - resources.getString(R.string.git_commit_move_text, oldCategory.name, newCategory.name), + resources.getString( + R.string.git_commit_move_text, + oldCategory.name, + newCategory.name + ), ) } } @@ -584,7 +617,9 @@ class PasswordStore : BaseGitActivity() { // Recursively list all files (not directories) below `source`, then // obtain the corresponding target file by resolving the relative path // starting at the destination folder. - source.listFilesRecursively().associateWith { destinationFile.resolve(it.relativeTo(source)) } + source.listFilesRecursively().associateWith { + destinationFile.resolve(it.relativeTo(source)) + } } else { mapOf(source to destinationFile) } |
