mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-02-17 07:30:14 -05:00
certify: viewkeyuseridsadapter cosmetics and checkbox capability
This commit is contained in:
parent
9920196f70
commit
efc8252598
@ -198,12 +198,13 @@ public class ViewKeyMainFragment extends Fragment implements
|
||||
static final int KEYRING_INDEX_USER_ID = 2;
|
||||
|
||||
static final String[] USER_IDS_PROJECTION =
|
||||
new String[]{KeychainContract.UserIds._ID, KeychainContract.UserIds.USER_ID,
|
||||
KeychainContract.UserIds.RANK, };
|
||||
// not the main user id
|
||||
static final String USER_IDS_SELECTION = KeychainContract.UserIds.RANK + " > 0 ";
|
||||
new String[]{
|
||||
KeychainContract.UserIds._ID,
|
||||
KeychainContract.UserIds.USER_ID,
|
||||
KeychainContract.UserIds.RANK,
|
||||
};
|
||||
static final String USER_IDS_SORT_ORDER =
|
||||
KeychainContract.UserIds.USER_ID + " COLLATE LOCALIZED ASC";
|
||||
KeychainContract.UserIds.RANK + " COLLATE LOCALIZED ASC";
|
||||
|
||||
static final String[] KEYS_PROJECTION =
|
||||
new String[]{KeychainContract.Keys._ID, KeychainContract.Keys.KEY_ID,
|
||||
@ -239,7 +240,7 @@ public class ViewKeyMainFragment extends Fragment implements
|
||||
|
||||
// Now create and return a CursorLoader that will take care of
|
||||
// creating a Cursor for the data being displayed.
|
||||
return new CursorLoader(getActivity(), baseUri, USER_IDS_PROJECTION, USER_IDS_SELECTION, null,
|
||||
return new CursorLoader(getActivity(), baseUri, USER_IDS_PROJECTION, null, null,
|
||||
USER_IDS_SORT_ORDER);
|
||||
}
|
||||
case LOADER_ID_KEYS: {
|
||||
|
@ -23,26 +23,48 @@ import android.support.v4.widget.CursorAdapter;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.TextView;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ViewKeyUserIdsAdapter extends CursorAdapter {
|
||||
private LayoutInflater mInflater;
|
||||
|
||||
private int mIndexUserId;
|
||||
private int mIndexUserId, mIndexRank;
|
||||
|
||||
public ViewKeyUserIdsAdapter(Context context, Cursor c, int flags) {
|
||||
final private ArrayList<Boolean> mCheckStates;
|
||||
|
||||
public ViewKeyUserIdsAdapter(Context context, Cursor c, int flags, boolean showCheckBoxes) {
|
||||
super(context, c, flags);
|
||||
|
||||
mInflater = LayoutInflater.from(context);
|
||||
|
||||
mCheckStates = showCheckBoxes ? new ArrayList<Boolean>() : null;
|
||||
|
||||
initIndex(c);
|
||||
}
|
||||
public ViewKeyUserIdsAdapter(Context context, Cursor c, int flags) {
|
||||
this(context, c, flags, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cursor swapCursor(Cursor newCursor) {
|
||||
initIndex(newCursor);
|
||||
if(mCheckStates != null) {
|
||||
mCheckStates.clear();
|
||||
if(newCursor != null) {
|
||||
int count = newCursor.getCount();
|
||||
mCheckStates.ensureCapacity(count);
|
||||
// initialize to true (use case knowledge: we usually want to sign all uids)
|
||||
for(int i = 0; i < count; i++)
|
||||
mCheckStates.add(true);
|
||||
}
|
||||
}
|
||||
|
||||
return super.swapCursor(newCursor);
|
||||
}
|
||||
@ -56,20 +78,67 @@ public class ViewKeyUserIdsAdapter extends CursorAdapter {
|
||||
private void initIndex(Cursor cursor) {
|
||||
if (cursor != null) {
|
||||
mIndexUserId = cursor.getColumnIndexOrThrow(UserIds.USER_ID);
|
||||
mIndexRank = cursor.getColumnIndexOrThrow(UserIds.RANK);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindView(View view, Context context, Cursor cursor) {
|
||||
String userIdStr = cursor.getString(mIndexUserId);
|
||||
|
||||
TextView userId = (TextView) view.findViewById(R.id.userId);
|
||||
userId.setText(userIdStr);
|
||||
TextView vRank = (TextView) view.findViewById(R.id.rank);
|
||||
TextView vUserId = (TextView) view.findViewById(R.id.userId);
|
||||
TextView vAddress = (TextView) view.findViewById(R.id.address);
|
||||
|
||||
vRank.setText(Integer.toString(cursor.getInt(mIndexRank)));
|
||||
|
||||
String[] userId = PgpKeyHelper.splitUserId(cursor.getString(mIndexUserId));
|
||||
if (userId[0] != null) {
|
||||
vUserId.setText(userId[0]);
|
||||
} else {
|
||||
vUserId.setText(R.string.user_id_no_name);
|
||||
}
|
||||
vAddress.setText(userId[1]);
|
||||
|
||||
// don't care further if checkboxes aren't shown
|
||||
if(mCheckStates == null)
|
||||
return;
|
||||
|
||||
final CheckBox vCheckBox = (CheckBox) view.findViewById(R.id.checkBox);
|
||||
final int position = cursor.getPosition();
|
||||
vCheckBox.setClickable(false);
|
||||
vCheckBox.setChecked(mCheckStates.get(position));
|
||||
vCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||
mCheckStates.set(position, b);
|
||||
}
|
||||
});
|
||||
view.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
vCheckBox.toggle();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<String> getSelectedUserIds() {
|
||||
ArrayList<String> result = new ArrayList<String>();
|
||||
for(int i = 0; i < mCheckStates.size(); i++) {
|
||||
if(mCheckStates.get(i)) {
|
||||
mCursor.moveToPosition(i);
|
||||
result.add(mCursor.getString(mIndexUserId));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
||||
return mInflater.inflate(R.layout.view_key_userids_item, null);
|
||||
View view = mInflater.inflate(R.layout.view_key_userids_item, null);
|
||||
// only need to do this once ever, since mShowCheckBoxes is final
|
||||
view.findViewById(R.id.checkBox).setVisibility(mCheckStates != null ? View.VISIBLE : View.GONE);
|
||||
return view;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,15 +2,44 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingRight="3dip"
|
||||
android:singleLine="true">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/userId"
|
||||
<CheckBox
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/user_id"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
android:id="@+id/checkBox" />
|
||||
|
||||
</LinearLayout>
|
||||
<TextView
|
||||
android:id="@+id/rank"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:text="0"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="10dp"
|
||||
android:layout_gravity="center_vertical" />
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/userId"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/user_id_no_name"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/address"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/label_email"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:paddingLeft="10dp" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
Loading…
Reference in New Issue
Block a user