Skip to content

Commit

Permalink
- Clean up some code
Browse files Browse the repository at this point in the history
- Add support for viewing parent in reply editor
- Automatically hide top toolbar when necessary
- Move Profile page to data object
- Fix UI bugs
  • Loading branch information
TheKeeperOfPie committed Jul 27, 2015
1 parent 9d38a11 commit d095878
Show file tree
Hide file tree
Showing 40 changed files with 1,395 additions and 840 deletions.
Binary file modified app/app-release.apk
Binary file not shown.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ android {
minSdkVersion 17
targetSdkVersion 22
versionCode 40
versionName "1.0.3"
versionName "1.1"
}
buildTypes {
release {
Expand Down
434 changes: 320 additions & 114 deletions app/src/main/java/com/winsonchiu/reader/FragmentNewPost.java

Large diffs are not rendered by default.

55 changes: 52 additions & 3 deletions app/src/main/java/com/winsonchiu/reader/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.URLUtil;
import android.widget.ImageView;
Expand All @@ -45,6 +46,7 @@
import com.winsonchiu.reader.comments.FragmentReply;
import com.winsonchiu.reader.data.reddit.Comment;
import com.winsonchiu.reader.data.reddit.Link;
import com.winsonchiu.reader.data.reddit.Message;
import com.winsonchiu.reader.data.reddit.Reddit;
import com.winsonchiu.reader.data.reddit.Replyable;
import com.winsonchiu.reader.data.reddit.Sort;
Expand Down Expand Up @@ -229,7 +231,36 @@ public void onResponse(String response) {
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this, "Failed to send reply", Toast.LENGTH_LONG).show();
Toast.makeText(MainActivity.this, R.string.failed_reply, Toast.LENGTH_LONG).show();
}
});
}

@Override
public void sendMessage(String name, String text) {

getReddit().sendComment(name, text, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(
response);
Message newMessage = Message.fromJson(
jsonObject.getJSONObject("json")
.getJSONObject("data")
.getJSONArray("things")
.getJSONObject(0));
getControllerInbox()
.insertMessage(newMessage);
}
catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this, R.string.failed_message, Toast.LENGTH_LONG).show();
}
});
}
Expand Down Expand Up @@ -492,6 +523,26 @@ public void showReplyEditor(Replyable replyable) {
.commit();
}

@Override
public void markRead(Thing thing) {

Map<String, String> params = new HashMap<>();
params.put("id", thing.getName());

getReddit()
.loadPost(Reddit.OAUTH_URL + "/api/read_message",
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {

}
}, params, 0);
}

};

