Codestyle cleanup

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2020-03-20 14:13:54 +05:30 committed by Aditya Wasan
parent 0aeb51efa4
commit 793abd690d
12 changed files with 68 additions and 61 deletions

View file

@ -148,6 +148,7 @@ class ClipboardService : Service() {
}
}
}
companion object {
private const val ACTION_CLEAR = "ACTION_CLEAR_CLIPBOARD"
private const val ACTION_START = "ACTION_START_CLIPBOARD_TIMER"

View file

@ -115,9 +115,9 @@ class PasswordStore : AppCompatActivity() {
!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.READ_EXTERNAL_STORAGE)) {
val snack = Snackbar.make(
findViewById(R.id.main_layout),
getString(R.string.access_sdcard_text),
Snackbar.LENGTH_INDEFINITE)
findViewById(R.id.main_layout),
getString(R.string.access_sdcard_text),
Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.dialog_ok) {
ActivityCompat.requestPermissions(
activity,
@ -614,9 +614,9 @@ class PasswordStore : AppCompatActivity() {
}
REQUEST_CODE_SELECT_FOLDER -> {
Timber.tag(TAG)
.d("Moving passwords to ${data!!.getStringExtra("SELECTED_FOLDER_PATH")}")
.d("Moving passwords to ${data!!.getStringExtra("SELECTED_FOLDER_PATH")}")
Timber.tag(TAG).d(
TextUtils.join(", ", requireNotNull(data.getStringArrayListExtra("Files")))
TextUtils.join(", ", requireNotNull(data.getStringArrayListExtra("Files")))
)
val target = File(requireNotNull(data.getStringExtra("SELECTED_FOLDER_PATH")))

View file

@ -123,7 +123,8 @@ class UserPreference : AppCompatActivity() {
OpenPgpUtils.convertKeyIdToHex(java.lang.Long.valueOf(s))
}
}
openkeystoreIdPreference?.isVisible = sharedPreferences.getString("ssh_openkeystore_keyid", null)?.isNotEmpty() ?: false
openkeystoreIdPreference?.isVisible = sharedPreferences.getString("ssh_openkeystore_keyid", null)?.isNotEmpty()
?: false
// see if the autofill service is enabled and check the preference accordingly
autoFillEnablePreference?.isChecked = callingActivity.isServiceEnabled
@ -332,12 +333,12 @@ class UserPreference : AppCompatActivity() {
val prefPwgenType = findPreference<ListPreference>("pref_key_pwgen_type")
showHideDependentPrefs(prefPwgenType?.value, prefIsCustomDict, prefCustomDictPicker)
prefPwgenType?.onPreferenceChangeListener = ChangeListener() { _, newValue ->
prefPwgenType?.onPreferenceChangeListener = ChangeListener { _, newValue ->
showHideDependentPrefs(newValue, prefIsCustomDict, prefCustomDictPicker)
true
}
prefIsCustomDict?.onPreferenceChangeListener = ChangeListener() { _, newValue ->
prefIsCustomDict?.onPreferenceChangeListener = ChangeListener { _, newValue ->
if (!(newValue as Boolean)) {
val customDictFile = File(context.filesDir, XkpwdDictionary.XKPWD_CUSTOM_DICT_FILE)
if (customDictFile.exists()) {
@ -688,7 +689,7 @@ class UserPreference : AppCompatActivity() {
@JvmStatic
private fun setCustomDictSummary(customDictPref: Preference?, uri: Uri) {
val fileName = uri.path?.substring(uri.path?.lastIndexOf(":")!! + 1)
customDictPref?.setSummary("Selected dictionary: " + fileName)
customDictPref?.summary = "Selected dictionary: " + fileName
}
}
}

View file

@ -313,8 +313,8 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
null
} else {
HoldToShowPasswordTransformation(
crypto_password_toggle_show,
Runnable { crypto_password_show.text = entry.password }
crypto_password_toggle_show,
Runnable { crypto_password_show.text = entry.password }
)
}
@ -367,19 +367,19 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
if (entry.hasTotp()) {
crypto_copy_otp.setOnClickListener {
copyOtpToClipBoard(
Otp.calculateCode(
entry.totpSecret,
Date().time / (1000 * entry.totpPeriod),
entry.totpAlgorithm,
entry.digits)
Otp.calculateCode(
entry.totpSecret,
Date().time / (1000 * entry.totpPeriod),
entry.totpAlgorithm,
entry.digits)
)
}
crypto_otp_show.text =
Otp.calculateCode(
entry.totpSecret,
Date().time / (1000 * entry.totpPeriod),
entry.totpAlgorithm,
entry.digits)
Otp.calculateCode(
entry.totpSecret,
Date().time / (1000 * entry.totpPeriod),
entry.totpAlgorithm,
entry.digits)
} else {
// we only want to calculate and show HOTP if the user requests it
crypto_copy_otp.setOnClickListener {
@ -394,31 +394,31 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
val checkInflater = LayoutInflater.from(this@PgpActivity)
val checkLayout = checkInflater.inflate(R.layout.otp_confirm_layout, null)
val rememberCheck: CheckBox =
checkLayout.findViewById(R.id.hotp_remember_checkbox)
checkLayout.findViewById(R.id.hotp_remember_checkbox)
val dialogBuilder = MaterialAlertDialogBuilder(this@PgpActivity)
dialogBuilder.setView(checkLayout)
dialogBuilder.setMessage(R.string.dialog_update_body)
.setCancelable(false)
.setPositiveButton(R.string.dialog_update_positive) { _, _ ->
run {
calculateAndCommitHotp(entry)
if (rememberCheck.isChecked) {
.setCancelable(false)
.setPositiveButton(R.string.dialog_update_positive) { _, _ ->
run {
calculateAndCommitHotp(entry)
if (rememberCheck.isChecked) {
val editor = settings.edit()
editor.putBoolean("hotp_remember_check", true)
editor.putBoolean("hotp_remember_choice", true)
editor.apply()
}
}
}
.setNegativeButton(R.string.dialog_update_negative) { _, _ ->
run {
calculateHotp(entry)
val editor = settings.edit()
editor.putBoolean("hotp_remember_check", true)
editor.putBoolean("hotp_remember_choice", true)
editor.putBoolean("hotp_remember_choice", false)
editor.apply()
}
}
}
.setNegativeButton(R.string.dialog_update_negative) { _, _ ->
run {
calculateHotp(entry)
val editor = settings.edit()
editor.putBoolean("hotp_remember_check", true)
editor.putBoolean("hotp_remember_choice", false)
editor.apply()
}
}
val updateDialog = dialogBuilder.create()
updateDialog.setTitle(R.string.dialog_update_title)
updateDialog.show()
@ -606,7 +606,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
RESULT_CODE_SUCCESS -> {
try {
val ids = result.getLongArrayExtra(OpenPgpApi.RESULT_KEY_IDS)
?: LongArray(0)
?: LongArray(0)
val keys = ids.map { it.toString() }.toSet()
// use Long

View file

@ -658,6 +658,7 @@ open class GitActivity : AppCompatActivity() {
const val REQUEST_INIT = 104
const val EDIT_SERVER = 105
const val REQUEST_SYNC = 106
@Suppress("Unused")
const val REQUEST_CREATE = 107
const val EDIT_GIT_CONFIG = 108

View file

@ -34,7 +34,7 @@ class XkpwdDictionary(context: Context) {
}
if (lines.isEmpty()) {
lines = context.getResources().openRawResource(R.raw.xkpwdict).bufferedReader().readLines()
lines = context.resources.openRawResource(R.raw.xkpwdict).bufferedReader().readLines()
}
for (word in lines) {

View file

@ -43,7 +43,7 @@ class ShowSshKeyFragment : DialogFragment() {
b.setOnClickListener {
val clipboard = activity.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip = ClipData.newPlainText("public key", publicKey.text.toString())
clipboard.setPrimaryClip(clip)
clipboard.primaryClip = clip
}
}
return ad

View file

@ -87,7 +87,8 @@ abstract class EntryRecyclerAdapter internal constructor(val values: ArrayList<P
// Replace the contents of a view (invoked by the layout manager)
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
settings = settings ?: PreferenceManager.getDefaultSharedPreferences(holder.view.context.applicationContext)
settings = settings
?: PreferenceManager.getDefaultSharedPreferences(holder.view.context.applicationContext)
val pass = values[position]
val showHidden = settings?.getBoolean("show_hidden_folders", false) ?: false
holder.name.text = pass.toString()

View file

@ -31,7 +31,7 @@ class PasswordGeneratorDialogFragment : DialogFragment() {
val monoTypeface = Typeface.createFromAsset(callingActivity.assets, "fonts/sourcecodepro.ttf")
builder.setView(view)
val prefs = requireActivity().applicationContext
.getSharedPreferences("PasswordGenerator", Context.MODE_PRIVATE)
.getSharedPreferences("PasswordGenerator", Context.MODE_PRIVATE)
view.findViewById<CheckBox>(R.id.numerals)?.isChecked = !prefs.getBoolean("0", false)
view.findViewById<CheckBox>(R.id.symbols)?.isChecked = prefs.getBoolean("y", false)

View file

@ -79,7 +79,7 @@ open class PasswordRepository protected constructor() {
fun isGitRepo(): Boolean {
if (repository != null) {
// Check if remote exists
return repository!!.config.getSubsections("remote").isNotEmpty() ?: false
return repository!!.config.getSubsections("remote").isNotEmpty()
}
return false
}

View file

@ -9,10 +9,13 @@ import androidx.biometric.BiometricPrompt
internal sealed class AuthenticationResult {
internal data class Success(val cryptoObject: BiometricPrompt.CryptoObject?) :
AuthenticationResult()
internal data class RecoverableError(val code: Int, val message: CharSequence) :
AuthenticationResult()
internal data class UnrecoverableError(val code: Int, val message: CharSequence) :
AuthenticationResult()
internal object Failure : AuthenticationResult()
internal object Cancelled : AuthenticationResult()
}

View file

@ -63,16 +63,16 @@ class EmitExpandableTransformationBehavior @JvmOverloads constructor(
val set = AnimatorSet()
set.playTogether(animations)
set.addListener(
onStart = {
if (expanded) {
child.isVisible = true
onStart = {
if (expanded) {
child.isVisible = true
}
},
onEnd = {
if (!expanded) {
child.isInvisible = true
}
}
},
onEnd = {
if (!expanded) {
child.isInvisible = true
}
}
)
return set
}
@ -97,10 +97,10 @@ class EmitExpandableTransformationBehavior @JvmOverloads constructor(
val alphaHolder = PropertyValuesHolder.ofFloat(View.ALPHA, 1f)
val animators = child.children.zip(delays) { view, delay ->
ObjectAnimator.ofPropertyValuesHolder(
view,
scaleXHolder,
scaleYHolder,
alphaHolder
view,
scaleXHolder,
scaleYHolder,
alphaHolder
).apply {
duration = EXPAND_DURATION
startDelay = delay
@ -124,10 +124,10 @@ class EmitExpandableTransformationBehavior @JvmOverloads constructor(
val alphaHolder = PropertyValuesHolder.ofFloat(View.ALPHA, 0f)
val animators = child.children.zip(delays) { view, delay ->
ObjectAnimator.ofPropertyValuesHolder(
view,
scaleXHolder,
scaleYHolder,
alphaHolder
view,
scaleXHolder,
scaleYHolder,
alphaHolder
).apply {
duration = COLLAPSE_DURATION
startDelay = delay