summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarsh Shandilya <msfjarvis@gmail.com>2018-10-12 13:39:06 +0530
committerMohamed Zenadi <zeapo@users.noreply.github.com>2018-10-12 10:09:06 +0200
commitb8c5dd85a6e32c47bee1bbb531846e6aef0dcb30 (patch)
treef695cdfad9b9eb437e8a7c3302ba3805ad445fc3
parent8e9c2363bb75a7024aa9ac30673a46259fda4c2e (diff)
treewide: Cleanup relevant build warnings (#433)
Signed-off-by: Harsh Shandilya <harsh@prjkt.io>
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/SelectFolderActivity.kt2
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/UserPreference.kt37
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt91
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/pwgenDialogFragment.java26
4 files changed, 78 insertions, 78 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/SelectFolderActivity.kt b/app/src/main/java/com/zeapo/pwdstore/SelectFolderActivity.kt
index 86076d4a..d0347cf0 100644
--- a/app/src/main/java/com/zeapo/pwdstore/SelectFolderActivity.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/SelectFolderActivity.kt
@@ -1,8 +1,8 @@
package com.zeapo.pwdstore
import android.app.Activity
-import android.app.FragmentManager
import android.os.Bundle
+import android.support.v4.app.FragmentManager
import android.support.v7.app.AppCompatActivity
import android.view.Menu
import android.view.MenuItem
diff --git a/app/src/main/java/com/zeapo/pwdstore/UserPreference.kt b/app/src/main/java/com/zeapo/pwdstore/UserPreference.kt
index 94a81b8f..aa26ecb1 100644
--- a/app/src/main/java/com/zeapo/pwdstore/UserPreference.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/UserPreference.kt
@@ -37,6 +37,7 @@ import java.io.File
import java.io.IOException
import java.text.SimpleDateFormat
import java.util.*
+import kotlin.collections.HashSet
class UserPreference : AppCompatActivity() {
private lateinit var prefsFragment: PrefsFragment
@@ -253,7 +254,7 @@ class UserPreference : AppCompatActivity() {
/**
* Opens a file explorer to import the private key
*/
- fun getSshKey(useDefaultPicker: Boolean) {
+ private fun getSshKey(useDefaultPicker: Boolean) {
val intent = if (useDefaultPicker) {
val intent = Intent(Intent.ACTION_GET_CONTENT)
intent.setType("*/*")
@@ -279,12 +280,10 @@ class UserPreference : AppCompatActivity() {
* @param reason The text to be shown to the user to explain why we're requesting this permission
* @param body The function to run
*/
- private fun runWithPermissions(requestedPermission: String, requestCode: Int, reason: String, body: () -> Unit): Unit {
+ private fun runWithPermissions(requestedPermission: String, requestCode: Int, reason: String, body: () -> Unit) {
if (ContextCompat.checkSelfPermission(this, requestedPermission) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this, requestedPermission)) {
- val snack = Snackbar.make(prefsFragment.view,
- reason,
- Snackbar.LENGTH_INDEFINITE)
+ val snack = Snackbar.make(prefsFragment.view!!, reason, Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.dialog_ok) {
ActivityCompat.requestPermissions(this, arrayOf(requestedPermission), requestCode)
}
@@ -317,7 +316,7 @@ class UserPreference : AppCompatActivity() {
/**
* Exports the passwords
*/
- private fun exportPasswords(): Unit {
+ private fun exportPasswords() {
val i = Intent(applicationContext, FilePickerActivity::class.java)
// Set these depending on your use case. These are the defaults.
@@ -403,7 +402,7 @@ class UserPreference : AppCompatActivity() {
SELECT_GIT_DIRECTORY -> {
val uri = data.data
- if (uri.path == Environment.getExternalStorageDirectory().path) {
+ if (uri?.path == Environment.getExternalStorageDirectory().path) {
// the user wants to use the root of the sdcard as a store...
AlertDialog.Builder(this)
.setTitle("SD-Card root selected")
@@ -413,13 +412,13 @@ class UserPreference : AppCompatActivity() {
.setPositiveButton("Remove everything") { _, _ ->
PreferenceManager.getDefaultSharedPreferences(applicationContext)
.edit()
- .putString("git_external_repo", uri.path)
+ .putString("git_external_repo", uri?.path)
.apply()
}.setNegativeButton(R.string.dialog_cancel, null).show()
} else {
PreferenceManager.getDefaultSharedPreferences(applicationContext)
.edit()
- .putString("git_external_repo", uri.path)
+ .putString("git_external_repo", uri?.path)
.apply()
}
}
@@ -428,8 +427,8 @@ class UserPreference : AppCompatActivity() {
val repositoryDirectory = PasswordRepository.getRepositoryDirectory(applicationContext)
val fmtOut = SimpleDateFormat("yyyy_MM_dd_HH_mm_ss", Locale.US)
val date = Date()
- val password_now = "/password_store_" + fmtOut.format(date)
- val targetDirectory = File(uri.path + password_now)
+ val passwordNow = "/password_store_" + fmtOut.format(date)
+ val targetDirectory = File(uri?.path + passwordNow)
if (repositoryDirectory != null) {
try {
FileUtils.copyDirectory(repositoryDirectory, targetDirectory, true)
@@ -463,13 +462,13 @@ class UserPreference : AppCompatActivity() {
}
companion object {
- private val IMPORT_SSH_KEY = 1
- private val IMPORT_PGP_KEY = 2
- private val EDIT_GIT_INFO = 3
- private val SELECT_GIT_DIRECTORY = 4
- private val EXPORT_PASSWORDS = 5
- private val EDIT_GIT_CONFIG = 6
- private val REQUEST_EXTERNAL_STORAGE_SSH_KEY = 50
- private val REQUEST_EXTERNAL_STORAGE_EXPORT_PWD = 51
+ private const val IMPORT_SSH_KEY = 1
+ private const val IMPORT_PGP_KEY = 2
+ private const val EDIT_GIT_INFO = 3
+ private const val SELECT_GIT_DIRECTORY = 4
+ private const val EXPORT_PASSWORDS = 5
+ private const val EDIT_GIT_CONFIG = 6
+ private const val REQUEST_EXTERNAL_STORAGE_SSH_KEY = 50
+ private const val REQUEST_EXTERNAL_STORAGE_EXPORT_PWD = 51
}
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt
index 4300aeba..4afc6e19 100644
--- a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt
@@ -93,7 +93,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
setContentView(R.layout.encrypt_layout)
generate_password?.setOnClickListener {
- pwgenDialogFragment().show(fragmentManager, "generator")
+ pwgenDialogFragment().show(supportFragmentManager, "generator")
}
title = getString(R.string.new_password_title)
@@ -149,7 +149,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
* Shows a simple toast message
*/
private fun showToast(message: String) {
- runOnUiThread({ Toast.makeText(this, message, Toast.LENGTH_SHORT).show() })
+ runOnUiThread { Toast.makeText(this, message, Toast.LENGTH_SHORT).show() }
}
/**
@@ -193,7 +193,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
api = api ?: OpenPgpApi(this, mServiceConnection?.service)
}
- private fun decryptAndVerify(receivedIntent: Intent? = null): Unit {
+ private fun decryptAndVerify(receivedIntent: Intent? = null) {
val data = receivedIntent ?: Intent()
data.action = ACTION_DECRYPT_VERIFY
@@ -293,26 +293,26 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
dialogBuilder.setView(checkLayout)
dialogBuilder.setMessage(R.string.dialog_update_body)
.setCancelable(false)
- .setPositiveButton(R.string.dialog_update_positive, DialogInterface.OnClickListener { dialog, id ->
+ .setPositiveButton(R.string.dialog_update_positive) { _, _ ->
run {
calculateAndCommitHotp(entry)
- if (rememberCheck.isChecked()) {
+ if (rememberCheck.isChecked) {
val editor = settings.edit()
editor.putBoolean("hotp_remember_check", true)
editor.putBoolean("hotp_remember_choice", true)
editor.commit()
}
}
- })
- .setNegativeButton(R.string.dialog_update_negative, DialogInterface.OnClickListener { dialog, id ->
- run {
- calculateHotp(entry)
- val editor = settings.edit()
- editor.putBoolean("hotp_remember_check", true)
- editor.putBoolean("hotp_remember_choice", false)
- editor.commit()
- }
- })
+ }
+ .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.commit()
+ }
+ }
val updateDialog = dialogBuilder.create()
updateDialog.setTitle(R.string.dialog_update_title)
updateDialog.show()
@@ -378,34 +378,33 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
val path = if (intent.getBooleanExtra("fromDecrypt", false)) fullPath else "$fullPath/$editName.gpg"
- api?.executeApiAsync(data, iStream, oStream, { result: Intent? -> when (result?.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
- OpenPgpApi.RESULT_CODE_SUCCESS -> {
- try {
- // TODO This might fail, we should check that the write is successful
- val outputStream = FileUtils.openOutputStream(File(path))
- outputStream.write(oStream.toByteArray())
- outputStream.close()
-
- val returnIntent = Intent()
- returnIntent.putExtra("CREATED_FILE", path)
- returnIntent.putExtra("NAME", editName)
-
- // if coming from decrypt screen->edit button
- if (intent.getBooleanExtra("fromDecrypt", false)) {
- returnIntent.putExtra("OPERATION", "EDIT")
- returnIntent.putExtra("needCommit", true)
- }
- setResult(RESULT_OK, returnIntent)
- finish()
-
- } catch (e: Exception) {
- Log.e(TAG, "An Exception occurred", e)
+ api?.executeApiAsync(data, iStream, oStream) { result: Intent? -> when (result?.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
+ OpenPgpApi.RESULT_CODE_SUCCESS -> {
+ try {
+ // TODO This might fail, we should check that the write is successful
+ val outputStream = FileUtils.openOutputStream(File(path))
+ outputStream.write(oStream.toByteArray())
+ outputStream.close()
+
+ val returnIntent = Intent()
+ returnIntent.putExtra("CREATED_FILE", path)
+ returnIntent.putExtra("NAME", editName)
+
+ // if coming from decrypt screen->edit button
+ if (intent.getBooleanExtra("fromDecrypt", false)) {
+ returnIntent.putExtra("OPERATION", "EDIT")
+ returnIntent.putExtra("needCommit", true)
}
+ setResult(RESULT_OK, returnIntent)
+ finish()
+ } catch (e: Exception) {
+ Log.e(TAG, "An Exception occurred", e)
}
- OpenPgpApi.RESULT_CODE_ERROR -> handleError(result)
}
+ OpenPgpApi.RESULT_CODE_ERROR -> handleError(result)
+ }
- })
+ }
}
@@ -415,7 +414,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
private fun editPassword() {
setContentView(R.layout.encrypt_layout)
generate_password?.setOnClickListener {
- pwgenDialogFragment().show(fragmentManager, "generator")
+ pwgenDialogFragment().show(supportFragmentManager, "generator")
}
title = getString(R.string.edit_password_title)
@@ -482,7 +481,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
private fun getKeyIds(receivedIntent: Intent? = null) {
val data = receivedIntent ?: Intent()
data.action = OpenPgpApi.ACTION_GET_KEY_IDS
- api?.executeApiAsync(data, null, null, { result: Intent? ->
+ api?.executeApiAsync(data, null, null) { result: Intent? ->
when (result?.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
OpenPgpApi.RESULT_CODE_SUCCESS -> {
try {
@@ -503,7 +502,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
RESULT_CODE_USER_INTERACTION_REQUIRED -> handleUserInteractionRequest(result, REQUEST_KEY_ID)
OpenPgpApi.RESULT_CODE_ERROR -> handleError(result)
}
- })
+ }
}
override fun onError(e: Exception?) {}
@@ -737,11 +736,11 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
}
companion object {
- val OPEN_PGP_BOUND = 101
- val REQUEST_DECRYPT = 202
- val REQUEST_KEY_ID = 203
+ const val OPEN_PGP_BOUND = 101
+ const val REQUEST_DECRYPT = 202
+ const val REQUEST_KEY_ID = 203
- val TAG = "PgpActivity"
+ const val TAG = "PgpActivity"
private var delayTask: DelayShow? = null
diff --git a/app/src/main/java/com/zeapo/pwdstore/pwgenDialogFragment.java b/app/src/main/java/com/zeapo/pwdstore/pwgenDialogFragment.java
index 141aaa76..8c4ad4a1 100644
--- a/app/src/main/java/com/zeapo/pwdstore/pwgenDialogFragment.java
+++ b/app/src/main/java/com/zeapo/pwdstore/pwgenDialogFragment.java
@@ -3,12 +3,12 @@ package com.zeapo.pwdstore;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
-import android.app.DialogFragment;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.os.Bundle;
+import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
@@ -18,6 +18,7 @@ import android.widget.EditText;
import android.widget.TextView;
import com.zeapo.pwdstore.pwgen.pwgen;
+import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
@@ -31,6 +32,7 @@ public class pwgenDialogFragment extends DialogFragment {
}
+ @NotNull
@SuppressLint("SetTextI18n")
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
@@ -45,22 +47,22 @@ public class pwgenDialogFragment extends DialogFragment {
SharedPreferences prefs
= getActivity().getApplicationContext().getSharedPreferences("pwgen", Context.MODE_PRIVATE);
- CheckBox checkBox = (CheckBox) view.findViewById(R.id.numerals);
+ CheckBox checkBox = view.findViewById(R.id.numerals);
checkBox.setChecked(!prefs.getBoolean("0", false));
- checkBox = (CheckBox) view.findViewById(R.id.symbols);
+ checkBox = view.findViewById(R.id.symbols);
checkBox.setChecked(prefs.getBoolean("y", false));
- checkBox = (CheckBox) view.findViewById(R.id.uppercase);
+ checkBox = view.findViewById(R.id.uppercase);
checkBox.setChecked(!prefs.getBoolean("A", false));
- checkBox = (CheckBox) view.findViewById(R.id.ambiguous);
+ checkBox = view.findViewById(R.id.ambiguous);
checkBox.setChecked(!prefs.getBoolean("B", false));
- checkBox = (CheckBox) view.findViewById(R.id.pronounceable);
+ checkBox = view.findViewById(R.id.pronounceable);
checkBox.setChecked(!prefs.getBoolean("s", true));
- TextView textView = (TextView) view.findViewById(R.id.lengthNumber);
+ TextView textView = view.findViewById(R.id.lengthNumber);
textView.setText(Integer.toString(prefs.getInt("length", 20)));
((TextView) view.findViewById(R.id.passwordText)).setTypeface(monoTypeface);
@@ -68,8 +70,8 @@ public class pwgenDialogFragment extends DialogFragment {
builder.setPositiveButton(getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
- EditText edit = (EditText) callingActivity.findViewById(R.id.crypto_password_edit);
- TextView generate = (TextView) view.findViewById(R.id.passwordText);
+ EditText edit = callingActivity.findViewById(R.id.crypto_password_edit);
+ TextView generate = view.findViewById(R.id.passwordText);
edit.setText(generate.getText());
}
});
@@ -88,7 +90,7 @@ public class pwgenDialogFragment extends DialogFragment {
@Override
public void onShow(DialogInterface dialog) {
setPreferences();
- TextView textView = (TextView) view.findViewById(R.id.passwordText);
+ TextView textView = view.findViewById(R.id.passwordText);
textView.setText(pwgen.generate(getActivity().getApplicationContext()).get(0));
Button b = ad.getButton(AlertDialog.BUTTON_NEUTRAL);
@@ -96,7 +98,7 @@ public class pwgenDialogFragment extends DialogFragment {
@Override
public void onClick(View v) {
setPreferences();
- TextView textView = (TextView) view.findViewById(R.id.passwordText);
+ TextView textView = view.findViewById(R.id.passwordText);
textView.setText(pwgen.generate(callingActivity.getApplicationContext()).get(0));
}
});
@@ -122,7 +124,7 @@ public class pwgenDialogFragment extends DialogFragment {
if (!((CheckBox) getDialog().findViewById(R.id.pronounceable)).isChecked()) {
preferences.add("s");
}
- EditText editText = (EditText) getDialog().findViewById(R.id.lengthNumber);
+ EditText editText = getDialog().findViewById(R.id.lengthNumber);
try {
int length = Integer.valueOf(editText.getText().toString());
pwgen.setPrefs(getActivity().getApplicationContext(), preferences, length);