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

Commit b8c5dd8

Browse files
msfjarviszeapo
authored andcommitted
treewide: Cleanup relevant build warnings (#433)
Signed-off-by: Harsh Shandilya <harsh@prjkt.io>
1 parent 8e9c236 commit b8c5dd8

File tree

4 files changed

+78
-78
lines changed

4 files changed

+78
-78
lines changed

app/src/main/java/com/zeapo/pwdstore/SelectFolderActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.zeapo.pwdstore
22

33
import android.app.Activity
4-
import android.app.FragmentManager
54
import android.os.Bundle
5+
import android.support.v4.app.FragmentManager
66
import android.support.v7.app.AppCompatActivity
77
import android.view.Menu
88
import android.view.MenuItem

app/src/main/java/com/zeapo/pwdstore/UserPreference.kt

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import java.io.File
3737
import java.io.IOException
3838
import java.text.SimpleDateFormat
3939
import java.util.*
40+
import kotlin.collections.HashSet
4041

4142
class UserPreference : AppCompatActivity() {
4243
private lateinit var prefsFragment: PrefsFragment
@@ -253,7 +254,7 @@ class UserPreference : AppCompatActivity() {
253254
/**
254255
* Opens a file explorer to import the private key
255256
*/
256-
fun getSshKey(useDefaultPicker: Boolean) {
257+
private fun getSshKey(useDefaultPicker: Boolean) {
257258
val intent = if (useDefaultPicker) {
258259
val intent = Intent(Intent.ACTION_GET_CONTENT)
259260
intent.setType("*/*")
@@ -279,12 +280,10 @@ class UserPreference : AppCompatActivity() {
279280
* @param reason The text to be shown to the user to explain why we're requesting this permission
280281
* @param body The function to run
281282
*/
282-
private fun runWithPermissions(requestedPermission: String, requestCode: Int, reason: String, body: () -> Unit): Unit {
283+
private fun runWithPermissions(requestedPermission: String, requestCode: Int, reason: String, body: () -> Unit) {
283284
if (ContextCompat.checkSelfPermission(this, requestedPermission) != PackageManager.PERMISSION_GRANTED) {
284285
if (ActivityCompat.shouldShowRequestPermissionRationale(this, requestedPermission)) {
285-
val snack = Snackbar.make(prefsFragment.view,
286-
reason,
287-
Snackbar.LENGTH_INDEFINITE)
286+
val snack = Snackbar.make(prefsFragment.view!!, reason, Snackbar.LENGTH_INDEFINITE)
288287
.setAction(R.string.dialog_ok) {
289288
ActivityCompat.requestPermissions(this, arrayOf(requestedPermission), requestCode)
290289
}
@@ -317,7 +316,7 @@ class UserPreference : AppCompatActivity() {
317316
/**
318317
* Exports the passwords
319318
*/
320-
private fun exportPasswords(): Unit {
319+
private fun exportPasswords() {
321320
val i = Intent(applicationContext, FilePickerActivity::class.java)
322321

323322
// Set these depending on your use case. These are the defaults.
@@ -403,7 +402,7 @@ class UserPreference : AppCompatActivity() {
403402
SELECT_GIT_DIRECTORY -> {
404403
val uri = data.data
405404

406-
if (uri.path == Environment.getExternalStorageDirectory().path) {
405+
if (uri?.path == Environment.getExternalStorageDirectory().path) {
407406
// the user wants to use the root of the sdcard as a store...
408407
AlertDialog.Builder(this)
409408
.setTitle("SD-Card root selected")
@@ -413,13 +412,13 @@ class UserPreference : AppCompatActivity() {
413412
.setPositiveButton("Remove everything") { _, _ ->
414413
PreferenceManager.getDefaultSharedPreferences(applicationContext)
415414
.edit()
416-
.putString("git_external_repo", uri.path)
415+
.putString("git_external_repo", uri?.path)
417416
.apply()
418417
}.setNegativeButton(R.string.dialog_cancel, null).show()
419418
} else {
420419
PreferenceManager.getDefaultSharedPreferences(applicationContext)
421420
.edit()
422-
.putString("git_external_repo", uri.path)
421+
.putString("git_external_repo", uri?.path)
423422
.apply()
424423
}
425424
}
@@ -428,8 +427,8 @@ class UserPreference : AppCompatActivity() {
428427
val repositoryDirectory = PasswordRepository.getRepositoryDirectory(applicationContext)
429428
val fmtOut = SimpleDateFormat("yyyy_MM_dd_HH_mm_ss", Locale.US)
430429
val date = Date()
431-
val password_now = "/password_store_" + fmtOut.format(date)
432-
val targetDirectory = File(uri.path + password_now)
430+
val passwordNow = "/password_store_" + fmtOut.format(date)
431+
val targetDirectory = File(uri?.path + passwordNow)
433432
if (repositoryDirectory != null) {
434433
try {
435434
FileUtils.copyDirectory(repositoryDirectory, targetDirectory, true)
@@ -463,13 +462,13 @@ class UserPreference : AppCompatActivity() {
463462
}
464463

465464
companion object {
466-
private val IMPORT_SSH_KEY = 1
467-
private val IMPORT_PGP_KEY = 2
468-
private val EDIT_GIT_INFO = 3
469-
private val SELECT_GIT_DIRECTORY = 4
470-
private val EXPORT_PASSWORDS = 5
471-
private val EDIT_GIT_CONFIG = 6
472-
private val REQUEST_EXTERNAL_STORAGE_SSH_KEY = 50
473-
private val REQUEST_EXTERNAL_STORAGE_EXPORT_PWD = 51
465+
private const val IMPORT_SSH_KEY = 1
466+
private const val IMPORT_PGP_KEY = 2
467+
private const val EDIT_GIT_INFO = 3
468+
private const val SELECT_GIT_DIRECTORY = 4
469+
private const val EXPORT_PASSWORDS = 5
470+
private const val EDIT_GIT_CONFIG = 6
471+
private const val REQUEST_EXTERNAL_STORAGE_SSH_KEY = 50
472+
private const val REQUEST_EXTERNAL_STORAGE_EXPORT_PWD = 51
474473
}
475474
}

app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
9393
setContentView(R.layout.encrypt_layout)
9494

9595
generate_password?.setOnClickListener {
96-
pwgenDialogFragment().show(fragmentManager, "generator")
96+
pwgenDialogFragment().show(supportFragmentManager, "generator")
9797
}
9898

9999
title = getString(R.string.new_password_title)
@@ -149,7 +149,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
149149
* Shows a simple toast message
150150
*/
151151
private fun showToast(message: String) {
152-
runOnUiThread({ Toast.makeText(this, message, Toast.LENGTH_SHORT).show() })
152+
runOnUiThread { Toast.makeText(this, message, Toast.LENGTH_SHORT).show() }
153153
}
154154

155155
/**
@@ -193,7 +193,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
193193
api = api ?: OpenPgpApi(this, mServiceConnection?.service)
194194
}
195195

196-
private fun decryptAndVerify(receivedIntent: Intent? = null): Unit {
196+
private fun decryptAndVerify(receivedIntent: Intent? = null) {
197197
val data = receivedIntent ?: Intent()
198198
data.action = ACTION_DECRYPT_VERIFY
199199

@@ -293,26 +293,26 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
293293
dialogBuilder.setView(checkLayout)
294294
dialogBuilder.setMessage(R.string.dialog_update_body)
295295
.setCancelable(false)
296-
.setPositiveButton(R.string.dialog_update_positive, DialogInterface.OnClickListener { dialog, id ->
296+
.setPositiveButton(R.string.dialog_update_positive) { _, _ ->
297297
run {
298298
calculateAndCommitHotp(entry)
299-
if (rememberCheck.isChecked()) {
299+
if (rememberCheck.isChecked) {
300300
val editor = settings.edit()
301301
editor.putBoolean("hotp_remember_check", true)
302302
editor.putBoolean("hotp_remember_choice", true)
303303
editor.commit()
304304
}
305305
}
306-
})
307-
.setNegativeButton(R.string.dialog_update_negative, DialogInterface.OnClickListener { dialog, id ->
308-
run {
309-
calculateHotp(entry)
310-
val editor = settings.edit()
311-
editor.putBoolean("hotp_remember_check", true)
312-
editor.putBoolean("hotp_remember_choice", false)
313-
editor.commit()
314-
}
315-
})
306+
}
307+
.setNegativeButton(R.string.dialog_update_negative) { _, _ ->
308+
run {
309+
calculateHotp(entry)
310+
val editor = settings.edit()
311+
editor.putBoolean("hotp_remember_check", true)
312+
editor.putBoolean("hotp_remember_choice", false)
313+
editor.commit()
314+
}
315+
}
316316
val updateDialog = dialogBuilder.create()
317317
updateDialog.setTitle(R.string.dialog_update_title)
318318
updateDialog.show()
@@ -378,34 +378,33 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
378378

379379
val path = if (intent.getBooleanExtra("fromDecrypt", false)) fullPath else "$fullPath/$editName.gpg"
380380

381-
api?.executeApiAsync(data, iStream, oStream, { result: Intent? -> when (result?.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
382-
OpenPgpApi.RESULT_CODE_SUCCESS -> {
383-
try {
384-
// TODO This might fail, we should check that the write is successful
385-
val outputStream = FileUtils.openOutputStream(File(path))
386-
outputStream.write(oStream.toByteArray())
387-
outputStream.close()
388-
389-
val returnIntent = Intent()
390-
returnIntent.putExtra("CREATED_FILE", path)
391-
returnIntent.putExtra("NAME", editName)
392-
393-
// if coming from decrypt screen->edit button
394-
if (intent.getBooleanExtra("fromDecrypt", false)) {
395-
returnIntent.putExtra("OPERATION", "EDIT")
396-
returnIntent.putExtra("needCommit", true)
397-
}
398-
setResult(RESULT_OK, returnIntent)
399-
finish()
400-
401-
} catch (e: Exception) {
402-
Log.e(TAG, "An Exception occurred", e)
381+
api?.executeApiAsync(data, iStream, oStream) { result: Intent? -> when (result?.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
382+
OpenPgpApi.RESULT_CODE_SUCCESS -> {
383+
try {
384+
// TODO This might fail, we should check that the write is successful
385+
val outputStream = FileUtils.openOutputStream(File(path))
386+
outputStream.write(oStream.toByteArray())
387+
outputStream.close()
388+
389+
val returnIntent = Intent()
390+
returnIntent.putExtra("CREATED_FILE", path)
391+
returnIntent.putExtra("NAME", editName)
392+
393+
// if coming from decrypt screen->edit button
394+
if (intent.getBooleanExtra("fromDecrypt", false)) {
395+
returnIntent.putExtra("OPERATION", "EDIT")
396+
returnIntent.putExtra("needCommit", true)
403397
}
398+
setResult(RESULT_OK, returnIntent)
399+
finish()
400+
} catch (e: Exception) {
401+
Log.e(TAG, "An Exception occurred", e)
404402
}
405-
OpenPgpApi.RESULT_CODE_ERROR -> handleError(result)
406403
}
404+
OpenPgpApi.RESULT_CODE_ERROR -> handleError(result)
405+
}
407406

408-
})
407+
}
409408
}
410409

411410

@@ -415,7 +414,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
415414
private fun editPassword() {
416415
setContentView(R.layout.encrypt_layout)
417416
generate_password?.setOnClickListener {
418-
pwgenDialogFragment().show(fragmentManager, "generator")
417+
pwgenDialogFragment().show(supportFragmentManager, "generator")
419418
}
420419

421420
title = getString(R.string.edit_password_title)
@@ -482,7 +481,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
482481
private fun getKeyIds(receivedIntent: Intent? = null) {
483482
val data = receivedIntent ?: Intent()
484483
data.action = OpenPgpApi.ACTION_GET_KEY_IDS
485-
api?.executeApiAsync(data, null, null, { result: Intent? ->
484+
api?.executeApiAsync(data, null, null) { result: Intent? ->
486485
when (result?.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
487486
OpenPgpApi.RESULT_CODE_SUCCESS -> {
488487
try {
@@ -503,7 +502,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
503502
RESULT_CODE_USER_INTERACTION_REQUIRED -> handleUserInteractionRequest(result, REQUEST_KEY_ID)
504503
OpenPgpApi.RESULT_CODE_ERROR -> handleError(result)
505504
}
506-
})
505+
}
507506
}
508507

509508
override fun onError(e: Exception?) {}
@@ -737,11 +736,11 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
737736
}
738737

739738
companion object {
740-
val OPEN_PGP_BOUND = 101
741-
val REQUEST_DECRYPT = 202
742-
val REQUEST_KEY_ID = 203
739+
const val OPEN_PGP_BOUND = 101
740+
const val REQUEST_DECRYPT = 202
741+
const val REQUEST_KEY_ID = 203
743742

744-
val TAG = "PgpActivity"
743+
const val TAG = "PgpActivity"
745744

746745
private var delayTask: DelayShow? = null
747746

app/src/main/java/com/zeapo/pwdstore/pwgenDialogFragment.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import android.annotation.SuppressLint;
44
import android.app.Activity;
55
import android.app.Dialog;
6-
import android.app.DialogFragment;
76
import android.content.Context;
87
import android.content.DialogInterface;
98
import android.content.SharedPreferences;
109
import android.graphics.Typeface;
1110
import android.os.Bundle;
11+
import android.support.v4.app.DialogFragment;
1212
import android.support.v7.app.AlertDialog;
1313
import android.view.LayoutInflater;
1414
import android.view.View;
@@ -18,6 +18,7 @@
1818
import android.widget.TextView;
1919

2020
import com.zeapo.pwdstore.pwgen.pwgen;
21+
import org.jetbrains.annotations.NotNull;
2122

2223
import java.util.ArrayList;
2324

@@ -31,6 +32,7 @@ public pwgenDialogFragment() {
3132
}
3233

3334

35+
@NotNull
3436
@SuppressLint("SetTextI18n")
3537
@Override
3638
public Dialog onCreateDialog(Bundle savedInstanceState) {
@@ -45,31 +47,31 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
4547
SharedPreferences prefs
4648
= getActivity().getApplicationContext().getSharedPreferences("pwgen", Context.MODE_PRIVATE);
4749

48-
CheckBox checkBox = (CheckBox) view.findViewById(R.id.numerals);
50+
CheckBox checkBox = view.findViewById(R.id.numerals);
4951
checkBox.setChecked(!prefs.getBoolean("0", false));
5052

51-
checkBox = (CheckBox) view.findViewById(R.id.symbols);
53+
checkBox = view.findViewById(R.id.symbols);
5254
checkBox.setChecked(prefs.getBoolean("y", false));
5355

54-
checkBox = (CheckBox) view.findViewById(R.id.uppercase);
56+
checkBox = view.findViewById(R.id.uppercase);
5557
checkBox.setChecked(!prefs.getBoolean("A", false));
5658

57-
checkBox = (CheckBox) view.findViewById(R.id.ambiguous);
59+
checkBox = view.findViewById(R.id.ambiguous);
5860
checkBox.setChecked(!prefs.getBoolean("B", false));
5961

60-
checkBox = (CheckBox) view.findViewById(R.id.pronounceable);
62+
checkBox = view.findViewById(R.id.pronounceable);
6163
checkBox.setChecked(!prefs.getBoolean("s", true));
6264

63-
TextView textView = (TextView) view.findViewById(R.id.lengthNumber);
65+
TextView textView = view.findViewById(R.id.lengthNumber);
6466
textView.setText(Integer.toString(prefs.getInt("length", 20)));
6567

6668
((TextView) view.findViewById(R.id.passwordText)).setTypeface(monoTypeface);
6769

6870
builder.setPositiveButton(getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
6971
@Override
7072
public void onClick(DialogInterface dialog, int which) {
71-
EditText edit = (EditText) callingActivity.findViewById(R.id.crypto_password_edit);
72-
TextView generate = (TextView) view.findViewById(R.id.passwordText);
73+
EditText edit = callingActivity.findViewById(R.id.crypto_password_edit);
74+
TextView generate = view.findViewById(R.id.passwordText);
7375
edit.setText(generate.getText());
7476
}
7577
});
@@ -88,15 +90,15 @@ public void onClick(DialogInterface dialog, int which) {
8890
@Override
8991
public void onShow(DialogInterface dialog) {
9092
setPreferences();
91-
TextView textView = (TextView) view.findViewById(R.id.passwordText);
93+
TextView textView = view.findViewById(R.id.passwordText);
9294
textView.setText(pwgen.generate(getActivity().getApplicationContext()).get(0));
9395

9496
Button b = ad.getButton(AlertDialog.BUTTON_NEUTRAL);
9597
b.setOnClickListener(new View.OnClickListener() {
9698
@Override
9799
public void onClick(View v) {
98100
setPreferences();
99-
TextView textView = (TextView) view.findViewById(R.id.passwordText);
101+
TextView textView = view.findViewById(R.id.passwordText);
100102
textView.setText(pwgen.generate(callingActivity.getApplicationContext()).get(0));
101103
}
102104
});
@@ -122,7 +124,7 @@ private void setPreferences () {
122124
if (!((CheckBox) getDialog().findViewById(R.id.pronounceable)).isChecked()) {
123125
preferences.add("s");
124126
}
125-
EditText editText = (EditText) getDialog().findViewById(R.id.lengthNumber);
127+
EditText editText = getDialog().findViewById(R.id.lengthNumber);
126128
try {
127129
int length = Integer.valueOf(editText.getText().toString());
128130
pwgen.setPrefs(getActivity().getApplicationContext(), preferences, length);

0 commit comments

Comments
 (0)