diff --git a/build.gradle b/build.gradle
index d64f093fe..6c752a48d 100644
--- a/build.gradle
+++ b/build.gradle
@@ -56,4 +56,4 @@ sonarqube {
property 'sonar.exclusions', '**/src/main/assets/**/*.*'
property 'sonar.test.exclusions', '**/src/test/**/*.*,**/src/androidTest/**/*.*'
}
-}
+}
\ No newline at end of file
diff --git a/omniNotes/build.gradle b/omniNotes/build.gradle
index dfa7ac3c7..010c86dd5 100644
--- a/omniNotes/build.gradle
+++ b/omniNotes/build.gradle
@@ -157,6 +157,7 @@ dependencies {
implementation 'com.google.android.apps.dashclock:dashclock-api:2.0.0'
implementation 'ch.acra:acra-http:5.11.2'
implementation 'ch.acra:acra-toast:5.11.2'
+ implementation 'commons-io:commons-io:2.16.1'
implementation 'com.github.gabrielemariotti.changeloglib:changelog:2.1.0'
implementation 'com.github.vikramkakkar:SublimePicker:8f573b1cfd'
implementation 'androidx.preference:preference-ktx:1.2.1'
@@ -202,11 +203,10 @@ dependencies {
implementation 'com.github.federicoiosue:pixlui:3.0.1'
// Flavors specific dependencies
- playImplementation 'io.nlopez.smartlocation:library:3.2.4'
- 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'
- fossImplementation 'com.jakewharton.timber:timber:5.0.1'
+ playImplementation 'com.google.android.gms:play-services-location:21.3.0'
+ betaImplementation 'com.google.android.gms:play-services-location:21.3.0'
+ alphaImplementation 'com.google.android.gms:play-services-location:21.3.0'
+// fossImplementation 'com.jakewharton.timber:timber:5.0.1'
}
def jacocoVersion = "0.8.7"
@@ -266,6 +266,8 @@ tasks.withType(Test).configureEach {
exceptionFormat "full"
}
}
-repositories {
- mavenCentral()
+
+tasks.register('wrapper', Wrapper) {
+ gradleVersion = '8.7'
+ validateDistributionUrl = false
}
diff --git a/omniNotes/gradle/wrapper/gradle-wrapper.jar b/omniNotes/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 000000000..e6441136f
Binary files /dev/null and b/omniNotes/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/omniNotes/gradle/wrapper/gradle-wrapper.properties b/omniNotes/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 000000000..a0777a32c
--- /dev/null
+++ b/omniNotes/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
+validateDistributionUrl=false
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
diff --git a/omniNotes/gradlew b/omniNotes/gradlew
new file mode 100755
index 000000000..1aa94a426
--- /dev/null
+++ b/omniNotes/gradlew
@@ -0,0 +1,249 @@
+#!/bin/sh
+
+#
+# Copyright © 2015-2021 the original authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+##############################################################################
+#
+# Gradle start up script for POSIX generated by Gradle.
+#
+# Important for running:
+#
+# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
+# noncompliant, but you have some other compliant shell such as ksh or
+# bash, then to run this script, type that shell name before the whole
+# command line, like:
+#
+# ksh Gradle
+#
+# Busybox and similar reduced shells will NOT work, because this script
+# requires all of these POSIX shell features:
+# * functions;
+# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
+# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
+# * compound commands having a testable exit status, especially «case»;
+# * various built-in commands including «command», «set», and «ulimit».
+#
+# Important for patching:
+#
+# (2) This script targets any POSIX shell, so it avoids extensions provided
+# by Bash, Ksh, etc; in particular arrays are avoided.
+#
+# The "traditional" practice of packing multiple parameters into a
+# space-separated string is a well documented source of bugs and security
+# problems, so this is (mostly) avoided, by progressively accumulating
+# options in "$@", and eventually passing that to Java.
+#
+# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
+# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
+# see the in-line comments for details.
+#
+# There are tweaks for specific operating systems such as AIX, CygWin,
+# Darwin, MinGW, and NonStop.
+#
+# (3) This script is generated from the Groovy template
+# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
+# within the Gradle project.
+#
+# You can find Gradle at https://github.com/gradle/gradle/.
+#
+##############################################################################
+
+# Attempt to set APP_HOME
+
+# Resolve links: $0 may be a link
+app_path=$0
+
+# Need this for daisy-chained symlinks.
+while
+ APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
+ [ -h "$app_path" ]
+do
+ ls=$( ls -ld "$app_path" )
+ link=${ls#*' -> '}
+ case $link in #(
+ /*) app_path=$link ;; #(
+ *) app_path=$APP_HOME$link ;;
+ esac
+done
+
+# This is normally unused
+# shellcheck disable=SC2034
+APP_BASE_NAME=${0##*/}
+# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
+APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD=maximum
+
+warn () {
+ echo "$*"
+} >&2
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+} >&2
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "$( uname )" in #(
+ CYGWIN* ) cygwin=true ;; #(
+ Darwin* ) darwin=true ;; #(
+ MSYS* | MINGW* ) msys=true ;; #(
+ NONSTOP* ) nonstop=true ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD=$JAVA_HOME/jre/sh/java
+ else
+ JAVACMD=$JAVA_HOME/bin/java
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD=java
+ if ! command -v java >/dev/null 2>&1
+ then
+ die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+fi
+
+# Increase the maximum file descriptors if we can.
+if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
+ case $MAX_FD in #(
+ max*)
+ # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC2039,SC3045
+ MAX_FD=$( ulimit -H -n ) ||
+ warn "Could not query maximum file descriptor limit"
+ esac
+ case $MAX_FD in #(
+ '' | soft) :;; #(
+ *)
+ # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC2039,SC3045
+ ulimit -n "$MAX_FD" ||
+ warn "Could not set maximum file descriptor limit to $MAX_FD"
+ esac
+fi
+
+# Collect all arguments for the java command, stacking in reverse order:
+# * args from the command line
+# * the main class name
+# * -classpath
+# * -D...appname settings
+# * --module-path (only if needed)
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
+
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if "$cygwin" || "$msys" ; then
+ APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
+ CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
+
+ JAVACMD=$( cygpath --unix "$JAVACMD" )
+
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ for arg do
+ if
+ case $arg in #(
+ -*) false ;; # don't mess with options #(
+ /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
+ [ -e "$t" ] ;; #(
+ *) false ;;
+ esac
+ then
+ arg=$( cygpath --path --ignore --mixed "$arg" )
+ fi
+ # Roll the args list around exactly as many times as the number of
+ # args, so each arg winds up back in the position where it started, but
+ # possibly modified.
+ #
+ # NB: a `for` loop captures its iteration list before it begins, so
+ # changing the positional parameters here affects neither the number of
+ # iterations, nor the values presented in `arg`.
+ shift # remove old arg
+ set -- "$@" "$arg" # push replacement arg
+ done
+fi
+
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+
+# Collect all arguments for the java command:
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
+# and any embedded shellness will be escaped.
+# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
+# treated as '${Hostname}' itself on the command line.
+
+set -- \
+ "-Dorg.gradle.appname=$APP_BASE_NAME" \
+ -classpath "$CLASSPATH" \
+ org.gradle.wrapper.GradleWrapperMain \
+ "$@"
+
+# Stop when "xargs" is not available.
+if ! command -v xargs >/dev/null 2>&1
+then
+ die "xargs is not available"
+fi
+
+# Use "xargs" to parse quoted args.
+#
+# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
+#
+# In Bash we could simply go:
+#
+# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
+# set -- "${ARGS[@]}" "$@"
+#
+# but POSIX shell has neither arrays nor command substitution, so instead we
+# post-process each arg (as a line of input to sed) to backslash-escape any
+# character that might be a shell metacharacter, then use eval to reverse
+# that process (while maintaining the separation between arguments), and wrap
+# the whole thing up as a single "set" statement.
+#
+# This will of course break if any of these variables contains a newline or
+# an unmatched quote.
+#
+
+eval "set -- $(
+ printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
+ xargs -n1 |
+ sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
+ tr '\n' ' '
+ )" '"$@"'
+
+exec "$JAVACMD" "$@"
diff --git a/omniNotes/gradlew.bat b/omniNotes/gradlew.bat
new file mode 100644
index 000000000..25da30dbd
--- /dev/null
+++ b/omniNotes/gradlew.bat
@@ -0,0 +1,92 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+
+@if "%DEBUG%"=="" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%"=="" set DIRNAME=.
+@rem This is normally unused
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if %ERRORLEVEL% equ 0 goto execute
+
+echo. 1>&2
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
+echo. 1>&2
+echo Please set the JAVA_HOME variable in your environment to match the 1>&2
+echo location of your Java installation. 1>&2
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto execute
+
+echo. 1>&2
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
+echo. 1>&2
+echo Please set the JAVA_HOME variable in your environment to match the 1>&2
+echo location of your Java installation. 1>&2
+
+goto fail
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
+
+:end
+@rem End local scope for the variables with windows NT shell
+if %ERRORLEVEL% equ 0 goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+set EXIT_CODE=%ERRORLEVEL%
+if %EXIT_CODE% equ 0 set EXIT_CODE=1
+if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
+exit /b %EXIT_CODE%
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/omniNotes/src/alpha/java/it/feio/android/omninotes/helpers/location/FuseLocationProvider.kt b/omniNotes/src/alpha/java/it/feio/android/omninotes/helpers/location/FuseLocationProvider.kt
new file mode 100644
index 000000000..b252ed4f9
--- /dev/null
+++ b/omniNotes/src/alpha/java/it/feio/android/omninotes/helpers/location/FuseLocationProvider.kt
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2013-2024 Federico Iosue (federico@iosue.it)
+ *
+ * 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 .
+ */
+package it.feio.android.omninotes.helpers.location
+
+import com.google.android.gms.location.LocationServices
+import it.feio.android.omninotes.OmniNotes
+import it.feio.android.omninotes.models.listeners.OnGeoUtilResultListener
+
+class FuseLocationProvider : LocationProvider {
+
+ @kotlin.Throws(SecurityException::class)
+ override fun getLocation(onGeoUtilResultListener: OnGeoUtilResultListener?) {
+ LocationServices.getFusedLocationProviderClient(OmniNotes.getAppContext()).getLastLocation()
+ .addOnSuccessListener { location ->
+ if (location == null) {
+ onGeoUtilResultListener?.onLocationUnavailable(null)
+ }
+ onGeoUtilResultListener?.onLocationRetrieved(location)
+ }
+ .addOnFailureListener { e -> onGeoUtilResultListener?.onLocationUnavailable(e) }
+ }
+
+}
diff --git a/omniNotes/src/main/java/it/feio/android/omninotes/models/listeners/OnGeoUtilResultListener.java b/omniNotes/src/alpha/java/it/feio/android/omninotes/helpers/location/LocationProviderFactory.kt
similarity index 67%
rename from omniNotes/src/main/java/it/feio/android/omninotes/models/listeners/OnGeoUtilResultListener.java
rename to omniNotes/src/alpha/java/it/feio/android/omninotes/helpers/location/LocationProviderFactory.kt
index be97ea346..1b59e41e9 100644
--- a/omniNotes/src/main/java/it/feio/android/omninotes/models/listeners/OnGeoUtilResultListener.java
+++ b/omniNotes/src/alpha/java/it/feio/android/omninotes/helpers/location/LocationProviderFactory.kt
@@ -14,21 +14,15 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
+package it.feio.android.omninotes.helpers.location
-package it.feio.android.omninotes.models.listeners;
+import lombok.experimental.UtilityClass
+@UtilityClass
+object LocationProviderFactory {
-import android.location.Location;
-
-
-public interface OnGeoUtilResultListener {
-
- void onAddressResolved(String address);
-
- void onCoordinatesResolved(Location location, String address);
-
- void onLocationRetrieved(Location location);
-
- void onLocationUnavailable();
- void onLocationNotEnabled();
+ @Override
+ fun getProvider(): LocationProvider {
+ return FuseLocationProvider()
+ }
}
diff --git a/omniNotes/src/androidTest/java/it/feio/android/omninotes/async/upgrade/UpgradeProcessorTest.kt b/omniNotes/src/androidTest/java/it/feio/android/omninotes/async/upgrade/UpgradeProcessorTest.kt
index 3f9c4054a..ab2a685bf 100644
--- a/omniNotes/src/androidTest/java/it/feio/android/omninotes/async/upgrade/UpgradeProcessorTest.kt
+++ b/omniNotes/src/androidTest/java/it/feio/android/omninotes/async/upgrade/UpgradeProcessorTest.kt
@@ -23,7 +23,6 @@ import it.feio.android.omninotes.utils.FileProviderHelper.getShareableUri
import it.feio.android.omninotes.utils.StorageHelper.createAttachmentFromUri
import org.junit.Assert.*
import org.junit.Test
-import java.util.stream.Stream
class UpgradeProcessorTest : BaseAndroidTestCase() {
@@ -32,7 +31,7 @@ class UpgradeProcessorTest : BaseAndroidTestCase() {
// Preparation of database state existent pre-612 version.
// Attachment used to be stored with "content://" scheme that allowed sharing but broke backups.
val note = createTestNote("t", "c", 1)
- var attachment = createAttachmentFromUri(testContext, note.attachmentsList[0].uri)
+ val attachment = createAttachmentFromUri(testContext, note.attachmentsList[0].uri)
attachment?.uri = getShareableUri(attachment)
note.attachmentsList[0] = attachment
dbHelper.updateNote(note, false)
diff --git a/omniNotes/src/androidTest/java/it/feio/android/omninotes/helpers/GeocodeProviderBaseFactoryTest.kt b/omniNotes/src/androidTest/java/it/feio/android/omninotes/helpers/GeocodeProviderBaseFactoryTest.kt
index f53f4c630..b97c05fb8 100644
--- a/omniNotes/src/androidTest/java/it/feio/android/omninotes/helpers/GeocodeProviderBaseFactoryTest.kt
+++ b/omniNotes/src/androidTest/java/it/feio/android/omninotes/helpers/GeocodeProviderBaseFactoryTest.kt
@@ -16,26 +16,22 @@
*/
package it.feio.android.omninotes.helpers
+import it.feio.android.omninotes.helpers.location.LocationProviderFactory
import it.feio.android.omninotes.testutils.BaseAndroidTestCase
import org.junit.Assert.assertNotNull
-import org.junit.Assert.assertTrue
import org.junit.Test
-class GeocodeProviderBaseFactoryTest : BaseAndroidTestCase() {
-
+class LocationProviderFactoryTest : BaseAndroidTestCase() {
+
@Test
@Throws(Exception::class)
fun checkUtilityClassWellDefined() {
- assertUtilityClassWellDefined(GeocodeProviderBaseFactory::class.java, true, true)
+ assertUtilityClassWellDefined(LocationProviderFactory::class.java, true, true)
}
@Test
fun provider() {
- assertNotNull(GeocodeProviderBaseFactory.getProvider(testContext))
+ assertNotNull(LocationProviderFactory.provider)
}
- @Test
- fun checkHighAccuracyLocationProvider() {
- assertTrue(GeocodeProviderBaseFactory.checkHighAccuracyLocationProvider(testContext))
- }
}
\ No newline at end of file
diff --git a/omniNotes/src/androidTest/java/it/feio/android/omninotes/testutils/BaseAndroidTestCase.java b/omniNotes/src/androidTest/java/it/feio/android/omninotes/testutils/BaseAndroidTestCase.java
index c9b6fff4a..26d0f765a 100644
--- a/omniNotes/src/androidTest/java/it/feio/android/omninotes/testutils/BaseAndroidTestCase.java
+++ b/omniNotes/src/androidTest/java/it/feio/android/omninotes/testutils/BaseAndroidTestCase.java
@@ -18,7 +18,6 @@
package it.feio.android.omninotes.testutils;
import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
-import static android.Manifest.permission.ACCESS_FINE_LOCATION;
import static android.Manifest.permission.POST_NOTIFICATIONS;
import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import static android.Manifest.permission.RECORD_AUDIO;
@@ -102,7 +101,7 @@ public void tearDown() {
.grant(android.Manifest.permission.CAMERA);
private static void grantPermissions() {
- GrantPermissionRule.grant(ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION, READ_EXTERNAL_STORAGE, RECORD_AUDIO);
+ GrantPermissionRule.grant(ACCESS_COARSE_LOCATION, READ_EXTERNAL_STORAGE, RECORD_AUDIO);
if (BuildHelper.isBelowOrEqual(VERSION_CODES.Q)) {
GrantPermissionRule.grant(WRITE_EXTERNAL_STORAGE);
}
diff --git a/omniNotes/src/androidTest/java/it/feio/android/omninotes/utils/GeocodeHelperTest.java b/omniNotes/src/androidTest/java/it/feio/android/omninotes/utils/GeocodeHelperTest.java
index d3d18d8af..6411f4133 100644
--- a/omniNotes/src/androidTest/java/it/feio/android/omninotes/utils/GeocodeHelperTest.java
+++ b/omniNotes/src/androidTest/java/it/feio/android/omninotes/utils/GeocodeHelperTest.java
@@ -21,6 +21,8 @@
import androidx.test.filters.FlakyTest;
import it.feio.android.omninotes.testutils.BaseAndroidTestCase;
import it.feio.android.omninotes.OmniNotes;
+import it.feio.android.omninotes.helpers.location.GeocodeHelper;
+
import java.io.IOException;
import org.junit.Assert;
import org.junit.Test;
diff --git a/omniNotes/src/beta/java/it/feio/android/omninotes/helpers/location/FuseLocationProvider.kt b/omniNotes/src/beta/java/it/feio/android/omninotes/helpers/location/FuseLocationProvider.kt
new file mode 100644
index 000000000..b252ed4f9
--- /dev/null
+++ b/omniNotes/src/beta/java/it/feio/android/omninotes/helpers/location/FuseLocationProvider.kt
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2013-2024 Federico Iosue (federico@iosue.it)
+ *
+ * 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 .
+ */
+package it.feio.android.omninotes.helpers.location
+
+import com.google.android.gms.location.LocationServices
+import it.feio.android.omninotes.OmniNotes
+import it.feio.android.omninotes.models.listeners.OnGeoUtilResultListener
+
+class FuseLocationProvider : LocationProvider {
+
+ @kotlin.Throws(SecurityException::class)
+ override fun getLocation(onGeoUtilResultListener: OnGeoUtilResultListener?) {
+ LocationServices.getFusedLocationProviderClient(OmniNotes.getAppContext()).getLastLocation()
+ .addOnSuccessListener { location ->
+ if (location == null) {
+ onGeoUtilResultListener?.onLocationUnavailable(null)
+ }
+ onGeoUtilResultListener?.onLocationRetrieved(location)
+ }
+ .addOnFailureListener { e -> onGeoUtilResultListener?.onLocationUnavailable(e) }
+ }
+
+}
diff --git a/omniNotes/src/beta/java/it/feio/android/omninotes/helpers/GeocodeProviderFactory.java b/omniNotes/src/beta/java/it/feio/android/omninotes/helpers/location/LocationProviderFactory.kt
similarity index 61%
rename from omniNotes/src/beta/java/it/feio/android/omninotes/helpers/GeocodeProviderFactory.java
rename to omniNotes/src/beta/java/it/feio/android/omninotes/helpers/location/LocationProviderFactory.kt
index b938ab847..1b59e41e9 100644
--- a/omniNotes/src/beta/java/it/feio/android/omninotes/helpers/GeocodeProviderFactory.java
+++ b/omniNotes/src/beta/java/it/feio/android/omninotes/helpers/location/LocationProviderFactory.kt
@@ -1,9 +1,9 @@
/*
- * Copyright (C) 2017-2024 Federico Iosue (federico.iosue@gmail.com)
+ * Copyright (C) 2013-2024 Federico Iosue (federico@iosue.it)
*
* 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 Foundatibehaon, either version 3 of the License, or
+ * 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,
@@ -14,9 +14,15 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
+package it.feio.android.omninotes.helpers.location
-package it.feio.android.omninotes.helpers;
+import lombok.experimental.UtilityClass
-public class GeocodeProviderFactory extends GeocodeProviderBaseFactory {
+@UtilityClass
+object LocationProviderFactory {
+ @Override
+ fun getProvider(): LocationProvider {
+ return FuseLocationProvider()
+ }
}
diff --git a/omniNotes/src/foss/java/it/feio/android/omninotes/helpers/location/LocationManagerLocationProvider.kt b/omniNotes/src/foss/java/it/feio/android/omninotes/helpers/location/LocationManagerLocationProvider.kt
new file mode 100644
index 000000000..59e84406a
--- /dev/null
+++ b/omniNotes/src/foss/java/it/feio/android/omninotes/helpers/location/LocationManagerLocationProvider.kt
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2013-2024 Federico Iosue (federico@iosue.it)
+ *
+ * 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 .
+ */
+package it.feio.android.omninotes.helpers.location
+
+import com.google.android.gms.location.LocationServices
+import it.feio.android.omninotes.OmniNotes
+import it.feio.android.omninotes.models.listeners.OnGeoUtilResultListener
+
+class FuseLocationProviderLocationManagerLocationProvider : LocationProvider {
+
+ @kotlin.Throws(SecurityException::class)
+ override fun getLocation(onGeoUtilResultListener: OnGeoUtilResultListener?) {
+ val lastKnownLocationByGps =
+ locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)
+ lastKnownLocationByGps?.let {
+ locationByGps = lastKnownLocationByGps
+ }
+
+ val lastKnownLocationByNetwork =
+ locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER)
+ lastKnownLocationByNetwork?.let {
+ locationByNetwork = lastKnownLocationByNetwork
+ }
+
+ if (locationByGps != null && locationByNetwork != null) {
+ if (locationByGps.accuracy > locationByNetwork!!.accuracy) {
+ currentLocation = locationByGps
+ latitude = currentLocation.latitude
+ longitude = currentLocation.longitude
+ // use latitude and longitude as per your need
+ } else {
+ currentLocation = locationByNetwork
+ latitude = currentLocation.latitude
+ longitude = currentLocation.longitude
+ // use latitude and longitude as per your need
+ }
+ }
+
+ }
+
+}
diff --git a/omniNotes/src/play/java/it/feio/android/omninotes/helpers/GeocodeProviderFactory.java b/omniNotes/src/foss/java/it/feio/android/omninotes/helpers/location/LocationProviderFactory.kt
similarity index 59%
rename from omniNotes/src/play/java/it/feio/android/omninotes/helpers/GeocodeProviderFactory.java
rename to omniNotes/src/foss/java/it/feio/android/omninotes/helpers/location/LocationProviderFactory.kt
index 46047f148..065ddcbea 100644
--- a/omniNotes/src/play/java/it/feio/android/omninotes/helpers/GeocodeProviderFactory.java
+++ b/omniNotes/src/foss/java/it/feio/android/omninotes/helpers/location/LocationProviderFactory.kt
@@ -14,20 +14,16 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
+package it.feio.android.omninotes.helpers.location
-package it.feio.android.omninotes.helpers;
+import lombok.experimental.UtilityClass
+import java.lang.Override
-import android.content.Context;
-import io.nlopez.smartlocation.location.LocationProvider;
-import io.nlopez.smartlocation.location.providers.LocationGooglePlayServicesWithFallbackProvider;
+@UtilityClass
+object LocationProviderFactory {
-public class GeocodeProviderFactory {
-
- private GeocodeProviderFactory() {
- // hides public constructor
- }
-
- public static LocationProvider getProvider(Context context) {
- return new LocationGooglePlayServicesWithFallbackProvider(context);
- }
+ @Override
+ fun getProvider(): LocationProvider? {
+ return LocationManagerLocationProvider()
+ }
}
diff --git a/omniNotes/src/main/AndroidManifest.xml b/omniNotes/src/main/AndroidManifest.xml
index f360e00fb..45d9d7d59 100644
--- a/omniNotes/src/main/AndroidManifest.xml
+++ b/omniNotes/src/main/AndroidManifest.xml
@@ -20,7 +20,6 @@
-
diff --git a/omniNotes/src/main/java/it/feio/android/omninotes/DetailFragment.java b/omniNotes/src/main/java/it/feio/android/omninotes/DetailFragment.java
index f0270cfa3..956d14265 100644
--- a/omniNotes/src/main/java/it/feio/android/omninotes/DetailFragment.java
+++ b/omniNotes/src/main/java/it/feio/android/omninotes/DetailFragment.java
@@ -20,7 +20,6 @@
import static android.content.Context.CLIPBOARD_SERVICE;
import static android.content.Context.LAYOUT_INFLATER_SERVICE;
import static android.content.pm.PackageManager.FEATURE_CAMERA;
-import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.widget.Toast.LENGTH_SHORT;
import static androidx.core.view.ViewCompat.animate;
import static it.feio.android.omninotes.BaseActivity.TRANSITION_HORIZONTAL;
@@ -69,7 +68,6 @@
import static java.lang.Long.parseLong;
import android.Manifest;
-import android.Manifest.permission;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.PendingIntent;
@@ -83,13 +81,13 @@
import android.graphics.Point;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
+import android.location.Address;
import android.location.Location;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.media.ThumbnailUtils;
import android.net.Uri;
import android.os.AsyncTask;
-import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.provider.MediaStore;
@@ -114,10 +112,7 @@
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.Toast;
-import androidx.activity.result.ActivityResultCallback;
-import androidx.activity.result.ActivityResultLauncher;
-import androidx.activity.result.contract.ActivityResultContracts;
-import androidx.core.content.ContextCompat;
+
import androidx.core.util.Pair;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.FragmentTransaction;
@@ -145,13 +140,13 @@
import it.feio.android.omninotes.exceptions.checked.ContentSecurityException;
import it.feio.android.omninotes.exceptions.checked.UnhandledIntentException;
import it.feio.android.omninotes.helpers.AttachmentsHelper;
-import it.feio.android.omninotes.helpers.BuildHelper;
import it.feio.android.omninotes.helpers.IntentHelper;
import it.feio.android.omninotes.helpers.LogDelegate;
import it.feio.android.omninotes.helpers.PermissionsHelper;
import it.feio.android.omninotes.helpers.TagOpenerHelper;
import it.feio.android.omninotes.helpers.date.DateHelper;
import it.feio.android.omninotes.helpers.date.RecurrenceHelper;
+import it.feio.android.omninotes.helpers.location.LocationProviderFactory;
import it.feio.android.omninotes.helpers.notifications.NotificationChannels.NotificationChannelNames;
import it.feio.android.omninotes.helpers.notifications.NotificationsHelper;
import it.feio.android.omninotes.models.Attachment;
@@ -173,7 +168,7 @@
import it.feio.android.omninotes.utils.Display;
import it.feio.android.omninotes.utils.FileHelper;
import it.feio.android.omninotes.utils.FileProviderHelper;
-import it.feio.android.omninotes.utils.GeocodeHelper;
+import it.feio.android.omninotes.helpers.location.GeocodeHelper;
import it.feio.android.omninotes.utils.IntentChecker;
import it.feio.android.omninotes.utils.KeyboardUtils;
import it.feio.android.omninotes.utils.PasswordHelper;
@@ -297,12 +292,6 @@ public void onAttach(Context context) {
EventBus.getDefault().post(new SwitchFragmentEvent(SwitchFragmentEvent.Direction.CHILDREN));
}
- @Override
- public void onStop() {
- super.onStop();
- GeocodeHelper.stop();
- }
-
@Override
public void onResume() {
super.onResume();
@@ -718,9 +707,9 @@ private void initViewLocation() {
private void getLocation(OnGeoUtilResultListener onGeoUtilResultListener) {
PermissionsHelper
- .requestPermission(this, Manifest.permission.ACCESS_FINE_LOCATION, R.string
+ .requestPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION, R.string
.permission_coarse_location, binding.snackbarPlaceholder,
- () -> GeocodeHelper.getLocation(onGeoUtilResultListener));
+ () -> LocationProviderFactory.INSTANCE.getProvider().getLocation(onGeoUtilResultListener));
}
private void initViewAttachments() {
@@ -959,8 +948,8 @@ public void onLocationRetrieved(Location location) {
}
@Override
- public void onLocationUnavailable() {
- mainActivity.showMessage(R.string.location_not_found, ONStyle.ALERT);
+ public void onLocationUnavailable(Exception e) {
+ mainActivity.showMessage(R.string.location_not_found + ": " + e.getMessage(), ONStyle.ALERT);
}
public void onLocationNotEnabled(){
@@ -984,13 +973,18 @@ public void onAddressResolved(String address) {
}
@Override
- public void onCoordinatesResolved(Location location, String address) {
- if (location != null) {
- noteTmp.setLatitude(location.getLatitude());
- noteTmp.setLongitude(location.getLongitude());
- noteTmp.setAddress(address);
+ public void onCoordinatesUnresolved(Exception e) {
+ mainActivity.showMessage(R.string.location_not_found + ": " + e.getMessage(), ONStyle.ALERT);
+ }
+
+ @Override
+ public void onCoordinatesResolved(Address address) {
+ if (address != null) {
+ noteTmp.setLatitude(address.getLatitude());
+ noteTmp.setLongitude(address.getLongitude());
+ noteTmp.setAddress(address.getAddressLine(0));
binding.fragmentDetailContent.location.setVisibility(View.VISIBLE);
- binding.fragmentDetailContent.location.setText(address);
+ binding.fragmentDetailContent.location.setText(address.getAddressLine(0));
fade(binding.fragmentDetailContent.location, true);
} else {
mainActivity.showMessage(R.string.location_not_found, ONStyle.ALERT);
@@ -2235,13 +2229,18 @@ public void onAddressResolved(String address) {
}
@Override
- public void onCoordinatesResolved(Location location, String address) {
+ public void onCoordinatesResolved(Address address) {
+ // Nothing to do
+ }
+
+ @Override
+ public void onCoordinatesUnresolved(Exception e) {
// Nothing to do
}
@Override
- public void onLocationUnavailable() {
- mainActivityWeakReference.get().showMessage(R.string.location_not_found, ONStyle.ALERT);
+ public void onLocationUnavailable(Exception e) {
+ mainActivityWeakReference.get().showMessage(R.string.location_not_found + ": " + e.getMessage(), ONStyle.ALERT);
}
@Override
public void onLocationNotEnabled(){
diff --git a/omniNotes/src/main/java/it/feio/android/omninotes/SettingsFragment.java b/omniNotes/src/main/java/it/feio/android/omninotes/SettingsFragment.java
index faa9d987f..004713fb7 100644
--- a/omniNotes/src/main/java/it/feio/android/omninotes/SettingsFragment.java
+++ b/omniNotes/src/main/java/it/feio/android/omninotes/SettingsFragment.java
@@ -72,7 +72,6 @@
import it.feio.android.omninotes.intro.IntroActivity;
import it.feio.android.omninotes.models.ONStyle;
import it.feio.android.omninotes.models.PasswordValidator.Result;
-import it.feio.android.omninotes.utils.IntentChecker;
import it.feio.android.omninotes.utils.PasswordHelper;
import it.feio.android.omninotes.utils.ResourcesUtils;
import it.feio.android.omninotes.utils.StorageHelper;
diff --git a/omniNotes/src/main/java/it/feio/android/omninotes/helpers/GeocodeProviderBaseFactory.java b/omniNotes/src/main/java/it/feio/android/omninotes/helpers/GeocodeProviderBaseFactory.java
deleted file mode 100644
index a2d8caec0..000000000
--- a/omniNotes/src/main/java/it/feio/android/omninotes/helpers/GeocodeProviderBaseFactory.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2013-2024 Federico Iosue (federico@iosue.it)
- *
- * 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 .
- */
-
-package it.feio.android.omninotes.helpers;
-
-import android.content.Context;
-import android.content.Intent;
-import android.location.LocationManager;
-import android.os.Build.VERSION_CODES;
-import android.provider.Settings;
-import android.widget.Toast;
-import io.nlopez.smartlocation.location.LocationProvider;
-import io.nlopez.smartlocation.location.providers.LocationGooglePlayServicesWithFallbackProvider;
-import it.feio.android.omninotes.R;
-import it.feio.android.omninotes.utils.GeocodeHelper;
-
-public class GeocodeProviderBaseFactory {
-
- protected GeocodeProviderBaseFactory() {
- // hides public constructor
- }
-
- public static LocationProvider getProvider(Context context) {
- if (BuildHelper.isBelow(VERSION_CODES.P) && checkHighAccuracyLocationProvider(context)) {
- Toast.makeText(context, R.string.location_set_high_accuracy, Toast.LENGTH_SHORT).show();
- context.startActivity((new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)));
- }
-
- return new LocationGooglePlayServicesWithFallbackProvider(context);
- }
-
- public static boolean checkHighAccuracyLocationProvider(Context context) {
- return GeocodeHelper.checkLocationProviderEnabled(context, LocationManager.GPS_PROVIDER);
- }
-
-}
diff --git a/omniNotes/src/main/java/it/feio/android/omninotes/utils/GeocodeHelper.java b/omniNotes/src/main/java/it/feio/android/omninotes/helpers/location/GeocodeHelper.java
similarity index 55%
rename from omniNotes/src/main/java/it/feio/android/omninotes/utils/GeocodeHelper.java
rename to omniNotes/src/main/java/it/feio/android/omninotes/helpers/location/GeocodeHelper.java
index 708b22e95..746432d86 100644
--- a/omniNotes/src/main/java/it/feio/android/omninotes/utils/GeocodeHelper.java
+++ b/omniNotes/src/main/java/it/feio/android/omninotes/helpers/location/GeocodeHelper.java
@@ -15,25 +15,25 @@
* along with this program. If not, see .
*/
-package it.feio.android.omninotes.utils;
+package it.feio.android.omninotes.helpers.location;
+import static android.os.Build.VERSION_CODES.TIRAMISU;
import static it.feio.android.omninotes.BuildConfig.MAPS_API_KEY;
-import static it.feio.android.omninotes.helpers.GeocodeProviderBaseFactory.checkHighAccuracyLocationProvider;
-import static it.feio.android.omninotes.helpers.GeocodeProviderBaseFactory.getProvider;
import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
-import android.location.LocationListener;
import android.location.LocationManager;
-import android.os.Bundle;
import android.text.TextUtils;
-import io.nlopez.smartlocation.SmartLocation;
-import io.nlopez.smartlocation.location.config.LocationParams;
+
import it.feio.android.omninotes.OmniNotes;
+import it.feio.android.omninotes.helpers.BuildHelper;
import it.feio.android.omninotes.helpers.LogDelegate;
import it.feio.android.omninotes.models.listeners.OnGeoUtilResultListener;
+import it.feio.android.omninotes.utils.SystemHelper;
+import lombok.experimental.UtilityClass;
+
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
@@ -50,131 +50,66 @@
import org.json.JSONObject;
-public class GeocodeHelper implements LocationListener {
+@UtilityClass
+public class GeocodeHelper {
private static final String PLACES_API_BASE = "https://maps.googleapis.com/maps/api/place";
private static final String TYPE_AUTOCOMPLETE = "/autocomplete";
private static final String OUT_JSON = "/json";
- @Override
- public void onLocationChanged(Location newLocation) {
- // Nothing to do
- }
-
-
- @Override
- @Deprecated
- public void onStatusChanged(String provider, int status, Bundle extras) {
- // Nothing to do
- }
-
-
- @Override
- public void onProviderEnabled(String provider) {
- // Nothing to do
- }
-
-
- @Override
- public void onProviderDisabled(String provider) {
- // Nothing to do
- }
-
-
- public static void getLocation(OnGeoUtilResultListener onGeoUtilResultListener) {
- SmartLocation.LocationControl bod = SmartLocation.with(OmniNotes.getAppContext())
- .location(getProvider(OmniNotes.getAppContext()))
- .config(LocationParams.NAVIGATION).oneFix();
-
- var location = bod.oneFix().getLastLocation();
-
- if (location != null) {
- onGeoUtilResultListener.onLocationRetrieved(location);
- } else {
- if (checkHighAccuracyLocationProvider(OmniNotes.getAppContext())) {
- onGeoUtilResultListener.onLocationUnavailable();
- } else {
- onGeoUtilResultListener.onLocationNotEnabled();
- }
- }
- }
-
-
- public static void stop() {
- SmartLocation.with(OmniNotes.getAppContext()).location().stop();
- if (Geocoder.isPresent()) {
- SmartLocation.with(OmniNotes.getAppContext()).geocoding().stop();
- }
- }
-
-
- static String getAddressFromCoordinates(Context mContext, double latitude,
+ public String getAddressFromCoordinates(Context mContext, double latitude,
double longitude) throws IOException {
- String addressString = "";
- Geocoder geocoder = new Geocoder(mContext, Locale.getDefault());
- List
addresses = geocoder.getFromLocation(latitude, longitude, 1);
- if (!addresses.isEmpty()) {
+ var geocoder = new Geocoder(mContext, Locale.getDefault());
+ var addresses = geocoder.getFromLocation(latitude, longitude, 1);
+ if (addresses != null && !addresses.isEmpty()) {
Address address = addresses.get(0);
if (address != null) {
- addressString = address.getThoroughfare() + ", " + address.getLocality();
+ return address.getThoroughfare() + ", " + address.getLocality();
}
}
- return addressString;
+ return "";
}
-
- public static void getAddressFromCoordinates(Location location,
+ public void getAddressFromCoordinates(Location location,
final OnGeoUtilResultListener onGeoUtilResultListener) {
- if (!Geocoder.isPresent()) {
- onGeoUtilResultListener.onAddressResolved("");
- } else {
- SmartLocation.with(OmniNotes.getAppContext()).geocoding()
- .reverse(location, (location1, list) -> {
- String address = !list.isEmpty() ? list.get(0).getAddressLine(0) : null;
- onGeoUtilResultListener.onAddressResolved(address);
- });
- }
- }
-
-
- public static double[] getCoordinatesFromAddress(Context mContext, String address)
- throws IOException {
- double[] result = new double[2];
- Geocoder geocoder = new Geocoder(mContext, Locale.getDefault());
- List addresses = geocoder.getFromLocationName(address, 1);
- if (!addresses.isEmpty()) {
- double latitude = addresses.get(0).getLatitude();
- double longitude = addresses.get(0).getLongitude();
- result[0] = latitude;
- result[1] = longitude;
+ try {
+ var address= getAddressFromCoordinates(OmniNotes.getAppContext(), location.getLatitude(),
+ location.getLongitude());
+ onGeoUtilResultListener.onAddressResolved(address);
+ } catch (IOException e) {
+ onGeoUtilResultListener.onLocationUnavailable(e);
}
- return result;
}
-
- public static void getCoordinatesFromAddress(String address, final OnGeoUtilResultListener
- listener) {
- SmartLocation.with(OmniNotes.getAppContext()).geocoding().direct(address, (name, results) -> {
- if (!results.isEmpty()) {
- listener.onCoordinatesResolved(results.get(0).getLocation(), address);
+ public void getCoordinatesFromAddress(String address, final OnGeoUtilResultListener listener) {
+ try {
+ var geocoder = new Geocoder(OmniNotes.getAppContext(), Locale.getDefault());
+ if (BuildHelper.isAboveOrEqual(TIRAMISU)) {
+ geocoder.getFromLocationName(address, 1, addresses -> listener.onCoordinatesResolved(addresses.get(0)));
+ } else {
+ var addresses = geocoder.getFromLocationName(address, 1);
+ if (addresses != null && !addresses.isEmpty()) {
+ listener.onCoordinatesResolved(addresses.get(0));
+ }
}
- });
+ } catch (IOException e) {
+ listener.onCoordinatesUnresolved(e);
+ }
}
-
public static List autocomplete(String input) {
if (TextUtils.isEmpty(MAPS_API_KEY)) {
return Collections.emptyList();
}
+
ArrayList resultList = null;
HttpURLConnection conn = null;
InputStreamReader in = null;
StringBuilder jsonResults = new StringBuilder();
try {
- URL url = new URL(
- PLACES_API_BASE + TYPE_AUTOCOMPLETE + OUT_JSON + "?key=" + MAPS_API_KEY + "&input=" +
- URLEncoder.encode(input, "utf8"));
+ var url = new URL(PLACES_API_BASE + TYPE_AUTOCOMPLETE + OUT_JSON + "?key="
+ + MAPS_API_KEY + "&input=" + URLEncoder.encode(input, "utf8"));
conn = (HttpURLConnection) url.openConnection();
in = new InputStreamReader(conn.getInputStream());
// Load the results into a StringBuilder
@@ -220,7 +155,6 @@ public static List autocomplete(String input) {
return resultList;
}
-
public static boolean areCoordinates(String string) {
var p = Pattern.compile(
"^[-+]?([1-8]?\\d(\\.\\d+)?|90(\\.0+)?),\\s*[-+]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$");
diff --git a/omniNotes/src/main/java/it/feio/android/omninotes/helpers/location/LocationProvider.java b/omniNotes/src/main/java/it/feio/android/omninotes/helpers/location/LocationProvider.java
new file mode 100644
index 000000000..89c16f8fc
--- /dev/null
+++ b/omniNotes/src/main/java/it/feio/android/omninotes/helpers/location/LocationProvider.java
@@ -0,0 +1,9 @@
+package it.feio.android.omninotes.helpers.location;
+
+import it.feio.android.omninotes.models.listeners.OnGeoUtilResultListener;
+
+public interface LocationProvider {
+
+ void getLocation(OnGeoUtilResultListener onGeoUtilResultListener) throws SecurityException;
+
+}
diff --git a/omniNotes/src/main/java/it/feio/android/omninotes/models/adapters/PlacesAutoCompleteAdapter.java b/omniNotes/src/main/java/it/feio/android/omninotes/models/adapters/PlacesAutoCompleteAdapter.java
index fbd1f5fff..000d7cd56 100644
--- a/omniNotes/src/main/java/it/feio/android/omninotes/models/adapters/PlacesAutoCompleteAdapter.java
+++ b/omniNotes/src/main/java/it/feio/android/omninotes/models/adapters/PlacesAutoCompleteAdapter.java
@@ -21,7 +21,7 @@
import android.widget.ArrayAdapter;
import android.widget.Filter;
import android.widget.Filterable;
-import it.feio.android.omninotes.utils.GeocodeHelper;
+import it.feio.android.omninotes.helpers.location.GeocodeHelper;
import java.util.List;
diff --git a/omniNotes/src/foss/java/it/feio/android/omninotes/helpers/GeocodeProviderFactory.java b/omniNotes/src/main/java/it/feio/android/omninotes/models/listeners/OnGeoUtilResultListener.kt
similarity index 62%
rename from omniNotes/src/foss/java/it/feio/android/omninotes/helpers/GeocodeProviderFactory.java
rename to omniNotes/src/main/java/it/feio/android/omninotes/models/listeners/OnGeoUtilResultListener.kt
index d791f9159..15c9749ed 100644
--- a/omniNotes/src/foss/java/it/feio/android/omninotes/helpers/GeocodeProviderFactory.java
+++ b/omniNotes/src/main/java/it/feio/android/omninotes/models/listeners/OnGeoUtilResultListener.kt
@@ -14,20 +14,21 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
+package it.feio.android.omninotes.models.listeners
-package it.feio.android.omninotes.helpers;
+import android.location.Address
+import android.location.Location
-import android.content.Context;
-import io.nlopez.smartlocation.location.LocationProvider;
-import io.nlopez.smartlocation.location.providers.LocationManagerProvider;
-public class GeocodeProviderFactory {
+interface OnGeoUtilResultListener {
- private GeocodeProviderFactory() {
- // hides public constructor
- }
+ fun onAddressResolved(address: String?)
- public static LocationProvider getProvider(Context context) {
- return new LocationManagerProvider();
- }
-}
\ No newline at end of file
+ fun onCoordinatesResolved(address: Address?)
+ fun onCoordinatesUnresolved(exception: Exception?)
+
+ fun onLocationRetrieved(location: Location?)
+
+ fun onLocationUnavailable(e: Exception?)
+ fun onLocationNotEnabled()
+}
diff --git a/omniNotes/src/main/res/values/integers.xml b/omniNotes/src/main/res/values/integers.xml
index 2c431a8e1..b6b4534c1 100644
--- a/omniNotes/src/main/res/values/integers.xml
+++ b/omniNotes/src/main/res/values/integers.xml
@@ -25,5 +25,5 @@
1
2
- 9080000
+ 12451000
diff --git a/omniNotes/src/play/java/it/feio/android/omninotes/helpers/location/FuseLocationProvider.kt b/omniNotes/src/play/java/it/feio/android/omninotes/helpers/location/FuseLocationProvider.kt
new file mode 100644
index 000000000..b252ed4f9
--- /dev/null
+++ b/omniNotes/src/play/java/it/feio/android/omninotes/helpers/location/FuseLocationProvider.kt
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2013-2024 Federico Iosue (federico@iosue.it)
+ *
+ * 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 .
+ */
+package it.feio.android.omninotes.helpers.location
+
+import com.google.android.gms.location.LocationServices
+import it.feio.android.omninotes.OmniNotes
+import it.feio.android.omninotes.models.listeners.OnGeoUtilResultListener
+
+class FuseLocationProvider : LocationProvider {
+
+ @kotlin.Throws(SecurityException::class)
+ override fun getLocation(onGeoUtilResultListener: OnGeoUtilResultListener?) {
+ LocationServices.getFusedLocationProviderClient(OmniNotes.getAppContext()).getLastLocation()
+ .addOnSuccessListener { location ->
+ if (location == null) {
+ onGeoUtilResultListener?.onLocationUnavailable(null)
+ }
+ onGeoUtilResultListener?.onLocationRetrieved(location)
+ }
+ .addOnFailureListener { e -> onGeoUtilResultListener?.onLocationUnavailable(e) }
+ }
+
+}
diff --git a/omniNotes/src/alpha/java/it/feio/android/omninotes/helpers/GeocodeProviderFactory.java b/omniNotes/src/play/java/it/feio/android/omninotes/helpers/location/LocationProviderFactory.kt
similarity index 75%
rename from omniNotes/src/alpha/java/it/feio/android/omninotes/helpers/GeocodeProviderFactory.java
rename to omniNotes/src/play/java/it/feio/android/omninotes/helpers/location/LocationProviderFactory.kt
index e2736784d..349a3d927 100644
--- a/omniNotes/src/alpha/java/it/feio/android/omninotes/helpers/GeocodeProviderFactory.java
+++ b/omniNotes/src/play/java/it/feio/android/omninotes/helpers/location/LocationProviderFactory.kt
@@ -14,9 +14,14 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
+package it.feio.android.omninotes.helpers.location
-package it.feio.android.omninotes.helpers;
+import lombok.experimental.UtilityClass
-public class GeocodeProviderFactory extends GeocodeProviderBaseFactory {
+@UtilityClass
+object LocationProviderFactory {
-}
\ No newline at end of file
+ @JvmStatic
+ val provider: LocationProvider
+ get() = FuseLocationProvider()
+}