add new categories screen in bookmarks page

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>
This commit is contained in:
parneet-guraya 2024-12-15 23:48:15 +05:30
parent f908f71a7e
commit 92e864db71
No known key found for this signature in database
GPG key ID: 63B807C4B2A9064B
7 changed files with 116 additions and 29 deletions

View file

@ -7,13 +7,13 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.FrameLayout;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import fr.free.nrw.commons.Media; import fr.free.nrw.commons.Media;
import fr.free.nrw.commons.R; import fr.free.nrw.commons.R;
import fr.free.nrw.commons.bookmarks.category.BookmarkCategoriesFragment;
import fr.free.nrw.commons.bookmarks.items.BookmarkItemsFragment; import fr.free.nrw.commons.bookmarks.items.BookmarkItemsFragment;
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsFragment; import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsFragment;
import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesFragment; import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesFragment;
@ -48,14 +48,21 @@ public class BookmarkListRootFragment extends CommonsDaggerSupportFragment imple
String title = bundle.getString("categoryName"); String title = bundle.getString("categoryName");
int order = bundle.getInt("order"); int order = bundle.getInt("order");
final int orderItem = bundle.getInt("orderItem"); final int orderItem = bundle.getInt("orderItem");
if (order == 0) {
listFragment = new BookmarkPicturesFragment(); switch (order){
} else { case 0: listFragment = new BookmarkPicturesFragment();
listFragment = new BookmarkLocationsFragment(); break;
case 1: listFragment = new BookmarkLocationsFragment();
break;
case 3: listFragment = new BookmarkCategoriesFragment();
break;
}
if(orderItem == 2) { if(orderItem == 2) {
listFragment = new BookmarkItemsFragment(); listFragment = new BookmarkItemsFragment();
} }
}
Bundle featuredArguments = new Bundle(); Bundle featuredArguments = new Bundle();
featuredArguments.putString("categoryName", title); featuredArguments.putString("categoryName", title);
listFragment.setArguments(featuredArguments); listFragment.setArguments(featuredArguments);

View file

@ -49,6 +49,13 @@ public class BookmarksPagerAdapter extends FragmentPagerAdapter {
new BookmarkListRootFragment(locationBundle, this), new BookmarkListRootFragment(locationBundle, this),
context.getString(R.string.title_page_bookmarks_items))); context.getString(R.string.title_page_bookmarks_items)));
} }
final Bundle categoriesBundle = new Bundle();
categoriesBundle.putString("categoryName",
context.getString(R.string.title_page_bookmarks_categories));
categoriesBundle.putInt("order", 3);
pages.add(new BookmarkPages(
new BookmarkListRootFragment(categoriesBundle, this),
context.getString(R.string.title_page_bookmarks_categories)));
notifyDataSetChanged(); notifyDataSetChanged();
} }

View file

@ -1,26 +1,109 @@
package fr.free.nrw.commons.bookmarks.category package fr.free.nrw.commons.bookmarks.category
import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Icon
import androidx.compose.material3.ListItem
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import dagger.android.support.DaggerFragment import dagger.android.support.DaggerFragment
import fr.free.nrw.commons.R import fr.free.nrw.commons.R
import fr.free.nrw.commons.category.CategoryDetailsActivity
import javax.inject.Inject
class BookmarkCategoriesFragment : DaggerFragment() { class BookmarkCategoriesFragment : DaggerFragment() {
@Inject
lateinit var bookmarkCategoriesDao: BookmarkCategoriesDao
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View {
// Inflate the layout for this fragment return ComposeView(requireContext()).apply {
return inflater.inflate(R.layout.fragment_bookmark_categories, container, false) setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent {
MaterialTheme {
val listOfBookmarks by bookmarkCategoriesDao.getAllCategories()
.collectAsStateWithLifecycle(initialValue = emptyList())
Surface(modifier = Modifier.fillMaxSize()) {
Box(contentAlignment = Alignment.Center) {
if (listOfBookmarks.isEmpty()) {
Text(text = stringResource(R.string.bookmark_empty))
} else {
LazyColumn {
items(items = listOfBookmarks) { bookmarkItem ->
CategoryItem(
categoryName = bookmarkItem.categoryName,
onClick = {
val categoryDetailsIntent = Intent(
requireContext(),
CategoryDetailsActivity::class.java
).putExtra("categoryName", it)
startActivity(categoryDetailsIntent)
}
)
}
}
}
}
}
}
}
}
} }
companion object {
@JvmStatic @Composable
fun newInstance(param1: String, param2: String) = fun CategoryItem(
BookmarkCategoriesFragment() modifier: Modifier = Modifier,
onClick: (String) -> Unit,
categoryName: String
) {
Row(modifier = modifier.clickable {
onClick(categoryName)
}) {
ListItem(
leadingContent = {
Icon(
modifier = Modifier.size(48.dp),
painter = painterResource(R.drawable.commons),
contentDescription = null
)
},
headlineContent = {
Text(text = categoryName)
}
)
}
} }
}
@Preview
@Composable
private fun CategoryItemPreview() {
CategoryItem(onClick = {}, categoryName = "Test Category")
}
}

