Updating project

This commit is contained in:
BGbaderguet 2020-12-26 09:28:00 +01:00
parent a4427b98dc
commit 60aaac5690
20 changed files with 398 additions and 31 deletions

View File

@ -5,6 +5,7 @@
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<GradleProjectSettings> <GradleProjectSettings>
<option name="testRunner" value="PLATFORM" /> <option name="testRunner" value="PLATFORM" />
<option name="disableWrapperSourceDistributionNotification" value="true" />
<option name="distributionType" value="DEFAULT_WRAPPED" /> <option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" /> <option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="1.8" /> <option name="gradleJvm" value="1.8" />

View File

@ -33,6 +33,10 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1' implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation "androidx.lifecycle:lifecycle-viewmodel:2.2.0"
implementation "androidx.lifecycle:lifecycle-livedata:2.2.0"
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.preference:preference:1.1.1'
implementation "androidx.room:room-runtime:2.2.5" implementation "androidx.room:room-runtime:2.2.5"
implementation 'com.google.android.gms:play-services-maps:17.0.0' implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
@ -41,3 +45,4 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
} }

View File

@ -18,6 +18,13 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.MyRealEstateAgency"> android:theme="@style/Theme.MyRealEstateAgency">
<activity android:name=".view.AgentsActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- <!--
The API key for Google Maps-based APIs is defined as a string resource. The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml"). (See the file "res/values/google_maps_api.xml").

View File

@ -0,0 +1,69 @@
package fr.romanet.vj.apps.myrealestateagency.adapter;
import java.util.List;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
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.adapter.AgentsAdapter.AgentViewHolder;
import fr.romanet.vj.apps.myrealestateagency.entities.Agent;
import fr.romanet.vj.apps.myrealestateagency.R;
public final class AgentsAdapter extends Adapter<AgentViewHolder>{
public static final class AgentViewHolder extends ViewHolder{
private final TextView agentFirstName;
private final TextView agentLastName;
private final TextView nameOfAgency;
public AgentViewHolder(@NonNull View itemView)
{
super(itemView);
agentFirstName = itemView.findViewById(R.id.agentFirstName);
agentLastName = itemView.findViewById(R.id.agentLastName);
nameOfAgency = itemView.findViewById(R.id.nameOfAgency);
}
public void update(final Agent agent)
{
agentFirstName.setText(agent.agentFirstName);
agentLastName.setText(agent.agentLastName);
nameOfAgency.setText(agent.agencyEmployerId);
}
}
private final List<Agent> agents;
public AgentsAdapter(List<Agent> agents)
{
this.agents = agents;
}
@NonNull
@Override
public AgentViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
{
final View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.viewholder_agent, parent, false);
return new AgentViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull AgentViewHolder holder, int position)
{
holder.update(agents.get(position));
}
@Override
public int getItemCount()
{
return agents.size();
}
}

View File

@ -0,0 +1,17 @@
package fr.romanet.vj.apps.myrealestateagency.dao;
import androidx.room.Dao;
import androidx.room.Query;
import androidx.room.Transaction;
import java.util.List;
import fr.romanet.vj.apps.myrealestateagency.entities.AgencyWithProperties;
@Dao
public interface AgencyWithPropertiesDao {
@Transaction
@Query("SELECT * FROM agency")
List<AgencyWithProperties> getAgenciesAndProperties();
}

View File

@ -14,6 +14,9 @@ public interface AgentDao {
@Query("SELECT * FROM agent") @Query("SELECT * FROM agent")
List<Agent> getAgentList(); List<Agent> getAgentList();
@Query("SELECT agency_name FROM agency INNER JOIN agent ON agent.agent_id = agency.agency_id WHERE agent.agency_employer_id = :idAgencyEmployer")
String getAgencyName(int idAgencyEmployer);
@Insert @Insert
void insertAgent(Agent agent); void insertAgent(Agent agent);
} }

View File

