mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-12 21:42:49 +01:00
Downloads with conductor. Remove flexible adapter 4 dependency and unused classes.
This commit is contained in:
parent
f521622d4d
commit
72ea256906
@ -100,17 +100,6 @@ android {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
||||||
compile "com.bluelinelabs:conductor:2.1.3"
|
|
||||||
compile 'com.github.inorichi:conductor-support-preference:master-SNAPSHOT'
|
|
||||||
|
|
||||||
final rxbindings_version = '1.0.1'
|
|
||||||
compile "com.jakewharton.rxbinding:rxbinding-kotlin:$rxbindings_version"
|
|
||||||
compile "com.jakewharton.rxbinding:rxbinding-appcompat-v7-kotlin:$rxbindings_version"
|
|
||||||
compile "com.jakewharton.rxbinding:rxbinding-support-v4-kotlin:$rxbindings_version"
|
|
||||||
compile "com.jakewharton.rxbinding:rxbinding-recyclerview-v7-kotlin:$rxbindings_version"
|
|
||||||
|
|
||||||
compile 'com.nightlynexus.viewstatepageradapter:viewstatepageradapter:1.0.4'
|
|
||||||
|
|
||||||
// Modified dependencies
|
// Modified dependencies
|
||||||
compile 'com.github.inorichi:subsampling-scale-image-view:01e5385'
|
compile 'com.github.inorichi:subsampling-scale-image-view:01e5385'
|
||||||
compile 'com.github.inorichi:junrar-android:634c1f5'
|
compile 'com.github.inorichi:junrar-android:634c1f5'
|
||||||
@ -201,12 +190,23 @@ dependencies {
|
|||||||
compile 'com.dmitrymalkovich.android:material-design-dimens:1.4'
|
compile 'com.dmitrymalkovich.android:material-design-dimens:1.4'
|
||||||
compile 'com.github.dmytrodanylyk.android-process-button:library:1.0.4'
|
compile 'com.github.dmytrodanylyk.android-process-button:library:1.0.4'
|
||||||
compile 'eu.davidea:flexible-adapter:5.0.0-rc1'
|
compile 'eu.davidea:flexible-adapter:5.0.0-rc1'
|
||||||
compile 'com.github.inorichi:FlexibleAdapter:93985fe' // v4.2.0 to be removed
|
|
||||||
compile 'com.nononsenseapps:filepicker:2.5.2'
|
compile 'com.nononsenseapps:filepicker:2.5.2'
|
||||||
compile 'com.github.amulyakhare:TextDrawable:558677e'
|
compile 'com.github.amulyakhare:TextDrawable:558677e'
|
||||||
compile 'com.afollestad.material-dialogs:core:0.9.4.2'
|
compile 'com.afollestad.material-dialogs:core:0.9.4.2'
|
||||||
compile 'me.zhanghai.android.systemuihelper:library:1.0.0'
|
compile 'me.zhanghai.android.systemuihelper:library:1.0.0'
|
||||||
compile 'de.hdodenhof:circleimageview:2.1.0'
|
compile 'de.hdodenhof:circleimageview:2.1.0'
|
||||||
|
compile 'com.nightlynexus.viewstatepageradapter:viewstatepageradapter:1.0.4'
|
||||||
|
|
||||||
|
// Conductor
|
||||||
|
compile "com.bluelinelabs:conductor:2.1.3"
|
||||||
|
compile 'com.github.inorichi:conductor-support-preference:9e36460'
|
||||||
|
|
||||||
|
// RxBindings
|
||||||
|
final rxbindings_version = '1.0.1'
|
||||||
|
compile "com.jakewharton.rxbinding:rxbinding-kotlin:$rxbindings_version"
|
||||||
|
compile "com.jakewharton.rxbinding:rxbinding-appcompat-v7-kotlin:$rxbindings_version"
|
||||||
|
compile "com.jakewharton.rxbinding:rxbinding-support-v4-kotlin:$rxbindings_version"
|
||||||
|
compile "com.jakewharton.rxbinding:rxbinding-recyclerview-v7-kotlin:$rxbindings_version"
|
||||||
|
|
||||||
// Tests
|
// Tests
|
||||||
testCompile 'junit:junit:4.12'
|
testCompile 'junit:junit:4.12'
|
||||||
|
@ -53,9 +53,6 @@
|
|||||||
android:scheme="tachiyomi" />
|
android:scheme="tachiyomi" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
|
||||||
android:name=".ui.download.DownloadActivity"
|
|
||||||
android:launchMode="singleTop" />
|
|
||||||
|
|
||||||
<provider
|
<provider
|
||||||
android:name="android.support.v4.content.FileProvider"
|
android:name="android.support.v4.content.FileProvider"
|
||||||
|
@ -3,7 +3,7 @@ package eu.kanade.tachiyomi.data.notification
|
|||||||
import android.app.PendingIntent
|
import android.app.PendingIntent
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import eu.kanade.tachiyomi.ui.download.DownloadActivity
|
import eu.kanade.tachiyomi.ui.main.MainActivity
|
||||||
import eu.kanade.tachiyomi.util.getUriCompat
|
import eu.kanade.tachiyomi.util.getUriCompat
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@ -17,8 +17,9 @@ object NotificationHandler {
|
|||||||
* @param context context of application
|
* @param context context of application
|
||||||
*/
|
*/
|
||||||
internal fun openDownloadManagerPendingActivity(context: Context): PendingIntent {
|
internal fun openDownloadManagerPendingActivity(context: Context): PendingIntent {
|
||||||
val intent = Intent(context, DownloadActivity::class.java).apply {
|
val intent = Intent(context, MainActivity::class.java).apply {
|
||||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
|
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
|
||||||
|
action = MainActivity.SHORTCUT_DOWNLOADS
|
||||||
}
|
}
|
||||||
return PendingIntent.getActivity(context, 0, intent, 0)
|
return PendingIntent.getActivity(context, 0, intent, 0)
|
||||||
}
|
}
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
package eu.kanade.tachiyomi.ui.base.adapter
|
|
||||||
|
|
||||||
import android.support.v7.widget.RecyclerView
|
|
||||||
import android.view.View
|
|
||||||
|
|
||||||
import eu.davidea.flexibleadapter4.FlexibleAdapter
|
|
||||||
|
|
||||||
abstract class FlexibleViewHolder(view: View,
|
|
||||||
private val adapter: FlexibleAdapter<*, *>,
|
|
||||||
private val itemClickListener: FlexibleViewHolder.OnListItemClickListener) :
|
|
||||||
RecyclerView.ViewHolder(view), View.OnClickListener, View.OnLongClickListener {
|
|
||||||
|
|
||||||
init {
|
|
||||||
view.setOnClickListener(this)
|
|
||||||
view.setOnLongClickListener(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onClick(view: View) {
|
|
||||||
if (itemClickListener.onListItemClick(adapterPosition)) {
|
|
||||||
toggleActivation()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onLongClick(view: View): Boolean {
|
|
||||||
itemClickListener.onListItemLongClick(adapterPosition)
|
|
||||||
toggleActivation()
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
fun toggleActivation() {
|
|
||||||
itemView.isActivated = adapter.isSelected(adapterPosition)
|
|
||||||
}
|
|
||||||
|
|
||||||
interface OnListItemClickListener {
|
|
||||||
fun onListItemClick(position: Int): Boolean
|
|
||||||
fun onListItemLongClick(position: Int)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
package eu.kanade.tachiyomi.ui.base.adapter
|
|
||||||
|
|
||||||
import android.support.v4.app.Fragment
|
|
||||||
import android.support.v4.app.FragmentManager
|
|
||||||
import android.support.v4.app.FragmentStatePagerAdapter
|
|
||||||
import android.util.SparseArray
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
abstract class SmartFragmentStatePagerAdapter(fragmentManager: FragmentManager) :
|
|
||||||
FragmentStatePagerAdapter(fragmentManager) {
|
|
||||||
// Sparse array to keep track of registered fragments in memory
|
|
||||||
private val registeredFragments = SparseArray<Fragment>()
|
|
||||||
|
|
||||||
// Register the fragment when the item is instantiated
|
|
||||||
override fun instantiateItem(container: ViewGroup, position: Int): Any {
|
|
||||||
val fragment = super.instantiateItem(container, position) as Fragment
|
|
||||||
registeredFragments.put(position, fragment)
|
|
||||||
return fragment
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unregister when the item is inactive
|
|
||||||
override fun destroyItem(container: ViewGroup?, position: Int, `object`: Any) {
|
|
||||||
registeredFragments.remove(position)
|
|
||||||
super.destroyItem(container, position, `object`)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the fragment for the position (if instantiated)
|
|
||||||
fun getRegisteredFragment(position: Int): Fragment {
|
|
||||||
return registeredFragments.get(position)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getRegisteredFragments(): List<Fragment> {
|
|
||||||
val fragments = ArrayList<Fragment>()
|
|
||||||
for (i in 0..registeredFragments.size() - 1) {
|
|
||||||
fragments.add(registeredFragments.valueAt(i))
|
|
||||||
}
|
|
||||||
return fragments
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,8 +1,7 @@
|
|||||||
package eu.kanade.tachiyomi.ui.download
|
package eu.kanade.tachiyomi.ui.download
|
||||||
|
|
||||||
import android.content.Context
|
import android.support.v7.widget.RecyclerView
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import eu.davidea.flexibleadapter4.FlexibleAdapter
|
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.download.model.Download
|
import eu.kanade.tachiyomi.data.download.model.Download
|
||||||
import eu.kanade.tachiyomi.util.inflate
|
import eu.kanade.tachiyomi.util.inflate
|
||||||
@ -12,7 +11,9 @@ import eu.kanade.tachiyomi.util.inflate
|
|||||||
*
|
*
|
||||||
* @param context the context of the fragment containing this adapter.
|
* @param context the context of the fragment containing this adapter.
|
||||||
*/
|
*/
|
||||||
class DownloadAdapter(private val context: Context) : FlexibleAdapter<DownloadHolder, Download>() {
|
class DownloadAdapter : RecyclerView.Adapter<DownloadHolder>() {
|
||||||
|
|
||||||
|
private var items = emptyList<Download>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
setHasStableIds(true)
|
setHasStableIds(true)
|
||||||
@ -24,10 +25,17 @@ class DownloadAdapter(private val context: Context) : FlexibleAdapter<DownloadHo
|
|||||||
* @param downloads the list to set.
|
* @param downloads the list to set.
|
||||||
*/
|
*/
|
||||||
fun setItems(downloads: List<Download>) {
|
fun setItems(downloads: List<Download>) {
|
||||||
mItems = downloads
|
items = downloads
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of downloads in the adapter
|
||||||
|
*/
|
||||||
|
override fun getItemCount(): Int {
|
||||||
|
return items.size
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the identifier for a download.
|
* Returns the identifier for a download.
|
||||||
*
|
*
|
||||||
@ -35,7 +43,7 @@ class DownloadAdapter(private val context: Context) : FlexibleAdapter<DownloadHo
|
|||||||
* @return an identifier for the item.
|
* @return an identifier for the item.
|
||||||
*/
|
*/
|
||||||
override fun getItemId(position: Int): Long {
|
override fun getItemId(position: Int): Long {
|
||||||
return getItem(position).chapter.id!!
|
return items[position].chapter.id!!
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,14 +65,8 @@ class DownloadAdapter(private val context: Context) : FlexibleAdapter<DownloadHo
|
|||||||
* @param position the position to bind.
|
* @param position the position to bind.
|
||||||
*/
|
*/
|
||||||
override fun onBindViewHolder(holder: DownloadHolder, position: Int) {
|
override fun onBindViewHolder(holder: DownloadHolder, position: Int) {
|
||||||
val download = getItem(position)
|
val download = items[position]
|
||||||
holder.onSetValues(download)
|
holder.onSetValues(download)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Used to filter the list. Not used.
|
|
||||||
*/
|
|
||||||
override fun updateDataSet(param: String) {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,246 +1,252 @@
|
|||||||
package eu.kanade.tachiyomi.ui.download
|
package eu.kanade.tachiyomi.ui.download
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v7.widget.LinearLayoutManager
|
import android.support.v7.widget.LinearLayoutManager
|
||||||
import android.view.Menu
|
import android.view.*
|
||||||
import android.view.MenuItem
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.data.download.DownloadService
|
||||||
import eu.kanade.tachiyomi.data.download.DownloadService
|
import eu.kanade.tachiyomi.data.download.model.Download
|
||||||
import eu.kanade.tachiyomi.data.download.model.Download
|
import eu.kanade.tachiyomi.source.model.Page
|
||||||
import eu.kanade.tachiyomi.source.model.Page
|
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
||||||
import eu.kanade.tachiyomi.ui.base.activity.BaseRxActivity
|
import kotlinx.android.synthetic.main.activity_download_manager.view.*
|
||||||
import eu.kanade.tachiyomi.util.plusAssign
|
import rx.Observable
|
||||||
import kotlinx.android.synthetic.main.fragment_download_queue.*
|
import rx.Subscription
|
||||||
import kotlinx.android.synthetic.main.toolbar.*
|
import rx.android.schedulers.AndroidSchedulers
|
||||||
import nucleus.factory.RequiresPresenter
|
import java.util.*
|
||||||
import rx.Observable
|
import java.util.concurrent.TimeUnit
|
||||||
import rx.Subscription
|
|
||||||
import rx.android.schedulers.AndroidSchedulers
|
/**
|
||||||
import rx.subscriptions.CompositeSubscription
|
* Controller that shows the currently active downloads.
|
||||||
import java.util.*
|
* Uses R.layout.fragment_download_queue.
|
||||||
import java.util.concurrent.TimeUnit
|
*/
|
||||||
|
class DownloadController : NucleusController<DownloadPresenter>() {
|
||||||
/**
|
|
||||||
* Activity that shows the currently active downloads.
|
/**
|
||||||
* Uses R.layout.fragment_download_queue.
|
* Adapter containing the active downloads.
|
||||||
*/
|
*/
|
||||||
@RequiresPresenter(DownloadPresenter::class)
|
private var adapter: DownloadAdapter? = null
|
||||||
class DownloadActivity : BaseRxActivity<DownloadPresenter>() {
|
|
||||||
/**
|
/**
|
||||||
* Adapter containing the active downloads.
|
* Map of subscriptions for active downloads.
|
||||||
*/
|
*/
|
||||||
private lateinit var adapter: DownloadAdapter
|
private val progressSubscriptions by lazy { HashMap<Download, Subscription>() }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subscription list to be cleared during [onDestroy].
|
* Whether the download queue is running or not.
|
||||||
*/
|
*/
|
||||||
private val subscriptions by lazy { CompositeSubscription() }
|
private var isRunning: Boolean = false
|
||||||
|
|
||||||
/**
|
init {
|
||||||
* Map of subscriptions for active downloads.
|
setHasOptionsMenu(true)
|
||||||
*/
|
}
|
||||||
private val progressSubscriptions by lazy { HashMap<Download, Subscription>() }
|
|
||||||
|
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View {
|
||||||
/**
|
return inflater.inflate(R.layout.activity_download_manager, container, false)
|
||||||
* Whether the download queue is running or not.
|
}
|
||||||
*/
|
|
||||||
private var isRunning: Boolean = false
|
override fun createPresenter(): DownloadPresenter {
|
||||||
|
return DownloadPresenter()
|
||||||
override fun onCreate(savedState: Bundle?) {
|
}
|
||||||
setAppTheme()
|
|
||||||
super.onCreate(savedState)
|
override fun getTitle(): String? {
|
||||||
setContentView(R.layout.activity_download_manager)
|
return resources?.getString(R.string.label_download_queue)
|
||||||
setupToolbar(toolbar)
|
}
|
||||||
setToolbarTitle(R.string.label_download_queue)
|
|
||||||
|
override fun onViewCreated(view: View, savedViewState: Bundle?) {
|
||||||
// Check if download queue is empty and update information accordingly.
|
super.onViewCreated(view, savedViewState)
|
||||||
setInformationView()
|
|
||||||
|
// Check if download queue is empty and update information accordingly.
|
||||||
// Initialize adapter.
|
setInformationView()
|
||||||
adapter = DownloadAdapter(this)
|
|
||||||
recycler.adapter = adapter
|
// Initialize adapter.
|
||||||
|
adapter = DownloadAdapter()
|
||||||
// Set the layout manager for the recycler and fixed size.
|
with(view) {
|
||||||
recycler.layoutManager = LinearLayoutManager(this)
|
recycler.adapter = adapter
|
||||||
recycler.setHasFixedSize(true)
|
|
||||||
|
// Set the layout manager for the recycler and fixed size.
|
||||||
// Suscribe to changes
|
recycler.layoutManager = LinearLayoutManager(context)
|
||||||
subscriptions += DownloadService.runningRelay
|
recycler.setHasFixedSize(true)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
}
|
||||||
.subscribe { onQueueStatusChange(it) }
|
|
||||||
|
// Suscribe to changes
|
||||||
subscriptions += presenter.getDownloadStatusObservable()
|
DownloadService.runningRelay
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe { onStatusChange(it) }
|
.subscribeUntilDestroy { onQueueStatusChange(it) }
|
||||||
|
|
||||||
subscriptions += presenter.getDownloadProgressObservable()
|
presenter.getDownloadStatusObservable()
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe { onUpdateDownloadedPages(it) }
|
.subscribeUntilDestroy { onStatusChange(it) }
|
||||||
}
|
|
||||||
|
presenter.getDownloadProgressObservable()
|
||||||
override fun onDestroy() {
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
for (subscription in progressSubscriptions.values) {
|
.subscribeUntilDestroy { onUpdateDownloadedPages(it) }
|
||||||
subscription.unsubscribe()
|
}
|
||||||
}
|
|
||||||
progressSubscriptions.clear()
|
override fun onDestroyView(view: View) {
|
||||||
subscriptions.clear()
|
super.onDestroyView(view)
|
||||||
super.onDestroy()
|
for (subscription in progressSubscriptions.values) {
|
||||||
}
|
subscription.unsubscribe()
|
||||||
|
}
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
progressSubscriptions.clear()
|
||||||
menuInflater.inflate(R.menu.download_queue, menu)
|
adapter = null
|
||||||
return true
|
}
|
||||||
}
|
|
||||||
|
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||||
override fun onPrepareOptionsMenu(menu: Menu): Boolean {
|
inflater.inflate(R.menu.download_queue, menu)
|
||||||
// Set start button visibility.
|
}
|
||||||
menu.findItem(R.id.start_queue).isVisible = !isRunning && !presenter.downloadQueue.isEmpty()
|
|
||||||
|
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||||
// Set pause button visibility.
|
// Set start button visibility.
|
||||||
menu.findItem(R.id.pause_queue).isVisible = isRunning
|
menu.findItem(R.id.start_queue).isVisible = !isRunning && !presenter.downloadQueue.isEmpty()
|
||||||
|
|
||||||
// Set clear button visibility.
|
// Set pause button visibility.
|
||||||
menu.findItem(R.id.clear_queue).isVisible = !presenter.downloadQueue.isEmpty()
|
menu.findItem(R.id.pause_queue).isVisible = isRunning
|
||||||
return true
|
|
||||||
}
|
// Set clear button visibility.
|
||||||
|
menu.findItem(R.id.clear_queue).isVisible = !presenter.downloadQueue.isEmpty()
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
}
|
||||||
when (item.itemId) {
|
|
||||||
R.id.start_queue -> DownloadService.start(this)
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
R.id.pause_queue -> {
|
val context = applicationContext ?: return false
|
||||||
DownloadService.stop(this)
|
when (item.itemId) {
|
||||||
presenter.pauseDownloads()
|
R.id.start_queue -> DownloadService.start(context)
|
||||||
}
|
R.id.pause_queue -> {
|
||||||
R.id.clear_queue -> {
|
DownloadService.stop(context)
|
||||||
DownloadService.stop(this)
|
presenter.pauseDownloads()
|
||||||
presenter.clearQueue()
|
}
|
||||||
}
|
R.id.clear_queue -> {
|
||||||
else -> return super.onOptionsItemSelected(item)
|
DownloadService.stop(context)
|
||||||
}
|
presenter.clearQueue()
|
||||||
return true
|
}
|
||||||
}
|
else -> return super.onOptionsItemSelected(item)
|
||||||
|
}
|
||||||
/**
|
return true
|
||||||
* Called when the status of a download changes.
|
}
|
||||||
*
|
|
||||||
* @param download the download whose status has changed.
|
/**
|
||||||
*/
|
* Called when the status of a download changes.
|
||||||
private fun onStatusChange(download: Download) {
|
*
|
||||||
when (download.status) {
|
* @param download the download whose status has changed.
|
||||||
Download.DOWNLOADING -> {
|
*/
|
||||||
observeProgress(download)
|
private fun onStatusChange(download: Download) {
|
||||||
// Initial update of the downloaded pages
|
when (download.status) {
|
||||||
onUpdateDownloadedPages(download)
|
Download.DOWNLOADING -> {
|
||||||
}
|
observeProgress(download)
|
||||||
Download.DOWNLOADED -> {
|
// Initial update of the downloaded pages
|
||||||
unsubscribeProgress(download)
|
onUpdateDownloadedPages(download)
|
||||||
onUpdateProgress(download)
|
}
|
||||||
onUpdateDownloadedPages(download)
|
Download.DOWNLOADED -> {
|
||||||
}
|
unsubscribeProgress(download)
|
||||||
Download.ERROR -> unsubscribeProgress(download)
|
onUpdateProgress(download)
|
||||||
}
|
onUpdateDownloadedPages(download)
|
||||||
}
|
}
|
||||||
|
Download.ERROR -> unsubscribeProgress(download)
|
||||||
/**
|
}
|
||||||
* Observe the progress of a download and notify the view.
|
}
|
||||||
*
|
|
||||||
* @param download the download to observe its progress.
|
/**
|
||||||
*/
|
* Observe the progress of a download and notify the view.
|
||||||
private fun observeProgress(download: Download) {
|
*
|
||||||
val subscription = Observable.interval(50, TimeUnit.MILLISECONDS)
|
* @param download the download to observe its progress.
|
||||||
// Get the sum of percentages for all the pages.
|
*/
|
||||||
.flatMap {
|
private fun observeProgress(download: Download) {
|
||||||
Observable.from(download.pages)
|
val subscription = Observable.interval(50, TimeUnit.MILLISECONDS)
|
||||||
.map(Page::progress)
|
// Get the sum of percentages for all the pages.
|
||||||
.reduce { x, y -> x + y }
|
.flatMap {
|
||||||
}
|
Observable.from(download.pages)
|
||||||
// Keep only the latest emission to avoid backpressure.
|
.map(Page::progress)
|
||||||
.onBackpressureLatest()
|
.reduce { x, y -> x + y }
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
}
|
||||||
.subscribe { progress ->
|
// Keep only the latest emission to avoid backpressure.
|
||||||
// Update the view only if the progress has changed.
|
.onBackpressureLatest()
|
||||||
if (download.totalProgress != progress) {
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
download.totalProgress = progress
|
.subscribe { progress ->
|
||||||
onUpdateProgress(download)
|
// Update the view only if the progress has changed.
|
||||||
}
|
if (download.totalProgress != progress) {
|
||||||
}
|
download.totalProgress = progress
|
||||||
|
onUpdateProgress(download)
|
||||||
// Avoid leaking subscriptions
|
}
|
||||||
progressSubscriptions.remove(download)?.unsubscribe()
|
}
|
||||||
|
|
||||||
progressSubscriptions.put(download, subscription)
|
// Avoid leaking subscriptions
|
||||||
}
|
progressSubscriptions.remove(download)?.unsubscribe()
|
||||||
|
|
||||||
/**
|
progressSubscriptions.put(download, subscription)
|
||||||
* Unsubscribes the given download from the progress subscriptions.
|
}
|
||||||
*
|
|
||||||
* @param download the download to unsubscribe.
|
/**
|
||||||
*/
|
* Unsubscribes the given download from the progress subscriptions.
|
||||||
private fun unsubscribeProgress(download: Download) {
|
*
|
||||||
progressSubscriptions.remove(download)?.unsubscribe()
|
* @param download the download to unsubscribe.
|
||||||
}
|
*/
|
||||||
|
private fun unsubscribeProgress(download: Download) {
|
||||||
/**
|
progressSubscriptions.remove(download)?.unsubscribe()
|
||||||
* Called when the queue's status has changed. Updates the visibility of the buttons.
|
}
|
||||||
*
|
|
||||||
* @param running whether the queue is now running or not.
|
/**
|
||||||
*/
|
* Called when the queue's status has changed. Updates the visibility of the buttons.
|
||||||
private fun onQueueStatusChange(running: Boolean) {
|
*
|
||||||
isRunning = running
|
* @param running whether the queue is now running or not.
|
||||||
supportInvalidateOptionsMenu()
|
*/
|
||||||
|
private fun onQueueStatusChange(running: Boolean) {
|
||||||
// Check if download queue is empty and update information accordingly.
|
isRunning = running
|
||||||
setInformationView()
|
activity?.invalidateOptionsMenu()
|
||||||
}
|
|
||||||
|
// Check if download queue is empty and update information accordingly.
|
||||||
/**
|
setInformationView()
|
||||||
* Called from the presenter to assign the downloads for the adapter.
|
}
|
||||||
*
|
|
||||||
* @param downloads the downloads from the queue.
|
/**
|
||||||
*/
|
* Called from the presenter to assign the downloads for the adapter.
|
||||||
fun onNextDownloads(downloads: List<Download>) {
|
*
|
||||||
supportInvalidateOptionsMenu()
|
* @param downloads the downloads from the queue.
|
||||||
setInformationView()
|
*/
|
||||||
adapter.setItems(downloads)
|
fun onNextDownloads(downloads: List<Download>) {
|
||||||
}
|
activity?.invalidateOptionsMenu()
|
||||||
|
setInformationView()
|
||||||
/**
|
adapter?.setItems(downloads)
|
||||||
* Called when the progress of a download changes.
|
}
|
||||||
*
|
|
||||||
* @param download the download whose progress has changed.
|
/**
|
||||||
*/
|
* Called when the progress of a download changes.
|
||||||
fun onUpdateProgress(download: Download) {
|
*
|
||||||
getHolder(download)?.notifyProgress()
|
* @param download the download whose progress has changed.
|
||||||
}
|
*/
|
||||||
|
fun onUpdateProgress(download: Download) {
|
||||||
/**
|
getHolder(download)?.notifyProgress()
|
||||||
* Called when a page of a download is downloaded.
|
}
|
||||||
*
|
|
||||||
* @param download the download whose page has been downloaded.
|
/**
|
||||||
*/
|
* Called when a page of a download is downloaded.
|
||||||
fun onUpdateDownloadedPages(download: Download) {
|
*
|
||||||
getHolder(download)?.notifyDownloadedPages()
|
* @param download the download whose page has been downloaded.
|
||||||
}
|
*/
|
||||||
|
fun onUpdateDownloadedPages(download: Download) {
|
||||||
/**
|
getHolder(download)?.notifyDownloadedPages()
|
||||||
* Returns the holder for the given download.
|
}
|
||||||
*
|
|
||||||
* @param download the download to find.
|
/**
|
||||||
* @return the holder of the download or null if it's not bound.
|
* Returns the holder for the given download.
|
||||||
*/
|
*
|
||||||
private fun getHolder(download: Download): DownloadHolder? {
|
* @param download the download to find.
|
||||||
return recycler.findViewHolderForItemId(download.chapter.id!!) as? DownloadHolder
|
* @return the holder of the download or null if it's not bound.
|
||||||
}
|
*/
|
||||||
|
private fun getHolder(download: Download): DownloadHolder? {
|
||||||
/**
|
val recycler = view?.recycler ?: return null
|
||||||
* Set information view when queue is empty
|
return recycler.findViewHolderForItemId(download.chapter.id!!) as? DownloadHolder
|
||||||
*/
|
}
|
||||||
private fun setInformationView() {
|
|
||||||
updateEmptyView(presenter.downloadQueue.isEmpty(),
|
/**
|
||||||
R.string.information_no_downloads, R.drawable.ic_file_download_black_128dp)
|
* Set information view when queue is empty
|
||||||
}
|
*/
|
||||||
|
private fun setInformationView() {
|
||||||
fun updateEmptyView(show: Boolean, textResource: Int, drawable: Int) {
|
val emptyView = view?.empty_view ?: return
|
||||||
// if (show) empty_view.show(drawable, textResource) else empty_view.hide()
|
if (presenter.downloadQueue.isEmpty()) {
|
||||||
}
|
emptyView.show(R.drawable.ic_file_download_black_128dp,
|
||||||
}
|
R.string.information_no_downloads)
|
||||||
|
} else {
|
||||||
|
emptyView.hide()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -12,9 +12,9 @@ import uy.kohesive.injekt.injectLazy
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Presenter of [DownloadActivity].
|
* Presenter of [DownloadController].
|
||||||
*/
|
*/
|
||||||
class DownloadPresenter : BasePresenter<DownloadActivity>() {
|
class DownloadPresenter : BasePresenter<DownloadController>() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Download manager.
|
* Download manager.
|
||||||
@ -33,7 +33,7 @@ class DownloadPresenter : BasePresenter<DownloadActivity>() {
|
|||||||
downloadQueue.getUpdatedObservable()
|
downloadQueue.getUpdatedObservable()
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.map { ArrayList(it) }
|
.map { ArrayList(it) }
|
||||||
.subscribeLatestCache(DownloadActivity::onNextDownloads, { view, error ->
|
.subscribeLatestCache(DownloadController::onNextDownloads, { view, error ->
|
||||||
Timber.e(error)
|
Timber.e(error)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package eu.kanade.tachiyomi.ui.main
|
package eu.kanade.tachiyomi.ui.main
|
||||||
|
|
||||||
import android.animation.ObjectAnimator
|
import android.animation.ObjectAnimator
|
||||||
import android.content.Intent
|
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v4.view.GravityCompat
|
import android.support.v4.view.GravityCompat
|
||||||
@ -19,7 +18,7 @@ import eu.kanade.tachiyomi.ui.base.controller.NoToolbarElevationController
|
|||||||
import eu.kanade.tachiyomi.ui.base.controller.SecondaryDrawerController
|
import eu.kanade.tachiyomi.ui.base.controller.SecondaryDrawerController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.TabbedController
|
import eu.kanade.tachiyomi.ui.base.controller.TabbedController
|
||||||
import eu.kanade.tachiyomi.ui.catalogue.CatalogueController
|
import eu.kanade.tachiyomi.ui.catalogue.CatalogueController
|
||||||
import eu.kanade.tachiyomi.ui.download.DownloadActivity
|
import eu.kanade.tachiyomi.ui.download.DownloadController
|
||||||
import eu.kanade.tachiyomi.ui.latest_updates.LatestUpdatesController
|
import eu.kanade.tachiyomi.ui.latest_updates.LatestUpdatesController
|
||||||
import eu.kanade.tachiyomi.ui.library.LibraryController
|
import eu.kanade.tachiyomi.ui.library.LibraryController
|
||||||
import eu.kanade.tachiyomi.ui.manga.MangaController
|
import eu.kanade.tachiyomi.ui.manga.MangaController
|
||||||
@ -85,7 +84,9 @@ class MainActivity : BaseActivity() {
|
|||||||
R.id.nav_drawer_catalogues -> setRoot(CatalogueController(), id)
|
R.id.nav_drawer_catalogues -> setRoot(CatalogueController(), id)
|
||||||
R.id.nav_drawer_latest_updates -> setRoot(LatestUpdatesController(), id)
|
R.id.nav_drawer_latest_updates -> setRoot(LatestUpdatesController(), id)
|
||||||
R.id.nav_drawer_downloads -> {
|
R.id.nav_drawer_downloads -> {
|
||||||
startActivity(Intent(this, DownloadActivity::class.java))
|
router.pushController(RouterTransaction.with(DownloadController())
|
||||||
|
.pushChangeHandler(FadeChangeHandler())
|
||||||
|
.popChangeHandler(FadeChangeHandler()))
|
||||||
}
|
}
|
||||||
R.id.nav_drawer_settings ->
|
R.id.nav_drawer_settings ->
|
||||||
router.pushController(RouterTransaction.with(SettingsMainController())
|
router.pushController(RouterTransaction.with(SettingsMainController())
|
||||||
@ -109,6 +110,7 @@ class MainActivity : BaseActivity() {
|
|||||||
SHORTCUT_CATALOGUES -> setSelectedDrawerItem(R.id.nav_drawer_catalogues)
|
SHORTCUT_CATALOGUES -> setSelectedDrawerItem(R.id.nav_drawer_catalogues)
|
||||||
SHORTCUT_MANGA -> router.setRoot(
|
SHORTCUT_MANGA -> router.setRoot(
|
||||||
RouterTransaction.with(MangaController(intent.extras)))
|
RouterTransaction.with(MangaController(intent.extras)))
|
||||||
|
SHORTCUT_DOWNLOADS -> setSelectedDrawerItem(R.id.nav_drawer_downloads)
|
||||||
else -> setSelectedDrawerItem(startScreenId)
|
else -> setSelectedDrawerItem(startScreenId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -225,6 +227,7 @@ class MainActivity : BaseActivity() {
|
|||||||
private const val SHORTCUT_RECENTLY_UPDATED = "eu.kanade.tachiyomi.SHOW_RECENTLY_UPDATED"
|
private const val SHORTCUT_RECENTLY_UPDATED = "eu.kanade.tachiyomi.SHOW_RECENTLY_UPDATED"
|
||||||
private const val SHORTCUT_RECENTLY_READ = "eu.kanade.tachiyomi.SHOW_RECENTLY_READ"
|
private const val SHORTCUT_RECENTLY_READ = "eu.kanade.tachiyomi.SHOW_RECENTLY_READ"
|
||||||
private const val SHORTCUT_CATALOGUES = "eu.kanade.tachiyomi.SHOW_CATALOGUES"
|
private const val SHORTCUT_CATALOGUES = "eu.kanade.tachiyomi.SHOW_CATALOGUES"
|
||||||
|
const val SHORTCUT_DOWNLOADS = "eu.kanade.tachiyomi.SHOW_DOWNLOADS"
|
||||||
const val SHORTCUT_MANGA = "eu.kanade.tachiyomi.SHOW_MANGA"
|
const val SHORTCUT_MANGA = "eu.kanade.tachiyomi.SHOW_MANGA"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,42 +1,22 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout
|
||||||
android:layout_width="match_parent"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_height="match_parent"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:fitsSystemWindows="true">
|
android:id="@+id/frame_container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<LinearLayout
|
<android.support.v7.widget.RecyclerView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical">
|
android:id="@+id/recycler"
|
||||||
|
tools:listitem="@layout/item_download"/>
|
||||||
|
|
||||||
<android.support.design.widget.AppBarLayout
|
<eu.kanade.tachiyomi.widget.EmptyView
|
||||||
android:id="@+id/appbar"
|
android:id="@+id/empty_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
|
||||||
<include layout="@layout/toolbar"/>
|
</FrameLayout>
|
||||||
|
|
||||||
</android.support.design.widget.AppBarLayout>
|
|
||||||
|
|
||||||
<FrameLayout
|
|
||||||
android:id="@+id/frame_container"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<android.support.v7.widget.RecyclerView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:id="@+id/recycler"
|
|
||||||
tools:listitem="@layout/item_download"/>
|
|
||||||
|
|
||||||
<eu.kanade.tachiyomi.widget.EmptyView
|
|
||||||
android:id="@+id/empty_view"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:visibility="gone"/>
|
|
||||||
</FrameLayout>
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</android.support.design.widget.CoordinatorLayout>
|
|
||||||
|
Loading…
Reference in New Issue
Block a user