Permalink
Browse files

SendCommentButton usage in CommentsActivity (layout and implementation)

  • Loading branch information...
frogermcs committed Dec 4, 2014
1 parent f1d39dd commit 1dac9dd2ac6f5f89e09c2791b6db06738e6b6b93
@@ -2,28 +2,31 @@
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.app.ActivityManager;
import android.os.Bundle;
import android.support.v4.view.ViewCompat;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AnimationUtils;
import android.view.animation.DecelerateInterpolator;
import android.widget.EditText;
import android.widget.LinearLayout;
import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import io.github.froger.instamaterial.view.SendCommentButton;
/**
* Created by froger_mcs on 11.11.14.
*/
public class CommentsActivity extends ActionBarActivity {
public class CommentsActivity extends ActionBarActivity implements SendCommentButton.OnSendClickListener {
public static final String ARG_DRAWING_START_LOCATION = "arg_drawing_start_location";
@InjectView(R.id.toolbar)
@@ -34,6 +37,10 @@
RecyclerView rvComments;
@InjectView(R.id.llAddComment)
LinearLayout llAddComment;
@InjectView(R.id.etComment)
EditText etComment;
@InjectView(R.id.btnSendComment)
SendCommentButton btnSendComment;
private CommentsAdapter commentsAdapter;
private int drawingStartLocation;
@@ -45,6 +52,7 @@ protected void onCreate(Bundle savedInstanceState) {
ButterKnife.inject(this);
setupToolbar();
setupComments();
setupSendCommentButton();
drawingStartLocation = getIntent().getIntExtra(ARG_DRAWING_START_LOCATION, 0);
if (savedInstanceState == null) {
@@ -82,11 +90,15 @@ public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
});
}
private void setupSendCommentButton() {
btnSendComment.setOnSendClickListener(this);
}
private void startIntroAnimation() {
ViewCompat.setElevation(toolbar, 0);
contentRoot.setScaleY(0.1f);
contentRoot.setPivotY(drawingStartLocation);
llAddComment.setTranslationY(100);
llAddComment.setTranslationY(200);
contentRoot.animate()
.scaleY(1)
@@ -134,12 +146,25 @@ public void onAnimationEnd(Animator animation) {
.start();
}
@OnClick(R.id.btnSendComment)
public void onSendCommentClick() {
commentsAdapter.addItem();
commentsAdapter.setAnimationsLocked(false);
commentsAdapter.setDelayEnterAnimation(false);
rvComments.smoothScrollBy(0, rvComments.getChildAt(0).getHeight() * commentsAdapter.getItemCount());
@Override
public void onSendClickListener(View v) {
if (validateComment()) {
commentsAdapter.addItem();
commentsAdapter.setAnimationsLocked(false);
commentsAdapter.setDelayEnterAnimation(false);
rvComments.smoothScrollBy(0, rvComments.getChildAt(0).getHeight() * commentsAdapter.getItemCount());
etComment.setText(null);
btnSendComment.setCurrentState(SendCommentButton.STATE_DONE, true);
}
}
private boolean validateComment() {
if (TextUtils.isEmpty(etComment.getText())) {
btnSendComment.startAnimation(AnimationUtils.loadAnimation(this, R.anim.shake_error));
return false;
}
return true;
}
}
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!--drawable/btn_send_comment.xml-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<layer-list>
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="90"
android:endColor="#00000000"
android:startColor="#22000000" />
</shape>
@@ -31,30 +31,54 @@
android:elevation="@dimen/default_elevation"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/rvComments"
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="none" />
android:layout_weight="1">
<android.support.v7.widget.RecyclerView
android:id="@+id/rvComments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none" />
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_gravity="bottom"
android:background="@drawable/shadow_top" />
</FrameLayout>
<LinearLayout
android:id="@+id/llAddComment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/bg_comments"
android:elevation="@dimen/default_elevation">
android:elevation="@dimen/default_elevation"
android:gravity="center_vertical"
android:paddingBottom="4dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="8dp">
<EditText
android:id="@+id/etComment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
android:layout_weight="1"
android:textColor="#555555"
android:textSize="14sp" />
<Button
<io.github.froger.instamaterial.view.SendCommentButton
android:id="@+id/btnSendComment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send" />
android:layout_width="72dp"
android:layout_height="match_parent"
android:layout_marginBottom="2dp"
android:layout_marginLeft="8dp"
android:background="@drawable/btn_send_comment"
android:elevation="4dp"
android:orientation="vertical" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?><!-- item_feed.xml -->
<?xml version="1.0" encoding="utf-8"?>
<!-- item_feed.xml -->
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
@@ -28,5 +29,26 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingRight="8dp">
<ImageButton
android:id="@+id/btnLike"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="@drawable/btn_feed_action"
android:src="@drawable/ic_heart_outline_grey" />
<ImageButton
android:id="@+id/btnComments"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="@drawable/btn_feed_action"
android:src="@drawable/ic_comment_outline_grey" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
@@ -1,6 +1,6 @@
#Wed Apr 10 15:27:10 PDT 2013
#Wed Dec 03 19:13:43 CET 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip

0 comments on commit 1dac9dd

Please sign in to comment.