parent
18bfe8c97a
commit
d6aeeb2dec
@ -0,0 +1,96 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
package org.mozilla.fenix.downloads
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.graphics.drawable.ColorDrawable
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||||
|
import kotlinx.android.synthetic.main.download_notification_layout.*
|
||||||
|
import mozilla.components.browser.state.state.content.DownloadState
|
||||||
|
import mozilla.components.feature.downloads.AbstractFetchDownloadService
|
||||||
|
import mozilla.components.feature.downloads.toMegabyteString
|
||||||
|
import org.mozilla.fenix.R
|
||||||
|
import org.mozilla.fenix.theme.ThemeManager
|
||||||
|
|
||||||
|
class DownloadNotificationBottomSheetDialog(
|
||||||
|
context: Context,
|
||||||
|
private val download: DownloadState,
|
||||||
|
private val didFail: Boolean,
|
||||||
|
private val tryAgain: (Long) -> Unit
|
||||||
|
// We must pass in the BottomSheetDialog theme for the transparent window background to apply properly
|
||||||
|
) : BottomSheetDialog(context, R.style.Theme_MaterialComponents_BottomSheetDialog) {
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
setContentView(R.layout.download_notification_layout)
|
||||||
|
|
||||||
|
if (didFail) {
|
||||||
|
download_notification_title.text =
|
||||||
|
context.getString(R.string.mozac_feature_downloads_failed_notification_text2)
|
||||||
|
|
||||||
|
download_notification_icon.setImageDrawable(context.getDrawable(
|
||||||
|
mozilla.components.feature.downloads.R.drawable.mozac_feature_download_ic_download_failed
|
||||||
|
))
|
||||||
|
|
||||||
|
download_notification_action_button.apply {
|
||||||
|
text = context.getString(
|
||||||
|
mozilla.components.feature.downloads.R.string.mozac_feature_downloads_button_try_again
|
||||||
|
)
|
||||||
|
setOnClickListener {
|
||||||
|
tryAgain(download.id)
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
val titleText = context.getString(
|
||||||
|
R.string.mozac_feature_downloads_completed_notification_text2
|
||||||
|
) + " (${download.contentLength?.toMegabyteString()})"
|
||||||
|
|
||||||
|
download_notification_title.text = titleText
|
||||||
|
|
||||||
|
download_notification_icon.setImageDrawable(context.getDrawable(
|
||||||
|
mozilla.components.feature.downloads.R.drawable.mozac_feature_download_ic_download_complete
|
||||||
|
))
|
||||||
|
|
||||||
|
download_notification_action_button.apply {
|
||||||
|
text = context.getString(
|
||||||
|
mozilla.components.feature.downloads.R.string.mozac_feature_downloads_button_open
|
||||||
|
)
|
||||||
|
setOnClickListener {
|
||||||
|
AbstractFetchDownloadService.openFile(
|
||||||
|
context = context,
|
||||||
|
contentType = download.contentType,
|
||||||
|
filePath = download.filePath
|
||||||
|
)
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
download_notification_close_button.setOnClickListener {
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
|
||||||
|
download_notification_filename.text = download.fileName
|
||||||
|
|
||||||
|
setOnShowListener {
|
||||||
|
window?.apply {
|
||||||
|
// setBackgroundDrawableResource(android.R.color.transparent)
|
||||||
|
setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
|
||||||
|
setLayout(
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
|
)
|
||||||
|
navigationBarColor = ContextCompat.getColor(
|
||||||
|
context,
|
||||||
|
ThemeManager.resolveAttribute(R.attr.foundation, context
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,91 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingBottom="16dp"
|
||||||
|
android:background="?foundation">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/download_notification_icon"
|
||||||
|
android:layout_width="32dp"
|
||||||
|
android:layout_height="32dp"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:scaleType="center"
|
||||||
|
app:srcCompat="@drawable/mozac_feature_download_ic_download_complete"
|
||||||
|
android:importantForAccessibility="no"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
android:tint="?primaryText"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/download_notification_title"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="11dp"
|
||||||
|
android:layout_marginStart="3dp"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:textColor="?primaryText"
|
||||||
|
android:paddingTop="4dp"
|
||||||
|
android:paddingStart="5dp"
|
||||||
|
android:paddingEnd="5dp"
|
||||||
|
android:layout_alignParentTop="true"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintHorizontal_bias="0.0"
|
||||||
|
app:layout_constraintEnd_toStartOf="@id/download_notification_close_button"
|
||||||
|
app:layout_constraintStart_toEndOf="@id/download_notification_icon"
|
||||||
|
tools:text="Download (85.7 MB)"/>
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/download_notification_close_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="12dp"
|
||||||
|
android:layout_marginStart="3dp"
|
||||||
|
android:contentDescription="@string/mozac_feature_downloads_button_close"
|
||||||
|
android:background="@null"
|
||||||
|
android:tint="?primaryText"
|
||||||
|
app:srcCompat="@drawable/mozac_ic_close"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
android:layout_marginTop="16dp"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/download_notification_filename"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="3dp"
|
||||||
|
android:textColor="?primaryText"
|
||||||
|
android:paddingTop="4dp"
|
||||||
|
android:paddingStart="5dp"
|
||||||
|
android:paddingEnd="5dp"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/download_notification_title"
|
||||||
|
app:layout_constraintStart_toEndOf="@id/download_notification_icon"
|
||||||
|
tools:text="Firefox_Preview_v2.1.apk"/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/download_notification_action_button"
|
||||||
|
android:textColor="?contrastText"
|
||||||
|
android:backgroundTint="?accentBright"
|
||||||
|
android:background="@drawable/rounded_all_corners"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/download_notification_filename"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:layout_marginBottom="4dp"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:textAllCaps="false"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/mozac_feature_downloads_button_open"/>
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Reference in New Issue