Skip to content
This repository has been archived by the owner on Aug 5, 2019. It is now read-only.

Commit

Permalink
Merge pull request #2 from cybertier/reorganize-sync-process
Browse files Browse the repository at this point in the history
Reorganize sync process
  • Loading branch information
felixpk authored Jul 14, 2019
2 parents b3fc24c + ef37517 commit 8bdab94
Show file tree
Hide file tree
Showing 18 changed files with 356 additions and 188 deletions.
1 change: 1 addition & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies {
// android
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.appcompat:appcompat:1.1.0-beta01'
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

Expand Down Expand Up @@ -43,9 +43,9 @@ public class ExchangeActivity extends AppCompatActivity {

private CameraFragment cameraFragment;

private CoordinatorLayout rootLayout;
private View qrFrame;
private TextView qrInfo;
private ConstraintLayout rootLayout;
private View qrFrame, scanFeedbackView, continueHintView, fragmentContainer;
private TextView scanFeedbackText, qrContentInfo;
private ImageView qrCode;
private ImageButton prevButton, nextButton;

Expand Down Expand Up @@ -76,10 +76,15 @@ protected void onCreate(Bundle savedInstanceState) {

private void initViews() {
rootLayout = findViewById(R.id.rootLayout);
fragmentContainer = findViewById(R.id.fragmentContainer);

qrFrame = findViewById(R.id.qrFrame);
qrCode = findViewById(R.id.qrCode);
qrInfo = findViewById(R.id.qrInfo);

scanFeedbackView = findViewById(R.id.scanFeedbackView);
scanFeedbackText = findViewById(R.id.scanFeedbackText);
continueHintView = findViewById(R.id.continueHint);
qrContentInfo = findViewById(R.id.qrContentInfo);

prevButton = findViewById(R.id.prevButton);
prevButton.setOnClickListener(onPrevClicked());
Expand Down Expand Up @@ -126,15 +131,12 @@ private void showQrCode(final Bitmap bitmap) {
@Override
public void run() {
qrCode.setImageBitmap(bitmap);
qrFrame.setVisibility(View.VISIBLE); // TODO animate
qrFrame.setVisibility(View.VISIBLE);
}
});
}

private void setSyncState(SyncState state) {

Log.d("DEBUG", "current sync state: " + state);

currentSyncState = state;

runOnUiThread(new Runnable() {
Expand All @@ -147,8 +149,11 @@ public void run() {
nextButton.setVisibility(View.GONE);

setCameraPreviewEnabled(true);
setReadQrStatus(ReadQrStatus.PENDING);
showQrCode(publicKeyQr);

setReadQrStatus(ReadQrStatus.PENDING);
scanFeedbackText.setText(R.string.scan_qr_hint);
qrContentInfo.setText(R.string.public_key);
break;
case KEY_EXCHANGE_DONE:
prevButton.setImageDrawable(getDrawable(R.drawable.ic_close));
Expand All @@ -157,17 +162,23 @@ public void run() {
nextButton.setVisibility(View.VISIBLE);

setCameraPreviewEnabled(false);
setReadQrStatus(ReadQrStatus.SUCCESS);
showQrCode(publicKeyQr);

setReadQrStatus(ReadQrStatus.SUCCESS);
scanFeedbackText.setText(R.string.public_key_received_hint);
qrContentInfo.setText(R.string.public_key);
break;
case DATA_EXCHANGE:
prevButton.setImageDrawable(getDrawable(R.drawable.ic_arrow_back));
prevButton.setVisibility(View.VISIBLE);
nextButton.setVisibility(View.GONE);

setCameraPreviewEnabled(true);
setReadQrStatus(ReadQrStatus.PENDING);
showQrCode(dataQr);

setReadQrStatus(ReadQrStatus.PENDING);
scanFeedbackText.setText(R.string.scan_qr_hint);
qrContentInfo.setText(R.string.sync_information);
break;
case DATA_EXCHANGE_DONE:
prevButton.setImageDrawable(getDrawable(R.drawable.ic_arrow_back));
Expand All @@ -176,16 +187,18 @@ public void run() {
nextButton.setVisibility(View.VISIBLE);

setCameraPreviewEnabled(false);
setReadQrStatus(ReadQrStatus.SUCCESS);
showQrCode(dataQr);

setReadQrStatus(ReadQrStatus.SUCCESS);
scanFeedbackText.setText(R.string.sync_info_received_hint);
qrContentInfo.setText(R.string.public_key);
break;
}
}
});
}

private void setReadQrStatus(ReadQrStatus status) {

currentReadQrStatus = status;

final Drawable drawable;
Expand All @@ -206,17 +219,26 @@ private void setReadQrStatus(ReadQrStatus status) {
break;
default:
drawable = getDrawable(R.drawable.ic_info_outline);
color = getColor(R.color.status_green);
color = getColor(R.color.status_amber);
break;
}

runOnUiThread(new Runnable() {
@Override
public void run() {
qrInfo.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
qrInfo.setCompoundDrawableTintList(ColorStateList.valueOf(color));
}
});
scanFeedbackText.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
scanFeedbackText.setCompoundDrawableTintList(ColorStateList.valueOf(color));

if (currentReadQrStatus == ReadQrStatus.SUCCESS) {
continueHintView.setVisibility(View.VISIBLE);
scanFeedbackView.setBackgroundTintList(ColorStateList.valueOf(getColor(R.color.white)));
qrFrame.setBackgroundTintList(ColorStateList.valueOf(getColor(R.color.white)));

fragmentContainer.animate().alpha(0).setDuration(250).start();
} else {
continueHintView.setVisibility(View.GONE);
scanFeedbackView.setBackgroundTintList(ColorStateList.valueOf(getColor(R.color.white_80)));
qrFrame.setBackgroundTintList(ColorStateList.valueOf(getColor(R.color.white_80)));

fragmentContainer.animate().alpha(1).setDuration(250).start();
}
}

private void setCameraPreviewEnabled(boolean enabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
public class LoginActivity extends AppCompatActivity {

private PreferenceManager preferenceManager;
private MispRestClient mispRestClient;

private ConstraintLayout constraintLayout;
private TextInputLayout serverAutomationKey;
Expand All @@ -46,7 +45,6 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_login);

preferenceManager = PreferenceManager.getInstance(this);
mispRestClient = MispRestClient.getInstance(LoginActivity.this);

getWindow().setStatusBarColor(getColor(R.color.colorPrimary));

Expand Down Expand Up @@ -97,7 +95,6 @@ private void initializeViews() {
private View.OnClickListener onClickDownload = new View.OnClickListener() {
@Override
public void onClick(View v) {

final String url = Objects.requireNonNull(serverUrl.getEditText()).getText().toString();
final String authkey = Objects.requireNonNull(serverAutomationKey.getEditText()).getText().toString();

Expand All @@ -120,7 +117,7 @@ public void onClick(View v) {
return;
}

mispRestClient.initMispRestInterface(url);
final MispRestClient mispRestClient = MispRestClient.getInstance(url, authkey);

// display progress bar
progressBar.setVisibility(View.VISIBLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);

mispRestClient = MispRestClient.getInstance(this);
preferenceManager = PreferenceManager.getInstance(this);
mispRestClient = MispRestClient.getInstance(preferenceManager.getServerUrl(), preferenceManager.getAuthKey());

init();
populateInformationViews();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import androidx.appcompat.app.AppCompatActivity;

import lu.circl.mispbump.auxiliary.PreferenceManager;
import lu.circl.mispbump.models.restModels.User;

/**
* This activity navigates to the next activity base on the user status.
* This is the first activity that gets loaded when the user starts the app.
* Starts either the login or home activity.
*/
public class StartUpActivity extends AppCompatActivity {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_upload);

preferenceManager = PreferenceManager.getInstance(UploadActivity.this);
restClient = MispRestClient.getInstance(this);
restClient = MispRestClient.getInstance(preferenceManager.getServerUrl(), preferenceManager.getAuthKey());

parseExtra();
initViews();
Expand Down
Loading

0 comments on commit 8bdab94

Please sign in to comment.