@ -1,22 +1,21 @@
package fr.romanet.vj.apps.myrealestateagency.database; package fr.romanet.vj.apps.myrealestateagency.database;
import android.content.Context;
import androidx.room.Database; import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase; import androidx.room.RoomDatabase;
import androidx.room.TypeConverters; import androidx.room.TypeConverters;
import fr.romanet.vj.apps.myrealestateagency.dao.AgencyDao; import fr.romanet.vj.apps.myrealestateagency.dao.AgencyDao;
import fr.romanet.vj.apps.myrealestateagency.dao.AgencyWithAgentsDao; import fr.romanet.vj.apps.myrealestateagency.dao.AgencyWithAgentsDao;
//import fr.romanet.vj.apps.myrealestateagency.dao.AgencyWithPropertiesDao; //import fr.romanet.vj.apps.myrealestateagency.dao.AgencyWithPropertiesDao;
import fr.romanet.vj.apps.myrealestateagency.dao.AgencyWithPropertiesDao;
import fr.romanet.vj.apps.myrealestateagency.dao.PropertyDao; import fr.romanet.vj.apps.myrealestateagency.dao.PropertyDao;
import fr.romanet.vj.apps.myrealestateagency.entities.Agency; import fr.romanet.vj.apps.myrealestateagency.entities.Agency;
import fr.romanet.vj.apps.myrealestateagency.entities.AgencyWithProperties;
import fr.romanet.vj.apps.myrealestateagency.entities.Agent; import fr.romanet.vj.apps.myrealestateagency.entities.Agent;
import fr.romanet.vj.apps.myrealestateagency.dao.AgentDao; import fr.romanet.vj.apps.myrealestateagency.dao.AgentDao;
import fr.romanet.vj.apps.myrealestateagency.entities.Property; import fr.romanet.vj.apps.myrealestateagency.entities.Property;
@Database(entities = {Agency.class, Agent.class, Property.class}, version = 1) @Database(entities = {Agency.class, Agent.class, Property.class}, version = 1, exportSchema = false)
@TypeConverters({Property.Converters.class}) @TypeConverters({Property.Converters.class})
public abstract class RealEstateAgencyDatabase extends RoomDatabase { public abstract class RealEstateAgencyDatabase extends RoomDatabase {
@ -24,6 +23,6 @@ public abstract class RealEstateAgencyDatabase extends RoomDatabase {
public abstract AgencyDao agencyDao(); public abstract AgencyDao agencyDao();
public abstract PropertyDao propertyDao(); public abstract PropertyDao propertyDao();
public abstract AgencyWithAgentsDao agencyWithAgentsDao(); public abstract AgencyWithAgentsDao agencyWithAgentsDao();
// public abstract AgencyWithPropertiesDao agencyWithPropertiesDaoDao(); public abstract AgencyWithPropertiesDao agencyWithPropertiesDaoDao();
} }

View File

@ -27,4 +27,12 @@ public class Agency {
public int getAgencyId() { public int getAgencyId() {
return agencyId; return agencyId;
} }
public static Agency[] populateAgencyTable(){
return new Agency[]{
new Agency("AgenceOFParis"),
new Agency("AgenceOFMarseille")
};
}
} }

View File

@ -1,15 +1,23 @@
package fr.romanet.vj.apps.myrealestateagency.entities; package fr.romanet.vj.apps.myrealestateagency.entities;
import androidx.room.Embedded; import androidx.room.Embedded;
import androidx.room.Relation; import androidx.room.Relation;
import java.util.List; import java.util.List;
//public class AgencyWithProperties { public class AgencyWithProperties {
// public int agency_id; @Embedded public Agency agency;
// @Relation( @Relation(
// parentColumn = "agency_id", parentColumn = "agency_id",
// entityColumn = "belongs_agency_id" entityColumn = "belongs_agency_id"
// ) )
// public List<AgencyWithProperties> agents; public List<Property> properties;
//}
public Agency getAgency() {
return agency;
}
public List<Property> getProperties() {
return properties;
}
}

View File

