diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index fe328c8..f79a265 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -4,6 +4,8 @@
+
+
images;
private ImageAdapter adapter;
@@ -104,10 +104,7 @@ public void onItemClick(AdapterView> parent, View view, int position, long id)
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
-// if (resultCode == RESULT_OK && requestCode == REQUEST_CODE) {
-// // Extract name value from result extras
-// searchFilter = (Filter) data.getSerializableExtra("Filter");
-// }
+ super.onActivityResult(requestCode, resultCode, data);
}
public String applyFilters(String url, String query) {
@@ -146,7 +143,6 @@ public boolean onQueryTextSubmit(String query) {
// Create Network client
httpClient = new AsyncHttpClient();
// Create search url
-// searchURL = url + query;
searchURL = applyFilters(url, query);
if(isNetworkAvailable()) {
@@ -177,6 +173,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
//noinspection SimplifiableIfStatement
case R.id.action_settings:
return true;
+ // Settings option selected
case R.id.miFilters:
showSettings();
return true;
@@ -188,11 +185,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
// Helper methods
private void showSettings() {
-// // Create an Intent
-// Intent settingsIntent = new Intent(ImageSearchActivity.this, SettingsActivity.class);
-//// settingsIntent.putExtra("Filter", searchFilter);
-// // Start the activity
-// startActivityForResult(settingsIntent, REQUEST_CODE);
+ // Creating Dialog Fragment
FragmentManager fm = getSupportFragmentManager();
SettingsFilterDialog filterDialog = SettingsFilterDialog.newInstance("Advanced Filters");
filterDialog.show(fm, "fragment_settings_filter_dialog");
@@ -211,16 +204,16 @@ public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
imageListJSON = response.getJSONObject("responseData").getJSONArray("results");
// Cleat list for the initial search (not for pagination)
images.clear();
-// Add images to the list
-// images.addAll(Image.fromJSONArray(imageListJSON));
-//// Refresh data by notifying adapter
-// adapter.notifyDataSetChanged();
+ // Add images to the list
+ // images.addAll(Image.fromJSONArray(imageListJSON));
+ // Refresh data by notifying adapter
+ // adapter.notifyDataSetChanged();
// Using another approach of updating adapter itself and hence it will trigger the change to datasource
adapter.addAll(Image.fromJSONArray(imageListJSON));
} catch (JSONException e) {
-// Log.e("ImageSearchActivity", "Failed to parse response json");
+ Log.e("ImageSearchActivity", "Failed to parse response json");
e.printStackTrace();
}
}
@@ -234,7 +227,7 @@ public void onFailure(int statusCode, Header[] headers, String responseString, T
}
public void fetchImagesWhileScrolling(String url, int page) {
- int offset = 8*(page-1);
+ int offset = kNumberOfImagesPerPage*(page-1);
String finalURL = url + "&start=" + offset;
httpClient.get(finalURL, new JsonHttpResponseHandler() {
@@ -262,6 +255,7 @@ public void onFailure(int statusCode, Header[] headers, String responseString, T
});
}
+ // Check if Internet is available
private Boolean isNetworkAvailable() {
ConnectivityManager connectivityManager
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
diff --git a/app/src/main/java/com/example/vikramjeet/activities/SettingsActivity.java b/app/src/main/java/com/example/vikramjeet/activities/SettingsActivity.java
index 985c243..5712a68 100644
--- a/app/src/main/java/com/example/vikramjeet/activities/SettingsActivity.java
+++ b/app/src/main/java/com/example/vikramjeet/activities/SettingsActivity.java
@@ -17,6 +17,7 @@
public class SettingsActivity extends ActionBarActivity {
+ private final int kDefaultSelection = 0;
private String imageSize;
private String imageColor;
private String imageType;
@@ -46,7 +47,7 @@ protected void onCreate(Bundle savedInstanceState) {
spinnerImageSize.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView> parent, View view, int position, long id) {
- if (position > 0) {
+ if (position > kDefaultSelection) {
imageSize = (String) parent.getItemAtPosition(position);
}
}
@@ -71,7 +72,7 @@ public void onNothingSelected(AdapterView> parent) {
spinnerColorFilter.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView> parent, View view, int position, long id) {
- if (position > 0) {
+ if (position > kDefaultSelection) {
imageColor = (String) parent.getItemAtPosition(position);
}
}
@@ -95,7 +96,7 @@ public void onNothingSelected(AdapterView> parent) {
spinnerImageSize.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView> parent, View view, int position, long id) {
- if (position > 0) {
+ if (position > kDefaultSelection) {
imageType = (String) parent.getItemAtPosition(position);
}
}
diff --git a/app/src/main/java/com/example/vikramjeet/fragments/SettingsFilterDialog.java b/app/src/main/java/com/example/vikramjeet/fragments/SettingsFilterDialog.java
index 05e85fc..bd257ee 100644
--- a/app/src/main/java/com/example/vikramjeet/fragments/SettingsFilterDialog.java
+++ b/app/src/main/java/com/example/vikramjeet/fragments/SettingsFilterDialog.java
@@ -29,6 +29,7 @@
*/
public class SettingsFilterDialog extends DialogFragment implements TextView.OnClickListener {
+ private final int kDefaultSelection = 0;
private String imageSize;
private String imageColor;
private String imageType;
@@ -77,10 +78,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
cancelButton = (Button) view.findViewById(R.id.btnCancel);
cancelButton.setOnClickListener(this);
-
-// String title = getArguments().getString("title");
-// getDialog().setTitle("title");
-
// Load spinner view
Spinner spinnerImageSize = (Spinner) view.findViewById(R.id.spinnerImageSize);
// Create an ArrayAdapter using the string array using custom spinner layout
@@ -94,7 +91,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
spinnerImageSize.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView> parent, View view, int position, long id) {
- if (position > 0) {
+ if (position > kDefaultSelection) {
imageSize = (String) parent.getItemAtPosition(position);
}
}
@@ -119,7 +116,7 @@ public void onNothingSelected(AdapterView> parent) {
spinnerColorFilter.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView> parent, View view, int position, long id) {
- if (position > 0) {
+ if (position > kDefaultSelection) {
imageColor = (String) parent.getItemAtPosition(position);
}
}
@@ -143,7 +140,7 @@ public void onNothingSelected(AdapterView> parent) {
spinnerImageSize.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView> parent, View view, int position, long id) {
- if (position > 0) {
+ if (position > kDefaultSelection) {
imageType = (String) parent.getItemAtPosition(position);
}
}
diff --git a/app/src/main/java/com/example/vikramjeet/models/Image.java b/app/src/main/java/com/example/vikramjeet/models/Image.java
index 26353cf..ec88784 100644
--- a/app/src/main/java/com/example/vikramjeet/models/Image.java
+++ b/app/src/main/java/com/example/vikramjeet/models/Image.java
@@ -19,6 +19,7 @@ public class Image implements Serializable {
private String title;
private String height;
private String width;
+ private String titleNoFormatting;
public Image(JSONObject json) {
try {
@@ -27,6 +28,8 @@ public Image(JSONObject json) {
title = json.getString("title");
height = json.getString("height");
width = json.getString("width");
+ titleNoFormatting = json.getString("titleNoFormatting");
+
} catch(JSONException e) {
Log.e("Image", "Failed to parse json in constructor");
e.printStackTrace();
@@ -70,4 +73,8 @@ public String getWidth() {
return width;
}
+ public String getTitleNoFormatting() {
+ return titleNoFormatting;
+ }
+
}