aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/autofill
diff options
context:
space:
mode:
authorHarsh Shandilya <msfjarvis@gmail.com>2019-10-01 22:14:28 +0530
committerGitHub <noreply@github.com>2019-10-01 22:14:28 +0530
commit073346c157ec34b750d175c8543f346e6eae94de (patch)
treea55d24ef43563f3a2d03d7938a1e96c1f5cd1caf /app/src/main/java/com/zeapo/pwdstore/autofill
parentc9dc4034f12b62f4470f92fb13ecd72871f4a5b7 (diff)
downloadHardenedPass-073346c157ec34b750d175c8543f346e6eae94de.tar.gz
HardenedPass-073346c157ec34b750d175c8543f346e6eae94de.zip
Redesign UI and introduce dark theme (#519)
Caveats: - The openpgp preference had to be removed because the open-intents developers are too lazy to update their libraries. Over the coming weeks I will be reimplementing a local solution for this instead. - The autofill dialog is broken but I since it is being worked on in #410 already I'm not going to bother fixing it.
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/autofill')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillFragment.kt25
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.kt11
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.kt26
3 files changed, 36 insertions, 26 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillFragment.kt b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillFragment.kt
index d01ccdc8..04b8d7ef 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillFragment.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillFragment.kt
@@ -6,6 +6,7 @@ import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.content.pm.PackageManager
+import android.net.Uri
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
@@ -15,21 +16,23 @@ import android.widget.EditText
import android.widget.ListView
import android.widget.RadioButton
import android.widget.RadioGroup
-import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
-import androidx.core.content.ContextCompat
+import androidx.appcompat.widget.AppCompatTextView
import androidx.fragment.app.DialogFragment
+import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.zeapo.pwdstore.PasswordStore
import com.zeapo.pwdstore.R
+import com.zeapo.pwdstore.utils.resolveAttribute
import com.zeapo.pwdstore.utils.splitLines
+
class AutofillFragment : DialogFragment() {
private var adapter: ArrayAdapter<String>? = null
private var isWeb: Boolean = false
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
- val builder = AlertDialog.Builder(requireContext())
+ val builder = MaterialAlertDialogBuilder(requireContext())
// this fragment is only created from the settings page (AutofillPreferenceActivity)
// need to interact with the recyclerAdapter which is a member of activity
val callingActivity = requireActivity() as AutofillPreferenceActivity
@@ -51,9 +54,13 @@ class AutofillFragment : DialogFragment() {
builder.setTitle(appName)
view.findViewById<View>(R.id.webURL).visibility = View.GONE
} else {
- iconPackageName = "com.android.browser"
+ val browserIntent = Intent("android.intent.action.VIEW", Uri.parse("http://"))
+ val resolveInfo = requireContext().packageManager
+ .resolveActivity(browserIntent, PackageManager.MATCH_DEFAULT_ONLY)
+ iconPackageName = resolveInfo?.activityInfo?.packageName
builder.setTitle("Website")
- (view.findViewById<View>(R.id.webURL) as EditText).setText(packageName)
+ (view.findViewById<View>(R.id.webURL) as EditText).setText(packageName
+ ?: "com.android.browser")
}
try {
builder.setIcon(callingActivity.packageManager.getApplicationIcon(iconPackageName))
@@ -65,15 +72,17 @@ class AutofillFragment : DialogFragment() {
adapter = object : ArrayAdapter<String>(requireContext(), android.R.layout.simple_list_item_1, android.R.id.text1) {
// set text color to black because default is white...
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
- val textView = super.getView(position, convertView, parent) as TextView
- textView.setTextColor(ContextCompat.getColor(context, R.color.grey_black_1000))
+ val textView = super.getView(position, convertView, parent) as AppCompatTextView
+ textView.setTextColor(requireContext().resolveAttribute(android.R.attr.textColor))
return textView
}
}
(view.findViewById<View>(R.id.matched) as ListView).adapter = adapter
// delete items by clicking them
(view.findViewById<View>(R.id.matched) as ListView).onItemClickListener =
- AdapterView.OnItemClickListener { _, _, position, _ -> adapter!!.remove(adapter!!.getItem(position)) }
+ AdapterView.OnItemClickListener { _, _, position, _ ->
+ adapter!!.remove(adapter!!.getItem(position))
+ }
// set the existing preference, if any
val prefs: SharedPreferences = if (!isWeb) {
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.kt b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.kt
index f4c9357b..7cd7fcb7 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.kt
@@ -7,8 +7,8 @@ import android.graphics.drawable.Drawable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
-import android.widget.ImageView
-import android.widget.TextView
+import androidx.appcompat.widget.AppCompatImageView
+import androidx.appcompat.widget.AppCompatTextView
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.SortedList
import androidx.recyclerview.widget.SortedListAdapterCallback
@@ -68,7 +68,6 @@ internal class AutofillRecyclerAdapter(
holder.name.text = app.appName
holder.secondary.visibility = View.VISIBLE
- holder.view.setBackgroundResource(R.color.grey_white_1000)
val prefs: SharedPreferences
prefs = if (app.appName != app.packageName) {
@@ -151,9 +150,9 @@ internal class AutofillRecyclerAdapter(
}
internal inner class ViewHolder(var view: View) : RecyclerView.ViewHolder(view), View.OnClickListener {
- var name: TextView = view.findViewById(R.id.app_name)
- var icon: ImageView = view.findViewById(R.id.app_icon)
- var secondary: TextView = view.findViewById(R.id.secondary_text)
+ var name: AppCompatTextView = view.findViewById(R.id.app_name)
+ var icon: AppCompatImageView = view.findViewById(R.id.app_icon)
+ var secondary: AppCompatTextView = view.findViewById(R.id.secondary_text)
var packageName: String? = null
var appName: String? = null
var isWeb: Boolean = false
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.kt b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.kt
index e4d1d04b..d9f42b00 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.kt
@@ -12,7 +12,6 @@ import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
-import android.preference.PreferenceManager
import android.provider.Settings
import android.util.Log
import android.view.WindowManager
@@ -21,6 +20,8 @@ import android.view.accessibility.AccessibilityNodeInfo
import android.view.accessibility.AccessibilityWindowInfo
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
+import androidx.preference.PreferenceManager
+import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.zeapo.pwdstore.PasswordEntry
import com.zeapo.pwdstore.R
import com.zeapo.pwdstore.utils.PasswordRepository
@@ -30,7 +31,6 @@ import org.openintents.openpgp.IOpenPgpService2
import org.openintents.openpgp.OpenPgpError
import org.openintents.openpgp.util.OpenPgpApi
import org.openintents.openpgp.util.OpenPgpServiceConnection
-
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.IOException
@@ -291,7 +291,7 @@ class AutofillService : AccessibilityService() {
when (preference) {
"/first" -> {
- if (!PasswordRepository.isInitialized()) {
+ if (!PasswordRepository.isInitialized) {
PasswordRepository.initialize(this)
}
items = searchPasswords(PasswordRepository.getRepositoryDirectory(this), webViewTitle)
@@ -313,7 +313,7 @@ class AutofillService : AccessibilityService() {
when (preference) {
"/first" -> {
- if (!PasswordRepository.isInitialized()) {
+ if (!PasswordRepository.isInitialized) {
PasswordRepository.initialize(this)
}
items = searchPasswords(PasswordRepository.getRepositoryDirectory(this), appName)
@@ -326,7 +326,7 @@ class AutofillService : AccessibilityService() {
// Put the newline separated list of passwords from the SharedPreferences
// file into the items list.
private fun getPreferredPasswords(preference: String) {
- if (!PasswordRepository.isInitialized()) {
+ if (!PasswordRepository.isInitialized) {
PasswordRepository.initialize(this)
}
val preferredPasswords = preference.splitLines()
@@ -366,7 +366,7 @@ class AutofillService : AccessibilityService() {
dialog = null
}
- val builder = AlertDialog.Builder(this, R.style.Theme_AppCompat_Dialog)
+ val builder = MaterialAlertDialogBuilder(this, R.style.AppTheme_Dialog)
builder.setNegativeButton(R.string.dialog_cancel) { _, _ ->
dialog!!.dismiss()
dialog = null
@@ -391,7 +391,7 @@ class AutofillService : AccessibilityService() {
dialog = null
}
- val builder = AlertDialog.Builder(this, R.style.Theme_AppCompat_Dialog)
+ val builder = MaterialAlertDialogBuilder(this, R.style.AppTheme_Dialog)
builder.setNegativeButton(R.string.dialog_cancel) { _, _ ->
dialog!!.dismiss()
dialog = null
@@ -525,11 +525,13 @@ class AutofillService : AccessibilityService() {
}
OpenPgpApi.RESULT_CODE_ERROR -> {
val error = result.getParcelableExtra<OpenPgpError>(OpenPgpApi.RESULT_ERROR)
- Toast.makeText(this@AutofillService,
- "Error from OpenKeyChain : " + error.message,
- Toast.LENGTH_LONG).show()
- Log.e(Constants.TAG, "onError getErrorId:" + error.errorId)
- Log.e(Constants.TAG, "onError getMessage:" + error.message)
+ if (error != null) {
+ Toast.makeText(this@AutofillService,
+ "Error from OpenKeyChain : " + error.message,
+ Toast.LENGTH_LONG).show()
+ Log.e(Constants.TAG, "onError getErrorId:" + error.errorId)
+ Log.e(Constants.TAG, "onError getMessage:" + error.message)
+ }
}
}
}