diff --git a/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/TrendActivity.java b/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/TrendActivity.java index 358754c..b8cdc7f 100644 --- a/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/TrendActivity.java +++ b/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/TrendActivity.java @@ -17,6 +17,7 @@ public class TrendActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + String stationName = (String)getIntent().getExtras().get("station"); setContentView(R.layout.activity_trend); BottomNavigationView navView = findViewById(R.id.nav_view); // Passing each menu ID as a set of Ids because each @@ -27,6 +28,7 @@ public class TrendActivity extends AppCompatActivity { NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment); NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration); NavigationUI.setupWithNavController(navView, navController); + } } \ No newline at end of file diff --git a/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/pressure/PressureTrendFragment.java b/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/pressure/PressureTrendFragment.java index 2b4d042..0aaad3e 100644 --- a/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/pressure/PressureTrendFragment.java +++ b/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/pressure/PressureTrendFragment.java @@ -18,18 +18,62 @@ public class PressureTrendFragment extends Fragment { private PressureTrendViewModel pressureTrendViewModel; + TextView stationName = null; + TextView lastDataTimestamp = null; + TextView currentValue = null; + TextView twoHours = null; + TextView fourHours = null; + TextView sixHours = null; + TextView eightHours = null; + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { pressureTrendViewModel = new ViewModelProvider(this).get(PressureTrendViewModel.class); - View root = inflater.inflate(R.layout.fragment_pressure, container, false); - //final TextView textView = root.findViewById(R.id.text_notifications); - pressureTrendViewModel.getText().observe(getViewLifecycleOwner(), new Observer() { - @Override - public void onChanged(@Nullable String s) { + - } + // inflate the main layout of the fragment + View root = inflater.inflate(R.layout.fragment_pressure, container, false); + + // load all elements from the layout + stationName = root.findViewById(R.id.textViewPressureTrendStationName); + lastDataTimestamp = root.findViewById(R.id.textViewPressureTrendLastTimestampValue); + currentValue = root.findViewById(R.id.textViewPressureTrendCurrentValue); + twoHours = root.findViewById(R.id.textViewPressureTrendTwoHoursValue); + fourHours = root.findViewById(R.id.textViewPressureTrendTwoHoursValue); + sixHours = root.findViewById(R.id.textViewPressureTrendSixHoursValue); + eightHours = root.findViewById(R.id.textViewPressureTrendEightHoursVal); + + pressureTrendViewModel.getStationName().observe(getViewLifecycleOwner(), s -> { + stationName.setText(s); }); + + pressureTrendViewModel.getLastMeasuremenetTime().observe(getViewLifecycleOwner(), s -> { + lastDataTimestamp.setText(s); + }); + + pressureTrendViewModel.getCurrentValue().observe(getViewLifecycleOwner(), s -> { + currentValue.setText(s); + }); + + pressureTrendViewModel.getTwoHoursValue().observe(getViewLifecycleOwner(), s -> { + twoHours.setText(s); + }); + + pressureTrendViewModel.getFourHoursValue().observe(getViewLifecycleOwner(), s -> { + fourHours.setText(s); + }); + + pressureTrendViewModel.getSixHoursValue().observe(getViewLifecycleOwner(), s -> { + sixHours.setText(s); + }); + + pressureTrendViewModel.getEightHoursValue().observe(getViewLifecycleOwner(), s -> { + eightHours.setText(s); + }); + + pressureTrendViewModel.updateData(); + return root; } } \ No newline at end of file diff --git a/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/pressure/PressureTrendViewModel.java b/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/pressure/PressureTrendViewModel.java index 6a544b6..0ce30fb 100644 --- a/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/pressure/PressureTrendViewModel.java +++ b/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/pressure/PressureTrendViewModel.java @@ -4,16 +4,80 @@ import androidx.lifecycle.LiveData; import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.ViewModel; +import org.threeten.bp.LocalDateTime; +import org.threeten.bp.ZoneId; +import org.threeten.bp.ZoneOffset; +import org.threeten.bp.ZonedDateTime; +import org.threeten.bp.format.DateTimeFormatter; +import org.threeten.bp.format.FormatStyle; + +import cc.pogoda.mobile.pogodacc.dao.TrendDao; +import cc.pogoda.mobile.pogodacc.type.web.Trend; + public class PressureTrendViewModel extends ViewModel { - private MutableLiveData mText; + private MutableLiveData stationName; + private MutableLiveData lastMeasuremenetTime; + private MutableLiveData currentValue; + private MutableLiveData twoHoursValue; + private MutableLiveData fourHoursValue; + private MutableLiveData sixHoursValue; + private MutableLiveData eightHoursValue; + + private TrendDao trendDao; + + private String station = ""; public PressureTrendViewModel() { - mText = new MutableLiveData<>(); - mText.setValue("This is notifications fragment"); + stationName = new MutableLiveData<>(); + lastMeasuremenetTime = new MutableLiveData<>(); + currentValue = new MutableLiveData<>(); + twoHoursValue = new MutableLiveData<>(); + fourHoursValue = new MutableLiveData<>(); + sixHoursValue = new MutableLiveData<>(); + eightHoursValue = new MutableLiveData<>(); + + trendDao = new TrendDao(); } - public LiveData getText() { - return mText; + public void updateData() { + Trend trend = trendDao.getStationTrend(station); + + // format the time and date according to current locale + String dt = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.SHORT).format(LocalDateTime.ofEpochSecond(trend.last_timestamp, 0, ZoneOffset.UTC).atOffset(ZoneOffset.UTC).atZoneSameInstant(ZoneOffset.systemDefault())); + + lastMeasuremenetTime.postValue(dt); + } + + public void setStation(String station) { + this.station = station; + } + + public LiveData getStationName() { + return stationName; + } + + public LiveData getLastMeasuremenetTime() { + return lastMeasuremenetTime; + } + + public LiveData getCurrentValue() { + return currentValue; + } + + public LiveData getTwoHoursValue() { + return twoHoursValue; + } + + public LiveData getFourHoursValue() { + return fourHoursValue; + } + + public LiveData getSixHoursValue() { + return sixHoursValue; + } + + public LiveData getEightHoursValue() { + return eightHoursValue; } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_trend.xml b/app/src/main/res/layout/activity_trend.xml index 38c0aa8..611f4b2 100644 --- a/app/src/main/res/layout/activity_trend.xml +++ b/app/src/main/res/layout/activity_trend.xml @@ -3,8 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/container" android:layout_width="match_parent" - android:layout_height="match_parent" - android:paddingTop="?attr/actionBarSize"> + android:layout_height="match_parent"> + app:navGraph="@navigation/mobile_navigation" + android:paddingBottom="?attr/actionBarSize"/> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_pressure.xml b/app/src/main/res/layout/fragment_pressure.xml index 9765f0e..f2730ef 100644 --- a/app/src/main/res/layout/fragment_pressure.xml +++ b/app/src/main/res/layout/fragment_pressure.xml @@ -78,7 +78,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="168dp" - android:layout_marginTop="8dp" android:fontFamily="sans-serif-black" android:text="TextView" android:textSize="18sp" @@ -90,7 +89,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="18dp" - android:layout_marginTop="32dp" + android:layout_marginTop="8dp" android:text="@string/h4_value" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/textViewPressureTrendTwoHoursValue" /> @@ -100,7 +99,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="168dp" - android:layout_marginTop="8dp" android:fontFamily="sans-serif-black" android:text="TextView" android:textSize="18sp" @@ -112,7 +110,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="17dp" - android:layout_marginTop="32dp" + android:layout_marginTop="8dp" android:text="@string/h6_value" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/textViewPressureTrendFourHoursValue" /> @@ -122,7 +120,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="168dp" - android:layout_marginTop="8dp" android:fontFamily="sans-serif-black" android:text="TextView" android:textSize="18sp" @@ -134,7 +131,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="18dp" - android:layout_marginTop="32dp" + android:layout_marginTop="8dp" android:text="@string/h8_value" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/textViewPressureTrendSixHoursValue" /> @@ -144,7 +141,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="168dp" - android:layout_marginTop="8dp" android:fontFamily="sans-serif-black" android:text="TextView" android:textSize="18sp"