upgraded dependencies

add option to remove single sync (WIP)
pull/9/head
Felix Prahl-Kamps 2019-10-13 18:24:46 +02:00
parent 24b26f5140
commit a1c3a37a32
11 changed files with 62 additions and 135 deletions

View File

@ -32,17 +32,17 @@ repositories {
dependencies {
// android
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.android.material:material:1.1.0-beta01'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.preference:preference:1.1.0-rc01'
implementation 'androidx.preference:preference:1.1.0'
// retrofit
implementation 'com.squareup.retrofit2:retrofit:2.6.1'
implementation 'com.squareup.retrofit2:converter-gson:2.6.1'
implementation 'com.squareup.retrofit2:converter-gson:2.6.2'
implementation 'com.squareup.okhttp3:logging-interceptor:4.1.0'
// barcode reading

View File

@ -3,6 +3,9 @@
xmlns:tools="http://schemas.android.com/tools"
package="lu.circl.mispbump">
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="false"
android:hardwareAccelerated="true"
@ -47,8 +50,5 @@
android:parentActivityName=".activities.HomeActivity"
android:theme="@style/AppTheme.Translucent" />
</application>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>

View File

@ -24,20 +24,15 @@ import lu.circl.mispbump.adapters.SyncInfoAdapter;
import lu.circl.mispbump.auxiliary.MispRestClient;
import lu.circl.mispbump.auxiliary.PreferenceManager;
import lu.circl.mispbump.interfaces.OnRecyclerItemClickListener;
import lu.circl.mispbump.models.ExchangeInformation;
import lu.circl.mispbump.models.SyncInformation;
import lu.circl.mispbump.models.restModels.MispServer;
import lu.circl.mispbump.models.restModels.MispUser;
import lu.circl.mispbump.models.restModels.Organisation;
import lu.circl.mispbump.models.restModels.Role;
import lu.circl.mispbump.models.restModels.Server;
import lu.circl.mispbump.models.restModels.User;
public class HomeActivity extends AppCompatActivity {
private PreferenceManager preferenceManager;
private MispRestClient restClient;
private List<SyncInformation> syncInformationList;
private RecyclerView recyclerView;
@ -56,8 +51,6 @@ public class HomeActivity extends AppCompatActivity {
setContentView(R.layout.activity_home);
preferenceManager = PreferenceManager.getInstance(this);
Pair<String, String> credentials = preferenceManager.getUserCredentials();
restClient = MispRestClient.getInstance(credentials.first, credentials.second);
initViews();
initRecyclerView();
@ -89,10 +82,6 @@ public class HomeActivity extends AppCompatActivity {
protected void onResume() {
super.onResume();
refreshRecyclerView();
if (!preferenceManager.getShowLocalSyncsOnly()) {
fetchRemoteSyncs();
}
}
@ -171,98 +160,4 @@ public class HomeActivity extends AppCompatActivity {
});
}
}
private void fetchRemoteSyncs() {
restClient.getAllServers(new MispRestClient.AllRawServersCallback() {
@Override
public void success(List<MispServer> mispServers) {
if (mispServers.size() < 1) {
return;
}
List<SyncInformation> syncInformationList = preferenceManager.getSyncInformationList();
for (MispServer mispServer : mispServers) {
boolean existsOffline = false;
for (SyncInformation syncInformation : syncInformationList) {
int localServerId = syncInformation.getRemote().getServer().getId();
int remoteServerId = mispServer.getServer().getId();
if (remoteServerId == localServerId) {
existsOffline = true;
break;
}
}
if (!existsOffline) {
// mispServer is not locally available
SyncInformation syncInformation = new SyncInformation();
ExchangeInformation local = new ExchangeInformation();
local.setOrganisation(preferenceManager.getUserOrganisation().toSyncOrganisation());
User syncUser = preferenceManager.getUserInfo().toSyncUser();
syncUser.setAuthkey("Could not be recovered");
syncUser.setPassword("Could not be recovered");
local.setSyncUser(syncUser);
local.setServer(new Server(preferenceManager.getUserCredentials().first));
ExchangeInformation remote = new ExchangeInformation();
remote.setServer(mispServer.getServer());
restClient.getOrganisation(mispServer.getRemoteOrganisation().getId(), new MispRestClient.OrganisationCallback() {
@Override
public void success(Organisation organisation) {
remote.setOrganisation(organisation);
restClient.getAllUsers(new MispRestClient.AllMispUsersCallback() {
@Override
public void success(List<MispUser> users) {
for (MispUser mispUser : users) {
boolean isSyncUserRole = false;
Role[] roles = preferenceManager.getRoles();
for (Role role : roles) {
if (role.getId().equals(mispUser.getRole().getId())) {
isSyncUserRole = role.isSyncUserRole();
break;
}
}
if (mispUser.getOrganisation().getId().equals(organisation.getId()) && isSyncUserRole) {
remote.setSyncUser(mispUser.getUser());
syncInformation.setLocal(local);
syncInformation.setRemote(remote);
preferenceManager.addSyncInformation(syncInformation);
refreshRecyclerView();
}
}
}
@Override
public void failure(String error) {
Snackbar.make(recyclerView, error, Snackbar.LENGTH_LONG).show();
}
});
}
@Override
public void failure(String error) {
Snackbar.make(recyclerView, error, Snackbar.LENGTH_LONG).show();
}
});
}
}
}
@Override
public void failure(String error) {
Snackbar.make(recyclerView, error, Snackbar.LENGTH_SHORT).show();
}
});
}
}

View File

@ -5,7 +5,9 @@ import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.MenuItem;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
@ -37,6 +39,17 @@ public class PreferenceActivity extends AppCompatActivity {
.commit();
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == android.R.id.home) {
onBackPressed();
return true;
}
return false;
}
public static class PreferencesFragment extends PreferenceFragmentCompat {
private Context context;

View File

@ -75,11 +75,15 @@ public class ProfileActivity extends AppCompatActivity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.menu_delete_profile) {
if (item.getItemId() == android.R.id.home) {
onBackPressed();
return true;
} else if (item.getItemId() == R.id.menu_delete_profile) {
clearDeviceAndLogOut();
return true;
}
return super.onOptionsItemSelected(item);
return false;
}

