Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: quick note - sync before adding #137

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.orgzly.android.usecase.NoteCreateFromNotification;
import com.orgzly.android.usecase.UseCaseRunner;
import com.orgzly.android.util.LogUtils;
import com.orgzly.android.sync.AutoSync;

import androidx.core.app.RemoteInput;

Expand All @@ -25,6 +26,8 @@ public void onReceive(Context context, Intent intent) {
String title = getNoteTitle(intent);

if (title != null) {
autoSync.trigger(AutoSync.Type.QUICK_NOTE_PRE_CREATE);

App.EXECUTORS.diskIO().execute(() ->
UseCaseRunner.run(new NoteCreateFromNotification(title)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,12 @@ public static boolean syncOnNoteCreate(Context context) {
context.getResources().getBoolean(R.bool.pref_default_auto_sync_on_note_create));
}

public static boolean syncOnNoteQuickPreCreate(Context context) {
return getDefaultSharedPreferences(context).getBoolean(
context.getResources().getString(R.string.pref_key_auto_sync_on_quick_note_pre_create),
context.getResources().getBoolean(R.bool.pref_default_auto_sync_on_quick_note_pre_create));
}

public static boolean syncOnNoteUpdate(Context context) {
return getDefaultSharedPreferences(context).getBoolean(
context.getResources().getString(R.string.pref_key_auto_sync_on_note_update),
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/orgzly/android/sync/AutoSync.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class AutoSync @Inject constructor(val context: Application, val dataRepository:
startSync()
}

Type.QUICK_NOTE_PRE_CREATE ->
if (AppPreferences.syncOnQuickNotePreCreate(context)) {
startSync()
}

Type.DATA_MODIFIED ->
if (AppPreferences.syncOnNoteUpdate(context)) {
startSync()
Expand Down Expand Up @@ -50,6 +55,7 @@ class AutoSync @Inject constructor(val context: Application, val dataRepository:
DATA_MODIFIED,
APP_RESUMED,
APP_SUSPENDED,
QUICK_NOTE_PRE_CREATE,
}

companion object {
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/prefs_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@
<string name="pref_key_auto_sync_on_note_create" translatable="false">pref_key_auto_sync_on_note_create</string>
<bool name="pref_default_auto_sync_on_note_create" translatable="false">false</bool>

<string name="pref_key_auto_sync_on_quick_note_pre_create" translatable="false">pref_key_auto_sync_on_quick_note_pre_create</string>
<bool name="pref_default_auto_sync_on_quick_note_pre_create" translatable="false">false</bool>

<string name="pref_key_auto_sync_on_note_update" translatable="false">pref_key_auto_sync_on_note_update</string>
<bool name="pref_default_auto_sync_on_note_update" translatable="false">false</bool>

Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,9 @@
<string name="pref_title_sync_after_note_create">Note created</string>
<string name="pref_summary_sync_after_note_create">Sync after creating a new note</string>

<string name="pref_title_sync_before_quick_note_create">Quick Note created</string>
<string name="pref_summary_sync_before_quick_note_create">Sync before creating a new quick note</string>

<string name="pref_title_sync_after_note_update">Note updated or deleted</string>
<string name="pref_summary_sync_after_note_update">Sync after updating or deleting a note</string>

Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/xml/prefs_screen_auto_sync.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
android:summary="@string/pref_summary_sync_after_note_create"
android:defaultValue="@bool/pref_default_auto_sync_on_note_create"/>

<SwitchPreference
android:key="@string/pref_key_auto_sync_on_quick_note_pre_create"
android:dependency="@string/pref_key_auto_sync"
android:title="@string/pref_title_sync_after_note_create"
android:summary="@string/pref_summary_sync_after_note_create"
android:defaultValue="@bool/pref_default_auto_sync_on_quick_note_pre_create"/>

<SwitchPreference
android:key="@string/pref_key_auto_sync_on_note_update"
android:dependency="@string/pref_key_auto_sync"
Expand Down
Loading