DownloadMenuSheet: Migrate to navigation components
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -19,9 +19,12 @@
|
|||||||
|
|
||||||
package com.aurora.store.data.model
|
package com.aurora.store.data.model
|
||||||
|
|
||||||
|
import android.os.Parcelable
|
||||||
import com.tonyodev.fetch2.Download
|
import com.tonyodev.fetch2.Download
|
||||||
|
import kotlinx.parcelize.Parcelize
|
||||||
|
|
||||||
data class DownloadFile(val download: Download) {
|
@Parcelize
|
||||||
|
data class DownloadFile(val download: Download) : Parcelable {
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int {
|
||||||
return download.id
|
return download.id
|
||||||
@@ -33,4 +36,4 @@ data class DownloadFile(val download: Download) {
|
|||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,6 @@ import com.aurora.store.util.Preferences
|
|||||||
import com.aurora.store.view.epoxy.views.DownloadViewModel_
|
import com.aurora.store.view.epoxy.views.DownloadViewModel_
|
||||||
import com.aurora.store.view.epoxy.views.app.NoAppViewModel_
|
import com.aurora.store.view.epoxy.views.app.NoAppViewModel_
|
||||||
import com.aurora.store.view.ui.commons.BaseFragment
|
import com.aurora.store.view.ui.commons.BaseFragment
|
||||||
import com.aurora.store.view.ui.sheets.DownloadMenuSheet
|
|
||||||
import com.tonyodev.fetch2.AbstractFetchListener
|
import com.tonyodev.fetch2.AbstractFetchListener
|
||||||
import com.tonyodev.fetch2.BuildConfig
|
import com.tonyodev.fetch2.BuildConfig
|
||||||
import com.tonyodev.fetch2.Download
|
import com.tonyodev.fetch2.Download
|
||||||
@@ -208,21 +207,8 @@ class DownloadFragment : BaseFragment(R.layout.fragment_download) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun openDownloadMenuSheet(downloadFile: DownloadFile) {
|
private fun openDownloadMenuSheet(downloadFile: DownloadFile) {
|
||||||
with(downloadFile) {
|
findNavController().navigate(
|
||||||
val fragment = childFragmentManager.findFragmentByTag(DownloadMenuSheet.TAG)
|
DownloadFragmentDirections.actionDownloadFragmentToDownloadMenuSheet(downloadFile)
|
||||||
if (fragment != null)
|
)
|
||||||
childFragmentManager.beginTransaction().remove(fragment).commitAllowingStateLoss()
|
|
||||||
|
|
||||||
DownloadMenuSheet().apply {
|
|
||||||
arguments = Bundle().apply {
|
|
||||||
putInt(DownloadMenuSheet.DOWNLOAD_ID, download.id)
|
|
||||||
putInt(DownloadMenuSheet.DOWNLOAD_STATUS, download.status.value)
|
|
||||||
putString(DownloadMenuSheet.DOWNLOAD_URL, download.url)
|
|
||||||
}
|
|
||||||
}.show(
|
|
||||||
childFragmentManager,
|
|
||||||
DownloadMenuSheet.TAG
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import android.os.Bundle
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.navigation.fragment.navArgs
|
||||||
import com.aurora.store.R
|
import com.aurora.store.R
|
||||||
import com.aurora.store.data.downloader.DownloadManager
|
import com.aurora.store.data.downloader.DownloadManager
|
||||||
import com.aurora.store.databinding.SheetDownloadMenuBinding
|
import com.aurora.store.databinding.SheetDownloadMenuBinding
|
||||||
@@ -30,16 +31,15 @@ import com.aurora.extensions.copyToClipBoard
|
|||||||
import com.aurora.extensions.toast
|
import com.aurora.extensions.toast
|
||||||
import com.tonyodev.fetch2.Fetch
|
import com.tonyodev.fetch2.Fetch
|
||||||
import com.tonyodev.fetch2.Status
|
import com.tonyodev.fetch2.Status
|
||||||
|
import kotlin.properties.Delegates
|
||||||
|
|
||||||
class DownloadMenuSheet : BaseBottomSheet() {
|
class DownloadMenuSheet : BaseBottomSheet() {
|
||||||
|
|
||||||
private lateinit var B: SheetDownloadMenuBinding
|
private lateinit var B: SheetDownloadMenuBinding
|
||||||
private lateinit var fetch: Fetch
|
private lateinit var fetch: Fetch
|
||||||
|
|
||||||
private var downloadId = 0
|
private val args: DownloadMenuSheetArgs by navArgs()
|
||||||
private var status = 0
|
private var status by Delegates.notNull<Int>()
|
||||||
private var url: String? = null
|
|
||||||
|
|
||||||
|
|
||||||
override fun onCreateContentView(
|
override fun onCreateContentView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
@@ -57,19 +57,8 @@ class DownloadMenuSheet : BaseBottomSheet() {
|
|||||||
.with(requireContext())
|
.with(requireContext())
|
||||||
.getFetchInstance()
|
.getFetchInstance()
|
||||||
|
|
||||||
if (arguments != null) {
|
status = args.downloadFile.download.status.value
|
||||||
val bundle = arguments
|
attachNavigation()
|
||||||
if (bundle != null) {
|
|
||||||
downloadId = bundle.getInt(DOWNLOAD_ID)
|
|
||||||
status = bundle.getInt(DOWNLOAD_STATUS)
|
|
||||||
url = bundle.getString(DOWNLOAD_URL)
|
|
||||||
attachNavigation()
|
|
||||||
} else {
|
|
||||||
dismissAllowingStateLoss()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
dismissAllowingStateLoss()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun attachNavigation() {
|
private fun attachNavigation() {
|
||||||
@@ -89,22 +78,22 @@ class DownloadMenuSheet : BaseBottomSheet() {
|
|||||||
setNavigationItemSelectedListener { item ->
|
setNavigationItemSelectedListener { item ->
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.action_copy -> {
|
R.id.action_copy -> {
|
||||||
requireContext().copyToClipBoard(url)
|
requireContext().copyToClipBoard(args.downloadFile.download.url)
|
||||||
requireContext().toast(requireContext().getString(R.string.toast_clipboard_copied))
|
requireContext().toast(requireContext().getString(R.string.toast_clipboard_copied))
|
||||||
}
|
}
|
||||||
R.id.action_pause -> {
|
R.id.action_pause -> {
|
||||||
fetch.pause(downloadId)
|
fetch.pause(args.downloadFile.download.id)
|
||||||
}
|
}
|
||||||
R.id.action_resume -> if (status == Status.FAILED.value || status == Status.CANCELLED.value) {
|
R.id.action_resume -> if (status == Status.FAILED.value || status == Status.CANCELLED.value) {
|
||||||
fetch.retry(downloadId)
|
fetch.retry(args.downloadFile.download.id)
|
||||||
} else {
|
} else {
|
||||||
fetch.resume(downloadId)
|
fetch.resume(args.downloadFile.download.id)
|
||||||
}
|
}
|
||||||
R.id.action_cancel -> {
|
R.id.action_cancel -> {
|
||||||
fetch.cancel(downloadId)
|
fetch.cancel(args.downloadFile.download.id)
|
||||||
}
|
}
|
||||||
R.id.action_clear -> {
|
R.id.action_clear -> {
|
||||||
fetch.delete(downloadId)
|
fetch.delete(args.downloadFile.download.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dismissAllowingStateLoss()
|
dismissAllowingStateLoss()
|
||||||
@@ -112,11 +101,4 @@ class DownloadMenuSheet : BaseBottomSheet() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
companion object {
|
|
||||||
const val TAG = "DOWNLOAD_MENU_SHEET"
|
|
||||||
const val DOWNLOAD_ID = "DOWNLOAD_ID"
|
|
||||||
const val DOWNLOAD_STATUS = "DOWNLOAD_STATUS"
|
|
||||||
const val DOWNLOAD_URL = "DOWNLOAD_URL"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -158,7 +158,11 @@
|
|||||||
android:id="@+id/downloadFragment"
|
android:id="@+id/downloadFragment"
|
||||||
android:name="com.aurora.store.view.ui.downloads.DownloadFragment"
|
android:name="com.aurora.store.view.ui.downloads.DownloadFragment"
|
||||||
android:label="@string/title_download_manager"
|
android:label="@string/title_download_manager"
|
||||||
tools:layout="@layout/fragment_download" />
|
tools:layout="@layout/fragment_download" >
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_downloadFragment_to_downloadMenuSheet"
|
||||||
|
app:destination="@id/downloadMenuSheet" />
|
||||||
|
</fragment>
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/appDetailsFragment"
|
android:id="@+id/appDetailsFragment"
|
||||||
android:name="com.aurora.store.view.ui.details.AppDetailsFragment"
|
android:name="com.aurora.store.view.ui.details.AppDetailsFragment"
|
||||||
@@ -392,4 +396,13 @@
|
|||||||
android:name="app"
|
android:name="app"
|
||||||
app:argType="com.aurora.gplayapi.data.models.App" />
|
app:argType="com.aurora.gplayapi.data.models.App" />
|
||||||
</dialog>
|
</dialog>
|
||||||
|
<dialog
|
||||||
|
android:id="@+id/downloadMenuSheet"
|
||||||
|
android:name="com.aurora.store.view.ui.sheets.DownloadMenuSheet"
|
||||||
|
android:label="DownloadMenuSheet"
|
||||||
|
tools:layout="@layout/sheet_download_menu">
|
||||||
|
<argument
|
||||||
|
android:name="downloadFile"
|
||||||
|
app:argType="com.aurora.store.data.model.DownloadFile" />
|
||||||
|
</dialog>
|
||||||
</navigation>
|
</navigation>
|
||||||
|
|||||||
Reference in New Issue
Block a user