mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 10:48:46 +00:00
Create new thread on search and show progress bar
This commit is contained in:
parent
4e7b180fe0
commit
4757ba2ddf
@ -9,6 +9,7 @@ import android.widget.EditText;
|
|||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
import android.widget.SearchView;
|
import android.widget.SearchView;
|
||||||
import com.example.listify.adapter.SearchResultsListAdapter;
|
import com.example.listify.adapter.SearchResultsListAdapter;
|
||||||
import com.example.listify.data.ItemSearch;
|
import com.example.listify.data.ItemSearch;
|
||||||
@ -23,7 +24,7 @@ import java.util.Properties;
|
|||||||
import static com.example.listify.MainActivity.am;
|
import static com.example.listify.MainActivity.am;
|
||||||
|
|
||||||
public class SearchResults extends AppCompatActivity implements SortDialogFragment.OnSortingListener, Requestor.Receiver {
|
public class SearchResults extends AppCompatActivity implements SortDialogFragment.OnSortingListener, Requestor.Receiver {
|
||||||
private ListView listView;
|
private ProgressBar loadingSearch;
|
||||||
private SearchResultsListAdapter searchResultsListAdapter;
|
private SearchResultsListAdapter searchResultsListAdapter;
|
||||||
private List<Product> resultsProductList = new ArrayList<>();
|
private List<Product> resultsProductList = new ArrayList<>();
|
||||||
private List<Product> resultsProductListSorted = new ArrayList<>();
|
private List<Product> resultsProductListSorted = new ArrayList<>();
|
||||||
@ -31,6 +32,7 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme
|
|||||||
private int storeSelection;
|
private int storeSelection;
|
||||||
private int sortMode;
|
private int sortMode;
|
||||||
private boolean descending;
|
private boolean descending;
|
||||||
|
boolean doneLoading = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendSort(int storeSelection, int sortMode, boolean descending) {
|
public void sendSort(int storeSelection, int sortMode, boolean descending) {
|
||||||
@ -47,6 +49,8 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme
|
|||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
|
loadingSearch = (ProgressBar) findViewById(R.id.progress_loading_search);
|
||||||
|
|
||||||
// Back button closes this activity and returns to previous activity (MainActivity)
|
// Back button closes this activity and returns to previous activity (MainActivity)
|
||||||
ImageButton backButton = (ImageButton) findViewById(R.id.backToHomeButton);
|
ImageButton backButton = (ImageButton) findViewById(R.id.backToHomeButton);
|
||||||
backButton.setOnClickListener(new View.OnClickListener() {
|
backButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@ -77,7 +81,7 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
listView = (ListView) findViewById(R.id.search_results_list);
|
ListView listView = (ListView) findViewById(R.id.search_results_list);
|
||||||
searchResultsListAdapter = new SearchResultsListAdapter(this, resultsProductListSorted);
|
searchResultsListAdapter = new SearchResultsListAdapter(this, resultsProductListSorted);
|
||||||
listView.setAdapter(searchResultsListAdapter);
|
listView.setAdapter(searchResultsListAdapter);
|
||||||
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||||
@ -96,7 +100,15 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme
|
|||||||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onQueryTextSubmit(String query) {
|
public boolean onQueryTextSubmit(String query) {
|
||||||
|
// Show progress bar
|
||||||
|
loadingSearch.setVisibility(View.VISIBLE);
|
||||||
|
Thread t = new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
doSearch(query);
|
doSearch(query);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
t.start();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,12 +134,8 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme
|
|||||||
sortDialog.show(getSupportFragmentManager(), "Sort");
|
sortDialog.show(getSupportFragmentManager(), "Sort");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Override default phone back button to add animation
|
// Override default phone back button to add animation
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
@ -136,10 +144,13 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void doSearch(String query) {
|
private void doSearch(String query) {
|
||||||
|
|
||||||
// Clear the old search results
|
// Clear the old search results
|
||||||
resultsProductList.clear();
|
resultsProductList.clear();
|
||||||
|
|
||||||
|
// Clear old search results from the view
|
||||||
|
resultsProductListSorted.clear();
|
||||||
|
searchResultsListAdapter.notifyDataSetChanged();
|
||||||
|
|
||||||
Properties configs = new Properties();
|
Properties configs = new Properties();
|
||||||
try {
|
try {
|
||||||
configs = AuthManager.loadProperties(this, "android.resource://" + getPackageName() + "/raw/auths.json");
|
configs = AuthManager.loadProperties(this, "android.resource://" + getPackageName() + "/raw/auths.json");
|
||||||
@ -178,7 +189,6 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme
|
|||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// TODO: May need to change this depending on if price is stored as a string or a double
|
|
||||||
case 2:
|
case 2:
|
||||||
resultsProductListSorted.sort(new Comparator<Product>() {
|
resultsProductListSorted.sort(new Comparator<Product>() {
|
||||||
@Override
|
@Override
|
||||||
@ -238,7 +248,13 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme
|
|||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
if (doneLoading) {
|
||||||
|
doneLoading = false;
|
||||||
searchResultsListAdapter.notifyDataSetChanged();
|
searchResultsListAdapter.notifyDataSetChanged();
|
||||||
|
|
||||||
|
// Hide progress bar
|
||||||
|
loadingSearch.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -280,5 +296,7 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme
|
|||||||
|
|
||||||
// Apply selected sorting to the list
|
// Apply selected sorting to the list
|
||||||
sortResults();
|
sortResults();
|
||||||
|
|
||||||
|
doneLoading = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -12,6 +12,16 @@
|
|||||||
tools:context=".SearchResults"
|
tools:context=".SearchResults"
|
||||||
tools:showIn="@layout/activity_search_results">
|
tools:showIn="@layout/activity_search_results">
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/progress_loading_search"
|
||||||
|
style="?android:attr/progressBarStyleLarge"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:indeterminate="true"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
|
||||||
<ListView
|
<ListView
|
||||||
android:id="@+id/search_results_list"
|
android:id="@+id/search_results_list"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user