Compare commits
No commits in common. "132aeadd5463a0504e3cd255ea2f01848f3d54cd" and "8697dee54ca92086a7ab73130bede10e7d4e02a7" have entirely different histories.
132aeadd54
...
8697dee54c
@ -19,11 +19,7 @@
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.MyRealEstateAgency">
|
||||
|
||||
<activity
|
||||
android:name=".view.AgentsActivity"
|
||||
android:theme="@style/Theme.MyRealEstateAgency"></activity>
|
||||
|
||||
<activity android:name=".view.HomeActivity">
|
||||
<activity android:name=".view.AgentsActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
|
||||
@ -22,17 +22,21 @@ public final class AgentsAdapter extends Adapter<AgentViewHolder>{
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,7 +51,7 @@ public final class AgentsAdapter extends Adapter<AgentViewHolder>{
|
||||
@Override
|
||||
public AgentViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
|
||||
{
|
||||
final View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.viewholder_agents, parent, false);
|
||||
final View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.viewholder_agent, parent, false);
|
||||
return new AgentViewHolder(view);
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package fr.romanet.vj.apps.myrealestateagency.dao;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.Query;
|
||||
@ -13,14 +12,11 @@ import fr.romanet.vj.apps.myrealestateagency.entities.Agent;
|
||||
public interface AgentDao {
|
||||
|
||||
@Query("SELECT * FROM agent")
|
||||
LiveData<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
|
||||
void insertAgent(Agent agent);
|
||||
|
||||
@Insert
|
||||
void insertPreAgents(Agent[] agents);
|
||||
}
|
||||
|
||||
@ -1,15 +1,8 @@
|
||||
package fr.romanet.vj.apps.myrealestateagency.database;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.room.Database;
|
||||
import androidx.room.Room;
|
||||
import androidx.room.RoomDatabase;
|
||||
import androidx.room.TypeConverters;
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import fr.romanet.vj.apps.myrealestateagency.dao.AgencyDao;
|
||||
import fr.romanet.vj.apps.myrealestateagency.dao.AgencyWithAgentsDao;
|
||||
@ -35,32 +28,4 @@ public abstract class RealEstateAgencyDatabase extends RoomDatabase {
|
||||
public abstract AgencyWithPropertiesDao agencyWithPropertiesDaoDao();
|
||||
public abstract DollarCurrencyDao dollarCurrencyDao();
|
||||
|
||||
private static RealEstateAgencyDatabase INSTANCE;
|
||||
|
||||
public synchronized static RealEstateAgencyDatabase getInstance(Context context) {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = buildDatabase(context);
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private static RealEstateAgencyDatabase buildDatabase(final Context context) {
|
||||
return Room.databaseBuilder(context,
|
||||
RealEstateAgencyDatabase.class,
|
||||
"my-real_estate_agency_db")
|
||||
.addCallback(new Callback() {
|
||||
@Override
|
||||
public void onCreate(@NonNull SupportSQLiteDatabase db) {
|
||||
super.onCreate(db);
|
||||
Executors.newSingleThreadScheduledExecutor().execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getInstance(context).agencyDao().insertPreData(Agency.populateAgencyTable());
|
||||
getInstance(context).agentDao().insertPreAgents(Agent.populateAgentsTable());
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
.allowMainThreadQueries().build();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,27 +0,0 @@
|
||||
package fr.romanet.vj.apps.myrealestateagency.repository;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import fr.romanet.vj.apps.myrealestateagency.dao.AgentDao;
|
||||
import fr.romanet.vj.apps.myrealestateagency.database.RealEstateAgencyDatabase;
|
||||
import fr.romanet.vj.apps.myrealestateagency.entities.Agent;
|
||||
|
||||
public class AgentRepository {
|
||||
|
||||
private AgentDao agentDao;
|
||||
private LiveData<List<Agent>> allAgents;
|
||||
|
||||
public AgentRepository(Application application) {
|
||||
RealEstateAgencyDatabase realEstateAgencyDatabase = RealEstateAgencyDatabase.getInstance(application);
|
||||
agentDao = realEstateAgencyDatabase.agentDao();
|
||||
allAgents = agentDao.getAgentList();
|
||||
}
|
||||
|
||||
public LiveData<List<Agent>> getAllAgents() {
|
||||
return allAgents;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
package fr.romanet.vj.apps.myrealestateagency.repository;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.room.Room;
|
||||
import androidx.room.RoomDatabase;
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase;
|
||||
|
||||
import java.util.List;
|
||||
import fr.romanet.vj.apps.myrealestateagency.database.RealEstateAgencyDatabase;
|
||||
import fr.romanet.vj.apps.myrealestateagency.entities.Agency;
|
||||
import fr.romanet.vj.apps.myrealestateagency.entities.Agent;
|
||||
import fr.romanet.vj.apps.myrealestateagency.entities.Property;
|
||||
|
||||
public final class MyRealEstateAgencyRepository {
|
||||
private static volatile MyRealEstateAgencyRepository instance;
|
||||
|
||||
public static MyRealEstateAgencyRepository getInstance(Context context)
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
synchronized (MyRealEstateAgencyRepository.class)
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new MyRealEstateAgencyRepository(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
private final RealEstateAgencyDatabase realEstateAgencyDatabaseDatabase;
|
||||
|
||||
public MyRealEstateAgencyRepository(Context context)
|
||||
{
|
||||
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 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);}
|
||||
}
|
||||
@ -6,7 +6,11 @@ import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import fr.romanet.vj.apps.myrealestateagency.R;
|
||||
@ -14,7 +18,7 @@ import fr.romanet.vj.apps.myrealestateagency.adapter.AgentsAdapter;
|
||||
import fr.romanet.vj.apps.myrealestateagency.entities.Agent;
|
||||
import fr.romanet.vj.apps.myrealestateagency.viewmodel.AgentsActivityViewModel;
|
||||
|
||||
final public class AgentsActivity extends AppCompatActivity{
|
||||
final public class AgentsActivity extends AppCompatActivity implements OnClickListener {
|
||||
|
||||
private RecyclerView recyclerView;
|
||||
|
||||
@ -27,22 +31,26 @@ final public class AgentsActivity extends AppCompatActivity{
|
||||
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();
|
||||
|
||||
Intent i = new Intent(AgentsActivity.this, MapsActivity.class);
|
||||
AgentsActivity.this.startActivity(i);
|
||||
}
|
||||
|
||||
private void observeAgents()
|
||||
{
|
||||
viewModel.agents.observe(this, new Observer<List<Agent>>()
|
||||
{
|
||||
viewModel.agents.observe(this, new Observer<List<Agent>>() {
|
||||
@Override
|
||||
public void onChanged(List<Agent> users)
|
||||
{
|
||||
final AgentsAdapter usersAdapter = new AgentsAdapter(users);
|
||||
recyclerView.setAdapter(usersAdapter);
|
||||
public void onChanged(List<Agent> agents) {
|
||||
final AgentsAdapter agentsAdapter = new AgentsAdapter(agents);
|
||||
recyclerView.setAdapter(agentsAdapter);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,46 +0,0 @@
|
||||
package fr.romanet.vj.apps.myrealestateagency.view;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemClock;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListView;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.lifecycle.LiveData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.romanet.vj.apps.myrealestateagency.R;
|
||||
import fr.romanet.vj.apps.myrealestateagency.database.RealEstateAgencyDatabase;
|
||||
import fr.romanet.vj.apps.myrealestateagency.entities.Agent;
|
||||
|
||||
final public class HomeActivity extends AppCompatActivity implements View.OnClickListener {
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_home);
|
||||
Button button = (Button) findViewById(R.id.buttonFirst);
|
||||
button.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
public void onClick(View v)
|
||||
{
|
||||
Intent intent = new Intent(HomeActivity.this, AgentsActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,26 +1,36 @@
|
||||
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.LiveData;
|
||||
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;
|
||||
import fr.romanet.vj.apps.myrealestateagency.repository.AgentRepository;
|
||||
|
||||
public class AgentsActivityViewModel extends AndroidViewModel {
|
||||
public final class AgentsActivityViewModel extends AndroidViewModel implements LifecycleObserver {
|
||||
|
||||
public LiveData<List<Agent>> agents = new MutableLiveData<>();
|
||||
public AgentRepository agentRepository;
|
||||
public MutableLiveData<List<Agent>> agents = new MutableLiveData<>();
|
||||
|
||||
private MyRealEstateAgencyRepository myRealEstateAgencyRepository;
|
||||
|
||||
public AgentsActivityViewModel(@NonNull Application application)
|
||||
{
|
||||
super(application);
|
||||
agentRepository = new AgentRepository(application);
|
||||
agents = agentRepository.getAllAgents();
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
||||
private void start_counter_on_activity_start(){
|
||||
agents.postValue(MyRealEstateAgencyRepository.getInstance(getApplication()).getAgents());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,18 +0,0 @@
|
||||
<?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">
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonFirst"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Button"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@ -21,10 +21,24 @@
|
||||
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>
|
||||
Loading…
Reference in New Issue
Block a user