Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ae8e1ddb82 | ||
|
|
9381065cf2 | ||
|
|
98b4ee71ae | ||
|
|
1b84c6fc15 | ||
|
|
ad9fb99205 | ||
|
|
4fdbf10054 | ||
|
|
3505c379cf | ||
|
|
6322022f47 | ||
|
|
adf60f289b | ||
|
|
27ccac205b | ||
|
|
664a7d4cea |
@@ -49,7 +49,7 @@ node {
|
||||
if (env.BRANCH_NAME == "master" && release) {
|
||||
echo "Deploying to production server ..."
|
||||
withCredentials([sshUserPrivateKey(credentialsId: "mowesta-server-key", keyFileVariable: "KEYFILE")]) {
|
||||
sh 'scp -i $KEYFILE site-ear/build/libs/site-ear-' + version + '.ear wildfly@apps-pro.nes.uni-due.de:/opt/wildfly-21-mowesta/standalone/deployments/mowesta.ear'
|
||||
// sh 'scp -i $KEYFILE site-ear/build/libs/site-ear-' + version + '.ear wildfly@apps-pro.nes.uni-due.de:/opt/wildfly-21-mowesta/standalone/deployments/mowesta.ear'
|
||||
sh 'scp -i $KEYFILE android-app/build/outputs/apk/prod/release/*.apk wildfly@apps-pro.nes.uni-due.de:/opt/android/mowesta/'
|
||||
sh 'scp -i $KEYFILE android-app/build/outputs/bundle/prodRelease/*.aab wildfly@apps-pro.nes.uni-due.de:/opt/android/mowesta/'
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ android {
|
||||
applicationId "com.mowesta.android.app"
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 30
|
||||
versionCode 26
|
||||
versionCode 27
|
||||
versionName "${versionApp}"
|
||||
buildConfigField "long", "BUILD_TIME", System.currentTimeMillis() + "L"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
@@ -55,11 +55,6 @@ public class CityGradientFragment extends CityFragment.ChildFragment {
|
||||
*/
|
||||
private TimeUtils timeUtils = new TimeUtils(System.currentTimeMillis(), null);
|
||||
|
||||
/**
|
||||
* The view pager of the parent.
|
||||
*/
|
||||
private ViewPager2 pager;
|
||||
|
||||
/**
|
||||
* The date formatter.
|
||||
*/
|
||||
@@ -94,8 +89,6 @@ public class CityGradientFragment extends CityFragment.ChildFragment {
|
||||
dateFormatter = new DateFormatter(getContext());
|
||||
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_gradient, container, false);
|
||||
// this is quite ugly, but we need to disable the view pager and collapse the toolbar
|
||||
pager = getActivity().findViewById(R.id.pager);
|
||||
AppBarLayout layout = getActivity().findViewById(R.id.layout_appbar);
|
||||
binding.gradientProgress1.setMax(TIMEOUT_REMOVER);
|
||||
binding.gradientProgress2.setMax(TIMEOUT_REMOVER);
|
||||
animator = ValueAnimator.ofInt(TIMEOUT_REMOVER, 0);
|
||||
@@ -110,34 +103,7 @@ public class CityGradientFragment extends CityFragment.ChildFragment {
|
||||
binding.gradientText.setAlpha(Math.min(1, Math.max(0, value / 1000f)));
|
||||
}
|
||||
});
|
||||
binding.gradientScroll.setOnTouchListener(binding.gradientTouch.createOnTouchListener(new TimeView.OnSlideListener() {
|
||||
@Override
|
||||
public void onSlide(float relative) {
|
||||
if (!hasData()) return;
|
||||
animator.cancel();
|
||||
binding.gradientProgress1.setProgress(TIMEOUT_REMOVER);
|
||||
binding.gradientProgress2.setProgress(TIMEOUT_REMOVER);
|
||||
binding.gradientText.setAlpha(1);
|
||||
handler.removeCallbacks(remover);
|
||||
if (!closed) {
|
||||
layout.setExpanded(false, true);
|
||||
closed = true;
|
||||
}
|
||||
pager.setUserInputEnabled(false);
|
||||
updateSelection(relative);
|
||||
updateCondition(relative);
|
||||
binding.gradientText.setVisibility(View.VISIBLE);
|
||||
updateGuide(relative);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlideEnd() {
|
||||
pager.setUserInputEnabled(true);
|
||||
closed = false;
|
||||
animator.start();
|
||||
handler.postDelayed(remover, TIMEOUT_REMOVER);
|
||||
}
|
||||
}));
|
||||
|
||||
binding.setLifecycleOwner(getViewLifecycleOwner());
|
||||
binding.gradientText.setVisibility(View.GONE);
|
||||
@@ -278,7 +244,53 @@ public class CityGradientFragment extends CityFragment.ChildFragment {
|
||||
public void onPause() {
|
||||
handler.removeCallbacks(remover);
|
||||
remover.run();
|
||||
binding.gradientScroll.setOnTouchListener(null);
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
AppBarLayout layout = getActivity().findViewById(R.id.layout_appbar);
|
||||
ViewPager2 pager = getActivity().findViewById(R.id.pager);
|
||||
binding.gradientScroll.setOnTouchListener(binding.gradientTouch.createOnTouchListener(new TimeView.OnSlideListener() {
|
||||
@Override
|
||||
public void onSlide(float relative) {
|
||||
if (!hasData()) return;
|
||||
animator.cancel();
|
||||
binding.gradientProgress1.setProgress(TIMEOUT_REMOVER);
|
||||
binding.gradientProgress2.setProgress(TIMEOUT_REMOVER);
|
||||
binding.gradientText.setAlpha(1);
|
||||
handler.removeCallbacks(remover);
|
||||
if (!closed) {
|
||||
if (layout != null)
|
||||
layout.setExpanded(false, true);
|
||||
closed = true;
|
||||
}
|
||||
if (pager != null)
|
||||
pager.setUserInputEnabled(false);
|
||||
updateSelection(relative);
|
||||
updateCondition(relative);
|
||||
binding.gradientText.setVisibility(View.VISIBLE);
|
||||
updateGuide(relative);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlideEnd() {
|
||||
if (pager != null)
|
||||
pager.setUserInputEnabled(true);
|
||||
closed = false;
|
||||
animator.start();
|
||||
handler.postDelayed(remover, TIMEOUT_REMOVER);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
binding.gradientTouch.setOnTouchListener(null);
|
||||
super.onDestroyView();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
package com.mowesta.android.app.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.content.res.ResourcesCompat;
|
||||
import androidx.core.os.ConfigurationCompat;
|
||||
|
||||
import com.mowesta.android.app.R;
|
||||
@@ -17,7 +13,7 @@ import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* A utiltiy class to comptue times when aggregating weather
|
||||
* A utility class to computes times when aggregating weather
|
||||
* conditions into weather summaries.
|
||||
*
|
||||
* @author Marcus
|
||||
@@ -44,15 +40,15 @@ public class TimeUtils {
|
||||
* @param tz The time zone.
|
||||
*/
|
||||
public TimeUtils(long now, String tz) {
|
||||
if (tz != null) {
|
||||
c.setTimeZone(TimeZone.getTimeZone(tz));
|
||||
}
|
||||
c.setTimeInMillis(now);
|
||||
update(today);
|
||||
c.add(Calendar.DAY_OF_MONTH, -1);
|
||||
update(yesterday);
|
||||
c.add(Calendar.DAY_OF_MONTH, 2);
|
||||
update(tomorrow);
|
||||
if (tz != null) {
|
||||
c.setTimeZone(TimeZone.getTimeZone(tz));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,7 +5,6 @@ apply plugin: 'maven-publish'
|
||||
|
||||
buildscript {
|
||||
dependencies {
|
||||
classpath "org.openapitools:openapi-generator-gradle-plugin:5.3.0"
|
||||
classpath 'com.android.tools.build:gradle:7.2.1'
|
||||
classpath 'com.google.android.gms:oss-licenses-plugin:0.10.4'
|
||||
classpath 'org.handte.gradle:gradle-android-eclipse:1.0.0'
|
||||
@@ -25,7 +24,7 @@ allprojects {
|
||||
|
||||
// set version for our project
|
||||
group = 'com.mowesta'
|
||||
version = '1.0.26'
|
||||
version = '1.0.27'
|
||||
|
||||
// set versions for our libraries
|
||||
ext {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
apply plugin: 'org.openapi.generator'
|
||||
plugins {
|
||||
id 'org.openapi.generator' version '6.0.1'
|
||||
}
|
||||
|
||||
description = "MoWeSta iOS Api"
|
||||
|
||||
@@ -17,8 +19,25 @@ task clean(type: Delete) {
|
||||
}
|
||||
|
||||
|
||||
task fixApiClient() {
|
||||
doLast {
|
||||
ant.replaceregexp(match:'Optional<T>.none as! T', replace:'E.init(nilLiteral: ()) as! T', flags:'g', byline:true) {
|
||||
fileset(dir: 'build/swagger/OpenAPIClient/Classes/OpenAPIs', includes: 'URLSessionImplementations.swift')
|
||||
}
|
||||
ant.replaceregexp(match:'if T.self is ExpressibleByNilLiteral.Type', replace:'if let E = T.self as? ExpressibleByNilLiteral.Type', flags:'g', byline:true) {
|
||||
fileset(dir: 'build/swagger/OpenAPIClient/Classes/OpenAPIs', includes: 'URLSessionImplementations.swift')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// require api build to access swagger definition
|
||||
tasks.register("build") { }
|
||||
tasks['openApiGenerate'].dependsOn(project(':common-api').tasks['build'])
|
||||
// require swagger code gen before compilation
|
||||
build.dependsOn('openApiGenerate')
|
||||
fixApiClient.dependsOn('openApiGenerate')
|
||||
build.dependsOn('fixApiClient')
|
||||
|
||||
@@ -14,6 +14,12 @@
|
||||
2C163321283A27D600F78CEE /* AppTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C163320283A27D600F78CEE /* AppTests.swift */; };
|
||||
2C16332B283A27D600F78CEE /* AppUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C16332A283A27D600F78CEE /* AppUITests.swift */; };
|
||||
2C16332D283A27D600F78CEE /* AppUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C16332C283A27D600F78CEE /* AppUITestsLaunchTests.swift */; };
|
||||
2C369C6628888E6800B5AFB2 /* StationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C369C6528888E6800B5AFB2 /* StationView.swift */; };
|
||||
2C369C6828889EAE00B5AFB2 /* ErrorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C369C6728889EAE00B5AFB2 /* ErrorView.swift */; };
|
||||
2C369C6A2889592500B5AFB2 /* StationsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C369C692889592500B5AFB2 /* StationsView.swift */; };
|
||||
2C369C6C2889719C00B5AFB2 /* MeasurementView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C369C6B2889719C00B5AFB2 /* MeasurementView.swift */; };
|
||||
2C369C6E2889D42700B5AFB2 /* DevicesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C369C6D2889D42700B5AFB2 /* DevicesView.swift */; };
|
||||
2C369C702889D44100B5AFB2 /* DeviceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C369C6F2889D44100B5AFB2 /* DeviceView.swift */; };
|
||||
2C865E3B284271C800F1A89A /* MoWeStaApi in Frameworks */ = {isa = PBXBuildFile; productRef = 2C865E3A284271C800F1A89A /* MoWeStaApi */; };
|
||||
2C865E3D2842850800F1A89A /* HideableTabView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C865E3C2842850800F1A89A /* HideableTabView.swift */; };
|
||||
2C865E3F28428ED600F1A89A /* TextBindings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C865E3E28428ED600F1A89A /* TextBindings.swift */; };
|
||||
@@ -23,6 +29,31 @@
|
||||
2CA28203283E201B00D4A05A /* KeyChain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CA28200283E201B00D4A05A /* KeyChain.swift */; };
|
||||
2CA28204283E201B00D4A05A /* UserDefault.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CA28201283E201B00D4A05A /* UserDefault.swift */; };
|
||||
2CA28205283E201B00D4A05A /* AppInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CA28202283E201B00D4A05A /* AppInfo.swift */; };
|
||||
2CA4E74F2885E62500B901ED /* LocosLabLeafles in Frameworks */ = {isa = PBXBuildFile; productRef = 2CA4E74E2885E62500B901ED /* LocosLabLeafles */; };
|
||||
2CA4E7512887CB9800B901ED /* CountryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CA4E7502887CB9800B901ED /* CountryView.swift */; };
|
||||
2CA4E7532887CBA300B901ED /* StateView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CA4E7522887CBA300B901ED /* StateView.swift */; };
|
||||
2CA4E7552887D18D00B901ED /* GeojsonConverter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CA4E7542887D18D00B901ED /* GeojsonConverter.swift */; };
|
||||
2CA4E757288826DA00B901ED /* PlaceMapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CA4E756288826DA00B901ED /* PlaceMapView.swift */; };
|
||||
2CAC431B287F1C8F0088C9FD /* ApiHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CAC431A287F1C8F0088C9FD /* ApiHeader.swift */; };
|
||||
2CAC431D287F399F0088C9FD /* CollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CAC431C287F399F0088C9FD /* CollectionView.swift */; };
|
||||
2CB84A35288B1D5B00DB8F41 /* Background.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CB84A34288B1D5B00DB8F41 /* Background.swift */; };
|
||||
2CB84A38288B1F2B00DB8F41 /* BaseTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CB84A37288B1F2B00DB8F41 /* BaseTask.swift */; };
|
||||
2CB84A3A288B206600DB8F41 /* RefreshTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CB84A39288B206600DB8F41 /* RefreshTask.swift */; };
|
||||
2CB84A3C288B20A200DB8F41 /* SyncTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CB84A3B288B20A200DB8F41 /* SyncTask.swift */; };
|
||||
2CB84A3E288C0E9200DB8F41 /* Favorites.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CB84A3D288C0E9200DB8F41 /* Favorites.swift */; };
|
||||
2CB84A40288C563D00DB8F41 /* GradientViews.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CB84A3F288C563D00DB8F41 /* GradientViews.swift */; };
|
||||
2CB84A42288C578500DB8F41 /* DataColorSchemes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CB84A41288C578500DB8F41 /* DataColorSchemes.swift */; };
|
||||
2CB84A44288C585000DB8F41 /* Interpolations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CB84A43288C584F00DB8F41 /* Interpolations.swift */; };
|
||||
2CB84A46288DA48500DB8F41 /* CityGradientView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CB84A45288DA48500DB8F41 /* CityGradientView.swift */; };
|
||||
2CB9AA532881AC0C00E9B888 /* FavoriteExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CB9AA522881AC0C00E9B888 /* FavoriteExtensions.swift */; };
|
||||
2CD7E0BF2884402500F9CE57 /* WeatherViews.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CD7E0BE2884402500F9CE57 /* WeatherViews.swift */; };
|
||||
2CD7E0C12884415A00F9CE57 /* CityForecastView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CD7E0C02884415A00F9CE57 /* CityForecastView.swift */; };
|
||||
2CD7E0C328849FF900F9CE57 /* WeatherAggregates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CD7E0C228849FF900F9CE57 /* WeatherAggregates.swift */; };
|
||||
2CD7E0C528856C3500F9CE57 /* PageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CD7E0C428856C3500F9CE57 /* PageView.swift */; };
|
||||
2CD7E0C728857A7900F9CE57 /* CustomizeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CD7E0C628857A7900F9CE57 /* CustomizeView.swift */; };
|
||||
2CD7E0C92885A0F700F9CE57 /* CityVideoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CD7E0C82885A0F700F9CE57 /* CityVideoView.swift */; };
|
||||
2CD7E0CD2885AD7D00F9CE57 /* RemoteImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CD7E0CC2885AD7D00F9CE57 /* RemoteImageView.swift */; };
|
||||
2CE5E860287ECB98006B8CDF /* ProgressViews.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CE5E85F287ECB98006B8CDF /* ProgressViews.swift */; };
|
||||
2CEB0281283EB09B00DF3151 /* Database.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 2CEB027F283EB09B00DF3151 /* Database.xcdatamodeld */; };
|
||||
2CEB02862840C50700DF3151 /* TermsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CEB02822840C50700DF3151 /* TermsView.swift */; };
|
||||
2CEB02872840C50700DF3151 /* ButtonStyles.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CEB02832840C50700DF3151 /* ButtonStyles.swift */; };
|
||||
@@ -71,6 +102,12 @@
|
||||
2C163326283A27D600F78CEE /* AppUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AppUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
2C16332A283A27D600F78CEE /* AppUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppUITests.swift; sourceTree = "<group>"; };
|
||||
2C16332C283A27D600F78CEE /* AppUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppUITestsLaunchTests.swift; sourceTree = "<group>"; };
|
||||
2C369C6528888E6800B5AFB2 /* StationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StationView.swift; sourceTree = "<group>"; };
|
||||
2C369C6728889EAE00B5AFB2 /* ErrorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorView.swift; sourceTree = "<group>"; };
|
||||
2C369C692889592500B5AFB2 /* StationsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StationsView.swift; sourceTree = "<group>"; };
|
||||
2C369C6B2889719C00B5AFB2 /* MeasurementView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MeasurementView.swift; sourceTree = "<group>"; };
|
||||
2C369C6D2889D42700B5AFB2 /* DevicesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DevicesView.swift; sourceTree = "<group>"; };
|
||||
2C369C6F2889D44100B5AFB2 /* DeviceView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceView.swift; sourceTree = "<group>"; };
|
||||
2C865E392842719F00F1A89A /* ios-api */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = "ios-api"; path = "../ios-api"; sourceTree = "<group>"; };
|
||||
2C865E3C2842850800F1A89A /* HideableTabView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HideableTabView.swift; sourceTree = "<group>"; };
|
||||
2C865E3E28428ED600F1A89A /* TextBindings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextBindings.swift; sourceTree = "<group>"; };
|
||||
@@ -80,6 +117,32 @@
|
||||
2CA28200283E201B00D4A05A /* KeyChain.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyChain.swift; sourceTree = "<group>"; };
|
||||
2CA28201283E201B00D4A05A /* UserDefault.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserDefault.swift; sourceTree = "<group>"; };
|
||||
2CA28202283E201B00D4A05A /* AppInfo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppInfo.swift; sourceTree = "<group>"; };
|
||||
2CA4E7502887CB9800B901ED /* CountryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CountryView.swift; sourceTree = "<group>"; };
|
||||
2CA4E7522887CBA300B901ED /* StateView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StateView.swift; sourceTree = "<group>"; };
|
||||
2CA4E7542887D18D00B901ED /* GeojsonConverter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeojsonConverter.swift; sourceTree = "<group>"; };
|
||||
2CA4E756288826DA00B901ED /* PlaceMapView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaceMapView.swift; sourceTree = "<group>"; };
|
||||
2CAC431A287F1C8F0088C9FD /* ApiHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApiHeader.swift; sourceTree = "<group>"; };
|
||||
2CAC431C287F399F0088C9FD /* CollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionView.swift; sourceTree = "<group>"; };
|
||||
2CB84A33288AFD3400DB8F41 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
|
||||
2CB84A34288B1D5B00DB8F41 /* Background.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Background.swift; sourceTree = "<group>"; };
|
||||
2CB84A37288B1F2B00DB8F41 /* BaseTask.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseTask.swift; sourceTree = "<group>"; };
|
||||
2CB84A39288B206600DB8F41 /* RefreshTask.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefreshTask.swift; sourceTree = "<group>"; };
|
||||
2CB84A3B288B20A200DB8F41 /* SyncTask.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SyncTask.swift; sourceTree = "<group>"; };
|
||||
2CB84A3D288C0E9200DB8F41 /* Favorites.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Favorites.swift; sourceTree = "<group>"; };
|
||||
2CB84A3F288C563D00DB8F41 /* GradientViews.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GradientViews.swift; sourceTree = "<group>"; };
|
||||
2CB84A41288C578500DB8F41 /* DataColorSchemes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataColorSchemes.swift; sourceTree = "<group>"; };
|
||||
2CB84A43288C584F00DB8F41 /* Interpolations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Interpolations.swift; sourceTree = "<group>"; };
|
||||
2CB84A45288DA48500DB8F41 /* CityGradientView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CityGradientView.swift; sourceTree = "<group>"; };
|
||||
2CB9AA522881AC0C00E9B888 /* FavoriteExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoriteExtensions.swift; sourceTree = "<group>"; };
|
||||
2CB9AA552882CD3600E9B888 /* lib-leafless */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = "lib-leafless"; path = "../ios-locoslab/lib-leafless"; sourceTree = "<group>"; };
|
||||
2CD7E0BE2884402500F9CE57 /* WeatherViews.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherViews.swift; sourceTree = "<group>"; };
|
||||
2CD7E0C02884415A00F9CE57 /* CityForecastView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CityForecastView.swift; sourceTree = "<group>"; };
|
||||
2CD7E0C228849FF900F9CE57 /* WeatherAggregates.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherAggregates.swift; sourceTree = "<group>"; };
|
||||
2CD7E0C428856C3500F9CE57 /* PageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageView.swift; sourceTree = "<group>"; };
|
||||
2CD7E0C628857A7900F9CE57 /* CustomizeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomizeView.swift; sourceTree = "<group>"; };
|
||||
2CD7E0C82885A0F700F9CE57 /* CityVideoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CityVideoView.swift; sourceTree = "<group>"; };
|
||||
2CD7E0CC2885AD7D00F9CE57 /* RemoteImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteImageView.swift; sourceTree = "<group>"; };
|
||||
2CE5E85F287ECB98006B8CDF /* ProgressViews.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressViews.swift; sourceTree = "<group>"; };
|
||||
2CEB0280283EB09B00DF3151 /* Database.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Database.xcdatamodel; sourceTree = "<group>"; };
|
||||
2CEB02822840C50700DF3151 /* TermsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TermsView.swift; sourceTree = "<group>"; };
|
||||
2CEB02832840C50700DF3151 /* ButtonStyles.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ButtonStyles.swift; sourceTree = "<group>"; };
|
||||
@@ -104,6 +167,7 @@
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
2CA4E74F2885E62500B901ED /* LocosLabLeafles in Frameworks */,
|
||||
2C865E3B284271C800F1A89A /* MoWeStaApi in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
@@ -128,6 +192,7 @@
|
||||
2C1632FE283A27D300F78CEE = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
2CB9AA552882CD3600E9B888 /* lib-leafless */,
|
||||
2C865E392842719F00F1A89A /* ios-api */,
|
||||
2C163309283A27D300F78CEE /* App */,
|
||||
2C16331F283A27D600F78CEE /* AppTests */,
|
||||
@@ -150,16 +215,19 @@
|
||||
2C163309283A27D300F78CEE /* App */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
2CB84A33288AFD3400DB8F41 /* Info.plist */,
|
||||
2CEB027F283EB09B00DF3151 /* Database.xcdatamodeld */,
|
||||
2CFC0F132841201E00E597DC /* Html */,
|
||||
2CEB028C2840C96D00DF3151 /* Ui */,
|
||||
2CEB027F283EB09B00DF3151 /* Database.xcdatamodeld */,
|
||||
2CA281FD283E1D1300D4A05A /* Model */,
|
||||
2CA281FC283E1D0400D4A05A /* View */,
|
||||
2CB84A36288B1EE900DB8F41 /* Task */,
|
||||
2CA281FB283E1CEB00D4A05A /* Util */,
|
||||
2C16330A283A27D300F78CEE /* Application.swift */,
|
||||
2CB84A34288B1D5B00DB8F41 /* Background.swift */,
|
||||
2C16330C283A27D300F78CEE /* ContentView.swift */,
|
||||
2C16330E283A27D600F78CEE /* Assets.xcassets */,
|
||||
2C163313283A27D600F78CEE /* Persistence.swift */,
|
||||
2C16330E283A27D600F78CEE /* Assets.xcassets */,
|
||||
2C163310283A27D600F78CEE /* Preview Content */,
|
||||
2CEB028A2840C54000DF3151 /* StartScreen.storyboard */,
|
||||
2CEB029C2840CD3200DF3151 /* Localizable.strings */,
|
||||
@@ -206,6 +274,8 @@
|
||||
2CA28200283E201B00D4A05A /* KeyChain.swift */,
|
||||
2CA28201283E201B00D4A05A /* UserDefault.swift */,
|
||||
2CF8D62928440FE4008FB7D0 /* UnitConverter.swift */,
|
||||
2CAC431A287F1C8F0088C9FD /* ApiHeader.swift */,
|
||||
2CA4E7542887D18D00B901ED /* GeojsonConverter.swift */,
|
||||
);
|
||||
path = Util;
|
||||
sourceTree = "<group>";
|
||||
@@ -222,6 +292,20 @@
|
||||
2CFC0F1B28421A0300E597DC /* FavoritesView.swift */,
|
||||
2C865E402842999600F1A89A /* CityView.swift */,
|
||||
2C865E42284393DA00F1A89A /* CityInfoView.swift */,
|
||||
2CD7E0C02884415A00F9CE57 /* CityForecastView.swift */,
|
||||
2CB84A45288DA48500DB8F41 /* CityGradientView.swift */,
|
||||
2CD7E0C82885A0F700F9CE57 /* CityVideoView.swift */,
|
||||
2CA4E7502887CB9800B901ED /* CountryView.swift */,
|
||||
2CA4E7522887CBA300B901ED /* StateView.swift */,
|
||||
2CAC431C287F399F0088C9FD /* CollectionView.swift */,
|
||||
2CD7E0BE2884402500F9CE57 /* WeatherViews.swift */,
|
||||
2CD7E0C628857A7900F9CE57 /* CustomizeView.swift */,
|
||||
2CA4E756288826DA00B901ED /* PlaceMapView.swift */,
|
||||
2C369C6528888E6800B5AFB2 /* StationView.swift */,
|
||||
2C369C692889592500B5AFB2 /* StationsView.swift */,
|
||||
2C369C6B2889719C00B5AFB2 /* MeasurementView.swift */,
|
||||
2C369C6F2889D44100B5AFB2 /* DeviceView.swift */,
|
||||
2C369C6D2889D42700B5AFB2 /* DevicesView.swift */,
|
||||
);
|
||||
path = View;
|
||||
sourceTree = "<group>";
|
||||
@@ -233,16 +317,36 @@
|
||||
2C865E3E28428ED600F1A89A /* TextBindings.swift */,
|
||||
2CF8D6252843D0DB008FB7D0 /* ImageBindings.swift */,
|
||||
2CF8D62728440E05008FB7D0 /* DataBindings.swift */,
|
||||
2CB9AA522881AC0C00E9B888 /* FavoriteExtensions.swift */,
|
||||
2CD7E0C228849FF900F9CE57 /* WeatherAggregates.swift */,
|
||||
2CB84A3D288C0E9200DB8F41 /* Favorites.swift */,
|
||||
2CB84A41288C578500DB8F41 /* DataColorSchemes.swift */,
|
||||
2CB84A43288C584F00DB8F41 /* Interpolations.swift */,
|
||||
);
|
||||
path = Model;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
2CB84A36288B1EE900DB8F41 /* Task */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
2CB84A37288B1F2B00DB8F41 /* BaseTask.swift */,
|
||||
2CB84A3B288B20A200DB8F41 /* SyncTask.swift */,
|
||||
2CB84A39288B206600DB8F41 /* RefreshTask.swift */,
|
||||
);
|
||||
path = Task;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
2CEB028C2840C96D00DF3151 /* Ui */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
2CEB029E2840E7FA00DF3151 /* ViewExtensions.swift */,
|
||||
2CEB02832840C50700DF3151 /* ButtonStyles.swift */,
|
||||
2C865E3C2842850800F1A89A /* HideableTabView.swift */,
|
||||
2CE5E85F287ECB98006B8CDF /* ProgressViews.swift */,
|
||||
2CD7E0C428856C3500F9CE57 /* PageView.swift */,
|
||||
2CD7E0CC2885AD7D00F9CE57 /* RemoteImageView.swift */,
|
||||
2C369C6728889EAE00B5AFB2 /* ErrorView.swift */,
|
||||
2CB84A3F288C563D00DB8F41 /* GradientViews.swift */,
|
||||
);
|
||||
path = Ui;
|
||||
sourceTree = "<group>";
|
||||
@@ -265,6 +369,7 @@
|
||||
name = App;
|
||||
packageProductDependencies = (
|
||||
2C865E3A284271C800F1A89A /* MoWeStaApi */,
|
||||
2CA4E74E2885E62500B901ED /* LocosLabLeafles */,
|
||||
);
|
||||
productName = App;
|
||||
productReference = 2C163307283A27D300F78CEE /* MoWeSta.app */;
|
||||
@@ -385,28 +490,58 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
2C865E3F28428ED600F1A89A /* TextBindings.swift in Sources */,
|
||||
2CB84A35288B1D5B00DB8F41 /* Background.swift in Sources */,
|
||||
2CB84A44288C585000DB8F41 /* Interpolations.swift in Sources */,
|
||||
2CB9AA532881AC0C00E9B888 /* FavoriteExtensions.swift in Sources */,
|
||||
2C369C702889D44100B5AFB2 /* DeviceView.swift in Sources */,
|
||||
2C865E412842999600F1A89A /* CityView.swift in Sources */,
|
||||
2CA4E7512887CB9800B901ED /* CountryView.swift in Sources */,
|
||||
2CA4E757288826DA00B901ED /* PlaceMapView.swift in Sources */,
|
||||
2C163314283A27D600F78CEE /* Persistence.swift in Sources */,
|
||||
2CB84A46288DA48500DB8F41 /* CityGradientView.swift in Sources */,
|
||||
2CB84A3C288B20A200DB8F41 /* SyncTask.swift in Sources */,
|
||||
2CF8D6262843D0DB008FB7D0 /* ImageBindings.swift in Sources */,
|
||||
2CA4E7552887D18D00B901ED /* GeojsonConverter.swift in Sources */,
|
||||
2CAC431B287F1C8F0088C9FD /* ApiHeader.swift in Sources */,
|
||||
2C369C6628888E6800B5AFB2 /* StationView.swift in Sources */,
|
||||
2CD7E0C528856C3500F9CE57 /* PageView.swift in Sources */,
|
||||
2CD7E0C12884415A00F9CE57 /* CityForecastView.swift in Sources */,
|
||||
2CEB02862840C50700DF3151 /* TermsView.swift in Sources */,
|
||||
2CA28204283E201B00D4A05A /* UserDefault.swift in Sources */,
|
||||
2CD7E0C728857A7900F9CE57 /* CustomizeView.swift in Sources */,
|
||||
2CFC0F18284219C600E597DC /* DrawerView.swift in Sources */,
|
||||
2CEB0281283EB09B00DF3151 /* Database.xcdatamodeld in Sources */,
|
||||
2CB84A40288C563D00DB8F41 /* GradientViews.swift in Sources */,
|
||||
2C369C6A2889592500B5AFB2 /* StationsView.swift in Sources */,
|
||||
2CD7E0CD2885AD7D00F9CE57 /* RemoteImageView.swift in Sources */,
|
||||
2CD7E0C92885A0F700F9CE57 /* CityVideoView.swift in Sources */,
|
||||
2CD7E0C328849FF900F9CE57 /* WeatherAggregates.swift in Sources */,
|
||||
2CA28203283E201B00D4A05A /* KeyChain.swift in Sources */,
|
||||
2C369C6E2889D42700B5AFB2 /* DevicesView.swift in Sources */,
|
||||
2CA281FF283E1D2F00D4A05A /* AppState.swift in Sources */,
|
||||
2CB84A38288B1F2B00DB8F41 /* BaseTask.swift in Sources */,
|
||||
2C369C6828889EAE00B5AFB2 /* ErrorView.swift in Sources */,
|
||||
2CA28205283E201B00D4A05A /* AppInfo.swift in Sources */,
|
||||
2C865E3D2842850800F1A89A /* HideableTabView.swift in Sources */,
|
||||
2CB84A3A288B206600DB8F41 /* RefreshTask.swift in Sources */,
|
||||
2CEB029F2840E7FA00DF3151 /* ViewExtensions.swift in Sources */,
|
||||
2CB84A3E288C0E9200DB8F41 /* Favorites.swift in Sources */,
|
||||
2CFC0F162842197C00E597DC /* LoginView.swift in Sources */,
|
||||
2C16330D283A27D300F78CEE /* ContentView.swift in Sources */,
|
||||
2CF8D62A28440FE4008FB7D0 /* UnitConverter.swift in Sources */,
|
||||
2CEB02872840C50700DF3151 /* ButtonStyles.swift in Sources */,
|
||||
2CA4E7532887CBA300B901ED /* StateView.swift in Sources */,
|
||||
2CB84A42288C578500DB8F41 /* DataColorSchemes.swift in Sources */,
|
||||
2CAC431D287F399F0088C9FD /* CollectionView.swift in Sources */,
|
||||
2CFC0F1A284219D400E597DC /* SearchView.swift in Sources */,
|
||||
2CD7E0BF2884402500F9CE57 /* WeatherViews.swift in Sources */,
|
||||
2C865E43284393DA00F1A89A /* CityInfoView.swift in Sources */,
|
||||
2CFC0F1C28421A0300E597DC /* FavoritesView.swift in Sources */,
|
||||
2CF8D62828440E05008FB7D0 /* DataBindings.swift in Sources */,
|
||||
2C369C6C2889719C00B5AFB2 /* MeasurementView.swift in Sources */,
|
||||
2CEB02892840C50700DF3151 /* SettingsView.swift in Sources */,
|
||||
2C16330B283A27D300F78CEE /* Application.swift in Sources */,
|
||||
2CE5E860287ECB98006B8CDF /* ProgressViews.swift in Sources */,
|
||||
2CEB02882840C50700DF3151 /* WebView.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
@@ -507,7 +642,7 @@
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 15.5;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 14.1;
|
||||
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
|
||||
MTL_FAST_MATH = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
@@ -562,7 +697,7 @@
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 15.5;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 14.1;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
MTL_FAST_MATH = YES;
|
||||
SDKROOT = iphoneos;
|
||||
@@ -578,16 +713,18 @@
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
CURRENT_PROJECT_VERSION = 2;
|
||||
DEVELOPMENT_ASSET_PATHS = "\"App/Preview Content\"";
|
||||
DEVELOPMENT_TEAM = 2KS4Z77UGE;
|
||||
ENABLE_PREVIEWS = YES;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
INFOPLIST_FILE = App/Info.plist;
|
||||
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
|
||||
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
|
||||
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
|
||||
INFOPLIST_KEY_UILaunchStoryboardName = StartScreen;
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait";
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 14.1;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
@@ -595,7 +732,7 @@
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 1.0;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.mowesta.ios.App;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.mowesta.app;
|
||||
PRODUCT_NAME = MoWeSta;
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
SWIFT_VERSION = 5.0;
|
||||
@@ -609,16 +746,18 @@
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
CURRENT_PROJECT_VERSION = 2;
|
||||
DEVELOPMENT_ASSET_PATHS = "\"App/Preview Content\"";
|
||||
DEVELOPMENT_TEAM = 2KS4Z77UGE;
|
||||
ENABLE_PREVIEWS = YES;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
INFOPLIST_FILE = App/Info.plist;
|
||||
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
|
||||
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
|
||||
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
|
||||
INFOPLIST_KEY_UILaunchStoryboardName = StartScreen;
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait";
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 14.1;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
@@ -626,7 +765,7 @@
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 1.0;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.mowesta.ios.App;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.mowesta.app;
|
||||
PRODUCT_NAME = MoWeSta;
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
SWIFT_VERSION = 5.0;
|
||||
@@ -756,6 +895,10 @@
|
||||
isa = XCSwiftPackageProductDependency;
|
||||
productName = MoWeStaApi;
|
||||
};
|
||||
2CA4E74E2885E62500B901ED /* LocosLabLeafles */ = {
|
||||
isa = XCSwiftPackageProductDependency;
|
||||
productName = LocosLabLeafles;
|
||||
};
|
||||
/* End XCSwiftPackageProductDependency section */
|
||||
|
||||
/* Begin XCVersionGroup section */
|
||||
|
||||
@@ -9,16 +9,41 @@ import SwiftUI
|
||||
|
||||
@main
|
||||
struct Application: App {
|
||||
let persistenceController = PersistenceController.shared
|
||||
|
||||
@State var appState = AppState();
|
||||
|
||||
let persistenceController = PersistenceController.shared
|
||||
@UIApplicationDelegateAdaptor(ApplicationDelegate.self) var appDelegate
|
||||
|
||||
@Environment(\.scenePhase) var scenePhase
|
||||
|
||||
var body: some Scene {
|
||||
WindowGroup {
|
||||
ContentView()
|
||||
.environment(\.managedObjectContext, persistenceController.container.viewContext)
|
||||
.environment(\.appState, appState)
|
||||
}.onChange(of: scenePhase) { phase in
|
||||
switch phase {
|
||||
case .background:
|
||||
appDelegate.background.scheduleTask()
|
||||
case .active:
|
||||
print("Executing foreground refresh.")
|
||||
RefreshTask().execute(completion: { success in
|
||||
print("Completed foreground refresh: \(success)")
|
||||
})
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class ApplicationDelegate: NSObject, UIApplicationDelegate {
|
||||
|
||||
let background = Background()
|
||||
|
||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
|
||||
background.registerTask()
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "icon_android.svg",
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="24" width="24" viewBox="0 0 48 48"><path d="M19.9 41.75h8.2v-2h-8.2ZM13 46q-1.2 0-2.1-.9-.9-.9-.9-2.1V5q0-1.2.9-2.1.9-.9 2.1-.9h22q1.2 0 2.1.9.9.9.9 2.1v38q0 1.2-.9 2.1-.9.9-2.1.9Zm0-7.5V43h22v-4.5Zm0-3h22v-26H13Zm0-29h22V5H13Zm0 32V43Zm0-32V5v1.5Z"/></svg>
|
||||
|
After Width: | Height: | Size: 305 B |
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "icon_arduino.svg",
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="24" width="24" viewBox="0 0 48 48"><path d="M18.85 29.15V18.9H29.1v10.25Zm3-3h4.25V21.9h-4.25ZM18 42v-4h-5q-1.2 0-2.1-.9-.9-.9-.9-2.1v-5H6v-3h4v-6.2H6v-3h4v-5q0-1.2.9-2.1.9-.9 2.1-.9h5V6h3v3.8h6.2V6h3v3.8h5q1.2 0 2.1.9.9.9.9 2.1v5H42v3h-3.8V27H42v3h-3.8v5q0 1.2-.9 2.1-.9.9-2.1.9h-5v4h-3v-4H21v4Zm17.2-7V12.8H13V35ZM24 24Z"/></svg>
|
||||
|
After Width: | Height: | Size: 379 B |
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "icon_devices.svg",
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="25" width="25" viewBox="0 0 48 48"><path d="M4 40v-4.5h4.3V11q0-1.2.9-2.1.9-.9 2.1-.9h31v3h-31v24.5H23V40Zm23.95 0q-.8 0-1.375-.6T26 37.8V15.95q0-.8.575-1.375T27.95 14h13.6q1 0 1.725.575.725.575.725 1.375V37.8q0 1-.725 1.6-.725.6-1.725.6ZM29 35.5h12V17H29Z"/></svg>
|
||||
|
After Width: | Height: | Size: 313 B |
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "icon_ios.svg",
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="24" width="24" viewBox="0 0 48 48"><path d="M13 46q-1.2 0-2.1-.9-.9-.9-.9-2.1V5q0-1.2.9-2.1.9-.9 2.1-.9h22q1.2 0 2.1.9.9.9.9 2.1v38q0 1.2-.9 2.1-.9.9-2.1.9Zm0-7.5V43h22v-4.5Zm11 3.75q.65 0 1.075-.425.425-.425.425-1.075 0-.65-.425-1.075-.425-.425-1.075-.425-.65 0-1.075.425-.425.425-.425 1.075 0 .65.425 1.075.425.425 1.075.425ZM13 35.5h22v-26H13Zm0-29h22V5H13Zm0 32V43Zm0-32V5v1.5Z"/></svg>
|
||||
|
After Width: | Height: | Size: 438 B |
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "icon_station.svg",
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="22" width="22" viewBox="0 0 48 48"><path d="M24 24q0-4.55 3.225-7.775Q30.45 13 35 13q4.55 0 7.775 3.225Q46 19.45 46 24ZM13 35q-4.55 0-7.775-3.225Q2 28.55 2 24h22q0 4.55-3.225 7.775Q17.55 35 13 35Zm11-11q-4.55 0-7.775-3.225Q13 17.55 13 13q0-4.55 3.225-7.775Q19.45 2 24 2Zm0 22V24q4.55 0 7.775 3.225Q35 30.45 35 35q0 4.55-3.225 7.775Q28.55 46 24 46Z"/></svg>
|
||||
|
After Width: | Height: | Size: 404 B |
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "icon_wind.svg",
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 22.0.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
viewBox="0 0 30 30" style="enable-background:new 0 0 30 30;" xml:space="preserve">
|
||||
<path d="M3.1,16.97c0,0.24,0.09,0.45,0.28,0.62c0.16,0.19,0.37,0.28,0.63,0.28H18.7c0.29,0,0.53,0.1,0.73,0.3
|
||||
c0.2,0.2,0.3,0.45,0.3,0.74c0,0.29-0.1,0.53-0.3,0.72c-0.2,0.19-0.44,0.29-0.74,0.29c-0.29,0-0.54-0.1-0.73-0.29
|
||||
c-0.16-0.18-0.36-0.26-0.6-0.26c-0.25,0-0.46,0.09-0.64,0.26s-0.27,0.38-0.27,0.61c0,0.25,0.09,0.46,0.28,0.63
|
||||
c0.56,0.55,1.22,0.83,1.96,0.83c0.78,0,1.45-0.27,2.01-0.81c0.56-0.54,0.83-1.19,0.83-1.97s-0.28-1.44-0.84-2
|
||||
c-0.56-0.56-1.23-0.84-2-0.84H4.01c-0.25,0-0.46,0.09-0.64,0.26C3.19,16.51,3.1,16.72,3.1,16.97z M3.1,13.69
|
||||
c0,0.23,0.09,0.43,0.28,0.61c0.17,0.18,0.38,0.26,0.63,0.26h20.04c0.78,0,1.45-0.27,2.01-0.82c0.56-0.54,0.84-1.2,0.84-1.97
|
||||
c0-0.77-0.28-1.44-0.84-1.99s-1.23-0.83-2.01-0.83c-0.77,0-1.42,0.27-1.95,0.8c-0.18,0.16-0.27,0.38-0.27,0.67
|
||||
c0,0.26,0.09,0.47,0.26,0.63c0.17,0.16,0.38,0.24,0.63,0.24c0.24,0,0.45-0.08,0.63-0.24c0.19-0.21,0.42-0.31,0.7-0.31
|
||||
c0.29,0,0.53,0.1,0.73,0.3c0.2,0.2,0.3,0.44,0.3,0.73c0,0.29-0.1,0.53-0.3,0.72c-0.2,0.19-0.44,0.29-0.73,0.29H4.01
|
||||
c-0.25,0-0.46,0.09-0.64,0.26C3.19,13.23,3.1,13.44,3.1,13.69z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.4 KiB |
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "icon_wind_direction.svg",
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 22.0.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
viewBox="0 0 30 30" style="enable-background:new 0 0 30 30;" xml:space="preserve">
|
||||
<path d="M3.74,14.5c0-2.04,0.51-3.93,1.52-5.66s2.38-3.1,4.11-4.11s3.61-1.51,5.64-1.51c1.52,0,2.98,0.3,4.37,0.89
|
||||
s2.58,1.4,3.59,2.4s1.81,2.2,2.4,3.6s0.89,2.85,0.89,4.39c0,1.52-0.3,2.98-0.89,4.37s-1.4,2.59-2.4,3.59s-2.2,1.8-3.59,2.39
|
||||
s-2.84,0.89-4.37,0.89c-1.53,0-3-0.3-4.39-0.89s-2.59-1.4-3.6-2.4s-1.8-2.2-2.4-3.58S3.74,16.03,3.74,14.5z M6.22,14.5
|
||||
c0,2.37,0.86,4.43,2.59,6.18c1.73,1.73,3.79,2.59,6.2,2.59c1.58,0,3.05-0.39,4.39-1.18s2.42-1.85,3.21-3.2s1.19-2.81,1.19-4.39
|
||||
s-0.4-3.05-1.19-4.4s-1.86-2.42-3.21-3.21s-2.81-1.18-4.39-1.18s-3.05,0.39-4.39,1.18S8.2,8.75,7.4,10.1S6.22,12.92,6.22,14.5z
|
||||
M11.11,20.35l3.75-13.11c0.01-0.1,0.06-0.15,0.15-0.15s0.14,0.05,0.15,0.15l3.74,13.11c0.04,0.11,0.03,0.19-0.02,0.25
|
||||
s-0.13,0.06-0.24,0l-3.47-1.3c-0.1-0.04-0.2-0.04-0.29,0l-3.5,1.3c-0.1,0.06-0.17,0.06-0.21,0S11.09,20.45,11.11,20.35z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "logo_fair.png",
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 84 KiB |
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "logo_ude.png",
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 39 KiB |
@@ -0,0 +1,52 @@
|
||||
//
|
||||
// BackgroundManager.swift
|
||||
// App
|
||||
//
|
||||
// Created by Marcus Handte on 22.07.22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import BackgroundTasks
|
||||
|
||||
/// A class to handle the background fetching
|
||||
public class Background {
|
||||
|
||||
public func registerTask() {
|
||||
print("Register background refresh.")
|
||||
BGTaskScheduler.shared.register(forTaskWithIdentifier: "com.mowesta.app.refresh", using: DispatchQueue.global()) { task in
|
||||
if let t = task as? BGAppRefreshTask {
|
||||
self.executeTask(task: t)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func scheduleTask() {
|
||||
print("Schedule background refresh.")
|
||||
let request = BGAppRefreshTaskRequest(identifier: "com.mowesta.app.refresh")
|
||||
request.earliestBeginDate = Date(timeIntervalSinceNow: 60 * 60)
|
||||
do {
|
||||
try BGTaskScheduler.shared.submit(request)
|
||||
} catch {
|
||||
print("Could not schedule refresh: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
func executeTask(task: BGAppRefreshTask) {
|
||||
print("Perform background refresh.")
|
||||
let state = AppState.shared
|
||||
var tasks: [BaseTask] = []
|
||||
if state.credentials != nil {
|
||||
tasks.append(SyncTask())
|
||||
}
|
||||
tasks.append(RefreshTask())
|
||||
task.expirationHandler = {
|
||||
BaseTask.cancel(all: tasks)
|
||||
}
|
||||
BaseTask.execute(all: tasks) { success in
|
||||
print("Completed background refresh: \(success)")
|
||||
task.setTaskCompleted(success: success)
|
||||
self.scheduleTask()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,14 +9,8 @@ import SwiftUI
|
||||
import CoreData
|
||||
|
||||
struct ContentView: View {
|
||||
@Environment(\.managedObjectContext) private var viewContext
|
||||
|
||||
@FetchRequest(
|
||||
sortDescriptors: [NSSortDescriptor(keyPath: \Item.timestamp, ascending: true)],
|
||||
animation: .default)
|
||||
private var items: FetchedResults<Item>
|
||||
|
||||
@Environment(\.appState) var appState
|
||||
@ObservedObject var appState = AppState.shared
|
||||
@Environment(\.tabViewState) var tabViewState
|
||||
|
||||
var body: some View {
|
||||
@@ -24,6 +18,12 @@ struct ContentView: View {
|
||||
TermsView() {
|
||||
appState.terms = AppState.TERMS_VERSION
|
||||
}
|
||||
.environmentObject(tabViewState)
|
||||
} else if (appState.device == nil) {
|
||||
NavigationView {
|
||||
LoginView(mode: .createDevice)
|
||||
}
|
||||
.navigationViewStyle(StackNavigationViewStyle())
|
||||
} else {
|
||||
NavigationView {
|
||||
DrawerView()
|
||||
@@ -32,46 +32,8 @@ struct ContentView: View {
|
||||
.environmentObject(tabViewState)
|
||||
}
|
||||
}
|
||||
|
||||
private func addItem() {
|
||||
withAnimation {
|
||||
let newItem = Item(context: viewContext)
|
||||
newItem.timestamp = Date()
|
||||
|
||||
do {
|
||||
try viewContext.save()
|
||||
} catch {
|
||||
// Replace this implementation with code to handle the error appropriately.
|
||||
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
|
||||
let nsError = error as NSError
|
||||
fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func deleteItems(offsets: IndexSet) {
|
||||
withAnimation {
|
||||
offsets.map { items[$0] }.forEach(viewContext.delete)
|
||||
|
||||
do {
|
||||
try viewContext.save()
|
||||
} catch {
|
||||
// Replace this implementation with code to handle the error appropriately.
|
||||
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
|
||||
let nsError = error as NSError
|
||||
fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private let itemFormatter: DateFormatter = {
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateStyle = .short
|
||||
formatter.timeStyle = .medium
|
||||
return formatter
|
||||
}()
|
||||
|
||||
struct ContentView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ContentView().environment(\.managedObjectContext, PersistenceController.preview.container.viewContext).preferredColorScheme(.dark)
|
||||
|
||||
@@ -9,16 +9,21 @@
|
||||
<attribute name="identifier" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<attribute name="location" optional="YES" attributeType="String"/>
|
||||
<attribute name="locationTime" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<attribute name="locationType" optional="YES" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<attribute name="position" optional="YES" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<attribute name="removed" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
|
||||
<attribute name="station" optional="YES" attributeType="String"/>
|
||||
<attribute name="type" optional="YES" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<attribute name="weatherTime" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<fetchIndex name="byPositionIndex">
|
||||
<fetchIndexElement property="position" type="Binary" order="ascending"/>
|
||||
<fetchIndexElement property="removed" type="Binary" order="ascending"/>
|
||||
</fetchIndex>
|
||||
</entity>
|
||||
<entity name="Item" representedClassName="Item" syncable="YES" codeGenerationType="class">
|
||||
<attribute name="timestamp" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
|
||||
</entity>
|
||||
<elements>
|
||||
<element name="Favorite" positionX="-63" positionY="-9" width="128" height="224"/>
|
||||
<element name="Item" positionX="-63" positionY="-18" width="128" height="44"/>
|
||||
<element name="Favorite" positionX="-63" positionY="-9" width="128" height="209"/>
|
||||
</elements>
|
||||
</model>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>BGTaskSchedulerPermittedIdentifiers</key>
|
||||
<array>
|
||||
<string>com.mowesta.app.refresh</string>
|
||||
</array>
|
||||
<key>UIBackgroundModes</key>
|
||||
<array>
|
||||
<string>fetch</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
import MoWeStaApi
|
||||
|
||||
/// The global application state that can be accessed all throughout the user interface
|
||||
/// to access the user and ui state and settings.
|
||||
@@ -14,36 +15,94 @@ public class AppState: ObservableObject {
|
||||
|
||||
// The current version of the license terms.
|
||||
static let TERMS_VERSION = 1
|
||||
|
||||
|
||||
// The shared application state.
|
||||
public static let shared = AppState()
|
||||
|
||||
// The version of the license terms that the user has accepted.
|
||||
@UserDefault("terms", defaultValue: 0) var terms: Int { willSet { objectWillChange.send() }}
|
||||
@UserDefault("terms", defaultValue: 0) var terms: Int { willSet { objectWillChange.send(); }}
|
||||
|
||||
// A boolean to indicate whether the app is in development mode.
|
||||
@UserDefault("development", defaultValue: false ) var development: Bool { willSet { objectWillChange.send() }}
|
||||
|
||||
// The device token used to upload data
|
||||
@UserDefault("token", defaultValue: "") var token: String
|
||||
|
||||
// The device created upon initialization.
|
||||
@UserDefault("device", defaultValue: "") var device: String
|
||||
|
||||
@UserDefault("precipitation", defaultValue: true) var precipitation: Bool { willSet { objectWillChange.send() }}
|
||||
@UserDefault("windSpeed", defaultValue: true) var windSpeed: Bool { willSet { objectWillChange.send() }}
|
||||
@UserDefault("cloudCoverage", defaultValue: true) var cloudCoverage: Bool { willSet { objectWillChange.send() }}
|
||||
@UserDefault("humidity", defaultValue: true) var humidity: Bool { willSet { objectWillChange.send() }}
|
||||
@UserDefault("snowDepth", defaultValue: true) var snowDepth: Bool { willSet { objectWillChange.send() }}
|
||||
@UserDefault("pressure", defaultValue: true) var pressure: Bool { willSet { objectWillChange.send() }}
|
||||
@UserDefault("unitSystem", defaultValue: .si) var unitSystem: UnitSystem { willSet { objectWillChange.send() }}
|
||||
@UserDefault("temperatureUnit", defaultValue: .both) var temperatureUnit: TemperatureUnit { willSet { objectWillChange.send() }}
|
||||
|
||||
var credentialFailure = false { willSet { objectWillChange.send() }}
|
||||
|
||||
private var loadedDevice: Device? = nil
|
||||
|
||||
var device: Device? {
|
||||
get {
|
||||
return loadedDevice
|
||||
}
|
||||
set(value) {
|
||||
objectWillChange.send()
|
||||
loadedDevice = value
|
||||
if (value != nil) {
|
||||
if let encoded = try? JSONEncoder().encode(value) {
|
||||
UserDefaults.standard.set(encoded, forKey: "device")
|
||||
}
|
||||
} else {
|
||||
UserDefaults.standard.removeObject(forKey: "device")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var keyChain: KeyChain
|
||||
|
||||
var credentials: UserCredentials? {
|
||||
get {
|
||||
if let result = try? keyChain.get() {
|
||||
return result
|
||||
}
|
||||
return nil
|
||||
}
|
||||
set(value) {
|
||||
try? keyChain.clear()
|
||||
if let v = value {
|
||||
try? keyChain.add(credentials: v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Sets the base url of the mowesta service
|
||||
public func setUrl(_ url: String) {
|
||||
UserDefaults.standard.set(url, forKey: "accountUrl")
|
||||
updateUrl()
|
||||
}
|
||||
|
||||
/// Updates the url of the api client
|
||||
private func updateUrl() {
|
||||
if let u = UserDefaults.standard.string(forKey: "accountUrl") {
|
||||
OpenAPIClientAPI.basePath = u
|
||||
}
|
||||
}
|
||||
|
||||
// Resets the device completely.
|
||||
public func reset() {
|
||||
device = nil
|
||||
terms = 0
|
||||
development = false
|
||||
token = ""
|
||||
device = ""
|
||||
}
|
||||
|
||||
private init() {
|
||||
self.keyChain = KeyChain(server: "www.mowesta.com")
|
||||
updateUrl()
|
||||
if let data = UserDefaults.standard.object(forKey: "device") as? Data,
|
||||
let value = try? JSONDecoder().decode(Device.self, from: data) {
|
||||
loadedDevice = value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private struct AppStateKey: EnvironmentKey {
|
||||
static let defaultValue: AppState = AppState()
|
||||
}
|
||||
|
||||
extension EnvironmentValues {
|
||||
var appState: AppState {
|
||||
get { self[AppStateKey.self] }
|
||||
set { self[AppStateKey.self] = newValue }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,24 +6,190 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
import MoWeStaApi
|
||||
|
||||
public enum UnitSystem {
|
||||
case SI
|
||||
case IM
|
||||
case BOTH
|
||||
public enum UnitSystem: Codable {
|
||||
case si
|
||||
case imperial
|
||||
case both
|
||||
}
|
||||
|
||||
public enum TemperatureUnit: Codable {
|
||||
case celsius
|
||||
case fahrenheit
|
||||
case both
|
||||
}
|
||||
|
||||
public class DataBindings {
|
||||
|
||||
|
||||
|
||||
|
||||
public static func getTemperature(_ value: Double, _ system: UnitSystem) -> String {
|
||||
return "";
|
||||
public static func getTemperature(_ value: Double, _ unit: TemperatureUnit) -> LocalizedStringKey {
|
||||
switch unit {
|
||||
case .celsius:
|
||||
return "format_temperature_celsius \(value)"
|
||||
case .fahrenheit:
|
||||
return "format_temperature_fahrenheit \(UnitConverter.celsiusToFahrenheit(value))"
|
||||
case .both:
|
||||
return "format_temperature_both \(value) \(UnitConverter.celsiusToFahrenheit(value))"
|
||||
}
|
||||
}
|
||||
|
||||
public static func getPressure(_ value: Double, _ system: UnitSystem) -> LocalizedStringKey {
|
||||
switch system {
|
||||
case .si:
|
||||
return "format_pressure_si \(value)"
|
||||
case .imperial:
|
||||
return "format_pressure_imperial \(UnitConverter.hpaToPsi(value))"
|
||||
case .both:
|
||||
return "format_pressure_both \(value) \(UnitConverter.hpaToPsi(value))"
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static func getHumidity(_ value: Double) -> LocalizedStringKey {
|
||||
return "format_humidity \(value)"
|
||||
}
|
||||
|
||||
public static func getCloudCoverage(_ value: Double) -> LocalizedStringKey {
|
||||
return "format_cloud_coverage \(value)"
|
||||
}
|
||||
|
||||
|
||||
public static func getWindSpeed(_ value: Double, _ system: UnitSystem) -> LocalizedStringKey {
|
||||
switch system {
|
||||
case .si:
|
||||
return "format_wind_speed_si \(UnitConverter.mpsToKmph(value)) \(UnitConverter.mpsToBFT(value))"
|
||||
case .imperial:
|
||||
return "format_wind_speed_imperial \(UnitConverter.mpsToMph(value)) \(UnitConverter.mpsToBFT(value))"
|
||||
case .both:
|
||||
return "format_wind_speed_both \(UnitConverter.mpsToKmph(value)) \(UnitConverter.mpsToMph(value))"
|
||||
}
|
||||
}
|
||||
|
||||
public static func getPrecipitation(_ value: Double, _ system: UnitSystem) -> LocalizedStringKey {
|
||||
switch system {
|
||||
case .si:
|
||||
return "format_precipitation_si \(value)"
|
||||
case .imperial:
|
||||
return "format_precipitation_imperial \(UnitConverter.mmToIn(value))"
|
||||
case .both:
|
||||
return "format_precipitation_both \(value) \(UnitConverter.mmToIn(value))"
|
||||
}
|
||||
}
|
||||
|
||||
public static func getSnow(_ value: Double, _ system: UnitSystem) -> LocalizedStringKey {
|
||||
switch system {
|
||||
case .si:
|
||||
return "format_snow_si \(value)"
|
||||
case .imperial:
|
||||
return "format_snow_imperial \(UnitConverter.mToFt(value))"
|
||||
case .both:
|
||||
return "format_snow_both \(value) \(UnitConverter.mToFt(value))"
|
||||
}
|
||||
}
|
||||
|
||||
public static func getAltitude(_ value: Double, _ system: UnitSystem) -> LocalizedStringKey {
|
||||
switch system {
|
||||
case .si:
|
||||
return "format_altitude_si \(value)"
|
||||
case .imperial:
|
||||
return "format_altitude_imperial \(UnitConverter.mToFt(value))"
|
||||
case .both:
|
||||
return "format_altitude_both \(value) \(UnitConverter.mToFt(value))"
|
||||
}
|
||||
}
|
||||
|
||||
public static func getWindDirection(_ value: WeatherCondition.WindDirection) -> Angle {
|
||||
switch value {
|
||||
case .unknown, .north:
|
||||
return Angle(degrees: 0)
|
||||
case .northEast:
|
||||
return Angle(degrees: 45)
|
||||
case .east:
|
||||
return Angle(degrees: 90)
|
||||
case .southEast:
|
||||
return Angle(degrees: 135)
|
||||
case .south:
|
||||
return Angle(degrees: 180)
|
||||
case .southWest:
|
||||
return Angle(degrees: -135)
|
||||
case .west:
|
||||
return Angle(degrees: -90)
|
||||
case .northWest:
|
||||
return Angle(degrees: -45)
|
||||
}
|
||||
}
|
||||
|
||||
public static func getDate(_ timestamp: Int64, _ timezone: String?) -> String {
|
||||
let time = Double(timestamp) / 1000.0
|
||||
let formatter = DateFormatter()
|
||||
let format = NSLocalizedString("format_date", comment: "")
|
||||
formatter.locale = Locale.current
|
||||
formatter.dateFormat = format.stringValue
|
||||
if let tz = timezone, let zone = TimeZone(identifier: tz) {
|
||||
formatter.timeZone = zone
|
||||
}
|
||||
return formatter.string(from: Date(timeIntervalSince1970: time))
|
||||
}
|
||||
|
||||
public static func getTime(_ timestamp: Int64, _ timezone: String?) -> String {
|
||||
let time = Double(timestamp) / 1000.0
|
||||
let formatter = DateFormatter()
|
||||
let format = NSLocalizedString("format_time", comment: "")
|
||||
formatter.locale = Locale.current
|
||||
formatter.dateFormat = format.stringValue
|
||||
if let tz = timezone, let zone = TimeZone(identifier: tz) {
|
||||
formatter.timeZone = zone
|
||||
}
|
||||
return formatter.string(from: Date(timeIntervalSince1970: time))
|
||||
}
|
||||
|
||||
public static func getHour(_ timestamp: Int64, _ timezone: String?) -> Int {
|
||||
let time = Double(timestamp) / 1000.0
|
||||
let formatter = DateFormatter()
|
||||
formatter.locale = Locale(identifier: "de_DE")
|
||||
formatter.dateFormat = "HH"
|
||||
if let tz = timezone, let zone = TimeZone(identifier: tz) {
|
||||
formatter.timeZone = zone
|
||||
}
|
||||
return Int(formatter.string(from: Date(timeIntervalSince1970: time)))!
|
||||
}
|
||||
|
||||
public static func getWeekday(_ timestamp: Int64, _ timezone: String?) -> String {
|
||||
let now = Date()
|
||||
let tomorrow = getDate(Int64(Calendar.current.date(byAdding: .day, value: 1, to: now)!.timeIntervalSince1970 * 1000), nil)
|
||||
let yesterday = getDate(Int64(Calendar.current.date(byAdding: .day, value: -1, to: now)!.timeIntervalSince1970 * 1000), nil)
|
||||
let today = getDate(Int64(now.timeIntervalSince1970 * 1000), nil)
|
||||
let date = getDate(timestamp, timezone)
|
||||
if date == tomorrow {
|
||||
return NSLocalizedString("date_tomorrow", comment: "")
|
||||
} else if date == today {
|
||||
return NSLocalizedString("date_today", comment: "")
|
||||
} else if date == yesterday {
|
||||
return NSLocalizedString("date_yesterday", comment: "")
|
||||
} else {
|
||||
let formatter = DateFormatter()
|
||||
formatter.locale = Locale.current
|
||||
formatter.dateFormat = "EEEE"
|
||||
if let tz = timezone, let zone = TimeZone(identifier: tz) {
|
||||
formatter.timeZone = zone
|
||||
}
|
||||
return formatter.string(from: Date(timeIntervalSince1970: Double(timestamp) / 1000))
|
||||
}
|
||||
}
|
||||
|
||||
public static func getInterval(_ timestamp: Int64, _ timezone: String?) -> String {
|
||||
let hour = getHour(timestamp, timezone)
|
||||
if hour < 6 {
|
||||
return NSLocalizedString("label_night", comment: "")
|
||||
} else if hour < 12 {
|
||||
return NSLocalizedString("label_morning", comment: "")
|
||||
} else if hour < 18 {
|
||||
return NSLocalizedString("label_afternoon", comment: "")
|
||||
} else {
|
||||
return NSLocalizedString("label_evening", comment: "")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
//
|
||||
// ColorScheme.swift - Color schemes for rendering data
|
||||
//
|
||||
// Created by Marcus Handte on 23.07.22.
|
||||
//
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
/// Base class for color schemes
|
||||
public class DataColorScheme {
|
||||
public func getColor(_ data: Double) -> UInt32 {
|
||||
return 0xFFFFFFFF
|
||||
}
|
||||
|
||||
public func color(_ data: Double) -> Color {
|
||||
let color = getColor(data)
|
||||
let alpha = Double((color >> 24) & 0xFF) / 255
|
||||
let red = Double((color >> 16) & 0xFF) / 255
|
||||
let green = Double((color >> 8) & 0xFF) / 255
|
||||
let blue = Double(color & 0xFF) / 255
|
||||
return Color(red: red, green: green, blue: blue, opacity: alpha)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// Color support at a particular value
|
||||
public struct ColorSupport {
|
||||
let value: Double
|
||||
let red: UInt8
|
||||
let green: UInt8
|
||||
let blue: UInt8
|
||||
let alpha: UInt8
|
||||
let color: UInt32
|
||||
|
||||
public init(value: Double, color: UInt32) {
|
||||
self.value = value
|
||||
self.alpha = UInt8((color >> 24) & 0xFF)
|
||||
self.red = UInt8((color >> 16) & 0xFF)
|
||||
self.green = UInt8((color >> 8) & 0xFF)
|
||||
self.blue = UInt8(color & 0xFF)
|
||||
self.color = color
|
||||
}
|
||||
}
|
||||
|
||||
/// A color scheme that perform interpolation at given support points
|
||||
public class InterpolatedColorScheme: DataColorScheme {
|
||||
|
||||
let supports: [ColorSupport]
|
||||
let interpolation: Interpolation
|
||||
|
||||
public init(supports: [ColorSupport], interpolation: Interpolation) {
|
||||
self.supports = supports.sorted(by: { a, b in return a.value <= b.value })
|
||||
self.interpolation = interpolation
|
||||
}
|
||||
|
||||
public override func getColor(_ data: Double) -> UInt32 {
|
||||
if let first = supports.first {
|
||||
if data < first.value {
|
||||
return first.color
|
||||
}
|
||||
for i in 1..<supports.count {
|
||||
if supports[i].value > data {
|
||||
return getColor(supports[i - 1], supports[i], data)
|
||||
}
|
||||
}
|
||||
return supports[supports.count - 1].color
|
||||
} else {
|
||||
return super.getColor(data)
|
||||
}
|
||||
}
|
||||
|
||||
func getColor(_ from: ColorSupport, _ to: ColorSupport, _ at: Double) -> UInt32 {
|
||||
let fraction = (at - from.value) / (to.value - from.value)
|
||||
let alpha = getColor(from.alpha, to.alpha, fraction)
|
||||
let red = getColor(from.red, to.red, fraction)
|
||||
let green = getColor(from.green, to.green, fraction)
|
||||
let blue = getColor(from.blue, to.blue, fraction)
|
||||
return (UInt32(alpha) << 24) | (UInt32(red) << 16) | (UInt32(green) << 8) | UInt32(blue)
|
||||
}
|
||||
|
||||
func getColor(_ from: UInt8, _ to: UInt8, _ at: Double) -> UInt8 {
|
||||
return UInt8(min(255, max(0, interpolation.interpolate(from: Double(from), to: Double(to), at: at))))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// MoWeSta specific color schemes
|
||||
public struct DataColorSchemes {
|
||||
|
||||
/// scheme for cloud cover
|
||||
let whiteCloud = InterpolatedColorScheme(supports: [
|
||||
ColorSupport(value: 0, color: 0x00FFFFFF),
|
||||
ColorSupport(value: 1, color: 0xFFFFFFFF)
|
||||
], interpolation: LinearInterpolation())
|
||||
|
||||
// scheme for temperature
|
||||
let scientificTemperature = InterpolatedColorScheme(supports: [
|
||||
ColorSupport(value: -35, color: 0xFF0000FB),
|
||||
ColorSupport(value: -30, color: 0xFF2E46FF),
|
||||
ColorSupport(value: -25, color: 0xFF3974FF),
|
||||
ColorSupport(value: -20, color: 0xFF39A9FF),
|
||||
ColorSupport(value: -15, color: 0xFF29DBFF),
|
||||
ColorSupport(value: -10, color: 0xFF30FFEF),
|
||||
ColorSupport(value: -5, color: 0xFF88FFBE),
|
||||
ColorSupport(value: 0, color: 0xFFB6FE8E),
|
||||
ColorSupport(value: 0, color: 0xFFFFFF00),
|
||||
ColorSupport(value: 5, color: 0xFFDAFF61),
|
||||
ColorSupport(value: 10, color: 0xFFF8FF26),
|
||||
ColorSupport(value: 15, color: 0xFFFEE100),
|
||||
ColorSupport(value: 20, color: 0xFFFFB200),
|
||||
ColorSupport(value: 25, color: 0xFFFE8500),
|
||||
ColorSupport(value: 30, color: 0xFFFF5100),
|
||||
ColorSupport(value: 35, color: 0xFFB30000)
|
||||
], interpolation: LinearInterpolation())
|
||||
|
||||
/// dynamic scheme for pressure
|
||||
public func pressure(min: Double, max: Double, avg: Double) -> InterpolatedColorScheme {
|
||||
return InterpolatedColorScheme(supports: [
|
||||
ColorSupport(value: min, color: 0xFF000000),
|
||||
ColorSupport(value: avg, color: 0xFF0000FF),
|
||||
ColorSupport(value: max, color: 0xFFFF00FF)
|
||||
], interpolation: LinearInterpolation())
|
||||
}
|
||||
|
||||
/// scheme for precipitation
|
||||
let precipitation = InterpolatedColorScheme(supports: [
|
||||
ColorSupport(value: 0, color: 0x0000000),
|
||||
ColorSupport(value: 0.1, color: 0x88008800),
|
||||
ColorSupport(value: 1, color: 0xFF00FF00), // Nieselregen (<1)
|
||||
ColorSupport(value: 10, color: 0xFF00FFFF),
|
||||
ColorSupport(value: 20, color: 0xFF0000FF), // Starkregen (>20)
|
||||
ColorSupport(value: 20, color: 0xFF880000),
|
||||
ColorSupport(value: 35, color: 0xFFFF0000), // Unwetter (>35)
|
||||
], interpolation: LinearInterpolation())
|
||||
|
||||
/// scheme for humidity
|
||||
let humidity = InterpolatedColorScheme(supports: [
|
||||
ColorSupport(value: 0, color: 0x0042BAD0),
|
||||
ColorSupport(value: 100, color: 0xFF42BAD0)
|
||||
], interpolation: LinearInterpolation())
|
||||
|
||||
/// scheme for depth
|
||||
let cloudDepth = InterpolatedColorScheme(supports: [
|
||||
ColorSupport(value: 0, color: 0x00FFFFFF),
|
||||
ColorSupport(value: 1, color: 0xFF999999)
|
||||
], interpolation: LinearInterpolation())
|
||||
|
||||
/// windspeed
|
||||
let windSpeed = InterpolatedColorScheme(supports: [
|
||||
ColorSupport(value: 0.5, color: 0xff7ec1d9),
|
||||
ColorSupport(value: 1.5, color: 0xff8ed1d9),
|
||||
ColorSupport(value: 3.3, color: 0xff8ed1d9),
|
||||
ColorSupport(value: 5.5, color: 0xff8ed1d9),
|
||||
ColorSupport(value: 7.9, color: 0xff8ed1d9),
|
||||
ColorSupport(value: 10.7, color: 0xff8ed1d9),
|
||||
ColorSupport(value: 13.8, color: 0xff8ed1d9),
|
||||
ColorSupport(value: 17.1, color: 0xff8ed1d9),
|
||||
ColorSupport(value: 20.7, color: 0xff8ed1d9),
|
||||
ColorSupport(value: 24.4, color: 0xff8ed1d9),
|
||||
ColorSupport(value: 28.4, color: 0xff8ed1d9),
|
||||
ColorSupport(value: 32.6, color: 0xff8ed1d9),
|
||||
ColorSupport(value: 32.7, color: 0xff8ed1d9)
|
||||
], interpolation: Interpolation())
|
||||
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
//
|
||||
// Favorite.swift
|
||||
// App
|
||||
//
|
||||
// Created by Marcus Handte on 15.07.22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import MoWeStaApi
|
||||
import AnyCodable
|
||||
|
||||
/// Extends the favorite entity generated by core data with additional properties (implemented via associated objects)
|
||||
/// to simplify the access to json encoded data stored in the database and to avoid repeated loading and unloading.
|
||||
extension Favorite {
|
||||
|
||||
/// The location which should be a city, state or country
|
||||
public var locationValue: Any? {
|
||||
get {
|
||||
if let loc = location, let data = loc.data(using: .utf8) {
|
||||
switch getLocationType() {
|
||||
case .city:
|
||||
return try? JSONDecoder().decode(City.self, from: data)
|
||||
case .country:
|
||||
return try? JSONDecoder().decode(Country.self, from: data)
|
||||
case .state:
|
||||
return try? JSONDecoder().decode(State.self, from: data)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
set {
|
||||
if let nv = newValue as? City {
|
||||
if let data = try? JSONEncoder().encode(nv) {
|
||||
location = String(decoding: data, as: UTF8.self)
|
||||
} else {
|
||||
location = nil
|
||||
}
|
||||
} else if let nv = newValue as? State {
|
||||
if let data = try? JSONEncoder().encode(nv) {
|
||||
location = String(decoding: data, as: UTF8.self)
|
||||
} else {
|
||||
location = nil
|
||||
}
|
||||
} else if let nv = newValue as? Country {
|
||||
if let data = try? JSONEncoder().encode(nv) {
|
||||
location = String(decoding: data, as: UTF8.self)
|
||||
} else {
|
||||
location = nil
|
||||
}
|
||||
} else {
|
||||
location = nil
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// The city
|
||||
public var cityValue: City? {
|
||||
get {
|
||||
if let c = city, let data = c.data(using: .utf8) {
|
||||
return try? JSONDecoder().decode(City.self, from: data)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
set {
|
||||
if let v = newValue, let data = try? JSONEncoder().encode(v) {
|
||||
city = String(decoding: data, as: UTF8.self)
|
||||
} else {
|
||||
city = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The weather condition.
|
||||
public var conditionValue: WeatherCondition? {
|
||||
get {
|
||||
if let c = condition, let data = c.data(using: .utf8) {
|
||||
return try? JSONDecoder().decode(WeatherCondition.self, from: data)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
set {
|
||||
if let v = newValue, let data = try? JSONEncoder().encode(v) {
|
||||
condition = String(decoding: data, as: UTF8.self)
|
||||
} else {
|
||||
condition = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The weather forecast.
|
||||
public var forecastValue: WeatherForecast? {
|
||||
get {
|
||||
if let f = forecast, let data = f.data(using: .utf8) {
|
||||
return try? JSONDecoder().decode(WeatherForecast.self, from: data)
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
set {
|
||||
if let v = newValue, let data = try? JSONEncoder().encode(v) {
|
||||
forecast = String(decoding: data, as: UTF8.self)
|
||||
} else {
|
||||
forecast = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The weatehr station
|
||||
public var stationValue: WeatherStation? {
|
||||
get {
|
||||
if let s = station, let data = s.data(using: .utf8) {
|
||||
return try? JSONDecoder().decode(WeatherStation.self, from: data)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
set {
|
||||
if let v = newValue, let data = try? JSONEncoder().encode(v) {
|
||||
station = String(decoding: data, as: UTF8.self)
|
||||
} else {
|
||||
station = nil
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// The boundary
|
||||
public var boundaryValue: Geometry? {
|
||||
get {
|
||||
if let b = boundary, let data = b.data(using: .utf8) {
|
||||
return try? JSONDecoder().decode(Geometry.self, from: data)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
set {
|
||||
if let v = newValue, let data = try? JSONEncoder().encode(v) {
|
||||
boundary = String(decoding: data, as: UTF8.self)
|
||||
} else {
|
||||
boundary = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Returns the loation type
|
||||
public func getLocationType() -> LocationHierarchy.ModelType {
|
||||
if (self.locationType == 2) {
|
||||
return .country
|
||||
} else if (self.locationType == 1) {
|
||||
return .state
|
||||
} else {
|
||||
return .city
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Sets the location type.
|
||||
public func setLocationType(type: LocationHierarchy.ModelType) {
|
||||
switch (type) {
|
||||
case .city:
|
||||
locationType = 0
|
||||
case .state:
|
||||
locationType = 1
|
||||
case .country:
|
||||
locationType = 2
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the loation type
|
||||
public func getLocationReferenceType() -> LocationReference.ModelType {
|
||||
if (self.locationType == 2) {
|
||||
return .country
|
||||
} else if (self.locationType == 1) {
|
||||
return .state
|
||||
} else {
|
||||
return .city
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the location type.
|
||||
public func setLocationReferenceType(type: LocationReference.ModelType) {
|
||||
switch (type) {
|
||||
case .city:
|
||||
locationType = 0
|
||||
case .state:
|
||||
locationType = 1
|
||||
case .country:
|
||||
locationType = 2
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
//
|
||||
// Favorites.swift
|
||||
// App
|
||||
//
|
||||
// Created by Marcus Handte on 23.07.22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import CoreData
|
||||
|
||||
struct Favorites {
|
||||
|
||||
public static func canDelete(_ favorite: Favorite?) -> Bool {
|
||||
if let f = favorite {
|
||||
return !f.removed && !f.isDeleted
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
public static func delete(_ context: NSManagedObjectContext, _ favorite: Favorite?) {
|
||||
if let f = favorite {
|
||||
if f.added {
|
||||
f.removed = true
|
||||
} else {
|
||||
context.delete(f)
|
||||
}
|
||||
do {
|
||||
try context.save()
|
||||
} catch {
|
||||
context.reset()
|
||||
}
|
||||
}
|
||||
BaseTask.execute(all: [SyncTask()]) { success in
|
||||
print("Successful update: \(success)")
|
||||
}
|
||||
}
|
||||
|
||||
public static func add(_ context: NSManagedObjectContext, _ favorite: Favorite?, values: (Favorite)->Void) {
|
||||
var fav: Favorite
|
||||
if let f = favorite {
|
||||
if f.isDeleted {
|
||||
f.removed = false
|
||||
fav = f
|
||||
} else {
|
||||
fav = Favorite(context: context)
|
||||
context.insert(fav)
|
||||
}
|
||||
} else {
|
||||
fav = Favorite(context: context)
|
||||
context.insert(fav)
|
||||
}
|
||||
values(fav)
|
||||
fav.position = Favorites.position(context) + 1
|
||||
do {
|
||||
try context.save()
|
||||
} catch {
|
||||
context.reset()
|
||||
}
|
||||
BaseTask.execute(all: [SyncTask(), RefreshTask()]) { success in
|
||||
print("Successful update: \(success)")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static func position(_ context: NSManagedObjectContext) -> Int16 {
|
||||
let request = NSFetchRequest<NSFetchRequestResult>()
|
||||
request.entity = Favorite.entity()
|
||||
request.resultType = .dictionaryResultType
|
||||
let expression = NSExpressionDescription()
|
||||
expression.name = "maxpos"
|
||||
expression.expression = NSExpression(forFunction: "max:", arguments: [NSExpression(forKeyPath: "position")])
|
||||
expression.expressionResultType = .integer16AttributeType
|
||||
request.propertiesToFetch = [ expression]
|
||||
request.resultType = .dictionaryResultType
|
||||
if let result = try? context.fetch(request) as? [[String:Int16]], let r = result.first, let res = r["maxpos"] {
|
||||
return res
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import Foundation
|
||||
|
||||
import class MoWeStaApi.LocationHierarchy
|
||||
import class MoWeStaApi.WeatherCondition
|
||||
import class MoWeStaApi.Device
|
||||
|
||||
public class ImageBindings {
|
||||
|
||||
@@ -50,7 +51,7 @@ public class ImageBindings {
|
||||
case .rainShowerSlight:
|
||||
return alternate ? "icon_night_showers" : "icon_day_showers"
|
||||
case .rainShowerModerateHeavy:
|
||||
return "icon_showers"
|
||||
return "icon_day_showers"
|
||||
case .rainShowerViolent:
|
||||
return "icon_storm_showers"
|
||||
case .snowShowerSlight:
|
||||
@@ -66,4 +67,15 @@ public class ImageBindings {
|
||||
}
|
||||
}
|
||||
|
||||
public static func getDeviceIcon(_ os: Device.Os) -> String {
|
||||
switch os {
|
||||
case .android:
|
||||
return "icon_android"
|
||||
case .arduino:
|
||||
return "icon_arduino"
|
||||
case .ios:
|
||||
return "icon_ios"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// Interpolations.swift
|
||||
// App
|
||||
//
|
||||
// Created by Marcus Handte on 23.07.22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// Base class for interpolations that implements a step function
|
||||
public class Interpolation {
|
||||
|
||||
/// Performs step interpolation with a breakpoint set to 0.5
|
||||
public func interpolate(from x: Double, to y: Double, at: Double) -> Double {
|
||||
return at < 0.5 ? x : y
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// A linear interpolation betwen x and y.
|
||||
public class LinearInterpolation: Interpolation {
|
||||
|
||||
/// Performs a linear interpolation between x (at 0) and y (at 1)
|
||||
public override func interpolate(from x: Double, to y: Double, at: Double) -> Double {
|
||||
return x + (y - x) * min(1, max(0, at));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,11 @@ import SwiftUI
|
||||
import class MoWeStaApi.City
|
||||
import class MoWeStaApi.LocationHierarchy
|
||||
import class MoWeStaApi.WeatherCondition
|
||||
import class MoWeStaApi.WeatherVideo
|
||||
import class MoWeStaApi.WeatherStation
|
||||
import class MoWeStaApi.State
|
||||
import class MoWeStaApi.Country
|
||||
import class MoWeStaApi.Device
|
||||
|
||||
public class TextBindings {
|
||||
|
||||
@@ -31,6 +36,24 @@ public class TextBindings {
|
||||
}
|
||||
}
|
||||
|
||||
public static func getName(_ state: State?, _ country: Country?) -> String? {
|
||||
var strings: [String] = [ ];
|
||||
if let s = state, let stateName = getName(s.names, true) {
|
||||
strings.append(stateName)
|
||||
}
|
||||
if let c = country, let countryName = getName(c.names, true) {
|
||||
strings.append(countryName)
|
||||
}
|
||||
if strings.count == 1 {
|
||||
return strings.first!
|
||||
} else if strings.count == 2 {
|
||||
return "\(strings[0]), \(strings[1])"
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static func getLocationName(_ hierarchy: LocationHierarchy) -> String {
|
||||
if let name = getName(hierarchy.names, false) {
|
||||
return name
|
||||
@@ -54,6 +77,15 @@ public class TextBindings {
|
||||
}
|
||||
return string
|
||||
}
|
||||
|
||||
public static func getRegionName(_ city: City) -> String {
|
||||
let name = getName(city.country.names, false)!
|
||||
if let s = city.state {
|
||||
return "\(getName(s.names, true)!), \(name)"
|
||||
} else {
|
||||
return name
|
||||
}
|
||||
}
|
||||
|
||||
public static func getCityType(_ city: City) -> LocalizedStringKey {
|
||||
switch (city.type) {
|
||||
@@ -68,7 +100,7 @@ public class TextBindings {
|
||||
}
|
||||
}
|
||||
|
||||
public static func getWeatherSource(_ condition: WeatherCondition) -> LocalizedStringKey {
|
||||
public static func getWeatherSource(_ condition: WeatherCondition) -> String {
|
||||
switch (condition.source) {
|
||||
case WeatherCondition.Source.cosmoEurope:
|
||||
return "source_cosmo_europe"
|
||||
@@ -143,5 +175,81 @@ public class TextBindings {
|
||||
}
|
||||
}
|
||||
|
||||
public static func getWindDirection(_ value: WeatherCondition.WindDirection) -> LocalizedStringKey {
|
||||
switch value {
|
||||
case .unknown, .north:
|
||||
return "direction_north"
|
||||
case .northEast:
|
||||
return "direction_north_east"
|
||||
case .east:
|
||||
return "direction_east"
|
||||
case .southEast:
|
||||
return "direction_south_east"
|
||||
case .south:
|
||||
return "direction_south"
|
||||
case .southWest:
|
||||
return "direction_south_west"
|
||||
case .west:
|
||||
return "direction_west"
|
||||
case .northWest:
|
||||
return "direction_north_west"
|
||||
}
|
||||
}
|
||||
|
||||
public static func getUnitSystem(_ value: UnitSystem) -> LocalizedStringKey {
|
||||
switch (value) {
|
||||
case .imperial:
|
||||
return "customize_system_imperial"
|
||||
case .si:
|
||||
return "customize_system_standard"
|
||||
case .both:
|
||||
return "customize_system_both"
|
||||
}
|
||||
}
|
||||
|
||||
public static func getTemperatureUnit(_ value: TemperatureUnit) -> LocalizedStringKey {
|
||||
switch (value) {
|
||||
case .celsius:
|
||||
return "customize_temperature_celsius"
|
||||
case .fahrenheit:
|
||||
return "customize_temperature_fahrenheit"
|
||||
case .both:
|
||||
return "customize_temperature_both"
|
||||
}
|
||||
}
|
||||
|
||||
public static func getVideoType(_ value: WeatherVideo.ModelType) -> LocalizedStringKey {
|
||||
switch value {
|
||||
case .pressure:
|
||||
return "video_type_pressure"
|
||||
case .precipitation:
|
||||
return "video_type_precipitation"
|
||||
case .cloud:
|
||||
return "video_type_cloud"
|
||||
case .temperature:
|
||||
return "video_type_temperature"
|
||||
case .wind:
|
||||
return "video_type_wind"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static func getOperatorName(_ value: WeatherStation.Operator) -> LocalizedStringKey{
|
||||
switch value {
|
||||
case .dwd:
|
||||
return "operator_dwd"
|
||||
}
|
||||
}
|
||||
|
||||
public static func getDeviceOs(_ value: Device.Os) -> LocalizedStringKey {
|
||||
switch value {
|
||||
case .ios:
|
||||
return "label_device_type_ios"
|
||||
case .arduino:
|
||||
return "label_device_type_arduino"
|
||||
case .android:
|
||||
return "label_device_type_android"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,331 @@
|
||||
//
|
||||
// WeatherAggregates.swift
|
||||
// App
|
||||
//
|
||||
// Created by Marcus Handte on 17.07.22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
import class MoWeStaApi.WeatherCondition
|
||||
import class MoWeStaApi.WeatherForecast
|
||||
|
||||
|
||||
struct WeatherSummary: Identifiable {
|
||||
let id = UUID()
|
||||
let title: LocalizedStringKey
|
||||
let subtitle: LocalizedStringKey
|
||||
let min: WeatherCondition
|
||||
let max: WeatherCondition
|
||||
|
||||
init?(title: LocalizedStringKey, subtitle: LocalizedStringKey, conditions: [WeatherCondition]) {
|
||||
self.title = title
|
||||
self.subtitle = subtitle
|
||||
if let f = conditions.first {
|
||||
min = f.copy()
|
||||
max = f.copy()
|
||||
for c in conditions {
|
||||
min.cloudCoverage = Swift.min(min.cloudCoverage, c.cloudCoverage)
|
||||
min.windSpeed = Swift.min(min.windSpeed, c.windSpeed)
|
||||
if (min.windSpeed == c.windSpeed) {
|
||||
min.windDirection = c.windDirection
|
||||
}
|
||||
min.temperature = Swift.min(min.temperature, c.temperature)
|
||||
min.snowDepth = Swift.min(min.snowDepth, c.snowDepth)
|
||||
min.pressure = Swift.min(min.pressure, c.pressure)
|
||||
min.precipitation = Swift.min(min.precipitation, c.precipitation)
|
||||
min.humidity = Swift.min(min.humidity, c.humidity)
|
||||
min.cloudDepth = Swift.min(min.cloudDepth, c.cloudDepth)
|
||||
min.type = mini(min.type, c.type)
|
||||
min.source = mini(min.source, c.source)
|
||||
|
||||
max.cloudCoverage = Swift.max(max.cloudCoverage, c.cloudCoverage)
|
||||
max.windSpeed = Swift.max(max.windSpeed, c.windSpeed)
|
||||
if (max.windSpeed == c.windSpeed) {
|
||||
max.windDirection = c.windDirection
|
||||
}
|
||||
max.temperature = Swift.max(max.temperature, c.temperature)
|
||||
max.snowDepth = Swift.max(max.snowDepth, c.snowDepth)
|
||||
max.pressure = Swift.max(max.pressure, c.pressure)
|
||||
max.precipitation = Swift.max(max.precipitation, c.precipitation)
|
||||
max.humidity = Swift.max(max.humidity, c.humidity)
|
||||
max.cloudDepth = Swift.max(max.cloudDepth, c.cloudDepth)
|
||||
max.type = maxi(max.type, c.type)
|
||||
max.source = maxi(max.source, c.source)
|
||||
}
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
private func mini(_ a: WeatherCondition.Source, _ b: WeatherCondition.Source) -> WeatherCondition.Source {
|
||||
let ra = getRank(a)
|
||||
let rb = getRank(b)
|
||||
if ra < 0 {
|
||||
return b
|
||||
}
|
||||
if rb < 0 {
|
||||
return a
|
||||
}
|
||||
return (ra < rb) ? a : b
|
||||
}
|
||||
|
||||
private func maxi(_ a: WeatherCondition.Source, _ b: WeatherCondition.Source) -> WeatherCondition.Source {
|
||||
let ra = getRank(a)
|
||||
let rb = getRank(b)
|
||||
if ra < 0 {
|
||||
return b
|
||||
}
|
||||
if rb < 0 {
|
||||
return a
|
||||
}
|
||||
return (ra > rb) ? a : b
|
||||
}
|
||||
|
||||
private func mini(_ a: WeatherCondition.ModelType, _ b: WeatherCondition.ModelType) -> WeatherCondition.ModelType {
|
||||
let ra = getRank(a)
|
||||
let rb = getRank(b)
|
||||
if ra < 0 {
|
||||
return b
|
||||
}
|
||||
if rb < 0 {
|
||||
return a
|
||||
}
|
||||
return (ra < rb) ? a : b
|
||||
}
|
||||
|
||||
private func maxi(_ a: WeatherCondition.ModelType, _ b: WeatherCondition.ModelType) -> WeatherCondition.ModelType {
|
||||
let ra = getRank(a)
|
||||
let rb = getRank(b)
|
||||
if ra < 0 {
|
||||
return b
|
||||
}
|
||||
if rb < 0 {
|
||||
return a
|
||||
}
|
||||
return (ra > rb) ? a : b
|
||||
}
|
||||
|
||||
private func getRank(_ source: WeatherCondition.Source) -> Int {
|
||||
switch (source) {
|
||||
case .iconGlobal:
|
||||
return 2;
|
||||
case .iconEurope:
|
||||
return 1;
|
||||
case .cosmoEurope:
|
||||
return 0;
|
||||
case .weatherStation:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private func getRank(_ type: WeatherCondition.ModelType) -> Int {
|
||||
switch (type) {
|
||||
case .clearSky:
|
||||
return 0
|
||||
case .mainlyClear:
|
||||
return 1
|
||||
case .partlyCloudy:
|
||||
return 2
|
||||
case .cloudy:
|
||||
return 3
|
||||
case .fog:
|
||||
return 4
|
||||
case .fogDepositingRime:
|
||||
return 5
|
||||
case .slightDrizzle:
|
||||
return 6
|
||||
case .slightRainNotFreezing:
|
||||
return 7
|
||||
case .rainShowerSlight:
|
||||
return 8
|
||||
case .drizzleFreezingSlight:
|
||||
return 9
|
||||
case .rainFreezingSlight:
|
||||
return 10
|
||||
case .slightFallOfSnowflakes:
|
||||
return 11
|
||||
case .snowShowerSlight:
|
||||
return 12
|
||||
case .moderateDrizzle:
|
||||
return 13
|
||||
case .heavyDrizzle:
|
||||
return 14
|
||||
case .moderateRainNotFreezing:
|
||||
return 15
|
||||
case .snowGrains:
|
||||
return 16
|
||||
case .moderateFallOfSnowflakes:
|
||||
return 17
|
||||
case .heavyRainNotFreezing:
|
||||
return 18
|
||||
case .drizzleFreezingModerateHeavy:
|
||||
return 19
|
||||
case .heavyFallOfSnowflakes:
|
||||
return 20
|
||||
case .rainShowerModerateHeavy:
|
||||
return 21
|
||||
case .rainFreezingModerateHeavy:
|
||||
return 22
|
||||
case .snowShowerModerateHeavy:
|
||||
return 23
|
||||
case .rainShowerViolent:
|
||||
return 24
|
||||
case .thunderstormSlightModerate:
|
||||
return 25
|
||||
case .thunderstormHailHeavy:
|
||||
return 26
|
||||
default:
|
||||
return -1
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension WeatherCondition {
|
||||
func copy() -> WeatherCondition {
|
||||
return WeatherCondition(cloudCoverage: cloudCoverage, cloudDepth: cloudDepth, duration: duration, hour: hour, humidity: humidity, precipitation: precipitation, pressure: pressure, snowDepth: snowDepth, source: source, temperature: temperature, time: time, type: type, windDirection: windDirection, windSpeed: windSpeed)
|
||||
}
|
||||
}
|
||||
|
||||
struct WeatherEntry: Identifiable {
|
||||
let id = UUID()
|
||||
let title: LocalizedStringKey
|
||||
let subtitle: LocalizedStringKey
|
||||
let condition: WeatherCondition
|
||||
}
|
||||
|
||||
|
||||
public class WeatherAggregate {
|
||||
|
||||
var hours: [WeatherEntry] = []
|
||||
var times: [WeatherSummary] = []
|
||||
var days: [WeatherSummary] = []
|
||||
|
||||
init(_ conditions: [WeatherCondition], _ timezone: String?) {
|
||||
let input = conditions.sorted { a, b in
|
||||
return a.time < b.time
|
||||
}
|
||||
var times: [[WeatherCondition]] = []
|
||||
var days: [[WeatherCondition]] = []
|
||||
var currentDay: [WeatherCondition] = []
|
||||
var currentTime: [WeatherCondition] = []
|
||||
for w in input {
|
||||
let title = LocalizedStringKey("format_title \(DataBindings.getWeekday(w.time, timezone))")
|
||||
let subtitle = LocalizedStringKey("format_title \(DataBindings.getTime(w.time, timezone)) \(DataBindings.getDate(w.time, timezone))")
|
||||
hours.append(WeatherEntry(title: title, subtitle: subtitle , condition: w))
|
||||
if let c = currentDay.first {
|
||||
if DataBindings.getDate(c.time, timezone) == DataBindings.getDate(w.time, timezone) {
|
||||
currentDay.append(w)
|
||||
} else {
|
||||
days.append(currentDay)
|
||||
currentDay = [ w ]
|
||||
times.append(currentTime)
|
||||
currentTime = []
|
||||
}
|
||||
} else {
|
||||
currentDay.append(w)
|
||||
}
|
||||
if let c = currentTime.first {
|
||||
if DataBindings.getInterval(c.time, timezone) == DataBindings.getInterval(w.time, timezone) {
|
||||
currentTime.append(w)
|
||||
} else {
|
||||
times.append(currentTime)
|
||||
currentTime = [ w ]
|
||||
}
|
||||
} else {
|
||||
currentTime.append(w)
|
||||
}
|
||||
}
|
||||
if (!currentDay.isEmpty) {
|
||||
days.append(currentDay)
|
||||
}
|
||||
if (!currentTime.isEmpty) {
|
||||
times.append(currentTime)
|
||||
}
|
||||
for d in days {
|
||||
if let first = d.first {
|
||||
let title = LocalizedStringKey("format_title \(DataBindings.getWeekday(first.time, timezone))")
|
||||
let subtitle = LocalizedStringKey("label_full_day")
|
||||
self.days.append(WeatherSummary(title: title, subtitle: subtitle, conditions: d)!)
|
||||
}
|
||||
}
|
||||
for t in times {
|
||||
if let first = t.first {
|
||||
let title = LocalizedStringKey("format_title \(DataBindings.getWeekday(first.time, timezone))")
|
||||
let subtitle = LocalizedStringKey("format_title \(DataBindings.getInterval(first.time, timezone))")
|
||||
self.times.append(WeatherSummary(title: title, subtitle: subtitle, conditions: t)!)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class WeatherGradientData {
|
||||
|
||||
let hours: [Int64]
|
||||
let temp: [Double]
|
||||
let cloudDepth: [Double]
|
||||
let cloudCoverage: [Double]
|
||||
let windSpeed: [Double]
|
||||
let humidity: [Double]
|
||||
let precipitation: [Double]
|
||||
let pressure: [Double]
|
||||
let averagePressure: Double
|
||||
let minimumPressure: Double
|
||||
let maximumPressure: Double
|
||||
|
||||
init(_ forecast: WeatherForecast) {
|
||||
var hours: [Int64] = []
|
||||
var temp: [Double] = []
|
||||
var cloudDepth: [Double] = []
|
||||
var cloudCoverage: [Double] = []
|
||||
var windSpeed: [Double] = []
|
||||
var humidity: [Double] = []
|
||||
var precipitation: [Double] = []
|
||||
var pressure: [Double] = []
|
||||
for c in forecast.conditions.sorted(by: { a, b in return a.time <= b.time }) {
|
||||
for i in 0..<c.duration {
|
||||
hours.append(c.time + Int64(i) * 3600000)
|
||||
temp.append(c.temperature)
|
||||
cloudDepth.append(c.cloudDepth)
|
||||
cloudCoverage.append(c.cloudCoverage)
|
||||
windSpeed.append(c.windSpeed)
|
||||
humidity.append(c.humidity)
|
||||
precipitation.append(c.precipitation)
|
||||
pressure.append(c.pressure)
|
||||
}
|
||||
}
|
||||
self.hours = hours
|
||||
self.temp = temp
|
||||
self.cloudDepth = cloudDepth
|
||||
self.cloudCoverage = cloudCoverage
|
||||
self.windSpeed = windSpeed
|
||||
self.humidity = humidity
|
||||
self.precipitation = precipitation
|
||||
self.pressure = pressure
|
||||
self.averagePressure = 1013.25 * pow(1 - 6.5 * forecast.surfaceHeight / 288150.0, 5.255);
|
||||
self.minimumPressure = averagePressure - 20
|
||||
self.maximumPressure = averagePressure + 10
|
||||
}
|
||||
|
||||
private func getIndex(selection: Double) -> Int? {
|
||||
if hours.count == 0 {
|
||||
return nil
|
||||
} else {
|
||||
let idx = max(0, min(selection, 1)) * Double(hours.count - 1)
|
||||
return max(0, min(hours.count - 1, Int(round(idx))))
|
||||
}
|
||||
}
|
||||
|
||||
public func getValue<T>(values: [T], at: Double) -> T? {
|
||||
if let idx = getIndex(selection: at) {
|
||||
if idx > 0 && idx < values.count {
|
||||
return values[idx]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ struct PersistenceController {
|
||||
static var preview: PersistenceController = {
|
||||
let result = PersistenceController(inMemory: true)
|
||||
let viewContext = result.container.viewContext
|
||||
/*
|
||||
for _ in 0..<10 {
|
||||
let newItem = Item(context: viewContext)
|
||||
newItem.timestamp = Date()
|
||||
@@ -24,7 +25,7 @@ struct PersistenceController {
|
||||
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
|
||||
let nsError = error as NSError
|
||||
fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
|
||||
}
|
||||
}*/
|
||||
return result
|
||||
}()
|
||||
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
//
|
||||
// Task.swift
|
||||
// App
|
||||
//
|
||||
// Created by Marcus Handte on 22.07.22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public class BaseTask {
|
||||
|
||||
/// A dispatch queue to ensure that tasks are executed sequentially
|
||||
public static let queue = DispatchQueue(label: "tasks")
|
||||
|
||||
/// A flag to indicate whether the operation is cancelled.
|
||||
private var canceled = false
|
||||
|
||||
/// A lock to guard the cancelled flag.
|
||||
private let lock = NSLock()
|
||||
|
||||
/// Creates the operation.
|
||||
public init() { }
|
||||
|
||||
/// Determines whether the operation should be canceled.
|
||||
///
|
||||
/// - returns: True if the operation is canceled, false otherwise.
|
||||
public func isCanceled() -> Bool {
|
||||
lock.lock()
|
||||
let result = canceled
|
||||
lock.unlock()
|
||||
return result
|
||||
}
|
||||
|
||||
/// Cancels the upload operation.
|
||||
public func cancel() {
|
||||
lock.lock()
|
||||
canceled = true
|
||||
lock.unlock()
|
||||
}
|
||||
|
||||
/// Executes a task an informs the completion handler on the main thread.
|
||||
public func execute(completion: @escaping (Bool) -> Void) {
|
||||
BaseTask.queue.async {
|
||||
let result = self.executeAsync()
|
||||
DispatchQueue.main.async {
|
||||
completion(result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Executes the task logic. Multiple classes
|
||||
func executeAsync() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
/// Cancels all tasks.
|
||||
public static func cancel(all tasks: [BaseTask]) {
|
||||
for t in tasks {
|
||||
t.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
/// Executes a series of tasks until one of them fails or all complete
|
||||
public static func execute(all tasks: [BaseTask], completion: @escaping (Bool) -> Void) {
|
||||
if tasks.count > 0 {
|
||||
var t = tasks
|
||||
BaseTask.execute(current: t.removeFirst(), next: t, completion: completion)
|
||||
} else {
|
||||
DispatchQueue.main.async {
|
||||
completion(true)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// Executes the current task and continues with the next tasks, if the task is successful.
|
||||
private static func execute(current: BaseTask, next: [BaseTask], completion: @escaping (Bool) -> Void) {
|
||||
BaseTask.queue.async {
|
||||
let result = current.executeAsync()
|
||||
if !result || next.count == 0 {
|
||||
DispatchQueue.main.async {
|
||||
completion(result)
|
||||
}
|
||||
} else {
|
||||
var t = next
|
||||
BaseTask.execute(current: t.removeFirst(), next: t, completion: completion)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,248 @@
|
||||
//
|
||||
// RefreshTask.swift
|
||||
// App
|
||||
//
|
||||
// Created by Marcus Handte on 22.07.22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import class MoWeStaApi.DefaultAPI
|
||||
import class MoWeStaApi.City
|
||||
import class MoWeStaApi.State
|
||||
import class MoWeStaApi.Country
|
||||
import class MoWeStaApi.WeatherCondition
|
||||
import class MoWeStaApi.WeatherForecast
|
||||
import class MoWeStaApi.WeatherStation
|
||||
import class MoWeStaApi.Geometry
|
||||
|
||||
/// Loads the location and weather info for all favorites.
|
||||
public class RefreshTask: BaseTask {
|
||||
|
||||
// The timeout to prevent frequent location downloads
|
||||
public static let LOCATION_TIMEOUT = 24 * 60 * 60 * 1000
|
||||
|
||||
// The timeout to prevent too frequent weather downloads
|
||||
public static let WEATHER_TIMEOUT = 5 * 60 * 1000
|
||||
|
||||
/// The persistence context
|
||||
let context = PersistenceController.shared.container.newBackgroundContext()
|
||||
|
||||
override func executeAsync() -> Bool {
|
||||
context.performAndWait {
|
||||
let fetch = Favorite.fetchRequest()
|
||||
if let favorites = try? fetch.execute() {
|
||||
print("Syncing \(favorites.count) favorites.")
|
||||
let group = DispatchGroup()
|
||||
let queue = DispatchQueue(label: "refresh", attributes: .concurrent)
|
||||
let semaphore = DispatchSemaphore(value: 3)
|
||||
for fav in favorites {
|
||||
if isCanceled() {
|
||||
print("Sync was cancelled.")
|
||||
break
|
||||
} else {
|
||||
print("Refresh start: \(fav.identifier)")
|
||||
if !fav.removed {
|
||||
semaphore.wait()
|
||||
group.enter()
|
||||
queue.async {
|
||||
let favref = FavoriteRefresher(self, fav)
|
||||
favref.refresh {
|
||||
print("Refresh complete: \(fav.identifier)")
|
||||
semaphore.signal()
|
||||
group.leave()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
group.wait()
|
||||
print("Saving refreshed context.")
|
||||
try? context.save()
|
||||
}
|
||||
}
|
||||
return !isCanceled()
|
||||
}
|
||||
}
|
||||
|
||||
/// A utility class to download the data for a favorite
|
||||
class FavoriteRefresher {
|
||||
|
||||
let task: RefreshTask
|
||||
let favorite: Favorite
|
||||
let now = Int64(NSDate().timeIntervalSince1970 * 1000)
|
||||
var remaining = 0
|
||||
var lock = NSRecursiveLock()
|
||||
var city: City? = nil
|
||||
var location: Any? = nil
|
||||
var boundary: Geometry? = nil
|
||||
var forecast: WeatherForecast? = nil
|
||||
var condition: WeatherCondition? = nil
|
||||
var station: WeatherStation? = nil
|
||||
|
||||
init(_ task: RefreshTask, _ favorite: Favorite) {
|
||||
self.favorite = favorite
|
||||
self.task = task
|
||||
}
|
||||
|
||||
private func isLocationIncomplete() -> Bool {
|
||||
return favorite.location == nil || favorite.forecast == nil
|
||||
}
|
||||
|
||||
private func isWeatherIncomplete() -> Bool {
|
||||
return favorite.condition == nil || favorite.forecast == nil
|
||||
}
|
||||
|
||||
|
||||
public func refresh(completion: @escaping () -> Void) {
|
||||
lock.lock()
|
||||
if !task.isCanceled() {
|
||||
if now - favorite.locationTime > RefreshTask.LOCATION_TIMEOUT || isLocationIncomplete() {
|
||||
switch favorite.getLocationType() {
|
||||
case .country:
|
||||
remaining += 2
|
||||
DefaultAPI.getCountry(id: favorite.identifier) {
|
||||
response, error in
|
||||
if let r = response {
|
||||
self.location = r
|
||||
}
|
||||
self.complete(completion: completion)
|
||||
}
|
||||
|
||||
DefaultAPI.getCountryCities(id: favorite.identifier, pageOffset: 0, pageSize: 1) {
|
||||
response, error in
|
||||
if let r = response, let f = r.elements.first {
|
||||
self.city = f
|
||||
self.refresh(f, true, completion)
|
||||
}
|
||||
self.complete(completion: completion)
|
||||
}
|
||||
/** This is too much data.
|
||||
DefaultAPI.getCountryBoundary(id: favorite.identifier) {
|
||||
response, error in
|
||||
if let r = response {
|
||||
self.boundary = r
|
||||
}
|
||||
self.complete(completion: completion)
|
||||
}
|
||||
*/
|
||||
case .state:
|
||||
remaining += 3
|
||||
DefaultAPI.getState(id: favorite.identifier) {
|
||||
response, error in
|
||||
if let r = response {
|
||||
self.location = r
|
||||
}
|
||||
self.complete(completion: completion)
|
||||
}
|
||||
DefaultAPI.getStateCities(id: favorite.identifier, pageOffset: 0, pageSize: 1) {
|
||||
response, error in
|
||||
if let r = response, let f = r.elements.first {
|
||||
self.city = f
|
||||
self.refresh(f, true, completion)
|
||||
}
|
||||
self.complete(completion: completion)
|
||||
}
|
||||
DefaultAPI.getStateBoundary(id: favorite.identifier) {
|
||||
response, error in
|
||||
if let r = response {
|
||||
self.boundary = r
|
||||
}
|
||||
self.complete(completion: completion)
|
||||
}
|
||||
case .city:
|
||||
remaining += 2
|
||||
DefaultAPI.getCity(id: favorite.identifier) {
|
||||
response, error in
|
||||
if let r = response {
|
||||
self.city = r
|
||||
self.location = r
|
||||
self.refresh(r, true, completion)
|
||||
}
|
||||
self.complete(completion: completion)
|
||||
}
|
||||
DefaultAPI.getCityBoundary(id: favorite.identifier) {
|
||||
response, error in
|
||||
if let r = response {
|
||||
self.boundary = r
|
||||
}
|
||||
self.complete(completion: completion)
|
||||
}
|
||||
}
|
||||
} else if now - favorite.weatherTime > RefreshTask.WEATHER_TIMEOUT || isWeatherIncomplete() {
|
||||
if let c = favorite.cityValue {
|
||||
refresh(c, false, completion)
|
||||
}
|
||||
}
|
||||
}
|
||||
if remaining == 0 {
|
||||
DispatchQueue.main.async {
|
||||
completion()
|
||||
}
|
||||
}
|
||||
lock.unlock()
|
||||
}
|
||||
|
||||
/// refreshes the weather for a city, optionally with location
|
||||
func refresh(_ city: City, _ full: Bool, _ completion: @escaping () -> Void) {
|
||||
if !task.isCanceled() {
|
||||
lock.lock()
|
||||
if full {
|
||||
remaining += 3
|
||||
} else {
|
||||
remaining += 2
|
||||
}
|
||||
lock.unlock()
|
||||
if full {
|
||||
DefaultAPI.getCityStation(id: city.id!) {
|
||||
response, error in
|
||||
if let r = response {
|
||||
self.station = r
|
||||
}
|
||||
self.complete(completion: completion)
|
||||
}
|
||||
}
|
||||
DefaultAPI.getCityForecast(id: city.id!) {
|
||||
response, error in
|
||||
if let r = response {
|
||||
self.forecast = r
|
||||
}
|
||||
self.complete(completion: completion)
|
||||
}
|
||||
DefaultAPI.getCityCondition(id: city.id!) {
|
||||
response, error in
|
||||
if let r = response {
|
||||
self.condition = r
|
||||
}
|
||||
self.complete(completion: completion)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// complete the task and sets the variables
|
||||
func complete(completion: @escaping () -> Void) {
|
||||
lock.lock()
|
||||
remaining -= 1
|
||||
if remaining == 0 {
|
||||
if let c = city, let l = location {
|
||||
if let b = boundary {
|
||||
favorite.boundaryValue = b
|
||||
}
|
||||
if let s = station {
|
||||
favorite.stationValue = s
|
||||
}
|
||||
favorite.locationValue = l
|
||||
favorite.cityValue = c
|
||||
favorite.locationTime = now
|
||||
}
|
||||
if let f = forecast, let c = condition {
|
||||
favorite.forecastValue = f
|
||||
favorite.conditionValue = c
|
||||
favorite.weatherTime = now
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
completion()
|
||||
}
|
||||
}
|
||||
lock.unlock()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
//
|
||||
// SyncTask.swift
|
||||
// App
|
||||
//
|
||||
// Created by Marcus Handte on 22.07.22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import class MoWeStaApi.DefaultAPI
|
||||
import class MoWeStaApi.Settings
|
||||
import class MoWeStaApi.LocationReference
|
||||
|
||||
public class SyncTask: BaseTask {
|
||||
|
||||
/// The persistence context
|
||||
let context = PersistenceController.shared.container.newBackgroundContext()
|
||||
|
||||
/// The app state
|
||||
let state = AppState.shared
|
||||
|
||||
/// The user credentials
|
||||
let credential = AppState.shared.credentials
|
||||
|
||||
|
||||
override func executeAsync() -> Bool {
|
||||
print("Performing favorite synchronization.")
|
||||
if let cs = credential {
|
||||
if let settings = SettingDownloader(cs).getSettings() {
|
||||
context.performAndWait {
|
||||
let fetch = Favorite.fetchRequest()
|
||||
if let favorites = try? fetch.execute() {
|
||||
/// create a diff
|
||||
var localOnlyFavorites = favorites
|
||||
var localAndServerFavorites: [LocationReference:Favorite] = [:]
|
||||
var remoteOnlyFavorites = settings.locations
|
||||
ref: for ref in settings.locations {
|
||||
for idx in localOnlyFavorites.indices {
|
||||
let fav = localOnlyFavorites[idx]
|
||||
if (fav.identifier == ref.id && fav.getLocationReferenceType() == ref.type) {
|
||||
localAndServerFavorites.updateValue(fav, forKey: ref)
|
||||
localOnlyFavorites.remove(at: idx)
|
||||
remoteOnlyFavorites.removeAll() { r in
|
||||
return ref.id == r.id && ref.type == r.type
|
||||
}
|
||||
continue ref
|
||||
}
|
||||
}
|
||||
}
|
||||
// handle favorites available remotely
|
||||
var newFavorties: [Favorite] = []
|
||||
var deletedFavorites: [Favorite] = []
|
||||
var changedFavorites: [Favorite] = []
|
||||
var newState = settings.locations
|
||||
var deleted = 0
|
||||
for idx in settings.locations.indices {
|
||||
let i = idx - deleted
|
||||
let ref = newState[i]
|
||||
if let fav = localAndServerFavorites[ref] {
|
||||
if fav.removed {
|
||||
newState.remove(at: i)
|
||||
deletedFavorites.append(fav)
|
||||
context.delete(fav)
|
||||
deleted += 1
|
||||
} else {
|
||||
fav.position = Int16(i)
|
||||
fav.added = true
|
||||
changedFavorites.append(fav)
|
||||
}
|
||||
} else {
|
||||
let fav = Favorite(context: context)
|
||||
fav.setLocationReferenceType(type: ref.type)
|
||||
fav.added = true
|
||||
fav.identifier = ref.id!
|
||||
fav.position = Int16(i)
|
||||
context.insert(fav)
|
||||
newFavorties.append(fav)
|
||||
}
|
||||
}
|
||||
/// handle local only favorties
|
||||
for fav in localOnlyFavorites {
|
||||
if fav.removed || fav.added {
|
||||
context.delete(fav)
|
||||
deletedFavorites.append(fav)
|
||||
} else {
|
||||
let ref = LocationReference(id: fav.identifier, type: fav.getLocationReferenceType())
|
||||
fav.position = Int16(newState.count)
|
||||
fav.added = true
|
||||
newState.append(ref)
|
||||
changedFavorites.append(fav)
|
||||
}
|
||||
}
|
||||
/// apply the state to the server
|
||||
let newSettings = Settings(creationTime: settings.creationTime, deleted: false, id: settings.id, locations: newState, modificationTime: settings.modificationTime)
|
||||
if SettingUploader(cs, newSettings).setSettings() {
|
||||
print("Saving local favorite changes since upload completed.")
|
||||
try? context.save()
|
||||
} else {
|
||||
print("Resetting local favorite changes since upload failed.")
|
||||
context.reset()
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
return !isCanceled()
|
||||
} else {
|
||||
print("Skipping sync since user is not logged in.")
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A class to perform a blocking download of the settings
|
||||
class SettingDownloader {
|
||||
|
||||
let credential: UserCredentials
|
||||
var settings: Settings? = nil
|
||||
|
||||
init(_ credential: UserCredentials) {
|
||||
self.credential = credential
|
||||
}
|
||||
|
||||
public func getSettings() -> Settings? {
|
||||
print("Loading user settings.")
|
||||
let group = DispatchGroup()
|
||||
group.enter()
|
||||
let rb = DefaultAPI.getCurrentUserSettingsWithRequestBuilder()
|
||||
rb.addHeaders(ApiHeader.create(credential))
|
||||
rb.execute() { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
print("Loaded user setttings.")
|
||||
self.settings = response.body
|
||||
case let .failure(.error(code, _, _, _)):
|
||||
print("Failed to load user settings.")
|
||||
if code == 403 {
|
||||
DispatchQueue.main.async {
|
||||
AppState.shared.credentialFailure = true
|
||||
}
|
||||
}
|
||||
}
|
||||
group.leave()
|
||||
}
|
||||
group.wait()
|
||||
print("Returning user settings: \(settings == nil)")
|
||||
return settings
|
||||
}
|
||||
}
|
||||
|
||||
/// A class to perform a blocking upload of the settings
|
||||
class SettingUploader {
|
||||
|
||||
let credential: UserCredentials
|
||||
let settings: Settings
|
||||
var success = false
|
||||
|
||||
init(_ credential: UserCredentials, _ settings: Settings) {
|
||||
self.credential = credential
|
||||
self.settings = settings
|
||||
}
|
||||
|
||||
public func setSettings() -> Bool {
|
||||
print("Uploading user settings.")
|
||||
let group = DispatchGroup()
|
||||
group.enter()
|
||||
let rb = DefaultAPI.setCurrentUserSettingsWithRequestBuilder(body: settings)
|
||||
rb.addHeaders(ApiHeader.create(credential))
|
||||
rb.execute() { result in
|
||||
switch result {
|
||||
case .success:
|
||||
print("Uploaded user setttings.")
|
||||
self.success = true
|
||||
case let .failure(.error(code, _, _, _)):
|
||||
print("Failed to upload user settings.")
|
||||
if code == 403 {
|
||||
DispatchQueue.main.async {
|
||||
AppState.shared.credentialFailure = true
|
||||
}
|
||||
}
|
||||
}
|
||||
group.leave()
|
||||
}
|
||||
group.wait()
|
||||
print("Returning upload settings: \(success)")
|
||||
return success
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,25 @@ import SwiftUI
|
||||
/// A button style that looks similar to a color button from material design.
|
||||
struct MaterialButtonStyle: ButtonStyle {
|
||||
|
||||
/// The background color
|
||||
let color: Color
|
||||
|
||||
let foreground: Color
|
||||
|
||||
/// A flag to indicate whether the button is disabled.
|
||||
let disabled: Bool;
|
||||
|
||||
init(disabled: Bool) {
|
||||
self.color = Color.accentColor
|
||||
self.foreground = Color.black
|
||||
self.disabled = disabled
|
||||
}
|
||||
|
||||
init(color: Color, disabled: Bool) {
|
||||
self.color = color
|
||||
self.foreground = Color.white
|
||||
self.disabled = disabled
|
||||
}
|
||||
|
||||
/// Modifies the view based on the configuration.
|
||||
///
|
||||
@@ -20,23 +37,49 @@ struct MaterialButtonStyle: ButtonStyle {
|
||||
configuration
|
||||
.label
|
||||
.font(.body.smallCaps())
|
||||
.foregroundColor(configuration.isPressed ? .gray : .white)
|
||||
.foregroundColor(disabled ? .white : foreground)
|
||||
.frame(maxWidth:.infinity)
|
||||
.padding(5)
|
||||
.background(disabled ? Color.gray : Color.accentColor)
|
||||
.padding(8)
|
||||
.background(color.opacity(configuration.isPressed ? 0.7 : 1))
|
||||
.cornerRadius(6)
|
||||
.opacity((configuration.isPressed || disabled) ? 0.7 : 1)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct OutlineButtonStyle: ButtonStyle {
|
||||
|
||||
/// The outline and text color
|
||||
let color: Color
|
||||
|
||||
/// Modifies the view based on the configuration.
|
||||
///
|
||||
/// - Parameter configuration: The configuration.
|
||||
/// - Returns: The modified view
|
||||
func makeBody(configuration: Configuration) -> some View {
|
||||
configuration
|
||||
.label
|
||||
.font(.body.smallCaps())
|
||||
.foregroundColor(configuration.isPressed ? .gray : color)
|
||||
.frame(maxWidth:.infinity)
|
||||
.padding(8)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 6)
|
||||
.stroke(configuration.isPressed ? .gray : color, lineWidth: 2)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// A button style that switches between the text color and the accent color.
|
||||
struct NullButtonStyle: ButtonStyle {
|
||||
|
||||
func makeBody(configuration: Configuration) -> some View {
|
||||
configuration
|
||||
.label
|
||||
.foregroundColor(configuration.isPressed ? Color.accentColor : Color("TextColor"))
|
||||
.opacity(configuration.isPressed ? 0.7 : 1)
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// ErrorView.swift
|
||||
// App
|
||||
//
|
||||
// Created by Marcus Handte on 20.07.22.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ErrorView: View {
|
||||
|
||||
let action: (() -> Void)?
|
||||
@State var opacity: Double = 0.0
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
Text("snackbar_error")
|
||||
.font(.body)
|
||||
.frame(maxWidth: .infinity)
|
||||
.foregroundColor(.white)
|
||||
.multilineTextAlignment(.center)
|
||||
if let a = action {
|
||||
Button(action: a) {
|
||||
Text("snackbar_reload")
|
||||
}
|
||||
.buttonStyle(MaterialButtonStyle(disabled: false))
|
||||
.frame(width: 100)
|
||||
.padding(.leading, 10)
|
||||
}
|
||||
}
|
||||
.padding(10)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 6)
|
||||
.foregroundColor(Color("PrimaryColor")))
|
||||
.padding(10)
|
||||
.opacity(opacity)
|
||||
.animation(.easeIn(duration: 0.5), value: opacity)
|
||||
.onAppear() {
|
||||
opacity = 1
|
||||
}
|
||||
.onDisappear() {
|
||||
opacity = 0
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
struct ErrorView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
VStack {
|
||||
Spacer()
|
||||
ErrorView() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,341 @@
|
||||
//
|
||||
// GradientViews.swift
|
||||
// App
|
||||
//
|
||||
// Created by Marcus Handte on 23.07.22.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
enum GradientOrientation {
|
||||
case horizontal
|
||||
case vertical
|
||||
}
|
||||
|
||||
|
||||
struct GradientView: View {
|
||||
|
||||
/// Dark mode or not
|
||||
@Environment(\.colorScheme) var colorMode
|
||||
|
||||
let data: [[Double]]
|
||||
let colorScheme: [DataColorScheme]
|
||||
let background: Color
|
||||
let orientation: GradientOrientation
|
||||
var selection: Binding<Double?>
|
||||
let linearGradient: [LinearGradient]
|
||||
let scale: Double = 3
|
||||
let size: CGFloat = 80
|
||||
|
||||
init(data: [Double], colorScheme: DataColorScheme, background: Color, orientation: GradientOrientation, selection: Binding<Double?>) {
|
||||
self.init(data: [ data], colorScheme: [colorScheme], background: background, orientation: orientation, selection:selection)
|
||||
}
|
||||
|
||||
init(data: [[Double]], colorScheme: [DataColorScheme], background: Color, orientation: GradientOrientation, selection: Binding<Double?>) {
|
||||
self.data = data
|
||||
self.colorScheme = colorScheme
|
||||
self.background = background
|
||||
self.orientation = orientation
|
||||
self.selection = selection
|
||||
var gradients: [LinearGradient] = []
|
||||
for i in 0..<min(data.count, colorScheme.count) {
|
||||
let start = UnitPoint(x: 0, y: 0)
|
||||
let end = UnitPoint(x: orientation == .horizontal ? 1 : 0, y: orientation == .vertical ? 1 : 0)
|
||||
var stops: [Gradient.Stop] = []
|
||||
if data[i].count == 0 {
|
||||
stops.append(Gradient.Stop(color: Color.black, location: 0))
|
||||
stops.append(Gradient.Stop(color: Color.black, location: 1))
|
||||
} else if data[i].count == 1 {
|
||||
let color = colorScheme[i].color(data[i][0])
|
||||
stops.append(Gradient.Stop(color: color, location: 0))
|
||||
stops.append(Gradient.Stop(color: color, location: 1))
|
||||
} else {
|
||||
let increment = 1 / Double(data[i].count - 1)
|
||||
for j in data[i].indices {
|
||||
stops.append(Gradient.Stop(color: colorScheme[i].color(data[i][j]), location: Double(j) * increment))
|
||||
}
|
||||
}
|
||||
gradients.append(LinearGradient(stops: stops, startPoint: start, endPoint: end))
|
||||
}
|
||||
self.linearGradient = gradients
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
GeometryReader { proxy in
|
||||
ZStack(alignment: .topLeading) {
|
||||
Rectangle()
|
||||
.foregroundColor(.clear)
|
||||
.background(colorMode == .dark ? Color.black : Color.white)
|
||||
.frame(width: proxy.size.width, height: proxy.size.height)
|
||||
Rectangle()
|
||||
.foregroundColor(.clear)
|
||||
.background(background)
|
||||
.frame(width: proxy.size.width, height: proxy.size.height)
|
||||
ForEach(linearGradient.indices, id: \.self) { i in
|
||||
Rectangle()
|
||||
.foregroundColor(.clear)
|
||||
.background(linearGradient[i])
|
||||
.frame(width: proxy.size.width, height: proxy.size.height)
|
||||
}
|
||||
|
||||
if let s = selection.wrappedValue {
|
||||
if orientation == .vertical {
|
||||
buildVertical(proxy: proxy, s: s)
|
||||
} else {
|
||||
buildHorizontal(proxy: proxy, s: s)
|
||||
}
|
||||
}
|
||||
}.clipped()
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
func buildVertical(proxy: GeometryProxy, s: Double) -> some View {
|
||||
let pivot = s * proxy.size.height
|
||||
let scaledSize = proxy.size.height * scale
|
||||
let scaledOffset = scale * proxy.size.height / 2 - scale * pivot
|
||||
let shiftOffset = pivot - size / 2
|
||||
VStack(spacing: 0) {
|
||||
Rectangle()
|
||||
.frame(height: 1)
|
||||
.frame(maxWidth: .infinity)
|
||||
ZStack(alignment: .topLeading) {
|
||||
|
||||
Rectangle()
|
||||
.fixedSize()
|
||||
.foregroundColor(.clear)
|
||||
.frame(width: proxy.size.width, height: scaledSize)
|
||||
.background(colorMode == .dark ? Color.black : Color.white)
|
||||
.offset(x: 0, y: scaledOffset)
|
||||
|
||||
Rectangle()
|
||||
.fixedSize()
|
||||
.foregroundColor(.clear)
|
||||
.frame(width: proxy.size.width, height: scaledSize)
|
||||
.background(background)
|
||||
.offset(x: 0, y: scaledOffset)
|
||||
|
||||
ForEach(linearGradient.indices, id: \.self) { i in
|
||||
Rectangle()
|
||||
.fixedSize()
|
||||
.foregroundColor(.clear)
|
||||
.frame(width: proxy.size.width, height: scaledSize)
|
||||
.background(linearGradient[i])
|
||||
.offset(x: 0, y: scaledOffset)
|
||||
}
|
||||
}
|
||||
.frame(width: proxy.size.width, height: size)
|
||||
.clipped()
|
||||
Rectangle()
|
||||
.frame(height: 1)
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
.offset(x: 0, y: shiftOffset)
|
||||
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
func buildHorizontal(proxy: GeometryProxy, s: Double) -> some View {
|
||||
let pivot = s * proxy.size.width
|
||||
let scaledSize = proxy.size.width * scale
|
||||
let scaledOffset = scale * proxy.size.width / 2 - scale * pivot
|
||||
let shiftOffset = pivot - size / 2
|
||||
HStack(spacing: 0) {
|
||||
Rectangle()
|
||||
.frame(width: 1)
|
||||
.frame(maxHeight: .infinity)
|
||||
ZStack(alignment: .topLeading) {
|
||||
Rectangle()
|
||||
.fixedSize()
|
||||
.foregroundColor(.clear)
|
||||
.frame(width: scaledSize, height: proxy.size.height)
|
||||
.background(colorMode == .dark ? Color.black : Color.white)
|
||||
.offset(x: scaledOffset, y: 0)
|
||||
|
||||
Rectangle()
|
||||
.fixedSize()
|
||||
.foregroundColor(.clear)
|
||||
.frame(width: scaledSize, height: proxy.size.height)
|
||||
.background(background)
|
||||
.offset(x: scaledOffset, y: 0)
|
||||
|
||||
ForEach(linearGradient.indices, id: \.self) { i in
|
||||
Rectangle()
|
||||
.fixedSize()
|
||||
.foregroundColor(.clear)
|
||||
.frame(width: scaledSize, height: proxy.size.height)
|
||||
.background(linearGradient[i])
|
||||
.offset(x: scaledOffset, y: 0)
|
||||
}
|
||||
}
|
||||
.frame(width: size, height: proxy.size.height)
|
||||
.clipped()
|
||||
Rectangle()
|
||||
.frame(width: 1)
|
||||
.frame(maxHeight: .infinity)
|
||||
}
|
||||
.offset(x: shiftOffset, y: 0)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct TimeView: View {
|
||||
|
||||
/// Dark mode or not
|
||||
@Environment(\.colorScheme) var colorScheme
|
||||
|
||||
let data: [Int64]
|
||||
let timezone: String?
|
||||
let orientation: GradientOrientation
|
||||
var selection: Binding<Double?>
|
||||
let scale: Double = 3
|
||||
let size: CGFloat = 80
|
||||
|
||||
|
||||
init(data: [Int64], timezone: String?, orientation: GradientOrientation, selection: Binding<Double?>) {
|
||||
self.data = data
|
||||
self.orientation = orientation
|
||||
self.selection = selection
|
||||
self.timezone = timezone
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
GeometryReader { proxy in
|
||||
ZStack(alignment: .topLeading) {
|
||||
if orientation == .vertical {
|
||||
buildMainVertical(size: proxy.size, scale: 1)
|
||||
} else {
|
||||
buildMainHorizontal(size: proxy.size, scale: 1)
|
||||
}
|
||||
if let s = selection.wrappedValue {
|
||||
if orientation == .vertical {
|
||||
buildVertical(proxy: proxy, s: s)
|
||||
} else {
|
||||
buildHorizontal(proxy: proxy, s: s)
|
||||
}
|
||||
}
|
||||
}.clipped()
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
func buildMainVertical(size: CGSize, scale: Double) -> some View {
|
||||
ZStack {
|
||||
VStack(spacing: 0) {
|
||||
ForEach(data.indices, id: \.self) { i in
|
||||
let d = data[i]
|
||||
let h = DataBindings.getHour(d, timezone)
|
||||
VStack(spacing: 0) {
|
||||
Rectangle()
|
||||
.background(h % 6 == 0 ? Color.accentColor : Color.clear)
|
||||
.foregroundColor(.clear)
|
||||
.padding([.leading, .trailing], h == 0 ? 4 : (h == 12 ? 8 : 12))
|
||||
.frame(height: 1 * scale)
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
}
|
||||
}
|
||||
if let first = data.first, let last = data.last {
|
||||
let div = max(1, last - first)
|
||||
let now = Int64(NSDate().timeIntervalSince1970 * 1000)
|
||||
let perc = Double(now - first) / Double(div)
|
||||
Rectangle()
|
||||
.frame(maxWidth:.infinity)
|
||||
.frame(height: 2 * scale)
|
||||
.foregroundColor(.clear)
|
||||
.background(Color("PrimaryColor"))
|
||||
.position(x: size.width / 2, y: perc * size.height * scale)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
func buildMainHorizontal(size: CGSize, scale: Double) -> some View {
|
||||
ZStack {
|
||||
HStack(spacing: 0) {
|
||||
ForEach(data.indices, id: \.self) { i in
|
||||
let d = data[i]
|
||||
let h = DataBindings.getHour(d, timezone)
|
||||
HStack(spacing: 0) {
|
||||
Rectangle()
|
||||
.background(h % 6 == 0 ? Color.accentColor : Color.clear)
|
||||
.foregroundColor(.clear)
|
||||
.padding([.top, .bottom], h == 0 ? 4 : (h == 12 ? 8 : 12))
|
||||
.frame(width: 1 * scale)
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
}
|
||||
}
|
||||
if let first = data.first, let last = data.last {
|
||||
let div = max(1, last - first)
|
||||
let now = Int64(NSDate().timeIntervalSince1970 * 1000)
|
||||
let perc = Double(now - first) / Double(div)
|
||||
Rectangle()
|
||||
.frame(maxHeight:.infinity)
|
||||
.frame(width: 2 * scale)
|
||||
.foregroundColor(.clear)
|
||||
.background(Color("PrimaryColor"))
|
||||
.position(x: perc * size.width * scale, y: size.height / 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ViewBuilder
|
||||
func buildVertical(proxy: GeometryProxy, s: Double) -> some View {
|
||||
let pivot = s * proxy.size.height
|
||||
let scaledSize = proxy.size.height * scale
|
||||
let scaledOffset = scale * proxy.size.height / 2 - scale * pivot
|
||||
let shiftOffset = pivot - size / 2
|
||||
VStack(spacing: 0) {
|
||||
Rectangle().frame(height: 1).frame(maxWidth: .infinity)
|
||||
ZStack(alignment: .topLeading) {
|
||||
Rectangle()
|
||||
.fixedSize()
|
||||
.foregroundColor(.clear)
|
||||
.frame(width: proxy.size.width, height: scaledSize)
|
||||
.background(colorScheme == .dark ? Color.black : Color.white)
|
||||
.offset(x: 0, y: scaledOffset)
|
||||
|
||||
buildMainVertical(size: proxy.size, scale: scale)
|
||||
.frame(width: proxy.size.width, height: scaledSize)
|
||||
.offset(x: 0, y: scaledOffset)
|
||||
|
||||
}
|
||||
.frame(width: proxy.size.width, height: size)
|
||||
.clipped()
|
||||
Rectangle().frame(height: 1).frame(maxWidth: .infinity)
|
||||
}
|
||||
.offset(x: 0, y: shiftOffset)
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
func buildHorizontal(proxy: GeometryProxy, s: Double) -> some View {
|
||||
let pivot = s * proxy.size.width
|
||||
let scaledSize = proxy.size.width * scale
|
||||
let scaledOffset = scale * proxy.size.width / 2 - scale * pivot
|
||||
let shiftOffset = pivot - size / 2
|
||||
HStack(spacing: 0) {
|
||||
Rectangle().frame(width: 1).frame(maxHeight: .infinity)
|
||||
ZStack(alignment: .topLeading) {
|
||||
Rectangle()
|
||||
.fixedSize()
|
||||
.foregroundColor(.clear)
|
||||
.frame(width: scaledSize, height: proxy.size.height)
|
||||
.background(colorScheme == .dark ? Color.black : Color.white)
|
||||
.offset(x: scaledOffset, y: 0)
|
||||
|
||||
buildMainHorizontal(size: proxy.size, scale: scale)
|
||||
.frame(width: scaledSize, height: proxy.size.height)
|
||||
.offset(x: scaledOffset, y: 0)
|
||||
}
|
||||
.frame(width: size, height: proxy.size.height)
|
||||
.clipped()
|
||||
|
||||
Rectangle().frame(width: 1).frame(maxHeight: .infinity)
|
||||
}
|
||||
.offset(x: shiftOffset, y: 0)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -50,7 +50,7 @@ extension EnvironmentValues {
|
||||
struct HideableTabItem: Identifiable {
|
||||
let id: Int
|
||||
let text: LocalizedStringKey
|
||||
let image: String
|
||||
let image: Image
|
||||
@ViewBuilder let builder: () -> AnyView
|
||||
}
|
||||
|
||||
@@ -60,46 +60,62 @@ struct HideableTabView: View {
|
||||
let tag: String
|
||||
@EnvironmentObject var tabViewState: TabViewState
|
||||
@State var selected: Int = 0;
|
||||
let insets: EdgeInsets;
|
||||
|
||||
|
||||
private let builder: () -> [HideableTabItem]
|
||||
|
||||
init(_ tag: String, _ builder: @escaping () -> [HideableTabItem]) {
|
||||
init(_ tag: String, _ insets: EdgeInsets, _ builder: @escaping () -> [HideableTabItem]) {
|
||||
self.tag = tag
|
||||
self.builder = builder
|
||||
self.insets = insets
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
let content = builder()
|
||||
VStack {
|
||||
VStack(spacing: 0) {
|
||||
HStack(spacing: 0) {
|
||||
Spacer()
|
||||
.frame(width: insets.leading)
|
||||
ForEach(content, id: \.id) {
|
||||
c in
|
||||
if c.id == selected {
|
||||
c.builder()
|
||||
}
|
||||
}
|
||||
if !tabViewState.isHidden(view: tag) {
|
||||
Spacer()
|
||||
Spacer()
|
||||
.frame(width: insets.leading)
|
||||
}
|
||||
if !tabViewState.isHidden(view: tag) {
|
||||
HStack {
|
||||
Spacer()
|
||||
.frame(width: insets.leading)
|
||||
ForEach(content, id: \.id) {
|
||||
c in
|
||||
Button(action: { selected = c.id }) {
|
||||
VStack {
|
||||
Image(systemName: c.image)
|
||||
.opacity(c.id == selected ? 1 : 0.5)
|
||||
.font(.title2)
|
||||
c.image
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.foregroundColor(c.id == selected ? Color.accentColor : Color.white)
|
||||
.padding(1)
|
||||
.frame(width: 28, height: 28)
|
||||
Text(c.text)
|
||||
.font(.caption2)
|
||||
.opacity(c.id == selected ? 1 : 0.5)
|
||||
.foregroundColor(c.id == selected ? Color.accentColor : Color.white)
|
||||
.font(c.id == selected ? .system(size: 10).bold() : .system(size: 10))
|
||||
.lineLimit(1)
|
||||
}
|
||||
.frame(minWidth: 0, maxWidth: .infinity)
|
||||
}
|
||||
.frame(minWidth: 0, maxWidth: 120)
|
||||
}.buttonStyle(NullButtonStyle())
|
||||
}
|
||||
Spacer()
|
||||
.frame(width: insets.trailing)
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding([.top, .bottom], 4)
|
||||
.background(Color("PrimaryColor"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// PagedView.swift
|
||||
// App
|
||||
//
|
||||
// Created by Marcus Handte on 18.07.22.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct PageItem: Identifiable {
|
||||
let id: Int
|
||||
var text: LocalizedStringKey
|
||||
@ViewBuilder let builder: () -> AnyView
|
||||
}
|
||||
|
||||
|
||||
struct PageView: View {
|
||||
|
||||
@State var pages: [PageItem]
|
||||
@Binding var current: Int
|
||||
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 0) {
|
||||
if current < 0 || current >= pages.count {
|
||||
EmptyView()
|
||||
} else {
|
||||
pages[current].builder()
|
||||
}
|
||||
Divider()
|
||||
HStack(spacing: 0) {
|
||||
ForEach(pages, id: \PageItem.id) { page in
|
||||
Button(action: {
|
||||
current = page.id
|
||||
}) {
|
||||
let t = Text(page.text)
|
||||
.frame(alignment: .center)
|
||||
.frame(maxWidth: .infinity)
|
||||
.frame(minHeight: 40)
|
||||
.lineLimit(1)
|
||||
if page.id == current {
|
||||
t
|
||||
.font(.caption.bold())
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 4)
|
||||
.foregroundColor(Color("PrimaryColor")))
|
||||
.foregroundColor(Color.accentColor)
|
||||
} else {
|
||||
t.font(.caption)
|
||||
}
|
||||
}
|
||||
.frame(minHeight: 44)
|
||||
.buttonStyle(NullButtonStyle())
|
||||
}
|
||||
}.padding([.trailing, .leading], 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct PagedView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
EmptyView()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
//
|
||||
// ProgressBar.swift
|
||||
// App
|
||||
//
|
||||
// Created by Marcus Handte on 13.07.22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
/// An indeterminate progress bar.
|
||||
struct ProgressSpinnerView: View {
|
||||
|
||||
/// The trimming of the circle animating from 0 to 1 and back.
|
||||
@State private var trim: CGFloat = CGFloat(0)
|
||||
/// The rotation of the circle animating from 90 to 450 degrees.
|
||||
@State private var rotation: Double = 90
|
||||
|
||||
/// Creates the progress bar.
|
||||
var body: some View {
|
||||
VStack {
|
||||
Spacer()
|
||||
Circle()
|
||||
.trim(from: 0.0, to: trim)
|
||||
.stroke(style: StrokeStyle(
|
||||
lineWidth: 8, lineCap: .round
|
||||
))
|
||||
.foregroundColor(.accentColor)
|
||||
.frame(width: 150, alignment: .center)
|
||||
.rotationEffect(Angle(degrees: rotation), anchor: .center)
|
||||
Spacer()
|
||||
}
|
||||
.onAppear() {
|
||||
DispatchQueue.main.async {
|
||||
withAnimation(Animation
|
||||
.linear(duration: 1.0)
|
||||
.repeatForever(autoreverses: false)) {
|
||||
rotation = 450
|
||||
}
|
||||
withAnimation(Animation.linear(duration: 1.0).repeatForever(autoreverses: true)) {
|
||||
trim = CGFloat(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
.onDisappear() {
|
||||
rotation = 90
|
||||
trim = CGFloat(0)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct ProgressBarView: View {
|
||||
|
||||
let factor = 0.2
|
||||
@State var offset = 0.0
|
||||
@Binding var animating:Bool
|
||||
|
||||
var body: some View {
|
||||
GeometryReader { geometry in
|
||||
ZStack(alignment: .leading) {
|
||||
Rectangle()
|
||||
.frame(width: geometry.size.width, height: geometry.size.height)
|
||||
.foregroundColor(.gray)
|
||||
.opacity(0.1)
|
||||
if (animating) {
|
||||
Rectangle()
|
||||
.offset(x: geometry.size.width * (1 - factor) * offset, y: 0)
|
||||
.frame(width: geometry.size.width * factor, height: geometry.size.height)
|
||||
.foregroundColor(Color.accentColor)
|
||||
.animation(.easeInOut(duration: 0.7).repeatForever(autoreverses: true), value: offset)
|
||||
}
|
||||
} .onChange(of: animating) { v in
|
||||
if (v) {
|
||||
withAnimation {
|
||||
offset = 1.0
|
||||
}
|
||||
} else {
|
||||
offset = 0.0
|
||||
}
|
||||
} .onAppear() {
|
||||
if (animating) {
|
||||
withAnimation {
|
||||
offset = 1.0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct PreviewWrapper: View, PreviewProvider {
|
||||
@State var animating = false
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
ProgressBarView(animating: $animating)
|
||||
.frame(maxHeight: 10)
|
||||
} .onAppear() {
|
||||
animating = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static var previews: some View {
|
||||
PreviewWrapper()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// RemoteImageView.swift
|
||||
// App
|
||||
//
|
||||
// Created by Marcus Handte on 18.07.22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
struct RemoteImageView<Placeholder: View, ConfiguredImage: View>: View {
|
||||
var url: URL
|
||||
private let placeholder: () -> Placeholder
|
||||
private let image: (Image) -> ConfiguredImage
|
||||
|
||||
@ObservedObject var imageLoader: ImageLoaderService
|
||||
@State var imageData: UIImage?
|
||||
|
||||
init(
|
||||
url: URL,
|
||||
@ViewBuilder placeholder: @escaping () -> Placeholder,
|
||||
@ViewBuilder image: @escaping (Image) -> ConfiguredImage
|
||||
) {
|
||||
self.url = url
|
||||
self.placeholder = placeholder
|
||||
self.image = image
|
||||
self.imageLoader = ImageLoaderService(url: url)
|
||||
}
|
||||
|
||||
@ViewBuilder private var imageContent: some View {
|
||||
if let data = imageData {
|
||||
image(Image(uiImage: data))
|
||||
} else {
|
||||
placeholder()
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
imageContent
|
||||
.onReceive(imageLoader.$image) { imageData in
|
||||
self.imageData = imageData
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ImageLoaderService: ObservableObject {
|
||||
@Published var image: UIImage? = nil
|
||||
|
||||
convenience init(url: URL) {
|
||||
self.init()
|
||||
loadImage(for: url)
|
||||
}
|
||||
|
||||
func loadImage(for url: URL) {
|
||||
let task = URLSession.shared.dataTask(with: url) { data, _, _ in
|
||||
guard let data = data else { return }
|
||||
DispatchQueue.main.async {
|
||||
self.image = UIImage(data: data) ?? nil
|
||||
}
|
||||
}
|
||||
task.resume()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// Headers.swift
|
||||
// App
|
||||
//
|
||||
// Created by Marcus Handte on 13.07.22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public class ApiHeader {
|
||||
|
||||
public static func create(_ credential: UserCredentials) -> [String:String] {
|
||||
let string = "\(credential.login):\(credential.password)"
|
||||
let data = Data(string.utf8)
|
||||
return ["Authorization" : "Basic \(data.base64EncodedString())"]
|
||||
}
|
||||
|
||||
public static func create(_ token: String) -> [String : String] {
|
||||
return ["Authorization" : "Bearer \(token)" ]
|
||||
}
|
||||
|
||||
public static func create(_ credential: UserCredentials, _ token: String) -> [String:String] {
|
||||
let string = "\(credential.login):\(credential.password)"
|
||||
let data = Data(string.utf8)
|
||||
return ["Authorization" : "Basic \(data.base64EncodedString()), Bearer \(token)"]
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
//
|
||||
// GeojsonConverter.swift - A utility to convert geojson boundaries to polylines.
|
||||
//
|
||||
// Created by Marcus Handte on 20.07.22.
|
||||
//
|
||||
import Foundation
|
||||
import class MoWeStaApi.Geometry
|
||||
import LocosLabGeometry
|
||||
import AnyCodable
|
||||
|
||||
/// A utility to extract coordinates from geojson boundaries.
|
||||
public class GeojsonConverter {
|
||||
|
||||
/// Returns the coordinates of the first (outer) ring found in the geometry.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - of: The geometry to extract coordinates.
|
||||
/// - returns: A (possibly empty) array of coordinates.
|
||||
public static func coordinates(of geometry: Geometry?, simplify: Double) -> [[Coordinate]] {
|
||||
var array: Array<Any> = Array<Any>()
|
||||
var next: Array<Any>? = nil
|
||||
if let c = geometry?.coordinates as? Array<Any> {
|
||||
next = c
|
||||
}
|
||||
//print(geometry?.coordinates)
|
||||
while next != nil {
|
||||
if let c = next {
|
||||
array.append(c)
|
||||
if !c.isEmpty {
|
||||
if let codable = c[0] as? AnyCodable, let x = codable.value as? Array<Any> {
|
||||
next = x
|
||||
} else if let x = c[0] as? Array<Any> {
|
||||
next = x
|
||||
} else {
|
||||
next = nil
|
||||
}
|
||||
} else {
|
||||
next = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
var data: [[Coordinate]] = []
|
||||
if !array.isEmpty {
|
||||
data.append(contentsOf: GeojsonConverter.extract(geometry!.coordinates!, array.count - 1))
|
||||
}
|
||||
var result: [[Coordinate]] = []
|
||||
data.forEach() { cords in
|
||||
result.append(Polylines.simplify(polyline: cords, deviation: simplify))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
public static func extract(_ array: Array<Any>, _ count: Int) -> [[Coordinate]] {
|
||||
var result: [[Coordinate]] = []
|
||||
if count > 2 {
|
||||
for a in array {
|
||||
if let x = a as? AnyCodable, let y = x.value as? Array<Any> {
|
||||
result.append(contentsOf: GeojsonConverter.extract(y, count - 1))
|
||||
} else if let y = a as? Array<Any> {
|
||||
result.append(contentsOf: GeojsonConverter.extract(y, count - 1))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if let firstCodable = array.first as? AnyCodable, let first = firstCodable.value as? Array<Any> {
|
||||
let coords = GeojsonConverter.ring(from: first)
|
||||
if !coords.isEmpty {
|
||||
result.append(coords)
|
||||
}
|
||||
} else if let first = array.first as? Array<Any> {
|
||||
let coords = GeojsonConverter.ring(from: first)
|
||||
if !coords.isEmpty {
|
||||
result.append(coords)
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static func ring(from first: Array<Any>) -> [Coordinate] {
|
||||
var coords: [Coordinate] = []
|
||||
first.forEach({ a in
|
||||
if let c = a as? Array<Any> {
|
||||
if c.count >= 2 {
|
||||
if let long = c[0] as? Double, let lat = c[1] as? Double {
|
||||
coords.append(Coordinate(longitude: long, latitude: lat))
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
return coords
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -14,6 +14,15 @@ public class UserCredentials: ObservableObject {
|
||||
@Published public var login: String = ""
|
||||
/// The account password.
|
||||
@Published public var password: String = ""
|
||||
|
||||
public init() {
|
||||
|
||||
}
|
||||
|
||||
public init(_ login: String, _ password: String) {
|
||||
self.login = login
|
||||
self.password = password
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// CityForecastView.swift
|
||||
// App
|
||||
//
|
||||
// Created by Marcus Handte on 17.07.22.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import class MoWeStaApi.City
|
||||
import class MoWeStaApi.WeatherCondition
|
||||
import class MoWeStaApi.WeatherForecast
|
||||
|
||||
struct CityForecastView: View {
|
||||
|
||||
let city: City
|
||||
let aggregate: WeatherAggregate
|
||||
let gradient: WeatherGradientData
|
||||
let page: Binding<Int>
|
||||
|
||||
|
||||
var body: some View {
|
||||
PageView(pages: [
|
||||
PageItem(id: 0, text: "city_info_gradient") {
|
||||
AnyView(CityGradientView(city: city, data: gradient))
|
||||
},
|
||||
PageItem(id: 1, text: "city_info_day") {
|
||||
AnyView(List(aggregate.days) { summary in
|
||||
WeatherSummaryView(title: summary.title, subtitle: summary.subtitle, summary: summary)
|
||||
}
|
||||
.listStyle(.plain)
|
||||
)
|
||||
},
|
||||
PageItem(id: 2, text: "city_info_time") {
|
||||
AnyView(List(aggregate.times) { summary in
|
||||
WeatherSummaryView(title: summary.title, subtitle: summary.subtitle, summary: summary)
|
||||
}.listStyle(.plain))
|
||||
},
|
||||
PageItem(id: 3, text: "city_info_hour") {
|
||||
AnyView(List(aggregate.hours) { entry in
|
||||
WeatherConditionView(title: entry.title, subtitle: entry.subtitle, condition: entry.condition)
|
||||
}.listStyle(.plain))
|
||||
}
|
||||
], current: page)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
//
|
||||
// CityGradientView.swift
|
||||
// App
|
||||
//
|
||||
// Created by Marcus Handte on 24.07.22.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import class MoWeStaApi.City
|
||||
|
||||
struct CityGradientView: View {
|
||||
|
||||
let city: City
|
||||
let data: WeatherGradientData
|
||||
let schemes = DataColorSchemes()
|
||||
@State var selection: Double?
|
||||
|
||||
var body: some View {
|
||||
GeometryReader { proxy in
|
||||
Group {
|
||||
if proxy.size.width < proxy.size.height {
|
||||
VStack {
|
||||
HStack(spacing: 0) {
|
||||
buildHeader()
|
||||
.frame(maxWidth: .infinity)
|
||||
|
||||
}
|
||||
GeometryReader { proxy2 in
|
||||
ZStack {
|
||||
HStack(spacing: 0) {
|
||||
buildContent(orientation: .vertical)
|
||||
}
|
||||
if let s = selection {
|
||||
let pos = Double(proxy2.size.height) * s
|
||||
let offset = pos < 150 ? pos + 100 : pos - 100
|
||||
CityGradientLabelView(city: city, data: data, orientation: .vertical, selection: s)
|
||||
.position(x:proxy2.size.width / 2, y: offset)
|
||||
}
|
||||
}
|
||||
.gesture(DragGesture(minimumDistance: 0)
|
||||
.onChanged({ value in
|
||||
selection = max(0, min(1, value.location.y / proxy2.size.height))
|
||||
|
||||
})
|
||||
.onEnded({ value in
|
||||
selection = nil
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
HStack {
|
||||
VStack(spacing: 0) {
|
||||
buildHeader()
|
||||
.frame(maxHeight: .infinity)
|
||||
}
|
||||
GeometryReader { proxy2 in
|
||||
ZStack {
|
||||
VStack(spacing: 0) {
|
||||
buildContent(orientation: .horizontal)
|
||||
}
|
||||
if let s = selection {
|
||||
let pos = Double(proxy2.size.width) * s
|
||||
let offset = pos < 180 ? pos + 120 : pos - 120
|
||||
CityGradientLabelView(city: city, data: data, orientation: .horizontal, selection: s)
|
||||
.position(x: CGFloat(offset), y: proxy2.size.height / 2)
|
||||
|
||||
}
|
||||
}
|
||||
.gesture(DragGesture(minimumDistance: 0)
|
||||
.onChanged({ value in
|
||||
selection = max(0, min(1, value.location.x / proxy2.size.width))
|
||||
|
||||
})
|
||||
.onEnded({ value in
|
||||
selection = nil
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}.navigationBarTitleDisplayMode(.inline)
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
func buildHeader() -> some View {
|
||||
Group {
|
||||
Image("icon_thermometer")
|
||||
.accessibilityHint("label_temperature")
|
||||
Image("icon_raindrops")
|
||||
.accessibilityHint("label_precipitation")
|
||||
Image("icon_cloud")
|
||||
.accessibilityHint("label_cloud_coverage")
|
||||
Image(systemName: "clock")
|
||||
.accessibilityHint("label_local_time")
|
||||
Image("icon_humidity")
|
||||
.accessibilityHint("label_humidity")
|
||||
Image("icon_wind")
|
||||
.accessibilityHint("label_wind_speed")
|
||||
Image("icon_barometer")
|
||||
.accessibilityHint("label_pressure")
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
func buildContent(orientation: GradientOrientation) -> some View {
|
||||
GradientView(data: data.temp, colorScheme: schemes.scientificTemperature, background: .clear, orientation: orientation, selection: $selection)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
GradientView(data: data.precipitation, colorScheme: schemes.precipitation, background: .yellow.opacity(0.1), orientation: orientation, selection: $selection)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
GradientView(data: [data.cloudCoverage, data.cloudDepth], colorScheme: [schemes.whiteCloud, schemes.cloudDepth], background: .blue, orientation: orientation, selection: $selection)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
TimeView(data: data.hours, timezone: city.timezone, orientation: orientation, selection: $selection)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
GradientView(data: data.humidity, colorScheme: schemes.humidity, background: .clear, orientation: orientation, selection: $selection)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
GradientView(data: data.windSpeed, colorScheme: schemes.windSpeed, background: .clear, orientation: orientation, selection: $selection)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
GradientView(data: data.pressure, colorScheme: schemes.pressure(min: data.minimumPressure, max: data.maximumPressure, avg: data.averagePressure), background: .clear, orientation: orientation, selection: $selection)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
struct CityGradientLabelView: View {
|
||||
|
||||
@ObservedObject var state = AppState.shared
|
||||
let time: Int64
|
||||
let timezone: String?
|
||||
let temperature: Double
|
||||
let humidity: Double
|
||||
let precipitation: Double
|
||||
let cloudCoverage: Double
|
||||
let pressure: Double
|
||||
let windSpeed: Double
|
||||
let orientation: GradientOrientation
|
||||
|
||||
init(city: City, data: WeatherGradientData, orientation: GradientOrientation, selection: Double) {
|
||||
self.orientation = orientation
|
||||
time = data.getValue(values: data.hours, at: selection) ?? 0
|
||||
timezone = city.timezone
|
||||
temperature = data.getValue(values: data.temp, at: selection) ?? 0
|
||||
humidity = data.getValue(values: data.humidity, at: selection) ?? 0
|
||||
precipitation = data.getValue(values: data.precipitation, at: selection) ?? 0
|
||||
cloudCoverage = data.getValue(values: data.cloudCoverage, at: selection) ?? 0
|
||||
pressure = data.getValue(values: data.pressure, at: selection) ?? 0
|
||||
windSpeed = data.getValue(values: data.windSpeed, at: selection) ?? 0
|
||||
}
|
||||
|
||||
|
||||
var body: some View {
|
||||
if orientation == .vertical {
|
||||
VStack(spacing: 0) {
|
||||
HStack {
|
||||
Text(DataBindings.getTemperature(temperature, state.temperatureUnit))
|
||||
.font(.caption)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.lineLimit(1)
|
||||
.foregroundColor(.white)
|
||||
Text(DataBindings.getCloudCoverage(cloudCoverage))
|
||||
.font(.caption)
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
.lineLimit(1)
|
||||
.foregroundColor(.white)
|
||||
Text(DataBindings.getHumidity(humidity))
|
||||
.font(.caption)
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
.lineLimit(1)
|
||||
.foregroundColor(.white)
|
||||
Text(DataBindings.getPressure(pressure, state.unitSystem))
|
||||
.font(.caption)
|
||||
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||
.lineLimit(1)
|
||||
.foregroundColor(.white)
|
||||
}.padding(.bottom, 8)
|
||||
HStack {
|
||||
Text(DataBindings.getPrecipitation(precipitation, state.unitSystem))
|
||||
.font(.caption)
|
||||
.frame(maxWidth: .infinity)
|
||||
.lineLimit(1)
|
||||
.foregroundColor(.white)
|
||||
Text("format_title \(DataBindings.getWeekday(time, timezone)) \(DataBindings.getTime(time, timezone))")
|
||||
.font(.caption)
|
||||
.frame(maxWidth: .infinity)
|
||||
.lineLimit(1)
|
||||
.foregroundColor(.white)
|
||||
Text(DataBindings.getWindSpeed(windSpeed, state.unitSystem))
|
||||
.font(.caption)
|
||||
.frame(maxWidth: .infinity)
|
||||
.lineLimit(1)
|
||||
.foregroundColor(.white)
|
||||
}
|
||||
}
|
||||
.padding(8)
|
||||
.background(Color.black)
|
||||
} else {
|
||||
VStack(spacing: 0) {
|
||||
Text(DataBindings.getTemperature(temperature, state.temperatureUnit))
|
||||
.font(.caption)
|
||||
.frame(maxHeight: .infinity)
|
||||
.multilineTextAlignment(.center)
|
||||
.lineLimit(2)
|
||||
.foregroundColor(.white)
|
||||
Text(DataBindings.getPrecipitation(precipitation, state.unitSystem))
|
||||
.font(.caption)
|
||||
.frame(maxHeight: .infinity)
|
||||
.multilineTextAlignment(.center)
|
||||
.lineLimit(2)
|
||||
.foregroundColor(.white)
|
||||
Text(DataBindings.getCloudCoverage(cloudCoverage))
|
||||
.font(.caption)
|
||||
.frame(maxHeight: .infinity)
|
||||
.multilineTextAlignment(.center)
|
||||
.lineLimit(2)
|
||||
.foregroundColor(.white)
|
||||
Text("format_title \(DataBindings.getWeekday(time, timezone)) \(DataBindings.getTime(time, timezone))")
|
||||
.font(.caption)
|
||||
.frame(maxHeight: .infinity)
|
||||
.multilineTextAlignment(.center)
|
||||
.lineLimit(2)
|
||||
.foregroundColor(.white)
|
||||
Text(DataBindings.getHumidity(humidity))
|
||||
.font(.caption)
|
||||
.frame(maxHeight: .infinity)
|
||||
.multilineTextAlignment(.center)
|
||||
.lineLimit(2)
|
||||
.foregroundColor(.white)
|
||||
Text(DataBindings.getWindSpeed(windSpeed, state.unitSystem))
|
||||
.font(.caption)
|
||||
.frame(maxHeight: .infinity)
|
||||
.multilineTextAlignment(.center)
|
||||
.lineLimit(2)
|
||||
.foregroundColor(.white)
|
||||
Text(DataBindings.getPressure(pressure, state.unitSystem))
|
||||
.font(.caption)
|
||||
.frame(maxHeight: .infinity)
|
||||
.multilineTextAlignment(.center)
|
||||
.lineLimit(2)
|
||||
.foregroundColor(.white)
|
||||
}
|
||||
.frame(width: 120)
|
||||
.background(Color.black)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -9,46 +9,27 @@ import SwiftUI
|
||||
import class MoWeStaApi.City
|
||||
import class MoWeStaApi.WeatherCondition
|
||||
import class MoWeStaApi.WeatherStation
|
||||
import LocosLabGeometry
|
||||
|
||||
struct CityInfoView: View {
|
||||
|
||||
var city: City
|
||||
var condition: WeatherCondition?
|
||||
var condition: WeatherCondition
|
||||
var station: WeatherStation?
|
||||
var boundary: [[Coordinate]]?
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
ScrollView(showsIndicators: false) {
|
||||
VStack {
|
||||
if let c = condition {
|
||||
VStack {
|
||||
HStack {
|
||||
Image(ImageBindings.getWeatherIcon(c))
|
||||
.renderingMode(.template)
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: 60)
|
||||
VStack {
|
||||
Text("city_info_title")
|
||||
.font(.body)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
Text(TextBindings.getWeatherSource(c))
|
||||
.font(.body)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
}
|
||||
Text(TextBindings.getWeatherType(c))
|
||||
.font(.title)
|
||||
.frame(maxWidth: .infinity)
|
||||
|
||||
}.padding()
|
||||
Divider()
|
||||
}
|
||||
WeatherConditionView(title: "city_info_title", subtitle: LocalizedStringKey(TextBindings.getWeatherSource(condition)), condition: condition)
|
||||
.padding()
|
||||
Divider()
|
||||
HStack {
|
||||
Image(systemName: "building.2")
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: 40)
|
||||
.padding([.trailing, .leading], 10)
|
||||
.padding([.trailing], 10)
|
||||
VStack(alignment: .leading) {
|
||||
if let cityName = TextBindings.getName(city.names, false) {
|
||||
Text(verbatim: cityName)
|
||||
@@ -57,24 +38,32 @@ struct CityInfoView: View {
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
if let state = city.state, let stateName = TextBindings.getName(state.names, false) {
|
||||
Text(verbatim: stateName)
|
||||
.lineLimit(1)
|
||||
.font(.body)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
NavigationLink(destination: {
|
||||
StateView(stateId: state.id!)
|
||||
}) {
|
||||
Text(verbatim: stateName)
|
||||
.lineLimit(1)
|
||||
.font(.body)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
}
|
||||
if let countryName = TextBindings.getName(city.country.names, false) {
|
||||
Text(verbatim: countryName)
|
||||
.lineLimit(1)
|
||||
.font(.body)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
NavigationLink(destination: {
|
||||
CountryView(countryId: city.country.id!)
|
||||
}) {
|
||||
Text(verbatim: countryName)
|
||||
.lineLimit(1)
|
||||
.font(.body)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
}
|
||||
}
|
||||
}.padding()
|
||||
Divider()
|
||||
VStack(alignment: .leading) {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
HStack {
|
||||
Image(systemName: "building")
|
||||
.frame(width: 60)
|
||||
.frame(width: 50)
|
||||
.font(.body)
|
||||
Text("label_city_type")
|
||||
Text(TextBindings.getCityType(city))
|
||||
@@ -84,7 +73,7 @@ struct CityInfoView: View {
|
||||
if let population = city.population {
|
||||
HStack {
|
||||
Image(systemName: "person.2")
|
||||
.frame(width: 60)
|
||||
.frame(width: 50)
|
||||
.font(.body)
|
||||
Text("label_population")
|
||||
Text(verbatim: "\(population)")
|
||||
@@ -92,27 +81,59 @@ struct CityInfoView: View {
|
||||
}.padding([.top, .bottom], 1)
|
||||
}
|
||||
HStack {
|
||||
Image(systemName: "clock")
|
||||
.frame(width: 60)
|
||||
Image(systemName: "map")
|
||||
.frame(width: 50)
|
||||
.font(.body)
|
||||
Text("label_timezone")
|
||||
Text(city.timezone)
|
||||
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||
}.padding([.top, .bottom], 1)
|
||||
|
||||
HStack {
|
||||
let time = Int64(Date().timeIntervalSince1970 * 1000)
|
||||
Image(systemName: "clock")
|
||||
.frame(width: 50)
|
||||
.font(.body)
|
||||
Text("label_local_time")
|
||||
Text("format_title \(DataBindings.getTime(time, city.timezone)) \(DataBindings.getDate(time, city.timezone))")
|
||||
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||
}.padding([.top, .bottom], 1)
|
||||
if let s = station {
|
||||
HStack {
|
||||
Image("icon_station")
|
||||
.frame(width: 50)
|
||||
.font(.body)
|
||||
.opacity(0.9)
|
||||
Text("label_station")
|
||||
.lineLimit(1)
|
||||
NavigationLink(destination: {
|
||||
StationView(station: s)
|
||||
}) {
|
||||
Text(s.name)
|
||||
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||
}
|
||||
}.padding([.top, .bottom], 1)
|
||||
}
|
||||
}.padding()
|
||||
Divider()
|
||||
PlaceMapView(center: Coordinate(longitude: city.coordinate.longitude, latitude: city.coordinate.latitude), zoom: 13, boundary: boundary)
|
||||
.frame(height: 200)
|
||||
.frame(maxWidth: .infinity)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 6))
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
struct CityInfoView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
|
||||
NavigationView {
|
||||
CityView(11409950)
|
||||
CityView(cityId: 11409950)
|
||||
.environmentObject(TabViewState())
|
||||
.environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,259 @@
|
||||
//
|
||||
// CityVideoView.swift
|
||||
// App
|
||||
//
|
||||
// Created by Marcus Handte on 18.07.22.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import class MoWeStaApi.WeatherVideo
|
||||
import class MoWeStaApi.City
|
||||
import class LocosLabLeafless.MapProjection
|
||||
import AVKit
|
||||
import LocosLabLeafless
|
||||
|
||||
struct CityVideoView: View {
|
||||
|
||||
var city: City
|
||||
var videos: WeatherVideos
|
||||
var pages: [PageItem] = []
|
||||
var page: Binding<Int>
|
||||
|
||||
init(city: City, videos: WeatherVideos, page: Binding<Int>) {
|
||||
self.city = city
|
||||
self.videos = videos
|
||||
self.page = page
|
||||
var id = 0
|
||||
if !videos.cosmoEurope.isEmpty {
|
||||
pages.append(PageItem(id: id, text: "video_source_cosmo_europe") {
|
||||
AnyView(
|
||||
List(videos.cosmoEurope, id: \WeatherVideo.type) { video in
|
||||
WeatherVideoImageView(city: city, video: video)
|
||||
}.listStyle(.plain)
|
||||
)
|
||||
})
|
||||
id += 1
|
||||
}
|
||||
if !videos.iconEurope.isEmpty {
|
||||
pages.append(PageItem(id: id, text: "video_source_icon_europe") {
|
||||
AnyView(
|
||||
List(videos.iconEurope, id: \WeatherVideo.type) { video in
|
||||
WeatherVideoImageView(city: city, video: video)
|
||||
}.listStyle(.plain)
|
||||
)
|
||||
})
|
||||
id += 1
|
||||
}
|
||||
if !videos.iconGlobal.isEmpty {
|
||||
pages.append(PageItem(id: id, text: "video_source_icon_global") {
|
||||
AnyView(
|
||||
List(videos.iconGlobal, id: \WeatherVideo.type) { video in
|
||||
WeatherVideoImageView(city: city, video: video)
|
||||
}.listStyle(.plain)
|
||||
)
|
||||
})
|
||||
id += 1
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
PageView(pages: pages, current: page)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct WeatherVideoImageView: View {
|
||||
|
||||
let city: City
|
||||
let video: WeatherVideo
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
VStack(alignment: .center) {
|
||||
RemoteImageView(url: URL(string: video.preview)!, placeholder: {
|
||||
Image(systemName: "film")
|
||||
.resizable()
|
||||
.aspectRatio(CGSize(width: 16, height: 9), contentMode: .fit)
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(32)
|
||||
.foregroundColor(Color("PrimaryColor").opacity(0.7))
|
||||
.background(Color.gray.opacity(0.2))
|
||||
.clipShape(RoundedRectangle(cornerRadius: 6))
|
||||
}, image: { image in
|
||||
image
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(maxWidth: .infinity)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 6))
|
||||
})
|
||||
Text(TextBindings.getVideoType(video.type))
|
||||
}
|
||||
NavigationLink(destination: WeatherVideoPlayerView(city: city, video: video)) {
|
||||
EmptyView()
|
||||
}.buttonStyle(PlainButtonStyle())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct WeatherVideoPlayerView: View {
|
||||
|
||||
let player: AVPlayer
|
||||
let city: City
|
||||
let video: WeatherVideo
|
||||
@State var seconds: Double = 0
|
||||
@State var observer: Any?
|
||||
@State var day = ""
|
||||
@State var time = ""
|
||||
@State var legend = true
|
||||
|
||||
init(city: City, video: WeatherVideo) {
|
||||
self.city = city
|
||||
self.video = video
|
||||
self.player = AVPlayer(url: URL(string: video.url)!)
|
||||
}
|
||||
|
||||
func computeCityOffset(size: CGSize) -> (CGFloat, CGFloat) {
|
||||
let sf = max(CGFloat(video.width) / size.width, CGFloat(video.height) / size.height)
|
||||
let width = CGFloat(video.width) / sf
|
||||
let height = CGFloat(video.height) / sf
|
||||
|
||||
let projection = MapProjection()
|
||||
let max = projection.project(longitude: video.northEast.longitude, latitude: video.northEast.latitude)
|
||||
let min = projection.project(longitude: video.southWest.longitude, latitude: video.southWest.latitude)
|
||||
let p = projection.project(longitude: city.coordinate.longitude, latitude: city.coordinate.latitude)
|
||||
|
||||
let dx = p.x - min.x
|
||||
let dy = p.y - min.y
|
||||
let tx = max.x - min.x
|
||||
let ty = max.y - min.y
|
||||
|
||||
let px = dx / tx
|
||||
let py = 1 - (dy / ty)
|
||||
|
||||
let x = width * px
|
||||
let y = height * py
|
||||
|
||||
return (x, y)
|
||||
}
|
||||
|
||||
func ignoreSafeArea(size: CGSize) -> Bool {
|
||||
return size.height > size.width
|
||||
}
|
||||
|
||||
func computeScaleDimensions(size: CGSize) -> (CGFloat, CGFloat, CGFloat, CGFloat) {
|
||||
let sf = max(CGFloat(video.width) / size.width, CGFloat(video.height) / size.height)
|
||||
let videoWidth = CGFloat(video.width) / sf
|
||||
let videoHeight = CGFloat(video.height) / sf
|
||||
|
||||
let labelWidth = size.width * 0.50
|
||||
let labelHeight = labelWidth / 10
|
||||
|
||||
if videoHeight + labelHeight + 10 < size.height {
|
||||
return (videoWidth / 2, videoHeight + labelHeight / 2 + 8, labelWidth, labelHeight)
|
||||
} else {
|
||||
return (videoWidth / 2, videoHeight - 4 - labelHeight / 2, labelWidth, labelHeight)
|
||||
}
|
||||
}
|
||||
|
||||
func computeLabelDimensions(size: CGSize) -> (CGFloat, CGFloat, CGFloat, CGFloat) {
|
||||
let sf = max(CGFloat(video.width) / size.width, CGFloat(video.height) / size.height)
|
||||
let videoWidth = CGFloat(video.width) / sf
|
||||
let videoHeight = CGFloat(video.height) / sf
|
||||
|
||||
let labelWidth = CGFloat(100)
|
||||
let labelHeight = CGFloat(50)
|
||||
|
||||
if videoHeight + labelHeight + 4 < size.height {
|
||||
return (videoWidth - labelWidth / 2 - 4, -labelHeight / 2 - 4, labelWidth, labelHeight)
|
||||
} else {
|
||||
return (videoWidth - labelWidth / 2 - 4, labelHeight / 2 + 4, labelWidth, labelHeight)
|
||||
}
|
||||
}
|
||||
|
||||
func updateLabelContent() {
|
||||
let hps = Double(video.fph) / Double(video.fps)
|
||||
let hours = seconds / hps
|
||||
let timestamp = video.time + Int64(video.start + Int(round(hours))) * 60 * 60 * 1000
|
||||
day = DataBindings.getWeekday(timestamp, city.timezone)
|
||||
time = DataBindings.getTime(timestamp, city.timezone)
|
||||
}
|
||||
|
||||
|
||||
|
||||
var body: some View {
|
||||
GeometryReader { proxy in
|
||||
let cityPosition = computeCityOffset(size: proxy.size)
|
||||
let scaleDimensions = computeScaleDimensions(size: proxy.size)
|
||||
let labelDimensions = computeLabelDimensions(size: proxy.size)
|
||||
VideoPlayer(player: player) {
|
||||
ZStack(alignment: .topLeading) {
|
||||
Color.clear
|
||||
RoundedRectangle(cornerRadius: 2)
|
||||
.foregroundColor(.white)
|
||||
.position(x: scaleDimensions.0, y: scaleDimensions.1 - 2)
|
||||
.frame(width: scaleDimensions.2 + 8, height: scaleDimensions.3 + 4)
|
||||
.opacity(legend ? 0.4 : 0)
|
||||
RemoteImageView(url: URL(string: video.scale)!, placeholder: { EmptyView() }) { image in
|
||||
image
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.position(x: scaleDimensions.0, y: scaleDimensions.1)
|
||||
.frame(width: scaleDimensions.2, height: scaleDimensions.3)
|
||||
}
|
||||
.opacity(legend ? 1 : 0)
|
||||
Circle()
|
||||
.strokeBorder(Color.accentColor, lineWidth: 2)
|
||||
.position(x: cityPosition.0, y: cityPosition.1)
|
||||
.frame(width: 10, height: 10)
|
||||
RoundedRectangle(cornerRadius: 6)
|
||||
.foregroundColor(Color.accentColor)
|
||||
.frame(width: labelDimensions.2, height: labelDimensions.3, alignment: .center)
|
||||
.position(x: labelDimensions.0, y: labelDimensions.1)
|
||||
VStack {
|
||||
Text(day).lineLimit(1).font(.caption)
|
||||
.foregroundColor(.black)
|
||||
Text(time).lineLimit(1).font(.caption)
|
||||
.foregroundColor(.black)
|
||||
} .frame(width: labelDimensions.2, height: labelDimensions.3, alignment: .center)
|
||||
.position(x: labelDimensions.0, y: labelDimensions.1)
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.ignoresSafeArea()
|
||||
}
|
||||
.aspectRatio(CGSize(width: 16, height: 9), contentMode: .fit)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.onAppear() {
|
||||
observer = player.addPeriodicTimeObserver(forInterval: CMTime(seconds: 0.5, preferredTimescale: 600), queue: nil) { time in
|
||||
seconds = time.seconds
|
||||
updateLabelContent()
|
||||
}
|
||||
player.play()
|
||||
}
|
||||
.onDisappear() {
|
||||
if let o = observer {
|
||||
player.removeTimeObserver(o)
|
||||
observer = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
.toolbar() {
|
||||
ToolbarItemGroup(placement: .navigationBarLeading) {
|
||||
Button(action: {
|
||||
legend.toggle()
|
||||
}) {
|
||||
if legend {
|
||||
Image(systemName: "minus.circle.fill")
|
||||
} else {
|
||||
Image(systemName: "minus.circle")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.navigationBarHidden(true)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.ignoresSafeArea()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import MapKit
|
||||
import class MoWeStaApi.City
|
||||
import class MoWeStaApi.DefaultAPI
|
||||
import class MoWeStaApi.WeatherCondition
|
||||
@@ -13,28 +14,64 @@ import class MoWeStaApi.WeatherForecast
|
||||
import class MoWeStaApi.WeatherVideo
|
||||
import class MoWeStaApi.WeatherVideoPage
|
||||
import class MoWeStaApi.WeatherStation
|
||||
import LocosLabGeometry
|
||||
import AnyCodable
|
||||
|
||||
struct CityView: View {
|
||||
|
||||
@Environment(\.managedObjectContext) private var viewContext
|
||||
@EnvironmentObject var tabViewState: TabViewState
|
||||
|
||||
var cityId: Int64
|
||||
|
||||
@State var favorite: Favorite?
|
||||
@State var cityName: String?
|
||||
@State var condition: WeatherCondition?
|
||||
@State var station: WeatherStation?
|
||||
@State var forecast: WeatherForecast?
|
||||
@State var videos: WeatherVideoPage?
|
||||
@State var aggregate: WeatherAggregate?
|
||||
@State var gradient: WeatherGradientData?
|
||||
@State var videos: WeatherVideos?
|
||||
@State var boundary: [[Coordinate]]?
|
||||
@State var city: City?
|
||||
@State var loading = 0
|
||||
@State var failure = false
|
||||
@State var customize = false
|
||||
@State var videoPage = 0
|
||||
@State var forecastPage = 0
|
||||
|
||||
init(_ cityId: Int64) {
|
||||
// autocomputed value to display a loading bar at the bottom
|
||||
@State var showLoadingAnimation = false
|
||||
|
||||
init(cityId: Int64) {
|
||||
self.cityId = cityId
|
||||
}
|
||||
|
||||
func reload() {
|
||||
print(cityId)
|
||||
favorite = nil // core data is too clever, so we must force a reload to detect field changes
|
||||
let request = Favorite.fetchRequest()
|
||||
request.predicate = NSPredicate(format: "%K == %@ AND %K == %@", #keyPath(Favorite.identifier), cityId as NSNumber, #keyPath(Favorite.locationType), 0 as NSNumber)
|
||||
if let result = try? viewContext.fetch(request) {
|
||||
if let first = result.first {
|
||||
favorite = first
|
||||
let now = Int64(NSDate().timeIntervalSince1970)
|
||||
if now - first.locationTime < RefreshTask.LOCATION_TIMEOUT {
|
||||
self.city = first.cityValue
|
||||
if let c = self.city {
|
||||
cityName = TextBindings.getName(c.names, false)
|
||||
}
|
||||
self.boundary = GeojsonConverter.coordinates(of: first.boundaryValue, simplify: 20)
|
||||
self.station = first.stationValue
|
||||
}
|
||||
if now - first.weatherTime < RefreshTask.WEATHER_TIMEOUT {
|
||||
self.forecast = first.forecastValue
|
||||
self.condition = first.conditionValue
|
||||
updateAggregate()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
favorite = nil
|
||||
}
|
||||
failure = false
|
||||
if city == nil {
|
||||
loading += 1
|
||||
@@ -43,30 +80,7 @@ struct CityView: View {
|
||||
if let r = response {
|
||||
city = r
|
||||
cityName = TextBindings.getName(r.names, false)
|
||||
} else {
|
||||
failure = true
|
||||
}
|
||||
loading -= 1
|
||||
}
|
||||
}
|
||||
if videos == nil {
|
||||
loading += 1
|
||||
DefaultAPI.getCityVideos(id: cityId) {
|
||||
response, error in
|
||||
if let r = response {
|
||||
videos = r
|
||||
} else {
|
||||
failure = true
|
||||
}
|
||||
loading -= 1
|
||||
}
|
||||
}
|
||||
if forecast == nil {
|
||||
loading += 1
|
||||
DefaultAPI.getCityForecast(id: cityId) {
|
||||
response, error in
|
||||
if let r = response {
|
||||
forecast = r
|
||||
updateAggregate()
|
||||
} else {
|
||||
failure = true
|
||||
}
|
||||
@@ -88,61 +102,256 @@ struct CityView: View {
|
||||
if station == nil {
|
||||
loading += 1
|
||||
DefaultAPI.getCityStation(id: cityId) {
|
||||
response, error in
|
||||
if error != nil {
|
||||
failure = true
|
||||
} else {
|
||||
station = response
|
||||
}
|
||||
loading -= 1
|
||||
}
|
||||
}
|
||||
if forecast == nil {
|
||||
loading += 1
|
||||
DefaultAPI.getCityForecast(id: cityId) {
|
||||
response, error in
|
||||
if let r = response {
|
||||
station = r
|
||||
forecast = r
|
||||
updateAggregate()
|
||||
} else {
|
||||
failure = true
|
||||
}
|
||||
loading -= 1
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if videos == nil {
|
||||
loading += 1
|
||||
DefaultAPI.getLatestCityVideos(id: cityId) {
|
||||
response, error in
|
||||
if let r = response {
|
||||
videos = WeatherVideos(r)
|
||||
} else {
|
||||
failure = true
|
||||
}
|
||||
loading -= 1
|
||||
}
|
||||
}
|
||||
if boundary == nil {
|
||||
loading += 1
|
||||
DefaultAPI.getCityBoundary(id: cityId) {
|
||||
response, error in
|
||||
if error != nil {
|
||||
failure = true
|
||||
} else {
|
||||
boundary = GeojsonConverter.coordinates(of: response, simplify: 20)
|
||||
}
|
||||
loading -= 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder func buildInfo() -> some View {
|
||||
if let ct = city {
|
||||
CityInfoView(city: ct, condition: condition, station: station)
|
||||
private func updateAggregate() {
|
||||
if let c = city, let f = forecast {
|
||||
aggregate = WeatherAggregate(f.conditions, c.timezone)
|
||||
gradient = WeatherGradientData(f)
|
||||
} else {
|
||||
EmptyView()
|
||||
aggregate = nil
|
||||
gradient = nil
|
||||
}
|
||||
}
|
||||
|
||||
private func openMaps(_ name: String, _ longitude: Double, _ latitude: Double) {
|
||||
let coordinates = CLLocationCoordinate2DMake(latitude, longitude)
|
||||
let regionSpan = MKCoordinateRegion(center: coordinates, latitudinalMeters: 5000, longitudinalMeters: 5000)
|
||||
let options = [
|
||||
MKLaunchOptionsMapCenterKey: NSValue(mkCoordinate: regionSpan.center),
|
||||
MKLaunchOptionsMapSpanKey: NSValue(mkCoordinateSpan: regionSpan.span)
|
||||
]
|
||||
let placemark = MKPlacemark(coordinate: coordinates, addressDictionary: nil)
|
||||
let mapItem = MKMapItem(placemark: placemark)
|
||||
mapItem.name = name
|
||||
mapItem.openInMaps(launchOptions: options)
|
||||
}
|
||||
|
||||
|
||||
@ViewBuilder func buildInfo() -> some View {
|
||||
VStack(spacing: 0) {
|
||||
if let ct = city, let co = condition {
|
||||
VStack(spacing: 0) {
|
||||
CityInfoView(city: ct, condition: co, station: station, boundary: boundary)
|
||||
.frame(maxWidth: 800)
|
||||
if (showLoadingAnimation) {
|
||||
ProgressBarView(animating: $showLoadingAnimation)
|
||||
.frame(height: 3)
|
||||
}
|
||||
}
|
||||
} else if loading > 0 {
|
||||
ProgressSpinnerView()
|
||||
}
|
||||
if loading == 0 && failure {
|
||||
Spacer()
|
||||
ErrorView() {
|
||||
reload()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder func buildForecast() -> some View {
|
||||
VStack(spacing: 0) {
|
||||
if let ct = city, let a = aggregate, let g = gradient {
|
||||
CityForecastView(city: ct, aggregate: a, gradient: g, page: $forecastPage)
|
||||
.frame(maxWidth: 800)
|
||||
} else if loading > 0 {
|
||||
ProgressSpinnerView()
|
||||
}
|
||||
if loading == 0 && failure {
|
||||
Spacer()
|
||||
ErrorView() {
|
||||
reload()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder func buildVideo() -> some View {
|
||||
VStack(spacing: 0) {
|
||||
if let ct = city, let vids = videos {
|
||||
CityVideoView(city: ct, videos: vids, page: $videoPage)
|
||||
.frame(maxWidth: 800)
|
||||
} else if loading > 0 {
|
||||
ProgressSpinnerView()
|
||||
}
|
||||
if loading == 0 && failure {
|
||||
Spacer()
|
||||
ErrorView() {
|
||||
reload()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var body: some View {
|
||||
HideableTabView("city") {
|
||||
[
|
||||
HideableTabItem(id: 0, text: "city_info", image: "info") {
|
||||
AnyView(buildInfo())
|
||||
},
|
||||
HideableTabItem(id: 1, text: "city_forecast", image: "calendar") {
|
||||
AnyView(EmptyView())
|
||||
},
|
||||
HideableTabItem(id: 2, text: "city_video", image: "video") {
|
||||
AnyView(EmptyView())
|
||||
GeometryReader { proxy in
|
||||
VStack(spacing: 0) {
|
||||
HideableTabView("city", proxy.safeAreaInsets) {
|
||||
[
|
||||
HideableTabItem(id: 0, text: "city_info", image: Image(systemName:"info.circle")) {
|
||||
AnyView(buildInfo())
|
||||
},
|
||||
HideableTabItem(id: 1, text: "city_forecast", image: Image(systemName:"calendar")) {
|
||||
AnyView(buildForecast())
|
||||
},
|
||||
HideableTabItem(id: 2, text: "city_video", image: Image(systemName:"film")) {
|
||||
AnyView(buildVideo())
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
Color("PrimaryColor")
|
||||
.frame(height: proxy.safeAreaInsets.bottom)
|
||||
.frame(maxWidth: .infinity)
|
||||
}.ignoresSafeArea(.all, edges: [.leading, .trailing, .bottom])
|
||||
}
|
||||
.if((cityName != nil)) {
|
||||
v in
|
||||
v.navigationTitle(cityName!)
|
||||
}
|
||||
.toolbar() {
|
||||
ToolbarItemGroup(placement: .navigationBarTrailing) {
|
||||
if loading == 0 {
|
||||
if Favorites.canDelete(favorite) {
|
||||
Button(action: {
|
||||
Favorites.delete(viewContext, favorite)
|
||||
reload()
|
||||
}) {
|
||||
Image(systemName: "heart.slash")
|
||||
}
|
||||
} else if !failure {
|
||||
Button(action: {
|
||||
Favorites.add(viewContext, favorite) { fav in
|
||||
fav.setLocationType(type: .city)
|
||||
fav.identifier = cityId
|
||||
fav.cityValue = city
|
||||
fav.locationValue = city
|
||||
fav.stationValue = station
|
||||
fav.forecastValue = forecast
|
||||
fav.conditionValue = condition
|
||||
}
|
||||
reload()
|
||||
}) {
|
||||
Image(systemName: "heart")
|
||||
}
|
||||
}
|
||||
}
|
||||
if let c = city, let name = TextBindings.getName(c.names, false) {
|
||||
Button(action: {
|
||||
openMaps(name, c.coordinate.longitude, c.coordinate.latitude)
|
||||
}) {
|
||||
Image(systemName: "map")
|
||||
}
|
||||
}
|
||||
Button(action: {
|
||||
customize.toggle()
|
||||
}) {
|
||||
Image(systemName: "gearshape")
|
||||
.accessibilityHint("action_customize")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $customize) {
|
||||
NavigationView() {
|
||||
CustomizeView()
|
||||
.navigationBarItems(trailing:
|
||||
Button(action: {
|
||||
customize.toggle()
|
||||
}) {
|
||||
Text("button_done")
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
.onAppear() {
|
||||
reload()
|
||||
tabViewState.setHidden(view: "main", hidden: true)
|
||||
}
|
||||
.onDisappear() { tabViewState.setHidden(view: "main", hidden: false)}
|
||||
.onChange(of: loading) { v in
|
||||
showLoadingAnimation = v > 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct WeatherVideos {
|
||||
|
||||
var cosmoEurope: [WeatherVideo] = []
|
||||
var iconEurope: [WeatherVideo] = []
|
||||
var iconGlobal: [WeatherVideo] = []
|
||||
|
||||
init(_ videos: [WeatherVideo]) {
|
||||
for v in videos {
|
||||
switch v.source {
|
||||
case .cosmoEurope:
|
||||
cosmoEurope.append(v)
|
||||
case .iconEurope:
|
||||
iconEurope.append(v)
|
||||
case .iconGlobal:
|
||||
iconGlobal.append(v)
|
||||
default:
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct CityView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
NavigationView {
|
||||
CityView(11409950)
|
||||
CityView(cityId: 11409950)
|
||||
.environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
|
||||
.environmentObject(TabViewState())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
//
|
||||
// CollectionView.swift
|
||||
// App
|
||||
//
|
||||
// Created by Marcus Handte on 13.07.22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
struct CollectionView: View {
|
||||
|
||||
@ObservedObject var appState = AppState.shared
|
||||
|
||||
@State var enabled = false { didSet { print(enabled) }}
|
||||
|
||||
|
||||
var body: some View {
|
||||
Group {
|
||||
VStack {
|
||||
ScrollView {
|
||||
ZStack(alignment: .topTrailing) {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
Text("collection_explain")
|
||||
.font(.body)
|
||||
Text("collection_note_location")
|
||||
.font(.body)
|
||||
Text("collection_note_data")
|
||||
.font(.body)
|
||||
Text("collection_note_enable")
|
||||
.font(.body)
|
||||
Toggle(isOn: $enabled) {
|
||||
Text("collection_on_off")
|
||||
.foregroundColor(Color("PrimaryColor"))
|
||||
.font(.title2.smallCaps())
|
||||
}.padding([.top, .bottom], 5)
|
||||
Text("collection_note_permission")
|
||||
.font(.body)
|
||||
Button("collection_button_continue") {
|
||||
// todo
|
||||
}.buttonStyle(MaterialButtonStyle(disabled: false))
|
||||
.padding(.top, 5)
|
||||
}.padding()
|
||||
Image("mowesta_sun")
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: 110, height: 110)
|
||||
.offset(x: -10, y: -105)
|
||||
}
|
||||
}
|
||||
Divider()
|
||||
HStack {
|
||||
Link(destination: URL(string: "https://www.uni-due.de")!) {
|
||||
Image("logo_ude")
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(maxWidth: .infinity, maxHeight: 70)
|
||||
}.padding([.leading, .trailing], 5)
|
||||
Link(destination: URL(string: "https://www.fair-opendata.de")!) {
|
||||
Image("logo_fair")
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(maxWidth: .infinity, maxHeight: 70)
|
||||
}.padding([.leading, .trailing], 5)
|
||||
}
|
||||
}
|
||||
}
|
||||
.navigationTitle("collection_title")
|
||||
.navigationBarTitleDisplayMode(.large)
|
||||
.navigationBarHidden(false)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
struct CollectionView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
NavigationView {
|
||||
CollectionView()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,228 @@
|
||||
//
|
||||
// CountryView.swift
|
||||
// App
|
||||
//
|
||||
// Created by Marcus Handte on 20.07.22.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import class MoWeStaApi.City
|
||||
import class MoWeStaApi.Country
|
||||
import class MoWeStaApi.DefaultAPI
|
||||
import LocosLabGeometry
|
||||
|
||||
struct CountryView: View {
|
||||
|
||||
@Environment(\.managedObjectContext) private var viewContext
|
||||
|
||||
let countryId: Int64
|
||||
|
||||
@State var country: Country? = nil
|
||||
@State var countryName: String? = nil
|
||||
@State var boundary: [[Coordinate]]? = nil
|
||||
@State var cities: [City] = []
|
||||
@State var loading = 0
|
||||
@State var failure = false
|
||||
@State var offset = 0
|
||||
@State var total = -1
|
||||
@State var favorite: Favorite?
|
||||
@State var showLoadingAnimation = false
|
||||
|
||||
|
||||
func reload() {
|
||||
if loading != 0 {
|
||||
return
|
||||
}
|
||||
favorite = nil // core data is too clever, so we must force a reload to detect field changes
|
||||
let request = Favorite.fetchRequest()
|
||||
request.predicate = NSPredicate(format: "%K == %@ AND %K == %@", #keyPath(Favorite.identifier), countryId as NSNumber, #keyPath(Favorite.locationType), 2 as NSNumber)
|
||||
if let result = try? viewContext.fetch(request) {
|
||||
if let first = result.first {
|
||||
favorite = first
|
||||
let now = Int64(NSDate().timeIntervalSince1970)
|
||||
if now - first.locationTime < RefreshTask.LOCATION_TIMEOUT {
|
||||
if let loc = first.locationValue as? Country {
|
||||
self.country = loc
|
||||
countryName = TextBindings.getName(loc.names, false)
|
||||
}
|
||||
// too much data
|
||||
//self.boundary = GeojsonConverter.coordinates(of: first.boundaryValue, simplify: 150)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
favorite = nil
|
||||
}
|
||||
failure = false
|
||||
if country == nil {
|
||||
loading += 1
|
||||
DefaultAPI.getCountry(id: countryId) {
|
||||
response, error in
|
||||
if let _ = error {
|
||||
self.failure = true
|
||||
} else if let r = response {
|
||||
country = r
|
||||
countryName = TextBindings.getName(r.names, false)
|
||||
}
|
||||
loading -= 1
|
||||
}
|
||||
}
|
||||
if boundary == nil {
|
||||
loading += 1
|
||||
DefaultAPI.getCountryBoundary(id: countryId, apiResponseQueue: DispatchQueue.global()) {
|
||||
response, error in
|
||||
var simplified: [[Coordinate]] = []
|
||||
if let r = response {
|
||||
simplified = GeojsonConverter.coordinates(of: r, simplify: 150)
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
if let _ = error {
|
||||
self.failure = true
|
||||
} else {
|
||||
boundary = simplified
|
||||
}
|
||||
loading -= 1
|
||||
}
|
||||
}
|
||||
}
|
||||
if total == -1 {
|
||||
if cities.isEmpty {
|
||||
loading += 1
|
||||
DefaultAPI.getCountryCities(id: countryId) {
|
||||
response, error in
|
||||
if let _ = error {
|
||||
self.failure = true
|
||||
} else if let r = response {
|
||||
cities.append(contentsOf: r.elements)
|
||||
total = r.total
|
||||
offset = r.size
|
||||
}
|
||||
loading -= 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func loadPage() {
|
||||
if loading != 0 || failure || offset > total {
|
||||
return
|
||||
}
|
||||
loading += 1
|
||||
DefaultAPI.getCountryCities(id: countryId, pageOffset: offset, pageSize: 50) {
|
||||
response, error in
|
||||
if let _ = error {
|
||||
self.failure = true
|
||||
} else if let r = response {
|
||||
cities.append(contentsOf: r.elements)
|
||||
total = r.total
|
||||
offset += r.size
|
||||
}
|
||||
loading -= 1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
if let c = country {
|
||||
List() {
|
||||
PlaceMapView(center: Coordinate(longitude: c.coordinate.longitude, latitude: c.coordinate.latitude), zoom: 4, boundary: boundary)
|
||||
.frame(height: 200)
|
||||
.frame(maxWidth: .infinity)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 6))
|
||||
ForEach(cities, id: \City.id) { city in
|
||||
CityEntryView(city: city)
|
||||
}
|
||||
if !showLoadingAnimation && !failure && total > offset {
|
||||
Button(action: {
|
||||
loadPage()
|
||||
}) {
|
||||
Text("action_load_more")
|
||||
.frame(maxWidth: .infinity)
|
||||
.frame(alignment: .center)
|
||||
.foregroundColor(.accentColor)
|
||||
}
|
||||
}
|
||||
}.listStyle(PlainListStyle())
|
||||
Spacer()
|
||||
ProgressBarView(animating: $showLoadingAnimation)
|
||||
.frame(height: 3)
|
||||
.frame(maxWidth: .infinity)
|
||||
} else if showLoadingAnimation {
|
||||
ProgressSpinnerView()
|
||||
}
|
||||
if failure && !showLoadingAnimation {
|
||||
Spacer()
|
||||
ErrorView() {
|
||||
reload()
|
||||
}
|
||||
}
|
||||
}
|
||||
.if((countryName != nil)) { v in
|
||||
v.navigationTitle(countryName!)
|
||||
}
|
||||
.onAppear() {
|
||||
reload()
|
||||
showLoadingAnimation = loading != 0
|
||||
}
|
||||
.onChange(of: loading) { value in
|
||||
showLoadingAnimation = value != 0
|
||||
}
|
||||
.toolbar() {
|
||||
ToolbarItemGroup(placement: .navigationBarTrailing) {
|
||||
if loading == 0 {
|
||||
if Favorites.canDelete(favorite) {
|
||||
Button(action: {
|
||||
Favorites.delete(viewContext, favorite)
|
||||
reload()
|
||||
}) {
|
||||
Image(systemName: "heart.slash")
|
||||
}
|
||||
} else if !failure {
|
||||
Button(action: {
|
||||
Favorites.add(viewContext, favorite) { fav in
|
||||
fav.setLocationType(type: .country)
|
||||
fav.identifier = countryId
|
||||
fav.locationValue = country
|
||||
if let c = cities.first {
|
||||
fav.cityValue = c
|
||||
}
|
||||
}
|
||||
reload()
|
||||
}) {
|
||||
Image(systemName: "heart")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct CityEntryView: View {
|
||||
|
||||
let city: City
|
||||
|
||||
var body: some View {
|
||||
NavigationLink(destination: { CityView(cityId: city.id!) }) {
|
||||
HStack {
|
||||
Image(systemName: "building.2")
|
||||
.font(.title)
|
||||
.padding(.trailing, 2)
|
||||
VStack(alignment:.leading) {
|
||||
Text(TextBindings.getName(city.names, false)!)
|
||||
.font(.body)
|
||||
Text(TextBindings.getRegionName(city))
|
||||
.font(.caption)
|
||||
}
|
||||
}.padding(2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct CountryView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
CountryView(countryId: 560)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
//
|
||||
// CustomizeView.swift
|
||||
// App
|
||||
//
|
||||
// Created by Marcus Handte on 18.07.22.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct CustomizeView: View {
|
||||
|
||||
@ObservedObject var state: AppState
|
||||
@State var unitSystem: UnitSystem
|
||||
@State var temperatureUnit: TemperatureUnit
|
||||
@State var precipitation: Bool
|
||||
@State var windSpeed: Bool
|
||||
@State var cloudCoverage: Bool
|
||||
@State var humidity: Bool
|
||||
@State var snowDepth: Bool
|
||||
@State var pressure: Bool
|
||||
|
||||
init() {
|
||||
self.state = AppState.shared
|
||||
self.unitSystem = AppState.shared.unitSystem
|
||||
self.temperatureUnit = AppState.shared.temperatureUnit
|
||||
self.precipitation = AppState.shared.precipitation
|
||||
self.windSpeed = AppState.shared.windSpeed
|
||||
self.cloudCoverage = AppState.shared.cloudCoverage
|
||||
self.humidity = AppState.shared.humidity
|
||||
self.snowDepth = AppState.shared.snowDepth
|
||||
self.pressure = AppState.shared.pressure
|
||||
}
|
||||
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
Section(header: Text("customize_section_units")) {
|
||||
Picker("customize_hint_system", selection: $unitSystem) {
|
||||
ForEach([ UnitSystem.si, UnitSystem.imperial, UnitSystem.both], id: \.self) { s in
|
||||
Text(TextBindings.getUnitSystem(s))
|
||||
}
|
||||
}
|
||||
Picker("customize_hint_temperature", selection: $temperatureUnit) {
|
||||
ForEach([ TemperatureUnit.celsius, TemperatureUnit.fahrenheit, TemperatureUnit.both], id: \.self) { t in
|
||||
Text(TextBindings.getTemperatureUnit(t))
|
||||
}
|
||||
}
|
||||
}
|
||||
Section(header: Text("customize_section_data")) {
|
||||
CustomizeToggleView(image: "icon_raindrops", label: "label_precipitation", enabled: $precipitation)
|
||||
CustomizeToggleView(image: "icon_wind_direction", label: "label_wind_speed", enabled: $windSpeed)
|
||||
CustomizeToggleView(image: "icon_cloud", label: "label_cloud_coverage", enabled: $cloudCoverage)
|
||||
CustomizeToggleView(image: "icon_humidity", label: "label_humidity", enabled: $humidity)
|
||||
CustomizeToggleView(image: "icon_snowflake_cold", label: "label_snow_depth", enabled: $snowDepth)
|
||||
CustomizeToggleView(image: "icon_barometer", label: "label_pressure", enabled: $pressure)
|
||||
}
|
||||
}
|
||||
.onChange(of: unitSystem, perform: { state.unitSystem = $0 })
|
||||
.onChange(of: temperatureUnit, perform: { state.temperatureUnit = $0 })
|
||||
.onChange(of: precipitation, perform: { state.precipitation = $0 })
|
||||
.onChange(of: windSpeed, perform: { state.windSpeed = $0 })
|
||||
.onChange(of: cloudCoverage, perform: { state.cloudCoverage = $0 })
|
||||
.onChange(of: humidity, perform: { state.humidity = $0 })
|
||||
.onChange(of: snowDepth, perform: { state.snowDepth = $0 })
|
||||
.onChange(of: pressure, perform: { state.pressure = $0 })
|
||||
.navigationTitle(Text("action_customize"))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct CustomizeToggleView: View {
|
||||
|
||||
let image: String
|
||||
let label: LocalizedStringKey
|
||||
let enabled: Binding<Bool>
|
||||
|
||||
var body: some View {
|
||||
Toggle(isOn: enabled) {
|
||||
HStack {
|
||||
Image(image)
|
||||
Text(label)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct CustomizeView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
NavigationView {
|
||||
CustomizeView()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
//
|
||||
// DeviceView.swift
|
||||
// App
|
||||
//
|
||||
// Created by Marcus Handte on 21.07.22.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import class MoWeStaApi.Device
|
||||
import class MoWeStaApi.DefaultAPI
|
||||
import class MoWeStaApi.Measurement
|
||||
import LocosLabGeometry
|
||||
|
||||
struct DeviceView: View {
|
||||
|
||||
let device: Device
|
||||
|
||||
@ObservedObject var state = AppState.shared
|
||||
@State var time = Int64(Date().timeIntervalSince1970 * 1000)
|
||||
@State var measurements: [DeviceMeasurement]? = nil
|
||||
@State var offset = 0
|
||||
@State var total = 0
|
||||
@State var loading = false
|
||||
@State var failure = false
|
||||
@State var measurement: DeviceMeasurement?
|
||||
@State var showMeasurement = false
|
||||
@State var showCustomize = false
|
||||
@State var customizeTemperature = false
|
||||
|
||||
|
||||
@ViewBuilder
|
||||
func createTrailing() -> some View {
|
||||
Button(action: {
|
||||
loadNext()
|
||||
}) {
|
||||
Text("action_load_more")
|
||||
.font(.body)
|
||||
.rotationEffect(.degrees(-90))
|
||||
.fixedSize()
|
||||
.frame(width: 44, height: 100)
|
||||
.foregroundColor(.accentColor)
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
GeometryReader { proxy in
|
||||
VStack(spacing: 0) {
|
||||
if let ms = measurements {
|
||||
ScrollView(showsIndicators: false) {
|
||||
MeasurementView(measurements: ms, action: { measurement in
|
||||
self.measurement = measurement
|
||||
showMeasurement = true
|
||||
}, trailing: (!loading && offset < total) ? createTrailing : nil )
|
||||
.frame(maxWidth: .infinity, minHeight: 300, idealHeight: max(300, proxy.size.height))
|
||||
}
|
||||
}
|
||||
if loading {
|
||||
if measurements == nil {
|
||||
ProgressSpinnerView()
|
||||
.frame(maxWidth: .infinity)
|
||||
} else {
|
||||
Spacer()
|
||||
ProgressBarView(animating: $loading)
|
||||
.frame(maxHeight: 3)
|
||||
}
|
||||
}
|
||||
if !loading && failure {
|
||||
Spacer()
|
||||
ErrorView() {
|
||||
loadNext()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.navigationTitle(device.model)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.onAppear {
|
||||
if measurements == nil && !loading {
|
||||
loadNext()
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $showMeasurement) {
|
||||
NavigationView() {
|
||||
MeasurementDetailSheet(measurement: $measurement)
|
||||
.navigationBarItems(trailing:
|
||||
Button(action: {
|
||||
showMeasurement.toggle()
|
||||
}) {
|
||||
Text("button_done")
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
.toolbar {
|
||||
ToolbarItemGroup(placement: .navigationBarTrailing) {
|
||||
Button(action: {
|
||||
customizeTemperature = true
|
||||
showCustomize = true
|
||||
}) {
|
||||
Image("icon_thermometer")
|
||||
.accessibilityHint("action_temperature")
|
||||
}
|
||||
|
||||
Button(action: {
|
||||
customizeTemperature = false
|
||||
showCustomize = true
|
||||
}) {
|
||||
Image("icon_barometer")
|
||||
.accessibilityHint("action_system")
|
||||
}
|
||||
}
|
||||
}
|
||||
.actionSheet(isPresented: $showCustomize) {
|
||||
if customizeTemperature {
|
||||
return ActionSheet(title: Text("action_temperature"), message: nil, buttons: [
|
||||
.default(Text("customize_temperature_celsius").foregroundColor(.accentColor)) {
|
||||
state.temperatureUnit = .celsius
|
||||
},
|
||||
.default(Text("customize_temperature_fahrenheit")) {
|
||||
state.temperatureUnit = .fahrenheit
|
||||
},
|
||||
.default(Text("customize_temperature_both")) {
|
||||
state.temperatureUnit = .both
|
||||
}
|
||||
])
|
||||
} else {
|
||||
return ActionSheet(title: Text("action_system"), message: nil, buttons: [
|
||||
.default(Text("customize_system_standard").foregroundColor(.accentColor)) {
|
||||
state.unitSystem = .si
|
||||
},
|
||||
.default(Text("customize_system_imperial")) {
|
||||
state.unitSystem = .imperial
|
||||
},
|
||||
.default(Text("customize_system_both")) {
|
||||
state.unitSystem = .both
|
||||
}
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public func loadNext() {
|
||||
if loading {
|
||||
return
|
||||
}
|
||||
if let credentials = state.credentials {
|
||||
failure = false
|
||||
loading = true
|
||||
let rb = DefaultAPI.getDeviceMeasurementsWithRequestBuilder(duration: time, id: device.id!, start: 0, pageOffset: offset, pageSize: 150)
|
||||
rb.addHeaders(ApiHeader.create(credentials))
|
||||
rb.execute() {
|
||||
result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
if measurements == nil {
|
||||
measurements = wrapMeasurements(response.body.elements);
|
||||
offset = response.body.size
|
||||
} else {
|
||||
measurements!.append(contentsOf: wrapMeasurements(response.body.elements))
|
||||
offset += response.body.size
|
||||
}
|
||||
total = response.body.total
|
||||
case let .failure(.error(code, _, _, _)):
|
||||
if code == 403 {
|
||||
state.credentialFailure = true
|
||||
}
|
||||
failure = true
|
||||
}
|
||||
loading = false
|
||||
}
|
||||
} else {
|
||||
state.credentialFailure = true
|
||||
}
|
||||
}
|
||||
|
||||
func wrapMeasurements(_ reports: [Measurement]) -> [DeviceMeasurement] {
|
||||
var result: [DeviceMeasurement] = []
|
||||
reports.forEach() { r in
|
||||
result.append(DeviceMeasurement(measurement: r))
|
||||
}
|
||||
return result
|
||||
}}
|
||||
|
||||
struct DeviceMeasurement: Measured {
|
||||
|
||||
let measurement: Measurement
|
||||
var id: Int64 { get { return measurement.id! } }
|
||||
var time: Int64 { get { return measurement.time } }
|
||||
var humidity: Double? { get { return measurement.humidity }}
|
||||
var pressure: Double? { get { return measurement.pressure }}
|
||||
var temperature: Double? { get { return measurement.temperature }}
|
||||
|
||||
}
|
||||
|
||||
struct MeasurementDetailSheet: View {
|
||||
|
||||
let measurement: Binding<DeviceMeasurement?>
|
||||
|
||||
var body: some View {
|
||||
ScrollView(showsIndicators: false) {
|
||||
VStack {
|
||||
MeasurementDetailView(measurement: measurement, action: nil)
|
||||
.padding([.leading, .trailing, .top])
|
||||
if let m = measurement.wrappedValue, let c = m.measurement.coordinate {
|
||||
PlaceMapView(center: Coordinate(longitude: c.longitude, latitude: c.latitude) , zoom: 14, boundary: nil)
|
||||
.frame(maxWidth: .infinity)
|
||||
.frame(height: 200)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 6))
|
||||
.padding([.leading, .trailing, .bottom])
|
||||
}
|
||||
}
|
||||
}
|
||||
.navigationBarTitle("label_measurement")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
//
|
||||
// DevicesView.swift
|
||||
// App
|
||||
//
|
||||
// Created by Marcus Handte on 21.07.22.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import class MoWeStaApi.Device
|
||||
import class MoWeStaApi.DefaultAPI
|
||||
|
||||
struct DevicesView: View {
|
||||
|
||||
@State var devices: [Device]? = nil
|
||||
@State var loading = false
|
||||
@State var failure = false
|
||||
@ObservedObject var state = AppState.shared
|
||||
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 0) {
|
||||
if let devs = devices {
|
||||
List(devs, id: \Device.id) { device in
|
||||
NavigationLink(destination: {
|
||||
DeviceView(device: device)
|
||||
}) {
|
||||
DeviceEntryView(device: device)
|
||||
}
|
||||
}.listStyle(PlainListStyle())
|
||||
}
|
||||
if loading {
|
||||
Spacer()
|
||||
ProgressBarView(animating: $loading)
|
||||
.frame(height: 3)
|
||||
}
|
||||
if !loading && failure {
|
||||
Spacer()
|
||||
ErrorView() {
|
||||
load()
|
||||
}
|
||||
}
|
||||
}.onAppear() {
|
||||
if devices == nil {
|
||||
load()
|
||||
}
|
||||
}.navigationTitle("navigation_devices")
|
||||
}
|
||||
|
||||
func load() {
|
||||
if loading {
|
||||
return
|
||||
}
|
||||
if let credential = state.credentials {
|
||||
loading = true
|
||||
failure = false
|
||||
devices = nil
|
||||
next(credential: credential, offset: 0)
|
||||
}
|
||||
}
|
||||
|
||||
func next(credential: UserCredentials, offset: Int) {
|
||||
let rb = DefaultAPI.getCurrentUserDevicesWithRequestBuilder(pageOffset: offset, pageSize: 50)
|
||||
rb.addHeaders(ApiHeader.create(credential))
|
||||
rb.execute() {
|
||||
response in
|
||||
switch response {
|
||||
case let .success(result):
|
||||
if devices == nil {
|
||||
devices = result.body.elements
|
||||
} else {
|
||||
devices!.append(contentsOf: result.body.elements)
|
||||
}
|
||||
let current = result.body.offset + result.body.size
|
||||
if current > result.body.total {
|
||||
loading = false
|
||||
} else {
|
||||
next(credential: credential, offset: current)
|
||||
}
|
||||
case let .failure(.error(code, _, _, _)):
|
||||
if (code == 403) {
|
||||
state.credentialFailure = true
|
||||
}
|
||||
failure = true
|
||||
loading = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct DeviceEntryView: View {
|
||||
|
||||
let device: Device
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
Image(ImageBindings.getDeviceIcon(device.os))
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: 40, height: 36)
|
||||
.padding([.leading, .trailing], 10)
|
||||
.accessibilityHint(TextBindings.getDeviceOs(device.os))
|
||||
VStack(alignment: .leading, spacing: 0) {
|
||||
Text(device.model)
|
||||
.font(.body)
|
||||
.multilineTextAlignment(.leading)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
Text("format_title \(device.manufacturer) \(device.device)")
|
||||
.font(.caption)
|
||||
.multilineTextAlignment(.leading)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
struct DevicesView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
DevicesView()
|
||||
}
|
||||
}
|
||||
@@ -8,19 +8,55 @@ import SwiftUI
|
||||
|
||||
/// The drawer view with tabs at the bottom.
|
||||
struct DrawerView: View {
|
||||
var body: some View {
|
||||
HideableTabView("main") {
|
||||
[
|
||||
HideableTabItem(id: 0, text: "navigation_favorites", image: "heart") {
|
||||
AnyView(FavoritesView())
|
||||
},
|
||||
HideableTabItem(id: 1, text: "navigation_search", image: "magnifyingglass") {
|
||||
AnyView(SearchView())
|
||||
},
|
||||
HideableTabItem(id: 2, text: "navigation_settings", image: "gear") {
|
||||
AnyView(SettingsView())
|
||||
|
||||
|
||||
@ObservedObject var state = AppState.shared
|
||||
@State var searchState = SearchState()
|
||||
@State var stationsState = StationsState()
|
||||
|
||||
|
||||
func buildDevicesTab() -> HideableTabItem {
|
||||
if state.credentials != nil {
|
||||
if state.credentialFailure {
|
||||
return HideableTabItem(id: 2, text: "navigation_devices", image: Image("icon_devices")) {
|
||||
AnyView(LoginView(mode: .changePassword))
|
||||
}
|
||||
]
|
||||
} else {
|
||||
return HideableTabItem(id: 2, text: "navigation_devices", image: Image("icon_devices")) {
|
||||
AnyView(DevicesView())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return HideableTabItem(id: 2, text: "navigation_account", image: Image(systemName: "person.crop.circle")) {
|
||||
AnyView(LoginView(mode: .linkAccount))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
GeometryReader { proxy in
|
||||
VStack(spacing: 0) {
|
||||
HideableTabView("main", proxy.safeAreaInsets) {
|
||||
[
|
||||
HideableTabItem(id: 0, text: "navigation_favorites", image: Image(systemName: "heart")) {
|
||||
AnyView(FavoritesView())
|
||||
},
|
||||
HideableTabItem(id: 1, text: "navigation_stations", image: Image("icon_station")) {
|
||||
AnyView(StationsView(state: stationsState))
|
||||
},
|
||||
buildDevicesTab(),
|
||||
HideableTabItem(id: 4, text: "navigation_settings", image: Image(systemName: "gear")) {
|
||||
AnyView(SettingsView())
|
||||
},
|
||||
HideableTabItem(id: 5, text: "navigation_search", image: Image(systemName: "magnifyingglass")) {
|
||||
AnyView(SearchView(state: searchState))
|
||||
}
|
||||
]
|
||||
}
|
||||
Color("PrimaryColor")
|
||||
.frame(height: proxy.safeAreaInsets.bottom)
|
||||
.frame(maxWidth: .infinity)
|
||||
}.ignoresSafeArea(.all, edges: [.bottom, .trailing, .leading])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,16 +6,290 @@
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import MoWeStaApi
|
||||
|
||||
struct FavoritesView: View {
|
||||
|
||||
@Environment(\.managedObjectContext) private var viewContext
|
||||
|
||||
@ObservedObject var state = AppState.shared
|
||||
|
||||
@FetchRequest(
|
||||
sortDescriptors: [NSSortDescriptor(keyPath: \Favorite.position, ascending: true)], animation: .default)
|
||||
private var favorites: FetchedResults<Favorite>
|
||||
|
||||
@SwiftUI.State var customizeTemperatureScale = false
|
||||
@SwiftUI.State var reloading = false
|
||||
|
||||
func isEmpty() -> Bool {
|
||||
return favorites.count == 0
|
||||
}
|
||||
|
||||
|
||||
var body: some View {
|
||||
let _ = print(
|
||||
String.localizedStringWithFormat(NSLocalizedString("format_temperature_celsius %lf", comment: ""), 1.12))
|
||||
Text("format_temperature_celsius \(1.356)")
|
||||
.navigationTitle("navigation_favorites")
|
||||
ZStack(alignment: .topTrailing) {
|
||||
Group {
|
||||
if (isEmpty()) {
|
||||
VStack {
|
||||
ScrollView {
|
||||
VStack {
|
||||
Text("favorite_explain_empty")
|
||||
.font(.body)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.multilineTextAlignment(.leading)
|
||||
FavoriteHelpView(image: "magnifyingglass", text: "favorite_explain_search")
|
||||
FavoriteHelpView(image: "heart", text: "favorite_explain_add")
|
||||
FavoriteHelpView(image: "arrow.down", text: "favorite_explain_drawer")
|
||||
}.padding()
|
||||
.frame(maxWidth: 800)
|
||||
}
|
||||
}.frame(maxWidth: .infinity)
|
||||
} else {
|
||||
List(favorites, id: \.id) { favorite in
|
||||
switch favorite.getLocationType() {
|
||||
case .country:
|
||||
NavigationLink(destination: {
|
||||
CountryView(countryId: favorite.identifier)
|
||||
}, label: {
|
||||
let c = favorite.locationValue as? Country
|
||||
FavoriteCountryView(country: c, city: favorite.cityValue, condition: favorite.conditionValue, unit: state.temperatureUnit)
|
||||
})
|
||||
case .state:
|
||||
NavigationLink(destination: {
|
||||
StateView(stateId: favorite.identifier)
|
||||
}, label: {
|
||||
let s = favorite.locationValue as? MoWeStaApi.State
|
||||
FavoriteStateView(state: s, city: favorite.cityValue, condition: favorite.conditionValue, unit: state.temperatureUnit)
|
||||
})
|
||||
case .city:
|
||||
NavigationLink(destination: {
|
||||
CityView(cityId: favorite.identifier)
|
||||
}, label: {
|
||||
FavoriteCityView(city: favorite.cityValue, condition: favorite.conditionValue, unit: state.temperatureUnit)
|
||||
})
|
||||
}
|
||||
}.listStyle(PlainListStyle())
|
||||
}
|
||||
}
|
||||
Image("mowesta_sun")
|
||||
.resizable()
|
||||
.frame(width: 80, height: 80)
|
||||
.offset(x: -5, y: -80)
|
||||
}
|
||||
.toolbar {
|
||||
ToolbarItemGroup(placement: .navigationBarTrailing) {
|
||||
Button(action: {
|
||||
if !reloading {
|
||||
reloading = true
|
||||
BaseTask.execute(all: [ SyncTask(), RefreshTask()]) { _ in
|
||||
reloading = false
|
||||
}
|
||||
}
|
||||
}) {
|
||||
Image(systemName: reloading ? "arrow.triangle.2.circlepath.circle.fill" : "arrow.triangle.2.circlepath.circle")
|
||||
.accessibilityHint("favorite_hint_reload")
|
||||
}
|
||||
Button(action: {
|
||||
customizeTemperatureScale.toggle()
|
||||
}) {
|
||||
Image("icon_thermometer")
|
||||
.accessibilityHint("action_temperature")
|
||||
}
|
||||
}
|
||||
}
|
||||
.actionSheet(isPresented: $customizeTemperatureScale) {
|
||||
ActionSheet(title: Text("action_temperature"), message: nil, buttons: [
|
||||
.default(Text("customize_temperature_celsius").foregroundColor(.accentColor)) {
|
||||
state.temperatureUnit = .celsius
|
||||
},
|
||||
.default(Text("customize_temperature_fahrenheit")) {
|
||||
state.temperatureUnit = .fahrenheit
|
||||
},
|
||||
.default(Text("customize_temperature_both")) {
|
||||
state.temperatureUnit = .both
|
||||
}
|
||||
])
|
||||
}
|
||||
.navigationBarHidden(false)
|
||||
.navigationTitle("navigation_favorites")
|
||||
.navigationBarTitleDisplayMode(.large)
|
||||
.onAppear() {
|
||||
RefreshTask().execute() { success in
|
||||
print("Refresh task completed: \(success)")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct FavoriteCityView: View {
|
||||
|
||||
let city: City?
|
||||
let condition: WeatherCondition?
|
||||
let unit: TemperatureUnit
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 4) {
|
||||
if let c = city {
|
||||
HStack {
|
||||
Image(systemName: "building.2")
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: 40, height: 32)
|
||||
.padding(.trailing, 8)
|
||||
VStack(alignment: .leading) {
|
||||
if let name = TextBindings.getName(c.names, false) {
|
||||
Text(name)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.lineLimit(1)
|
||||
}
|
||||
if let region = TextBindings.getName(c.state, c.country) {
|
||||
Text(region)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.lineLimit(1)
|
||||
.font(.caption)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
FavoriteConditionView(condition: condition, unit: unit)
|
||||
}.padding(8)
|
||||
}
|
||||
}
|
||||
|
||||
struct FavoriteStateView: View {
|
||||
|
||||
let state: MoWeStaApi.State?
|
||||
let city: City?
|
||||
let condition: WeatherCondition?
|
||||
let unit: TemperatureUnit
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 4) {
|
||||
if let s = state {
|
||||
HStack {
|
||||
Image(systemName: "map")
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: 40, height: 32)
|
||||
.padding(.trailing, 8)
|
||||
VStack(alignment: .leading) {
|
||||
if let name = TextBindings.getName(s.names, false) {
|
||||
Text(name)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.lineLimit(1)
|
||||
}
|
||||
if let region = TextBindings.getName(s.country.names, false) {
|
||||
Text(region)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.lineLimit(1)
|
||||
.font(.caption)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
FavoriteConditionView(condition: condition, unit: unit)
|
||||
if let c = city, let name = TextBindings.getName(c.names, false) {
|
||||
Text("favorite_weather_in \(name)")
|
||||
.frame(maxWidth: .infinity)
|
||||
.foregroundColor(.white)
|
||||
.background(Color("PrimaryColor"))
|
||||
.clipShape(RoundedRectangle(cornerRadius: 6))
|
||||
}
|
||||
}.padding(8)
|
||||
}
|
||||
}
|
||||
|
||||
struct FavoriteCountryView: View {
|
||||
|
||||
let country: Country?
|
||||
let city: City?
|
||||
let condition: WeatherCondition?
|
||||
let unit: TemperatureUnit
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 4) {
|
||||
if let c = country {
|
||||
HStack {
|
||||
Image(systemName: "globe")
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: 40, height: 32)
|
||||
.padding(.trailing, 8)
|
||||
VStack(alignment: .leading) {
|
||||
if let name = TextBindings.getName(c.names, false) {
|
||||
Text(name)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.lineLimit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
FavoriteConditionView(condition: condition, unit: unit)
|
||||
if let c = city, let name = TextBindings.getName(c.names, false) {
|
||||
Text("favorite_weather_in \(name)")
|
||||
.frame(maxWidth: .infinity)
|
||||
.foregroundColor(.white)
|
||||
.background(Color("PrimaryColor"))
|
||||
.clipShape(RoundedRectangle(cornerRadius: 6))
|
||||
}
|
||||
}.padding(8)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct FavoriteConditionView: View {
|
||||
let condition: WeatherCondition?
|
||||
let unit: TemperatureUnit
|
||||
|
||||
var body: some View {
|
||||
if let c = condition {
|
||||
HStack {
|
||||
Image(ImageBindings.getWeatherIcon(c))
|
||||
.renderingMode(.template)
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: 40, height: 40)
|
||||
.padding(.trailing, 8)
|
||||
VStack(alignment: .leading) {
|
||||
Text(TextBindings.getWeatherType(c))
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.lineLimit(1)
|
||||
Text(DataBindings.getTemperature(c.temperature, unit))
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.lineLimit(1)
|
||||
.font(.body.bold())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
EmptyView()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct FavoriteHelpView: View {
|
||||
|
||||
let image: String
|
||||
let text: LocalizedStringKey
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 20) {
|
||||
VStack {
|
||||
Image(systemName: image)
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: 24, height: 24)
|
||||
.padding(.top, 8)
|
||||
}
|
||||
Text(text)
|
||||
.font(.body)
|
||||
.multilineTextAlignment(.leading)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct FavoritesView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
FavoritesView()
|
||||
|
||||
@@ -6,15 +6,326 @@
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Foundation
|
||||
import class MoWeStaApi.OpenAPIClientAPI
|
||||
import class MoWeStaApi.DefaultAPI
|
||||
import class MoWeStaApi.DeviceInfo
|
||||
import class MoWeStaApi.Device
|
||||
import enum MoWeStaApi.ErrorResponse
|
||||
|
||||
|
||||
/// different login modes
|
||||
enum LoginMode {
|
||||
/// creates a new device
|
||||
case createDevice
|
||||
/// links an existing account
|
||||
case linkAccount
|
||||
/// changes a password after login failure
|
||||
case changePassword
|
||||
}
|
||||
|
||||
struct LoginView: View {
|
||||
var body: some View {
|
||||
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
|
||||
|
||||
@ObservedObject var appState = AppState.shared
|
||||
let mode: LoginMode
|
||||
@State var username: String
|
||||
@State var password: String
|
||||
@State var hidden = true
|
||||
@State var checking = false
|
||||
@State var lastError = ""
|
||||
|
||||
let explanation: LocalizedStringKey
|
||||
let disableUsername: Bool
|
||||
let title: LocalizedStringKey
|
||||
let showRegistration: Bool
|
||||
let textLogin: LocalizedStringKey
|
||||
let textContinue: LocalizedStringKey?
|
||||
|
||||
init(mode: LoginMode) {
|
||||
self.mode = mode
|
||||
switch mode {
|
||||
case .createDevice:
|
||||
explanation = "login_explain_create"
|
||||
disableUsername = false
|
||||
title = "login_title"
|
||||
showRegistration = true
|
||||
textLogin = "login_button_create"
|
||||
textContinue = "login_button_continue"
|
||||
username = ""
|
||||
password = ""
|
||||
case .linkAccount:
|
||||
explanation = "login_explain_update"
|
||||
disableUsername = false
|
||||
title = "navigation_account"
|
||||
showRegistration = true
|
||||
textLogin = "login_button_update"
|
||||
textContinue = nil
|
||||
username = ""
|
||||
password = ""
|
||||
case .changePassword:
|
||||
explanation = "login_explain_password"
|
||||
disableUsername = true
|
||||
title = "navigation_devices"
|
||||
showRegistration = false
|
||||
textLogin = "login_button_password"
|
||||
textContinue = "login_button_retry"
|
||||
if let c = AppState.shared.credentials {
|
||||
username = c.login
|
||||
password = c.password
|
||||
} else {
|
||||
username = ""
|
||||
password = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
let invalid = isInvalid()
|
||||
Group {
|
||||
if checking {
|
||||
ProgressSpinnerView()
|
||||
} else {
|
||||
VStack(spacing: 0) {
|
||||
ScrollView {
|
||||
VStack(spacing: 16) {
|
||||
Text(explanation)
|
||||
.font(.body)
|
||||
HStack {
|
||||
Image(systemName: "person")
|
||||
TextField("login_hint_user", text: $username)
|
||||
.frame(maxWidth: .infinity, minHeight: 24)
|
||||
.autocapitalization(.none)
|
||||
.disableAutocorrection(true)
|
||||
.disabled(disableUsername)
|
||||
}
|
||||
.padding(8)
|
||||
.frame(maxWidth: 400)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 6)
|
||||
.stroke(.gray, lineWidth: 2)
|
||||
)
|
||||
HStack {
|
||||
Image(systemName: "lock")
|
||||
if (hidden) {
|
||||
SecureField("login_hint_password", text: $password)
|
||||
.frame(maxWidth: .infinity, minHeight: 24)
|
||||
.autocapitalization(.none)
|
||||
} else {
|
||||
TextField("login_hint_password", text: $password)
|
||||
.frame(maxWidth: .infinity, minHeight: 24)
|
||||
.autocapitalization(.none)
|
||||
.disableAutocorrection(true)
|
||||
}
|
||||
Button(action: { hidden.toggle() }, label: {
|
||||
Image(systemName: hidden ? "eye" : "eye.slash")
|
||||
})
|
||||
.buttonStyle(NullButtonStyle())
|
||||
}
|
||||
.padding(8)
|
||||
.frame(maxWidth: 400)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 6)
|
||||
.stroke(.gray, lineWidth: 2)
|
||||
)
|
||||
Button(textLogin) {
|
||||
onButton(true)
|
||||
}
|
||||
.buttonStyle(MaterialButtonStyle(disabled: invalid.0))
|
||||
.disabled(invalid.0)
|
||||
.frame(maxWidth: 400)
|
||||
if let t = textContinue {
|
||||
Button(t) {
|
||||
onButton(false)
|
||||
}
|
||||
.buttonStyle(OutlineButtonStyle(color: Color("PrimaryColor")))
|
||||
.frame(maxWidth: 400)
|
||||
}
|
||||
if showRegistration {
|
||||
Link(destination: URL(string: NSLocalizedString("login_url_register", comment: ""))!) {
|
||||
Text("login_text_register")
|
||||
.font(.body)
|
||||
.foregroundColor(Color("PrimaryColor"))
|
||||
}
|
||||
}
|
||||
}.padding()
|
||||
}
|
||||
if (invalid.1.count > 0) {
|
||||
Text(LocalizedStringKey(invalid.1))
|
||||
.font(.body.bold())
|
||||
.foregroundColor(.accentColor)
|
||||
.frame(minHeight: 24)
|
||||
}
|
||||
Spacer()
|
||||
if lastError.count > 0 {
|
||||
Text(LocalizedStringKey(lastError))
|
||||
.foregroundColor(.white)
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
.multilineTextAlignment(.center)
|
||||
.padding(10)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 6)
|
||||
.foregroundColor(Color("PrimaryColor")))
|
||||
.padding(10)
|
||||
.onAppear() {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
|
||||
withAnimation() {
|
||||
lastError = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}.frame(maxWidth: 800)
|
||||
}
|
||||
}
|
||||
.navigationTitle(title)
|
||||
.navigationBarTitleDisplayMode(.large)
|
||||
.navigationBarHidden(false)
|
||||
}
|
||||
|
||||
func isInvalid() -> (Bool, String) {
|
||||
if (username.count == 0 && password.count == 0) {
|
||||
return (true, "")
|
||||
} else if (username.count < 5) {
|
||||
return (true, "login_error_login_too_short")
|
||||
} else if (username.count > 32) {
|
||||
return (true, "login_error_login_too_long")
|
||||
} else {
|
||||
let range = NSRange(location: 0, length: username.utf16.count)
|
||||
let regex = try! NSRegularExpression(pattern: "[a-zA-Z0-9]{\(username.count)}")
|
||||
if regex.firstMatch(in: username, range: range) != nil {
|
||||
if (password.count == 0) {
|
||||
return (true, "login_error_password_missing")
|
||||
} else {
|
||||
return (false, "")
|
||||
}
|
||||
} else {
|
||||
return (true, "login_error_login_invalid_chars")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func onButton(_ login: Bool) -> Void {
|
||||
switch mode {
|
||||
case .createDevice:
|
||||
createDevice(login)
|
||||
case .linkAccount:
|
||||
linkDevice()
|
||||
case .changePassword:
|
||||
changePassword(login)
|
||||
}
|
||||
}
|
||||
|
||||
func linkDevice() -> Void {
|
||||
checking = true
|
||||
lastError = ""
|
||||
let credential = UserCredentials(username, password)
|
||||
let userRequest = DefaultAPI.getCurrentUserWithRequestBuilder()
|
||||
userRequest.addHeaders(ApiHeader.create(credential))
|
||||
userRequest.execute() { userResult in
|
||||
switch userResult {
|
||||
case let .success(userResponse):
|
||||
let linkRequest = DefaultAPI.setCurrentUserWithRequestBuilder(body: userResponse.body)
|
||||
linkRequest.addHeaders(ApiHeader.create(credential, appState.token))
|
||||
linkRequest.execute() { linkResult in
|
||||
switch linkResult {
|
||||
case let .success(linkResponse):
|
||||
if let dev = appState.device {
|
||||
dev.user = linkResponse.body.id
|
||||
appState.device = dev
|
||||
}
|
||||
appState.credentials = credential
|
||||
BaseTask.execute(all: [ SyncTask(), RefreshTask()], completion: { _ in })
|
||||
case let .failure(.error(code, _, _, _)):
|
||||
if (code == 403) {
|
||||
lastError = "login_failure_credentials"
|
||||
} else if code == 409 {
|
||||
lastError = "login_failure_conflict"
|
||||
} else {
|
||||
lastError = "login_failure_network"
|
||||
}
|
||||
}
|
||||
checking = false
|
||||
}
|
||||
case let .failure(.error(code, _, _, _)):
|
||||
if (code == 403) {
|
||||
lastError = "login_failure_credentials"
|
||||
} else {
|
||||
lastError = "login_failure_network"
|
||||
}
|
||||
checking = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func changePassword(_ login: Bool) {
|
||||
var credential = appState.credentials
|
||||
if login {
|
||||
credential = UserCredentials(username, password)
|
||||
}
|
||||
if let c = credential {
|
||||
checking = true
|
||||
lastError = ""
|
||||
let request = DefaultAPI.getCurrentUserWithRequestBuilder()
|
||||
request.addHeaders(ApiHeader.create(c))
|
||||
request.execute() { response in
|
||||
switch response {
|
||||
case .success:
|
||||
appState.credentials = c
|
||||
appState.credentialFailure = false
|
||||
BaseTask.execute(all: [ SyncTask(), RefreshTask()], completion: { _ in })
|
||||
case let .failure(.error(code, _, _, _)):
|
||||
if (code == 403) {
|
||||
lastError = "login_failure_credentials"
|
||||
} else {
|
||||
lastError = "login_failure_network"
|
||||
}
|
||||
}
|
||||
checking = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func createDevice(_ login: Bool) -> Void {
|
||||
let model = UIDevice.current.localizedModel
|
||||
let os = UIDevice.current.systemName
|
||||
let info = DeviceInfo(device: os, manufacturer: "Apple", model: model, os: .ios)
|
||||
let request = DefaultAPI.createDeviceWithRequestBuilder(body: info)
|
||||
let credential = UserCredentials(username, password)
|
||||
if login {
|
||||
request.addHeaders(ApiHeader.create(credential))
|
||||
}
|
||||
checking = true
|
||||
lastError = ""
|
||||
request.execute() { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
let d = response.body
|
||||
appState.token = d.token
|
||||
appState.device = Device(creationTime: d.creationTime, deleted: d.deleted, device: d.device, id: d.id, manufacturer: d.manufacturer, model: d.model, modificationTime: d.modificationTime, os: .ios, user: d.user)
|
||||
if (login) {
|
||||
appState.credentials = credential
|
||||
BaseTask.execute(all: [ SyncTask(), RefreshTask()], completion: { _ in })
|
||||
}
|
||||
case let .failure(.error(a, _, _, _)):
|
||||
if (login && a == 403) {
|
||||
lastError = "login_failure_credentials"
|
||||
} else {
|
||||
lastError = "login_failure_network"
|
||||
}
|
||||
}
|
||||
checking = false
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct LoginView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
LoginView()
|
||||
NavigationView {
|
||||
LoginView(mode: .createDevice)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,259 @@
|
||||
//
|
||||
// MeasurementView.swift
|
||||
// App
|
||||
//
|
||||
// Created by Marcus Handte on 21.07.22.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
protocol Measured: Identifiable {
|
||||
var time: Int64 { get }
|
||||
var humidity: Double? { get }
|
||||
var pressure: Double? { get }
|
||||
var temperature: Double? { get }
|
||||
}
|
||||
|
||||
struct MeasurementRange {
|
||||
let minHumidity: Double?
|
||||
let maxHumidity: Double?
|
||||
let minPressure: Double?
|
||||
let maxPressure: Double?
|
||||
let minTemperature: Double?
|
||||
let maxTemperature: Double?
|
||||
}
|
||||
|
||||
struct MeasurementView<M: Measured
|
||||
, V: View>: View {
|
||||
|
||||
let measurements: [M]
|
||||
let action: ((M) -> Void)?
|
||||
let trailing: (() -> V)?
|
||||
|
||||
func getRange() -> MeasurementRange {
|
||||
var minHumidty: Double = 0
|
||||
var maxHumidity: Double = 0
|
||||
var humidity = 0
|
||||
var minPressure: Double = 0
|
||||
var maxPressure: Double = 0
|
||||
var pressure = 0
|
||||
var minTemperature: Double = 0
|
||||
var maxTemperature: Double = 0
|
||||
var temperature = 0
|
||||
for m in measurements {
|
||||
if let h = m.humidity {
|
||||
if humidity == 0 {
|
||||
minHumidty = h
|
||||
maxHumidity = h
|
||||
humidity = 1
|
||||
} else {
|
||||
humidity += 1
|
||||
minHumidty = min(minHumidty, h)
|
||||
maxHumidity = max(maxHumidity, h)
|
||||
}
|
||||
}
|
||||
if let p = m.pressure {
|
||||
if pressure == 0 {
|
||||
minPressure = p
|
||||
maxPressure = p
|
||||
pressure = 1
|
||||
} else {
|
||||
pressure += 1
|
||||
minPressure = min(minPressure, p)
|
||||
maxPressure = max(maxPressure, p)
|
||||
}
|
||||
}
|
||||
if let t = m.temperature {
|
||||
if temperature == 0 {
|
||||
minTemperature = t
|
||||
maxTemperature = t
|
||||
temperature = 1
|
||||
} else {
|
||||
temperature += 1
|
||||
minTemperature = min(minTemperature, t)
|
||||
maxTemperature = max(maxTemperature, t)
|
||||
}
|
||||
}
|
||||
}
|
||||
return MeasurementRange(
|
||||
minHumidity: humidity > 0 ? minHumidty : nil,
|
||||
maxHumidity: humidity > 0 ? maxHumidity : nil,
|
||||
minPressure: pressure > 0 ? minPressure : nil,
|
||||
maxPressure: pressure > 0 ? maxPressure : nil,
|
||||
minTemperature: temperature > 0 ? minTemperature : nil,
|
||||
maxTemperature: temperature > 0 ? maxTemperature : nil)
|
||||
}
|
||||
|
||||
|
||||
var body: some View {
|
||||
let range = getRange()
|
||||
GeometryReader { proxy in
|
||||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
HStack(alignment: .top, spacing: 4) {
|
||||
ForEach(measurements) { m in
|
||||
let mv = MeasurementEntryView(measurement: m, range: range, proxy: proxy)
|
||||
if let a = action {
|
||||
Button(action: {
|
||||
a(m)
|
||||
}) {
|
||||
mv
|
||||
}.buttonStyle(NullButtonStyle())
|
||||
} else {
|
||||
mv
|
||||
}
|
||||
}
|
||||
if let t = trailing {
|
||||
t()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct MeasurementEntryView<M: Measured>: View {
|
||||
let measurement: M
|
||||
let range: MeasurementRange
|
||||
let proxy: GeometryProxy
|
||||
@ObservedObject var state = AppState.shared
|
||||
|
||||
func getOffset(_ value: Double, _ min: Double?, _ max: Double?) -> CGFloat {
|
||||
let height = proxy.size.height - 140 - 16
|
||||
if let mini = min, let maxi = max {
|
||||
let dy = maxi - mini
|
||||
if dy > 0 {
|
||||
let dt = value - mini
|
||||
let pc = dt / dy
|
||||
return CGFloat((1 - pc) * height + 4)
|
||||
}
|
||||
}
|
||||
return CGFloat( height / 2 + 4)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 0) {
|
||||
HStack(alignment: .top, spacing: 0) {
|
||||
Text(DataBindings.getDate(measurement.time, nil))
|
||||
.font(.caption)
|
||||
.rotationEffect(.degrees(-90))
|
||||
.fixedSize()
|
||||
.frame(width: 22, height: 100)
|
||||
Text(DataBindings.getTime(measurement.time, nil))
|
||||
.font(.caption)
|
||||
.rotationEffect(.degrees(-90))
|
||||
.fixedSize()
|
||||
.frame(width: 22, height: 100)
|
||||
}.background(
|
||||
RoundedRectangle(cornerRadius: 6)
|
||||
.foregroundColor(Color.gray)
|
||||
.opacity(0.2))
|
||||
ZStack(alignment: .top) {
|
||||
Spacer()
|
||||
.frame(maxHeight: .infinity)
|
||||
|
||||
if let p = measurement.pressure {
|
||||
Text("format_measure_pressure \(state.unitSystem == .imperial ? UnitConverter.hpaToPsi(p) : p)")
|
||||
.frame(width: 40, height: 40, alignment: .center)
|
||||
.multilineTextAlignment(.center)
|
||||
.font(.caption)
|
||||
.foregroundColor(.white)
|
||||
.background(Circle()
|
||||
.foregroundColor(.blue))
|
||||
.offset(x: 0, y: getOffset(p, range.minPressure, range.maxPressure))
|
||||
}
|
||||
|
||||
if let h = measurement.humidity {
|
||||
Text("format_measure_humidity \(h)")
|
||||
.frame(width: 40, height: 40, alignment: .center)
|
||||
.multilineTextAlignment(.center)
|
||||
.font(.caption)
|
||||
.foregroundColor(.white)
|
||||
.background(Circle()
|
||||
.foregroundColor(Color("PrimaryColor")))
|
||||
.offset(x: 0, y: getOffset(h, range.minHumidity, range.maxHumidity))
|
||||
}
|
||||
|
||||
if let t = measurement.temperature {
|
||||
Text("format_measure_temperature \(state.temperatureUnit == .fahrenheit ? UnitConverter.celsiusToFahrenheit(t) : t)")
|
||||
.frame(width: 40, height: 40, alignment: .center)
|
||||
.multilineTextAlignment(.center)
|
||||
.font(.caption)
|
||||
.foregroundColor(.black)
|
||||
.background(Circle()
|
||||
.foregroundColor(.accentColor))
|
||||
.offset(x: 0, y: getOffset(t, range.minTemperature, range.maxTemperature))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
.frame(width: 44, height: max(200, proxy.size.height))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
struct MeasurementDetailView<M: Measured>: View {
|
||||
let measurement: Binding<M?>
|
||||
let action: (() -> Void)?
|
||||
@ObservedObject var state = AppState.shared
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .trailing, spacing: 4) {
|
||||
if let a = action {
|
||||
Button(action: a) {
|
||||
Image(systemName: "xmark.circle")
|
||||
.font(.headline)
|
||||
.accessibilityHint(Text("button_close"))
|
||||
}
|
||||
.padding(.bottom, 8)
|
||||
}
|
||||
if let m = measurement.wrappedValue {
|
||||
HStack {
|
||||
Image(systemName: "clock")
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.help("label_time")
|
||||
.accessibilityHint("label_time")
|
||||
.frame(width: 40, height: 16)
|
||||
Text("format_title \(DataBindings.getTime(m.time, nil)) \(DataBindings.getDate(m.time, nil))")
|
||||
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||
.lineLimit(1)
|
||||
}
|
||||
if let t = m.temperature {
|
||||
WeatherDataView("icon_thermometer", "label_temperature", DataBindings.getTemperature(t, state.temperatureUnit))
|
||||
}
|
||||
if let h = m.humidity {
|
||||
WeatherDataView("icon_humidity", "label_humidity", DataBindings.getHumidity(h))
|
||||
}
|
||||
if let p = m.pressure {
|
||||
WeatherDataView("icon_barometer", "label_pressure", DataBindings.getPressure(p, state.unitSystem))
|
||||
}
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct Sample: Measured{
|
||||
|
||||
var id = UUID()
|
||||
var time: Int64 = Int64(Date().timeIntervalSince1970 * 1000)
|
||||
var temperature: Double? = Double.random(in: 1..<5)
|
||||
var humidity: Double? = Double.random(in: 70..<86)
|
||||
var pressure: Double? = Double.random(in: 900..<1100)
|
||||
|
||||
}
|
||||
|
||||
|
||||
struct MeasurementView_Previews: PreviewProvider {
|
||||
|
||||
static var previews: some View {
|
||||
MeasurementView(measurements: [ Sample(), Sample(), Sample(), Sample(), Sample()], action: { m in
|
||||
print("Measurement \(m) clicked")
|
||||
}) {
|
||||
AnyView(EmptyView())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
//
|
||||
// MapView.swift
|
||||
// App
|
||||
//
|
||||
// Created by Marcus Handte on 20.07.22.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Foundation
|
||||
import LocosLabGeometry
|
||||
import LocosLabLeafless
|
||||
|
||||
/// The actual view that renders the map of a place with the optional boundaries
|
||||
struct PlaceMapView: UIViewRepresentable {
|
||||
|
||||
/// Dark mode or not
|
||||
@Environment(\.colorScheme) var colorScheme
|
||||
/// The initial center.
|
||||
let center: Coordinate
|
||||
// The initial zoom.
|
||||
let zoom: Int
|
||||
/// The boundary to render.
|
||||
let boundary: [[Coordinate]]?
|
||||
|
||||
/// Called to create the underlying UIKit view.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - context: The context with the coordinator.
|
||||
/// - returns: The map view.
|
||||
func makeUIView(context: Context) -> MapView {
|
||||
let v = MapView(frame:CGRect())
|
||||
let o = v.options
|
||||
o.pinchToRotate = false
|
||||
o.pinchToZoom = false
|
||||
o.doubleTapZoom = false
|
||||
o.dragToMove = false
|
||||
v.options = o
|
||||
v.setCenter(center: Coordinate(longitude: center.longitude, latitude: center.latitude))
|
||||
v.setZoom(zoom: zoom)
|
||||
return v
|
||||
}
|
||||
|
||||
/// Creates a coordinator that holds the view state.
|
||||
///
|
||||
/// - returns: The coordinator.
|
||||
func makeCoordinator() -> PlaceMapCoordinator {
|
||||
return PlaceMapCoordinator(self)
|
||||
}
|
||||
|
||||
/// Updates the view when the state changed.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - uiView: The UiKit element with the map view.
|
||||
/// - context: The context with the coordinator.
|
||||
func updateUIView(_ uiView: MapView, context: Context) {
|
||||
context.coordinator.update(uiView, self)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// The coordinator that manages updates to the state of the underlying Leafless view.
|
||||
class PlaceMapCoordinator {
|
||||
|
||||
/// The current center
|
||||
var center: Coordinate
|
||||
// The current zoom
|
||||
var zoom: Int
|
||||
// The boundary that is rendered
|
||||
var boundary: [[Coordinate]]?
|
||||
// The polyline representing the boundary
|
||||
var polylines: [Polyline] = []
|
||||
/// The current layer.
|
||||
var tilelayer: TileLayer?
|
||||
/// The color scheme of the layer.
|
||||
var colorScheme: ColorScheme
|
||||
/// The circle to mark the spot
|
||||
var circle: LocosLabLeafless.Circle
|
||||
|
||||
/// Creates a new coordinator and initializes the variables
|
||||
///
|
||||
/// - parameters:
|
||||
/// - mapView: The view to initialize the toggles.
|
||||
init(_ mapView: PlaceMapView) {
|
||||
self.center = mapView.center
|
||||
self.zoom = mapView.zoom
|
||||
self.colorScheme = mapView.colorScheme
|
||||
let opts = CircleOptions()
|
||||
opts.strokeColor = nil
|
||||
opts.fillColor = UIColor(Color.accentColor)
|
||||
opts.opacity = 0.5
|
||||
circle = LocosLabLeafless.Circle(options: opts)
|
||||
circle.radius = 10
|
||||
circle.strokeWidth = 3
|
||||
circle.unit = CircleUnit.pixel
|
||||
circle.coordinate = mapView.center
|
||||
}
|
||||
|
||||
/// Called to update the Leafless MapView on a change to the state of the view.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - mapView: The map view to apply changes.
|
||||
/// - placeMapView: The map view that has changed.
|
||||
func update(_ mapView: MapView, _ placeMapView: PlaceMapView) {
|
||||
if tilelayer == nil || colorScheme != placeMapView.colorScheme {
|
||||
if let t = tilelayer {
|
||||
_ = mapView.removeLayer(layer: t)
|
||||
_ = mapView.removeShape(shape: circle)
|
||||
}
|
||||
colorScheme = placeMapView.colorScheme
|
||||
let url = colorScheme == .dark ? "https://www.mowesta.com/carta/tile/dark/{z}/{x}/{y}.png" : "https://www.mowesta.com/carta/tile/{z}/{x}/{y}.png"
|
||||
let layerOptions = TileLayerOptions(url: url)
|
||||
let tl = TileLayer(options: layerOptions)
|
||||
mapView.addLayer(layer: tl);
|
||||
tilelayer = tl
|
||||
mapView.addShape(shape: circle)
|
||||
}
|
||||
|
||||
|
||||
if !equals(placeMapView.boundary, boundary) {
|
||||
if !polylines.isEmpty {
|
||||
polylines.forEach({ p in
|
||||
_ = mapView.removeShape(shape: p)
|
||||
})
|
||||
polylines = []
|
||||
}
|
||||
if let cs = placeMapView.boundary {
|
||||
var cords: [Coordinate] = []
|
||||
cs.forEach({ b in
|
||||
let options = PolylineOptions()
|
||||
options.fillColor = UIColor(Color.accentColor)
|
||||
options.fillOpacity = 0.7
|
||||
options.strokeCap = .round
|
||||
options.strokeJoin = .round
|
||||
options.strokeWidth = 3
|
||||
options.strokeOpacity = 0.9
|
||||
if placeMapView.colorScheme == .dark {
|
||||
options.strokeColor = UIColor(Color.accentColor)
|
||||
} else {
|
||||
options.strokeColor = UIColor(Color("PrimaryColor"))
|
||||
}
|
||||
let p = Polyline(coordinates: b, options: options)
|
||||
mapView.addShape(shape: p)
|
||||
polylines.append(p)
|
||||
cords.append(contentsOf: b)
|
||||
})
|
||||
if !cords.isEmpty {
|
||||
mapView.setViewport(bounds: Box(coordinates: cords), padding: MapPoint(x: 5, y: 5))
|
||||
}
|
||||
}
|
||||
}
|
||||
if polylines.isEmpty && (center.latitude != placeMapView.center.latitude
|
||||
|| center.longitude != placeMapView.center.longitude
|
||||
|| zoom != placeMapView.zoom) {
|
||||
mapView.setCenter(center: placeMapView.center)
|
||||
mapView.setZoom(zoom: placeMapView.zoom)
|
||||
circle.coordinate = center
|
||||
}
|
||||
self.center = placeMapView.center
|
||||
self.zoom = placeMapView.zoom
|
||||
self.boundary = placeMapView.boundary
|
||||
}
|
||||
|
||||
func equals(_ a: [[Coordinate]]?, _ b: [[Coordinate]]?) -> Bool {
|
||||
if (a == nil && b != nil) || (a != nil && b == nil) {
|
||||
return false
|
||||
}
|
||||
if let x = a, let y = b {
|
||||
if x.count != y.count {
|
||||
return false
|
||||
}
|
||||
for i in 0..<x.count {
|
||||
if x[i].count != y[i].count {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return a == nil && b == nil
|
||||
}
|
||||
|
||||
|
||||
/// Creates an color from an RGB value (0-255).
|
||||
///
|
||||
/// - parameters:
|
||||
/// - r: The red component.
|
||||
/// - g: The green component.
|
||||
/// - b: The blue component.
|
||||
func createColor(_ r: Int, _ g: Int, _ b: Int) -> UIColor {
|
||||
return UIColor(red: CGFloat(Float(Double(r) / 255.0)), green: CGFloat(Float(Double(g) / 255.0)), blue: CGFloat(Float(Double(b) / 255.0)), alpha: 1)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||