kopia lustrzana https://github.com/SP8EBC/MeteoSystem
daily
rodzic
2002ecc016
commit
f469aeaea5
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -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<String>() {
|
||||
@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;
|
||||
}
|
||||
}
|
|
@ -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<String> mText;
|
||||
private MutableLiveData<String> stationName;
|
||||
private MutableLiveData<String> lastMeasuremenetTime;
|
||||
private MutableLiveData<String> currentValue;
|
||||
private MutableLiveData<String> twoHoursValue;
|
||||
private MutableLiveData<String> fourHoursValue;
|
||||
private MutableLiveData<String> sixHoursValue;
|
||||
private MutableLiveData<String> 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<String> 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<String> getStationName() {
|
||||
return stationName;
|
||||
}
|
||||
|
||||
public LiveData<String> getLastMeasuremenetTime() {
|
||||
return lastMeasuremenetTime;
|
||||
}
|
||||
|
||||
public LiveData<String> getCurrentValue() {
|
||||
return currentValue;
|
||||
}
|
||||
|
||||
public LiveData<String> getTwoHoursValue() {
|
||||
return twoHoursValue;
|
||||
}
|
||||
|
||||
public LiveData<String> getFourHoursValue() {
|
||||
return fourHoursValue;
|
||||
}
|
||||
|
||||
public LiveData<String> getSixHoursValue() {
|
||||
return sixHoursValue;
|
||||
}
|
||||
|
||||
public LiveData<String> getEightHoursValue() {
|
||||
return eightHoursValue;
|
||||
}
|
||||
}
|
|
@ -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">
|
||||
|
||||
<com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
android:id="@+id/nav_view"
|
||||
|
@ -28,6 +27,7 @@
|
|||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:navGraph="@navigation/mobile_navigation" />
|
||||
app:navGraph="@navigation/mobile_navigation"
|
||||
android:paddingBottom="?attr/actionBarSize"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -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"
|
||||
|
|
Ładowanie…
Reference in New Issue