├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── ic_playstore.png
│ │ ├── res
│ │ │ ├── drawable
│ │ │ │ ├── configure_0.png
│ │ │ │ ├── configure_1.png
│ │ │ │ ├── configure_2.png
│ │ │ │ ├── configure_3.png
│ │ │ │ ├── configure_4.png
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── drawable-hdpi
│ │ │ │ └── ic_osmand_logo.png
│ │ │ ├── drawable-mdpi
│ │ │ │ ├── ic_osmand_logo.png
│ │ │ │ └── ic_sync_action.xml
│ │ │ ├── drawable-xhdpi
│ │ │ │ └── ic_osmand_logo.png
│ │ │ ├── drawable-xxhdpi
│ │ │ │ └── ic_osmand_logo.png
│ │ │ ├── values
│ │ │ │ ├── ic_launcher_background.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── strings.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── layout
│ │ │ │ ├── settings_activity.xml
│ │ │ │ ├── dialog_install_osm_and.xml
│ │ │ │ ├── activity_intro_welcome.xml
│ │ │ │ ├── activity_intro_directory.xml
│ │ │ │ ├── activity_intro_install_osmand.xml
│ │ │ │ └── activity_intro_configure_osmand.xml
│ │ │ ├── menu
│ │ │ │ └── settings_activity.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── folder.xml
│ │ │ └── xml
│ │ │ │ └── root_preferences.xml
│ │ ├── java
│ │ │ └── org
│ │ │ │ └── decsync
│ │ │ │ └── osmand
│ │ │ │ ├── external
│ │ │ │ ├── PlatformUtil.java
│ │ │ │ ├── Algorithms.java
│ │ │ │ ├── ColorDialogs.java
│ │ │ │ ├── OsmAndAidlHelper.java
│ │ │ │ └── GPXUtilities.java
│ │ │ │ ├── model
│ │ │ │ ├── OsmandCategory.kt
│ │ │ │ ├── AppDatabase.kt
│ │ │ │ ├── FavoriteDao.kt
│ │ │ │ ├── CategoryDao.kt
│ │ │ │ ├── DecsyncFavorite.kt
│ │ │ │ ├── OsmandFavorite.kt
│ │ │ │ ├── DecsyncCategory.kt
│ │ │ │ └── DecsyncItem.kt
│ │ │ │ ├── PrefUtils.kt
│ │ │ │ ├── Utils.kt
│ │ │ │ ├── SettingsActivity.kt
│ │ │ │ ├── DecsyncListeners.kt
│ │ │ │ ├── DiffUtil.kt
│ │ │ │ ├── DecsyncUtils.kt
│ │ │ │ └── IntroActivity.kt
│ │ └── AndroidManifest.xml
│ └── test
│ │ └── java
│ │ └── org
│ │ └── decsync
│ │ └── osmand
│ │ └── ModelTest.kt
├── proguard-rules.pro
├── build.gradle
└── schemas
│ └── org.decsync.osmand.model.AppDatabase
│ └── 1.json
├── settings.gradle
├── screenshots
├── Screenshot_0.png
├── Screenshot_1.png
├── Screenshot_2.png
├── Screenshot_3.png
└── Screenshot_4.png
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── README.md
├── gradle.properties
├── .gitignore
├── gradlew.bat
├── gradlew
├── svg
└── logo.svg
└── LICENSE.txt
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 | rootProject.name = "OsmAnd DecSync"
--------------------------------------------------------------------------------
/app/src/main/ic_playstore.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/39aldo39/OsmAnd-DecSync/HEAD/app/src/main/ic_playstore.png
--------------------------------------------------------------------------------
/screenshots/Screenshot_0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/39aldo39/OsmAnd-DecSync/HEAD/screenshots/Screenshot_0.png
--------------------------------------------------------------------------------
/screenshots/Screenshot_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/39aldo39/OsmAnd-DecSync/HEAD/screenshots/Screenshot_1.png
--------------------------------------------------------------------------------
/screenshots/Screenshot_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/39aldo39/OsmAnd-DecSync/HEAD/screenshots/Screenshot_2.png
--------------------------------------------------------------------------------
/screenshots/Screenshot_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/39aldo39/OsmAnd-DecSync/HEAD/screenshots/Screenshot_3.png
--------------------------------------------------------------------------------
/screenshots/Screenshot_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/39aldo39/OsmAnd-DecSync/HEAD/screenshots/Screenshot_4.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/39aldo39/OsmAnd-DecSync/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable/configure_0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/39aldo39/OsmAnd-DecSync/HEAD/app/src/main/res/drawable/configure_0.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/configure_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/39aldo39/OsmAnd-DecSync/HEAD/app/src/main/res/drawable/configure_1.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/configure_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/39aldo39/OsmAnd-DecSync/HEAD/app/src/main/res/drawable/configure_2.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/configure_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/39aldo39/OsmAnd-DecSync/HEAD/app/src/main/res/drawable/configure_3.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/configure_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/39aldo39/OsmAnd-DecSync/HEAD/app/src/main/res/drawable/configure_4.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/39aldo39/OsmAnd-DecSync/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/39aldo39/OsmAnd-DecSync/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/39aldo39/OsmAnd-DecSync/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/39aldo39/OsmAnd-DecSync/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/39aldo39/OsmAnd-DecSync/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_osmand_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/39aldo39/OsmAnd-DecSync/HEAD/app/src/main/res/drawable-hdpi/ic_osmand_logo.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_osmand_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/39aldo39/OsmAnd-DecSync/HEAD/app/src/main/res/drawable-mdpi/ic_osmand_logo.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_osmand_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/39aldo39/OsmAnd-DecSync/HEAD/app/src/main/res/drawable-xhdpi/ic_osmand_logo.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_osmand_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/39aldo39/OsmAnd-DecSync/HEAD/app/src/main/res/drawable-xxhdpi/ic_osmand_logo.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/39aldo39/OsmAnd-DecSync/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/39aldo39/OsmAnd-DecSync/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/39aldo39/OsmAnd-DecSync/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/39aldo39/OsmAnd-DecSync/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/39aldo39/OsmAnd-DecSync/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFFFFF
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 30sp
4 | 16sp
5 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Oct 20 18:50:54 CEST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/settings_activity.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/settings_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/folder.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | OsmAnd DecSync
2 | ==============
3 |
4 | OsmAnd DecSync is an Android application which synchronizes the favorites of [OsmAnd](https://osmand.net) using [DecSync](https://github.com/39aldo39/DecSync) without requiring a server. To start synchronizing, all you have to do is synchronize your selected DecSync directory, using for example [Syncthing](https://syncthing.net).
5 |
6 | Donations
7 | ---------
8 |
9 | ### PayPal
10 | [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4V96AFD3S4TPJ)
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_sync_action.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFA033
4 | #EE5622
5 | #008BF8
6 |
7 | #2f7af5
8 |
9 | #20000000
10 | #EF6C00
11 | #0277BD
12 | #F9A825
13 | #009688
14 | #404040
15 |
--------------------------------------------------------------------------------
/app/src/main/java/org/decsync/osmand/external/PlatformUtil.java:
--------------------------------------------------------------------------------
1 | package org.decsync.osmand.external;
2 |
3 | // Stripped from net.osmand.PlatformUtil
4 | //
5 |
6 | import org.xmlpull.v1.XmlPullParser;
7 | import org.xmlpull.v1.XmlPullParserException;
8 |
9 | public class PlatformUtil {
10 | public static XmlPullParser newXMLPullParser() throws XmlPullParserException{
11 | org.kxml2.io.KXmlParser xmlParser = new org.kxml2.io.KXmlParser();
12 | xmlParser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
13 | return xmlParser;
14 | }
15 | }
--------------------------------------------------------------------------------
/app/src/main/java/org/decsync/osmand/model/OsmandCategory.kt:
--------------------------------------------------------------------------------
1 | package org.decsync.osmand.model
2 |
3 | sealed class OsmandCategoryOrDefault {
4 | abstract val name: String
5 | abstract val colorTag: String
6 | abstract val visible: Boolean
7 | }
8 |
9 | data class OsmandCategory(
10 | override val name: String, override val colorTag: String, override val visible: Boolean
11 | ) : OsmandCategoryOrDefault() {
12 | fun toDecsyncCategory(id: String): DecsyncCategory {
13 | return DecsyncCategory(id, name, colorTag, visible)
14 | }
15 | }
16 |
17 | object DefaultOsmandCategory : OsmandCategoryOrDefault() {
18 | override val name = "Favorites"
19 | override val colorTag = "yellow"
20 | override val visible = true
21 | }
--------------------------------------------------------------------------------
/app/src/main/java/org/decsync/osmand/model/AppDatabase.kt:
--------------------------------------------------------------------------------
1 | package org.decsync.osmand.model
2 |
3 | import android.content.Context
4 | import androidx.room.Database
5 | import androidx.room.Room
6 | import androidx.room.RoomDatabase
7 |
8 | @Database(entities = [DecsyncFavorite::class, DecsyncCategory::class], version = 1)
9 | abstract class AppDatabase : RoomDatabase() {
10 | abstract fun favoriteDao(): FavoriteDao
11 | abstract fun categoryDao(): CategoryDao
12 |
13 | companion object {
14 | private const val DATABASE_NAME = "db"
15 |
16 | fun createDatabase(context: Context): AppDatabase {
17 | return Room.databaseBuilder(context.applicationContext, AppDatabase::class.java, DATABASE_NAME).build()
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/app/src/main/java/org/decsync/osmand/model/FavoriteDao.kt:
--------------------------------------------------------------------------------
1 | package org.decsync.osmand.model
2 |
3 | import androidx.room.*
4 |
5 | @Dao
6 | abstract class FavoriteDao {
7 | @get:Query("SELECT * FROM favorites")
8 | abstract val all: List
9 |
10 | @Query("SELECT * FROM favorites where favId = :favId")
11 | abstract fun findById(favId: String): DecsyncFavorite?
12 |
13 | @Insert(onConflict = OnConflictStrategy.REPLACE)
14 | abstract fun insert(vararg favorites: DecsyncFavorite)
15 |
16 | @Update
17 | abstract fun update(vararg favorites: DecsyncFavorite)
18 |
19 | @Delete
20 | abstract fun delete(vararg favorites: DecsyncFavorite)
21 |
22 | @Query("DELETE FROM favorites")
23 | abstract fun deleteAll()
24 | }
--------------------------------------------------------------------------------
/app/src/main/java/org/decsync/osmand/model/CategoryDao.kt:
--------------------------------------------------------------------------------
1 | package org.decsync.osmand.model
2 |
3 | import androidx.room.*
4 |
5 | @Dao
6 | abstract class CategoryDao {
7 | @get:Query("SELECT * FROM categories")
8 | abstract val all: List
9 |
10 | @Query("SELECT * FROM categories where catId = :catId")
11 | abstract fun findById(catId: String): DecsyncCategory?
12 |
13 | @Insert(onConflict = OnConflictStrategy.REPLACE)
14 | abstract fun insert(vararg categories: DecsyncCategory)
15 |
16 | @Update
17 | abstract fun update(vararg categories: DecsyncCategory)
18 |
19 | @Delete
20 | abstract fun delete(vararg categories: DecsyncCategory)
21 |
22 | @Query("DELETE FROM categories")
23 | abstract fun deleteAll()
24 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
15 |
--------------------------------------------------------------------------------
/app/src/main/java/org/decsync/osmand/model/DecsyncFavorite.kt:
--------------------------------------------------------------------------------
1 | package org.decsync.osmand.model
2 |
3 | import androidx.room.Entity
4 | import androidx.room.Index
5 | import androidx.room.PrimaryKey
6 |
7 | @Entity(tableName = "favorites",
8 | indices = [(Index(value = ["favId"], unique = true))])
9 | data class DecsyncFavorite(
10 | @PrimaryKey val favId: String,
11 | var lat: Double, var lon: Double,
12 | var name: String, var description: String?,
13 | var catId: String?
14 | ) {
15 | companion object {
16 | fun default(favId: String): DecsyncFavorite = DecsyncFavorite(favId, 0.0, 0.0, favId, null, null)
17 | }
18 |
19 | @ExperimentalStdlibApi
20 | fun getMapsFavorite(): Maps.Favorite {
21 | return Maps.Favorite(favId, lat, lon, name, description, catId) { catId }
22 | }
23 | }
--------------------------------------------------------------------------------
/app/src/main/java/org/decsync/osmand/model/OsmandFavorite.kt:
--------------------------------------------------------------------------------
1 | package org.decsync.osmand.model
2 |
3 | data class OsmandFavorite(
4 | val lat: Double, val lon: Double,
5 | val name: String, val description: String?,
6 | val catName: String, val colorTag: String, val visible: Boolean
7 | ) {
8 | fun getCategory(): OsmandCategoryOrDefault {
9 | if (catName == DefaultOsmandCategory.name &&
10 | colorTag == DefaultOsmandCategory.colorTag &&
11 | visible == DefaultOsmandCategory.visible) {
12 | return DefaultOsmandCategory
13 | }
14 | return OsmandCategory(catName, colorTag, visible)
15 | }
16 |
17 | fun toDecsyncFavorite(id: String, catId: String?): DecsyncFavorite {
18 | return DecsyncFavorite(id, lat, lon, name, description, catId)
19 | }
20 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
--------------------------------------------------------------------------------
/app/src/main/java/org/decsync/osmand/model/DecsyncCategory.kt:
--------------------------------------------------------------------------------
1 | package org.decsync.osmand.model
2 |
3 | import androidx.room.Entity
4 | import androidx.room.Index
5 | import androidx.room.PrimaryKey
6 | import org.decsync.osmand.Utils
7 |
8 | sealed class DecsyncCategoryOrDefault {
9 | abstract val name: String
10 | abstract val colorTag: String
11 | abstract val visible: Boolean
12 | }
13 |
14 | @Entity(tableName = "categories",
15 | indices = [(Index(value = ["catId"], unique = true))])
16 | data class DecsyncCategory(
17 | @PrimaryKey val catId: String,
18 | override var name: String, override var colorTag: String, override var visible: Boolean
19 | ) : DecsyncCategoryOrDefault() {
20 | companion object {
21 | fun default(catId: String): DecsyncCategory = DecsyncCategory(catId, catId, "black", true)
22 | }
23 |
24 | @ExperimentalStdlibApi
25 | fun getMapsCategory(): Maps.Category {
26 | val colorString = Utils.colorStringForTag(colorTag)
27 | return Maps.Category(catId, name, colorString, visible)
28 | }
29 | }
30 |
31 | object DefaultDecsyncCategory : DecsyncCategoryOrDefault() {
32 | override val name = "Favorites"
33 | override val colorTag = "yellow"
34 | override val visible = true
35 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/root_preferences.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
6 |
8 |
9 |
10 |
11 |
12 |
17 |
18 |
19 |
20 |
24 |
25 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 | *.aab
5 |
6 | # Files for the ART/Dalvik VM
7 | *.dex
8 |
9 | # Java class files
10 | *.class
11 |
12 | # Generated files
13 | bin/
14 | gen/
15 | out/
16 | # Uncomment the following line in case you need and you don't have the release build type files in your app
17 | # release/
18 |
19 | # Gradle files
20 | .gradle/
21 | build/
22 |
23 | # Local configuration file (sdk path, etc)
24 | local.properties
25 |
26 | # Proguard folder generated by Eclipse
27 | proguard/
28 |
29 | # Log Files
30 | *.log
31 |
32 | # Android Studio Navigation editor temp files
33 | .navigation/
34 |
35 | # Android Studio captures folder
36 | captures/
37 |
38 | # IntelliJ
39 | *.iml
40 | .idea
41 |
42 | # Keystore files
43 | # Uncomment the following lines if you do not want to check your keystore files in.
44 | #*.jks
45 | #*.keystore
46 |
47 | # External native build folder generated in Android Studio 2.2 and later
48 | .externalNativeBuild
49 |
50 | # Google Services (e.g. APIs or Firebase)
51 | # google-services.json
52 |
53 | # Freeline
54 | freeline.py
55 | freeline/
56 | freeline_project_description.json
57 |
58 | # fastlane
59 | fastlane/report.xml
60 | fastlane/Preview.html
61 | fastlane/screenshots
62 | fastlane/test_output
63 | fastlane/readme.md
64 |
65 | # Version control
66 | vcs.xml
67 |
68 | # lint
69 | lint/intermediates/
70 | lint/generated/
71 | lint/outputs/
72 | lint/tmp/
73 | # lint/reports/
74 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/dialog_install_osm_and.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
20 |
21 |
27 |
28 |
29 |
30 |
36 |
37 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 | apply plugin: 'kotlin-kapt'
5 |
6 | android {
7 | compileSdkVersion 31
8 |
9 | defaultConfig {
10 | applicationId "org.decsync.osmand"
11 | minSdkVersion 21
12 | targetSdkVersion 31
13 | versionCode 2
14 | versionName "0.2"
15 | }
16 |
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | kapt {
26 | arguments {
27 | arg("room.schemaLocation", "$projectDir/schemas")
28 | }
29 | }
30 |
31 | dependencies {
32 | implementation fileTree(dir: "libs", include: ["*.jar"])
33 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
34 | implementation 'androidx.core:core-ktx:1.7.0'
35 | implementation 'androidx.appcompat:appcompat:1.4.0'
36 | implementation 'androidx.preference:preference-ktx:1.1.1'
37 | implementation 'androidx.room:room-runtime:2.4.0'
38 | implementation 'androidx.work:work-runtime:2.7.1'
39 | implementation 'com.google.android.material:material:1.4.0'
40 | kapt 'androidx.room:room-compiler:2.4.0'
41 | implementation "net.osmand:android-aidl-lib:master-snapshot@aar"
42 | implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.1"
43 | implementation "org.decsync:libdecsync:2.2.1"
44 | implementation "net.sf.kxml:kxml2:2.3.0"
45 | implementation 'com.github.AppIntro:AppIntro:6.1.0'
46 |
47 | testImplementation 'junit:junit:4.13.2'
48 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_intro_welcome.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
25 |
26 |
31 |
32 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_intro_directory.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
25 |
26 |
31 |
32 |
40 |
41 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_intro_install_osmand.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
25 |
26 |
31 |
32 |
40 |
41 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/app/src/main/java/org/decsync/osmand/external/Algorithms.java:
--------------------------------------------------------------------------------
1 | package org.decsync.osmand.external;
2 |
3 | // Stripped from net.osmand.util.Algorithms
4 | //
5 |
6 | /**
7 | * Basic algorithms that are not in jdk
8 | */
9 | public class Algorithms {
10 | public static boolean isEmpty(CharSequence s) {
11 | return s == null || s.length() == 0;
12 | }
13 |
14 | public static boolean objectEquals(Object a, Object b) {
15 | if (a == null) {
16 | return b == null;
17 | } else {
18 | return a.equals(b);
19 | }
20 | }
21 |
22 | /**
23 | * Parse the color string, and return the corresponding color-int.
24 | * If the string cannot be parsed, throws an IllegalArgumentException
25 | * exception. Supported formats are:
26 | * #RRGGBB
27 | * #AARRGGBB
28 | */
29 | public static int parseColor(String colorString) throws IllegalArgumentException {
30 | if (colorString.charAt(0) == '#') {
31 | // Use a long to avoid rollovers on #ffXXXXXX
32 | if (colorString.length() == 4) {
33 | colorString = "#" +
34 | colorString.charAt(1) + colorString.charAt(1) +
35 | colorString.charAt(2) + colorString.charAt(2) +
36 | colorString.charAt(3) + colorString.charAt(3);
37 | }
38 | long color = Long.parseLong(colorString.substring(1), 16);
39 | if (colorString.length() == 7) {
40 | // Set the alpha value
41 | color |= 0x00000000ff000000;
42 | } else if (colorString.length() != 9) {
43 | throw new IllegalArgumentException("Unknown color " + colorString); //$NON-NLS-1$
44 | }
45 | return (int) color;
46 | }
47 | throw new IllegalArgumentException("Unknown color " + colorString); //$NON-NLS-1$
48 | }
49 |
50 | public static String colorToString(int color) {
51 | if ((0xFF000000 & color) == 0xFF000000) {
52 | return "#" + format(6, Integer.toHexString(color & 0x00FFFFFF)); //$NON-NLS-1$
53 | } else {
54 | return "#" + format(8, Integer.toHexString(color)); //$NON-NLS-1$
55 | }
56 | }
57 |
58 | private static String format(int i, String hexString) {
59 | while (hexString.length() < i) {
60 | hexString = "0" + hexString;
61 | }
62 | return hexString;
63 | }
64 | }
--------------------------------------------------------------------------------
/app/src/main/java/org/decsync/osmand/model/DecsyncItem.kt:
--------------------------------------------------------------------------------
1 | package org.decsync.osmand.model
2 |
3 | import kotlinx.serialization.json.*
4 | import org.decsync.library.Decsync.StoredEntry
5 | import org.decsync.library.DecsyncItem
6 | import org.decsync.library.DecsyncItem.Value.Normal
7 | import org.decsync.library.DecsyncItem.Value.Reference
8 |
9 | @ExperimentalStdlibApi
10 | object Maps {
11 | class Favorite(
12 | favId: String,
13 | lat: Double,
14 | lon: Double,
15 | name: String,
16 | description: String?,
17 | internalCatId: Any?,
18 | category: () -> String?
19 | ) : DecsyncItem {
20 | override val type = "MapsFavorite"
21 | override val id = favId
22 | override val idStoredEntry = StoredEntry(listOf("favorites", favId), JsonNull)
23 |
24 | private val positionValue = buildJsonArray {
25 | add(lat)
26 | add(lon)
27 | }
28 | private val defaultPosition = buildJsonArray {
29 | add(0)
30 | add(0)
31 | }
32 | override val entries = mapOf(
33 | StoredEntry(listOf("favorites", favId), JsonPrimitive("position")) to
34 | Normal(positionValue, defaultPosition),
35 | StoredEntry(listOf("favorites", favId), JsonPrimitive("name")) to
36 | Normal(JsonPrimitive(name), JsonPrimitive(favId)),
37 | StoredEntry(listOf("favorites", favId), JsonPrimitive("description")) to
38 | Normal(JsonPrimitive(description), JsonNull),
39 | StoredEntry(listOf("favorites", favId), JsonPrimitive("category")) to
40 | Reference(internalCatId) { JsonPrimitive(category()) }
41 | )
42 | }
43 |
44 | class Category(
45 | catId: String,
46 | name: String,
47 | color: String,
48 | visible: Boolean
49 | ) : DecsyncItem {
50 | override val type = "MapsCategory"
51 | override val id = catId
52 | override val idStoredEntry: StoredEntry? = null
53 | override val entries = mapOf(
54 | StoredEntry(listOf("categories", catId), JsonPrimitive("name")) to
55 | Normal(JsonPrimitive(name), JsonPrimitive(catId)),
56 | StoredEntry(listOf("categories", catId), JsonPrimitive("color")) to
57 | Normal(JsonPrimitive(color), JsonPrimitive("#000000")),
58 | StoredEntry(listOf("categories", catId), JsonPrimitive("visible")) to
59 | Normal(JsonPrimitive(visible), JsonPrimitive(true))
60 | )
61 | }
62 | }
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/java/org/decsync/osmand/external/ColorDialogs.java:
--------------------------------------------------------------------------------
1 | package org.decsync.osmand.external;
2 |
3 | // Stripped from net.osmand.plus.util.ColorDialogs
4 | //
5 |
6 | import android.graphics.Color;
7 |
8 | public class ColorDialogs {
9 | public static int[] pallette = new int[] {
10 | 0xffeecc22,
11 | 0xffd00d0d,
12 | 0xffff5020,
13 | 0xffeeee10,
14 | 0xff88e030,
15 | 0xff00842b,
16 | 0xff10c0f0,
17 | 0xff1010a0,
18 | 0xffa71de1,
19 | 0xffe044bb,
20 | 0xff8e2512,
21 | 0xff000001
22 | };
23 |
24 | public static String[] paletteColorTags = new String[] {
25 | "darkyellow",
26 | "red",
27 | "orange",
28 | "yellow",
29 | "lightgreen",
30 | "green",
31 | "lightblue",
32 | "blue",
33 | "purple",
34 | "pink",
35 | "brown",
36 | "black"
37 | };
38 |
39 | private static double getDistanceBetweenColors(int color1, int color2) {
40 | double distance;
41 |
42 | double r1 = Color.red(color1);
43 | double g1 = Color.green(color1);
44 | double b1 = Color.blue(color1);
45 | double a1 = Color.alpha(color1);
46 |
47 | double r2 = Color.red(color2);
48 | double g2 = Color.green(color2);
49 | double b2 = Color.blue(color2);
50 | double a2 = Color.alpha(color2);
51 |
52 | distance = Math.sqrt(Math.pow(r1 - r2, 2) + Math.pow(g1 - g2, 2) + Math.pow(b1 - b2, 2));
53 |
54 | if (distance == 0) {
55 | distance = Math.sqrt(Math.pow(a1 - a2, 2));
56 | }
57 |
58 | return distance;
59 | }
60 |
61 | public static int getNearestColor(int source, int[] colors) {
62 | double distance = Double.MAX_VALUE;
63 |
64 | int index = 0;
65 | for (int i = 0; i < colors.length; i++) {
66 | double newDistance = getDistanceBetweenColors(source, colors[i]);
67 | if (newDistance < distance) {
68 | index = i;
69 | distance = newDistance;
70 | }
71 | }
72 |
73 | return colors[index];
74 | }
75 |
76 | public static int getColorByTag(String tag) {
77 | String t = tag.toLowerCase();
78 | for (int i = 0; i < paletteColorTags.length; i++) {
79 | String colorTag = paletteColorTags[i];
80 | if (colorTag.equals(t)) {
81 | return pallette[i];
82 | }
83 | }
84 | return 0;
85 | }
86 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
11 |
19 |
25 |
33 |
39 |
45 |
49 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/app/src/main/java/org/decsync/osmand/PrefUtils.kt:
--------------------------------------------------------------------------------
1 | package org.decsync.osmand
2 |
3 | import android.content.Context
4 | import android.net.Uri
5 | import androidx.appcompat.app.AppCompatDelegate
6 | import androidx.preference.PreferenceManager
7 |
8 | class PrefUtils {
9 | companion object {
10 | const val DECSYNC_ENABLED = "decsync.enabled"
11 | const val THEME = "theme"
12 | const val LAST_UPDATE = "last_update"
13 | const val INTRO_DONE = "intro.done"
14 | const val OSMAND_DATA_DIR = "osmand_data_dir"
15 |
16 | fun getDecsyncEnabled(context: Context): Boolean {
17 | val settings = PreferenceManager.getDefaultSharedPreferences(context)
18 | return settings.getBoolean(DECSYNC_ENABLED, false)
19 | }
20 |
21 | fun setDecsyncEnabled(context: Context, value: Boolean) {
22 | val editor = PreferenceManager.getDefaultSharedPreferences(context).edit()
23 | editor.putBoolean(DECSYNC_ENABLED, value)
24 | editor.apply()
25 | }
26 |
27 | fun notifyTheme(context: Context) {
28 | val settings = PreferenceManager.getDefaultSharedPreferences(context)
29 | val mode = Integer.parseInt(settings.getString(THEME, null) ?: "-1")
30 | AppCompatDelegate.setDefaultNightMode(mode)
31 | }
32 |
33 | fun getLastProcessedOsmandUpdate(context: Context): Long {
34 | val settings = PreferenceManager.getDefaultSharedPreferences(context)
35 | return settings.getLong(LAST_UPDATE, 0)
36 | }
37 |
38 | fun setLastProcessedOsmandUpdate(context: Context, time: Long) {
39 | val editor = PreferenceManager.getDefaultSharedPreferences(context).edit()
40 | editor.putLong(LAST_UPDATE, time)
41 | editor.apply()
42 | }
43 |
44 | fun getIntroDone(context: Context): Boolean {
45 | val settings = PreferenceManager.getDefaultSharedPreferences(context)
46 | return settings.getBoolean(INTRO_DONE, false)
47 | }
48 |
49 | fun setIntroDone(context: Context, value: Boolean) {
50 | val editor = PreferenceManager.getDefaultSharedPreferences(context).edit()
51 | editor.putBoolean(INTRO_DONE, value)
52 | editor.apply()
53 | }
54 |
55 | fun getOsmandFavoritesUri(context: Context): Uri? {
56 | val settings = PreferenceManager.getDefaultSharedPreferences(context)
57 | return settings.getString(OSMAND_DATA_DIR, null)?.let(Uri::parse)
58 | }
59 |
60 | fun setOsmandFavoritesUri(context: Context, value: Uri) {
61 | val editor = PreferenceManager.getDefaultSharedPreferences(context).edit()
62 | editor.putString(OSMAND_DATA_DIR, value.toString())
63 | editor.apply()
64 | }
65 |
66 | fun removeOsmandFavoritesUri(context: Context) {
67 | val editor = PreferenceManager.getDefaultSharedPreferences(context).edit()
68 | editor.remove(OSMAND_DATA_DIR)
69 | editor.apply()
70 | }
71 | }
72 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | OsmAnd DecSync
3 |
4 | Settings
5 | Introduction
6 |
7 |
8 | Synchronize now
9 | Synchronizing now
10 | About OsmAnd DecSync
11 | DecSync
12 | Enable DecSync
13 | Synchronize favorites between devices
14 | No DecSync directory configured
15 | Theme
16 | Theme
17 |
18 | - -1
19 | - 1
20 | - 2
21 |
22 |
23 | - System default
24 | - Light
25 | - Dark
26 |
27 |
28 | DecSync support disabled
29 | Errors
30 | No app store available
31 |
32 |
33 | Welcome to OsmAnd DecSync
34 | OsmAnd DecSync synchronizes your favorites in OsmAnd using DecSync
35 | Install OsmAnd
36 | OsmAnd needs to be installed
37 | Install OsmAnd
38 | Please install OsmAnd
39 | Configure OsmAnd
40 | The storage location of OsmAnd needs to be changed to be available to other apps
41 | Make OsmAnd use the shared storage by selecting Settings → OsmAnd settings → Data storage folder → Shared memory. Then choose the favourites.gpx file in the relevant folder.
42 | Choose OsmAnd\'s favourites.gpx file
43 | The selected file is not OsmAnd\'s favourites.gpx
44 | Please select the right file using the stated instructions
45 | DecSync Directory
46 | To start synchronizing, all you have to do is synchronize the DecSync directory
47 | Choose directory
48 | Please select a DecSync directory
49 |
50 | OsmAnd logo
51 | You need to install some version of OsmAnd, so you can test Intents API
52 | Install OsmAnd
53 |
--------------------------------------------------------------------------------
/app/src/main/java/org/decsync/osmand/Utils.kt:
--------------------------------------------------------------------------------
1 | package org.decsync.osmand
2 |
3 | import android.app.Activity
4 | import android.content.Context
5 | import android.content.Intent
6 | import android.content.pm.PackageManager
7 | import android.net.Uri
8 | import android.widget.Toast
9 | import androidx.documentfile.provider.DocumentFile
10 | import org.decsync.library.Diff
11 | import org.decsync.osmand.external.Algorithms
12 | import org.decsync.osmand.external.ColorDialogs
13 | import org.decsync.osmand.external.GPXUtilities
14 | import org.decsync.osmand.model.DefaultOsmandCategory
15 | import org.decsync.osmand.model.OsmandFavorite
16 |
17 | object Utils {
18 | fun Diff.Result.map(transform: (T) -> V): Diff.Result {
19 | return Diff.Result(
20 | insertions.map(transform),
21 | deletions.map(transform),
22 | changes.map { (x, y) -> Pair(transform(x), transform(y)) }
23 | )
24 | }
25 |
26 | fun getLastOsmandUpdate(context: Context): Long {
27 | val uri = PrefUtils.getOsmandFavoritesUri(context) ?: throw Exception("No favourites.gpx configured")
28 | return DocumentFile.fromSingleUri(context, uri)!!.lastModified()
29 | }
30 |
31 | fun getOsmandFavorites(context: Context): List {
32 | val uri = PrefUtils.getOsmandFavoritesUri(context) ?: throw Exception("No favourites.gpx configured")
33 | val res = context.contentResolver.openInputStream(uri)?.use { input ->
34 | GPXUtilities.loadGPXFile(input)
35 | } ?: throw Exception("Could not open input stream for OsmAnd's favourites.gpx")
36 | if (res.error != null) {
37 | throw Exception("Failed to load favorites file", res.error)
38 | }
39 | return res.points.map { wpt ->
40 | val catName = wpt.category ?: DefaultOsmandCategory.name
41 | val colorTag = nearestTagForColorInt(wpt.color)
42 | val visible = !wpt.extensionsToRead.containsKey("hidden")
43 | OsmandFavorite(wpt.lat, wpt.lon, wpt.name, wpt.desc, catName, colorTag, visible)
44 | }
45 | }
46 |
47 | fun nearestTagForColorString(colorString: String): String {
48 | val colorInt = Algorithms.parseColor(colorString)
49 | return nearestTagForColorInt(colorInt)
50 | }
51 |
52 | fun nearestTagForColorInt(colorInt: Int): String {
53 | val colorOsmandInt = ColorDialogs.getNearestColor(colorInt, ColorDialogs.pallette)
54 | val colorOsmandIndex = ColorDialogs.pallette.indexOf(colorOsmandInt)
55 | return ColorDialogs.paletteColorTags[colorOsmandIndex]
56 | }
57 |
58 | fun colorStringForTag(colorTag: String): String {
59 | val colorInt = ColorDialogs.getColorByTag(colorTag)
60 | return Algorithms.colorToString(colorInt)
61 | }
62 |
63 | fun appInstalled(activity: Activity, packageName: String): Boolean {
64 | return try {
65 | activity.packageManager.getPackageInfo(packageName, 0)
66 | true
67 | } catch (e: PackageManager.NameNotFoundException) {
68 | false
69 | }
70 | }
71 |
72 | fun installApp(activity: Activity, packageName: String) {
73 | val intent = Intent(Intent.ACTION_VIEW)
74 | intent.data = Uri.parse("market://details?id=$packageName")
75 | if (intent.resolveActivity(activity.packageManager) == null) {
76 | Toast.makeText(activity, R.string.no_app_store, Toast.LENGTH_SHORT).show()
77 | return
78 | }
79 | activity.startActivity(intent)
80 | }
81 | }
--------------------------------------------------------------------------------
/app/src/main/java/org/decsync/osmand/SettingsActivity.kt:
--------------------------------------------------------------------------------
1 | package org.decsync.osmand
2 |
3 | import android.content.Intent
4 | import android.os.Bundle
5 | import android.view.Menu
6 | import android.view.MenuItem
7 | import android.widget.Toast
8 | import androidx.appcompat.app.AppCompatActivity
9 | import androidx.appcompat.app.AppCompatDelegate
10 | import androidx.preference.ListPreference
11 | import androidx.preference.Preference
12 | import androidx.preference.PreferenceFragmentCompat
13 | import androidx.work.OneTimeWorkRequest
14 | import androidx.work.WorkManager
15 | import com.google.android.material.snackbar.Snackbar
16 |
17 | @ExperimentalStdlibApi
18 | class SettingsActivity : AppCompatActivity() {
19 | private var syncNowMenuItem: MenuItem? = null
20 |
21 | override fun onCreate(savedInstanceState: Bundle?) {
22 | PrefUtils.notifyTheme(this)
23 | super.onCreate(savedInstanceState)
24 |
25 | if (!PrefUtils.getIntroDone(this)) {
26 | val intent = Intent(this, IntroActivity::class.java)
27 | startActivity(intent)
28 | finish()
29 | return
30 | }
31 |
32 | setContentView(R.layout.settings_activity)
33 | supportFragmentManager
34 | .beginTransaction()
35 | .replace(R.id.settings, SettingsFragment())
36 | .commit()
37 | }
38 |
39 | override fun onCreateOptionsMenu(menu: Menu): Boolean {
40 | menuInflater.inflate(R.menu.settings_activity, menu)
41 | syncNowMenuItem = menu.findItem(R.id.sync_now)
42 | syncNowMenuItem?.isEnabled = PrefUtils.getDecsyncEnabled(this)
43 | return true
44 | }
45 |
46 | override fun onOptionsItemSelected(item: MenuItem): Boolean {
47 | when (item.itemId) {
48 | R.id.sync_now -> {
49 | if (PrefUtils.getDecsyncEnabled(this)) {
50 | val workManager = WorkManager.getInstance(this)
51 | val workRequest = OneTimeWorkRequest.Builder(DecsyncWorker::class.java).build()
52 | workManager.enqueue(workRequest)
53 | Snackbar.make(findViewById(R.id.settings), R.string.settings_synchronizing_now, Snackbar.LENGTH_LONG).show()
54 | } else {
55 | Toast.makeText(this, R.string.decsync_disabled, Toast.LENGTH_LONG).show()
56 | }
57 | }
58 | else -> return super.onOptionsItemSelected(item)
59 | }
60 | return true
61 | }
62 |
63 | class SettingsFragment : PreferenceFragmentCompat() {
64 | override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
65 | setPreferencesFromResource(R.xml.root_preferences, rootKey)
66 |
67 | findPreference(PrefUtils.DECSYNC_ENABLED)?.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
68 | if (newValue == true) {
69 | val intent = Intent(requireActivity(), IntroActivity::class.java)
70 | startActivity(intent)
71 | requireActivity().finish()
72 | false
73 | } else {
74 | (requireActivity() as SettingsActivity).syncNowMenuItem?.isEnabled = false
75 | val workManager = WorkManager.getInstance(requireContext())
76 | workManager.cancelAllWork()
77 | true
78 | }
79 | }
80 |
81 | findPreference(PrefUtils.THEME)?.summaryProvider = ListPreference.SimpleSummaryProvider.getInstance()
82 | findPreference(PrefUtils.THEME)?.setOnPreferenceChangeListener { _, newValue ->
83 | val mode = Integer.parseInt(newValue as String)
84 | AppCompatDelegate.setDefaultNightMode(mode)
85 | true
86 | }
87 | }
88 | }
89 | }
--------------------------------------------------------------------------------
/app/schemas/org.decsync.osmand.model.AppDatabase/1.json:
--------------------------------------------------------------------------------
1 | {
2 | "formatVersion": 1,
3 | "database": {
4 | "version": 1,
5 | "identityHash": "a84a30652aab7421e97df7fdfd87ae40",
6 | "entities": [
7 | {
8 | "tableName": "favorites",
9 | "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`favId` TEXT NOT NULL, `lat` REAL NOT NULL, `lon` REAL NOT NULL, `name` TEXT NOT NULL, `description` TEXT, `catId` TEXT, PRIMARY KEY(`favId`))",
10 | "fields": [
11 | {
12 | "fieldPath": "favId",
13 | "columnName": "favId",
14 | "affinity": "TEXT",
15 | "notNull": true
16 | },
17 | {
18 | "fieldPath": "lat",
19 | "columnName": "lat",
20 | "affinity": "REAL",
21 | "notNull": true
22 | },
23 | {
24 | "fieldPath": "lon",
25 | "columnName": "lon",
26 | "affinity": "REAL",
27 | "notNull": true
28 | },
29 | {
30 | "fieldPath": "name",
31 | "columnName": "name",
32 | "affinity": "TEXT",
33 | "notNull": true
34 | },
35 | {
36 | "fieldPath": "description",
37 | "columnName": "description",
38 | "affinity": "TEXT",
39 | "notNull": false
40 | },
41 | {
42 | "fieldPath": "catId",
43 | "columnName": "catId",
44 | "affinity": "TEXT",
45 | "notNull": false
46 | }
47 | ],
48 | "primaryKey": {
49 | "columnNames": [
50 | "favId"
51 | ],
52 | "autoGenerate": false
53 | },
54 | "indices": [
55 | {
56 | "name": "index_favorites_favId",
57 | "unique": true,
58 | "columnNames": [
59 | "favId"
60 | ],
61 | "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_favorites_favId` ON `${TABLE_NAME}` (`favId`)"
62 | }
63 | ],
64 | "foreignKeys": []
65 | },
66 | {
67 | "tableName": "categories",
68 | "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`catId` TEXT NOT NULL, `name` TEXT NOT NULL, `colorTag` TEXT NOT NULL, `visible` INTEGER NOT NULL, PRIMARY KEY(`catId`))",
69 | "fields": [
70 | {
71 | "fieldPath": "catId",
72 | "columnName": "catId",
73 | "affinity": "TEXT",
74 | "notNull": true
75 | },
76 | {
77 | "fieldPath": "name",
78 | "columnName": "name",
79 | "affinity": "TEXT",
80 | "notNull": true
81 | },
82 | {
83 | "fieldPath": "colorTag",
84 | "columnName": "colorTag",
85 | "affinity": "TEXT",
86 | "notNull": true
87 | },
88 | {
89 | "fieldPath": "visible",
90 | "columnName": "visible",
91 | "affinity": "INTEGER",
92 | "notNull": true
93 | }
94 | ],
95 | "primaryKey": {
96 | "columnNames": [
97 | "catId"
98 | ],
99 | "autoGenerate": false
100 | },
101 | "indices": [
102 | {
103 | "name": "index_categories_catId",
104 | "unique": true,
105 | "columnNames": [
106 | "catId"
107 | ],
108 | "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_categories_catId` ON `${TABLE_NAME}` (`catId`)"
109 | }
110 | ],
111 | "foreignKeys": []
112 | }
113 | ],
114 | "views": [],
115 | "setupQueries": [
116 | "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
117 | "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'a84a30652aab7421e97df7fdfd87ae40')"
118 | ]
119 | }
120 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_intro_configure_osmand.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
26 |
27 |
36 |
37 |
44 |
49 |
54 |
59 |
64 |
69 |
74 |
75 |
76 |
77 |
86 |
87 |
95 |
96 |
97 |
98 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/java/org/decsync/osmand/DecsyncListeners.kt:
--------------------------------------------------------------------------------
1 | package org.decsync.osmand
2 |
3 | import android.util.Log
4 | import kotlinx.serialization.json.*
5 | import org.decsync.library.Decsync
6 | import org.decsync.osmand.model.DecsyncCategory
7 | import org.decsync.osmand.model.DecsyncFavorite
8 | import org.decsync.osmand.model.DefaultDecsyncCategory
9 |
10 | private const val TAG = "DecsyncListeners"
11 |
12 | @ExperimentalStdlibApi
13 | object DecsyncListeners {
14 | fun favoriteListener(path: List, entries: List, extra: Extra): Boolean {
15 | Log.d(TAG, "Execute favorite entries in $path: $entries")
16 | val favId = path[0]
17 | val prevFavorite = extra.db.favoriteDao().findById(favId)
18 | val newFavorite = prevFavorite?.copy() ?: DecsyncFavorite.default(favId)
19 | val added = updateFavorite(newFavorite, entries)
20 |
21 | var categoryAdded: DecsyncCategory? = null
22 | val getNewCategory = {
23 | newFavorite.catId?.let { catId ->
24 | extra.db.categoryDao().findById(catId) ?: run {
25 | DecsyncCategory.default(catId).also { category ->
26 | extra.db.categoryDao().insert(category)
27 | categoryAdded = category
28 | }
29 | }
30 | } ?: DefaultDecsyncCategory
31 | }
32 |
33 | var success = true
34 | if (prevFavorite == null) {
35 | if (added == true) {
36 | val newCategory = getNewCategory()
37 | success = extra.aidlHelper?.addFavorite(
38 | newFavorite.lat, newFavorite.lon, newFavorite.name, newFavorite.description, "",
39 | newCategory.name, newCategory.colorTag, newCategory.visible
40 | ) ?: true
41 | if (success) {
42 | extra.db.favoriteDao().insert(newFavorite)
43 | extra.observer.applyDiff(
44 | insertions = listOf(newFavorite.getMapsFavorite()),
45 | isFromDecsyncListener = true
46 | )
47 | } else {
48 | Log.w(TAG, "Could not add favorite $newFavorite in OsmAnd")
49 | }
50 | } else {
51 | Log.i(TAG, "Unknown favorite $favId")
52 | }
53 | } else {
54 | val prevCategory = prevFavorite.catId?.let { catId ->
55 | extra.db.categoryDao().findById(catId) ?: DecsyncCategory.default(catId)
56 | } ?: DefaultDecsyncCategory
57 | if (added == false) {
58 | success = extra.aidlHelper?.removeFavorite(
59 | prevFavorite.lat, prevFavorite.lon, prevFavorite.name, prevCategory.name
60 | ) ?: true
61 | if (success) {
62 | extra.db.favoriteDao().delete(prevFavorite)
63 | } else {
64 | Log.w(TAG, "Could not remove favorite $prevFavorite in OsmAnd")
65 | }
66 | } else {
67 | if (newFavorite != prevFavorite) {
68 | val newCategory = getNewCategory()
69 | success = extra.aidlHelper?.updateFavorite(
70 | prevFavorite.lat, prevFavorite.lon, prevFavorite.name, prevCategory.name,
71 | newFavorite.lat, newFavorite.lon, newFavorite.name, newFavorite.description,
72 | newCategory.name, newCategory.colorTag, newCategory.visible
73 | ) ?: true
74 | if (success) {
75 | extra.db.favoriteDao().update(newFavorite)
76 | } else {
77 | Log.w(TAG, "Could not update favorite $newFavorite in OsmAnd")
78 | }
79 | }
80 | }
81 | }
82 |
83 | if (success) {
84 | // Execute properties of new category
85 | categoryAdded?.let { category ->
86 | extra.db.categoryDao().insert(category)
87 | extra.observer.applyDiff(
88 | insertions = listOf(category.getMapsCategory()),
89 | isFromDecsyncListener = true
90 | )
91 | }
92 | }
93 |
94 | return success
95 | }
96 |
97 | private fun updateFavorite(favorite: DecsyncFavorite, entries: List): Boolean? {
98 | var added: Boolean? = null
99 | for (entry in entries) {
100 | when (val key = entry.key.jsonPrimitive.contentOrNull) {
101 | null -> added = entry.value.jsonPrimitive.boolean
102 | "position" -> {
103 | val position = entry.value.jsonArray
104 | favorite.lat = position[0].jsonPrimitive.double
105 | favorite.lon = position[1].jsonPrimitive.double
106 | }
107 | "name" -> favorite.name = entry.value.jsonPrimitive.content
108 | "description" -> favorite.description = entry.value.jsonPrimitive.contentOrNull
109 | "category" -> favorite.catId = entry.value.jsonPrimitive.contentOrNull
110 | else -> Log.w(TAG, "Unknown key for category: $key")
111 | }
112 | }
113 | return added
114 | }
115 |
116 | fun categoryListener(path: List, entries: List, extra: Extra): Boolean {
117 | Log.d(TAG, "Execute category entries in $path: $entries")
118 | val catId = path[0]
119 | val prevCategory = extra.db.categoryDao().findById(catId) ?: run {
120 | Log.i(TAG, "Unknown category")
121 | return true
122 | }
123 | val newCategory = prevCategory.copy()
124 | updateCategory(newCategory, entries)
125 |
126 | var success = true
127 | if (newCategory != prevCategory) {
128 | success = extra.aidlHelper?.updateFavoriteGroup(
129 | prevCategory.name, prevCategory.colorTag, prevCategory.visible,
130 | newCategory.name, newCategory.colorTag, newCategory.visible
131 | ) ?: true
132 | if (success) {
133 | extra.db.categoryDao().update(newCategory)
134 | } else {
135 | Log.w(TAG, "Could not update category $newCategory in OsmAnd")
136 | }
137 | }
138 |
139 | return success
140 | }
141 |
142 | private fun updateCategory(category: DecsyncCategory, entries: List) {
143 | for (entry in entries) {
144 | when (val key = entry.key.jsonPrimitive.content) {
145 | "name" -> category.name = entry.value.jsonPrimitive.content
146 | "color" -> {
147 | val colorString = entry.value.jsonPrimitive.content
148 | category.colorTag = Utils.nearestTagForColorString(colorString)
149 | }
150 | "visible" -> category.visible = entry.value.jsonPrimitive.boolean
151 | else -> Log.w(TAG, "Unknown key for category: $key")
152 | }
153 | }
154 | }
155 | }
--------------------------------------------------------------------------------
/app/src/main/java/org/decsync/osmand/DiffUtil.kt:
--------------------------------------------------------------------------------
1 | package org.decsync.osmand
2 |
3 | import org.decsync.library.Diff
4 | import org.decsync.osmand.model.*
5 | import java.util.*
6 |
7 | fun getDiffResults(
8 | decsyncFavorites: List,
9 | decsyncCategories: List,
10 | osmandFavorites: List
11 | ): Pair, Diff.Result> {
12 | val (osmandCategories, favoritePairing, categoryPairing) = pairDecsyncOsmand(decsyncFavorites, decsyncCategories, osmandFavorites)
13 |
14 | val categoryInsertions = mutableListOf()
15 | val categoryDeletions = decsyncCategories.toMutableList()
16 | val categoryChanges = mutableListOf>()
17 | for (osmandCategory in osmandCategories) {
18 | val decsyncCategory = categoryPairing[osmandCategory.name]
19 | if (decsyncCategory == null) {
20 | // Insertion
21 | val newId = UUID.randomUUID().toString()
22 | val newDecsyncCategory = osmandCategory.toDecsyncCategory(newId)
23 | categoryPairing[osmandCategory.name] = newDecsyncCategory
24 | categoryInsertions += newDecsyncCategory
25 | } else {
26 | // Change
27 | categoryDeletions.remove(decsyncCategory)
28 | val newDecsyncCategory = osmandCategory.toDecsyncCategory(decsyncCategory.catId)
29 | if (decsyncCategory != newDecsyncCategory) {
30 | categoryChanges += decsyncCategory to newDecsyncCategory
31 | }
32 | }
33 | }
34 | val categoryResult = Diff.Result(categoryInsertions, categoryDeletions, categoryChanges)
35 |
36 | val favoriteInsertions = mutableListOf()
37 | val favoriteDeletions = decsyncFavorites.toMutableList()
38 | val favoriteChanges = mutableListOf>()
39 | for (osmandFavorite in osmandFavorites) {
40 | val decsyncFavorite = favoritePairing[osmandFavorite.name]
41 | val osmandCategory = osmandFavorite.getCategory()
42 | val catId = if (osmandCategory is DefaultOsmandCategory) {
43 | null
44 | } else {
45 | categoryPairing[osmandFavorite.catName]!!.catId
46 | }
47 | if (decsyncFavorite == null) {
48 | // Insertion
49 | val newId = UUID.randomUUID().toString()
50 | val newDecsyncFavorite = osmandFavorite.toDecsyncFavorite(newId, catId)
51 | favoriteInsertions += newDecsyncFavorite
52 | } else {
53 | // Change
54 | favoriteDeletions.remove(decsyncFavorite)
55 | val newDecsyncFavorite = osmandFavorite.toDecsyncFavorite(decsyncFavorite.favId, catId)
56 | if (decsyncFavorite != newDecsyncFavorite) {
57 | favoriteChanges += decsyncFavorite to newDecsyncFavorite
58 | }
59 | }
60 | }
61 | val favoriteResult = Diff.Result(favoriteInsertions, favoriteDeletions, favoriteChanges)
62 | return Pair(favoriteResult, categoryResult)
63 | }
64 |
65 | private data class PairingResult(
66 | val osmandCategories: List,
67 | val favoritePairing: MutableMap,
68 | val categoryPairing: MutableMap
69 | )
70 |
71 | private fun pairDecsyncOsmand(
72 | decsyncFavorites: List,
73 | decsyncCategories: List,
74 | osmandFavorites: List
75 | ): PairingResult {
76 | val osmandCategories = osmandFavorites.map { it.getCategory() }.filterIsInstance().distinctBy { it.name }
77 |
78 | // We pair favorites based on two criteria:
79 | // 1. Their location
80 | // 2. Their name
81 | // First we pair them when (1) and (2) are equal, then when just (1) is equal and finally when just (2) is equal
82 | val sameLocation = { osmandFavorite: OsmandFavorite, decsyncFavorite: DecsyncFavorite ->
83 | osmandFavorite.lat == decsyncFavorite.lat &&
84 | osmandFavorite.lon == decsyncFavorite.lon
85 | }
86 | val sameFavoriteName = { osmandFavorite: OsmandFavorite, decsyncFavorite: DecsyncFavorite ->
87 | osmandFavorite.name == decsyncFavorite.name
88 | }
89 | val favoritePairing = pairTwoPreds(osmandFavorites, decsyncFavorites, { it.name }, sameLocation, sameFavoriteName)
90 |
91 | // We also pair categories based on two criteria:
92 | // 1. Their name
93 | // 2. Their color and their children (over half of them remain the same)
94 | // The order is the same as for favorites: first (1) and (2), then just (1) and finally just (2)
95 | val sameCategoryName = { osmandCategory: OsmandCategory, decsyncCategory: DecsyncCategory ->
96 | osmandCategory.name == decsyncCategory.name
97 | }
98 | val decsyncChildrenCount = mutableMapOf()
99 | val bothChildrenCount = mutableMapOf, Int>()
100 | for (osmandFavorite in osmandFavorites) {
101 | val osmandCatName = osmandFavorite.catName
102 | val decsyncCatId = favoritePairing[osmandFavorite.name]?.catId ?: continue
103 | val key = Pair(osmandCatName, decsyncCatId)
104 | decsyncChildrenCount[decsyncCatId] = (decsyncChildrenCount[decsyncCatId] ?: 0) + 1
105 | bothChildrenCount[key] = (bothChildrenCount[key] ?: 0) + 1
106 | }
107 | val sameColorAndMostlySameChildren = { osmandCategory: OsmandCategory, decsyncCategory: DecsyncCategory ->
108 | val decsyncCount = decsyncChildrenCount[decsyncCategory.catId] ?: 0
109 | val bothCount = bothChildrenCount[Pair(osmandCategory.name, decsyncCategory.catId)] ?: 0
110 | osmandCategory.colorTag == decsyncCategory.colorTag && 2*bothCount > decsyncCount
111 | }
112 | val categoryPairing = pairTwoPreds(osmandCategories, decsyncCategories, { it.name }, sameCategoryName, sameColorAndMostlySameChildren)
113 |
114 | return PairingResult(osmandCategories, favoritePairing, categoryPairing)
115 | }
116 |
117 | private fun pairTwoPreds(
118 | list1: List,
119 | list2: List,
120 | getKey: (T1) -> V1,
121 | predicate1: (T1, T2) -> Boolean,
122 | predicate2: (T1, T2) -> Boolean,
123 | ): MutableMap {
124 | val pairing = mutableMapOf()
125 | val list1 = list1.toMutableList()
126 | val list2 = list2.toMutableList()
127 | pair(list1, list2, pairing, getKey) { oldItem, newItem ->
128 | predicate1(oldItem, newItem) && predicate2(oldItem, newItem)
129 | }
130 | pair(list1, list2, pairing, getKey) { oldItem, newItem ->
131 | predicate1(oldItem, newItem)
132 | }
133 | pair(list1, list2, pairing, getKey) { oldItem, newItem ->
134 | predicate2(oldItem, newItem)
135 | }
136 | return pairing
137 | }
138 |
139 | private fun pair(
140 | list1: MutableList,
141 | list2: MutableList,
142 | pairing: MutableMap,
143 | getKey: (T1) -> V1,
144 | predicate: (T1, T2) -> Boolean
145 | ) {
146 | val iterator1 = list1.iterator()
147 | while (iterator1.hasNext()) {
148 | val item1 = iterator1.next()
149 | val iterator2 = list2.iterator()
150 | while (iterator2.hasNext()) {
151 | val item2 = iterator2.next()
152 | if (predicate(item1, item2)) {
153 | iterator1.remove()
154 | iterator2.remove()
155 | pairing[getKey(item1)] = item2
156 | break
157 | }
158 | }
159 | }
160 | }
--------------------------------------------------------------------------------
/app/src/main/java/org/decsync/osmand/DecsyncUtils.kt:
--------------------------------------------------------------------------------
1 | package org.decsync.osmand
2 |
3 | import android.app.NotificationChannel
4 | import android.app.NotificationManager
5 | import android.app.PendingIntent
6 | import android.content.Context
7 | import android.content.Intent
8 | import android.graphics.BitmapFactory
9 | import android.net.Uri
10 | import android.os.Build
11 | import android.util.Log
12 | import androidx.core.app.NotificationCompat
13 | import androidx.work.Worker
14 | import androidx.work.WorkerParameters
15 | import org.decsync.library.*
16 | import org.decsync.osmand.Utils.map
17 | import org.decsync.osmand.external.OsmAndAidlHelper
18 | import org.decsync.osmand.model.AppDatabase
19 |
20 | private const val TAG = "DecsyncUtils"
21 | private val ownAppId = getAppId("OsmAnd")
22 | private const val ERROR_NOTIFICATION_ID = 1
23 |
24 | @ExperimentalStdlibApi
25 | data class Extra(
26 | val db: AppDatabase,
27 | val aidlHelper: OsmAndAidlHelper?,
28 | val observer: MyDecsyncObserver
29 | )
30 |
31 | object OsmandMissingException : Exception()
32 |
33 | @ExperimentalStdlibApi
34 | class MyDecsyncObserver(
35 | private val decsync: Decsync,
36 | db: AppDatabase,
37 | aidlHelper: OsmAndAidlHelper?
38 | ) : DecsyncObserver() {
39 | private val extra = Extra(db, aidlHelper, this)
40 | override fun isDecsyncEnabled(): Boolean = true // Observer only used for applyDiff
41 |
42 | override fun setEntries(entries: List) {
43 | decsync.setEntries(entries)
44 | }
45 |
46 | override fun executeStoredEntries(storedEntries: List) {
47 | decsync.executeStoredEntries(storedEntries, extra)
48 | }
49 |
50 | fun initStoredEntries() {
51 | decsync.initStoredEntries()
52 | }
53 |
54 | fun executeAllStoredEntries() {
55 | decsync.executeStoredEntriesForPathPrefix(emptyList(), extra)
56 | }
57 |
58 | fun executeAllNewEntries() {
59 | decsync.executeAllNewEntries(extra)
60 | }
61 | }
62 |
63 | @ExperimentalStdlibApi
64 | class DecsyncWorker(private val context: Context, params: WorkerParameters) : Worker(context, params) {
65 | override fun doWork(): Result {
66 | if (!PrefUtils.getDecsyncEnabled(context)) return Result.success()
67 | val isInitSync = inputData.getBoolean(KEY_IS_INIT_SYNC, false)
68 | Log.d(TAG, "Sync started")
69 | try {
70 | val decsyncDir = DecsyncPrefUtils.getDecsyncDir(context) ?: throw Exception(context.getString(R.string.settings_decsync_dir_not_configured))
71 | val decsync = Decsync(context, decsyncDir, "maps", null, ownAppId).apply {
72 | addMultiListenerWithSuccess(listOf("favorites"), DecsyncListeners::favoriteListener)
73 | addMultiListenerWithSuccess(listOf("categories"), DecsyncListeners::categoryListener)
74 | }
75 | val db = AppDatabase.createDatabase(context)
76 | val aidlHelper = OsmAndAidlHelper(context) {
77 | throw OsmandMissingException
78 | }
79 | // TODO: check whether the plugin is enabled
80 | val myDecsyncObserver = MyDecsyncObserver(decsync, db, aidlHelper)
81 |
82 | if (isInitSync) {
83 | Log.d(TAG, "Executing init sync")
84 |
85 | // Delete all OsmAnd data, so we start fresh
86 | db.favoriteDao().deleteAll()
87 | db.categoryDao().deleteAll()
88 |
89 | // Populate the database with the DecSync data, so we can get the right mapping
90 | // between the ids, otherwise all OsmAnd data would be considered insertions.
91 | MyDecsyncObserver(decsync, db, null /* Only sync the database */).apply {
92 | initStoredEntries()
93 | executeAllStoredEntries()
94 | }
95 |
96 | // Update the database to reflect the OsmAnd state, but only write insertions to DecSync
97 | writeOsmandUpdates(db, myDecsyncObserver, true)
98 |
99 | // Execute all the DecSync updates
100 | myDecsyncObserver.executeAllStoredEntries()
101 |
102 | } else {
103 | try {
104 | // Write the OsmAnd updates
105 | writeOsmandUpdates(db, myDecsyncObserver)
106 |
107 | // Execute the DecSync updates
108 | myDecsyncObserver.executeAllNewEntries()
109 | } catch (e: Exception) {
110 | Log.w(TAG, e)
111 | return Result.failure()
112 | }
113 | }
114 | return Result.success()
115 | } catch (e: OsmandMissingException) {
116 | val intent = Intent()
117 | intent.data = Uri.parse("market://details?id=net.osmand.plus")
118 | showException(Exception(context.getString(R.string.install_osmand_dialog_message)), intent)
119 | return Result.failure()
120 | } catch (e: Exception) {
121 | showException(e, Intent(context, SettingsActivity::class.java))
122 | return Result.failure()
123 | }
124 | }
125 |
126 | private fun writeOsmandUpdates(db: AppDatabase, myDecsyncObserver: MyDecsyncObserver, isInitSync: Boolean = false) {
127 | val lastOsmandProcessedUpdate = PrefUtils.getLastProcessedOsmandUpdate(context)
128 | val lastOsmandUpdate = Utils.getLastOsmandUpdate(context)
129 | if (!isInitSync && lastOsmandProcessedUpdate >= lastOsmandUpdate) return
130 | val osmandFavorites = Utils.getOsmandFavorites(context)
131 |
132 | val decsyncFavorites = db.favoriteDao().all
133 | val decsyncCategories = db.categoryDao().all
134 | val (favoriteResult, categoryResult) = getDiffResults(
135 | decsyncFavorites,
136 | decsyncCategories,
137 | osmandFavorites
138 | )
139 | Log.d(TAG, "Updating favorite db")
140 | db.favoriteDao().insert(*favoriteResult.insertions.toTypedArray())
141 | db.favoriteDao().delete(*favoriteResult.deletions.toTypedArray())
142 | db.favoriteDao().update(*favoriteResult.changes.map { it.second }.toTypedArray())
143 | val mapsFavoriteResult = favoriteResult.map { it.getMapsFavorite() }
144 | if (isInitSync) {
145 | Log.d(TAG, "Processing favorite insertions: ${favoriteResult.insertions}")
146 | myDecsyncObserver.applyDiff(insertions = mapsFavoriteResult.insertions)
147 | } else {
148 | Log.d(TAG, "Processing favoriteResult: $favoriteResult")
149 | myDecsyncObserver.applyDiff(mapsFavoriteResult)
150 | }
151 | Log.d(TAG, "Updating category db")
152 | db.categoryDao().insert(*categoryResult.insertions.toTypedArray())
153 | db.categoryDao().delete(*categoryResult.deletions.toTypedArray())
154 | db.categoryDao().update(*categoryResult.changes.map { it.second }.toTypedArray())
155 | val mapsCategoryResult = categoryResult.map { it.getMapsCategory() }
156 | if (isInitSync) {
157 | Log.d(TAG, "Processing category insertions: ${categoryResult.insertions}")
158 | myDecsyncObserver.applyDiff(insertions = mapsCategoryResult.insertions)
159 | } else {
160 | Log.d(TAG, "Processing categoryResult: $categoryResult")
161 | myDecsyncObserver.applyDiff(mapsCategoryResult)
162 | }
163 |
164 | PrefUtils.setLastProcessedOsmandUpdate(context, lastOsmandUpdate)
165 | }
166 |
167 | private fun showException(e: Exception, intent: Intent) {
168 | Log.e(TAG, "", e)
169 | PrefUtils.setDecsyncEnabled(context, false)
170 |
171 | val channelId = "channel_error"
172 | val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
173 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
174 | val channel = NotificationChannel(
175 | channelId,
176 | context.getString(R.string.channel_error_name),
177 | NotificationManager.IMPORTANCE_DEFAULT
178 | )
179 | notificationManager.createNotificationChannel(channel)
180 | }
181 | val notification = NotificationCompat.Builder(context, channelId)
182 | .setSmallIcon(R.drawable.ic_launcher_foreground)
183 | .setLargeIcon(
184 | BitmapFactory.decodeResource(
185 | context.resources,
186 | R.mipmap.ic_launcher
187 | )
188 | )
189 | .setContentTitle(context.getString(R.string.decsync_disabled))
190 | .setContentText(e.localizedMessage)
191 | .setContentIntent(PendingIntent.getActivity(context, 0, intent, 0))
192 | .build()
193 | notificationManager.notify(ERROR_NOTIFICATION_ID, notification)
194 | }
195 |
196 | companion object {
197 | const val KEY_IS_INIT_SYNC = "KEY_IS_INIT_SYNC"
198 | }
199 | }
--------------------------------------------------------------------------------
/app/src/main/java/org/decsync/osmand/IntroActivity.kt:
--------------------------------------------------------------------------------
1 | package org.decsync.osmand
2 |
3 | import android.app.Activity
4 | import android.content.Intent
5 | import android.net.Uri
6 | import android.os.Build
7 | import android.os.Bundle
8 | import android.provider.DocumentsContract
9 | import android.view.LayoutInflater
10 | import android.view.View
11 | import android.view.ViewGroup
12 | import android.widget.Button
13 | import android.widget.Toast
14 | import androidx.core.content.ContextCompat
15 | import androidx.fragment.app.Fragment
16 | import androidx.work.Data
17 | import androidx.work.OneTimeWorkRequest
18 | import androidx.work.PeriodicWorkRequest
19 | import androidx.work.WorkManager
20 | import com.github.appintro.AppIntro2
21 | import com.github.appintro.SlidePolicy
22 | import kotlinx.android.synthetic.main.activity_intro_configure_osmand.*
23 | import kotlinx.android.synthetic.main.activity_intro_directory.*
24 | import org.decsync.library.DecsyncPrefUtils
25 | import org.decsync.library.InsufficientAccessException
26 | import org.decsync.library.checkUriPermissions
27 | import java.util.concurrent.TimeUnit
28 |
29 | @ExperimentalStdlibApi
30 | class IntroActivity : AppIntro2() {
31 | override fun onCreate(savedInstanceState: Bundle?) {
32 | super.onCreate(savedInstanceState)
33 |
34 | isWizardMode = true
35 | showStatusBar(true)
36 | setBarColor(ContextCompat.getColor(this, R.color.bg_intro_bottom_bar))
37 |
38 | val osmandFavoritesUri = PrefUtils.getOsmandFavoritesUri(this)
39 | if (osmandFavoritesUri != null) {
40 | try {
41 | checkUriPermissions(this, osmandFavoritesUri)
42 | } catch (e: InsufficientAccessException) {
43 | PrefUtils.removeOsmandFavoritesUri(this)
44 | }
45 | }
46 | val decsyncDir = DecsyncPrefUtils.getDecsyncDir(this)
47 | if (decsyncDir != null) {
48 | try {
49 | checkUriPermissions(this, decsyncDir)
50 | } catch (e: InsufficientAccessException) {
51 | DecsyncPrefUtils.removeDecsyncDir(this)
52 | }
53 | }
54 |
55 | if (!PrefUtils.getIntroDone(this)) {
56 | addSlide(SlideWelcome())
57 | }
58 | if (!SlideInstallOsmand.isPolicyRespected(this)) {
59 | addSlide(SlideInstallOsmand())
60 | }
61 | addSlide(SlideConfigureOsmand())
62 | addSlide(SlideDirectory())
63 | }
64 |
65 | override fun onIntroFinished() {
66 | super.onIntroFinished()
67 |
68 | PrefUtils.setIntroDone(this, true)
69 | PrefUtils.setDecsyncEnabled(this, true)
70 |
71 | val workManager = WorkManager.getInstance(this)
72 | val inputData = Data.Builder()
73 | .putBoolean(DecsyncWorker.KEY_IS_INIT_SYNC, true)
74 | .build()
75 | val workRequest = OneTimeWorkRequest.Builder(DecsyncWorker::class.java)
76 | .setInputData(inputData)
77 | .build()
78 | workManager.enqueue(workRequest)
79 |
80 | val periodicWorkRequest = PeriodicWorkRequest.Builder(DecsyncWorker::class.java, 1, TimeUnit.HOURS)
81 | .setInitialDelay(1, TimeUnit.HOURS)
82 | .build()
83 | workManager.enqueue(periodicWorkRequest)
84 |
85 | val intent = Intent(this, SettingsActivity::class.java)
86 | startActivity(intent)
87 | finish()
88 | }
89 | }
90 |
91 | class SlideWelcome : Fragment() {
92 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
93 | return inflater.inflate(R.layout.activity_intro_welcome, container, false)
94 | }
95 | }
96 |
97 | class SlideInstallOsmand : Fragment(), SlidePolicy {
98 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
99 | val view = inflater.inflate(R.layout.activity_intro_install_osmand, container, false)
100 |
101 | val installOsmandButton = view.findViewById