aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java
diff options
context:
space:
mode:
authorMatthew Wong <wongma@protonmail.ch>2015-08-09 16:04:09 -0400
committerMatthew Wong <wongma@protonmail.ch>2015-08-14 17:36:48 -0400
commitad173d9d05c29790d6f647df641e5de28e32fd58 (patch)
tree4cbf4579d39392c2d647459eec10ff7f95466a7e /app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java
parent51a05087e5a349afa3f4e0febdc3a339179e9bbd (diff)
downloadHardenedPass-ad173d9d05c29790d6f647df641e5de28e32fd58.tar.gz
HardenedPass-ad173d9d05c29790d6f647df641e5de28e32fd58.zip
Autofill per-app settings dialog opens on click on suggestion or on existing app
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java53
1 files changed, 51 insertions, 2 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java
index b59223bd..eff94c51 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java
@@ -1,7 +1,11 @@
package com.zeapo.pwdstore.autofill;
+import android.app.DialogFragment;
+import android.content.Context;
+import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
+import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
@@ -16,29 +20,40 @@ import java.util.ArrayList;
public class AutofillRecyclerAdapter extends RecyclerView.Adapter<AutofillRecyclerAdapter.ViewHolder> {
private ArrayList<ApplicationInfo> apps;
private PackageManager pm;
+ private AutofillActivity activity;
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public View view;
public TextView name;
+ public TextView secondary;
public ImageView icon;
+ public String packageName;
public ViewHolder(View view) {
super(view);
this.view = view;
name = (TextView) view.findViewById(R.id.app_name);
+ secondary = (TextView) view.findViewById(R.id.secondary_text);
icon = (ImageView) view.findViewById(R.id.app_icon);
view.setOnClickListener(this);
}
@Override
public void onClick(View v) {
-
+ DialogFragment df = new AutofillFragment();
+ Bundle args = new Bundle();
+ args.putString("packageName", packageName);
+ args.putString("appName", name.getText().toString());
+ args.putInt("position", getAdapterPosition());
+ df.setArguments(args);
+ df.show(activity.getFragmentManager(), "autofill_dialog");
}
}
- public AutofillRecyclerAdapter(ArrayList<ApplicationInfo> apps, PackageManager pm) {
+ public AutofillRecyclerAdapter(ArrayList<ApplicationInfo> apps, PackageManager pm, AutofillActivity activity) {
this.apps = apps;
this.pm = pm;
+ this.activity = activity;
}
@Override
@@ -52,11 +67,45 @@ public class AutofillRecyclerAdapter extends RecyclerView.Adapter<AutofillRecycl
public void onBindViewHolder(AutofillRecyclerAdapter.ViewHolder holder, int position) {
ApplicationInfo app = apps.get(position);
holder.name.setText(pm.getApplicationLabel(app));
+ SharedPreferences prefs
+ = activity.getApplicationContext().getSharedPreferences("autofill", Context.MODE_PRIVATE);
+ String preference = prefs.getString(app.packageName, "first");
+ switch (preference) {
+ case "first":
+ holder.secondary.setText("Automatically match with password");
+ break;
+ case "never":
+ holder.secondary.setText("Never autofill");
+ break;
+ default:
+ holder.secondary.setText("Match with " + preference);
+ break;
+ }
holder.icon.setImageDrawable(pm.getApplicationIcon(app));
+ holder.packageName = app.packageName;
}
@Override
public int getItemCount() {
return apps.size();
}
+
+ public boolean contains(String packageName) {
+ for (ApplicationInfo app : apps) {
+ if (app.packageName.equals(packageName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void add(String packageName) {
+ try {
+ ApplicationInfo app = pm.getApplicationInfo(packageName, 0);
+ this.apps.add(app);
+ notifyItemInserted(apps.size());
+ } catch (PackageManager.NameNotFoundException e) {
+ e.printStackTrace();
+ }
+ }
}