Skip to content

Commit

Permalink
Added ability to upvote & reply to individual DN comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbutcher committed Nov 26, 2015
1 parent ec32f74 commit 1e08fa9
Show file tree
Hide file tree
Showing 12 changed files with 559 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,17 @@ void comment(@Path("id") long storyId,
@Field("comment[body]") String comment,
Callback<Comment> callback);

@FormUrlEncoded
@POST("/api/v1/comments/{id}/reply")
void replyToComment(@Path("id") long commentId,
@Field("comment[body]") String comment,
Callback<Comment> callback);

@POST("/api/v1/comments/{id}/upvote")
void upvoteComment(@Path("id") long commentId,
@Body String ignored, // can remove when retrofit releases this fix:
// https://github
// .com/square/retrofit/commit/19ac1e2c4551448184ad66c4a0ec172e2741c2ee
Callback<Comment> callback);

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ public class Comment implements Parcelable {
public final String body_html;
public final Date created_at;
public final int depth;
public final int vote_count;
public int vote_count;
public final long user_id;
public final String user_display_name;
public final String user_portrait_url;
public final String user_job;
public final List<Comment> comments;

// TODO move this to a decorator
public Boolean upvoted;

public Comment(long id,
String body,
String body_html,
Expand Down
406 changes: 372 additions & 34 deletions app/src/main/java/io/plaidapp/ui/DesignerNewsStory.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* An extension to TextView which supports a custom state of {@link #STATE_ORIGINAL_POSTER} for
* denoting that a comment author was the original poster.
*/
public class AuthorTextView extends TextView {
public class AuthorTextView extends BaselineGridTextView {

private static final int[] STATE_ORIGINAL_POSTER = {R.attr.state_original_poster};

Expand Down
17 changes: 9 additions & 8 deletions app/src/main/res/animator/comment_selection.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
Copyright 2015 Google Inc.
Expand All @@ -17,19 +16,21 @@
-->

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_activated="true">

<item android:state_activated="true">
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="translationZ"
android:valueTo="@dimen/z_card"
android:valueType="floatType" />
android:duration="@android:integer/config_shortAnimTime"
android:interpolator="@android:interpolator/fast_out_slow_in" />
</item>

<item>
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="translationZ"
android:valueTo="0dp"
android:valueType="floatType" />
android:duration="@android:integer/config_shortAnimTime"
android:interpolator="@android:interpolator/fast_out_slow_in" />
</item>
</selector>

</selector>
37 changes: 37 additions & 0 deletions app/src/main/res/animator/comment_selection_delayed.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2015 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_activated="true">
<objectAnimator
android:propertyName="translationZ"
android:valueTo="@dimen/z_card"
android:startOffset="280"
android:duration="@android:integer/config_shortAnimTime"
android:interpolator="@android:interpolator/fast_out_slow_in" />
</item>

<item>
<objectAnimator
android:propertyName="translationZ"
android:valueTo="0dp"
android:duration="@android:integer/config_shortAnimTime"
android:interpolator="@android:interpolator/fast_out_slow_in" />
</item>

</selector>
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/comment_background.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
android:enterFadeDuration="@android:integer/config_shortAnimTime"
android:exitFadeDuration="@android:integer/config_shortAnimTime">

<item android:state_activated="true" android:drawable="@android:color/white" />
<item android:state_activated="true" android:drawable="@color/selected_comment_background" />

</selector>
94 changes: 46 additions & 48 deletions app/src/main/res/layout/designer_news_comment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,65 +15,63 @@
limitations under the License.
-->

<LinearLayout
<io.plaidapp.ui.widget.ForegroundRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:baselineAligned="false">
android:background="@drawable/comment_background"
android:foreground="?android:selectableItemBackground"
android:stateListAnimator="@animator/comment_selection_delayed">

<ImageView
android:id="@+id/depth"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/padding_normal"
android:layout_marginEnd="@dimen/spacing_normal" />
android:layout_marginEnd="@dimen/spacing_normal"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignBottom="@+id/comment_text" />

<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingBottom="@dimen/spacing_normal"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/spacing_normal"
android:paddingEnd="@dimen/padding_normal"
android:orientation="horizontal">

<io.plaidapp.ui.widget.AuthorTextView
android:id="@+id/comment_author"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:ellipsize="end"
android:textAppearance="@style/TextAppearance.CommentAuthor.DesignerNews"
tools:text="Nick B" />

<TextView
android:id="@+id/comment_time_ago"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="end"
android:textAppearance="@style/TextAppearance.CommentTimestamp"
tools:text="3 hours ago" />

</LinearLayout>
<io.plaidapp.ui.widget.BaselineGridTextView
android:id="@+id/comment_time_ago"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
app:topPaddingHint="@dimen/spacing_normal"
android:paddingEnd="@dimen/padding_normal"
android:textAppearance="@style/TextAppearance.CommentTimestamp"
tools:text="3 hours ago" />

<io.plaidapp.ui.widget.BaselineGridTextView
android:id="@+id/comment_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingEnd="@dimen/padding_normal"
android:paddingBottom="@dimen/spacing_micro"
android:textColorLink="@color/designer_news_links"
android:textColorHighlight="@color/designer_news_link_highlight"
tools:text="Comment body, comment body, comment body, comment body, comment body, comment body, comment body, comment body, comment body, comment body, comment body, comment body, comment body, comment body, comment body, comment body, comment body, comment body, comment body,"
style="@style/Widget.Plaid.Comment" />
<io.plaidapp.ui.widget.AuthorTextView
android:id="@+id/comment_author"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentTop="true"
android:layout_toEndOf="@id/depth"
android:layout_toStartOf="@id/comment_time_ago"
app:topPaddingHint="@dimen/spacing_normal"
android:ellipsize="end"
android:textAppearance="@style/TextAppearance.CommentAuthor.DesignerNews"
tools:text="Nick B" />

</LinearLayout>
<io.plaidapp.ui.widget.BaselineGridTextView
android:id="@+id/comment_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/depth"
android:layout_below="@id/comment_author"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginTop="@dimen/spacing_micro"
android:paddingEnd="@dimen/padding_normal"
android:paddingBottom="@dimen/padding_normal"
android:textColorLink="@color/designer_news_links"
android:textColorHighlight="@color/designer_news_link_highlight"
tools:text="Dude do you use sketch? You should totally use sketch. Should designers code??"
style="@style/Widget.Plaid.Comment" />

</LinearLayout>
</io.plaidapp.ui.widget.ForegroundRelativeLayout>
73 changes: 73 additions & 0 deletions app/src/main/res/layout/designer_news_comment_actions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2015 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:listPreferredItemHeight"
android:paddingStart="@dimen/spacing_normal"
android:paddingEnd="@dimen/padding_normal"
android:paddingBottom="@dimen/spacing_normal"
android:clipToPadding="false"
android:background="@color/selected_comment_background"
android:elevation="@dimen/z_card">

<Button
android:id="@+id/comment_votes"
android:layout_width="@dimen/fab_size"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:drawableTop="@drawable/ic_upvote"
android:textAppearance="@style/TextAppearance.CommentAuthor"
tools:text="33 likes"
style="?android:borderlessButtonStyle" />

<android.support.design.widget.TextInputLayout
android:id="@+id/comment_reply_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/fab_size"
android:paddingStart="@dimen/spacing_micro"
app:hintTextAppearance="@style/TextAppearance.FloatLabelHint">

<EditText
android:id="@+id/comment_reply"
android:hint="@string/hint_reply"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="top"
android:inputType="textMultiLine|textCapSentences"
android:textSize="16sp"
android:textColor="@color/text_primary_dark" />

</android.support.design.widget.TextInputLayout>

<ImageButton
android:id="@+id/post_reply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:padding="@dimen/spacing_normal"
android:src="@drawable/ic_add_comment_state"
android:background="?android:selectableItemBackgroundBorderless"
android:visibility="invisible" />

</FrameLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<color name="divider">#1f000000</color> <!-- 12% black -->
<color name="page_indicator_dark">#80333333</color>
<color name="page_indicator_dark_selected">#ff333333</color>
<color name="selected_comment_background">#ffffffff</color>

<!-- text (most text uses material theme colours) -->
<color name="hint_disabled_dark">#43000000</color> <!-- 26% black -->
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<dimen name="fab_plus_single_padding">72dp</dimen> <!-- fab_size + padding_normal -->
<dimen name="half_fab_plus_single_padding">44dp</dimen> <!-- (fab_size / 2) + padding_normal -->


<!-- dialogs -->
<dimen name="padding_dialog">24dp</dimen>
<dimen name="dialog_title_spacing">20dp</dimen>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<string name="need_login">Woah there chief. First you\'ll need&#160;to</string> <!-- &#160; == nbsp -->
<string name="dribbble_logged_in_as">Logged in as</string>
<string name="comment">Comment</string>
<string name="hint_reply">Reply</string>

<!-- main screen -->
<string name="search">Search</string>
Expand Down Expand Up @@ -100,7 +101,6 @@
<item quantity="other">%s views</item>
</plurals>
<string name="share">share</string>
<string name="hint_reply">Reply</string>
<string name="prospects_cant_post">Sorry but prospects cannot comment :(</string>

<!-- dribbble login -->
Expand Down

0 comments on commit 1e08fa9

Please sign in to comment.