diff options
Diffstat (limited to 'app/src/main/java/ml')
7 files changed, 80 insertions, 23 deletions
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<RecyclerView.ViewHold Intent intent = new Intent(mContext, ViewImageActivity.class); intent.putExtra(ViewImageActivity.IMAGE_URL_KEY, imageUrl); intent.putExtra(ViewImageActivity.TITLE_KEY, title); - intent.putExtra(ViewImageActivity.SUBREDDIT_KEY, subredditName); - intent.putExtra(ViewImageActivity.ID_KEY, id); + intent.putExtra(ViewImageActivity.FILE_NAME_KEY, subredditName.substring(2) + + "-" + id.substring(3)); mContext.startActivity(intent); } }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewImageActivity.java index d0161399..031fc88a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewImageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewImageActivity.java @@ -57,8 +57,7 @@ public class ViewImageActivity extends AppCompatActivity { static final String TITLE_KEY = "TK"; static final String IMAGE_URL_KEY = "IUK"; - static final String SUBREDDIT_KEY = "SK"; - static final String ID_KEY = "IK"; + static final String FILE_NAME_KEY = "FNK"; private boolean isActionBarHidden = false; private boolean isDownloading = false; @@ -83,12 +82,11 @@ public class ViewImageActivity extends AppCompatActivity { Intent intent = getIntent(); mImageUrl = intent.getExtras().getString(IMAGE_URL_KEY); + mImageFileName = intent.getExtras().getString(FILE_NAME_KEY); String title = intent.getExtras().getString(TITLE_KEY); final Spannable text = new SpannableString(title); setTitle(text); - mImageFileName = intent.getExtras().getString(SUBREDDIT_KEY).substring(2) + "-" + intent.getExtras().getString(ID_KEY).substring(3); - final RelativeLayout relativeLayout = findViewById(R.id.parent_relative_layout_view_image_activity); final GestureImageView imageView = findViewById(R.id.image_view_view_image_activity); final ProgressBar progressBar = findViewById(R.id.progress_bar_view_image_activity); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java index 51912948..ff467f4c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java @@ -168,8 +168,8 @@ public class ViewPostDetailActivity extends AppCompatActivity { Intent intent = new Intent(ViewPostDetailActivity.this, ViewImageActivity.class); intent.putExtra(ViewImageActivity.IMAGE_URL_KEY, mPostData.getUrl()); intent.putExtra(ViewImageActivity.TITLE_KEY, mPostData.getTitle()); - intent.putExtra(ViewImageActivity.SUBREDDIT_KEY, mPostData.getSubredditName()); - intent.putExtra(ViewImageActivity.ID_KEY, mPostData.getId()); + intent.putExtra(ViewImageActivity.FILE_NAME_KEY, mPostData.getSubredditName().substring(2) + + "-" + mPostData.getId().substring(3)); startActivity(intent); } }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java index 6b4126b8..99fcc56e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java @@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit; import android.arch.lifecycle.Observer; import android.arch.lifecycle.ViewModelProviders; +import android.content.Intent; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; @@ -12,6 +13,7 @@ import android.support.v4.app.Fragment; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.MenuItem; +import android.view.View; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; @@ -39,7 +41,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity { setSupportActionBar(toolbar); String id = getIntent().getExtras().getString(EXTRA_SUBREDDIT_ID); - String subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME); + final String subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME); final String title = "r/" + subredditName; setTitle(title); @@ -77,22 +79,60 @@ public class ViewSubredditDetailActivity extends AppCompatActivity { mSubredditViewModel = ViewModelProviders.of(this, factory).get(SubredditViewModel.class); mSubredditViewModel.getSubredditLiveData().observe(this, new Observer<SubredditData>() { @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()); + } } } }); |