mirror of https://github.com/MISP/misp-bump
fix read sync info, modified upload state adapter
parent
8869c405cb
commit
0c98e4d009
|
@ -28,8 +28,10 @@
|
||||||
android:screenOrientation="portrait"
|
android:screenOrientation="portrait"
|
||||||
android:theme="@style/AppTheme.Fullscreen">
|
android:theme="@style/AppTheme.Fullscreen">
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name=".UploadActivity"/>
|
|
||||||
<activity android:name=".SyncUploadActivity"/>
|
<activity android:name=".SyncUploadActivity"
|
||||||
|
android:label="@string/upload"/>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".MyOrganisationActivity"
|
android:name=".MyOrganisationActivity"
|
||||||
android:label="@string/credentials_activity"
|
android:label="@string/credentials_activity"
|
||||||
|
|
|
@ -12,6 +12,7 @@ import android.support.design.widget.FloatingActionButton;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.app.FragmentTransaction;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.view.animation.DecelerateInterpolator;
|
import android.view.animation.DecelerateInterpolator;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
|
@ -120,12 +121,12 @@ public class QrSyncActivity extends AppCompatActivity implements View.OnClickLis
|
||||||
|
|
||||||
private void startPublicKeyExchange() {
|
private void startPublicKeyExchange() {
|
||||||
|
|
||||||
|
currentScanState = ScanState.public_key;
|
||||||
cameraFragment.setReadQrEnabled(true);
|
cameraFragment.setReadQrEnabled(true);
|
||||||
|
|
||||||
TextView info = findViewById(R.id.qr_info);
|
TextView info = findViewById(R.id.qr_info);
|
||||||
info.setText(getText(R.string.public_key));
|
info.setText(getText(R.string.public_key));
|
||||||
|
|
||||||
currentScanState = ScanState.public_key;
|
|
||||||
|
|
||||||
User myUser = preferenceManager.getMyUser();
|
User myUser = preferenceManager.getMyUser();
|
||||||
Organisation myOrg = preferenceManager.getMyOrganisation();
|
Organisation myOrg = preferenceManager.getMyOrganisation();
|
||||||
|
@ -149,13 +150,12 @@ public class QrSyncActivity extends AppCompatActivity implements View.OnClickLis
|
||||||
|
|
||||||
private void startSyncInformationExchange() {
|
private void startSyncInformationExchange() {
|
||||||
|
|
||||||
|
currentScanState = ScanState.information;
|
||||||
cameraFragment.setReadQrEnabled(true);
|
cameraFragment.setReadQrEnabled(true);
|
||||||
|
|
||||||
TextView info = findViewById(R.id.qr_info);
|
TextView info = findViewById(R.id.qr_info);
|
||||||
info.setText(getString(R.string.sync_information));
|
info.setText(getString(R.string.sync_information));
|
||||||
|
|
||||||
currentScanState = ScanState.information;
|
|
||||||
|
|
||||||
Organisation myOrg = preferenceManager.getMyOrganisation();
|
Organisation myOrg = preferenceManager.getMyOrganisation();
|
||||||
|
|
||||||
proceedToSyncInfoFab.setVisibility(View.GONE);
|
proceedToSyncInfoFab.setVisibility(View.GONE);
|
||||||
|
@ -210,10 +210,12 @@ public class QrSyncActivity extends AppCompatActivity implements View.OnClickLis
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
syncInformationReceivedDialog(new SyncInformationQr(qrData));
|
syncInformationReceivedDialog(new SyncInformationQr(cryptography.decrypt(qrData)));
|
||||||
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
|
||||||
|
Log.e("MISP_LOG", "onReadQrCode: ", e);
|
||||||
|
|
||||||
notExpectedFormatDialog();
|
notExpectedFormatDialog();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -264,8 +266,6 @@ public class QrSyncActivity extends AppCompatActivity implements View.OnClickLis
|
||||||
|
|
||||||
private void publicKeyReceivedDialog(final PublicKeyQr pkqr) {
|
private void publicKeyReceivedDialog(final PublicKeyQr pkqr) {
|
||||||
|
|
||||||
cameraFragment.setReadQrEnabled(false);
|
|
||||||
|
|
||||||
AlertDialog.Builder adb = new AlertDialog.Builder(this);
|
AlertDialog.Builder adb = new AlertDialog.Builder(this);
|
||||||
LayoutInflater inflater = getLayoutInflater();
|
LayoutInflater inflater = getLayoutInflater();
|
||||||
|
|
||||||
|
@ -300,8 +300,6 @@ public class QrSyncActivity extends AppCompatActivity implements View.OnClickLis
|
||||||
|
|
||||||
private void syncInformationReceivedDialog(final SyncInformationQr siqr) {
|
private void syncInformationReceivedDialog(final SyncInformationQr siqr) {
|
||||||
|
|
||||||
cameraFragment.setReadQrEnabled(false);
|
|
||||||
|
|
||||||
AlertDialog.Builder adb = new AlertDialog.Builder(this);
|
AlertDialog.Builder adb = new AlertDialog.Builder(this);
|
||||||
LayoutInflater inflater = getLayoutInflater();
|
LayoutInflater inflater = getLayoutInflater();
|
||||||
|
|
||||||
|
|
|
@ -79,10 +79,15 @@ public class SyncUploadActivity extends AppCompatActivity implements View.OnClic
|
||||||
|
|
||||||
fabStart = findViewById(R.id.fab_start);
|
fabStart = findViewById(R.id.fab_start);
|
||||||
fabStart.setVisibility(View.VISIBLE);
|
fabStart.setVisibility(View.VISIBLE);
|
||||||
|
fabStart.setOnClickListener(this);
|
||||||
|
|
||||||
fabFinish = findViewById(R.id.fab_finish);
|
fabFinish = findViewById(R.id.fab_finish);
|
||||||
fabFinish.setVisibility(View.GONE);
|
fabFinish.setVisibility(View.GONE);
|
||||||
|
fabFinish.setOnClickListener(this);
|
||||||
|
|
||||||
fabRetry = findViewById(R.id.fab_retry);
|
fabRetry = findViewById(R.id.fab_retry);
|
||||||
fabRetry.setVisibility(View.GONE);
|
fabRetry.setVisibility(View.GONE);
|
||||||
|
fabRetry.setOnClickListener(this);
|
||||||
|
|
||||||
// RecyclerView
|
// RecyclerView
|
||||||
|
|
||||||
|
@ -97,12 +102,12 @@ public class SyncUploadActivity extends AppCompatActivity implements View.OnClic
|
||||||
|
|
||||||
uploadStates = new UploadState[6];
|
uploadStates = new UploadState[6];
|
||||||
|
|
||||||
uploadStates[0].setTitle("Validate upload information");
|
uploadStates[0] = new UploadState("Validate upload information");
|
||||||
uploadStates[1].setTitle("Check connection to server");
|
uploadStates[1] = new UploadState("Check connection to server");
|
||||||
uploadStates[2].setTitle("Create local organisation");
|
uploadStates[2] = new UploadState("Create local organisation");
|
||||||
uploadStates[3].setTitle("Create sync user & add to organisation");
|
uploadStates[3] = new UploadState("Create sync user & add to organisation");
|
||||||
uploadStates[4].setTitle("Create external organisation");
|
uploadStates[4] = new UploadState("Create external organisation");
|
||||||
uploadStates[5].setTitle("Create sync server");
|
uploadStates[5] = new UploadState("Create sync server");
|
||||||
|
|
||||||
uploadStateAdapter.setStates(uploadStates);
|
uploadStateAdapter.setStates(uploadStates);
|
||||||
|
|
||||||
|
@ -139,6 +144,7 @@ public class SyncUploadActivity extends AppCompatActivity implements View.OnClic
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeTask(int index) {
|
private void executeTask(int index) {
|
||||||
|
|
||||||
switch (index) {
|
switch (index) {
|
||||||
case 0:
|
case 0:
|
||||||
checkBundle(uploadStates[index]);
|
checkBundle(uploadStates[index]);
|
||||||
|
@ -170,6 +176,7 @@ public class SyncUploadActivity extends AppCompatActivity implements View.OnClic
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeNextTask() {
|
private void executeNextTask() {
|
||||||
|
|
||||||
currentTask++;
|
currentTask++;
|
||||||
|
|
||||||
if (currentTask > uploadStates.length) {
|
if (currentTask > uploadStates.length) {
|
||||||
|
@ -180,6 +187,11 @@ public class SyncUploadActivity extends AppCompatActivity implements View.OnClic
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setApplicationError(boolean canRetry) {
|
private void setApplicationError(boolean canRetry) {
|
||||||
|
|
||||||
|
setErrorOnRemainingTasks();
|
||||||
|
|
||||||
|
uploadStateAdapter.notifyDataSetChanged();
|
||||||
|
|
||||||
fabFinish.setVisibility(View.VISIBLE);
|
fabFinish.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
if (canRetry) {
|
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
|
// Upload States
|
||||||
|
|
||||||
private void checkBundle(UploadState state) {
|
private void checkBundle(UploadState state) {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import de.overview.wg.its.mispbump.R;
|
import de.overview.wg.its.mispbump.R;
|
||||||
import de.overview.wg.its.mispbump.model.UploadState;
|
import de.overview.wg.its.mispbump.model.UploadState;
|
||||||
|
@ -20,7 +21,8 @@ public class UploadStateAdapter extends RecyclerView.Adapter<UploadStateAdapter.
|
||||||
class MyViewHolder extends RecyclerView.ViewHolder {
|
class MyViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
private TextView title, error;
|
private TextView title, error;
|
||||||
private ImageView pendingIcon, errorIcon, doneIcon, inProgressIcon;
|
private ImageView pendingIcon, errorIcon, doneIcon;
|
||||||
|
private ProgressBar progressBar;
|
||||||
|
|
||||||
private MyViewHolder(View view) {
|
private MyViewHolder(View view) {
|
||||||
|
|
||||||
|
@ -32,7 +34,8 @@ public class UploadStateAdapter extends RecyclerView.Adapter<UploadStateAdapter.
|
||||||
pendingIcon = view.findViewById(R.id.state_pending);
|
pendingIcon = view.findViewById(R.id.state_pending);
|
||||||
errorIcon = view.findViewById(R.id.state_error);
|
errorIcon = view.findViewById(R.id.state_error);
|
||||||
doneIcon = view.findViewById(R.id.state_done);
|
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) {
|
private void setState(UploadState.State state) {
|
||||||
|
@ -41,7 +44,7 @@ public class UploadStateAdapter extends RecyclerView.Adapter<UploadStateAdapter.
|
||||||
errorIcon.setVisibility(View.GONE);
|
errorIcon.setVisibility(View.GONE);
|
||||||
pendingIcon.setVisibility(View.GONE);
|
pendingIcon.setVisibility(View.GONE);
|
||||||
doneIcon.setVisibility(View.GONE);
|
doneIcon.setVisibility(View.GONE);
|
||||||
inProgressIcon.setVisibility(View.GONE);
|
progressBar.setVisibility(View.GONE);
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case PENDING:
|
case PENDING:
|
||||||
|
@ -49,7 +52,7 @@ public class UploadStateAdapter extends RecyclerView.Adapter<UploadStateAdapter.
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IN_PROGRESS:
|
case IN_PROGRESS:
|
||||||
inProgressIcon.setVisibility(View.VISIBLE);
|
progressBar.setVisibility(View.VISIBLE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DONE:
|
case DONE:
|
||||||
|
@ -60,6 +63,10 @@ public class UploadStateAdapter extends RecyclerView.Adapter<UploadStateAdapter.
|
||||||
errorIcon.setVisibility(View.VISIBLE);
|
errorIcon.setVisibility(View.VISIBLE);
|
||||||
error.setVisibility(View.VISIBLE);
|
error.setVisibility(View.VISIBLE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case FOLLOW_ERROR:
|
||||||
|
errorIcon.setVisibility(View.VISIBLE);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,8 +79,10 @@ public class UploadStateAdapter extends RecyclerView.Adapter<UploadStateAdapter.
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public UploadStateAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public UploadStateAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
|
||||||
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_upload_state, parent, false);
|
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_upload_state, parent, false);
|
||||||
return new UploadStateAdapter.MyViewHolder(itemView);
|
return new UploadStateAdapter.MyViewHolder(itemView);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -203,7 +203,6 @@ public class CameraFragment extends Fragment implements ActivityCompat.OnRequest
|
||||||
SparseArray<Barcode> barcodes = barcodeDetector.detect(frame);
|
SparseArray<Barcode> barcodes = barcodeDetector.detect(frame);
|
||||||
|
|
||||||
if (barcodes.size() > 0) {
|
if (barcodes.size() > 0) {
|
||||||
Log.d(TAG, "onImageAvailable: " + barcodes.valueAt(0).rawValue);
|
|
||||||
parentActivity.onReadQrCode(barcodes.valueAt(0).rawValue);
|
parentActivity.onReadQrCode(barcodes.valueAt(0).rawValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,8 @@ public class UploadState {
|
||||||
PENDING,
|
PENDING,
|
||||||
IN_PROGRESS,
|
IN_PROGRESS,
|
||||||
DONE,
|
DONE,
|
||||||
ERROR
|
ERROR,
|
||||||
|
FOLLOW_ERROR
|
||||||
}
|
}
|
||||||
private State currentState = State.PENDING;
|
private State currentState = State.PENDING;
|
||||||
private String title, error;
|
private String title, error;
|
||||||
|
@ -19,6 +20,7 @@ public class UploadState {
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTitle(String title) {
|
public void setTitle(String title) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
}
|
}
|
||||||
|
@ -26,20 +28,28 @@ public class UploadState {
|
||||||
public String getErrorMessage() {
|
public String getErrorMessage() {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setError(String error) {
|
public void setError(String error) {
|
||||||
this.error = error;
|
this.error = error;
|
||||||
this.currentState = State.ERROR;
|
this.currentState = State.ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDone() {
|
public void setDone() {
|
||||||
this.currentState = State.DONE;
|
this.currentState = State.DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInProgress() {
|
public void setInProgress() {
|
||||||
this.currentState = State.IN_PROGRESS;
|
this.currentState = State.IN_PROGRESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPending() {
|
public void setPending() {
|
||||||
this.currentState = State.PENDING;
|
this.currentState = State.PENDING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setFollowError () {
|
||||||
|
this.currentState = State.FOLLOW_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
public State getCurrentState() {
|
public State getCurrentState() {
|
||||||
return currentState;
|
return currentState;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,68 +12,55 @@
|
||||||
app:cardPreventCornerOverlap="true"
|
app:cardPreventCornerOverlap="true"
|
||||||
app:contentPadding="16dp">
|
app:contentPadding="16dp">
|
||||||
|
|
||||||
<RelativeLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:orientation="vertical"
|
||||||
android:layout_height="match_parent">
|
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
|
<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:id="@+id/state_error_text"
|
||||||
android:layout_width="match_parent"
|
android:text="This will be a meaningful error, somewhen in the future!"
|
||||||
android:layout_height="wrap_content"
|
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="32dp"
|
android:layout_marginTop="8dp"
|
||||||
android:textColor="#FFCC0000"
|
android:textColor="#f44336"/>
|
||||||
android:text="ERRROOOORRR"
|
|
||||||
android:layout_below="@id/title"/>
|
|
||||||
|
|
||||||
<ImageView
|
</LinearLayout>
|
||||||
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>
|
|
||||||
|
|
||||||
</android.support.v7.widget.CardView>
|
</android.support.v7.widget.CardView>
|
||||||
|
|
Loading…
Reference in New Issue