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

Sync reminder with calendar button #848

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ buildscript {
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.3'
classpath 'com.android.tools.build:gradle:7.1.1'
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.0"
classpath 'com.adarshr:gradle-test-logger-plugin:2.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
VERSION_NAME=6.1.0
VERSION_CODE=301
VERSION_NAME=6.2.0
VERSION_CODE=302
PACKAGE=it.feio.android.omninotes
MIN_SDK=21
TARGET_SDK=29
TARGET_SDK=30
BUILD_TOOLS=29.0.2

android.enableJetifier=true
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
27 changes: 2 additions & 25 deletions omniNotes/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ if (signConfigExists) {
}

android {

compileSdkVersion Integer.parseInt(project.TARGET_SDK)
// buildToolsVersion project.BUILD_TOOLS

defaultConfig {
applicationId project.PACKAGE
Expand Down Expand Up @@ -143,6 +141,8 @@ dependencies {
annotationProcessor 'org.androidannotations:androidannotations:4.8.0'
implementation 'org.androidannotations:androidannotations-api:4.8.0'

implementation "androidx.core:core-ktx:1.6.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.larswerkman:HoloColorPicker:1.4'
implementation 'de.keyboardsurfer.android.widget:crouton:1.8.4@aar'
implementation 'com.google.android.apps.dashclock:dashclock-api:2.0.0'
Expand Down Expand Up @@ -202,30 +202,7 @@ dependencies {
betaImplementation 'io.nlopez.smartlocation:library:3.2.4'
alphaImplementation 'io.nlopez.smartlocation:library:3.2.4'
fossImplementation 'com.github.federicoiosue:smart-location-lib:3.2.6'

playImplementation('com.github.federicoiosue:analitica:0.0.3:googleAnalyticsRelease@aar') {
transitive = true
}
betaImplementation('com.github.federicoiosue:analitica:0.0.3:googleAnalyticsRelease@aar') {
transitive = true
}
alphaImplementation('com.github.federicoiosue:analitica:0.0.3:googleAnalyticsRelease@aar') {
transitive = true
}
fossImplementation('com.github.federicoiosue:analitica:0.0.3:piwikRelease@aar') {
transitive = true
}
playImplementation 'com.google.android.gms:play-services-analytics:9.0.2'
betaImplementation 'com.google.android.gms:play-services-analytics:9.0.2'
alphaImplementation 'com.google.android.gms:play-services-analytics:9.0.2'
fossImplementation('org.piwik.sdk:piwik-sdk:1.0.2') {
exclude group: 'com.jakewharton.timber', module: 'timber'
}
fossImplementation 'com.jakewharton.timber:timber:4.5.1'

testImplementation 'junit:junit:4.12'
implementation "androidx.core:core-ktx:1.6.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

configurations.all {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import android.net.Uri;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import it.feio.android.omninotes.BaseAndroidTestCase;
import it.feio.android.omninotes.RetryableAssert;
import it.feio.android.omninotes.OmniNotes;
import it.feio.android.omninotes.exceptions.BackupException;
import it.feio.android.omninotes.exceptions.checked.BackupAttachmentException;
import it.feio.android.omninotes.models.Attachment;
Expand All @@ -32,7 +32,6 @@
import it.feio.android.omninotes.utils.StorageHelper;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.util.Collection;
import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -152,6 +151,19 @@ public void importAttachment() throws IOException, BackupAttachmentException {
assertTrue(new File(attachment.getUri().getPath()).exists());
}

@Test
public void importSettings_notFound() throws IOException {
BackupHelper.importSettings(backupDir);
}

@Test
public void importSettings() throws IOException {
new File(backupDir, StorageHelper.getSharedPreferencesFile(OmniNotes.getAppContext()).getName())
.createNewFile();

BackupHelper.importSettings(backupDir);
}

private Attachment createTestAttachmentBackup() throws IOException {
File testAttachment = new File(attachmentsBackupDir, "testAttachment");
if (!testAttachment.createNewFile()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package it.feio.android.omninotes.ui;

import androidx.test.espresso.matcher.ViewMatchers;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;
import it.feio.android.omninotes.R;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.longClick;
import static androidx.test.espresso.action.ViewActions.scrollTo;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.RootMatchers.isDialog;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withParent;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.not;

@RunWith(AndroidJUnit4.class)
@LargeTest
public class CalendarReminderSyncTest extends BaseEspressoTest {

@Test
public void syncButtonAppears() throws InterruptedException {
Thread.sleep(1500);

onView(Matchers.allOf(ViewMatchers.withId(R.id.fab_expand_menu_button),
withParent(withId(R.id.fab)),
isDisplayed())).perform(click());

onView(allOf(withId(R.id.fab_note),
withParent(withId(R.id.fab)),
isDisplayed())).perform(click());

onView(withId(R.id.reminder_layout)).perform(scrollTo(), click());
onView(allOf(withId(R.id.buttonPositive), withText("Ok"), isDisplayed())).perform(click());
onView(withId(R.id.sync_reminder_layout)).check(matches(isDisplayed()));

Thread.sleep(1500);

}

@Test
public void syncButtonDisappears() throws InterruptedException {
Thread.sleep(1500);

onView(Matchers.allOf(ViewMatchers.withId(R.id.fab_expand_menu_button),
withParent(withId(R.id.fab)),
isDisplayed())).perform(click());

onView(allOf(withId(R.id.fab_note),
withParent(withId(R.id.fab)),
isDisplayed())).perform(click());

onView(withId(R.id.reminder_layout)).perform(scrollTo(), click());
onView(allOf(withId(R.id.buttonPositive), withText("Ok"), isDisplayed())).perform(click());

onView(withId(R.id.reminder_layout)).perform(scrollTo(), longClick());
onView(withText("Ok"))
.inRoot(isDialog())
.check(matches(isDisplayed()))
.perform(click());

onView(withId(R.id.sync_reminder_layout)).check(matches(not(isDisplayed())));

Thread.sleep(1500);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.isRoot;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withParent;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
Expand Down Expand Up @@ -66,6 +67,7 @@ public void mrJingle_displayedOnLastNoteArchived() {
createTestNote("title", "content", 0);
archiveNotes(dbHelper.getAllNotes(false), true);

onView(isRoot()).perform(waitId(R.id.empty_list, 2000));
onView(allOf(withId(R.id.empty_list), withText(R.string.no_items_in_list),
withParent(withParent(IsInstanceOf.instanceOf(android.widget.FrameLayout.class))),
isDisplayed())).check(matches(isDisplayed()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2013-2022 Federico Iosue ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package it.feio.android.omninotes.utils

import it.feio.android.omninotes.BaseAndroidTestCase
import junit.framework.Assert.assertTrue
import org.junit.Test

class StorageHelperTest : BaseAndroidTestCase() {

@Test
fun getOrCreateExternalStoragePublicDir() {
val dir = StorageHelper.getOrCreateExternalStoragePublicDir()

assertTrue(dir.canRead())
assertTrue(dir.canWrite())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,12 @@ protected void onCreate(Bundle savedInstanceState) {
initUI();
}


@Override
public void onStart() {
((OmniNotes) getApplication()).getAnalyticsHelper().trackScreenView(getClass().getName());
super.onStart();
}


@Override
public boolean onNavigateUp() {
onBackPressed();
return true;
}


private void initUI() {
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,9 @@

public class BaseFragment extends Fragment {


private static final long OPTIONS_ITEM_CLICK_DELAY_TIME = 1000;
private long mLastClickTime;

@Override
public void onStart() {
super.onStart();
((OmniNotes) getActivity().getApplication()).getAnalyticsHelper()
.trackScreenView(getClass().getName());
}

@Override
public void onDestroy() {
super.onDestroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.provider.CalendarContract;
import android.provider.MediaStore;
import android.text.Editable;
import android.text.Selection;
Expand Down Expand Up @@ -199,6 +200,7 @@ public class DetailFragment extends BaseFragment implements OnReminderPickedList
private static final int CATEGORY = 5;
private static final int DETAIL = 6;
private static final int FILES = 7;
private static final int GCALENDAR = 8;

private FragmentDetailBinding binding;

Expand Down Expand Up @@ -619,6 +621,7 @@ private void initViewReminder() {
.getRecurrenceRule());
});


binding.fragmentDetailContent.reminderLayout.setOnLongClickListener(v -> {
MaterialDialog dialog = new MaterialDialog.Builder(mainActivity)
.content(R.string.remove_reminder)
Expand All @@ -629,6 +632,7 @@ private void initViewReminder() {
binding.fragmentDetailContent.reminderIcon
.setImageResource(R.drawable.ic_alarm_black_18dp);
binding.fragmentDetailContent.datetime.setText("");
binding.fragmentDetailContent.syncReminderLayout.setVisibility(View.GONE);
}).build();
dialog.show();
return true;
Expand All @@ -641,6 +645,18 @@ private void initViewReminder() {
.setImageResource(R.drawable.ic_alarm_add_black_18dp);
binding.fragmentDetailContent.datetime.setText(reminderString);
}

//For the sync reminder
binding.fragmentDetailContent.syncReminderLayout.setOnClickListener(v -> {
syncReminder();
});

//Sync Reminder
if (noteTmp.getAlarm() != null)
binding.fragmentDetailContent.syncReminderLayout.setVisibility(View.VISIBLE);
else
binding.fragmentDetailContent.syncReminderLayout.setVisibility(View.GONE);

}

private void initViewLocation() {
Expand Down Expand Up @@ -986,6 +1002,10 @@ public void onPrepareOptionsMenu(Menu menu) {
.setVisible(noteTmp.isChecklist() && mChecklistManager.getCheckedCount() > 0);
menu.findItem(R.id.menu_lock).setVisible(!noteTmp.isLocked());
menu.findItem(R.id.menu_unlock).setVisible(noteTmp.isLocked());

//If a reminder had been set for the note, then the "sync reminder option" will appear
//menu.findItem(R.id.menu_sync_reminder).setVisible(noteTmp.getAlarm() != null);

// If note is trashed only this options will be available from menu
if (noteTmp.isTrashed()) {
menu.findItem(R.id.menu_untrash).setVisible(true);
Expand Down Expand Up @@ -1097,12 +1117,24 @@ public boolean onOptionsItemSelected(MenuItem item) {
default:
LogDelegate.w("Invalid menu option selected");
}
return super.onOptionsItemSelected(item);
}

((OmniNotes) getActivity().getApplication()).getAnalyticsHelper()
.trackActionFromResourceId(getActivity(),
item.getItemId());
private void syncReminder () {

return super.onOptionsItemSelected(item);
//First save the note, them call the calendar intent
saveNote(this);

Intent intent = new Intent(Intent.ACTION_INSERT)
.setData(CalendarContract.Events.CONTENT_URI)
.putExtra(CalendarContract.Events.TITLE, noteTmp.getTitle())
.putExtra(CalendarContract.Events.DESCRIPTION, noteTmp.getContent())
.putExtra(CalendarContract.Events.EVENT_LOCATION, noteTmp.getAddress())
.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, parseLong(noteTmp.getAlarm()))
.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, parseLong(noteTmp.getAlarm()))
.putExtra(CalendarContract.Events.RRULE, noteTmp.getRecurrenceRule());

startActivity(intent);
}

private void showNoteInfo() {
Expand Down Expand Up @@ -2000,6 +2032,8 @@ public void onReminderPicked(long reminder) {
binding.fragmentDetailContent.reminderIcon.setImageResource(R.drawable.ic_alarm_black_18dp);
binding.fragmentDetailContent.datetime
.setText(RecurrenceHelper.getNoteReminderText(reminder));

binding.fragmentDetailContent.syncReminderLayout.setVisibility(View.VISIBLE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,6 @@ protected void onCreate(Bundle savedInstanceState) {
initData();
}

@Override
public void onStart() {
((OmniNotes) getApplication()).getAnalyticsHelper().trackScreenView(getClass().getName());
super.onStart();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
Expand Down
Loading