Merge pull request #43 from ClaytonWWilson/aaron-branch

Aaron branch
This commit is contained in:
DreamCoder23 2020-10-08 16:11:28 -07:00 committed by GitHub
commit b68e22ee23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 88 additions and 13 deletions

View File

@ -40,8 +40,7 @@
<activity android:name="com.example.listify.ui.LoginPage" />
<activity android:name="com.example.listify.ui.ForgotPasswordPage" />
<activity android:name="com.example.listify.ui.ResetPasswordPage" />
<activity android:name="com.example.listify.List" />
<activity android:name="com.example.listify.ListPage" />
</application>
</manifest>

View File

@ -13,13 +13,24 @@ import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.example.listify.data.Item;
import com.example.listify.data.List;
import com.example.listify.data.ListEntry;
import com.example.listify.model.Product;
import static com.example.listify.MainActivity.am;
import org.json.JSONException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Properties;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
public class List extends AppCompatActivity {
public class ListPage extends AppCompatActivity {
ListView listView;
MyAdapter myAdapter;
@ -33,8 +44,51 @@ public class List extends AppCompatActivity {
ArrayList<String> pQuantity = new ArrayList<>(); //String[] pQuantity = {"1"};
ArrayList<Integer> pImages = new ArrayList<>(); //int[] pImages = {R.drawable.milk};
Requestor requestor;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
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"));
SynchronousReceiver<List> lr = new SynchronousReceiver<>();
//ListReceiver<List> lr = new ListReceiver<>();
requestor.getObject("39", List.class, lr);
List list;
try {
list = lr.await();
}
catch(Exception e) {
list = null;
}
if(list != null) {
for (ListEntry entry : list.getEntries()) {
int product = entry.getProductID();
SynchronousReceiver<Item> pr = new SynchronousReceiver<>();
requestor.getObject(Integer.toString(product), Item.class, pr, pr);
Item item;
try {
item = pr.await();
} catch (Exception e) {
item = null;
}
if(item != null) {
pNames.add(item.getDescription());
pStores.add("Kroger");
pPrices.add(item.getPrice().toString());
pQuantity.add("1");
pImages.add(R.drawable.placeholder);
}
}
}
pNames.add("Half-gallon organic whole milk");
pStores.add("Kroger");
pPrices.add("$5.00");
@ -53,8 +107,6 @@ public class List extends AppCompatActivity {
pQuantity.add("1");
pImages.add(R.drawable.peanutbutter);
int currSize = pNames.size();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
@ -151,4 +203,27 @@ public class List extends AppCompatActivity {
return listproduct;
}
}
class ListReceiver<T> implements Requestor.Receiver<T> {
@Override
public void acceptDelivery(T delivered) {
for(ListEntry entry : ((List) delivered).getEntries()) {
int product = entry.getProductID();
ProductReceiver<Item> pr = new ProductReceiver<>();
requestor.getObject(Integer.toString(product), Item.class, pr);
pQuantity.add("1");
}
}
}
class ProductReceiver<T> implements Requestor.Receiver<T> {
@Override
public void acceptDelivery(T delivered) {
Item i = (Item) delivered;
pNames.add(i.getDescription());
pStores.add("Kroger");
pPrices.add(i.getPrice().toString());
pImages.add(R.drawable.placeholder);
}
}
}

View File

@ -30,6 +30,8 @@ import java.util.Random;
public class MainActivity extends AppCompatActivity implements CreateListDialogFragment.OnNewListListener {
private AppBarConfiguration mAppBarConfiguration;
public static AuthManager am = new AuthManager();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -86,6 +88,7 @@ public class MainActivity extends AppCompatActivity implements CreateListDialogF
List testList = new List(-1, "New List", "user filled by lambda", Instant.now().toEpochMilli());
//Everything except addedDate is used for ItemEntry
ListEntry entry = new ListEntry(1, 4, Math.abs(new Random().nextInt()), Instant.now().toEpochMilli(),false);
SynchronousReceiver<Integer> idReceiver = new SynchronousReceiver<>();
try {
requestor.postObject(testList, idReceiver, idReceiver);

View File

@ -10,6 +10,7 @@ import android.widget.EditText;
import com.example.listify.R;
import com.example.listify.AuthManager;
import com.example.listify.MainActivity;
import static com.example.listify.MainActivity.am;
import androidx.appcompat.app.AppCompatActivity;
@ -51,10 +52,8 @@ public class LoginPage extends AppCompatActivity {
String email = emailText.getText().toString();
String password = passwordText.getText().toString();
AuthManager authManager = new AuthManager();
try {
authManager.signIn(email, password);
am.signIn(email, password);
Intent intent = new Intent(LoginPage.this, MainActivity.class);
startActivity(intent);
}

View File

@ -10,6 +10,7 @@ import android.widget.EditText;
import com.example.listify.R;
import com.example.listify.AuthManager;
import com.example.listify.MainActivity;
import static com.example.listify.MainActivity.am;
import androidx.appcompat.app.AppCompatActivity;
@ -17,8 +18,6 @@ public class SignupPage extends AppCompatActivity implements CodePage.CodeDialog
private Button button1; //Log in page button
private Button button2; //Sign up button
AuthManager authManager = new AuthManager();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -44,7 +43,7 @@ public class SignupPage extends AppCompatActivity implements CodePage.CodeDialog
String password = passwordText.getText().toString();
try {
authManager.startSignUp(email, password);
am.startSignUp(email, password);
}
catch(Exception e) {
return;
@ -67,7 +66,7 @@ public class SignupPage extends AppCompatActivity implements CodePage.CodeDialog
}
else {
try {
authManager.confirmSignUp(code);
am.confirmSignUp(code);
Intent intent = new Intent(SignupPage.this, MainActivity.class);
startActivity(intent);
}

View File

@ -32,7 +32,7 @@ public class HomeFragment extends Fragment {
toListPage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(HomeFragment.this.getActivity(), com.example.listify.List.class);
Intent intent = new Intent(HomeFragment.this.getActivity(), com.example.listify.ListPage.class);
startActivity(intent);
}
});