mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-08 06:42:21 -04:00
Removed explicit backPressed handling and added an action to downloads from reader
This commit is contained in:
parent
526b011162
commit
6f7d35c303
@ -24,5 +24,4 @@ sealed class Action {
|
||||
data class DatabaseEmission(val downloads: List<DownloadItem>) : Action()
|
||||
object ClickedDownload : Action()
|
||||
object ClickedRetry : Action()
|
||||
object PressedBack : Action()
|
||||
}
|
||||
|
@ -22,10 +22,8 @@ import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import kotlinx.android.synthetic.main.fragment_custom_download.cd_view_animator
|
||||
import kotlinx.android.synthetic.main.layout_custom_download_error.cd_error_text
|
||||
@ -45,15 +43,12 @@ import org.kiwix.kiwixmobile.custom.R
|
||||
import org.kiwix.kiwixmobile.custom.customActivityComponent
|
||||
import org.kiwix.kiwixmobile.custom.download.Action.ClickedDownload
|
||||
import org.kiwix.kiwixmobile.custom.download.Action.ClickedRetry
|
||||
import org.kiwix.kiwixmobile.custom.download.Action.PressedBack
|
||||
import org.kiwix.kiwixmobile.custom.download.State.DownloadComplete
|
||||
import org.kiwix.kiwixmobile.custom.download.State.DownloadFailed
|
||||
import org.kiwix.kiwixmobile.custom.download.State.DownloadInProgress
|
||||
import org.kiwix.kiwixmobile.custom.download.State.DownloadRequired
|
||||
import javax.inject.Inject
|
||||
|
||||
var pressBackCallback = 0
|
||||
|
||||
class CustomDownloadFragment : BaseFragment(), FragmentActivityExtensions {
|
||||
|
||||
private val downloadViewModel by lazy {
|
||||
@ -96,14 +91,6 @@ class CustomDownloadFragment : BaseFragment(), FragmentActivityExtensions {
|
||||
compositeDisposable.clear()
|
||||
}
|
||||
|
||||
override fun onBackPressed(activity: AppCompatActivity): FragmentActivityExtensions.Super {
|
||||
pressBackCallback = 1
|
||||
downloadViewModel.actions.offer(PressedBack)
|
||||
// findNavController().popBackStack()
|
||||
// findNavController().navigate(R.id.customReaderFragment)
|
||||
return super.onBackPressed(activity)
|
||||
}
|
||||
|
||||
private fun render(state: State) {
|
||||
return when (state) {
|
||||
DownloadRequired -> cd_view_animator.setDistinctDisplayedChild(0)
|
||||
|
@ -29,7 +29,6 @@ import org.kiwix.kiwixmobile.core.downloader.model.DownloadState.Failed
|
||||
import org.kiwix.kiwixmobile.custom.download.Action.ClickedDownload
|
||||
import org.kiwix.kiwixmobile.custom.download.Action.ClickedRetry
|
||||
import org.kiwix.kiwixmobile.custom.download.Action.DatabaseEmission
|
||||
import org.kiwix.kiwixmobile.custom.download.Action.PressedBack
|
||||
import org.kiwix.kiwixmobile.custom.download.State.DownloadComplete
|
||||
import org.kiwix.kiwixmobile.custom.download.State.DownloadFailed
|
||||
import org.kiwix.kiwixmobile.custom.download.State.DownloadInProgress
|
||||
@ -77,7 +76,7 @@ class CustomDownloadViewModel @Inject constructor(
|
||||
is DatabaseEmission -> reduceDatabaseEmission(state, action)
|
||||
ClickedRetry,
|
||||
ClickedDownload -> state.also { _effects.offer(downloadCustom) }
|
||||
is PressedBack -> state.also { _effects.offer(finishAndStartMain) }
|
||||
// is PressedBack -> state.also { _effects.offer(finishAndStartMain) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,23 +19,14 @@
|
||||
package org.kiwix.kiwixmobile.custom.download.effects
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.navigation.findNavController
|
||||
import org.kiwix.kiwixmobile.core.base.SideEffect
|
||||
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.start
|
||||
import org.kiwix.kiwixmobile.custom.R
|
||||
import org.kiwix.kiwixmobile.custom.download.pressBackCallback
|
||||
import org.kiwix.kiwixmobile.custom.main.CustomMainActivity
|
||||
import javax.inject.Inject
|
||||
|
||||
class FinishAndStartMain @Inject constructor() : SideEffect<Unit> {
|
||||
override fun invokeWith(activity: AppCompatActivity) {
|
||||
if (pressBackCallback == 1) {
|
||||
activity.findNavController(R.id.customDownloadFragment)
|
||||
.navigate(R.id.action_customDownload_to_customReader)
|
||||
activity.onBackPressed()
|
||||
} else {
|
||||
activity.finish()
|
||||
activity.start<CustomMainActivity>()
|
||||
}
|
||||
activity.finish()
|
||||
activity.start<CustomMainActivity>()
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ import org.kiwix.kiwixmobile.core.utils.urlSuffixToParsableUrl
|
||||
import org.kiwix.kiwixmobile.custom.BuildConfig
|
||||
import org.kiwix.kiwixmobile.custom.R
|
||||
import org.kiwix.kiwixmobile.custom.customActivityComponent
|
||||
import org.kiwix.kiwixmobile.custom.download.pressBackCallback
|
||||
import org.kiwix.kiwixmobile.custom.main.CustomReaderFragmentDirections.actionCustomReaderToCustomDownload
|
||||
import java.util.Locale
|
||||
import javax.inject.Inject
|
||||
|
||||
@ -154,12 +154,8 @@ class CustomReaderFragment : CoreReaderFragment() {
|
||||
) == PERMISSION_DENIED
|
||||
) {
|
||||
requestPermissions(arrayOf(READ_EXTERNAL_STORAGE), REQUEST_READ_FOR_OBB)
|
||||
}
|
||||
if (pressBackCallback == 1) {
|
||||
findNavController().navigateUp()
|
||||
}
|
||||
else {
|
||||
findNavController().navigate(R.id.customDownloadFragment)
|
||||
} else {
|
||||
findNavController().navigate(actionCustomReaderToCustomDownload())
|
||||
}
|
||||
}
|
||||
)
|
||||
|
@ -24,6 +24,12 @@
|
||||
android:id="@+id/customReaderFragment"
|
||||
android:name="org.kiwix.kiwixmobile.custom.main.CustomReaderFragment"
|
||||
android:label="CustomReaderFragment">
|
||||
<action
|
||||
android:id="@+id/action_customReader_to_customDownload"
|
||||
app:destination="@id/customDownloadFragment"
|
||||
app:popUpTo="@id/customDownloadFragment"
|
||||
app:popUpToInclusive="true" />
|
||||
|
||||
<argument
|
||||
android:name="pageUrl"
|
||||
android:defaultValue=""
|
||||
@ -61,7 +67,7 @@
|
||||
android:id="@+id/action_customDownload_to_customReader"
|
||||
app:destination="@id/customReaderFragment"
|
||||
app:popUpTo="@+id/customReaderFragment"
|
||||
app:popUpToInclusive="true"/>
|
||||
app:popUpToInclusive="true" />
|
||||
|
||||
</fragment>
|
||||
<fragment
|
||||
|
Loading…
x
Reference in New Issue
Block a user