kopia lustrzana https://github.com/SP8EBC/MeteoSystem
favourites and all station moved to main application class
rodzic
5e984ce264
commit
31135df0c9
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 188 KiB |
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 196 KiB |
|
@ -36,6 +36,8 @@ repositories {
|
|||
|
||||
dependencies {
|
||||
|
||||
implementation 'org.tinylog:tinylog-api:2.1.0'
|
||||
runtimeOnly 'org.tinylog:tinylog-impl:2.1.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.3.1'
|
||||
implementation 'com.google.android.material:material:1.4.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
android:networkSecurityConfig="@xml/network_security_config"
|
||||
android:roundIcon="@mipmap/ic_launcher_icon_foreground"
|
||||
android:supportsRtl="true"
|
||||
android:name=".Main"
|
||||
android:theme="@style/Theme.Meteosystem">
|
||||
<activity
|
||||
android:name="cc.pogoda.mobile.meteosystem.activity.SettingsActivity"
|
||||
|
|
|
@ -0,0 +1,217 @@
|
|||
package cc.pogoda.mobile.meteosystem;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.os.StrictMode;
|
||||
import android.os.strictmode.Violation;
|
||||
|
||||
import com.jakewharton.threetenabp.AndroidThreeTen;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import cc.pogoda.mobile.meteosystem.activity.handler.MainActImageButtonFavouritesClickEvent;
|
||||
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.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 Main extends Application {
|
||||
|
||||
private File directory;
|
||||
|
||||
private File directoryForLogs;
|
||||
|
||||
private Context ctx;
|
||||
|
||||
private ConfigurationFile confFile;
|
||||
|
||||
private FileNames fileNames;
|
||||
|
||||
private FavouritiesFile favouritiesFile;
|
||||
|
||||
public List<WeatherStation> getListOfAllStations() {
|
||||
return listOfAllStations;
|
||||
}
|
||||
|
||||
private List<WeatherStation> listOfAllStations;
|
||||
|
||||
public List<WeatherStation> getFavs() {
|
||||
return favs;
|
||||
}
|
||||
|
||||
private List<WeatherStation> favs;
|
||||
|
||||
public File getDirectory() {
|
||||
return directory;
|
||||
}
|
||||
|
||||
public File getDirectoryForLogs() {
|
||||
return directoryForLogs;
|
||||
}
|
||||
|
||||
public ConfigurationFile getConfFile() {
|
||||
return confFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
ctx = this.getApplicationContext();
|
||||
|
||||
confFile = new ConfigurationFile(ctx);
|
||||
|
||||
StrictMode.VmPolicy.Builder b = new StrictMode.VmPolicy.Builder();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
StrictMode.VmPolicy policy = b.detectAll().detectNonSdkApiUsage().penaltyListener((Runnable r) -> r.run(), (Violation v) -> {v.printStackTrace();}).build();
|
||||
StrictMode.setVmPolicy(policy);
|
||||
}
|
||||
|
||||
directory = getApplicationContext().getDir("meteosystem", Context.MODE_PRIVATE);
|
||||
|
||||
directoryForLogs = new File(directory.getAbsolutePath() + "/logs/");
|
||||
|
||||
System.setProperty("tinylog.directory", directoryForLogs.getAbsolutePath());
|
||||
|
||||
Logger.info("Application starting...");
|
||||
|
||||
AndroidThreeTen.init(this);
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
|
||||
ConfigurationFile confFile = new ConfigurationFile(ctx);
|
||||
|
||||
confFile.restoreFromFile();
|
||||
|
||||
fileNames = new FileNames(ctx);
|
||||
|
||||
favouritiesFile = new FavouritiesFile(fileNames);
|
||||
|
||||
// download all stations from API
|
||||
listOfAllStations = new AllStationsDao().getAllStations();
|
||||
|
||||
Logger.info("[Main][onCreate][listOfAllStations.size() = " + listOfAllStations.size() + "]");
|
||||
|
||||
// recreate list of favorites
|
||||
recreateListOfFavs();
|
||||
|
||||
if (AppConfiguration.locale != null && !AppConfiguration.locale.equals("default") ) {
|
||||
Logger.debug("[Main][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("[Main][onCreate][locale = " + locale.toLanguageTag() + "]");
|
||||
resources.updateConfiguration(config, resources.getDisplayMetrics());
|
||||
}
|
||||
}
|
||||
|
||||
private void recreateListOfFavs() {
|
||||
|
||||
// check if this is a first call after application start
|
||||
if (favs == null) {
|
||||
favs = favouritiesFile.loadFavourites();
|
||||
}
|
||||
|
||||
// if favs is still null it means that favourites file doesn't even exists
|
||||
// so and user hasn't added any station to it yet
|
||||
if (favs == null) {
|
||||
favs = new ArrayList<>();
|
||||
}
|
||||
else {
|
||||
// update values for the fav list with listOfAllStations
|
||||
//for (WeatherStation f : favs) {
|
||||
for (int i = 0; i < favs.size(); i++) {
|
||||
|
||||
//
|
||||
WeatherStation fromFavs = favs.get(i);
|
||||
|
||||
// find an index of updated station
|
||||
int idx = listOfAllStations.indexOf(fromFavs);
|
||||
|
||||
// get the station
|
||||
WeatherStation fromAllStations = listOfAllStations.get(idx);
|
||||
|
||||
// update all parameters
|
||||
fromFavs.setAvailableParameters(fromAllStations.getAvailableParameters());
|
||||
fromFavs.setMoreInfo(fromAllStations.getMoreInfo());
|
||||
fromFavs.setImageAlign(fromAllStations.getImageAlign());
|
||||
fromFavs.setImageUrl(fromAllStations.getImageUrl());
|
||||
fromFavs.setSponsorUrl(fromAllStations.getSponsorUrl());
|
||||
fromFavs.setMoreInfo(fromAllStations.getMoreInfo());
|
||||
fromFavs.setLon(fromAllStations.getLon());
|
||||
fromFavs.setLat(fromAllStations.getLat());
|
||||
fromFavs.setDisplayedName(fromAllStations.getDisplayedName());
|
||||
fromFavs.setDisplayedLocation(fromAllStations.getDisplayedLocation());
|
||||
fromFavs.setTimezone(fromAllStations.getTimezone());
|
||||
fromFavs.setCallsignSsid(fromAllStations.getCallsignSsid());
|
||||
fromFavs.setStationNameTextColor(fromAllStations.getStationNameTextColor());
|
||||
|
||||
// there is no need to delete and put object on the list once again
|
||||
// as a list does not make a copy of the object. It (ArrayList) keeps
|
||||
// only a reference to an object
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void weatherStationListHandler(WeatherStationListEvent serviceEvent) {
|
||||
Logger.info("[Main][weatherStationListHandler][serviceEvent = " + serviceEvent + "]");
|
||||
|
||||
switch (serviceEvent.getEventReason()) {
|
||||
|
||||
case ADD:
|
||||
// check of list consist this station
|
||||
if (favs.contains(serviceEvent.getStation())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// add favourites to list
|
||||
favs.add(serviceEvent.getStation());
|
||||
|
||||
try {
|
||||
// save the list into JSON file
|
||||
favouritiesFile.persistFavourities(favs);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
break;
|
||||
case DELETE:
|
||||
favs.remove(serviceEvent.getStation());
|
||||
|
||||
try {
|
||||
// save the list into JSON file
|
||||
favouritiesFile.persistFavourities(favs);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// recreate parceable object and pass it everywhere
|
||||
recreateListOfFavs();
|
||||
//Toast.makeText(this, intentServiceResult.getResultValue(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
}
|
|
@ -4,34 +4,43 @@ import androidx.appcompat.app.AppCompatActivity;
|
|||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
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.ParceableFavsCallReason;
|
||||
import cc.pogoda.mobile.meteosystem.type.ParceableStationsList;
|
||||
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;
|
||||
|
||||
ParceableStationsList allStationsList;
|
||||
private List<WeatherStation> allStationsList;
|
||||
|
||||
Main main;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_all_stations);
|
||||
|
||||
allStationsList = getIntent().getParcelableExtra("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.getList(), this, ParceableFavsCallReason.Reason.ALL_STATIONS);
|
||||
adapter = new WeatherStationRecyclerViewAdapter(allStationsList, this, ParceableFavsCallReason.Reason.ALL_STATIONS);
|
||||
|
||||
recyclerViewAllStations.setAdapter(adapter);
|
||||
|
||||
|
|
|
@ -153,8 +153,6 @@ public class ExportDataActivity extends AppCompatActivity {
|
|||
|
||||
act = this;
|
||||
|
||||
ParceableStationsList favs = getIntent().getParcelableExtra("favs");
|
||||
|
||||
formatSpinner = findViewById(R.id.spinnerOutputFormat);
|
||||
selectStationButton = findViewById(R.id.buttonSelectStationExport);
|
||||
stationNameToExport = findViewById(R.id.textViewStationToExport);
|
||||
|
@ -189,7 +187,6 @@ public class ExportDataActivity extends AppCompatActivity {
|
|||
@Override
|
||||
public void onClick(View view) {
|
||||
intent = new Intent(act, FavouritesActivity.class);
|
||||
intent.putExtra("favs", favs);
|
||||
|
||||
ParceableFavsCallReason callReason = new ParceableFavsCallReason(ParceableFavsCallReason.Reason.EXPORT_SELECT);
|
||||
intent.putExtra("callReason", callReason);
|
||||
|
|
|
@ -10,8 +10,11 @@ import androidx.appcompat.app.AppCompatActivity;
|
|||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
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.ParceableFavsCallReason;
|
||||
|
@ -20,9 +23,11 @@ import cc.pogoda.mobile.meteosystem.type.WeatherStation;
|
|||
|
||||
public class FavouritesActivity extends AppCompatActivity {
|
||||
|
||||
Main main;
|
||||
|
||||
RecyclerView recyclerViewFavourites;
|
||||
|
||||
ParceableStationsList favourites, sortedFavourites;
|
||||
List<WeatherStation> favourites, sortedFavourites;
|
||||
|
||||
boolean sorting = false;
|
||||
|
||||
|
@ -58,7 +63,7 @@ public class FavouritesActivity extends AppCompatActivity {
|
|||
sorting = true;
|
||||
|
||||
if (recyclerViewFavourites != null) {
|
||||
adapter = new WeatherStationRecyclerViewAdapter(sortedFavourites.getList(), this, callReason.getReason());
|
||||
adapter = new WeatherStationRecyclerViewAdapter(sortedFavourites, this, callReason.getReason());
|
||||
|
||||
adapter.createAndStartUpdater();
|
||||
|
||||
|
@ -70,7 +75,7 @@ public class FavouritesActivity extends AppCompatActivity {
|
|||
sorting = false;
|
||||
|
||||
if (recyclerViewFavourites != null) {
|
||||
adapter = new WeatherStationRecyclerViewAdapter(favourites.getList(), this, callReason.getReason());
|
||||
adapter = new WeatherStationRecyclerViewAdapter(favourites, this, callReason.getReason());
|
||||
|
||||
adapter.createAndStartUpdater();
|
||||
|
||||
|
@ -89,15 +94,17 @@ public class FavouritesActivity extends AppCompatActivity {
|
|||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
favourites = getIntent().getParcelableExtra("favs");
|
||||
//favourites = getIntent().getParcelableExtra("favs");
|
||||
main = (Main)getApplication();
|
||||
|
||||
sortedFavourites = new ParceableStationsList(favourites);
|
||||
favourites = main.getFavs();
|
||||
sortedFavourites = new ArrayList<>(favourites);
|
||||
|
||||
sortedFavourites.getList().sort(new WxStationComparator());
|
||||
sortedFavourites.sort(new WxStationComparator());
|
||||
|
||||
callReason = getIntent().getParcelableExtra("callReason");
|
||||
|
||||
if (favourites == null || favourites.getList().size() == 0) {
|
||||
if (favourites == null || favourites.size() == 0) {
|
||||
setContentView(R.layout.activity_favourites_empty);
|
||||
}
|
||||
else {
|
||||
|
@ -106,7 +113,7 @@ public class FavouritesActivity extends AppCompatActivity {
|
|||
recyclerViewFavourites = findViewById(R.id.recyclerViewFavourites);
|
||||
|
||||
if (recyclerViewFavourites != null) {
|
||||
adapter = new WeatherStationRecyclerViewAdapter(favourites.getList(), this, callReason.getReason());
|
||||
adapter = new WeatherStationRecyclerViewAdapter(favourites, this, callReason.getReason());
|
||||
|
||||
adapter.createAndStartUpdater();
|
||||
|
||||
|
|
|
@ -23,12 +23,14 @@ import com.jakewharton.threetenabp.AndroidThreeTen;
|
|||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import cc.pogoda.mobile.meteosystem.Main;
|
||||
import cc.pogoda.mobile.meteosystem.R;
|
||||
import cc.pogoda.mobile.meteosystem.activity.handler.MainActImageButtonAllStationsClickEvent;
|
||||
import cc.pogoda.mobile.meteosystem.activity.handler.MainActImageButtonExportClickEvent;
|
||||
|
@ -45,20 +47,10 @@ import cc.pogoda.mobile.meteosystem.type.WeatherStationListEvent;
|
|||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private Main main;
|
||||
|
||||
private Context baseContext;
|
||||
|
||||
private FileNames fileNames;
|
||||
|
||||
private FavouritiesFile favouritiesFile;
|
||||
|
||||
private List<WeatherStation> listOfAllStations;
|
||||
|
||||
List<WeatherStation> favs;
|
||||
|
||||
private ParceableStationsList parceableListOfAllStations;
|
||||
|
||||
private ParceableStationsList parceableListOfFavStations;
|
||||
|
||||
private MainActImageButtonFavouritesClickEvent mainActImageButtonFavouritesClickEvent = null;
|
||||
|
||||
private ImageButton imageButtonFavourites;
|
||||
|
@ -71,66 +63,6 @@ public class MainActivity extends AppCompatActivity {
|
|||
|
||||
}
|
||||
|
||||
private void recreateListOfFavs() {
|
||||
|
||||
// check if this is a first call after application start
|
||||
if (favs == null) {
|
||||
favs = favouritiesFile.loadFavourites();
|
||||
}
|
||||
|
||||
// if favs is still null it means that favourites file doesn't even exists
|
||||
// so and user hasn't added any station to it yet
|
||||
if (favs == null) {
|
||||
favs = new ArrayList<>();
|
||||
}
|
||||
else {
|
||||
// update values for the fav list with listOfAllStations
|
||||
//for (WeatherStation f : favs) {
|
||||
for (int i = 0; i < favs.size(); i++) {
|
||||
|
||||
//
|
||||
WeatherStation fromFavs = favs.get(i);
|
||||
|
||||
// find an index of updated station
|
||||
int idx = listOfAllStations.indexOf(fromFavs);
|
||||
|
||||
// get the station
|
||||
WeatherStation fromAllStations = listOfAllStations.get(idx);
|
||||
|
||||
// update all parameters
|
||||
fromFavs.setAvailableParameters(fromAllStations.getAvailableParameters());
|
||||
fromFavs.setMoreInfo(fromAllStations.getMoreInfo());
|
||||
fromFavs.setImageAlign(fromAllStations.getImageAlign());
|
||||
fromFavs.setImageUrl(fromAllStations.getImageUrl());
|
||||
fromFavs.setSponsorUrl(fromAllStations.getSponsorUrl());
|
||||
fromFavs.setMoreInfo(fromAllStations.getMoreInfo());
|
||||
fromFavs.setLon(fromAllStations.getLon());
|
||||
fromFavs.setLat(fromAllStations.getLat());
|
||||
fromFavs.setDisplayedName(fromAllStations.getDisplayedName());
|
||||
fromFavs.setDisplayedLocation(fromAllStations.getDisplayedLocation());
|
||||
fromFavs.setTimezone(fromAllStations.getTimezone());
|
||||
fromFavs.setCallsignSsid(fromAllStations.getCallsignSsid());
|
||||
fromFavs.setStationNameTextColor(fromAllStations.getStationNameTextColor());
|
||||
|
||||
// there is no need to delete and put object on the list once again
|
||||
// as a list does not make a copy of the object. It (ArrayList) keeps
|
||||
// only a reference to an object
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
parceableListOfFavStations = ParceableStationsList.createFromStdList(favs);
|
||||
|
||||
// create an event handler fired when a user click 'favourites' button
|
||||
mainActImageButtonFavouritesClickEvent = new MainActImageButtonFavouritesClickEvent(this, parceableListOfFavStations);
|
||||
|
||||
// assign on click listener
|
||||
if (imageButtonFavourites != null) {
|
||||
imageButtonFavourites.setOnClickListener(mainActImageButtonFavouritesClickEvent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
@ -143,69 +75,45 @@ public class MainActivity extends AppCompatActivity {
|
|||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
recreateListOfFavs();
|
||||
//recreateListOfFavs();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
main = (Main) getApplication();
|
||||
|
||||
baseContext = getApplicationContext();
|
||||
|
||||
StrictMode.VmPolicy.Builder b = new StrictMode.VmPolicy.Builder();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
StrictMode.VmPolicy policy = b.detectAll().detectNonSdkApiUsage().penaltyListener((Runnable r) -> r.run(), (Violation v) -> {v.printStackTrace();}).build();
|
||||
StrictMode.setVmPolicy(policy);
|
||||
}
|
||||
// create an event handler fired when a user click 'favourites' button
|
||||
mainActImageButtonFavouritesClickEvent = new MainActImageButtonFavouritesClickEvent(this);
|
||||
|
||||
// register to Event bus to receive events when a station is added od removed from favourites
|
||||
EventBus.getDefault().register(this);
|
||||
|
||||
AndroidThreeTen.init(this);
|
||||
|
||||
ConfigurationFile confFile = new ConfigurationFile(baseContext);
|
||||
|
||||
confFile.restoreFromFile();
|
||||
|
||||
if (AppConfiguration.locale != null && !AppConfiguration.locale.equals("default") ) {
|
||||
Locale locale = new Locale(AppConfiguration.locale);
|
||||
Locale.setDefault(locale);
|
||||
Resources resources = this.getResources();
|
||||
Configuration config = resources.getConfiguration();
|
||||
config.setLocale(locale);
|
||||
resources.updateConfiguration(config, resources.getDisplayMetrics());
|
||||
// assign on click listener
|
||||
if (imageButtonFavourites != null) {
|
||||
imageButtonFavourites.setOnClickListener(mainActImageButtonFavouritesClickEvent);
|
||||
}
|
||||
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
fileNames = new FileNames(baseContext);
|
||||
|
||||
favouritiesFile = new FavouritiesFile(fileNames);
|
||||
|
||||
// download all stations from API
|
||||
listOfAllStations = new AllStationsDao().getAllStations();
|
||||
|
||||
// convert this to parceable to exchange across intents
|
||||
parceableListOfAllStations = ParceableStationsList.createFromStdList(listOfAllStations);
|
||||
|
||||
// recreate list of favorites
|
||||
recreateListOfFavs();
|
||||
|
||||
ImageButton imageButtonAllStations = (ImageButton)findViewById(R.id.imageButtonAllStations);
|
||||
if (imageButtonAllStations != null)
|
||||
imageButtonAllStations.setOnClickListener(new MainActImageButtonAllStationsClickEvent(this, parceableListOfAllStations));
|
||||
imageButtonAllStations.setOnClickListener(new MainActImageButtonAllStationsClickEvent(this));
|
||||
|
||||
imageButtonFavourites = (ImageButton)findViewById(R.id.imageButtonFavourites);
|
||||
if (imageButtonFavourites != null) {
|
||||
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, parceableListOfFavStations));
|
||||
exportButton.setOnClickListener(new MainActImageButtonExportClickEvent(this));
|
||||
}
|
||||
|
||||
settingsButton = (ImageButton) findViewById(R.id.imageButtonSettings);
|
||||
if (settingsButton != null) {
|
||||
settingsButton.setOnClickListener(new MainActImageButtonSettingsClickEvent(this, confFile));
|
||||
settingsButton.setOnClickListener(new MainActImageButtonSettingsClickEvent(this, main.getConfFile()));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -239,37 +147,4 @@ public class MainActivity extends AppCompatActivity {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void weatherStationListHandler(WeatherStationListEvent serviceEvent) {
|
||||
System.out.println(serviceEvent.toString());
|
||||
|
||||
switch (serviceEvent.getEventReason()) {
|
||||
|
||||
case ADD:
|
||||
// check of list consist this station
|
||||
if (favs.contains(serviceEvent.getStation())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// add favourites to list
|
||||
favs.add(serviceEvent.getStation());
|
||||
|
||||
try {
|
||||
// save the list into JSON file
|
||||
favouritiesFile.persistFavourities(favs);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
break;
|
||||
case DELETE:
|
||||
favs.remove(serviceEvent.getStation());
|
||||
break;
|
||||
}
|
||||
|
||||
// recreate parceable object and pass it everywhere
|
||||
recreateListOfFavs();
|
||||
//Toast.makeText(this, intentServiceResult.getResultValue(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
}
|
|
@ -14,11 +14,10 @@ public class MainActImageButtonAllStationsClickEvent implements View.OnClickList
|
|||
|
||||
Intent intent;
|
||||
|
||||
public MainActImageButtonAllStationsClickEvent(AppCompatActivity parent, ParceableStationsList allStations) {
|
||||
public MainActImageButtonAllStationsClickEvent(AppCompatActivity parent) {
|
||||
this.parent = parent;
|
||||
|
||||
intent = new Intent(this.parent, AllStationsActivity.class);
|
||||
intent.putExtra("all_stations", allStations);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ import android.view.View;
|
|||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import org.tinylog.Logger;
|
||||
|
||||
import cc.pogoda.mobile.meteosystem.activity.ExportDataActivity;
|
||||
import cc.pogoda.mobile.meteosystem.type.ParceableStationsList;
|
||||
|
||||
|
@ -14,16 +16,17 @@ public class MainActImageButtonExportClickEvent implements View.OnClickListener{
|
|||
|
||||
Intent intent;
|
||||
|
||||
public MainActImageButtonExportClickEvent(AppCompatActivity p, ParceableStationsList favs) {
|
||||
public MainActImageButtonExportClickEvent(AppCompatActivity p) {
|
||||
parent = p;
|
||||
|
||||
intent = new Intent(this.parent, ExportDataActivity.class);
|
||||
intent.putExtra("favs", favs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
||||
Logger.info("[MainActImageButtonExportClickEvent][onClick]");
|
||||
|
||||
parent.startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,11 +15,10 @@ public class MainActImageButtonFavouritesClickEvent implements View.OnClickListe
|
|||
|
||||
Intent intent;
|
||||
|
||||
public MainActImageButtonFavouritesClickEvent(AppCompatActivity parent, ParceableStationsList favs) {
|
||||
public MainActImageButtonFavouritesClickEvent(AppCompatActivity parent) {
|
||||
this.parent = parent;
|
||||
|
||||
intent = new Intent(this.parent, FavouritesActivity.class);
|
||||
intent.putExtra("favs", favs);
|
||||
|
||||
ParceableFavsCallReason callReason = new ParceableFavsCallReason(ParceableFavsCallReason.Reason.FAVOURITES);
|
||||
intent.putExtra("callReason", callReason);
|
||||
|
|
|
@ -3,6 +3,7 @@ package cc.pogoda.mobile.meteosystem.file;
|
|||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
@ -29,6 +30,8 @@ public class FavouritiesFile {
|
|||
|
||||
File file = fileNames.getFavJsonFile();
|
||||
|
||||
Logger.info("[FavouritiesFile][loadFavourites][file = " + file + "]");
|
||||
|
||||
try {
|
||||
// create an input stream to load file content
|
||||
FileInputStream fns = new FileInputStream(file);
|
||||
|
@ -56,6 +59,8 @@ public class FavouritiesFile {
|
|||
station.setSystemName(root.getJSONObject(i).getString("systemName"));
|
||||
|
||||
out.add(station);
|
||||
|
||||
Logger.debug("[FavouritiesFile][loadFavourites][i = " + i +"][station.getSystemName() = " + station.getSystemName() + "]");
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
@ -81,6 +86,8 @@ public class FavouritiesFile {
|
|||
// main array for all stations
|
||||
JSONArray mainArray = new JSONArray();
|
||||
|
||||
Logger.info("[FavouritiesFile][persistFavourities][favourites.size() = " + favourites.size() + "]");
|
||||
|
||||
for (WeatherStation wx : favourites) {
|
||||
JSONObject obj = new JSONObject();
|
||||
|
||||
|
@ -95,6 +102,8 @@ public class FavouritiesFile {
|
|||
obj.put("lon", wx.getLon());
|
||||
|
||||
mainArray.put(obj);
|
||||
|
||||
Logger.debug("[FavouritiesFile][persistFavourities][wx.getSystemName() = " + wx.getSystemName() + "]");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
exception = unpack
|
||||
writer1 = logcat
|
||||
writer1.level = TRACE
|
||||
writer1.format = {date: HH:mm:ss.SSS} {tag} {method}({file}:{line}): {message}
|
||||
|
||||
writer2 = rolling file
|
||||
writer2.level = debug
|
||||
writer2.file = #{tinylog.directory}/log_{date:yyyy-MM-dd}.txt
|
||||
writer2.format = {date: HH:mm:ss.SSS} {class}.{method}()\n{level}: {message}
|
||||
writer2.policies = daily
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
exception = unpack
|
||||
writer1 = rolling file
|
||||
writer1.level = debug
|
||||
writer1.file = #{tinylog.directory}/log_{date:yyyy-MM-dd}.txt
|
||||
writer1.backups = 7
|
||||
writer1.format = {date: HH:mm:ss.SSS} {class}.{method}()\n{level}: {message}
|
||||
writer1.policies = daily
|
||||
|
||||
writer2 = logcat
|
||||
writer2.level = TRACE
|
||||
writer2.format = {date: HH:mm:ss.SSS} {class}.{method}()\n{level}: {message}
|
||||
|
Ładowanie…
Reference in New Issue