Merge branch 'search-history' into sharing-permissions

This commit is contained in:
NMerz
2020-11-14 14:32:27 -05:00
10 changed files with 210 additions and 8 deletions

View File

@@ -16,19 +16,15 @@ import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;
import com.amplifyframework.auth.AuthException;
import com.example.listify.data.Item;
import com.example.listify.data.ItemSearch;
import com.example.listify.data.List;
import com.example.listify.data.ListEntry;
import com.example.listify.data.SearchHistory;
import com.example.listify.ui.LoginPage;
import com.google.android.material.navigation.NavigationView;
import org.json.JSONException;
import java.io.IOException;
import java.time.Instant;
import java.util.Arrays;
import java.util.Properties;
import java.util.Random;
import static com.example.listify.SplashActivity.showSplash;
@@ -108,7 +104,14 @@ public class MainActivity extends AppCompatActivity implements CreateListDialogF
}
Requestor requestor = new Requestor(authManager, configs.getProperty("apiKey"));
SynchronousReceiver<SearchHistory> historyReceiver = new SynchronousReceiver<>();
requestor.getObject("N/A", SearchHistory.class, historyReceiver, historyReceiver);
try {
System.out.println(historyReceiver.await());
} catch (Exception e) {
e.printStackTrace();
}
/*
List testList = new List(-1, "New List", "user filled by lambda", Instant.now().toEpochMilli());
ListEntry entry = new ListEntry(1, 4, Math.abs(new Random().nextInt()), Instant.now().toEpochMilli(),false);
@@ -139,6 +142,7 @@ public class MainActivity extends AppCompatActivity implements CreateListDialogF
} catch (Exception receiverError) {
receiverError.printStackTrace();
}
*/
}
//------------------------------------------------------------------------------------------//

View File

@@ -60,6 +60,25 @@ public class Requestor {
launchCall(deleteRequest, null, classType, failureHandler);
}
public void putObject(Object toPost) throws JSONException {
putObject(toPost, (RequestErrorHandler) null);
}
public void putObject(Object toPost, RequestErrorHandler failureHandler) throws JSONException {
putObject(toPost, null, failureHandler);
}
public void putObject(Object toPost, Receiver<Integer> idReceiver) throws JSONException {
putObject(toPost, idReceiver, null);
}
public void putObject(Object toPut, Receiver<Integer> idReceiver, RequestErrorHandler failureHandler) throws JSONException {
String putURL = DEV_BASEURL + "/" + toPut.getClass().getSimpleName();
Request putRequest = buildBaseRequest(putURL, "PUT", new Gson().toJson(toPut));
launchCall(putRequest, idReceiver, Integer.class, failureHandler);
}
public void postObject(Object toPost) throws JSONException {
postObject(toPost, (RequestErrorHandler) null);
}
@@ -85,7 +104,7 @@ public class Requestor {
String responseString = response.body().string();
if (receiver != null) {
if (classType == null) {
Log.e("Requestor Contract Error", "classType while receiver populated");
Log.e("Requestor Contract Error", "no/null classType while receiver populated");
}
try {
receiver.acceptDelivery(new Gson().fromJson(responseString, classType));

View File

@@ -0,0 +1,30 @@
package com.example.listify.data;
import java.util.ArrayList;
public class SearchHistory {
ArrayList<String> searches;
public SearchHistory(ArrayList<String> searches) {
this.searches = searches;
}
public ArrayList<String> getSearches() {
return searches;
}
public void setSearches(ArrayList<String> searches) {
this.searches = searches;
}
public void addSearch(String newSearch) {
searches.add(newSearch);
}
@Override
public String toString() {
return "SearchHistory{" +
"searches=" + searches +
'}';
}
}