View file

@ -4,6 +4,7 @@ import dagger.Module
import dagger.android.ContributesAndroidInjector import dagger.android.ContributesAndroidInjector
import fr.free.nrw.commons.bookmarks.BookmarkFragment import fr.free.nrw.commons.bookmarks.BookmarkFragment
import fr.free.nrw.commons.bookmarks.BookmarkListRootFragment import fr.free.nrw.commons.bookmarks.BookmarkListRootFragment
import fr.free.nrw.commons.bookmarks.category.BookmarkCategoriesFragment
import fr.free.nrw.commons.bookmarks.items.BookmarkItemsFragment import fr.free.nrw.commons.bookmarks.items.BookmarkItemsFragment
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsFragment import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsFragment
import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesFragment import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesFragment
@ -97,6 +98,9 @@ abstract class FragmentBuilderModule {
@ContributesAndroidInjector(modules = [BookmarkItemsFragmentModule::class]) @ContributesAndroidInjector(modules = [BookmarkItemsFragmentModule::class])
abstract fun bindBookmarkItemListFragment(): BookmarkItemsFragment abstract fun bindBookmarkItemListFragment(): BookmarkItemsFragment
@ContributesAndroidInjector
abstract fun bindBookmarkCategoriesListFragment(): BookmarkCategoriesFragment
@ContributesAndroidInjector @ContributesAndroidInjector
abstract fun bindReviewOutOfContextFragment(): ReviewImageFragment abstract fun bindReviewOutOfContextFragment(): ReviewImageFragment

View file

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".bookmarks.category.BookmarkCategoriesFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
</FrameLayout>

View file

@ -5,7 +5,6 @@
<item <item
android:id="@+id/menu_bookmark_current_category" android:id="@+id/menu_bookmark_current_category"
android:icon="@drawable/menu_icon_bookmark_selector"
android:title="@string/menu_bookmark" android:title="@string/menu_bookmark"
app:showAsAction="ifRoom" /> app:showAsAction="ifRoom" />

View file

@ -415,6 +415,7 @@
<string name="map_application_missing">No compatible map application could be found on your device. Please install a map application to use this feature.</string> <string name="map_application_missing">No compatible map application could be found on your device. Please install a map application to use this feature.</string>
<string name="title_page_bookmarks_pictures">Pictures</string> <string name="title_page_bookmarks_pictures">Pictures</string>
<string name="title_page_bookmarks_locations">Locations</string> <string name="title_page_bookmarks_locations">Locations</string>
<string name="title_page_bookmarks_categories">Categories</string>
<string name="menu_bookmark">Add/Remove to bookmarks</string> <string name="menu_bookmark">Add/Remove to bookmarks</string>
<string name="provider_bookmarks">Bookmarks</string> <string name="provider_bookmarks">Bookmarks</string>
<string name="bookmark_empty">You haven\'t added any bookmarks</string> <string name="bookmark_empty">You haven\'t added any bookmarks</string>