aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2018-08-23 09:27:16 +0000
committerAlex Ning <chineseperson5@gmail.com>2018-08-23 09:27:16 +0000
commitf90bd4d1cce5f5ca523e4cae395a652a67811615 (patch)
tree885ee1ac2374154e963647c54f6a93a1934c9349 /app/src/main
parent97079663ff8e6fdae31d168df79f6e8329c8766e (diff)
downloadinfinity-for-reddit-f90bd4d1cce5f5ca523e4cae395a652a67811615.tar
infinity-for-reddit-f90bd4d1cce5f5ca523e4cae395a652a67811615.tar.gz
infinity-for-reddit-f90bd4d1cce5f5ca523e4cae395a652a67811615.tar.bz2
infinity-for-reddit-f90bd4d1cce5f5ca523e4cae395a652a67811615.tar.lz
infinity-for-reddit-f90bd4d1cce5f5ca523e4cae395a652a67811615.tar.xz
infinity-for-reddit-f90bd4d1cce5f5ca523e4cae395a652a67811615.tar.zst
infinity-for-reddit-f90bd4d1cce5f5ca523e4cae395a652a67811615.zip
Change the logic of parsing the subreddit icon. Click the icon and the banner of the subreddit to view the image in ViewImageActivity.
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java1
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubredditData.java20
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubscribedThing.java18
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewImageActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java50
-rw-r--r--app/src/main/res/layout/activity_view_subreddit_detail.xml13
8 files changed, 89 insertions, 27 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());
+ }
}
}
});
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"/>
<LinearLayout
android:layout_width="match_parent"
@@ -64,7 +65,8 @@
<RelativeLayout
android:layout_width="match_parent"
- android:layout_height="wrap_content">
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="16dp">
<TextView
android:id="@+id/subscriber_count_text_view_view_subreddit_detail_activity"
@@ -92,8 +94,11 @@
android:id="@+id/description_text_view_view_subreddit_detail_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_margin="16dp"
- android:textColor="@android:color/black" />
+ android:layout_marginStart="16dp"
+ android:layout_marginEnd="16dp"
+ android:layout_marginBottom="16dp"
+ android:textColor="@android:color/black"
+ android:visibility="gone"/>
</LinearLayout>