Compare commits

..

No commits in common. "7498a5ab5e0f13adebb0bd4f20a6c3d771a54e7d" and "d6ab1178e8d76241cea91c638acf6ce03d6c80a4" have entirely different histories.

13 changed files with 38 additions and 252 deletions

View File

@ -44,8 +44,5 @@ dependencies {
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
}

View File

@ -1,34 +0,0 @@
package fr.romanet.vj.apps.myrealestateagency;
import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
public class DollarCurrencyObj implements Serializable {
@SerializedName("rates")
private DollarCurrencyRateObj dollarCurrencyRateObj;
@SerializedName("date")
private String fetchDate;
public DollarCurrencyObj(DollarCurrencyRateObj dollarCurrencyRateObj, String fetchDate) {
this.dollarCurrencyRateObj = dollarCurrencyRateObj;
this.fetchDate = fetchDate;
}
public DollarCurrencyRateObj getDollarCurrencyRateObj() {
return dollarCurrencyRateObj;
}
public void setDollarCurrencyRateObj(DollarCurrencyRateObj dollarCurrencyRateObj) {
this.dollarCurrencyRateObj = dollarCurrencyRateObj;
}
public String getFetchDate() {
return fetchDate;
}
public void setFetchDate(String fetchDate) {
this.fetchDate = fetchDate;
}
}

View File

@ -1,23 +0,0 @@
package fr.romanet.vj.apps.myrealestateagency;
import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
public class DollarCurrencyRateObj implements Serializable {
@SerializedName("USD")
double value;
public DollarCurrencyRateObj(double value) {
this.value = value;
}
public double getValue() {
return value;
}
public void setValue(double value) {
this.value = value;
}
}

View File

@ -3,8 +3,6 @@ package fr.romanet.vj.apps.myrealestateagency.dao;
import androidx.room.Dao;
import androidx.room.Query;
import java.text.DateFormat;
import java.util.Date;
import java.util.List;
import fr.romanet.vj.apps.myrealestateagency.entities.DollarCurrency;
@ -14,7 +12,4 @@ public interface DollarCurrencyDao {
@Query("SELECT * FROM dollar")
List<DollarCurrency> getDollarCurrencyList();
// @Query("UPDATE dollar SET value = :value WHERE fetch_date = :fetchDate")
// void updateDollarRate(double value, Date fetchDate);
}

View File

