Skip to content

Commit

Permalink
Se agrega mensaje den historial vacio y cambio de color theme
Browse files Browse the repository at this point in the history
  • Loading branch information
ESimonLeon committed Oct 20, 2021
1 parent 7afe6db commit 919dc87
Show file tree
Hide file tree
Showing 14 changed files with 114 additions and 33 deletions.
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions .idea/runConfigurations.xml

This file was deleted.

17 changes: 13 additions & 4 deletions app/src/main/java/com/example/examengapsi/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
Expand All @@ -31,6 +32,7 @@ public class MainActivity extends AppCompatActivity implements MainInterface.Mai

private MainPresenter mainPresenter;
RecyclerView recyclerView, recyclerViewHistory;
LinearLayout llEmpty;
ProductsListAdapter productsListAdapter;
SearchHistoryAdapter searchHistoryAdapter;
SearchHistory searchHistory;
Expand All @@ -43,9 +45,12 @@ public class MainActivity extends AppCompatActivity implements MainInterface.Mai
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

llEmpty = findViewById(R.id.llEmpty);

mainPresenter = new MainPresenter(this, this);

searchHistory = new SearchHistory();
Expand All @@ -56,6 +61,7 @@ protected void onCreate(Bundle savedInstanceState) {
}

private void createRecyclerView(ArrayList<Producto> products) {
if (products.size() > 0) llEmpty.setVisibility(View.GONE);
recyclerView = findViewById(R.id.idRvProducts);
productsListAdapter = new ProductsListAdapter(this, products);
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
Expand Down Expand Up @@ -93,7 +99,7 @@ public boolean onQueryTextChange(String newText) {


private void searchProduct(String query) {
showAlert("Buscando "+ query, getString(R.string.cargando_datos));
showAlert("Buscando " + query, getString(R.string.cargando_datos));
mainPresenter.searchProduct(query);
}

Expand Down Expand Up @@ -137,29 +143,32 @@ protected Void doInBackground(SearchHistory... searchHistories) {
}
}

private class SearchHistoryDBTask extends AsyncTask<Void,Void, List<SearchHistory>>{
private class SearchHistoryDBTask extends AsyncTask<Void, Void, List<SearchHistory>> {

@Override
protected List<SearchHistory> doInBackground(Void... voids) {
listHistory = AppDataBase.getAppDB(getApplicationContext()).searchHistoryDAO().findAllHistory();
return listHistory;
}

@Override
public void onPostExecute(List<SearchHistory> searchHistory){
public void onPostExecute(List<SearchHistory> searchHistory) {
showHistory(searchHistory);
}

private void showHistory(List<SearchHistory> searchHistory) {
createRecyclerHistory(searchHistory);
createRecyclerHistory(searchHistory);
}
}


private void createRecyclerHistory(List<SearchHistory> searchHistory) {
if (searchHistory.size() > 0) llEmpty.setVisibility(View.GONE);
recyclerViewHistory = findViewById(R.id.idRvProducts);
searchHistoryAdapter = new SearchHistoryAdapter(this, searchHistory);
recyclerViewHistory.setLayoutManager(new LinearLayoutManager(this));
recyclerViewHistory.setAdapter(searchHistoryAdapter);
recyclerViewHistory.addItemDecoration(new DividerItemDecoration(this, LinearLayout.VERTICAL));
recyclerViewHistory.setHasFixedSize(true);
recyclerViewHistory.isNestedScrollingEnabled();
searchHistoryAdapter.setOnClickListener(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.os.Build;
import android.util.Log;

import androidx.annotation.RequiresApi;

Expand Down Expand Up @@ -38,7 +39,6 @@ public void searchProduct(String text) {
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public void onResponse(Call<String> call, Response<String> response) {

if (response.isSuccessful()) {
try {
if (response.body() != null) {
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/ic_baseline_error_outline_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="@android:color/black"
tools:ignore="VectorRaster">
<path
android:fillColor="#ff000000"
android:pathData="M11,15h2v2h-2zM11,7h2v6h-2zM11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"/>
</vector>
11 changes: 6 additions & 5 deletions app/src/main/res/drawable/ic_search_black_24dp.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
android:width="24dp"
android:height="24dp"
android:tint="@android:color/black"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M15.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57l0.27,0.28v0.79l5,4.99L20.49,19l-4.99,-5zM9.5,14C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z"/>
android:pathData="M15.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57l0.27,0.28v0.79l5,4.99L20.49,19l-4.99,-5zM9.5,14C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z" />
</vector>
30 changes: 26 additions & 4 deletions app/src/main/res/layout/content_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,33 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/idRvHistory"

<LinearLayout
android:id="@+id/llEmpty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal" />
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:padding="10dp"
android:orientation="vertical">

<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:contentDescription="@string/cargando_datos"
android:scaleType="centerCrop"
android:src="@drawable/ic_baseline_error_outline_24" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:text="@string/empty_data"
android:textColor="@android:color/black"
android:textSize="16dp" />
</LinearLayout>

</RelativeLayout>
6 changes: 4 additions & 2 deletions app/src/main/res/layout/item_search_history.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
android:id="@+id/idTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_margin="7dp"/>
android:layout_margin="7dp"
android:gravity="left"
android:textColor="@android:color/black"
android:textSize="14dp" />

3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<resources>
<string name="app_name">ExamenGapsi</string>
<string name="app_name">Buscador Productos</string>
<string name="action_settings">Settings</string>
<!-- Strings used for fragments for navigation -->
<string name="first_fragment_label">First Fragment</string>
Expand All @@ -12,4 +12,5 @@
<string name="historial_de_busqueda">Historial de busqueda</string>
<string name="cargando_datos">Cargando datos...</string>
<string name="busca_producto_hint">Busca producto</string>
<string name="empty_data">No hay datos en el historial</string>
</resources>
4 changes: 2 additions & 2 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorPrimary">#82B1FF</item>
<item name="colorPrimaryDark">#82B1FF</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

Expand Down

0 comments on commit 919dc87

Please sign in to comment.