mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 10:48:46 +00:00
Viewing sharees v1
This commit is contained in:
parent
5f14d24625
commit
519feec6f4
@ -249,7 +249,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
|
|
||||||
|
|
||||||
MyAdapter (Context c, ArrayList<String> names, ArrayList<String> stores, ArrayList<String> prices, ArrayList<String> quantity, ArrayList<String> images) {
|
MyAdapter (Context c, ArrayList<String> names, ArrayList<String> stores, ArrayList<String> prices, ArrayList<String> quantity, ArrayList<String> images) {
|
||||||
super(c, R.layout.activity_listproductentry, R.id.productView, names);
|
super(c, R.layout.shopping_list_product_entry, R.id.productView, names);
|
||||||
context = c;
|
context = c;
|
||||||
pNames = names;
|
pNames = names;
|
||||||
pStores = stores;
|
pStores = stores;
|
||||||
@ -262,7 +262,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
@Override
|
@Override
|
||||||
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
||||||
LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
View listproduct = layoutInflater.inflate(R.layout.activity_listproductentry, parent,false);
|
View listproduct = layoutInflater.inflate(R.layout.shopping_list_product_entry, parent,false);
|
||||||
|
|
||||||
decrQuan = (Button) listproduct.findViewById(R.id.buttonDecr);
|
decrQuan = (Button) listproduct.findViewById(R.id.buttonDecr);
|
||||||
incrQuan = (Button) listproduct.findViewById(R.id.buttonIncr);
|
incrQuan = (Button) listproduct.findViewById(R.id.buttonIncr);
|
||||||
|
|||||||
102
Listify/app/src/main/java/com/example/listify/ListSharees.java
Normal file
102
Listify/app/src/main/java/com/example/listify/ListSharees.java
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
package com.example.listify;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.ListView;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.bumptech.glide.Glide;
|
||||||
|
import com.example.listify.adapter.ShareeSwipeableAdapter;
|
||||||
|
import com.example.listify.adapter.ShoppingListsSwipeableAdapter;
|
||||||
|
import com.example.listify.data.Chain;
|
||||||
|
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 org.json.JSONException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import static com.example.listify.MainActivity.am;
|
||||||
|
|
||||||
|
public class ListSharees extends AppCompatActivity implements Requestor.Receiver {
|
||||||
|
ShareeSwipeableAdapter myAdapter;
|
||||||
|
Requestor requestor;
|
||||||
|
ProgressBar loadingListItems;
|
||||||
|
|
||||||
|
|
||||||
|
DecimalFormat df = new DecimalFormat("0.00");
|
||||||
|
|
||||||
|
// TODO: Display a message if their list is empty
|
||||||
|
@Override
|
||||||
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_listofsharees);
|
||||||
|
|
||||||
|
final int listID = (int) getIntent().getSerializableExtra("listID");
|
||||||
|
|
||||||
|
Properties configs = new Properties();
|
||||||
|
try {
|
||||||
|
configs = AuthManager.loadProperties(this, "android.resource://" + getPackageName() + "/raw/auths.json");
|
||||||
|
} catch (IOException | JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
requestor = new Requestor(am, configs.getProperty("apiKey"));
|
||||||
|
requestor.getObject(Integer.toString(listID), ListShare.class, this);
|
||||||
|
|
||||||
|
loadingListItems = findViewById(R.id.progress_loading_list_items);
|
||||||
|
loadingListItems.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void acceptDelivery(Object delivered) {
|
||||||
|
ListShare sharee = (ListShare) delivered;
|
||||||
|
|
||||||
|
if(sharee != null) {
|
||||||
|
SynchronousReceiver<ListShare> listShareReceiver = new SynchronousReceiver<>();
|
||||||
|
requestor.getObject(Integer.toString(sharee.getListID()), ListShare.class, listShareReceiver, listShareReceiver);
|
||||||
|
|
||||||
|
ArrayList<ListShare> resultList = new ArrayList<>();
|
||||||
|
ListShare result;
|
||||||
|
|
||||||
|
try {
|
||||||
|
result = listShareReceiver.await();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
result = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(result != null) {
|
||||||
|
resultList.add(result);
|
||||||
|
|
||||||
|
for(ListShare r : result.getEntries()) {
|
||||||
|
resultList.add(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
myAdapter = new ShareeSwipeableAdapter(this, resultList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,128 @@
|
|||||||
|
package com.example.listify.adapter;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.BaseAdapter;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.chauthai.swipereveallayout.SwipeRevealLayout;
|
||||||
|
import com.chauthai.swipereveallayout.ViewBinderHelper;
|
||||||
|
import com.example.listify.AuthManager;
|
||||||
|
import com.example.listify.ListPage;
|
||||||
|
import com.example.listify.R;
|
||||||
|
import com.example.listify.Requestor;
|
||||||
|
import com.example.listify.data.List;
|
||||||
|
import com.example.listify.data.ListShare;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import static com.example.listify.MainActivity.am;
|
||||||
|
|
||||||
|
public class ShareeSwipeableAdapter extends BaseAdapter {
|
||||||
|
private Activity activity;
|
||||||
|
private ArrayList<ListShare> sharees;
|
||||||
|
private LayoutInflater inflater;
|
||||||
|
private final ViewBinderHelper binderHelper;
|
||||||
|
|
||||||
|
public ShareeSwipeableAdapter(Activity activity, ArrayList<ListShare> sharees){
|
||||||
|
binderHelper = new ViewBinderHelper();
|
||||||
|
this.activity = activity;
|
||||||
|
this.sharees = sharees;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
return sharees.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getItem(int position) {
|
||||||
|
return sharees.get(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getItemId(int position) {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
|
ViewHolder holder;
|
||||||
|
|
||||||
|
Properties configs = new Properties();
|
||||||
|
try {
|
||||||
|
configs = AuthManager.loadProperties(activity, "android.resource://" + activity.getPackageName() + "/raw/auths.json");
|
||||||
|
} catch (IOException | JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
Requestor requestor = new Requestor(am, configs.getProperty("apiKey"));
|
||||||
|
|
||||||
|
if (inflater == null) {
|
||||||
|
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
|
}
|
||||||
|
if (convertView == null) {
|
||||||
|
convertView = inflater.inflate(R.layout.shopping_lists_swipeable_name_item, null);
|
||||||
|
|
||||||
|
holder = new ViewHolder();
|
||||||
|
holder.swipeLayout = (SwipeRevealLayout)convertView.findViewById(R.id.swipe_layout);
|
||||||
|
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);
|
||||||
|
|
||||||
|
convertView.setTag(holder);
|
||||||
|
} else {
|
||||||
|
holder = (ViewHolder) convertView.getTag();
|
||||||
|
}
|
||||||
|
|
||||||
|
final ListShare currSharee = sharees.get(position);
|
||||||
|
|
||||||
|
// Bind the view to the unique list ID
|
||||||
|
binderHelper.bind(holder.swipeLayout, currSharee.getShareWithEmail());
|
||||||
|
|
||||||
|
holder.textView.setText(currSharee.getShareWithEmail());
|
||||||
|
|
||||||
|
holder.deleteList.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
holder.shareList.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
holder.frontView.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return convertView;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ViewHolder {
|
||||||
|
SwipeRevealLayout swipeLayout;
|
||||||
|
View frontView;
|
||||||
|
View deleteList;
|
||||||
|
View shareList;
|
||||||
|
TextView textView;
|
||||||
|
}
|
||||||
|
}
|
||||||
22
Listify/app/src/main/res/layout/activity_listofsharees.xml
Normal file
22
Listify/app/src/main/res/layout/activity_listofsharees.xml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<RelativeLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/progress_loading_list_items"
|
||||||
|
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
|
||||||
|
android:id="@+id/listOfSharees"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginTop="0dp" />
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
Loading…
Reference in New Issue
Block a user