diff --git a/.idea/misc.xml b/.idea/misc.xml
index f16a0ff..ce9de9a 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -53,7 +53,7 @@
-
+
diff --git a/app/build.gradle b/app/build.gradle
index 1234879..a7a530f 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -8,8 +8,8 @@ android {
applicationId "org.kore.kolabnotes.android"
minSdkVersion 16
targetSdkVersion 23
- versionCode 69
- versionName "2.0.4"
+ versionCode 70
+ versionName "2.0.5"
//Running test
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 8ae1416..db43de3 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -180,18 +180,6 @@
android:label="@string/title_activity_settings"
android:theme="@style/SettingsTheme">
-
-
-
-
-
-
-
diff --git a/app/src/main/java/org/kore/kolabnotes/android/fragment/OverviewFragment.java b/app/src/main/java/org/kore/kolabnotes/android/fragment/OverviewFragment.java
index a863f9e..5674ba8 100644
--- a/app/src/main/java/org/kore/kolabnotes/android/fragment/OverviewFragment.java
+++ b/app/src/main/java/org/kore/kolabnotes/android/fragment/OverviewFragment.java
@@ -60,6 +60,7 @@
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
import com.mikepenz.materialdrawer.model.interfaces.IProfile;
+import org.kore.kolab.notes.Attachment;
import org.kore.kolab.notes.AuditInformation;
import org.kore.kolab.notes.Colors;
import org.kore.kolab.notes.Identification;
@@ -76,8 +77,11 @@
import org.kore.kolabnotes.android.TagListActivity;
import org.kore.kolabnotes.android.Utils;
import org.kore.kolabnotes.android.adapter.NoteAdapter;
+import org.kore.kolabnotes.android.content.AccountIdentifier;
import org.kore.kolabnotes.android.content.ActiveAccount;
import org.kore.kolabnotes.android.content.ActiveAccountRepository;
+import org.kore.kolabnotes.android.content.AttachmentRepository;
+import org.kore.kolabnotes.android.content.ModificationRepository;
import org.kore.kolabnotes.android.content.NoteRepository;
import org.kore.kolabnotes.android.content.NoteSorting;
import org.kore.kolabnotes.android.content.NoteTagRepository;
@@ -141,6 +145,8 @@ public class OverviewFragment extends Fragment implements /*NoteAdapter.NoteSele
private TagRepository tagRepository;
private NoteTagRepository notetagRepository;
private ActiveAccountRepository activeAccountRepository;
+ private AttachmentRepository attachmentRepository;
+ private ModificationRepository modificationRepository;
private Toolbar toolbar;
private Drawer mDrawer;
@@ -175,6 +181,8 @@ public void onAttach(Activity activity) {
tagRepository = new TagRepository(activity);
notetagRepository = new NoteTagRepository(activity);
activeAccountRepository = new ActiveAccountRepository(activity);
+ attachmentRepository = new AttachmentRepository(activity);
+ modificationRepository = new ModificationRepository(activity);
}
@Override
@@ -194,6 +202,16 @@ public void onActivityCreated(Bundle savedInstanceState) {
mAccountManager = AccountManager.get(activity);
Account[] accounts = mAccountManager.getAccountsByType(AuthenticatorActivity.ARG_ACCOUNT_TYPE);
+ Set allAccounts = activeAccountRepository.getAllAccounts();
+
+ if(allAccounts.size() == 0){
+ allAccounts = activeAccountRepository.initAccounts();
+ }
+
+ //For accounts cleanup
+ Set accountsForDeletion = new LinkedHashSet<>(allAccounts);
+ accountsForDeletion.remove(new AccountIdentifier("local","Notes"));
+
ProfileDrawerItem[] profiles = new ProfileDrawerItem[accounts.length+1];
profiles[0] = new ProfileDrawerItem().withName(getResources().getString(R.string.drawer_account_local)).withTag("Notes").withIcon(getResources().getDrawable(R.drawable.ic_local_account));
@@ -225,8 +243,13 @@ public void onActivityCreated(Bundle savedInstanceState) {
}
profiles[i+1] = item;
+
+ accountsForDeletion.remove(new AccountIdentifier(email,rootFolder));
}
+ cleanupAccounts(accountsForDeletion);
+
+
mAccount = new AccountHeaderBuilder()
.withActivity(this.activity)
.withHeaderBackground(R.drawable.drawer_header_background)
@@ -324,6 +347,37 @@ public void run() {
setListState();
}
+ private void cleanupAccounts(Set accountsForDeletion){
+ Thread cleanupThread = new Thread(new AccountsCleaner(accountsForDeletion));
+ cleanupThread.start();
+ }
+
+ final class AccountsCleaner implements Runnable{
+
+ private final Set accountsForDeletion;
+
+ public AccountsCleaner(Set accountsForDeletion){
+ this.accountsForDeletion = accountsForDeletion;
+ }
+
+ @Override
+ public void run() {
+ for(AccountIdentifier identifier : accountsForDeletion){
+ String email = identifier.getAccount();
+ String rootFolder = identifier.getRootFolder();
+ activeAccountRepository.deleteAccount(identifier.getAccount(),identifier.getRootFolder());
+
+ notesRepository.cleanAccount(email, rootFolder);
+ notetagRepository.cleanAccount(email,rootFolder);
+ tagRepository.cleanAccount(email,rootFolder);
+ attachmentRepository.cleanAccount(email, rootFolder);
+ modificationRepository.cleanAccount(email,rootFolder);
+
+ Log.d("AccountsCleaner","Cleaned account:"+identifier);
+ }
+ }
+ }
+
@Override
public void onPause() {
super.onPause();
diff --git a/app/src/main/java/org/kore/kolabnotes/android/security/AccountDeletionReceiver.java b/app/src/main/java/org/kore/kolabnotes/android/security/AccountDeletionReceiver.java
deleted file mode 100644
index e4483ae..0000000
--- a/app/src/main/java/org/kore/kolabnotes/android/security/AccountDeletionReceiver.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package org.kore.kolabnotes.android.security;
-
-import android.accounts.Account;
-import android.accounts.AccountManager;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-
-import org.kore.kolabnotes.android.content.AccountIdentifier;
-import org.kore.kolabnotes.android.content.ActiveAccountRepository;
-import org.kore.kolabnotes.android.content.AttachmentRepository;
-import org.kore.kolabnotes.android.content.ModificationRepository;
-import org.kore.kolabnotes.android.content.NoteRepository;
-import org.kore.kolabnotes.android.content.NoteTagRepository;
-import org.kore.kolabnotes.android.content.TagRepository;
-
-import java.util.LinkedHashSet;
-import java.util.Set;
-
-public class AccountDeletionReceiver extends BroadcastReceiver {
- public AccountDeletionReceiver() {
- }
-
- @Override
- public void onReceive(Context context, Intent intent) {
- final NoteTagRepository noteTagRepository = new NoteTagRepository(context);
- final TagRepository tagRepository = new TagRepository(context);
- final NoteRepository noteRepository = new NoteRepository(context);
- final ModificationRepository modificationRepository = new ModificationRepository(context);
- final AttachmentRepository attachmentRepository = new AttachmentRepository(context);
- final ActiveAccountRepository activeAccountRepository = new ActiveAccountRepository(context);
- final AccountManager accountManager = AccountManager.get(context);
- final Account[] accounts = accountManager.getAccounts();
-
- Set allAccounts = activeAccountRepository.getAllAccounts();
-
- if(allAccounts.size() == 0){
- allAccounts = activeAccountRepository.initAccounts();
- }
-
- Set accountsForDeletion = new LinkedHashSet<>(allAccounts);
-
- for(Account account : accounts){
- String email = accountManager.getUserData(account, AuthenticatorActivity.KEY_EMAIL);
- String rootFolder = accountManager.getUserData(account,AuthenticatorActivity.KEY_ROOT_FOLDER);
-
- accountsForDeletion.remove(new AccountIdentifier(email,rootFolder));
- }
- accountsForDeletion.remove(new AccountIdentifier("local","Notes"));
-
- for(AccountIdentifier identifier : accountsForDeletion){
- String email = identifier.getAccount();
- String rootFolder = identifier.getRootFolder();
- activeAccountRepository.deleteAccount(identifier.getAccount(),identifier.getRootFolder());
-
- noteRepository.cleanAccount(email,rootFolder);
- noteTagRepository.cleanAccount(email,rootFolder);
- tagRepository.cleanAccount(email,rootFolder);
- attachmentRepository.cleanAccount(email, rootFolder);
- modificationRepository.cleanAccount(email,rootFolder);
- }
- }
-}