-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/nomtek/NomtekUtills
- Loading branch information
Showing
32 changed files
with
567 additions
and
106 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
app/src/main/java/com/nomtek/recyclerbucketlist/example/HomeListAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.nomtek.recyclerbucketlist.example | ||
|
||
import com.hannesdorfmann.adapterdelegates3.ListDelegationAdapter | ||
import com.nomtek.recyclerbucketlist.example.delegates.ColorHomeListItemAdapterDelegate | ||
import com.nomtek.recyclerbucketlist.example.delegates.CounterHomeListItemAdapterDelegate | ||
import com.nomtek.recyclerbucketlist.example.delegates.FooterHomeListItemAdapterDelegate | ||
|
||
class HomeListAdapter : ListDelegationAdapter<MutableList<HomeListItem>>() { | ||
|
||
init { | ||
delegatesManager.addDelegate(ColorHomeListItemAdapterDelegate()) | ||
delegatesManager.addDelegate(CounterHomeListItemAdapterDelegate()) | ||
delegatesManager.addDelegate(FooterHomeListItemAdapterDelegate()) | ||
} | ||
} | ||
|
||
|
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/nomtek/recyclerbucketlist/example/HomeListItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.nomtek.recyclerbucketlist.example | ||
|
||
interface HomeListItem | ||
|
||
data class CounterHomeListItem(val counterValue: Int) : HomeListItem | ||
|
||
data class ColorHomeListItem(val color: Int) : HomeListItem | ||
|
||
data class FooterHomeListItem(val onAddColorButtonClicked: () -> Unit, | ||
val onRemoveColorButtonClicked: () -> Unit) : HomeListItem |
64 changes: 64 additions & 0 deletions
64
app/src/main/java/com/nomtek/recyclerbucketlist/example/HomeListItemBucket.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.nomtek.recyclerbucketlist.example | ||
|
||
import android.graphics.Color | ||
import com.nomtek.libs.recyclerbucketlist.ListItemBucket | ||
import java.util.* | ||
|
||
class HomeListItemBucket : ListItemBucket<HomeListItem>() { | ||
|
||
init { | ||
putItems(COLORS_ITEM_TOP_BUCKET, Collections.emptyList()) | ||
putItems(COUNTER_ITEM_BUCKET, CounterHomeListItem(0)) | ||
val colors: IntArray = intArrayOf(Color.RED, Color.GREEN, Color.BLUE, Color.CYAN) | ||
putItems(COLORS_ITEM_BUCKET, colors.map { ColorHomeListItem(it) }) | ||
} | ||
|
||
fun setFooterItem(onAddColorButtonClicked: () -> Unit, | ||
onRemoveColorButtonClicked: () -> Unit) { | ||
putItems(FOOTER_ITEM_BUCKET, FooterHomeListItem(onAddColorButtonClicked, onRemoveColorButtonClicked)) | ||
} | ||
|
||
fun removeTopColor() { | ||
val items = getItems(COLORS_ITEM_TOP_BUCKET) as MutableList<HomeListItem>? | ||
items?.let { | ||
if (it.isNotEmpty()) { | ||
it.removeAt(it.size - 1) | ||
decrementCounter() | ||
} | ||
} | ||
} | ||
|
||
fun addTopColor() { | ||
addItems(COLORS_ITEM_TOP_BUCKET, ColorHomeListItem(Color.YELLOW)) | ||
incrementCounter() | ||
} | ||
|
||
private fun getCounterValue(): Int { | ||
val item = getFirstItem(COUNTER_ITEM_BUCKET) as CounterHomeListItem | ||
return item.counterValue | ||
} | ||
|
||
private fun incrementCounter() { | ||
setCounterValue(getCounterValue() + 1) | ||
} | ||
|
||
private fun decrementCounter() { | ||
setCounterValue(getCounterValue() - 1) | ||
} | ||
|
||
private fun setCounterValue(counterValue: Int) { | ||
putItems(COUNTER_ITEM_BUCKET, CounterHomeListItem(counterValue)) | ||
} | ||
|
||
|
||
companion object { | ||
|
||
private const val COLORS_ITEM_TOP_BUCKET = 0 | ||
|
||
private const val COUNTER_ITEM_BUCKET = 1 | ||
|
||
private const val COLORS_ITEM_BUCKET = 2 | ||
|
||
private const val FOOTER_ITEM_BUCKET = 3 | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
app/src/main/java/com/nomtek/recyclerbucketlist/example/RecyclerListItemBucketActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.nomtek.recyclerbucketlist.example | ||
|
||
import android.os.Bundle | ||
import android.support.v7.app.AppCompatActivity | ||
import android.support.v7.widget.LinearLayoutManager | ||
import com.nomtek.toolbarcontroller.example.R | ||
import kotlinx.android.synthetic.main.activity_recycler.* | ||
|
||
class RecyclerListItemBucketActivity : AppCompatActivity() { | ||
|
||
private val adapter = HomeListAdapter() | ||
|
||
private val bucket = HomeListItemBucket() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_recycler) | ||
recyclerView.setHasFixedSize(true) | ||
recyclerView.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false) | ||
recyclerView.adapter = adapter | ||
bucket.setFooterItem( | ||
onAddColorButtonClicked = { | ||
bucket.addTopColor() | ||
refreshItems() | ||
}, | ||
onRemoveColorButtonClicked = { | ||
bucket.removeTopColor() | ||
refreshItems() | ||
}) | ||
refreshItems() | ||
|
||
} | ||
|
||
private fun refreshItems() { | ||
setItems(bucket.items) | ||
} | ||
|
||
private fun setItems(items: List<HomeListItem>) { | ||
adapter.items = items.toMutableList() | ||
adapter.notifyDataSetChanged() | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
.../java/com/nomtek/recyclerbucketlist/example/delegates/ColorHomeListItemAdapterDelegate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.nomtek.recyclerbucketlist.example.delegates | ||
|
||
import android.support.v7.widget.RecyclerView | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import com.hannesdorfmann.adapterdelegates3.AbsListItemAdapterDelegate | ||
import com.nomtek.recyclerbucketlist.example.ColorHomeListItem | ||
import com.nomtek.recyclerbucketlist.example.HomeListItem | ||
import com.nomtek.toolbarcontroller.example.R | ||
import kotlinx.android.synthetic.main.color_list_item_view.view.* | ||
|
||
class ColorHomeListItemAdapterDelegate : AbsListItemAdapterDelegate<ColorHomeListItem, HomeListItem, | ||
ColorHomeListItemAdapterDelegate.ViewHolder>() { | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup): ViewHolder { | ||
val view = LayoutInflater.from(parent.context).inflate(R.layout.color_list_item_view, parent, false) | ||
return ViewHolder(view) | ||
} | ||
|
||
override fun isForViewType(item: HomeListItem, items: MutableList<HomeListItem>, position: Int): | ||
Boolean { | ||
return item is ColorHomeListItem | ||
} | ||
|
||
override fun onBindViewHolder(item: ColorHomeListItem, vh: ViewHolder, payload: MutableList<Any>) { | ||
vh.itemView.contentView.setBackgroundColor(item.color) | ||
} | ||
|
||
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) | ||
} |
31 changes: 31 additions & 0 deletions
31
...ava/com/nomtek/recyclerbucketlist/example/delegates/CounterHomeListItemAdapterDelegate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.nomtek.recyclerbucketlist.example.delegates | ||
|
||
import android.support.v7.widget.RecyclerView | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import com.hannesdorfmann.adapterdelegates3.AbsListItemAdapterDelegate | ||
import com.nomtek.recyclerbucketlist.example.CounterHomeListItem | ||
import com.nomtek.recyclerbucketlist.example.HomeListItem | ||
import com.nomtek.toolbarcontroller.example.R | ||
import kotlinx.android.synthetic.main.counter_list_item_view.view.* | ||
|
||
class CounterHomeListItemAdapterDelegate : AbsListItemAdapterDelegate<CounterHomeListItem, HomeListItem, | ||
CounterHomeListItemAdapterDelegate.ViewHolder>() { | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup): ViewHolder { | ||
val view = LayoutInflater.from(parent.context).inflate(R.layout.counter_list_item_view, parent, false) | ||
return ViewHolder(view) | ||
} | ||
|
||
override fun isForViewType(item: HomeListItem, items: MutableList<HomeListItem>, position: Int): | ||
Boolean { | ||
return item is CounterHomeListItem | ||
} | ||
|
||
override fun onBindViewHolder(item: CounterHomeListItem, vh: ViewHolder, payload: MutableList<Any>) { | ||
vh.itemView.textView.text = item.counterValue.toString() | ||
} | ||
|
||
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) | ||
} |
36 changes: 36 additions & 0 deletions
36
...java/com/nomtek/recyclerbucketlist/example/delegates/FooterHomeListItemAdapterDelegate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.nomtek.recyclerbucketlist.example.delegates | ||
|
||
import android.support.v7.widget.RecyclerView | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import com.hannesdorfmann.adapterdelegates3.AbsListItemAdapterDelegate | ||
import com.nomtek.recyclerbucketlist.example.FooterHomeListItem | ||
import com.nomtek.recyclerbucketlist.example.HomeListItem | ||
import com.nomtek.toolbarcontroller.example.R | ||
import kotlinx.android.synthetic.main.footer_list_item_view.view.* | ||
|
||
class FooterHomeListItemAdapterDelegate : AbsListItemAdapterDelegate<FooterHomeListItem, HomeListItem, | ||
FooterHomeListItemAdapterDelegate.ViewHolder>() { | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup): ViewHolder { | ||
val view = LayoutInflater.from(parent.context).inflate(R.layout.footer_list_item_view, | ||
parent, false) | ||
return ViewHolder(view) | ||
} | ||
|
||
override fun isForViewType(item: HomeListItem, items: MutableList<HomeListItem>, position: Int): Boolean { | ||
return item is FooterHomeListItem | ||
} | ||
|
||
override fun onBindViewHolder(item: FooterHomeListItem, vh: ViewHolder, payload: MutableList<Any>) { | ||
vh.itemView.buttonAddColor.setOnClickListener { | ||
item.onAddColorButtonClicked() | ||
} | ||
vh.itemView.buttonRemoveColor.setOnClickListener { | ||
item.onRemoveColorButtonClicked() | ||
} | ||
} | ||
|
||
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,30 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
<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="match_parent" | ||
android:gravity="center" | ||
android:orientation="vertical" | ||
tools:context="com.nomtek.MainActivity"> | ||
|
||
<Button | ||
android:id="@+id/toolbarButton" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Toolbar Controller" | ||
app:layout_constraintBottom_toTopOf="@+id/statusbarButton" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
android:text="Toolbar Controller" /> | ||
|
||
<Button | ||
android:id="@+id/statusbarButton" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Statusbar Controller" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/toolbarButton" /> | ||
android:layout_marginTop="16dp" | ||
android:text="Statusbar Controller" /> | ||
|
||
</android.support.constraint.ConstraintLayout> | ||
<Button | ||
android:id="@+id/recyclerListItemBucketButton" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="16dp" | ||
android:text="RecyclerView list item bucket" /> | ||
|
||
</LinearLayout> |
Oops, something went wrong.