Setting the agent activity at first screen when application is launched
This commit is contained in:
parent
132aeadd54
commit
07e6033e30
@ -19,11 +19,7 @@
|
|||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.MyRealEstateAgency">
|
android:theme="@style/Theme.MyRealEstateAgency">
|
||||||
|
|
||||||
<activity
|
<activity android:name=".view.AgentsActivity">
|
||||||
android:name=".view.AgentsActivity"
|
|
||||||
android:theme="@style/Theme.MyRealEstateAgency"></activity>
|
|
||||||
|
|
||||||
<activity android:name=".view.HomeActivity">
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<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 agentLastName;
|
||||||
|
|
||||||
|
private final TextView agencyName;
|
||||||
|
|
||||||
public AgentViewHolder(@NonNull View itemView)
|
public AgentViewHolder(@NonNull View itemView)
|
||||||
{
|
{
|
||||||
super(itemView);
|
super(itemView);
|
||||||
agentFirstName = itemView.findViewById(R.id.agentFirstName);
|
agentFirstName = itemView.findViewById(R.id.agentFirstName);
|
||||||
agentLastName = itemView.findViewById(R.id.agentLastName);
|
agentLastName = itemView.findViewById(R.id.agentLastName);
|
||||||
|
agencyName = itemView.findViewById(R.id.agencyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(final Agent agent)
|
public void update(final Agent agent)
|
||||||
{
|
{
|
||||||
agentFirstName.setText(agent.agentFirstName);
|
agentFirstName.setText("First name : " + agent.agentFirstName);
|
||||||
agentLastName.setText(agent.agentLastName);
|
agentLastName.setText("Last name : " + agent.agentLastName);
|
||||||
|
agencyName.setText("Agency : " + agent.nameOfAgency);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -15,8 +15,8 @@ public interface AgentDao {
|
|||||||
@Query("SELECT * FROM agent")
|
@Query("SELECT * FROM agent")
|
||||||
LiveData<List<Agent>> getAgentList();
|
LiveData<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")
|
@Query("SELECT agency_name FROM agency INNER JOIN agent ON agent.agency_employer_id = agency.agency_id WHERE agent.agent_id = :idAgent")
|
||||||
String getAgencyName(int idAgencyEmployer);
|
String getAgencyName(int idAgent);
|
||||||
|
|
||||||
@Insert
|
@Insert
|
||||||
void insertAgent(Agent agent);
|
void insertAgent(Agent agent);
|
||||||
|
|||||||
@ -13,12 +13,10 @@ import java.util.concurrent.Executors;
|
|||||||
|
|
||||||
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.DollarCurrencyDao;
|
import fr.romanet.vj.apps.myrealestateagency.dao.DollarCurrencyDao;
|
||||||
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.DollarCurrency;
|
import fr.romanet.vj.apps.myrealestateagency.entities.DollarCurrency;
|
||||||
|
|||||||
@ -30,9 +30,9 @@ public class Agency {
|
|||||||
|
|
||||||
public static Agency[] populateAgencyTable(){
|
public static Agency[] populateAgencyTable(){
|
||||||
return new Agency[]{
|
return new Agency[]{
|
||||||
new Agency("AgenceOFParis"),
|
new Agency("Agency of Paris"),
|
||||||
new Agency("AgenceOFMarseille")
|
new Agency("Agency of Marseille"),
|
||||||
|
new Agency("France Habitation")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,8 +57,9 @@ public class Agent {
|
|||||||
public static Agent[] populateAgentsTable(){
|
public static Agent[] populateAgentsTable(){
|
||||||
return new Agent[]{
|
return new Agent[]{
|
||||||
new Agent("Bader", "Guetari", 1),
|
new Agent("Bader", "Guetari", 1),
|
||||||
new Agent("Khalil", "Guetari", 2),
|
new Agent("Valentin", "Romanet", 2),
|
||||||
new Agent("Achref", "Guetari", 1)
|
new Agent("Francois", "Durant", 3),
|
||||||
|
new Agent("Francis", "Huster", 1)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,4 +24,9 @@ public class AgentRepository {
|
|||||||
public LiveData<List<Agent>> getAllAgents() {
|
public LiveData<List<Agent>> getAllAgents() {
|
||||||
return allAgents;
|
return allAgents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getAgencyName(Agent agent)
|
||||||
|
{
|
||||||
|
return agentDao.getAgencyName(agent.agentId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,6 +39,7 @@ final public class AgentsActivity extends AppCompatActivity{
|
|||||||
@Override
|
@Override
|
||||||
public void onChanged(List<Agent> users)
|
public void onChanged(List<Agent> users)
|
||||||
{
|
{
|
||||||
|
viewModel.setAgents();
|
||||||
final AgentsAdapter usersAdapter = new AgentsAdapter(users);
|
final AgentsAdapter usersAdapter = new AgentsAdapter(users);
|
||||||
recyclerView.setAdapter(usersAdapter);
|
recyclerView.setAdapter(usersAdapter);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,6 +19,7 @@ import fr.romanet.vj.apps.myrealestateagency.R;
|
|||||||
import fr.romanet.vj.apps.myrealestateagency.database.RealEstateAgencyDatabase;
|
import fr.romanet.vj.apps.myrealestateagency.database.RealEstateAgencyDatabase;
|
||||||
import fr.romanet.vj.apps.myrealestateagency.entities.Agent;
|
import fr.romanet.vj.apps.myrealestateagency.entities.Agent;
|
||||||
|
|
||||||
|
//Activity that is useless for the moment
|
||||||
final public class HomeActivity extends AppCompatActivity implements View.OnClickListener {
|
final public class HomeActivity extends AppCompatActivity implements View.OnClickListener {
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -23,4 +23,15 @@ public class AgentsActivityViewModel extends AndroidViewModel {
|
|||||||
agentRepository = new AgentRepository(application);
|
agentRepository = new AgentRepository(application);
|
||||||
agents = agentRepository.getAllAgents();
|
agents = agentRepository.getAllAgents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAgents()
|
||||||
|
{
|
||||||
|
List<Agent> currentList = agents.getValue();
|
||||||
|
for(int i = 0; i < currentList.size(); i++)
|
||||||
|
{
|
||||||
|
Agent currentAgent = currentList.get(i);
|
||||||
|
String nameOfAgency = agentRepository.getAgencyName(currentList.get(i));
|
||||||
|
currentAgent.setNameOfAgency(nameOfAgency);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,7 @@
|
|||||||
android:id="@+id/buttonFirst"
|
android:id="@+id/buttonFirst"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Button"
|
android:text="Start_application"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
|||||||
@ -27,4 +27,14 @@
|
|||||||
tools:text="@tools:sample/full_names"
|
tools:text="@tools:sample/full_names"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/agencyName"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="@id/agentLastName"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/agentLastName"
|
||||||
|
tools:text="@tools:sample/full_names"
|
||||||
|
/>
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
Loading…
Reference in New Issue
Block a user