Skip to content
This repository has been archived by the owner on Mar 26, 2019. It is now read-only.

Commit

Permalink
add browser option to show media as a list
Browse files Browse the repository at this point in the history
  • Loading branch information
befora committed Aug 27, 2018
1 parent 725fdc2 commit e5ce678
Show file tree
Hide file tree
Showing 24 changed files with 383 additions and 68 deletions.
1 change: 1 addition & 0 deletions app/src/main/java/com/sethchhim/kuboo_client/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ object Constants {
internal const val ARG_TRANSITION_URL = "ARG_TRANSITION_URL"

internal const val KEY_APP_THEME = "KEY_APP_THEME"
internal const val KEY_BROWSER_MEDIA_FORCE_LIST = "KEY_BROWSER_MEDIA_FORCE_LIST"
internal const val KEY_BROWSER_IMMERSIVE = "KEY_BROWSER_IMMERSIVE"
internal const val KEY_DOWNLOAD_SAVE_PATH = "KEY_DOWNLOAD_SAVE_PATH"
internal const val KEY_DOWNLOAD_TRACKING_INTERVAL = "KEY_DOWNLOAD_TRACKING_INTERVAL"
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/com/sethchhim/kuboo_client/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,10 @@ object Extensions {

internal fun Book.getBrowserContentType() =
when (isBrowserMediaType()) {
true -> BrowserContentType.MEDIA
true -> when (Settings.BROWSER_MEDIA_FORCE_LIST) {
true -> BrowserContentType.MEDIA_FORCE_LIST
false -> BrowserContentType.MEDIA
}
false -> BrowserContentType.FOLDER
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/sethchhim/kuboo_client/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ object Settings {
var MARK_FINISHED = false
var PREVIEW = true
var REVERSE_LAYOUT = false
var BROWSER_MEDIA_FORCE_LIST = true

const val SHARED_ELEMENT_TRANSITION_DURATION = 350L //Screen rotation delay before animation.
const val RECYCLER_VIEW_DELAY = 600L
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Browser(var type: Int, var book: Book) : MultiItemEntity {
companion object {
const val FOLDER = 1
const val MEDIA = 2
const val MEDIA_FORCE_LIST = 3
}

override fun getItemType(): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.sethchhim.kuboo_client.data.repository

import android.os.Parcelable
import com.sethchhim.kuboo_client.Extensions.isFileType
import com.sethchhim.kuboo_client.Settings
import com.sethchhim.kuboo_client.data.model.Browser
import com.sethchhim.kuboo_remote.model.Book
import timber.log.Timber
Expand All @@ -15,7 +16,10 @@ class BrowserRepository {
contentList.clear()
list.forEach {
when (it.isFileType()) {
true -> contentList.add(Browser(Browser.MEDIA, it))
true -> when (Settings.BROWSER_MEDIA_FORCE_LIST) {
true -> contentList.add(Browser(Browser.MEDIA_FORCE_LIST, it))
false -> contentList.add(Browser(Browser.MEDIA, it))
}
false -> contentList.add(Browser(Browser.FOLDER, it))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ open class MainActivity : MainActivityImpl3_Service(), BottomNavigationView.OnNa

override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_main, menu)
browserLayoutMenuItem = menu.findItem(R.id.main_action_browser_layout)
downloadMenuItem = menu.findItem(R.id.main_action_download)
httpsMenuItem = menu.findItem(R.id.main_action_https)
markFinishedAddMenuItem = menu.findItem(R.id.main_action_mark_finished_add)
Expand Down Expand Up @@ -189,6 +190,7 @@ open class MainActivity : MainActivityImpl3_Service(), BottomNavigationView.OnNa
when (item.itemId) {
R.id.main_overflow_about -> showActivityAbout()
R.id.main_overflow_log -> showActivityLog()
R.id.main_action_browser_layout -> toggleBrowserLayout()
R.id.main_action_https -> showDialogHttps()
R.id.main_action_download -> startSelectionDownload()
R.id.main_action_mark_finished_add -> startSelectionAddFinished()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.annotation.SuppressLint
import android.content.Intent
import android.support.design.widget.BottomNavigationView
import android.support.v4.app.Fragment
import android.support.v4.content.ContextCompat
import android.support.v7.widget.SearchView
import android.support.v7.widget.Toolbar
import android.view.MenuItem
Expand All @@ -12,10 +13,12 @@ import android.widget.TextView
import butterknife.BindView
import com.sethchhim.kuboo_client.Extensions.show
import com.sethchhim.kuboo_client.R
import com.sethchhim.kuboo_client.Settings
import com.sethchhim.kuboo_client.ui.about.AboutActivity
import com.sethchhim.kuboo_client.ui.base.BaseActivity
import com.sethchhim.kuboo_client.ui.log.LogActivity
import com.sethchhim.kuboo_client.ui.main.browser.*
import com.sethchhim.kuboo_client.ui.main.browser.custom.BrowserContentType
import com.sethchhim.kuboo_client.ui.main.downloads.DownloadsFragment
import com.sethchhim.kuboo_client.ui.main.home.HomeFragment
import com.sethchhim.kuboo_client.ui.main.home.HomeFragmentImpl1_Content
Expand Down Expand Up @@ -50,6 +53,7 @@ open class MainActivityImpl0_View : BaseActivity() {
@BindView(R.id.main_layout_base_toolBar) lateinit var toolbar: Toolbar
@BindView(R.id.main_layout_base_frameLayout) lateinit var frameLayout: FrameLayout

internal lateinit var browserLayoutMenuItem: MenuItem
internal lateinit var downloadMenuItem: MenuItem
internal lateinit var httpsMenuItem: MenuItem
internal lateinit var markFinishedAddMenuItem: MenuItem
Expand All @@ -76,12 +80,14 @@ open class MainActivityImpl0_View : BaseActivity() {
}

internal fun setStateDisconnected(response: Response?) {
hideMenuItemBrowserLayout()
hideMenuItemSearch()
hideMenuItemHttps()
showFragmentFail(response)
}

internal fun setStateLoading() {
hideMenuItemBrowserLayout()
hideMenuItemSearch()
hideMenuItemHttps()
showFragmentLoading()
Expand Down Expand Up @@ -182,6 +188,10 @@ open class MainActivityImpl0_View : BaseActivity() {

protected fun getSelectedBrowserTitle() = "${getString(R.string.main_selected)} (${viewModel.getSelectedListSize()})"

internal fun hideMenuItemBrowserLayout() {
if (::browserLayoutMenuItem.isInitialized && browserLayoutMenuItem.isVisible) browserLayoutMenuItem.isVisible = false
}

protected fun hideMenuItemHttps() {
if (::httpsMenuItem.isInitialized && httpsMenuItem.isVisible) httpsMenuItem.isVisible = false
}
Expand All @@ -192,6 +202,10 @@ open class MainActivityImpl0_View : BaseActivity() {

private fun showFragmentFail(response: Response?) = supportFragmentManager.show(FailFragment.newInstance(response), R.id.main_layout_base_frameLayout)

private fun showMenuItemBrowserLayout() {
if (::browserLayoutMenuItem.isInitialized && !browserLayoutMenuItem.isVisible) browserLayoutMenuItem.isVisible = true
}

private fun showMenuItemHttps() {
if (::httpsMenuItem.isInitialized && !httpsMenuItem.isVisible) httpsMenuItem.isVisible = true
}
Expand All @@ -200,9 +214,38 @@ open class MainActivityImpl0_View : BaseActivity() {
if (::searchMenuItem.isInitialized && !searchMenuItem.isVisible) searchMenuItem.isVisible = true
}

internal fun toggleMenuItemBrowserLayout(browserContentType: BrowserContentType) {
if (::browserLayoutMenuItem.isInitialized) {
when (browserContentType) {
BrowserContentType.MEDIA -> {
browserLayoutMenuItem.icon = ContextCompat.getDrawable(this, R.drawable.ic_view_list_white_24dp)
showMenuItemBrowserLayout()
}
BrowserContentType.MEDIA_FORCE_LIST -> {
browserLayoutMenuItem.icon = ContextCompat.getDrawable(this, R.drawable.ic_view_module_white_24dp)
showMenuItemBrowserLayout()
}
else -> hideMenuItemBrowserLayout()
}
}
}

protected fun toggleMenuItemHttps() = when (viewModel.isConnectedEncrypted()) {
true -> showMenuItemHttps()
false -> hideMenuItemHttps()
}

protected fun toggleBrowserLayout() {
Settings.BROWSER_MEDIA_FORCE_LIST = !Settings.BROWSER_MEDIA_FORCE_LIST
sharedPrefsHelper.saveBrowserMediaForceList()
(getCurrentFragment() as? BrowserBaseFragment)?.let {
it.contentRecyclerView.contentType = when (Settings.BROWSER_MEDIA_FORCE_LIST) {
true -> BrowserContentType.MEDIA_FORCE_LIST
false -> BrowserContentType.MEDIA
}
toggleMenuItemBrowserLayout(it.contentRecyclerView.contentType)
it.onSwipeRefresh()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,16 @@ open class MainActivityImpl2_Selection : MainActivityImpl1_Content() {

private fun resetAllColorState() = (getCurrentFragment() as? BrowserBaseFragment)?.contentAdapter?.resetAllColorState()

private fun getBrowserContentType() = (getCurrentFragment() as? BrowserBaseFragment)?.contentRecyclerView?.contentType

private fun setSelectionMenuStateSelected() {
title = getSelectedBrowserTitle()
downloadMenuItem.visible()
searchMenuItem.gone()
markFinishedDeleteMenuItem.visible()
markFinishedAddMenuItem.visible()

hideMenuItemBrowserLayout()
hideMenuItemHttps()
}

Expand All @@ -106,6 +109,7 @@ open class MainActivityImpl2_Selection : MainActivityImpl1_Content() {
markFinishedDeleteMenuItem.gone()
markFinishedAddMenuItem.gone()

getBrowserContentType()?.let { toggleMenuItemBrowserLayout(it) }
toggleMenuItemHttps()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ open class BrowserBaseFragment : BrowserBaseFragmentImpl1_Content() {
isFirstInstance = false
}

override fun onDestroy() {
super.onDestroy()
mainActivity.hideMenuItemBrowserLayout()
}

override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
setContentSpanCount(newConfig.orientation, contentRecyclerView.contentType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.sethchhim.kuboo_client.Settings
import com.sethchhim.kuboo_client.ui.main.browser.adapter.BrowserContentAdapter
import com.sethchhim.kuboo_client.ui.main.browser.adapter.BrowserPathAdapter
import com.sethchhim.kuboo_client.ui.main.browser.custom.BrowserContentType.MEDIA
import com.sethchhim.kuboo_client.ui.main.browser.custom.BrowserContentType.MEDIA_FORCE_LIST
import com.sethchhim.kuboo_client.ui.main.browser.handler.PaginationHandler
import com.sethchhim.kuboo_remote.model.Book
import com.sethchhim.kuboo_remote.model.Pagination
Expand Down Expand Up @@ -70,7 +71,10 @@ open class BrowserBaseFragmentImpl1_Content : BrowserBaseFragmentImpl0_View() {
}

setStateConnected()
setContentSpanCount(resources.configuration.orientation, book.getBrowserContentType())

val browserContentType = book.getBrowserContentType()
setContentSpanCount(resources.configuration.orientation, browserContentType)
mainActivity.toggleMenuItemBrowserLayout(browserContentType)
populatePaginationLinks(book, newResult)
contentAdapter.update(newResult)
if (loadState) loadRecyclerViewState(book)
Expand Down Expand Up @@ -106,8 +110,15 @@ open class BrowserBaseFragmentImpl1_Content : BrowserBaseFragmentImpl0_View() {
private fun onPopulateMediaSuccess(book: Book?, result: List<Book>) {
Timber.i("onPopulateMediaSuccess result: ${result.size}")
setStateConnected()
setContentSpanCount(resources.configuration.orientation, MEDIA)
book?.let { populatePaginationLinks(it, result) }
setContentSpanCount(resources.configuration.orientation, when (Settings.BROWSER_MEDIA_FORCE_LIST) {
true -> MEDIA_FORCE_LIST
false -> MEDIA
})

book?.let {
populatePaginationLinks(it, result)
mainActivity.toggleMenuItemBrowserLayout(book.getBrowserContentType())
}
contentAdapter.update(result)
}

Expand All @@ -133,4 +144,8 @@ open class BrowserBaseFragmentImpl1_Content : BrowserBaseFragmentImpl0_View() {
}
}

open fun onSwipeRefresh() {
//override in children
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package com.sethchhim.kuboo_client.ui.main.browser
import android.arch.lifecycle.Observer
import android.os.Bundle
import android.view.View
import com.sethchhim.kuboo_client.Constants.URL_PATH_LATEST
import com.sethchhim.kuboo_client.Extensions.gone
import com.sethchhim.kuboo_remote.model.Book

class BrowserLatestFragment : BrowserBaseFragment() {

Expand All @@ -22,9 +24,14 @@ class BrowserLatestFragment : BrowserBaseFragment() {
setStateLoading()
resetRecyclerView()
paginationHandler.reset()
viewModel.getLatestListFromServer().observe(this, Observer { handleMediaResult(null, it) })
viewModel.getLatestListFromServer().observe(this, Observer {
val book = Book().apply { linkSubsection = URL_PATH_LATEST }
handleMediaResult(book, it)
})
}

private fun onSwipeRefresh() = populateLatest()

override fun onSwipeRefresh() {
super.onSwipeRefresh()
populateLatest()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package com.sethchhim.kuboo_client.ui.main.browser
import android.arch.lifecycle.Observer
import android.os.Bundle
import android.view.View
import com.sethchhim.kuboo_client.Constants
import com.sethchhim.kuboo_client.Extensions.gone
import com.sethchhim.kuboo_remote.model.Book

class BrowserRecentFragment : BrowserBaseFragment() {

Expand All @@ -22,9 +24,14 @@ class BrowserRecentFragment : BrowserBaseFragment() {
setStateLoading()
resetRecyclerView()
paginationHandler.reset()
viewModel.getRecentListFromDao().observe(this, Observer { handleMediaResult(null, it) })
viewModel.getRecentListFromDao().observe(this, Observer {
val book = Book().apply { linkSubsection = Constants.URL_PATH_GRID_DIRECTORY }
handleMediaResult(book, it)
})
}

private fun onSwipeRefresh() = populateRecent()

override fun onSwipeRefresh() {
super.onSwipeRefresh()
populateRecent()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class BrowserRemoteFragment : BrowserBaseFragment() {
}
}

private fun onSwipeRefresh() {
override fun onSwipeRefresh() {
super.onSwipeRefresh()
val book = viewModel.getCurrentBook()
when (book != null) {
true -> {
Expand All @@ -62,5 +63,4 @@ class BrowserRemoteFragment : BrowserBaseFragment() {
false -> Timber.e("No licenseList available to populate swipe refresh!")
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package com.sethchhim.kuboo_client.ui.main.browser
import android.arch.lifecycle.Observer
import android.os.Bundle
import android.view.View
import com.sethchhim.kuboo_client.Constants
import com.sethchhim.kuboo_client.Constants.ARG_SEARCH
import com.sethchhim.kuboo_client.Extensions.gone
import com.sethchhim.kuboo_remote.model.Book

class BrowserSearchFragment : BrowserBaseFragment() {

Expand All @@ -24,13 +26,19 @@ class BrowserSearchFragment : BrowserBaseFragment() {
populateSearch()
}

private fun onSwipeRefresh() = populateSearch()
override fun onSwipeRefresh() {
super.onSwipeRefresh()
populateSearch()
}

private fun populateSearch() {
setStateLoading()
resetRecyclerView()
paginationHandler.reset()
viewModel.getListByQuery(stringQuery).observe(this, Observer { result -> handleMediaResult(null, result) })
viewModel.getListByQuery(stringQuery).observe(this, Observer { result ->
val book = Book().apply { linkSubsection = "${Constants.URL_PATH_SEARCH}$stringQuery" }
handleMediaResult(book, result)
})
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,20 @@ class BrowserSeriesFragment : BrowserBaseFragment() {
populateSeries()
}

private fun onSwipeRefresh() = populateSeries()
override fun onSwipeRefresh() {
super.onSwipeRefresh()
populateSeries()
}

private fun populateSeries() {
setStateLoading()
resetRecyclerView()
paginationHandler.reset()
val stringUrl = viewModel.getActiveServer() + seriesBook.linkXmlPath
val book = Book().apply { linkSubsection = seriesBook.linkXmlPath }
viewModel.getListByUrl(stringUrl).observe(this, Observer { result -> handleMediaResult(book, result) })
viewModel.getListByUrl(stringUrl).observe(this, Observer { result ->
val book = Book().apply { linkSubsection = seriesBook.linkXmlPath }
handleMediaResult(book, result)
})
}

companion object {
Expand Down
Loading

0 comments on commit e5ce678

Please sign in to comment.