diff options
author | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-07-02 15:10:50 +0200 |
---|---|---|
committer | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-07-02 15:10:50 +0200 |
commit | 4f83a4f1636e674bea60d806610f55022c2d9b5e (patch) | |
tree | 20af10248c7f27d69c71be0b0556c38ad58e51cc /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter | |
parent | 7408a35e1984c4791ce956bdc2ba225f8e0c3a7c (diff) | |
download | open-keychain-4f83a4f1636e674bea60d806610f55022c2d9b5e.tar.gz open-keychain-4f83a4f1636e674bea60d806610f55022c2d9b5e.tar.bz2 open-keychain-4f83a4f1636e674bea60d806610f55022c2d9b5e.zip |
Edit key: adding user ids
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter')
3 files changed, 209 insertions, 146 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAdapter.java index 7fc78dc41..7bf9334b8 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAdapter.java @@ -123,6 +123,7 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC TextView vComment = (TextView) view.findViewById(R.id.comment); ImageView vVerified = (ImageView) view.findViewById(R.id.certified); ImageView vHasChanges = (ImageView) view.findViewById(R.id.has_changes); + ImageView vEditImage = (ImageView) view.findViewById(R.id.edit_image); String userId = cursor.getString(mIndexUserId); String[] splitUserId = KeyRing.splitUserId(userId); @@ -167,8 +168,10 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC } else { vHasChanges.setVisibility(View.GONE); } + vEditImage.setVisibility(View.VISIBLE); } else { vHasChanges.setVisibility(View.GONE); + vEditImage.setVisibility(View.GONE); } if (isRevoked) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAddedAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAddedAdapter.java new file mode 100644 index 000000000..ff0ec70f3 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAddedAdapter.java @@ -0,0 +1,206 @@ +/* + * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package org.sufficientlysecure.keychain.ui.adapter; + +import android.app.Activity; +import android.content.Context; +import android.text.Editable; +import android.text.TextUtils; +import android.text.TextWatcher; +import android.util.Patterns; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.AutoCompleteTextView; +import android.widget.EditText; +import android.widget.ImageButton; + +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.helper.ContactHelper; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; + +public class UserIdsAddedAdapter extends ArrayAdapter<UserIdsAddedAdapter.UserIdModel> { + private LayoutInflater mInflater; + private Activity mActivity; + + private ArrayAdapter<String> mAutoCompleteNameAdapter; + private ArrayAdapter<String> mAutoCompleteEmailAdapter; + + // hold a private reference to the underlying data List + private List<UserIdModel> mData; + + public static class UserIdModel { + String name = ""; + String address = ""; + String comment = ""; + + @Override + public String toString() { + String userId = null; + if (!TextUtils.isEmpty(name)) { + userId = name; + if (!TextUtils.isEmpty(comment)) { + userId += " (" + comment + ")"; + } + if (!TextUtils.isEmpty(address)) { + userId += " <" + address + ">"; + } + } + return userId; + } + } + + public UserIdsAddedAdapter(Activity activity, List<UserIdModel> data) { + super(activity, -1, data); + mActivity = activity; + mInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + mData = data; + mAutoCompleteNameAdapter = new ArrayAdapter<String> + (mActivity, android.R.layout.simple_dropdown_item_1line, + ContactHelper.getPossibleUserNames(mActivity) + ); + mAutoCompleteEmailAdapter = new ArrayAdapter<String> + (mActivity, android.R.layout.simple_dropdown_item_1line, + ContactHelper.getPossibleUserEmails(mActivity) + ); + } + + public List<String> getDataAsStringList() { + ArrayList<String> out = new ArrayList<String>(); + for (UserIdModel id : mData) { + out.add(id.toString()); + } + + return out; + } + + static class ViewHolder { + public AutoCompleteTextView vAddress; + public AutoCompleteTextView vName; + public EditText vComment; + public ImageButton vDelete; + // also hold a reference to the model item + public UserIdModel mModel; + } + + public View getView(final int position, View convertView, ViewGroup parent) { + if (convertView == null) { + // Not recycled, inflate a new view + convertView = mInflater.inflate(R.layout.edit_key_user_id_added_item, null); + final ViewHolder viewHolder = new ViewHolder(); + viewHolder.vAddress = (AutoCompleteTextView) convertView.findViewById(R.id.user_id_added_item_address); + viewHolder.vName = (AutoCompleteTextView) convertView.findViewById(R.id.user_id_added_item_name); + viewHolder.vComment = (EditText) convertView.findViewById(R.id.user_id_added_item_comment); + viewHolder.vDelete = (ImageButton) convertView.findViewById(R.id.user_id_added_item_delete); + convertView.setTag(viewHolder); + + viewHolder.vAddress.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + } + + @Override + public void afterTextChanged(Editable s) { + // update referenced item in view holder + viewHolder.mModel.address = s.toString(); + + // show icon on valid email addresses + if (viewHolder.mModel.address.length() > 0) { + Matcher emailMatcher = Patterns.EMAIL_ADDRESS.matcher(viewHolder.mModel.address); + if (emailMatcher.matches()) { + viewHolder.vAddress.setCompoundDrawablesWithIntrinsicBounds(0, 0, + R.drawable.uid_mail_ok, 0); + } else { + viewHolder.vAddress.setCompoundDrawablesWithIntrinsicBounds(0, 0, + R.drawable.uid_mail_bad, 0); + } + } else { + // remove drawable if email is empty + viewHolder.vAddress.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); + } + } + }); + + viewHolder.vName.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + } + + @Override + public void afterTextChanged(Editable s) { + // update referenced item in view holder + viewHolder.mModel.name = s.toString(); + } + }); + + viewHolder.vComment.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + } + + @Override + public void afterTextChanged(Editable s) { + // update referenced item in view holder + viewHolder.mModel.comment = s.toString(); + } + }); + + viewHolder.vDelete.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + // remove reference model item from adapter (data and notify about change) + UserIdsAddedAdapter.this.remove(viewHolder.mModel); + } + }); + + } + final ViewHolder holder = (ViewHolder) convertView.getTag(); + + // save reference to model item + holder.mModel = getItem(position); + + holder.vAddress.setText(holder.mModel.address); + holder.vAddress.setThreshold(1); // Start working from first character + holder.vAddress.setAdapter(mAutoCompleteEmailAdapter); + + holder.vName.setText(holder.mModel.name); + holder.vName.setThreshold(1); // Start working from first character + holder.vName.setAdapter(mAutoCompleteNameAdapter); + + holder.vComment.setText(holder.mModel.comment); + + return convertView; + } + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsNewAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsNewAdapter.java deleted file mode 100644 index dffce50a4..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsNewAdapter.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (C) 2013-2014 Dominik Schürmann <dominik@dominikschuermann.de> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package org.sufficientlysecure.keychain.ui.adapter; - -import android.annotation.TargetApi; -import android.app.Activity; -import android.content.Context; -import android.os.Build; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.CheckBox; -import android.widget.EditText; -import android.widget.ImageView; -import android.widget.TextView; - -import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.pgp.KeyRing; - -import java.util.List; - -public class UserIdsNewAdapter extends ArrayAdapter<String> { - protected LayoutInflater mInflater; - protected Activity mActivity; - - protected List<String> mData; - -// static class ViewHolder { -// public TextView vName; -// public TextView vAddress; -// public TextView vComment; -// public ImageView vVerified; -// public ImageView vHasChanges; -// public CheckBox vCheckBox; -// } - - public UserIdsNewAdapter(Activity activity) { - super(activity, -1); - mActivity = activity; - mInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - } - - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - public void setData(List<String> data) { - clear(); - if (data != null) { - this.mData = data; - - // add data to extended ArrayAdapter - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - addAll(data); - } else { - for (String entry : data) { - add(entry); - } - } - } - } - - public List<String> getData() { -// String name = mName.getText().toString(); -// - String email = mAddress.getText().toString(); -// - String comment = mComment.getText().toString(); -// - -// - String userId = null; -// - if (!TextUtils.isEmpty(name)) { -// - userId = name; -// - if (!TextUtils.isEmpty(comment)) { -// - userId += " (" + comment + ")"; -// - } -// - if (!TextUtils.isEmpty(email)) { -// - userId += " <" + email + ">"; -// - } -// - } - return mData; - } - - @Override - public boolean hasStableIds() { - return true; - } - - public View getView(int position, View convertView, ViewGroup parent) { - String entry = mData.get(position); -// ViewHolder holder; -// if (convertView == null) { -// holder = new ViewHolder(); - convertView = mInflater.inflate(R.layout.edit_key_new_userids_item, null); - EditText vName = (EditText) convertView.findViewById(R.id.userId); - EditText vAddress = (EditText) convertView.findViewById(R.id.address); - EditText vComment = (EditText) convertView.findViewById(R.id.comment); -// holder.vVerified = (ImageView) convertView.findViewById(R.id.certified); - ImageView vHasChanges = (ImageView) convertView.findViewById(R.id.has_changes); -// holder.vCheckBox = (CheckBox) convertView.findViewById(R.id.checkBox); -// convertView.setTag(holder); -// } else { -// holder = (ViewHolder) convertView.getTag(); -// } - -// // user id -// String[] splitUserId = KeyRing.splitUserId(entry); -// if (splitUserId[0] != null) { -// vName.setText(splitUserId[0]); -// } else { -// vName.setText(R.string.user_id_no_name); -// } -// if (splitUserId[1] != null) { -// vAddress.setText(splitUserId[1]); -// vAddress.setVisibility(View.VISIBLE); -// } else { -// holder.vAddress.setVisibility(View.GONE); -// } -// if (splitUserId[2] != null) { -// vComment.setText(splitUserId[2]); -// vComment.setVisibility(View.VISIBLE); -// } else { -// holder.vComment.setVisibility(View.GONE); -// } -// -// holder.vCheckBox.setVisibility(View.GONE); -// -// holder.vVerified.setImageResource(R.drawable.key_certify_ok_depth0); -// -// // all items are "new" -// holder.vHasChanges.setVisibility(View.VISIBLE); - - return convertView; - } - -} |