View File

@ -3,8 +3,11 @@ package lu.circl.mispbump.activities;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
@ -25,6 +28,7 @@ public class SyncInfoDetailActivity extends AppCompatActivity {
public static String EXTRA_SYNC_INFO_UUID = "EXTRA_SYNC_INFO_UUID";
private UUID syncUUID;
private PreferenceManager preferenceManager;
private SyncInformation syncInformation;
@ -42,10 +46,11 @@ public class SyncInfoDetailActivity extends AppCompatActivity {
setContentView(R.layout.activity_sync_info_detail);
preferenceManager = PreferenceManager.getInstance(SyncInfoDetailActivity.this);
syncInformation = preferenceManager.getSyncInformation(getExtraUuid());
syncUUID = getExtraUuid();
syncInformation = preferenceManager.getSyncInformation(syncUUID);
if (syncInformation == null) {
throw new RuntimeException("Could not find UploadInformation with UUID {" + getExtraUuid().toString() + "}");
throw new RuntimeException("Could not find UploadInformation with UUID {" + syncUUID + "}");
}
initToolbar();
@ -53,6 +58,22 @@ public class SyncInfoDetailActivity extends AppCompatActivity {
populateContent();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_sync_detail, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
// preferenceManager.removeUploadInformation(syncUUID);
if (item.getItemId() == android.R.id.home) {
onBackPressed();
return true;
} else return item.getItemId() == R.id.menu_delete_sync;
}
@Override
protected void onPause() {
super.onPause();

View File

@ -53,7 +53,7 @@ public class SyncInfoAdapter extends RecyclerView.Adapter<SyncInfoAdapter.ViewHo
holder.orgName.setText(item.getRemote().getOrganisation().getName());
if (item.getHasUnpublishedChanges()) {
if (!item.getHasUnpublishedChanges()) {
ImageViewCompat.setImageTintList(holder.syncStatus, ColorStateList.valueOf(context.getColor(R.color.status_green)));
holder.syncStatus.setImageResource(R.drawable.ic_check_outline);
} else {
@ -61,21 +61,6 @@ public class SyncInfoAdapter extends RecyclerView.Adapter<SyncInfoAdapter.ViewHo
holder.syncStatus.setImageResource(R.drawable.ic_error_outline);
}
// switch (item.getCurrentSyncStatus()) {
// case COMPLETE:
// ImageViewCompat.setImageTintList(holder.syncStatus, ColorStateList.valueOf(context.getColor(R.color.status_green)));
// holder.syncStatus.setImageResource(R.drawable.ic_check_outline);
// break;
// case FAILURE:
// ImageViewCompat.setImageTintList(holder.syncStatus, ColorStateList.valueOf(context.getColor(R.color.status_red)));
// holder.syncStatus.setImageResource(R.drawable.ic_error_outline);
// break;
// case PENDING:
// ImageViewCompat.setImageTintList(holder.syncStatus, ColorStateList.valueOf(context.getColor(R.color.status_amber)));
// holder.syncStatus.setImageResource(R.drawable.ic_pending);
// break;
// }
holder.rootView.setOnClickListener(view -> onRecyclerPositionClickListener.onClick(view, position));
}

View File

@ -60,7 +60,7 @@ public class MispRestClient {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(url)
.addConverterFactory(GsonConverterFactory.create())
.client(getCustomClient(true, true, authkey))
.client(getCustomClient(false, false, authkey))
.build();
mispService = retrofit.create(MispService.class);

View File

@ -3,6 +3,7 @@
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.SyncInfoDetailActivity"

View File

@ -5,7 +5,6 @@
<item
android:id="@+id/menu_delete_profile"
android:icon="@drawable/ic_delete_forever"
android:title="Delete Profile"
/>
android:title="Delete Profile" />
</menu>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_delete_sync"
android:icon="@drawable/ic_delete_forever"
android:title="Delete Synchronisation" />
</menu>