Skip to content

Commit 33b1388

Browse files
committed
Initial commit
0 parents  commit 33b1388

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1607
-0
lines changed

app/build.gradle

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
apply plugin: 'com.android.application'
2+
3+
apply plugin: 'kotlin-android'
4+
5+
apply plugin: 'kotlin-android-extensions'
6+
7+
android {
8+
compileSdkVersion 26
9+
defaultConfig {
10+
applicationId "de.taop.swipeactionsample"
11+
minSdkVersion 14
12+
targetSdkVersion 26
13+
versionCode 1
14+
versionName "1.0"
15+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16+
vectorDrawables.useSupportLibrary = true
17+
}
18+
buildTypes {
19+
release {
20+
minifyEnabled false
21+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22+
}
23+
}
24+
}
25+
26+
dependencies {
27+
implementation fileTree(dir: 'libs', include: ['*.jar'])
28+
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
29+
implementation 'com.android.support:appcompat-v7:26.1.0'
30+
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
31+
implementation 'com.android.support:design:26.1.0'
32+
testImplementation 'junit:junit:4.12'
33+
androidTestImplementation 'com.android.support.test:runner:1.0.1'
34+
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
35+
compile project(path: ':swipeaction')
36+
}

app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile

app/src/main/AndroidManifest.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="de.taop.swipeactionsample">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/AppTheme">
12+
<activity
13+
android:name=".MainActivity"
14+
android:label="@string/app_name"
15+
android:theme="@style/AppTheme.NoActionBar">
16+
<intent-filter>
17+
<action android:name="android.intent.action.MAIN" />
18+
19+
<category android:name="android.intent.category.LAUNCHER" />
20+
</intent-filter>
21+
</activity>
22+
</application>
23+
24+
</manifest>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package de.taop.swipeactionsample
2+
3+
import android.os.Bundle
4+
import android.support.v7.app.AppCompatActivity
5+
import android.support.v7.widget.LinearLayoutManager
6+
import android.view.Menu
7+
import android.view.MenuItem
8+
import de.taop.swipeaction.AlternatingBackgroundItemDecoration
9+
import de.taop.swipeaction.SwipeActionSetupHelper
10+
import de.taop.swipeaction.actions.DeleteAction
11+
import de.taop.swipeactionsample.dummyItems.DummyAdapter
12+
import de.taop.swipeactionsample.dummyItems.DummyItem
13+
14+
import kotlinx.android.synthetic.main.activity_main.*
15+
import kotlinx.android.synthetic.main.content_main.*
16+
17+
class MainActivity : AppCompatActivity() {
18+
19+
override fun onCreate(savedInstanceState: Bundle?) {
20+
super.onCreate(savedInstanceState)
21+
setContentView(R.layout.activity_main)
22+
setSupportActionBar(toolbar)
23+
24+
fab.setOnClickListener { view ->
25+
(list.adapter as DummyAdapter).addItem(DummyItem())
26+
}
27+
28+
list.layoutManager = LinearLayoutManager(this)
29+
list.adapter = DummyAdapter(List(6, {
30+
DummyItem(it)
31+
}) as ArrayList<DummyItem>)
32+
33+
// set Background colors of list
34+
list.addItemDecoration(AlternatingBackgroundItemDecoration(this, R.color.colorWhite, R.color.colorGrey))
35+
36+
// create swipe actions
37+
val pendingDeleteAction = DeleteAction(list, R.id.container)
38+
val instantDeleteAction = DeleteAction(list, R.id.container,
39+
false,
40+
iconID = R.drawable.ic_delete_forever_black_24dp,
41+
colorID = R.color.colorInstantDelete)
42+
43+
instantDeleteAction.setSnackBarText(R.string.deleteUndo, R.plurals.deletedItems)
44+
45+
SwipeActionSetupHelper.setUpRecyclerView(this, list, pendingDeleteAction, instantDeleteAction)
46+
47+
instantDeleteAction.itemsDeletedCallback = {
48+
}
49+
50+
pendingDeleteAction.itemsDeletedCallback = {
51+
}
52+
53+
}
54+
55+
override fun onCreateOptionsMenu(menu: Menu): Boolean {
56+
// Inflate the menu; this adds items to the action bar if it is present.
57+
menuInflater.inflate(R.menu.menu_main, menu)
58+
return true
59+
}
60+
61+
override fun onOptionsItemSelected(item: MenuItem): Boolean {
62+
// Handle action bar item clicks here. The action bar will
63+
// automatically handle clicks on the Home/Up button, so long
64+
// as you specify a parent activity in AndroidManifest.xml.
65+
return when (item.itemId) {
66+
R.id.action_settings -> true
67+
else -> super.onOptionsItemSelected(item)
68+
}
69+
}
70+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package de.taop.swipeactionsample.dummyItems
2+
3+
import android.support.v7.widget.RecyclerView
4+
import android.view.LayoutInflater
5+
import android.view.View
6+
import android.view.ViewGroup
7+
import de.taop.swipeaction.actions.SwipeActionAdapter
8+
import de.taop.swipeactionsample.R
9+
import kotlinx.android.synthetic.main.dummy_layout.view.*
10+
11+
12+
class DummyAdapter(var items: ArrayList<DummyItem>, val itemClick: (DummyItem) -> Unit = {})
13+
: RecyclerView.Adapter<DummyAdapter.DummyViewHolder>(),
14+
SwipeActionAdapter {
15+
16+
fun addItem(item: Any) {
17+
items.add(item as DummyItem)
18+
notifyItemInserted(items.size - 1)
19+
}
20+
21+
override fun addItemAt(position: Int, item: Any) {
22+
items.add(position, item as DummyItem)
23+
notifyItemInserted(position)
24+
}
25+
26+
override fun removeItemAt(position: Int) {
27+
items.removeAt(position)
28+
notifyItemRemoved(position)
29+
}
30+
31+
override fun getItemAt(position: Int): DummyItem = items[position]
32+
33+
override fun containsItem(item: Any): Boolean = items.contains(item)
34+
35+
override fun getIndexOfItem(itemAt: Any): Int = items.indexOf(itemAt)
36+
37+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DummyViewHolder {
38+
val view = LayoutInflater.from(parent.context).inflate(R.layout.dummy_layout, parent, false)
39+
return DummyViewHolder(view, itemClick)
40+
}
41+
42+
fun setData(newDataSet: MutableList<DummyItem>) {
43+
items = newDataSet.toList() as ArrayList<DummyItem>
44+
notifyDataSetChanged()
45+
}
46+
47+
override fun onBindViewHolder(holder: DummyViewHolder, position: Int) {
48+
holder.bindView(items[position], position)
49+
}
50+
51+
override fun getItemCount(): Int = items.size ?: 0
52+
53+
class DummyViewHolder(val view: View, val itemClick: (DummyItem) -> Unit) : RecyclerView.ViewHolder(view) {
54+
55+
fun bindView(item: DummyItem, position: Int) {
56+
with(item) {
57+
item.position = position
58+
itemView.name.text = "original position: ${item.position}"
59+
itemView.setOnClickListener { itemClick(this) }
60+
}
61+
62+
}
63+
}
64+
65+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package de.taop.swipeactionsample.dummyItems
2+
3+
/**
4+
* Created by Adrian on 04.12.2017.
5+
*/
6+
data class DummyItem(var position: Int = -1)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package de.taop.swipeactionsample.sampleActions
2+
3+
import android.content.Intent
4+
import android.os.Handler
5+
import android.os.Looper
6+
import android.support.v4.content.ContextCompat.startActivity
7+
import android.support.v7.widget.RecyclerView
8+
import de.taop.swipeactionsample.R
9+
import java.util.concurrent.TimeUnit
10+
11+
12+
/**
13+
* Example Share Action.
14+
*
15+
* @author Adrian Bernhart
16+
*/
17+
class ShareAction(recyclerView: RecyclerView) : de.taop.swipeaction.actions.SwipeAction(recyclerView, "share", R.drawable.ic_share_black_24dp, actionBGColorID = R.color.colorShare) {
18+
19+
companion object {
20+
val REQUEST_WRITE_STORAGE = 1617
21+
}
22+
23+
private var lastSharedPosition: Int = -1
24+
25+
override fun performAction(swipedHolder: RecyclerView.ViewHolder, swipeDirection: Int) {
26+
lastSharedPosition = swipedHolder.adapterPosition
27+
share(swipedHolder.adapterPosition)
28+
29+
//reset the swiped item after a timeout
30+
Thread({
31+
TimeUnit.MILLISECONDS.sleep(1000)
32+
33+
Handler(Looper.getMainLooper()).post({
34+
adapter.notifyItemChanged(swipedHolder.adapterPosition)
35+
})
36+
}).start()
37+
38+
}
39+
40+
private fun share(adapterPosition: Int) {
41+
startShareIntent("Position $adapterPosition was shared!")
42+
}
43+
44+
private fun startShareIntent(urlKey: String) {
45+
val share = Intent(Intent.ACTION_SEND)
46+
share.type = "text"
47+
share.putExtra(Intent.EXTRA_TEXT, urlKey)
48+
// grants user read permission to the uri if needed
49+
startActivity(context, Intent.createChooser(share, "Share Action"), null)
50+
}
51+
52+
53+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:aapt="http://schemas.android.com/aapt"
3+
android:width="108dp"
4+
android:height="108dp"
5+
android:viewportHeight="108"
6+
android:viewportWidth="108">
7+
<path
8+
android:fillType="evenOdd"
9+
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
10+
android:strokeColor="#00000000"
11+
android:strokeWidth="1">
12+
<aapt:attr name="android:fillColor">
13+
<gradient
14+
android:endX="78.5885"
15+
android:endY="90.9159"
16+
android:startX="48.7653"
17+
android:startY="61.0927"
18+
android:type="linear">
19+
<item
20+
android:color="#44000000"
21+
android:offset="0.0" />
22+
<item
23+
android:color="#00000000"
24+
android:offset="1.0" />
25+
</gradient>
26+
</aapt:attr>
27+
</path>
28+
<path
29+
android:fillColor="#FFFFFF"
30+
android:fillType="nonZero"
31+
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
32+
android:strokeColor="#00000000"
33+
android:strokeWidth="1" />
34+
</vector>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24.0"
5+
android:viewportHeight="24.0">
6+
<path
7+
android:fillColor="#FF000000"
8+
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
9+
</vector>

0 commit comments

Comments
 (0)