Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/stefan-niedermann/nextcloud-notes.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Niedermann <info@niedermann.it>2021-04-02 20:03:41 +0300
committerStefan Niedermann <info@niedermann.it>2021-04-02 20:15:54 +0300
commite38805a4d86e3e3a757677689e86cdbbd136a5ea (patch)
tree36f292ebcba5b5abcb656eb40c2a6aaf8497963c /app/src/main/java
parent1a0e99fd4d456e02ef38332fc1a50ad842f0142a (diff)
parent0b48efa8b20c2dfca87f3ca78bdcb65227160093 (diff)
Merge branch 'master' into 831-room
# Conflicts: # app/build.gradle # app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedActivity.java # app/src/main/java/it/niedermann/owncloud/notes/branding/BrandingUtil.java # app/src/main/java/it/niedermann/owncloud/notes/edit/BaseNoteFragment.java # app/src/main/java/it/niedermann/owncloud/notes/edit/NotePreviewFragment.java # app/src/main/java/it/niedermann/owncloud/notes/persistence/AbstractNotesDatabase.java # app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_19_20.java # app/src/main/res/values-hu-rHU/strings.xml
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/LockedActivity.java9
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedActivity.java4
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedDialogFragment.java8
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedFragment.java2
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedPreferenceCategory.java12
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedSnackbar.java6
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedSwitchPreference.java9
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/branding/BrandingUtil.java50
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/edit/NotePreviewFragment.java5
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/AbstractNotesDatabase.java0
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java2
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClient.java2
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClientV02.java2
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClientV1.java2
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java12
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_19_20.java234
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_20_21.java232
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesFragment.java31
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/shared/model/ServerResponse.java2
19 files changed, 308 insertions, 316 deletions
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/LockedActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/LockedActivity.java
index 7ce7206b..7a58282f 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/LockedActivity.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/LockedActivity.java
@@ -3,14 +3,15 @@ package it.niedermann.owncloud.notes;
import android.app.KeyguardManager;
import android.content.Context;
import android.content.Intent;
-import android.os.Build;
import android.os.Bundle;
import android.util.Log;
+import android.view.WindowManager;
import androidx.annotation.Nullable;
+import androidx.preference.PreferenceManager;
-import it.niedermann.owncloud.notes.exception.ExceptionHandler;
import it.niedermann.owncloud.notes.branding.BrandedActivity;
+import it.niedermann.owncloud.notes.exception.ExceptionHandler;
public abstract class LockedActivity extends BrandedActivity {
@@ -25,6 +26,10 @@ public abstract class LockedActivity extends BrandedActivity {
Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this));
+ if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(getString(R.string.pref_key_prevent_screen_capture), false)) {
+ getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
+ }
+
if (isTaskRoot()) {
askToUnlock();
}
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedActivity.java
index 70b07af0..55d492d6 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedActivity.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedActivity.java
@@ -38,9 +38,7 @@ public abstract class BrandedActivity extends AppCompatActivity implements Brand
getTheme().resolveAttribute(R.attr.colorAccent, typedValue, true);
colorAccent = typedValue.data;
- if (BrandingUtil.isBrandingEnabled(this)) {
- readBrandColors(this).observe(this, (pair) -> applyBrand(pair.first, pair.second));
- }
+ readBrandColors(this).observe(this, (pair) -> applyBrand(pair.first, pair.second));
}
@Override
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedDialogFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedDialogFragment.java
index 63eb2a69..57d24adf 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedDialogFragment.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedDialogFragment.java
@@ -14,11 +14,9 @@ public abstract class BrandedDialogFragment extends DialogFragment implements Br
@Nullable Context context = getContext();
if (context != null) {
- if (BrandingUtil.isBrandingEnabled(context)) {
- @ColorInt final int mainColor = BrandingUtil.readBrandMainColor(context);
- @ColorInt final int textColor = BrandingUtil.readBrandTextColor(context);
- applyBrand(mainColor, textColor);
- }
+ @ColorInt final int mainColor = BrandingUtil.readBrandMainColor(context);
+ @ColorInt final int textColor = BrandingUtil.readBrandTextColor(context);
+ applyBrand(mainColor, textColor);
}
}
}
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedFragment.java
index 5752bff8..b134919c 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedFragment.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedFragment.java
@@ -32,7 +32,7 @@ public abstract class BrandedFragment extends Fragment implements Branded {
colorPrimary = typedValue.data;
@Nullable Context context = getContext();
- if (context != null && BrandingUtil.isBrandingEnabled(context)) {
+ if (context != null) {
@ColorInt final int mainColor = BrandingUtil.readBrandMainColor(context);
@ColorInt final int textColor = BrandingUtil.readBrandTextColor(context);
applyBrand(mainColor, textColor);
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedPreferenceCategory.java b/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedPreferenceCategory.java
index d2bcd274..7d75a412 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedPreferenceCategory.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedPreferenceCategory.java
@@ -34,13 +34,11 @@ public class BrandedPreferenceCategory extends PreferenceCategory {
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
- if (BrandingUtil.isBrandingEnabled(getContext())) {
- final View v = holder.itemView.findViewById(android.R.id.title);
- @Nullable final Context context = getContext();
- if (context != null && v instanceof TextView) {
- @ColorInt final int mainColor = getSecondaryForegroundColorDependingOnTheme(context, BrandingUtil.readBrandMainColor(context));
- ((TextView) v).setTextColor(mainColor);
- }
+ final View v = holder.itemView.findViewById(android.R.id.title);
+ @Nullable final Context context = getContext();
+ if (context != null && v instanceof TextView) {
+ @ColorInt final int mainColor = getSecondaryForegroundColorDependingOnTheme(context, BrandingUtil.readBrandMainColor(context));
+ ((TextView) v).setTextColor(mainColor);
}
}
}
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedSnackbar.java b/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedSnackbar.java
index aabd3f04..1bb39297 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedSnackbar.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedSnackbar.java
@@ -15,10 +15,8 @@ public class BrandedSnackbar {
@NonNull
public static Snackbar make(@NonNull View view, @NonNull CharSequence text, @Snackbar.Duration int duration) {
final Snackbar snackbar = Snackbar.make(view, text, duration);
- if (BrandingUtil.isBrandingEnabled(view.getContext())) {
- int color = BrandingUtil.readBrandMainColor(view.getContext());
- snackbar.setActionTextColor(ColorUtil.INSTANCE.isColorDark(color) ? Color.WHITE : color);
- }
+ final int color = BrandingUtil.readBrandMainColor(view.getContext());
+ snackbar.setActionTextColor(ColorUtil.INSTANCE.isColorDark(color) ? Color.WHITE : color);
return snackbar;
}
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedSwitchPreference.java b/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedSwitchPreference.java
index 6d673dd1..d81d3df2 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedSwitchPreference.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedSwitchPreference.java
@@ -59,13 +59,8 @@ public class BrandedSwitchPreference extends SwitchPreference implements Branded
@Override
public void applyBrand(@ColorInt int mainColor, @ColorInt int textColor) {
- if (BrandingUtil.isBrandingEnabled(getContext())) {
- this.mainColor = mainColor;
- this.textColor = textColor;
- } else {
- this.mainColor = getContext().getResources().getColor(R.color.defaultBrand);
- this.textColor = Color.WHITE;
- }
+ this.mainColor = mainColor;
+ this.textColor = textColor;
// onBindViewHolder is called after applyBrand, therefore we have to store the given values and apply them later.
applyBrand();
}
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandingUtil.java b/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandingUtil.java
index a22cabe9..bc0faca7 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandingUtil.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandingUtil.java
@@ -19,7 +19,6 @@ import androidx.core.graphics.drawable.DrawableCompat;
import androidx.core.util.Pair;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MediatorLiveData;
-import androidx.lifecycle.MutableLiveData;
import androidx.preference.PreferenceManager;
import it.niedermann.android.sharedpreferences.SharedPreferenceIntLiveData;
@@ -38,11 +37,6 @@ public class BrandingUtil {
}
- public static boolean isBrandingEnabled(@NonNull Context context) {
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
- return prefs.getBoolean(context.getString(R.string.pref_key_branding), true);
- }
-
public static LiveData<Pair<Integer, Integer>> readBrandColors(@NonNull Context context) {
return new BrandingLiveData(context);
}
@@ -70,57 +64,41 @@ public class BrandingUtil {
}
public static LiveData<Integer> readBrandMainColorLiveData(@NonNull Context context) {
- if (BrandingUtil.isBrandingEnabled(context)) {
- SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
- Log.v(TAG, "--- Read: shared_preference_theme_main");
- return new SharedPreferenceIntLiveData(sharedPreferences, pref_key_branding_main, context.getApplicationContext().getResources().getColor(R.color.defaultBrand));
- } else {
- return new MutableLiveData<>(context.getResources().getColor(R.color.defaultBrand));
- }
+ final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
+ Log.v(TAG, "--- Read: shared_preference_theme_main");
+ return new SharedPreferenceIntLiveData(sharedPreferences, pref_key_branding_main, context.getApplicationContext().getResources().getColor(R.color.defaultBrand));
}
public static LiveData<Integer> readBrandTextColorLiveData(@NonNull Context context) {
- if (BrandingUtil.isBrandingEnabled(context)) {
- SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
- Log.v(TAG, "--- Read: shared_preference_theme_text");
- return new SharedPreferenceIntLiveData(sharedPreferences, pref_key_branding_text, Color.WHITE);
- } else {
- return new MutableLiveData<>(Color.WHITE);
- }
+ final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
+ Log.v(TAG, "--- Read: shared_preference_theme_text");
+ return new SharedPreferenceIntLiveData(sharedPreferences, pref_key_branding_text, Color.WHITE);
}
@ColorInt
public static int readBrandMainColor(@NonNull Context context) {
- if (BrandingUtil.isBrandingEnabled(context)) {
- SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
- Log.v(TAG, "--- Read: shared_preference_theme_main");
- return sharedPreferences.getInt(pref_key_branding_main, context.getApplicationContext().getResources().getColor(R.color.defaultBrand));
- } else {
- return ContextCompat.getColor(context, R.color.defaultBrand);
- }
+ final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
+ Log.v(TAG, "--- Read: shared_preference_theme_main");
+ return sharedPreferences.getInt(pref_key_branding_main, context.getApplicationContext().getResources().getColor(R.color.defaultBrand));
}
@ColorInt
public static int readBrandTextColor(@NonNull Context context) {
- if (isBrandingEnabled(context)) {
- SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
- Log.v(TAG, "--- Read: shared_preference_theme_text");
- return sharedPreferences.getInt(pref_key_branding_text, Color.WHITE);
- } else {
- return Color.WHITE;
- }
+ final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
+ Log.v(TAG, "--- Read: shared_preference_theme_text");
+ return sharedPreferences.getInt(pref_key_branding_text, Color.WHITE);
}
public static void saveBrandColors(@NonNull Context context, @ColorInt int mainColor, @ColorInt int textColor) {
final int previousMainColor = readBrandMainColor(context);
final int previousTextColor = readBrandTextColor(context);
- SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
+ final SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
Log.v(TAG, "--- Write: shared_preference_theme_main" + " | " + mainColor);
Log.v(TAG, "--- Write: shared_preference_theme_text" + " | " + textColor);
editor.putInt(pref_key_branding_main, mainColor);
editor.putInt(pref_key_branding_text, textColor);
editor.apply();
- if (isBrandingEnabled(context) && context instanceof BrandedActivity) {
+ if (context instanceof BrandedActivity) {
if (mainColor != previousMainColor || textColor != previousTextColor) {
final BrandedActivity activity = (BrandedActivity) context;
activity.runOnUiThread(() -> ActivityCompat.recreate(activity));
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/edit/NotePreviewFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/edit/NotePreviewFragment.java
index 1c73988f..67507b1b 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/edit/NotePreviewFragment.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/edit/NotePreviewFragment.java
@@ -44,6 +44,9 @@ public class NotePreviewFragment extends SearchableBaseNoteFragment implements O
private boolean noteLoaded = false;
+ @Nullable
+ private Runnable setScrollY;
+
@Override
public void onPrepareOptionsMenu(@NonNull Menu menu) {
super.onPrepareOptionsMenu(menu);
@@ -85,6 +88,8 @@ public class NotePreviewFragment extends SearchableBaseNoteFragment implements O
super.onActivityCreated(savedInstanceState);
binding.swiperefreshlayout.setOnRefreshListener(this);
+ registerInternalNoteLinkHandler();
+ binding.singleNoteContent.setMarkdownString(note.getContent(), setScrollY);
binding.singleNoteContent.setMovementMethod(LinkMovementMethod.getInstance());
final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(requireActivity().getApplicationContext());
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/AbstractNotesDatabase.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/AbstractNotesDatabase.java
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/AbstractNotesDatabase.java
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java
index 328b083c..2cd2d02b 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java
@@ -441,7 +441,7 @@ public class NoteServerSyncHelper {
try {
final Map<Long, Long> idMap = db.getIdMap(localAccount.getId());
final Calendar modified = localAccount.getModified();
- final long modifiedForServer = modified == null ? 0 : modified.getTimeInMillis() / 1000;
+ final long modifiedForServer = modified == null ? 0 : modified.getTimeInMillis() / 1_000;
final ServerResponse.NotesResponse response = notesClient.getNotes(ssoAccount, modifiedForServer, localAccount.getETag());
List<Note> remoteNotes = response.getNotes();
Set<Long> remoteIDs = new HashSet<>();
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClient.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClient.java
index 07048ec9..b7a5f3a9 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClient.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClient.java
@@ -191,7 +191,7 @@ public abstract class NotesClient {
long lastModified = 0;
final AidlNetworkRequest.PlainHeader lastModifiedHeader = response.getPlainHeader(HEADER_KEY_LAST_MODIFIED);
if (lastModifiedHeader != null)
- lastModified = new Date(lastModifiedHeader.getValue()).getTime() / 1000;
+ lastModified = new Date(lastModifiedHeader.getValue()).getTime() / 1_000;
Log.d(TAG, "ETag: " + etag + "; Last-Modified: " + lastModified + " (" + lastModified + ")");
String supportedApiVersions = null;
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClientV02.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClientV02.java
index 8e6743d9..2ee7a550 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClientV02.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClientV02.java
@@ -34,7 +34,7 @@ public class NotesClientV02 extends NotesClient {
private NoteResponse putNote(SingleSignOnAccount ssoAccount, Note note, String path, String method) throws Exception {
JSONObject paramObject = new JSONObject();
paramObject.accumulate(JSON_CONTENT, note.getContent());
- paramObject.accumulate(JSON_MODIFIED, note.getModified().getTimeInMillis() / 1000);
+ paramObject.accumulate(JSON_MODIFIED, note.getModified().getTimeInMillis() / 1_000);
paramObject.accumulate(JSON_FAVORITE, note.getFavorite());
paramObject.accumulate(JSON_CATEGORY, note.getCategory());
return new NoteResponse(requestServer(ssoAccount, path, method, null, paramObject, null));
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClientV1.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClientV1.java
index 1094b559..f685b057 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClientV1.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClientV1.java
@@ -35,7 +35,7 @@ public class NotesClientV1 extends NotesClient {
JSONObject paramObject = new JSONObject();
paramObject.accumulate(JSON_TITLE, note.getTitle());
paramObject.accumulate(JSON_CONTENT, note.getContent());
- paramObject.accumulate(JSON_MODIFIED, note.getModified().getTimeInMillis() / 1000);
+ paramObject.accumulate(JSON_MODIFIED, note.getModified().getTimeInMillis() / 1_000);
paramObject.accumulate(JSON_FAVORITE, note.getFavorite());
paramObject.accumulate(JSON_CATEGORY, note.getCategory());
return new NoteResponse(requestServer(ssoAccount, path, method, null, paramObject, null));
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java
index 9432d6fa..d53f5443 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java
@@ -1,4 +1,4 @@
- package it.niedermann.owncloud.notes.persistence;
+package it.niedermann.owncloud.notes.persistence;
import android.content.Context;
import android.content.Intent;
@@ -61,6 +61,7 @@ import it.niedermann.owncloud.notes.persistence.migration.Migration_16_17;
import it.niedermann.owncloud.notes.persistence.migration.Migration_17_18;
import it.niedermann.owncloud.notes.persistence.migration.Migration_18_19;
import it.niedermann.owncloud.notes.persistence.migration.Migration_19_20;
+import it.niedermann.owncloud.notes.persistence.migration.Migration_20_21;
import it.niedermann.owncloud.notes.persistence.migration.Migration_9_10;
import it.niedermann.owncloud.notes.shared.model.ApiVersion;
import it.niedermann.owncloud.notes.shared.model.Capabilities;
@@ -87,7 +88,7 @@ import static it.niedermann.owncloud.notes.widget.singlenote.SingleNoteWidget.up
CategoryOptions.class,
SingleNoteWidgetData.class,
NotesListWidgetData.class
- }, version = 20
+ }, version = 21
)
@TypeConverters({Converters.class})
public abstract class NotesDatabase extends RoomDatabase {
@@ -116,7 +117,8 @@ public abstract class NotesDatabase extends RoomDatabase {
new Migration_16_17(),
new Migration_17_18(),
new Migration_18_19(context),
- new Migration_19_20()
+ new Migration_19_20(context),
+ new Migration_20_21()
)
.fallbackToDestructiveMigrationOnDowngrade()
.fallbackToDestructiveMigration()
@@ -271,8 +273,8 @@ public abstract class NotesDatabase extends RoomDatabase {
if (newTitle != null) {
title = newTitle;
} else {
- if ((oldNote.getRemoteId() == null || localAccount.getPreferredApiVersion() == null || localAccount.getPreferredApiVersion().compareTo(new ApiVersion("1.0", 0, 0)) < 0) &&
- (defaultNonEmptyTitle.equals(oldNote.getTitle()))) {
+ if ((oldNote.getRemoteId() == null || localAccount.getPreferredApiVersion() == null || localAccount.getPreferredApiVersion().compareTo(new ApiVersion("1.0", 0, 0)) < 0) &&
+ (defaultNonEmptyTitle.equals(oldNote.getTitle()))) {
title = NoteUtil.generateNonEmptyNoteTitle(newContent, context);
} else {
title = oldNote.getTitle();
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_19_20.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_19_20.java
index 36630d8d..7a1d6ff3 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_19_20.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_19_20.java
@@ -1,232 +1,30 @@
package it.niedermann.owncloud.notes.persistence.migration;
-import android.content.ContentValues;
-import android.database.Cursor;
-import android.database.sqlite.SQLiteOpenHelper;
-import android.graphics.Color;
+import android.content.Context;
+import android.content.SharedPreferences;
import androidx.annotation.NonNull;
-import androidx.room.OnConflictStrategy;
-import androidx.room.RoomDatabase;
+import androidx.preference.PreferenceManager;
import androidx.room.migration.Migration;
import androidx.sqlite.db.SupportSQLiteDatabase;
-import it.niedermann.android.util.ColorUtil;
+public class Migration_19_20 extends Migration {
-public final class Migration_19_20 extends Migration {
-
- public Migration_19_20() {
- super(19, 20);
- }
+ @NonNull
+ private final Context context;
/**
- * From {@link SQLiteOpenHelper} to {@link RoomDatabase}
- * https://github.com/stefan-niedermann/nextcloud-deck/issues/531
+ * Removes <code>branding</code> from {@link SharedPreferences} because we do no longer allow to disable it.
+ *
+ * @param context {@link Context}
*/
- @Override
- public void migrate(@NonNull SupportSQLiteDatabase db) {
- dropOldIndices(db);
-
- createNewTables(db);
- createNewIndices(db);
-
- migrateAccounts(db);
- migrateCategories(db);
- migrateNotes(db);
- migrateNotesListWidgets(db);
- migrateSingleNotesWidgets(db);
-
- dropOldTables(db);
- }
-
- private static void dropOldIndices(@NonNull SupportSQLiteDatabase db) {
- db.execSQL("DROP INDEX ACCOUNTS_URL_idx");
- db.execSQL("DROP INDEX ACCOUNTS_USERNAME_idx");
- db.execSQL("DROP INDEX ACCOUNTS_ACCOUNT_NAME_idx");
- db.execSQL("DROP INDEX ACCOUNTS_ETAG_idx");
- db.execSQL("DROP INDEX ACCOUNTS_MODIFIED_idx");
- db.execSQL("DROP INDEX NOTES_REMOTEID_idx");
- db.execSQL("DROP INDEX NOTES_ACCOUNT_ID_idx");
- db.execSQL("DROP INDEX NOTES_STATUS_idx");
- db.execSQL("DROP INDEX NOTES_FAVORITE_idx");
- db.execSQL("DROP INDEX NOTES_CATEGORY_idx");
- db.execSQL("DROP INDEX NOTES_MODIFIED_idx");
- }
-
- private static void createNewTables(@NonNull SupportSQLiteDatabase db) {
- db.execSQL("CREATE TABLE `Account` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `url` TEXT NOT NULL DEFAULT '', `userName` TEXT NOT NULL DEFAULT '', `accountName` TEXT NOT NULL DEFAULT '', `eTag` TEXT, `modified` INTEGER, `apiVersion` TEXT, `color` INTEGER NOT NULL DEFAULT -16743735, `textColor` INTEGER NOT NULL DEFAULT -16777216, `capabilitiesETag` TEXT)");
- db.execSQL("CREATE TABLE `CategoryOptions` (`accountId` INTEGER NOT NULL, `category` TEXT NOT NULL, `sortingMethod` INTEGER, PRIMARY KEY(`accountId`, `category`), FOREIGN KEY(`accountId`) REFERENCES `Account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )");
- db.execSQL("CREATE TABLE `Note` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `remoteId` INTEGER, `accountId` INTEGER NOT NULL, `status` TEXT NOT NULL, `title` TEXT NOT NULL DEFAULT '', `category` TEXT NOT NULL DEFAULT '', `modified` INTEGER, `content` TEXT NOT NULL DEFAULT '', `favorite` INTEGER NOT NULL DEFAULT 0, `eTag` TEXT, `excerpt` TEXT NOT NULL DEFAULT '', `scrollY` INTEGER NOT NULL DEFAULT 0, FOREIGN KEY(`accountId`) REFERENCES `Account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )");
- db.execSQL("CREATE TABLE `NotesListWidgetData` (`mode` INTEGER NOT NULL, `category` TEXT, `id` INTEGER NOT NULL, `accountId` INTEGER NOT NULL, `themeMode` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`accountId`) REFERENCES `Account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`accountId`, `category`) REFERENCES `CategoryOptions`(`accountId`, `category`) ON UPDATE NO ACTION ON DELETE CASCADE )");
- db.execSQL("CREATE TABLE `SingleNoteWidgetData` (`noteId` INTEGER NOT NULL, `id` INTEGER NOT NULL, `accountId` INTEGER NOT NULL, `themeMode` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`accountId`) REFERENCES `Account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`noteId`) REFERENCES `Note`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )");
- }
-
- private static void createNewIndices(@NonNull SupportSQLiteDatabase db) {
- db.execSQL("CREATE INDEX `IDX_ACCOUNT_ACCOUNTNAME` ON `Account` (`accountName`)");
- db.execSQL("CREATE INDEX `IDX_ACCOUNT_ETAG` ON `Account` (`eTag`)");
- db.execSQL("CREATE INDEX `IDX_ACCOUNT_MODIFIED` ON `Account` (`modified`)");
- db.execSQL("CREATE INDEX `IDX_ACCOUNT_URL` ON `Account` (`url`)");
- db.execSQL("CREATE INDEX `IDX_ACCOUNT_USERNAME` ON `Account` (`userName`)");
- db.execSQL("CREATE INDEX `IDX_CATEGORIYOPTIONS_ACCOUNTID` ON `CategoryOptions` (`accountId`)");
- db.execSQL("CREATE INDEX `IDX_CATEGORIYOPTIONS_CATEGORY` ON `CategoryOptions` (`category`)");
- db.execSQL("CREATE INDEX `IDX_CATEGORIYOPTIONS_SORTING_METHOD` ON `CategoryOptions` (`sortingMethod`)");
- db.execSQL("CREATE INDEX `IDX_NOTESLISTWIDGETDATA_ACCOUNTID` ON `NotesListWidgetData` (`accountId`)");
- db.execSQL("CREATE INDEX `IDX_NOTESLISTWIDGETDATA_CATEGORY` ON `NotesListWidgetData` (`category`)");
- db.execSQL("CREATE INDEX `IDX_NOTESLISTWIDGETDATA_ACCOUNT_CATEGORY` ON `NotesListWidgetData` (`accountId`, `category`)");
- db.execSQL("CREATE INDEX `IDX_NOTE_ACCOUNTID` ON `Note` (`accountId`)");
- db.execSQL("CREATE INDEX `IDX_NOTE_CATEGORY` ON `Note` (`category`)");
- db.execSQL("CREATE INDEX `IDX_NOTE_FAVORITE` ON `Note` (`favorite`)");
- db.execSQL("CREATE INDEX `IDX_NOTE_MODIFIED` ON `Note` (`modified`)");
- db.execSQL("CREATE INDEX `IDX_NOTE_REMOTEID` ON `Note` (`remoteId`)");
- db.execSQL("CREATE INDEX `IDX_NOTE_STATUS` ON `Note` (`status`)");
- db.execSQL("CREATE INDEX `IDX_SINGLENOTEWIDGETDATA_ACCOUNTID` ON `SingleNoteWidgetData` (`accountId`)");
- db.execSQL("CREATE INDEX `IDX_SINGLENOTEWIDGETDATA_NOTEID` ON `SingleNoteWidgetData` (`noteId`)");
-
- db.execSQL("CREATE UNIQUE INDEX `IDX_UNIQUE_CATEGORYOPTIONS_ACCOUNT_CATEGORY` ON `CategoryOptions` (`accountId`, `category`)");
-
- db.execSQL("CREATE TRIGGER TRG_CLEANUP_CATEGORIES_DEL AFTER DELETE ON Note BEGIN DELETE FROM CategoryOptions WHERE CategoryOptions.category NOT IN (SELECT Note.category FROM Note WHERE Note.accountId = CategoryOptions.accountId); END;");
- db.execSQL("CREATE TRIGGER TRG_CLEANUP_CATEGORIES_UPD AFTER UPDATE ON Note BEGIN DELETE FROM CategoryOptions WHERE CategoryOptions.category NOT IN (SELECT Note.category FROM Note WHERE Note.accountId = CategoryOptions.accountId); END;");
-
- }
-
- private static void migrateAccounts(@NonNull SupportSQLiteDatabase db) {
- final Cursor cursor = db.query("SELECT * FROM ACCOUNTS", null);
- final ContentValues values = new ContentValues(10);
-
- final int COLUMN_POSITION_ID = cursor.getColumnIndex("ID");
- final int COLUMN_POSITION_URL = cursor.getColumnIndex("URL");
- final int COLUMN_POSITION_USERNAME = cursor.getColumnIndex("USERNAME");
- final int COLUMN_POSITION_ACCOUNT_NAME = cursor.getColumnIndex("ACCOUNT_NAME");
- final int COLUMN_POSITION_ETAG = cursor.getColumnIndex("ETAG");
- final int COLUMN_POSITION_MODIFIED = cursor.getColumnIndex("MODIFIED");
- final int COLUMN_POSITION_API_VERSION = cursor.getColumnIndex("API_VERSION");
- final int COLUMN_POSITION_COLOR = cursor.getColumnIndex("COLOR");
- final int COLUMN_POSITION_TEXT_COLOR = cursor.getColumnIndex("TEXT_COLOR");
- final int COLUMN_POSITION_CAPABILITIES_ETAG = cursor.getColumnIndex("CAPABILITIES_ETAG");
-
- while (cursor.moveToNext()) {
- values.put("ID", cursor.getInt(COLUMN_POSITION_ID));
- values.put("URL", cursor.getString(COLUMN_POSITION_URL));
- values.put("USERNAME", cursor.getString(COLUMN_POSITION_USERNAME));
- values.put("ACCOUNTNAME", cursor.getString(COLUMN_POSITION_ACCOUNT_NAME));
- values.put("ETAG", cursor.getString(COLUMN_POSITION_ETAG));
- values.put("MODIFIED", cursor.getLong(COLUMN_POSITION_MODIFIED));
- values.put("APIVERSION", cursor.getString(COLUMN_POSITION_API_VERSION));
- try {
- values.put("COLOR", Color.parseColor(ColorUtil.INSTANCE.formatColorToParsableHexString(cursor.getString(COLUMN_POSITION_COLOR))));
- } catch (Exception e) {
- e.printStackTrace();
- values.put("COLOR", -16743735);
- }
- try {
- values.put("TEXTCOLOR", Color.parseColor(ColorUtil.INSTANCE.formatColorToParsableHexString(cursor.getString(COLUMN_POSITION_TEXT_COLOR))));
- } catch (Exception e) {
- e.printStackTrace();
- values.put("TEXTCOLOR", -16777216);
- }
- values.put("CAPABILITIESETAG", cursor.getString(COLUMN_POSITION_CAPABILITIES_ETAG));
- db.insert("ACCOUNT", OnConflictStrategy.REPLACE, values);
- }
- cursor.close();
- }
-
- private static void migrateCategories(@NonNull SupportSQLiteDatabase db) {
- final Cursor cursor = db.query("SELECT * FROM CATEGORIES", null);
- final ContentValues values = new ContentValues(3);
-
- final int COLUMN_POSITION_ACCOUNT_ID = cursor.getColumnIndex("CATEGORY_ACCOUNT_ID");
- final int COLUMN_POSITION_TITLE = cursor.getColumnIndex("CATEGORY_TITLE");
- final int COLUMN_POSITION_SORTING_METHOD = cursor.getColumnIndex("CATEGORY_SORTING_METHOD");
-
- while (cursor.moveToNext()) {
- values.put("ACCOUNTID", cursor.getInt(COLUMN_POSITION_ACCOUNT_ID));
- values.put("CATEGORY", cursor.getString(COLUMN_POSITION_TITLE));
- values.put("SORTINGMETHOD", cursor.getInt(COLUMN_POSITION_SORTING_METHOD));
- db.insert("CATEGORYOPTIONS", OnConflictStrategy.REPLACE, values);
- }
- cursor.close();
- }
-
- private static void migrateNotes(@NonNull SupportSQLiteDatabase db) {
- final Cursor cursor = db.query("SELECT NOTES.*, CATEGORIES.category_title as `CAT_TITLE` FROM NOTES LEFT JOIN CATEGORIES ON NOTES.category = CATEGORIES.category_id", null);
- final ContentValues values = new ContentValues(12);
-
- final int COLUMN_POSITION_ID = cursor.getColumnIndex("ID");
- final int COLUMN_POSITION_REMOTEID = cursor.getColumnIndex("REMOTEID");
- final int COLUMN_POSITION_ACCOUNT_ID = cursor.getColumnIndex("ACCOUNT_ID");
- final int COLUMN_POSITION_STATUS = cursor.getColumnIndex("STATUS");
- final int COLUMN_POSITION_TITLE = cursor.getColumnIndex("TITLE");
- final int COLUMN_POSITION_MODIFIED = cursor.getColumnIndex("MODIFIED");
- final int COLUMN_POSITION_CONTENT = cursor.getColumnIndex("CONTENT");
- final int COLUMN_POSITION_FAVORITE = cursor.getColumnIndex("FAVORITE");
- final int COLUMN_POSITION_CAT_TITLE = cursor.getColumnIndex("CAT_TITLE");
- final int COLUMN_POSITION_ETAG = cursor.getColumnIndex("ETAG");
- final int COLUMN_POSITION_EXCERPT = cursor.getColumnIndex("EXCERPT");
- final int COLUMN_POSITION_SCROLL_Y = cursor.getColumnIndex("SCROLL_Y");
-
- while (cursor.moveToNext()) {
- values.put("ID", cursor.getInt(COLUMN_POSITION_ID));
- values.put("REMOTEID", cursor.getInt(COLUMN_POSITION_REMOTEID));
- values.put("ACCOUNTID", cursor.getInt(COLUMN_POSITION_ACCOUNT_ID));
- values.put("STATUS", cursor.getString(COLUMN_POSITION_STATUS));
- values.put("TITLE", cursor.getString(COLUMN_POSITION_TITLE));
- values.put("MODIFIED", cursor.getLong(COLUMN_POSITION_MODIFIED));
- values.put("CONTENT", cursor.getString(COLUMN_POSITION_CONTENT));
- values.put("FAVORITE", cursor.getInt(COLUMN_POSITION_FAVORITE));
- values.put("CATEGORY", cursor.getString(COLUMN_POSITION_CAT_TITLE));
- values.put("ETAG", cursor.getString(COLUMN_POSITION_ETAG));
- values.put("EXCERPT", cursor.getString(COLUMN_POSITION_EXCERPT));
- values.put("SCROLLY", cursor.getString(COLUMN_POSITION_SCROLL_Y));
- db.insert("NOTE", OnConflictStrategy.REPLACE, values);
- }
- cursor.close();
- }
-
- private static void migrateNotesListWidgets(@NonNull SupportSQLiteDatabase db) {
- final Cursor cursor = db.query("SELECT WIDGET_NOTE_LISTS.*, CATEGORIES.category_title as `CATEGORY` FROM WIDGET_NOTE_LISTS LEFT JOIN CATEGORIES ON WIDGET_NOTE_LISTS.CATEGORY_ID = CATEGORIES.category_id", null);
- final ContentValues values = new ContentValues(5);
-
- final int COLUMN_POSITION_ID = cursor.getColumnIndex("ID");
- final int COLUMN_POSITION_ACCOUNT_ID = cursor.getColumnIndex("ACCOUNT_ID");
- final int COLUMN_POSITION_CATEGORY = cursor.getColumnIndex("CATEGORY");
- final int COLUMN_POSITION_MODE = cursor.getColumnIndex("MODE");
- final int COLUMN_POSITION_THEME_MODE = cursor.getColumnIndex("THEME_MODE");
-
- while (cursor.moveToNext()) {
- values.put("ID", cursor.getInt(COLUMN_POSITION_ID));
- values.put("ACCOUNTID", cursor.getInt(COLUMN_POSITION_ACCOUNT_ID));
- values.put("CATEGORY", cursor.getString(COLUMN_POSITION_CATEGORY));
- values.put("MODE", cursor.getInt(COLUMN_POSITION_MODE));
- values.put("THEMEMODE", cursor.getInt(COLUMN_POSITION_THEME_MODE));
- db.insert("NOTESLISTWIDGETDATA", OnConflictStrategy.REPLACE, values);
- }
- cursor.close();
- }
-
- private static void migrateSingleNotesWidgets(@NonNull SupportSQLiteDatabase db) {
- final Cursor cursor = db.query("SELECT * FROM WIDGET_SINGLE_NOTES", null);
- final ContentValues values = new ContentValues(4);
-
- final int COLUMN_POSITION_ID = cursor.getColumnIndex("ID");
- final int COLUMN_POSITION_ACCOUNT_ID = cursor.getColumnIndex("ACCOUNT_ID");
- final int COLUMN_POSITION_NOTE_ID = cursor.getColumnIndex("NOTE_ID");
- final int COLUMN_POSITION_THEME_MODE = cursor.getColumnIndex("THEME_MODE");
-
- while (cursor.moveToNext()) {
- values.put("ID", cursor.getInt(COLUMN_POSITION_ID));
- values.put("ACCOUNTID", cursor.getInt(COLUMN_POSITION_ACCOUNT_ID));
- values.put("NOTEID", cursor.getInt(COLUMN_POSITION_NOTE_ID));
- values.put("THEMEMODE", cursor.getInt(COLUMN_POSITION_THEME_MODE));
- db.insert("SINGLENOTEWIDGETDATA", OnConflictStrategy.REPLACE, values);
- }
- cursor.close();
+ public Migration_19_20(@NonNull Context context) {
+ super(19, 20);
+ this.context = context;
}
- private static void dropOldTables(@NonNull SupportSQLiteDatabase db) {
- db.execSQL("DROP TABLE IF EXISTS WIDGET_SINGLE_NOTES");
- db.execSQL("DROP TABLE IF EXISTS WIDGET_NOTE_LISTS");
- db.execSQL("DROP TABLE IF EXISTS CATEGORIES");
- db.execSQL("DROP TABLE IF EXISTS NOTES");
- db.execSQL("DROP TABLE IF EXISTS ACCOUNTS");
+ @Override
+ public void migrate(@NonNull SupportSQLiteDatabase database) {
+ PreferenceManager.getDefaultSharedPreferences(context).edit().remove("branding").apply();
}
-}
+} \ No newline at end of file
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_20_21.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_20_21.java
new file mode 100644
index 00000000..21e1d363
--- /dev/null
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_20_21.java
@@ -0,0 +1,232 @@
+package it.niedermann.owncloud.notes.persistence.migration;
+
+import android.content.ContentValues;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteOpenHelper;
+import android.graphics.Color;
+
+import androidx.annotation.NonNull;
+import androidx.room.OnConflictStrategy;
+import androidx.room.RoomDatabase;
+import androidx.room.migration.Migration;
+import androidx.sqlite.db.SupportSQLiteDatabase;
+
+import it.niedermann.android.util.ColorUtil;
+
+public final class Migration_20_21 extends Migration {
+
+ public Migration_20_21() {
+ super(20, 21);
+ }
+
+ /**
+ * From {@link SQLiteOpenHelper} to {@link RoomDatabase}
+ * https://github.com/stefan-niedermann/nextcloud-deck/issues/531
+ */
+ @Override
+ public void migrate(@NonNull SupportSQLiteDatabase db) {
+ dropOldIndices(db);
+
+ createNewTables(db);
+ createNewIndices(db);
+
+ migrateAccounts(db);
+ migrateCategories(db);
+ migrateNotes(db);
+ migrateNotesListWidgets(db);
+ migrateSingleNotesWidgets(db);
+
+ dropOldTables(db);
+ }
+
+ private static void dropOldIndices(@NonNull SupportSQLiteDatabase db) {
+ db.execSQL("DROP INDEX ACCOUNTS_URL_idx");
+ db.execSQL("DROP INDEX ACCOUNTS_USERNAME_idx");
+ db.execSQL("DROP INDEX ACCOUNTS_ACCOUNT_NAME_idx");
+ db.execSQL("DROP INDEX ACCOUNTS_ETAG_idx");
+ db.execSQL("DROP INDEX ACCOUNTS_MODIFIED_idx");
+ db.execSQL("DROP INDEX NOTES_REMOTEID_idx");
+ db.execSQL("DROP INDEX NOTES_ACCOUNT_ID_idx");
+ db.execSQL("DROP INDEX NOTES_STATUS_idx");
+ db.execSQL("DROP INDEX NOTES_FAVORITE_idx");
+ db.execSQL("DROP INDEX NOTES_CATEGORY_idx");
+ db.execSQL("DROP INDEX NOTES_MODIFIED_idx");
+ }
+
+ private static void createNewTables(@NonNull SupportSQLiteDatabase db) {
+ db.execSQL("CREATE TABLE `Account` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `url` TEXT NOT NULL DEFAULT '', `userName` TEXT NOT NULL DEFAULT '', `accountName` TEXT NOT NULL DEFAULT '', `eTag` TEXT, `modified` INTEGER, `apiVersion` TEXT, `color` INTEGER NOT NULL DEFAULT -16743735, `textColor` INTEGER NOT NULL DEFAULT -16777216, `capabilitiesETag` TEXT)");
+ db.execSQL("CREATE TABLE `CategoryOptions` (`accountId` INTEGER NOT NULL, `category` TEXT NOT NULL, `sortingMethod` INTEGER, PRIMARY KEY(`accountId`, `category`), FOREIGN KEY(`accountId`) REFERENCES `Account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )");
+ db.execSQL("CREATE TABLE `Note` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `remoteId` INTEGER, `accountId` INTEGER NOT NULL, `status` TEXT NOT NULL, `title` TEXT NOT NULL DEFAULT '', `category` TEXT NOT NULL DEFAULT '', `modified` INTEGER, `content` TEXT NOT NULL DEFAULT '', `favorite` INTEGER NOT NULL DEFAULT 0, `eTag` TEXT, `excerpt` TEXT NOT NULL DEFAULT '', `scrollY` INTEGER NOT NULL DEFAULT 0, FOREIGN KEY(`accountId`) REFERENCES `Account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )");
+ db.execSQL("CREATE TABLE `NotesListWidgetData` (`mode` INTEGER NOT NULL, `category` TEXT, `id` INTEGER NOT NULL, `accountId` INTEGER NOT NULL, `themeMode` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`accountId`) REFERENCES `Account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`accountId`, `category`) REFERENCES `CategoryOptions`(`accountId`, `category`) ON UPDATE NO ACTION ON DELETE CASCADE )");
+ db.execSQL("CREATE TABLE `SingleNoteWidgetData` (`noteId` INTEGER NOT NULL, `id` INTEGER NOT NULL, `accountId` INTEGER NOT NULL, `themeMode` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`accountId`) REFERENCES `Account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`noteId`) REFERENCES `Note`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )");
+ }
+
+ private static void createNewIndices(@NonNull SupportSQLiteDatabase db) {
+ db.execSQL("CREATE INDEX `IDX_ACCOUNT_ACCOUNTNAME` ON `Account` (`accountName`)");
+ db.execSQL("CREATE INDEX `IDX_ACCOUNT_ETAG` ON `Account` (`eTag`)");
+ db.execSQL("CREATE INDEX `IDX_ACCOUNT_MODIFIED` ON `Account` (`modified`)");
+ db.execSQL("CREATE INDEX `IDX_ACCOUNT_URL` ON `Account` (`url`)");
+ db.execSQL("CREATE INDEX `IDX_ACCOUNT_USERNAME` ON `Account` (`userName`)");
+ db.execSQL("CREATE INDEX `IDX_CATEGORIYOPTIONS_ACCOUNTID` ON `CategoryOptions` (`accountId`)");
+ db.execSQL("CREATE INDEX `IDX_CATEGORIYOPTIONS_CATEGORY` ON `CategoryOptions` (`category`)");
+ db.execSQL("CREATE INDEX `IDX_CATEGORIYOPTIONS_SORTING_METHOD` ON `CategoryOptions` (`sortingMethod`)");
+ db.execSQL("CREATE INDEX `IDX_NOTESLISTWIDGETDATA_ACCOUNTID` ON `NotesListWidgetData` (`accountId`)");
+ db.execSQL("CREATE INDEX `IDX_NOTESLISTWIDGETDATA_CATEGORY` ON `NotesListWidgetData` (`category`)");
+ db.execSQL("CREATE INDEX `IDX_NOTESLISTWIDGETDATA_ACCOUNT_CATEGORY` ON `NotesListWidgetData` (`accountId`, `category`)");
+ db.execSQL("CREATE INDEX `IDX_NOTE_ACCOUNTID` ON `Note` (`accountId`)");
+ db.execSQL("CREATE INDEX `IDX_NOTE_CATEGORY` ON `Note` (`category`)");
+ db.execSQL("CREATE INDEX `IDX_NOTE_FAVORITE` ON `Note` (`favorite`)");
+ db.execSQL("CREATE INDEX `IDX_NOTE_MODIFIED` ON `Note` (`modified`)");
+ db.execSQL("CREATE INDEX `IDX_NOTE_REMOTEID` ON `Note` (`remoteId`)");
+ db.execSQL("CREATE INDEX `IDX_NOTE_STATUS` ON `Note` (`status`)");
+ db.execSQL("CREATE INDEX `IDX_SINGLENOTEWIDGETDATA_ACCOUNTID` ON `SingleNoteWidgetData` (`accountId`)");
+ db.execSQL("CREATE INDEX `IDX_SINGLENOTEWIDGETDATA_NOTEID` ON `SingleNoteWidgetData` (`noteId`)");
+
+ db.execSQL("CREATE UNIQUE INDEX `IDX_UNIQUE_CATEGORYOPTIONS_ACCOUNT_CATEGORY` ON `CategoryOptions` (`accountId`, `category`)");
+
+ db.execSQL("CREATE TRIGGER TRG_CLEANUP_CATEGORIES_DEL AFTER DELETE ON Note BEGIN DELETE FROM CategoryOptions WHERE CategoryOptions.category NOT IN (SELECT Note.category FROM Note WHERE Note.accountId = CategoryOptions.accountId); END;");
+ db.execSQL("CREATE TRIGGER TRG_CLEANUP_CATEGORIES_UPD AFTER UPDATE ON Note BEGIN DELETE FROM CategoryOptions WHERE CategoryOptions.category NOT IN (SELECT Note.category FROM Note WHERE Note.accountId = CategoryOptions.accountId); END;");
+
+ }
+
+ private static void migrateAccounts(@NonNull SupportSQLiteDatabase db) {
+ final Cursor cursor = db.query("SELECT * FROM ACCOUNTS", null);
+ final ContentValues values = new ContentValues(10);
+
+ final int COLUMN_POSITION_ID = cursor.getColumnIndex("ID");
+ final int COLUMN_POSITION_URL = cursor.getColumnIndex("URL");
+ final int COLUMN_POSITION_USERNAME = cursor.getColumnIndex("USERNAME");
+ final int COLUMN_POSITION_ACCOUNT_NAME = cursor.getColumnIndex("ACCOUNT_NAME");
+ final int COLUMN_POSITION_ETAG = cursor.getColumnIndex("ETAG");
+ final int COLUMN_POSITION_MODIFIED = cursor.getColumnIndex("MODIFIED");
+ final int COLUMN_POSITION_API_VERSION = cursor.getColumnIndex("API_VERSION");
+ final int COLUMN_POSITION_COLOR = cursor.getColumnIndex("COLOR");
+ final int COLUMN_POSITION_TEXT_COLOR = cursor.getColumnIndex("TEXT_COLOR");
+ final int COLUMN_POSITION_CAPABILITIES_ETAG = cursor.getColumnIndex("CAPABILITIES_ETAG");
+
+ while (cursor.moveToNext()) {
+ values.put("ID", cursor.getInt(COLUMN_POSITION_ID));
+ values.put("URL", cursor.getString(COLUMN_POSITION_URL));
+ values.put("USERNAME", cursor.getString(COLUMN_POSITION_USERNAME));
+ values.put("ACCOUNTNAME", cursor.getString(COLUMN_POSITION_ACCOUNT_NAME));
+ values.put("ETAG", cursor.getString(COLUMN_POSITION_ETAG));
+ values.put("MODIFIED", cursor.getLong(COLUMN_POSITION_MODIFIED) * 1_000);
+ values.put("APIVERSION", cursor.getString(COLUMN_POSITION_API_VERSION));
+ try {
+ values.put("COLOR", Color.parseColor(ColorUtil.INSTANCE.formatColorToParsableHexString(cursor.getString(COLUMN_POSITION_COLOR))));
+ } catch (Exception e) {
+ e.printStackTrace();
+ values.put("COLOR", -16743735);
+ }
+ try {
+ values.put("TEXTCOLOR", Color.parseColor(ColorUtil.INSTANCE.formatColorToParsableHexString(cursor.getString(COLUMN_POSITION_TEXT_COLOR))));
+ } catch (Exception e) {
+ e.printStackTrace();
+ values.put("TEXTCOLOR", -16777216);
+ }
+ values.put("CAPABILITIESETAG", cursor.getString(COLUMN_POSITION_CAPABILITIES_ETAG));
+ db.insert("ACCOUNT", OnConflictStrategy.REPLACE, values);
+ }
+ cursor.close();
+ }
+
+ private static void migrateCategories(@NonNull SupportSQLiteDatabase db) {
+ final Cursor cursor = db.query("SELECT * FROM CATEGORIES", null);
+ final ContentValues values = new ContentValues(3);
+
+ final int COLUMN_POSITION_ACCOUNT_ID = cursor.getColumnIndex("CATEGORY_ACCOUNT_ID");
+ final int COLUMN_POSITION_TITLE = cursor.getColumnIndex("CATEGORY_TITLE");
+ final int COLUMN_POSITION_SORTING_METHOD = cursor.getColumnIndex("CATEGORY_SORTING_METHOD");
+
+ while (cursor.moveToNext()) {
+ values.put("ACCOUNTID", cursor.getInt(COLUMN_POSITION_ACCOUNT_ID));
+ values.put("CATEGORY", cursor.getString(COLUMN_POSITION_TITLE));
+ values.put("SORTINGMETHOD", cursor.getInt(COLUMN_POSITION_SORTING_METHOD));
+ db.insert("CATEGORYOPTIONS", OnConflictStrategy.REPLACE, values);
+ }
+ cursor.close();
+ }
+
+ private static void migrateNotes(@NonNull SupportSQLiteDatabase db) {
+ final Cursor cursor = db.query("SELECT NOTES.*, CATEGORIES.category_title as `CAT_TITLE` FROM NOTES LEFT JOIN CATEGORIES ON NOTES.category = CATEGORIES.category_id", null);
+ final ContentValues values = new ContentValues(12);
+
+ final int COLUMN_POSITION_ID = cursor.getColumnIndex("ID");
+ final int COLUMN_POSITION_REMOTEID = cursor.getColumnIndex("REMOTEID");
+ final int COLUMN_POSITION_ACCOUNT_ID = cursor.getColumnIndex("ACCOUNT_ID");
+ final int COLUMN_POSITION_STATUS = cursor.getColumnIndex("STATUS");
+ final int COLUMN_POSITION_TITLE = cursor.getColumnIndex("TITLE");
+ final int COLUMN_POSITION_MODIFIED = cursor.getColumnIndex("MODIFIED");
+ final int COLUMN_POSITION_CONTENT = cursor.getColumnIndex("CONTENT");
+ final int COLUMN_POSITION_FAVORITE = cursor.getColumnIndex("FAVORITE");
+ final int COLUMN_POSITION_CAT_TITLE = cursor.getColumnIndex("CAT_TITLE");
+ final int COLUMN_POSITION_ETAG = cursor.getColumnIndex("ETAG");
+ final int COLUMN_POSITION_EXCERPT = cursor.getColumnIndex("EXCERPT");
+ final int COLUMN_POSITION_SCROLL_Y = cursor.getColumnIndex("SCROLL_Y");
+
+ while (cursor.moveToNext()) {
+ values.put("ID", cursor.getInt(COLUMN_POSITION_ID));
+ values.put("REMOTEID", cursor.getInt(COLUMN_POSITION_REMOTEID));
+ values.put("ACCOUNTID", cursor.getInt(COLUMN_POSITION_ACCOUNT_ID));
+ values.put("STATUS", cursor.getString(COLUMN_POSITION_STATUS));
+ values.put("TITLE", cursor.getString(COLUMN_POSITION_TITLE));
+ values.put("MODIFIED", cursor.getLong(COLUMN_POSITION_MODIFIED) * 1_000);
+ values.put("CONTENT", cursor.getString(COLUMN_POSITION_CONTENT));
+ values.put("FAVORITE", cursor.getInt(COLUMN_POSITION_FAVORITE));
+ values.put("CATEGORY", cursor.getString(COLUMN_POSITION_CAT_TITLE));
+ values.put("ETAG", cursor.getString(COLUMN_POSITION_ETAG));
+ values.put("EXCERPT", cursor.getString(COLUMN_POSITION_EXCERPT));
+ values.put("SCROLLY", cursor.getString(COLUMN_POSITION_SCROLL_Y));
+ db.insert("NOTE", OnConflictStrategy.REPLACE, values);
+ }
+ cursor.close();
+ }
+
+ private static void migrateNotesListWidgets(@NonNull SupportSQLiteDatabase db) {
+ final Cursor cursor = db.query("SELECT WIDGET_NOTE_LISTS.*, CATEGORIES.category_title as `CATEGORY` FROM WIDGET_NOTE_LISTS LEFT JOIN CATEGORIES ON WIDGET_NOTE_LISTS.CATEGORY_ID = CATEGORIES.category_id", null);
+ final ContentValues values = new ContentValues(5);
+
+ final int COLUMN_POSITION_ID = cursor.getColumnIndex("ID");
+ final int COLUMN_POSITION_ACCOUNT_ID = cursor.getColumnIndex("ACCOUNT_ID");
+ final int COLUMN_POSITION_CATEGORY = cursor.getColumnIndex("CATEGORY");
+ final int COLUMN_POSITION_MODE = cursor.getColumnIndex("MODE");
+ final int COLUMN_POSITION_THEME_MODE = cursor.getColumnIndex("THEME_MODE");
+
+ while (cursor.moveToNext()) {
+ values.put("ID", cursor.getInt(COLUMN_POSITION_ID));
+ values.put("ACCOUNTID", cursor.getInt(COLUMN_POSITION_ACCOUNT_ID));
+ values.put("CATEGORY", cursor.getString(COLUMN_POSITION_CATEGORY));
+ values.put("MODE", cursor.getInt(COLUMN_POSITION_MODE));
+ values.put("THEMEMODE", cursor.getInt(COLUMN_POSITION_THEME_MODE));
+ db.insert("NOTESLISTWIDGETDATA", OnConflictStrategy.REPLACE, values);
+ }
+ cursor.close();
+ }
+
+ private static void migrateSingleNotesWidgets(@NonNull SupportSQLiteDatabase db) {
+ final Cursor cursor = db.query("SELECT * FROM WIDGET_SINGLE_NOTES", null);
+ final ContentValues values = new ContentValues(4);
+
+ final int COLUMN_POSITION_ID = cursor.getColumnIndex("ID");
+ final int COLUMN_POSITION_ACCOUNT_ID = cursor.getColumnIndex("ACCOUNT_ID");
+ final int COLUMN_POSITION_NOTE_ID = cursor.getColumnIndex("NOTE_ID");
+ final int COLUMN_POSITION_THEME_MODE = cursor.getColumnIndex("THEME_MODE");
+
+ while (cursor.moveToNext()) {
+ values.put("ID", cursor.getInt(COLUMN_POSITION_ID));
+ values.put("ACCOUNTID", cursor.getInt(COLUMN_POSITION_ACCOUNT_ID));
+ values.put("NOTEID", cursor.getInt(COLUMN_POSITION_NOTE_ID));
+ values.put("THEMEMODE", cursor.getInt(COLUMN_POSITION_THEME_MODE));
+ db.insert("SINGLENOTEWIDGETDATA", OnConflictStrategy.REPLACE, values);
+ }
+ cursor.close();
+ }
+
+ private static void dropOldTables(@NonNull SupportSQLiteDatabase db) {
+ db.execSQL("DROP TABLE IF EXISTS WIDGET_SINGLE_NOTES");
+ db.execSQL("DROP TABLE IF EXISTS WIDGET_NOTE_LISTS");
+ db.execSQL("DROP TABLE IF EXISTS CATEGORIES");
+ db.execSQL("DROP TABLE IF EXISTS NOTES");
+ db.execSQL("DROP TABLE IF EXISTS ACCOUNTS");
+ }
+}
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesFragment.java
index 017d5df5..8af467fb 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesFragment.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesFragment.java
@@ -29,8 +29,8 @@ public class PreferencesFragment extends PreferenceFragmentCompat implements Bra
private BrandedSwitchPreference fontPref;
private BrandedSwitchPreference lockPref;
private BrandedSwitchPreference wifiOnlyPref;
- private BrandedSwitchPreference brandingPref;
private BrandedSwitchPreference gridViewPref;
+ private BrandedSwitchPreference preventScreenCapturePref;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
@@ -43,20 +43,6 @@ public class PreferencesFragment extends PreferenceFragmentCompat implements Bra
fontPref = findPreference(getString(R.string.pref_key_font));
- brandingPref = findPreference(getString(R.string.pref_key_branding));
- if (brandingPref != null) {
- brandingPref.setOnPreferenceChangeListener((Preference preference, Object newValue) -> {
- updateNoteListWidgets(requireContext());
- final Boolean branding = (Boolean) newValue;
- Log.v(TAG, "branding: " + branding);
- requireActivity().setResult(Activity.RESULT_OK);
- ActivityCompat.recreate(requireActivity());
- return true;
- });
- } else {
- Log.e(TAG, "Could not find preference with key: \"" + getString(R.string.pref_key_branding) + "\"");
- }
-
gridViewPref = findPreference(getString(R.string.pref_key_gridview));
if (gridViewPref != null) {
gridViewPref.setOnPreferenceChangeListener((Preference preference, Object newValue) -> {
@@ -67,19 +53,18 @@ public class PreferencesFragment extends PreferenceFragmentCompat implements Bra
return true;
});
} else {
- Log.e(TAG, "Could not find preference with key: \"" + getString(R.string.pref_key_branding) + "\"");
+ Log.e(TAG, "Could not find preference with key: \"" + getString(R.string.pref_key_gridview) + "\"");
+ }
+
+ preventScreenCapturePref = findPreference(getString(R.string.pref_key_prevent_screen_capture));
+ if (preventScreenCapturePref == null) {
+ Log.e(TAG, "Could not find \"" + getString(R.string.pref_key_prevent_screen_capture) + "\"-preference.");
}
lockPref = findPreference(getString(R.string.pref_key_lock));
if (lockPref != null) {
if (!DeviceCredentialUtil.areCredentialsAvailable(requireContext())) {
lockPref.setVisible(false);
- Preference securityCategory = findPreference(getString(R.string.pref_category_security));
- if (securityCategory != null) {
- securityCategory.setVisible(false);
- } else {
- Log.e(TAG, "Could not find preference " + getString(R.string.pref_category_security));
- }
} else {
lockPref.setOnPreferenceChangeListener((preference, newValue) -> {
NotesApplication.setLockedPreference((Boolean) newValue);
@@ -132,7 +117,7 @@ public class PreferencesFragment extends PreferenceFragmentCompat implements Bra
fontPref.applyBrand(mainColor, textColor);
lockPref.applyBrand(mainColor, textColor);
wifiOnlyPref.applyBrand(mainColor, textColor);
- brandingPref.applyBrand(mainColor, textColor);
gridViewPref.applyBrand(mainColor, textColor);
+ preventScreenCapturePref.applyBrand(mainColor, textColor);
}
}
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/ServerResponse.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/ServerResponse.java
index 2f13d9ac..60c4ad5e 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/ServerResponse.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/ServerResponse.java
@@ -87,7 +87,7 @@ public class ServerResponse {
}
if (!json.isNull(NotesClient.JSON_MODIFIED)) {
modified = Calendar.getInstance();
- modified.setTimeInMillis(json.getLong(NotesClient.JSON_MODIFIED) * 1000);
+ modified.setTimeInMillis(json.getLong(NotesClient.JSON_MODIFIED) * 1_000);
}
if (!json.isNull(NotesClient.JSON_FAVORITE)) {
favorite = json.getBoolean(NotesClient.JSON_FAVORITE);