mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Added bookmark section in not-logged-in version (#4256)
* added bookmark in not-logged-in version * javadoc * javadoc update * spacing * added unit test
This commit is contained in:
parent
4f130e4dd0
commit
7d8ea51c4f
7 changed files with 119 additions and 12 deletions
|
|
@ -14,6 +14,7 @@ import com.google.android.material.tabs.TabLayout;
|
||||||
|
|
||||||
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
||||||
import fr.free.nrw.commons.explore.ParentViewPager;
|
import fr.free.nrw.commons.explore.ParentViewPager;
|
||||||
|
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||||
import fr.free.nrw.commons.theme.BaseActivity;
|
import fr.free.nrw.commons.theme.BaseActivity;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
|
@ -21,6 +22,7 @@ import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import fr.free.nrw.commons.R;
|
import fr.free.nrw.commons.R;
|
||||||
import fr.free.nrw.commons.contributions.ContributionController;
|
import fr.free.nrw.commons.contributions.ContributionController;
|
||||||
|
import javax.inject.Named;
|
||||||
|
|
||||||
public class BookmarkFragment extends CommonsDaggerSupportFragment {
|
public class BookmarkFragment extends CommonsDaggerSupportFragment {
|
||||||
|
|
||||||
|
|
@ -35,6 +37,13 @@ public class BookmarkFragment extends CommonsDaggerSupportFragment {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ContributionController controller;
|
ContributionController controller;
|
||||||
|
/**
|
||||||
|
* To check if the user is loggedIn or not.
|
||||||
|
*/
|
||||||
|
@Inject
|
||||||
|
@Named("default_preferences")
|
||||||
|
public
|
||||||
|
JsonKvStore applicationKvStore;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static BookmarkFragment newInstance() {
|
public static BookmarkFragment newInstance() {
|
||||||
|
|
@ -65,12 +74,26 @@ public class BookmarkFragment extends CommonsDaggerSupportFragment {
|
||||||
// reference to the Fragment from FragmentManager, using findFragmentById()
|
// reference to the Fragment from FragmentManager, using findFragmentById()
|
||||||
supportFragmentManager = getChildFragmentManager();
|
supportFragmentManager = getChildFragmentManager();
|
||||||
|
|
||||||
adapter = new BookmarksPagerAdapter(supportFragmentManager, getContext());
|
adapter = new BookmarksPagerAdapter(supportFragmentManager, getContext(),
|
||||||
|
applicationKvStore.getBoolean("login_skipped"));
|
||||||
viewPager.setAdapter(adapter);
|
viewPager.setAdapter(adapter);
|
||||||
tabLayout.setupWithViewPager(viewPager);
|
tabLayout.setupWithViewPager(viewPager);
|
||||||
|
setupTabLayout();
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method sets up the tab layout.
|
||||||
|
* If the adapter has only one element it sets the visibility of tabLayout to gone.
|
||||||
|
*/
|
||||||
|
public void setupTabLayout(){
|
||||||
|
tabLayout.setVisibility(View.VISIBLE);
|
||||||
|
if (adapter.getCount() == 1) {
|
||||||
|
tabLayout.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
((BookmarkListRootFragment) (adapter.getItem(tabLayout.getSelectedTabPosition())))
|
((BookmarkListRootFragment) (adapter.getItem(tabLayout.getSelectedTabPosition())))
|
||||||
.backPressed();
|
.backPressed();
|
||||||
|
|
|
||||||
|
|
@ -185,7 +185,7 @@ public class BookmarkListRootFragment extends CommonsDaggerSupportFragment imple
|
||||||
if(mediaDetails!=null) {
|
if(mediaDetails!=null) {
|
||||||
if (mediaDetails.isVisible()) {
|
if (mediaDetails.isVisible()) {
|
||||||
// todo add get list fragment
|
// todo add get list fragment
|
||||||
((BookmarkFragment) getParentFragment()).tabLayout.setVisibility(View.VISIBLE);
|
((BookmarkFragment) getParentFragment()).setupTabLayout();
|
||||||
ArrayList<Integer> removed=mediaDetails.getRemovedItems();
|
ArrayList<Integer> removed=mediaDetails.getRemovedItems();
|
||||||
removeFragment(mediaDetails);
|
removeFragment(mediaDetails);
|
||||||
((BookmarkFragment) getParentFragment()).setScroll(true);
|
((BookmarkFragment) getParentFragment()).setScroll(true);
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,14 @@ public class BookmarksPagerAdapter extends FragmentPagerAdapter {
|
||||||
|
|
||||||
private ArrayList<BookmarkPages> pages;
|
private ArrayList<BookmarkPages> pages;
|
||||||
|
|
||||||
BookmarksPagerAdapter(FragmentManager fm, Context context) {
|
/**
|
||||||
|
* Default Constructor
|
||||||
|
* @param fm
|
||||||
|
* @param context
|
||||||
|
* @param onlyPictures is true if the fragment requires only BookmarkPictureFragment
|
||||||
|
* (i.e. when no user is logged in).
|
||||||
|
*/
|
||||||
|
BookmarksPagerAdapter(FragmentManager fm, Context context,boolean onlyPictures) {
|
||||||
super(fm);
|
super(fm);
|
||||||
pages = new ArrayList<>();
|
pages = new ArrayList<>();
|
||||||
Bundle picturesBundle = new Bundle();
|
Bundle picturesBundle = new Bundle();
|
||||||
|
|
@ -28,13 +35,16 @@ public class BookmarksPagerAdapter extends FragmentPagerAdapter {
|
||||||
pages.add(new BookmarkPages(
|
pages.add(new BookmarkPages(
|
||||||
new BookmarkListRootFragment(picturesBundle, this),
|
new BookmarkListRootFragment(picturesBundle, this),
|
||||||
context.getString(R.string.title_page_bookmarks_pictures)));
|
context.getString(R.string.title_page_bookmarks_pictures)));
|
||||||
|
if (!onlyPictures) {
|
||||||
|
// if onlyPictures is false we also add the location fragment.
|
||||||
Bundle locationBundle = new Bundle();
|
Bundle locationBundle = new Bundle();
|
||||||
locationBundle.putString("categoryName", context.getString(R.string.title_page_bookmarks_locations));
|
locationBundle.putString("categoryName",
|
||||||
|
context.getString(R.string.title_page_bookmarks_locations));
|
||||||
locationBundle.putInt("order", 1);
|
locationBundle.putInt("order", 1);
|
||||||
pages.add(new BookmarkPages(
|
pages.add(new BookmarkPages(
|
||||||
new BookmarkListRootFragment(locationBundle, this),
|
new BookmarkListRootFragment(locationBundle, this),
|
||||||
context.getString(R.string.title_page_bookmarks_locations)));
|
context.getString(R.string.title_page_bookmarks_locations)));
|
||||||
|
}
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ public class MainActivity extends BaseActivity
|
||||||
onSupportNavigateUp();
|
onSupportNavigateUp();
|
||||||
});
|
});
|
||||||
if (applicationKvStore.getBoolean("login_skipped") == true) {
|
if (applicationKvStore.getBoolean("login_skipped") == true) {
|
||||||
setTitle(getString(R.string.explore_tab_title_mobile));
|
setTitle(getString(R.string.navigation_item_explore));
|
||||||
setUpLoggedOutPager();
|
setUpLoggedOutPager();
|
||||||
} else {
|
} else {
|
||||||
if(savedInstanceState == null){
|
if(savedInstanceState == null){
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import fr.free.nrw.commons.R;
|
import fr.free.nrw.commons.R;
|
||||||
|
import fr.free.nrw.commons.bookmarks.BookmarkFragment;
|
||||||
import fr.free.nrw.commons.explore.ExploreFragment;
|
import fr.free.nrw.commons.explore.ExploreFragment;
|
||||||
import org.wikipedia.model.EnumCode;
|
import org.wikipedia.model.EnumCode;
|
||||||
import org.wikipedia.model.EnumCodeMap;
|
import org.wikipedia.model.EnumCodeMap;
|
||||||
|
|
@ -19,6 +20,13 @@ public enum NavTabLoggedOut implements EnumCode {
|
||||||
return ExploreFragment.newInstance();
|
return ExploreFragment.newInstance();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
FAVORITES(R.string.favorites, R.drawable.ic_round_star_border_24px) {
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public Fragment newInstance() {
|
||||||
|
return BookmarkFragment.newInstance();
|
||||||
|
}
|
||||||
|
},
|
||||||
MORE(R.string.more, R.drawable.ic_menu_black_24dp) {
|
MORE(R.string.more, R.drawable.ic_menu_black_24dp) {
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ class BookmarksPagerAdapterTests {
|
||||||
@Before
|
@Before
|
||||||
fun setUp() {
|
fun setUp() {
|
||||||
MockitoAnnotations.initMocks(this)
|
MockitoAnnotations.initMocks(this)
|
||||||
bookmarksPagerAdapter = BookmarksPagerAdapter(fragmentManager, context)
|
bookmarksPagerAdapter = BookmarksPagerAdapter(fragmentManager, context, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,66 @@
|
||||||
|
package fr.free.nrw.commons.bookmarks
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.fragment.app.FragmentManager
|
||||||
|
import org.junit.Assert
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import org.mockito.Mock
|
||||||
|
import org.mockito.MockitoAnnotations
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BookmarksPagerAdapter when user is not loggedIn.
|
||||||
|
*/
|
||||||
|
class LoggedOutBookmarksPagerAdapterTests {
|
||||||
|
@Mock
|
||||||
|
private lateinit var bookmarksPagerAdapter: BookmarksPagerAdapter
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private lateinit var fragmentManager: FragmentManager
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private lateinit var context: Context
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup the adapter
|
||||||
|
*/
|
||||||
|
@Before
|
||||||
|
fun setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this)
|
||||||
|
bookmarksPagerAdapter = BookmarksPagerAdapter(fragmentManager, context, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* checkNotNull
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
fun checkNotNull() {
|
||||||
|
Assert.assertNotNull(bookmarksPagerAdapter)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getItems
|
||||||
|
* Logged out bookmark adapter has just one item.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
fun testGetItem() {
|
||||||
|
bookmarksPagerAdapter.getItem(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* itemCount
|
||||||
|
* Logged out bookmark adapter has just one item.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
fun testGetCount() {
|
||||||
|
Assert.assertEquals(bookmarksPagerAdapter.count, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getTitle.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
fun testGetPageTitle() {
|
||||||
|
bookmarksPagerAdapter.getPageTitle(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue