After Width: | Height: | Size: 92 KiB |
After Width: | Height: | Size: 94 KiB |
After Width: | Height: | Size: 169 KiB |
After Width: | Height: | Size: 3.4 MiB |
After Width: | Height: | Size: 118 KiB |
After Width: | Height: | Size: 3.3 MiB |
After Width: | Height: | Size: 119 KiB |
After Width: | Height: | Size: 110 KiB |
After Width: | Height: | Size: 170 KiB |
After Width: | Height: | Size: 100 KiB |
After Width: | Height: | Size: 100 KiB |
After Width: | Height: | Size: 115 KiB |
|
@ -5,12 +5,12 @@ import android.os.Bundle;
|
|||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -30,7 +30,6 @@ public class UploadActivity extends AppCompatActivity {
|
|||
private PreferenceManager preferenceManager;
|
||||
private UploadInformation uploadInformation;
|
||||
|
||||
private CoordinatorLayout rootLayout;
|
||||
private MispRestClient restClient;
|
||||
private UploadAction availableAction, orgAction, userAction, serverAction;
|
||||
|
||||
|
@ -90,6 +89,7 @@ public class UploadActivity extends AppCompatActivity {
|
|||
}
|
||||
};
|
||||
|
||||
private FloatingActionButton fab;
|
||||
|
||||
private boolean errorWhileUpload;
|
||||
|
||||
|
@ -143,14 +143,18 @@ public class UploadActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
private void initViews() {
|
||||
rootLayout = findViewById(R.id.rootLayout);
|
||||
getWindow().setStatusBarColor(getColor(R.color.colorPrimary));
|
||||
|
||||
fab = findViewById(R.id.fab);
|
||||
fab.hide();
|
||||
|
||||
// toolbar
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
ActionBar ab = getSupportActionBar();
|
||||
assert ab != null;
|
||||
ab.setDisplayShowTitleEnabled(true);
|
||||
|
||||
ab.setDisplayShowTitleEnabled(false);
|
||||
ab.setDisplayHomeAsUpEnabled(true);
|
||||
ab.setHomeAsUpIndicator(R.drawable.ic_close);
|
||||
|
||||
|
@ -167,6 +171,44 @@ public class UploadActivity extends AppCompatActivity {
|
|||
preferenceManager.addUploadInformation(uploadInformation);
|
||||
}
|
||||
|
||||
private void setUploadActionState(UploadAction uploadAction, UploadAction.UploadState state, @Nullable String error) {
|
||||
uploadAction.setCurrentUploadState(state);
|
||||
uploadAction.setError(error);
|
||||
|
||||
switch (state) {
|
||||
case PENDING:
|
||||
if (fab.isShown()) {
|
||||
fab.hide();
|
||||
}
|
||||
break;
|
||||
case LOADING:
|
||||
errorWhileUpload = false;
|
||||
if (fab.isShown()) {
|
||||
fab.hide();
|
||||
}
|
||||
break;
|
||||
case DONE:
|
||||
errorWhileUpload = false;
|
||||
break;
|
||||
case ERROR:
|
||||
uploadInformation.setCurrentSyncStatus(UploadInformation.SyncStatus.FAILURE);
|
||||
|
||||
fab.setImageResource(R.drawable.ic_autorenew);
|
||||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
setUploadActionState(availableAction, UploadAction.UploadState.LOADING, null);
|
||||
startUpload();
|
||||
}
|
||||
});
|
||||
if (!fab.isShown()) {
|
||||
fab.show();
|
||||
}
|
||||
errorWhileUpload = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private User generateSyncUser(Organisation organisation) {
|
||||
User syncUser = new User();
|
||||
|
@ -204,35 +246,16 @@ public class UploadActivity extends AppCompatActivity {
|
|||
|
||||
private void mispAvailable(boolean available, String error) {
|
||||
if (available) {
|
||||
availableAction.setCurrentUploadState(UploadAction.UploadState.DONE);
|
||||
availableAction.setError(null);
|
||||
|
||||
setUploadActionState(availableAction, UploadAction.UploadState.DONE, null);
|
||||
restClient.addOrganisation(uploadInformation.getRemote().organisation, organisationCallback);
|
||||
} else {
|
||||
availableAction.setCurrentUploadState(UploadAction.UploadState.ERROR);
|
||||
availableAction.setError(error);
|
||||
uploadInformation.setCurrentSyncStatus(UploadInformation.SyncStatus.FAILURE);
|
||||
errorWhileUpload = true;
|
||||
|
||||
Snackbar sb = Snackbar.make(rootLayout, error, Snackbar.LENGTH_INDEFINITE);
|
||||
|
||||
sb.setAction("Retry", new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
availableAction.setError(null);
|
||||
availableAction.setCurrentUploadState(UploadAction.UploadState.LOADING);
|
||||
errorWhileUpload = false;
|
||||
startUpload();
|
||||
}
|
||||
});
|
||||
|
||||
sb.show();
|
||||
setUploadActionState(availableAction, UploadAction.UploadState.ERROR, error);
|
||||
}
|
||||
}
|
||||
|
||||
private void organisationAdded(Organisation organisation) {
|
||||
if (organisation != null) {
|
||||
orgAction.setCurrentUploadState(UploadAction.UploadState.DONE);
|
||||
setUploadActionState(orgAction, UploadAction.UploadState.DONE, null);
|
||||
uploadInformation.getRemote().organisation.id = organisation.id;
|
||||
restClient.addUser(generateSyncUser(organisation), userCallback);
|
||||
} else {
|
||||
|
@ -245,10 +268,7 @@ public class UploadActivity extends AppCompatActivity {
|
|||
|
||||
@Override
|
||||
public void failure(String error) {
|
||||
uploadInformation.setCurrentSyncStatus(UploadInformation.SyncStatus.FAILURE);
|
||||
orgAction.setCurrentUploadState(UploadAction.UploadState.ERROR);
|
||||
orgAction.setError(error);
|
||||
errorWhileUpload = true;
|
||||
setUploadActionState(orgAction, UploadAction.UploadState.ERROR, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -256,7 +276,7 @@ public class UploadActivity extends AppCompatActivity {
|
|||
|
||||
private void userAdded(User user) {
|
||||
if (user != null) {
|
||||
userAction.setCurrentUploadState(UploadAction.UploadState.DONE);
|
||||
setUploadActionState(userAction, UploadAction.UploadState.DONE, null);
|
||||
restClient.getAllServers(allServersCallback);
|
||||
} else {
|
||||
restClient.getUser(uploadInformation.getRemote().syncUserEmail, new MispRestClient.UserCallback() {
|
||||
|
@ -267,10 +287,7 @@ public class UploadActivity extends AppCompatActivity {
|
|||
|
||||
@Override
|
||||
public void failure(String error) {
|
||||
uploadInformation.setCurrentSyncStatus(UploadInformation.SyncStatus.FAILURE);
|
||||
userAction.setCurrentUploadState(UploadAction.UploadState.ERROR);
|
||||
userAction.setError(error);
|
||||
errorWhileUpload = true;
|
||||
setUploadActionState(userAction, UploadAction.UploadState.ERROR, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -290,20 +307,26 @@ public class UploadActivity extends AppCompatActivity {
|
|||
|
||||
restClient.addServer(serverToUpload, serverCallback);
|
||||
} else {
|
||||
serverAction.setCurrentUploadState(UploadAction.UploadState.ERROR);
|
||||
setUploadActionState(serverAction, UploadAction.UploadState.ERROR, "Could not retrieve server information");
|
||||
}
|
||||
}
|
||||
|
||||
private void serverAdded(Server server) {
|
||||
if (server != null) {
|
||||
serverAction.setCurrentUploadState(UploadAction.UploadState.DONE);
|
||||
setUploadActionState(serverAction, UploadAction.UploadState.DONE, null);
|
||||
uploadInformation.setCurrentSyncStatus(UploadInformation.SyncStatus.COMPLETE);
|
||||
saveCurrentState();
|
||||
|
||||
fab.setImageResource(R.drawable.ic_check);
|
||||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
fab.show();
|
||||
} else {
|
||||
uploadInformation.setCurrentSyncStatus(UploadInformation.SyncStatus.FAILURE);
|
||||
serverAction.setCurrentUploadState(UploadAction.UploadState.ERROR);
|
||||
serverAction.setError("Could not add server");
|
||||
errorWhileUpload = true;
|
||||
setUploadActionState(serverAction, UploadAction.UploadState.ERROR, "Could not add server");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,10 +69,10 @@ public class UploadAction extends ConstraintLayout {
|
|||
public void setError(String error) {
|
||||
if (error == null) {
|
||||
errorView.setVisibility(GONE);
|
||||
} else {
|
||||
errorView.setText(error);
|
||||
errorView.setVisibility(VISIBLE);
|
||||
}
|
||||
|
||||
errorView.setText(error);
|
||||
errorView.setVisibility(VISIBLE);
|
||||
}
|
||||
|
||||
public void setCurrentUploadState(UploadState state) {
|
||||
|
|
|
@ -4,6 +4,6 @@
|
|||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:fillColor="#FFFFFF"
|
||||
android:pathData="M12,6v1.79c0,0.45 0.54,0.67 0.85,0.35l2.79,-2.79c0.2,-0.2 0.2,-0.51 0,-0.71l-2.79,-2.79c-0.31,-0.31 -0.85,-0.09 -0.85,0.36L12,4c-4.42,0 -8,3.58 -8,8 0,1.04 0.2,2.04 0.57,2.95 0.27,0.67 1.13,0.85 1.64,0.34 0.27,-0.27 0.38,-0.68 0.23,-1.04C6.15,13.56 6,12.79 6,12c0,-3.31 2.69,-6 6,-6zM17.79,8.71c-0.27,0.27 -0.38,0.69 -0.23,1.04 0.28,0.7 0.44,1.46 0.44,2.25 0,3.31 -2.69,6 -6,6v-1.79c0,-0.45 -0.54,-0.67 -0.85,-0.35l-2.79,2.79c-0.2,0.2 -0.2,0.51 0,0.71l2.79,2.79c0.31,0.31 0.85,0.09 0.85,-0.35L12,20c4.42,0 8,-3.58 8,-8 0,-1.04 -0.2,-2.04 -0.57,-2.95 -0.27,-0.67 -1.13,-0.85 -1.64,-0.34z"/>
|
||||
</vector>
|
||||
|
|
|
@ -19,7 +19,17 @@
|
|||
android:layout_height="?attr/actionBarSize"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
|
||||
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
|
||||
android:background="@color/colorPrimary" />
|
||||
android:background="@color/colorPrimary">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/toolbarTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
|
||||
android:text="Upload"
|
||||
android:layout_gravity="center"/>
|
||||
|
||||
</androidx.appcompat.widget.Toolbar>
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
|
@ -38,7 +48,7 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:description="Check if instance is available" />
|
||||
app:description="MISP instance available" />
|
||||
|
||||
<lu.circl.mispbump.customViews.UploadAction
|
||||
android:id="@+id/orgAction"
|
||||
|
@ -73,4 +83,12 @@
|
|||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:description="Add sync server" />
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="16dp"
|
||||
android:src="@drawable/ic_check"/>
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|