Skip to content

Commit

Permalink
Added new fragment for spaces list and empty view
Browse files Browse the repository at this point in the history
  • Loading branch information
JuancaG05 committed Dec 23, 2022
1 parent 9cda585 commit cd827fb
Show file tree
Hide file tree
Showing 13 changed files with 246 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,23 @@ import com.owncloud.android.domain.files.model.FileListOption
@StringRes
fun FileListOption.toTitleStringRes(): Int = when (this) {
FileListOption.ALL_FILES -> R.string.file_list_empty_title_all_files
FileListOption.SPACES_LIST -> R.string.spaces_list_empty_title
FileListOption.SHARED_BY_LINK -> R.string.file_list_empty_title_shared_by_links
FileListOption.AV_OFFLINE -> R.string.file_list_empty_title_available_offline
}

@StringRes
fun FileListOption.toSubtitleStringRes(): Int = when (this) {
FileListOption.ALL_FILES -> R.string.file_list_empty_subtitle_all_files
FileListOption.SPACES_LIST -> R.string.spaces_list_empty_subtitle
FileListOption.SHARED_BY_LINK -> R.string.file_list_empty_subtitle_shared_by_links
FileListOption.AV_OFFLINE -> R.string.file_list_empty_subtitle_available_offline
}

@DrawableRes
fun FileListOption.toDrawableRes(): Int = when (this) {
FileListOption.ALL_FILES -> R.drawable.ic_folder
FileListOption.SPACES_LIST -> R.drawable.ic_spaces
FileListOption.SHARED_BY_LINK -> R.drawable.ic_shared_by_link
FileListOption.AV_OFFLINE -> R.drawable.ic_available_offline
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ class MainFileListViewModel(
getFileByRemotePathUseCase.execute(GetFileByRemotePathUseCase.Params(fileById.owner, ROOT_PATH)).getDataOrNull()
} else fileById
}
FileListOption.SPACES_LIST -> {
// TODO: Spaces is not applicable here at the moment
parentDir = TODO()
}
}
} else if (parentId == ROOT_PARENT_ID.toLong()) {
// Browsing to parent folder. Root
Expand Down Expand Up @@ -231,6 +235,7 @@ class MainFileListViewModel(
FileListOption.ALL_FILES -> retrieveFlowForAllFiles(currentFolderDisplayed, accountName)
FileListOption.SHARED_BY_LINK -> retrieveFlowForShareByLink(currentFolderDisplayed, accountName)
FileListOption.AV_OFFLINE -> retrieveFlowForAvailableOffline(currentFolderDisplayed, accountName)
FileListOption.SPACES_LIST -> TODO()
}.toFileListUiState(
currentFolderDisplayed,
accountName,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* ownCloud Android client application
*
* @author Juan Carlos Garrote Gascón
*
* Copyright (C) 2022 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 <http://www.gnu.org/licenses/>.
*/

package com.owncloud.android.presentation.spaces

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import com.owncloud.android.databinding.SpacesListFragmentBinding
import com.owncloud.android.domain.files.model.FileListOption
import com.owncloud.android.extensions.toDrawableRes
import com.owncloud.android.extensions.toSubtitleStringRes
import com.owncloud.android.extensions.toTitleStringRes

class SpacesListFragment : Fragment() {
private var _binding: SpacesListFragmentBinding? = null
private val binding get() = _binding!!

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = SpacesListFragmentBinding.inflate(inflater, container, false)
return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
showOrHideEmptyView()
}

// TODO: Use this method only when necessary, for the moment the empty view is shown always
private fun showOrHideEmptyView() {
binding.recyclerSpacesList.isVisible = false

with(binding.emptyDataParent) {
root.isVisible = true
listEmptyDatasetIcon.setImageResource(FileListOption.SPACES_LIST.toDrawableRes())
listEmptyDatasetTitle.setText(FileListOption.SPACES_LIST.toTitleStringRes())
listEmptyDatasetSubTitle.setText(FileListOption.SPACES_LIST.toSubtitleStringRes())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.widget.AppCompatImageView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.GravityCompat
import androidx.core.view.get
import androidx.core.view.isVisible
import androidx.drawerlayout.widget.DrawerLayout
import androidx.drawerlayout.widget.DrawerLayout.DrawerListener
Expand All @@ -51,7 +52,9 @@ import com.google.android.material.navigation.NavigationView
import com.owncloud.android.BuildConfig
import com.owncloud.android.MainApp.Companion.initDependencyInjection
import com.owncloud.android.R
import com.owncloud.android.domain.capabilities.model.OCCapability
import com.owncloud.android.domain.files.model.FileListOption
import com.owncloud.android.domain.utils.Event
import com.owncloud.android.extensions.goToUrl
import com.owncloud.android.extensions.openPrivacyPolicy
import com.owncloud.android.extensions.sendEmail
Expand All @@ -63,9 +66,11 @@ import com.owncloud.android.presentation.avatar.AvatarUtils
import com.owncloud.android.presentation.accounts.AccountsManagementActivity
import com.owncloud.android.presentation.accounts.AccountsManagementActivity.Companion.KEY_ACCOUNT_LIST_CHANGED
import com.owncloud.android.presentation.accounts.AccountsManagementActivity.Companion.KEY_CURRENT_ACCOUNT_CHANGED
import com.owncloud.android.presentation.capabilities.CapabilityViewModel
import com.owncloud.android.utils.DisplayUtils
import com.owncloud.android.utils.PreferenceUtils
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.koin.core.parameter.parametersOf
import timber.log.Timber
import kotlin.math.ceil

Expand All @@ -76,6 +81,11 @@ import kotlin.math.ceil
abstract class DrawerActivity : ToolbarActivity() {

private val drawerViewModel by viewModel<DrawerViewModel>()
private val capabilitiesViewModel by viewModel<CapabilityViewModel> {
parametersOf(
account?.name
)
}

private var menuAccountAvatarRadiusDimension = 0f
private var currentAccountAvatarRadiusDimension = 0f
Expand Down Expand Up @@ -213,6 +223,19 @@ abstract class DrawerActivity : ToolbarActivity() {
open fun setupNavigationBottomBar(menuItemId: Int) {
// Allow or disallow touches with other visible windows
getBottomNavigationView()?.filterTouchesWhenObscured = PreferenceUtils.shouldDisallowTouchesWithOtherVisibleWindows(this)
if (account != null) {
capabilitiesViewModel.capabilities.observe(this, Event.EventObserver { uiResult: UIResult<OCCapability> ->
if (uiResult is UIResult.Success) {
val capabilities = uiResult.data
if (capabilities?.isSpacesAllowed() == true) {
getBottomNavigationView()?.menu?.get(0)?.title = getString(R.string.bottom_nav_personal)
getBottomNavigationView()?.menu?.get(1)?.isVisible = capabilities.isSpacesProjectsAllowed()
} else {
getBottomNavigationView()?.menu?.get(0)?.title = getString(R.string.bottom_nav_files)
}
}
})
}
setCheckedItemAtBottomBar(menuItemId)
getBottomNavigationView()?.setOnNavigationItemSelectedListener { menuItem: MenuItem ->
bottomBarNavigationTo(menuItem.itemId, getBottomNavigationView()?.selectedItemId == menuItem.itemId)
Expand All @@ -223,6 +246,7 @@ abstract class DrawerActivity : ToolbarActivity() {
private fun bottomBarNavigationTo(menuItemId: Int, isCurrentOptionActive: Boolean) {
when (menuItemId) {
R.id.nav_all_files -> navigateToOption(FileListOption.ALL_FILES)
R.id.nav_spaces -> navigateToOption(FileListOption.SPACES_LIST)
R.id.nav_uploads -> if (!isCurrentOptionActive) {
val uploadListIntent = Intent(applicationContext, UploadListActivity::class.java)
uploadListIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
Expand Down Expand Up @@ -680,6 +704,12 @@ abstract class DrawerActivity : ToolbarActivity() {
*/
protected abstract fun restart()

/**
* Checks if the spaces tab is currently selected
*/
protected fun isSpacesTabSelected() =
getBottomNavigationView()?.menu?.findItem(R.id.nav_spaces)?.isChecked == true

companion object {
private const val KEY_IS_ACCOUNT_CHOOSER_ACTIVE = "IS_ACCOUNT_CHOOSER_ACTIVE"
private const val KEY_CHECKED_MENU_ITEM = "CHECKED_MENU_ITEM"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,12 @@ public void navigateToOption(FileListOption fileListOption) {
case ALL_FILES:
restart();
break;
case SPACES_LIST:
intent = new Intent(this, FileDisplayActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra(EXTRA_FILE_LIST_OPTION, (Parcelable) FileListOption.SPACES_LIST);
startActivity(intent);
break;
case SHARED_BY_LINK:
intent = new Intent(this, FileDisplayActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import com.owncloud.android.presentation.files.operations.FileOperation
import com.owncloud.android.presentation.files.operations.FileOperationsViewModel
import com.owncloud.android.presentation.security.bayPassUnlockOnce
import com.owncloud.android.presentation.capabilities.CapabilityViewModel
import com.owncloud.android.presentation.spaces.SpacesListFragment
import com.owncloud.android.presentation.transfers.TransfersViewModel
import com.owncloud.android.providers.WorkManagerProvider
import com.owncloud.android.syncadapter.FileSyncAdapter
Expand Down Expand Up @@ -142,6 +143,9 @@ class FileDisplayActivity : FileActivity(),
private val listMainFileFragment: MainFileListFragment?
get() = supportFragmentManager.findFragmentByTag(TAG_LIST_OF_FILES) as MainFileListFragment?

private val spacesListFragment: SpacesListFragment?
get() = supportFragmentManager.findFragmentByTag(TAG_LIST_OF_SPACES) as SpacesListFragment?

private val secondFragment: FileFragment?
get() = supportFragmentManager.findFragmentByTag(TAG_SECOND_FRAGMENT) as FileFragment?

Expand Down Expand Up @@ -253,7 +257,11 @@ class FileDisplayActivity : FileActivity(),
capabilitiesViewModel.capabilities.observe(this, Event.EventObserver {
onCapabilitiesOperationFinish(it)
})
initAndShowListOfFiles()
if (isSpacesTabSelected()) {
initAndShowListOfSpaces()
} else {
initAndShowListOfFiles()
}
}

startListeningToOperations()
Expand Down Expand Up @@ -327,7 +335,14 @@ class FileDisplayActivity : FileActivity(),
setSearchListener(findViewById(R.id.root_toolbar_search_view))
}
val transaction = supportFragmentManager.beginTransaction()
transaction.add(R.id.left_fragment_container, mainListOfFiles, TAG_LIST_OF_FILES)
transaction.replace(R.id.left_fragment_container, mainListOfFiles, TAG_LIST_OF_FILES)
transaction.commit()
}

private fun initAndShowListOfSpaces() {
val listOfSpaces = SpacesListFragment()
val transaction = supportFragmentManager.beginTransaction()
transaction.replace(R.id.left_fragment_container, listOfSpaces, TAG_LIST_OF_SPACES)
transaction.commit()
}

Expand Down Expand Up @@ -684,7 +699,9 @@ class FileDisplayActivity : FileActivity(),
super.onResume()

setCheckedItemAtBottomBar(getMenuItemForFileListOption(fileListOption))
listMainFileFragment?.updateFileListOption(fileListOption, file)
if (!isSpacesTabSelected()) {
listMainFileFragment?.updateFileListOption(fileListOption, file)
}

// refresh list of files
refreshListOfFilesFragment()
Expand Down Expand Up @@ -843,6 +860,7 @@ class FileDisplayActivity : FileActivity(),
FileListOption.AV_OFFLINE -> getString(R.string.drawer_item_only_available_offline)
FileListOption.SHARED_BY_LINK -> getString(R.string.drawer_item_shared_by_link_files)
FileListOption.ALL_FILES -> getString(R.string.default_display_name_for_root_folder)
FileListOption.SPACES_LIST -> getString(R.string.drawer_item_spaces)
}
setupRootToolbar(title, isSearchEnabled = true)
listMainFileFragment?.setSearchListener(findViewById(R.id.root_toolbar_search_view))
Expand Down Expand Up @@ -1317,15 +1335,25 @@ class FileDisplayActivity : FileActivity(),

private fun navigateTo(newFileListOption: FileListOption) {
if (fileListOption != newFileListOption) {
if (listMainFileFragment != null) {
if (newFileListOption == FileListOption.SPACES_LIST) {
initAndShowListOfSpaces()
fileListOption = FileListOption.SPACES_LIST
updateToolbar(null)
}
else if (listMainFileFragment != null) {
fileListOption = newFileListOption
file = storageManager.getFileByPath(OCFile.ROOT_PATH)
listMainFileFragment?.updateFileListOption(newFileListOption, file)
updateToolbar(null)
} else if (spacesListFragment != null) {
fileListOption = newFileListOption
file = storageManager.getFileByPath(OCFile.ROOT_PATH)
initAndShowListOfFiles()
updateToolbar(null)
} else {
super.navigateToOption(FileListOption.ALL_FILES)
}
} else {
} else if (newFileListOption != FileListOption.SPACES_LIST) {
browseToRoot()
}
}
Expand All @@ -1335,6 +1363,7 @@ class FileDisplayActivity : FileActivity(),
}

private fun getMenuItemForFileListOption(fileListOption: FileListOption?): Int = when (fileListOption) {
FileListOption.SPACES_LIST -> R.id.nav_spaces
FileListOption.SHARED_BY_LINK -> R.id.nav_shared_by_link_files
FileListOption.AV_OFFLINE -> R.id.nav_available_offline_files
else -> R.id.nav_all_files
Expand Down Expand Up @@ -1444,6 +1473,7 @@ class FileDisplayActivity : FileActivity(),

companion object {
private const val TAG_LIST_OF_FILES = "LIST_OF_FILES"
private const val TAG_LIST_OF_SPACES = "LIST_OF_SPACES"
private const val TAG_SECOND_FRAGMENT = "SECOND_FRAGMENT"

private const val KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW"
Expand Down
9 changes: 9 additions & 0 deletions owncloudApp/src/main/res/drawable/ic_spaces.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:fillColor="#FF000000"
android:pathData="M6,22.5L6,6h16.5v16.5ZM6,42L6,25.5h16.5L22.5,42ZM25.5,22.5L25.5,6L42,6v16.5ZM25.5,42L25.5,25.5L42,25.5L42,42Z"/>
</vector>
Loading

0 comments on commit cd827fb

Please sign in to comment.