tls-psk: use inline progress animation

This commit is contained in:
Vincent Breitmoser
2017-05-30 16:26:05 +02:00
parent 0c3a247d9e
commit 9b20c97e01
4 changed files with 105 additions and 25 deletions

View File

@@ -91,6 +91,7 @@ public class KeyTransferInteractor {
private SSLServerSocket serverSocket;
private byte[] dataToSend;
private String sendPassthrough;
static TransferThread createClientTransferThread(KeyTransferCallback callback, byte[] presharedKey,
String host, int port) {
@@ -209,8 +210,9 @@ public class KeyTransferInteractor {
dataToSend = null;
socket.setSoTimeout(2000);
sendDataAndClose(socket.getOutputStream(), data);
invokeListener(CONNECTION_SEND_OK, null);
sendData(socket.getOutputStream(), data);
invokeListener(CONNECTION_SEND_OK, sendPassthrough);
sendPassthrough = null;
return true;
}
return false;
@@ -226,7 +228,7 @@ public class KeyTransferInteractor {
return builder.toString();
}
private void sendDataAndClose(OutputStream outputStream, byte[] data) throws IOException {
private void sendData(OutputStream outputStream, byte[] data) throws IOException {
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream);
bufferedOutputStream.write(data);
bufferedOutputStream.close();
@@ -265,8 +267,9 @@ public class KeyTransferInteractor {
handler.post(runnable);
}
synchronized void sendDataAndClose(byte[] dataToSend) {
synchronized void sendData(byte[] dataToSend, String passthrough) {
this.dataToSend = dataToSend;
this.sendPassthrough = passthrough;
}
@Override
@@ -297,8 +300,8 @@ public class KeyTransferInteractor {
transferThread = null;
}
public void sendData(byte[] dataToSend) {
transferThread.sendDataAndClose(dataToSend);
public void sendData(byte[] dataToSend, String passthrough) {
transferThread.sendData(dataToSend, passthrough);
}
public interface KeyTransferCallback {

View File

@@ -26,6 +26,7 @@ import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.RequiresApi;
import android.support.v4.app.LoaderManager;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
@@ -96,7 +97,8 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
try {
byte[] armoredSecretKey =
KeyRepository.createDatabaseInteractor(context).getSecretKeyRingAsArmoredData(masterKeyId);
connectionSend(armoredSecretKey);
secretKeyAdapter.focusItem(masterKeyId);
connectionSend(armoredSecretKey, Long.toString(masterKeyId));
} catch (IOException | NotFoundException | PgpGeneralException e) {
e.printStackTrace();
}
@@ -129,9 +131,18 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
}
@Override
public void onDataSentOk(String arg) {
public void onDataSentOk(String passthrough) {
Log.d(Constants.TAG, "data sent ok!");
view.showFakeSendProgressDialog();
final long masterKeyId = Long.parseLong(passthrough);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
secretKeyAdapter.focusItem(null);
secretKeyAdapter.addToFinishedItems(masterKeyId);
}
}, 750);
// view.showFakeSendProgressDialog();
}
@@ -162,11 +173,11 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
}
}
private void connectionSend(byte[] armoredSecretKey) {
private void connectionSend(byte[] armoredSecretKey, String passthrough) {
if (keyTransferClientInteractor != null) {
keyTransferClientInteractor.sendData(armoredSecretKey);
keyTransferClientInteractor.sendData(armoredSecretKey, passthrough);
} else if (keyTransferServerInteractor != null) {
keyTransferServerInteractor.sendData(armoredSecretKey);
keyTransferServerInteractor.sendData(armoredSecretKey, passthrough);
}
}

View File

@@ -1,6 +1,7 @@
package org.sufficientlysecure.keychain.ui.transfer.view;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
@@ -14,6 +15,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.ViewAnimator;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.transfer.loader.SecretKeyLoader;
@@ -22,7 +24,11 @@ import org.sufficientlysecure.keychain.ui.util.recyclerview.DividerItemDecoratio
public class TransferSecretKeyList extends RecyclerView {
private OnClickTransferKeyListener onClickTransferKeyListener;
private static final int STATE_INVISIBLE = 0;
private static final int STATE_BUTTON = 1;
private static final int STATE_PROGRESS = 2;
private static final int STATE_TRANSFERRED = 3;
public TransferSecretKeyList(Context context) {
super(context);
@@ -42,6 +48,7 @@ public class TransferSecretKeyList extends RecyclerView {
private void init(Context context) {
setLayoutManager(new LinearLayoutManager(context));
addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL_LIST));
setItemAnimator(null);
}
public static class TransferKeyAdapter extends RecyclerView.Adapter<TransferKeyViewHolder> {
@@ -49,7 +56,9 @@ public class TransferSecretKeyList extends RecyclerView {
private final LayoutInflater layoutInflater;
private final OnClickTransferKeyListener onClickTransferKeyListener;
private Long focusedMasterKeyId;
private List<SecretKeyItem> data;
private ArrayList<Long> finishedItems;
public TransferKeyAdapter(Context context, LayoutInflater layoutInflater,
@@ -67,7 +76,8 @@ public class TransferSecretKeyList extends RecyclerView {
@Override
public void onBindViewHolder(TransferKeyViewHolder holder, int position) {
SecretKeyItem item = data.get(position);
holder.bind(context, item, onClickTransferKeyListener);
boolean isFinished = finishedItems.contains(item.masterKeyId);
holder.bind(context, item, onClickTransferKeyListener, focusedMasterKeyId, isFinished);
}
@Override
@@ -82,9 +92,19 @@ public class TransferSecretKeyList extends RecyclerView {
public void setData(List<SecretKeyItem> data) {
this.data = data;
this.finishedItems = new ArrayList<>();
notifyDataSetChanged();
}
public void addToFinishedItems(long masterKeyId) {
finishedItems.add(masterKeyId);
}
public void focusItem(Long masterKeyId) {
focusedMasterKeyId = masterKeyId;
notifyItemRangeChanged(0, getItemCount());
}
public Loader<List<SecretKeyItem>> createLoader(Context context) {
return new SecretKeyLoader(context, context.getContentResolver());
}
@@ -95,8 +115,9 @@ public class TransferSecretKeyList extends RecyclerView {
private final TextView vEmail;
private final TextView vCreation;
private final View vSendButton;
private final ViewAnimator vState;
public TransferKeyViewHolder(View itemView) {
TransferKeyViewHolder(View itemView) {
super(itemView);
vName = (TextView) itemView.findViewById(R.id.key_list_item_name);
@@ -104,9 +125,12 @@ public class TransferSecretKeyList extends RecyclerView {
vCreation = (TextView) itemView.findViewById(R.id.key_list_item_creation);
vSendButton = itemView.findViewById(R.id.button_transfer);
vState = (ViewAnimator) itemView.findViewById(R.id.transfer_state);
}
private void bind(Context context, final SecretKeyItem item, final OnClickTransferKeyListener onClickTransferKeyListener) {
private void bind(Context context, final SecretKeyItem item,
final OnClickTransferKeyListener onClickTransferKeyListener, Long focusedMasterKeyId,
boolean isFinished) {
if (item.name != null) {
vName.setText(item.name);
vName.setVisibility(View.VISIBLE);
@@ -125,7 +149,20 @@ public class TransferSecretKeyList extends RecyclerView {
DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_ABBREV_MONTH);
vCreation.setText(context.getString(R.string.label_key_created, dateTime));
if (onClickTransferKeyListener != null) {
if (focusedMasterKeyId != null) {
if (focusedMasterKeyId != item.masterKeyId) {
itemView.animate().alpha(0.2f).start();
vState.setDisplayedChild(isFinished ? STATE_TRANSFERRED : STATE_INVISIBLE);
} else {
itemView.setAlpha(1.0f);
vState.setDisplayedChild(STATE_PROGRESS);
}
} else {
itemView.animate().alpha(1.0f).start();
vState.setDisplayedChild(isFinished ? STATE_TRANSFERRED : STATE_BUTTON);
}
if (focusedMasterKeyId == null && onClickTransferKeyListener != null) {
vSendButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {

View File

@@ -2,11 +2,12 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:maxLines="1"
android:gravity="center_vertical"
android:orientation="horizontal">
<LinearLayout
@@ -47,14 +48,42 @@
</LinearLayout>
<ImageView
<org.sufficientlysecure.keychain.ui.widget.ToolableViewAnimator
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:id="@+id/button_transfer"
android:src="@drawable/ic_play_arrow_white_24dp"
android:tint="@color/md_black_1000"
android:background="?selectableItemBackground"
/>
android:outAnimation="@anim/fade_out"
android:inAnimation="@anim/fade_in"
android:id="@+id/transfer_state"
custom:initialView="2">
<Space
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:id="@+id/button_transfer"
android:src="@drawable/ic_play_arrow_white_24dp"
android:tint="@color/md_black_1000"
android:background="?selectableItemBackground"
/>
<ProgressBar
android:layout_width="36dp"
android:layout_height="36dp"
android:padding="8dp"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:src="@drawable/ic_check_black_24dp"
android:tint="@color/android_green_light"
/>
</org.sufficientlysecure.keychain.ui.widget.ToolableViewAnimator>
</LinearLayout>