fix read sync info, modified upload state adapter

pull/5/head
Felix Prahl-Kamps 2018-08-19 13:54:15 +02:00
parent 8869c405cb
commit 0c98e4d009
7 changed files with 115 additions and 81 deletions

View File

@ -28,8 +28,10 @@
android:screenOrientation="portrait"
android:theme="@style/AppTheme.Fullscreen">
</activity>
<activity android:name=".UploadActivity"/>
<activity android:name=".SyncUploadActivity"/>
<activity android:name=".SyncUploadActivity"
android:label="@string/upload"/>
<activity
android:name=".MyOrganisationActivity"
android:label="@string/credentials_activity"

View File

@ -12,6 +12,7 @@ import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.*;
import android.view.animation.DecelerateInterpolator;
import android.widget.ImageButton;
@ -120,12 +121,12 @@ public class QrSyncActivity extends AppCompatActivity implements View.OnClickLis
private void startPublicKeyExchange() {
currentScanState = ScanState.public_key;
cameraFragment.setReadQrEnabled(true);
TextView info = findViewById(R.id.qr_info);
info.setText(getText(R.string.public_key));
currentScanState = ScanState.public_key;
User myUser = preferenceManager.getMyUser();
Organisation myOrg = preferenceManager.getMyOrganisation();
@ -149,13 +150,12 @@ public class QrSyncActivity extends AppCompatActivity implements View.OnClickLis
private void startSyncInformationExchange() {
currentScanState = ScanState.information;
cameraFragment.setReadQrEnabled(true);
TextView info = findViewById(R.id.qr_info);
info.setText(getString(R.string.sync_information));
currentScanState = ScanState.information;
Organisation myOrg = preferenceManager.getMyOrganisation();
proceedToSyncInfoFab.setVisibility(View.GONE);
@ -210,10 +210,12 @@ public class QrSyncActivity extends AppCompatActivity implements View.OnClickLis
try {
syncInformationReceivedDialog(new SyncInformationQr(qrData));
syncInformationReceivedDialog(new SyncInformationQr(cryptography.decrypt(qrData)));
} catch (JSONException e) {
Log.e("MISP_LOG", "onReadQrCode: ", e);
notExpectedFormatDialog();
}
@ -264,8 +266,6 @@ public class QrSyncActivity extends AppCompatActivity implements View.OnClickLis
private void publicKeyReceivedDialog(final PublicKeyQr pkqr) {
cameraFragment.setReadQrEnabled(false);
AlertDialog.Builder adb = new AlertDialog.Builder(this);
LayoutInflater inflater = getLayoutInflater();
@ -300,8 +300,6 @@ public class QrSyncActivity extends AppCompatActivity implements View.OnClickLis
private void syncInformationReceivedDialog(final SyncInformationQr siqr) {
cameraFragment.setReadQrEnabled(false);
AlertDialog.Builder adb = new AlertDialog.Builder(this);
LayoutInflater inflater = getLayoutInflater();

View File

@ -79,10 +79,15 @@ public class SyncUploadActivity extends AppCompatActivity implements View.OnClic
fabStart = findViewById(R.id.fab_start);
fabStart.setVisibility(View.VISIBLE);
fabStart.setOnClickListener(this);
fabFinish = findViewById(R.id.fab_finish);
fabFinish.setVisibility(View.GONE);
fabFinish.setOnClickListener(this);
fabRetry = findViewById(R.id.fab_retry);
fabRetry.setVisibility(View.GONE);
fabRetry.setOnClickListener(this);
// RecyclerView
@ -97,12 +102,12 @@ public class SyncUploadActivity extends AppCompatActivity implements View.OnClic
uploadStates = new UploadState[6];
uploadStates[0].setTitle("Validate upload information");
uploadStates[1].setTitle("Check connection to server");
uploadStates[2].setTitle("Create local organisation");
uploadStates[3].setTitle("Create sync user & add to organisation");
uploadStates[4].setTitle("Create external organisation");
uploadStates[5].setTitle("Create sync server");
uploadStates[0] = new UploadState("Validate upload information");
uploadStates[1] = new UploadState("Check connection to server");
uploadStates[2] = new UploadState("Create local organisation");
uploadStates[3] = new UploadState("Create sync user & add to organisation");
uploadStates[4] = new UploadState("Create external organisation");
uploadStates[5] = new UploadState("Create sync server");
uploadStateAdapter.setStates(uploadStates);
@ -139,6 +144,7 @@ public class SyncUploadActivity extends AppCompatActivity implements View.OnClic
}
private void executeTask(int index) {
switch (index) {
case 0:
checkBundle(uploadStates[index]);
@ -170,6 +176,7 @@ public class SyncUploadActivity extends AppCompatActivity implements View.OnClic
}
private void executeNextTask() {
currentTask++;
if (currentTask > uploadStates.length) {
@ -180,6 +187,11 @@ public class SyncUploadActivity extends AppCompatActivity implements View.OnClic
}
private void setApplicationError(boolean canRetry) {
setErrorOnRemainingTasks();
uploadStateAdapter.notifyDataSetChanged();
fabFinish.setVisibility(View.VISIBLE);
if (canRetry) {
@ -187,6 +199,23 @@ public class SyncUploadActivity extends AppCompatActivity implements View.OnClic
}
}
private void setErrorOnRemainingTasks() {
boolean errorFound = false;
for (int i = 0; i < uploadStates.length; i++) {
if (!errorFound && uploadStates[i].getCurrentState() == UploadState.State.ERROR) {
errorFound = true;
continue;
}
if (errorFound) {
uploadStates[i].setFollowError();
}
}
}
// Upload States
private void checkBundle(UploadState state) {

View File

@ -6,6 +6,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import de.overview.wg.its.mispbump.R;
import de.overview.wg.its.mispbump.model.UploadState;
@ -20,7 +21,8 @@ public class UploadStateAdapter extends RecyclerView.Adapter<UploadStateAdapter.
class MyViewHolder extends RecyclerView.ViewHolder {
private TextView title, error;
private ImageView pendingIcon, errorIcon, doneIcon, inProgressIcon;
private ImageView pendingIcon, errorIcon, doneIcon;
private ProgressBar progressBar;
private MyViewHolder(View view) {
@ -32,7 +34,8 @@ public class UploadStateAdapter extends RecyclerView.Adapter<UploadStateAdapter.
pendingIcon = view.findViewById(R.id.state_pending);
errorIcon = view.findViewById(R.id.state_error);
doneIcon = view.findViewById(R.id.state_done);
inProgressIcon = view.findViewById(R.id.state_in_progress);
progressBar = view.findViewById(R.id.state_in_progress);
}
private void setState(UploadState.State state) {
@ -41,7 +44,7 @@ public class UploadStateAdapter extends RecyclerView.Adapter<UploadStateAdapter.
errorIcon.setVisibility(View.GONE);
pendingIcon.setVisibility(View.GONE);
doneIcon.setVisibility(View.GONE);
inProgressIcon.setVisibility(View.GONE);
progressBar.setVisibility(View.GONE);
switch (state) {
case PENDING:
@ -49,7 +52,7 @@ public class UploadStateAdapter extends RecyclerView.Adapter<UploadStateAdapter.
break;
case IN_PROGRESS:
inProgressIcon.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.VISIBLE);
break;
case DONE:
@ -60,6 +63,10 @@ public class UploadStateAdapter extends RecyclerView.Adapter<UploadStateAdapter.
errorIcon.setVisibility(View.VISIBLE);
error.setVisibility(View.VISIBLE);
break;
case FOLLOW_ERROR:
errorIcon.setVisibility(View.VISIBLE);
break;
}
}
}
@ -72,8 +79,10 @@ public class UploadStateAdapter extends RecyclerView.Adapter<UploadStateAdapter.
@NonNull
@Override
public UploadStateAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_upload_state, parent, false);
return new UploadStateAdapter.MyViewHolder(itemView);
}
@Override

View File

@ -203,7 +203,6 @@ public class CameraFragment extends Fragment implements ActivityCompat.OnRequest
SparseArray<Barcode> barcodes = barcodeDetector.detect(frame);
if (barcodes.size() > 0) {
Log.d(TAG, "onImageAvailable: " + barcodes.valueAt(0).rawValue);
parentActivity.onReadQrCode(barcodes.valueAt(0).rawValue);
}
}

View File

@ -6,7 +6,8 @@ public class UploadState {
PENDING,
IN_PROGRESS,
DONE,
ERROR
ERROR,
FOLLOW_ERROR
}
private State currentState = State.PENDING;
private String title, error;
@ -19,6 +20,7 @@ public class UploadState {
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@ -26,20 +28,28 @@ public class UploadState {
public String getErrorMessage() {
return error;
}
public void setError(String error) {
this.error = error;
this.currentState = State.ERROR;
}
public void setDone() {
this.currentState = State.DONE;
}
public void setInProgress() {
this.currentState = State.IN_PROGRESS;
}
public void setPending() {
this.currentState = State.PENDING;
}
public void setFollowError () {
this.currentState = State.FOLLOW_ERROR;
}
public State getCurrentState() {
return currentState;
}

View File

@ -12,68 +12,55 @@
app:cardPreventCornerOverlap="true"
app:contentPadding="16dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_weight="1.0"
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textStyle="bold"
android:text="Title"/>
<ImageView
android:id="@+id/state_pending"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:tint="@color/colorPrimary"
android:src="@drawable/icon_hour_glass"/>
<ProgressBar
android:id="@+id/state_in_progress"
android:layout_width="24dp" android:layout_height="24dp"/>
<ImageView
android:id="@+id/state_done"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tint="#4CAF50"
android:src="@drawable/icon_round_check"/>
<ImageView
android:id="@+id/state_error"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tint="#f44336"
android:src="@drawable/icon_round_error"/>
</LinearLayout>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textSize="18sp"
android:textStyle="bold"
android:text="Title"/>
<TextView
android:visibility="gone"
android:id="@+id/state_error_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:textColor="#FFCC0000"
android:text="ERRROOOORRR"
android:layout_below="@id/title"/>
android:text="This will be a meaningful error, somewhen in the future!"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textColor="#f44336"/>
<ImageView
android:id="@+id/state_pending"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tint="@color/colorPrimary"
android:src="@drawable/icon_hour_glass"/>
<ImageView
android:visibility="gone"
android:id="@+id/state_in_progress"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tint="@color/colorPrimary"
android:src="@drawable/icon_cloud_upload"/>
<ImageView
android:visibility="gone"
android:id="@+id/state_done"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tint="@color/colorPrimary"
android:src="@drawable/icon_round_check"/>
<ImageView
android:visibility="gone"
android:id="@+id/state_error"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tint="@color/colorPrimary"
android:src="@drawable/icon_round_error"/>
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>