@ -3,6 +3,7 @@ package fr.romanet.vj.apps.myrealestateagency.entities;
import androidx.room.ColumnInfo; import androidx.room.ColumnInfo;
import androidx.room.Entity; import androidx.room.Entity;
import androidx.room.ForeignKey; import androidx.room.ForeignKey;
import androidx.room.Ignore;
import androidx.room.Index; import androidx.room.Index;
import androidx.room.PrimaryKey; import androidx.room.PrimaryKey;
@ -30,6 +31,9 @@ public class Agent {
@ColumnInfo(name = "agency_employer_id", index = true) @ColumnInfo(name = "agency_employer_id", index = true)
public int agencyEmployerId; public int agencyEmployerId;
@Ignore
public String nameOfAgency;
public Agent(String agentFirstName, String agentLastName, int agencyEmployerId) public Agent(String agentFirstName, String agentLastName, int agencyEmployerId)
{ {
agentId = 0; agentId = 0;
@ -42,4 +46,19 @@ public class Agent {
{ {
return agentFirstName; return agentFirstName;
} }
public void setNameOfAgency(String nameOfAgency)
{
this.nameOfAgency = nameOfAgency;
}
public int getAgencyEmployerId() {return agencyEmployerId;}
public static Agent[] populateAgentsTable(){
return new Agent[]{
new Agent("Bader", "Guetari", 1),
new Agent("Khalil", "Guetari", 2),
new Agent("Achref", "Guetari", 1)
};
}
} }

View File

@ -36,19 +36,23 @@ public class Property {
@ColumnInfo(name = "latitude") @ColumnInfo(name = "latitude")
public long latitude; public long latitude;
//@Embedded @Embedded
//public PropertyStatue propertyStatue; public PropertyStatue propertyStatue;
@ColumnInfo(name = "belongs_agency_id") @Embedded
public PropertyType propertyType;
@ColumnInfo(name = "belongs_agency_id", index = true)
public int belongsToAgencyId; public int belongsToAgencyId;
public Property(String description, String address, long longitude, long latitude) public Property(String description, String address, long longitude, long latitude, int belongsToAgencyId)
{ {
propertyId = 0; propertyId = 0;
this.description = description; this.description = description;
this.address = address; this.address = address;
this.longitude = longitude; this.longitude = longitude;
this.latitude = latitude; this.latitude = latitude;
this.belongsToAgencyId = belongsToAgencyId;
} }
public static class Converters { public static class Converters {

View File

@ -17,8 +17,4 @@ public class PropertyStatue{
@ColumnInfo(name = "price") @ColumnInfo(name = "price")
public double price; public double price;
@Embedded
public PropertyType propertyType;
} }

View File

@ -0,0 +1,15 @@
package fr.romanet.vj.apps.myrealestateagency.repository;
import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import java.io.IOException;
import java.util.List;
public class MapsActivityRepository {
public List<Address> get_lat_long_from_address(String address, Context context) throws IOException {
Geocoder gc = new Geocoder(context);
return gc.getFromLocationName(address, 1);
}
}

View File

@ -1,17 +1,14 @@
package fr.romanet.vj.apps.myrealestateagency.repository; package fr.romanet.vj.apps.myrealestateagency.repository;
import android.content.Context; import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import androidx.room.Room; import androidx.room.Room;
import java.io.IOException;
import java.util.List; import java.util.List;
import fr.romanet.vj.apps.myrealestateagency.database.RealEstateAgencyDatabase; import fr.romanet.vj.apps.myrealestateagency.database.RealEstateAgencyDatabase;
import fr.romanet.vj.apps.myrealestateagency.entities.Agency; import fr.romanet.vj.apps.myrealestateagency.entities.Agency;
import fr.romanet.vj.apps.myrealestateagency.entities.Agent; import fr.romanet.vj.apps.myrealestateagency.entities.Agent;
import fr.romanet.vj.apps.myrealestateagency.entities.Property;
public final class MyRealEstateAgencyRepository { public final class MyRealEstateAgencyRepository {
private static volatile MyRealEstateAgencyRepository instance; private static volatile MyRealEstateAgencyRepository instance;
@ -34,14 +31,14 @@ public final class MyRealEstateAgencyRepository {
private final RealEstateAgencyDatabase realEstateAgencyDatabaseDatabase; private final RealEstateAgencyDatabase realEstateAgencyDatabaseDatabase;
private MyRealEstateAgencyRepository(Context context) public MyRealEstateAgencyRepository(Context context)
{ {
realEstateAgencyDatabaseDatabase = Room.databaseBuilder(context, RealEstateAgencyDatabase.class, "real_estate_agency_db").allowMainThreadQueries().build(); realEstateAgencyDatabaseDatabase = Room.databaseBuilder(context, RealEstateAgencyDatabase.class, "real_estate_agency_db").allowMainThreadQueries().build();
} }
public List<Agent> getAgents(){return realEstateAgencyDatabaseDatabase.agentDao().getAgentList();}
public void addAgency(Agency agency){realEstateAgencyDatabaseDatabase.agencyDao().insertAgency(agency);} public void addAgency(Agency agency){realEstateAgencyDatabaseDatabase.agencyDao().insertAgency(agency);}
public void addAgent(Agent agent){realEstateAgencyDatabaseDatabase.agentDao().insertAgent(agent);} public void addAgent(Agent agent){realEstateAgencyDatabaseDatabase.agentDao().insertAgent(agent);}
public void addProperty(Property property){realEstateAgencyDatabaseDatabase.propertyDao().insertProperty(property);}
public String getAgencyName(Agent agent){return realEstateAgencyDatabaseDatabase.agentDao().getAgencyName(agent.agencyEmployerId);}
} }

View File

@ -0,0 +1,54 @@
package fr.romanet.vj.apps.myrealestateagency.view;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import java.util.List;
import fr.romanet.vj.apps.myrealestateagency.R;
import fr.romanet.vj.apps.myrealestateagency.Repository.MyRealEstateAgencyRepository;
import fr.romanet.vj.apps.myrealestateagency.adapter.AgentsAdapter;
import fr.romanet.vj.apps.myrealestateagency.entities.Agency;
import fr.romanet.vj.apps.myrealestateagency.entities.Agent;
import fr.romanet.vj.apps.myrealestateagency.viewmodel.AgentsActivityViewModel;
final public class AgentsActivity extends AppCompatActivity implements OnClickListener {
private RecyclerView recyclerView;
private AgentsActivityViewModel viewModel;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_agents);
recyclerView = findViewById(R.id.recyclerViewAgents);
recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
viewModel = new ViewModelProvider(this).get(AgentsActivityViewModel.class);
observeAgents();
}
private void observeAgents()
{
viewModel.agents.observe(this, new Observer<List<Agent>>() {
@Override
public void onChanged(List<Agent> agents) {
final AgentsAdapter agentsAdapter = new AgentsAdapter(agents);
recyclerView.setAdapter(agentsAdapter);
}
});
}
@Override
public void onClick(View view) {
}
}

View File

@ -0,0 +1,53 @@
package fr.romanet.vj.apps.myrealestateagency.view;
import androidx.fragment.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import java.util.List;
import fr.romanet.vj.apps.myrealestateagency.R;
import fr.romanet.vj.apps.myrealestateagency.repository.MapsActivityRepository;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
// mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
// List<String> ll = MapsActivityRepository.get
}
}

View File

@ -0,0 +1,38 @@
package fr.romanet.vj.apps.myrealestateagency.viewmodel;
import android.app.Application;
import android.os.Handler;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleEventObserver;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.OnLifecycleEvent;
import androidx.lifecycle.ViewModel;
import java.util.List;
import fr.romanet.vj.apps.myrealestateagency.Repository.MyRealEstateAgencyRepository;
import fr.romanet.vj.apps.myrealestateagency.entities.Agent;
public final class AgentsActivityViewModel extends AndroidViewModel implements LifecycleObserver {
public MutableLiveData<List<Agent>> agents = new MutableLiveData<>();
private MyRealEstateAgencyRepository myRealEstateAgencyRepository;
public AgentsActivityViewModel(@NonNull Application application)
{
super(application);
myRealEstateAgencyRepository = new MyRealEstateAgencyRepository(application);
agents.postValue(MyRealEstateAgencyRepository.getInstance(getApplication()).getAgents());
}
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
private void start_counter_on_activity_start(){
agents.postValue(MyRealEstateAgencyRepository.getInstance(getApplication()).getAgents());
}
}

View File

@ -0,0 +1,21 @@
<?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"
tools:context=".view.AgentsActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerViewAgents"
android:layout_width="0dp"
android:layout_height="0dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".view.MapsActivity" />

View File

@ -0,0 +1,44 @@
<?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="wrap_content"
android:background="?attr/selectableItemBackground"
android:padding="12dp">
<TextView
android:id="@+id/agentFirstName"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@id/agentLastName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="@tools:sample/full_names" />
<TextView
android:id="@+id/agentLastName"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@id/nameOfAgency"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/agentFirstName"
app:layout_constraintTop_toBottomOf="@id/agentFirstName"
tools:text="@tools:sample/full_names"
/>
<TextView
android:id="@+id/nameOfAgency"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/agentLastName"
tools:text="@tools:sample/us_phones"
/>
</androidx.constraintlayout.widget.ConstraintLayout>