Skip to content

Commit

Permalink
Merge pull request #3460 from owncloud/new_arch/empty_folder
Browse files Browse the repository at this point in the history
New arch/empty folder
  • Loading branch information
jabarros authored Nov 25, 2021
2 parents 553cb37 + 6d8032c commit ff7090d
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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>()
Expand Down Expand Up @@ -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)
}
}
}
}
Expand Down Expand Up @@ -115,5 +119,9 @@ class FileListAdapter(
}
}

interface FileListAdapterListener {
fun clickItem(ocFile: OCFile)
}

inner class ViewHolder(val binding: ItemFileListBinding) : RecyclerView.ViewHolder(binding.root)
}
Original file line number Diff line number Diff line change
@@ -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)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

}
}

Expand All @@ -72,6 +83,7 @@ class MainFileListFragment : Fragment() {
it.onSuccess { data ->
val files = data ?: emptyList()
fileListAdapter.updateFileList(filesToAdd = files)
registerListAdapterDataObserver()
mainFileListViewModel.manageListOfFiles(files)
}
})
Expand Down Expand Up @@ -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
Expand Down
49 changes: 49 additions & 0 deletions owncloudApp/src/main/res/layout/item_empty_dataset.xml
Original file line number Diff line number Diff line change
@@ -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>
10 changes: 10 additions & 0 deletions owncloudApp/src/main/res/layout/main_file_list_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions owncloudApp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit ff7090d

Please sign in to comment.