Skip to content

Commit

Permalink
- Added ability to delete already added payloads
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Rekun committed Jul 5, 2018
1 parent c29f0ba commit 34f60f9
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
Expand Up @@ -6,9 +6,11 @@ import android.view.View
import android.view.ViewGroup
import com.pavelrekun.rekado.R
import com.pavelrekun.rekado.data.Payload
import com.pavelrekun.rekado.services.eventbus.Events
import com.pavelrekun.rekado.services.utils.FilesHelper
import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.item_payload.*
import java.io.File
import org.greenrobot.eventbus.EventBus

class PayloadsAdapter(var data: MutableList<Payload>) : RecyclerView.Adapter<PayloadsAdapter.ViewHolder>() {

Expand All @@ -33,6 +35,13 @@ class PayloadsAdapter(var data: MutableList<Payload>) : RecyclerView.Adapter<Pay

fun bind(payload: Payload) {
itemPayloadName.text = payload.name

itemPayloadRemove.visibility = if (payload.name == "sx_loader.bin") View.GONE else View.VISIBLE

itemPayloadRemove.setOnClickListener {
FilesHelper.removeFile(payload.path)
EventBus.getDefault().postSticky(Events.UpdateListEvent())
}
}

}
Expand Down
Expand Up @@ -5,6 +5,7 @@ import com.pavelrekun.rekado.services.eventbus.Events
import com.pavelrekun.rekado.services.payloads.PayloadHelper
import org.greenrobot.eventbus.EventBus
import java.io.*
import java.nio.file.Path


object FilesHelper {
Expand All @@ -31,4 +32,8 @@ object FilesHelper {
}
}

fun removeFile(path: String) {
File(path).delete()
}

}
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_remove.xml
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="28dp"
android:height="28dp"
android:viewportHeight="24"
android:viewportWidth="24">

<path
android:fillColor="@color/colorIcons"
android:pathData="M16 9v10H8V9h8m-1.5-6h-5l-1 1H5v2h14V4h-3.5l-1-1zM18 7H6v12c0 1.1 0.9 2 2 2h8c1.1 0 2-0.9 2-2V7z" />
</vector>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_about.xml
Expand Up @@ -96,7 +96,7 @@
android:padding="16dp"
android:text="@string/about_information_description"
android:textColor="?android:attr/textColorPrimary"
android:textSize="16sp" />
android:textSize="14sp" />

</LinearLayout>

Expand Down
19 changes: 16 additions & 3 deletions app/src/main/res/layout/item_payload.xml
Expand Up @@ -2,17 +2,30 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:layout_height="56dp"
android:gravity="center_vertical"
android:orientation="horizontal">

<TextView
android:id="@+id/itemPayloadName"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:textColor="?android:attr/textColorPrimary"
android:textSize="16sp"
tools:text="SX OS" />

<ImageView
android:id="@+id/itemPayloadRemove"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:contentDescription="@null"
android:focusable="true"
android:src="@drawable/ic_remove" />

</LinearLayout>

0 comments on commit 34f60f9

Please sign in to comment.