diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-10-06 12:41:29 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2020-10-06 12:41:29 +0300 |
commit | ac20a45c07a5c29e4967af9de66c74fc51561544 (patch) | |
tree | c1e1dd649fa72430829e163d375633f8b44a6933 /app/src/main/java/it/niedermann/owncloud/notes | |
parent | b27664cc15e894d478570bcf86115cc5ef933a47 (diff) |
#831 Migrate from SQLiteOpenHelper to Room
Remove old SqliteOpenHelper database
Diffstat (limited to 'app/src/main/java/it/niedermann/owncloud/notes')
66 files changed, 355 insertions, 617 deletions
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/AppendToNoteActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/AppendToNoteActivity.java index 803de361..5b3d0cfc 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/AppendToNoteActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/AppendToNoteActivity.java @@ -9,9 +9,9 @@ import android.widget.Toast; import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; +import it.niedermann.owncloud.notes.main.MainActivity; import it.niedermann.owncloud.notes.persistence.entity.NoteEntity; import it.niedermann.owncloud.notes.shared.model.DBNote; -import it.niedermann.owncloud.notes.main.MainActivity; public class AppendToNoteActivity extends MainActivity { diff --git a/app/src/main/java/it/niedermann/owncloud/notes/FormattingHelpActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/FormattingHelpActivity.java index 0e537956..68ae25a5 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/FormattingHelpActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/FormattingHelpActivity.java @@ -17,7 +17,6 @@ import androidx.preference.PreferenceManager; import com.yydcdut.markdown.MarkdownProcessor; import com.yydcdut.markdown.syntax.text.TextFactory; -import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.branding.BrandedActivity; import it.niedermann.owncloud.notes.databinding.ActivityFormattingHelpBinding; 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 8b024050..7a882e84 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/LockedActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/LockedActivity.java @@ -9,8 +9,8 @@ import android.util.Log; import androidx.annotation.Nullable; -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 { diff --git a/app/src/main/java/it/niedermann/owncloud/notes/about/AboutActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/about/AboutActivity.java index d764ba7a..fb868bc0 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/about/AboutActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/about/AboutActivity.java @@ -8,8 +8,8 @@ import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentPagerAdapter; -import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.LockedActivity; +import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.branding.BrandingUtil; import it.niedermann.owncloud.notes.databinding.ActivityAboutBinding; diff --git a/app/src/main/java/it/niedermann/owncloud/notes/accountpicker/AccountPickerDialogFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/accountpicker/AccountPickerDialogFragment.java index 8ca0205c..16d9c33f 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/accountpicker/AccountPickerDialogFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/accountpicker/AccountPickerDialogFragment.java @@ -21,7 +21,6 @@ import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.branding.BrandedAlertDialogBuilder; import it.niedermann.owncloud.notes.branding.BrandedDialogFragment; import it.niedermann.owncloud.notes.databinding.DialogChooseAccountBinding; -import it.niedermann.owncloud.notes.persistence.NotesDatabase; import it.niedermann.owncloud.notes.persistence.NotesRoomDatabase; import it.niedermann.owncloud.notes.persistence.entity.LocalAccountEntity; import it.niedermann.owncloud.notes.shared.account.AccountChooserAdapter; diff --git a/app/src/main/java/it/niedermann/owncloud/notes/accountpicker/AccountPickerListener.java b/app/src/main/java/it/niedermann/owncloud/notes/accountpicker/AccountPickerListener.java index c77e1824..ff9875f2 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/accountpicker/AccountPickerListener.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/accountpicker/AccountPickerListener.java @@ -2,8 +2,8 @@ package it.niedermann.owncloud.notes.accountpicker; import androidx.annotation.NonNull; -import it.niedermann.owncloud.notes.shared.model.LocalAccount; +import it.niedermann.owncloud.notes.persistence.entity.LocalAccountEntity; public interface AccountPickerListener { - void onAccountPicked(@NonNull LocalAccount account); + void onAccountPicked(@NonNull LocalAccountEntity account); }
\ No newline at end of file diff --git a/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherAdapter.java b/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherAdapter.java index 5488fd8d..e2498eb2 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherAdapter.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherAdapter.java @@ -12,18 +12,15 @@ import java.util.List; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.persistence.entity.LocalAccountEntity; -import it.niedermann.owncloud.notes.shared.model.LocalAccount; - -import static it.niedermann.owncloud.notes.persistence.entity.LocalAccountEntity.entityToLocalAccount; public class AccountSwitcherAdapter extends RecyclerView.Adapter<AccountSwitcherViewHolder> { @NonNull private final List<LocalAccountEntity> localAccounts = new ArrayList<>(); @NonNull - private final Consumer<LocalAccount> onAccountClick; + private final Consumer<LocalAccountEntity> onAccountClick; - public AccountSwitcherAdapter(@NonNull Consumer<LocalAccount> onAccountClick) { + public AccountSwitcherAdapter(@NonNull Consumer<LocalAccountEntity> onAccountClick) { this.onAccountClick = onAccountClick; setHasStableIds(true); } @@ -41,7 +38,7 @@ public class AccountSwitcherAdapter extends RecyclerView.Adapter<AccountSwitcher @Override public void onBindViewHolder(@NonNull AccountSwitcherViewHolder holder, int position) { - holder.bind(entityToLocalAccount(localAccounts.get(position)), onAccountClick); + holder.bind(localAccounts.get(position), onAccountClick); } @Override diff --git a/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherDialog.java b/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherDialog.java index 75e55a1c..b9317dfe 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherDialog.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherDialog.java @@ -20,7 +20,6 @@ import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.branding.BrandedDialogFragment; import it.niedermann.owncloud.notes.databinding.DialogAccountSwitcherBinding; import it.niedermann.owncloud.notes.manageaccounts.ManageAccountsActivity; -import it.niedermann.owncloud.notes.persistence.NotesDatabase; import it.niedermann.owncloud.notes.persistence.NotesRoomDatabase; import it.niedermann.owncloud.notes.persistence.entity.LocalAccountEntity; import it.niedermann.owncloud.notes.shared.model.LocalAccount; @@ -35,8 +34,7 @@ public class AccountSwitcherDialog extends BrandedDialogFragment { private static final String KEY_CURRENT_ACCOUNT_ID = "current_account_id"; - private NotesDatabase sqliteOpenHelperDatabase; - private NotesRoomDatabase roomDatabase; + private NotesRoomDatabase db; private DialogAccountSwitcherBinding binding; private AccountSwitcherListener accountSwitcherListener; private long currentAccountId; @@ -58,8 +56,7 @@ public class AccountSwitcherDialog extends BrandedDialogFragment { this.currentAccountId = args.getLong(KEY_CURRENT_ACCOUNT_ID); } - sqliteOpenHelperDatabase = NotesDatabase.getInstance(getActivity()); - roomDatabase = NotesRoomDatabase.getInstance(getActivity()); + db = NotesRoomDatabase.getInstance(requireActivity()); } @NonNull @@ -67,7 +64,7 @@ public class AccountSwitcherDialog extends BrandedDialogFragment { public Dialog onCreateDialog(Bundle savedInstanceState) { binding = DialogAccountSwitcherBinding.inflate(requireActivity().getLayoutInflater()); - LocalAccountEntity currentLocalAccount = roomDatabase.getLocalAccountDao().getAccount(currentAccountId); + LocalAccountEntity currentLocalAccount = db.getLocalAccountDao().getAccount(currentAccountId); binding.accountName.setText(currentLocalAccount.getUsername()); binding.accountHost.setText(Uri.parse(currentLocalAccount.getUrl()).getHost()); Glide.with(requireContext()) @@ -82,7 +79,7 @@ public class AccountSwitcherDialog extends BrandedDialogFragment { dismiss(); })); binding.accountsList.setAdapter(adapter); - List<LocalAccountEntity> localAccounts = roomDatabase.getLocalAccountDao().getAccounts(); + List<LocalAccountEntity> localAccounts = db.getLocalAccountDao().getAccounts(); for (LocalAccountEntity localAccount : localAccounts) { if (localAccount.getId() == currentLocalAccount.getId()) { localAccounts.remove(localAccount); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherListener.java b/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherListener.java index 35750f2f..81542161 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherListener.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherListener.java @@ -1,11 +1,11 @@ package it.niedermann.owncloud.notes.accountswitcher; -import it.niedermann.owncloud.notes.shared.model.LocalAccount; +import it.niedermann.owncloud.notes.persistence.entity.LocalAccountEntity; public interface AccountSwitcherListener { void addAccount(); - void onAccountChosen(LocalAccount localAccount); + void onAccountChosen(LocalAccountEntity localAccount); - void onAccountDeleted(LocalAccount localAccount); + void onAccountDeleted(LocalAccountEntity localAccount); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherViewHolder.java b/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherViewHolder.java index fcc3d91c..3908fced 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherViewHolder.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherViewHolder.java @@ -13,7 +13,7 @@ import com.bumptech.glide.request.RequestOptions; import it.niedermann.android.glidesso.SingleSignOnUrl; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.databinding.ItemAccountChooseBinding; -import it.niedermann.owncloud.notes.shared.model.LocalAccount; +import it.niedermann.owncloud.notes.persistence.entity.LocalAccountEntity; public class AccountSwitcherViewHolder extends RecyclerView.ViewHolder { @@ -24,11 +24,11 @@ public class AccountSwitcherViewHolder extends RecyclerView.ViewHolder { binding = ItemAccountChooseBinding.bind(itemView); } - public void bind(@NonNull LocalAccount localAccount, @NonNull Consumer<LocalAccount> onAccountClick) { - binding.accountName.setText(localAccount.getUserName()); + public void bind(@NonNull LocalAccountEntity localAccount, @NonNull Consumer<LocalAccountEntity> onAccountClick) { + binding.accountName.setText(localAccount.getUsername()); binding.accountHost.setText(Uri.parse(localAccount.getUrl()).getHost()); Glide.with(itemView.getContext()) - .load(new SingleSignOnUrl(localAccount.getAccountName(), localAccount.getUrl() + "/index.php/avatar/" + Uri.encode(localAccount.getUserName()) + "/64")) + .load(new SingleSignOnUrl(localAccount.getAccountName(), localAccount.getUrl() + "/index.php/avatar/" + Uri.encode(localAccount.getUsername()) + "/64")) .placeholder(R.drawable.ic_account_circle_grey_24dp) .error(R.drawable.ic_account_circle_grey_24dp) .apply(RequestOptions.circleCropTransform()) 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 a3dd233c..6d673dd1 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 @@ -16,8 +16,6 @@ import androidx.preference.SwitchPreference; import it.niedermann.owncloud.notes.R; -import static android.os.Build.VERSION.SDK_INT; -import static android.os.Build.VERSION_CODES.JELLY_BEAN; import static it.niedermann.owncloud.notes.branding.BrandingUtil.getSecondaryForegroundColorDependingOnTheme; public class BrandedSwitchPreference extends SwitchPreference implements Branded { 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 d22fb4a3..3b3ea7f2 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 @@ -16,8 +16,8 @@ import androidx.annotation.NonNull; import androidx.core.graphics.drawable.DrawableCompat; import androidx.preference.PreferenceManager; -import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.NotesApplication; +import it.niedermann.owncloud.notes.R; import static it.niedermann.owncloud.notes.shared.util.ColorUtil.contrastRatioIsSufficient; diff --git a/app/src/main/java/it/niedermann/owncloud/notes/edit/BaseNoteFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/edit/BaseNoteFragment.java index 30cc6732..d6ba527b 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/edit/BaseNoteFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/edit/BaseNoteFragment.java @@ -36,16 +36,13 @@ import it.niedermann.owncloud.notes.edit.category.CategoryDialogFragment; import it.niedermann.owncloud.notes.edit.category.CategoryDialogFragment.CategoryDialogListener; import it.niedermann.owncloud.notes.edit.title.EditTitleDialogFragment; import it.niedermann.owncloud.notes.edit.title.EditTitleDialogFragment.EditTitleListener; -import it.niedermann.owncloud.notes.persistence.NotesDatabase; import it.niedermann.owncloud.notes.persistence.NotesRoomDatabase; import it.niedermann.owncloud.notes.persistence.entity.LocalAccountEntity; import it.niedermann.owncloud.notes.persistence.entity.NoteEntity; import it.niedermann.owncloud.notes.shared.model.ApiVersion; import it.niedermann.owncloud.notes.shared.model.CloudNote; -import it.niedermann.owncloud.notes.shared.model.DBNote; import it.niedermann.owncloud.notes.shared.model.DBStatus; import it.niedermann.owncloud.notes.shared.model.ISyncCallback; -import it.niedermann.owncloud.notes.shared.model.LocalAccount; import it.niedermann.owncloud.notes.shared.util.ColorUtil; import it.niedermann.owncloud.notes.shared.util.NoteUtil; import it.niedermann.owncloud.notes.shared.util.ShareUtil; @@ -76,8 +73,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego @Nullable private NoteEntity originalNote; private int originalScrollY; - protected NotesDatabase sqliteOpenHelperDatabase; - protected NotesRoomDatabase roomDatabase; + protected NotesRoomDatabase db; private NoteFragmentListener listener; private boolean titleModified = false; @@ -91,8 +87,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego } catch (ClassCastException e) { throw new ClassCastException(context.getClass() + " must implement " + NoteFragmentListener.class); } - sqliteOpenHelperDatabase = NotesDatabase.getInstance(context); - roomDatabase = NotesRoomDatabase.getInstance(context); + db = NotesRoomDatabase.getInstance(context); } @Override @@ -100,7 +95,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego super.onCreate(savedInstanceState); try { this.ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(requireActivity().getApplicationContext()); - this.localAccountEntity = roomDatabase.getLocalAccountDao().getLocalAccountByAccountName(ssoAccount.name); + this.localAccountEntity = db.getLocalAccountDao().getLocalAccountByAccountName(ssoAccount.name); if (savedInstanceState == null) { long id = requireArguments().getLong(PARAM_NOTE_ID); @@ -108,11 +103,11 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego long accountId = requireArguments().getLong(PARAM_ACCOUNT_ID); if (accountId > 0) { /* Switch account if account id has been provided */ - this.localAccountEntity = roomDatabase.getLocalAccountDao().getAccount(accountId); + this.localAccountEntity = db.getLocalAccountDao().getAccount(accountId); SingleAccountHelper.setCurrentAccount(requireActivity().getApplicationContext(), localAccountEntity.getAccountName()); } isNew = false; - note = originalNote = roomDatabase.getNoteDao().getNote(localAccountEntity.getId(), id); + note = originalNote = db.getNoteDao().getNote(localAccountEntity.getId(), id); } else { CloudNote cloudNote = (CloudNote) requireArguments().getSerializable(PARAM_NEWNOTE); String content = requireArguments().getString(PARAM_CONTENT); @@ -123,7 +118,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego note = new NoteEntity(-1, -1, null, NoteUtil.generateNoteTitle(content), content, false, getString(R.string.category_readonly), null, DBStatus.VOID, -1, "", 0); } } else { - note = roomDatabase.getNoteDao().getNote(localAccountEntity.getId(), roomDatabase.addNoteAndSync(ssoAccount, localAccountEntity.getId(), cloudNote)); + note = db.getNoteDao().getNote(localAccountEntity.getId(), db.addNoteAndSync(ssoAccount, localAccountEntity.getId(), cloudNote)); originalNote = null; } } @@ -224,18 +219,18 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego switch (item.getItemId()) { case R.id.menu_cancel: if (originalNote == null) { - roomDatabase.deleteNoteAndSync(ssoAccount, note.getId()); + db.deleteNoteAndSync(ssoAccount, note.getId()); } else { - roomDatabase.updateNoteAndSync(ssoAccount, localAccountEntity, originalNote, null, null, null); + db.updateNoteAndSync(ssoAccount, localAccountEntity, originalNote, null, null, null); } listener.close(); return true; case R.id.menu_delete: - roomDatabase.deleteNoteAndSync(ssoAccount, note.getId()); + db.deleteNoteAndSync(ssoAccount, note.getId()); listener.close(); return true; case R.id.menu_favorite: - roomDatabase.toggleFavoriteAndSync(ssoAccount, note.getId(), null); + db.toggleFavoriteAndSync(ssoAccount, note.getId(), null); listener.onNoteUpdated(note); prepareFavoriteOption(item); return true; @@ -291,7 +286,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego public void onCloseNote() { if (!titleModified && originalNote == null && getContent().isEmpty()) { - roomDatabase.deleteNoteAndSync(ssoAccount, note.getId()); + db.deleteNoteAndSync(ssoAccount, note.getId()); } } @@ -307,12 +302,12 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego if (note.getContent().equals(newContent)) { if (note.getScrollY() != originalScrollY) { Log.v(TAG, "... only saving new scroll state, since content did not change"); - roomDatabase.getNoteDao().updateScrollY(note.getId(), note.getScrollY()); + db.getNoteDao().updateScrollY(note.getId(), note.getScrollY()); } else { Log.v(TAG, "... not saving, since nothing has changed"); } } else { - note = roomDatabase.updateNoteAndSync(ssoAccount, localAccountEntity, note, newContent, null, callback); + note = db.updateNoteAndSync(ssoAccount, localAccountEntity, note, newContent, null, callback); listener.onNoteUpdated(note); requireActivity().invalidateOptionsMenu(); } @@ -356,7 +351,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego @Override public void onCategoryChosen(String category) { - roomDatabase.setCategory(ssoAccount, note, category, null); + db.setCategory(ssoAccount, note, category, null); listener.onNoteUpdated(note); } @@ -364,12 +359,12 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego public void onTitleEdited(String newTitle) { titleModified = true; note.setTitle(newTitle); - note = roomDatabase.updateNoteAndSync(ssoAccount, localAccountEntity, note, note.getContent(), newTitle, null); + note = db.updateNoteAndSync(ssoAccount, localAccountEntity, note, note.getContent(), newTitle, null); listener.onNoteUpdated(note); } - public void moveNote(LocalAccount account) { - roomDatabase.moveNoteToAnotherAccount(ssoAccount, note.getAccountId(), note, account.getId()); + public void moveNote(LocalAccountEntity account) { + db.moveNoteToAnotherAccount(ssoAccount, note.getAccountId(), note, account.getId()); listener.close(); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/edit/EditNoteActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/edit/EditNoteActivity.java index 783800b1..9aa200ce 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/edit/EditNoteActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/edit/EditNoteActivity.java @@ -20,14 +20,13 @@ import java.util.Objects; import it.niedermann.owncloud.notes.LockedActivity; import it.niedermann.owncloud.notes.R; -import it.niedermann.owncloud.notes.databinding.ActivityEditBinding; import it.niedermann.owncloud.notes.accountpicker.AccountPickerListener; +import it.niedermann.owncloud.notes.databinding.ActivityEditBinding; import it.niedermann.owncloud.notes.main.MainActivity; +import it.niedermann.owncloud.notes.persistence.entity.LocalAccountEntity; import it.niedermann.owncloud.notes.persistence.entity.NoteEntity; import it.niedermann.owncloud.notes.shared.model.Category; import it.niedermann.owncloud.notes.shared.model.CloudNote; -import it.niedermann.owncloud.notes.shared.model.DBNote; -import it.niedermann.owncloud.notes.shared.model.LocalAccount; import it.niedermann.owncloud.notes.shared.util.NoteUtil; public class EditNoteActivity extends LockedActivity implements BaseNoteFragment.NoteFragmentListener, AccountPickerListener { @@ -270,7 +269,7 @@ public class EditNoteActivity extends LockedActivity implements BaseNoteFragment } @Override - public void onAccountPicked(@NonNull LocalAccount account) { + public void onAccountPicked(@NonNull LocalAccountEntity account) { fragment.moveNote(account); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteEditFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteEditFragment.java index ba297b95..3cbb9d2d 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteEditFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteEditFragment.java @@ -32,11 +32,11 @@ import com.yydcdut.markdown.syntax.edit.EditFactory; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.databinding.FragmentNoteEditBinding; +import it.niedermann.owncloud.notes.edit.format.ContextBasedFormattingCallback; +import it.niedermann.owncloud.notes.edit.format.ContextBasedRangeFormattingCallback; import it.niedermann.owncloud.notes.shared.model.CloudNote; import it.niedermann.owncloud.notes.shared.model.ISyncCallback; import it.niedermann.owncloud.notes.shared.util.MarkDownUtil; -import it.niedermann.owncloud.notes.edit.format.ContextBasedFormattingCallback; -import it.niedermann.owncloud.notes.edit.format.ContextBasedRangeFormattingCallback; import static androidx.core.view.ViewCompat.isAttachedToWindow; import static it.niedermann.owncloud.notes.shared.util.DisplayUtils.searchAndColor; 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 d5769b1f..d0773368 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 @@ -36,9 +36,7 @@ import java.util.HashSet; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.databinding.FragmentNotePreviewBinding; -import it.niedermann.owncloud.notes.persistence.NotesDatabase; import it.niedermann.owncloud.notes.persistence.entity.NoteEntity; -import it.niedermann.owncloud.notes.shared.model.DBNote; import it.niedermann.owncloud.notes.shared.util.MarkDownUtil; import it.niedermann.owncloud.notes.shared.util.NoteLinksUtils; import it.niedermann.owncloud.notes.shared.util.SSOUtil; @@ -163,7 +161,7 @@ public class NotePreviewFragment extends SearchableBaseNoteFragment implements O .setOnLinkClickCallback((view, link) -> { if (NoteLinksUtils.isNoteLink(link)) { final Intent intent = new Intent(requireActivity().getApplicationContext(), EditNoteActivity.class) - .putExtra(EditNoteActivity.PARAM_NOTE_ID, roomDatabase.getNoteDao().getLocalIdByRemoteId(this.note.getAccountId(), extractNoteRemoteId(link))); + .putExtra(EditNoteActivity.PARAM_NOTE_ID, db.getNoteDao().getLocalIdByRemoteId(this.note.getAccountId(), extractNoteRemoteId(link))); startActivity(intent); } else { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(link)); @@ -216,7 +214,7 @@ public class NotePreviewFragment extends SearchableBaseNoteFragment implements O TextProcessorChain chain = defaultTextProcessorChain(note); SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(requireContext()); sqliteOpenHelperDatabase.getNoteServerSyncHelper().addCallbackPull(ssoAccount, () -> { - note = roomDatabase.getNoteDao().getNote(note.getAccountId(), note.getId()); + note = db.getNoteDao().getNote(note.getAccountId(), note.getId()); changedText = note.getContent(); binding.singleNoteContent.setText(parseCompat(markdownProcessor, chain.apply(note.getContent()))); binding.swiperefreshlayout.setRefreshing(false); @@ -239,7 +237,7 @@ public class NotePreviewFragment extends SearchableBaseNoteFragment implements O private TextProcessorChain defaultTextProcessorChain(NoteEntity note) { TextProcessorChain chain = new TextProcessorChain(); - chain.add(new NoteLinksProcessor(new HashSet<>(roomDatabase.getNoteDao().getRemoteIds(note.getAccountId())))); + chain.add(new NoteLinksProcessor(new HashSet<>(db.getNoteDao().getRemoteIds(note.getAccountId())))); chain.add(new WwwLinksProcessor()); return chain; } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteReadonlyFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteReadonlyFragment.java index 2d35594e..b2041f7b 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteReadonlyFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteReadonlyFragment.java @@ -28,7 +28,6 @@ import com.yydcdut.markdown.syntax.text.TextFactory; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.databinding.FragmentNotePreviewBinding; import it.niedermann.owncloud.notes.shared.model.ISyncCallback; -import it.niedermann.owncloud.notes.persistence.NotesDatabase; import it.niedermann.owncloud.notes.shared.util.MarkDownUtil; import it.niedermann.owncloud.notes.shared.util.NoteLinksUtils; @@ -105,7 +104,7 @@ public class NoteReadonlyFragment extends SearchableBaseNoteFragment { .setOnLinkClickCallback((view, link) -> { if (NoteLinksUtils.isNoteLink(link)) { long noteRemoteId = NoteLinksUtils.extractNoteRemoteId(link); - long noteLocalId = roomDatabase.getNoteDao().getLocalIdByRemoteId(this.note.getAccountId(), noteRemoteId); + long noteLocalId = db.getNoteDao().getLocalIdByRemoteId(this.note.getAccountId(), noteRemoteId); Intent intent = new Intent(requireActivity().getApplicationContext(), EditNoteActivity.class); intent.putExtra(EditNoteActivity.PARAM_NOTE_ID, noteLocalId); startActivity(intent); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/edit/category/CategoryDialogFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/edit/category/CategoryDialogFragment.java index a5802e10..ea8dd1ba 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/edit/category/CategoryDialogFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/edit/category/CategoryDialogFragment.java @@ -14,7 +14,6 @@ import android.widget.EditText; import androidx.annotation.NonNull; import androidx.fragment.app.DialogFragment; import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentManager; import java.util.List; @@ -24,7 +23,7 @@ import it.niedermann.owncloud.notes.branding.BrandedDialogFragment; import it.niedermann.owncloud.notes.branding.BrandingUtil; import it.niedermann.owncloud.notes.databinding.DialogChangeCategoryBinding; import it.niedermann.owncloud.notes.main.NavigationAdapter; -import it.niedermann.owncloud.notes.persistence.NotesDatabase; +import it.niedermann.owncloud.notes.persistence.NotesRoomDatabase; /** * This {@link DialogFragment} allows for the selection of a category. @@ -37,7 +36,7 @@ public class CategoryDialogFragment extends BrandedDialogFragment { private static final String STATE_CATEGORY = "category"; private DialogChangeCategoryBinding binding; - private NotesDatabase db; + private NotesRoomDatabase db; private CategoryDialogListener listener; private EditText editCategory; @@ -82,7 +81,7 @@ public class CategoryDialogFragment extends BrandedDialogFragment { } else { throw new IllegalArgumentException("Calling activity or target fragment must implement " + CategoryDialogListener.class.getSimpleName()); } - db = NotesDatabase.getInstance(getActivity()); + db = NotesRoomDatabase.getInstance(requireActivity()); } @NonNull diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java index e04bdb22..d31e9eb5 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java @@ -47,7 +47,6 @@ import com.nextcloud.android.sso.model.SingleSignOnAccount; import java.net.HttpURLConnection; import java.util.ArrayList; import java.util.List; -import java.util.Map; import it.niedermann.owncloud.notes.FormattingHelpActivity; import it.niedermann.owncloud.notes.LockedActivity; @@ -75,7 +74,6 @@ import it.niedermann.owncloud.notes.persistence.LoadNotesListTask; import it.niedermann.owncloud.notes.persistence.LoadNotesListTask.NotesLoadedListener; import it.niedermann.owncloud.notes.persistence.NoteServerSyncHelper; import it.niedermann.owncloud.notes.persistence.NoteServerSyncHelper.ViewProvider; -import it.niedermann.owncloud.notes.persistence.NotesDatabase; import it.niedermann.owncloud.notes.persistence.NotesRoomDatabase; import it.niedermann.owncloud.notes.persistence.dao.LocalAccountDao; import it.niedermann.owncloud.notes.persistence.entity.CategoryEntity; @@ -88,7 +86,6 @@ import it.niedermann.owncloud.notes.shared.model.CategorySortingMethod; import it.niedermann.owncloud.notes.shared.model.DBNote; import it.niedermann.owncloud.notes.shared.model.ISyncCallback; import it.niedermann.owncloud.notes.shared.model.Item; -import it.niedermann.owncloud.notes.shared.model.LocalAccount; import it.niedermann.owncloud.notes.shared.model.NoteClickListener; import it.niedermann.owncloud.notes.shared.util.NoteUtil; @@ -97,7 +94,6 @@ import static android.view.View.VISIBLE; import static it.niedermann.owncloud.notes.NotesApplication.isDarkThemeActive; import static it.niedermann.owncloud.notes.NotesApplication.isGridViewEnabled; import static it.niedermann.owncloud.notes.branding.BrandingUtil.getSecondaryForegroundColorDependingOnTheme; -import static it.niedermann.owncloud.notes.persistence.entity.LocalAccountEntity.entityToLocalAccount; import static it.niedermann.owncloud.notes.shared.util.ColorUtil.contrastRatioIsSufficient; import static it.niedermann.owncloud.notes.shared.util.SSOUtil.askForNewAccount; import static java.util.Arrays.asList; @@ -143,7 +139,6 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V protected ItemAdapter adapter; - protected NotesDatabase sqliteOpenHelperDatabase = null; protected NotesRoomDatabase roomDatabase = null; private NavigationAdapter adapterCategories; private NavigationItem itemRecent; @@ -195,7 +190,6 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V categoryAdapterSelectedItem = savedInstanceState.getString(SAVED_STATE_NAVIGATION_ADAPTER_SLECTION); } - sqliteOpenHelperDatabase = NotesDatabase.getInstance(this); roomDatabase = NotesRoomDatabase.getInstance(this); gridView = isGridViewEnabled(); @@ -239,7 +233,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V refreshLists(); if (localAccount != null) { synchronize(); - sqliteOpenHelperDatabase.getNoteServerSyncHelper().addCallbackPull(ssoAccount, syncCallBack); + roomDatabase.getNoteServerSyncHelper().addCallbackPull(ssoAccount, syncCallBack); } super.onResume(); } @@ -262,7 +256,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V try { BrandingUtil.saveBrandColors(this, Color.parseColor(localAccount.getColor()), Color.parseColor(localAccount.getTextColor())); ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(getApplicationContext()); - new NotesListViewItemTouchHelper(ssoAccount, this, sqliteOpenHelperDatabase, roomDatabase, adapter, syncCallBack, this::refreshLists, swipeRefreshLayout, this, gridView) + new NotesListViewItemTouchHelper(ssoAccount, this, roomDatabase, adapter, syncCallBack, this::refreshLists, swipeRefreshLayout, this, gridView) .attachToRecyclerView(listView); synchronize(); } catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e) { @@ -384,7 +378,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V localAccount.setColor(capabilities.getColor()); localAccount.setTextColor(capabilities.getTextColor()); BrandingUtil.saveBrandColors(this, Color.parseColor(localAccount.getColor()), Color.parseColor(localAccount.getTextColor())); - sqliteOpenHelperDatabase.updateApiVersion(localAccount.getId(), capabilities.getApiVersion()); + roomDatabase.updateApiVersion(localAccount.getId(), capabilities.getApiVersion()); Log.i(TAG, capabilities.toString()); } catch (Exception e) { if (e instanceof NextcloudHttpRequestFailedException && ((NextcloudHttpRequestFailedException) e).getStatusCode() == HttpURLConnection.HTTP_NOT_MODIFIED) { @@ -524,7 +518,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V if (localAccount == null) { return new ArrayList<>(); } - List<CategoryNavigationItem> categories = sqliteOpenHelperDatabase.getCategories(localAccount.getId()); + List<CategoryNavigationItem> categories = roomDatabase.getCategories(localAccount.getId()); if (!categories.isEmpty() && categories.get(0).label.isEmpty()) { itemUncategorized = categories.get(0); itemUncategorized.label = getString(R.string.action_uncategorized); @@ -895,7 +889,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V if (selected) { v.setSelected(true); mActionMode = startSupportActionMode(new MultiSelectedActionModeCallback( - this, this, sqliteOpenHelperDatabase, roomDatabase, localAccount.getId(), canMoveNoteToAnotherAccounts, adapter, listView, this::refreshLists, getSupportFragmentManager(), activityBinding.searchView + this, this, roomDatabase, localAccount.getId(), canMoveNoteToAnotherAccounts, adapter, listView, this::refreshLists, getSupportFragmentManager(), activityBinding.searchView )); int checkedItemCount = adapter.getSelected().size(); mActionMode.setTitle(getResources().getQuantityString(R.plurals.ab_selected, checkedItemCount, checkedItemCount)); @@ -929,7 +923,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V } private void synchronize() { - NoteServerSyncHelper syncHelper = sqliteOpenHelperDatabase.getNoteServerSyncHelper(); + NoteServerSyncHelper syncHelper = roomDatabase.getNoteServerSyncHelper(); if (!syncHelper.isSyncPossible()) { syncHelper.updateNetworkStatus(); } @@ -954,14 +948,14 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V } @Override - public void onAccountChosen(LocalAccount localAccount) { + public void onAccountChosen(LocalAccountEntity localAccount) { binding.drawerLayout.closeDrawer(GravityCompat.START); selectAccount(localAccount.getAccountName()); } @Override - public void onAccountDeleted(LocalAccount localAccount) { - sqliteOpenHelperDatabase.deleteAccount(localAccount); + public void onAccountDeleted(LocalAccountEntity localAccount) { + roomDatabase.deleteAccount(localAccount); if (localAccount.getId() == this.localAccount.getId()) { List<LocalAccountEntity> remainingAccounts = roomDatabase.getLocalAccountDao().getAccounts(); if (remainingAccounts.size() > 0) { @@ -975,12 +969,12 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V } @Override - public void onAccountPicked(@NonNull LocalAccount account) { + public void onAccountPicked(@NonNull LocalAccountEntity account) { List<Integer> selection = new ArrayList<>(adapter.getSelected()); adapter.deselect(0); for (Integer i : selection) { - DBNote note = (DBNote) adapter.getItem(i); + NoteEntity note = (NoteEntity) adapter.getItem(i); roomDatabase.moveNoteToAnotherAccount(ssoAccount, note.getAccountId(), roomDatabase.getNoteDao().getNote(note.getAccountId(), note.getId()), account.getId()); RecyclerView.ViewHolder viewHolder = listView.findViewHolderForAdapterPosition(i); if (viewHolder != null) { diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/MultiSelectedActionModeCallback.java b/app/src/main/java/it/niedermann/owncloud/notes/main/MultiSelectedActionModeCallback.java index 15dc2ec5..45063c8f 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/MultiSelectedActionModeCallback.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/MultiSelectedActionModeCallback.java @@ -26,12 +26,11 @@ import java.util.ArrayList; import java.util.List; import it.niedermann.owncloud.notes.R; -import it.niedermann.owncloud.notes.branding.BrandedSnackbar; import it.niedermann.owncloud.notes.accountpicker.AccountPickerDialogFragment; +import it.niedermann.owncloud.notes.branding.BrandedSnackbar; import it.niedermann.owncloud.notes.edit.category.CategoryDialogFragment; import it.niedermann.owncloud.notes.main.items.ItemAdapter; import it.niedermann.owncloud.notes.persistence.NoteServerSyncHelper.ViewProvider; -import it.niedermann.owncloud.notes.persistence.NotesDatabase; import it.niedermann.owncloud.notes.persistence.NotesRoomDatabase; import it.niedermann.owncloud.notes.persistence.entity.NoteEntity; import it.niedermann.owncloud.notes.shared.model.DBNote; @@ -44,8 +43,7 @@ public class MultiSelectedActionModeCallback implements Callback { private final Context context; private final ViewProvider viewProvider; - private final NotesDatabase sqliteOpenHelperDatabase; - private final NotesRoomDatabase roomDatabase; + private final NotesRoomDatabase db; private final long currentLocalAccountId; private final boolean canMoveNoteToAnotherAccounts; private final ItemAdapter adapter; @@ -55,11 +53,10 @@ public class MultiSelectedActionModeCallback implements Callback { private final SearchView searchView; public MultiSelectedActionModeCallback( - Context context, ViewProvider viewProvider, NotesDatabase sqliteOpenHelperDatabase, NotesRoomDatabase roomDatabase, long currentLocalAccountId, boolean canMoveNoteToAnotherAccounts, ItemAdapter adapter, RecyclerView recyclerView, Runnable refreshLists, FragmentManager fragmentManager, SearchView searchView) { + Context context, ViewProvider viewProvider, NotesRoomDatabase db, long currentLocalAccountId, boolean canMoveNoteToAnotherAccounts, ItemAdapter adapter, RecyclerView recyclerView, Runnable refreshLists, FragmentManager fragmentManager, SearchView searchView) { this.context = context; this.viewProvider = viewProvider; - this.sqliteOpenHelperDatabase = sqliteOpenHelperDatabase; - this.roomDatabase = roomDatabase; + this.db = db; this.currentLocalAccountId = currentLocalAccountId; this.canMoveNoteToAnotherAccounts = canMoveNoteToAnotherAccounts; this.adapter = adapter; @@ -109,8 +106,8 @@ public class MultiSelectedActionModeCallback implements Callback { List<Integer> selection = adapter.getSelected(); for (Integer i : selection) { DBNote note = (DBNote) adapter.getItem(i); - deletedNotes.add(NoteEntity.entityToDBNote(roomDatabase.getNoteDao().getNote(note.getAccountId(), note.getId()))); - roomDatabase.deleteNoteAndSync(ssoAccount, note.getId()); + deletedNotes.add(NoteEntity.entityToDBNote(db.getNoteDao().getNote(note.getAccountId(), note.getId()))); + db.deleteNoteAndSync(ssoAccount, note.getId()); } mode.finish(); // Action picked, so close the CAB //after delete selection has to be cleared @@ -121,9 +118,9 @@ public class MultiSelectedActionModeCallback implements Callback { : context.getResources().getQuantityString(R.plurals.bulk_notes_deleted, deletedNotes.size(), deletedNotes.size()); BrandedSnackbar.make(viewProvider.getView(), deletedSnackbarTitle, Snackbar.LENGTH_LONG) .setAction(R.string.action_undo, (View v) -> { - sqliteOpenHelperDatabase.getNoteServerSyncHelper().addCallbackPush(ssoAccount, refreshLists::run); + db.getNoteServerSyncHelper().addCallbackPush(ssoAccount, refreshLists::run); for (DBNote deletedNote : deletedNotes) { - roomDatabase.addNoteAndSync(ssoAccount, deletedNote.getAccountId(), deletedNote); + db.addNoteAndSync(ssoAccount, deletedNote.getAccountId(), deletedNote); } refreshLists.run(); String restoreSnackbarTitle = deletedNotes.size() == 1 @@ -149,7 +146,7 @@ public class MultiSelectedActionModeCallback implements Callback { final StringBuilder noteContents = new StringBuilder(); for (Integer i : adapter.getSelected()) { final DBNote noteWithoutContent = (DBNote) adapter.getItem(i); - final String tempFullNote = roomDatabase.getNoteDao().getNote(noteWithoutContent.getAccountId(), noteWithoutContent.getId()).getContent(); + final String tempFullNote = db.getNoteDao().getNote(noteWithoutContent.getAccountId(), noteWithoutContent.getId()).getContent(); if (!TextUtils.isEmpty(tempFullNote)) { if (noteContents.length() > 0) { noteContents.append("\n\n"); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/items/ItemAdapter.java b/app/src/main/java/it/niedermann/owncloud/notes/main/items/ItemAdapter.java index a82aa8c4..ff71c6eb 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/items/ItemAdapter.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/items/ItemAdapter.java @@ -25,16 +25,16 @@ import it.niedermann.owncloud.notes.databinding.ItemNotesListNoteItemGridOnlyTit import it.niedermann.owncloud.notes.databinding.ItemNotesListNoteItemWithExcerptBinding; import it.niedermann.owncloud.notes.databinding.ItemNotesListNoteItemWithoutExcerptBinding; import it.niedermann.owncloud.notes.databinding.ItemNotesListSectionItemBinding; -import it.niedermann.owncloud.notes.persistence.entity.NoteEntity; -import it.niedermann.owncloud.notes.shared.model.DBNote; -import it.niedermann.owncloud.notes.shared.model.Item; -import it.niedermann.owncloud.notes.shared.model.NoteClickListener; import it.niedermann.owncloud.notes.main.items.grid.NoteViewGridHolder; import it.niedermann.owncloud.notes.main.items.grid.NoteViewGridHolderOnlyTitle; import it.niedermann.owncloud.notes.main.items.list.NoteViewHolderWithExcerpt; import it.niedermann.owncloud.notes.main.items.list.NoteViewHolderWithoutExcerpt; import it.niedermann.owncloud.notes.main.items.section.SectionItem; import it.niedermann.owncloud.notes.main.items.section.SectionViewHolder; +import it.niedermann.owncloud.notes.persistence.entity.NoteEntity; +import it.niedermann.owncloud.notes.shared.model.DBNote; +import it.niedermann.owncloud.notes.shared.model.Item; +import it.niedermann.owncloud.notes.shared.model.NoteClickListener; import static it.niedermann.owncloud.notes.shared.util.NoteUtil.getFontSizeFromPreferences; diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/items/NoteViewHolder.java b/app/src/main/java/it/niedermann/owncloud/notes/main/items/NoteViewHolder.java index 43c05b2b..e1cd4d44 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/items/NoteViewHolder.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/items/NoteViewHolder.java @@ -26,12 +26,12 @@ import com.google.android.material.chip.Chip; import java.util.regex.Matcher; import java.util.regex.Pattern; +import it.niedermann.owncloud.notes.NotesApplication; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.branding.BrandingUtil; import it.niedermann.owncloud.notes.shared.model.DBNote; import it.niedermann.owncloud.notes.shared.model.DBStatus; import it.niedermann.owncloud.notes.shared.model.NoteClickListener; -import it.niedermann.owncloud.notes.NotesApplication; import static android.view.View.INVISIBLE; import static android.view.View.VISIBLE; diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/items/grid/NoteViewGridHolder.java b/app/src/main/java/it/niedermann/owncloud/notes/main/items/grid/NoteViewGridHolder.java index 765b970a..78cd52f0 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/items/grid/NoteViewGridHolder.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/items/grid/NoteViewGridHolder.java @@ -11,9 +11,9 @@ import androidx.annotation.Nullable; import androidx.annotation.Px; import it.niedermann.owncloud.notes.databinding.ItemNotesListNoteItemGridBinding; +import it.niedermann.owncloud.notes.main.items.NoteViewHolder; import it.niedermann.owncloud.notes.shared.model.DBNote; import it.niedermann.owncloud.notes.shared.model.NoteClickListener; -import it.niedermann.owncloud.notes.main.items.NoteViewHolder; import static android.view.View.GONE; import static android.view.View.VISIBLE; diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/items/grid/NoteViewGridHolderOnlyTitle.java b/app/src/main/java/it/niedermann/owncloud/notes/main/items/grid/NoteViewGridHolderOnlyTitle.java index 6468e964..52abd8ed 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/items/grid/NoteViewGridHolderOnlyTitle.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/items/grid/NoteViewGridHolderOnlyTitle.java @@ -10,9 +10,9 @@ import androidx.annotation.Nullable; import androidx.annotation.Px; import it.niedermann.owncloud.notes.databinding.ItemNotesListNoteItemGridOnlyTitleBinding; +import it.niedermann.owncloud.notes.main.items.NoteViewHolder; import it.niedermann.owncloud.notes.shared.model.DBNote; import it.niedermann.owncloud.notes.shared.model.NoteClickListener; -import it.niedermann.owncloud.notes.main.items.NoteViewHolder; public class NoteViewGridHolderOnlyTitle extends NoteViewHolder { @NonNull diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NoteViewHolderWithExcerpt.java b/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NoteViewHolderWithExcerpt.java index 0f41d745..a8a5cb45 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NoteViewHolderWithExcerpt.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NoteViewHolderWithExcerpt.java @@ -8,10 +8,10 @@ import androidx.annotation.Nullable; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.databinding.ItemNotesListNoteItemWithExcerptBinding; +import it.niedermann.owncloud.notes.main.items.NoteViewHolder; import it.niedermann.owncloud.notes.shared.model.DBNote; import it.niedermann.owncloud.notes.shared.model.DBStatus; import it.niedermann.owncloud.notes.shared.model.NoteClickListener; -import it.niedermann.owncloud.notes.main.items.NoteViewHolder; public class NoteViewHolderWithExcerpt extends NoteViewHolder { @NonNull diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NoteViewHolderWithoutExcerpt.java b/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NoteViewHolderWithoutExcerpt.java index 9b056925..39a08101 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NoteViewHolderWithoutExcerpt.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NoteViewHolderWithoutExcerpt.java @@ -8,10 +8,10 @@ import androidx.annotation.Nullable; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.databinding.ItemNotesListNoteItemWithoutExcerptBinding; +import it.niedermann.owncloud.notes.main.items.NoteViewHolder; import it.niedermann.owncloud.notes.shared.model.DBNote; import it.niedermann.owncloud.notes.shared.model.DBStatus; import it.niedermann.owncloud.notes.shared.model.NoteClickListener; -import it.niedermann.owncloud.notes.main.items.NoteViewHolder; public class NoteViewHolderWithoutExcerpt extends NoteViewHolder { @NonNull diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NotesListViewItemTouchHelper.java b/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NotesListViewItemTouchHelper.java index caa80d7d..20bbc604 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NotesListViewItemTouchHelper.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NotesListViewItemTouchHelper.java @@ -17,15 +17,14 @@ import com.nextcloud.android.sso.model.SingleSignOnAccount; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.branding.BrandedSnackbar; -import it.niedermann.owncloud.notes.persistence.NotesRoomDatabase; -import it.niedermann.owncloud.notes.persistence.entity.NoteEntity; -import it.niedermann.owncloud.notes.shared.model.DBNote; -import it.niedermann.owncloud.notes.shared.model.ISyncCallback; import it.niedermann.owncloud.notes.main.items.ItemAdapter; import it.niedermann.owncloud.notes.main.items.NoteViewHolder; import it.niedermann.owncloud.notes.main.items.section.SectionViewHolder; import it.niedermann.owncloud.notes.persistence.NoteServerSyncHelper.ViewProvider; -import it.niedermann.owncloud.notes.persistence.NotesDatabase; +import it.niedermann.owncloud.notes.persistence.NotesRoomDatabase; +import it.niedermann.owncloud.notes.persistence.entity.NoteEntity; +import it.niedermann.owncloud.notes.shared.model.DBNote; +import it.niedermann.owncloud.notes.shared.model.ISyncCallback; public class NotesListViewItemTouchHelper extends ItemTouchHelper { @@ -35,7 +34,6 @@ public class NotesListViewItemTouchHelper extends ItemTouchHelper { public NotesListViewItemTouchHelper( @NonNull SingleSignOnAccount ssoAccount, @NonNull Context context, - @NonNull NotesDatabase sqliteOpenHelperDatabase, @NonNull NotesRoomDatabase roomDatabase, @NonNull ItemAdapter adapter, @NonNull ISyncCallback syncCallBack, @@ -85,7 +83,7 @@ public class NotesListViewItemTouchHelper extends ItemTouchHelper { } else { BrandedSnackbar.make(viewProvider.getView(), context.getString(R.string.action_note_deleted, dbNote.getTitle()), UNDO_DURATION) .setAction(R.string.action_undo, (View v) -> { - sqliteOpenHelperDatabase.getNoteServerSyncHelper().addCallbackPush(ssoAccount, refreshLists::run); + roomDatabase.getNoteServerSyncHelper().addCallbackPush(ssoAccount, refreshLists::run); roomDatabase.addNoteAndSync(ssoAccount, dbNote.getAccountId(), dbNote); refreshLists.run(); BrandedSnackbar.make(viewProvider.getView(), context.getString(R.string.action_note_restored, dbNote.getTitle()), Snackbar.LENGTH_SHORT) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountAdapter.java b/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountAdapter.java index f02a1581..03e18162 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountAdapter.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountAdapter.java @@ -13,22 +13,19 @@ import java.util.List; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.persistence.entity.LocalAccountEntity; -import it.niedermann.owncloud.notes.shared.model.LocalAccount; - -import static it.niedermann.owncloud.notes.persistence.entity.LocalAccountEntity.entityToLocalAccount; public class ManageAccountAdapter extends RecyclerView.Adapter<ManageAccountViewHolder> { @Nullable - private LocalAccount currentLocalAccount = null; + private LocalAccountEntity currentLocalAccount = null; @NonNull private final List<LocalAccountEntity> localAccounts = new ArrayList<>(); @NonNull - private final Consumer<LocalAccount> onAccountClick; + private final Consumer<LocalAccountEntity> onAccountClick; @Nullable - private final Consumer<LocalAccount> onAccountDelete; + private final Consumer<LocalAccountEntity> onAccountDelete; - public ManageAccountAdapter(@NonNull Consumer<LocalAccount> onAccountClick, @Nullable Consumer<LocalAccount> onAccountDelete) { + public ManageAccountAdapter(@NonNull Consumer<LocalAccountEntity> onAccountClick, @Nullable Consumer<LocalAccountEntity> onAccountDelete) { this.onAccountClick = onAccountClick; this.onAccountDelete = onAccountDelete; setHasStableIds(true); @@ -48,7 +45,7 @@ public class ManageAccountAdapter extends RecyclerView.Adapter<ManageAccountView @Override public void onBindViewHolder(@NonNull ManageAccountViewHolder holder, int position) { final LocalAccountEntity localAccount = localAccounts.get(position); - holder.bind(entityToLocalAccount(localAccount), (localAccountClicked) -> { + holder.bind(localAccount, (localAccountClicked) -> { setCurrentLocalAccount(localAccountClicked); onAccountClick.accept(localAccountClicked); }, (localAccountToDelete -> { @@ -76,7 +73,7 @@ public class ManageAccountAdapter extends RecyclerView.Adapter<ManageAccountView notifyDataSetChanged(); } - public void setCurrentLocalAccount(@Nullable LocalAccount currentLocalAccount) { + public void setCurrentLocalAccount(@Nullable LocalAccountEntity currentLocalAccount) { this.currentLocalAccount = currentLocalAccount; notifyDataSetChanged(); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountViewHolder.java b/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountViewHolder.java index 0ec7f186..a5794505 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountViewHolder.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountViewHolder.java @@ -1,5 +1,6 @@ package it.niedermann.owncloud.notes.manageaccounts; +import android.graphics.Color; import android.graphics.drawable.LayerDrawable; import android.net.Uri; import android.view.View; @@ -15,7 +16,7 @@ import com.bumptech.glide.request.RequestOptions; import it.niedermann.android.glidesso.SingleSignOnUrl; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.databinding.ItemAccountChooseBinding; -import it.niedermann.owncloud.notes.shared.model.LocalAccount; +import it.niedermann.owncloud.notes.persistence.entity.LocalAccountEntity; import static android.view.View.GONE; import static android.view.View.VISIBLE; @@ -30,11 +31,11 @@ public class ManageAccountViewHolder extends RecyclerView.ViewHolder { binding = ItemAccountChooseBinding.bind(itemView); } - public void bind(@NonNull LocalAccount localAccount, @NonNull Consumer<LocalAccount> onAccountClick, @Nullable Consumer<LocalAccount> onAccountDelete, boolean isCurrentAccount) { - binding.accountName.setText(localAccount.getUserName()); + public void bind(@NonNull LocalAccountEntity localAccount, @NonNull Consumer<LocalAccountEntity> onAccountClick, @Nullable Consumer<LocalAccountEntity> onAccountDelete, boolean isCurrentAccount) { + binding.accountName.setText(localAccount.getUsername()); binding.accountHost.setText(Uri.parse(localAccount.getUrl()).getHost()); Glide.with(itemView.getContext()) - .load(new SingleSignOnUrl(localAccount.getAccountName(), localAccount.getUrl() + "/index.php/avatar/" + Uri.encode(localAccount.getUserName()) + "/64")) + .load(new SingleSignOnUrl(localAccount.getAccountName(), localAccount.getUrl() + "/index.php/avatar/" + Uri.encode(localAccount.getUsername()) + "/64")) .error(R.drawable.ic_account_circle_grey_24dp) .apply(RequestOptions.circleCropTransform()) .into(binding.accountItemAvatar); @@ -47,7 +48,7 @@ public class ManageAccountViewHolder extends RecyclerView.ViewHolder { } if (isCurrentAccount) { binding.currentAccountIndicator.setVisibility(VISIBLE); - applyBrandToLayerDrawable((LayerDrawable) binding.currentAccountIndicator.getDrawable(), R.id.area, localAccount.getColor()); + applyBrandToLayerDrawable((LayerDrawable) binding.currentAccountIndicator.getDrawable(), R.id.area, Color.parseColor(localAccount.getColor())); } else { binding.currentAccountIndicator.setVisibility(GONE); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java index 73a2fbc6..ae5d2165 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java @@ -16,16 +16,11 @@ import it.niedermann.owncloud.notes.LockedActivity; import it.niedermann.owncloud.notes.databinding.ActivityManageAccountsBinding; import it.niedermann.owncloud.notes.persistence.NotesRoomDatabase; import it.niedermann.owncloud.notes.persistence.entity.LocalAccountEntity; -import it.niedermann.owncloud.notes.shared.model.LocalAccount; -import it.niedermann.owncloud.notes.persistence.NotesDatabase; - -import static it.niedermann.owncloud.notes.persistence.entity.LocalAccountEntity.entityToLocalAccount; public class ManageAccountsActivity extends LockedActivity { private ActivityManageAccountsBinding binding; private ManageAccountAdapter adapter; - private NotesDatabase sqliteOpenHelperDatabase = null; private NotesRoomDatabase roomDatabase = null; @Override @@ -37,13 +32,12 @@ public class ManageAccountsActivity extends LockedActivity { setSupportActionBar(binding.toolbar); - sqliteOpenHelperDatabase = NotesDatabase.getInstance(this); roomDatabase = NotesRoomDatabase.getInstance(this); List<LocalAccountEntity> localAccounts = roomDatabase.getLocalAccountDao().getAccounts(); adapter = new ManageAccountAdapter((localAccount) -> SingleAccountHelper.setCurrentAccount(getApplicationContext(), localAccount.getAccountName()), (localAccount) -> { - sqliteOpenHelperDatabase.deleteAccount(localAccount); + roomDatabase.deleteAccount(localAccount); for (LocalAccountEntity temp : localAccounts) { if (temp.getId() == localAccount.getId()) { localAccounts.remove(temp); @@ -52,7 +46,7 @@ public class ManageAccountsActivity extends LockedActivity { } if (localAccounts.size() > 0) { SingleAccountHelper.setCurrentAccount(getApplicationContext(), localAccounts.get(0).getAccountName()); - adapter.setCurrentLocalAccount(entityToLocalAccount(localAccounts.get(0))); + adapter.setCurrentLocalAccount(localAccounts.get(0)); } else { setResult(AppCompatActivity.RESULT_FIRST_USER); finish(); @@ -62,7 +56,7 @@ public class ManageAccountsActivity extends LockedActivity { try { SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(this); if (ssoAccount != null) { - adapter.setCurrentLocalAccount(entityToLocalAccount(roomDatabase.getLocalAccountDao().getLocalAccountByAccountName(ssoAccount.name))); + adapter.setCurrentLocalAccount(roomDatabase.getLocalAccountDao().getLocalAccountByAccountName(ssoAccount.name)); } } catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e) { e.printStackTrace(); 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 index 46d36e1c..5d46eda7 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/AbstractNotesDatabase.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/AbstractNotesDatabase.java @@ -24,6 +24,9 @@ import it.niedermann.owncloud.notes.persistence.migration.Migration_8_9; import it.niedermann.owncloud.notes.persistence.migration.Migration_9_10; import it.niedermann.owncloud.notes.shared.util.DatabaseIndexUtil; +import static it.niedermann.owncloud.notes.widget.notelist.NoteListWidget.updateNoteListWidgets; +import static it.niedermann.owncloud.notes.widget.singlenote.SingleNoteWidget.updateSingleNoteWidgets; + abstract class AbstractNotesDatabase extends SQLiteOpenHelper { private static final int database_version = 19; @@ -210,5 +213,12 @@ abstract class AbstractNotesDatabase extends SQLiteOpenHelper { onCreate(db); } - protected abstract void notifyWidgets(); + + /** + * Notify about changed notes. + */ + protected void notifyWidgets() { + updateSingleNoteWidgets(getContext()); + updateNoteListWidgets(getContext()); + } } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/CapabilitiesWorker.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/CapabilitiesWorker.java index e0925188..1ffa7629 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/CapabilitiesWorker.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/CapabilitiesWorker.java @@ -22,7 +22,6 @@ import java.util.concurrent.TimeUnit; import it.niedermann.owncloud.notes.persistence.entity.LocalAccountEntity; import it.niedermann.owncloud.notes.shared.model.Capabilities; -import it.niedermann.owncloud.notes.shared.model.LocalAccount; public class CapabilitiesWorker extends Worker { @@ -52,7 +51,7 @@ public class CapabilitiesWorker extends Worker { final Capabilities capabilities = CapabilitiesClient.getCapabilities(getApplicationContext(), ssoAccount, account.getCapabilitiesETag()); roomDatabase.getLocalAccountDao().updateCapabilitiesETag(account.getId(), capabilities.getETag()); roomDatabase.updateBrand(account.getId(), capabilities); - sqliteOpenHelperDatabase.updateApiVersion(account.getId(), capabilities.getApiVersion()); + roomDatabase.updateApiVersion(account.getId(), capabilities.getApiVersion()); Log.i(TAG, capabilities.toString()); } catch (Exception e) { if (e instanceof NextcloudHttpRequestFailedException) { diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/LoadNotesListTask.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/LoadNotesListTask.java index 973b74aa..3527d102 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/LoadNotesListTask.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/LoadNotesListTask.java @@ -13,12 +13,12 @@ import java.util.Calendar; import java.util.List; import it.niedermann.owncloud.notes.R; +import it.niedermann.owncloud.notes.main.items.section.SectionItem; import it.niedermann.owncloud.notes.persistence.entity.NoteEntity; import it.niedermann.owncloud.notes.shared.model.Category; +import it.niedermann.owncloud.notes.shared.model.CategorySortingMethod; import it.niedermann.owncloud.notes.shared.model.DBNote; import it.niedermann.owncloud.notes.shared.model.Item; -import it.niedermann.owncloud.notes.main.items.section.SectionItem; -import it.niedermann.owncloud.notes.shared.model.CategorySortingMethod; import it.niedermann.owncloud.notes.shared.util.NoteUtil; public class LoadNotesListTask extends AsyncTask<Void, Void, List<Item>> { 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 0783bc13..a3f0d509 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 @@ -37,16 +37,12 @@ import it.niedermann.owncloud.notes.branding.BrandedSnackbar; import it.niedermann.owncloud.notes.exception.ExceptionDialogFragment; import it.niedermann.owncloud.notes.persistence.entity.LocalAccountEntity; import it.niedermann.owncloud.notes.persistence.entity.NoteEntity; -import it.niedermann.owncloud.notes.shared.model.CloudNote; -import it.niedermann.owncloud.notes.shared.model.DBNote; import it.niedermann.owncloud.notes.shared.model.DBStatus; import it.niedermann.owncloud.notes.shared.model.ISyncCallback; -import it.niedermann.owncloud.notes.shared.model.LocalAccount; import it.niedermann.owncloud.notes.shared.model.ServerResponse; import it.niedermann.owncloud.notes.shared.model.SyncResultStatus; import it.niedermann.owncloud.notes.shared.util.SSOUtil; -import static it.niedermann.owncloud.notes.persistence.entity.LocalAccountEntity.entityToLocalAccount; import static java.net.HttpURLConnection.HTTP_NOT_FOUND; import static java.net.HttpURLConnection.HTTP_NOT_MODIFIED; @@ -59,8 +55,7 @@ public class NoteServerSyncHelper { private static NoteServerSyncHelper instance; - private final NotesDatabase sqliteOpenHelperDatabase; - private final NotesRoomDatabase roomDatabase; + private final NotesRoomDatabase db; private final Context context; // Track network connection changes using a BroadcastReceiver @@ -102,10 +97,9 @@ public class NoteServerSyncHelper { private final Map<String, List<ISyncCallback>> callbacksPush = new HashMap<>(); private final Map<String, List<ISyncCallback>> callbacksPull = new HashMap<>(); - private NoteServerSyncHelper(NotesDatabase sqliteOpenHelperDatabase, NotesRoomDatabase roomDatabase) { - this.sqliteOpenHelperDatabase = sqliteOpenHelperDatabase; - this.roomDatabase = roomDatabase; - this.context = sqliteOpenHelperDatabase.getContext(); + private NoteServerSyncHelper(NotesRoomDatabase db) { + this.db = db; + this.context = db.getContext(); this.syncOnlyOnWifiKey = context.getApplicationContext().getResources().getString(R.string.pref_key_wifi_only); // Registers BroadcastReceiver to track network connection changes. @@ -123,12 +117,12 @@ public class NoteServerSyncHelper { * This has to be a singleton in order to realize correct registering and unregistering of * the BroadcastReceiver, which listens on changes of network connectivity. * - * @param sqliteOpenHelperDatabase NoteSQLiteOpenHelper + * @param roomDatabase {@link NotesRoomDatabase} * @return NoteServerSyncHelper */ - public static synchronized NoteServerSyncHelper getInstance(NotesDatabase sqliteOpenHelperDatabase, NotesRoomDatabase roomDatabase) { + public static synchronized NoteServerSyncHelper getInstance(NotesRoomDatabase roomDatabase) { if (instance == null) { - instance = new NoteServerSyncHelper(sqliteOpenHelperDatabase, roomDatabase); + instance = new NoteServerSyncHelper(roomDatabase); } return instance; } @@ -219,7 +213,7 @@ public class NoteServerSyncHelper { Log.d(TAG, "Sync requested (" + (onlyLocalChanges ? "onlyLocalChanges" : "full") + "; " + (Boolean.TRUE.equals(syncActive.get(ssoAccount.name)) ? "sync active" : "sync NOT active") + ") ..."); if (isSyncPossible() && (!Boolean.TRUE.equals(syncActive.get(ssoAccount.name)) || onlyLocalChanges)) { Log.d(TAG, "... starting now"); - final LocalAccountEntity localAccount = roomDatabase.getLocalAccountDao().getLocalAccountByAccountName(ssoAccount.name); + final LocalAccountEntity localAccount = db.getLocalAccountDao().getLocalAccountByAccountName(ssoAccount.name); if (localAccount == null) { Log.e(TAG, LocalAccountEntity.class.getSimpleName() + " for ssoAccount \"" + ssoAccount.name + "\" is null. Cannot synchronize.", new IllegalStateException()); return; @@ -363,7 +357,7 @@ public class NoteServerSyncHelper { Log.d(TAG, "pushLocalChanges()"); boolean success = true; - List<NoteEntity> notes = roomDatabase.getNoteDao().getLocalModifiedNotes(localAccount.getId()); + List<NoteEntity> notes = db.getNoteDao().getLocalModifiedNotes(localAccount.getId()); for (NoteEntity note : notes) { Log.d(TAG, " Process Local Note: " + note); try { @@ -388,7 +382,7 @@ public class NoteServerSyncHelper { remoteNote = notesClient.createNote(ssoAccount, note).getNote(); } // Please note, that db.updateNote() realizes an optimistic conflict resolution, which is required for parallel changes of this Note from the UI. - roomDatabase.updateNote(localAccount.getId(), note.getId(), remoteNote, note); + db.updateNote(localAccount.getId(), note.getId(), remoteNote, note); break; case LOCAL_DELETED: if (note.getRemoteId() > 0) { @@ -406,7 +400,7 @@ public class NoteServerSyncHelper { Log.v(TAG, " ...delete (only local, since it has never been synchronized)"); } // Please note, that db.deleteNote() realizes an optimistic conflict resolution, which is required for parallel changes of this Note from the UI. - roomDatabase.deleteNote(note.getId(), DBStatus.LOCAL_DELETED); + db.deleteNote(note.getId(), DBStatus.LOCAL_DELETED); break; default: throw new IllegalStateException("Unknown State of Note: " + note); @@ -435,7 +429,7 @@ public class NoteServerSyncHelper { private boolean pullRemoteChanges() { Log.d(TAG, "pullRemoteChanges() for account " + localAccount.getAccountName()); try { - final Map<Long, Long> idMap = roomDatabase.getIdMap(localAccount.getId()); + final Map<Long, Long> idMap = db.getIdMap(localAccount.getId()); final ServerResponse.NotesResponse response = notesClient.getNotes(ssoAccount, localAccount.getModified(), localAccount.getETag()); List<NoteEntity> remoteNotes = response.getNotes(); Set<Long> remoteIDs = new HashSet<>(); @@ -449,13 +443,13 @@ public class NoteServerSyncHelper { Log.v(TAG, " ... found → Update"); Long remoteId = idMap.get(remoteNote.getRemoteId()); if (remoteId != null) { - roomDatabase.updateNote(localAccount.getId(), remoteId, remoteNote, null); + db.updateNote(localAccount.getId(), remoteId, remoteNote, null); } else { Log.e(TAG, "Tried to update note from server, but remoteId of note is null. " + remoteNote); } } else { Log.v(TAG, " ... create"); - roomDatabase.addNote(localAccount.getId(), remoteNote); + db.addNote(localAccount.getId(), remoteNote); } } Log.d(TAG, " Remove remotely deleted Notes (only those without local changes)"); @@ -463,17 +457,17 @@ public class NoteServerSyncHelper { for (Map.Entry<Long, Long> entry : idMap.entrySet()) { if (!remoteIDs.contains(entry.getKey())) { Log.v(TAG, " ... remove " + entry.getValue()); - roomDatabase.deleteNote(entry.getValue(), DBStatus.VOID); + db.deleteNote(entry.getValue(), DBStatus.VOID); } } // update ETag and Last-Modified in order to reduce size of next response localAccount.setETag(response.getETag()); localAccount.setModified(response.getLastModified()); - roomDatabase.getLocalAccountDao().updateETag(localAccount.getId(), localAccount.getETag()); - roomDatabase.getLocalAccountDao().updateModified(localAccount.getId(), localAccount.getModified()); + db.getLocalAccountDao().updateETag(localAccount.getId(), localAccount.getETag()); + db.getLocalAccountDao().updateModified(localAccount.getId(), localAccount.getModified()); try { - if (sqliteOpenHelperDatabase.updateApiVersion(localAccount.getId(), response.getSupportedApiVersions())) { + if (db.updateApiVersion(localAccount.getId(), response.getSupportedApiVersions())) { localAccount.setPreferredApiVersion(response.getSupportedApiVersions()); } } catch (Exception e) { @@ -518,8 +512,8 @@ public class NoteServerSyncHelper { callback.onFinish(); } } - sqliteOpenHelperDatabase.notifyWidgets(); - roomDatabase.updateDynamicShortcuts(localAccount.getId()); + db.notifyWidgets(); + db.updateDynamicShortcuts(localAccount.getId()); // start next sync if scheduled meanwhile if (syncScheduled.containsKey(ssoAccount.name) && syncScheduled.get(ssoAccount.name) != null && Boolean.TRUE.equals(syncScheduled.get(ssoAccount.name))) { scheduleSync(ssoAccount, false); 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 941dd7f2..7134025e 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 @@ -27,7 +27,6 @@ import java.util.Objects; import it.niedermann.owncloud.notes.persistence.entity.NoteEntity; import it.niedermann.owncloud.notes.shared.model.ApiVersion; -import it.niedermann.owncloud.notes.shared.model.CloudNote; import it.niedermann.owncloud.notes.shared.model.ServerResponse.NoteResponse; import it.niedermann.owncloud.notes.shared.model.ServerResponse.NotesResponse; 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 bcdf5fff..b2ec6164 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 @@ -13,7 +13,6 @@ import java.util.HashMap; import java.util.Map; import it.niedermann.owncloud.notes.persistence.entity.NoteEntity; -import it.niedermann.owncloud.notes.shared.model.CloudNote; import it.niedermann.owncloud.notes.shared.model.ServerResponse.NoteResponse; import it.niedermann.owncloud.notes.shared.model.ServerResponse.NotesResponse; 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 deleted file mode 100644 index 08cdd89e..00000000 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java +++ /dev/null @@ -1,329 +0,0 @@ -package it.niedermann.owncloud.notes.persistence; - -import android.content.ContentValues; -import android.content.Context; -import android.content.res.Resources; -import android.database.Cursor; -import android.database.sqlite.SQLiteDatabase; -import android.text.TextUtils; -import android.util.Log; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.WorkerThread; - -import com.nextcloud.android.sso.AccountImporter; -import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException; -import com.nextcloud.android.sso.model.SingleSignOnAccount; - -import org.json.JSONArray; -import org.json.JSONException; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.List; - -import it.niedermann.owncloud.notes.R; -import it.niedermann.owncloud.notes.main.NavigationAdapter; -import it.niedermann.owncloud.notes.shared.model.ApiVersion; -import it.niedermann.owncloud.notes.shared.model.CategorySortingMethod; -import it.niedermann.owncloud.notes.shared.model.CloudNote; -import it.niedermann.owncloud.notes.shared.model.DBNote; -import it.niedermann.owncloud.notes.shared.model.DBStatus; -import it.niedermann.owncloud.notes.shared.model.ISyncCallback; -import it.niedermann.owncloud.notes.shared.model.LocalAccount; -import it.niedermann.owncloud.notes.shared.util.NoteUtil; - -import static it.niedermann.owncloud.notes.shared.util.NoteUtil.generateNoteExcerpt; -import static it.niedermann.owncloud.notes.widget.notelist.NoteListWidget.updateNoteListWidgets; -import static it.niedermann.owncloud.notes.widget.singlenote.SingleNoteWidget.updateSingleNoteWidgets; - -/** - * Helps to add, get, update and delete Notes with the option to trigger a Resync with the Server. - */ -@Deprecated -public class NotesDatabase extends AbstractNotesDatabase { - - private static final String TAG = NotesDatabase.class.getSimpleName(); - - private static NotesDatabase instance; - - private final NoteServerSyncHelper serverSyncHelper; - - private NotesDatabase(@NonNull Context context) { - super(context, database_name, null); - serverSyncHelper = NoteServerSyncHelper.getInstance(this, NotesRoomDatabase.getInstance(context)); - } - - public static NotesDatabase getInstance(Context context) { - if (instance == null) - return instance = new NotesDatabase(context); - else - return instance; - } - - public NoteServerSyncHelper getNoteServerSyncHelper() { - return serverSyncHelper; - } - - /** - * This method return all of the categories with given accountId - * - * @param accountId The user account Id - * @return All of the categories with given accountId - */ - @NonNull - @WorkerThread - public List<NavigationAdapter.CategoryNavigationItem> getCategories(long accountId) { - return searchCategories(accountId, null); - } - - /** - * This method return the category list containing all of the categories containing the - * search pattern and matched with the given accountId - * The join operation is used because it is needed that the number of notes in each category - * If search pattern is null, this method will return all of the categories for corresponding accountId - * - * @param accountId The user account ID - * @param search The search pattern - * @return The category list containing all of the categories matched - */ - @NonNull - @WorkerThread - public List<NavigationAdapter.CategoryNavigationItem> searchCategories(long accountId, String search) { - validateAccountId(accountId); - String columns = key_category_id + ", " + key_category_title + ", COUNT(*)"; - String selection = key_status + " != ? AND " + - key_category_account_id + " = ? AND " + - key_category_title + " LIKE ? " + - (search == null ? "" : " AND " + key_category_title + " != \"\""); - String rawQuery = "SELECT " + columns + - " FROM " + table_category + - " INNER JOIN " + table_notes + - " ON " + key_category + " = " + key_category_id + - " WHERE " + selection + - " GROUP BY " + key_category_title; - - Cursor cursor = getReadableDatabase().rawQuery(rawQuery, - new String[]{DBStatus.LOCAL_DELETED.getTitle(), String.valueOf(accountId), - search == null ? "%" : "%" + search.trim() + "%"}); - - List<NavigationAdapter.CategoryNavigationItem> categories = new ArrayList<>(cursor.getCount()); - while (cursor.moveToNext()) { - Resources res = getContext().getResources(); - String category = cursor.getString(1).toLowerCase(); - int icon = NavigationAdapter.ICON_FOLDER; - if (category.equals(res.getString(R.string.category_music).toLowerCase())) { - icon = R.drawable.ic_library_music_grey600_24dp; - } else if (category.equals(res.getString(R.string.category_movies).toLowerCase()) || category.equals(res.getString(R.string.category_movie).toLowerCase())) { - icon = R.drawable.ic_local_movies_grey600_24dp; - } else if (category.equals(res.getString(R.string.category_work).toLowerCase())) { - icon = R.drawable.ic_work_grey600_24dp; - } - categories.add(new NavigationAdapter.CategoryNavigationItem("category:" + cursor.getString(1), cursor.getString(1), cursor.getInt(2), icon, cursor.getLong(0))); - } - - cursor.close(); - return categories; - } - - private long addCategory(long accountId, @NonNull String title) { - validateAccountId(accountId); - SQLiteDatabase db = getWritableDatabase(); - ContentValues values = new ContentValues(2); - values.put(key_category_account_id, accountId); - values.put(key_category_title, title); - return db.insert(table_category, null, values); - } - - public DBNote updateNoteAndSync(SingleSignOnAccount ssoAccount, @NonNull LocalAccount localAccount, @NonNull DBNote oldNote, @Nullable String newContent, @Nullable ISyncCallback callback) { - return updateNoteAndSync(ssoAccount, localAccount, oldNote, newContent, null, callback); - } - - /** - * Updates a single Note with a new content. - * The title is derived from the new content automatically, and modified date as well as DBStatus are updated, too -- if the content differs to the state in the database. - * - * @param oldNote Note to be changed - * @param newContent New content. If this is <code>null</code>, then <code>oldNote</code> is saved again (useful for undoing changes). - * @param newTitle New title. If this is <code>null</code>, then either the old title is reused (in case the note has been synced before) or a title is generated (in case it is a new note) - * @param callback When the synchronization is finished, this callback will be invoked (optional). - * @return changed {@link DBNote} if differs from database, otherwise the old {@link DBNote}. - */ - public DBNote updateNoteAndSync(SingleSignOnAccount ssoAccount, @NonNull LocalAccount localAccount, @NonNull DBNote oldNote, @Nullable String newContent, @Nullable String newTitle, @Nullable ISyncCallback callback) { - DBNote newNote; - if (newContent == null) { - newNote = new DBNote(oldNote.getId(), oldNote.getRemoteId(), oldNote.getModified(), oldNote.getTitle(), oldNote.getContent(), oldNote.isFavorite(), oldNote.getCategory(), oldNote.getEtag(), DBStatus.LOCAL_EDITED, localAccount.getId(), oldNote.getExcerpt(), oldNote.getScrollY()); - } else { - final String title; - if (newTitle != null) { - title = newTitle; - } else { - if (oldNote.getRemoteId() == 0 || localAccount.getPreferredApiVersion() == null || localAccount.getPreferredApiVersion().compareTo(new ApiVersion("1.0", 0, 0)) < 0) { - title = NoteUtil.generateNonEmptyNoteTitle(newContent, getContext()); - } else { - title = oldNote.getTitle(); - } - } - newNote = new DBNote(oldNote.getId(), oldNote.getRemoteId(), Calendar.getInstance(), title, newContent, oldNote.isFavorite(), oldNote.getCategory(), oldNote.getEtag(), DBStatus.LOCAL_EDITED, localAccount.getId(), generateNoteExcerpt(newContent, title), oldNote.getScrollY()); - } - SQLiteDatabase db = this.getWritableDatabase(); - ContentValues values = new ContentValues(7); - values.put(key_status, newNote.getStatus().getTitle()); - values.put(key_title, newNote.getTitle()); - values.put(key_category, getCategoryIdByTitle(newNote.getAccountId(), newNote.getCategory())); - values.put(key_modified, newNote.getModified().getTimeInMillis() / 1000); - values.put(key_content, newNote.getContent()); - values.put(key_excerpt, newNote.getExcerpt()); - values.put(key_scroll_y, newNote.getScrollY()); - int rows = db.update(table_notes, values, key_id + " = ? AND (" + key_content + " != ? OR " + key_category + " != ?)", new String[]{String.valueOf(newNote.getId()), newNote.getContent(), newNote.getCategory()}); - removeEmptyCategory(localAccount.getId()); - // if data was changed, set new status and schedule sync (with callback); otherwise invoke callback directly. - if (rows > 0) { - notifyWidgets(); - if (callback != null) { - serverSyncHelper.addCallbackPush(ssoAccount, callback); - } - serverSyncHelper.scheduleSync(ssoAccount, true); - return newNote; - } else { - if (callback != null) { - callback.onFinish(); - } - return oldNote; - } - } - - /** - * Notify about changed notes. - */ - protected void notifyWidgets() { - updateSingleNoteWidgets(getContext()); - updateNoteListWidgets(getContext()); - } - - /** - * @param apiVersion has to be a JSON array as a string <code>["0.2", "1.0", ...]</code> - * @return whether or not the given {@link ApiVersion} has been written to the database - * @throws IllegalArgumentException if the apiVersion does not match the expected format - */ - public boolean updateApiVersion(long accountId, @Nullable String apiVersion) throws IllegalArgumentException { - validateAccountId(accountId); - if (apiVersion != null) { - try { - JSONArray apiVersions = new JSONArray(apiVersion); - for (int i = 0; i < apiVersions.length(); i++) { - ApiVersion.of(apiVersions.getString(i)); - } - if (apiVersions.length() > 0) { - final SQLiteDatabase db = this.getWritableDatabase(); - final ContentValues values = new ContentValues(1); - values.put(key_api_version, apiVersion); - final int updatedRows = db.update(table_accounts, values, key_id + " = ?", new String[]{String.valueOf(accountId)}); - if (updatedRows == 1) { - Log.i(TAG, "Updated " + key_api_version + " to \"" + apiVersion + "\" for accountId = " + accountId); - } else { - Log.e(TAG, "Updated " + updatedRows + " but expected only 1 for accountId = " + accountId + " and apiVersion = \"" + apiVersion + "\""); - } - return true; - } else { - Log.i(TAG, "Given API version is a valid JSON array but does not contain any valid API versions. Do not update database."); - } - } catch (NumberFormatException e) { - throw new IllegalArgumentException("API version does contain a non-valid version: " + apiVersion); - } catch (JSONException e) { - throw new IllegalArgumentException("API version must contain be a JSON array: " + apiVersion); - } - } else { - Log.v(TAG, "Given API version is null. Do not update database"); - } - return false; - } - - /** - * @param localAccount the {@link LocalAccount} that should be deleted - * @throws IllegalArgumentException if no account has been deleted by the given accountId - */ - public void deleteAccount(@NonNull LocalAccount localAccount) throws IllegalArgumentException { - validateAccountId(localAccount.getId()); - SQLiteDatabase db = this.getWritableDatabase(); - int deletedAccounts = db.delete(table_accounts, key_id + " = ?", new String[]{String.valueOf(localAccount.getId())}); - if (deletedAccounts < 1) { - Log.e(TAG, "AccountId '" + localAccount.getId() + "' did not delete any account"); - throw new IllegalArgumentException("The given accountId does not delete any row"); - } else if (deletedAccounts > 1) { - Log.e(TAG, "AccountId '" + localAccount.getId() + "' deleted unexpectedly '" + deletedAccounts + "' accounts"); - } - - try { - SSOClient.invalidateAPICache(AccountImporter.getSingleSignOnAccount(getContext(), localAccount.getAccountName())); - } catch (NextcloudFilesAppAccountNotFoundException e) { - e.printStackTrace(); - SSOClient.invalidateAPICache(); - } - - final int deletedNotes = db.delete(table_notes, key_account_id + " = ?", new String[]{String.valueOf(localAccount.getId())}); - Log.v(TAG, "Deleted " + deletedNotes + " notes from account " + localAccount.getId()); - } - - private static void validateAccountId(long accountId) { - if (accountId < 1) { - throw new IllegalArgumentException("accountId must be greater than 0"); - } - } - - /** - * Get the category if with the given category title - * The method does not support fuzzy search. - * Because the category title in database is unique, there will not at most one result. - * If there is no such category, database will create it if create flag is set. - * Otherwise this method will return -1 as default value. - * - * @param accountId The user {@link LocalAccount} Id - * @param categoryTitle The category title which will be search in the db - * @return -1 if there is no such category else the corresponding id - * @deprecated replaced by #{{@link NotesRoomDatabase#getOrCreateCategoryIdByTitle(long, String)}} - */ - @NonNull - @WorkerThread - @Deprecated - private Integer getCategoryIdByTitle(long accountId, @NonNull String categoryTitle) { - validateAccountId(accountId); - SQLiteDatabase db = getReadableDatabase(); - Cursor cursor = db.query( - table_category, - new String[]{key_category_id}, - key_category_title + " = ? AND " + key_category_account_id + " = ? ", - new String[]{categoryTitle, String.valueOf(accountId)}, - null, - null, - null); - int id; - if (cursor.moveToNext()) { - id = cursor.getInt(0); - } else { - id = (int) addCategory(accountId, categoryTitle); - if (id == -1) { - Log.e(TAG, String.format("Error occurs when creating category: %s", categoryTitle)); - } - } - cursor.close(); - return id; - } - - /** - * This function will be called when the category or note is updated. - * Because sometime we will remove some notes in categories. - * Such that there must be such a category without any note. - * For these useless category, it is better to remove. - * Move a note from a category to another may also lead to the same result. - * - * @param accountId The user accountId - */ - private void removeEmptyCategory(long accountId) { - validateAccountId(accountId); - getReadableDatabase().delete(table_category, - key_category_id + " NOT IN (SELECT " + key_category + " FROM " + table_notes + ")", - null); - } -} diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRoomDatabase.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRoomDatabase.java index 3fb6ce34..b2f1363b 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRoomDatabase.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRoomDatabase.java @@ -1,12 +1,12 @@ package it.niedermann.owncloud.notes.persistence; -import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.ShortcutInfo; import android.content.pm.ShortcutManager; -import android.database.sqlite.SQLiteDatabase; +import android.content.res.Resources; +import android.database.Cursor; import android.graphics.drawable.Icon; import android.os.Build; import android.text.TextUtils; @@ -23,8 +23,13 @@ import androidx.room.TypeConverters; import androidx.room.migration.Migration; import androidx.sqlite.db.SupportSQLiteDatabase; +import com.nextcloud.android.sso.AccountImporter; +import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException; import com.nextcloud.android.sso.model.SingleSignOnAccount; +import org.json.JSONArray; +import org.json.JSONException; + import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; @@ -34,12 +39,14 @@ import java.util.Map; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.edit.EditNoteActivity; +import it.niedermann.owncloud.notes.main.NavigationAdapter; import it.niedermann.owncloud.notes.persistence.dao.CategoryDao; import it.niedermann.owncloud.notes.persistence.dao.LocalAccountDao; import it.niedermann.owncloud.notes.persistence.dao.NoteDao; import it.niedermann.owncloud.notes.persistence.dao.WidgetNotesListDao; import it.niedermann.owncloud.notes.persistence.dao.WidgetSingleNoteDao; import it.niedermann.owncloud.notes.persistence.entity.CategoryEntity; +import it.niedermann.owncloud.notes.persistence.entity.CategoryWithNotesCount; import it.niedermann.owncloud.notes.persistence.entity.Converters; import it.niedermann.owncloud.notes.persistence.entity.LocalAccountEntity; import it.niedermann.owncloud.notes.persistence.entity.NoteEntity; @@ -53,7 +60,6 @@ import it.niedermann.owncloud.notes.shared.model.CloudNote; import it.niedermann.owncloud.notes.shared.model.DBNote; import it.niedermann.owncloud.notes.shared.model.DBStatus; import it.niedermann.owncloud.notes.shared.model.ISyncCallback; -import it.niedermann.owncloud.notes.shared.model.LocalAccount; import it.niedermann.owncloud.notes.shared.util.ColorUtil; import it.niedermann.owncloud.notes.shared.util.NoteUtil; @@ -82,9 +88,9 @@ public abstract class NotesRoomDatabase extends RoomDatabase { public static NotesRoomDatabase getInstance(@NonNull Context context) { if (instance == null) { - instance = create(context); - NotesRoomDatabase.context = context; - syncHelper = NoteServerSyncHelper.getInstance(NotesDatabase.getInstance(context), instance); + instance = create(context.getApplicationContext()); + NotesRoomDatabase.context = context.getApplicationContext(); + NotesRoomDatabase.syncHelper = NoteServerSyncHelper.getInstance(instance); } return instance; } @@ -511,4 +517,104 @@ public abstract class NotesRoomDatabase extends RoomDatabase { return oldNote; } } + + /** + * @param apiVersion has to be a JSON array as a string <code>["0.2", "1.0", ...]</code> + * @return whether or not the given {@link ApiVersion} has been written to the database + * @throws IllegalArgumentException if the apiVersion does not match the expected format + */ + public boolean updateApiVersion(long accountId, @Nullable String apiVersion) throws IllegalArgumentException { + validateAccountId(accountId); + if (apiVersion != null) { + try { + JSONArray apiVersions = new JSONArray(apiVersion); + for (int i = 0; i < apiVersions.length(); i++) { + ApiVersion.of(apiVersions.getString(i)); + } + if (apiVersions.length() > 0) { + final int updatedRows = getLocalAccountDao().updateApiVersion(accountId, apiVersion); + if (updatedRows == 1) { + Log.i(TAG, "Updated apiVersion to \"" + apiVersion + "\" for accountId = " + accountId); + } else { + Log.e(TAG, "Updated " + updatedRows + " but expected only 1 for accountId = " + accountId + " and apiVersion = \"" + apiVersion + "\""); + } + return true; + } else { + Log.i(TAG, "Given API version is a valid JSON array but does not contain any valid API versions. Do not update database."); + } + } catch (NumberFormatException e) { + throw new IllegalArgumentException("API version does contain a non-valid version: " + apiVersion); + } catch (JSONException e) { + throw new IllegalArgumentException("API version must contain be a JSON array: " + apiVersion); + } + } else { + Log.v(TAG, "Given API version is null. Do not update database"); + } + return false; + } + + /** + * @param localAccount the {@link LocalAccountEntity} that should be deleted + * @throws IllegalArgumentException if no account has been deleted by the given accountId + */ + public void deleteAccount(@NonNull LocalAccountEntity localAccount) throws IllegalArgumentException { + validateAccountId(localAccount.getId()); + int deletedAccounts = getLocalAccountDao().deleteAccount(localAccount); + if (deletedAccounts < 1) { + Log.e(TAG, "AccountId '" + localAccount.getId() + "' did not delete any account"); + throw new IllegalArgumentException("The given accountId does not delete any row"); + } else if (deletedAccounts > 1) { + Log.e(TAG, "AccountId '" + localAccount.getId() + "' deleted unexpectedly '" + deletedAccounts + "' accounts"); + } + + try { + SSOClient.invalidateAPICache(AccountImporter.getSingleSignOnAccount(context, localAccount.getAccountName())); + } catch (NextcloudFilesAppAccountNotFoundException e) { + e.printStackTrace(); + SSOClient.invalidateAPICache(); + } + + final int deletedNotes = getNoteDao().deleteByAccountId(localAccount.getId()); + Log.v(TAG, "Deleted " + deletedNotes + " notes from account " + localAccount.getId()); + } + + public List<NavigationAdapter.CategoryNavigationItem> searchCategories(long accountId, String search) { + validateAccountId(accountId); + List<CategoryWithNotesCount> counters = getCategoryDao().searchCategories(accountId, search.trim()); + List<NavigationAdapter.CategoryNavigationItem> categories = new ArrayList<>(counters.size()); + for(CategoryWithNotesCount counter: counters) { + Resources res = context.getResources(); + String category = counter.getCategory().getTitle().toLowerCase(); + int icon = NavigationAdapter.ICON_FOLDER; + if (category.equals(res.getString(R.string.category_music).toLowerCase())) { + icon = R.drawable.ic_library_music_grey600_24dp; + } else if (category.equals(res.getString(R.string.category_movies).toLowerCase()) || category.equals(res.getString(R.string.category_movie).toLowerCase())) { + icon = R.drawable.ic_local_movies_grey600_24dp; + } else if (category.equals(res.getString(R.string.category_work).toLowerCase())) { + icon = R.drawable.ic_work_grey600_24dp; + } + categories.add(new NavigationAdapter.CategoryNavigationItem("category:" + counter.getCategory().getTitle(), counter.getCategory().getTitle(), counter.getTotalNotes(), icon, counter.getCategory().getId())); + } + return categories; + } + + /** + * This method return all of the categories with given accountId + * + * @param accountId The user account Id + * @return All of the categories with given accountId + */ + @NonNull + @WorkerThread + public List<NavigationAdapter.CategoryNavigationItem> getCategories(long accountId) { + return searchCategories(accountId, null); + } + + public NoteServerSyncHelper getNoteServerSyncHelper() { + return NotesRoomDatabase.syncHelper; + } + + public Context getContext() { + return NotesRoomDatabase.context; + } } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/SyncWorker.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/SyncWorker.java index 810c1813..916ff48f 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/SyncWorker.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/SyncWorker.java @@ -21,7 +21,6 @@ import java.util.concurrent.TimeUnit; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.persistence.entity.LocalAccountEntity; -import it.niedermann.owncloud.notes.shared.model.LocalAccount; public class SyncWorker extends Worker { diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/CategoryDao.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/CategoryDao.java index f935d136..32f8b07d 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/CategoryDao.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/CategoryDao.java @@ -4,7 +4,10 @@ import androidx.room.Dao; import androidx.room.Insert; import androidx.room.Query; +import java.util.List; + import it.niedermann.owncloud.notes.persistence.entity.CategoryEntity; +import it.niedermann.owncloud.notes.persistence.entity.CategoryWithNotesCount; import it.niedermann.owncloud.notes.shared.model.CategorySortingMethod; @Dao @@ -58,4 +61,8 @@ public interface CategoryDao { @Query("SELECT title FROM CategoryEntity WHERE id = :categoryId") String getCategoryTitleById(long categoryId); + + @Query("SELECT id, title, COUNT(*) FROM CategoryEntity INNER JOIN NoteEntity ON CategoryEntity.id = NoteEntity.category_id" + + " WHERE status != 'LOCAL_DELETED' AND accountId = :accountId AND title LIKE '%' + :categoryTitle + '%' GROUP BY title") + List<CategoryWithNotesCount> searchCategories(Long accountId, String categoryTitle); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/LocalAccountDao.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/LocalAccountDao.java index c53a11f3..76a0fd6e 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/LocalAccountDao.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/LocalAccountDao.java @@ -1,6 +1,7 @@ package it.niedermann.owncloud.notes.persistence.dao; import androidx.room.Dao; +import androidx.room.Delete; import androidx.room.Insert; import androidx.room.Query; @@ -14,6 +15,9 @@ public interface LocalAccountDao { @Insert long insert(LocalAccountEntity localAccountEntity); + @Delete + int deleteAccount(LocalAccountEntity localAccountEntity); + @Query("SELECT * FROM localaccountentity WHERE id = :accountId") LocalAccountEntity getAccount(long accountId); @@ -37,4 +41,7 @@ public interface LocalAccountDao { @Query("UPDATE localaccountentity SET modified = :modified WHERE id = :id") void updateModified(long id, long modified); + + @Query("UPDATE localaccountentity SET apiVersion = :apiVersion WHERE id = :id") + int updateApiVersion(Long id, String apiVersion); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/NoteDao.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/NoteDao.java index acad14f8..3dc521ed 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/NoteDao.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/NoteDao.java @@ -24,12 +24,15 @@ public interface NoteDao { @Update(onConflict = OnConflictStrategy.REPLACE) int updateNote(NoteEntity newNote); + @Query("DELETE FROM noteentity WHERE accountId = :accountId") + int deleteByAccountId(Long accountId); + /** * Returns a list of all Notes in the Database * * @return List<Note> */ - @Query("SELECT * FROM NoteEntity WHERE accountId = :accountId AND status != \"LOCAL_DELETED\" ORDER BY favorite DESC, modified DESC") + @Query("SELECT * FROM NoteEntity WHERE accountId = :accountId AND status != 'LOCAL_DELETED' ORDER BY favorite DESC, modified DESC") List<NoteEntity> getNotes(long accountId); @Query("DELETE FROM NoteEntity WHERE id = :id and status = :forceDBStatus") @@ -53,10 +56,10 @@ public interface NoteDao { * @param accountId get the remoteIds from all notes of this account * @return {@link Set<String>} remoteIds from all notes */ - @Query("SELECT DISTINCT remoteId FROM NoteEntity WHERE accountId = :accountId AND status != \"LOCAL_DELETED\"") + @Query("SELECT DISTINCT remoteId FROM NoteEntity WHERE accountId = :accountId AND status != 'LOCAL_DELETED'") List<Long> getRemoteIds(long accountId); - @Query("SELECT * FROM NoteEntity WHERE accountId = :accountId AND status != \"LOCAL_DELETED\"") + @Query("SELECT * FROM NoteEntity WHERE accountId = :accountId AND status != 'LOCAL_DELETED'") List<NoteEntity> getRemoteIdAndId(long accountId); /** @@ -65,7 +68,7 @@ public interface NoteDao { * @param remoteId int - remote ID of the requested Note * @return {@link DBNote#getId()} */ - @Query("SELECT id FROM NoteEntity WHERE accountId = :accountId AND remoteId = :remoteId AND status != \"LOCAL_DELETED\"") + @Query("SELECT id FROM NoteEntity WHERE accountId = :accountId AND remoteId = :remoteId AND status != 'LOCAL_DELETED'") Long getLocalIdByRemoteId(long accountId, long remoteId); @Query("SELECT COUNT(*) FROM NoteEntity WHERE status != 'LOCAL_DELETED' AND accountId = :accountId AND favorite = 1") @@ -79,22 +82,22 @@ public interface NoteDao { * * @return {@link List<NoteEntity>} */ - @Query("SELECT * FROM NoteEntity WHERE status != \"VOID\" AND accountId = :accountId") + @Query("SELECT * FROM NoteEntity WHERE status != 'VOID' AND accountId = :accountId") List<NoteEntity> getLocalModifiedNotes(long accountId); - @Query("SELECT * FROM NoteEntity WHERE status != \"LOCAL_DELETED\" AND accountId = :accountId ORDER BY modified DESC LIMIT 4") + @Query("SELECT * FROM NoteEntity WHERE status != 'LOCAL_DELETED' AND accountId = :accountId ORDER BY modified DESC LIMIT 4") List<NoteEntity> getRecentNotes(long accountId); - @Query("UPDATE NoteEntity SET status = \"LOCAL_EDITED\", favorite = ((favorite | 1) - (favorite & 1)) WHERE id = :id") + @Query("UPDATE NoteEntity SET status = 'LOCAL_EDITED', favorite = ((favorite | 1) - (favorite & 1)) WHERE id = :id") void toggleFavorite(long id); - @Query("SELECT * FROM NoteEntity WHERE accountId = :accountId AND status != \"LOCAL_DELETED\" AND (title LIKE \"%\" + :query + \"%\" OR content LIKE \"%\" + :query + \"%\" OR category_title LIKE \"%\" + :query + \"%\") AND (category_title = :category OR title LIKE :category + \"/%\") AND favorite = :favorite ORDER BY favorite DESC, :sortingMethod") + @Query("SELECT * FROM NoteEntity WHERE accountId = :accountId AND status != 'LOCAL_DELETED' AND (title LIKE '%' + :query + '%' OR content LIKE '%' + :query + '%' OR category_title LIKE '%' + :query + '%') AND (category_title = :category OR title LIKE :category + '/%') AND favorite = :favorite ORDER BY favorite DESC, :sortingMethod") List<NoteEntity> searchNotes(long accountId, String query, String category, Boolean favorite, CategorySortingMethod sortingMethod); /** * Needed for subcategories, see https://github.com/stefan-niedermann/nextcloud-notes/issues/902 */ - @Query("SELECT * FROM NoteEntity WHERE accountId = :accountId AND status != \"LOCAL_DELETED\" AND (title LIKE \"%\" + :query + \"%\" OR content LIKE \"%\" + :query + \"%\" OR category_title LIKE \"%\" + :query + \"%\") AND (category_title = :category OR title LIKE :category + \"/%\") AND favorite = :favorite ORDER BY category_title, favorite DESC, :sortingMethod") + @Query("SELECT * FROM NoteEntity WHERE accountId = :accountId AND status != 'LOCAL_DELETED' AND (title LIKE '%' + :query + '%' OR content LIKE '%' + :query + '%' OR category_title LIKE '%' + :query + '%') AND (category_title = :category OR title LIKE :category + '/%') AND favorite = :favorite ORDER BY category_title, favorite DESC, :sortingMethod") List<NoteEntity> searchNotesSubcategory(long accountId, String query, String category, Boolean favorite, CategorySortingMethod sortingMethod); @Query("UPDATE NoteEntity SET remoteId = :remoteId WHERE id = :id") @@ -116,7 +119,7 @@ public interface NoteDao { */ @Query( "UPDATE NoteEntity SET id = :id, title = :title, modified = :modified, title = :title, favorite = :favorite, etag = :eTag, content = :content " + - "WHERE id = :id AND status = \"VOID\" AND (modified != :modified OR favorite != :favorite OR category_title != :categoryTitle OR (eTag == NULL OR eTag != :eTag) OR content != :content)" + "WHERE id = :id AND status = 'VOID' AND (modified != :modified OR favorite != :favorite OR category_title != :categoryTitle OR (eTag == NULL OR eTag != :eTag) OR content != :content)" ) void updateIfNotModifiedLocallyAndRemoteColumnHasChanged(long id, long modified, String title, Boolean favorite, String categoryTitle, String eTag, String content); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/WidgetNotesListDao.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/WidgetNotesListDao.java index 444ecb62..902d6037 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/WidgetNotesListDao.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/WidgetNotesListDao.java @@ -1,15 +1,9 @@ package it.niedermann.owncloud.notes.persistence.dao; -import android.database.Cursor; -import android.database.sqlite.SQLiteDatabase; - -import androidx.annotation.NonNull; import androidx.room.Dao; import androidx.room.Insert; import androidx.room.Query; -import java.util.NoSuchElementException; - import it.niedermann.owncloud.notes.persistence.entity.WidgetNotesListEntity; import it.niedermann.owncloud.notes.widget.notelist.NoteListsWidgetData; diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/CategoryWithNotesCount.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/CategoryWithNotesCount.java new file mode 100644 index 00000000..3fcda2c0 --- /dev/null +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/CategoryWithNotesCount.java @@ -0,0 +1,26 @@ +package it.niedermann.owncloud.notes.persistence.entity; + +import androidx.room.Embedded; + +public class CategoryWithNotesCount { + + @Embedded + private CategoryEntity category; + private Integer totalNotes; + + public CategoryEntity getCategory() { + return category; + } + + public void setCategory(CategoryEntity category) { + this.category = category; + } + + public Integer getTotalNotes() { + return totalNotes; + } + + public void setTotalNotes(Integer totalNotes) { + this.totalNotes = totalNotes; + } +} diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Converters.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Converters.java index 4b9fc350..e8cacec6 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Converters.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/Converters.java @@ -31,7 +31,7 @@ public class Converters { @TypeConverter public static Calendar longToCalendar(Long value) { - if(value == null) { + if (value == null) { return null; } Calendar calendar = Calendar.getInstance(); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/LocalAccountEntity.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/LocalAccountEntity.java index f8a0d1a1..229decab 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/LocalAccountEntity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/LocalAccountEntity.java @@ -25,12 +25,12 @@ import it.niedermann.owncloud.notes.shared.util.ColorUtil; @Entity() public class LocalAccountEntity { @PrimaryKey - public int id; + public Long id; private String url; private String username; private String accountName; private String eTag; - private long modified; + private Long modified; private String apiVersion; private String capabilitiesETag; private String color; @@ -40,11 +40,11 @@ public class LocalAccountEntity { @Ignore private ApiVersion preferredApiVersion; - public int getId() { + public Long getId() { return id; } - public void setId(int id) { + public void setId(Long id) { this.id = id; } @@ -168,24 +168,6 @@ public class LocalAccountEntity { this.preferredApiVersion = null; } } - - @Nullable - @Deprecated - public static LocalAccount entityToLocalAccount(@Nullable LocalAccountEntity entity) { - if(entity == null) { - return null; - } - LocalAccount localAccount = new LocalAccount(); - localAccount.setAccountName(entity.getAccountName()); - localAccount.setCapabilitiesETag(entity.getCapabilitiesETag()); - localAccount.setColor(Color.parseColor('#' + entity.getColor())); - localAccount.setTextColor(Color.parseColor('#' + entity.getTextColor())); - localAccount.setETag(entity.getETag()); - localAccount.setId(entity.getId()); - localAccount.setModified(entity.getModified()); - localAccount.setUrl(entity.getUrl()); - return localAccount; - } } // DatabaseIndexUtil.createIndex(db, table_accounts, key_url, key_username, key_account_name, key_etag, key_modified);
\ No newline at end of file diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/NoteEntity.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/NoteEntity.java index d7f384de..674a33c6 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/NoteEntity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/NoteEntity.java @@ -4,8 +4,6 @@ import androidx.room.Embedded; import androidx.room.Entity; import androidx.room.Ignore; import androidx.room.PrimaryKey; -import androidx.room.Relation; -import androidx.room.TypeConverters; import java.io.Serializable; import java.util.Calendar; @@ -153,7 +151,7 @@ public class NoteEntity implements Serializable, Item { @Deprecated public static DBNote entityToDBNote(NoteEntity entity) { - if(entity == null) { + if (entity == null) { return null; } return new DBNote( diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/WidgetNotesListEntity.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/WidgetNotesListEntity.java index 9180f552..e6a4666a 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/WidgetNotesListEntity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/WidgetNotesListEntity.java @@ -1,11 +1,9 @@ package it.niedermann.owncloud.notes.persistence.entity; import androidx.annotation.IntRange; -import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.room.Entity; import androidx.room.Ignore; -import androidx.room.PrimaryKey; import it.niedermann.owncloud.notes.widget.AbstractWidgetData; diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_11_12.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_11_12.java index 6fd531c9..b77eeb88 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_11_12.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_11_12.java @@ -5,8 +5,8 @@ import android.database.sqlite.SQLiteDatabase; import androidx.annotation.NonNull; -import it.niedermann.owncloud.notes.shared.model.ApiVersion; import it.niedermann.owncloud.notes.persistence.CapabilitiesWorker; +import it.niedermann.owncloud.notes.shared.model.ApiVersion; public class Migration_11_12 { /** diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_8_9.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_8_9.java index 03e171f3..571adceb 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_8_9.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_8_9.java @@ -15,9 +15,9 @@ import androidx.preference.PreferenceManager; import java.net.MalformedURLException; import java.net.URL; +import it.niedermann.owncloud.notes.shared.util.DatabaseIndexUtil; import it.niedermann.owncloud.notes.widget.notelist.NoteListWidget; import it.niedermann.owncloud.notes.widget.singlenote.SingleNoteWidget; -import it.niedermann.owncloud.notes.shared.util.DatabaseIndexUtil; public class Migration_8_9 { diff --git a/app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesActivity.java index e808a3a0..f872aac3 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesActivity.java @@ -4,8 +4,8 @@ import android.os.Bundle; import androidx.annotation.Nullable; -import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.LockedActivity; +import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.databinding.ActivityPreferencesBinding; /** 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 d324b9f6..eeb7d007 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 @@ -11,13 +11,13 @@ import androidx.preference.ListPreference; import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; +import it.niedermann.owncloud.notes.NotesApplication; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.branding.Branded; import it.niedermann.owncloud.notes.branding.BrandedSwitchPreference; import it.niedermann.owncloud.notes.branding.BrandingUtil; import it.niedermann.owncloud.notes.persistence.SyncWorker; import it.niedermann.owncloud.notes.shared.util.DeviceCredentialUtil; -import it.niedermann.owncloud.notes.NotesApplication; import static it.niedermann.owncloud.notes.widget.notelist.NoteListWidget.updateNoteListWidgets; diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/account/AccountChooserAdapter.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/account/AccountChooserAdapter.java index 6d831be3..35d28d6f 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/account/AccountChooserAdapter.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/account/AccountChooserAdapter.java @@ -11,18 +11,15 @@ import java.util.List; import it.niedermann.owncloud.notes.databinding.ItemAccountChooseBinding; import it.niedermann.owncloud.notes.persistence.entity.LocalAccountEntity; -import it.niedermann.owncloud.notes.shared.model.LocalAccount; - -import static it.niedermann.owncloud.notes.persistence.entity.LocalAccountEntity.entityToLocalAccount; public class AccountChooserAdapter extends RecyclerView.Adapter<AccountChooserViewHolder> { @NonNull private final List<LocalAccountEntity> localAccounts; @NonNull - private final Consumer<LocalAccount> targetAccountConsumer; + private final Consumer<LocalAccountEntity> targetAccountConsumer; - public AccountChooserAdapter(@NonNull List<LocalAccountEntity> localAccounts, @NonNull Consumer<LocalAccount> targetAccountConsumer) { + public AccountChooserAdapter(@NonNull List<LocalAccountEntity> localAccounts, @NonNull Consumer<LocalAccountEntity> targetAccountConsumer) { super(); this.localAccounts = localAccounts; this.targetAccountConsumer = targetAccountConsumer; @@ -36,7 +33,7 @@ public class AccountChooserAdapter extends RecyclerView.Adapter<AccountChooserVi @Override public void onBindViewHolder(@NonNull AccountChooserViewHolder holder, int position) { - holder.bind(entityToLocalAccount(localAccounts.get(position)), targetAccountConsumer); + holder.bind(localAccounts.get(position), targetAccountConsumer); } @Override diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/account/AccountChooserViewHolder.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/account/AccountChooserViewHolder.java index 9fc2f382..de95250c 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/account/AccountChooserViewHolder.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/account/AccountChooserViewHolder.java @@ -11,7 +11,7 @@ import com.bumptech.glide.request.RequestOptions; import it.niedermann.android.glidesso.SingleSignOnUrl; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.databinding.ItemAccountChooseBinding; -import it.niedermann.owncloud.notes.shared.model.LocalAccount; +import it.niedermann.owncloud.notes.persistence.entity.LocalAccountEntity; public class AccountChooserViewHolder extends RecyclerView.ViewHolder { private final ItemAccountChooseBinding binding; @@ -21,17 +21,17 @@ public class AccountChooserViewHolder extends RecyclerView.ViewHolder { this.binding = binding; } - public void bind(LocalAccount localAccount, Consumer<LocalAccount> targetAccountConsumer) { + public void bind(LocalAccountEntity localAccount, Consumer<LocalAccountEntity> targetAccountConsumer) { Glide .with(binding.accountItemAvatar.getContext()) - .load(new SingleSignOnUrl(localAccount.getAccountName(), localAccount.getUrl() + "/index.php/avatar/" + Uri.encode(localAccount.getUserName()) + "/64")) + .load(new SingleSignOnUrl(localAccount.getAccountName(), localAccount.getUrl() + "/index.php/avatar/" + Uri.encode(localAccount.getUsername()) + "/64")) .placeholder(R.drawable.ic_account_circle_grey_24dp) .error(R.drawable.ic_account_circle_grey_24dp) .apply(RequestOptions.circleCropTransform()) .into(binding.accountItemAvatar); binding.accountLayout.setOnClickListener((v) -> targetAccountConsumer.accept(localAccount)); - binding.accountName.setText(localAccount.getUserName()); + binding.accountName.setText(localAccount.getUsername()); binding.accountHost.setText(Uri.parse(localAccount.getUrl()).getHost()); } }
\ No newline at end of file diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/CloudNote.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/CloudNote.java index cf6c51e8..6ba3a943 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/CloudNote.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/CloudNote.java @@ -13,6 +13,7 @@ import it.niedermann.owncloud.notes.shared.util.NoteUtil; * CloudNote represents a remote note from an OwnCloud server. * It can be directly generated from the JSON answer from the server. */ +@Deprecated public class CloudNote implements Serializable { private long remoteId; private String title = ""; diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/DBNote.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/DBNote.java index 059a1ce3..5ec1434d 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/DBNote.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/DBNote.java @@ -9,6 +9,7 @@ import java.util.Calendar; * DBNote represents a single note from the local SQLite database with all attributes. * It extends CloudNote with attributes required for local data management. */ +@Deprecated public class DBNote extends CloudNote implements Item, Serializable { private final long id; diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/util/DatabaseIndexUtil.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/util/DatabaseIndexUtil.java index 235711ef..59707b24 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/util/DatabaseIndexUtil.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/util/DatabaseIndexUtil.java @@ -14,8 +14,8 @@ public class DatabaseIndexUtil { } - public static void createIndex(@NonNull SQLiteDatabase db, @NonNull String table, @NonNull String ...columns) { - for (String column: columns) { + public static void createIndex(@NonNull SQLiteDatabase db, @NonNull String table, @NonNull String... columns) { + for (String column : columns) { createIndex(db, table, column); } } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/util/NoteUtil.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/util/NoteUtil.java index 014d3377..9254de82 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/util/NoteUtil.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/util/NoteUtil.java @@ -91,7 +91,7 @@ public class NoteUtil { @NonNull public static String generateNoteExcerpt(@NonNull String content, @Nullable String title) { content = removeMarkDown(content.trim()); - if(TextUtils.isEmpty(content)) { + if (TextUtils.isEmpty(content)) { return ""; } if (!TextUtils.isEmpty(title)) { diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/util/text/NoteLinksProcessor.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/util/text/NoteLinksProcessor.java index ac4c3680..a8c6926e 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/util/text/NoteLinksProcessor.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/util/text/NoteLinksProcessor.java @@ -3,13 +3,13 @@ package it.niedermann.owncloud.notes.shared.util.text; import android.text.TextUtils; import android.util.Log; +import androidx.annotation.VisibleForTesting; + import java.util.HashSet; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; -import androidx.annotation.VisibleForTesting; - public class NoteLinksProcessor extends TextProcessor { private static final String TAG = NoteLinksProcessor.class.getSimpleName(); @@ -28,9 +28,9 @@ public class NoteLinksProcessor extends TextProcessor { /** * Replaces all links to other notes of the form `[<link-text>](<note-file-id>)` * in the markdown string with links to a dummy url. - * + * <p> * Why is this needed? - * See discussion in issue #623 + * See discussion in issue #623 * * @return Markdown with all note-links replaced with dummy-url-links */ diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/util/text/TextProcessor.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/util/text/TextProcessor.java index 4eb4e4f7..cd17ad17 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/util/text/TextProcessor.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/util/text/TextProcessor.java @@ -3,6 +3,7 @@ package it.niedermann.owncloud.notes.shared.util.text; abstract public class TextProcessor { /** * Applies a specified transformation on a text string and returns the updated string. + * * @param s Text to transform * @return Transformed text */ diff --git a/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidget.java b/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidget.java index 1c94433c..50905c40 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidget.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidget.java @@ -13,16 +13,15 @@ import android.widget.RemoteViews; import java.util.NoSuchElementException; +import it.niedermann.owncloud.notes.NotesApplication; import it.niedermann.owncloud.notes.R; +import it.niedermann.owncloud.notes.branding.BrandingUtil; +import it.niedermann.owncloud.notes.edit.EditNoteActivity; +import it.niedermann.owncloud.notes.main.MainActivity; import it.niedermann.owncloud.notes.persistence.NotesRoomDatabase; import it.niedermann.owncloud.notes.persistence.entity.LocalAccountEntity; import it.niedermann.owncloud.notes.preferences.DarkModeSetting; -import it.niedermann.owncloud.notes.edit.EditNoteActivity; -import it.niedermann.owncloud.notes.main.MainActivity; -import it.niedermann.owncloud.notes.branding.BrandingUtil; import it.niedermann.owncloud.notes.shared.model.Category; -import it.niedermann.owncloud.notes.persistence.NotesDatabase; -import it.niedermann.owncloud.notes.NotesApplication; import static it.niedermann.owncloud.notes.edit.EditNoteActivity.PARAM_CATEGORY; import static it.niedermann.owncloud.notes.widget.notelist.NoteListsWidgetData.MODE_DISPLAY_ALL; diff --git a/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetConfigurationActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetConfigurationActivity.java index 978e49ee..cdcb6d0c 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetConfigurationActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetConfigurationActivity.java @@ -18,33 +18,28 @@ import com.nextcloud.android.sso.helper.SingleAccountHelper; import java.util.ArrayList; import java.util.List; -import java.util.Map; -import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.LockedActivity; +import it.niedermann.owncloud.notes.NotesApplication; +import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.main.MainActivity; -import it.niedermann.owncloud.notes.persistence.NotesRoomDatabase; -import it.niedermann.owncloud.notes.persistence.entity.WidgetNotesListEntity; -import it.niedermann.owncloud.notes.shared.model.LocalAccount; import it.niedermann.owncloud.notes.main.NavigationAdapter; import it.niedermann.owncloud.notes.main.NavigationAdapter.CategoryNavigationItem; -import it.niedermann.owncloud.notes.persistence.NotesDatabase; -import it.niedermann.owncloud.notes.NotesApplication; +import it.niedermann.owncloud.notes.persistence.NotesRoomDatabase; +import it.niedermann.owncloud.notes.persistence.entity.LocalAccountEntity; +import it.niedermann.owncloud.notes.persistence.entity.WidgetNotesListEntity; -import static it.niedermann.owncloud.notes.persistence.entity.LocalAccountEntity.entityToLocalAccount; public class NoteListWidgetConfigurationActivity extends LockedActivity { private static final String TAG = Activity.class.getSimpleName(); private int appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID; - - private LocalAccount localAccount = null; + private LocalAccountEntity localAccount = null; private NavigationAdapter adapterCategories; private NavigationAdapter.NavigationItem itemRecent; private NavigationAdapter.NavigationItem itemFavorites; - private NotesDatabase sqliteOpenHelperDatabase = null; private NotesRoomDatabase roomDatabase = null; @Override @@ -53,10 +48,9 @@ public class NoteListWidgetConfigurationActivity extends LockedActivity { setResult(RESULT_CANCELED); setContentView(R.layout.activity_note_list_configuration); - sqliteOpenHelperDatabase = NotesDatabase.getInstance(this); roomDatabase = NotesRoomDatabase.getInstance(this); try { - this.localAccount = entityToLocalAccount(roomDatabase.getLocalAccountDao().getLocalAccountByAccountName(SingleAccountHelper.getCurrentSingleSignOnAccount(this).name)); + this.localAccount = roomDatabase.getLocalAccountDao().getLocalAccountByAccountName(SingleAccountHelper.getCurrentSingleSignOnAccount(this).name); } catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e) { e.printStackTrace(); Toast.makeText(this, R.string.widget_not_logged_in, Toast.LENGTH_LONG).show(); @@ -149,7 +143,7 @@ public class NoteListWidgetConfigurationActivity extends LockedActivity { return new ArrayList<>(); } NavigationAdapter.NavigationItem itemUncategorized; - List<CategoryNavigationItem> categories = sqliteOpenHelperDatabase.getCategories(localAccount.getId()); + List<CategoryNavigationItem> categories = roomDatabase.getCategories(localAccount.getId()); if (!categories.isEmpty() && categories.get(0).label.isEmpty()) { itemUncategorized = categories.get(0); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetFactory.java b/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetFactory.java index e7c68402..9372b81c 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetFactory.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/widget/notelist/NoteListWidgetFactory.java @@ -11,14 +11,12 @@ import android.widget.RemoteViewsService; import java.util.List; +import it.niedermann.owncloud.notes.NotesApplication; import it.niedermann.owncloud.notes.R; +import it.niedermann.owncloud.notes.edit.EditNoteActivity; import it.niedermann.owncloud.notes.persistence.NotesRoomDatabase; import it.niedermann.owncloud.notes.persistence.entity.NoteEntity; import it.niedermann.owncloud.notes.preferences.DarkModeSetting; -import it.niedermann.owncloud.notes.edit.EditNoteActivity; -import it.niedermann.owncloud.notes.shared.model.DBNote; -import it.niedermann.owncloud.notes.persistence.NotesDatabase; -import it.niedermann.owncloud.notes.NotesApplication; import static it.niedermann.owncloud.notes.widget.notelist.NoteListsWidgetData.MODE_DISPLAY_ALL; import static it.niedermann.owncloud.notes.widget.notelist.NoteListsWidgetData.MODE_DISPLAY_CATEGORY; @@ -30,8 +28,7 @@ public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFact private final Context context; private final NoteListsWidgetData data; private final boolean darkTheme; - private NotesDatabase sqliteOpenHelperDatabase; - private NotesRoomDatabase roomDatabase; + private NotesRoomDatabase db; private List<NoteEntity> noteEntities; NoteListWidgetFactory(Context context, Intent intent) { @@ -39,9 +36,8 @@ public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFact final int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); - sqliteOpenHelperDatabase = NotesDatabase.getInstance(context); - roomDatabase = NotesRoomDatabase.getInstance(context); - data = roomDatabase.getWidgetNotesListDao().getNoteListWidgetData(appWidgetId); + db = NotesRoomDatabase.getInstance(context); + data = db.getWidgetNotesListDao().getNoteListWidgetData(appWidgetId); darkTheme = NotesApplication.isDarkThemeActive(context, DarkModeSetting.fromModeID(data.getThemeMode())); } @@ -56,14 +52,14 @@ public class NoteListWidgetFactory implements RemoteViewsService.RemoteViewsFact Log.v(TAG, "--- data - " + data); switch (data.getMode()) { case MODE_DISPLAY_ALL: - noteEntities = roomDatabase.getNoteDao().getNotes(data.getAccountId()); + noteEntities = db.getNoteDao().getNotes(data.getAccountId()); break; case MODE_DISPLAY_STARRED: - noteEntities = roomDatabase.getNoteDao().searchNotes(data.getAccountId(), null, null, true, null); + noteEntities = db.getNoteDao().searchNotes(data.getAccountId(), null, null, true, null); break; case MODE_DISPLAY_CATEGORY: if (data.getCategoryId() != null) { - noteEntities = roomDatabase.getNoteDao().searchNotes(data.getAccountId(), null, roomDatabase.getCategoryDao().getCategoryTitleById(data.getCategoryId()), null, null); + noteEntities = db.getNoteDao().searchNotes(data.getAccountId(), null, db.getCategoryDao().getCategoryTitleById(data.getCategoryId()), null, null); } break; } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidget.java b/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidget.java index 4f5fdcdc..7ecec33a 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidget.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidget.java @@ -12,14 +12,13 @@ import android.widget.RemoteViews; import java.util.NoSuchElementException; +import it.niedermann.owncloud.notes.NotesApplication; import it.niedermann.owncloud.notes.R; +import it.niedermann.owncloud.notes.edit.BaseNoteFragment; +import it.niedermann.owncloud.notes.edit.EditNoteActivity; import it.niedermann.owncloud.notes.persistence.NotesRoomDatabase; import it.niedermann.owncloud.notes.persistence.entity.WidgetSingleNoteEntity; import it.niedermann.owncloud.notes.preferences.DarkModeSetting; -import it.niedermann.owncloud.notes.edit.EditNoteActivity; -import it.niedermann.owncloud.notes.edit.BaseNoteFragment; -import it.niedermann.owncloud.notes.persistence.NotesDatabase; -import it.niedermann.owncloud.notes.NotesApplication; public class SingleNoteWidget extends AppWidgetProvider { diff --git a/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidgetConfigurationActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidgetConfigurationActivity.java index fd17fe51..72febe4f 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidgetConfigurationActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidgetConfigurationActivity.java @@ -12,12 +12,12 @@ import android.widget.Toast; import androidx.appcompat.widget.Toolbar; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; +import it.niedermann.owncloud.notes.NotesApplication; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.exception.ExceptionHandler; import it.niedermann.owncloud.notes.main.MainActivity; import it.niedermann.owncloud.notes.persistence.entity.WidgetSingleNoteEntity; import it.niedermann.owncloud.notes.shared.model.DBNote; -import it.niedermann.owncloud.notes.NotesApplication; public class SingleNoteWidgetConfigurationActivity extends MainActivity { diff --git a/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidgetFactory.java b/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidgetFactory.java index 1ef8223c..1547a352 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidgetFactory.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidgetFactory.java @@ -13,16 +13,15 @@ import com.yydcdut.markdown.syntax.text.TextFactory; import java.util.NoSuchElementException; +import it.niedermann.owncloud.notes.NotesApplication; import it.niedermann.owncloud.notes.R; +import it.niedermann.owncloud.notes.edit.EditNoteActivity; import it.niedermann.owncloud.notes.persistence.NotesRoomDatabase; import it.niedermann.owncloud.notes.persistence.entity.NoteEntity; import it.niedermann.owncloud.notes.persistence.entity.WidgetSingleNoteEntity; import it.niedermann.owncloud.notes.preferences.DarkModeSetting; -import it.niedermann.owncloud.notes.edit.EditNoteActivity; import it.niedermann.owncloud.notes.shared.model.DBNote; -import it.niedermann.owncloud.notes.persistence.NotesDatabase; import it.niedermann.owncloud.notes.shared.util.MarkDownUtil; -import it.niedermann.owncloud.notes.NotesApplication; import static it.niedermann.owncloud.notes.shared.util.MarkDownUtil.parseCompat; @@ -32,8 +31,7 @@ public class SingleNoteWidgetFactory implements RemoteViewsService.RemoteViewsFa private final Context context; private final int appWidgetId; - private NotesDatabase sqliteOpenHelperDatabase; - private NotesRoomDatabase roomDatabase; + private NotesRoomDatabase db; private DBNote note; private boolean darkModeActive = false; @@ -43,12 +41,11 @@ public class SingleNoteWidgetFactory implements RemoteViewsService.RemoteViewsFa this.context = context; appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); - sqliteOpenHelperDatabase = NotesDatabase.getInstance(context); - roomDatabase = NotesRoomDatabase.getInstance(context); + db = NotesRoomDatabase.getInstance(context); markdownProcessor = new MarkdownProcessor(this.context); markdownProcessor.factory(TextFactory.create()); try { - WidgetSingleNoteEntity data = roomDatabase.getWidgetSingleNoteDao().getSingleNoteWidgetData(appWidgetId); + WidgetSingleNoteEntity data = db.getWidgetSingleNoteDao().getSingleNoteWidgetData(appWidgetId); darkModeActive = NotesApplication.isDarkThemeActive(context, DarkModeSetting.fromModeID(data.getThemeMode())); } catch (NoSuchElementException e) { Log.w(TAG, "Widget with ID " + appWidgetId + " seems to be not configured yet."); @@ -65,10 +62,10 @@ public class SingleNoteWidgetFactory implements RemoteViewsService.RemoteViewsFa @Override public void onDataSetChanged() { try { - final WidgetSingleNoteEntity data = roomDatabase.getWidgetSingleNoteDao().getSingleNoteWidgetData(appWidgetId); + final WidgetSingleNoteEntity data = db.getWidgetSingleNoteDao().getSingleNoteWidgetData(appWidgetId); final long noteId = data.getNoteId(); Log.v(TAG, "Fetch note with id " + noteId); - note = NoteEntity.entityToDBNote(roomDatabase.getNoteDao().getNote(data.getAccountId(), noteId)); + note = NoteEntity.entityToDBNote(db.getNoteDao().getNote(data.getAccountId(), noteId)); if (note == null) { Log.e(TAG, "Error: note not found"); |