Skip to content

Commit

Permalink
[ADD] Implementar busqueda en activity recepciones
Browse files Browse the repository at this point in the history
  • Loading branch information
sergio-teruel committed Feb 17, 2015
1 parent a296d42 commit 2e7a4da
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 37 deletions.
5 changes: 0 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@
<activity
android:name=".Recepciones"
android:label="@string/title_activity_recepciones" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable"/>
</activity>
<activity
android:name=".MovArticuloSerie"
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/es/incaser/apps/stockcontrol/DbAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,16 @@ public Cursor getRecepciones(String codigoEmpresa) {
return db.query(table, new String[]{campos}, "CodigoEmpresa=? AND TipoMovimiento=?",
new String[]{codigoEmpresa, TipoMovimiento.ENTRADA}, groupBy, "", "FechaRegistro DESC");
}

public Cursor getRecepcionesSearch(String codigoEmpresa, String searchText) {
searchText = "%" + searchText +"%";
String table = "MovimientoStock";
String campos ="MAX(id) as id, CodigoEmpresa, Ejercicio, Serie, Documento, MatriculaTransporte_, SUM(Unidades) AS Unidades";
String groupBy = "CodigoEmpresa, Ejercicio, Serie, Documento, MatriculaTransporte_";
return db.query(table, new String[]{campos}, "CodigoEmpresa=? AND TipoMovimiento=? AND (Documento like ? OR MatriculaTransporte_ like ?)",
new String[]{codigoEmpresa, TipoMovimiento.ENTRADA, searchText, searchText}, groupBy, "", "FechaRegistro DESC");
}

public Cursor getExpediciones(String codigoEmpresa) {
// MovimientosStock Distinct serie-documento
String table = "MovimientoStock LEFT JOIN Choferes ON MovimientoStock.CodigoChofer=Choferes.CodigoChofer";
Expand Down
44 changes: 13 additions & 31 deletions app/src/main/java/es/incaser/apps/stockcontrol/Recepciones.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ protected void onResume() {

public void linkListViewMovimientoStock(){
lvMovimientoStock = (ListView) findViewById(R.id.lv_recepciones);
lvMovimientoStock.setEmptyView(findViewById(R.id.lay_empty_listview));
movStockAdapter = new MovStockAdapter(this);
lvMovimientoStock.setAdapter(movStockAdapter);
}
Expand All @@ -52,39 +53,16 @@ public void linkListViewMovimientoStock(){
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_recepciones, menu);
searchView = (SearchView) menu.findItem(R.id.reception_search).getActionView();
setupSearchView();
setupSearchView(menu);
return true;
}

private void setupSearchView() {


//searchView.setIconifiedByDefault(true);

SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
if (searchManager != null) {
List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch();

// Try to use the "applications" global search provider
SearchableInfo info = searchManager.getSearchableInfo(getComponentName());
for (SearchableInfo inf : searchables) {
if (inf.getSuggestAuthority() != null
&& inf.getSuggestAuthority().startsWith("applications")) {
info = inf;
}
}
searchView.setSearchableInfo(info);
}

private void setupSearchView(Menu menu) {
searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
searchView.setOnQueryTextListener(this);
searchView.setOnCloseListener(new SearchView.OnCloseListener() {
@Override
public boolean onClose() {
return false;
}
});
searchView.setIconifiedByDefault(true);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
Expand All @@ -102,13 +80,13 @@ public boolean onOptionsItemSelected(MenuItem item) {

@Override
public boolean onQueryTextSubmit(String query) {
//Toast.makeText(this, query, Toast.LENGTH_SHORT).show();
return false;
}

@Override
public boolean onQueryTextChange(String newText) {
//Toast.makeText(this, newText, Toast.LENGTH_SHORT).show();
movStockAdapter.search(newText);
movStockAdapter.notifyDataSetChanged();
return false;
}

Expand All @@ -119,7 +97,11 @@ public class MovStockAdapter extends BaseAdapter implements View.OnClickListener
public MovStockAdapter(Context ctx){
context = ctx;
dbAdapter = new DbAdapter(context);
cursor = dbAdapter.getRecepciones(MainActivity.codigoEmpresa);
search("");
}

public void search(String searchText){
cursor = dbAdapter.getRecepcionesSearch(MainActivity.codigoEmpresa, searchText);
cursor.moveToFirst();
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_recepciones.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
android:id="@+id/lv_recepciones"
android:layout_width="match_parent"
android:layout_height="match_parent"></ListView>
<include layout="@layout/empty_list_view"/>
</LinearLayout>

</RelativeLayout>
14 changes: 14 additions & 0 deletions app/src/main/res/layout/empty_list_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lay_empty_listview"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/emptyListView" >
</TextView>

</LinearLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/menu/menu_recepciones.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<item android:id="@+id/action_settings" android:title="@string/action_settings"
android:orderInCategory="100" app:showAsAction="never" />
<item
android:id="@+id/reception_search"
android:id="@+id/action_search"
app:showAsAction="always"
android:title="Search"
android:icon="@drawable/ic_action_search"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@
<string name="status_sync_not_insql">NO EN SQL</string>
<string name="app_label">Stock Control</string>
<string name="search_hint">Buscar...</string>
<string name="emptyListView">No hay datos</string>

</resources>

0 comments on commit 2e7a4da

Please sign in to comment.