Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

treewide: Cleanup relevant build warnings #433

Merged
merged 1 commit into from
Oct 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Expand Down
37 changes: 18 additions & 19 deletions app/src/main/java/com/zeapo/pwdstore/UserPreference.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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("*/*")
Expand All @@ -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)
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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")
Expand All @@ -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()
}
}
Expand All @@ -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)
Expand Down Expand Up @@ -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
}
}
91 changes: 45 additions & 46 deletions app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,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)
Expand Down Expand Up @@ -148,7 +148,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() }
}

/**
Expand Down Expand Up @@ -192,7 +192,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

Expand Down Expand Up @@ -292,26 +292,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()
Expand Down Expand Up @@ -377,34 +377,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)
}

})
}
}


Expand All @@ -414,7 +413,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)
Expand Down Expand Up @@ -481,7 +480,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 {
Expand All @@ -502,7 +501,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?) {}
Expand Down Expand Up @@ -718,11 +717,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

Expand Down
26 changes: 14 additions & 12 deletions app/src/main/java/com/zeapo/pwdstore/pwgenDialogFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
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;
Expand All @@ -18,6 +18,7 @@
import android.widget.TextView;

import com.zeapo.pwdstore.pwgen.pwgen;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;

Expand All @@ -31,6 +32,7 @@ public pwgenDialogFragment() {
}


@NotNull
@SuppressLint("SetTextI18n")
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Expand All @@ -45,31 +47,31 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
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);

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());
}
});
Expand All @@ -88,15 +90,15 @@ public void onClick(DialogInterface dialog, int which) {
@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);
b.setOnClickListener(new View.OnClickListener() {
@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));
}
});
Expand All @@ -122,7 +124,7 @@ private void setPreferences () {
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);
Expand Down