diff --git a/app/src/main/java/fr/romanet/vj/apps/myweather/ICityService.java b/app/src/main/java/fr/romanet/vj/apps/myweather/ICityService.java index 5fa52d2..44a60dd 100644 --- a/app/src/main/java/fr/romanet/vj/apps/myweather/ICityService.java +++ b/app/src/main/java/fr/romanet/vj/apps/myweather/ICityService.java @@ -24,6 +24,11 @@ public interface ICityService */ void addCity(City cityToAdd); + /** + * Updating the fields of a specific city + */ + void updateCity(City cityToUpdate); + /** * Get all cities sorted by name * @return {@link List} diff --git a/app/src/main/java/fr/romanet/vj/apps/myweather/bo/City.java b/app/src/main/java/fr/romanet/vj/apps/myweather/bo/City.java index 8572a06..13d7b51 100644 --- a/app/src/main/java/fr/romanet/vj/apps/myweather/bo/City.java +++ b/app/src/main/java/fr/romanet/vj/apps/myweather/bo/City.java @@ -30,7 +30,7 @@ final public class City implements Serializable } /** - * The primary key of the city in our datbase which is automatically incremented + * The primary key of the city in our database which is automatically incremented */ @PrimaryKey(autoGenerate = true) public int id; @@ -40,16 +40,21 @@ final public class City implements Serializable */ @NonNull public String nameCity; + @Nullable - public String w_icon; + public String w_icon = null; + @Nullable - public String w_temp; + public String w_temp = null; + @Nullable - public String w_feelsliketemp; + public String w_feelsliketemp = null; + @Nullable - public String w_mintemp; + public String w_mintemp = null; + @Nullable - public String w_maxtemp; + public String w_maxtemp = null; /** * Constructor of the city class @@ -61,6 +66,26 @@ final public class City implements Serializable this.nameCity = nameCity; } + public void setW_icon(@Nullable String w_icon) { + this.w_icon = w_icon; + } + + public void setW_temp(@Nullable String w_temp) { + this.w_temp = w_temp; + } + + public void setW_feelsliketemp(@Nullable String w_feelsliketemp) { + this.w_feelsliketemp = w_feelsliketemp; + } + + public void setW_mintemp(@Nullable String w_mintemp) { + this.w_mintemp = w_mintemp; + } + + public void setW_maxtemp(@Nullable String w_maxtemp) { + this.w_maxtemp = w_maxtemp; + } + /** * Equals function that return true or false weither both name are same and both object belongs to City class * @param o The object to compare @@ -68,26 +93,20 @@ final public class City implements Serializable */ @Override public boolean equals(Object o) { - if (this == o) - { - return true; - } - if (o == null || getClass() != o.getClass()) - { - return false; - } - City city1 = (City) o; - - return nameCity.equals(city1.nameCity); + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + City city = (City) o; + return id == city.id && + nameCity.equals(city.nameCity) && + Objects.equals(w_icon, city.w_icon) && + Objects.equals(w_temp, city.w_temp) && + Objects.equals(w_feelsliketemp, city.w_feelsliketemp) && + Objects.equals(w_mintemp, city.w_mintemp) && + Objects.equals(w_maxtemp, city.w_maxtemp); } - /** - * hashCode function - * @return Clé de hashage (int) - */ @Override - public int hashCode() - { - return Objects.hash(nameCity); + public int hashCode() { + return Objects.hash(id, nameCity, w_icon, w_temp, w_feelsliketemp, w_mintemp, w_maxtemp); } } diff --git a/app/src/main/java/fr/romanet/vj/apps/myweather/dao/CityDao.java b/app/src/main/java/fr/romanet/vj/apps/myweather/dao/CityDao.java index 363da0e..ddb53d7 100644 --- a/app/src/main/java/fr/romanet/vj/apps/myweather/dao/CityDao.java +++ b/app/src/main/java/fr/romanet/vj/apps/myweather/dao/CityDao.java @@ -5,6 +5,8 @@ import androidx.room.Delete; import androidx.room.Insert; import androidx.room.OnConflictStrategy; import androidx.room.Query; +import androidx.room.Update; + import fr.romanet.vj.apps.myweather.ICityService; import fr.romanet.vj.apps.myweather.bo.City; import java.util.List; @@ -24,7 +26,11 @@ public interface CityDao extends ICityService @Insert(onConflict = OnConflictStrategy.REPLACE) void addCity(City cityToAdd); + @Update + void updateCity(City cityToUpdate); + @Override @Query("SELECT * FROM City ORDER BY nameCity DESC") List sortCityByName(); + } diff --git a/app/src/main/java/fr/romanet/vj/apps/myweather/repository/CityRepository.java b/app/src/main/java/fr/romanet/vj/apps/myweather/repository/CityRepository.java index 84635f8..fdfb35b 100644 --- a/app/src/main/java/fr/romanet/vj/apps/myweather/repository/CityRepository.java +++ b/app/src/main/java/fr/romanet/vj/apps/myweather/repository/CityRepository.java @@ -48,6 +48,8 @@ public final class CityRepository cityDatabase.cityDao().addCity(cityToAdd); } + public void updateCity(City cityToUpdate) {cityDatabase.cityDao().updateCity(cityToUpdate);} + public List sortCityByName() { return cityDatabase.cityDao().sortCityByName();