diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
new file mode 100644
index 0000000..b933e0e
--- /dev/null
+++ b/.idea/deploymentTargetDropDown.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index e103088..30dc261 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -6,38 +6,43 @@
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/java/cc/pogoda/mobile/meteosystem/Main.java b/app/src/main/java/cc/pogoda/mobile/meteosystem/Main.java
index 297bebd..cde412e 100644
--- a/app/src/main/java/cc/pogoda/mobile/meteosystem/Main.java
+++ b/app/src/main/java/cc/pogoda/mobile/meteosystem/Main.java
@@ -2,7 +2,9 @@ package cc.pogoda.mobile.meteosystem;
import android.app.Application;
import android.content.Context;
+import android.content.Intent;
+import androidx.annotation.NonNull;
import com.jakewharton.threetenabp.AndroidThreeTen;
import org.greenrobot.eventbus.EventBus;
@@ -17,15 +19,19 @@ import java.util.HashMap;
import java.util.List;
import cc.pogoda.mobile.meteosystem.activity.updater.FavouritesStationSummaryUpdater;
+
import cc.pogoda.mobile.meteosystem.dao.AllStationsDao;
import cc.pogoda.mobile.meteosystem.file.ConfigurationFile;
import cc.pogoda.mobile.meteosystem.file.FavouritiesFile;
import cc.pogoda.mobile.meteosystem.file.FileNames;
+import cc.pogoda.mobile.meteosystem.service.GetAllStationsService;
+import cc.pogoda.mobile.meteosystem.type.AllStationsReceivedEvent;
import cc.pogoda.mobile.meteosystem.type.WeatherStation;
import cc.pogoda.mobile.meteosystem.type.WeatherStationListEvent;
import cc.pogoda.mobile.meteosystem.type.web.Summary;
public class Main extends Application {
+ private static String TAG = Main.class.getSimpleName();
private File directory;
@@ -121,10 +127,9 @@ public class Main extends Application {
favouritiesFile = new FavouritiesFile(fileNames);
- // download all stations from API
- listOfAllStations = new AllStationsDao().getAllStations();
-
- Logger.info("[Main][onCreate][listOfAllStations.size() = " + listOfAllStations.size() + "]");
+ // Download all stations from API in background via JobIntentService. Results are send
+ //back with Broadcast receiver.
+ startGetAllStationsService();
// recreate list of favorites
recreateListOfFavs();
@@ -145,8 +150,20 @@ public class Main extends Application {
// }
}
+
+ @Override
+ public void onTerminate() {
+ super.onTerminate();
+ EventBus.getDefault().unregister(this);
+ }
+
private void recreateListOfFavs() {
+ if(listOfAllStations == null) {
+ Logger.info("[recreateListOfFavs]listOfAllStations=null]");
+ return;
+ }
+
// check if this is a first call after application start
if (favs == null) {
favs = favouritiesFile.loadFavourites();
@@ -239,22 +256,19 @@ public class Main extends Application {
}
+ @Subscribe(threadMode = ThreadMode.BACKGROUND)
+ public void allStationsEventHandler(@NonNull AllStationsReceivedEvent event) {
+ this.listOfAllStations = event.getStations();
+ recreateListOfFavs();
+ }
+
public boolean listOfAllStationsReady() {
- if (listOfAllStations != null && listOfAllStations.size() > 0) {
- return true;
- }
- else {
- return false;
- }
+ return listOfAllStations != null && listOfAllStations.size() > 0;
}
public boolean listOfFavsReady() {
- if (favs != null/* && favs.size() > 0*/) {
- return true;
- }
- else {
- return false;
- }
+ /* && favs.size() > 0*/
+ return favs != null;
}
public boolean checkIsOnFavsList(String _system_name) {
@@ -270,4 +284,10 @@ public class Main extends Application {
return out;
}
+
+ public void startGetAllStationsService () {
+ Intent mIntent = new Intent(this, GetAllStationsService.class);
+ GetAllStationsService.enqueueWork(this, mIntent);
+ }
+
}
diff --git a/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/AllStationsActivity.java b/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/AllStationsActivity.java
index 25d8bcf..e91a1e2 100644
--- a/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/AllStationsActivity.java
+++ b/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/AllStationsActivity.java
@@ -1,48 +1,85 @@
package cc.pogoda.mobile.meteosystem.activity;
+import android.os.Bundle;
+import android.widget.Toast;
+
+import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
+import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
+
+import org.greenrobot.eventbus.EventBus;
+import org.greenrobot.eventbus.Subscribe;
+import org.greenrobot.eventbus.ThreadMode;
+
+import java.util.LinkedList;
+import java.util.List;
import cc.pogoda.mobile.meteosystem.Main;
import cc.pogoda.mobile.meteosystem.R;
import cc.pogoda.mobile.meteosystem.adapter.WeatherStationRecyclerViewAdapter;
+import cc.pogoda.mobile.meteosystem.type.AllStationsReceivedEvent;
import cc.pogoda.mobile.meteosystem.type.ParceableFavsCallReason;
+import cc.pogoda.mobile.meteosystem.type.StartStationsRefreshEvent;
import cc.pogoda.mobile.meteosystem.type.WeatherStation;
-import cc.pogoda.mobile.meteosystem.type.web.Summary;
-
-import android.os.Bundle;
-
-import java.util.List;
public class AllStationsActivity extends AppCompatActivity {
- RecyclerView recyclerViewAllStations;
-
- Summary test;
-
- private List allStationsList;
-
- Main main;
+ private final List allStationsList = new LinkedList<>();
+ private SwipeRefreshLayout refreshLayout;
+ private WeatherStationRecyclerViewAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+
setContentView(R.layout.activity_all_stations);
- main = (Main) getApplication();
-
- //allStationsList = getIntent().getParcelableExtra("all_stations");
- allStationsList = main.getListOfAllStations();
-
- recyclerViewAllStations = findViewById(R.id.recyclerViewAllStations);
-
- WeatherStationRecyclerViewAdapter adapter = null;
-
- adapter = new WeatherStationRecyclerViewAdapter(allStationsList, this, ParceableFavsCallReason.Reason.ALL_STATIONS);
+ refreshLayout = findViewById(R.id.refreshAllStationsView);
+ refreshLayout.setOnRefreshListener(
+ () -> ((Main) getApplication()).startGetAllStationsService()
+ );
+ RecyclerView recyclerViewAllStations = findViewById(R.id.recyclerViewAllStations);
+ adapter = new WeatherStationRecyclerViewAdapter(
+ allStationsList, this, ParceableFavsCallReason.Reason.ALL_STATIONS);
recyclerViewAllStations.setAdapter(adapter);
-
recyclerViewAllStations.setLayoutManager(new LinearLayoutManager(this));
}
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ EventBus.getDefault().register(this);
+ updateStationList(((Main) getApplication()).getListOfAllStations());
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ EventBus.getDefault().unregister(this);
+ }
+
+ private void updateStationList(List stations) {
+ if (stations != null) {
+ allStationsList.clear();
+ allStationsList.addAll(stations);
+ refreshLayout.setRefreshing(false);
+ adapter.notifyDataSetChanged();
+ } else {
+ EventBus.getDefault().post(new StartStationsRefreshEvent());
+ }
+ }
+
+ @Subscribe(threadMode = ThreadMode.MAIN)
+ public void allStationsEventHandler(@NonNull AllStationsReceivedEvent event) {
+ updateStationList(event.getStations());
+ }
+
+ @Subscribe(threadMode = ThreadMode.MAIN)
+ public void startStationsRefreshEventHandler(@NonNull StartStationsRefreshEvent event) {
+ refreshLayout.setRefreshing(true);
+ Toast.makeText(this, R.string.refreshing_station_list, Toast.LENGTH_SHORT).show();
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/FavouritesActivity.java b/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/FavouritesActivity.java
index 648ba95..c3171ff 100644
--- a/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/FavouritesActivity.java
+++ b/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/FavouritesActivity.java
@@ -3,31 +3,43 @@ package cc.pogoda.mobile.meteosystem.activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
+import android.widget.LinearLayout;
+import android.widget.ListView;
+import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
+import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
+
+import org.greenrobot.eventbus.EventBus;
+import org.greenrobot.eventbus.Subscribe;
+import org.greenrobot.eventbus.ThreadMode;
import java.util.ArrayList;
import java.util.Comparator;
+import java.util.LinkedList;
import java.util.List;
import cc.pogoda.mobile.meteosystem.Main;
import cc.pogoda.mobile.meteosystem.R;
import cc.pogoda.mobile.meteosystem.adapter.WeatherStationRecyclerViewAdapter;
+import cc.pogoda.mobile.meteosystem.type.AllStationsReceivedEvent;
import cc.pogoda.mobile.meteosystem.type.ParceableFavsCallReason;
-import cc.pogoda.mobile.meteosystem.type.ParceableStationsList;
+import cc.pogoda.mobile.meteosystem.type.StartStationsRefreshEvent;
import cc.pogoda.mobile.meteosystem.type.WeatherStation;
public class FavouritesActivity extends AppCompatActivity {
- Main main;
-
RecyclerView recyclerViewFavourites;
- List favourites, sortedFavourites;
+ private SwipeRefreshLayout refreshLayout;
+
+ List favourites = new LinkedList<>();
+
+ List sortedFavourites;
boolean sorting = false;
@@ -35,14 +47,11 @@ public class FavouritesActivity extends AppCompatActivity {
ParceableFavsCallReason callReason;
- private class WxStationComparator implements Comparator {
+ private static class WxStationComparator implements Comparator {
@Override
public int compare(WeatherStation station, WeatherStation t1) {
- String name = station.getDisplayedName();
- String name1 = t1.getDisplayedName();
-
- return (name.compareTo(name1));
+ return (station.getDisplayedName().compareTo(t1.getDisplayedName()));
}
}
@@ -82,8 +91,6 @@ public class FavouritesActivity extends AppCompatActivity {
recyclerViewFavourites.setAdapter(adapter);
}
- break;
- case R.id.fav_remove_noext:
break;
}
@@ -93,43 +100,65 @@ public class FavouritesActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_favourites);
- //favourites = getIntent().getParcelableExtra("favs");
- main = (Main)getApplication();
-
- favourites = main.getFavs();
- sortedFavourites = new ArrayList<>(favourites);
-
- sortedFavourites.sort(new WxStationComparator());
+ recyclerViewFavourites = findViewById(R.id.recyclerViewFavourites);
+ refreshLayout = findViewById(R.id.refreshViewFavourites);
+ refreshLayout.setOnRefreshListener(
+ () -> ((Main) getApplication()).startGetAllStationsService()
+ );
callReason = getIntent().getParcelableExtra("callReason");
+ adapter = new WeatherStationRecyclerViewAdapter(favourites,
+ this, callReason.getReason());
+ recyclerViewFavourites.setAdapter(adapter);
+ recyclerViewFavourites.setLayoutManager(new LinearLayoutManager(this));
+ }
- if (favourites == null || favourites.size() == 0) {
- setContentView(R.layout.activity_favourites_empty);
- }
- else {
- setContentView(R.layout.activity_favourites);
+ @Override
+ protected void onResume() {
+ super.onResume();
+ EventBus.getDefault().register(this);
+ updateStationList();
+ }
- recyclerViewFavourites = findViewById(R.id.recyclerViewFavourites);
-
- if (recyclerViewFavourites != null) {
- adapter = new WeatherStationRecyclerViewAdapter(favourites, this, callReason.getReason());
-
- adapter.createAndStartUpdater();
-
- recyclerViewFavourites.setAdapter(adapter);
-
- recyclerViewFavourites.setLayoutManager(new LinearLayoutManager(this));
- }
- }
+ @Override
+ protected void onPause() {
+ super.onPause();
+ EventBus.getDefault().unregister(this);
}
@Override
protected void onDestroy() {
+ adapter.stopUpdater();
super.onDestroy();
+ }
- if (adapter != null) {
- adapter.stopUpdater();
+ private void updateStationList() {
+ List favList = ((Main) getApplication()).getFavs();
+
+ if(favList != null) {
+ favourites.clear();
+ favourites.addAll(favList);
+ refreshLayout.setRefreshing(false);
+ sortedFavourites = new ArrayList<>(favourites);
+ sortedFavourites.sort(new WxStationComparator());
+ adapter.notifyDataSetChanged();
+ if (!favList.isEmpty()) {
+ adapter.createAndStartUpdater();
+ }
}
+
+ }
+
+ @Subscribe(threadMode = ThreadMode.MAIN)
+ public void allStationsEventHandler(@NonNull AllStationsReceivedEvent event) {
+ updateStationList();
+ }
+
+ @Subscribe(threadMode = ThreadMode.MAIN)
+ public void startStationsRefreshEventHandler(@NonNull StartStationsRefreshEvent event) {
+ refreshLayout.setRefreshing(true);
+ Toast.makeText(this, R.string.refreshing_station_list, Toast.LENGTH_SHORT).show();
}
}
diff --git a/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/MainActivity.java b/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/MainActivity.java
index 17471b9..c50c657 100644
--- a/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/MainActivity.java
+++ b/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/MainActivity.java
@@ -2,10 +2,6 @@ package cc.pogoda.mobile.meteosystem.activity;
// https://www.softicons.com/web-icons/vector-stylish-weather-icons-by-bartosz-kaszubowski/sun-rays-cloud-icon#google_vignette
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.appcompat.app.AppCompatActivity;
-
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
@@ -13,27 +9,21 @@ import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.net.Uri;
-import android.os.Build;
import android.os.Bundle;
-import android.os.StrictMode;
-import android.os.strictmode.Violation;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageButton;
-import com.jakewharton.threetenabp.AndroidThreeTen;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.appcompat.app.AppCompatActivity;
import org.greenrobot.eventbus.EventBus;
-import org.greenrobot.eventbus.Subscribe;
-import org.greenrobot.eventbus.ThreadMode;
import org.threeten.bp.LocalDateTime;
import org.threeten.bp.format.DateTimeFormatter;
import org.tinylog.Logger;
import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
import java.util.Locale;
import cc.pogoda.mobile.meteosystem.Main;
@@ -43,33 +33,12 @@ import cc.pogoda.mobile.meteosystem.activity.handler.MainActImageButtonExportCli
import cc.pogoda.mobile.meteosystem.activity.handler.MainActImageButtonFavouritesClickEvent;
import cc.pogoda.mobile.meteosystem.activity.handler.MainActImageButtonSettingsClickEvent;
import cc.pogoda.mobile.meteosystem.config.AppConfiguration;
-import cc.pogoda.mobile.meteosystem.dao.AllStationsDao;
-import cc.pogoda.mobile.meteosystem.file.ConfigurationFile;
import cc.pogoda.mobile.meteosystem.file.CopyLog;
-import cc.pogoda.mobile.meteosystem.file.FavouritiesFile;
-import cc.pogoda.mobile.meteosystem.file.FileNames;
-import cc.pogoda.mobile.meteosystem.type.ParceableStationsList;
-import cc.pogoda.mobile.meteosystem.type.WeatherStation;
-import cc.pogoda.mobile.meteosystem.type.WeatherStationListEvent;
public class MainActivity extends AppCompatActivity {
private Main main;
- private Context baseContext;
-
- private MainActImageButtonFavouritesClickEvent mainActImageButtonFavouritesClickEvent = null;
-
- private ImageButton imageButtonFavourites;
-
- private ImageButton exportButton;
-
- private ImageButton settingsButton;
-
- public MainActivity() {
-
- }
-
@Override
protected void onDestroy() {
super.onDestroy();
@@ -95,48 +64,34 @@ public class MainActivity extends AppCompatActivity {
main = (Main) getApplication();
- baseContext = getApplicationContext();
-
- if (AppConfiguration.locale != null && !AppConfiguration.locale.equals("default") ) {
- Logger.debug("[MainActivity][onCreate][AppConfiguration.locale = " + AppConfiguration.locale + "]");
+ if (AppConfiguration.locale != null && !AppConfiguration.locale.equals("default")) {
+ Logger.debug("[MainActivity][onCreate][AppConfiguration.locale = "
+ + AppConfiguration.locale + "]");
Locale locale = new Locale(AppConfiguration.locale);
Locale.setDefault(locale);
Resources resources = this.getResources();
Configuration config = resources.getConfiguration();
config.setLocale(locale);
- Logger.debug("[MainActivity][onCreate][locale = " + locale.toLanguageTag() + "]");
+ Logger.debug("[MainActivity][onCreate][locale = " + locale.toLanguageTag() + "]");
resources.updateConfiguration(config, resources.getDisplayMetrics());
}
- // create an event handler fired when a user click 'favourites' button
- mainActImageButtonFavouritesClickEvent = new MainActImageButtonFavouritesClickEvent(this);
-
- // assign on click listener
- if (imageButtonFavourites != null) {
- imageButtonFavourites.setOnClickListener(mainActImageButtonFavouritesClickEvent);
- }
-
setContentView(R.layout.activity_main);
- ImageButton imageButtonAllStations = (ImageButton)findViewById(R.id.imageButtonAllStations);
- if (imageButtonAllStations != null)
- imageButtonAllStations.setOnClickListener(new MainActImageButtonAllStationsClickEvent(this));
+ ImageButton imageButtonAllStations = findViewById(R.id.imageButtonAllStations);
+ imageButtonAllStations.setOnClickListener(
+ new MainActImageButtonAllStationsClickEvent(this));
- imageButtonFavourites = (ImageButton)findViewById(R.id.imageButtonFavourites);
- if (imageButtonFavourites != null) {
- imageButtonFavourites.setOnClickListener(new MainActImageButtonFavouritesClickEvent(this));
- }
+ ImageButton imageButtonFavourites = findViewById(R.id.imageButtonFavourites);
+ imageButtonFavourites.setOnClickListener(
+ new MainActImageButtonFavouritesClickEvent(this));
- // set an action for clicking on export data button
- exportButton = (ImageButton)findViewById(R.id.imageButtonExport);
- if (exportButton != null) {
- exportButton.setOnClickListener(new MainActImageButtonExportClickEvent(this));
- }
+ ImageButton exportButton = findViewById(R.id.imageButtonExport);
+ exportButton.setOnClickListener(new MainActImageButtonExportClickEvent(this));
- settingsButton = (ImageButton) findViewById(R.id.imageButtonSettings);
- if (settingsButton != null) {
- settingsButton.setOnClickListener(new MainActImageButtonSettingsClickEvent(this, main.getConfFile()));
- }
+ ImageButton settingsButton = findViewById(R.id.imageButtonSettings);
+ settingsButton.setOnClickListener(
+ new MainActImageButtonSettingsClickEvent(this, main.getConfFile()));
}
@@ -146,21 +101,23 @@ public class MainActivity extends AppCompatActivity {
if (requestCode == 123 && resultCode == RESULT_OK) {
Uri uri = data.getData();
- Logger.debug("[MainActivity][onActivityResult][requestCode = 123][uri.getPath() = " + uri.getPath() +"]");
+ Logger.debug("[MainActivity][onActivityResult][requestCode = 123][uri.getPath() = "
+ + uri.getPath() + "]");
- grantUriPermission(getPackageName(), uri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
- getContentResolver().takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
+ grantUriPermission(getPackageName(), uri,
+ Intent.FLAG_GRANT_READ_URI_PERMISSION
+ | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
+ getContentResolver().takePersistableUriPermission(uri,
+ Intent.FLAG_GRANT_READ_URI_PERMISSION
+ | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
try {
- CopyLog.forDay(main.getFileNames(), LocalDateTime.now(), getContentResolver().openOutputStream(uri));
+ CopyLog.forDay(main.getFileNames(), LocalDateTime.now(),
+ getContentResolver().openOutputStream(uri));
} catch (FileNotFoundException e) {
Logger.error("[MainActivity][onActivityResult][FileNotFoundException]");
}
- // getContentResolver().openOutputStream(exportUri)
-
- //exportUri = uri;
-
}
super.onActivityResult(requestCode, resultCode, data);
@@ -183,7 +140,8 @@ public class MainActivity extends AppCompatActivity {
"CZE: Sylwiusz Pachel\r\n" +
"GER: Jakub Fiałek\r\n" +
"LAT: Andris Stikāns\r\n" +
- "UKR, RUS: Влад Поливач \r\n(Wład Polywacz)\r\n\r\nProgram Icon: Bartosz Kaszubowski");
+ "UKR, RUS: Влад Поливач \r\n" +
+ "(Wład Polywacz)\r\n\r\nProgram Icon: Bartosz Kaszubowski");
builder.setPositiveButton(R.string.ok, (DialogInterface var1, int var2) -> {
var1.dismiss();
});
@@ -193,11 +151,12 @@ public class MainActivity extends AppCompatActivity {
break;
}
- case (R.id.menu_item_log_export) : {
+ case (R.id.menu_item_log_export): {
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("text/plain");
- intent.putExtra(Intent.EXTRA_TITLE, "meteosystem_" +LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE) + ".log");
+ intent.putExtra(Intent.EXTRA_TITLE, "meteosystem_" +
+ LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE) + ".log");
startActivityForResult(intent, 123);
@@ -209,21 +168,11 @@ public class MainActivity extends AppCompatActivity {
}
public boolean listOfAllStationsReady() {
- if (main != null) {
- return main.listOfAllStationsReady();
- }
- else {
- return false;
- }
+ return main.listOfAllStationsReady() && main != null;
}
public boolean listOfAllFavsReady() {
- if (main != null) {
- return main.listOfFavsReady();
- }
- else {
- return false;
- }
+ return main.listOfFavsReady() && main != null;
}
}
\ No newline at end of file
diff --git a/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/handler/MainActImageButtonAllStationsClickEvent.java b/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/handler/MainActImageButtonAllStationsClickEvent.java
index fd4f7b0..509eeab 100644
--- a/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/handler/MainActImageButtonAllStationsClickEvent.java
+++ b/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/handler/MainActImageButtonAllStationsClickEvent.java
@@ -12,27 +12,15 @@ import cc.pogoda.mobile.meteosystem.type.ParceableStationsList;
public class MainActImageButtonAllStationsClickEvent implements View.OnClickListener {
MainActivity parent;
-
Intent intent;
public MainActImageButtonAllStationsClickEvent(MainActivity parent) {
this.parent = parent;
-
intent = new Intent(this.parent, AllStationsActivity.class);
-
-
}
@Override
public void onClick(View v) {
- if (parent.listOfAllStationsReady()) {
- launchActivity();
- }
-
- return;
- }
-
- private void launchActivity() {
parent.startActivity(intent);
}
}
diff --git a/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/handler/MainActImageButtonFavouritesClickEvent.java b/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/handler/MainActImageButtonFavouritesClickEvent.java
index 3ebe3d4..d9153b2 100644
--- a/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/handler/MainActImageButtonFavouritesClickEvent.java
+++ b/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/handler/MainActImageButtonFavouritesClickEvent.java
@@ -27,9 +27,6 @@ public class MainActImageButtonFavouritesClickEvent implements View.OnClickListe
@Override
public void onClick(View view) {
- if (parent.listOfAllFavsReady()) {
- parent.startActivity(intent);
-
- }
+ parent.startActivity(intent);
}
}
diff --git a/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/updater/FavouritesStationDetailsOnListUpdater.java b/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/updater/FavouritesStationDetailsOnListUpdater.java
index b681975..0a545db 100644
--- a/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/updater/FavouritesStationDetailsOnListUpdater.java
+++ b/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/updater/FavouritesStationDetailsOnListUpdater.java
@@ -95,7 +95,8 @@ public class FavouritesStationDetailsOnListUpdater implements Runnable {
Summary summary = stationNameSummary.get(stationSystemName);
// query for available parameters
- AvailableParametersWeb params = availableParametersDao.getAvaliableParamsByStationName(stationSystemName);
+ AvailableParametersWeb params
+ = availableParametersDao.getAvaliableParamsByStationName(stationSystemName);
// if data has been collected
if (summary != null && params != null) {
@@ -103,6 +104,9 @@ public class FavouritesStationDetailsOnListUpdater implements Runnable {
String str;
+ Logger.debug("[FavouritesStationDetailsOnListUpdater][run][stationSystemName = " +
+ "" + stationSystemName +"][summary.last_timestamp = " + summary.last_timestamp +"]");
+
// check if this station transmits wind information
if (params.hasWind) {
@@ -138,7 +142,7 @@ public class FavouritesStationDetailsOnListUpdater implements Runnable {
}
}
else {
- Logger.error("[FavouritesStationDetailsOnListUpdater][run][summary object is null!! Maybe the API responds exeptionally slow?]");
+ Logger.error("[FavouritesStationDetailsOnListUpdater][run][summary object is null!! Maybe the API responds exceptionally slow?]");
nextExecutionDelay = 3000;
}
}
diff --git a/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/updater/FavouritesStationSummaryUpdater.java b/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/updater/FavouritesStationSummaryUpdater.java
index 2b67ff6..aa5d53c 100644
--- a/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/updater/FavouritesStationSummaryUpdater.java
+++ b/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/updater/FavouritesStationSummaryUpdater.java
@@ -79,6 +79,9 @@ public class FavouritesStationSummaryUpdater implements Runnable {
}
+ else {
+ Logger.info("[FavouritesStationSummaryUpdater][run][no station to update]");
+ }
if (forceUpdate) {
forceUpdate = false;
diff --git a/app/src/main/java/cc/pogoda/mobile/meteosystem/adapter/WeatherStationRecyclerViewAdapter.java b/app/src/main/java/cc/pogoda/mobile/meteosystem/adapter/WeatherStationRecyclerViewAdapter.java
index 9734b05..e0533d9 100644
--- a/app/src/main/java/cc/pogoda/mobile/meteosystem/adapter/WeatherStationRecyclerViewAdapter.java
+++ b/app/src/main/java/cc/pogoda/mobile/meteosystem/adapter/WeatherStationRecyclerViewAdapter.java
@@ -26,9 +26,9 @@ import cc.pogoda.mobile.meteosystem.dao.SummaryDao;
import cc.pogoda.mobile.meteosystem.type.ParceableFavsCallReason;
import cc.pogoda.mobile.meteosystem.type.WeatherStation;
-public class WeatherStationRecyclerViewAdapter extends RecyclerView.Adapter {
+public class WeatherStationRecyclerViewAdapter extends RecyclerView.Adapter {
- private List stations;
+ final private List stations;
AppCompatActivity activity;
@@ -51,7 +51,13 @@ public class WeatherStationRecyclerViewAdapter extends RecyclerView.Adapter stations, AppCompatActivity parentActivity, ParceableFavsCallReason.Reason callReason) {
+ private static final int VIEW_TYPE_EMPTY_LIST = 0;
+ private static final int VIEW_TYPE_OBJECT = 1;
+
+ public WeatherStationRecyclerViewAdapter(
+ List stations,
+ AppCompatActivity parentActivity,
+ ParceableFavsCallReason.Reason callReason) {
this.stations = stations;
this.activity = parentActivity;
this.reason = callReason;
@@ -62,77 +68,95 @@ public class WeatherStationRecyclerViewAdapter extends RecyclerView.Adapter 22) {
- textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20.0f);
- } else {
- textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22.0f);
- }
- }
- else {
if (station.getDisplayedName().length() > 22) {
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20.0f);
} else {
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22.0f);
}
+
+ button.setOnClickListener(new AllStationsActRecyclerViewButtonClickEvent(station, activity, reason));
}
- button.setOnClickListener(new AllStationsActRecyclerViewButtonClickEvent(station, activity, reason));
+ // this if distinguish between All Stations and Favorites view
+ if (textViewData != null && favsUpdater != null) {
+
+ favsUpdater.addNewStation(station.getSystemName(), textViewData);
+ }
}
-
- // this if distinguish between All Stations and Favorites view
- if (textViewData != null && favsUpdater != null) {
-
- favsUpdater.addNewStation(station.getSystemName(), textViewData);
- }
-
}
@Override
public int getItemCount() {
- return stations.size();
+ // In case of empty station list at least 1 should be returned to properly select view type
+ // and render empty list info.
+ return stations.isEmpty() ? 1 : stations.size();
}
-
public void createAndStartUpdater() {
// check if there is previous instance of updater
@@ -148,10 +172,19 @@ public class WeatherStationRecyclerViewAdapter extends RecyclerView.Adapter allStations = new AllStationsDao().getAllStations();
+ if (allStations != null){
+ EventBus.getDefault().post(new AllStationsReceivedEvent(allStations));
+ Logger.debug("onHandleWork done. allStations size:" + allStations.size());
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/cc/pogoda/mobile/meteosystem/type/AllStationsReceivedEvent.java b/app/src/main/java/cc/pogoda/mobile/meteosystem/type/AllStationsReceivedEvent.java
new file mode 100644
index 0000000..e00d396
--- /dev/null
+++ b/app/src/main/java/cc/pogoda/mobile/meteosystem/type/AllStationsReceivedEvent.java
@@ -0,0 +1,18 @@
+package cc.pogoda.mobile.meteosystem.type;
+
+import androidx.annotation.NonNull;
+
+import java.util.List;
+
+public class AllStationsReceivedEvent {
+ List stations;
+
+ public AllStationsReceivedEvent(@NonNull List stations) {
+ this.stations = stations;
+ }
+
+ @NonNull
+ public List getStations(){
+ return this.stations;
+ }
+}
diff --git a/app/src/main/java/cc/pogoda/mobile/meteosystem/type/StartStationsRefreshEvent.java b/app/src/main/java/cc/pogoda/mobile/meteosystem/type/StartStationsRefreshEvent.java
new file mode 100644
index 0000000..154046a
--- /dev/null
+++ b/app/src/main/java/cc/pogoda/mobile/meteosystem/type/StartStationsRefreshEvent.java
@@ -0,0 +1,4 @@
+package cc.pogoda.mobile.meteosystem.type;
+
+public class StartStationsRefreshEvent {
+}
diff --git a/app/src/main/res/layout/activity_all_stations.xml b/app/src/main/res/layout/activity_all_stations.xml
index fdea513..350e91f 100644
--- a/app/src/main/res/layout/activity_all_stations.xml
+++ b/app/src/main/res/layout/activity_all_stations.xml
@@ -5,11 +5,18 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.AllStationsActivity">
-
-
+ android:layout_height="match_parent">
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_all_stations_empty.xml b/app/src/main/res/layout/activity_all_stations_empty.xml
new file mode 100644
index 0000000..aacac8e
--- /dev/null
+++ b/app/src/main/res/layout/activity_all_stations_empty.xml
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_favourites.xml b/app/src/main/res/layout/activity_favourites.xml
index 5cf827b..a103b22 100644
--- a/app/src/main/res/layout/activity_favourites.xml
+++ b/app/src/main/res/layout/activity_favourites.xml
@@ -1,10 +1,17 @@
-
+ android:layout_height="match_parent">
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/menu/menu_favourites.xml b/app/src/main/res/menu/menu_favourites.xml
index 26bcb68..8f2631b 100644
--- a/app/src/main/res/menu/menu_favourites.xml
+++ b/app/src/main/res/menu/menu_favourites.xml
@@ -8,7 +8,4 @@
-
\ No newline at end of file
diff --git a/app/src/main/res/values-en-rUS/strings.xml b/app/src/main/res/values-en-rUS/strings.xml
index 66087dc..fc81af2 100644
--- a/app/src/main/res/values-en-rUS/strings.xml
+++ b/app/src/main/res/values-en-rUS/strings.xml
@@ -70,7 +70,7 @@
Sort in adding order
Clear removed stations
Three days
- Plots data lenght
+ Plots data length
Pressure
Wind
Current Value
@@ -90,7 +90,7 @@
Weather forecast
From
To
- Laguage
+ Language
Unit of measure
Windspeed unit
Filter
@@ -114,4 +114,6 @@
Export data decimation
Minimum time resolution
URL to more information
+ Refreshing station list
+
\ No newline at end of file
diff --git a/app/src/main/res/values-pl-rPL/strings.xml b/app/src/main/res/values-pl-rPL/strings.xml
index 0b6a143..5bac34a 100644
--- a/app/src/main/res/values-pl-rPL/strings.xml
+++ b/app/src/main/res/values-pl-rPL/strings.xml
@@ -114,4 +114,7 @@
Decymacja eskportowanych danych
Minimalny krok w minutach
Więcej informacji
+ Odświeżanie listy stacji
+ Brak stacji na liście.
+ Proszę poczekać lub pociągnąć w dół aby odświeżyć.
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 0443187..843a021 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -144,4 +144,7 @@
Changing language requires app restart after making a choose in this window.
URL to more information
+ Refreshing station list
+ There are no stations on this list.
+ Please wait or pull down to refresh list.
\ No newline at end of file