Updating list of properties screen
This commit is contained in:
parent
a7dc63d6c9
commit
7cf32d048f
@ -19,11 +19,6 @@
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.MyRealEstateAgency">
|
||||
|
||||
<activity
|
||||
android:name=".view.PropertiesActivity"
|
||||
android:parentActivityName=".view.AgentsActivity"
|
||||
android:theme="@style/Theme.MyRealEstateAgency"></activity>
|
||||
|
||||
<activity android:name=".view.AgentsActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
@ -32,6 +27,16 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".view.PropertiesActivity"
|
||||
android:parentActivityName=".view.AgentsActivity"
|
||||
android:theme="@style/Theme.MyRealEstateAgency"></activity>
|
||||
|
||||
<activity
|
||||
android:name=".view.AddPropertyActivity"
|
||||
android:parentActivityName=".view.PropertiesActivity"
|
||||
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.
|
||||
|
||||
@ -8,7 +8,6 @@ import androidx.room.Query;
|
||||
import java.util.List;
|
||||
|
||||
import fr.romanet.vj.apps.myrealestateagency.entities.Agency;
|
||||
import fr.romanet.vj.apps.myrealestateagency.entities.Agent;
|
||||
import fr.romanet.vj.apps.myrealestateagency.entities.Property;
|
||||
|
||||
@Dao
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
package fr.romanet.vj.apps.myrealestateagency.view;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import fr.romanet.vj.apps.myrealestateagency.R;
|
||||
|
||||
public class AddPropertyActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_add_property);
|
||||
}
|
||||
}
|
||||
@ -2,10 +2,11 @@ package fr.romanet.vj.apps.myrealestateagency.view;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
import android.view.View.OnClickListener;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.SavedStateViewModelFactory;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
@ -13,15 +14,13 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
import java.util.List;
|
||||
|
||||
import fr.romanet.vj.apps.myrealestateagency.R;
|
||||
import fr.romanet.vj.apps.myrealestateagency.adapter.AgentsAdapter;
|
||||
import fr.romanet.vj.apps.myrealestateagency.adapter.PropertiesAdapter;
|
||||
import fr.romanet.vj.apps.myrealestateagency.entities.Agency;
|
||||
import fr.romanet.vj.apps.myrealestateagency.entities.Agent;
|
||||
import fr.romanet.vj.apps.myrealestateagency.entities.Property;
|
||||
import fr.romanet.vj.apps.myrealestateagency.viewmodel.PropertiesActivityViewModel;
|
||||
import fr.romanet.vj.apps.myrealestateagency.viewmodel.PropertiesActivityViewModelFactory;
|
||||
|
||||
public class PropertiesActivity extends AppCompatActivity {
|
||||
public class PropertiesActivity extends AppCompatActivity implements OnClickListener {
|
||||
|
||||
public static final String AGENCY_EXTRA = "agencyExtra";
|
||||
|
||||
@ -31,6 +30,8 @@ public class PropertiesActivity extends AppCompatActivity {
|
||||
|
||||
private RecyclerView recyclerView;
|
||||
|
||||
private Agency agency;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
@ -38,7 +39,8 @@ public class PropertiesActivity extends AppCompatActivity {
|
||||
setContentView(R.layout.activity_properties);
|
||||
recyclerView = findViewById(R.id.recyclerViewProperties);
|
||||
recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
|
||||
Agency agency = (Agency) getIntent().getSerializableExtra("agencyExtra");
|
||||
findViewById(R.id.buttonAddProperty).setOnClickListener(this);
|
||||
agency = (Agency) getIntent().getSerializableExtra("agencyExtra");
|
||||
viewModel = new ViewModelProvider(this, new PropertiesActivityViewModelFactory(this.getApplication(), agency)).get(PropertiesActivityViewModel.class);
|
||||
observeProperties();
|
||||
}
|
||||
@ -55,4 +57,18 @@ public class PropertiesActivity extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
viewModel.loadProperties(agency);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
final Intent intent = new Intent(this, AddPropertyActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,16 +5,12 @@ import android.app.Application;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.SavedStateHandle;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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.view.PropertiesActivity;
|
||||
|
||||
public class PropertiesActivityViewModel extends AndroidViewModel {
|
||||
|
||||
@ -27,6 +23,11 @@ public class PropertiesActivityViewModel extends AndroidViewModel {
|
||||
agencyRepository = new AgencyRepository(application);
|
||||
properties = agencyRepository.getProperties(agency);
|
||||
}
|
||||
|
||||
public void loadProperties(Agency agency)
|
||||
{
|
||||
properties = agencyRepository.getProperties(agency);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
5
app/src/main/res/drawable/ic_house.xml
Normal file
5
app/src/main/res/drawable/ic_house.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="#132ED2"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M19,9.3V4h-3v2.6L12,3L2,12h3v8h5v-6h4v6h5v-8h3L19,9.3zM10,10c0,-1.1 0.9,-2 2,-2s2,0.9 2,2H10z"/>
|
||||
</vector>
|
||||
98
app/src/main/res/layout/activity_add_property.xml
Normal file
98
app/src/main/res/layout/activity_add_property.xml
Normal file
@ -0,0 +1,98 @@
|
||||
<?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.AddPropertyActivity"
|
||||
>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/avatar"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
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"
|
||||
/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/addPropertyAddress"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/address"
|
||||
android:inputType="textPersonName"
|
||||
app:layout_constraintBottom_toTopOf="@id/addPropertyType"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/avatar"
|
||||
/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/addPropertyType"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/Type"
|
||||
android:inputType="phone"
|
||||
app:layout_constraintBottom_toTopOf="@id/addPropertyNumberOfRooms"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/addPropertyAddress"
|
||||
/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/addPropertyNumberOfRooms"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/Number_of_room"
|
||||
android:inputType="textPostalAddress"
|
||||
app:layout_constraintBottom_toTopOf="@id/addPropertyPrice"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/addPropertyType"
|
||||
/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/addPropertyPrice"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/price"
|
||||
android:inputType="textPostalAddress"
|
||||
app:layout_constraintBottom_toTopOf="@id/addPropertyDescription"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/addPropertyNumberOfRooms"
|
||||
/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/addPropertyDescription"
|
||||
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/save"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/addPropertyPrice"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/save"
|
||||
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/addPropertyDescription"
|
||||
/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@ -18,7 +18,7 @@
|
||||
/>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fab"
|
||||
android:id="@+id/buttonAddProperty"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_agency_add"
|
||||
|
||||
6
app/src/main/res/layout/activity_properties_detail.xml
Normal file
6
app/src/main/res/layout/activity_properties_detail.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@ -1,4 +1,10 @@
|
||||
<resources>
|
||||
<string name="app_name">My Real Estate Agency</string>
|
||||
<string name="title_activity_maps">Map</string>
|
||||
<string name="address">Address</string>
|
||||
<string name="description">Description</string>
|
||||
<string name="Number_of_room">Number of rooms</string>
|
||||
<string name="price">Price</string>
|
||||
<string name="Type">Type</string>
|
||||
<string name="save">Save</string>
|
||||
</resources>
|
||||
Loading…
Reference in New Issue
Block a user