mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 02:38:47 +00:00
working on pull to refresh
This commit is contained in:
parent
3de53be847
commit
89e1d2cb2c
@ -14,6 +14,7 @@ import android.widget.*;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
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.ListEntry;
|
||||
import com.example.listify.data.ListShare;
|
||||
import com.example.listify.ui.home.HomeFragment;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.DecimalFormat;
|
||||
@ -38,6 +40,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
||||
ListView listView;
|
||||
MyAdapter myAdapter;
|
||||
Requestor requestor;
|
||||
SwipeRefreshLayout refreshList;
|
||||
|
||||
Button incrQuan;
|
||||
Button decrQuan;
|
||||
@ -90,6 +93,8 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
||||
loadingListItems = findViewById(R.id.progress_loading_list_items);
|
||||
loadingListItems.setVisibility(View.VISIBLE);
|
||||
|
||||
tvTotalPrice = (TextView) findViewById(R.id.total_price);
|
||||
|
||||
clearAll = (Button) findViewById(R.id.buttonClear);
|
||||
clearAll.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@ -144,6 +149,22 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
||||
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
|
||||
@ -193,6 +214,24 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
||||
|
||||
@Override
|
||||
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;
|
||||
|
||||
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() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -284,6 +321,8 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
refreshList.setRefreshing(false);
|
||||
}
|
||||
|
||||
class MyAdapter extends ArrayAdapter<String> {
|
||||
|
||||
@ -35,7 +35,6 @@ public class SortDialogFragment extends DialogFragment {
|
||||
}
|
||||
|
||||
|
||||
// TODO: Sorting should scroll the user back to the top of the page
|
||||
@Override
|
||||
public Dialog onCreateDialog(final Bundle savedInstanceState) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
|
||||
@ -37,12 +37,19 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ListView
|
||||
android:id="@+id/listView"
|
||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
android:id="@+id/refresh_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="600dp"
|
||||
android:layout_marginTop="50dp"
|
||||
android:paddingBottom="20dp"/>
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<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
|
||||
android:layout_width="match_parent"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user