2019-08-22 16:58:50 +02:00
|
|
|
package lu.circl.mispbump.activities;
|
|
|
|
|
|
|
|
|
2019-10-04 17:42:16 +02:00
|
|
|
import android.animation.Animator;
|
2019-08-22 16:58:50 +02:00
|
|
|
import android.animation.ValueAnimator;
|
|
|
|
import android.content.Intent;
|
2019-10-04 17:42:16 +02:00
|
|
|
import android.graphics.drawable.AnimatedVectorDrawable;
|
2019-08-22 16:58:50 +02:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.View;
|
2019-10-04 17:42:16 +02:00
|
|
|
import android.view.animation.DecelerateInterpolator;
|
2019-08-22 16:58:50 +02:00
|
|
|
import android.widget.LinearLayout;
|
2019-10-04 17:42:16 +02:00
|
|
|
import android.widget.TextView;
|
2019-08-22 16:58:50 +02:00
|
|
|
|
|
|
|
import androidx.appcompat.app.ActionBar;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import androidx.appcompat.widget.Toolbar;
|
|
|
|
|
|
|
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
2019-10-06 20:18:58 +02:00
|
|
|
import com.google.android.material.snackbar.Snackbar;
|
2019-08-22 16:58:50 +02:00
|
|
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
import lu.circl.mispbump.R;
|
|
|
|
import lu.circl.mispbump.auxiliary.PreferenceManager;
|
|
|
|
import lu.circl.mispbump.customViews.MaterialPasswordView;
|
2019-10-04 17:42:16 +02:00
|
|
|
import lu.circl.mispbump.customViews.MaterialPreferenceSwitch;
|
2019-08-22 16:58:50 +02:00
|
|
|
import lu.circl.mispbump.customViews.MaterialPreferenceText;
|
|
|
|
import lu.circl.mispbump.models.SyncInformation;
|
|
|
|
|
|
|
|
|
|
|
|
public class SyncInfoDetailActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
public static String EXTRA_SYNC_INFO_UUID = "EXTRA_SYNC_INFO_UUID";
|
|
|
|
|
|
|
|
private PreferenceManager preferenceManager;
|
|
|
|
private SyncInformation syncInformation;
|
|
|
|
|
|
|
|
private boolean fabMenuExpanded;
|
2019-10-04 17:42:16 +02:00
|
|
|
private boolean dataLocallyChanged;
|
2019-08-22 16:58:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2019-10-04 17:42:16 +02:00
|
|
|
setContentView(R.layout.activity_sync_info_detail_v2);
|
2019-08-22 16:58:50 +02:00
|
|
|
|
|
|
|
preferenceManager = PreferenceManager.getInstance(SyncInfoDetailActivity.this);
|
|
|
|
syncInformation = preferenceManager.getSyncInformation(getExtraUuid());
|
|
|
|
|
|
|
|
if (syncInformation == null) {
|
|
|
|
throw new RuntimeException("Could not find UploadInformation with UUID {" + getExtraUuid().toString() + "}");
|
|
|
|
}
|
|
|
|
|
|
|
|
initToolbar();
|
|
|
|
initFabMenu();
|
|
|
|
populateContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPause() {
|
|
|
|
super.onPause();
|
2019-10-04 17:42:16 +02:00
|
|
|
|
|
|
|
if (dataLocallyChanged) {
|
|
|
|
syncInformation.setSyncedWithRemote(false);
|
|
|
|
}
|
|
|
|
|
2019-08-22 16:58:50 +02:00
|
|
|
preferenceManager.addSyncInformation(syncInformation);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private UUID getExtraUuid() {
|
|
|
|
return (UUID) getIntent().getSerializableExtra(EXTRA_SYNC_INFO_UUID);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initToolbar() {
|
|
|
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
|
|
|
setSupportActionBar(toolbar);
|
|
|
|
|
|
|
|
ActionBar ab = getSupportActionBar();
|
|
|
|
assert ab != null;
|
|
|
|
|
|
|
|
ab.setDisplayHomeAsUpEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initFabMenu() {
|
|
|
|
FloatingActionButton fab = findViewById(R.id.fab_main);
|
|
|
|
FloatingActionButton fabUpload = findViewById(R.id.fab_upload);
|
|
|
|
FloatingActionButton fabDownload = findViewById(R.id.fab_download);
|
|
|
|
|
|
|
|
LinearLayout uploadLayout = findViewById(R.id.layout_upload);
|
|
|
|
LinearLayout downloadLayout = findViewById(R.id.layout_download);
|
|
|
|
|
2019-10-04 17:42:16 +02:00
|
|
|
TextView uploadText = findViewById(R.id.fab_upload_text);
|
|
|
|
TextView downloadText = findViewById(R.id.fab_download_text);
|
|
|
|
|
|
|
|
View menuBackground = findViewById(R.id.menu_background);
|
|
|
|
|
2019-08-22 16:58:50 +02:00
|
|
|
uploadLayout.setVisibility(View.GONE);
|
|
|
|
downloadLayout.setVisibility(View.GONE);
|
|
|
|
|
2019-10-04 17:42:16 +02:00
|
|
|
int animationSpeed = 200;
|
|
|
|
|
|
|
|
ValueAnimator openAnimation = ValueAnimator.ofFloat(0f, 1f);
|
|
|
|
openAnimation.setDuration(animationSpeed);
|
|
|
|
openAnimation.setInterpolator(new DecelerateInterpolator());
|
|
|
|
openAnimation.addUpdateListener(updateAnimation -> {
|
|
|
|
float x = (float) updateAnimation.getAnimatedValue();
|
|
|
|
|
|
|
|
fabUpload.setAlpha(x);
|
|
|
|
fabUpload.setTranslationY((1 - x) * 50);
|
|
|
|
uploadText.setAlpha(x);
|
|
|
|
uploadText.setTranslationX((1 - x) * -200);
|
|
|
|
|
|
|
|
fabDownload.setAlpha(x);
|
|
|
|
fabDownload.setTranslationY((1 - x) * 50);
|
|
|
|
downloadText.setAlpha(x);
|
|
|
|
downloadText.setTranslationX((1 - x) * -200);
|
|
|
|
|
|
|
|
menuBackground.setAlpha(x * 0.9f);
|
|
|
|
});
|
|
|
|
openAnimation.addListener(new Animator.AnimatorListener() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationStart(Animator animator) {
|
|
|
|
uploadLayout.setVisibility(View.VISIBLE);
|
|
|
|
downloadLayout.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animator) {
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public void onAnimationCancel(Animator animator) {
|
|
|
|
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public void onAnimationRepeat(Animator animator) {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ValueAnimator closeAnimation = ValueAnimator.ofFloat(1f, 0f);
|
|
|
|
closeAnimation.setDuration(animationSpeed);
|
|
|
|
closeAnimation.setInterpolator(new DecelerateInterpolator());
|
|
|
|
closeAnimation.addUpdateListener(updateAnimation -> {
|
|
|
|
float x = (float) updateAnimation.getAnimatedValue();
|
|
|
|
|
|
|
|
fabUpload.setAlpha(x);
|
|
|
|
fabUpload.setTranslationY((1 - x) * 50);
|
|
|
|
uploadText.setAlpha(x);
|
|
|
|
uploadText.setTranslationX((1 - x) * -200);
|
|
|
|
|
|
|
|
fabDownload.setAlpha(x);
|
|
|
|
fabDownload.setTranslationY((1 - x) * 50);
|
|
|
|
downloadText.setAlpha(x);
|
|
|
|
downloadText.setTranslationX((1 - x) * -200);
|
|
|
|
|
|
|
|
menuBackground.setAlpha(x * 0.9f);
|
|
|
|
});
|
|
|
|
closeAnimation.addListener(new Animator.AnimatorListener() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationStart(Animator animator) {
|
|
|
|
uploadLayout.setVisibility(View.VISIBLE);
|
|
|
|
downloadLayout.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animator) {
|
2019-08-22 16:58:50 +02:00
|
|
|
uploadLayout.setVisibility(View.GONE);
|
|
|
|
downloadLayout.setVisibility(View.GONE);
|
2019-10-04 17:42:16 +02:00
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public void onAnimationCancel(Animator animator) {
|
|
|
|
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public void onAnimationRepeat(Animator animator) {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
AnimatedVectorDrawable open = (AnimatedVectorDrawable) getDrawable(R.drawable.animated_arrow_cloud_down);
|
|
|
|
AnimatedVectorDrawable close = (AnimatedVectorDrawable) getDrawable(R.drawable.animated_arrow_down_cloud);
|
2019-08-22 16:58:50 +02:00
|
|
|
|
2019-10-04 17:42:16 +02:00
|
|
|
View.OnClickListener expandCollapseClick = view -> {
|
|
|
|
if (fabMenuExpanded) {
|
|
|
|
menuBackground.setClickable(false);
|
|
|
|
|
|
|
|
fab.setImageDrawable(close);
|
|
|
|
close.start();
|
|
|
|
|
|
|
|
closeAnimation.start();
|
2019-08-22 16:58:50 +02:00
|
|
|
fabMenuExpanded = false;
|
|
|
|
} else {
|
2019-10-04 17:42:16 +02:00
|
|
|
menuBackground.setClickable(true);
|
|
|
|
|
|
|
|
fab.setImageDrawable(open);
|
|
|
|
open.start();
|
2019-08-22 16:58:50 +02:00
|
|
|
|
2019-10-04 17:42:16 +02:00
|
|
|
openAnimation.start();
|
2019-08-22 16:58:50 +02:00
|
|
|
fabMenuExpanded = true;
|
|
|
|
}
|
2019-10-04 17:42:16 +02:00
|
|
|
};
|
2019-08-22 16:58:50 +02:00
|
|
|
|
2019-10-04 17:42:16 +02:00
|
|
|
menuBackground.setOnClickListener(expandCollapseClick);
|
|
|
|
menuBackground.setClickable(false);
|
|
|
|
fab.setOnClickListener(expandCollapseClick);
|
2019-08-22 16:58:50 +02:00
|
|
|
|
2019-10-04 17:42:16 +02:00
|
|
|
fabUpload.setOnClickListener(view -> {
|
2019-08-22 16:58:50 +02:00
|
|
|
preferenceManager.addSyncInformation(syncInformation);
|
|
|
|
Intent upload = new Intent(SyncInfoDetailActivity.this, UploadActivity.class);
|
|
|
|
upload.putExtra(UploadActivity.EXTRA_SYNC_INFO_UUID, syncInformation.getUuid().toString());
|
|
|
|
startActivity(upload);
|
|
|
|
});
|
|
|
|
|
|
|
|
fabDownload.setOnClickListener(view -> {
|
2019-10-06 20:18:58 +02:00
|
|
|
// TODO download content from MISP instance
|
|
|
|
Snackbar.make(view, "Not implemented yet", Snackbar.LENGTH_LONG).show();
|
2019-08-22 16:58:50 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void populateContent() {
|
|
|
|
|
|
|
|
// information
|
|
|
|
|
|
|
|
MaterialPreferenceText name = findViewById(R.id.name);
|
2019-08-22 17:14:25 +02:00
|
|
|
name.setSubtitle(syncInformation.getRemote().getOrganisation().getName());
|
2019-08-22 16:58:50 +02:00
|
|
|
|
|
|
|
MaterialPreferenceText uuid = findViewById(R.id.uuid);
|
2019-08-22 17:14:25 +02:00
|
|
|
uuid.setSubtitle(syncInformation.getRemote().getOrganisation().getUuid());
|
2019-08-22 16:58:50 +02:00
|
|
|
|
|
|
|
MaterialPreferenceText sector = findViewById(R.id.sector);
|
2019-08-22 17:14:25 +02:00
|
|
|
sector.setSubtitle(syncInformation.getRemote().getOrganisation().getSector());
|
2019-08-22 16:58:50 +02:00
|
|
|
|
|
|
|
MaterialPreferenceText description = findViewById(R.id.description);
|
2019-08-22 17:14:25 +02:00
|
|
|
description.setSubtitle(syncInformation.getRemote().getOrganisation().getDescription());
|
2019-08-22 16:58:50 +02:00
|
|
|
|
|
|
|
// settings
|
|
|
|
|
2019-10-04 17:42:16 +02:00
|
|
|
MaterialPreferenceSwitch allowSelfSigned = findViewById(R.id.switch_allow_self_signed);
|
2019-08-22 17:14:25 +02:00
|
|
|
allowSelfSigned.setChecked(syncInformation.getRemote().getServer().getSelfSigned());
|
2019-10-04 17:42:16 +02:00
|
|
|
allowSelfSigned.setOnCheckedChangeListener((cb, b) -> {
|
2019-08-22 17:14:25 +02:00
|
|
|
syncInformation.getRemote().getServer().setSelfSigned(b);
|
2019-10-04 17:42:16 +02:00
|
|
|
dataLocallyChanged = true;
|
|
|
|
});
|
2019-08-22 16:58:50 +02:00
|
|
|
|
2019-10-04 17:42:16 +02:00
|
|
|
MaterialPreferenceSwitch allowPush = findViewById(R.id.switch_allow_push);
|
|
|
|
allowPush.setChecked(syncInformation.getRemote().getServer().getPush());
|
|
|
|
allowPush.setOnCheckedChangeListener((cb, b) -> {
|
|
|
|
syncInformation.getRemote().getServer().setPush(b);
|
|
|
|
dataLocallyChanged = true;
|
2019-08-22 16:58:50 +02:00
|
|
|
});
|
|
|
|
|
2019-10-04 17:42:16 +02:00
|
|
|
MaterialPreferenceSwitch allowPull = findViewById(R.id.switch_allow_pull);
|
|
|
|
allowPull.setChecked(syncInformation.getRemote().getServer().getPull());
|
|
|
|
allowPull.setOnCheckedChangeListener((cb, b) -> {
|
|
|
|
syncInformation.getRemote().getServer().setPull(b);
|
|
|
|
dataLocallyChanged = true;
|
|
|
|
});
|
2019-08-22 16:58:50 +02:00
|
|
|
|
2019-10-04 17:42:16 +02:00
|
|
|
MaterialPreferenceSwitch allowCache = findViewById(R.id.switch_allow_cache);
|
|
|
|
allowCache.setChecked(syncInformation.getRemote().getServer().getCachingEnabled());
|
|
|
|
allowCache.setOnCheckedChangeListener((cb, b) -> {
|
|
|
|
syncInformation.getRemote().getServer().setCachingEnabled(b);
|
|
|
|
dataLocallyChanged = true;
|
|
|
|
});
|
2019-08-22 16:58:50 +02:00
|
|
|
|
|
|
|
// credentials
|
|
|
|
|
|
|
|
MaterialPreferenceText email = findViewById(R.id.email);
|
|
|
|
email.setSubtitle(syncInformation.getLocal().getSyncUser().getEmail());
|
|
|
|
|
|
|
|
MaterialPasswordView password = findViewById(R.id.password);
|
|
|
|
password.setPassword(syncInformation.getLocal().getSyncUser().getPassword());
|
|
|
|
|
|
|
|
MaterialPasswordView authkey = findViewById(R.id.authkey);
|
|
|
|
authkey.setPassword(syncInformation.getLocal().getSyncUser().getAuthkey());
|
|
|
|
}
|
|
|
|
}
|