Skip to content
This repository has been archived by the owner on Sep 17, 2023. It is now read-only.

Commit

Permalink
Add a message for user when there are no projects
Browse files Browse the repository at this point in the history
Signed-off-by: PranavPurwar <[email protected]>
  • Loading branch information
PranavPurwar committed Jul 25, 2023
1 parent 3067706 commit f111f29
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,21 +163,15 @@ class ProjectFragment : BaseBindingFragment<FragmentProjectBinding>(),

private fun observeViewModelProjects() {
viewModel.projects.observe(viewLifecycleOwner) { projects ->
showSnackBarIfNoProjects(projects)
if (projects.isEmpty() && binding.switcher.currentView != binding.noProjects) {
binding.switcher.showNext()
} else if (binding.switcher.currentView != binding.projectList) {
binding.switcher.showPrevious()
}
projectAdapter.submitList(projects)
}
}

private fun showSnackBarIfNoProjects(projects: List<Project>) {
if (projects.isEmpty()) {
Snackbar.make(
requireView(),
"No projects found",
Snackbar.LENGTH_LONG
).show()
}
}

override fun onProjectClicked(project: Project) {
navigateToEditorFragment(project)
}
Expand Down
27 changes: 23 additions & 4 deletions app/src/main/res/layout/fragment_project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,32 @@
android:visibility="gone" />
</com.google.android.material.appbar.AppBarLayout>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/project_list"
<ViewSwitcher
android:id="@+id/switcher"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:transitionGroup="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/project_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:transitionGroup="true"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<TextView
android:id="@+id/no_projects"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/no_projects_found_create_one_now"
android:textAppearance="?attr/textAppearanceHeadline6"
android:transitionGroup="true"
android:visibility="gone" />

</ViewSwitcher>

<include
android:id="@+id/fabs"
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/layout/project_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

<com.google.android.material.card.MaterialCardView 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"
style="@style/Widget.CosmicIde.ListItemCard"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?colorSurfaceVariant"
android:paddingHorizontal="16dp"
android:paddingVertical="12dp">

Expand All @@ -28,7 +28,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/author"
app:layout_constraintVertical_chainStyle="packed" />

<TextView
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,5 @@
<string name="install_required_resources">Install required resources</string>
<string name="clone_from_git">Clone from Git</string>
<string name="class_name">Class name</string>
<string name="no_projects_found_create_one_now">No projects found. Create one now!</string>
</resources>

0 comments on commit f111f29

Please sign in to comment.