From 5d1a86d472e18d4f32cac18aa69bda4205d471bd Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 12 Mar 2017 18:46:45 +0100 Subject: [PATCH] Crash analytics with Firebase Conversation line visual --- app/build.gradle | 2 + .../tusky/ConversationLineItemDecoration.java | 41 +++++++++++++++++++ .../keylesspalace/tusky/SplashActivity.java | 2 +- .../tusky/ViewThreadFragment.java | 2 + .../drawable/conversation_divider_dark.xml | 7 ++++ app/src/main/res/values/dimens.xml | 1 + 6 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/com/keylesspalace/tusky/ConversationLineItemDecoration.java create mode 100644 app/src/main/res/drawable/conversation_divider_dark.xml diff --git a/app/build.gradle b/app/build.gradle index 9e976658..a71f3b4d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -43,9 +43,11 @@ dependencies { compile 'com.github.arimorty:floatingsearchview:2.0.3' compile 'com.jakewharton:butterknife:8.4.0' compile 'com.google.firebase:firebase-messaging:10.0.1' + compile 'com.google.firebase:firebase-crash:10.0.1' testCompile 'junit:junit:4.12' annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0' } + apply plugin: 'com.google.gms.google-services' \ No newline at end of file diff --git a/app/src/main/java/com/keylesspalace/tusky/ConversationLineItemDecoration.java b/app/src/main/java/com/keylesspalace/tusky/ConversationLineItemDecoration.java new file mode 100644 index 00000000..6532bdd6 --- /dev/null +++ b/app/src/main/java/com/keylesspalace/tusky/ConversationLineItemDecoration.java @@ -0,0 +1,41 @@ +package com.keylesspalace.tusky; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Canvas; +import android.graphics.drawable.Drawable; +import android.support.v7.widget.RecyclerView; +import android.util.TypedValue; +import android.view.View; + +import static android.util.TypedValue.COMPLEX_UNIT_DIP; + +class ConversationLineItemDecoration extends RecyclerView.ItemDecoration { + private final Context mContext; + private final Drawable mDivider; + + public ConversationLineItemDecoration(Context context, Drawable divider) { + mContext = context; + mDivider = divider; + } + + @Override + public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { + // Fun fact: this method draws in pixels, but all layouts are in DP, so I'm using the divider's + // own 2dp width to calculate what I want + int dividerLeft = parent.getPaddingLeft() + mContext.getResources().getDimensionPixelSize(R.dimen.status_left_line_margin); + int dividerRight = dividerLeft + mDivider.getIntrinsicWidth(); + + int childCount = parent.getChildCount(); + + for (int i = 0; i < childCount - 1; i++) { + View child = parent.getChildAt(i); + + int dividerTop = child.getTop() + (i == 0 ? mContext.getResources().getDimensionPixelSize(R.dimen.account_avatar_margin) : 0); + int dividerBottom = (i == childCount - 2 ? dividerTop + mContext.getResources().getDimensionPixelSize(R.dimen.account_avatar_margin) : child.getBottom()); + + mDivider.setBounds(dividerLeft, dividerTop, dividerRight, dividerBottom); + mDivider.draw(c); + } + } +} diff --git a/app/src/main/java/com/keylesspalace/tusky/SplashActivity.java b/app/src/main/java/com/keylesspalace/tusky/SplashActivity.java index 11111e22..dcb35fdd 100644 --- a/app/src/main/java/com/keylesspalace/tusky/SplashActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/SplashActivity.java @@ -36,7 +36,7 @@ public class SplashActivity extends Activity { getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_splash); - + /* Determine whether the user is currently logged in, and if so go ahead and load the * timeline. Otherwise, start the activity_login screen. */ SharedPreferences preferences = getSharedPreferences( diff --git a/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java b/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java index a83c35e2..de535035 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java @@ -20,6 +20,7 @@ import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.design.widget.Snackbar; +import android.support.v4.content.ContextCompat; import android.support.v7.widget.DividerItemDecoration; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; @@ -63,6 +64,7 @@ public class ViewThreadFragment extends SFragment implements StatusActionListene R.drawable.status_divider_dark); divider.setDrawable(drawable); recyclerView.addItemDecoration(divider); + recyclerView.addItemDecoration(new ConversationLineItemDecoration(context, ContextCompat.getDrawable(context, R.drawable.conversation_divider_dark))); adapter = new ThreadAdapter(this); recyclerView.setAdapter(adapter); diff --git a/app/src/main/res/drawable/conversation_divider_dark.xml b/app/src/main/res/drawable/conversation_divider_dark.xml new file mode 100644 index 00000000..42034487 --- /dev/null +++ b/app/src/main/res/drawable/conversation_divider_dark.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index c01d532c..c2babd78 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -20,4 +20,5 @@ 8dp 8dp 8dp + 38dp