From b58664dae5f013a15da70c2cb647fb4b615edab3 Mon Sep 17 00:00:00 2001 From: Sean Mac Gillicuddy Date: Tue, 7 Jan 2020 15:37:06 +0000 Subject: [PATCH 1/5] #716 Merge library tabs "Device" & "Downloading" - remove downloading view --- .../di/components/KiwixActivityComponent.kt | 2 - .../zim_manager/SectionsPagerAdapter.kt | 33 ++++--- .../zim_manager/ZimManageActivity.kt | 19 +--- .../download_view/DownloadAdapter.kt | 59 ------------ .../download_view/DownloadFragment.kt | 94 ------------------- .../download_view/DownloadViewHolder.kt | 49 ---------- .../library_view/LibraryFragment.kt | 8 +- .../library_view/adapter/LibraryDelegate.kt | 12 ++- .../library_view/adapter/LibraryListItem.kt | 32 +++++++ .../library_view/adapter/LibraryViewHolder.kt | 58 ++++++++---- .../{download_item.xml => item_download.xml} | 9 +- app/src/main/res/layout/item_library.xml | 50 +++++----- .../res/layout/layout_download_management.xml | 24 ----- .../core/downloader/DownloadRequester.kt | 3 +- .../kiwixmobile/core/downloader/Downloader.kt | 3 +- .../core/downloader/DownloaderImpl.kt | 5 +- .../fetch/FetchDownloadRequester.kt | 5 +- 17 files changed, 145 insertions(+), 320 deletions(-) delete mode 100644 app/src/main/java/org/kiwix/kiwixmobile/zim_manager/download_view/DownloadAdapter.kt delete mode 100644 app/src/main/java/org/kiwix/kiwixmobile/zim_manager/download_view/DownloadFragment.kt delete mode 100644 app/src/main/java/org/kiwix/kiwixmobile/zim_manager/download_view/DownloadViewHolder.kt rename app/src/main/res/layout/{download_item.xml => item_download.xml} (93%) delete mode 100644 app/src/main/res/layout/layout_download_management.xml diff --git a/app/src/main/java/org/kiwix/kiwixmobile/di/components/KiwixActivityComponent.kt b/app/src/main/java/org/kiwix/kiwixmobile/di/components/KiwixActivityComponent.kt index 088d28a54..14e78e78a 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/di/components/KiwixActivityComponent.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/di/components/KiwixActivityComponent.kt @@ -32,7 +32,6 @@ import org.kiwix.kiwixmobile.splash.KiwixSplashActivity import org.kiwix.kiwixmobile.webserver.ZimHostActivity import org.kiwix.kiwixmobile.webserver.ZimHostModule import org.kiwix.kiwixmobile.zim_manager.ZimManageActivity -import org.kiwix.kiwixmobile.zim_manager.download_view.DownloadFragment import org.kiwix.kiwixmobile.zim_manager.fileselect_view.ZimFileSelectFragment import org.kiwix.kiwixmobile.zim_manager.fileselect_view.effects.DeleteFiles import org.kiwix.kiwixmobile.zim_manager.library_view.LibraryFragment @@ -46,7 +45,6 @@ import org.kiwix.kiwixmobile.zim_manager.library_view.LibraryFragment ] ) interface KiwixActivityComponent { - fun inject(downloadFragment: DownloadFragment) fun inject(libraryFragment: LibraryFragment) fun inject(zimFileSelectFragment: ZimFileSelectFragment) fun inject(deleteFiles: DeleteFiles) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/SectionsPagerAdapter.kt b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/SectionsPagerAdapter.kt index f458a2717..d14cf10e0 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/SectionsPagerAdapter.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/SectionsPagerAdapter.kt @@ -20,31 +20,30 @@ package org.kiwix.kiwixmobile.zim_manager import android.content.Context import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentPagerAdapter -import org.kiwix.kiwixmobile.core.R -import org.kiwix.kiwixmobile.zim_manager.download_view.DownloadFragment +import org.kiwix.kiwixmobile.core.R.string +import org.kiwix.kiwixmobile.core.base.BaseFragment import org.kiwix.kiwixmobile.zim_manager.fileselect_view.ZimFileSelectFragment import org.kiwix.kiwixmobile.zim_manager.library_view.LibraryFragment +import kotlin.reflect.KFunction0 class SectionsPagerAdapter( private val context: Context, + private val pagerData: Array = + arrayOf( + PagerData(::ZimFileSelectFragment, string.local_zims), + PagerData(::LibraryFragment, string.remote_zims) + ), fm: FragmentManager ) : FragmentPagerAdapter(fm) { - override fun getItem(position: Int) = when (position) { - 0 -> ZimFileSelectFragment() - 1 -> LibraryFragment() - 2 -> DownloadFragment() - else -> throw RuntimeException("No matching fragment for position: $position") - } + override fun getItem(position: Int) = pagerData[position].fragmentConstructor.invoke() - override fun getCount() = 3 + override fun getCount() = pagerData.size - override fun getPageTitle(position: Int): String = context.getString( - when (position) { - 0 -> R.string.local_zims - 1 -> R.string.remote_zims - 2 -> R.string.zim_downloads - else -> throw RuntimeException("No matching title for position: $position") - } - ) + override fun getPageTitle(position: Int): String = context.getString(pagerData[position].title) } + +data class PagerData( + val fragmentConstructor: KFunction0, + val title: Int +) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/ZimManageActivity.kt b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/ZimManageActivity.kt index bfcc6fd77..f8c419bf8 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/ZimManageActivity.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/ZimManageActivity.kt @@ -19,7 +19,6 @@ package org.kiwix.kiwixmobile.zim_manager import android.content.Intent import android.os.Bundle -import android.provider.Settings.System import android.view.Menu import android.view.MenuItem import androidx.appcompat.widget.SearchView @@ -31,9 +30,7 @@ import org.kiwix.kiwixmobile.R import org.kiwix.kiwixmobile.core.base.BaseActivity import org.kiwix.kiwixmobile.core.dao.NewLanguagesDao import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.start -import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.startWithActionFrom import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.viewModel -import org.kiwix.kiwixmobile.core.main.CoreMainActivity import org.kiwix.kiwixmobile.core.utils.LanguageUtils import org.kiwix.kiwixmobile.kiwixActivityComponent import org.kiwix.kiwixmobile.language.LanguageActivity @@ -46,7 +43,7 @@ class ZimManageActivity : BaseActivity() { private val zimManageViewModel by lazy { viewModel(viewModelFactory) } private val mSectionsPagerAdapter: SectionsPagerAdapter by lazy { - SectionsPagerAdapter(this, supportFragmentManager) + SectionsPagerAdapter(this, fm = supportFragmentManager) } private var searchItem: MenuItem? = null @@ -68,7 +65,7 @@ class ZimManageActivity : BaseActivity() { setUpToolbar() manageViewPager.run { adapter = mSectionsPagerAdapter - offscreenPageLimit = 2 + offscreenPageLimit = mSectionsPagerAdapter.count - 1 tabs.setupWithViewPager(this) addOnPageChangeListener(SimplePageChangeListener(::updateMenu)) } @@ -105,24 +102,14 @@ class ZimManageActivity : BaseActivity() { } } - override fun onBackPressed() { - val value = System.getInt(contentResolver, System.ALWAYS_FINISH_ACTIVITIES, 0) - if (value == 1) { - startWithActionFrom() - } else { - super.onBackPressed() // optional depending on your needs - } - } - override fun onCreateOptionsMenu(menu: Menu): Boolean { // Inflate the menu; this adds items to the action bar if it is present. menuInflater.inflate(R.menu.menu_zim_manager, menu) searchItem = menu.findItem(R.id.action_search) languageItem = menu.findItem(R.id.select_language) getZimItem = menu.findItem(R.id.get_zim_nearby_device) - val searchView = searchItem!!.actionView as SearchView updateMenu(manageViewPager.currentItem) - searchView.setOnQueryTextListener( + (searchItem?.actionView as? SearchView)?.setOnQueryTextListener( SimpleTextListener(zimManageViewModel.requestFiltering::onNext) ) return true diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/download_view/DownloadAdapter.kt b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/download_view/DownloadAdapter.kt deleted file mode 100644 index c9df76dba..000000000 --- a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/download_view/DownloadAdapter.kt +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Kiwix Android - * Copyright (c) 2019 Kiwix - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ -package org.kiwix.kiwixmobile.zim_manager.download_view - -import android.view.ViewGroup -import androidx.recyclerview.widget.RecyclerView -import org.kiwix.kiwixmobile.R -import org.kiwix.kiwixmobile.core.downloader.model.DownloadItem -import org.kiwix.kiwixmobile.core.extensions.ViewGroupExtensions.inflate - -class DownloadAdapter(private val itemClickListener: (DownloadItem) -> Unit) : - RecyclerView.Adapter() { - - init { - setHasStableIds(true) - } - - var itemList: List = mutableListOf() - set(value) { - field = value - notifyDataSetChanged() - } - - override fun getItemId(position: Int) = itemList[position].downloadId - - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ) = DownloadViewHolder( - parent.inflate( - R.layout.download_item, - false - ) - ) - - override fun getItemCount() = itemList.size - - override fun onBindViewHolder( - holder: DownloadViewHolder, - position: Int - ) { - holder.bind(itemList[position], itemClickListener) - } -} diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/download_view/DownloadFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/download_view/DownloadFragment.kt deleted file mode 100644 index b7c11b85b..000000000 --- a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/download_view/DownloadFragment.kt +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Kiwix Android - * Copyright (c) 2019 Kiwix - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ -package org.kiwix.kiwixmobile.zim_manager.download_view - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.lifecycle.Observer -import androidx.lifecycle.ViewModelProvider -import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView -import kotlinx.android.synthetic.main.layout_download_management.download_management_no_downloads -import kotlinx.android.synthetic.main.layout_download_management.zim_downloader_list -import org.kiwix.kiwixmobile.R -import org.kiwix.kiwixmobile.core.base.BaseActivity -import org.kiwix.kiwixmobile.core.base.BaseFragment -import org.kiwix.kiwixmobile.core.downloader.Downloader -import org.kiwix.kiwixmobile.core.downloader.model.DownloadItem -import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.viewModel -import org.kiwix.kiwixmobile.core.utils.DialogShower -import org.kiwix.kiwixmobile.core.utils.KiwixDialog.YesNoDialog.StopDownload -import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil -import org.kiwix.kiwixmobile.zim_manager.ZimManageActivity -import org.kiwix.kiwixmobile.zim_manager.ZimManageViewModel -import javax.inject.Inject - -class DownloadFragment : BaseFragment() { - - @Inject lateinit var viewModelFactory: ViewModelProvider.Factory - @Inject lateinit var dialogShower: DialogShower - @Inject lateinit var sharedPreferenceUtil: SharedPreferenceUtil - @Inject lateinit var downloader: Downloader - - private val zimManageViewModel by lazy { - activity!!.viewModel(viewModelFactory) - } - - private val downloadAdapter = DownloadAdapter { - dialogShower.show(StopDownload, { downloader.cancelDownload(it) }) - } - - override fun inject(baseActivity: BaseActivity) { - (baseActivity as ZimManageActivity).cachedComponent.inject(this) - } - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View = - inflater.inflate(R.layout.layout_download_management, container, false) - - override fun onViewCreated( - view: View, - savedInstanceState: Bundle? - ) { - super.onViewCreated(view, savedInstanceState) - zim_downloader_list.run { - adapter = downloadAdapter - layoutManager = LinearLayoutManager(context, RecyclerView.VERTICAL, false) - setHasFixedSize(true) - } - zimManageViewModel.downloadItems.observe(this, Observer { - onDownloadItemsUpdate(it!!) - }) - } - - private fun onDownloadItemsUpdate(items: List) { - downloadAdapter.itemList = items - updateNoDownloads(items) - } - - private fun updateNoDownloads(downloadItems: List) { - download_management_no_downloads.visibility = - if (downloadItems.isEmpty()) View.VISIBLE - else View.GONE - } -} diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/download_view/DownloadViewHolder.kt b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/download_view/DownloadViewHolder.kt deleted file mode 100644 index 6235838c5..000000000 --- a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/download_view/DownloadViewHolder.kt +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Kiwix Android - * Copyright (c) 2019 Kiwix - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ -package org.kiwix.kiwixmobile.zim_manager.download_view - -import android.view.View -import androidx.recyclerview.widget.RecyclerView -import kotlinx.android.extensions.LayoutContainer -import kotlinx.android.synthetic.main.download_item.description -import kotlinx.android.synthetic.main.download_item.downloadProgress -import kotlinx.android.synthetic.main.download_item.downloadState -import kotlinx.android.synthetic.main.download_item.eta -import kotlinx.android.synthetic.main.download_item.favicon -import kotlinx.android.synthetic.main.download_item.stop -import kotlinx.android.synthetic.main.download_item.title -import org.kiwix.kiwixmobile.core.downloader.model.DownloadItem -import org.kiwix.kiwixmobile.core.extensions.setBitmap - -class DownloadViewHolder(override val containerView: View) : RecyclerView.ViewHolder(containerView), - LayoutContainer { - fun bind( - downloadItem: DownloadItem, - itemClickListener: (DownloadItem) -> Unit - ) { - favicon.setBitmap(downloadItem.favIcon) - title.text = downloadItem.title - description.text = downloadItem.description - downloadProgress.progress = downloadItem.progress - stop.setOnClickListener { - itemClickListener.invoke(downloadItem) - } - downloadState.text = downloadItem.downloadState.toReadableState(containerView.context) - eta.text = downloadItem.readableEta - } -} diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/LibraryFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/LibraryFragment.kt index 1dcb84ed5..d49593bfb 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/LibraryFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/LibraryFragment.kt @@ -45,6 +45,7 @@ import org.kiwix.kiwixmobile.core.extensions.toast import org.kiwix.kiwixmobile.core.settings.StorageCalculator import org.kiwix.kiwixmobile.core.utils.BookUtils import org.kiwix.kiwixmobile.core.utils.DialogShower +import org.kiwix.kiwixmobile.core.utils.KiwixDialog.YesNoDialog.StopDownload import org.kiwix.kiwixmobile.core.utils.KiwixDialog.YesNoDialog.WifiOnly import org.kiwix.kiwixmobile.core.utils.NetworkUtils import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil @@ -57,6 +58,7 @@ import org.kiwix.kiwixmobile.zim_manager.ZimManageViewModel import org.kiwix.kiwixmobile.zim_manager.library_view.adapter.LibraryAdapter import org.kiwix.kiwixmobile.zim_manager.library_view.adapter.LibraryDelegate.BookDelegate import org.kiwix.kiwixmobile.zim_manager.library_view.adapter.LibraryDelegate.DividerDelegate +import org.kiwix.kiwixmobile.zim_manager.library_view.adapter.LibraryDelegate.DownloadDelegate import org.kiwix.kiwixmobile.zim_manager.library_view.adapter.LibraryListItem import org.kiwix.kiwixmobile.zim_manager.library_view.adapter.LibraryListItem.BookItem import java.io.File @@ -78,7 +80,11 @@ class LibraryFragment : BaseFragment() { private val libraryAdapter: LibraryAdapter by lazy { LibraryAdapter( - BookDelegate(bookUtils, ::onBookItemClick), DividerDelegate + BookDelegate(bookUtils, ::onBookItemClick), + DownloadDelegate { + dialogShower.show(StopDownload, { downloader.cancelDownload(it.downloadId) }) + }, + DividerDelegate ) } diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/adapter/LibraryDelegate.kt b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/adapter/LibraryDelegate.kt index 1ddf7de13..f85c9c3e0 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/adapter/LibraryDelegate.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/adapter/LibraryDelegate.kt @@ -19,11 +19,13 @@ package org.kiwix.kiwixmobile.zim_manager.library_view.adapter import android.view.ViewGroup import org.kiwix.kiwixmobile.R +import org.kiwix.kiwixmobile.core.base.adapter.AbsDelegateAdapter import org.kiwix.kiwixmobile.core.extensions.ViewGroupExtensions.inflate import org.kiwix.kiwixmobile.core.utils.BookUtils -import org.kiwix.kiwixmobile.core.base.adapter.AbsDelegateAdapter import org.kiwix.kiwixmobile.zim_manager.library_view.adapter.LibraryListItem.BookItem import org.kiwix.kiwixmobile.zim_manager.library_view.adapter.LibraryListItem.DividerItem +import org.kiwix.kiwixmobile.zim_manager.library_view.adapter.LibraryListItem.LibraryDownloadItem +import org.kiwix.kiwixmobile.zim_manager.library_view.adapter.LibraryViewHolder.DownloadViewHolder import org.kiwix.kiwixmobile.zim_manager.library_view.adapter.LibraryViewHolder.LibraryBookViewHolder import org.kiwix.kiwixmobile.zim_manager.library_view.adapter.LibraryViewHolder.LibraryDividerViewHolder @@ -44,6 +46,14 @@ sealed class LibraryDelegate> ) } + class DownloadDelegate(private val clickAction: (LibraryDownloadItem) -> Unit) : + LibraryDelegate() { + override val itemClass = LibraryDownloadItem::class.java + + override fun createViewHolder(parent: ViewGroup) = + DownloadViewHolder(parent.inflate(R.layout.item_download, false), clickAction) + } + object DividerDelegate : LibraryDelegate() { override val itemClass = DividerItem::class.java diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/adapter/LibraryListItem.kt b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/adapter/LibraryListItem.kt index 514452ecc..429eeaf35 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/adapter/LibraryListItem.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/adapter/LibraryListItem.kt @@ -18,6 +18,10 @@ package org.kiwix.kiwixmobile.zim_manager.library_view.adapter +import org.kiwix.kiwixmobile.core.downloader.model.Base64String +import org.kiwix.kiwixmobile.core.downloader.model.DownloadModel +import org.kiwix.kiwixmobile.core.downloader.model.DownloadState +import org.kiwix.kiwixmobile.core.downloader.model.Seconds import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity.Book import org.kiwix.kiwixmobile.core.zim_manager.KiwixTag import org.kiwix.kiwixmobile.zim_manager.Fat32Checker @@ -53,4 +57,32 @@ sealed class LibraryListItem { size.toLongOrNull() ?: 0L < Fat32Checker.FOUR_GIGABYTES_IN_KILOBYTES } } + + data class LibraryDownloadItem( + val downloadId: Long, + val favIcon: Base64String, + val title: String, + val description: String, + val bytesDownloaded: Long, + val totalSizeBytes: Long, + val progress: Int, + val eta: Seconds, + val downloadState: DownloadState, + override val id: Long = downloadId + ) : LibraryListItem() { + + val readableEta: CharSequence = eta.takeIf { it.seconds > 0L }?.toHumanReadableTime() ?: "" + + constructor(downloadModel: DownloadModel) : this( + downloadModel.downloadId, + Base64String(downloadModel.book.favicon), + downloadModel.book.title, + downloadModel.book.description, + downloadModel.bytesDownloaded, + downloadModel.totalSizeOfDownload, + downloadModel.progress, + Seconds(downloadModel.etaInMilliSeconds / 1000L), + DownloadState.from(downloadModel.state, downloadModel.error) + ) + } } diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/adapter/LibraryViewHolder.kt b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/adapter/LibraryViewHolder.kt index 6cad8282f..60eb7c4fe 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/adapter/LibraryViewHolder.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/adapter/LibraryViewHolder.kt @@ -23,16 +23,23 @@ import android.view.View import android.view.View.MeasureSpec import android.widget.Toast import androidx.annotation.StringRes -import kotlinx.android.synthetic.main.item_library.creator -import kotlinx.android.synthetic.main.item_library.date -import kotlinx.android.synthetic.main.item_library.description -import kotlinx.android.synthetic.main.item_library.favicon -import kotlinx.android.synthetic.main.item_library.fileName -import kotlinx.android.synthetic.main.item_library.language -import kotlinx.android.synthetic.main.item_library.publisher -import kotlinx.android.synthetic.main.item_library.size +import kotlinx.android.synthetic.main.item_download.downloadProgress +import kotlinx.android.synthetic.main.item_download.downloadState +import kotlinx.android.synthetic.main.item_download.eta +import kotlinx.android.synthetic.main.item_download.libraryDownloadDescription +import kotlinx.android.synthetic.main.item_download.libraryDownloadFavicon +import kotlinx.android.synthetic.main.item_download.libraryDownloadTitle +import kotlinx.android.synthetic.main.item_download.stop +import kotlinx.android.synthetic.main.item_library.libraryBookCreator +import kotlinx.android.synthetic.main.item_library.libraryBookDate +import kotlinx.android.synthetic.main.item_library.libraryBookDescription +import kotlinx.android.synthetic.main.item_library.libraryBookFavicon +import kotlinx.android.synthetic.main.item_library.libraryBookFileName +import kotlinx.android.synthetic.main.item_library.libraryBookLanguage +import kotlinx.android.synthetic.main.item_library.libraryBookPublisher +import kotlinx.android.synthetic.main.item_library.libraryBookSize +import kotlinx.android.synthetic.main.item_library.libraryBookTitle import kotlinx.android.synthetic.main.item_library.tags -import kotlinx.android.synthetic.main.item_library.title import kotlinx.android.synthetic.main.item_library.unableToDownload import kotlinx.android.synthetic.main.library_divider.divider_text import org.kiwix.kiwixmobile.R @@ -48,6 +55,7 @@ import org.kiwix.kiwixmobile.zim_manager.Fat32Checker.FileSystemState.CannotWrit import org.kiwix.kiwixmobile.zim_manager.Fat32Checker.FileSystemState.Unknown import org.kiwix.kiwixmobile.zim_manager.library_view.adapter.LibraryListItem.BookItem import org.kiwix.kiwixmobile.zim_manager.library_view.adapter.LibraryListItem.DividerItem +import org.kiwix.kiwixmobile.zim_manager.library_view.adapter.LibraryListItem.LibraryDownloadItem sealed class LibraryViewHolder(containerView: View) : BaseViewHolder(containerView) { @@ -58,15 +66,15 @@ sealed class LibraryViewHolder(containerView: View) : private val clickAction: (BookItem) -> Unit ) : LibraryViewHolder(view) { override fun bind(item: BookItem) { - title.setTextAndVisibility(item.book.title) - description.setTextAndVisibility(item.book.description) - creator.setTextAndVisibility(item.book.creator) - publisher.setTextAndVisibility(item.book.publisher) - date.setTextAndVisibility(item.book.date) - size.setTextAndVisibility(KiloByte(item.book.size).humanReadable) - language.text = bookUtils.getLanguage(item.book.getLanguage()) - fileName.text = NetworkUtils.parseURL(CoreApp.getInstance(), item.book.url) - favicon.setBitmap(Base64String(item.book.favicon)) + libraryBookTitle.setTextAndVisibility(item.book.title) + libraryBookDescription.setTextAndVisibility(item.book.description) + libraryBookCreator.setTextAndVisibility(item.book.creator) + libraryBookPublisher.setTextAndVisibility(item.book.publisher) + libraryBookDate.setTextAndVisibility(item.book.date) + libraryBookSize.setTextAndVisibility(KiloByte(item.book.size).humanReadable) + libraryBookLanguage.text = bookUtils.getLanguage(item.book.getLanguage()) + libraryBookFileName.text = NetworkUtils.parseURL(CoreApp.getInstance(), item.book.url) + libraryBookFavicon.setBitmap(Base64String(item.book.favicon)) containerView.setOnClickListener { clickAction.invoke(item) } containerView.isClickable = item.canBeDownloaded @@ -87,6 +95,20 @@ sealed class LibraryViewHolder(containerView: View) : } } + class DownloadViewHolder(view: View, private val clickAction: (LibraryDownloadItem) -> Unit) : + LibraryViewHolder(view) { + + override fun bind(item: LibraryDownloadItem) { + libraryDownloadFavicon.setBitmap(item.favIcon) + libraryDownloadTitle.text = item.title + libraryDownloadDescription.text = item.description + downloadProgress.progress = item.progress + stop.setOnClickListener { clickAction.invoke(item) } + downloadState.text = item.downloadState.toReadableState(containerView.context) + eta.text = item.readableEta + } + } + class LibraryDividerViewHolder(view: View) : LibraryViewHolder(view) { override fun bind(item: DividerItem) { divider_text.text = item.text diff --git a/app/src/main/res/layout/download_item.xml b/app/src/main/res/layout/item_download.xml similarity index 93% rename from app/src/main/res/layout/download_item.xml rename to app/src/main/res/layout/item_download.xml index 058c8fc8a..86eaa9565 100644 --- a/app/src/main/res/layout/download_item.xml +++ b/app/src/main/res/layout/item_download.xml @@ -11,7 +11,7 @@ android:paddingRight="@dimen/activity_horizontal_margin"> + android:src="@mipmap/ic_launcher" + tools:ignore="RtlHardcoded" /> + app:layout_constraintStart_toStartOf="@+id/libraryBookTitle" + app:layout_constraintTop_toBottomOf="@id/libraryBookFileName" /> - - - - - - - diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/DownloadRequester.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/DownloadRequester.kt index ca8a4c58a..cf41124ab 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/DownloadRequester.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/DownloadRequester.kt @@ -17,10 +17,9 @@ */ package org.kiwix.kiwixmobile.core.downloader -import org.kiwix.kiwixmobile.core.downloader.model.DownloadItem import org.kiwix.kiwixmobile.core.downloader.model.DownloadRequest interface DownloadRequester { fun enqueue(downloadRequest: DownloadRequest): Long - fun cancel(downloadItem: DownloadItem) + fun cancel(downloadId: Long) } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/Downloader.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/Downloader.kt index 2942b6a72..53f5c4d5a 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/Downloader.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/Downloader.kt @@ -18,9 +18,8 @@ package org.kiwix.kiwixmobile.core.downloader import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity -import org.kiwix.kiwixmobile.core.downloader.model.DownloadItem interface Downloader { fun download(book: LibraryNetworkEntity.Book) - fun cancelDownload(downloadItem: DownloadItem) + fun cancelDownload(downloadId: Long) } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/DownloaderImpl.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/DownloaderImpl.kt index 20fa3ffc1..7483d0be0 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/DownloaderImpl.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/DownloaderImpl.kt @@ -21,7 +21,6 @@ package org.kiwix.kiwixmobile.core.downloader import io.reactivex.Observable import org.kiwix.kiwixmobile.core.dao.FetchDownloadDao import org.kiwix.kiwixmobile.core.data.remote.KiwixService -import org.kiwix.kiwixmobile.core.downloader.model.DownloadItem import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity.Book import javax.inject.Inject @@ -47,7 +46,7 @@ class DownloaderImpl @Inject constructor( if (book.url.endsWith("meta4")) kiwixService.getMetaLinks(book.url).map { it.relevantUrl.value } else Observable.just(book.url) - override fun cancelDownload(downloadItem: DownloadItem) { - downloadRequester.cancel(downloadItem) + override fun cancelDownload(downloadId: Long) { + downloadRequester.cancel(downloadId) } } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/fetch/FetchDownloadRequester.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/fetch/FetchDownloadRequester.kt index 9208ceee2..b53d77e52 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/fetch/FetchDownloadRequester.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/fetch/FetchDownloadRequester.kt @@ -22,7 +22,6 @@ import com.tonyodev.fetch2.NetworkType.ALL import com.tonyodev.fetch2.NetworkType.WIFI_ONLY import com.tonyodev.fetch2.Request import org.kiwix.kiwixmobile.core.downloader.DownloadRequester -import org.kiwix.kiwixmobile.core.downloader.model.DownloadItem import org.kiwix.kiwixmobile.core.downloader.model.DownloadRequest import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil import javax.inject.Inject @@ -38,8 +37,8 @@ class FetchDownloadRequester @Inject constructor( return request.id.toLong() } - override fun cancel(downloadItem: DownloadItem) { - fetch.delete(downloadItem.downloadId.toInt()) + override fun cancel(downloadId: Long) { + fetch.delete(downloadId.toInt()) } } From 44c1952604504a0bb3e786f4c8c6044b3703e0e5 Mon Sep 17 00:00:00 2001 From: Sean Mac Gillicuddy Date: Tue, 7 Jan 2020 16:33:55 +0000 Subject: [PATCH 2/5] #716 Merge library tabs "Device" & "Downloading" - render downloads in library --- .../zim_manager/ZimManageViewModel.kt | 75 ++++++++----------- .../library_view/LibraryFragment.kt | 7 +- .../library_view/adapter/LibraryListItem.kt | 5 +- 3 files changed, 37 insertions(+), 50 deletions(-) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/ZimManageViewModel.kt b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/ZimManageViewModel.kt index 7cce3e810..7574ffb04 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/ZimManageViewModel.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/ZimManageViewModel.kt @@ -38,7 +38,6 @@ import org.kiwix.kiwixmobile.core.dao.NewBookDao import org.kiwix.kiwixmobile.core.dao.NewLanguagesDao import org.kiwix.kiwixmobile.core.data.DataSource import org.kiwix.kiwixmobile.core.data.remote.KiwixService -import org.kiwix.kiwixmobile.core.downloader.model.DownloadItem import org.kiwix.kiwixmobile.core.downloader.model.DownloadModel import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity.Book @@ -67,6 +66,7 @@ import org.kiwix.kiwixmobile.zim_manager.fileselect_view.effects.StartMultiSelec import org.kiwix.kiwixmobile.zim_manager.library_view.adapter.LibraryListItem import org.kiwix.kiwixmobile.zim_manager.library_view.adapter.LibraryListItem.BookItem import org.kiwix.kiwixmobile.zim_manager.library_view.adapter.LibraryListItem.DividerItem +import org.kiwix.kiwixmobile.zim_manager.library_view.adapter.LibraryListItem.LibraryDownloadItem import java.util.LinkedList import java.util.Locale import java.util.concurrent.TimeUnit.MILLISECONDS @@ -97,7 +97,6 @@ class ZimManageViewModel @Inject constructor( val sideEffects = PublishProcessor.create>() val libraryItems: MutableLiveData> = MutableLiveData() - val downloadItems: MutableLiveData> = MutableLiveData() val fileSelectListStates: MutableLiveData = MutableLiveData() val deviceListIsRefreshing = MutableLiveData() val libraryListIsRefreshing = MutableLiveData() @@ -132,7 +131,6 @@ class ZimManageViewModel @Inject constructor( val networkLibrary = PublishProcessor.create() val languages = languageDao.languages() return arrayOf( - updateDownloadItems(downloads), updateBookItems(), checkFileSystemForBooksOnRequest(booksFromDao), updateLibraryItems(booksFromDao, downloads, networkLibrary, languages), @@ -343,64 +341,65 @@ class ZimManageViewModel @Inject constructor( filter: String, fileSystemState: FileSystemState ): List { - val downloadedBooksIds = booksOnFileSystem.map { it.book.id } - val downloadingBookIds = activeDownloads.map { it.book.id } val activeLanguageCodes = allLanguages.filter(Language::active) .map(Language::languageCode) val booksUnfilteredByLanguage = - applyUserFilter( - libraryNetworkEntity.books - .filterNot { downloadedBooksIds.contains(it.id) } - .filterNot { downloadingBookIds.contains(it.id) }, + applySearchFilter( + libraryNetworkEntity.books - booksOnFileSystem.map(BookOnDisk::book), filter ) - return listOf( - *createLibrarySection( - booksUnfilteredByLanguage.filter { activeLanguageCodes.contains(it.language) }, - fileSystemState, - R.string.your_languages, - Long.MAX_VALUE - ), - *createLibrarySection( - booksUnfilteredByLanguage.filterNot { activeLanguageCodes.contains(it.language) }, + val booksWithActiveLanguages = + booksUnfilteredByLanguage.filter { activeLanguageCodes.contains(it.language) } + return createLibrarySection( + booksWithActiveLanguages, + activeDownloads, + fileSystemState, + R.string.your_languages, + Long.MAX_VALUE + ) + + createLibrarySection( + booksUnfilteredByLanguage - booksWithActiveLanguages, + activeDownloads, fileSystemState, R.string.other_languages, Long.MIN_VALUE ) - ) } private fun createLibrarySection( books: List, + activeDownloads: List, fileSystemState: FileSystemState, sectionStringId: Int, sectionId: Long ) = if (books.isNotEmpty()) - arrayOf( - DividerItem(sectionId, context.getString(sectionStringId)), - *toBookItems(books, fileSystemState) - ) - else emptyArray() + listOf(DividerItem(sectionId, context.getString(sectionStringId))) + + books.asLibraryItems(activeDownloads, fileSystemState) + else emptyList() - private fun applyUserFilter( - booksUnfilteredByLanguage: List, + private fun applySearchFilter( + unDownloadedBooks: List, filter: String ) = if (filter.isEmpty()) { - booksUnfilteredByLanguage + unDownloadedBooks } else { - booksUnfilteredByLanguage.forEach { it.calculateSearchMatches(filter, bookUtils) } - booksUnfilteredByLanguage.filter { it.searchMatches > 0 } + unDownloadedBooks.forEach { it.calculateSearchMatches(filter, bookUtils) } + unDownloadedBooks.filter { it.searchMatches > 0 } } - private fun toBookItems( - books: List, + private fun List.asLibraryItems( + activeDownloads: List, fileSystemState: FileSystemState - ) = - books.map { BookItem(it, fileSystemState) }.toTypedArray() + ) = map { book -> + activeDownloads.firstOrNull { download -> download.book == book } + ?.let(::LibraryDownloadItem) + ?: BookItem(book, fileSystemState) + } - private fun checkFileSystemForBooksOnRequest(booksFromDao: Flowable>) = + private fun checkFileSystemForBooksOnRequest(booksFromDao: Flowable>): + Disposable = requestFileSystemCheck .subscribeOn(Schedulers.io()) .observeOn(Schedulers.io()) @@ -462,12 +461,4 @@ class ZimManageViewModel @Inject constructor( newBookOnDisk.apply { isSelected = firstOrNull?.isSelected ?: false } }) } - - private fun updateDownloadItems(downloadModels: Flowable>) = - downloadModels - .map { it.map(::DownloadItem) } - .subscribe( - downloadItems::postValue, - Throwable::printStackTrace - ) } diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/LibraryFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/LibraryFragment.kt index d49593bfb..10913c4d3 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/LibraryFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/LibraryFragment.kt @@ -49,7 +49,6 @@ import org.kiwix.kiwixmobile.core.utils.KiwixDialog.YesNoDialog.StopDownload import org.kiwix.kiwixmobile.core.utils.KiwixDialog.YesNoDialog.WifiOnly import org.kiwix.kiwixmobile.core.utils.NetworkUtils import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil -import org.kiwix.kiwixmobile.core.utils.TestingUtils import org.kiwix.kiwixmobile.zim_manager.NetworkState import org.kiwix.kiwixmobile.zim_manager.NetworkState.CONNECTED import org.kiwix.kiwixmobile.zim_manager.NetworkState.NOT_CONNECTED @@ -104,10 +103,7 @@ class LibraryFragment : BaseFragment() { inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? - ): View? { - TestingUtils.bindResource(LibraryFragment::class.java) - return inflater.inflate(R.layout.activity_library, container, false) - } + ): View = inflater.inflate(R.layout.activity_library, container, false) override fun onViewCreated( view: View, @@ -154,7 +150,6 @@ class LibraryFragment : BaseFragment() { else string.no_items_msg ) libraryErrorText.visibility = VISIBLE - TestingUtils.unbindResource(LibraryFragment::class.java) } else { libraryErrorText.visibility = GONE } diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/adapter/LibraryListItem.kt b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/adapter/LibraryListItem.kt index 429eeaf35..b9884f7e5 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/adapter/LibraryListItem.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/library_view/adapter/LibraryListItem.kt @@ -68,7 +68,7 @@ sealed class LibraryListItem { val progress: Int, val eta: Seconds, val downloadState: DownloadState, - override val id: Long = downloadId + override val id: Long ) : LibraryListItem() { val readableEta: CharSequence = eta.takeIf { it.seconds > 0L }?.toHumanReadableTime() ?: "" @@ -82,7 +82,8 @@ sealed class LibraryListItem { downloadModel.totalSizeOfDownload, downloadModel.progress, Seconds(downloadModel.etaInMilliSeconds / 1000L), - DownloadState.from(downloadModel.state, downloadModel.error) + DownloadState.from(downloadModel.state, downloadModel.error), + downloadModel.book.id.hashCode().toLong() ) } } From 96321bc5e67d7049ca8668a24d3a390b40eb574a Mon Sep 17 00:00:00 2001 From: Sean Mac Gillicuddy Date: Tue, 7 Jan 2020 16:56:31 +0000 Subject: [PATCH 3/5] #716 Merge library tabs "Device" & "Downloading" - amend tests for new flow --- .../zim_manager/ZimManageActivityTest.kt | 20 +++++-------- .../kiwixmobile/zim_manager/ZimManageRobot.kt | 24 +++------------ .../zim_manager/ZimManageViewModelTest.kt | 29 ++----------------- 3 files changed, 13 insertions(+), 60 deletions(-) diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/zim_manager/ZimManageActivityTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/zim_manager/ZimManageActivityTest.kt index 650897006..9a354edc2 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/zim_manager/ZimManageActivityTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/zim_manager/ZimManageActivityTest.kt @@ -63,20 +63,13 @@ class ZimManageActivityTest : BaseActivityTest() { forceResponse("012345678901234567890123456789012345678901234567890123456789012345678") attempt(10) { clickOn(book) - waitForEmptyView() + clickStop() + clickNegativeDialogButton() + clickStop() + clickPositiveDialogButton() } - } - clickOnDownloading { - clickStop() - clickNegativeDialogButton() - clickStop() - clickPositiveDialogButton() - } - clickOnOnline { forceResponse("01234") clickOn(book) - } - clickOnDownloading { waitForEmptyView() } clickOnDevice { @@ -90,8 +83,9 @@ class ZimManageActivityTest : BaseActivityTest() { clickPositiveDialogButton() waitForEmptyView() } - clickOnOnline { } - } clickOnLanguageIcon { } + clickOnOnline { + } clickOnLanguageIcon { } + } } private fun forceResponse(body: String) { diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/zim_manager/ZimManageRobot.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/zim_manager/ZimManageRobot.kt index 25f68185a..5b10d711d 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/zim_manager/ZimManageRobot.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/zim_manager/ZimManageRobot.kt @@ -42,22 +42,11 @@ class ZimManageRobot : BaseRobot() { return library(func) } - fun clickOnDownloading(func: DownloadRobot.() -> Unit): DownloadRobot { - clickOnTab(R.string.zim_downloads) - return download(func) - } - fun clickOnDevice(func: DeviceRobot.() -> Unit): DeviceRobot { clickOnTab(R.string.local_zims) return device(func) } - infix fun clickOnLanguageIcon(function: LanguageRobot.() -> Unit): LanguageRobot { - TextId(R.string.remote_zims) - clickOn(ViewId(R.id.select_language)) - return language(function) - } - private fun library(func: LibraryRobot.() -> Unit) = LibraryRobot().apply(func) inner class LibraryRobot : BaseRobot() { init { @@ -79,20 +68,15 @@ class ZimManageRobot : BaseRobot() { fun waitForEmptyView() { isVisible(ViewId(R.id.libraryErrorText), VERY_LONG_WAIT) } - } - - private fun download(func: DownloadRobot.() -> Unit) = DownloadRobot().apply(func) - inner class DownloadRobot : BaseRobot() { - init { - isVisible(ViewId(R.id.zim_download_root)) - } fun clickStop() { clickOn(ViewId(R.id.stop), LONG_WAIT) } - fun waitForEmptyView() { - isVisible(ViewId(R.id.download_management_no_downloads), 11000L) + infix fun clickOnLanguageIcon(function: LanguageRobot.() -> Unit): LanguageRobot { + TextId(R.string.remote_zims) + clickOn(ViewId(R.id.select_language)) + return language(function) } } diff --git a/app/src/test/java/org/kiwix/kiwixmobile/zim_manager/ZimManageViewModelTest.kt b/app/src/test/java/org/kiwix/kiwixmobile/zim_manager/ZimManageViewModelTest.kt index 442b0722b..2451d83a8 100644 --- a/app/src/test/java/org/kiwix/kiwixmobile/zim_manager/ZimManageViewModelTest.kt +++ b/app/src/test/java/org/kiwix/kiwixmobile/zim_manager/ZimManageViewModelTest.kt @@ -56,7 +56,6 @@ import org.kiwix.kiwixmobile.zim_manager.library_view.adapter.LibraryListItem import org.kiwix.sharedFunctions.InstantExecutorExtension import org.kiwix.sharedFunctions.book import org.kiwix.sharedFunctions.bookOnDisk -import org.kiwix.sharedFunctions.downloadItem import org.kiwix.sharedFunctions.downloadModel import org.kiwix.sharedFunctions.language import org.kiwix.sharedFunctions.libraryNetworkEntity @@ -64,7 +63,6 @@ import org.kiwix.sharedFunctions.resetSchedulers import org.kiwix.sharedFunctions.setScheduler import java.util.Locale import java.util.concurrent.TimeUnit.MILLISECONDS -import java.util.concurrent.TimeUnit.SECONDS @ExtendWith(InstantExecutorExtension::class) class ZimManageViewModelTest { @@ -149,29 +147,6 @@ class ZimManageViewModelTest { } } - @Nested - inner class Downloads { - @Test - fun `on emission from database render downloads`() { - expectDownloads() - viewModel.downloadItems - .test() - .assertValue(listOf(downloadItem())) - } - - private fun expectDownloads( - expectedDownloads: List = listOf( - downloadModel() - ) - ) { - every { application.getString(any()) } returns "" - downloads.offer(expectedDownloads) - testScheduler.triggerActions() - testScheduler.advanceTimeBy(1, SECONDS) - testScheduler.triggerActions() - } - } - @Nested inner class Books { @Test @@ -344,7 +319,7 @@ class ZimManageViewModelTest { } @Test - fun `library update removes from sources`() { + fun `library update removes from sources and maps to list items`() { every { application.getString(R.string.your_languages) } returns "1" every { application.getString(R.string.other_languages) } returns "2" val bookAlreadyOnDisk = book( @@ -394,7 +369,7 @@ class ZimManageViewModelTest { LibraryListItem.DividerItem(Long.MAX_VALUE, "1"), LibraryListItem.BookItem(bookWithActiveLanguage, CanWrite4GbFile), LibraryListItem.DividerItem(Long.MIN_VALUE, "2"), - LibraryListItem.BookItem(bookWithInactiveLanguage, CanWrite4GbFile) + LibraryListItem.LibraryDownloadItem(downloadModel(book = bookDownloading)) ) ) } From 17e22b8f1209b35f9c02e4fa1f08f1a687cd7c39 Mon Sep 17 00:00:00 2001 From: Sean Mac Gillicuddy Date: Tue, 7 Jan 2020 17:15:21 +0000 Subject: [PATCH 4/5] #716 Merge library tabs "Device" & "Downloading" - remove invalid test --- .../java/org/kiwix/kiwixmobile/main/MainActivityTest.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/main/MainActivityTest.java b/app/src/androidTest/java/org/kiwix/kiwixmobile/main/MainActivityTest.java index 35e58e075..9716dd5ca 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/main/MainActivityTest.java +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/main/MainActivityTest.java @@ -81,12 +81,4 @@ public class MainActivityTest { BaristaSleepInteractions.sleep(TEST_PAUSE_MS); clickOn(R.string.remote_zims); } - - @Test - public void navigateDownloadingContent() { - BaristaSleepInteractions.sleep(TEST_PAUSE_MS); - BaristaMenuClickInteractions.clickMenu(getResourceString(R.string.menu_zim_manager)); - BaristaSleepInteractions.sleep(TEST_PAUSE_MS); - clickOn(R.string.zim_downloads); - } } From fa97194627cf7d96f907a9183c6850dc79f812f3 Mon Sep 17 00:00:00 2001 From: Sean Mac Gillicuddy Date: Mon, 13 Jan 2020 09:56:20 +0000 Subject: [PATCH 5/5] #716 get rid of m prefix --- .../org/kiwix/kiwixmobile/zim_manager/ZimManageActivity.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/ZimManageActivity.kt b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/ZimManageActivity.kt index f8c419bf8..9ca914fcc 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/ZimManageActivity.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/ZimManageActivity.kt @@ -42,7 +42,7 @@ class ZimManageActivity : BaseActivity() { val cachedComponent by lazy { kiwixActivityComponent } private val zimManageViewModel by lazy { viewModel(viewModelFactory) } - private val mSectionsPagerAdapter: SectionsPagerAdapter by lazy { + private val sectionsPagerAdapter: SectionsPagerAdapter by lazy { SectionsPagerAdapter(this, fm = supportFragmentManager) } @@ -64,8 +64,8 @@ class ZimManageActivity : BaseActivity() { setUpToolbar() manageViewPager.run { - adapter = mSectionsPagerAdapter - offscreenPageLimit = mSectionsPagerAdapter.count - 1 + adapter = sectionsPagerAdapter + offscreenPageLimit = sectionsPagerAdapter.count - 1 tabs.setupWithViewPager(this) addOnPageChangeListener(SimplePageChangeListener(::updateMenu)) }