mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 18:48:48 +00:00
Connected List UI with API
This commit is contained in:
parent
6b3a645b4a
commit
2d80ff2282
@ -34,7 +34,7 @@
|
|||||||
<activity android:name="com.example.listify.ui.LoginPage" />
|
<activity android:name="com.example.listify.ui.LoginPage" />
|
||||||
<activity android:name="com.example.listify.ui.ForgotPasswordPage" />
|
<activity android:name="com.example.listify.ui.ForgotPasswordPage" />
|
||||||
<activity android:name="com.example.listify.ui.ResetPasswordPage" />
|
<activity android:name="com.example.listify.ui.ResetPasswordPage" />
|
||||||
<activity android:name="com.example.listify.List" />
|
<activity android:name="com.example.listify.ListPage" />
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@ -13,13 +13,24 @@ import android.widget.EditText;
|
|||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
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.ArrayList;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
public class List extends AppCompatActivity {
|
public class ListPage extends AppCompatActivity {
|
||||||
ListView listView;
|
ListView listView;
|
||||||
MyAdapter myAdapter;
|
MyAdapter myAdapter;
|
||||||
|
|
||||||
@ -33,8 +44,50 @@ public class List extends AppCompatActivity {
|
|||||||
ArrayList<String> pQuantity = new ArrayList<>(); //String[] pQuantity = {"1"};
|
ArrayList<String> pQuantity = new ArrayList<>(); //String[] pQuantity = {"1"};
|
||||||
ArrayList<Integer> pImages = new ArrayList<>(); //int[] pImages = {R.drawable.milk};
|
ArrayList<Integer> pImages = new ArrayList<>(); //int[] pImages = {R.drawable.milk};
|
||||||
|
|
||||||
|
Requestor requestor;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
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<>();
|
||||||
|
requestor.getObject("-1", List.class, lr, 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");
|
pNames.add("Half-gallon organic whole milk");
|
||||||
pStores.add("Kroger");
|
pStores.add("Kroger");
|
||||||
pPrices.add("$5.00");
|
pPrices.add("$5.00");
|
||||||
@ -53,8 +106,6 @@ public class List extends AppCompatActivity {
|
|||||||
pQuantity.add("1");
|
pQuantity.add("1");
|
||||||
pImages.add(R.drawable.peanutbutter);
|
pImages.add(R.drawable.peanutbutter);
|
||||||
|
|
||||||
int currSize = pNames.size();
|
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_list);
|
setContentView(R.layout.activity_list);
|
||||||
|
|
||||||
@ -151,4 +202,27 @@ public class List extends AppCompatActivity {
|
|||||||
return listproduct;
|
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);
|
||||||
|
}
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
@ -29,6 +29,8 @@ import java.util.Random;
|
|||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
private AppBarConfiguration mAppBarConfiguration;
|
private AppBarConfiguration mAppBarConfiguration;
|
||||||
|
|
||||||
|
public static AuthManager am = new AuthManager();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import android.widget.EditText;
|
|||||||
import com.example.listify.R;
|
import com.example.listify.R;
|
||||||
import com.example.listify.AuthManager;
|
import com.example.listify.AuthManager;
|
||||||
import com.example.listify.MainActivity;
|
import com.example.listify.MainActivity;
|
||||||
|
import static com.example.listify.MainActivity.am;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
@ -51,10 +52,8 @@ public class LoginPage extends AppCompatActivity {
|
|||||||
String email = emailText.getText().toString();
|
String email = emailText.getText().toString();
|
||||||
String password = passwordText.getText().toString();
|
String password = passwordText.getText().toString();
|
||||||
|
|
||||||
AuthManager authManager = new AuthManager();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
authManager.signIn(email, password);
|
am.signIn(email, password);
|
||||||
Intent intent = new Intent(LoginPage.this, MainActivity.class);
|
Intent intent = new Intent(LoginPage.this, MainActivity.class);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import android.widget.EditText;
|
|||||||
import com.example.listify.R;
|
import com.example.listify.R;
|
||||||
import com.example.listify.AuthManager;
|
import com.example.listify.AuthManager;
|
||||||
import com.example.listify.MainActivity;
|
import com.example.listify.MainActivity;
|
||||||
|
import static com.example.listify.MainActivity.am;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
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 button1; //Log in page button
|
||||||
private Button button2; //Sign up button
|
private Button button2; //Sign up button
|
||||||
|
|
||||||
AuthManager authManager = new AuthManager();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -44,7 +43,7 @@ public class SignupPage extends AppCompatActivity implements CodePage.CodeDialog
|
|||||||
String password = passwordText.getText().toString();
|
String password = passwordText.getText().toString();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
authManager.startSignUp(email, password);
|
am.startSignUp(email, password);
|
||||||
}
|
}
|
||||||
catch(Exception e) {
|
catch(Exception e) {
|
||||||
return;
|
return;
|
||||||
@ -67,7 +66,7 @@ public class SignupPage extends AppCompatActivity implements CodePage.CodeDialog
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
authManager.confirmSignUp(code);
|
am.confirmSignUp(code);
|
||||||
Intent intent = new Intent(SignupPage.this, MainActivity.class);
|
Intent intent = new Intent(SignupPage.this, MainActivity.class);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,7 +32,7 @@ public class HomeFragment extends Fragment {
|
|||||||
toListPage.setOnClickListener(new View.OnClickListener() {
|
toListPage.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
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);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user