From d902aa8c7f283bfabf1cda4b36e9bbe69479f877 Mon Sep 17 00:00:00 2001 From: Konrad Renner Date: Mon, 2 May 2016 10:51:55 +0200 Subject: [PATCH] - Attachment support - Attachment preview for tablets - Bugfixing --- app/build.gradle | 2 +- app/src/main/AndroidManifest.xml | 4 ++++ .../content/ActiveAccountRepository.java | 24 +++++++++++++++++++ .../android/content/DatabaseHelper.java | 19 +-------------- .../security/AccountDeletionReceiver.java | 7 +++++- 5 files changed, 36 insertions(+), 20 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1945301..6398751 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,7 +9,7 @@ android { minSdkVersion 16 targetSdkVersion 23 versionCode 68 - versionName "2.0.2" + versionName "2.0.3" //Running test testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index da8f180..8ae1416 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -187,6 +187,10 @@ + + diff --git a/app/src/main/java/org/kore/kolabnotes/android/content/ActiveAccountRepository.java b/app/src/main/java/org/kore/kolabnotes/android/content/ActiveAccountRepository.java index ecf58df..79adcfa 100644 --- a/app/src/main/java/org/kore/kolabnotes/android/content/ActiveAccountRepository.java +++ b/app/src/main/java/org/kore/kolabnotes/android/content/ActiveAccountRepository.java @@ -1,11 +1,14 @@ package org.kore.kolabnotes.android.content; +import android.accounts.Account; +import android.accounts.AccountManager; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import org.kore.kolabnotes.android.Utils; +import org.kore.kolabnotes.android.security.AuthenticatorActivity; import java.sql.Timestamp; import java.util.ArrayList; @@ -49,6 +52,27 @@ public Set getAllAccounts() { return accounts; } + public Set initAccounts() { + LinkedHashSet ret = new LinkedHashSet<>(); + final SQLiteDatabase db = ConnectionManager.getDatabase(context); + + insertAccount(db, "local", "Notes"); + ret.add(new AccountIdentifier("local","Notes")); + + final AccountManager accountManager = AccountManager.get(context); + final Account[] accounts = accountManager.getAccounts(); + + for(Account account : accounts){ + String email = accountManager.getUserData(account, AuthenticatorActivity.KEY_EMAIL); + String rootFolder = accountManager.getUserData(account,AuthenticatorActivity.KEY_ROOT_FOLDER); + + insertAccount(db, email, rootFolder); + ret.add(new AccountIdentifier(email, rootFolder)); + } + + return ret; + } + public void insertAccount(String account, String rootFolder) { insertAccount(ConnectionManager.getDatabase(context), account, rootFolder); } diff --git a/app/src/main/java/org/kore/kolabnotes/android/content/DatabaseHelper.java b/app/src/main/java/org/kore/kolabnotes/android/content/DatabaseHelper.java index d704f24..87a40f4 100644 --- a/app/src/main/java/org/kore/kolabnotes/android/content/DatabaseHelper.java +++ b/app/src/main/java/org/kore/kolabnotes/android/content/DatabaseHelper.java @@ -193,24 +193,7 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL(CREATE_ATTACHMENT); } if(oldVersion < 7){ - createAccountsTable(db); + db.execSQL(CREATE_ACCOUNTS); } } - - private void createAccountsTable(SQLiteDatabase db) { - db.execSQL(CREATE_ACCOUNTS); - final ActiveAccountRepository activeAccountRepository = new ActiveAccountRepository(context); - activeAccountRepository.insertAccount(db, "local", "Notes"); - - final AccountManager accountManager = AccountManager.get(context); - final Account[] accounts = accountManager.getAccounts(); - - for(Account account : accounts){ - String email = accountManager.getUserData(account, AuthenticatorActivity.KEY_EMAIL); - String rootFolder = accountManager.getUserData(account,AuthenticatorActivity.KEY_ROOT_FOLDER); - - activeAccountRepository.insertAccount(db, email, rootFolder); - } - } - } \ No newline at end of file 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 index 3aef815..e4483ae 100644 --- a/app/src/main/java/org/kore/kolabnotes/android/security/AccountDeletionReceiver.java +++ b/app/src/main/java/org/kore/kolabnotes/android/security/AccountDeletionReceiver.java @@ -32,7 +32,12 @@ public void onReceive(Context context, Intent intent) { final AccountManager accountManager = AccountManager.get(context); final Account[] accounts = accountManager.getAccounts(); - final Set allAccounts = activeAccountRepository.getAllAccounts(); + Set allAccounts = activeAccountRepository.getAllAccounts(); + + if(allAccounts.size() == 0){ + allAccounts = activeAccountRepository.initAccounts(); + } + Set accountsForDeletion = new LinkedHashSet<>(allAccounts); for(Account account : accounts){