treewide: Cleanup relevant build warnings (#433)

Signed-off-by: Harsh Shandilya <harsh@prjkt.io>
This commit is contained in:
Harsh Shandilya
2018-10-12 13:39:06 +05:30
committed by Mohamed Zenadi
parent 8e9c2363bb
commit b8c5dd85a6
4 changed files with 76 additions and 76 deletions

View File

@@ -1,8 +1,8 @@
package com.zeapo.pwdstore package com.zeapo.pwdstore
import android.app.Activity import android.app.Activity
import android.app.FragmentManager
import android.os.Bundle import android.os.Bundle
import android.support.v4.app.FragmentManager
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem

View File

@@ -37,6 +37,7 @@ import java.io.File
import java.io.IOException import java.io.IOException
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.*
import kotlin.collections.HashSet
class UserPreference : AppCompatActivity() { class UserPreference : AppCompatActivity() {
private lateinit var prefsFragment: PrefsFragment private lateinit var prefsFragment: PrefsFragment
@@ -253,7 +254,7 @@ class UserPreference : AppCompatActivity() {
/** /**
* Opens a file explorer to import the private key * Opens a file explorer to import the private key
*/ */
fun getSshKey(useDefaultPicker: Boolean) { private fun getSshKey(useDefaultPicker: Boolean) {
val intent = if (useDefaultPicker) { val intent = if (useDefaultPicker) {
val intent = Intent(Intent.ACTION_GET_CONTENT) val intent = Intent(Intent.ACTION_GET_CONTENT)
intent.setType("*/*") 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 reason The text to be shown to the user to explain why we're requesting this permission
* @param body The function to run * @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 (ContextCompat.checkSelfPermission(this, requestedPermission) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this, requestedPermission)) { if (ActivityCompat.shouldShowRequestPermissionRationale(this, requestedPermission)) {
val snack = Snackbar.make(prefsFragment.view, val snack = Snackbar.make(prefsFragment.view!!, reason, Snackbar.LENGTH_INDEFINITE)
reason,
Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.dialog_ok) { .setAction(R.string.dialog_ok) {
ActivityCompat.requestPermissions(this, arrayOf(requestedPermission), requestCode) ActivityCompat.requestPermissions(this, arrayOf(requestedPermission), requestCode)
} }
@@ -317,7 +316,7 @@ class UserPreference : AppCompatActivity() {
/** /**
* Exports the passwords * Exports the passwords
*/ */
private fun exportPasswords(): Unit { private fun exportPasswords() {
val i = Intent(applicationContext, FilePickerActivity::class.java) val i = Intent(applicationContext, FilePickerActivity::class.java)
// Set these depending on your use case. These are the defaults. // Set these depending on your use case. These are the defaults.
@@ -403,7 +402,7 @@ class UserPreference : AppCompatActivity() {
SELECT_GIT_DIRECTORY -> { SELECT_GIT_DIRECTORY -> {
val uri = data.data 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... // the user wants to use the root of the sdcard as a store...
AlertDialog.Builder(this) AlertDialog.Builder(this)
.setTitle("SD-Card root selected") .setTitle("SD-Card root selected")
@@ -413,13 +412,13 @@ class UserPreference : AppCompatActivity() {
.setPositiveButton("Remove everything") { _, _ -> .setPositiveButton("Remove everything") { _, _ ->
PreferenceManager.getDefaultSharedPreferences(applicationContext) PreferenceManager.getDefaultSharedPreferences(applicationContext)
.edit() .edit()
.putString("git_external_repo", uri.path) .putString("git_external_repo", uri?.path)
.apply() .apply()
}.setNegativeButton(R.string.dialog_cancel, null).show() }.setNegativeButton(R.string.dialog_cancel, null).show()
} else { } else {
PreferenceManager.getDefaultSharedPreferences(applicationContext) PreferenceManager.getDefaultSharedPreferences(applicationContext)
.edit() .edit()
.putString("git_external_repo", uri.path) .putString("git_external_repo", uri?.path)
.apply() .apply()
} }
} }
@@ -428,8 +427,8 @@ class UserPreference : AppCompatActivity() {
val repositoryDirectory = PasswordRepository.getRepositoryDirectory(applicationContext) val repositoryDirectory = PasswordRepository.getRepositoryDirectory(applicationContext)
val fmtOut = SimpleDateFormat("yyyy_MM_dd_HH_mm_ss", Locale.US) val fmtOut = SimpleDateFormat("yyyy_MM_dd_HH_mm_ss", Locale.US)
val date = Date() val date = Date()
val password_now = "/password_store_" + fmtOut.format(date) val passwordNow = "/password_store_" + fmtOut.format(date)
val targetDirectory = File(uri.path + password_now) val targetDirectory = File(uri?.path + passwordNow)
if (repositoryDirectory != null) { if (repositoryDirectory != null) {
try { try {
FileUtils.copyDirectory(repositoryDirectory, targetDirectory, true) FileUtils.copyDirectory(repositoryDirectory, targetDirectory, true)
@@ -463,13 +462,13 @@ class UserPreference : AppCompatActivity() {
} }
companion object { companion object {
private val IMPORT_SSH_KEY = 1 private const val IMPORT_SSH_KEY = 1
private val IMPORT_PGP_KEY = 2 private const val IMPORT_PGP_KEY = 2
private val EDIT_GIT_INFO = 3 private const val EDIT_GIT_INFO = 3
private val SELECT_GIT_DIRECTORY = 4 private const val SELECT_GIT_DIRECTORY = 4
private val EXPORT_PASSWORDS = 5 private const val EXPORT_PASSWORDS = 5
private val EDIT_GIT_CONFIG = 6 private const val EDIT_GIT_CONFIG = 6
private val REQUEST_EXTERNAL_STORAGE_SSH_KEY = 50 private const val REQUEST_EXTERNAL_STORAGE_SSH_KEY = 50
private val REQUEST_EXTERNAL_STORAGE_EXPORT_PWD = 51 private const val REQUEST_EXTERNAL_STORAGE_EXPORT_PWD = 51
} }
} }

View File

@@ -93,7 +93,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
setContentView(R.layout.encrypt_layout) setContentView(R.layout.encrypt_layout)
generate_password?.setOnClickListener { generate_password?.setOnClickListener {
pwgenDialogFragment().show(fragmentManager, "generator") pwgenDialogFragment().show(supportFragmentManager, "generator")
} }
title = getString(R.string.new_password_title) title = getString(R.string.new_password_title)
@@ -149,7 +149,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
* Shows a simple toast message * Shows a simple toast message
*/ */
private fun showToast(message: String) { 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) api = api ?: OpenPgpApi(this, mServiceConnection?.service)
} }
private fun decryptAndVerify(receivedIntent: Intent? = null): Unit { private fun decryptAndVerify(receivedIntent: Intent? = null) {
val data = receivedIntent ?: Intent() val data = receivedIntent ?: Intent()
data.action = ACTION_DECRYPT_VERIFY data.action = ACTION_DECRYPT_VERIFY
@@ -293,26 +293,26 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
dialogBuilder.setView(checkLayout) dialogBuilder.setView(checkLayout)
dialogBuilder.setMessage(R.string.dialog_update_body) dialogBuilder.setMessage(R.string.dialog_update_body)
.setCancelable(false) .setCancelable(false)
.setPositiveButton(R.string.dialog_update_positive, DialogInterface.OnClickListener { dialog, id -> .setPositiveButton(R.string.dialog_update_positive) { _, _ ->
run { run {
calculateAndCommitHotp(entry) calculateAndCommitHotp(entry)
if (rememberCheck.isChecked()) { if (rememberCheck.isChecked) {
val editor = settings.edit() val editor = settings.edit()
editor.putBoolean("hotp_remember_check", true) editor.putBoolean("hotp_remember_check", true)
editor.putBoolean("hotp_remember_choice", true) editor.putBoolean("hotp_remember_choice", true)
editor.commit() editor.commit()
} }
} }
}) }
.setNegativeButton(R.string.dialog_update_negative, DialogInterface.OnClickListener { dialog, id -> .setNegativeButton(R.string.dialog_update_negative) { _, _ ->
run { run {
calculateHotp(entry) calculateHotp(entry)
val editor = settings.edit() val editor = settings.edit()
editor.putBoolean("hotp_remember_check", true) editor.putBoolean("hotp_remember_check", true)
editor.putBoolean("hotp_remember_choice", false) editor.putBoolean("hotp_remember_choice", false)
editor.commit() editor.commit()
} }
}) }
val updateDialog = dialogBuilder.create() val updateDialog = dialogBuilder.create()
updateDialog.setTitle(R.string.dialog_update_title) updateDialog.setTitle(R.string.dialog_update_title)
updateDialog.show() updateDialog.show()
@@ -378,34 +378,33 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
val path = if (intent.getBooleanExtra("fromDecrypt", false)) fullPath else "$fullPath/$editName.gpg" 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)) { api?.executeApiAsync(data, iStream, oStream) { result: Intent? -> when (result?.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
OpenPgpApi.RESULT_CODE_SUCCESS -> { OpenPgpApi.RESULT_CODE_SUCCESS -> {
try { try {
// TODO This might fail, we should check that the write is successful // TODO This might fail, we should check that the write is successful
val outputStream = FileUtils.openOutputStream(File(path)) val outputStream = FileUtils.openOutputStream(File(path))
outputStream.write(oStream.toByteArray()) outputStream.write(oStream.toByteArray())
outputStream.close() outputStream.close()
val returnIntent = Intent() val returnIntent = Intent()
returnIntent.putExtra("CREATED_FILE", path) returnIntent.putExtra("CREATED_FILE", path)
returnIntent.putExtra("NAME", editName) returnIntent.putExtra("NAME", editName)
// if coming from decrypt screen->edit button // if coming from decrypt screen->edit button
if (intent.getBooleanExtra("fromDecrypt", false)) { if (intent.getBooleanExtra("fromDecrypt", false)) {
returnIntent.putExtra("OPERATION", "EDIT") returnIntent.putExtra("OPERATION", "EDIT")
returnIntent.putExtra("needCommit", true) returnIntent.putExtra("needCommit", true)
}
setResult(RESULT_OK, returnIntent)
finish()
} catch (e: Exception) {
Log.e(TAG, "An Exception occurred", e)
} }
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() { private fun editPassword() {
setContentView(R.layout.encrypt_layout) setContentView(R.layout.encrypt_layout)
generate_password?.setOnClickListener { generate_password?.setOnClickListener {
pwgenDialogFragment().show(fragmentManager, "generator") pwgenDialogFragment().show(supportFragmentManager, "generator")
} }
title = getString(R.string.edit_password_title) title = getString(R.string.edit_password_title)
@@ -482,7 +481,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
private fun getKeyIds(receivedIntent: Intent? = null) { private fun getKeyIds(receivedIntent: Intent? = null) {
val data = receivedIntent ?: Intent() val data = receivedIntent ?: Intent()
data.action = OpenPgpApi.ACTION_GET_KEY_IDS 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)) { when (result?.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
OpenPgpApi.RESULT_CODE_SUCCESS -> { OpenPgpApi.RESULT_CODE_SUCCESS -> {
try { try {
@@ -503,7 +502,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
RESULT_CODE_USER_INTERACTION_REQUIRED -> handleUserInteractionRequest(result, REQUEST_KEY_ID) RESULT_CODE_USER_INTERACTION_REQUIRED -> handleUserInteractionRequest(result, REQUEST_KEY_ID)
OpenPgpApi.RESULT_CODE_ERROR -> handleError(result) OpenPgpApi.RESULT_CODE_ERROR -> handleError(result)
} }
}) }
} }
override fun onError(e: Exception?) {} override fun onError(e: Exception?) {}
@@ -737,11 +736,11 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
} }
companion object { companion object {
val OPEN_PGP_BOUND = 101 const val OPEN_PGP_BOUND = 101
val REQUEST_DECRYPT = 202 const val REQUEST_DECRYPT = 202
val REQUEST_KEY_ID = 203 const val REQUEST_KEY_ID = 203
val TAG = "PgpActivity" const val TAG = "PgpActivity"
private var delayTask: DelayShow? = null private var delayTask: DelayShow? = null

View File

@@ -3,12 +3,12 @@ package com.zeapo.pwdstore;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@@ -18,6 +18,7 @@ import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import com.zeapo.pwdstore.pwgen.pwgen; import com.zeapo.pwdstore.pwgen.pwgen;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
@@ -31,6 +32,7 @@ public class pwgenDialogFragment extends DialogFragment {
} }
@NotNull
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
@@ -45,22 +47,22 @@ public class pwgenDialogFragment extends DialogFragment {
SharedPreferences prefs SharedPreferences prefs
= getActivity().getApplicationContext().getSharedPreferences("pwgen", Context.MODE_PRIVATE); = 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.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.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.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.setChecked(!prefs.getBoolean("B", false));
checkBox = (CheckBox) view.findViewById(R.id.pronounceable); checkBox = view.findViewById(R.id.pronounceable);
checkBox.setChecked(!prefs.getBoolean("s", true)); 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.setText(Integer.toString(prefs.getInt("length", 20)));
((TextView) view.findViewById(R.id.passwordText)).setTypeface(monoTypeface); ((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() { builder.setPositiveButton(getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
EditText edit = (EditText) callingActivity.findViewById(R.id.crypto_password_edit); EditText edit = callingActivity.findViewById(R.id.crypto_password_edit);
TextView generate = (TextView) view.findViewById(R.id.passwordText); TextView generate = view.findViewById(R.id.passwordText);
edit.setText(generate.getText()); edit.setText(generate.getText());
} }
}); });
@@ -88,7 +90,7 @@ public class pwgenDialogFragment extends DialogFragment {
@Override @Override
public void onShow(DialogInterface dialog) { public void onShow(DialogInterface dialog) {
setPreferences(); setPreferences();
TextView textView = (TextView) view.findViewById(R.id.passwordText); TextView textView = view.findViewById(R.id.passwordText);
textView.setText(pwgen.generate(getActivity().getApplicationContext()).get(0)); textView.setText(pwgen.generate(getActivity().getApplicationContext()).get(0));
Button b = ad.getButton(AlertDialog.BUTTON_NEUTRAL); Button b = ad.getButton(AlertDialog.BUTTON_NEUTRAL);
@@ -96,7 +98,7 @@ public class pwgenDialogFragment extends DialogFragment {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
setPreferences(); setPreferences();
TextView textView = (TextView) view.findViewById(R.id.passwordText); TextView textView = view.findViewById(R.id.passwordText);
textView.setText(pwgen.generate(callingActivity.getApplicationContext()).get(0)); 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()) { if (!((CheckBox) getDialog().findViewById(R.id.pronounceable)).isChecked()) {
preferences.add("s"); preferences.add("s");
} }
EditText editText = (EditText) getDialog().findViewById(R.id.lengthNumber); EditText editText = getDialog().findViewById(R.id.lengthNumber);
try { try {
int length = Integer.valueOf(editText.getText().toString()); int length = Integer.valueOf(editText.getText().toString());
pwgen.setPrefs(getActivity().getApplicationContext(), preferences, length); pwgen.setPrefs(getActivity().getApplicationContext(), preferences, length);