mirror of
https://github.com/Matte23/circolapp.git
synced 2025-12-05 23:19:10 +00:00
Add share button for Android
This commit is contained in:
@@ -39,6 +39,7 @@ class AttachmentAdapter(
|
||||
inner class AttachmentViewHolder(binding: ItemAttachmentBinding) : RecyclerView.ViewHolder(binding.root) {
|
||||
var title: TextView = binding.attachmentTitleTextview
|
||||
var viewButton: ImageButton = binding.attachmentViewButton
|
||||
var shareButton: ImageButton = binding.attachmentShareButton
|
||||
var downloadButton: ImageButton = binding.attachmentDownloadButton
|
||||
}
|
||||
|
||||
@@ -56,6 +57,10 @@ class AttachmentAdapter(
|
||||
FileUtils.viewFile(attachmentsUrls[position], context)
|
||||
}
|
||||
|
||||
holder.shareButton.setOnClickListener {
|
||||
FileUtils.shareFile(attachmentsUrls[position], context)
|
||||
}
|
||||
|
||||
holder.downloadButton.setOnClickListener {
|
||||
val file = DownloadableFile(attachmentsNames[position], attachmentsUrls[position])
|
||||
FileUtils.downloadFile(file, adapterCallback, context)
|
||||
|
||||
@@ -62,6 +62,7 @@ class CircularLetterAdapter(
|
||||
var date: TextView = binding.circularDateTextview
|
||||
var collapseButton: ImageButton = binding.circularCollapseButton
|
||||
var viewButton: ImageButton = binding.circularViewButton
|
||||
var shareButton: ImageButton = binding.circularShareButton
|
||||
var downloadButton: ImageButton = binding.circularDownloadButton
|
||||
var favouriteButton: ImageButton = binding.circularFavouriteButton
|
||||
var reminderButton: ImageButton = binding.circularReminderButton
|
||||
@@ -118,6 +119,7 @@ class CircularLetterAdapter(
|
||||
holder.collapseButton.contentDescription = context.getString(R.string.image_expand)
|
||||
|
||||
holder.viewButton.visibility = View.GONE
|
||||
holder.shareButton.visibility = View.GONE
|
||||
holder.downloadButton.visibility = View.GONE
|
||||
holder.favouriteButton.visibility = View.GONE
|
||||
holder.reminderButton.visibility = View.GONE
|
||||
@@ -134,6 +136,7 @@ class CircularLetterAdapter(
|
||||
holder.collapseButton.contentDescription = context.getString(R.string.image_collapse)
|
||||
|
||||
holder.viewButton.visibility = View.VISIBLE
|
||||
holder.shareButton.visibility = View.VISIBLE
|
||||
holder.downloadButton.visibility = View.VISIBLE
|
||||
holder.favouriteButton.visibility = View.VISIBLE
|
||||
holder.reminderButton.visibility = View.VISIBLE
|
||||
@@ -154,6 +157,10 @@ class CircularLetterAdapter(
|
||||
FileUtils.viewFile(circulars[position].url, context)
|
||||
}
|
||||
|
||||
holder.shareButton.setOnClickListener {
|
||||
FileUtils.shareFile(circulars[position].url, context)
|
||||
}
|
||||
|
||||
holder.downloadButton.setOnClickListener {
|
||||
val file = DownloadableFile(circulars[position].name, circulars[position].url)
|
||||
FileUtils.downloadFile(file, adapterCallback, context)
|
||||
|
||||
@@ -43,6 +43,17 @@ object FileUtils {
|
||||
context.startActivity(viewIntent)
|
||||
}
|
||||
|
||||
fun shareFile(url: String, context: Context) {
|
||||
val sendIntent: Intent = Intent().apply {
|
||||
action = Intent.ACTION_SEND
|
||||
putExtra(Intent.EXTRA_TEXT, url)
|
||||
type = "text/plain"
|
||||
}
|
||||
|
||||
val shareIntent = Intent.createChooser(sendIntent, null)
|
||||
context.startActivity(shareIntent)
|
||||
}
|
||||
|
||||
fun downloadFile(
|
||||
file: DownloadableFile,
|
||||
adapterCallback: CircularLetterAdapter.AdapterCallback,
|
||||
|
||||
10
app/src/main/res/drawable/baseline_share_24.xml
Normal file
10
app/src/main/res/drawable/baseline_share_24.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z" />
|
||||
</vector>
|
||||
@@ -35,6 +35,19 @@
|
||||
android:src="@drawable/baseline_visibility_24"
|
||||
android:tint="@color/colorSecondary"
|
||||
android:contentDescription="@string/image_view_attachment"
|
||||
app:layout_constraintEnd_toStartOf="@+id/attachment_share_button"
|
||||
app:layout_constraintTop_toTopOf="@+id/attachment_title_textview"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/attachment_title_textview" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/attachment_share_button"
|
||||
style="?borderlessButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:adjustViewBounds="true"
|
||||
android:src="@drawable/baseline_share_24"
|
||||
android:tint="@color/colorSecondary"
|
||||
android:contentDescription="@string/image_share_attachment"
|
||||
app:layout_constraintEnd_toStartOf="@+id/attachment_download_button"
|
||||
app:layout_constraintTop_toTopOf="@+id/attachment_title_textview"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/attachment_title_textview" />
|
||||
|
||||
@@ -62,55 +62,71 @@
|
||||
<ImageButton
|
||||
android:id="@+id/circular_view_button"
|
||||
style="?android:attr/borderlessButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:contentDescription="@string/image_view_circular"
|
||||
android:src="@drawable/baseline_visibility_24"
|
||||
android:tint="@color/colorSecondary"
|
||||
android:contentDescription="@string/image_view_circular"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toTopOf="@+id/circulars_attachments_list"
|
||||
app:layout_constraintEnd_toStartOf="@+id/circular_share_button"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/circular_share_button"
|
||||
style="?android:attr/borderlessButtonStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/image_share_circular"
|
||||
android:gravity="center"
|
||||
android:src="@drawable/baseline_share_24"
|
||||
android:tint="@color/colorSecondary"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toTopOf="@+id/circulars_attachments_list"
|
||||
app:layout_constraintEnd_toStartOf="@+id/circular_download_button"
|
||||
app:layout_constraintStart_toEndOf="@+id/circular_view_button" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/circular_download_button"
|
||||
style="?android:attr/borderlessButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/image_download_circular"
|
||||
android:gravity="center"
|
||||
android:src="@drawable/baseline_get_app_24"
|
||||
android:tint="@color/colorSecondary"
|
||||
android:contentDescription="@string/image_download_circular"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toTopOf="@+id/circulars_attachments_list"
|
||||
app:layout_constraintEnd_toStartOf="@+id/circular_guideline"
|
||||
app:layout_constraintStart_toEndOf="@+id/circular_view_button" />
|
||||
app:layout_constraintEnd_toStartOf="@+id/circular_favourite_button"
|
||||
app:layout_constraintStart_toEndOf="@+id/circular_share_button" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/circular_favourite_button"
|
||||
style="?android:attr/borderlessButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/image_add_favourite"
|
||||
android:src="@drawable/baseline_star_24"
|
||||
android:tint="@color/colorSecondary"
|
||||
android:contentDescription="@string/image_add_favourite"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toTopOf="@+id/circulars_attachments_list"
|
||||
app:layout_constraintEnd_toStartOf="@+id/circular_reminder_button"
|
||||
app:layout_constraintStart_toStartOf="@+id/circular_guideline" />
|
||||
app:layout_constraintStart_toEndOf="@+id/circular_download_button" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/circular_reminder_button"
|
||||
style="?android:attr/borderlessButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:contentDescription="@string/image_add_reminder"
|
||||
android:src="@drawable/baseline_notifications_24"
|
||||
android:tint="@color/colorSecondary"
|
||||
android:contentDescription="@string/image_add_reminder"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toTopOf="@+id/circulars_attachments_list"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/circular_favourite_button" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/circulars_attachments_list"
|
||||
@@ -125,13 +141,6 @@
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<androidx.constraintlayout.widget.Guideline
|
||||
android:id="@+id/circular_guideline"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintGuide_percent="0.5" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
@@ -78,8 +78,10 @@
|
||||
<string name="snackbar_connection_not_available">Rete non disponibile. I risultati potrebbero non essere aggiornati</string>
|
||||
|
||||
<string name="image_view_attachment">Visualizza allegato</string>
|
||||
<string name="image_share_attachment">Condividi allegato</string>
|
||||
<string name="image_download_attachment">Scarica allegato</string>
|
||||
<string name="image_view_circular">Visualizza circolare</string>
|
||||
<string name="image_share_circular">Condividi circolare</string>
|
||||
<string name="image_download_circular">Scarica circolare</string>
|
||||
<string name="image_add_favourite">Aggiungi ai preferiti</string>
|
||||
<string name="image_add_reminder">Aggiungi promemoria</string>
|
||||
|
||||
@@ -79,8 +79,10 @@
|
||||
<string name="snackbar_connection_not_available">Network not available. Results may be outdated</string>
|
||||
|
||||
<string name="image_view_attachment">View attachment</string>
|
||||
<string name="image_share_attachment">Share attachment</string>
|
||||
<string name="image_download_attachment">Download attachment</string>
|
||||
<string name="image_view_circular">View circular</string>
|
||||
<string name="image_share_circular">Share circular</string>
|
||||
<string name="image_download_circular">Download circular</string>
|
||||
<string name="image_add_favourite">Add to favourites</string>
|
||||
<string name="image_add_reminder">Add reminder</string>
|
||||
|
||||
Reference in New Issue
Block a user