aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java19
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java32
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostData.java1
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java7
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditRecyclerViewAdapter.java13
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserRecyclerViewAdapter.java20
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java19
7 files changed, 76 insertions, 35 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
index 309d7a0f..5f559aa1 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
@@ -91,7 +91,7 @@ public class MainActivity extends AppCompatActivity {
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
- DrawerLayout drawer = findViewById(R.id.drawer_layout);
+ final DrawerLayout drawer = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
@@ -142,8 +142,15 @@ public class MainActivity extends AppCompatActivity {
glide.load(mBannerImageUrl).into(mBannerImageView);
}
- final SubscribedSubredditRecyclerViewAdapter subredditadapter = new SubscribedSubredditRecyclerViewAdapter(this);
+ final SubscribedSubredditRecyclerViewAdapter subredditadapter = new SubscribedSubredditRecyclerViewAdapter(this,
+ new SubscribedSubredditRecyclerViewAdapter.OnItemClickListener() {
+ @Override
+ public void onClick() {
+ drawer.closeDrawers();
+ }
+ });
subscribedSubredditRecyclerView.setAdapter(subredditadapter);
+
mSubscribedSubredditViewModel = ViewModelProviders.of(this).get(SubscribedSubredditViewModel.class);
mSubscribedSubredditViewModel.getAllSubscribedSubreddits().observe(this, new Observer<List<SubscribedSubredditData>>() {
@Override
@@ -158,7 +165,13 @@ public class MainActivity extends AppCompatActivity {
}
});
- final SubscribedUserRecyclerViewAdapter userAdapter = new SubscribedUserRecyclerViewAdapter(this);
+ final SubscribedUserRecyclerViewAdapter userAdapter = new SubscribedUserRecyclerViewAdapter(this,
+ new SubscribedUserRecyclerViewAdapter.OnItemClickListener() {
+ @Override
+ public void onClick() {
+ drawer.closeDrawers();
+ }
+ });
subscribedUserRecyclerView.setAdapter(userAdapter);
mSubscribedUserViewModel = ViewModelProviders.of(this).get(SubscribedUserViewModel.class);
mSubscribedUserViewModel.getAllSubscribedUsers().observe(this, new Observer<List<SubscribedUserData>>() {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java
index 4330afe3..2f8a4091 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java
@@ -200,17 +200,31 @@ class ParsePost {
bestPostData.add(new PostData(id, fullName, subredditNamePrefixed, formattedPostTime,
title, url, url, permalink, score, postType, voteType, gilded, nsfw, stickied, isCrosspost));
} else {
- //Link post
- Log.i("link", Integer.toString(i));
- int postType = PostData.LINK_TYPE;
- PostData linkPostData = new PostData(id, fullName, subredditNamePrefixed, formattedPostTime,
- title, previewUrl, url, permalink, score, postType, voteType, gilded, nsfw, stickied, isCrosspost);
- if(data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) {
- linkPostData.setSelfText("");
+ if (url.contains(permalink)) {
+ //Text post but with a preview
+ Log.i("text with image", Integer.toString(i));
+ int postType = PostData.TEXT_TYPE;
+ PostData textWithImagePostData = new PostData(id, fullName, subredditNamePrefixed, formattedPostTime,
+ title, permalink, score, postType, voteType, gilded, nsfw, stickied, isCrosspost);
+ if(data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) {
+ textWithImagePostData.setSelfText("");
+ } else {
+ textWithImagePostData.setSelfText(data.getString(JSONUtils.SELFTEXT_HTML_KEY).trim());
+ }
+ bestPostData.add(textWithImagePostData);
} else {
- linkPostData.setSelfText(data.getString(JSONUtils.SELFTEXT_HTML_KEY).trim());
+ //Link post
+ Log.i("link", Integer.toString(i));
+ int postType = PostData.LINK_TYPE;
+ PostData linkPostData = new PostData(id, fullName, subredditNamePrefixed, formattedPostTime,
+ title, previewUrl, url, permalink, score, postType, voteType, gilded, nsfw, stickied, isCrosspost);
+ if(data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) {
+ linkPostData.setSelfText("");
+ } else {
+ linkPostData.setSelfText(data.getString(JSONUtils.SELFTEXT_HTML_KEY).trim());
+ }
+ bestPostData.add(linkPostData);
}
- bestPostData.add(linkPostData);
}
}
} else {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostData.java
index 289ca083..0ece0b00 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostData.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostData.java
@@ -36,7 +36,6 @@ class PostData implements Parcelable {
private boolean isCrosspost;
private boolean isDashVideo;
private boolean isDownloadableGifOrVideo;
- private PostData crosspostParentPostData;
PostData(String id, String fullName, String subredditNamePrefixed, String postTime, String title,
String previewUrl, String permalink, int score, int postType, int voteType, int gilded,
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
index 8a80821e..86b1254a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
@@ -69,8 +69,8 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
mPostData = postData;
mPaginationSynchronizer = paginationSynchronizer;
this.hasMultipleSubreddits = hasMultipleSubreddits;
- glide = Glide.with(mContext);
- subredditDao = SubredditRoomDatabase.getDatabase(mContext).subredditDao();
+ glide = Glide.with(mContext.getApplicationContext());
+ subredditDao = SubredditRoomDatabase.getDatabase(mContext.getApplicationContext()).subredditDao();
}
}
@@ -308,8 +308,9 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
}
});
break;
- default:
+ case PostData.TEXT_TYPE:
((DataViewHolder) holder).typeTextView.setText("TEXT");
+ break;
}
((DataViewHolder) holder).upvoteButton.setOnClickListener(new View.OnClickListener() {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditRecyclerViewAdapter.java
index 196785e4..3c60f487 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditRecyclerViewAdapter.java
@@ -20,10 +20,16 @@ class SubscribedSubredditRecyclerViewAdapter extends RecyclerView.Adapter<Recycl
private Context mContext;
private List<SubscribedSubredditData> mSubscribedSubredditData;
private RequestManager glide;
+ private OnItemClickListener mOnItemClickListener;
- SubscribedSubredditRecyclerViewAdapter(Context context) {
- mContext = context;
- glide = Glide.with(context);
+ interface OnItemClickListener {
+ void onClick();
+ }
+
+ SubscribedSubredditRecyclerViewAdapter(Context context, OnItemClickListener onItemClickListener) {
+ mContext = context.getApplicationContext();
+ glide = Glide.with(context.getApplicationContext());
+ mOnItemClickListener = onItemClickListener;
}
@NonNull
@@ -38,6 +44,7 @@ class SubscribedSubredditRecyclerViewAdapter extends RecyclerView.Adapter<Recycl
@Override
public void onClick(View view) {
if(viewHolder.getAdapterPosition() >= 0) {
+ mOnItemClickListener.onClick();
Intent intent = new Intent(mContext, ViewSubredditDetailActivity.class);
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, mSubscribedSubredditData.get(viewHolder.getAdapterPosition()).getName());
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_VALUE_KEY, mSubscribedSubredditData.get(viewHolder.getAdapterPosition()).getId());
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserRecyclerViewAdapter.java
index cb779a2c..44089043 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserRecyclerViewAdapter.java
@@ -16,13 +16,17 @@ import java.util.List;
import de.hdodenhof.circleimageview.CircleImageView;
class SubscribedUserRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
- private Context mContext;
private List<SubscribedUserData> mSubscribedUserData;
private RequestManager glide;
+ private OnItemClickListener mOnItemClickListener;
- SubscribedUserRecyclerViewAdapter(Context context) {
- mContext = context;
- glide = Glide.with(context);
+ interface OnItemClickListener {
+ void onClick();
+ }
+
+ SubscribedUserRecyclerViewAdapter(Context context, OnItemClickListener onItemClickListener) {
+ glide = Glide.with(context.getApplicationContext());
+ mOnItemClickListener = onItemClickListener;
}
@NonNull
@@ -33,6 +37,14 @@ class SubscribedUserRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
+ viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ //Need to be implemented
+
+ mOnItemClickListener.onClick();
+ }
+ });
if(!mSubscribedUserData.get(i).getIconUrl().equals("")) {
glide.load(mSubscribedUserData.get(i).getIconUrl()).into(((UserViewHolder) viewHolder).iconCircleImageView);
} else {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
index 799f033d..b38414bf 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
@@ -205,6 +205,12 @@ public class ViewPostDetailActivity extends AppCompatActivity {
if(mPostData.isNSFW()) {
mNSFWTextView.setVisibility(View.VISIBLE);
}
+
+ if(!mPostData.getSelfText().equals("")) {
+ mContentTextView.setVisibility(View.VISIBLE);
+ mContentTextView.setHtml(mPostData.getSelfText());
+ }
+
mScoreTextView.setText(Integer.toString(mPostData.getScore()));
mShareButton.setOnClickListener(new View.OnClickListener() {
@@ -235,10 +241,6 @@ public class ViewPostDetailActivity extends AppCompatActivity {
break;
case PostData.LINK_TYPE:
mTypeTextView.setText("LINK");
- if(mPostData.getSelfText() != null && !mPostData.getSelfText().equals("")) {
- mContentTextView.setVisibility(View.VISIBLE);
- mContentTextView.setHtml(mPostData.getSelfText());
- }
mImageView.setOnClickListener(new View.OnClickListener() {
@Override
@@ -296,10 +298,6 @@ public class ViewPostDetailActivity extends AppCompatActivity {
break;
case PostData.NO_PREVIEW_LINK_TYPE:
mTypeTextView.setText("LINK");
- if(!mPostData.getSelfText().equals("")) {
- mContentTextView.setVisibility(View.VISIBLE);
- mContentTextView.setHtml(mPostData.getSelfText());
- }
mNoPreviewLinkImageView.setVisibility(View.VISIBLE);
mNoPreviewLinkImageView.setOnClickListener(new View.OnClickListener() {
@Override
@@ -315,10 +313,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
break;
case PostData.TEXT_TYPE:
mTypeTextView.setText("TEXT");
- if(!mPostData.getSelfText().equals("")) {
- mContentTextView.setVisibility(View.VISIBLE);
- mContentTextView.setHtml(mPostData.getSelfText());
- }
+ break;
}
queryComment();