tls-psk: handle disconnect in ui
This commit is contained in:
parent
703603782f
commit
b14674749b
|
@ -122,7 +122,8 @@ public class RemoteDeduplicateActivity extends FragmentActivity {
|
|||
|
||||
keyChoiceList = (RecyclerView) view.findViewById(R.id.duplicate_key_list);
|
||||
keyChoiceList.setLayoutManager(new LinearLayoutManager(activity));
|
||||
keyChoiceList.addItemDecoration(new DividerItemDecoration(activity, DividerItemDecoration.VERTICAL_LIST));
|
||||
keyChoiceList.addItemDecoration(
|
||||
new DividerItemDecoration(activity, DividerItemDecoration.VERTICAL_LIST, true));
|
||||
|
||||
setupListenersForPresenter();
|
||||
mvpView = createMvpView(view, layoutInflater);
|
||||
|
|
|
@ -75,7 +75,8 @@ public class SettingsCacheTTLFragment extends Fragment {
|
|||
recyclerView.setHasFixedSize(true);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST));
|
||||
recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST,
|
||||
true));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ public class IdentitiesCardView extends CardView implements IdentitiesMvpView {
|
|||
|
||||
vIdentities = (RecyclerView) view.findViewById(R.id.view_key_user_ids);
|
||||
vIdentities.setLayoutManager(new LinearLayoutManager(context));
|
||||
vIdentities.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL_LIST));
|
||||
vIdentities.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL_LIST, false));
|
||||
|
||||
Button userIdsEditButton = (Button) view.findViewById(R.id.view_key_card_user_ids_edit);
|
||||
userIdsEditButton.setOnClickListener(new OnClickListener() {
|
||||
|
|
|
@ -185,12 +185,14 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
|
|||
|
||||
@Override
|
||||
public void onConnectionLost() {
|
||||
Log.d(Constants.TAG, "Lost connection!");
|
||||
if (!wasConnected) {
|
||||
// display connection error?
|
||||
connectionStartListen();
|
||||
view.showErrorConnectionFailed();
|
||||
} else {
|
||||
view.showViewDisconnected();
|
||||
secretKeyAdapter.disableAll();
|
||||
}
|
||||
// TODO handle error?
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -201,7 +203,7 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
|
|||
try {
|
||||
// TODO move to worker thread?
|
||||
UncachedKeyRing uncachedKeyRing = UncachedKeyRing.decodeFromData(receivedData.getBytes());
|
||||
String primaryUserId = uncachedKeyRing.getPublicKey().getPrimaryUserId();
|
||||
String primaryUserId = uncachedKeyRing.getPublicKey().getPrimaryUserIdWithFallback();
|
||||
UserId userId = OpenPgpUtils.splitUserId(primaryUserId);
|
||||
|
||||
ReceivedKeyItem receivedKeyItem = new ReceivedKeyItem(receivedData, uncachedKeyRing.getMasterKeyId(),
|
||||
|
@ -285,6 +287,8 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
|
|||
void showConnectionEstablished(String hostname);
|
||||
void showReceivingKeys();
|
||||
|
||||
void showViewDisconnected();
|
||||
|
||||
void scanQrCode();
|
||||
void setQrImage(Bitmap qrCode);
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ public class ReceivedSecretKeyList extends RecyclerView {
|
|||
|
||||
private void init(Context context) {
|
||||
setLayoutManager(new LinearLayoutManager(context));
|
||||
addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL_LIST));
|
||||
addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL_LIST, true));
|
||||
}
|
||||
|
||||
public static class ReceivedKeyAdapter extends Adapter<ReceivedKeyViewHolder> {
|
||||
|
|
|
@ -42,12 +42,13 @@ import com.google.zxing.client.android.Intents;
|
|||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||
import org.sufficientlysecure.keychain.service.ImportKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.ui.QrCodeCaptureActivity;
|
||||
import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
|
||||
import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper.Callback;
|
||||
import org.sufficientlysecure.keychain.ui.transfer.presenter.TransferPresenter;
|
||||
import org.sufficientlysecure.keychain.ui.transfer.presenter.TransferPresenter.TransferMvpView;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
||||
|
||||
|
||||
@RequiresApi(api = VERSION_CODES.LOLLIPOP)
|
||||
|
@ -63,7 +64,8 @@ public class TransferFragment extends Fragment implements TransferMvpView {
|
|||
private ImageView vQrCodeImage;
|
||||
private TransferPresenter presenter;
|
||||
private ViewAnimator vTransferAnimator;
|
||||
private TextView vConnectionStatusText;
|
||||
private TextView vConnectionStatusText1;
|
||||
private TextView vConnectionStatusText2;
|
||||
private RecyclerView vTransferKeyList;
|
||||
private RecyclerView vReceivedKeyList;
|
||||
|
||||
|
@ -76,7 +78,8 @@ public class TransferFragment extends Fragment implements TransferMvpView {
|
|||
|
||||
vTransferAnimator = (ViewAnimator) view.findViewById(R.id.transfer_animator);
|
||||
|
||||
vConnectionStatusText = (TextView) view.findViewById(R.id.connection_status);
|
||||
vConnectionStatusText1 = (TextView) view.findViewById(R.id.connection_status_1);
|
||||
vConnectionStatusText2 = (TextView) view.findViewById(R.id.connection_status_2);
|
||||
vTransferKeyList = (RecyclerView) view.findViewById(R.id.transfer_key_list);
|
||||
vReceivedKeyList = (RecyclerView) view.findViewById(R.id.received_key_list);
|
||||
|
||||
|
@ -117,7 +120,8 @@ public class TransferFragment extends Fragment implements TransferMvpView {
|
|||
|
||||
@Override
|
||||
public void showConnectionEstablished(String hostname) {
|
||||
vConnectionStatusText.setText("Connected to: " + hostname);
|
||||
vConnectionStatusText1.setText("Connected to: " + hostname);
|
||||
vConnectionStatusText2.setText("Connected to: " + hostname);
|
||||
vTransferAnimator.setDisplayedChild(VIEW_CONNECTED);
|
||||
}
|
||||
|
||||
|
@ -126,6 +130,12 @@ public class TransferFragment extends Fragment implements TransferMvpView {
|
|||
vTransferAnimator.setDisplayedChild(VIEW_RECEIVING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showViewDisconnected() {
|
||||
vConnectionStatusText1.setText("Disconnected!");
|
||||
vConnectionStatusText2.setText("Disconnected!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setQrImage(final Bitmap qrCode) {
|
||||
vQrCodeImage.getViewTreeObserver().addOnGlobalLayoutListener(
|
||||
|
@ -171,17 +181,17 @@ public class TransferFragment extends Fragment implements TransferMvpView {
|
|||
|
||||
@Override
|
||||
public void showErrorBadKey() {
|
||||
|
||||
Notify.create(getActivity(), "Failed reading incoming key!", Style.ERROR).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showErrorConnectionFailed() {
|
||||
|
||||
Notify.create(getActivity(), "Connection failed!", Style.ERROR).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showResultNotification(ImportKeyResult result) {
|
||||
result.createNotify(getActivity()).show(this);
|
||||
result.createNotify(getActivity()).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -48,7 +48,7 @@ public class TransferSecretKeyList extends RecyclerView {
|
|||
|
||||
private void init(Context context) {
|
||||
setLayoutManager(new LinearLayoutManager(context));
|
||||
addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL_LIST));
|
||||
addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL_LIST, true));
|
||||
setItemAnimator(null);
|
||||
}
|
||||
|
||||
|
@ -60,6 +60,7 @@ public class TransferSecretKeyList extends RecyclerView {
|
|||
private Long focusedMasterKeyId;
|
||||
private List<SecretKeyItem> data;
|
||||
private ArrayList<Long> finishedItems = new ArrayList<>();
|
||||
private boolean disableAll;
|
||||
|
||||
|
||||
public TransferKeyAdapter(Context context, LayoutInflater layoutInflater,
|
||||
|
@ -78,7 +79,7 @@ public class TransferSecretKeyList extends RecyclerView {
|
|||
public void onBindViewHolder(TransferKeyViewHolder holder, int position) {
|
||||
SecretKeyItem item = data.get(position);
|
||||
boolean isFinished = finishedItems.contains(item.masterKeyId);
|
||||
holder.bind(context, item, onClickTransferKeyListener, focusedMasterKeyId, isFinished);
|
||||
holder.bind(context, item, onClickTransferKeyListener, focusedMasterKeyId, isFinished, disableAll);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -114,6 +115,11 @@ public class TransferSecretKeyList extends RecyclerView {
|
|||
public Loader<List<SecretKeyItem>> createLoader(Context context) {
|
||||
return new SecretKeyLoader(context, context.getContentResolver());
|
||||
}
|
||||
|
||||
public void disableAll() {
|
||||
disableAll = true;
|
||||
notifyItemRangeChanged(0, getItemCount());
|
||||
}
|
||||
}
|
||||
|
||||
static class TransferKeyViewHolder extends RecyclerView.ViewHolder {
|
||||
|
@ -136,7 +142,7 @@ public class TransferSecretKeyList extends RecyclerView {
|
|||
|
||||
private void bind(Context context, final SecretKeyItem item,
|
||||
final OnClickTransferKeyListener onClickTransferKeyListener, Long focusedMasterKeyId,
|
||||
boolean isFinished) {
|
||||
boolean isFinished, boolean disableAll) {
|
||||
if (item.name != null) {
|
||||
vName.setText(item.name);
|
||||
vName.setVisibility(View.VISIBLE);
|
||||
|
@ -155,6 +161,13 @@ public class TransferSecretKeyList extends RecyclerView {
|
|||
DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_ABBREV_MONTH);
|
||||
vCreation.setText(context.getString(R.string.label_key_created, dateTime));
|
||||
|
||||
if (disableAll) {
|
||||
itemView.setAlpha(0.2f);
|
||||
vState.setDisplayedChild(STATE_INVISIBLE);
|
||||
vSendButton.setOnClickListener(null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (focusedMasterKeyId != null) {
|
||||
if (focusedMasterKeyId != item.masterKeyId) {
|
||||
itemView.animate().alpha(0.2f).start();
|
||||
|
|
|
@ -34,12 +34,14 @@ public class DividerItemDecoration extends RecyclerView.ItemDecoration {
|
|||
public static final int HORIZONTAL_LIST = LinearLayoutManager.HORIZONTAL;
|
||||
|
||||
public static final int VERTICAL_LIST = LinearLayoutManager.VERTICAL;
|
||||
private final boolean showAfterLast;
|
||||
|
||||
private Drawable mDivider;
|
||||
|
||||
private int mOrientation;
|
||||
|
||||
public DividerItemDecoration(Context context, int orientation) {
|
||||
public DividerItemDecoration(Context context, int orientation, boolean showAfterLast) {
|
||||
this.showAfterLast = showAfterLast;
|
||||
final TypedArray a = context.obtainStyledAttributes(ATTRS);
|
||||
mDivider = a.getDrawable(0);
|
||||
a.recycle();
|
||||
|
@ -66,8 +68,11 @@ public class DividerItemDecoration extends RecyclerView.ItemDecoration {
|
|||
final int left = parent.getPaddingLeft();
|
||||
final int right = parent.getWidth() - parent.getPaddingRight();
|
||||
|
||||
final int childCount = parent.getChildCount();
|
||||
for (int i = 0; i < childCount -1; i++) {
|
||||
int childCount = parent.getChildCount();
|
||||
if (!showAfterLast) {
|
||||
childCount -= 1;
|
||||
}
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
final View child = parent.getChildAt(i);
|
||||
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
|
||||
.getLayoutParams();
|
||||
|
|
|
@ -8,7 +8,9 @@
|
|||
android:minHeight="?attr/listPreferredItemHeight"
|
||||
android:maxLines="1"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
android:orientation="horizontal"
|
||||
android:paddingLeft="4dp"
|
||||
android:paddingRight="4dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dip"
|
||||
|
@ -54,7 +56,6 @@
|
|||
android:outAnimation="@anim/fade_out"
|
||||
android:inAnimation="@anim/fade_in"
|
||||
android:id="@+id/transfer_state"
|
||||
android:measureAllChildren="false"
|
||||
custom:initialView="04">
|
||||
|
||||
<Space
|
||||
|
@ -64,6 +65,7 @@
|
|||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end|center_vertical"
|
||||
android:padding="8dp"
|
||||
android:id="@+id/button_transfer"
|
||||
android:src="@drawable/ic_play_arrow_white_24dp"
|
||||
|
@ -74,12 +76,14 @@
|
|||
<ProgressBar
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_gravity="end|center_vertical"
|
||||
android:padding="8dp"
|
||||
/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end|center_vertical"
|
||||
android:padding="8dp"
|
||||
android:src="@drawable/ic_check_black_24dp"
|
||||
android:tint="@color/android_green_light"
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
android:id="@+id/transfer_animator"
|
||||
android:inAnimation="@anim/fade_in_delayed"
|
||||
android:outAnimation="@anim/fade_out"
|
||||
custom:initialView="03">
|
||||
custom:initialView="02">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
@ -58,9 +58,17 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="Connection status:"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:id="@+id/connection_status"
|
||||
android:text="Connected to: 123.456.123.123"
|
||||
android:id="@+id/connection_status_1"
|
||||
tools:text="Connected to 123.456.123.123"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<TextView
|
||||
|
@ -80,7 +88,6 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/transfer_key_list"
|
||||
android:padding="16dp"
|
||||
/>
|
||||
|
||||
</ScrollView>
|
||||
|
@ -97,9 +104,17 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="Connection status:"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:id="@+id/connection_status_2"
|
||||
android:text="Connected to: 123.456.123.123"
|
||||
tools:text="Connected to 123.456.123.123"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<TextView
|
||||
|
@ -119,7 +134,6 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/received_key_list"
|
||||
android:padding="16dp"
|
||||
/>
|
||||
|
||||
</ScrollView>
|
||||
|
|
Loading…
Reference in a new issue