-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
luca
committed
Aug 11, 2019
1 parent
3f44708
commit f351da3
Showing
15 changed files
with
332 additions
and
1 deletion.
There are no files selected for viewing
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
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
44 changes: 44 additions & 0 deletions
44
sampleapp/src/main/java/com/kirkbushman/sampleapp/activities/RoleActivity.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,44 @@ | ||
package com.kirkbushman.sampleapp.activities | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.kirkbushman.sampleapp.R | ||
import com.kirkbushman.sampleapp.SampleApplication | ||
import com.kirkbushman.sampleapp.doAsync | ||
import com.kirkbushman.zammad.models.Role | ||
import kotlinx.android.synthetic.main.activity_role.* | ||
|
||
class RoleActivity : AppCompatActivity() { | ||
|
||
companion object { | ||
|
||
private const val PARAM_ROLE = "intent_param_role" | ||
|
||
fun start(context: Context, role: Role) { | ||
|
||
val intent = Intent(context, RoleActivity::class.java) | ||
intent.putExtra(PARAM_ROLE, role) | ||
|
||
context.startActivity(intent) | ||
} | ||
} | ||
|
||
private val client by lazy { SampleApplication.instance.getClient() } | ||
private val role by lazy { intent.getParcelableExtra(PARAM_ROLE) as Role } | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_role) | ||
|
||
var newRole: Role? = null | ||
doAsync(doWork = { | ||
|
||
newRole = client?.role(role.id, true) | ||
}, onPost = { | ||
|
||
role_text.text = newRole.toString() | ||
}) | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
sampleapp/src/main/java/com/kirkbushman/sampleapp/activities/RolesActivity.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,50 @@ | ||
package com.kirkbushman.sampleapp.activities | ||
|
||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.kirkbushman.sampleapp.R | ||
import com.kirkbushman.sampleapp.SampleApplication | ||
import com.kirkbushman.sampleapp.controllers.OnClickCallback | ||
import com.kirkbushman.sampleapp.controllers.RolesController | ||
import com.kirkbushman.sampleapp.doAsync | ||
import com.kirkbushman.zammad.models.Role | ||
import kotlinx.android.synthetic.main.activity_groups.* | ||
|
||
class RolesActivity : AppCompatActivity() { | ||
|
||
private val client by lazy { SampleApplication.instance.getClient() } | ||
|
||
private val roles = ArrayList<Role>() | ||
private val controller by lazy { | ||
RolesController(object : OnClickCallback { | ||
|
||
override fun onClick(position: Int) { | ||
|
||
val role = roles[position] | ||
RoleActivity.start(this@RolesActivity, role) | ||
} | ||
}) | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_roles) | ||
|
||
setSupportActionBar(toolbar) | ||
supportActionBar?.let { | ||
it.setDisplayHomeAsUpEnabled(true) | ||
it.setDisplayShowHomeEnabled(true) | ||
} | ||
|
||
list.setHasFixedSize(true) | ||
list.setController(controller) | ||
|
||
doAsync(doWork = { | ||
|
||
roles.addAll(client?.roles() ?: listOf()) | ||
}, onPost = { | ||
|
||
controller.setRoles(roles) | ||
}) | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
sampleapp/src/main/java/com/kirkbushman/sampleapp/controllers/RolesController.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,35 @@ | ||
package com.kirkbushman.sampleapp.controllers | ||
|
||
import com.airbnb.epoxy.EpoxyController | ||
import com.kirkbushman.sampleapp.models.empty | ||
import com.kirkbushman.sampleapp.models.role | ||
import com.kirkbushman.zammad.models.Role | ||
|
||
class RolesController(private val callback: OnClickCallback) : EpoxyController() { | ||
|
||
private val roles = ArrayList<Role>() | ||
|
||
fun setRoles(roles: Collection<Role>) { | ||
this.roles.clear() | ||
this.roles.addAll(roles) | ||
requestModelBuild() | ||
} | ||
|
||
override fun buildModels() { | ||
|
||
if (roles.isEmpty()) { | ||
empty { | ||
id("empty_items") | ||
} | ||
} | ||
|
||
roles.forEach { | ||
|
||
role { | ||
id(it.id) | ||
role(it) | ||
clickListener { _, _, _, position -> callback.onClick(position) } | ||
} | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
sampleapp/src/main/java/com/kirkbushman/sampleapp/models/RoleModel.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,41 @@ | ||
package com.kirkbushman.sampleapp.models | ||
|
||
import android.view.View | ||
import android.widget.LinearLayout | ||
import android.widget.TextView | ||
import com.airbnb.epoxy.EpoxyAttribute | ||
import com.airbnb.epoxy.EpoxyModelClass | ||
import com.airbnb.epoxy.EpoxyModelWithHolder | ||
import com.kirkbushman.sampleapp.R | ||
import com.kirkbushman.zammad.models.Role | ||
|
||
@EpoxyModelClass(layout = R.layout.item_role) | ||
abstract class RoleModel : EpoxyModelWithHolder<RoleHolder>() { | ||
|
||
@EpoxyAttribute | ||
lateinit var role: Role | ||
|
||
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) | ||
lateinit var clickListener: View.OnClickListener | ||
|
||
override fun bind(holder: RoleHolder) { | ||
|
||
holder.roleName.text = role.name | ||
holder.roleActive.text = role.active.toString() | ||
holder.roleCreated.text = role.createdAt | ||
|
||
holder.container.setOnClickListener(clickListener) | ||
} | ||
|
||
override fun unbind(holder: RoleHolder) { | ||
holder.container.setOnClickListener(null) | ||
} | ||
} | ||
|
||
class RoleHolder : KotlinHolder() { | ||
|
||
val container by bind<LinearLayout>(R.id.container) | ||
val roleName by bind<TextView>(R.id.role_name) | ||
val roleActive by bind<TextView>(R.id.role_active) | ||
val roleCreated by bind<TextView>(R.id.role_created) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<TextView | ||
android:id="@+id/role_text" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="16dp" | ||
/> | ||
|
||
</LinearLayout> |
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,33 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.coordinatorlayout.widget.CoordinatorLayout | ||
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="match_parent"> | ||
|
||
<com.google.android.material.appbar.AppBarLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
|
||
<androidx.appcompat.widget.Toolbar | ||
android:id="@+id/toolbar" | ||
android:layout_width="match_parent" | ||
android:layout_height="?android:attr/actionBarSize" | ||
app:layout_scrollFlags="scroll|enterAlways"> | ||
|
||
</androidx.appcompat.widget.Toolbar> | ||
|
||
</com.google.android.material.appbar.AppBarLayout> | ||
|
||
<com.airbnb.epoxy.EpoxyRecyclerView | ||
android:id="@+id/list" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:clipToPadding="true" | ||
android:scrollbars="vertical" | ||
android:fadeScrollbars="true" | ||
app:itemSpacing="16dp" | ||
app:layoutManager="@string/linear_layout" | ||
app:layout_behavior="@string/appbar_scrolling_view_behavior" /> | ||
|
||
</androidx.coordinatorlayout.widget.CoordinatorLayout> |
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,35 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<com.google.android.material.card.MaterialCardView | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="8dp"> | ||
|
||
<LinearLayout | ||
android:id="@+id/container" | ||
android:orientation="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
|
||
<TextView | ||
android:id="@+id/role_name" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:textSize="16sp" | ||
android:textStyle="bold" | ||
android:layout_margin="8dp" /> | ||
|
||
<TextView | ||
android:id="@+id/role_active" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="8dp" /> | ||
|
||
<TextView | ||
android:id="@+id/role_created" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="8dp" /> | ||
|
||
</LinearLayout> | ||
</com.google.android.material.card.MaterialCardView> |
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