eventListenerComment = new AdapterCommentList.ViewHolderComment.EventListener() {
Expand Down Expand Up @@ -984,14 +1035,12 @@ public ControllerProfile getControllerProfile() {

@Override
public void onAuthFinished(boolean success) {
selectNavigationItem(R.id.item_home, 0, false);
if (success) {
Toast.makeText(this, getString(R.string.login_success), Toast.LENGTH_SHORT)
.show();
loadAccountInfo();
getControllerUser().reloadUser();
getControllerSearch().reloadSubscriptionList();
getControllerLinks().loadFrontPage(Sort.HOT, true);
}
else {
Toast.makeText(this, getString(R.string.login_failure), Toast.LENGTH_SHORT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.winsonchiu.reader.data.reddit.Thing;
import com.winsonchiu.reader.utils.AnimationUtils;
import com.winsonchiu.reader.AppSettings;
import com.winsonchiu.reader.profile.ControllerProfile;
Expand Down Expand Up @@ -478,8 +479,7 @@ public void onClick(View v) {
if (!TextUtils.isEmpty(editTextReply.getText())) {
sendReply();
InputMethodManager inputManager = (InputMethodManager) itemView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(itemView.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
inputManager.hideSoftInputFromWindow(itemView.getWindowToken(), 0);
}
}
});
Expand Down Expand Up @@ -557,7 +557,7 @@ private void sendReply() {
else {
eventListenerBase.sendComment(comment.getName(), editTextReply.getText().toString());
}
comment.setReplyExpanded(!comment.isReplyExpanded());
comment.setReplyExpanded(false);
layoutContainerReply.setVisibility(View.GONE);
}

Expand Down Expand Up @@ -594,10 +594,19 @@ private void initializeToolbar() {
menu.getItem(index).getIcon().setColorFilter(colorFilterMenuItem);
}

buttonReplyEditor.setColorFilter(colorFilterMenuItem);
}

public void expandToolbarActions() {

if (comment.isNew()) {
eventListenerBase.markRead(comment);
comment.setIsNew(false);
textInfo.setTextColor(comment.isNew() ? itemView.getResources()
.getColor(R.color.textColorAlert) : colorTextSecondary);
return;
}

if (comment.isMore()) {
eventListener.loadNestedComments(comment);
return;
Expand Down Expand Up @@ -767,7 +776,9 @@ public void onBind(Comment comment, String userName) {

}

textComment.setTextColor(comment.getGilded() > 0 ? resources.getColor(R.color.gildedComment) : colorTextPrimary);
textComment.setTextColor(
comment.getGilded() > 0 ? resources.getColor(R.color.gildedComment) :
colorTextPrimary);

}

Expand Down Expand Up @@ -796,9 +807,13 @@ public void setTextInfo() {
spannableVote.setSpan(new ForegroundColorSpan(voteColor), 0, spannableVote.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}

Spannable spannableScore = new SpannableString(String.valueOf(comment.getScore()));
Spannable spannableScore;

if (!comment.isScoreHidden()) {
if (comment.isScoreHidden()) {
spannableScore = new SpannableString(String.valueOf(0));
}
else {
spannableScore = new SpannableString(String.valueOf(comment.getScore()));
spannableScore.setSpan(new ForegroundColorSpan(
comment.getScore() > 0 ? colorPositive : colorNegative), 0,
spannableScore.length(),
Expand Down Expand Up @@ -852,7 +867,7 @@ else if (userName.equals(comment.getAuthor())) {
.concat(spannableVote, spannableScore, " by ", spannableAuthor, flair,
timestamp, comment.getEdited() > 0 ? "*" : ""));

Linkify.addLinks(textInfo, Linkify.ALL);
Linkify.addLinks(textInfo, Linkify.WEB_URLS);
}

public void syncSaveIcon() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.view.GestureDetectorCompat;
Expand Down Expand Up @@ -107,6 +108,8 @@ public class FragmentComments extends FragmentBase implements Toolbar.OnMenuItem
private GestureDetectorCompat gestureDetector;
private SharedPreferences preferences;
private PorterDuffColorFilter colorFilterIcon;
private CoordinatorLayout layoutCoordinator;
private AppBarLayout layoutAppBar;

public static FragmentComments newInstance() {
FragmentComments fragment = new FragmentComments();
Expand Down Expand Up @@ -404,6 +407,9 @@ public void onRefresh() {
}
});

layoutCoordinator = (CoordinatorLayout) view.findViewById(R.id.layout_coordinator);
layoutAppBar = (AppBarLayout) view.findViewById(R.id.layout_app_bar);

linearLayoutManager = new LinearLayoutManager(activity);
recyclerCommentList = (RecyclerView) view.findViewById(R.id.recycler_comment_list);
recyclerCommentList.setLayoutManager(linearLayoutManager);
Expand Down Expand Up @@ -474,6 +480,12 @@ public int getRecyclerHeight() {
public RecyclerView.LayoutManager getLayoutManager() {
return linearLayoutManager;
}

@Override
public void hideToolbar() {
AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
}
};

YouTubeListener youTubeListener = new YouTubeListener() {
Expand Down Expand Up @@ -1050,13 +1062,12 @@ public boolean onMenuItemClick(MenuItem item) {
break;
}

for (Sort sort : Sort.values()) {
if (sort.getMenuId() == item.getItemId()) {
mListener.getControllerComments()
.setSort(sort);
linearLayoutManager.scrollToPositionWithOffset(1, 0);
return true;
}
Sort sort = Sort.fromMenuId(item.getItemId());
if (sort != null) {
mListener.getControllerComments()
.setSort(sort);
linearLayoutManager.scrollToPositionWithOffset(1, 0);
return true;
}

return true;
Expand Down
Loading

0 comments on commit d095878

Please sign in to comment.