mirror of
https://github.com/Matte23/circolapp.git
synced 2025-12-06 07:29:10 +00:00
Add attachments list
This commit is contained in:
@@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* Circolapp
|
||||||
|
* Copyright (C) 2019 Matteo Schiff
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.underdesk.circolapp.adapters
|
||||||
|
|
||||||
|
import android.app.DownloadManager
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Environment
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.widget.ImageButton
|
||||||
|
import android.widget.TextView
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import kotlinx.android.synthetic.main.item_attachment.view.*
|
||||||
|
import net.underdesk.circolapp.R
|
||||||
|
|
||||||
|
class AttachmentAdapter(
|
||||||
|
private val attachmentsNames: List<String>,
|
||||||
|
private val attachmentsUrls: List<String>
|
||||||
|
) :
|
||||||
|
RecyclerView.Adapter<AttachmentAdapter.AttachmentViewHolder>() {
|
||||||
|
private lateinit var context: Context
|
||||||
|
|
||||||
|
inner class AttachmentViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||||
|
var title: TextView = view.attachment_title_textview
|
||||||
|
var viewButton: ImageButton = view.attachment_view_button
|
||||||
|
var downloadButton: ImageButton = view.attachment_download_button
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AttachmentViewHolder {
|
||||||
|
val itemView = LayoutInflater.from(parent.context)
|
||||||
|
.inflate(R.layout.item_attachment, parent, false)
|
||||||
|
context = parent.context
|
||||||
|
|
||||||
|
return AttachmentViewHolder(itemView)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: AttachmentViewHolder, position: Int) {
|
||||||
|
holder.title.text = attachmentsNames[position]
|
||||||
|
|
||||||
|
holder.viewButton.setOnClickListener {
|
||||||
|
val viewIntent = Intent(Intent.ACTION_VIEW)
|
||||||
|
viewIntent.setDataAndType(Uri.parse(attachmentsUrls[position]), "application/pdf")
|
||||||
|
context.startActivity(viewIntent)
|
||||||
|
}
|
||||||
|
|
||||||
|
holder.downloadButton.setOnClickListener {
|
||||||
|
val request = DownloadManager.Request(Uri.parse(attachmentsUrls[position]))
|
||||||
|
request.setTitle(attachmentsNames[position])
|
||||||
|
request.setDestinationInExternalPublicDir(
|
||||||
|
Environment.DIRECTORY_DOWNLOADS,
|
||||||
|
"Circolapp/" + attachmentsNames[position] + ".pdf"
|
||||||
|
)
|
||||||
|
|
||||||
|
(context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager).enqueue(request)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getItemCount() = attachmentsNames.size
|
||||||
|
}
|
||||||
@@ -28,6 +28,7 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.ImageButton
|
import android.widget.ImageButton
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import kotlinx.android.synthetic.main.item_circular.view.*
|
import kotlinx.android.synthetic.main.item_circular.view.*
|
||||||
import net.underdesk.circolapp.R
|
import net.underdesk.circolapp.R
|
||||||
@@ -46,6 +47,7 @@ class CircularLetterAdapter(private val circulars: List<Circular>) :
|
|||||||
var downloadButton: ImageButton = view.circular_download_button
|
var downloadButton: ImageButton = view.circular_download_button
|
||||||
var favouriteButton: ImageButton = view.circular_favourite_button
|
var favouriteButton: ImageButton = view.circular_favourite_button
|
||||||
var reminderButton: ImageButton = view.circular_reminder_button
|
var reminderButton: ImageButton = view.circular_reminder_button
|
||||||
|
var attachmentsList: RecyclerView = view.circulars_attachments_list
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CircularLetterViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CircularLetterViewHolder {
|
||||||
@@ -77,6 +79,18 @@ class CircularLetterAdapter(private val circulars: List<Circular>) :
|
|||||||
|
|
||||||
(context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager).enqueue(request)
|
(context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager).enqueue(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (circulars[position].attachmentsNames.isNotEmpty()) {
|
||||||
|
holder.attachmentsList.visibility = View.VISIBLE
|
||||||
|
holder.attachmentsList.layoutManager = LinearLayoutManager(context)
|
||||||
|
holder.attachmentsList.adapter = AttachmentAdapter(
|
||||||
|
circulars[position].attachmentsNames,
|
||||||
|
circulars[position].attachmentsUrls
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
holder.attachmentsList.visibility = View.GONE
|
||||||
|
holder.attachmentsList.adapter = null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemCount() = circulars.size
|
override fun getItemCount() = circulars.size
|
||||||
|
|||||||
51
app/src/main/res/layout/item_attachment.xml
Normal file
51
app/src/main/res/layout/item_attachment.xml
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:id="@+id/linearLayout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/attachment_divider"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:background="@color/colorDivider"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/attachment_title_textview"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@+id/attachment_view_button"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/attachment_view_button"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="@+id/attachment_view_button" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/attachment_view_button"
|
||||||
|
style="?borderlessButtonStyle"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="4dp"
|
||||||
|
android:adjustViewBounds="true"
|
||||||
|
android:scaleType="centerInside"
|
||||||
|
android:src="@drawable/baseline_visibility_24"
|
||||||
|
android:tint="@color/colorAccent"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/attachment_download_button"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/attachment_divider" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/attachment_download_button"
|
||||||
|
style="?borderlessButtonStyle"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="4dp"
|
||||||
|
android:adjustViewBounds="true"
|
||||||
|
android:src="@drawable/baseline_get_app_24"
|
||||||
|
android:tint="@color/colorAccent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/attachment_divider" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@@ -51,7 +51,8 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="8dp"
|
android:layout_marginStart="8dp"
|
||||||
android:src="@drawable/baseline_visibility_24"
|
android:src="@drawable/baseline_visibility_24"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
android:tint="@color/colorAccent"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/circulars_attachments_list"
|
||||||
app:layout_constraintStart_toStartOf="parent" />
|
app:layout_constraintStart_toStartOf="parent" />
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
@@ -61,7 +62,8 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:src="@drawable/baseline_get_app_24"
|
android:src="@drawable/baseline_get_app_24"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
android:tint="@color/colorAccent"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/circulars_attachments_list"
|
||||||
app:layout_constraintEnd_toStartOf="@+id/circular_guideline"
|
app:layout_constraintEnd_toStartOf="@+id/circular_guideline"
|
||||||
app:layout_constraintStart_toEndOf="@+id/circular_view_button" />
|
app:layout_constraintStart_toEndOf="@+id/circular_view_button" />
|
||||||
|
|
||||||
@@ -71,7 +73,8 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:src="@drawable/baseline_star_24"
|
android:src="@drawable/baseline_star_24"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
android:tint="@color/colorAccent"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/circulars_attachments_list"
|
||||||
app:layout_constraintEnd_toStartOf="@+id/circular_reminder_button"
|
app:layout_constraintEnd_toStartOf="@+id/circular_reminder_button"
|
||||||
app:layout_constraintStart_toStartOf="@+id/circular_guideline" />
|
app:layout_constraintStart_toStartOf="@+id/circular_guideline" />
|
||||||
|
|
||||||
@@ -82,9 +85,22 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginEnd="8dp"
|
android:layout_marginEnd="8dp"
|
||||||
android:src="@drawable/baseline_notifications_24"
|
android:src="@drawable/baseline_notifications_24"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
android:tint="@color/colorAccent"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/circulars_attachments_list"
|
||||||
app:layout_constraintEnd_toEndOf="parent" />
|
app:layout_constraintEnd_toEndOf="parent" />
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/circulars_attachments_list"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:layout_marginBottom="4dp"
|
||||||
|
android:nestedScrollingEnabled="false"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent" />
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.Guideline
|
<androidx.constraintlayout.widget.Guideline
|
||||||
android:id="@+id/circular_guideline"
|
android:id="@+id/circular_guideline"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|||||||
@@ -3,4 +3,5 @@
|
|||||||
<color name="colorPrimary">#008577</color>
|
<color name="colorPrimary">#008577</color>
|
||||||
<color name="colorPrimaryDark">#00574B</color>
|
<color name="colorPrimaryDark">#00574B</color>
|
||||||
<color name="colorAccent">#D81B60</color>
|
<color name="colorAccent">#D81B60</color>
|
||||||
|
<color name="colorDivider">#BDBDBD</color>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user