extend-uid: button and list to add user ids

This commit is contained in:
Vincent Breitmoser 2015-11-02 22:14:21 +01:00 committed by Dominik Schürmann
parent a041acab65
commit 4ec51fcd9f
2 changed files with 91 additions and 3 deletions

View file

@ -18,6 +18,7 @@
package org.sufficientlysecure.keychain.ui;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
@ -45,7 +46,10 @@ import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround;
import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter;
import org.sufficientlysecure.keychain.ui.adapter.UserIdsAddedAdapter;
import org.sufficientlysecure.keychain.ui.dialog.AddUserIdDialogFragment;
import org.sufficientlysecure.keychain.ui.dialog.EditUserIdDialogFragment;
import org.sufficientlysecure.keychain.ui.dialog.SetPassphraseDialogFragment;
import org.sufficientlysecure.keychain.ui.dialog.UserIdInfoDialogFragment;
import org.sufficientlysecure.keychain.util.Log;
@ -55,11 +59,14 @@ public class ViewKeyAdvUserIdsFragment extends LoaderFragment implements
public static final String ARG_DATA_URI = "uri";
public static final String ARG_HAS_SECRET = "has_secret";
private ListView mUserIds;
private static final int LOADER_ID_USER_IDS = 0;
private ListView mUserIds;
private ListView mUserIdsAddedList;
private View mUserIdsAddedLayout;
private UserIdsAdapter mUserIdsAdapter;
private UserIdsAddedAdapter mUserIdsAddedAdapter;
private Uri mDataUri;
private boolean mHasSecret;
@ -71,6 +78,8 @@ public class ViewKeyAdvUserIdsFragment extends LoaderFragment implements
View view = inflater.inflate(R.layout.view_key_adv_main_fragment, getContainer());
mUserIds = (ListView) view.findViewById(R.id.view_key_user_ids);
mUserIdsAddedList = (ListView) view.findViewById(R.id.view_key_user_ids_added);
mUserIdsAddedLayout = view.findViewById(R.id.view_key_user_ids_add_layout);
mUserIds.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
@ -79,6 +88,13 @@ public class ViewKeyAdvUserIdsFragment extends LoaderFragment implements
}
});
view.findViewById(R.id.view_key_action_add_user_id).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addUserId();
}
});
return root;
}
@ -153,6 +169,29 @@ public class ViewKeyAdvUserIdsFragment extends LoaderFragment implements
});
}
private void addUserId() {
Handler returnHandler = new Handler() {
@Override
public void handleMessage(Message message) {
if (message.what == SetPassphraseDialogFragment.MESSAGE_OKAY) {
Bundle data = message.getData();
// add new user id
mUserIdsAddedAdapter.add(data
.getString(AddUserIdDialogFragment.MESSAGE_DATA_USER_ID));
}
}
};
// Create a new Messenger for the communication back
Messenger messenger = new Messenger(returnHandler);
// pre-fill out primary name
AddUserIdDialogFragment addUserIdDialog = AddUserIdDialogFragment.newInstance(messenger, "");
addUserIdDialog.show(getActivity().getSupportFragmentManager(), "addUserIdDialog");
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
@ -237,7 +276,14 @@ public class ViewKeyAdvUserIdsFragment extends LoaderFragment implements
activity.startActionMode(new Callback() {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
mEditModeSaveKeyringParcel = new SaveKeyringParcel(0L, new byte[0]);
mUserIdsAddedAdapter =
new UserIdsAddedAdapter(getActivity(), mEditModeSaveKeyringParcel.mAddUserIds, false);
mUserIdsAddedList.setAdapter(mUserIdsAddedAdapter);
mUserIdsAddedLayout.setVisibility(View.VISIBLE);
mUserIdsAdapter.setEditMode(mEditModeSaveKeyringParcel);
getLoaderManager().restartLoader(LOADER_ID_USER_IDS, null, ViewKeyAdvUserIdsFragment.this);
@ -262,6 +308,7 @@ public class ViewKeyAdvUserIdsFragment extends LoaderFragment implements
public void onDestroyActionMode(ActionMode mode) {
mEditModeSaveKeyringParcel = null;
mUserIdsAdapter.setEditMode(null);
mUserIdsAddedLayout.setVisibility(View.GONE);
getLoaderManager().restartLoader(LOADER_ID_USER_IDS, null, ViewKeyAdvUserIdsFragment.this);
}
});

View file

@ -1,6 +1,7 @@
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools">
<!-- focusable and related properties to workaround http://stackoverflow.com/q/16182331-->
<LinearLayout
@ -28,6 +29,46 @@
android:layout_marginBottom="4dp"
android:layout_weight="1" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/view_key_user_ids_add_layout"
android:visibility="gone"
tools:visibility="visible">
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="?android:attr/listDivider" />
<org.sufficientlysecure.keychain.ui.widget.FixedListView
android:id="@+id/view_key_user_ids_added"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="?android:attr/listDivider" />
<TextView
android:id="@+id/view_key_action_add_user_id"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/edit_key_action_add_identity"
android:minHeight="?android:attr/listPreferredItemHeight"
android:drawableRight="@drawable/ic_person_add_grey_24dp"
android:drawablePadding="8dp"
android:gravity="center_vertical"
android:clickable="true"
style="?android:attr/borderlessButtonStyle" />
</LinearLayout>
</LinearLayout>
</ScrollView>