Edit, add, and delete a property
This commit is contained in:
parent
2e1bdf74aa
commit
ab89d29061
@ -29,13 +29,20 @@
|
||||
|
||||
<activity
|
||||
android:name=".view.PropertiesActivity"
|
||||
android:parentActivityName=".view.AgentsActivity"
|
||||
android:theme="@style/Theme.MyRealEstateAgency"></activity>
|
||||
|
||||
<activity
|
||||
android:name=".view.AddPropertyActivity"
|
||||
android:theme="@style/Theme.MyRealEstateAgency"></activity>
|
||||
|
||||
<activity
|
||||
android:name=".view.PropertiesDetailActivity"
|
||||
android:theme="@style/Theme.MyRealEstateAgency"></activity>
|
||||
|
||||
<activity
|
||||
android:name=".view.EditPropertyActivity"
|
||||
android:theme="@style/Theme.MyRealEstateAgency"></activity>
|
||||
|
||||
<activity android:name=".view.MapsActivity"></activity>
|
||||
<!--
|
||||
The API key for Google Maps-based APIs is defined as a string resource.
|
||||
|
||||
@ -2,6 +2,7 @@ package fr.romanet.vj.apps.myrealestateagency.adapter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -10,9 +11,16 @@ import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView.Adapter;
|
||||
import androidx.recyclerview.widget.RecyclerView.ViewHolder;
|
||||
|
||||
import fr.romanet.vj.apps.myrealestateagency.Config;
|
||||
import fr.romanet.vj.apps.myrealestateagency.MyApp;
|
||||
import fr.romanet.vj.apps.myrealestateagency.adapter.PropertiesAdapter.PropertiesViewHolder;
|
||||
import fr.romanet.vj.apps.myrealestateagency.R;
|
||||
import fr.romanet.vj.apps.myrealestateagency.entities.Property;
|
||||
import fr.romanet.vj.apps.myrealestateagency.view.PropertiesActivity;
|
||||
import fr.romanet.vj.apps.myrealestateagency.view.PropertiesDetailActivity;
|
||||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
|
||||
public class PropertiesAdapter extends Adapter<PropertiesViewHolder> {
|
||||
|
||||
@ -36,7 +44,17 @@ public class PropertiesAdapter extends Adapter<PropertiesViewHolder> {
|
||||
{
|
||||
agencyAddress.setText("Address : " + property.address);
|
||||
agencyDescription.setText("Description : " + property.description);
|
||||
agencyPrice.setText("Price : ");
|
||||
agencyPrice.setText("Price : " + Double.toString(property.propertyStatue.price));
|
||||
itemView.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
final Intent intent = new Intent(itemView.getContext(), PropertiesDetailActivity.class);
|
||||
intent.putExtra(PropertiesDetailActivity.PROPERTY_EXTRA, property);
|
||||
itemView.getContext().startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
private final List<Property> properties;
|
||||
|
||||
@ -2,8 +2,10 @@ package fr.romanet.vj.apps.myrealestateagency.dao;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Delete;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.Update;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -20,4 +22,10 @@ public interface PropertyDao {
|
||||
|
||||
@Insert
|
||||
void insertPreProperties(Property[] properties);
|
||||
|
||||
@Update
|
||||
void updateProperty(Property property);
|
||||
|
||||
@Delete
|
||||
void deleteProperty(Property property);
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ import androidx.room.Index;
|
||||
import androidx.room.PrimaryKey;
|
||||
import androidx.room.TypeConverter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Date;
|
||||
|
||||
import static androidx.room.ForeignKey.CASCADE;
|
||||
@ -18,7 +19,7 @@ import static androidx.room.ForeignKey.CASCADE;
|
||||
parentColumns = "agency_id",
|
||||
childColumns = "belongs_agency_id",
|
||||
onDelete = CASCADE))
|
||||
public class Property {
|
||||
public class Property implements Serializable {
|
||||
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
@ColumnInfo(name = "property_id")
|
||||
@ -31,10 +32,10 @@ public class Property {
|
||||
public String address;
|
||||
|
||||
@ColumnInfo(name = "longitude")
|
||||
public double longitude;
|
||||
public Double longitude;
|
||||
|
||||
@ColumnInfo(name = "latitude")
|
||||
public double latitude;
|
||||
public Double latitude;
|
||||
|
||||
@Embedded
|
||||
public PropertyStatue propertyStatue;
|
||||
@ -57,6 +58,46 @@ public class Property {
|
||||
this.propertyType = propertyType;
|
||||
}
|
||||
|
||||
public Double getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public void setLongitude(Double longitude) {
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
public Double getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public void setLatitude(Double latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
public void setPropertyId(int propertyId) {
|
||||
this.propertyId = propertyId;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public void setPropertyStatue(PropertyStatue propertyStatue) {
|
||||
this.propertyStatue = propertyStatue;
|
||||
}
|
||||
|
||||
public void setBelongsToAgencyId(int belongsToAgencyId) {
|
||||
this.belongsToAgencyId = belongsToAgencyId;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public void setPropertyType(PropertyType propertyType) {
|
||||
this.propertyType = propertyType;
|
||||
}
|
||||
|
||||
public static class Converters {
|
||||
|
||||
@TypeConverter
|
||||
@ -72,8 +113,8 @@ public class Property {
|
||||
|
||||
public static Property[] populatePropertyTable() {
|
||||
return new Property[]{
|
||||
new Property("Amazing property in the best district of Paris", "15 rue Champs-Elysée", 15.8, 17.8, 1,
|
||||
new PropertyStatue(false, null, 15.8), new PropertyType("Appartment", 3, 9.8))
|
||||
new Property("Amazing property in the best district of Le Chesnay", "3 rue du docteur audigier", 15.8, 17.8, 1,
|
||||
new PropertyStatue(false, null, 15.8), new PropertyType("Apartment", 3, 9.8))
|
||||
//new Property("Best appartment in Velizy-Villacoublay", "Rue de Villacoublay, 78140 Vélizy-Villacoublay", 19.8, 20.8, 1),
|
||||
//new Property("Amazing property in the best district of Marseille", "15 rue de Marseille", 15.8, 17.8, 1),
|
||||
};
|
||||
|
||||
@ -4,9 +4,10 @@ import androidx.annotation.Nullable;
|
||||
import androidx.room.ColumnInfo;
|
||||
import androidx.room.Embedded;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Date;
|
||||
|
||||
public class PropertyStatue{
|
||||
public class PropertyStatue implements Serializable {
|
||||
|
||||
@ColumnInfo(name = "statue_sale")
|
||||
public boolean statueSale;
|
||||
@ -24,4 +25,16 @@ public class PropertyStatue{
|
||||
this.soldDate = soldDate;
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public void setPrice(double price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public void setSoldDate(@Nullable Date soldDate) {
|
||||
this.soldDate = soldDate;
|
||||
}
|
||||
|
||||
public void setStatueSale(boolean statueSale) {
|
||||
this.statueSale = statueSale;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,7 +2,9 @@ package fr.romanet.vj.apps.myrealestateagency.entities;
|
||||
|
||||
import androidx.room.ColumnInfo;
|
||||
|
||||
public class PropertyType {
|
||||
import java.io.Serializable;
|
||||
|
||||
public class PropertyType implements Serializable {
|
||||
|
||||
@ColumnInfo(name = "type_description")
|
||||
public String typeDescription;
|
||||
@ -20,4 +22,15 @@ public class PropertyType {
|
||||
this.surfaceArea = surfaceArea;
|
||||
}
|
||||
|
||||
public void setNumberRooms(int numberRooms) {
|
||||
this.numberRooms = numberRooms;
|
||||
}
|
||||
|
||||
public void setSurfaceArea(double surfaceArea) {
|
||||
this.surfaceArea = surfaceArea;
|
||||
}
|
||||
|
||||
public void setTypeDescription(String typeDescription) {
|
||||
this.typeDescription = typeDescription;
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,4 +29,8 @@ public class PropertyRepository {
|
||||
{
|
||||
propertyDao.insertProperty(property);
|
||||
}
|
||||
|
||||
public void updateProperty(Property property) {propertyDao.updateProperty(property);}
|
||||
|
||||
public void deleteProperty(Property property){propertyDao.deleteProperty(property);}
|
||||
}
|
||||
@ -101,8 +101,8 @@ public class AddPropertyActivity extends AppCompatActivity implements OnClickLis
|
||||
final String propertyType = type.getEditableText().toString();
|
||||
final int propertyNumberRooms = Integer.parseInt(numberRooms.getEditableText().toString());
|
||||
final double propertyPrice = Double.parseDouble(price.getEditableText().toString());
|
||||
final double propertySurface = Double.parseDouble(numberRooms.getEditableText().toString());
|
||||
final String propertyDescription = price.getEditableText().toString();
|
||||
final double propertySurface = Double.parseDouble(surface.getEditableText().toString());
|
||||
final String propertyDescription = description.getEditableText().toString();
|
||||
|
||||
try {
|
||||
viewModel.saveProperty(propertyAddress, propertyType, propertyNumberRooms, propertyPrice, propertySurface, propertyDescription);
|
||||
|
||||
@ -59,7 +59,6 @@ final public class AgentsActivity extends AppCompatActivity{
|
||||
viewModel.setAgents();
|
||||
final AgentsAdapter usersAdapter = new AgentsAdapter(users);
|
||||
recyclerView.setAdapter(usersAdapter);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -0,0 +1,118 @@
|
||||
package fr.romanet.vj.apps.myrealestateagency.view;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.lifecycle.SavedStateViewModelFactory;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import fr.romanet.vj.apps.myrealestateagency.MyApp;
|
||||
import fr.romanet.vj.apps.myrealestateagency.R;
|
||||
import fr.romanet.vj.apps.myrealestateagency.entities.Property;
|
||||
import fr.romanet.vj.apps.myrealestateagency.repository.PropertyRepository;
|
||||
import fr.romanet.vj.apps.myrealestateagency.viewmodel.EditPropertyActivityViewModel;
|
||||
import fr.romanet.vj.apps.myrealestateagency.viewmodel.PropertiesDetailActivityViewModel;
|
||||
|
||||
public class EditPropertyActivity extends AppCompatActivity {
|
||||
|
||||
public static final String PROPERTY_EXTRA = "PropertyExtra";
|
||||
|
||||
public EditPropertyActivityViewModel viewModel;
|
||||
|
||||
private Property property;
|
||||
|
||||
private TextView type;
|
||||
|
||||
private TextView numberRooms;
|
||||
|
||||
private TextView price;
|
||||
|
||||
private TextView surface;
|
||||
|
||||
private TextView statue;
|
||||
|
||||
private TextView dateOfSale;
|
||||
|
||||
private TextView description;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_edit_property);
|
||||
viewModel = new ViewModelProvider(this, new SavedStateViewModelFactory(getApplication(), this, getIntent().getExtras())).get(EditPropertyActivityViewModel.class);
|
||||
|
||||
type = findViewById(R.id.editPropertyType);
|
||||
numberRooms = findViewById(R.id.editPropertyNumberOfRooms);
|
||||
price = findViewById(R.id.editPropertyPrice);
|
||||
surface = findViewById(R.id.editPropertySurface);
|
||||
statue = findViewById(R.id.editPropertyStatueSale);
|
||||
dateOfSale = findViewById(R.id.editPropertySoldDate);
|
||||
description = findViewById(R.id.editPropertyDescription);
|
||||
property = (Property) getIntent().getSerializableExtra("PropertyExtra");
|
||||
setForm();
|
||||
findViewById(R.id.editPropertyButton).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
final String propertyTypeEdit = type.getEditableText().toString();
|
||||
final int propertyNumberRoomsEdit = Integer.parseInt(numberRooms.getEditableText().toString());
|
||||
final double propertyPriceEdit = Double.parseDouble(price.getEditableText().toString());
|
||||
final double propertySurfaceEdit = Double.parseDouble(surface.getEditableText().toString());
|
||||
final String propertyDescriptionEdit = description.getEditableText().toString();
|
||||
property.propertyType.setTypeDescription(propertyTypeEdit);
|
||||
property.propertyType.setNumberRooms(propertyNumberRoomsEdit);
|
||||
property.propertyStatue.setPrice(propertyPriceEdit);
|
||||
property.propertyType.setSurfaceArea(propertySurfaceEdit);
|
||||
property.setDescription(propertyDescriptionEdit);
|
||||
PropertyRepository propertyRepository = new PropertyRepository(MyApp.getInstance());
|
||||
propertyRepository.updateProperty(property);
|
||||
finish();
|
||||
final Intent intent = new Intent(EditPropertyActivity.this, PropertiesDetailActivity.class);
|
||||
intent.putExtra(PropertiesDetailActivity.PROPERTY_EXTRA, property);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setForm()
|
||||
{
|
||||
Date date = Calendar.getInstance().getTime();
|
||||
DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd");
|
||||
boolean sale = property.propertyStatue.statueSale;
|
||||
String saleOrNot;
|
||||
String dateOfSaleString;
|
||||
if(sale == true)
|
||||
{
|
||||
saleOrNot = "sold";
|
||||
type.setText(property.propertyType.typeDescription);
|
||||
numberRooms.setText(Integer.toString(property.propertyType.numberRooms));
|
||||
price.setText((new DecimalFormat("##.##").format(property.propertyStatue.price)));
|
||||
surface.setText((new DecimalFormat("##.##").format(property.propertyType.surfaceArea)));
|
||||
statue.setText(saleOrNot);
|
||||
dateOfSale.setText(dateFormat.format(property.propertyStatue.soldDate));
|
||||
description.setText(property.description);
|
||||
}
|
||||
else
|
||||
{
|
||||
saleOrNot = "Not sold";
|
||||
dateOfSaleString = "No date of sale";
|
||||
type.setText(property.propertyType.typeDescription);
|
||||
numberRooms.setText(Integer.toString(property.propertyType.numberRooms));
|
||||
price.setText((new DecimalFormat("##.##").format(property.propertyStatue.price)));
|
||||
surface.setText((new DecimalFormat("##.##").format(property.propertyType.surfaceArea)));
|
||||
statue.setText(saleOrNot);
|
||||
dateOfSale.setText(dateOfSaleString);
|
||||
description.setText(property.description);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,127 @@
|
||||
package fr.romanet.vj.apps.myrealestateagency.view;
|
||||
|
||||
public class PropertiesDetailActivity {
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.lifecycle.SavedStateViewModelFactory;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import fr.romanet.vj.apps.myrealestateagency.R;
|
||||
import fr.romanet.vj.apps.myrealestateagency.entities.Property;
|
||||
import fr.romanet.vj.apps.myrealestateagency.viewmodel.PropertiesDetailActivityViewModel;
|
||||
|
||||
public class PropertiesDetailActivity extends AppCompatActivity {
|
||||
|
||||
public static final String PROPERTY_EXTRA = "PropertyExtra";
|
||||
|
||||
public PropertiesDetailActivityViewModel viewModel;
|
||||
|
||||
private Property property;
|
||||
|
||||
private TextView address;
|
||||
|
||||
private TextView type;
|
||||
|
||||
private TextView numberRooms;
|
||||
|
||||
private TextView price;
|
||||
|
||||
private TextView surface;
|
||||
|
||||
private TextView latitude;
|
||||
|
||||
private TextView longitude;
|
||||
|
||||
private TextView statue;
|
||||
|
||||
private TextView dateOfSale;
|
||||
|
||||
private TextView description;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_details_property);
|
||||
viewModel = new ViewModelProvider(this, new SavedStateViewModelFactory(getApplication(), this, getIntent().getExtras())).get(PropertiesDetailActivityViewModel.class);
|
||||
|
||||
address = findViewById(R.id.detailsPropertyAddress);
|
||||
type = findViewById(R.id.detailsPropertyType);
|
||||
numberRooms = findViewById(R.id.detailsPropertyNumberOfRooms);
|
||||
price = findViewById(R.id.detailsPropertyPrice);
|
||||
surface = findViewById(R.id.detailsPropertySurface);
|
||||
latitude = findViewById(R.id.detailsPropertyLatitude);
|
||||
longitude = findViewById(R.id.detailsPropertyLongitude);
|
||||
statue = findViewById(R.id.detailsPropertyStatueSale);
|
||||
dateOfSale = findViewById(R.id.detailsSoldDate);
|
||||
description = findViewById(R.id.detailsPropertyDescription);
|
||||
property = (Property) getIntent().getSerializableExtra("PropertyExtra");
|
||||
setForm();
|
||||
findViewById(R.id.deletePropertyButton).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
finish();
|
||||
viewModel.deleteProperty();
|
||||
}
|
||||
});
|
||||
|
||||
findViewById(R.id.buttonEditProperty).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
onPause();
|
||||
final Intent intent = new Intent(PropertiesDetailActivity.this, EditPropertyActivity.class);
|
||||
intent.putExtra(EditPropertyActivity.PROPERTY_EXTRA, property);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setForm()
|
||||
{
|
||||
Date date = Calendar.getInstance().getTime();
|
||||
DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd");
|
||||
boolean sale = property.propertyStatue.statueSale;
|
||||
String saleOrNot;
|
||||
String dateOfSaleString;
|
||||
if(sale == true)
|
||||
{
|
||||
saleOrNot = "sold";
|
||||
address.setText("Address : " + property.address);
|
||||
type.setText("Type : " + property.propertyType.typeDescription);
|
||||
numberRooms.setText("Number of rooms : " + Integer.toString(property.propertyType.numberRooms));
|
||||
price.setText("Price : " + (new DecimalFormat("##.##").format(property.propertyStatue.price)));
|
||||
surface.setText("Surface : " + (new DecimalFormat("##.##").format(property.propertyType.surfaceArea)));
|
||||
latitude.setText("Latitude : " + (new DecimalFormat("##.##").format(property.latitude)));
|
||||
longitude.setText("Longitude : " + (new DecimalFormat("##.##").format(property.longitude)));
|
||||
statue.setText("Statue : " + saleOrNot);
|
||||
dateOfSale.setText("Date of sale : " + dateFormat.format(property.propertyStatue.soldDate));
|
||||
description.setText("Description : " + property.description);
|
||||
}
|
||||
else
|
||||
{
|
||||
saleOrNot = "Not sold";
|
||||
dateOfSaleString = "No date of sale";
|
||||
address.setText("Address : " + property.address);
|
||||
type.setText("Type : " + property.propertyType.typeDescription);
|
||||
numberRooms.setText("Number of rooms : " + Integer.toString(property.propertyType.numberRooms));
|
||||
price.setText("Price : " + (new DecimalFormat("##.##").format(property.propertyStatue.price)));
|
||||
surface.setText("Surface : " + (new DecimalFormat("##.##").format(property.propertyType.surfaceArea)));
|
||||
latitude.setText("Latitude : " + (new DecimalFormat("##.##").format(property.latitude)));
|
||||
longitude.setText("Longitude : " + (new DecimalFormat("##.##").format(property.longitude)));
|
||||
statue.setText("Statue : " + saleOrNot);
|
||||
dateOfSale.setText("Date of sale : " + dateOfSaleString);
|
||||
description.setText("Description : " + property.description);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,27 @@
|
||||
package fr.romanet.vj.apps.myrealestateagency.viewmodel;
|
||||
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.SavedStateHandle;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import fr.romanet.vj.apps.myrealestateagency.MyApp;
|
||||
import fr.romanet.vj.apps.myrealestateagency.entities.Property;
|
||||
import fr.romanet.vj.apps.myrealestateagency.repository.PropertyRepository;
|
||||
import fr.romanet.vj.apps.myrealestateagency.view.PropertiesDetailActivity;
|
||||
|
||||
public class EditPropertyActivityViewModel extends ViewModel {
|
||||
public MutableLiveData<Property> property = new MutableLiveData<>();
|
||||
private PropertyRepository propertyRepository;
|
||||
|
||||
public EditPropertyActivityViewModel(SavedStateHandle savedStateHandle)
|
||||
{
|
||||
final Property propertyExtra = savedStateHandle.get(PropertiesDetailActivity.PROPERTY_EXTRA);
|
||||
property.postValue(propertyExtra);
|
||||
propertyRepository = new PropertyRepository(MyApp.getInstance());
|
||||
}
|
||||
|
||||
public void editProperty()
|
||||
{
|
||||
propertyRepository.updateProperty(property.getValue());
|
||||
}
|
||||
}
|
||||
@ -1,26 +1,32 @@
|
||||
package fr.romanet.vj.apps.myrealestateagency.viewmodel;
|
||||
|
||||
import android.app.Application;
|
||||
import android.location.Address;
|
||||
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import fr.romanet.vj.apps.myrealestateagency.MyApp;
|
||||
import fr.romanet.vj.apps.myrealestateagency.entities.Agency;
|
||||
import fr.romanet.vj.apps.myrealestateagency.entities.Property;
|
||||
import fr.romanet.vj.apps.myrealestateagency.repository.AgencyRepository;
|
||||
import fr.romanet.vj.apps.myrealestateagency.repository.MapsActivityRepository;
|
||||
import fr.romanet.vj.apps.myrealestateagency.repository.PropertyRepository;
|
||||
|
||||
public class PropertiesActivityViewModel extends AndroidViewModel {
|
||||
|
||||
public AgencyRepository agencyRepository;
|
||||
public PropertyRepository propertyRepository;
|
||||
public LiveData<List<Property>> properties = new MutableLiveData<>();
|
||||
|
||||
public PropertiesActivityViewModel(Application application, Agency agency)
|
||||
{
|
||||
public PropertiesActivityViewModel(Application application, Agency agency) throws IOException {
|
||||
super(application);
|
||||
agencyRepository = new AgencyRepository(application);
|
||||
propertyRepository = new PropertyRepository(application);
|
||||
properties = agencyRepository.getProperties(agency);
|
||||
}
|
||||
|
||||
@ -28,6 +34,16 @@ public class PropertiesActivityViewModel extends AndroidViewModel {
|
||||
{
|
||||
properties = agencyRepository.getProperties(agency);
|
||||
}
|
||||
|
||||
public void setLonLat() throws IOException {
|
||||
for(int i = 0; i < properties.getValue().size(); i++)
|
||||
{
|
||||
Address address = MapsActivityRepository.get_lat_long_from_address(properties.getValue().get(i).address, MyApp.getContext());
|
||||
properties.getValue().get(i).setLongitude(address.getLongitude());
|
||||
properties.getValue().get(i).setLatitude(address.getLatitude());
|
||||
propertyRepository.updateProperty(properties.getValue().get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -5,6 +5,8 @@ import android.app.Application;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import fr.romanet.vj.apps.myrealestateagency.entities.Agency;
|
||||
|
||||
public class PropertiesActivityViewModelFactory implements ViewModelProvider.Factory {
|
||||
@ -20,6 +22,11 @@ public class PropertiesActivityViewModelFactory implements ViewModelProvider.Fac
|
||||
|
||||
@Override
|
||||
public <T extends ViewModel> T create(Class<T> modelClass) {
|
||||
try {
|
||||
return (T) new PropertiesActivityViewModel(mApplication, mParam);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
package fr.romanet.vj.apps.myrealestateagency.viewmodel;
|
||||
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.SavedStateHandle;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import fr.romanet.vj.apps.myrealestateagency.MyApp;
|
||||
import fr.romanet.vj.apps.myrealestateagency.entities.Property;
|
||||
import fr.romanet.vj.apps.myrealestateagency.repository.PropertyRepository;
|
||||
import fr.romanet.vj.apps.myrealestateagency.view.PropertiesDetailActivity;
|
||||
|
||||
public class PropertiesDetailActivityViewModel extends ViewModel {
|
||||
public MutableLiveData<Property> property = new MutableLiveData<>();
|
||||
private PropertyRepository propertyRepository;
|
||||
|
||||
public PropertiesDetailActivityViewModel(SavedStateHandle savedStateHandle)
|
||||
{
|
||||
final Property propertyExtra = savedStateHandle.get(PropertiesDetailActivity.PROPERTY_EXTRA);
|
||||
property.postValue(propertyExtra);
|
||||
propertyRepository = new PropertyRepository(MyApp.getInstance());
|
||||
}
|
||||
|
||||
public void deleteProperty()
|
||||
{
|
||||
propertyRepository.deleteProperty(property.getValue());
|
||||
}
|
||||
}
|
||||
@ -11,15 +11,14 @@
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/avatar"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="116dp"
|
||||
android:layout_height="80dp"
|
||||
android:src="@drawable/ic_house"
|
||||
app:layout_constraintBottom_toTopOf="@id/addPropertyAddress"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_chainStyle="spread"
|
||||
/>
|
||||
app:layout_constraintVertical_chainStyle="spread" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/addPropertyAddress"
|
||||
|
||||
189
app/src/main/res/layout/activity_details_property.xml
Normal file
189
app/src/main/res/layout/activity_details_property.xml
Normal file
@ -0,0 +1,189 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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"
|
||||
>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/avatar"
|
||||
android:layout_width="148dp"
|
||||
android:layout_height="106dp"
|
||||
android:src="@drawable/ic_house"
|
||||
app:layout_constraintBottom_toTopOf="@id/detailsPropertyAddress"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_chainStyle="spread" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/detailsPropertyAddress"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/address"
|
||||
android:inputType="textPersonName"
|
||||
app:layout_constraintBottom_toTopOf="@id/detailsPropertyNumberOfRooms"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/avatar"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/detailsPropertyType"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/Type"
|
||||
android:inputType="textPersonName"
|
||||
app:layout_constraintBottom_toTopOf="@id/detailsPropertyNumberOfRooms"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/detailsPropertyAddress"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/detailsPropertyNumberOfRooms"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/Number_of_room"
|
||||
android:inputType="textPersonName"
|
||||
app:layout_constraintBottom_toTopOf="@id/detailsPropertyPrice"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/detailsPropertyType"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/detailsPropertyPrice"
|
||||
android:layout_width="157dp"
|
||||
android:layout_height="28dp"
|
||||
android:hint="@string/price"
|
||||
android:inputType="phone"
|
||||
app:layout_constraintBottom_toTopOf="@id/detailsPropertySurface"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/detailsPropertyNumberOfRooms" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/detailsPropertySurface"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/surface"
|
||||
android:inputType="textPersonName"
|
||||
app:layout_constraintBottom_toTopOf="@id/detailsPropertyLatitude"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/detailsPropertyPrice"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/detailsPropertyLatitude"
|
||||
android:layout_width="111dp"
|
||||
android:layout_height="19dp"
|
||||
android:hint="@string/latitude"
|
||||
android:inputType="textPersonName"
|
||||
app:layout_constraintBottom_toTopOf="@id/detailsPropertyStatueSale"
|
||||
app:layout_constraintHorizontal_bias="0.646"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/detailsPropertySurface" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/detailsPropertyLongitude"
|
||||
android:layout_width="111dp"
|
||||
android:layout_height="19dp"
|
||||
android:layout_marginStart="200dp"
|
||||
android:hint="@string/longitude"
|
||||
android:inputType="textPersonName"
|
||||
app:layout_constraintBottom_toTopOf="@id/detailsPropertyStatueSale"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/detailsPropertySurface" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/detailsPropertyStatueSale"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/statueSale"
|
||||
android:inputType="textPersonName"
|
||||
app:layout_constraintBottom_toTopOf="@id/detailsPropertyDescription"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/detailsPropertyLatitude"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/detailsPropertyDescription"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/soldDate"
|
||||
android:inputType="textMultiLine"
|
||||
app:layout_constraintBottom_toTopOf="@id/detailsSoldDate"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/detailsPropertyStatueSale"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/detailsSoldDate"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/description"
|
||||
android:inputType="textMultiLine"
|
||||
android:minLines="4"
|
||||
android:lines="4"
|
||||
app:layout_constraintBottom_toTopOf="@id/deletePropertyButton"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
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="@color/purple_700"
|
||||
android:text="@string/delete"
|
||||
android:textColor="@android:color/white"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.498"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/detailsSoldDate" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button"
|
||||
android:layout_width="112dp"
|
||||
android:layout_height="42dp"
|
||||
android:text="Convert"
|
||||
app:layout_constraintBottom_toTopOf="@+id/detailsPropertySurface"
|
||||
app:layout_constraintEnd_toEndOf="@+id/detailsPropertyNumberOfRooms"
|
||||
app:layout_constraintHorizontal_bias="0.355"
|
||||
app:layout_constraintStart_toEndOf="@+id/detailsPropertyPrice"
|
||||
app:layout_constraintTop_toBottomOf="@+id/detailsPropertyNumberOfRooms"
|
||||
app:layout_constraintVertical_bias="0.307" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonEditProperty"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="36dp"
|
||||
android:text="Edit"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/deletePropertyButton"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/detailsSoldDate"
|
||||
app:layout_constraintVertical_bias="0.531" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Map"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.783"
|
||||
app:layout_constraintStart_toEndOf="@+id/deletePropertyButton"
|
||||
app:layout_constraintTop_toBottomOf="@+id/detailsSoldDate"
|
||||
app:layout_constraintVertical_bias="0.546" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
143
app/src/main/res/layout/activity_edit_property.xml
Normal file
143
app/src/main/res/layout/activity_edit_property.xml
Normal file
@ -0,0 +1,143 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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.EditPropertyActivity"
|
||||
>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/avatar"
|
||||
android:layout_width="105dp"
|
||||
android:layout_height="82dp"
|
||||
android:src="@drawable/ic_house"
|
||||
app:layout_constraintBottom_toTopOf="@id/editPropertyType"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_chainStyle="spread" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editPropertyType"
|
||||
android:layout_width="268dp"
|
||||
android:layout_height="43dp"
|
||||
android:hint="@string/Type"
|
||||
android:inputType="textPersonName"
|
||||
app:layout_constraintBottom_toTopOf="@id/editPropertyPrice"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/avatar" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editPropertyNumberOfRooms"
|
||||
android:layout_width="276dp"
|
||||
android:layout_height="45dp"
|
||||
android:hint="@string/Number_of_room"
|
||||
android:inputType="textPersonName"
|
||||
app:layout_constraintBottom_toTopOf="@id/editPropertyPrice"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="@+id/editPropertyType"
|
||||
app:layout_constraintTop_toBottomOf="@id/editPropertyType" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editPropertyPrice"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/price"
|
||||
android:inputType="textPersonName"
|
||||
app:layout_constraintBottom_toTopOf="@id/editPropertySurface"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/editPropertyNumberOfRooms"
|
||||
/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editPropertySurface"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/surface"
|
||||
android:inputType="phone"
|
||||
app:layout_constraintBottom_toTopOf="@id/editPropertyStatueSale"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/editPropertyPrice"
|
||||
/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editPropertyStatueSale"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/statueSale"
|
||||
android:inputType="textPersonName"
|
||||
app:layout_constraintBottom_toTopOf="@id/editPropertySoldDate"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/editPropertySurface"
|
||||
/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editPropertySoldDate"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/soldDate"
|
||||
android:inputType="textPersonName"
|
||||
app:layout_constraintBottom_toTopOf="@id/editPropertyDescription"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/editPropertyStatueSale"
|
||||
/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editPropertyDescription"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/description"
|
||||
android:inputType="textMultiLine"
|
||||
android:minLines="4"
|
||||
android:lines="4"
|
||||
app:layout_constraintBottom_toTopOf="@id/editPropertyButton"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/editPropertySoldDate"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/editPropertyButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:backgroundTint="@color/purple_700"
|
||||
android:text="@string/save"
|
||||
android:textColor="@android:color/white"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/editPropertyDescription"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="98dp"
|
||||
android:layout_height="40dp"
|
||||
android:text="@string/Type"
|
||||
app:layout_constraintBottom_toTopOf="@+id/editPropertyNumberOfRooms"
|
||||
app:layout_constraintEnd_toStartOf="@+id/editPropertyType"
|
||||
app:layout_constraintHorizontal_bias="0.035"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/avatar"
|
||||
app:layout_constraintVertical_bias="0.804" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="93dp"
|
||||
android:layout_height="52dp"
|
||||
android:layout_marginEnd="40dp"
|
||||
android:text="@string/Number_of_room"
|
||||
app:layout_constraintBottom_toTopOf="@+id/editPropertyPrice"
|
||||
app:layout_constraintEnd_toStartOf="@+id/editPropertyNumberOfRooms"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView"
|
||||
app:layout_constraintVertical_bias="0.47" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@ -11,6 +11,10 @@
|
||||
<string name="delete">Delete</string>
|
||||
<string name="map">Map</string>
|
||||
<string name="surface">Surface</string>
|
||||
<string name="statueSale">Statue</string>
|
||||
<string name="soldDate">Date of Sold</string>
|
||||
<string name="latitude">Latitude</string>
|
||||
<string name="longitude">Longitude</string>
|
||||
<string name="cannot_add_property">Cannot add the property</string>
|
||||
<string name="converter">Convert</string>
|
||||
</resources>
|
||||
Loading…
Reference in New Issue
Block a user