-
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.
added article attachments download, with sample
- Loading branch information
luca
committed
Aug 30, 2019
1 parent
ef99651
commit 8558565
Showing
16 changed files
with
348 additions
and
5 deletions.
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
53 changes: 53 additions & 0 deletions
53
sampleapp/src/main/java/com/kirkbushman/sampleapp/activities/AttachmentActivity.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,53 @@ | ||
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.ArticleAttachment | ||
import com.kirkbushman.zammad.models.Ticket | ||
import com.kirkbushman.zammad.models.TicketArticle | ||
import kotlinx.android.synthetic.main.activity_attachment.* | ||
|
||
class AttachmentActivity : AppCompatActivity() { | ||
|
||
companion object { | ||
|
||
private const val PARAM_TICKET = "intent_param_ticket" | ||
private const val PARAM_ARTICLE = "intent_param_article" | ||
private const val PARAM_ATTACHMENT = "intent_param_attachment" | ||
|
||
fun start(context: Context, ticket: Ticket, article: TicketArticle, attachment: ArticleAttachment) { | ||
|
||
val intent = Intent(context, AttachmentActivity::class.java) | ||
intent.putExtra(PARAM_TICKET, ticket) | ||
intent.putExtra(PARAM_ARTICLE, article) | ||
intent.putExtra(PARAM_ATTACHMENT, attachment) | ||
|
||
context.startActivity(intent) | ||
} | ||
} | ||
|
||
private val client by lazy { SampleApplication.instance.getClient() } | ||
|
||
private val ticket by lazy { intent.getParcelableExtra(PARAM_TICKET) as Ticket } | ||
private val article by lazy { intent.getParcelableExtra(PARAM_ARTICLE) as TicketArticle } | ||
private val attachment by lazy { intent.getParcelableExtra(PARAM_ATTACHMENT) as ArticleAttachment } | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_attachment) | ||
|
||
var fileContent = "" | ||
doAsync(doWork = { | ||
|
||
fileContent = client?.ticketArticleAttachment(ticket, article, attachment) ?: "" | ||
}, onPost = { | ||
|
||
attachment_text.text = fileContent | ||
}) | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
sampleapp/src/main/java/com/kirkbushman/sampleapp/activities/AttachmentsActivity.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.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.controllers.AttachmentsController | ||
import com.kirkbushman.sampleapp.controllers.OnClickCallback | ||
import com.kirkbushman.zammad.models.ArticleAttachment | ||
import com.kirkbushman.zammad.models.Ticket | ||
import com.kirkbushman.zammad.models.TicketArticle | ||
import kotlinx.android.synthetic.main.activity_attachments.* | ||
|
||
class AttachmentsActivity : AppCompatActivity() { | ||
|
||
companion object { | ||
|
||
private const val PARAM_TICKET = "intent_param_ticket" | ||
private const val PARAM_ARTICLE = "intent_param_article" | ||
|
||
fun start(context: Context, ticket: Ticket, article: TicketArticle) { | ||
|
||
val intent = Intent(context, AttachmentsActivity::class.java) | ||
intent.putExtra(PARAM_TICKET, ticket) | ||
intent.putExtra(PARAM_ARTICLE, article) | ||
|
||
context.startActivity(intent) | ||
} | ||
} | ||
|
||
private val ticket by lazy { intent.getParcelableExtra(PARAM_TICKET) as Ticket } | ||
private val article by lazy { intent.getParcelableExtra(PARAM_ARTICLE) as TicketArticle } | ||
|
||
private val attachments = ArrayList<ArticleAttachment>() | ||
|
||
private val controller by lazy { | ||
AttachmentsController(object : OnClickCallback { | ||
|
||
override fun onClick(position: Int) { | ||
|
||
val attachment = attachments[position] | ||
AttachmentActivity.start(this@AttachmentsActivity, ticket, article, attachment) | ||
} | ||
}) | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_attachments) | ||
|
||
setSupportActionBar(toolbar) | ||
supportActionBar?.let { | ||
it.setDisplayHomeAsUpEnabled(true) | ||
it.setDisplayShowHomeEnabled(true) | ||
} | ||
|
||
list.setHasFixedSize(true) | ||
list.setController(controller) | ||
|
||
attachments.addAll(article.attachments) | ||
controller.setAttachments(attachments) | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
sampleapp/src/main/java/com/kirkbushman/sampleapp/controllers/AttachmentsController.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.attachment | ||
import com.kirkbushman.sampleapp.models.empty | ||
import com.kirkbushman.zammad.models.ArticleAttachment | ||
|
||
class AttachmentsController(private val callback: OnClickCallback) : EpoxyController() { | ||
|
||
private val attachments = ArrayList<ArticleAttachment>() | ||
|
||
fun setAttachments(attachments: Collection<ArticleAttachment>) { | ||
this.attachments.clear() | ||
this.attachments.addAll(attachments) | ||
requestModelBuild() | ||
} | ||
|
||
override fun buildModels() { | ||
|
||
if (attachments.isEmpty()) { | ||
empty { | ||
id("empty_items") | ||
} | ||
} | ||
|
||
attachments.forEach { | ||
|
||
attachment { | ||
id(it.id) | ||
attachment(it) | ||
clickListener { _, _, _, position -> callback.onClick(position) } | ||
} | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
sampleapp/src/main/java/com/kirkbushman/sampleapp/controllers/OnArticleCallback.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,6 @@ | ||
package com.kirkbushman.sampleapp.controllers | ||
|
||
interface OnArticleCallback : OnClickCallback { | ||
|
||
fun onAttachmentsClick(position: Int) | ||
} |
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
39 changes: 39 additions & 0 deletions
39
sampleapp/src/main/java/com/kirkbushman/sampleapp/models/AttachmentModel.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,39 @@ | ||
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.ArticleAttachment | ||
|
||
@EpoxyModelClass(layout = R.layout.item_attachment) | ||
abstract class AttachmentModel : EpoxyModelWithHolder<AttachmentHolder>() { | ||
|
||
@EpoxyAttribute | ||
lateinit var attachment: ArticleAttachment | ||
|
||
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) | ||
lateinit var clickListener: View.OnClickListener | ||
|
||
override fun bind(holder: AttachmentHolder) { | ||
|
||
holder.attachmentFilename.text = attachment.filename | ||
holder.attachmentFilesize.text = attachment.size.toString() | ||
|
||
holder.container.setOnClickListener(clickListener) | ||
} | ||
|
||
override fun unbind(holder: AttachmentHolder) { | ||
holder.container.setOnClickListener(null) | ||
} | ||
} | ||
|
||
class AttachmentHolder : KotlinHolder() { | ||
|
||
val container by bind<LinearLayout>(R.id.container) | ||
val attachmentFilename by bind<TextView>(R.id.attachment_filename) | ||
val attachmentFilesize by bind<TextView>(R.id.attachment_filesize) | ||
} |
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"?> | ||
<ScrollView 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/attachment_text" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="16dp" | ||
/> | ||
|
||
</ScrollView> |
Oops, something went wrong.