diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/adapters/filelist/FileListAdapter.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/adapters/filelist/FileListAdapter.kt index f5a37455693..2fe6a55080f 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/presentation/adapters/filelist/FileListAdapter.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/adapters/filelist/FileListAdapter.kt @@ -38,7 +38,8 @@ import com.owncloud.android.utils.DisplayUtils import com.owncloud.android.utils.MimetypeIconUtil class FileListAdapter( - private val context: Context + private val context: Context, + private val listener: FileListAdapterListener ) : RecyclerView.Adapter<FileListAdapter.ViewHolder>() { private val files = mutableListOf<OCFile>() @@ -83,6 +84,9 @@ class FileListAdapter( } //TODO Check this with FileListListAdapter.java and its viewType (LIST or GRID) getSharedIcon(imageView = binding.sharedIcon, file = this) + binding.root.setOnClickListener { + listener.clickItem(this) + } } } } @@ -115,5 +119,9 @@ class FileListAdapter( } } + interface FileListAdapterListener { + fun clickItem(ocFile: OCFile) + } + inner class ViewHolder(val binding: ItemFileListBinding) : RecyclerView.ViewHolder(binding.root) } diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/observers/EmptyDataObserver.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/observers/EmptyDataObserver.kt new file mode 100644 index 00000000000..b2c585f40fe --- /dev/null +++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/observers/EmptyDataObserver.kt @@ -0,0 +1,36 @@ +package com.owncloud.android.presentation.observers + +import android.view.View +import androidx.core.view.isVisible +import androidx.recyclerview.widget.RecyclerView + +class EmptyDataObserver constructor(recyclerView: RecyclerView?, emptyView: View?): RecyclerView.AdapterDataObserver() { + + private var emptyView: View? = null + private var recyclerView: RecyclerView? = null + + init { + this.recyclerView = recyclerView + this.emptyView = emptyView + checkIfEmpty() + } + + + private fun checkIfEmpty() { + if (emptyView != null && recyclerView!!.adapter != null) { + val emptyViewVisible = recyclerView!!.adapter!!.itemCount == 0 + emptyView!!.isVisible = emptyViewVisible + recyclerView!!.isVisible = !emptyViewVisible + } + } + + override fun onChanged() { + super.onChanged() + checkIfEmpty() + } + + override fun onItemRangeChanged(positionStart: Int, itemCount: Int) { + super.onItemRangeChanged(positionStart, itemCount) + } + +} \ No newline at end of file diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/ui/files/filelist/MainFileListFragment.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/ui/files/filelist/MainFileListFragment.kt index e73ec971051..d6704aa689d 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/presentation/ui/files/filelist/MainFileListFragment.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/ui/files/filelist/MainFileListFragment.kt @@ -30,6 +30,7 @@ import com.owncloud.android.databinding.MainFileListFragmentBinding import com.owncloud.android.domain.files.model.OCFile import com.owncloud.android.domain.utils.Event import com.owncloud.android.presentation.adapters.filelist.FileListAdapter +import com.owncloud.android.presentation.observers.EmptyDataObserver import com.owncloud.android.presentation.onSuccess import org.koin.androidx.viewmodel.ext.android.viewModel @@ -58,11 +59,21 @@ class MainFileListFragment : Fragment() { private fun initViews() { //Set RecyclerView and its adapter. - fileListAdapter = FileListAdapter(context = requireContext()) + fileListAdapter = FileListAdapter(context = requireContext(), listener = object : + FileListAdapter.FileListAdapterListener { + override fun clickItem(ocFile: OCFile) { + if (ocFile.isFolder) { + mainFileListViewModel.listDirectory(ocFile) + // TODO Manage animation listDirectoryWithAnimationDown + } else { /// Click on a file + // TODO Click on a file + } + } + + } ) binding.recyclerViewMainFileList.apply { layoutManager = LinearLayoutManager(requireContext()) adapter = fileListAdapter - } } @@ -72,6 +83,7 @@ class MainFileListFragment : Fragment() { it.onSuccess { data -> val files = data ?: emptyList() fileListAdapter.updateFileList(filesToAdd = files) + registerListAdapterDataObserver() mainFileListViewModel.manageListOfFiles(files) } }) @@ -110,6 +122,11 @@ class MainFileListFragment : Fragment() { return args != null && args.getBoolean(ARG_JUST_FOLDERS, false) } + private fun registerListAdapterDataObserver() { + val emptyDataObserver = EmptyDataObserver(binding.recyclerViewMainFileList, binding.emptyDataParent.root) + fileListAdapter.registerAdapterDataObserver(emptyDataObserver) + } + override fun onDestroy() { super.onDestroy() _binding = null diff --git a/owncloudApp/src/main/res/layout/item_empty_dataset.xml b/owncloudApp/src/main/res/layout/item_empty_dataset.xml new file mode 100644 index 00000000000..fe17d69be37 --- /dev/null +++ b/owncloudApp/src/main/res/layout/item_empty_dataset.xml @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="utf-8"?> +<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_gravity="center" + android:gravity="center" + android:orientation="vertical" + android:paddingTop="@dimen/standard_half_padding" + android:paddingBottom="@dimen/standard_half_padding"> + + <ImageView + android:id="@+id/list_empty_dataset_icon" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:src="@drawable/ic_folder" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + + <TextView + android:id="@+id/list_empty_dataset_title" + style="@style/TextAppearance.MaterialComponents.Subtitle1" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_marginStart="@dimen/standard_margin" + android:layout_marginEnd="@dimen/standard_margin" + android:gravity="center" + android:padding="@dimen/standard_half_padding" + android:text="@string/local_file_list_empty" + android:textStyle="bold" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/list_empty_dataset_icon" /> + + <TextView + android:id="@+id/list_empty_dataset_sub_title" + style="@style/TextAppearance.MaterialComponents.Body1" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_marginStart="@dimen/standard_margin" + android:layout_marginEnd="@dimen/standard_margin" + android:gravity="center" + android:text="@string/folder_upload_some_content_or_sync_devices" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/list_empty_dataset_title" /> +</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file diff --git a/owncloudApp/src/main/res/layout/main_file_list_fragment.xml b/owncloudApp/src/main/res/layout/main_file_list_fragment.xml index 820ad5d1fb8..ab316253e13 100644 --- a/owncloudApp/src/main/res/layout/main_file_list_fragment.xml +++ b/owncloudApp/src/main/res/layout/main_file_list_fragment.xml @@ -35,6 +35,16 @@ app:layout_constraintTop_toTopOf="parent" tools:listitem="@layout/item_file_list" /> + <include + android:id="@+id/empty_data_parent" + layout="@layout/item_empty_dataset" + android:layout_width="match_parent" + android:visibility="gone" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintTop_toBottomOf="@id/recyclerView_main_file_list" + android:layout_height="match_parent" + android:layout_gravity="center" /> + <include android:id="@+id/footer_main_file_list" layout="@layout/list_footer" diff --git a/owncloudApp/src/main/res/values/strings.xml b/owncloudApp/src/main/res/values/strings.xml index cba30ab82e9..cddcff3e108 100644 --- a/owncloudApp/src/main/res/values/strings.xml +++ b/owncloudApp/src/main/res/values/strings.xml @@ -634,4 +634,6 @@ <string name="scoped_storage_wizard_migration_in_progress">Migrating your files. Please don’t turn your device off.</string> <string name="scoped_storage_wizard_migration_in_progress_button">Working… Please wait</string> <string name="scoped_storage_wizard_title">More security for your files</string> + + <string name="folder_upload_some_content_or_sync_devices">Upload some content or sync with your devices!</string> </resources>