parent
c130c7853f
commit
83ee5d8c61
|
@ -0,0 +1,46 @@
|
|||
package dummydomain.yetanothercallblocker;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
/*
|
||||
* https://stackoverflow.com/a/27037230
|
||||
*/
|
||||
public class CustomVerticalDivider extends RecyclerView.ItemDecoration {
|
||||
|
||||
private static final int[] ATTRS = new int[]{android.R.attr.listDivider};
|
||||
|
||||
private Drawable mDivider;
|
||||
|
||||
public CustomVerticalDivider(Context context) {
|
||||
final TypedArray a = context.obtainStyledAttributes(ATTRS);
|
||||
mDivider = a.getDrawable(0);
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(@NonNull Canvas c, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
|
||||
int dpItemPadding = parent.getResources().getDimensionPixelSize(R.dimen.item_padding);
|
||||
int left = dpItemPadding; // parent.getPaddingLeft();
|
||||
int right = parent.getWidth() - dpItemPadding; // parent.getPaddingRight();
|
||||
|
||||
int childCount = parent.getChildCount();
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
View child = parent.getChildAt(i);
|
||||
|
||||
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
|
||||
|
||||
int top = child.getBottom() + params.bottomMargin;
|
||||
int bottom = top + mDivider.getIntrinsicHeight();
|
||||
|
||||
mDivider.setBounds(left, top, right, bottom);
|
||||
mDivider.draw(c);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -51,6 +51,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
callLogAdapter = new CallLogItemRecyclerViewAdapter(callLogItems, this::onCallLogItemClicked);
|
||||
RecyclerView recyclerView = findViewById(R.id.callLogList);
|
||||
recyclerView.setAdapter(callLogAdapter);
|
||||
recyclerView.addItemDecoration(new CustomVerticalDivider(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -7,29 +7,29 @@
|
|||
android:orientation="vertical"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/callLogPermissionMessage"
|
||||
android:layout_width="wrap_content"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="start"
|
||||
android:layout_marginStart="@dimen/text_margin"
|
||||
android:layout_marginLeft="@dimen/text_margin"
|
||||
android:paddingTop="@dimen/item_padding"
|
||||
android:text="@string/call_log_permission_message"
|
||||
android:textAlignment="textStart"
|
||||
android:visibility="gone" />
|
||||
android:orientation="vertical"
|
||||
android:padding="@dimen/item_padding">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/callLogTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="start"
|
||||
android:layout_marginStart="@dimen/text_margin"
|
||||
android:layout_marginLeft="@dimen/text_margin"
|
||||
android:layout_marginBottom="@dimen/text_margin"
|
||||
android:paddingTop="@dimen/item_padding"
|
||||
android:text="@string/recent_calls"
|
||||
android:textAlignment="textStart" />
|
||||
<TextView
|
||||
android:id="@+id/callLogPermissionMessage"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="start"
|
||||
android:text="@string/call_log_permission_message"
|
||||
android:textAlignment="textStart"
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/callLogTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="start"
|
||||
android:text="@string/recent_calls"
|
||||
android:textAlignment="textStart" />
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/callLogList"
|
||||
|
|
|
@ -3,22 +3,15 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/text_margin"
|
||||
android:layout_marginLeft="@dimen/text_margin"
|
||||
android:layout_marginEnd="@dimen/text_margin"
|
||||
android:layout_marginRight="@dimen/text_margin"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center_vertical|start"
|
||||
android:orientation="horizontal">
|
||||
android:orientation="horizontal"
|
||||
android:padding="@dimen/item_padding">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/callTypeIcon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="1dp"
|
||||
android:layout_marginRight="1dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:src="@drawable/ic_call_missed_24dp" />
|
||||
|
||||
<TextView
|
||||
|
@ -26,11 +19,9 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLength="25"
|
||||
android:maxLength="15"
|
||||
android:maxLines="1"
|
||||
android:textAppearance="?attr/textAppearanceListItem"
|
||||
tools:text="+12345678901" />
|
||||
|
@ -39,10 +30,6 @@
|
|||
android:id="@+id/numberInfoIcon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="6dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginRight="1dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:src="@drawable/ic_thumb_down_24dp" />
|
||||
|
||||
<Space
|
||||
|
@ -54,10 +41,6 @@
|
|||
android:id="@+id/time"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/text_margin"
|
||||
android:layout_marginLeft="@dimen/text_margin"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:textAppearance="?attr/textAppearanceListItemSecondary"
|
||||
android:textSize="12sp"
|
||||
tools:text="1 minute ago" />
|
||||
|
|
Loading…
Reference in New Issue