@ -22,7 +22,7 @@ import fr.romanet.vj.apps.myrealestateagency.dao.AgentDao;
import fr.romanet.vj.apps.myrealestateagency.entities.DollarCurrency;
import fr.romanet.vj.apps.myrealestateagency.entities.Property;
@Database(entities = {Agency.class, Agent.class, Property.class, DollarCurrency.class}, version = 2, exportSchema = false)
@Database(entities = {Agency.class, Agent.class, Property.class, DollarCurrency.class}, version = 1, exportSchema = false)
@TypeConverters({Property.Converters.class})
public abstract class RealEstateAgencyDatabase extends RoomDatabase {

View File

@ -6,15 +6,11 @@ import androidx.room.Entity;
import androidx.room.Index;
import androidx.room.PrimaryKey;
import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
import java.sql.Date;
import java.time.LocalDate;
@Entity(tableName = "dollar",
primaryKeys = {"value", "fetch_date"})
public class DollarCurrency implements Serializable {
public class DollarCurrency {
@NonNull
@ColumnInfo(name = "value")
@ -22,9 +18,9 @@ public class DollarCurrency implements Serializable {
@NonNull
@ColumnInfo(name = "fetch_date")
private String fetchDate;
private Date fetchDate;
public DollarCurrency(@NonNull double value, @NonNull String fetchDate)
public DollarCurrency(@NonNull double value, @NonNull Date fetchDate)
{
this.value = value;
this.fetchDate = fetchDate;
@ -40,12 +36,12 @@ public class DollarCurrency implements Serializable {
this.value = value;
}
public String getFetchDate()
public Date getFetchDate()
{
return fetchDate;
}
public void setFetchDate(String fetchDate)
public void setFetchDate(Date fetchDate)
{
this.fetchDate = fetchDate;
}

View File

@ -1,21 +0,0 @@
package fr.romanet.vj.apps.myrealestateagency.entities;
import com.google.gson.annotations.SerializedName;
public class Rate {
@SerializedName("USD")
private String value;
public Rate(String value) {
this.value = value;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}

View File

@ -1,13 +0,0 @@
package fr.romanet.vj.apps.myrealestateagency.network;
import fr.romanet.vj.apps.myrealestateagency.DollarCurrencyObj;
import fr.romanet.vj.apps.myrealestateagency.entities.DollarCurrency;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Query;
public interface JsonApiInterface {
@GET("latest")
Call<DollarCurrencyObj> getDollarRate(@Query("symbols") String symbols);
}

View File

@ -1,28 +0,0 @@
package fr.romanet.vj.apps.myrealestateagency.repository;
import android.app.Application;
import java.util.Date;
import fr.romanet.vj.apps.myrealestateagency.dao.DollarCurrencyDao;
import fr.romanet.vj.apps.myrealestateagency.database.RealEstateAgencyDatabase;
import fr.romanet.vj.apps.myrealestateagency.entities.DollarCurrency;
public class DollarCurrencyRepository {
private DollarCurrencyDao dollarCurrencyDao;
public DollarCurrencyRepository(Application application) {
RealEstateAgencyDatabase realEstateAgencyDatabase = RealEstateAgencyDatabase.getInstance(application);
dollarCurrencyDao = realEstateAgencyDatabase.dollarCurrencyDao();
}
public DollarCurrency get_dollar_currency_rate()
{
return dollarCurrencyDao.getDollarCurrencyList().get(0);
}
// public void update_dollar_rate(Double value, Date fetch_date){
// dollarCurrencyDao.updateDollarRate(value, fetch_date);
// }
}

View File

@ -1,29 +1,20 @@
package fr.romanet.vj.apps.myrealestateagency.repository;
import android.app.Application;
import android.util.Log;
import androidx.lifecycle.LiveData;
import java.util.List;
import fr.romanet.vj.apps.myrealestateagency.DollarCurrencyObj;
import fr.romanet.vj.apps.myrealestateagency.dao.PropertyDao;
import fr.romanet.vj.apps.myrealestateagency.database.RealEstateAgencyDatabase;
import fr.romanet.vj.apps.myrealestateagency.entities.Agency;
import fr.romanet.vj.apps.myrealestateagency.entities.Property;
import fr.romanet.vj.apps.myrealestateagency.network.JsonApiInterface;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class PropertyRepository {
public PropertyDao propertyDao;
public LiveData<List<Property>> allProperties;
private double dollar_rate;
public PropertyRepository(Application application) {
RealEstateAgencyDatabase realEstateAgencyDatabase = RealEstateAgencyDatabase.getInstance(application);
@ -31,50 +22,6 @@ public class PropertyRepository {
allProperties = propertyDao.getPropertyList();
}
public double get_dollar_rate(){
// - Answer
dollar_rate = 1;
Log.d("CAT", "---------> Call...");
// - Build Retrofit API tool
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.exchangeratesapi.io/")
.addConverterFactory(GsonConverterFactory.create())
.build();
JsonApiInterface jsonApiInterface = retrofit.create(JsonApiInterface.class);
// Call<DollarCurrency> call = jsonApiInterface.getDollarRate("USD");
Call<DollarCurrencyObj> call = jsonApiInterface.getDollarRate("USD");
call.enqueue(new Callback<DollarCurrencyObj>() {
@Override
public void onResponse(Call<DollarCurrencyObj> call, Response<DollarCurrencyObj> response) {
if(! response.isSuccessful()){
Log.d("CAT", "---------> RESP[unsuc]:" + String.valueOf(response.code()));
dollar_rate = -1;
return;
}
Log.d("CAT", "---------> RESP ALL:" + response.toString());
DollarCurrencyObj dollarCurrencyObj = response.body();
Log.d("CAT", "---------> RESP:" + dollarCurrencyObj.getDollarCurrencyRateObj().getValue() + " | " + String.valueOf(dollarCurrencyObj.getFetchDate()));
dollar_rate = dollarCurrencyObj.getDollarCurrencyRateObj().getValue();
}
@Override
public void onFailure(Call<DollarCurrencyObj> call, Throwable t) {
Log.d("CAT", "---------> FAILED:" + String.valueOf(t));
dollar_rate = -1;
return;
}
});
Log.d("CAT", "---------> Call...END");
return dollar_rate;
}
public Property getOnePropertyById(int propertyId){return propertyDao.getOnePropertyById(propertyId);}

View File

@ -129,10 +129,4 @@ public class PropertiesDetailActivity extends AppCompatActivity {
Intent i = new Intent(PropertiesDetailActivity.this, MapsActivity.class);
PropertiesDetailActivity.this.startActivity(i);
}
public void convert_currency(View view){
double price_value = viewModel.convert_currency(property);
price.setText("RRPrice : " + (new DecimalFormat("##.##").format(price_value)));
// price.setText("RRPrice : " + (new DecimalFormat("##.##").format(1.1)));
}
}

View File

@ -1,10 +1,7 @@
package fr.romanet.vj.apps.myrealestateagency.viewmodel;
import android.util.Log;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.SavedStateHandle;
import androidx.lifecycle.Transformations;
import androidx.lifecycle.ViewModel;
import fr.romanet.vj.apps.myrealestateagency.MyApp;
@ -16,34 +13,15 @@ public class PropertiesDetailActivityViewModel extends ViewModel {
public MutableLiveData<Property> property = new MutableLiveData<>();
private PropertyRepository propertyRepository;
private Boolean current_currency_is_eur;
public PropertiesDetailActivityViewModel(SavedStateHandle savedStateHandle)
{
final Property propertyExtra = savedStateHandle.get(PropertiesDetailActivity.PROPERTY_EXTRA);
property.postValue(propertyExtra);
propertyRepository = new PropertyRepository(MyApp.getInstance());
current_currency_is_eur = true;
}
public void deleteProperty()
{
propertyRepository.deleteProperty(property.getValue());
}
public double convert_currency(Property property){
if(current_currency_is_eur){
double dollar_rate = propertyRepository.get_dollar_rate();
double usd_price = property.propertyStatue.price * dollar_rate;
current_currency_is_eur = false;
Log.d("CAT", "----------> Convert was EUR (dollar rate:" + String.valueOf(dollar_rate) + ")");
return usd_price;
}else{
current_currency_is_eur = true;
Log.d("CAT", "----------> Convert was USD");
return property.propertyStatue.price;
}
}
}

View File

@ -1,11 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="12dp"
tools:context=".view.PropertiesDetailActivity">
tools:context=".view.PropertiesDetailActivity"
>
<ImageView
android:id="@+id/avatar"
@ -22,14 +24,13 @@
android:id="@+id/detailsPropertyAddress"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:hint="@string/address"
android:inputType="textPersonName"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@id/detailsPropertyNumberOfRooms"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/avatar" />
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/avatar"
/>
<TextView
android:id="@+id/detailsPropertyType"
@ -38,9 +39,10 @@
android:hint="@string/Type"
android:inputType="textPersonName"
app:layout_constraintBottom_toTopOf="@id/detailsPropertyNumberOfRooms"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/detailsPropertyAddress" />
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/detailsPropertyAddress"
/>
<TextView
android:id="@+id/detailsPropertyNumberOfRooms"
@ -49,9 +51,10 @@
android:hint="@string/Number_of_room"
android:inputType="textPersonName"
app:layout_constraintBottom_toTopOf="@id/detailsPropertyPrice"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/detailsPropertyType" />
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/detailsPropertyType"
/>
<TextView
android:id="@+id/detailsPropertyPrice"
@ -59,7 +62,6 @@
android:layout_height="28dp"
android:hint="@string/price"
android:inputType="phone"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@id/detailsPropertySurface"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/detailsPropertyNumberOfRooms" />
@ -71,9 +73,10 @@
android:hint="@string/surface"
android:inputType="textPersonName"
app:layout_constraintBottom_toTopOf="@id/detailsPropertyLatitude"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/detailsPropertyPrice" />
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/detailsPropertyPrice"
/>
<TextView
android:id="@+id/detailsPropertyLatitude"
@ -103,11 +106,11 @@
android:layout_height="wrap_content"
android:hint="@string/statueSale"
android:inputType="textPersonName"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@id/detailsPropertyDescription"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/detailsPropertyLatitude" />
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/detailsPropertyLatitude"
/>
<TextView
android:id="@+id/detailsPropertyDescription"
@ -116,9 +119,10 @@
android:hint="@string/soldDate"
android:inputType="textMultiLine"
app:layout_constraintBottom_toTopOf="@id/detailsSoldDate"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/detailsPropertyStatueSale" />
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/detailsPropertyStatueSale"
/>
<TextView
android:id="@+id/detailsSoldDate"
@ -126,22 +130,21 @@
android:layout_height="wrap_content"
android:hint="@string/description"
android:inputType="textMultiLine"
android:lines="4"
android:minLines="4"
android:lines="4"
app:layout_constraintBottom_toTopOf="@id/deletePropertyButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/detailsPropertyDescription" />
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/detailsPropertyDescription"
/>
<Button
android:id="@+id/deletePropertyButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#E91E63"
android:backgroundTint="@color/purple_700"
android:text="@string/delete"
android:textColor="@android:color/white"
android:textSize="12sp"
app:icon="@android:drawable/ic_menu_delete"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
@ -153,7 +156,6 @@
android:layout_width="112dp"
android:layout_height="42dp"
android:text="Convert"
android:onClick="convert_currency"
app:layout_constraintBottom_toTopOf="@+id/detailsPropertySurface"
app:layout_constraintEnd_toEndOf="@+id/detailsPropertyNumberOfRooms"
app:layout_constraintHorizontal_bias="0.355"
@ -165,28 +167,24 @@
android:id="@+id/buttonEditProperty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="36dp"
android:text="Edit"
android:textSize="12sp"
app:icon="@android:drawable/ic_menu_edit"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/deletePropertyButton"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/detailsSoldDate"
app:layout_constraintVertical_bias="0.431" />
app:layout_constraintVertical_bias="0.531" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="goto_map"
android:text="Map"
android:textSize="12sp"
app:icon="@android:drawable/ic_dialog_map"
android:onClick="goto_map"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintHorizontal_bias="0.783"
app:layout_constraintStart_toEndOf="@+id/deletePropertyButton"
app:layout_constraintTop_toBottomOf="@+id/detailsSoldDate"
app:layout_constraintVertical_bias="0.49" />
app:layout_constraintVertical_bias="0.546" />
</androidx.constraintlayout.widget.ConstraintLayout>