diff --git a/android-app/src/main/java/com/mowesta/android/app/ApiObservableRegistry.java b/android-app/src/main/java/com/mowesta/android/app/ApiObservableRegistry.java index 7e668bca..f30d6e07 100644 --- a/android-app/src/main/java/com/mowesta/android/app/ApiObservableRegistry.java +++ b/android-app/src/main/java/com/mowesta/android/app/ApiObservableRegistry.java @@ -67,10 +67,19 @@ public class ApiObservableRegistry { @Override protected List map(Integer v) { final UserWithPassword userWithPassword = app.getRepository().user.getValue(); + int pageOffset=0; + int pageSize=20; if (userWithPassword == null || userWithPassword.getUser() == null || userWithPassword.getUser().getLogin() == null ||userWithPassword.getPassword() == null) { return Collections.emptyList(); } - return app.getApiClient(userWithPassword.getUser().getLogin(), userWithPassword.getPassword()).getCurrentUserDevices(0, 20).getElements(); + List deviceList = app.getApiClient(userWithPassword.getUser().getLogin(), userWithPassword.getPassword()).getCurrentUserDevices(pageOffset, pageSize).getElements(); + while(deviceList.size()==pageSize){ + List newdeviceList = app.getApiClient(userWithPassword.getUser().getLogin(), userWithPassword.getPassword()).getCurrentUserDevices(pageOffset+20, pageSize+20).getElements(); + for (Device device : newdeviceList){ + deviceList.add(device); + } + } + return deviceList; } }; @@ -78,11 +87,22 @@ public class ApiObservableRegistry { @Override protected List map (Long id) { final UserWithPassword userWithPassword = app.getRepository().user.getValue(); + int pageOffset=0; + int pageSize=20; if (userWithPassword == null || userWithPassword.getUser() == null || userWithPassword.getUser().getLogin() == null ||userWithPassword.getPassword() == null) { return Collections.emptyList(); } - return app.getApiClient(userWithPassword.getUser().getLogin(), userWithPassword.getPassword()).getDeviceMeasurements(id, System.currentTimeMillis() - TimeUnit.HOURS.toMillis(24 * 7), TimeUnit.HOURS.toMillis(24 * 7), 0, 20) - .getElements(); + + List measurementList = app.getApiClient(userWithPassword.getUser().getLogin(), userWithPassword.getPassword()).getDeviceMeasurements(id, System.currentTimeMillis() - TimeUnit.HOURS.toMillis(24 *3 ), TimeUnit.HOURS.toMillis(24*3 ), pageOffset, pageSize) + .getElements(); + while(measurementList.size()==pageSize){ + List newmeasurementList = app.getApiClient(userWithPassword.getUser().getLogin(), userWithPassword.getPassword()).getDeviceMeasurements(id, System.currentTimeMillis() - TimeUnit.HOURS.toMillis(24*3 ), TimeUnit.HOURS.toMillis(24*3 ), pageOffset+20, pageSize+20) + .getElements(); + for (Measurement measurement: newmeasurementList){ + measurementList.add(measurement); + } + } + return measurementList; } }; diff --git a/android-app/src/main/java/com/mowesta/android/app/MainActivity.java b/android-app/src/main/java/com/mowesta/android/app/MainActivity.java index e280931e..3aeb4f79 100644 --- a/android-app/src/main/java/com/mowesta/android/app/MainActivity.java +++ b/android-app/src/main/java/com/mowesta/android/app/MainActivity.java @@ -12,6 +12,8 @@ import android.util.Log; import android.view.MenuItem; import android.view.View; import android.widget.TextView; + +import androidx.activity.OnBackPressedCallback; import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBarDrawerToggle; import androidx.appcompat.app.AppCompatActivity; @@ -30,9 +32,12 @@ import com.google.android.material.navigation.NavigationView; import com.mowesta.android.app.fragment.ChooseWeatherFragment; import com.mowesta.android.app.fragment.LoginCreateFragment; import com.mowesta.android.app.fragment.LoginUpdateFragment; +import com.mowesta.android.app.fragment.LoginUserFragment; import com.mowesta.android.app.fragment.SettingsFragment; +import com.mowesta.android.app.fragment.ShowDeviceWeatherFragment; import com.mowesta.android.app.fragment.ShowDevicesFragment; import com.mowesta.android.app.fragment.ShowHomeFragment; +import com.mowesta.android.app.fragment.ShowWeatherFragment; import com.mowesta.android.app.fragment.TermsFragment; import com.mowesta.android.app.model.UserWithPassword; import com.mowesta.android.app.repository.IValueListener; @@ -81,13 +86,22 @@ public class MainActivity extends AppCompatActivity implements SettingsFragment. @Override public void onValueChanged(Value source, UserWithPassword oldValue, UserWithPassword newValue) { DeviceHandle handle = source.getRepository().deviceHandle.getValue(); + MenuItem logout = navigationView.getMenu().findItem(R.id.menu_logout); + MenuItem devices = navigationView.getMenu().findItem(menu_devices); + if(newValue!=null){ + devices.setVisible(true); + } else devices.setVisible(false); + + logout.setTitle("Login"); if (newValue != null) { usernameView.setText(newValue.getUser().getName()); + logout.setTitle("Logout"); } else if (handle != null && handle.getUser() == null) { usernameView.setText(R.string.nav_user_none); } else { usernameView.setText(R.string.nav_user_error); } + } }; @@ -97,12 +111,11 @@ public class MainActivity extends AppCompatActivity implements SettingsFragment. private IValueListener deviceListener = new IValueListener() { @Override public void onValueChanged(Value source, DeviceHandle oldValue, DeviceHandle newValue) { - if (newValue != null) { - MenuItem connect = navigationView.getMenu().findItem(R.id.menu_connect); - MenuItem logout = navigationView.getMenu().findItem(R.id.menu_logout); + MenuItem connect = navigationView.getMenu().findItem(R.id.menu_connect); + /*if (newValue != null) { connect.setVisible(newValue.getUser() == null); - logout.setVisible(app.getRepository().user.getValue()!= null); - } + }*/ + connect.setVisible(false); } }; @@ -135,6 +148,7 @@ public class MainActivity extends AppCompatActivity implements SettingsFragment. */ private GoogleApiClient googleApiClient; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -153,8 +167,12 @@ public class MainActivity extends AppCompatActivity implements SettingsFragment. createNavigationDrawer(); checkPermissions(); new UpdateUserTask(app, null).execute(); + + } + + public void settingsrequest() { googleApiClient = new GoogleApiClient.Builder(getApplicationContext()) .addApi(LocationServices.API) .build(); googleApiClient.connect(); @@ -252,10 +270,10 @@ public class MainActivity extends AppCompatActivity implements SettingsFragment. showSettings(); break; case R.id.menu_connect: - showLogin(); + //showLogin(); break; case R.id.menu_logout: - // logout(); + logout(); break; } closeDrawerIfNeeded(); @@ -395,6 +413,7 @@ public class MainActivity extends AppCompatActivity implements SettingsFragment. private void showSettings() { closeViews(TAG_SLAVE); showSlave(new SettingsFragment()); + setTitle(R.string.settings); } private void showLogin() { @@ -413,16 +432,32 @@ public class MainActivity extends AppCompatActivity implements SettingsFragment. ft.commit(); } + @Override public void onBackPressed() { Fragment f = getSupportFragmentManager().findFragmentById(R.id.container); + FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); if (f instanceof TermsFragment) { if (((TermsFragment)f).canGoBack()) { ((TermsFragment) f).goBack(); return; } + } else if(f instanceof ShowHomeFragment){ + ft.remove(f); + ft.replace(R.id.container, new ShowHomeFragment()); + ft.commit(); + } else if(f instanceof ShowDeviceWeatherFragment){ + ft.replace(R.id.container, new ShowDevicesFragment()).commit(); + }else if(f instanceof ShowWeatherFragment){ + ft.replace(R.id.container, new ShowWeatherFragment()); + } + else { + ft.remove(f); + ft.replace(R.id.container, new ShowHomeFragment()); + ft.commit(); } super.onBackPressed(); + } private void closeViews(String tag) { @@ -442,7 +477,10 @@ public class MainActivity extends AppCompatActivity implements SettingsFragment. private void logout(){ Log.d(TAG, "logout the user"); app.getRepository().user.setValue(null); - showLogin(); + app.getRepository().deviceHandle.setValue(null); + FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + ft.replace(R.id.container, new LoginUserFragment(R.string.login, R.string.login_text, R.string.login)); + ft.commit(); } diff --git a/android-app/src/main/java/com/mowesta/android/app/MeasureService.java b/android-app/src/main/java/com/mowesta/android/app/MeasureService.java index 162b2e3d..531a91d4 100644 --- a/android-app/src/main/java/com/mowesta/android/app/MeasureService.java +++ b/android-app/src/main/java/com/mowesta/android/app/MeasureService.java @@ -555,7 +555,7 @@ public class MeasureService extends Service implements SensorEventListener { data.put("BATTERY_TEMPERATURE", String.valueOf(calculatedtemperature)); - if (sensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE) != null) { + if (sensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE) != null && millibarsOfPressure!=0) { data.put("SENSOR_PRESSURE", String.valueOf(millibarsOfPressure)); } @@ -569,15 +569,22 @@ public class MeasureService extends Service implements SensorEventListener { if (hasDeviceHandle()) { device = app.getRepository().deviceHandle.getValue(); - + Log.d(TAG, "DeviceID"+device.getId()); measurement.setDevice(device.getId()); } + measurement.setVersion((long) BuildConfig.VERSION_CODE); data.put("BATTERY_CHARGING", String.valueOf(batterycharging)); - data.put("CPU_TEMPERATURE", String.valueOf(getCpuTemperature())); - data.put("CPU_FREQUENCY", String.valueOf(getCpuFrequency())); + if(getCpuFrequency()!=null) { + data.put("CPU_FREQUENCY", String.valueOf(getCpuFrequency())); + } + if(getCpuTemperature()!=null) { + data.put("CPU_TEMPERATURE", String.valueOf(getCpuTemperature())); + } + + boolean isScreenOn = powerManager.isScreenOn(); data.put("SCREEN_ENABLED", String.valueOf(isScreenOn)); diff --git a/android-app/src/main/java/com/mowesta/android/app/fragment/AbstractLoginFragment.java b/android-app/src/main/java/com/mowesta/android/app/fragment/AbstractLoginFragment.java index c04f9faa..acfc00c6 100644 --- a/android-app/src/main/java/com/mowesta/android/app/fragment/AbstractLoginFragment.java +++ b/android-app/src/main/java/com/mowesta/android/app/fragment/AbstractLoginFragment.java @@ -9,6 +9,7 @@ import android.text.method.PasswordTransformationMethod; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.WindowManager; import android.widget.Button; import android.widget.EditText; import android.widget.ImageButton; @@ -96,6 +97,7 @@ public abstract class AbstractLoginFragment extends AbstractFragment { builder.create().show(); } else { onLogin(username, password); + view.clearFocus(); } } }); @@ -123,6 +125,7 @@ public abstract class AbstractLoginFragment extends AbstractFragment { return view; } + public abstract void onLogin(String username, String password); public abstract void onContinue(); diff --git a/android-app/src/main/java/com/mowesta/android/app/fragment/LoginCreateFragment.java b/android-app/src/main/java/com/mowesta/android/app/fragment/LoginCreateFragment.java index 9613fdb2..7e564203 100644 --- a/android-app/src/main/java/com/mowesta/android/app/fragment/LoginCreateFragment.java +++ b/android-app/src/main/java/com/mowesta/android/app/fragment/LoginCreateFragment.java @@ -10,6 +10,8 @@ import com.mowesta.android.feign.model.DeviceHandle; import android.content.Intent; +import androidx.fragment.app.FragmentTransaction; + /** * Fragment that handles the login. * diff --git a/android-app/src/main/java/com/mowesta/android/app/fragment/LoginUserFragment.java b/android-app/src/main/java/com/mowesta/android/app/fragment/LoginUserFragment.java new file mode 100644 index 00000000..6b4cda53 --- /dev/null +++ b/android-app/src/main/java/com/mowesta/android/app/fragment/LoginUserFragment.java @@ -0,0 +1,75 @@ +package com.mowesta.android.app.fragment; + + +import android.content.Intent; + +import androidx.fragment.app.FragmentTransaction; + +import com.mowesta.android.app.MainActivity; +import com.mowesta.android.app.R; +import com.mowesta.android.app.model.UserWithPassword; +import com.mowesta.android.app.repository.IValueListener; +import com.mowesta.android.app.repository.Repository; +import com.mowesta.android.app.repository.Value; +import com.mowesta.android.app.task.CreateDeviceTask; +import com.mowesta.android.app.task.LoginUserTask; +import com.mowesta.android.feign.model.DeviceHandle; + +public class LoginUserFragment extends AbstractLoginFragment { + + /** + * The listener that keeps track of the device creation. + */ + private IValueListener userWithPasswordIValueListener = new IValueListener() { + @Override + public void onValueChanged(Value source, UserWithPassword oldValue, UserWithPassword newValue) { + if (newValue != null) { + FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); + ft.replace(R.id.container, new ShowHomeFragment()); + ft.commit(); + } + } + }; + + + /** + * Creates a login fragment with the specified title resource, + * explanation resource and login button resource. + * + * @param title The string resource with the title. + * @param explanation The string resource with the explanation. + * @param login The string resource with the login button. + */ + public LoginUserFragment(int title, int explanation, int login) { + super(title, explanation, login); + } + + @Override + public void onLogin(String username, String password) { + LoginUserTask loginUserTask = new LoginUserTask(getApp(), username, password); + loginUserTask.execute(); + //CreateDeviceTask task = new CreateDeviceTask(getApp(), username, password); + //task.execute(); + } + + @Override + public void onContinue() { + FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); + ft.replace(R.id.container, new ShowHomeFragment()); + ft.commit(); + } + + @Override + public void onResume() { + super.onResume(); + Repository repository = getRepository(); + repository.user.addValueListener(userWithPasswordIValueListener, true); + } + + @Override + public void onPause() { + Repository repository = getRepository(); + repository.user.removeValueListener(userWithPasswordIValueListener); + super.onPause(); + } +} diff --git a/android-app/src/main/java/com/mowesta/android/app/fragment/ShowDeviceWeatherFragment.java b/android-app/src/main/java/com/mowesta/android/app/fragment/ShowDeviceWeatherFragment.java index 0b415b33..8fa0ce1a 100644 --- a/android-app/src/main/java/com/mowesta/android/app/fragment/ShowDeviceWeatherFragment.java +++ b/android-app/src/main/java/com/mowesta/android/app/fragment/ShowDeviceWeatherFragment.java @@ -1,6 +1,7 @@ package com.mowesta.android.app.fragment; import android.annotation.SuppressLint; +import android.app.AlertDialog; import android.content.Context; import android.graphics.drawable.AnimatedStateListDrawable; import android.graphics.drawable.Drawable; @@ -55,6 +56,8 @@ public class ShowDeviceWeatherFragment extends AbstractObservableFragment { app = getApp(); final View view = inflater.inflate(R.layout.fragment_show_deviceweather, container, false); + setLoadingSpinner(view.findViewById(R.id.loadingSpinnerShowDevicesWeather)); + final RecyclerView recyclerView = view.findViewById(R.id.deviceWeather); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); List measurementList = new ArrayList<>(); @@ -62,7 +65,7 @@ public class ShowDeviceWeatherFragment extends AbstractObservableFragment { recyclerView.setAdapter(devicesAdapter); - addDisposable("getDeviceMeasurements", getApiObservableRegistry() + addDisposableWithLoading("getDeviceMeasurements", getApiObservableRegistry() .getDeviceMeasurements.getObservable(device.getId(), true).subscribe(measurements -> { measurementList.clear(); @@ -111,24 +114,35 @@ public class ShowDeviceWeatherFragment extends AbstractObservableFragment { public void onBindViewHolder(DevicesAdapter.ViewHolder viewHolder, int position) { // Get the data model based on position Measurement condition = measurementList.get(position); - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("DD.MM.yyyy \n HH:mm"); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd.MM.yyyy \n HH:mm"); DecimalFormat decimalFormat = new DecimalFormat("#0.0"); // Set item views based on your views and data model viewHolder.deviceModel.setText(device.getModel()+ "\n" + condition.getDevice()); if(condition.getTime()!=null) viewHolder.date.setText(simpleDateFormat.format(new Date(condition.getTime()))); - if(condition.getData().get("BATTERY_TEMPERATURE")!=null && device.getOs()!= Device.OsEnum.ARDUINO) viewHolder.deviceTemperature.setText(decimalFormat.format(getTemperatureOfDevice(Double.parseDouble(condition.getData().get("BATTERY_TEMPERATURE"))))+"°C"); - if(condition.getData().get("SENSOR_TEMPERATURE")!=null && device.getOs()== Device.OsEnum.ARDUINO) viewHolder.deviceTemperature.setText(decimalFormat.format(Double.parseDouble(condition.getData().get("SENSOR_TEMPERATURE")))+"°C"); - if(condition.getData().get("SENSOR_HUMIDITY")!=null) viewHolder.deviceHumidity.setText(decimalFormat.format(Integer.parseInt(condition.getData().get("SENSOR_HUMIDITY")))+"%"); - if(condition.getData().get("SENSOR_PRESSURE")!=null) viewHolder.devicePressure.setText(decimalFormat.format(Double.parseDouble(condition.getData().get("SENSOR_PRESSURE")))+"mbar"); - if(device.getOs()!= Device.OsEnum.ARDUINO){ - Drawable smartphone = getResources().getDrawable(R.drawable.ic_androidsmartphone); - viewHolder.deviceImage.setImageDrawable(smartphone); - } else { + if(device.getOs()== Device.OsEnum.ARDUINO){ Drawable weatherstation = getResources().getDrawable(R.drawable.ic_weatherstation_dp); viewHolder.deviceImage.setImageDrawable(weatherstation); + if(condition.getTemperature()!=null) viewHolder.deviceTemperature.setText(decimalFormat.format(condition.getTemperature())+"°C"); + if(condition.getHumidity()!=null) viewHolder.deviceHumidity.setText(decimalFormat.format(condition.getHumidity())+"%"); + if(condition.getPressure()!=null) viewHolder.devicePressure.setText(decimalFormat.format(condition.getPressure())+"hPA"); + + + } else { + Drawable smartphone = getResources().getDrawable(R.drawable.ic_androidsmartphone); + viewHolder.deviceImage.setImageDrawable(smartphone); + if(condition.getData().get("BATTERY_TEMPERATURE")!=null) viewHolder.deviceTemperature.setText(decimalFormat.format(Double.parseDouble(condition.getData().get("BATTERY_TEMPERATURE")))+"°C"); + if(condition.getData().get("SENSOR_TEMPERATURE")!=null) viewHolder.deviceTemperature.setText(decimalFormat.format(Double.parseDouble(condition.getData().get("SENSOR_TEMPERATURE")))+"°C"); + if(condition.getData().get("SENSOR_HUMIDITY")!=null) viewHolder.deviceHumidity.setText(decimalFormat.format(Integer.parseInt(condition.getData().get("SENSOR_HUMIDITY")))+"%"); + if(condition.getData().get("SENSOR_PRESSURE")!=null) viewHolder.devicePressure.setText(decimalFormat.format(Double.parseDouble(condition.getData().get("SENSOR_PRESSURE")))+"hPA"); + + /*if(condition.getTemperature()!=null) viewHolder.deviceTemperature.setText(decimalFormat.format(condition.getTemperature())+"°C"); + if(condition.getHumidity()!=null) viewHolder.deviceHumidity.setText(decimalFormat.format(condition.getHumidity())+"%"); + if(condition.getPressure()!=null) viewHolder.devicePressure.setText(decimalFormat.format(condition.getPressure())+"hPA");*/ } + + viewHolder.itemView.setOnClickListener(view -> showInformations(condition)); } // Returns the total count of items in the list @@ -161,16 +175,60 @@ public class ShowDeviceWeatherFragment extends AbstractObservableFragment { deviceModel = itemView.findViewById(R.id.deviceModel); deviceTemperature = itemView.findViewById(R.id.deviceTemperature); devicePressure = itemView.findViewById(R.id.devicePressure); - deviceHumidity = itemView.findViewById(R.id.devicePressure); + deviceHumidity = itemView.findViewById(R.id.deviceHumidity); date = itemView.findViewById(R.id.date); deviceImage = itemView.findViewById(R.id.deviceimage); } } } + private void showInformations(Measurement measurement){ - public double getTemperatureOfDevice(double batterytemperature){ - return (0.4776 + 0.8765*batterytemperature); + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setTitle(R.string.detail); + builder.setMessage(getDetails(measurement)); + builder.setPositiveButton(R.string.close, (dialog,id)->{ + }); + + AlertDialog showDeviceInfo = builder.create(); + showDeviceInfo.show(); } + private String getDetails(Measurement measurement){ + DecimalFormat decimalFormat = new DecimalFormat("#0"); + String details=""; + + if(measurement.getCoordinate().getLatitude()!=null && measurement.getCoordinate().getLongitude()!=null ){ + details+="Longitude: " + measurement.getCoordinate().getLongitude() + + "\nLatitude: " + measurement.getCoordinate().getLatitude(); + } + if(measurement.getData().get("CPU_FREQUENCY")!=null){ + details+="\nCPU-Frequency: " + (decimalFormat.format(Double.parseDouble(measurement.getData().get("CPU_FREQUENCY"))/1000)) +" MHz"; + } + if(measurement.getData().get("CPU_TEMPERATURE")!=null){ + details+="\nCPU-Temperature: " + measurement.getData().get("CPU_TEMPERATURE") + " °C"; + } + if( measurement.getData().get("BATTERY_VOLTAGE")!= null){ + details+= "\nBattery-Voltage: " + measurement.getData().get("BATTERY_VOLTAGE")+" Volt"; + } + if(measurement.getData().get("SOLAR_VOLTAGE")!=null){ + details+= "\nSolar-Voltage: " + measurement.getData().get("SOLAR_VOLTAGE") +" Volt"; + } + if(measurement.getData().get("BATTERY_TEMPERATURE")!=null) { + details+="\nBattery-Temperature: "+ decimalFormat.format(Double.parseDouble(measurement.getData().get("BATTERY_TEMPERATURE")))+"°C"; + } + if(measurement.getData().get("SENSOR_TEMPERATURE")!=null) { + details+="\nAmbient Temperature: "+decimalFormat.format(Double.parseDouble(measurement.getData().get("SENSOR_TEMPERATURE")))+"°C"; + } + if(measurement.getData().get("SENSOR_HUMIDITY")!=null) { + details+="\nHumidity: "+decimalFormat.format(Integer.parseInt(measurement.getData().get("SENSOR_HUMIDITY")))+"%"; + } + if(measurement.getData().get("SENSOR_PRESSURE")!=null) { + details+="\nPressure: "+decimalFormat.format(Double.parseDouble(measurement.getData().get("SENSOR_PRESSURE")))+"hPA"; + } + + return details; + } + + } diff --git a/android-app/src/main/java/com/mowesta/android/app/fragment/ShowDevicesFragment.java b/android-app/src/main/java/com/mowesta/android/app/fragment/ShowDevicesFragment.java index 048c5ef4..e35ebe39 100644 --- a/android-app/src/main/java/com/mowesta/android/app/fragment/ShowDevicesFragment.java +++ b/android-app/src/main/java/com/mowesta/android/app/fragment/ShowDevicesFragment.java @@ -94,9 +94,7 @@ public class ShowDevicesFragment extends AbstractPositionObservableFragment { List deviceList = new ArrayList<>(); final ShowDevicesFragment.DevicesAdapter devicesAdapter = new ShowDevicesFragment.DevicesAdapter(deviceList); recyclerView.setAdapter(devicesAdapter); - - Log.d(TAG, "onCreateView: your device" + app.getRepository().deviceHandle.getValue().getId()); - + addDisposableWithLoading("getCurrentUserDevices", getApiObservableRegistry() .getCurrentUserDevices.getObservable(0, true).subscribe(devices -> { diff --git a/android-app/src/main/java/com/mowesta/android/app/fragment/ShowWeatherFragment.java b/android-app/src/main/java/com/mowesta/android/app/fragment/ShowWeatherFragment.java index 8b027276..38a8b58c 100644 --- a/android-app/src/main/java/com/mowesta/android/app/fragment/ShowWeatherFragment.java +++ b/android-app/src/main/java/com/mowesta/android/app/fragment/ShowWeatherFragment.java @@ -10,12 +10,14 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; +import android.widget.Toast; import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.mowesta.android.app.R; +import com.mowesta.android.app.model.UserWithPassword; import com.mowesta.android.feign.model.*; import io.reactivex.Observable; @@ -175,6 +177,11 @@ public class ShowWeatherFragment extends AbstractObservableFragment { } private void toggleFavorite(View v) { + final UserWithPassword userWithPassword = getRepository().user.getValue(); + if (userWithPassword == null || userWithPassword.getUser() == null || userWithPassword.getUser().getLogin() == null || userWithPassword.getPassword() == null) { + Toast.makeText(requireContext(), getText(R.string.favorites_no_account), Toast.LENGTH_LONG).show(); + return; + } addDisposableWithLoading("getSettings", getApiObservableRegistry() .getSettings .getObservable(0L, true) diff --git a/android-app/src/main/java/com/mowesta/android/app/fragment/TermsFragment.java b/android-app/src/main/java/com/mowesta/android/app/fragment/TermsFragment.java index 2bc72344..48501214 100644 --- a/android-app/src/main/java/com/mowesta/android/app/fragment/TermsFragment.java +++ b/android-app/src/main/java/com/mowesta/android/app/fragment/TermsFragment.java @@ -80,7 +80,7 @@ public class TermsFragment extends AbstractFragment { return true; } }); - webView.loadUrl("file:///android_asset/terms.html"); + webView.loadUrl("https://www.mowesta.com/terms-of-service/"); View acceptView = view.findViewById(R.id.fragment_terms_accept); acceptView.setVisibility(getRepository().isTermsAccepted()?View.GONE:View.VISIBLE); final Button continueButton = (Button) view.findViewById(R.id.start_button_continue); diff --git a/android-app/src/main/java/com/mowesta/android/app/task/LoginUserTask.java b/android-app/src/main/java/com/mowesta/android/app/task/LoginUserTask.java new file mode 100644 index 00000000..e8eb4c73 --- /dev/null +++ b/android-app/src/main/java/com/mowesta/android/app/task/LoginUserTask.java @@ -0,0 +1,110 @@ +package com.mowesta.android.app.task; + + +import android.util.Log; +import com.mowesta.android.app.MowestaApp; +import com.mowesta.android.app.R; +import com.mowesta.android.app.model.UserWithPassword; +import com.mowesta.android.app.repository.AsyncError; +import com.mowesta.android.app.repository.AsyncInteraction; +import com.mowesta.android.feign.model.User; + +import java.net.HttpURLConnection; + +import feign.FeignException; + + +public class LoginUserTask extends AbstractApiTask { + + /** + * The log tag for the task. + */ + private static final String TAG = "LoginUserTask"; + + /** + * The error code for network errors. + */ + public static final int ERROR_NETWORK = 1; + /** + * The error code for login errors. + */ + public static final int ERROR_LOGIN = 2; + /** + * The username. + */ + private String username; + /** + * The password. + */ + private String password; + /** + * A flag that determines whether there is a user. + */ + private boolean authenticated; + + /** + * The User. + */ + private User user; + + /** + * Creates a new LoginUserTask. + * + * @param app The app. + * @param username The username. + * @param password The password. + */ + public LoginUserTask(MowestaApp app, String username, String password) { + super(app); + this.username = username; + this.password = password; + authenticated = (username != null && password != null); + if (authenticated) { + apiClient = app.getApiClient(username, password); + } else { + apiClient = app.getApiClient(); + } + } + + /** + * Executes the task. + */ + public void execute() { + super.execute(new Void[0]); + } + + + + @Override + protected AsyncError doInBackground(Void... voids) { + if (authenticated) { + try { + user = apiClient.getCurrentUser(); + Log.d(TAG, "Login success for " + username + " with id " + (user==null?"":user.getId()) + "."); + } catch (FeignException e) { + Log.d(TAG, "Login failure: " + e.status() + " " + e.getMessage()); + return getError(e); + } + } + return null; + } + + @Override + protected void onPostExecute(AsyncError asyncError) { + + UserWithPassword userWithPassword = new UserWithPassword(); + + userWithPassword.setUser(user); + userWithPassword.setPassword(password); + app.getRepository().user.setValue(userWithPassword); + app.getRepository().deviceHandle.setValue(null); + } + + private AsyncError getError(FeignException e) { + if (e.status() == HttpURLConnection.HTTP_FORBIDDEN) { + return new AsyncError(ERROR_LOGIN, R.string.login_failed_msg); + } else { + return new AsyncError(ERROR_NETWORK, R.string.login_device_failed); + } + } +} diff --git a/android-app/src/main/res/layout/device_weather_layout.xml b/android-app/src/main/res/layout/device_weather_layout.xml index 4ffc2df8..0b37d1f5 100644 --- a/android-app/src/main/res/layout/device_weather_layout.xml +++ b/android-app/src/main/res/layout/device_weather_layout.xml @@ -28,10 +28,10 @@ android:id="@+id/deviceModel" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="Modell" + android:text="-" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@+id/deviceTemperature" - app:layout_constraintHorizontal_bias="0.088" + app:layout_constraintHorizontal_bias="0.04" app:layout_constraintStart_toEndOf="@+id/deviceimage" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.513" /> @@ -40,7 +40,7 @@ android:id="@+id/deviceTemperature" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="0°C" + android:text="-" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/deviceimage" @@ -50,7 +50,7 @@ android:id="@+id/devicePressure" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="0mbar" + android:text="-" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@+id/deviceHumidity" app:layout_constraintStart_toEndOf="@+id/deviceTemperature" @@ -60,9 +60,9 @@ android:id="@+id/deviceHumidity" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginEnd="8dp" - android:layout_marginRight="8dp" - android:text="0%" + android:layout_marginEnd="16dp" + android:layout_marginRight="16dp" + android:text="-" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" @@ -72,7 +72,7 @@ android:id="@+id/date" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="Date" + android:text="-" android:textSize="10sp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@+id/deviceTemperature" diff --git a/android-app/src/main/res/layout/fragment_show_deviceweather.xml b/android-app/src/main/res/layout/fragment_show_deviceweather.xml index 88d43895..cc612364 100644 --- a/android-app/src/main/res/layout/fragment_show_deviceweather.xml +++ b/android-app/src/main/res/layout/fragment_show_deviceweather.xml @@ -6,6 +6,22 @@ tools:context="com.mowesta.android.app.fragment.ShowDeviceWeatherFragment" android:id="@+id/linearLayout"> + + + android:layout_height="match_parent" + android:fitsSystemWindows="true"> + + + + + + + + + app:layout_constraintVertical_bias="0.16" /> @@ -95,7 +148,7 @@ app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/weather" - app:layout_constraintVertical_bias="0.009"> + app:layout_constraintVertical_bias="0.0"> + app:layout_constraintVertical_bias="0.084" /> - \ No newline at end of file + + \ No newline at end of file diff --git a/android-app/src/main/res/layout/weather_prediction_layout.xml b/android-app/src/main/res/layout/weather_prediction_layout.xml index cf178541..ef86614b 100644 --- a/android-app/src/main/res/layout/weather_prediction_layout.xml +++ b/android-app/src/main/res/layout/weather_prediction_layout.xml @@ -7,26 +7,30 @@ android:id="@+id/linearLayout2"> + app:layout_constraintBottom_toTopOf="@+id/viHorizontalLine" + app:autoSizeTextType="uniform" + /> + android:gravity="center_horizontal" + android:singleLine="true"/> @@ -142,7 +146,7 @@ android:layout_height="wrap_content" android:id="@+id/teRain" app:layout_constraintBottom_toBottomOf="@+id/tePressure" - app:layout_constraintEnd_toStartOf="@+id/imWeatherIcon" + app:layout_constraintEnd_toEndOf="@+id/imWeatherIcon" app:layout_constraintStart_toStartOf="@+id/imTemperature" tools:text="3cm"/> @@ -190,6 +194,7 @@ Benachrichtigungen des Messungsdiensts. \?°C + Du musst dich in einem Account einloggen um Favoriten speichern zu können. Navigationsmenü öffnen @@ -26,6 +27,7 @@ Nutzung ohne Konto Verbindungsfehler Ausloggen + Einstellungen Geräteeinrichtung @@ -33,6 +35,8 @@ Hallo! Damit wir Deinen Standort vor unbefugtem Zugriff schützen können, müssen wir Dein Gerät einrichten. Falls Du ein Konto hast, können wir das Gerät damit verbinden. Dadurch kannst Du über einen Webbrowser auf Deine Daten auch ohne App zugreifen. Falls Du ein Konto hast, können wir Dein Gerät damit verbinden. Dadurch kannst Du über einen Webbrowser auf den Gerätestandort und den Standortverlauf jederzeit zugreifen. Login + Login + Bitte logge dich ein. Passwort Anmelden und Gerät einrichten Anmelden und Gerät verbinden @@ -92,15 +96,22 @@ Welches Gerät möchten Sie hinzufügen? Geräte Es gibt Ihr Gerät schon! + Schließen + Details Willkommen zu MoWeSta! Ihrer mobilen Wetterstation - Diese App ermöglicht es Ihnen das Wetter Ihrer Stadt sich anzeigen zulassen. - Zudem können Sie sich Ihre Lieblingsstädte als Favoriten abspeichern und so immer direkt auf Ihre Stadt zugreifen! - Mit MoWeSta ist es möglich mit Ihrem Android Gerät Wetterdaten zu sammeln. - Sie können dazu unter dem Navigationsmenü, unter dem Punkt Geräte ihr Android Gerät hinzufügen. - Des Weiteren ist es dort auch möglich Ihre eigenen Wetterstation von MoWeSta hinzuzufügen. - Anschließend können Sie sich Ihre Messungen, die Sie mit Ihren Geräte durchgeführt haben, dort anzeigen lassen. + Im Menüpunkt Wetter ist es Ihnen möglich das Wetter Ihrer Stadt sich anzeigen zulassen. + Zudem können Sie sich Ihre Lieblingsstädte als Favoriten abspeichern indem Sie das Herz aktivieren und so immer direkt auf Ihre Stadt zugreifen! + Um Ihre Lieblingsstadt als Favorit speichern zu können, müssen sie registriert und eingeloggt sein. + Mit MoWeSta ist es außerdem möglich mit Ihrem Android Gerät oder einer Wetterstation von MoWeSta Wetterdaten zu sammeln. + Sie können dazu im Navigationsmenü, unter dem Punkt Geräte ihr Android Gerät oder Ihre eigene Wetterstation von MoWeSta mit dem "+" hinzuzufügen. + Anschließend können Sie sich Ihre Messungen, die Sie mit Ihren Geräte durchgeführt haben, dort anzeigen lassen. Sie können zudem weitere Details Ihrer Messung + sich anzeigen lassen, wenn Sie auf die jeweilige Messung klicken. Um Ihre Geräte sehen und hinzufügen zu können müssen Sie registriert sein! + Mit Ihrer Hilfe können, durch das Sammeln von weiteren Wetterdaten über Ihr Smartphone oder Ihrer Wetterstation + von MoWeSta, zukünftig die Wettervorhersagen verbessert werden! Somit wird es möglich sein mit Ihren gesammelten Daten + präzisere Vorhersagen zu erreichen. + Helfen Sie uns! diff --git a/android-app/src/main/res/values/strings.xml b/android-app/src/main/res/values/strings.xml index aec0b552..58c41dc7 100644 --- a/android-app/src/main/res/values/strings.xml +++ b/android-app/src/main/res/values/strings.xml @@ -16,6 +16,7 @@ Notifications of the measurement service. \?°C + You need to be logged into an account to save favorites. Open navigation @@ -35,6 +36,8 @@ Hi there! To protect your location, we must register your device. If you have an account, we can link your device to it, so you can access its location through a web browser. If you have an account, we can link your device to it. This allows you to access the device location and its location history through a web browser at any time. Username + Login + Please login. Password Register with account Link with account @@ -45,6 +48,7 @@ Please check your internet connection. Your device is already connected with an account. Show or hide password + Settings @@ -95,15 +99,23 @@ Which device do you want to add? Devices Your device already exists! + Close + Details Welcome to MoWeSta! Your mobile Weatherstation - This app allows you to view the weather of your city. - You can also save your favorite cities as favorites and always have direct access to your city! - With MoWeSta it is possible to collect weather data with your Android device. - You can add your Android device in the navigation menu under Devices. - Furthermore, it is also possible to add your own MoWeSta weather station. - You can then have your measurements that you carried out with your devices displayed there. - To see and add your devices you have to be registered! + In the menu item Weather it is possible for you to display the weather of your city. +In addition, you can save your favorite cities as favorites, compensate the heart and so always directly to your city base! +In order to have your favorite city as a favorite, they have to take care of themselves and be. + With MoWeSta it is also possible to collect weather data with your Android device or a MoWeSta weather station. +You can add your Android device or your own MoWeSta weather station with the "+" in the navigation menu under Devices. +You can then have your measurements that you carried out with your devices displayed there. + You can also see more details of your measurement +can be displayed when you click on the respective measurement. +To see and add your devices you have to be registered! + With your help, you can collect additional weather data using your smartphone or your weather station +MoWeSta will improve the weather forecasts in the future! So it will be possible with your collected data +to achieve more precise predictions. + Help us!