2019-08-22 16:58:50 +02:00
|
|
|
package lu.circl.mispbump.activities;
|
|
|
|
|
|
|
|
|
|
|
|
import android.animation.ValueAnimator;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.graphics.Color;
|
|
|
|
import android.graphics.drawable.ColorDrawable;
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.ViewGroupOverlay;
|
|
|
|
import android.widget.CheckBox;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.appcompat.app.ActionBar;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import androidx.appcompat.widget.Toolbar;
|
|
|
|
|
|
|
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
|
|
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
import lu.circl.mispbump.R;
|
|
|
|
import lu.circl.mispbump.auxiliary.PreferenceManager;
|
|
|
|
import lu.circl.mispbump.customViews.MaterialPasswordView;
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_sync_info_detail);
|
|
|
|
|
|
|
|
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();
|
|
|
|
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);
|
|
|
|
|
|
|
|
uploadLayout.setVisibility(View.GONE);
|
|
|
|
downloadLayout.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
fab.setOnClickListener(view -> {
|
|
|
|
if (fabMenuExpanded) {
|
|
|
|
uploadLayout.setVisibility(View.GONE);
|
|
|
|
downloadLayout.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
fabMenuExpanded = false;
|
|
|
|
} else {
|
|
|
|
uploadLayout.setVisibility(View.VISIBLE);
|
|
|
|
downloadLayout.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
fabMenuExpanded = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
fabUpload.setOnClickListener(view -> {
|
|
|
|
|
|
|
|
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 -> {
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
CheckBox allowSelfSigned = findViewById(R.id.checkbox_self_signed);
|
2019-08-22 17:14:25 +02:00
|
|
|
allowSelfSigned.setChecked(syncInformation.getRemote().getServer().getSelfSigned());
|
2019-08-22 16:58:50 +02:00
|
|
|
allowSelfSigned.setOnCheckedChangeListener((compoundButton, b) -> {
|
2019-08-22 17:14:25 +02:00
|
|
|
syncInformation.getRemote().getServer().setSelfSigned(b);
|
2019-08-22 16:58:50 +02:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
CheckBox push = findViewById(R.id.checkbox_push);
|
2019-08-22 17:14:25 +02:00
|
|
|
push.setChecked(syncInformation.getRemote().getServer().getPush());
|
|
|
|
push.setOnCheckedChangeListener((compoundButton, b) -> syncInformation.getRemote().getServer().setPush(b));
|
2019-08-22 16:58:50 +02:00
|
|
|
|
|
|
|
CheckBox pull = findViewById(R.id.checkbox_pull);
|
2019-08-22 17:14:25 +02:00
|
|
|
pull.setChecked(syncInformation.getRemote().getServer().getPull());
|
|
|
|
pull.setOnCheckedChangeListener((compundButton, b) -> syncInformation.getRemote().getServer().setPull(b));
|
2019-08-22 16:58:50 +02:00
|
|
|
|
|
|
|
CheckBox cache = findViewById(R.id.checkbox_cache);
|
2019-08-22 17:14:25 +02:00
|
|
|
cache.setChecked(syncInformation.getRemote().getServer().getCachingEnabled());
|
|
|
|
cache.setOnCheckedChangeListener((compoundButton, b) -> syncInformation.getRemote().getServer().setCachingEnabled(b));
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void applyDim(@NonNull ViewGroup parent, float dimAmount) {
|
|
|
|
// ViewGroup root = (ViewGroup) getWindow().getDecorView().getRootView();
|
|
|
|
Drawable dim = new ColorDrawable(Color.BLACK);
|
|
|
|
dim.setBounds(0, 0, parent.getWidth(), parent.getHeight());
|
|
|
|
|
|
|
|
ValueAnimator valueAnimator = ValueAnimator.ofFloat(dimAmount);
|
|
|
|
|
|
|
|
valueAnimator.addUpdateListener(valueAnim -> {
|
|
|
|
float value = (float) valueAnim.getAnimatedValue();
|
|
|
|
dim.setAlpha((int) (255 * value));
|
|
|
|
ViewGroupOverlay overlay = parent.getOverlay();
|
|
|
|
overlay.add(dim);
|
|
|
|
});
|
|
|
|
|
|
|
|
valueAnimator.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void clearDim(@NonNull ViewGroup parent) {
|
|
|
|
ViewGroupOverlay overlay = parent.getOverlay();
|
|
|
|
overlay.clear();
|
|
|
|
}
|
|
|
|
}
|