mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-15 18:28:47 +00:00
Merge branch 'improvements' into list-renaming
This commit is contained in:
commit
41f8ccbf30
@ -2,6 +2,7 @@ import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -9,6 +10,7 @@ public class ChainGetter implements CallHandler {
|
||||
private final Connection connection;
|
||||
|
||||
private final String GET_CHAIN = "SELECT * FROM Chain WHERE chainID = ?;";
|
||||
private final String GET_CHAINS = "SELECT chainID FROM Chain;";
|
||||
|
||||
public ChainGetter(Connection connection, String cognitoID) {
|
||||
this.connection = connection;
|
||||
@ -16,8 +18,21 @@ public class ChainGetter implements CallHandler {
|
||||
|
||||
@Override
|
||||
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryMap, String cognitoID) throws SQLException {
|
||||
Integer id = Integer.parseInt(queryMap.get("id"));
|
||||
if (id == -1) {
|
||||
PreparedStatement getChains = connection.prepareStatement(GET_CHAINS);
|
||||
System.out.println(getChains);
|
||||
ResultSet getChainsResults = getChains.executeQuery();
|
||||
System.out.println(getChainsResults);
|
||||
ArrayList<Integer> chainIDs = new ArrayList<>();
|
||||
while (getChainsResults.next()) {
|
||||
chainIDs.add(getChainsResults.getInt("chainID"));
|
||||
}
|
||||
return chainIDs;
|
||||
}
|
||||
|
||||
PreparedStatement statement = connection.prepareStatement(GET_CHAIN);
|
||||
statement.setInt(1, Integer.parseInt(queryMap.get("id")));
|
||||
statement.setInt(1, id);
|
||||
System.out.println(statement);
|
||||
ResultSet queryResults = statement.executeQuery();
|
||||
queryResults.first();
|
||||
|
||||
@ -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));
|
||||
|
||||
@ -10,6 +10,8 @@ import android.widget.*;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
import com.example.listify.ui.home.HomeFragment;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.example.listify.data.*;
|
||||
import org.json.JSONException;
|
||||
@ -27,6 +29,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
||||
ListView listView;
|
||||
MyAdapter myAdapter;
|
||||
Requestor requestor;
|
||||
SwipeRefreshLayout refreshList;
|
||||
|
||||
Button incrQuan;
|
||||
Button decrQuan;
|
||||
@ -59,7 +62,9 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_list);
|
||||
|
||||
final int listID = (int) getIntent().getSerializableExtra("listID");
|
||||
final int LIST_ID = (int) getIntent().getSerializableExtra("listID");
|
||||
final String LIST_NAME = (String) getIntent().getSerializableExtra("listName");
|
||||
setTitle(LIST_NAME);
|
||||
|
||||
Properties configs = new Properties();
|
||||
try {
|
||||
@ -68,7 +73,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
||||
e.printStackTrace();
|
||||
}
|
||||
requestor = new Requestor(am, configs.getProperty("apiKey"));
|
||||
requestor.getObject(Integer.toString(listID), List.class, this);
|
||||
requestor.getObject(Integer.toString(LIST_ID), List.class, this);
|
||||
|
||||
listView = findViewById(R.id.listView);
|
||||
myAdapter = new MyAdapter(this, pNames, pStores, pPrices, pQuantity, pImages);
|
||||
@ -77,6 +82,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
|
||||
@ -114,7 +121,8 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
EditText sharedEmailText = (EditText) codeView.findViewById(R.id.editTextTextSharedEmail);
|
||||
String sharedEmail = sharedEmailText.getText().toString();
|
||||
ListShare listShare = new ListShare(listID, sharedEmail, "Read, Write, Delete, Share");
|
||||
|
||||
ListShare listShare = new ListShare(LIST_ID, sharedEmail, "Read, Write, Delete, Share");
|
||||
try {
|
||||
requestor.putObject(listShare);
|
||||
}
|
||||
@ -131,6 +139,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
|
||||
@ -180,6 +204,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) {
|
||||
@ -260,8 +302,6 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
tvTotalPrice = (TextView) findViewById(R.id.total_price);
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -271,6 +311,8 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
refreshList.setRefreshing(false);
|
||||
}
|
||||
|
||||
class MyAdapter extends ArrayAdapter<String> {
|
||||
@ -330,7 +372,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
||||
catch (Exception e) {
|
||||
Log.i("Authentication", e.toString());
|
||||
}
|
||||
listView.setAdapter(myAdapter);
|
||||
myAdapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
if(Integer.parseInt(pQuantity.get(position)) <= 1) {
|
||||
@ -365,7 +407,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
||||
catch (Exception e) {
|
||||
Log.i("Authentication", e.toString());
|
||||
}
|
||||
listView.setAdapter(myAdapter);
|
||||
myAdapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
if(Integer.parseInt(pQuantity.get(position)) > 1) {
|
||||
@ -391,7 +433,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
||||
pImages.remove(position);
|
||||
|
||||
requestor.deleteObject(pListItemPair.remove(position));
|
||||
listView.setAdapter(myAdapter);
|
||||
myAdapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@ -90,8 +90,13 @@ public class ListPickerDialogFragment extends DialogFragment {
|
||||
btnMinus.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// Set to 1 if it is empty
|
||||
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));
|
||||
}
|
||||
@ -102,6 +107,11 @@ public class ListPickerDialogFragment extends DialogFragment {
|
||||
btnPlus.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// Set to 1 if it is empty
|
||||
if (etQuantity.getText().toString().equals("")) {
|
||||
etQuantity.setText("1");
|
||||
}
|
||||
|
||||
int curQauntity = Integer.parseInt(etQuantity.getText().toString());
|
||||
curQauntity++;
|
||||
etQuantity.setText(String.format("%d", curQauntity));
|
||||
|
||||
@ -154,7 +154,7 @@ public class MainActivity extends AppCompatActivity implements CreateListDialogF
|
||||
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
||||
NavigationView navigationView = findViewById(R.id.nav_view);
|
||||
mAppBarConfiguration = new AppBarConfiguration.Builder(
|
||||
R.id.nav_home, R.id.nav_profile)
|
||||
R.id.nav_home, R.id.nav_profile, R.id.nav_logout)
|
||||
.setDrawerLayout(drawer)
|
||||
.build();
|
||||
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
|
||||
@ -179,20 +179,14 @@ public class MainActivity extends AppCompatActivity implements CreateListDialogF
|
||||
}
|
||||
|
||||
public void onClickSignout(MenuItem m) {
|
||||
m.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
try {
|
||||
am.signOutUser();
|
||||
Intent intent = new Intent(MainActivity.this, com.example.listify.ui.LoginPage.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Log.i("Authentication", e.toString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
try {
|
||||
am.signOutUser();
|
||||
Intent intent = new Intent(MainActivity.this, com.example.listify.ui.LoginPage.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Log.i("Authentication", e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -13,6 +13,8 @@ import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.SearchView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.example.listify.adapter.SearchResultsListAdapter;
|
||||
import com.example.listify.data.Chain;
|
||||
import com.example.listify.data.ItemSearch;
|
||||
@ -28,9 +30,10 @@ import java.util.Properties;
|
||||
import static com.example.listify.MainActivity.am;
|
||||
|
||||
public class SearchResults extends AppCompatActivity implements FilterDialogFragment.OnFilterListener, SortDialogFragment.OnSortListener, Requestor.Receiver {
|
||||
private ListView listView;
|
||||
private ListView resultsListView;
|
||||
private MenuItem filterItem;
|
||||
private ProgressBar loadingSearch;
|
||||
private TextView tvNoResults;
|
||||
private SearchResultsListAdapter searchResultsListAdapter;
|
||||
private List<Product> resultsProductList = new ArrayList<>();
|
||||
private List<Product> resultsProductListSorted = new ArrayList<>();
|
||||
@ -64,6 +67,7 @@ public class SearchResults extends AppCompatActivity implements FilterDialogFrag
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
loadingSearch = (ProgressBar) findViewById(R.id.progress_loading_search);
|
||||
tvNoResults = (TextView) findViewById(R.id.tv_search_no_results);
|
||||
|
||||
// Back button closes this activity and returns to previous activity (MainActivity)
|
||||
ImageButton backButton = (ImageButton) findViewById(R.id.backToHomeButton);
|
||||
@ -95,10 +99,10 @@ public class SearchResults extends AppCompatActivity implements FilterDialogFrag
|
||||
}
|
||||
});
|
||||
|
||||
ListView listView = (ListView) findViewById(R.id.search_results_list);
|
||||
resultsListView = (ListView) findViewById(R.id.search_results_list);
|
||||
searchResultsListAdapter = new SearchResultsListAdapter(this, resultsProductListSorted);
|
||||
listView.setAdapter(searchResultsListAdapter);
|
||||
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
resultsListView.setAdapter(searchResultsListAdapter);
|
||||
resultsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
Intent itemDetailsPage = new Intent(SearchResults.this, ItemDetails.class);
|
||||
@ -207,13 +211,22 @@ public class SearchResults extends AppCompatActivity implements FilterDialogFrag
|
||||
requestor.getObject(query, ItemSearch.class, this);
|
||||
}
|
||||
|
||||
// TODO: Scroll the list back to the top when a search, sort, or filter is performed
|
||||
// Sorts the search results
|
||||
private void sortResults() {
|
||||
// Reset the filtered list
|
||||
resultsProductListSorted.clear();
|
||||
resultsProductListSorted.addAll(resultsProductList);
|
||||
|
||||
// Scroll the user back to the top of the results
|
||||
if (resultsListView != null) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
resultsListView.smoothScrollToPosition(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Sort Modes
|
||||
// 0 default (no sorting)
|
||||
// 1 itemName
|
||||
@ -311,10 +324,22 @@ public class SearchResults extends AppCompatActivity implements FilterDialogFrag
|
||||
}
|
||||
|
||||
// This is called after the search results come back from the server
|
||||
// TODO: Display a "no results" message if nothing is found when searching
|
||||
@Override
|
||||
public void acceptDelivery(Object delivered) {
|
||||
ItemSearch results = (ItemSearch) delivered;
|
||||
|
||||
// Display "no results" message if the search returns none
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (results.getResults().size() == 0) {
|
||||
tvNoResults.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
tvNoResults.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
HashMap<Integer,String> chainNameMap = new HashMap<>();
|
||||
for (int i = 0; i < results.getResults().size(); i++) {
|
||||
|
||||
@ -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());
|
||||
|
||||
@ -10,6 +10,7 @@ import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.example.listify.model.Product;
|
||||
import com.example.listify.R;
|
||||
|
||||
@ -55,8 +56,12 @@ public class SearchResultsListAdapter extends BaseAdapter {
|
||||
TextView itemStore = (TextView) convertView.findViewById(R.id.item_store);
|
||||
|
||||
Product product = productList.get(position);
|
||||
// TODO: If image url is broken, display @drawable/ic_baseline_broken_image_600.xml
|
||||
Glide.with(activity).load(product.getImageUrl()).into(productImage);
|
||||
|
||||
Glide.with(activity)
|
||||
.applyDefaultRequestOptions(new RequestOptions().placeholder(R.drawable.ic_baseline_image_600).error(R.drawable.ic_baseline_broken_image_600))
|
||||
.load(product.getImageUrl())
|
||||
.into(productImage);
|
||||
|
||||
if (product.getItemName().length() >= 60) {
|
||||
itemName.setText(product.getItemName().substring(0, 60) + "...");
|
||||
} else {
|
||||
|
||||
@ -80,7 +80,8 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter {
|
||||
holder.frontView = convertView.findViewById(R.id.front_layout);
|
||||
holder.deleteList = convertView.findViewById(R.id.delete_list);
|
||||
holder.shareList = convertView.findViewById(R.id.share_list);
|
||||
holder.textView = (TextView) convertView.findViewById(R.id.shopping_list_name);
|
||||
holder.listName = (TextView) convertView.findViewById(R.id.shopping_list_name);
|
||||
holder.itemCount = (TextView) convertView.findViewById(R.id.shopping_list_item_count);
|
||||
|
||||
convertView.setTag(holder);
|
||||
} else {
|
||||
@ -93,11 +94,14 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter {
|
||||
binderHelper.bind(holder.swipeLayout, Integer.toString(curList.getListID()));
|
||||
|
||||
if(curList.isShared()) {
|
||||
holder.textView.setText(curList.getName() + " (shared)");
|
||||
holder.listName.setText(curList.getName() + " (shared)");
|
||||
}
|
||||
else {
|
||||
holder.textView.setText(curList.getName());
|
||||
holder.listName.setText(curList.getName());
|
||||
}
|
||||
|
||||
holder.itemCount.setText(String.format("%d items", curList.getEntries().length));
|
||||
|
||||
holder.deleteList.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@ -157,8 +161,10 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter {
|
||||
public void onClick(View v) {
|
||||
Intent listPage = new Intent(activity, ListPage.class);
|
||||
|
||||
// Send the list ID
|
||||
// Send the list ID and list name
|
||||
listPage.putExtra("listID", curList.getListID());
|
||||
listPage.putExtra("listName", curList.getName());
|
||||
|
||||
activity.startActivity(listPage);
|
||||
}
|
||||
});
|
||||
@ -171,6 +177,7 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter {
|
||||
View frontView;
|
||||
View deleteList;
|
||||
View shareList;
|
||||
TextView textView;
|
||||
TextView listName;
|
||||
TextView itemCount;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
package com.example.listify.ui.home;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
public class HomeViewModel extends ViewModel {
|
||||
|
||||
private MutableLiveData<String> mText;
|
||||
|
||||
public HomeViewModel() {
|
||||
mText = new MutableLiveData<>();
|
||||
mText.setValue("This is home fragment");
|
||||
}
|
||||
|
||||
public LiveData<String> getText() {
|
||||
return mText;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M10.09,15.59L11.5,17l5,-5 -5,-5 -1.41,1.41L12.67,11H3v2h9.67l-2.58,2.59zM19,3H5c-1.11,0 -2,0.9 -2,2v4h2V5h14v14H5v-4H3v4c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2V5c0,-1.1 -0.9,-2 -2,-2z"/>
|
||||
</vector>
|
||||
@ -0,0 +1,5 @@
|
||||
<vector android:height="600dp" android:tint="?attr/colorControlNormal"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="600dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M21,19V5c0,-1.1 -0.9,-2 -2,-2H5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2zM8.5,13.5l2.5,3.01L14.5,12l4.5,6H5l3.5,-4.5z"/>
|
||||
</vector>
|
||||
@ -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"
|
||||
|
||||
@ -29,4 +29,14 @@
|
||||
android:divider="@color/list_divider"
|
||||
android:dividerHeight="1dp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_search_no_results"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="80dp"
|
||||
android:textSize="20sp"
|
||||
android:text="No Results"
|
||||
android:gravity="center"
|
||||
android:visibility="gone"/>
|
||||
|
||||
</RelativeLayout>
|
||||
@ -38,6 +38,7 @@
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="50dp"
|
||||
android:text="@string/_1"
|
||||
android:digits="0123456789"
|
||||
android:inputType="number"/>
|
||||
|
||||
<Button
|
||||
|
||||
@ -35,6 +35,7 @@
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="50dp"
|
||||
android:text="@string/_1"
|
||||
android:digits="0123456789"
|
||||
android:inputType="number"/>
|
||||
|
||||
<Button
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -40,11 +40,18 @@
|
||||
android:layout_height="50dp">
|
||||
<TextView
|
||||
android:id="@+id/shopping_list_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="20sp"
|
||||
android:textStyle="bold"
|
||||
android:layout_gravity="center"/>
|
||||
android:layout_gravity="center_vertical"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/shopping_list_item_count"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="20sp"
|
||||
android:layout_gravity="center_vertical|end"/>
|
||||
</FrameLayout>
|
||||
|
||||
</com.chauthai.swipereveallayout.SwipeRevealLayout>
|
||||
@ -17,7 +17,8 @@
|
||||
<item
|
||||
android:id="@+id/nav_logout"
|
||||
android:title="Sign out"
|
||||
android:onClick="onClickSignout" />
|
||||
android:onClick="onClickSignout"
|
||||
android:icon="@drawable/ic_baseline_exit_to_app_24"/>
|
||||
|
||||
<!-- <item-->
|
||||
<!-- android:id="@+id/nav_gallery"-->
|
||||
|
||||
Loading…
Reference in New Issue
Block a user