diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 87af099..5c4abe1 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,6 @@ [versions] agp = "8.12.2" -kotlin = "2.1.21" +kotlin = "2.2.10" coreKtx = "1.16.0" junit = "4.13.2" junitVersion = "1.3.0" @@ -14,7 +14,7 @@ runner = "1.5.2" core = "1.5.0" ktor = "3.2.3" kotlinxSerialization = "1.7.3" -ksp = "2.1.21-2.0.1" +ksp = "2.2.10-2.0.2" diff --git a/ios/Klottr/Klottr.xcodeproj/project.pbxproj b/ios/Klottr/Klottr.xcodeproj/project.pbxproj new file mode 100644 index 0000000..be2db13 --- /dev/null +++ b/ios/Klottr/Klottr.xcodeproj/project.pbxproj @@ -0,0 +1,563 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 77; + objects = { + +/* Begin PBXContainerItemProxy section */ + 412CF4592E7037D800EADB15 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 412CF4402E7037D600EADB15 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 412CF4472E7037D700EADB15; + remoteInfo = Klottr; + }; + 412CF4632E7037D800EADB15 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 412CF4402E7037D600EADB15 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 412CF4472E7037D700EADB15; + remoteInfo = Klottr; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + 412CF4482E7037D700EADB15 /* Klottr.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Klottr.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 412CF4582E7037D800EADB15 /* KlottrTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = KlottrTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 412CF4622E7037D800EADB15 /* KlottrUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = KlottrUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFileSystemSynchronizedRootGroup section */ + 412CF44A2E7037D700EADB15 /* Klottr */ = { + isa = PBXFileSystemSynchronizedRootGroup; + path = Klottr; + sourceTree = ""; + }; + 412CF45B2E7037D800EADB15 /* KlottrTests */ = { + isa = PBXFileSystemSynchronizedRootGroup; + path = KlottrTests; + sourceTree = ""; + }; + 412CF4652E7037D800EADB15 /* KlottrUITests */ = { + isa = PBXFileSystemSynchronizedRootGroup; + path = KlottrUITests; + sourceTree = ""; + }; +/* End PBXFileSystemSynchronizedRootGroup section */ + +/* Begin PBXFrameworksBuildPhase section */ + 412CF4452E7037D700EADB15 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 412CF4552E7037D800EADB15 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 412CF45F2E7037D800EADB15 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 412CF43F2E7037D600EADB15 = { + isa = PBXGroup; + children = ( + 412CF44A2E7037D700EADB15 /* Klottr */, + 412CF45B2E7037D800EADB15 /* KlottrTests */, + 412CF4652E7037D800EADB15 /* KlottrUITests */, + 412CF4492E7037D700EADB15 /* Products */, + ); + sourceTree = ""; + }; + 412CF4492E7037D700EADB15 /* Products */ = { + isa = PBXGroup; + children = ( + 412CF4482E7037D700EADB15 /* Klottr.app */, + 412CF4582E7037D800EADB15 /* KlottrTests.xctest */, + 412CF4622E7037D800EADB15 /* KlottrUITests.xctest */, + ); + name = Products; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 412CF4472E7037D700EADB15 /* Klottr */ = { + isa = PBXNativeTarget; + buildConfigurationList = 412CF46C2E7037D800EADB15 /* Build configuration list for PBXNativeTarget "Klottr" */; + buildPhases = ( + 412CF4442E7037D700EADB15 /* Sources */, + 412CF4452E7037D700EADB15 /* Frameworks */, + 412CF4462E7037D700EADB15 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + fileSystemSynchronizedGroups = ( + 412CF44A2E7037D700EADB15 /* Klottr */, + ); + name = Klottr; + packageProductDependencies = ( + ); + productName = Klottr; + productReference = 412CF4482E7037D700EADB15 /* Klottr.app */; + productType = "com.apple.product-type.application"; + }; + 412CF4572E7037D800EADB15 /* KlottrTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 412CF46F2E7037D800EADB15 /* Build configuration list for PBXNativeTarget "KlottrTests" */; + buildPhases = ( + 412CF4542E7037D800EADB15 /* Sources */, + 412CF4552E7037D800EADB15 /* Frameworks */, + 412CF4562E7037D800EADB15 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 412CF45A2E7037D800EADB15 /* PBXTargetDependency */, + ); + fileSystemSynchronizedGroups = ( + 412CF45B2E7037D800EADB15 /* KlottrTests */, + ); + name = KlottrTests; + packageProductDependencies = ( + ); + productName = KlottrTests; + productReference = 412CF4582E7037D800EADB15 /* KlottrTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; + 412CF4612E7037D800EADB15 /* KlottrUITests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 412CF4722E7037D800EADB15 /* Build configuration list for PBXNativeTarget "KlottrUITests" */; + buildPhases = ( + 412CF45E2E7037D800EADB15 /* Sources */, + 412CF45F2E7037D800EADB15 /* Frameworks */, + 412CF4602E7037D800EADB15 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 412CF4642E7037D800EADB15 /* PBXTargetDependency */, + ); + fileSystemSynchronizedGroups = ( + 412CF4652E7037D800EADB15 /* KlottrUITests */, + ); + name = KlottrUITests; + packageProductDependencies = ( + ); + productName = KlottrUITests; + productReference = 412CF4622E7037D800EADB15 /* KlottrUITests.xctest */; + productType = "com.apple.product-type.bundle.ui-testing"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 412CF4402E7037D600EADB15 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1610; + LastUpgradeCheck = 1610; + TargetAttributes = { + 412CF4472E7037D700EADB15 = { + CreatedOnToolsVersion = 16.1; + }; + 412CF4572E7037D800EADB15 = { + CreatedOnToolsVersion = 16.1; + TestTargetID = 412CF4472E7037D700EADB15; + }; + 412CF4612E7037D800EADB15 = { + CreatedOnToolsVersion = 16.1; + TestTargetID = 412CF4472E7037D700EADB15; + }; + }; + }; + buildConfigurationList = 412CF4432E7037D600EADB15 /* Build configuration list for PBXProject "Klottr" */; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 412CF43F2E7037D600EADB15; + minimizedProjectReferenceProxies = 1; + preferredProjectObjectVersion = 77; + productRefGroup = 412CF4492E7037D700EADB15 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 412CF4472E7037D700EADB15 /* Klottr */, + 412CF4572E7037D800EADB15 /* KlottrTests */, + 412CF4612E7037D800EADB15 /* KlottrUITests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 412CF4462E7037D700EADB15 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 412CF4562E7037D800EADB15 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 412CF4602E7037D800EADB15 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 412CF4442E7037D700EADB15 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 412CF4542E7037D800EADB15 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 412CF45E2E7037D800EADB15 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 412CF45A2E7037D800EADB15 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 412CF4472E7037D700EADB15 /* Klottr */; + targetProxy = 412CF4592E7037D800EADB15 /* PBXContainerItemProxy */; + }; + 412CF4642E7037D800EADB15 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 412CF4472E7037D700EADB15 /* Klottr */; + targetProxy = 412CF4632E7037D800EADB15 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin XCBuildConfiguration section */ + 412CF46A2E7037D800EADB15 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 18.1; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 412CF46B2E7037D800EADB15 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 18.1; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 412CF46D2E7037D800EADB15 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"Klottr/Preview Content\""; + DEVELOPMENT_TEAM = 9LY47TPGT7; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchScreen_Generation = YES; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = se.ointressant.Klottr; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 412CF46E2E7037D800EADB15 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"Klottr/Preview Content\""; + DEVELOPMENT_TEAM = 9LY47TPGT7; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchScreen_Generation = YES; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = se.ointressant.Klottr; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; + 412CF4702E7037D800EADB15 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = 9LY47TPGT7; + GENERATE_INFOPLIST_FILE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 18.1; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = se.ointressant.KlottrTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Klottr.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Klottr"; + }; + name = Debug; + }; + 412CF4712E7037D800EADB15 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = 9LY47TPGT7; + GENERATE_INFOPLIST_FILE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 18.1; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = se.ointressant.KlottrTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Klottr.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Klottr"; + }; + name = Release; + }; + 412CF4732E7037D800EADB15 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = 9LY47TPGT7; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = se.ointressant.KlottrUITests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_TARGET_NAME = Klottr; + }; + name = Debug; + }; + 412CF4742E7037D800EADB15 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = 9LY47TPGT7; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = se.ointressant.KlottrUITests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_TARGET_NAME = Klottr; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 412CF4432E7037D600EADB15 /* Build configuration list for PBXProject "Klottr" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 412CF46A2E7037D800EADB15 /* Debug */, + 412CF46B2E7037D800EADB15 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 412CF46C2E7037D800EADB15 /* Build configuration list for PBXNativeTarget "Klottr" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 412CF46D2E7037D800EADB15 /* Debug */, + 412CF46E2E7037D800EADB15 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 412CF46F2E7037D800EADB15 /* Build configuration list for PBXNativeTarget "KlottrTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 412CF4702E7037D800EADB15 /* Debug */, + 412CF4712E7037D800EADB15 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 412CF4722E7037D800EADB15 /* Build configuration list for PBXNativeTarget "KlottrUITests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 412CF4732E7037D800EADB15 /* Debug */, + 412CF4742E7037D800EADB15 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 412CF4402E7037D600EADB15 /* Project object */; +} diff --git a/ios/Klottr/Klottr.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/ios/Klottr/Klottr.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/ios/Klottr/Klottr.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/ios/Klottr/Klottr.xcodeproj/project.xcworkspace/xcuserdata/olle.xcuserdatad/UserInterfaceState.xcuserstate b/ios/Klottr/Klottr.xcodeproj/project.xcworkspace/xcuserdata/olle.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..f3a7525 Binary files /dev/null and b/ios/Klottr/Klottr.xcodeproj/project.xcworkspace/xcuserdata/olle.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/ios/Klottr/Klottr.xcodeproj/xcuserdata/olle.xcuserdatad/xcschemes/xcschememanagement.plist b/ios/Klottr/Klottr.xcodeproj/xcuserdata/olle.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..9f6a586 --- /dev/null +++ b/ios/Klottr/Klottr.xcodeproj/xcuserdata/olle.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + Klottr.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/ios/Klottr/Klottr/Assets.xcassets/AccentColor.colorset/Contents.json b/ios/Klottr/Klottr/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 0000000..eb87897 --- /dev/null +++ b/ios/Klottr/Klottr/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/ios/Klottr/Klottr/Assets.xcassets/AppIcon.appiconset/Contents.json b/ios/Klottr/Klottr/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..2305880 --- /dev/null +++ b/ios/Klottr/Klottr/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,35 @@ +{ + "images" : [ + { + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "tinted" + } + ], + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/ios/Klottr/Klottr/Assets.xcassets/Contents.json b/ios/Klottr/Klottr/Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/ios/Klottr/Klottr/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/ios/Klottr/Klottr/ContentView.swift b/ios/Klottr/Klottr/ContentView.swift new file mode 100644 index 0000000..c29691d --- /dev/null +++ b/ios/Klottr/Klottr/ContentView.swift @@ -0,0 +1,24 @@ +// +// ContentView.swift +// Klottr +// +// Created by Olof Hedman on 2025-09-09. +// + +import SwiftUI + +struct ContentView: View { + var body: some View { + VStack { + Image(systemName: "globe") + .imageScale(.large) + .foregroundStyle(.tint) + Text("Hello, world!") + } + .padding() + } +} + +#Preview { + ContentView() +} diff --git a/ios/Klottr/Klottr/KlottrApp.swift b/ios/Klottr/Klottr/KlottrApp.swift new file mode 100644 index 0000000..be665cb --- /dev/null +++ b/ios/Klottr/Klottr/KlottrApp.swift @@ -0,0 +1,17 @@ +// +// KlottrApp.swift +// Klottr +// +// Created by Olof Hedman on 2025-09-09. +// + +import SwiftUI + +@main +struct KlottrApp: App { + var body: some Scene { + WindowGroup { + ContentView() + } + } +} diff --git a/ios/Klottr/Klottr/Preview Content/Preview Assets.xcassets/Contents.json b/ios/Klottr/Klottr/Preview Content/Preview Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/ios/Klottr/Klottr/Preview Content/Preview Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/ios/Klottr/KlottrTests/KlottrTests.swift b/ios/Klottr/KlottrTests/KlottrTests.swift new file mode 100644 index 0000000..45c33f0 --- /dev/null +++ b/ios/Klottr/KlottrTests/KlottrTests.swift @@ -0,0 +1,17 @@ +// +// KlottrTests.swift +// KlottrTests +// +// Created by Olof Hedman on 2025-09-09. +// + +import Testing +@testable import Klottr + +struct KlottrTests { + + @Test func example() async throws { + // Write your test here and use APIs like `#expect(...)` to check expected conditions. + } + +} diff --git a/ios/Klottr/KlottrUITests/KlottrUITests.swift b/ios/Klottr/KlottrUITests/KlottrUITests.swift new file mode 100644 index 0000000..8d66a8a --- /dev/null +++ b/ios/Klottr/KlottrUITests/KlottrUITests.swift @@ -0,0 +1,43 @@ +// +// KlottrUITests.swift +// KlottrUITests +// +// Created by Olof Hedman on 2025-09-09. +// + +import XCTest + +final class KlottrUITests: XCTestCase { + + override func setUpWithError() throws { + // Put setup code here. This method is called before the invocation of each test method in the class. + + // In UI tests it is usually best to stop immediately when a failure occurs. + continueAfterFailure = false + + // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. + } + + override func tearDownWithError() throws { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + @MainActor + func testExample() throws { + // UI tests must launch the application that they test. + let app = XCUIApplication() + app.launch() + + // Use XCTAssert and related functions to verify your tests produce the correct results. + } + + @MainActor + func testLaunchPerformance() throws { + if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) { + // This measures how long it takes to launch your application. + measure(metrics: [XCTApplicationLaunchMetric()]) { + XCUIApplication().launch() + } + } + } +} diff --git a/ios/Klottr/KlottrUITests/KlottrUITestsLaunchTests.swift b/ios/Klottr/KlottrUITests/KlottrUITestsLaunchTests.swift new file mode 100644 index 0000000..8c388c4 --- /dev/null +++ b/ios/Klottr/KlottrUITests/KlottrUITestsLaunchTests.swift @@ -0,0 +1,33 @@ +// +// KlottrUITestsLaunchTests.swift +// KlottrUITests +// +// Created by Olof Hedman on 2025-09-09. +// + +import XCTest + +final class KlottrUITestsLaunchTests: XCTestCase { + + override class var runsForEachTargetApplicationUIConfiguration: Bool { + true + } + + override func setUpWithError() throws { + continueAfterFailure = false + } + + @MainActor + func testLaunch() throws { + let app = XCUIApplication() + app.launch() + + // Insert steps here to perform after app launch but before taking a screenshot, + // such as logging into a test account or navigating somewhere in the app + + let attachment = XCTAttachment(screenshot: app.screenshot()) + attachment.name = "Launch Screen" + attachment.lifetime = .keepAlways + add(attachment) + } +} diff --git a/shared/src/androidMain/kotlin/app/klottr/util/FoundStore.kt b/shared/src/androidMain/kotlin/app/klottr/util/FoundStore.kt deleted file mode 100644 index da44075..0000000 --- a/shared/src/androidMain/kotlin/app/klottr/util/FoundStore.kt +++ /dev/null @@ -1,206 +0,0 @@ -package app.klottr.util - -import android.content.Context -import app.klottr.prefs.KvPrefs -import org.json.JSONObject - -actual object FoundStore { - private const val KEY_KEYS = "keys" // StringSet med "layer|id" - private const val MIGRATED_FLAG = "__found_migrated_v1" // migration från legacy prefs - private const val LEGACY_PREF = "klottr_found_store" - private const val AWAY_THRESHOLD_METERS = 200 - - actual val LAYER_KLOTTER: String = "klotter" - actual val LAYER_WIKI: String = "wiki" - actual val LAYER_DM: String = "dm" - - private fun key(layer: String, id: String) = "$layer|$id" - - /** Migrera gamla FoundStore-poster från separat SharedPreferences till KvPrefs (engångs). */ - private fun ensureMigrated(ctx: Any?) { - if (KvPrefs.getBoolean(MIGRATED_FLAG, false)) return - val context = ctx as? Context ?: return - val legacy = context.getSharedPreferences(LEGACY_PREF, Context.MODE_PRIVATE) - val legacyKeys = legacy.getStringSet(KEY_KEYS, emptySet()) ?: emptySet() - if (legacyKeys.isEmpty()) { - KvPrefs.putBoolean(MIGRATED_FLAG, true) - return - } - // slå ihop med ev. befintligt i KvPrefs - val cur = KvPrefs.getStringSet(KEY_KEYS).toMutableSet() - cur.addAll(legacyKeys) - KvPrefs.putStringSet(KEY_KEYS, cur) - // flytta varje post - for (k in legacyKeys) { - legacy.getString(k, null)?.let { KvPrefs.putString(k, it) } - } - KvPrefs.putBoolean(MIGRATED_FLAG, true) - // OBS: vi tömmer inte legacy prefs här – ofarligt att låta dem vara kvar. - } - - actual fun isFound(ctx: Any?, layer: String, id: String): Boolean { - ensureMigrated(ctx) - val k = key(layer, id) - val set = KvPrefs.getStringSet(KEY_KEYS) - return k in set - } - - actual fun markFound( - ctx: Any?, - layer: String, - id: String, - label: String, - lat: Double, - lon: Double, - timeMillis: Long - ): Boolean { - ensureMigrated(ctx) - val k = key(layer, id) - val set = KvPrefs.getStringSet(KEY_KEYS).toMutableSet() - - val existingJson = KvPrefs.getString(k, null) - val existed = existingJson != null - val prev = try { if (existingJson != null) JSONObject(existingJson) else null } catch (_: Throwable) { null } - - val wasAway = prev?.optBoolean("away", false) ?: false - - val firstVisit = prev?.optLong("first_visit", -1L)?.takeIf { it > 0 } - ?: (prev?.optLong("time", timeMillis) ?: timeMillis) - val lastVisit = timeMillis - - val oldLabel = (prev?.optString("label", "") ?: "").trim() - val incoming = label.trim() - val betterIncoming = incoming.isNotBlank() && !incoming.equals("Okänt klotter", ignoreCase = true) - val newLabel = when { - betterIncoming -> incoming - oldLabel.isNotBlank() -> oldLabel - else -> incoming - } - - val obj = (prev ?: JSONObject()).apply { - put("layer", layer) - put("id", id) - put("label", newLabel) - put("lat", lat) - put("lon", lon) - put("time", lastVisit) // legacy-fält - put("first_visit", firstVisit) - put("last_visit", lastVisit) - put("away", false) // vi är "inne" igen - } - - KvPrefs.putString(k, obj.toString()) - if (!set.contains(k)) { - set.add(k) - KvPrefs.putStringSet(KEY_KEYS, set) - } - // Ny träff om första gång(en) eller om vi varit "away" tidigare - return !existed || wasAway - } - - actual fun isAway(ctx: Any?, layer: String, id: String): Boolean { - ensureMigrated(ctx) - val k = key(layer, id) - val js = KvPrefs.getString(k, null) ?: return false - return try { JSONObject(js).optBoolean("away", false) } catch (_: Throwable) { false } - } - - actual fun getFirstVisitMillis(ctx: Any?, layer: String, id: String): Long? { - ensureMigrated(ctx) - val js = KvPrefs.getString(key(layer, id), null) ?: return null - return try { - val obj = JSONObject(js) - when { - obj.has("first_visit") -> obj.optLong("first_visit") - obj.has("time") -> obj.optLong("time") - else -> null - } - } catch (_: Throwable) { null } - } - - actual fun getLastVisitMillis(ctx: Any?, layer: String, id: String): Long? { - ensureMigrated(ctx) - val js = KvPrefs.getString(key(layer, id), null) ?: return null - return try { - val obj = JSONObject(js) - when { - obj.has("last_visit") -> obj.optLong("last_visit") - obj.has("time") -> obj.optLong("time") - else -> null - } - } catch (_: Throwable) { null } - } - - actual fun updateAwayFlags(ctx: Any?, currentLat: Double, currentLon: Double, thresholdMeters: Int) { - ensureMigrated(ctx) - val keys = KvPrefs.getStringSet(KEY_KEYS) - if (keys.isEmpty()) return - - var touched = false - for (k in keys) { - val js = KvPrefs.getString(k, null) ?: continue - val obj = try { JSONObject(js) } catch (_: Throwable) { continue } - - val lat = obj.optDouble("lat", Double.NaN) - val lon = obj.optDouble("lon", Double.NaN) - if (lat.isNaN() || lon.isNaN()) continue - - val dist = distanceMeters(currentLat, currentLon, lat, lon) - val isAway = obj.optBoolean("away", false) - - if (dist > thresholdMeters && !isAway) { - obj.put("away", true) - KvPrefs.putString(k, obj.toString()) - touched = true - } - } - // inget behov av extra skrivning för KEY_KEYS här - // touched används ej, men kvar om vi i framtiden vill signalera ändring - @Suppress("UNUSED_VARIABLE") - touched - } - - actual fun remove(ctx: Any?, layer: String, id: String) { - ensureMigrated(ctx) - val k = key(layer, id) - val set = KvPrefs.getStringSet(KEY_KEYS).toMutableSet() - if (!set.remove(k)) return - KvPrefs.putStringSet(KEY_KEYS, set) - KvPrefs.remove(k) - } - - actual fun getAll(ctx: Any?): List { - ensureMigrated(ctx) - val set = KvPrefs.getStringSet(KEY_KEYS) - if (set.isEmpty()) return emptyList() - val list = ArrayList(set.size) - for (k in set) { - val s = KvPrefs.getString(k, null) ?: continue - try { - val o = JSONObject(s) - list += FoundEntry( - layer = o.optString("layer"), - id = o.optString("id"), - label = o.optString("label"), - lat = o.optDouble("lat"), - lon = o.optDouble("lon"), - timeMillis = o.optLong("time") - ) - } catch (_: Throwable) { - // Ignorera trasiga poster - } - } - return list.sortedByDescending { it.timeMillis } - } - - actual fun clearAll(ctx: Any?) { - ensureMigrated(ctx) - // Rensa endast FoundStore’s nycklar – inte hela KvPrefs - val set = KvPrefs.getStringSet(KEY_KEYS) - if (set.isEmpty()) return - for (k in set) { - KvPrefs.remove(k) - } - KvPrefs.putStringSet(KEY_KEYS, emptySet()) - } -} diff --git a/shared/src/commonMain/kotlin/app/klottr/util/FoundStore.kt b/shared/src/commonMain/kotlin/app/klottr/util/FoundStore.kt index 54d70e5..272f8ff 100644 --- a/shared/src/commonMain/kotlin/app/klottr/util/FoundStore.kt +++ b/shared/src/commonMain/kotlin/app/klottr/util/FoundStore.kt @@ -1,17 +1,55 @@ package app.klottr.util -expect object FoundStore { - // Lager (samma som tidigare) - val LAYER_KLOTTER: String - val LAYER_WIKI: String - val LAYER_DM: String +import app.klottr.prefs.KvPrefs +import kotlinx.serialization.Serializable +import kotlinx.serialization.json.Json +import kotlin.math.* - fun isFound(ctx: Any?, layer: String, id: String): Boolean +@Serializable +private data class FoundRecord( + val layer: String, + val id: String, + val label: String, + val lat: Double, + val lon: Double, + val first_visit: Long, + val last_visit: Long, + val away: Boolean +) +object FoundStore { + private const val KEY_KEYS = "keys" // Set of "layer|id" + // keep your layer constants + val LAYER_KLOTTER: String = "klotter" + val LAYER_WIKI: String = "wiki" + val LAYER_DM: String = "dm" + + private val json = Json { ignoreUnknownKeys = true } + private fun key(layer: String, id: String) = "$layer|$id" + + // ---- queries ---- /** * Markera som funnet. Sparar första fyndtiden; uppdaterar inte om det redan finns. * @return true om nytt fynd sparades, annars false (även true om ”re-armed” efter away). */ + fun isFound(ctx: Any?, layer: String, id: String): Boolean = + key(layer, id) in KvPrefs.getStringSet(KEY_KEYS) + + fun isAway(ctx: Any?, layer: String, id: String): Boolean = + KvPrefs.getString(key(layer, id), null) + ?.let { runCatching { json.decodeFromString(FoundRecord.serializer(), it) }.getOrNull()?.away } + ?: false + + fun getFirstVisitMillis(ctx: Any?, layer: String, id: String): Long? = + KvPrefs.getString(key(layer, id), null) + ?.let { runCatching { json.decodeFromString(FoundRecord.serializer(), it) }.getOrNull()?.first_visit } + + fun getLastVisitMillis(ctx: Any?, layer: String, id: String): Long? = + KvPrefs.getString(key(layer, id), null) + ?.let { runCatching { json.decodeFromString(FoundRecord.serializer(), it) }.getOrNull()?.last_visit } + + // ---- mutations ---- + /** Returns true if it was new or previously marked away. */ fun markFound( ctx: Any?, layer: String, @@ -20,27 +58,74 @@ expect object FoundStore { lat: Double, lon: Double, timeMillis: Long - ): Boolean + ): Boolean { + val k = key(layer, id) + val prev = KvPrefs.getString(k, null) + ?.let { runCatching { json.decodeFromString(FoundRecord.serializer(), it) }.getOrNull() } - fun isAway(ctx: Any?, layer: String, id: String): Boolean - fun getFirstVisitMillis(ctx: Any?, layer: String, id: String): Long? - fun getLastVisitMillis(ctx: Any?, layer: String, id: String): Long? + val wasAway = prev?.away ?: false + val firstVisit = prev?.first_visit?.takeIf { it > 0 } ?: (prev?.last_visit ?: timeMillis) + val newLabel = if (label.isNotBlank()) label else (prev?.label ?: "") + + val rec = FoundRecord( + layer = layer, id = id, label = newLabel, + lat = lat, lon = lon, + first_visit = firstVisit, + last_visit = timeMillis, + away = false + ) + KvPrefs.putString(k, json.encodeToString(FoundRecord.serializer(), rec)) + + val set = KvPrefs.getStringSet(KEY_KEYS).toMutableSet() + if (set.add(k)) KvPrefs.putStringSet(KEY_KEYS, set) + + return prev == null || wasAway + } /** * Sätt away=true för alla sparade fynd där nuvarande position är > tröskeln. */ - fun updateAwayFlags( - ctx: Any?, - currentLat: Double, - currentLon: Double, - thresholdMeters: Int = 200 - ) + fun updateAwayFlags(ctx: Any?, currentLat: Double, currentLon: Double, thresholdMeters: Int = 200) { + val keys = KvPrefs.getStringSet(KEY_KEYS) + if (keys.isEmpty()) return + for (k in keys) { + val rec = KvPrefs.getString(k, null) + ?.let { runCatching { json.decodeFromString(FoundRecord.serializer(), it) }.getOrNull() } + ?: continue + if (!rec.away && distanceMeters(currentLat, currentLon, rec.lat, rec.lon) > thresholdMeters) { + KvPrefs.putString(k, json.encodeToString(FoundRecord.serializer(), rec.copy(away = true))) + } + } + } - fun remove(ctx: Any?, layer: String, id: String) + fun remove(ctx: Any?, layer: String, id: String) { + val k = key(layer, id) + val set = KvPrefs.getStringSet(KEY_KEYS).toMutableSet() + if (set.remove(k)) KvPrefs.putStringSet(KEY_KEYS, set) + KvPrefs.remove(k) + } /** Hämtar alla fynd (senaste först). */ - fun getAll(ctx: Any?): List + fun getAll(ctx: Any?): List { + val set = KvPrefs.getStringSet(KEY_KEYS) + if (set.isEmpty()) return emptyList() + return buildList(set.size) { + for (k in set) { + val rec = KvPrefs.getString(k, null) + ?.let { runCatching { json.decodeFromString(FoundRecord.serializer(), it) }.getOrNull() } + ?: continue + // Adjust ctor if your FoundEntry differs + add(FoundEntry(rec.layer, rec.id, rec.label, rec.lat, rec.lon, rec.last_visit)) + } + }.sortedByDescending { it.timeMillis } + } /** Rensar alla fynd (endast FoundStore’s nycklar, inte övriga inställningar). */ - fun clearAll(ctx: Any?) -} \ No newline at end of file + fun clearAll(ctx: Any?) { + val set = KvPrefs.getStringSet(KEY_KEYS) + if (set.isEmpty()) return + for (k in set) KvPrefs.remove(k) + KvPrefs.putStringSet(KEY_KEYS, emptySet()) + } + +} diff --git a/shared/src/commonMain/kotlin/app/klottr/util/Geo.kt b/shared/src/commonMain/kotlin/app/klottr/util/SharedGeo.kt similarity index 100% rename from shared/src/commonMain/kotlin/app/klottr/util/Geo.kt rename to shared/src/commonMain/kotlin/app/klottr/util/SharedGeo.kt diff --git a/shared/src/iosMain/kotlin/app/klottr/prefs/KvPrefs.kt b/shared/src/iosMain/kotlin/app/klottr/prefs/KvPrefs.kt new file mode 100644 index 0000000..3c16019 --- /dev/null +++ b/shared/src/iosMain/kotlin/app/klottr/prefs/KvPrefs.kt @@ -0,0 +1,77 @@ +package app.klottr.prefs + +import platform.Foundation.NSBundle +import platform.Foundation.NSUserDefaults + +actual object KvPrefs { + private val d: NSUserDefaults by lazy { NSUserDefaults.standardUserDefaults() } + private val listeners = mutableSetOf<(String?) -> Unit>() + + actual fun init(platformArg: Any?) { + // iOS needs no arg; kept for parity with Android. + } + + actual fun getString(key: String, def: String?): String? = + d.stringForKey(key) ?: def + + actual fun putString(key: String, value: String?) { + if (value == null) d.removeObjectForKey(key) + else d.setObject(value, forKey = key) + notifyChanged(key) + } + + actual fun getInt(key: String, def: Int): Int = + if (d.objectForKey(key) == null) def else d.integerForKey(key).toInt() + + actual fun putInt(key: String, value: Int) { + d.setInteger(value.toLong(), forKey = key) + notifyChanged(key) + } + + actual fun getBoolean(key: String, def: Boolean): Boolean = + if (d.objectForKey(key) == null) def else d.boolForKey(key) + + actual fun putBoolean(key: String, value: Boolean) { + d.setBool(value, forKey = key) + notifyChanged(key) + } + + actual fun getStringSet(key: String): Set { + // Stored as NSArray in defaults + val arr = d.arrayForKey(key) as? List<*> + return arr?.mapNotNull { it as? String }?.toSet() ?: emptySet() + } + + actual fun putStringSet(key: String, value: Set) { + d.setObject(value.toList(), forKey = key) + notifyChanged(key) + } + + actual fun remove(key: String) { + d.removeObjectForKey(key) + notifyChanged(key) + } + + actual fun clearAll() { + // Clear this app's domain + val domain = NSBundle.mainBundle.bundleIdentifier + if (domain != null) { + d.removePersistentDomainForName(domain) + notifyChanged(null) + } + } + + actual fun addListener(listener: (key: String?) -> Unit) { + listeners.add(listener) + } + + actual fun removeListener(listener: (key: String?) -> Unit) { + listeners.remove(listener) + } + + private fun notifyChanged(key: String?) { + // Snapshot to avoid concurrent modification if listeners add/remove inside callback + val snapshot = listeners.toList() + snapshot.forEach { it.invoke(key) } + } +}