kopia lustrzana https://github.com/SP8EBC/MeteoSystem
favourites update handler moved to main
rodzic
31135df0c9
commit
660390391a
|
@ -5,6 +5,8 @@ import android.content.Context;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
import android.os.StrictMode;
|
import android.os.StrictMode;
|
||||||
import android.os.strictmode.Violation;
|
import android.os.strictmode.Violation;
|
||||||
|
|
||||||
|
@ -22,11 +24,13 @@ import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import cc.pogoda.mobile.meteosystem.activity.handler.MainActImageButtonFavouritesClickEvent;
|
import cc.pogoda.mobile.meteosystem.activity.handler.MainActImageButtonFavouritesClickEvent;
|
||||||
|
import cc.pogoda.mobile.meteosystem.activity.updater.FavouritesStationDetailsUpdater;
|
||||||
import cc.pogoda.mobile.meteosystem.config.AppConfiguration;
|
import cc.pogoda.mobile.meteosystem.config.AppConfiguration;
|
||||||
import cc.pogoda.mobile.meteosystem.dao.AllStationsDao;
|
import cc.pogoda.mobile.meteosystem.dao.AllStationsDao;
|
||||||
import cc.pogoda.mobile.meteosystem.file.ConfigurationFile;
|
import cc.pogoda.mobile.meteosystem.file.ConfigurationFile;
|
||||||
import cc.pogoda.mobile.meteosystem.file.FavouritiesFile;
|
import cc.pogoda.mobile.meteosystem.file.FavouritiesFile;
|
||||||
import cc.pogoda.mobile.meteosystem.file.FileNames;
|
import cc.pogoda.mobile.meteosystem.file.FileNames;
|
||||||
|
import cc.pogoda.mobile.meteosystem.type.ParceableFavsCallReason;
|
||||||
import cc.pogoda.mobile.meteosystem.type.ParceableStationsList;
|
import cc.pogoda.mobile.meteosystem.type.ParceableStationsList;
|
||||||
import cc.pogoda.mobile.meteosystem.type.WeatherStation;
|
import cc.pogoda.mobile.meteosystem.type.WeatherStation;
|
||||||
import cc.pogoda.mobile.meteosystem.type.WeatherStationListEvent;
|
import cc.pogoda.mobile.meteosystem.type.WeatherStationListEvent;
|
||||||
|
@ -57,6 +61,10 @@ public class Main extends Application {
|
||||||
|
|
||||||
private List<WeatherStation> favs;
|
private List<WeatherStation> favs;
|
||||||
|
|
||||||
|
private Handler handler = null;
|
||||||
|
|
||||||
|
private FavouritesStationDetailsUpdater favsUpdater = null;
|
||||||
|
|
||||||
public File getDirectory() {
|
public File getDirectory() {
|
||||||
return directory;
|
return directory;
|
||||||
}
|
}
|
||||||
|
@ -99,6 +107,10 @@ public class Main extends Application {
|
||||||
|
|
||||||
confFile.restoreFromFile();
|
confFile.restoreFromFile();
|
||||||
|
|
||||||
|
handler = new Handler(Looper.getMainLooper());
|
||||||
|
|
||||||
|
favsUpdater = new FavouritesStationDetailsUpdater(handler);
|
||||||
|
|
||||||
fileNames = new FileNames(ctx);
|
fileNames = new FileNames(ctx);
|
||||||
|
|
||||||
favouritiesFile = new FavouritiesFile(fileNames);
|
favouritiesFile = new FavouritiesFile(fileNames);
|
||||||
|
@ -214,4 +226,43 @@ public class Main extends Application {
|
||||||
//Toast.makeText(this, intentServiceResult.getResultValue(), Toast.LENGTH_SHORT).show();
|
//Toast.makeText(this, intentServiceResult.getResultValue(), Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean listOfAllStationsReady() {
|
||||||
|
if (listOfAllStations != null && listOfAllStations.size() > 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean listOfFavsReady() {
|
||||||
|
if (favs != null && favs.size() > 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createAndStartUpdater() {
|
||||||
|
|
||||||
|
// check if there is previous instance of updater
|
||||||
|
if (favsUpdater != null && favsUpdater.isEnabled()) {
|
||||||
|
stopUpdater();
|
||||||
|
}
|
||||||
|
|
||||||
|
handler = new Handler(Looper.getMainLooper());
|
||||||
|
favsUpdater = new FavouritesStationDetailsUpdater(handler);
|
||||||
|
|
||||||
|
handler.postDelayed(favsUpdater, 300);
|
||||||
|
favsUpdater.setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopUpdater() {
|
||||||
|
if (reason.equals(ParceableFavsCallReason.Reason.FAVOURITES)) {
|
||||||
|
handler.removeCallbacks(favsUpdater);
|
||||||
|
favsUpdater.setEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import cc.pogoda.mobile.meteosystem.Main;
|
||||||
import cc.pogoda.mobile.meteosystem.R;
|
import cc.pogoda.mobile.meteosystem.R;
|
||||||
import cc.pogoda.mobile.meteosystem.adapter.WeatherStationRecyclerViewAdapter;
|
import cc.pogoda.mobile.meteosystem.adapter.WeatherStationRecyclerViewAdapter;
|
||||||
import cc.pogoda.mobile.meteosystem.type.ParceableFavsCallReason;
|
import cc.pogoda.mobile.meteosystem.type.ParceableFavsCallReason;
|
||||||
import cc.pogoda.mobile.meteosystem.type.ParceableStationsList;
|
|
||||||
import cc.pogoda.mobile.meteosystem.type.WeatherStation;
|
import cc.pogoda.mobile.meteosystem.type.WeatherStation;
|
||||||
import cc.pogoda.mobile.meteosystem.type.web.Summary;
|
import cc.pogoda.mobile.meteosystem.type.web.Summary;
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,6 @@ public class MainActivity extends AppCompatActivity {
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
//recreateListOfFavs();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -147,4 +146,22 @@ public class MainActivity extends AppCompatActivity {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean listOfAllStationsReady() {
|
||||||
|
if (main != null) {
|
||||||
|
return main.listOfAllStationsReady();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean listOfAllFavsReady() {
|
||||||
|
if (main != null) {
|
||||||
|
return main.listOfFavsReady();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -6,15 +6,16 @@ import android.view.View;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
import cc.pogoda.mobile.meteosystem.activity.AllStationsActivity;
|
import cc.pogoda.mobile.meteosystem.activity.AllStationsActivity;
|
||||||
|
import cc.pogoda.mobile.meteosystem.activity.MainActivity;
|
||||||
import cc.pogoda.mobile.meteosystem.type.ParceableStationsList;
|
import cc.pogoda.mobile.meteosystem.type.ParceableStationsList;
|
||||||
|
|
||||||
public class MainActImageButtonAllStationsClickEvent implements View.OnClickListener {
|
public class MainActImageButtonAllStationsClickEvent implements View.OnClickListener {
|
||||||
|
|
||||||
AppCompatActivity parent;
|
MainActivity parent;
|
||||||
|
|
||||||
Intent intent;
|
Intent intent;
|
||||||
|
|
||||||
public MainActImageButtonAllStationsClickEvent(AppCompatActivity parent) {
|
public MainActImageButtonAllStationsClickEvent(MainActivity parent) {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
|
|
||||||
intent = new Intent(this.parent, AllStationsActivity.class);
|
intent = new Intent(this.parent, AllStationsActivity.class);
|
||||||
|
@ -24,7 +25,9 @@ public class MainActImageButtonAllStationsClickEvent implements View.OnClickList
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
launchActivity();
|
if (parent.listOfAllStationsReady()) {
|
||||||
|
launchActivity();
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,16 +6,17 @@ import android.view.View;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
import cc.pogoda.mobile.meteosystem.activity.FavouritesActivity;
|
import cc.pogoda.mobile.meteosystem.activity.FavouritesActivity;
|
||||||
|
import cc.pogoda.mobile.meteosystem.activity.MainActivity;
|
||||||
import cc.pogoda.mobile.meteosystem.type.ParceableFavsCallReason;
|
import cc.pogoda.mobile.meteosystem.type.ParceableFavsCallReason;
|
||||||
import cc.pogoda.mobile.meteosystem.type.ParceableStationsList;
|
import cc.pogoda.mobile.meteosystem.type.ParceableStationsList;
|
||||||
|
|
||||||
public class MainActImageButtonFavouritesClickEvent implements View.OnClickListener{
|
public class MainActImageButtonFavouritesClickEvent implements View.OnClickListener{
|
||||||
|
|
||||||
AppCompatActivity parent;
|
MainActivity parent;
|
||||||
|
|
||||||
Intent intent;
|
Intent intent;
|
||||||
|
|
||||||
public MainActImageButtonFavouritesClickEvent(AppCompatActivity parent) {
|
public MainActImageButtonFavouritesClickEvent(MainActivity parent) {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
|
|
||||||
intent = new Intent(this.parent, FavouritesActivity.class);
|
intent = new Intent(this.parent, FavouritesActivity.class);
|
||||||
|
@ -26,7 +27,9 @@ public class MainActImageButtonFavouritesClickEvent implements View.OnClickListe
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
|
if (parent.listOfAllFavsReady()) {
|
||||||
|
parent.startActivity(intent);
|
||||||
|
|
||||||
parent.startActivity(intent);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,6 @@ public class WeatherStationRecyclerViewAdapter extends RecyclerView.Adapter<AllS
|
||||||
|
|
||||||
FavouritesStationDetailsUpdater favsUpdater = null;
|
FavouritesStationDetailsUpdater favsUpdater = null;
|
||||||
|
|
||||||
Handler handler = null;
|
|
||||||
|
|
||||||
public WeatherStationRecyclerViewAdapter(List<WeatherStation> stations, AppCompatActivity parentActivity, ParceableFavsCallReason.Reason callReason) {
|
public WeatherStationRecyclerViewAdapter(List<WeatherStation> stations, AppCompatActivity parentActivity, ParceableFavsCallReason.Reason callReason) {
|
||||||
this.stations = stations;
|
this.stations = stations;
|
||||||
|
@ -49,30 +48,6 @@ public class WeatherStationRecyclerViewAdapter extends RecyclerView.Adapter<AllS
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createAndStartUpdater() {
|
|
||||||
|
|
||||||
if (reason.equals(ParceableFavsCallReason.Reason.FAVOURITES)) {
|
|
||||||
|
|
||||||
// check if there is previous instance of updater
|
|
||||||
if (favsUpdater != null && favsUpdater.isEnabled()) {
|
|
||||||
stopUpdater();
|
|
||||||
}
|
|
||||||
|
|
||||||
handler = new Handler();
|
|
||||||
favsUpdater = new FavouritesStationDetailsUpdater(handler);
|
|
||||||
|
|
||||||
handler.postDelayed(favsUpdater, 300);
|
|
||||||
favsUpdater.setEnabled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopUpdater() {
|
|
||||||
if (reason.equals(ParceableFavsCallReason.Reason.FAVOURITES)) {
|
|
||||||
handler.removeCallbacks(favsUpdater);
|
|
||||||
favsUpdater.setEnabled(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public AllStationsActRecyclerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public AllStationsActRecyclerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
|
|
@ -1,27 +1,32 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:orientation="horizontal"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/linearLayout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content">
|
||||||
android:paddingTop="10dp"
|
|
||||||
android:paddingBottom="10dp"
|
|
||||||
>
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/station_name"
|
android:id="@+id/station_name"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_marginStart="16dp"
|
||||||
android:fontFamily="@font/alegreya_sans_sc_medium"
|
android:fontFamily="@font/alegreya_sans_sc_medium"
|
||||||
android:textSize="20sp" />
|
android:textSize="20sp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/station_button"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/station_button"
|
android:id="@+id/station_button"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
android:paddingLeft="16dp"
|
android:paddingLeft="16dp"
|
||||||
android:paddingRight="16dp"
|
android:paddingRight="16dp"
|
||||||
android:textSize="10sp"
|
android:textSize="10sp"
|
||||||
/>
|
app:layout_constraintBaseline_toBaselineOf="@+id/station_name"
|
||||||
</LinearLayout>
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/station_name" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -22,7 +22,7 @@
|
||||||
<string name="station_not_comm">Uwaga! Ta stacja nie wysyła żadnych danych dłużej niż od 2 godzin</string>
|
<string name="station_not_comm">Uwaga! Ta stacja nie wysyła żadnych danych dłużej niż od 2 godzin</string>
|
||||||
<string name="station_disabled">Uwaga! Stacja została tymczasowo wyłączona bądź nie pracuje od dłuższego czasu</string>
|
<string name="station_disabled">Uwaga! Stacja została tymczasowo wyłączona bądź nie pracuje od dłuższego czasu</string>
|
||||||
<string name="archive_data">Dane Archiwalne</string>
|
<string name="archive_data">Dane Archiwalne</string>
|
||||||
<string name="export_from">Exportuj do</string>
|
<string name="export_from">Exportuj od</string>
|
||||||
<string name="time_scale">Skala czasu</string>
|
<string name="time_scale">Skala czasu</string>
|
||||||
<string name="mean_value">Średnia</string>
|
<string name="mean_value">Średnia</string>
|
||||||
<string name="max_value">Wartość maksymalna</string>
|
<string name="max_value">Wartość maksymalna</string>
|
||||||
|
|
Ładowanie…
Reference in New Issue