diff --git a/android-app/build.gradle b/android-app/build.gradle index eeb5c819..76bfbced 100644 --- a/android-app/build.gradle +++ b/android-app/build.gradle @@ -25,7 +25,6 @@ ext { dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) - implementation project(":android-feign") implementation project(":android-sdk") implementation "javax.xml.bind:jaxb-api:${versionJaxb}" diff --git a/android-app/proguard-rules.pro b/android-app/proguard-rules.pro new file mode 100644 index 00000000..481bb434 --- /dev/null +++ b/android-app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/android-app/src/main/java/com/mowesta/android/app/MowestaActivity.java b/android-app/src/main/java/com/mowesta/android/app/MowestaActivity.java index ed9857f0..a2d9f49e 100644 --- a/android-app/src/main/java/com/mowesta/android/app/MowestaActivity.java +++ b/android-app/src/main/java/com/mowesta/android/app/MowestaActivity.java @@ -15,6 +15,11 @@ import androidx.core.app.ActivityCompat; import androidx.core.content.PermissionChecker; import androidx.preference.PreferenceManager; +import com.mowesta.android.app.database.FavoriteDatabase; +import com.mowesta.android.app.repository.UserCredentials; +import com.mowesta.android.app.task.DatabaseTask; +import com.mowesta.android.app.task.RefreshTask; +import com.mowesta.android.app.task.SyncTask; import com.mowesta.android.app.util.PermissionUtil; import java.io.File; @@ -34,6 +39,11 @@ public class MowestaActivity extends AppCompatActivity { */ public static String TAG = "MowestaActivity"; + /** + * One hour in milliseconds. + */ + private static final int ONE_HOUR = 60*60*1000; + /** * The code used to request the permissions. */ @@ -44,6 +54,32 @@ public class MowestaActivity extends AppCompatActivity { */ private MowestaSettings settings; + /** + * The application. + */ + private IApp app; + + /** + * The task that determines whether we should automatically refresh or update + * the database. + */ + protected DatabaseTask favoriteTask = new DatabaseTask<>( + (input, database) -> database.getAccessor().getUpdateTime(), + (input, result) -> { + if (result != null && result < System.currentTimeMillis() - ONE_HOUR) { + Log.d(TAG, "Starting automatic favorite synchronization."); + UserCredentials c = app.getUserRepository().getCredentials().getValue(); + FavoriteDatabase db = app.getFavoriteRepository().getDatabase(); + if (c != null) new SyncTask(db, null).execute(app.getClientFactory().createClient(c)); + new RefreshTask(db, null).execute(app.getClientFactory().createClient()); + } else { + Log.d(TAG, "Ignoring request for favorite synchronization since data is up-to-date."); + } + } + ); + + + /** * The listener that observes the activation of the mowesta sdk service * and checks for the permissions. @@ -63,6 +99,8 @@ public class MowestaActivity extends AppCompatActivity { @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); + app = (IApp) getApplication(); + favoriteTask.execute(null, app.getFavoriteRepository().getDatabase()); settings = new MowestaSettings(getApplication()); setContentView(R.layout.activity_app); installHttpCache(); diff --git a/android-app/src/main/java/com/mowesta/android/app/MowestaApp.java b/android-app/src/main/java/com/mowesta/android/app/MowestaApp.java index a2a67d02..ede99978 100644 --- a/android-app/src/main/java/com/mowesta/android/app/MowestaApp.java +++ b/android-app/src/main/java/com/mowesta/android/app/MowestaApp.java @@ -5,11 +5,13 @@ import android.content.Context; import android.content.SharedPreferences; import androidx.preference.PreferenceManager; +import com.mowesta.android.app.database.FavoriteDatabase; import com.mowesta.android.app.repository.ClientFactory; import com.mowesta.android.app.repository.DeviceRepository; import com.mowesta.android.app.repository.FavoriteRepository; import com.mowesta.android.app.repository.UserCredentials; import com.mowesta.android.app.repository.UserRepository; +import com.mowesta.android.app.task.DatabaseTask; /** * Te main application of the application that is used @@ -19,6 +21,7 @@ import com.mowesta.android.app.repository.UserRepository; */ public class MowestaApp extends Application implements IApp { + /** * The user repository. */ @@ -38,8 +41,8 @@ public class MowestaApp extends Application implements IApp { @Override public void onCreate() { super.onCreate(); - userRepository = new UserRepository.Builder().build(this); - deviceRepository = new DeviceRepository.Builder().build(this); + userRepository = new UserRepository.Builder().setTrace(false).build(this); + deviceRepository = new DeviceRepository.Builder().setTrace(false).build(this); favoriteRepository = new FavoriteRepository(this); MowestaService.startService(this); } diff --git a/android-app/src/main/java/com/mowesta/android/app/MowestaSettings.java b/android-app/src/main/java/com/mowesta/android/app/MowestaSettings.java index 92369429..61b7035b 100644 --- a/android-app/src/main/java/com/mowesta/android/app/MowestaSettings.java +++ b/android-app/src/main/java/com/mowesta/android/app/MowestaSettings.java @@ -6,6 +6,7 @@ import android.content.SharedPreferences; import android.content.res.Resources; import androidx.annotation.NonNull; +import androidx.lifecycle.MutableLiveData; import androidx.preference.PreferenceManager; import com.mowesta.android.sdk.SdkSettings; @@ -35,6 +36,42 @@ public class MowestaSettings extends SdkSettings { */ public static final String COLLECTION_SHOWN = "collection_shown"; + /** + * The key to a boolean to store whether the diagram will use + * celsius (true) or fahrenheit (false). + */ + public static final String TEMPERATURE_CELSIUS = "temperature_celsius"; + + /** + * The key to a boolean to show/hide the precipitation. + */ + public static final String SHOW_PRECIPITATION = "show_precipitation"; + + /** + * The key to a boolean to show/hide the wind speed and direction. + */ + public static final String SHOW_WIND = "show_wind"; + + /** + * The key to a boolean to show/hide the cloud coverage. + */ + public static final String SHOW_CLOUD = "show_cloud"; + + /** + * The key to a boolean to show/hide the humidty. + */ + public static final String SHOW_HUMIDITY = "show_humidity"; + + /** + * The key to a boolean to show/hide the snow depth. + */ + public static final String SHOW_SNOW = "show_snow"; + + /** + * The key to a boolean to show/hide the pressure. + */ + public static final String SHOW_PRESSURE = "show_pressure"; + /** * Creates the settings with the context. * @@ -130,5 +167,168 @@ public class MowestaSettings extends SdkSettings { } + /** + * Determines whether the diagram uses celsius or fahrenheit. + * + * @return True if the diagram uses celsius, false if fahrenheit + */ + public boolean isTemperatureCelsius() { + boolean defaultValue = getResources().getBoolean(R.bool.temperature_celsius_default); + return preferences.getBoolean(TEMPERATURE_CELSIUS, defaultValue); + } + + /** + * Sets the boolean to indicate whether the diagram uses fahrenheit + * or celsius. + * + * @param value The value. + */ + public void setTemperatureCelsius(boolean value) { + SharedPreferences.Editor e = preferences.edit(); + e.putBoolean(TEMPERATURE_CELSIUS, value); + e.apply(); + } + + /** + * Determines whether the temperature is in celsisus or fahrenheit without object allocation. + * + * @param context The context. + * @return True if temperature is in celsius. + */ + public static boolean isTemperatureCelsisus(@NonNull Context context) { + boolean defaultValue = context.getResources().getBoolean(R.bool.temperature_celsius_default); + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); + return preferences.getBoolean(TEMPERATURE_CELSIUS, defaultValue); + } + + /** + * Determines whether the cloud coverage is shown. + * + * @return True to show, false to hide. + */ + public boolean isShowCloud() { + boolean defaultValue = getResources().getBoolean(R.bool.show_cloud_default); + return preferences.getBoolean(SHOW_CLOUD, defaultValue); + } + + /** + * Sets the boolean to determine whether the cloud coverage is shown. + * + * @param value True to show, false to hide. + */ + public void setShowCloud(boolean value) { + SharedPreferences.Editor e = preferences.edit(); + e.putBoolean(SHOW_CLOUD, value); + e.apply(); + } + + + /** + * Determines whether the humidity is shown. + * + * @return True to show, false to hide. + */ + public boolean isShowHumidity() { + boolean defaultValue = getResources().getBoolean(R.bool.show_humidity_default); + return preferences.getBoolean(SHOW_HUMIDITY, defaultValue); + } + + /** + * Sets the boolean to determine whether the humidity is shown. + * + * @param value True to show, false to hide. + */ + public void setShowHumidity(boolean value) { + SharedPreferences.Editor e = preferences.edit(); + e.putBoolean(SHOW_HUMIDITY, value); + e.apply(); + } + + /** + * Determines whether the pressure is shown. + * + * @return True to show, false to hide. + */ + public boolean isShowPressure() { + boolean defaultValue = getResources().getBoolean(R.bool.show_pressure_default); + return preferences.getBoolean(SHOW_PRESSURE, defaultValue); + } + + /** + * Sets the boolean to determine whether the pressure is shown. + * + * @param value True to show, false to hide. + */ + public void setShowPressure(boolean value) { + SharedPreferences.Editor e = preferences.edit(); + e.putBoolean(SHOW_PRESSURE, value); + e.apply(); + } + + /** + * Determines whether the precipitation is shown. + * + * @return True to show, false to hide. + */ + public boolean isShowPrecipitation() { + boolean defaultValue = getResources().getBoolean(R.bool.show_precipitation_default); + return preferences.getBoolean(SHOW_PRECIPITATION, defaultValue); + } + + /** + * Sets the boolean to determine whether the precipitation is shown. + * + * @param value True to show, false to hide. + */ + public void setShowPrecipitation(boolean value) { + SharedPreferences.Editor e = preferences.edit(); + e.putBoolean(SHOW_PRECIPITATION, value); + e.apply(); + } + + /** + * Determines whether the wind is shown. + * + * @return True to show, false to hide. + */ + public boolean isShowWind() { + boolean defaultValue = getResources().getBoolean(R.bool.show_wind_default); + return preferences.getBoolean(SHOW_WIND, defaultValue); + } + + /** + * Sets the boolean to determine whether the wind is shown. + * + * @param value True to show, false to hide. + */ + public void setShowWind(boolean value) { + SharedPreferences.Editor e = preferences.edit(); + e.putBoolean(SHOW_WIND, value); + e.apply(); + } + + + /** + * Determines whether the snow depth is shown. + * + * @return True to show, false to hide. + */ + public boolean isShowSnow() { + boolean defaultValue = getResources().getBoolean(R.bool.show_snow_default); + return preferences.getBoolean(SHOW_SNOW, defaultValue); + } + + /** + * Sets the boolean to determine whether the snow depth is shown. + * + * @param value True to show, false to hide. + */ + public void setShowSnow(boolean value) { + SharedPreferences.Editor e = preferences.edit(); + e.putBoolean(SHOW_SNOW, value); + e.apply(); + } + + } diff --git a/android-app/src/main/java/com/mowesta/android/app/adapter/PreferenceLiveData.java b/android-app/src/main/java/com/mowesta/android/app/adapter/PreferenceLiveData.java new file mode 100644 index 00000000..6ab64282 --- /dev/null +++ b/android-app/src/main/java/com/mowesta/android/app/adapter/PreferenceLiveData.java @@ -0,0 +1,85 @@ +package com.mowesta.android.app.adapter; + +import android.content.Context; +import android.content.SharedPreferences; + +import androidx.annotation.NonNull; +import androidx.lifecycle.LiveData; +import androidx.lifecycle.MutableLiveData; + +/** + * A live data object for boolean preferences that automatically + * handles the subscription based on the observer count. + * + * @author Marcus + */ +public class PreferenceLiveData extends MutableLiveData { + + /** + * The key. + */ + private String key; + + /** + * The default value. + */ + private boolean defaultValue; + + /** + * The preferences to attach to. + */ + private SharedPreferences preferences; + + /** + * The listener to track changes to the value. + */ + private SharedPreferences.OnSharedPreferenceChangeListener listener = new SharedPreferences.OnSharedPreferenceChangeListener() { + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String k) { + if (key.equals(k)) { + boolean newValue = sharedPreferences.getBoolean(key, defaultValue); + if (newValue != getValue()) { + setValue(newValue); + } + } + } + }; + + /** + * Creates a new preference live data object for the shared preferences + * using the key assuming that it stores boolean values and the default + * value. + * + * @param preferences The preferences. + * @param key The key. + * @param defaultValue The default value. + */ + public PreferenceLiveData(@NonNull SharedPreferences preferences, @NonNull String key, boolean defaultValue) { + this.key = key; + this.preferences = preferences; + this.defaultValue = defaultValue; + } + + @Override + public void setValue(Boolean value) { + super.setValue(value); + if (value != preferences.getBoolean(key, defaultValue)) { + SharedPreferences.Editor e = preferences.edit(); + e.putBoolean(key, value); + e.apply(); + } + } + + @Override + protected void onActive() { + super.onActive(); + preferences.registerOnSharedPreferenceChangeListener(listener); + setValue(preferences.getBoolean(key, defaultValue)); + } + + @Override + protected void onInactive() { + super.onInactive(); + preferences.unregisterOnSharedPreferenceChangeListener(listener); + } +} diff --git a/android-app/src/main/java/com/mowesta/android/app/database/Favorite.java b/android-app/src/main/java/com/mowesta/android/app/database/Favorite.java index 8c066075..4d2ed3f8 100644 --- a/android-app/src/main/java/com/mowesta/android/app/database/Favorite.java +++ b/android-app/src/main/java/com/mowesta/android/app/database/Favorite.java @@ -6,6 +6,7 @@ import androidx.annotation.NonNull; import androidx.room.ColumnInfo; import androidx.room.Entity; import androidx.room.Ignore; +import androidx.room.Index; import androidx.room.TypeConverters; import com.fasterxml.jackson.databind.MapperFeature; @@ -31,7 +32,12 @@ import java.io.IOException; * * @author Marcus */ -@Entity(primaryKeys = { "type", "id" }, tableName = "favorite") +@Entity(primaryKeys = { "type", "id" }, tableName = "favorite", indices = { + @Index({"weatherTime", "deleted"}), + @Index({"locationTime", "deleted"}), + @Index({"deleted", "position"}), + @Index({"added", "deleted"}) +}) public class Favorite { /** diff --git a/android-app/src/main/java/com/mowesta/android/app/database/FavoriteAccessor.java b/android-app/src/main/java/com/mowesta/android/app/database/FavoriteAccessor.java index 641dabab..6db80f5d 100644 --- a/android-app/src/main/java/com/mowesta/android/app/database/FavoriteAccessor.java +++ b/android-app/src/main/java/com/mowesta/android/app/database/FavoriteAccessor.java @@ -27,6 +27,16 @@ public interface FavoriteAccessor { @Query("select * from favorite where not deleted order by position") LiveData> getActive(); + + /** + * returns the oldest entry in the database to determine whether + * an automatic refresh is necessary. + * + * @return The minimum time. + */ + @Query("select min(locationTime, weatherTime) from favorite where not deleted") + Long getUpdateTime(); + /** * Returns all favorites ordered by their position. * @@ -71,7 +81,7 @@ public interface FavoriteAccessor { /** * Returns the number of local favorites that - * defintively require synchronization. + * definitively require synchronization. * * @return The number of local favorites to sync. */ @@ -82,6 +92,6 @@ public interface FavoriteAccessor { * Deletes all favorites from the database. */ @Query("delete from favorite") - void resetAll(); + void clearAll(); } diff --git a/android-app/src/main/java/com/mowesta/android/app/database/FavoriteDatabase.java b/android-app/src/main/java/com/mowesta/android/app/database/FavoriteDatabase.java index 7530cc15..de7a74c4 100644 --- a/android-app/src/main/java/com/mowesta/android/app/database/FavoriteDatabase.java +++ b/android-app/src/main/java/com/mowesta/android/app/database/FavoriteDatabase.java @@ -10,7 +10,7 @@ import androidx.room.RoomDatabase; * is used as a cache to ensure that the locations can * be accessed offline. */ -@Database(entities = { Favorite.class }, version = 2, exportSchema = false) +@Database(entities = { Favorite.class }, version = 3, exportSchema = false) public abstract class FavoriteDatabase extends RoomDatabase { /** diff --git a/android-app/src/main/java/com/mowesta/android/app/fragment/AbstractDiagramFragment.java b/android-app/src/main/java/com/mowesta/android/app/fragment/AbstractDiagramFragment.java new file mode 100644 index 00000000..77704996 --- /dev/null +++ b/android-app/src/main/java/com/mowesta/android/app/fragment/AbstractDiagramFragment.java @@ -0,0 +1,89 @@ +package com.mowesta.android.app.fragment; + +import android.content.SharedPreferences; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.RecyclerView; + +import com.mowesta.android.app.MowestaSettings; +import com.mowesta.android.app.R; + +/** + * A fragment that extends the network fragment with an additional + * menu to handle the diagram. + * + * @author Marcus + */ +public abstract class AbstractDiagramFragment extends AbstractNetworkFragment { + + /** + * The settings to read the state of the unit. + */ + private MowestaSettings settings; + + /** + * A preference listener that is running as long as we are resumed. + */ + private SharedPreferences.OnSharedPreferenceChangeListener unitListener = (prefs, key) -> { + if (MowestaSettings.TEMPERATURE_CELSIUS.equals(key)) onUnitChanged(); + }; + + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + settings = new MowestaSettings(getActivity().getApplication()); + super.onCreate(savedInstanceState); + setHasOptionsMenu(true); + } + + @Override + public void onResume() { + super.onResume(); + settings.getPreferences().registerOnSharedPreferenceChangeListener(unitListener); + onUnitChanged(); + } + + @Override + public void onPause() { + super.onPause(); + settings.getPreferences().unregisterOnSharedPreferenceChangeListener(unitListener); + } + + /** + * Called whenever the unit changes. Subclasses may overwrite this, + * but should call through to super. + */ + public void onUnitChanged() { + getActivity().invalidateOptionsMenu(); + } + + @Override + public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { + super.onCreateOptionsMenu(menu, inflater); + inflater.inflate(R.menu.menu_unit, menu); + boolean celsius = settings.isTemperatureCelsius(); + menu.findItem(R.id.unit_celsius).setVisible(celsius); + menu.findItem(R.id.unit_fahrenheit).setVisible(!celsius); + } + + @Override + public boolean onOptionsItemSelected(@NonNull MenuItem item) { + switch (item.getItemId()) { + case R.id.unit_fahrenheit: + settings.setTemperatureCelsius(true); + return true; + case R.id.unit_celsius: + settings.setTemperatureCelsius(false); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + +} diff --git a/android-app/src/main/java/com/mowesta/android/app/fragment/CityForecastFragment.java b/android-app/src/main/java/com/mowesta/android/app/fragment/CityForecastFragment.java index 485c36d9..dc53f143 100644 --- a/android-app/src/main/java/com/mowesta/android/app/fragment/CityForecastFragment.java +++ b/android-app/src/main/java/com/mowesta/android/app/fragment/CityForecastFragment.java @@ -2,6 +2,9 @@ package com.mowesta.android.app.fragment; import android.os.Bundle; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; diff --git a/android-app/src/main/java/com/mowesta/android/app/fragment/CityFragment.java b/android-app/src/main/java/com/mowesta/android/app/fragment/CityFragment.java index 04b63a99..1e5c163b 100644 --- a/android-app/src/main/java/com/mowesta/android/app/fragment/CityFragment.java +++ b/android-app/src/main/java/com/mowesta/android/app/fragment/CityFragment.java @@ -2,6 +2,9 @@ package com.mowesta.android.app.fragment; import android.os.Bundle; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; @@ -68,6 +71,32 @@ public class CityFragment extends AbstractPlaceFragment { return getView().findViewById(R.id.bottom_navigation); } + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setHasOptionsMenu(true); + } + + @Override + public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { + super.onCreateOptionsMenu(menu, inflater); + inflater.inflate(R.menu.menu_customize, menu); + } + + @Override + public boolean onOptionsItemSelected(@NonNull MenuItem item) { + switch (item.getItemId()) { + case R.id.action_customize: + getChildFragmentManager() + .beginTransaction() + .add(new CustomizeDialogFragment(), "customize") + .commit(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { @@ -98,4 +127,6 @@ public class CityFragment extends AbstractPlaceFragment { NavigationUI.setupWithNavController(layout, toolbar, controller, builder.build()); return root; } + + } diff --git a/android-app/src/main/java/com/mowesta/android/app/fragment/CityInfoFragment.java b/android-app/src/main/java/com/mowesta/android/app/fragment/CityInfoFragment.java index ee8cb6ef..0917d81e 100644 --- a/android-app/src/main/java/com/mowesta/android/app/fragment/CityInfoFragment.java +++ b/android-app/src/main/java/com/mowesta/android/app/fragment/CityInfoFragment.java @@ -25,6 +25,7 @@ import com.mowesta.android.feign.model.City; import com.mowesta.android.feign.model.Country; import com.mowesta.android.feign.model.State; import com.mowesta.android.feign.model.WeatherCondition; +import com.mowesta.android.feign.model.WeatherStation; import java.util.ArrayList; import java.util.List; @@ -76,6 +77,17 @@ public class CityInfoFragment extends CityFragment.ChildFragment { model.getBoundary().observe(getViewLifecycleOwner(), (b) -> updateMap.run()); binding.setModel(model); binding.setCondition(condition); + NavController controller = Navigation.findNavController(getActivity(), R.id.navigation_app); + binding.setStationListener(new CityViewModel.OnStationSelectedListener() { + @Override + public void onStationSelected(WeatherStation station) { + // go to the station fragment + NavOptions.Builder opts = new NavOptions.Builder().setEnterAnim(R.anim.slide_in_right).setExitAnim(R.anim.slide_out_left); + Bundle bundle = new Bundle(); + bundle.putLong("id", station.getId()); + controller.navigate(R.id.destination_station, bundle, opts.build()); + } + }); binding.setLifecycleOwner(getViewLifecycleOwner()); return binding.getRoot(); } diff --git a/android-app/src/main/java/com/mowesta/android/app/fragment/CustomizeDialogFragment.java b/android-app/src/main/java/com/mowesta/android/app/fragment/CustomizeDialogFragment.java new file mode 100644 index 00000000..bd2a9ce4 --- /dev/null +++ b/android-app/src/main/java/com/mowesta/android/app/fragment/CustomizeDialogFragment.java @@ -0,0 +1,36 @@ +package com.mowesta.android.app.fragment; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.databinding.DataBindingUtil; +import androidx.lifecycle.ViewModelProvider; + +import com.google.android.material.bottomsheet.BottomSheetDialogFragment; +import com.mowesta.android.app.R; +import com.mowesta.android.app.databinding.DialogCustomizeBinding; +import com.mowesta.android.app.model.CustomizeViewModel; + +/** + * A bottom sheet dialog that enables the user to customize the weather data. + * + * @author Marcus + */ +public class CustomizeDialogFragment extends BottomSheetDialogFragment { + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + DialogCustomizeBinding binding = DataBindingUtil.inflate(inflater, R.layout.dialog_customize, container, false); + CustomizeViewModel model = new ViewModelProvider(this).get(CustomizeViewModel.class); + binding.setModel(model); + binding.setLifecycleOwner(getViewLifecycleOwner()); + binding.setCloseListener(() -> { this.dismiss(); }); + return binding.getRoot(); + } + +} diff --git a/android-app/src/main/java/com/mowesta/android/app/fragment/DeviceFragment.java b/android-app/src/main/java/com/mowesta/android/app/fragment/DeviceFragment.java index d37d2173..2902c1ff 100644 --- a/android-app/src/main/java/com/mowesta/android/app/fragment/DeviceFragment.java +++ b/android-app/src/main/java/com/mowesta/android/app/fragment/DeviceFragment.java @@ -7,6 +7,7 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import androidx.databinding.DataBindingUtil; import androidx.lifecycle.ViewModelProvider; @@ -34,7 +35,7 @@ import com.mowesta.android.feign.model.Measurement; * * @author Marcus */ -public class DeviceFragment extends AbstractNetworkFragment { +public class DeviceFragment extends AbstractDiagramFragment { @Override protected AbstractNetworkViewModel getNetworkViewModel() { @@ -50,7 +51,7 @@ public class DeviceFragment extends AbstractNetworkFragment { View root = binding.getRoot(); CollapsingToolbarLayout layout = root.findViewById(R.id.layout_toolbar); Toolbar toolbar = root.findViewById(R.id.toolbar); - MapView mapView = root.findViewById(R.id.map); + ((AppCompatActivity)getActivity()).setSupportActionBar(toolbar); model.getDevice().observe(getViewLifecycleOwner(), (device)-> { String title = ""; if (device != null) { @@ -100,4 +101,10 @@ public class DeviceFragment extends AbstractNetworkFragment { recyclerView.setAdapter(adapter); } + @Override + public void onUnitChanged() { + super.onUnitChanged(); + RecyclerView recyclerView = getView().findViewById(R.id.recycler); + recyclerView.getAdapter().notifyDataSetChanged(); + } } diff --git a/android-app/src/main/java/com/mowesta/android/app/fragment/FavoritesFragment.java b/android-app/src/main/java/com/mowesta/android/app/fragment/FavoritesFragment.java index b3d6bab3..c2f784f3 100644 --- a/android-app/src/main/java/com/mowesta/android/app/fragment/FavoritesFragment.java +++ b/android-app/src/main/java/com/mowesta/android/app/fragment/FavoritesFragment.java @@ -76,6 +76,13 @@ public class FavoritesFragment extends Fragment { } } })); + View layoutHelp = view.findViewById(R.id.favorites_help); + View layoutList = view.findViewById(R.id.favorites_list); + model.getFavorites().observe(getViewLifecycleOwner(), (list)-> { + boolean empty = (list == null || list.size() == 0); + layoutHelp.setVisibility(empty ? View.VISIBLE: View.GONE); + layoutList.setVisibility(empty ? View.GONE: View.VISIBLE); + }); } @Override diff --git a/android-app/src/main/java/com/mowesta/android/app/fragment/SettingsFragment.java b/android-app/src/main/java/com/mowesta/android/app/fragment/SettingsFragment.java index 671da973..575d90d1 100644 --- a/android-app/src/main/java/com/mowesta/android/app/fragment/SettingsFragment.java +++ b/android-app/src/main/java/com/mowesta/android/app/fragment/SettingsFragment.java @@ -7,11 +7,18 @@ import com.google.android.gms.oss.licenses.OssLicensesMenuActivity; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.mowesta.android.app.BuildConfig; import com.mowesta.android.app.IApp; +import com.mowesta.android.app.MowestaApp; +import com.mowesta.android.app.MowestaService; import com.mowesta.android.app.MowestaSettings; import com.mowesta.android.app.R; +import com.mowesta.android.app.database.FavoriteDatabase; import com.mowesta.android.app.repository.DeviceRepository; +import com.mowesta.android.app.task.DatabaseTask; +import com.mowesta.android.sdk.SdkRepository; +import com.mowesta.android.sdk.task.ClearTask; import android.annotation.TargetApi; +import android.app.Activity; import android.app.Dialog; import android.content.ActivityNotFoundException; import android.content.DialogInterface; @@ -92,6 +99,11 @@ public class SettingsFragment extends PreferenceFragmentCompat { */ private static final String KEY_DEVELOPMENT_TOKEN = "development_token"; + /** + * The key to clear the sdk cache. + */ + private static final String KEY_DEVELOPMENT_CLEAR_CACHE = "development_clear_cache"; + /** * The key for the notification preference category. */ @@ -146,6 +158,7 @@ public class SettingsFragment extends PreferenceFragmentCompat { bindReset(); bindTerms(); bindLicenses(); + bindSdkSettings(); return v; } @@ -309,6 +322,9 @@ public class SettingsFragment extends PreferenceFragmentCompat { }); } + /** + * Binds the terms preference. + */ private void bindTerms() { setClickListener(KEY_ABOUT_TERMS, new Preference.OnPreferenceClickListener() { @Override @@ -319,7 +335,9 @@ public class SettingsFragment extends PreferenceFragmentCompat { }); } - + /** + * Binds the license preference. + */ private void bindLicenses() { setClickListener(KEY_ABOUT_LICENSES, new Preference.OnPreferenceClickListener() { @Override @@ -331,6 +349,21 @@ public class SettingsFragment extends PreferenceFragmentCompat { }); } + /** + * Binds the sdk settings. + */ + private void bindSdkSettings() { + setClickListener(KEY_DEVELOPMENT_CLEAR_CACHE, new Preference.OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + new ClearTask(SdkRepository.getInstance(getActivity().getApplication()), false, () -> { + Toast.makeText(preference.getContext(), R.string.setting_development_clear_message, Toast.LENGTH_SHORT).show(); + }).execute(); + return false; + } + }); + } + /** * Enables the developmentGroup mode. */ @@ -397,9 +430,29 @@ public class SettingsFragment extends PreferenceFragmentCompat { b.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - //getRepository().user.setValue(null); - //getRepository().deviceHandle.setValue(null); // remove the device handle - getActivity().finish(); + // stop the service and its background processing + Log.d(TAG, "Resetting the device."); + Activity activity = getActivity(); + MowestaService.stopService(activity); + // reset the settings + MowestaApp app = (MowestaApp)activity.getApplication(); + SdkRepository sdk = SdkRepository.getInstance(app); + MowestaSettings settings = new MowestaSettings(app); + settings.setPrivacyMeasure(false); + settings.setCollectionShown(false); + app.getUserRepository().clearCredentials(); + app.getDeviceRepository().clearDevice(); + new ClearTask(sdk, true, ()-> { + new DatabaseTask + ((input, database)-> { + Log.d(TAG, "Clearing database."); + database.getAccessor().clearAll(); + return null; + },(input, result)-> { + Log.d(TAG, "Finishing the activity."); + activity.finish(); + }).execute(null, app.getFavoriteRepository().getDatabase()); + }).execute(); } }); b.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { diff --git a/android-app/src/main/java/com/mowesta/android/app/fragment/StationFragment.java b/android-app/src/main/java/com/mowesta/android/app/fragment/StationFragment.java index 58d40309..bf70d15e 100644 --- a/android-app/src/main/java/com/mowesta/android/app/fragment/StationFragment.java +++ b/android-app/src/main/java/com/mowesta/android/app/fragment/StationFragment.java @@ -1,13 +1,18 @@ package com.mowesta.android.app.fragment; import android.annotation.SuppressLint; +import android.content.SharedPreferences; import android.os.Bundle; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import androidx.databinding.DataBindingUtil; import androidx.fragment.app.Fragment; @@ -24,6 +29,7 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior; import com.locoslab.android.leafless.MapView; import com.locoslab.android.leafless.marker.Marker; import com.locoslab.library.geometry.wgs.Coordinate; +import com.mowesta.android.app.MowestaSettings; import com.mowesta.android.app.R; import com.mowesta.android.app.adapter.CityEntryPagedListAdapter; import com.mowesta.android.app.adapter.DiagramEntryPagedListAdapter; @@ -45,7 +51,7 @@ import com.mowesta.android.feign.model.WeatherStation; * * @author Marcus */ -public class StationFragment extends AbstractNetworkFragment { +public class StationFragment extends AbstractDiagramFragment { /** * The marker displayed on the map. @@ -71,6 +77,7 @@ public class StationFragment extends AbstractNetworkFragment { View root = binding.getRoot(); CollapsingToolbarLayout layout = root.findViewById(R.id.layout_toolbar); Toolbar toolbar = root.findViewById(R.id.toolbar); + ((AppCompatActivity)getActivity()).setSupportActionBar(toolbar); MapView mapView = root.findViewById(R.id.map); MapViewUtil.setupNonInteractiveMap(mapView); model.getStation().observe(getViewLifecycleOwner(), (station)-> { @@ -161,6 +168,14 @@ public class StationFragment extends AbstractNetworkFragment { (expanded?BottomSheetBehavior.STATE_EXPANDED:BottomSheetBehavior.STATE_COLLAPSED)); } + @Override + public void onUnitChanged() { + super.onUnitChanged(); + RecyclerView recyclerView = getView().findViewById(R.id.recycler); + recyclerView.getAdapter().notifyDataSetChanged(); + } + + } diff --git a/android-app/src/main/java/com/mowesta/android/app/fragment/VideoFragment.java b/android-app/src/main/java/com/mowesta/android/app/fragment/VideoFragment.java index e8a1fd78..174eae37 100644 --- a/android-app/src/main/java/com/mowesta/android/app/fragment/VideoFragment.java +++ b/android-app/src/main/java/com/mowesta/android/app/fragment/VideoFragment.java @@ -1,5 +1,6 @@ package com.mowesta.android.app.fragment; +import android.media.MediaPlayer; import android.net.Uri; import android.os.Bundle; import android.os.Handler; @@ -158,12 +159,20 @@ public class VideoFragment extends Fragment { */ TimeUtils timeUtils; + /** + * The last position that we fetched from the player. + */ + private int lastPosition; + /** * Timer. */ Runnable timer = () -> { - int secs = player.getCurrentPosition() / 1000; - long time = args.getVideo().getTime() + (args.getVideo().getStart() + secs) * 60 * 60 * 1000; + lastPosition = player.getCurrentPosition(); + int secs = lastPosition / 1000; + double hps = args.getVideo().getFph() / (double)args.getVideo().getFps(); + int hours = (int)(secs / hps); + long time = args.getVideo().getTime() + (args.getVideo().getStart() + hours) * 60 * 60 * 1000; int dayRes = timeUtils.getDayName(time); String day; if (dayRes != 0) { @@ -176,8 +185,6 @@ public class VideoFragment extends Fragment { handler.postDelayed(this.timer, 500); }; - - @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { @@ -204,11 +211,11 @@ public class VideoFragment extends Fragment { args.getVideo().getSouthWest().getLongitude(), args.getVideo().getSouthWest().getLatitude()); player.setVideoURI(Uri.parse(args.getVideo().getUrl())); if (savedInstanceState != null) { - player.seekTo(savedInstanceState.getInt("position", 0)); - if (savedInstanceState.getBoolean("playing")) player.start(); - } else { - player.start(); + int pos = savedInstanceState.getInt("position", 0); + Log.d(TAG, "Resuming playback at position " + pos + "."); + player.seekTo(pos); } + player.start(); if (args.getCity() != null) { timezone = args.getCity().getTimezone(); marker.setPosition(args.getCity().getCoordinate().getLongitude(), args.getCity().getCoordinate().getLatitude()); @@ -221,8 +228,8 @@ public class VideoFragment extends Fragment { @Override public void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); - outState.putInt("position", player.getCurrentPosition()); - outState.putBoolean("playing", player.isPlaying()); + Log.d(TAG, "Saving playback position at " + lastPosition + "."); + outState.putInt("position", lastPosition); } @Override diff --git a/android-app/src/main/java/com/mowesta/android/app/model/BindingAdapters.java b/android-app/src/main/java/com/mowesta/android/app/model/BindingAdapters.java index f9d64bdb..eddae3f0 100644 --- a/android-app/src/main/java/com/mowesta/android/app/model/BindingAdapters.java +++ b/android-app/src/main/java/com/mowesta/android/app/model/BindingAdapters.java @@ -591,7 +591,8 @@ public class BindingAdapters { view.setVisibility(View.GONE); } else { view.setVisibility(View.VISIBLE); - view.setText(view.getResources().getString(R.string.format_compact, (float)entry.getTemperature().getAbsoluteValue())); + float temp = BindingTransforms.getTemperature(view.getContext(), entry.getTemperature().getAbsoluteValue()); + view.setText(view.getResources().getString(R.string.format_compact, temp)); } } diff --git a/android-app/src/main/java/com/mowesta/android/app/model/BindingTransforms.java b/android-app/src/main/java/com/mowesta/android/app/model/BindingTransforms.java index 8398b459..fc0f4509 100644 --- a/android-app/src/main/java/com/mowesta/android/app/model/BindingTransforms.java +++ b/android-app/src/main/java/com/mowesta/android/app/model/BindingTransforms.java @@ -1,10 +1,13 @@ package com.mowesta.android.app.model; import android.content.Context; +import android.content.SharedPreferences; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.preference.PreferenceManager; +import com.mowesta.android.app.MowestaSettings; import com.mowesta.android.app.R; import com.mowesta.android.app.view.JamIcon; import com.mowesta.android.app.view.WeatherIcon; @@ -22,6 +25,23 @@ import java.util.Map; public class BindingTransforms { + /** + * Returns the temperature as float in celsius or fahrenheit based on + * the user's current settings. + * + * @param context The context. + * @param celsius The temperature in celsius. + * @return The temperature in celsisus or fahrenheit. + */ + public static float getTemperature(@NonNull Context context, double celsius) { + if (MowestaSettings.isTemperatureCelsisus(context)) { + return (float)celsius; + } else { + return (float) Math.round((celsius * 9 / 5) + 32); + } + } + + /** * Returns the best (non-null) name from a map of names given the current * language settings and the preference for short values. diff --git a/android-app/src/main/java/com/mowesta/android/app/model/CityViewModel.java b/android-app/src/main/java/com/mowesta/android/app/model/CityViewModel.java index d61cccf4..dc3f7f56 100644 --- a/android-app/src/main/java/com/mowesta/android/app/model/CityViewModel.java +++ b/android-app/src/main/java/com/mowesta/android/app/model/CityViewModel.java @@ -3,11 +3,9 @@ package com.mowesta.android.app.model; import android.app.Application; import androidx.annotation.NonNull; -import androidx.lifecycle.AndroidViewModel; import androidx.lifecycle.LiveData; import androidx.lifecycle.MutableLiveData; -import com.mowesta.android.app.IApp; import com.mowesta.android.app.R; import com.mowesta.android.app.database.Favorite; import com.mowesta.android.app.database.FavoriteDatabase; @@ -36,6 +34,20 @@ import java.util.List; */ public class CityViewModel extends AbstractPlaceViewModel { + /** + * A listener that is informed when a station is selected. + */ + public interface OnStationSelectedListener { + + /** + * Called when a station is selected. + * + * @param station The selected station. + */ + void onStationSelected(WeatherStation station); + } + + /** * The current weather condition. */ @@ -96,7 +108,9 @@ public class CityViewModel extends AbstractPlaceViewModel { */ private final MutableLiveData boundary = new MutableLiveData<>(); - + /** + * The loader for the city data. + */ private final ApiTask, City> cityLoader = new ApiTask<> ((input, client) -> client.getCity(input.getValue()), (input, result) -> { completeRequest(input, () -> city.setValue(result)); }, diff --git a/android-app/src/main/java/com/mowesta/android/app/model/ConditionViewModel.java b/android-app/src/main/java/com/mowesta/android/app/model/ConditionViewModel.java index 98418847..224457de 100644 --- a/android-app/src/main/java/com/mowesta/android/app/model/ConditionViewModel.java +++ b/android-app/src/main/java/com/mowesta/android/app/model/ConditionViewModel.java @@ -16,7 +16,7 @@ import com.mowesta.android.feign.model.WeatherCondition; * * @author Marcus */ -public class ConditionViewModel extends AndroidViewModel { +public class ConditionViewModel extends CustomizeViewModel { /** * The title to display. diff --git a/android-app/src/main/java/com/mowesta/android/app/model/CustomizeViewModel.java b/android-app/src/main/java/com/mowesta/android/app/model/CustomizeViewModel.java new file mode 100644 index 00000000..02225607 --- /dev/null +++ b/android-app/src/main/java/com/mowesta/android/app/model/CustomizeViewModel.java @@ -0,0 +1,125 @@ +package com.mowesta.android.app.model; + +import android.app.Application; +import android.content.SharedPreferences; +import android.content.res.Resources; + +import androidx.annotation.NonNull; +import androidx.lifecycle.AndroidViewModel; +import androidx.lifecycle.MutableLiveData; +import androidx.preference.Preference; +import androidx.preference.PreferenceManager; + +import com.mowesta.android.app.MowestaSettings; +import com.mowesta.android.app.R; +import com.mowesta.android.app.adapter.PreferenceLiveData; + +/** + * The view model that enables the customization. + */ +public class CustomizeViewModel extends AndroidViewModel { + + /** + * The live data with the precipitation. + */ + private final PreferenceLiveData showPrecipitation; + + /** + * The live data with the wind speed and direction. + */ + private final PreferenceLiveData showWind; + + /** + * The live data with the cloud coverage. + */ + private final PreferenceLiveData showCloud; + + /** + * The live data with the humidity. + */ + private final PreferenceLiveData showHumidity; + + /** + * The live data with the snow. + */ + private final PreferenceLiveData showSnow; + + /** + * The live data with the pressure. + */ + private final PreferenceLiveData showPressure; + + + /** + * Creates a new view model and initializes it from the settings. + * + * @param application The application. + */ + public CustomizeViewModel(@NonNull Application application) { + super(application); + Resources r = application.getResources(); + SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(application); + showPressure = new PreferenceLiveData(p, MowestaSettings.SHOW_PRESSURE, r.getBoolean(R.bool.show_pressure_default)); + showSnow = new PreferenceLiveData(p, MowestaSettings.SHOW_SNOW, r.getBoolean(R.bool.show_snow_default)); + showHumidity = new PreferenceLiveData(p, MowestaSettings.SHOW_HUMIDITY, r.getBoolean(R.bool.show_humidity_default)); + showCloud = new PreferenceLiveData(p, MowestaSettings.SHOW_CLOUD, r.getBoolean(R.bool.show_cloud_default)); + showWind = new PreferenceLiveData(p, MowestaSettings.SHOW_WIND, r.getBoolean(R.bool.show_wind_default)); + showPrecipitation = new PreferenceLiveData(p, MowestaSettings.SHOW_PRECIPITATION, r.getBoolean(R.bool.show_precipitation_default)); + } + + /** + * Returns the live data to control the visibility of the cloud. + * + * @return The live data to control the cloud visibility. + */ + public MutableLiveData getShowCloud() { + return showCloud; + } + + /** + * Returns the live data to control the visibility of the humidity. + * + * @return The live data to control the humidity visibility. + */ + public MutableLiveData getShowHumidity() { + return showHumidity; + } + + /** + * Returns the live data to control the visibility of the precipitation. + * + * @return The live data to control the precipitation visibility. + */ + public MutableLiveData getShowPrecipitation() { + return showPrecipitation; + } + + /** + * Returns the live data to control the visibility of the pressure. + * + * @return The live data to control the pressure visibility. + */ + public MutableLiveData getShowPressure() { + return showPressure; + } + + /** + * Returns the live data to control the visibility of the show. + * + * @return The live data to control the show visibility. + */ + public MutableLiveData getShowSnow() { + return showSnow; + } + + /** + * Returns the live data to control the visibility of the wind. + * + * @return The live data to control the wind visibility. + */ + public MutableLiveData getShowWind() { + return showWind; + } + + +} diff --git a/android-app/src/main/java/com/mowesta/android/app/model/LoginViewModel.java b/android-app/src/main/java/com/mowesta/android/app/model/LoginViewModel.java index b8ed7c4a..3aa42d19 100644 --- a/android-app/src/main/java/com/mowesta/android/app/model/LoginViewModel.java +++ b/android-app/src/main/java/com/mowesta/android/app/model/LoginViewModel.java @@ -129,10 +129,10 @@ public class LoginViewModel extends AndroidViewModel { /** * Links an existing device with the user. */ - final ApiTask linkTask = new ApiTask((input, client) -> { - return client.setCurrentDeviceUser(); + final ApiTask linkTask = new ApiTask((input, client) -> { + return client.setCurrentDeviceUser((Device)input[1]); }, (input, result) -> { - getUserRepository().setCredentials(input); + getUserRepository().setCredentials((UserCredentials)input[0]); getDeviceRepository().setDevice(result); destination.setValue(Destination.DEVICES); }, (input, status) -> { @@ -144,6 +144,7 @@ public class LoginViewModel extends AndroidViewModel { } else { failure.setValue(R.string.login_failure_network); } + System.out.println("Failure is: " + status); }); @@ -192,6 +193,7 @@ public class LoginViewModel extends AndroidViewModel { loginEnabled.setValue(Boolean.TRUE); explanationText.setValue(R.string.login_explain_update); loginButtonText.setValue(R.string.login_button_update); + noLoginButtonText.setValue(R.string.login_button_continue); } } else { registerButtonVisible.setValue(Boolean.TRUE); @@ -421,8 +423,9 @@ public class LoginViewModel extends AndroidViewModel { DefaultApi api = getClientFactory().createClient(credentials); passwordTask.execute(credentials, api); } else { + Device device = getDeviceRepository().getDevice().getValue(); DefaultApi api = getClientFactory().createClient(credentials, getDeviceRepository().getHandle().getValue()); - linkTask.execute(credentials, api); + linkTask.execute(new Object[] { credentials, device }, api); } } else { DefaultApi api = getClientFactory().createClient(credentials); diff --git a/android-app/src/main/java/com/mowesta/android/app/model/SummaryViewModel.java b/android-app/src/main/java/com/mowesta/android/app/model/SummaryViewModel.java index ff2f5fa3..58abf1c3 100644 --- a/android-app/src/main/java/com/mowesta/android/app/model/SummaryViewModel.java +++ b/android-app/src/main/java/com/mowesta/android/app/model/SummaryViewModel.java @@ -16,7 +16,7 @@ import com.mowesta.android.feign.model.WeatherCondition; * * @author Marcus */ -public class SummaryViewModel extends AndroidViewModel { +public class SummaryViewModel extends CustomizeViewModel { /** * The minimum values. @@ -413,6 +413,7 @@ public class SummaryViewModel extends AndroidViewModel { r.setTemperature(wc.getTemperature()); r.setTime(wc.getTime()); r.setWindSpeed(wc.getWindSpeed()); + r.setWindDirection(wc.getWindDirection()); r.setType(wc.getType()); return r; } diff --git a/android-app/src/main/java/com/mowesta/android/app/repository/DeviceRepository.java b/android-app/src/main/java/com/mowesta/android/app/repository/DeviceRepository.java index f0efff2b..7d8102da 100644 --- a/android-app/src/main/java/com/mowesta/android/app/repository/DeviceRepository.java +++ b/android-app/src/main/java/com/mowesta/android/app/repository/DeviceRepository.java @@ -1,12 +1,16 @@ package com.mowesta.android.app.repository; +import android.util.Log; + import androidx.annotation.NonNull; import androidx.lifecycle.LiveData; import androidx.lifecycle.MutableLiveData; +import com.fasterxml.jackson.databind.ObjectMapper; import com.mowesta.android.app.IApp; import com.mowesta.android.feign.model.Device; import com.mowesta.android.feign.model.DeviceHandle; +import com.mowesta.android.feign.model.User; /** * The device repository stores the state about the device. @@ -15,6 +19,11 @@ import com.mowesta.android.feign.model.DeviceHandle; */ public class DeviceRepository extends Repository { + /** + * The log tag. + */ + private static final String TAG = "DeviceRepository"; + /** * A builder for the device repository. */ @@ -30,6 +39,22 @@ public class DeviceRepository extends Repository { */ private String handle; + /** + * A flag to trace changes. + */ + private boolean trace; + + + /** + * Enables tracing. + * + * @param trace True to enable, false to disable. + * @return The builder for chaining. + */ + public DeviceRepository.Builder setTrace(boolean trace) { + this.trace = trace; + return this; + } /** * Sets the initial device. * @@ -77,6 +102,14 @@ public class DeviceRepository extends Repository { */ public DeviceRepository build(IApp application) { DeviceRepository r = new DeviceRepository(application); + if (trace) { + r.getDevice().observeForever((d) -> { + Log.d(TAG, "Setting device to " + (d==null?"null":d.getId()) + " with user " + (d==null?"null":d.getUser()) + "."); + }); + r.getHandle().observeForever((h) -> { + Log.d(TAG, "Setting handle to " + h + "."); + }); + } FileStoreObserver deviceObserver = new FileStoreObserver(application.getContext(), Device.class, "device.json", false); FileStoreObserver handleObserver = new FileStoreObserver(application.getContext(), String.class, "handle.json", true); r.device.setValue(device == null ? deviceObserver.loadValue() : device); diff --git a/android-app/src/main/java/com/mowesta/android/app/repository/UserRepository.java b/android-app/src/main/java/com/mowesta/android/app/repository/UserRepository.java index 4b84840c..b9b2cf90 100644 --- a/android-app/src/main/java/com/mowesta/android/app/repository/UserRepository.java +++ b/android-app/src/main/java/com/mowesta/android/app/repository/UserRepository.java @@ -1,6 +1,7 @@ package com.mowesta.android.app.repository; import android.os.Build; +import android.util.Log; import androidx.annotation.NonNull; import androidx.lifecycle.LiveData; @@ -18,6 +19,11 @@ import com.mowesta.android.feign.model.User; */ public class UserRepository extends Repository { + /** + * The log tag. + */ + private static final String TAG = "UserRepository"; + /** * A builder for the user repository. * @@ -35,6 +41,11 @@ public class UserRepository extends Repository { */ private UserCredentials credentials; + /** + * A flag to trace changes. + */ + private boolean trace; + /** * Sets the initial user. * @@ -46,6 +57,17 @@ public class UserRepository extends Repository { return this; } + /** + * Enables tracing. + * + * @param trace True to enable, false to disable. + * @return The builder for chaining. + */ + public Builder setTrace(boolean trace) { + this.trace = trace; + return this; + } + /** * Sets the initial user credentials. * @@ -83,6 +105,17 @@ public class UserRepository extends Repository { */ public UserRepository build(IApp application) { UserRepository r = new UserRepository(application); + if (trace) { + r.state.observeForever((s) -> { + Log.d(TAG, "Setting state to " + s.name()); + }); + r.credentials.observeForever((c)-> { + Log.d(TAG, "Setting credentials to " + (c==null?"null":(c.getLogin()+":"+c.getPassword())) + "."); + }); + r.user.observeForever((u)-> { + Log.d(TAG, "Setting user to " + (u==null?"null":(u.getLogin() + ":" + u.getId())) + "."); + }); + } FileStoreObserver userObserver = new FileStoreObserver(application.getContext(), User.class, "user.json", false); FileStoreObserver credentialsObserver = new FileStoreObserver(application.getContext(), UserCredentials.class, "credentials.json", true); r.user.setValue(user == null ? userObserver.loadValue() : user); @@ -210,6 +243,7 @@ public class UserRepository extends Repository { */ public void clearCredentials() { this.credentials.setValue(null); + this.user.setValue(null); this.state.setValue(State.INVALID); } diff --git a/android-app/src/main/java/com/mowesta/android/app/task/AbstractTask.java b/android-app/src/main/java/com/mowesta/android/app/task/AbstractTask.java deleted file mode 100644 index b416ef5a..00000000 --- a/android-app/src/main/java/com/mowesta/android/app/task/AbstractTask.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.mowesta.android.app.task; - -import android.os.AsyncTask; - -import com.mowesta.android.app.MowestaApp; - -/** - * Base class for the AsyncTasks - * - * @author Arman - */ -public abstract class AbstractTask extends AsyncTask { - - /** - * Reference to the app - */ - protected MowestaApp app; - - AbstractTask(MowestaApp app) { - this.app = app; - } -} diff --git a/android-app/src/main/java/com/mowesta/android/app/task/RefreshTask.java b/android-app/src/main/java/com/mowesta/android/app/task/RefreshTask.java index 06bdf073..8c5547ac 100644 --- a/android-app/src/main/java/com/mowesta/android/app/task/RefreshTask.java +++ b/android-app/src/main/java/com/mowesta/android/app/task/RefreshTask.java @@ -9,6 +9,7 @@ import com.mowesta.android.feign.api.DefaultApi; import com.mowesta.android.feign.model.City; import com.mowesta.android.feign.model.CityPage; +import java.util.ArrayList; import java.util.List; /** @@ -58,20 +59,24 @@ public class RefreshTask { * The task that updates the database in the background * using the sequential executor. */ - DatabaseTask updateTask = new DatabaseTask<>( - (input, database) -> { - Favorite target = database.getAccessor().findById(input.getType(), input.getId()); - if (target != null && !target.isDeleted()) { - target.setLocation(input.getLocation()); - target.setBoundary(input.getBoundary()); - target.setCity(input.getCity()); - target.setForecast(input.getForecast()); - target.setStation(input.getStation()); - target.setWeatherTime(input.getWeatherTime()); - target.setLocationTime(input.getLocationTime()); - target.setCondition(input.getCondition()); - database.getAccessor().update(target); - } + DatabaseTask, Void> updateTask = new DatabaseTask<>( + (list, database) -> { + database.runInTransaction(() -> { + for (Favorite input: list) { + Favorite target = database.getAccessor().findById(input.getType(), input.getId()); + if (target != null && !target.isDeleted()) { + target.setLocation(input.getLocation()); + target.setBoundary(input.getBoundary()); + target.setCity(input.getCity()); + target.setForecast(input.getForecast()); + target.setStation(input.getStation()); + target.setWeatherTime(input.getWeatherTime()); + target.setLocationTime(input.getLocationTime()); + target.setCondition(input.getCondition()); + database.getAccessor().update(target); + } + } + }); return null; }, (input, output) -> { }); @@ -98,15 +103,17 @@ public class RefreshTask { @Override protected Boolean doInBackground(Void... voids) { List favorites = database.getAccessor().getAll(); + List modified = new ArrayList<>(); try { for (Favorite f: favorites) { - if (! f.isDeleted()) { - refresh(client, f); - updateTask.execute(f, database); + if (! f.isDeleted() && refresh(client, f)) { + modified.add(f); } } + if (modified.size() > 0) updateTask.execute(modified, database); return true; } catch (Exception e) { + if (modified.size() > 0) updateTask.execute(modified, database); return false; } } @@ -124,10 +131,13 @@ public class RefreshTask { * * @param client The client. * @param target The target. + * @return True if modified, false otherwise. */ - private void refresh(DefaultApi client, Favorite target) { + private boolean refresh(DefaultApi client, Favorite target) { + boolean modified = false; long now = System.currentTimeMillis(); if (now - target.getLocationTime() > ONE_DAY || isLocationIncomplete(target)) { + modified = true; City city = null; switch (target.getType()) { case CITY: @@ -159,6 +169,7 @@ public class RefreshTask { target.setWeatherTime(now); } } else if (now - target.getWeatherTime() > TWO_MINUTES || isWeatherIncomplete(target)) { + modified = true; City city = target.getCity(); if (city != null) { target.setForecast(client.getCityForecast(city.getId())); @@ -166,6 +177,7 @@ public class RefreshTask { target.setWeatherTime(now); } } + return modified; } /** diff --git a/android-app/src/main/java/com/mowesta/android/app/task/SyncTask.java b/android-app/src/main/java/com/mowesta/android/app/task/SyncTask.java index 09db1d83..19cc08c5 100644 --- a/android-app/src/main/java/com/mowesta/android/app/task/SyncTask.java +++ b/android-app/src/main/java/com/mowesta/android/app/task/SyncTask.java @@ -148,9 +148,14 @@ public class SyncTask { // apply all changes remotely client.setCurrentUserSettings(settings); // apply all changes locally - for (Favorite f: changedFavorites) database.getAccessor().update(f); - for (Favorite f: deletedFavorites) database.getAccessor().delete(f); - for (Favorite f: newFavorites) database.getAccessor().add(f); + database.runInTransaction(new Runnable() { + @Override + public void run() { + for (Favorite f: changedFavorites) database.getAccessor().update(f); + for (Favorite f: deletedFavorites) database.getAccessor().delete(f); + for (Favorite f: newFavorites) database.getAccessor().add(f); + } + }); return true; } catch (Exception e) { return false; diff --git a/android-app/src/main/res/drawable/ic_baseline_ac_unit_24.xml b/android-app/src/main/res/drawable/ic_baseline_ac_unit_24.xml new file mode 100644 index 00000000..45df675e --- /dev/null +++ b/android-app/src/main/res/drawable/ic_baseline_ac_unit_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/android-app/src/main/res/drawable/ic_baseline_delete_outline_24.xml b/android-app/src/main/res/drawable/ic_baseline_delete_outline_24.xml new file mode 100644 index 00000000..5fb767e4 --- /dev/null +++ b/android-app/src/main/res/drawable/ic_baseline_delete_outline_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/android-app/src/main/res/drawable/ic_baseline_menu_24.xml b/android-app/src/main/res/drawable/ic_baseline_menu_24.xml new file mode 100644 index 00000000..4350ba96 --- /dev/null +++ b/android-app/src/main/res/drawable/ic_baseline_menu_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/android-app/src/main/res/drawable/ic_baseline_storage_24.xml b/android-app/src/main/res/drawable/ic_baseline_storage_24.xml new file mode 100644 index 00000000..5ca45e33 --- /dev/null +++ b/android-app/src/main/res/drawable/ic_baseline_storage_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/android-app/src/main/res/drawable/ic_baseline_wifi_24.xml b/android-app/src/main/res/drawable/ic_baseline_wifi_24.xml new file mode 100644 index 00000000..b95c22ac --- /dev/null +++ b/android-app/src/main/res/drawable/ic_baseline_wifi_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/android-app/src/main/res/drawable/ic_celsius_white_24.xml b/android-app/src/main/res/drawable/ic_celsius_white_24.xml new file mode 100644 index 00000000..e31ed16e --- /dev/null +++ b/android-app/src/main/res/drawable/ic_celsius_white_24.xml @@ -0,0 +1,15 @@ + + + + diff --git a/android-app/src/main/res/drawable/ic_fahrenheit_white_24.xml b/android-app/src/main/res/drawable/ic_fahrenheit_white_24.xml new file mode 100644 index 00000000..13f9c3ff --- /dev/null +++ b/android-app/src/main/res/drawable/ic_fahrenheit_white_24.xml @@ -0,0 +1,15 @@ + + + + diff --git a/android-app/src/main/res/drawable/ic_view_headline_black_24dp.xml b/android-app/src/main/res/drawable/ic_view_headline_black_24dp.xml new file mode 100644 index 00000000..f9d849bf --- /dev/null +++ b/android-app/src/main/res/drawable/ic_view_headline_black_24dp.xml @@ -0,0 +1,10 @@ + + + diff --git a/android-app/src/main/res/drawable/ic_view_headline_white_24dp.xml b/android-app/src/main/res/drawable/ic_view_headline_white_24dp.xml new file mode 100644 index 00000000..c5bb81e9 --- /dev/null +++ b/android-app/src/main/res/drawable/ic_view_headline_white_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/android-app/src/main/res/drawable/selector_search.xml b/android-app/src/main/res/drawable/selector_search.xml deleted file mode 100644 index ff3e587b..00000000 --- a/android-app/src/main/res/drawable/selector_search.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - diff --git a/android-app/src/main/res/layout/dialog_customize.xml b/android-app/src/main/res/layout/dialog_customize.xml new file mode 100644 index 00000000..fad77851 --- /dev/null +++ b/android-app/src/main/res/layout/dialog_customize.xml @@ -0,0 +1,195 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/android-app/src/main/res/layout/dialog_measurement.xml b/android-app/src/main/res/layout/dialog_measurement.xml index 9c456165..1da21b49 100644 --- a/android-app/src/main/res/layout/dialog_measurement.xml +++ b/android-app/src/main/res/layout/dialog_measurement.xml @@ -11,14 +11,14 @@ name="closeListener" type="Runnable" /> - + android:layout_height="400dp"> + android:layout_width="match_parent"> - + diff --git a/android-app/src/main/res/layout/fragment_city_info.xml b/android-app/src/main/res/layout/fragment_city_info.xml index e55ec46c..db30120d 100644 --- a/android-app/src/main/res/layout/fragment_city_info.xml +++ b/android-app/src/main/res/layout/fragment_city_info.xml @@ -5,6 +5,7 @@ + @@ -21,7 +22,9 @@ layout="@layout/view_condition" app:model="@{condition}" /> - + diff --git a/android-app/src/main/res/layout/fragment_collection.xml b/android-app/src/main/res/layout/fragment_collection.xml index d19738e5..034c9c42 100644 --- a/android-app/src/main/res/layout/fragment_collection.xml +++ b/android-app/src/main/res/layout/fragment_collection.xml @@ -20,6 +20,7 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/android-app/src/main/res/layout/fragment_login.xml b/android-app/src/main/res/layout/fragment_login.xml index 17c37cef..b4431dd0 100644 --- a/android-app/src/main/res/layout/fragment_login.xml +++ b/android-app/src/main/res/layout/fragment_login.xml @@ -111,7 +111,9 @@ + android:text="@string/terms_button_accept" /> diff --git a/android-app/src/main/res/layout/view_city_detail.xml b/android-app/src/main/res/layout/view_city_detail.xml index 0c4848a7..877b9182 100644 --- a/android-app/src/main/res/layout/view_city_detail.xml +++ b/android-app/src/main/res/layout/view_city_detail.xml @@ -7,6 +7,9 @@ + - - - + + + + - - @@ -81,7 +80,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" - android:layout_marginTop="16dp"> + android:layout_marginTop="8dp"> + @@ -46,7 +47,7 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:orientation="vertical"> - - @@ -84,7 +85,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" - android:layout_marginTop="16dp"> + android:layout_marginTop="8dp"> + + + \ No newline at end of file diff --git a/android-app/src/main/res/menu/menu_place.xml b/android-app/src/main/res/menu/menu_place.xml index 5a1aa38d..d6c58ca5 100644 --- a/android-app/src/main/res/menu/menu_place.xml +++ b/android-app/src/main/res/menu/menu_place.xml @@ -4,17 +4,21 @@ diff --git a/android-app/src/main/res/menu/menu_unit.xml b/android-app/src/main/res/menu/menu_unit.xml new file mode 100644 index 00000000..e4b5ef77 --- /dev/null +++ b/android-app/src/main/res/menu/menu_unit.xml @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/android-app/src/main/res/values-de/strings.xml b/android-app/src/main/res/values-de/strings.xml index 562699c6..b583abaf 100644 --- a/android-app/src/main/res/values-de/strings.xml +++ b/android-app/src/main/res/values-de/strings.xml @@ -20,23 +20,21 @@ Falls Du ein MoWeSta Konto hast, können wir das Gerät damit verbinden. Dadurch kannst Du Deine Favoriten zwischen mehreren Geräten teilen und Du kannst von jeder MoWeSta App auf Deine Messungen zugreifen. Die letzte Anmeldung ist fehlgeschlagen. Falls Du Dein Passwort an einem anderen Gerät geändert hast, gib bitte Dein neues Passwort ein. Falls Du Dein Konto gelöscht hast, setze das Gerät über die Einstellungen zurück. - Login - Bitte logge dich ein. + Kontoname Passwort - Anmelden und Gerät einrichten - Anmelden und Gerät verbinden + Anmelden und einrichten + Anmelden und verbinden Passwort ändern Falls Du noch keins hast, kannst Du Dir hier ein neues Konto kostenlos anlegen. - Weiter ohne Anmeldung + Ohne Anmeldung einrichten Anmeldefehler, bitte prüfe Deine Zugangsdaten. Nochmal anmelden Einrichtung fehlgeschlagen. Hat Dein Gerät gerade kein Netz? Dein Gerät ist bereits mit einem Konto verbunden. - Bitte gib Deinen Nutzernamen ein. - Dein Nutzername ist zu kurz. - Dein Nutzername ist zu lang. - Dein Nutzername enthält ungültige Zeichen. + Dein Kontoname ist zu kurz. + Dein Kontoname ist zu lang. + Dein Kontoname enthält ungültige Zeichen. Bitte gib Dein Passwort ein. Dein Passwort ist zu kurz. @@ -51,6 +49,10 @@ Jetzt mitmachen Lass uns loslegen + Hier findest Du normalerweise Deine Lieblingsorte. Scheinbar hast Du aber noch keine Orte hinzugefügt. + Um Orte anzuzeigen, tippe auf das Lupensymbol oben rechts und gib die ersten Buchstaben des Ortsnamens ein. Tippe danach auf den gewünschten Ort in der Liste mit den Suchergebnissen. + Um einen Lieblingsort hinzuzufügen, lass Dir den Ort anzeigen und tippe einmal auf die Schaltfläche mit dem Herzsymbol oben rechts. Um einen Lieblingsort zu entfernen, tippe einfach nochmal auf das Herzsymbol. + Weitere Funktionen findest Du auch im Hauptmenü. Um das Hauptmenü zu öffnen, wische mit einem Finger von ganz links nach rechts über Deinen Bildschirm oder tippe auf das Menüsymbol oben links. @@ -59,7 +61,7 @@ Aktiviert die Erfassung von Messungen im Hintergrund. Deaktivierung beendet die Messung und Übertragung von Daten. Zurücksetzen Entfernt alle auf dem Gerät gespeicherten Daten und setzt die Geräteregistierung zurück. Nach der Ausführung muss das Gerät erneut registriert werden. - Möchtest Du wirklich alle Daten löschen? Dieser Vorgang ist unumkehrbar. + Möchtest Du wirklich ALLE Daten löschen? Das kannst Du nicht mehr rückgängig machen! Benachrichtigungen Anwendung Ermöglicht das Ein- und Ausblenden von Benachrichtigungen, die von der App erstellt werden. @@ -73,13 +75,21 @@ Version $code$ | $version$ @ $build$ Entwicklung - Geräteninfos + Geräteinfos Geräteschlüssel - MoWeSta Url + Dienstadresse Konfiguriert die URL der MoWeSta API, die vom HTTP Client der App verwendet wird. + Cache löschen + Löscht alle gecachten Standortdaten vom Gerät. + Der Cache wurde gelöscht. Du bist jetzt im Entwicklermodus. - Du bist jetzt wieder im normalen Modus. - + Du bist jetzt wieder im Anwendermodus. + Cache nutzen + Nutzung gecachter Standortdaten zur Standortbestimmung. + Gps nutzen + Nutzung des internen Gps-Empfängers zur Standortbestimmung. + Netzwerk nutzen + Nutzung der verfügbaren Netzwerkdaten zur Standortbestimmung. Ost Nord @@ -117,10 +127,10 @@ Schneeschauer Leichte Gewitter Starke Gewitter - Numerische Vorhersage (DWD ICON Global) - Numerische Vorhersage (DWD ICON Europa) - Numerische Vorhersage (DWD COSMO-D2 Europa) - Messung durch Wetterstation + DWD ICON Global + DWD ICON Europa + DWD COSMO-D2 Europa + DWD Wetterstation ICON Global ICON Europa D2 Europa @@ -142,8 +152,6 @@ Ortszeit Quelle - Zeit - Datum Temperatur Windgeschwindigkeit Wolkendichte @@ -151,8 +159,6 @@ Luftfeuchtigkeit Schneehöhe Niederschlag - Längengrad - Breitengrad Höhe Name Betreiber @@ -185,6 +191,7 @@ Tag Tageszeit Stunde + Wetterstation Gesamter Tag Morgens Mittags @@ -205,6 +212,9 @@ Bei Wikipedia anzeigen Aktualisieren Gerät hinzufügen + In Fahrenheit anzeigen + In Celsius anzeigen + Ansicht anpassen Fehler beim Laden der Daten. Neu\nladen diff --git a/android-app/src/main/res/values/colors.xml b/android-app/src/main/res/values/colors.xml index fbaea24f..e58619b7 100644 --- a/android-app/src/main/res/values/colors.xml +++ b/android-app/src/main/res/values/colors.xml @@ -4,9 +4,7 @@ #ffffff #00695C #A000695C - #439889 #003d33 #f9a825 - #ffd95a #eeeeee diff --git a/android-app/src/main/res/values/generic.xml b/android-app/src/main/res/values/generic.xml index 9ee43e79..d43275a1 100644 --- a/android-app/src/main/res/values/generic.xml +++ b/android-app/src/main/res/values/generic.xml @@ -28,6 +28,14 @@ false false false + true + true + true + true + true + true + true + diff --git a/android-app/src/main/res/values/strings.xml b/android-app/src/main/res/values/strings.xml index 9edcb078..8515cae3 100644 --- a/android-app/src/main/res/values/strings.xml +++ b/android-app/src/main/res/values/strings.xml @@ -21,7 +21,6 @@ If you have an MoWeSta account, we can link your device to it. This allows you to share your favorites across multiple devices and you can also access your measurements from any MoWeSta app. The last login attempt failed. If you have changed your password on another device, please enter your new password. If you have deleted your account, please reset the device via the app settings. Username - Please log in. Password Register with account Link with account @@ -33,7 +32,6 @@ Please check your internet connection. Your device is already connected with an account. - Please enter your login. Your login is too short. Your login is too long. Your login contains invalid characters. @@ -51,14 +49,19 @@ Participate now Let\'s get started - + Here you can view your favorite places, but apparently you did not add a place just yet. + To find a place, tap the magnifier icon in the upper right corner and enter the first few characters of its name. Then, tap on the place in the list of search results. + To add a favorite place, find the place and tap once on the button with the heart icon. To remove the place, tap the heart icon again. + You can find more features in the navigation menu. To open the menu, swipe your finger from the leftmost corner of your screen to the right or tap the menu icon in the upper left corner. + + Privacy Measurements Enables the service to perform measurements in the background. If disabled, the application will no longer perform and upload measurements. Reset Removes all app data stored on your device and unregisters the device. After deletion, you will have to re-register your device. - Do you really want remove all app data? This cannot be undone. + Do you really want remove ALL data? You cannot undo this later! Notifications Application Tap to control which app notifications are displayed in your notification area while the app is running. @@ -72,12 +75,22 @@ Version $code$ | $version$ @ $build$ Development - Device Infos - Device Token - MoWeSta Url - Sets the url to the MoWeSta api that is used by the app\'s HTTP client. - You are now in development mode. - You are now back in normal mode. + Device Info + Device Key + Service Address + Sets the URL to the MoWeSta API that is used by the app\'s HTTP client. + Clear Cache + Clears all cached location information from the device. + Location cache cleared. + You are now in developer mode. + You are now back in user mode. + Use Cache + Consider the local cache as a source of location information. + Use Gps + Consider the built-in GPS as a source of location information. + Use Net + Consider the network as a source of location information. + East North @@ -139,8 +152,6 @@ Local Time Source - Time - Date Temperature Wind Speed Cloud Coverage @@ -148,8 +159,6 @@ Humidity Snow Depth Precipitation - Longitude - Latitude Altitude Name @@ -184,6 +193,7 @@ Day Time Hour + Weather station Full day Morning Afternoon @@ -204,6 +214,9 @@ Open in Wikipedia Refresh Add device + Show as Fahrenheit + Show as Celsius + Customize view Failed to load data. Reload diff --git a/android-app/src/main/res/values/styles.xml b/android-app/src/main/res/values/styles.xml index 053c07bc..b652d456 100644 --- a/android-app/src/main/res/values/styles.xml +++ b/android-app/src/main/res/values/styles.xml @@ -1,30 +1,7 @@ - - - - - - - + diff --git a/android-app/src/main/res/values/themes.xml b/android-app/src/main/res/values/themes.xml index 7fb57f01..387fc138 100644 --- a/android-app/src/main/res/values/themes.xml +++ b/android-app/src/main/res/values/themes.xml @@ -40,8 +40,4 @@ @color/colorAccent - diff --git a/android-app/src/main/res/xml/settings.xml b/android-app/src/main/res/xml/settings.xml index 4702a567..539bedb1 100644 --- a/android-app/src/main/res/xml/settings.xml +++ b/android-app/src/main/res/xml/settings.xml @@ -3,7 +3,7 @@ - + + + + \ No newline at end of file diff --git a/android-sdk/build.gradle b/android-sdk/build.gradle index f3887e60..23c7a79b 100644 --- a/android-sdk/build.gradle +++ b/android-sdk/build.gradle @@ -27,7 +27,7 @@ android { dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) - implementation project(":android-feign") + api project(":android-feign") implementation "androidx.appcompat:appcompat:${versionAndroidXAppcompat}" diff --git a/android-sdk/src/main/java/com/mowesta/android/sdk/database/BufferDatabase.java b/android-sdk/src/main/java/com/mowesta/android/sdk/database/BufferDatabase.java index 11c88f40..be781736 100644 --- a/android-sdk/src/main/java/com/mowesta/android/sdk/database/BufferDatabase.java +++ b/android-sdk/src/main/java/com/mowesta/android/sdk/database/BufferDatabase.java @@ -115,6 +115,15 @@ public abstract class BufferDatabase extends RoomDatabase { return result; } + /** + * Clears all data from the database. + */ + @Transaction + public void clearAll() { + deleteData(); + deleteMeasurements(); + } + // methods used for testing /** @@ -187,6 +196,19 @@ public abstract class BufferDatabase extends RoomDatabase { */ @Query("select * from data where measurement=:measurement") abstract List getDataForMeasurement(long measurement); + + /** + * Deletes all measurements without their data. + */ + @Query("delete from measurement") + abstract void deleteMeasurements(); + + /** + * Deletes all data without their measurements. + */ + @Query("delete from data") + abstract void deleteData(); + } diff --git a/android-sdk/src/main/java/com/mowesta/android/sdk/task/ClearTask.java b/android-sdk/src/main/java/com/mowesta/android/sdk/task/ClearTask.java new file mode 100644 index 00000000..146f7f6d --- /dev/null +++ b/android-sdk/src/main/java/com/mowesta/android/sdk/task/ClearTask.java @@ -0,0 +1,90 @@ +package com.mowesta.android.sdk.task; + +import android.os.AsyncTask; +import android.util.Log; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.mowesta.android.sdk.SdkRepository; +import com.mowesta.android.sdk.database.LocationEntity; +import com.mowesta.android.sdk.database.NetworkEntity; + +import java.util.List; + +/** + * A task that clears the location cache and optionally the buffer database. + * + * @author Marcus + */ +public class ClearTask extends AsyncTask { + + /** + * An interface to synchronize with the task completion. + */ + public interface OnCompletionListener { + /** + * Called to signal the task completion. + */ + void onCompletion(); + } + + /** + * The log tag. + */ + private static final String TAG = "ClearTask"; + + /** + * The repository to get hold of the database. + */ + @NonNull private SdkRepository repository; + + /** + * The completion listener. + */ + @Nullable private OnCompletionListener completionListener; + + /** + * Flag to control whether to delete the measurements as well. + */ + private boolean measurements; + + /** + * Creates a new task to clear the cache and optionally the measurements. + * + * @param repository The repository. + * @param withMeasurements Flag to control whether the measurements should also be wiped. + * @param completionListener The optional completion listener. + */ + public ClearTask(@NonNull SdkRepository repository, boolean withMeasurements, @Nullable OnCompletionListener completionListener) { + this.repository = repository; + this.completionListener = completionListener; + this.measurements = withMeasurements; + } + + /** + * Executes the task on the thread pool executor. + */ + public void execute() { + executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); + } + + + @Override + protected Void doInBackground(Void... voids) { + Log.d(TAG, "Clearing the cache database."); + repository.getCacheDatabase().getAccessor().clearAll(); + if (measurements) { + Log.d(TAG, "Clearing the buffer database."); + repository.getBufferDatabase().getAccessor().clearAll(); + } + return null; + } + + @Override + protected void onPostExecute(Void aVoid) { + super.onPostExecute(aVoid); + if (completionListener != null) + completionListener.onCompletion(); + } +} diff --git a/common-api/src/main/java/com/mowesta/api/device/IDeviceService.java b/common-api/src/main/java/com/mowesta/api/device/IDeviceService.java index ef8369a5..673d4a88 100644 --- a/common-api/src/main/java/com/mowesta/api/device/IDeviceService.java +++ b/common-api/src/main/java/com/mowesta/api/device/IDeviceService.java @@ -80,7 +80,7 @@ public interface IDeviceService { }) @PermitAll @RolesAllowed({Roles.DEVICE, Roles.USER}) - Response setCurrentDeviceUser(@NotNull @Valid Device device); + Response setCurrentDeviceUser(@ApiParam(value = "The device data.", required = true)@NotNull @Valid Device device); /** * Returns the current device. diff --git a/mowesta.cdr b/mowesta.cdr index f1dca3b5..7305bfe8 100644 Binary files a/mowesta.cdr and b/mowesta.cdr differ