diff --git a/app/src/main/java/fr/romanet/vj/apps/myrealestateagency/view/EditPropertyActivity.java b/app/src/main/java/fr/romanet/vj/apps/myrealestateagency/view/EditPropertyActivity.java index 25c2221..782e6a6 100644 --- a/app/src/main/java/fr/romanet/vj/apps/myrealestateagency/view/EditPropertyActivity.java +++ b/app/src/main/java/fr/romanet/vj/apps/myrealestateagency/view/EditPropertyActivity.java @@ -11,6 +11,7 @@ import androidx.lifecycle.ViewModelProvider; import java.text.DateFormat; import java.text.DecimalFormat; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; @@ -63,16 +64,34 @@ public class EditPropertyActivity extends AppCompatActivity { @Override public void onClick(View view) { + boolean soldOrNot; + Date dateToEdit = null; + try { + dateToEdit = new SimpleDateFormat("yyyy-MM-dd").parse(dateOfSale.getEditableText().toString()); + } catch (ParseException e) { + e.printStackTrace(); + } 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(); + final String sold = statue.getEditableText().toString(); + if(sold == "Sold") + { + soldOrNot = true; + } + else + { + soldOrNot = false; + } property.propertyType.setTypeDescription(propertyTypeEdit); property.propertyType.setNumberRooms(propertyNumberRoomsEdit); property.propertyStatue.setPrice(propertyPriceEdit); property.propertyType.setSurfaceArea(propertySurfaceEdit); property.setDescription(propertyDescriptionEdit); + property.propertyStatue.setStatueSale(soldOrNot); + property.propertyStatue.setSoldDate(dateToEdit); PropertyRepository propertyRepository = new PropertyRepository(MyApp.getInstance()); propertyRepository.updateProperty(property); finish(); @@ -93,8 +112,8 @@ public class EditPropertyActivity extends AppCompatActivity { 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))); + price.setText((new DecimalFormat("##.##").format(property.propertyStatue.price)).replace(',', '.')); + surface.setText((new DecimalFormat("##.##").format(property.propertyType.surfaceArea)).replace(',', '.')); description.setText(property.description); diff --git a/app/src/main/java/fr/romanet/vj/apps/myrealestateagency/view/PropertiesDetailActivity.java b/app/src/main/java/fr/romanet/vj/apps/myrealestateagency/view/PropertiesDetailActivity.java index bfc3f12..794835c 100644 --- a/app/src/main/java/fr/romanet/vj/apps/myrealestateagency/view/PropertiesDetailActivity.java +++ b/app/src/main/java/fr/romanet/vj/apps/myrealestateagency/view/PropertiesDetailActivity.java @@ -4,6 +4,7 @@ import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.TextView; +import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; import androidx.lifecycle.Observer; diff --git a/app/src/main/java/fr/romanet/vj/apps/myrealestateagency/viewmodel/AddPropertyActivityViewModel.java b/app/src/main/java/fr/romanet/vj/apps/myrealestateagency/viewmodel/AddPropertyActivityViewModel.java index a8ab6e9..ee0d6be 100644 --- a/app/src/main/java/fr/romanet/vj/apps/myrealestateagency/viewmodel/AddPropertyActivityViewModel.java +++ b/app/src/main/java/fr/romanet/vj/apps/myrealestateagency/viewmodel/AddPropertyActivityViewModel.java @@ -53,6 +53,7 @@ public class AddPropertyActivityViewModel extends AndroidViewModel { Property propertyToAdd = new Property(propertyDescription, propertyAddress, longitude, latitude, this.agency.getAgencyId(), new PropertyStatue(false, null, propertyPrice), new PropertyType(propertyType, propertyNumberRooms, propertySurface)); propertyRepository.insertProperty(propertyToAdd); + event.postValue(Event.ResetForm); } else diff --git a/app/src/main/res/layout/activity_edit_property.xml b/app/src/main/res/layout/activity_edit_property.xml index 8614dae..0bc6135 100644 --- a/app/src/main/res/layout/activity_edit_property.xml +++ b/app/src/main/res/layout/activity_edit_property.xml @@ -13,7 +13,7 @@ android:id="@+id/textView3" android:layout_width="82dp" android:layout_height="31dp" - android:layout_marginTop="60dp" + android:layout_marginTop="12dp" android:text="@string/price" app:layout_constraintEnd_toStartOf="@+id/editPropertyPrice" app:layout_constraintHorizontal_bias="1.0" @@ -145,19 +145,19 @@ android:text="@string/Number_of_room" app:layout_constraintBottom_toTopOf="@+id/editPropertyPrice" app:layout_constraintEnd_toStartOf="@+id/editPropertyNumberOfRooms" - app:layout_constraintHorizontal_bias="0.347" + app:layout_constraintHorizontal_bias="0.13" app:layout_constraintStart_toStartOf="@+id/textView" app:layout_constraintTop_toBottomOf="@+id/textView" - app:layout_constraintVertical_bias="1.0" /> + app:layout_constraintVertical_bias="0.55" /> @@ -165,10 +165,10 @@ android:id="@+id/textView5" android:layout_width="84dp" android:layout_height="33dp" - android:layout_marginTop="40dp" - android:text="@string/statueSale" + android:layout_marginTop="24dp" + android:text="@string/edit_sold" app:layout_constraintEnd_toStartOf="@+id/editPropertyStatueSale" - app:layout_constraintHorizontal_bias="1.0" + app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="@+id/textView4" app:layout_constraintTop_toBottomOf="@+id/textView4" /> @@ -177,7 +177,7 @@ android:layout_width="78dp" android:layout_height="39dp" android:layout_marginTop="36dp" - android:text="@string/soldDate" + android:text="@string/editSoldDate" app:layout_constraintEnd_toStartOf="@+id/editPropertySoldDate" app:layout_constraintHorizontal_bias="1.0" app:layout_constraintStart_toStartOf="@+id/textView5" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7eb26fc..17b75c4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -17,5 +17,7 @@ Latitude Longitude Cannot add the property + Enter "Sold" or "Not sold" + Enter like yyyy-mm-dd ! Convert \ No newline at end of file