Skip to content

Commit

Permalink
change delete button to a swipe
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinLiddle committed Mar 16, 2018
1 parent 4d6a8e7 commit 8dca53f
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 98 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dependencies {
compile 'com.pkmmte.pkrss:pkrss:1.2'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.5.0'
compile 'joda-time:joda-time:2.9.9'
compile 'com.chauthai.swipereveallayout:swipe-reveal-layout:1.4.1'

testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.15.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void seekTo(int pos) {

@Override
public boolean isPlaying() {
return mMediaPlayer.isPlaying();
return mMediaPlayer != null && mMediaPlayer.isPlaying();
}

@Override
Expand Down
26 changes: 8 additions & 18 deletions app/src/main/java/com/krevin/crockpod/alarm/AlarmListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import android.widget.TextView;
import android.widget.ToggleButton;

import com.chauthai.swipereveallayout.SwipeRevealLayout;
import com.chauthai.swipereveallayout.ViewBinderHelper;
import com.krevin.crockpod.CrockpodActivity;
import com.krevin.crockpod.R;
import com.krevin.crockpod.alarm.repositories.AlarmRepository;
Expand Down Expand Up @@ -70,6 +72,7 @@ private void refreshAlarmList() {

private class AlarmListAdapter extends RecyclerView.Adapter<AlarmHolder> {
private final List<Alarm> mAlarms;
private final ViewBinderHelper viewBinderHelper = new ViewBinderHelper();

AlarmListAdapter(List<Alarm> mAlarms) {
this.mAlarms = mAlarms;
Expand All @@ -84,7 +87,9 @@ public AlarmHolder onCreateViewHolder(ViewGroup parent, int viewType) {

@Override
public void onBindViewHolder(AlarmHolder holder, int position) {
holder.bindAlarm(mAlarms.get(position));
Alarm alarm = mAlarms.get(position);
holder.bindAlarm(alarm);
viewBinderHelper.bind(holder.mSwipeRevealLayout, alarm.getId().toString());
}

@Override
Expand All @@ -95,21 +100,17 @@ public int getItemCount() {

private class AlarmHolder extends RecyclerView.ViewHolder {

private final SwipeRevealLayout mSwipeRevealLayout;
private final TextView mAlarmTextView;
private final LinearLayout mDeleteAlarmLayout;
private final Button mDeleteAlarmButton;
private final ToggleButton mToggleAlarmButton;
private final ImageButton mExpandButton;
private final ImageButton mContractButton;

AlarmHolder(View itemView) {
super(itemView);
mSwipeRevealLayout = itemView.findViewById(R.id.swipe_layout);
mAlarmTextView = itemView.findViewById(R.id.alarm_text);
mDeleteAlarmLayout = itemView.findViewById(R.id.delete_alarm_layout);
mDeleteAlarmButton = itemView.findViewById(R.id.delete_alarm_button);
mToggleAlarmButton = itemView.findViewById(R.id.toggle_alarm_button);
mExpandButton = itemView.findViewById(R.id.alarm_item_expand);
mContractButton = itemView.findViewById(R.id.alarm_item_contract);
}

void bindAlarm(final Alarm alarm) {
Expand All @@ -131,17 +132,6 @@ void bindAlarm(final Alarm alarm) {
setToggleAlarmButtonOpacity();
mAlarmRepository.set(alarm);
});

mExpandButton.setOnClickListener(buttonView -> {
mDeleteAlarmLayout.setVisibility(View.VISIBLE);
mExpandButton.setVisibility(View.GONE);
mContractButton.setVisibility(View.VISIBLE);
});
mContractButton.setOnClickListener(buttonView -> {
mDeleteAlarmLayout.setVisibility(View.GONE);
mExpandButton.setVisibility(View.VISIBLE);
mContractButton.setVisibility(View.GONE);
});
}

void setToggleAlarmButtonOpacity() {
Expand Down
129 changes: 50 additions & 79 deletions app/src/main/res/layout/alarm_list_item.xml
Original file line number Diff line number Diff line change
@@ -1,94 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@color/lightAccent"
android:orientation="vertical">
<com.chauthai.swipereveallayout.SwipeRevealLayout
android:id="@+id/swipe_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@color/lightAccent"
android:orientation="vertical"
app:dragEdge="right"
app:mode="same_level">

<RelativeLayout
android:id="@+id/alarm_container"
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp">
android:layout_height="match_parent"
android:background="@android:color/holo_red_dark">

<ToggleButton
android:id="@+id/toggle_alarm_button"
android:layout_width="wrap_content"
<Button
android:id="@+id/delete_alarm_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_gravity="center_horizontal|top"
android:background="@android:color/transparent"
android:src="@drawable/ic_delete"
android:textColor="@color/white"/>

<TextView
android:id="@+id/alarm_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_margin="10dp"
android:layout_toStartOf="@id/toggle_alarm_button"
android:ellipsize="end"
android:hint="7:00am - NPR Hourly News and other things that are super cool that idk about"
android:maxLines="1"/>

</RelativeLayout>

<View
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:background="@color/colorAccent"/>
android:drawableBottom="@drawable/ic_delete"
android:drawableTint="@color/white"/>
</FrameLayout>

<LinearLayout
android:id="@+id/delete_alarm_layout"
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:visibility="gone">
android:layout_height="match_parent">

<Button
android:id="@+id/delete_alarm_button"
<RelativeLayout
android:id="@+id/alarm_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:drawablePadding="5dp"
android:drawableStart="@drawable/ic_delete"
android:drawableTint="@color/white"
android:padding="5dp"
android:text="@string/delete"
android:textAllCaps="true"
android:textColor="@color/white"
android:textStyle="bold"/>
android:orientation="horizontal"
android:padding="10dp">

</LinearLayout>
<ToggleButton
android:id="@+id/toggle_alarm_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:background="@android:color/transparent"
android:src="@drawable/ic_delete"
android:textColor="@color/white"/>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginEnd="10dp">
<TextView
android:id="@+id/alarm_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_margin="10dp"
android:layout_toStartOf="@id/toggle_alarm_button"
android:ellipsize="end"
android:hint="7:00am - NPR Hourly News and other things that are super cool that idk about"
android:maxLines="1"/>

<ImageButton
android:id="@+id/alarm_item_expand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:src="@drawable/ic_expand_more_black_24dp"
android:tint="@color/white"/>

<ImageButton
android:id="@+id/alarm_item_contract"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:src="@drawable/ic_expand_less_black_24dp"
android:tint="@color/white"
android:visibility="gone"/>
</LinearLayout>
</RelativeLayout>
</FrameLayout>

</LinearLayout>
</com.chauthai.swipereveallayout.SwipeRevealLayout>

0 comments on commit 8dca53f

Please sign in to comment.