Drag to refresh lists activity

This commit is contained in:
Clayton Wilson 2020-11-15 00:21:38 -05:00
parent 0aa80b514f
commit 3de53be847
4 changed files with 49 additions and 18 deletions

View File

@ -62,8 +62,12 @@ public class CreateListAddDialogFragment extends DialogFragment {
btnMinus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (etQuantity.getText().toString().equals("")) {
etQuantity.setText("1");
}
int curQauntity = Integer.parseInt(etQuantity.getText().toString());
if (curQauntity > 0) {
if (curQauntity > 1) {
curQauntity--;
etQuantity.setText(String.format("%d", curQauntity));
}
@ -74,6 +78,10 @@ public class CreateListAddDialogFragment extends DialogFragment {
btnPlus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (etQuantity.getText().toString().equals("")) {
etQuantity.setText("1");
}
int curQauntity = Integer.parseInt(etQuantity.getText().toString());
curQauntity++;
etQuantity.setText(String.format("%d", curQauntity));

View File

@ -6,11 +6,14 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.example.listify.AuthManager;
import com.example.listify.CreateListDialogFragment;
import com.example.listify.LoadingCircleDialog;
@ -37,6 +40,7 @@ public class HomeFragment extends Fragment implements CreateListDialogFragment.O
ListView shoppingListsView;
ProgressBar loadingLists;
TextView emptyMessage;
SwipeRefreshLayout refreshLists;
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_home, container, false);
@ -44,6 +48,7 @@ public class HomeFragment extends Fragment implements CreateListDialogFragment.O
loadingLists = (ProgressBar) root.findViewById(R.id.progress_loading_lists);
loadingLists.setVisibility(View.VISIBLE);
emptyMessage = (TextView) root.findViewById(R.id.textViewEmpty);
refreshLists = (SwipeRefreshLayout) root.findViewById(R.id.refresh_lists);
Properties configs = new Properties();
try {
@ -55,8 +60,8 @@ public class HomeFragment extends Fragment implements CreateListDialogFragment.O
requestor = new Requestor(am, configs.getProperty("apiKey"));
SynchronousReceiver<Integer[]> listIdsReceiver = new SynchronousReceiver<>();
final Requestor.Receiver<Integer[]> recv = this;
requestor.getListOfIds(List.class, recv, null);
// final Requestor.Receiver<Integer[]> recv = this;
requestor.getListOfIds(List.class, this, null);
FloatingActionButton fab = (FloatingActionButton) root.findViewById(R.id.new_list_fab);
@ -70,6 +75,23 @@ public class HomeFragment extends Fragment implements CreateListDialogFragment.O
}
});
refreshLists.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
Properties configs = new Properties();
try {
configs = AuthManager.loadProperties(getContext(), "android.resource://" + getActivity().getPackageName() + "/raw/auths.json");
} catch (IOException | JSONException e) {
e.printStackTrace();
}
requestor = new Requestor(am, configs.getProperty("apiKey"));
SynchronousReceiver<Integer[]> listIdsReceiver = new SynchronousReceiver<>();
requestor.getListOfIds(List.class, HomeFragment.this, null);
}
});
return root;
}
@ -130,6 +152,9 @@ public class HomeFragment extends Fragment implements CreateListDialogFragment.O
@Override
public void acceptDelivery(Object delivered) {
// Remove old lists on refresh
shoppingLists.clear();
Integer[] listIds = (Integer[]) delivered;
// Create threads and add them to a list
Thread[] threads = new Thread[listIds.length];
@ -169,16 +194,6 @@ public class HomeFragment extends Fragment implements CreateListDialogFragment.O
@Override
public void run() {
shoppingListsView.setAdapter(shoppingListsSwipeableAdapter);
// shoppingListsView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
// @Override
// public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// Intent listPage = new Intent(getContext(), ListPage.class);
//
// // Send the list ID
// listPage.putExtra("listID", shoppingLists.get(position).getItemID());
// startActivity(listPage);
// }
// });
loadingLists.setVisibility(View.GONE);
if(listIds.length == 0) {
@ -187,5 +202,6 @@ public class HomeFragment extends Fragment implements CreateListDialogFragment.O
}
});
refreshLists.setRefreshing(false);
}
}

View File

@ -35,6 +35,7 @@
android:layout_width="60dp"
android:layout_height="50dp"
android:text="@string/_1"
android:digits="0123456789"
android:inputType="number"/>
<Button

View File

@ -20,12 +20,18 @@
android:indeterminate="true"
android:visibility="gone"/>
<ListView
android:id="@+id/shopping_lists"
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/refresh_lists"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="@color/list_divider"
android:dividerHeight="1dp"/>
android:layout_height="wrap_content" >
<ListView
android:id="@+id/shopping_lists"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="@color/list_divider"
android:dividerHeight="1dp"/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/new_list_fab"