Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/nomtek/NomtekUtills
Browse files Browse the repository at this point in the history
  • Loading branch information
Damian Kwasniak committed Nov 20, 2018
2 parents bddad63 + d2db92c commit 9f8be8c
Show file tree
Hide file tree
Showing 32 changed files with 567 additions and 106 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Detailed instructions are available in **How to use** sections.

### How to install
##### 1. Add jitpack repository to your gradle file

```gradle
allprojects {
repositories { ...
Expand All @@ -20,12 +21,22 @@ allprojects {
<img src="./resources/app.gif" width="250">

```gradle
implementation 'com.github.nomtek.NomtekUtills:toolbarcontroller:1.0.2'
implementation 'com.github.nomtek.NomtekUtills:toolbarcontroller:1.0.3'
```
###### StatusbarController [How to use](https://github.com/nomtek/NomtekUtills/blob/master/statusbarcontroller/README.md)

<img src="./resources/statusbar.gif" width="250">

```gradle
implementation 'com.github.nomtek.NomtekUtills:statusbarcontroller:1.0.2'
```
implementation 'com.github.nomtek.NomtekUtills:statusbarcontroller:1.0.3'
```

###### RecyclerBucketList [How to use](https://github.com/nomtek/NomtekUtills/blob/master/recyclerbucketlist/README.md)

<img src="./resources/recycler_bucket.gif" width="250">

```gradle
implementation 'com.github.nomtek.NomtekUtills:recyclerbucketlist:1.0.3'
```


7 changes: 6 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
compileSdkVersion 28
defaultConfig {
applicationId "com.nomtek.toolbarcontroller.example"
minSdkVersion 16
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName "1.0"
Expand All @@ -30,9 +30,14 @@ dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
implementation("com.hannesdorfmann:adapterdelegates3:3.0.1"){
// exclusion is not necessary, but generally a good idea.
exclude group: 'com.google.android', module: 'support-v4'
}
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(':toolbarcontroller')
implementation project(':statusbarcontroller')
implementation project(':recyclerbucketlist')
}
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.nomtek.toolbarcontroller.example">

<application
Expand All @@ -9,9 +10,10 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".ToolbarActivity"/>
<activity android:name=".ToolbarActivity" />
<activity android:name=".ToolbarSecondActivity" />
<activity android:name="com.nomtek.statusbarcontroller.example.StatusBarActivity" />
<activity android:name="com.nomtek.recyclerbucketlist.example.RecyclerListItemBucketActivity" />
<activity android:name="com.nomtek.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/nomtek/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.nomtek
import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import com.nomtek.recyclerbucketlist.example.RecyclerListItemBucketActivity
import com.nomtek.statusbarcontroller.example.StatusBarActivity
import com.nomtek.toolbarcontroller.example.R
import com.nomtek.toolbarcontroller.example.ToolbarActivity
Expand All @@ -23,5 +24,8 @@ class MainActivity : AppCompatActivity() {
statusbarButton.setOnClickListener {
startActivity(Intent(this, StatusBarActivity::class.java))
}
recyclerListItemBucketButton.setOnClickListener {
startActivity(Intent(this, RecyclerListItemBucketActivity::class.java))
}
}
}
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())
}
}


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
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
}
}
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()
}
}
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)
}
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)
}
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)
}
27 changes: 14 additions & 13 deletions app/src/main/res/layout/activity_main.xml
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>
Loading

0 comments on commit 9f8be8c

Please sign in to comment.