diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java index d798f8dc..78b2255e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java @@ -53,6 +53,7 @@ class JSONUtils { static final String SCORE_HIDDEN_KEY = "score_hidden"; static final String SUBREDDIT_KEY = "subreddit"; static final String BANNER_IMG_KEY = "banner_img"; + static final String BANNER_BACKGROUND_IMAGE_KEY = "banner_background_image"; static final String ICON_IMG_KEY = "icon_img"; static final String COMMUNITY_ICON_KEY = "community_icon"; static final String LINK_KARMA_KEY = "link_karma"; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubredditData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubredditData.java index 47fa851e..9a2fe016 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubredditData.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubredditData.java @@ -44,17 +44,23 @@ class ParseSubredditData { String id = data.getString(JSONUtils.NAME_KEY); String subredditFullName = data.getString(JSONUtils.DISPLAY_NAME_PREFIXED); String description = data.getString(JSONUtils.PUBLIC_DESCRIPTION).trim(); - String bannerImageUrl = data.getString(JSONUtils.BANNER_IMG_KEY); - String iconImageUrl = data.getString(JSONUtils.ICON_IMG_KEY); - if(iconImageUrl.equals("") || iconImageUrl.equals("null")) { - iconImageUrl = data.getString(JSONUtils.COMMUNITY_ICON_KEY); - if(iconImageUrl.equals("null")) { - iconImageUrl = ""; + String bannerImageUrl = data.getString(JSONUtils.BANNER_BACKGROUND_IMAGE_KEY); + if(bannerImageUrl.equals("") || bannerImageUrl.equals("null")) { + bannerImageUrl= data.getString(JSONUtils.BANNER_IMG_KEY); + if(bannerImageUrl.equals("null")) { + bannerImageUrl = ""; + } + } + String iconUrl = data.getString(JSONUtils.COMMUNITY_ICON_KEY); + if(iconUrl.equals("") || iconUrl.equals("null")) { + iconUrl = data.getString(JSONUtils.ICON_IMG_KEY); + if(iconUrl.equals("null")) { + iconUrl = ""; } } int nSubscribers = data.getInt(JSONUtils.SUBSCRIBERS_KEY); int nCurrentOnlineSubscribers = data.getInt(JSONUtils.ACTIVE_USER_COUNT); - subredditData = new SubredditData(id, subredditFullName, iconImageUrl, bannerImageUrl, description, nSubscribers); + subredditData = new SubredditData(id, subredditFullName, iconUrl, bannerImageUrl, description, nSubscribers); mNCurrentOnlineSubscribers = nCurrentOnlineSubscribers; } catch (JSONException e) { parseFailed = true; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubscribedThing.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubscribedThing.java index 63b82702..5d0c4606 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubscribedThing.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubscribedThing.java @@ -65,8 +65,20 @@ class ParseSubscribedThing { for(int i = 0; i < children.length(); i++) { JSONObject data = children.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY); String name = data.getString(JSONUtils.DISPLAY_NAME); - String bannerUrl = data.getString(JSONUtils.BANNER_IMG_KEY); - String iconUrl = data.getString(JSONUtils.ICON_IMG_KEY); + String bannerImageUrl = data.getString(JSONUtils.BANNER_IMG_KEY); + if(bannerImageUrl.equals("") || bannerImageUrl.equals("null")) { + bannerImageUrl= data.getString(JSONUtils.BANNER_IMG_KEY); + if(bannerImageUrl.equals("null")) { + bannerImageUrl = ""; + } + } + String iconUrl = data.getString(JSONUtils.COMMUNITY_ICON_KEY); + if(iconUrl.equals("") || iconUrl.equals("null")) { + iconUrl = data.getString(JSONUtils.ICON_IMG_KEY); + if(iconUrl.equals("null")) { + iconUrl = ""; + } + } String id = data.getString(JSONUtils.NAME_KEY); if(iconUrl.equals("") || iconUrl.equals("null")) { iconUrl = data.getString(JSONUtils.COMMUNITY_ICON_KEY); @@ -84,7 +96,7 @@ class ParseSubscribedThing { String description = data.getString(JSONUtils.PUBLIC_DESCRIPTION).trim(); int nSubscribers = data.getInt(JSONUtils.SUBSCRIBERS_KEY); newSubscribedSubredditData.add(new SubscribedSubredditData(id, name, iconUrl)); - newSubredditData.add(new SubredditData(id, subredditFullName, iconUrl, bannerUrl, description, nSubscribers)); + newSubredditData.add(new SubredditData(id, subredditFullName, iconUrl, bannerImageUrl, description, nSubscribers)); } } lastItem = jsonResponse.getJSONObject(JSONUtils.DATA_KEY).getString(JSONUtils.AFTER_KEY); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java index b7a918cd..933af11d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java @@ -170,8 +170,8 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter() { @Override - public void onChanged(@Nullable SubredditData subredditData) { + public void onChanged(@Nullable final SubredditData subredditData) { if(subredditData != null) { - if(!subredditData.getBannerUrl().equals("") && !subredditData.getBannerUrl().equals("null")) { + if(subredditData.getBannerUrl().equals("")) { + iconCircleImageView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + //Do nothing as it has no image + } + }); + } else { glide.load(subredditData.getBannerUrl()).into(bannerImageView); + bannerImageView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(ViewSubredditDetailActivity.this, ViewImageActivity.class); + intent.putExtra(ViewImageActivity.TITLE_KEY, title); + intent.putExtra(ViewImageActivity.IMAGE_URL_KEY, subredditData.getBannerUrl()); + intent.putExtra(ViewImageActivity.FILE_NAME_KEY, subredditName + "-banner"); + startActivity(intent); + } + }); } - if(subredditData.getIconUrl().equals("") || subredditData.getIconUrl().equals("null")) { + if(subredditData.getIconUrl().equals("")) { glide.load(getDrawable(R.drawable.subreddit_default_icon)).into(iconCircleImageView); + iconCircleImageView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + //Do nothing as it is a default icon + } + }); } else { glide.load(subredditData.getIconUrl()).into(iconCircleImageView); + iconCircleImageView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(ViewSubredditDetailActivity.this, ViewImageActivity.class); + intent.putExtra(ViewImageActivity.TITLE_KEY, title); + intent.putExtra(ViewImageActivity.IMAGE_URL_KEY, subredditData.getIconUrl()); + intent.putExtra(ViewImageActivity.FILE_NAME_KEY, subredditName + "-icon"); + startActivity(intent); + } + }); } subredditNameTextView.setText(subredditData.getName()); String nSubscribers = getString(R.string.subscribers_number_detail, subredditData.getNSubscribers()); nSubscribersTextView.setText(nSubscribers); - descriptionTextView.setText(subredditData.getDescription()); + if(subredditData.getDescription().equals("")) { + descriptionTextView.setVisibility(View.GONE); + } else { + descriptionTextView.setVisibility(View.VISIBLE); + descriptionTextView.setText(subredditData.getDescription()); + } } } }); diff --git a/app/src/main/res/layout/activity_view_subreddit_detail.xml b/app/src/main/res/layout/activity_view_subreddit_detail.xml index ce3c4d55..d5f6ec57 100644 --- a/app/src/main/res/layout/activity_view_subreddit_detail.xml +++ b/app/src/main/res/layout/activity_view_subreddit_detail.xml @@ -43,7 +43,8 @@ app:civ_border_width="1dp" android:layout_below="@id/banner_image_view_view_subreddit_detail_activity" android:layout_centerHorizontal="true" - android:elevation="1000dp"/> + android:elevation="4dp" + app:civ_circle_background_color="@android:color/white"/> + android:layout_height="wrap_content" + android:layout_marginBottom="16dp"> + android:layout_marginStart="16dp" + android:layout_marginEnd="16dp" + android:layout_marginBottom="16dp" + android:textColor="@android:color/black" + android:visibility="gone"/>