Setting the agent activity at first screen when application is launched

This commit is contained in:
BGbaderguet 2020-12-29 18:17:58 +01:00
parent 132aeadd54
commit 07e6033e30
12 changed files with 44 additions and 17 deletions

View File

@ -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" />

View File

@ -22,17 +22,21 @@ public final class AgentsAdapter extends Adapter<AgentViewHolder>{
private final TextView agentLastName;
private final TextView agencyName;
public AgentViewHolder(@NonNull View itemView)
{
super(itemView);
agentFirstName = itemView.findViewById(R.id.agentFirstName);
agentLastName = itemView.findViewById(R.id.agentLastName);
agencyName = itemView.findViewById(R.id.agencyName);
}
public void update(final Agent agent)
{
agentFirstName.setText(agent.agentFirstName);
agentLastName.setText(agent.agentLastName);
agentFirstName.setText("First name : " + agent.agentFirstName);
agentLastName.setText("Last name : " + agent.agentLastName);
agencyName.setText("Agency : " + agent.nameOfAgency);
}
}

View File

@ -15,8 +15,8 @@ public interface AgentDao {
@Query("SELECT * FROM agent")
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")
String getAgencyName(int 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 idAgent);
@Insert
void insertAgent(Agent agent);

View File

@ -13,12 +13,10 @@ import java.util.concurrent.Executors;
import fr.romanet.vj.apps.myrealestateagency.dao.AgencyDao;
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.DollarCurrencyDao;
import fr.romanet.vj.apps.myrealestateagency.dao.PropertyDao;
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.dao.AgentDao;
import fr.romanet.vj.apps.myrealestateagency.entities.DollarCurrency;

View File

@ -30,9 +30,9 @@ public class Agency {
public static Agency[] populateAgencyTable(){
return new Agency[]{
new Agency("AgenceOFParis"),
new Agency("AgenceOFMarseille")
new Agency("Agency of Paris"),
new Agency("Agency of Marseille"),
new Agency("France Habitation")
};
}
}

View File

@ -57,8 +57,9 @@ public class Agent {
public static Agent[] populateAgentsTable(){
return new Agent[]{
new Agent("Bader", "Guetari", 1),
new Agent("Khalil", "Guetari", 2),
new Agent("Achref", "Guetari", 1)
new Agent("Valentin", "Romanet", 2),
new Agent("Francois", "Durant", 3),
new Agent("Francis", "Huster", 1)
};
}
}

View File

@ -24,4 +24,9 @@ public class AgentRepository {
public LiveData<List<Agent>> getAllAgents() {
return allAgents;
}
public String getAgencyName(Agent agent)
{
return agentDao.getAgencyName(agent.agentId);
}
}

View File

@ -39,6 +39,7 @@ final public class AgentsActivity extends AppCompatActivity{
@Override
public void onChanged(List<Agent> users)
{
viewModel.setAgents();
final AgentsAdapter usersAdapter = new AgentsAdapter(users);
recyclerView.setAdapter(usersAdapter);
}

View File

@ -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.entities.Agent;
//Activity that is useless for the moment
final public class HomeActivity extends AppCompatActivity implements View.OnClickListener {

View File

@ -23,4 +23,15 @@ public class AgentsActivityViewModel extends AndroidViewModel {
agentRepository = new AgentRepository(application);
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);
}
}
}

View File

@ -10,7 +10,7 @@
android:id="@+id/buttonFirst"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:text="Start_application"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"

View File

@ -27,4 +27,14 @@
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>