Add custom view to show an empty list message for folder, feed and item lists

This commit is contained in:
Shinokuni 2019-09-29 13:25:18 +02:00
parent 044dd00ac4
commit dc552b29e7
11 changed files with 129 additions and 28 deletions

View File

@ -9,6 +9,7 @@ import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
@ -90,7 +91,7 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
private MainViewModel viewModel;
private DrawerManager drawerManager;
private RelativeLayout emptyListLayout;
private LinearLayout emptyListLayout;
private RelativeLayout syncProgressLayout;
private TextView syncProgress;
private ProgressBar syncProgressBar;

View File

@ -9,7 +9,6 @@ import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.LinearLayoutManager;
@ -69,13 +68,21 @@ public class FeedsFragment extends Fragment {
viewModel = ViewModelProviders.of(this).get(ManageFeedsFoldersViewModel.class);
viewModel.setAccount(account);
viewModel.getFeedsWithFolder().observe(this, feedWithFolders -> adapter.submitList(feedWithFolders));
viewModel.getFeedsWithFolder().observe(this, feedWithFolders -> {
adapter.submitList(feedWithFolders);
if (feedWithFolders.size() > 0) {
binding.feedsEmptyList.setVisibility(View.GONE);
} else {
binding.feedsEmptyList.setVisibility(View.VISIBLE);
}
});
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_feeds, container, false);
binding = FragmentFeedsBinding.inflate(inflater);
return binding.getRoot();
}

View File

@ -67,7 +67,15 @@ public class FoldersFragment extends Fragment {
viewModel = ViewModelProviders.of(this).get(ManageFeedsFoldersViewModel.class);
viewModel.setAccount(account);
viewModel.getFoldersWithFeedCount().observe(this, folders -> adapter.submitList(folders));
viewModel.getFoldersWithFeedCount().observe(this, folders -> {
adapter.submitList(folders);
if (folders.size() > 0) {
binding.foldersEmptyList.setVisibility(View.GONE);
} else {
binding.foldersEmptyList.setVisibility(View.VISIBLE);
}
});
}
@Override

View File

@ -0,0 +1,28 @@
package com.readrops.app.utils
import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import com.readrops.app.R
/**
* A simple custom view to display a empty list message
*/
class EmptyListView(context: Context, attrs: AttributeSet) : LinearLayout(context, attrs) {
init {
// no binding here, it makes the view rendering fail
View.inflate(context, R.layout.empty_list_view, this)
val imageView: ImageView = findViewById(R.id.empty_list_image)
val textView: TextView = findViewById(R.id.empty_list_text_v)
val attributes = context.obtainStyledAttributes(attrs, R.styleable.EmptyListView)
imageView.setImageDrawable(attributes.getDrawable(R.styleable.EmptyListView_image))
textView.text = attributes.getString(R.styleable.EmptyListView_text)
attributes.recycle()
}
}

View File

@ -84,29 +84,14 @@
android:layout_height="match_parent"
android:animateLayoutChanges="true">
<RelativeLayout
<com.readrops.app.utils.EmptyListView
android:id="@+id/empty_list_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:image="@drawable/ic_rss_feed_grey"
app:text="@string/no_item"
android:layout_gravity="center"
android:visibility="gone">
<ImageView
android:id="@+id/empty_list_imageview"
android:layout_width="200dp"
android:layout_height="200dp"
android:src="@drawable/ic_rss_feed_grey" />
<TextView
style="@style/TextAppearance.AppCompat.Large"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/empty_list_imageview"
android:layout_centerInParent="true"
android:text="@string/no_feed" />
</RelativeLayout>
android:visibility="gone" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/add_feed_fab"

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical"
tools:ignore="UseCompoundDrawables">
<ImageView
android:id="@+id/empty_list_image"
android:layout_width="200dp"
android:layout_height="200dp"
tools:src="@drawable/ic_rss_feed_grey" />
<TextView
android:id="@+id/empty_list_text_v"
style="@style/TextAppearance.AppCompat.Large"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="@string/no_feed" />
</LinearLayout>
</FrameLayout>
</layout>

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".fragments.FeedsFragment">
@ -12,9 +13,20 @@
android:id="@+id/feeds_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listItem="@layout/feed_layout">
tools:itemCount="5"
tools:listitem="@layout/feed_layout" />
</androidx.recyclerview.widget.RecyclerView>
<com.readrops.app.utils.EmptyListView
android:id="@+id/feeds_empty_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:image="@drawable/ic_rss_feed_grey"
app:layout_constraintBottom_toBottomOf="@+id/feeds_recyclerview"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:text="@string/no_feed" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".fragments.FoldersFragment">
@ -11,6 +12,22 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/folders_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
tools:itemCount="5"
tools:listitem="@layout/folder_layout" />
<com.readrops.app.utils.EmptyListView
android:id="@+id/folders_empty_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:image="@drawable/ic_folder_grey"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:text="@string/no_folder" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

View File

@ -27,7 +27,7 @@
<string name="feed_name">Nom du flux</string>
<string name="edit_feed">Modifier le flux</string>
<string name="folder">Dossier</string>
<string name="no_folder">Pas de dossier</string>
<string name="no_folder">Aucun dossier</string>
<string name="cancel">Retour</string>
<string name="delete_feed">Supprimer le flux ?</string>
<string name="load">Charger</string>
@ -81,5 +81,6 @@
<string name="feeds_number">%1$s flux</string>
<string name="feed_number">%1$s flux</string>
<string name="delete">Supprimer</string>
<string name="no_item">Aucun item</string>
</resources>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="EmptyListView">
<attr name="image" format="reference" />
<attr name="text" format="string" />
</declare-styleable>
</resources>

View File

@ -89,4 +89,5 @@
<string name="feed_number">%1$s feed</string>
<string name="delete">Delete</string>
<string name="app_description" translatable="false"><![CDATA[%1$s <br/><br/> %2$s]]></string>
<string name="no_item">No item</string>
</resources>