working on pull to refresh

This commit is contained in:
Clayton Wilson 2020-11-15 20:11:23 -05:00
parent 3de53be847
commit 89e1d2cb2c
3 changed files with 53 additions and 8 deletions

View File

@ -14,6 +14,7 @@ import android.widget.*;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
@ -22,6 +23,7 @@ import com.example.listify.data.Item;
import com.example.listify.data.List; import com.example.listify.data.List;
import com.example.listify.data.ListEntry; import com.example.listify.data.ListEntry;
import com.example.listify.data.ListShare; import com.example.listify.data.ListShare;
import com.example.listify.ui.home.HomeFragment;
import java.io.IOException; import java.io.IOException;
import java.text.DecimalFormat; import java.text.DecimalFormat;
@ -38,6 +40,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
ListView listView; ListView listView;
MyAdapter myAdapter; MyAdapter myAdapter;
Requestor requestor; Requestor requestor;
SwipeRefreshLayout refreshList;
Button incrQuan; Button incrQuan;
Button decrQuan; Button decrQuan;
@ -90,6 +93,8 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
loadingListItems = findViewById(R.id.progress_loading_list_items); loadingListItems = findViewById(R.id.progress_loading_list_items);
loadingListItems.setVisibility(View.VISIBLE); loadingListItems.setVisibility(View.VISIBLE);
tvTotalPrice = (TextView) findViewById(R.id.total_price);
clearAll = (Button) findViewById(R.id.buttonClear); clearAll = (Button) findViewById(R.id.buttonClear);
clearAll.setOnClickListener(new View.OnClickListener() { clearAll.setOnClickListener(new View.OnClickListener() {
@Override @Override
@ -144,6 +149,22 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
dialog.show(); dialog.show();
} }
}); });
refreshList = (SwipeRefreshLayout) findViewById(R.id.refresh_list);
refreshList.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
Properties configs = new Properties();
try {
configs = AuthManager.loadProperties(ListPage.this, "android.resource://" + getPackageName() + "/raw/auths.json");
} catch (IOException | JSONException e) {
e.printStackTrace();
}
requestor = new Requestor(am, configs.getProperty("apiKey"));
requestor.getObject(Integer.toString(LIST_ID), List.class, ListPage.this);
}
});
} }
@Override @Override
@ -193,6 +214,24 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
@Override @Override
public void acceptDelivery(Object delivered) { public void acceptDelivery(Object delivered) {
// Clear out old values
runOnUiThread(new Runnable() {
@Override
public void run() {
pNames.clear();
pStores.clear();
pPrices.clear();
pQuantity.clear();
pImages.clear();
totalPriceByStore.clear();
storeID2Name.clear();
storeHeaderIndex.clear();
pListItemPair.clear();
totalPrice = 0;
tvTotalPrice.setText(String.format("$%.2f", totalPrice));
}
});
List list = (List) delivered; List list = (List) delivered;
if(list != null) { if(list != null) {
@ -273,8 +312,6 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
} }
} }
tvTotalPrice = (TextView) findViewById(R.id.total_price);
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -284,6 +321,8 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
} }
}); });
} }
refreshList.setRefreshing(false);
} }
class MyAdapter extends ArrayAdapter<String> { class MyAdapter extends ArrayAdapter<String> {

View File

@ -35,7 +35,6 @@ public class SortDialogFragment extends DialogFragment {
} }
// TODO: Sorting should scroll the user back to the top of the page
@Override @Override
public Dialog onCreateDialog(final Bundle savedInstanceState) { public Dialog onCreateDialog(final Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

View File

@ -37,12 +37,19 @@
</LinearLayout> </LinearLayout>
<ListView <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/listView" android:id="@+id/refresh_list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="600dp" android:layout_height="wrap_content">
android:layout_marginTop="50dp"
android:paddingBottom="20dp"/> <ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="600dp"
android:layout_marginTop="50dp"
android:paddingBottom="20dp"/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"