mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Migrated Bookmarks Package From Butterknife to ViewBinding (#5594)
* Butterknife to ViewBinding * code fix to pass all tests * code cleanup & binding added to tests
This commit is contained in:
parent
3e5424e18d
commit
161e2edc31
9 changed files with 130 additions and 139 deletions
|
|
@ -5,23 +5,15 @@ import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import android.widget.FrameLayout;
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
import com.google.android.material.tabs.TabLayout;
|
|
||||||
|
|
||||||
import fr.free.nrw.commons.contributions.MainActivity;
|
import fr.free.nrw.commons.contributions.MainActivity;
|
||||||
|
import fr.free.nrw.commons.databinding.FragmentBookmarksBinding;
|
||||||
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.kvstore.JsonKvStore;
|
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;
|
||||||
|
|
||||||
import butterknife.BindView;
|
|
||||||
import butterknife.ButterKnife;
|
|
||||||
import fr.free.nrw.commons.R;
|
|
||||||
import fr.free.nrw.commons.contributions.ContributionController;
|
import fr.free.nrw.commons.contributions.ContributionController;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
|
|
@ -29,12 +21,7 @@ public class BookmarkFragment extends CommonsDaggerSupportFragment {
|
||||||
|
|
||||||
private FragmentManager supportFragmentManager;
|
private FragmentManager supportFragmentManager;
|
||||||
private BookmarksPagerAdapter adapter;
|
private BookmarksPagerAdapter adapter;
|
||||||
@BindView(R.id.viewPagerBookmarks)
|
FragmentBookmarksBinding binding;
|
||||||
ParentViewPager viewPager;
|
|
||||||
@BindView(R.id.tab_layout)
|
|
||||||
TabLayout tabLayout;
|
|
||||||
@BindView(R.id.fragmentContainer)
|
|
||||||
FrameLayout fragmentContainer;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ContributionController controller;
|
ContributionController controller;
|
||||||
|
|
@ -54,7 +41,9 @@ public class BookmarkFragment extends CommonsDaggerSupportFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setScroll(boolean canScroll) {
|
public void setScroll(boolean canScroll) {
|
||||||
viewPager.setCanScroll(canScroll);
|
if (binding!=null) {
|
||||||
|
binding.viewPagerBookmarks.setCanScroll(canScroll);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -68,8 +57,7 @@ public class BookmarkFragment extends CommonsDaggerSupportFragment {
|
||||||
@Nullable final ViewGroup container,
|
@Nullable final ViewGroup container,
|
||||||
@Nullable final Bundle savedInstanceState) {
|
@Nullable final Bundle savedInstanceState) {
|
||||||
super.onCreateView(inflater, container, savedInstanceState);
|
super.onCreateView(inflater, container, savedInstanceState);
|
||||||
View view = inflater.inflate(R.layout.fragment_bookmarks, container, false);
|
binding = FragmentBookmarksBinding.inflate(inflater, container, false);
|
||||||
ButterKnife.bind(this, view);
|
|
||||||
|
|
||||||
// Activity can call methods in the fragment by acquiring a
|
// Activity can call methods in the fragment by acquiring a
|
||||||
// reference to the Fragment from FragmentManager, using findFragmentById()
|
// reference to the Fragment from FragmentManager, using findFragmentById()
|
||||||
|
|
@ -77,14 +65,14 @@ public class BookmarkFragment extends CommonsDaggerSupportFragment {
|
||||||
|
|
||||||
adapter = new BookmarksPagerAdapter(supportFragmentManager, getContext(),
|
adapter = new BookmarksPagerAdapter(supportFragmentManager, getContext(),
|
||||||
applicationKvStore.getBoolean("login_skipped"));
|
applicationKvStore.getBoolean("login_skipped"));
|
||||||
viewPager.setAdapter(adapter);
|
binding.viewPagerBookmarks.setAdapter(adapter);
|
||||||
tabLayout.setupWithViewPager(viewPager);
|
binding.tabLayout.setupWithViewPager(binding.viewPagerBookmarks);
|
||||||
|
|
||||||
((MainActivity) getActivity()).showTabs();
|
((MainActivity) getActivity()).showTabs();
|
||||||
((BaseActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
((BaseActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
||||||
|
|
||||||
setupTabLayout();
|
setupTabLayout();
|
||||||
return view;
|
return binding.getRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -92,15 +80,15 @@ public class BookmarkFragment extends CommonsDaggerSupportFragment {
|
||||||
* visibility of tabLayout to gone.
|
* visibility of tabLayout to gone.
|
||||||
*/
|
*/
|
||||||
public void setupTabLayout() {
|
public void setupTabLayout() {
|
||||||
tabLayout.setVisibility(View.VISIBLE);
|
binding.tabLayout.setVisibility(View.VISIBLE);
|
||||||
if (adapter.getCount() == 1) {
|
if (adapter.getCount() == 1) {
|
||||||
tabLayout.setVisibility(View.GONE);
|
binding.tabLayout.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
if (((BookmarkListRootFragment) (adapter.getItem(tabLayout.getSelectedTabPosition())))
|
if (((BookmarkListRootFragment) (adapter.getItem(binding.tabLayout.getSelectedTabPosition())))
|
||||||
.backPressed()) {
|
.backPressed()) {
|
||||||
// The event is handled internally by the adapter , no further action required.
|
// The event is handled internally by the adapter , no further action required.
|
||||||
return;
|
return;
|
||||||
|
|
@ -108,4 +96,10 @@ public class BookmarkFragment extends CommonsDaggerSupportFragment {
|
||||||
// Event is not handled by the adapter ( performed back action ) change action bar.
|
// Event is not handled by the adapter ( performed back action ) change action bar.
|
||||||
((BaseActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
((BaseActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
binding = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,6 @@ 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 butterknife.BindView;
|
|
||||||
import butterknife.ButterKnife;
|
|
||||||
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.items.BookmarkItemsFragment;
|
import fr.free.nrw.commons.bookmarks.items.BookmarkItemsFragment;
|
||||||
|
|
@ -22,6 +20,7 @@ import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesFragment;
|
||||||
import fr.free.nrw.commons.category.CategoryImagesCallback;
|
import fr.free.nrw.commons.category.CategoryImagesCallback;
|
||||||
import fr.free.nrw.commons.category.GridViewAdapter;
|
import fr.free.nrw.commons.category.GridViewAdapter;
|
||||||
import fr.free.nrw.commons.contributions.MainActivity;
|
import fr.free.nrw.commons.contributions.MainActivity;
|
||||||
|
import fr.free.nrw.commons.databinding.FragmentFeaturedRootBinding;
|
||||||
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
||||||
import fr.free.nrw.commons.media.MediaDetailPagerFragment;
|
import fr.free.nrw.commons.media.MediaDetailPagerFragment;
|
||||||
import fr.free.nrw.commons.navtab.NavTab;
|
import fr.free.nrw.commons.navtab.NavTab;
|
||||||
|
|
@ -39,8 +38,7 @@ public class BookmarkListRootFragment extends CommonsDaggerSupportFragment imple
|
||||||
public Fragment listFragment;
|
public Fragment listFragment;
|
||||||
private BookmarksPagerAdapter bookmarksPagerAdapter;
|
private BookmarksPagerAdapter bookmarksPagerAdapter;
|
||||||
|
|
||||||
@BindView(R.id.explore_container)
|
FragmentFeaturedRootBinding binding;
|
||||||
FrameLayout container;
|
|
||||||
|
|
||||||
public BookmarkListRootFragment() {
|
public BookmarkListRootFragment() {
|
||||||
//empty constructor necessary otherwise crashes on recreate
|
//empty constructor necessary otherwise crashes on recreate
|
||||||
|
|
@ -70,9 +68,8 @@ public class BookmarkListRootFragment extends CommonsDaggerSupportFragment imple
|
||||||
@Nullable final ViewGroup container,
|
@Nullable final ViewGroup container,
|
||||||
@Nullable final Bundle savedInstanceState) {
|
@Nullable final Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
View view = inflater.inflate(R.layout.fragment_featured_root, container, false);
|
binding = FragmentFeaturedRootBinding.inflate(inflater, container, false);
|
||||||
ButterKnife.bind(this, view);
|
return binding.getRoot();
|
||||||
return view;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -241,8 +238,8 @@ public class BookmarkListRootFragment extends CommonsDaggerSupportFragment imple
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
Log.d("deneme8", "on media clicked");
|
Log.d("deneme8", "on media clicked");
|
||||||
container.setVisibility(View.VISIBLE);
|
binding.exploreContainer.setVisibility(View.VISIBLE);
|
||||||
((BookmarkFragment) getParentFragment()).tabLayout.setVisibility(View.GONE);
|
((BookmarkFragment) getParentFragment()).binding.tabLayout.setVisibility(View.GONE);
|
||||||
mediaDetails = MediaDetailPagerFragment.newInstance(false, true);
|
mediaDetails = MediaDetailPagerFragment.newInstance(false, true);
|
||||||
((BookmarkFragment) getParentFragment()).setScroll(false);
|
((BookmarkFragment) getParentFragment()).setScroll(false);
|
||||||
setFragment(mediaDetails, listFragment);
|
setFragment(mediaDetails, listFragment);
|
||||||
|
|
@ -253,4 +250,10 @@ public class BookmarkListRootFragment extends CommonsDaggerSupportFragment imple
|
||||||
public void onBackStackChanged() {
|
public void onBackStackChanged() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
binding = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,9 @@ import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import butterknife.BindView;
|
|
||||||
import butterknife.ButterKnife;
|
|
||||||
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.databinding.FragmentBookmarksItemsBinding;
|
||||||
import fr.free.nrw.commons.upload.structure.depictions.DepictedItem;
|
import fr.free.nrw.commons.upload.structure.depictions.DepictedItem;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
@ -26,17 +25,7 @@ import org.jetbrains.annotations.NotNull;
|
||||||
*/
|
*/
|
||||||
public class BookmarkItemsFragment extends DaggerFragment {
|
public class BookmarkItemsFragment extends DaggerFragment {
|
||||||
|
|
||||||
@BindView(R.id.status_message)
|
private FragmentBookmarksItemsBinding binding;
|
||||||
TextView statusTextView;
|
|
||||||
|
|
||||||
@BindView(R.id.loading_images_progress_bar)
|
|
||||||
ProgressBar progressBar;
|
|
||||||
|
|
||||||
@BindView(R.id.list_view)
|
|
||||||
RecyclerView recyclerView;
|
|
||||||
|
|
||||||
@BindView(R.id.parent_layout)
|
|
||||||
RelativeLayout parentLayout;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
BookmarkItemsController controller;
|
BookmarkItemsController controller;
|
||||||
|
|
@ -51,16 +40,13 @@ public class BookmarkItemsFragment extends DaggerFragment {
|
||||||
final ViewGroup container,
|
final ViewGroup container,
|
||||||
final Bundle savedInstanceState
|
final Bundle savedInstanceState
|
||||||
) {
|
) {
|
||||||
final View v = inflater.inflate(R.layout.fragment_bookmarks_items, container, false);
|
binding = FragmentBookmarksItemsBinding.inflate(inflater, container, false);
|
||||||
ButterKnife.bind(this, v);
|
return binding.getRoot();
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated(final @NotNull View view, @Nullable final Bundle savedInstanceState) {
|
public void onViewCreated(final @NotNull View view, @Nullable final Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
progressBar.setVisibility(View.VISIBLE);
|
|
||||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
|
||||||
initList(requireContext());
|
initList(requireContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,13 +63,19 @@ public class BookmarkItemsFragment extends DaggerFragment {
|
||||||
private void initList(final Context context) {
|
private void initList(final Context context) {
|
||||||
final List<DepictedItem> depictItems = controller.loadFavoritesItems();
|
final List<DepictedItem> depictItems = controller.loadFavoritesItems();
|
||||||
final BookmarkItemsAdapter adapter = new BookmarkItemsAdapter(depictItems, context);
|
final BookmarkItemsAdapter adapter = new BookmarkItemsAdapter(depictItems, context);
|
||||||
recyclerView.setAdapter(adapter);
|
binding.listView.setAdapter(adapter);
|
||||||
progressBar.setVisibility(View.GONE);
|
binding.loadingImagesProgressBar.setVisibility(View.GONE);
|
||||||
if (depictItems.isEmpty()) {
|
if (depictItems.isEmpty()) {
|
||||||
statusTextView.setText(R.string.bookmark_empty);
|
binding.statusMessage.setText(R.string.bookmark_empty);
|
||||||
statusTextView.setVisibility(View.VISIBLE);
|
binding.statusMessage.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
statusTextView.setVisibility(View.GONE);
|
binding.statusMessage.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
binding = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import butterknife.ButterKnife;
|
||||||
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.contributions.ContributionController;
|
import fr.free.nrw.commons.contributions.ContributionController;
|
||||||
|
import fr.free.nrw.commons.databinding.FragmentBookmarksLocationsBinding;
|
||||||
import fr.free.nrw.commons.nearby.Place;
|
import fr.free.nrw.commons.nearby.Place;
|
||||||
import fr.free.nrw.commons.nearby.fragments.CommonPlaceClickActions;
|
import fr.free.nrw.commons.nearby.fragments.CommonPlaceClickActions;
|
||||||
import fr.free.nrw.commons.nearby.fragments.PlaceAdapter;
|
import fr.free.nrw.commons.nearby.fragments.PlaceAdapter;
|
||||||
|
|
@ -31,10 +32,7 @@ import kotlin.Unit;
|
||||||
|
|
||||||
public class BookmarkLocationsFragment extends DaggerFragment {
|
public class BookmarkLocationsFragment extends DaggerFragment {
|
||||||
|
|
||||||
@BindView(R.id.statusMessage) TextView statusTextView;
|
public FragmentBookmarksLocationsBinding binding;
|
||||||
@BindView(R.id.loadingImagesProgressBar) ProgressBar progressBar;
|
|
||||||
@BindView(R.id.listView) RecyclerView recyclerView;
|
|
||||||
@BindView(R.id.parentLayout) RelativeLayout parentLayout;
|
|
||||||
|
|
||||||
@Inject BookmarkLocationsController controller;
|
@Inject BookmarkLocationsController controller;
|
||||||
@Inject ContributionController contributionController;
|
@Inject ContributionController contributionController;
|
||||||
|
|
@ -75,16 +73,15 @@ public class BookmarkLocationsFragment extends DaggerFragment {
|
||||||
ViewGroup container,
|
ViewGroup container,
|
||||||
Bundle savedInstanceState
|
Bundle savedInstanceState
|
||||||
) {
|
) {
|
||||||
View v = inflater.inflate(R.layout.fragment_bookmarks_locations, container, false);
|
binding = FragmentBookmarksLocationsBinding.inflate(inflater, container, false);
|
||||||
ButterKnife.bind(this, v);
|
return binding.getRoot();
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
progressBar.setVisibility(View.VISIBLE);
|
binding.loadingImagesProgressBar.setVisibility(View.VISIBLE);
|
||||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
binding.listView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||||
adapter = new PlaceAdapter(bookmarkLocationDao,
|
adapter = new PlaceAdapter(bookmarkLocationDao,
|
||||||
place -> Unit.INSTANCE,
|
place -> Unit.INSTANCE,
|
||||||
(place, isBookmarked) -> {
|
(place, isBookmarked) -> {
|
||||||
|
|
@ -94,7 +91,7 @@ public class BookmarkLocationsFragment extends DaggerFragment {
|
||||||
commonPlaceClickActions,
|
commonPlaceClickActions,
|
||||||
inAppCameraLocationPermissionLauncher
|
inAppCameraLocationPermissionLauncher
|
||||||
);
|
);
|
||||||
recyclerView.setAdapter(adapter);
|
binding.listView.setAdapter(adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -109,12 +106,12 @@ public class BookmarkLocationsFragment extends DaggerFragment {
|
||||||
private void initList() {
|
private void initList() {
|
||||||
List<Place> places = controller.loadFavoritesLocations();
|
List<Place> places = controller.loadFavoritesLocations();
|
||||||
adapter.setItems(places);
|
adapter.setItems(places);
|
||||||
progressBar.setVisibility(View.GONE);
|
binding.loadingImagesProgressBar.setVisibility(View.GONE);
|
||||||
if (places.size() <= 0) {
|
if (places.size() <= 0) {
|
||||||
statusTextView.setText(R.string.bookmark_empty);
|
binding.statusMessage.setText(R.string.bookmark_empty);
|
||||||
statusTextView.setVisibility(View.VISIBLE);
|
binding.statusMessage.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
statusTextView.setVisibility(View.GONE);
|
binding.statusMessage.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -122,4 +119,10 @@ public class BookmarkLocationsFragment extends DaggerFragment {
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
contributionController.handleActivityResult(getActivity(), requestCode, resultCode, data);
|
contributionController.handleActivityResult(getActivity(), requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
binding = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,20 +9,15 @@ 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.GridView;
|
|
||||||
import android.widget.ListAdapter;
|
import android.widget.ListAdapter;
|
||||||
import android.widget.ProgressBar;
|
|
||||||
import android.widget.RelativeLayout;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import butterknife.BindView;
|
|
||||||
import butterknife.ButterKnife;
|
|
||||||
import dagger.android.support.DaggerFragment;
|
import dagger.android.support.DaggerFragment;
|
||||||
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.BookmarkListRootFragment;
|
import fr.free.nrw.commons.bookmarks.BookmarkListRootFragment;
|
||||||
import fr.free.nrw.commons.category.GridViewAdapter;
|
import fr.free.nrw.commons.category.GridViewAdapter;
|
||||||
|
import fr.free.nrw.commons.databinding.FragmentBookmarksPicturesBinding;
|
||||||
import fr.free.nrw.commons.utils.NetworkUtils;
|
import fr.free.nrw.commons.utils.NetworkUtils;
|
||||||
import fr.free.nrw.commons.utils.ViewUtil;
|
import fr.free.nrw.commons.utils.ViewUtil;
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
|
|
@ -37,11 +32,7 @@ public class BookmarkPicturesFragment extends DaggerFragment {
|
||||||
private GridViewAdapter gridAdapter;
|
private GridViewAdapter gridAdapter;
|
||||||
private CompositeDisposable compositeDisposable = new CompositeDisposable();
|
private CompositeDisposable compositeDisposable = new CompositeDisposable();
|
||||||
|
|
||||||
@BindView(R.id.statusMessage) TextView statusTextView;
|
private FragmentBookmarksPicturesBinding binding;
|
||||||
@BindView(R.id.loadingImagesProgressBar) ProgressBar progressBar;
|
|
||||||
@BindView(R.id.bookmarkedPicturesList) GridView gridView;
|
|
||||||
@BindView(R.id.parentLayout) RelativeLayout parentLayout;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
BookmarkPicturesController controller;
|
BookmarkPicturesController controller;
|
||||||
|
|
||||||
|
|
@ -59,15 +50,14 @@ public class BookmarkPicturesFragment extends DaggerFragment {
|
||||||
ViewGroup container,
|
ViewGroup container,
|
||||||
Bundle savedInstanceState
|
Bundle savedInstanceState
|
||||||
) {
|
) {
|
||||||
View v = inflater.inflate(R.layout.fragment_bookmarks_pictures, container, false);
|
binding = FragmentBookmarksPicturesBinding.inflate(inflater, container, false);
|
||||||
ButterKnife.bind(this, v);
|
return binding.getRoot();
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
gridView.setOnItemClickListener((AdapterView.OnItemClickListener) getParentFragment());
|
binding.bookmarkedPicturesList.setOnItemClickListener((AdapterView.OnItemClickListener) getParentFragment());
|
||||||
initList();
|
initList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,13 +71,14 @@ public class BookmarkPicturesFragment extends DaggerFragment {
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
compositeDisposable.clear();
|
compositeDisposable.clear();
|
||||||
|
binding = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
if (controller.needRefreshBookmarkedPictures()) {
|
if (controller.needRefreshBookmarkedPictures()) {
|
||||||
gridView.setVisibility(GONE);
|
binding.bookmarkedPicturesList.setVisibility(GONE);
|
||||||
if (gridAdapter != null) {
|
if (gridAdapter != null) {
|
||||||
gridAdapter.clear();
|
gridAdapter.clear();
|
||||||
((BookmarkListRootFragment)getParentFragment()).viewPagerNotifyDataSetChanged();
|
((BookmarkListRootFragment)getParentFragment()).viewPagerNotifyDataSetChanged();
|
||||||
|
|
@ -107,8 +98,8 @@ public class BookmarkPicturesFragment extends DaggerFragment {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
progressBar.setVisibility(VISIBLE);
|
binding.loadingImagesProgressBar.setVisibility(VISIBLE);
|
||||||
statusTextView.setVisibility(GONE);
|
binding.statusMessage.setVisibility(GONE);
|
||||||
|
|
||||||
compositeDisposable.add(controller.loadBookmarkedPictures()
|
compositeDisposable.add(controller.loadBookmarkedPictures()
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
|
|
@ -120,12 +111,12 @@ public class BookmarkPicturesFragment extends DaggerFragment {
|
||||||
* Handles the UI updates for no internet scenario
|
* Handles the UI updates for no internet scenario
|
||||||
*/
|
*/
|
||||||
private void handleNoInternet() {
|
private void handleNoInternet() {
|
||||||
progressBar.setVisibility(GONE);
|
binding.loadingImagesProgressBar.setVisibility(GONE);
|
||||||
if (gridAdapter == null || gridAdapter.isEmpty()) {
|
if (gridAdapter == null || gridAdapter.isEmpty()) {
|
||||||
statusTextView.setVisibility(VISIBLE);
|
binding.statusMessage.setVisibility(VISIBLE);
|
||||||
statusTextView.setText(getString(R.string.no_internet));
|
binding.statusMessage.setText(getString(R.string.no_internet));
|
||||||
} else {
|
} else {
|
||||||
ViewUtil.showShortSnackbar(parentLayout, R.string.no_internet);
|
ViewUtil.showShortSnackbar(binding.parentLayout, R.string.no_internet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -136,7 +127,7 @@ public class BookmarkPicturesFragment extends DaggerFragment {
|
||||||
private void handleError(Throwable throwable) {
|
private void handleError(Throwable throwable) {
|
||||||
Timber.e(throwable, "Error occurred while loading images inside a category");
|
Timber.e(throwable, "Error occurred while loading images inside a category");
|
||||||
try{
|
try{
|
||||||
ViewUtil.showShortSnackbar(parentLayout, R.string.error_loading_images);
|
ViewUtil.showShortSnackbar(binding.getRoot(), R.string.error_loading_images);
|
||||||
initErrorView();
|
initErrorView();
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
@ -147,12 +138,12 @@ public class BookmarkPicturesFragment extends DaggerFragment {
|
||||||
* Handles the UI updates for a error scenario
|
* Handles the UI updates for a error scenario
|
||||||
*/
|
*/
|
||||||
private void initErrorView() {
|
private void initErrorView() {
|
||||||
progressBar.setVisibility(GONE);
|
binding.loadingImagesProgressBar.setVisibility(GONE);
|
||||||
if (gridAdapter == null || gridAdapter.isEmpty()) {
|
if (gridAdapter == null || gridAdapter.isEmpty()) {
|
||||||
statusTextView.setVisibility(VISIBLE);
|
binding.statusMessage.setVisibility(VISIBLE);
|
||||||
statusTextView.setText(getString(R.string.no_images_found));
|
binding.statusMessage.setText(getString(R.string.no_images_found));
|
||||||
} else {
|
} else {
|
||||||
statusTextView.setVisibility(GONE);
|
binding.statusMessage.setVisibility(GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -160,12 +151,12 @@ public class BookmarkPicturesFragment extends DaggerFragment {
|
||||||
* Handles the UI updates when there is no bookmarks
|
* Handles the UI updates when there is no bookmarks
|
||||||
*/
|
*/
|
||||||
private void initEmptyBookmarkListView() {
|
private void initEmptyBookmarkListView() {
|
||||||
progressBar.setVisibility(GONE);
|
binding.loadingImagesProgressBar.setVisibility(GONE);
|
||||||
if (gridAdapter == null || gridAdapter.isEmpty()) {
|
if (gridAdapter == null || gridAdapter.isEmpty()) {
|
||||||
statusTextView.setVisibility(VISIBLE);
|
binding.statusMessage.setVisibility(VISIBLE);
|
||||||
statusTextView.setText(getString(R.string.bookmark_empty));
|
binding.statusMessage.setText(getString(R.string.bookmark_empty));
|
||||||
} else {
|
} else {
|
||||||
statusTextView.setVisibility(GONE);
|
binding.statusMessage.setVisibility(GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -188,18 +179,18 @@ public class BookmarkPicturesFragment extends DaggerFragment {
|
||||||
setAdapter(collection);
|
setAdapter(collection);
|
||||||
} else {
|
} else {
|
||||||
if (gridAdapter.containsAll(collection)) {
|
if (gridAdapter.containsAll(collection)) {
|
||||||
progressBar.setVisibility(GONE);
|
binding.loadingImagesProgressBar.setVisibility(GONE);
|
||||||
statusTextView.setVisibility(GONE);
|
binding.statusMessage.setVisibility(GONE);
|
||||||
gridView.setVisibility(VISIBLE);
|
binding.bookmarkedPicturesList.setVisibility(VISIBLE);
|
||||||
gridView.setAdapter(gridAdapter);
|
binding.bookmarkedPicturesList.setAdapter(gridAdapter);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
gridAdapter.addItems(collection);
|
gridAdapter.addItems(collection);
|
||||||
((BookmarkListRootFragment) getParentFragment()).viewPagerNotifyDataSetChanged();
|
((BookmarkListRootFragment) getParentFragment()).viewPagerNotifyDataSetChanged();
|
||||||
}
|
}
|
||||||
progressBar.setVisibility(GONE);
|
binding.loadingImagesProgressBar.setVisibility(GONE);
|
||||||
statusTextView.setVisibility(GONE);
|
binding.statusMessage.setVisibility(GONE);
|
||||||
gridView.setVisibility(VISIBLE);
|
binding.bookmarkedPicturesList.setVisibility(VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -212,7 +203,7 @@ public class BookmarkPicturesFragment extends DaggerFragment {
|
||||||
R.layout.layout_category_images,
|
R.layout.layout_category_images,
|
||||||
mediaList
|
mediaList
|
||||||
);
|
);
|
||||||
gridView.setAdapter(gridAdapter);
|
binding.bookmarkedPicturesList.setAdapter(gridAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -221,6 +212,7 @@ public class BookmarkPicturesFragment extends DaggerFragment {
|
||||||
* @return GridView Adapter
|
* @return GridView Adapter
|
||||||
*/
|
*/
|
||||||
public ListAdapter getAdapter() {
|
public ListAdapter getAdapter() {
|
||||||
return gridView.getAdapter();
|
return binding.bookmarkedPicturesList.getAdapter();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ import fr.free.nrw.commons.TestCommonsApplication
|
||||||
import fr.free.nrw.commons.createTestClient
|
import fr.free.nrw.commons.createTestClient
|
||||||
import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesFragment
|
import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesFragment
|
||||||
import fr.free.nrw.commons.contributions.MainActivity
|
import fr.free.nrw.commons.contributions.MainActivity
|
||||||
|
import fr.free.nrw.commons.databinding.FragmentBookmarksBinding
|
||||||
|
import fr.free.nrw.commons.databinding.FragmentFeaturedRootBinding
|
||||||
import fr.free.nrw.commons.explore.ParentViewPager
|
import fr.free.nrw.commons.explore.ParentViewPager
|
||||||
import fr.free.nrw.commons.media.MediaDetailPagerFragment
|
import fr.free.nrw.commons.media.MediaDetailPagerFragment
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
|
|
@ -81,6 +83,8 @@ class BookmarkListRootFragmentUnitTest {
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var adapter: BookmarksPagerAdapter
|
private lateinit var adapter: BookmarksPagerAdapter
|
||||||
|
|
||||||
|
private lateinit var binding: FragmentFeaturedRootBinding
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setUp() {
|
fun setUp() {
|
||||||
MockitoAnnotations.openMocks(this)
|
MockitoAnnotations.openMocks(this)
|
||||||
|
|
@ -95,14 +99,17 @@ class BookmarkListRootFragmentUnitTest {
|
||||||
fragmentTransaction.commitNowAllowingStateLoss()
|
fragmentTransaction.commitNowAllowingStateLoss()
|
||||||
|
|
||||||
bookmarkFragment = BookmarkFragment()
|
bookmarkFragment = BookmarkFragment()
|
||||||
|
bookmarkFragment.binding = FragmentBookmarksBinding.inflate(LayoutInflater.from(activity))
|
||||||
|
|
||||||
|
binding = FragmentFeaturedRootBinding.inflate(LayoutInflater.from(activity))
|
||||||
|
|
||||||
Whitebox.setInternalState(fragment, "mChildFragmentManager", childFragmentManager)
|
Whitebox.setInternalState(fragment, "mChildFragmentManager", childFragmentManager)
|
||||||
Whitebox.setInternalState(fragment, "mParentFragment", bookmarkFragment)
|
Whitebox.setInternalState(fragment, "mParentFragment", bookmarkFragment)
|
||||||
Whitebox.setInternalState(fragment, "listFragment", listFragment)
|
Whitebox.setInternalState(fragment, "listFragment", listFragment)
|
||||||
Whitebox.setInternalState(fragment, "mediaDetails", mediaDetails)
|
Whitebox.setInternalState(fragment, "mediaDetails", mediaDetails)
|
||||||
Whitebox.setInternalState(fragment, "bookmarksPagerAdapter", bookmarksPagerAdapter)
|
Whitebox.setInternalState(fragment, "bookmarksPagerAdapter", bookmarksPagerAdapter)
|
||||||
Whitebox.setInternalState(bookmarkFragment, "tabLayout", tabLayout)
|
Whitebox.setInternalState(bookmarkFragment.binding, "tabLayout", tabLayout)
|
||||||
Whitebox.setInternalState(bookmarkFragment, "viewPager", viewPager)
|
Whitebox.setInternalState(bookmarkFragment.binding, "viewPagerBookmarks", viewPager)
|
||||||
Whitebox.setInternalState(bookmarkFragment, "adapter", adapter)
|
Whitebox.setInternalState(bookmarkFragment, "adapter", adapter)
|
||||||
|
|
||||||
whenever(childFragmentManager.beginTransaction()).thenReturn(childFragmentTransaction)
|
whenever(childFragmentManager.beginTransaction()).thenReturn(childFragmentTransaction)
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ import fr.free.nrw.commons.R
|
||||||
import fr.free.nrw.commons.TestCommonsApplication
|
import fr.free.nrw.commons.TestCommonsApplication
|
||||||
import fr.free.nrw.commons.createTestClient
|
import fr.free.nrw.commons.createTestClient
|
||||||
import fr.free.nrw.commons.category.CategoryItem
|
import fr.free.nrw.commons.category.CategoryItem
|
||||||
|
import fr.free.nrw.commons.databinding.FragmentBookmarksItemsBinding
|
||||||
import fr.free.nrw.commons.profile.ProfileActivity
|
import fr.free.nrw.commons.profile.ProfileActivity
|
||||||
import fr.free.nrw.commons.upload.structure.depictions.DepictedItem
|
import fr.free.nrw.commons.upload.structure.depictions.DepictedItem
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
|
|
@ -25,6 +26,7 @@ import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
import org.mockito.MockitoAnnotations
|
import org.mockito.MockitoAnnotations
|
||||||
|
import org.powermock.reflect.Whitebox
|
||||||
import org.robolectric.Robolectric
|
import org.robolectric.Robolectric
|
||||||
import org.robolectric.RobolectricTestRunner
|
import org.robolectric.RobolectricTestRunner
|
||||||
import org.robolectric.annotation.Config
|
import org.robolectric.annotation.Config
|
||||||
|
|
@ -45,8 +47,7 @@ class BookmarkItemsFragmentUnitTest {
|
||||||
private lateinit var recyclerView: RecyclerView
|
private lateinit var recyclerView: RecyclerView
|
||||||
private lateinit var layoutInflater: LayoutInflater
|
private lateinit var layoutInflater: LayoutInflater
|
||||||
|
|
||||||
@Mock
|
private lateinit var binding: FragmentBookmarksItemsBinding
|
||||||
private lateinit var parentLayout: RelativeLayout
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var savedInstanceState: Bundle
|
private lateinit var savedInstanceState: Bundle
|
||||||
|
|
@ -89,17 +90,16 @@ class BookmarkItemsFragmentUnitTest {
|
||||||
layoutInflater = LayoutInflater.from(activity)
|
layoutInflater = LayoutInflater.from(activity)
|
||||||
view = layoutInflater
|
view = layoutInflater
|
||||||
.inflate(R.layout.fragment_bookmarks_items, null) as View
|
.inflate(R.layout.fragment_bookmarks_items, null) as View
|
||||||
|
binding = FragmentBookmarksItemsBinding.inflate(layoutInflater)
|
||||||
|
|
||||||
statusTextView = view.findViewById(R.id.status_message)
|
statusTextView = view.findViewById(R.id.status_message)
|
||||||
progressBar = view.findViewById(R.id.loading_images_progress_bar)
|
progressBar = view.findViewById(R.id.loading_images_progress_bar)
|
||||||
recyclerView = view.findViewById(R.id.list_view)
|
recyclerView = view.findViewById(R.id.list_view)
|
||||||
|
|
||||||
fragment.statusTextView = statusTextView
|
|
||||||
fragment.progressBar = progressBar
|
|
||||||
fragment.recyclerView = recyclerView
|
|
||||||
fragment.parentLayout = parentLayout
|
|
||||||
fragment.controller = controller
|
fragment.controller = controller
|
||||||
|
|
||||||
|
Whitebox.setInternalState(fragment, "binding", binding)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ import fr.free.nrw.commons.R
|
||||||
import fr.free.nrw.commons.TestCommonsApplication
|
import fr.free.nrw.commons.TestCommonsApplication
|
||||||
import fr.free.nrw.commons.createTestClient
|
import fr.free.nrw.commons.createTestClient
|
||||||
import fr.free.nrw.commons.contributions.ContributionController
|
import fr.free.nrw.commons.contributions.ContributionController
|
||||||
|
import fr.free.nrw.commons.databinding.FragmentBookmarksLocationsBinding
|
||||||
import fr.free.nrw.commons.kvstore.JsonKvStore
|
import fr.free.nrw.commons.kvstore.JsonKvStore
|
||||||
import fr.free.nrw.commons.nearby.Place
|
import fr.free.nrw.commons.nearby.Place
|
||||||
import fr.free.nrw.commons.nearby.fragments.CommonPlaceClickActions
|
import fr.free.nrw.commons.nearby.fragments.CommonPlaceClickActions
|
||||||
|
|
@ -52,9 +53,6 @@ class BookmarkLocationFragmentUnitTests {
|
||||||
@Mock
|
@Mock
|
||||||
lateinit var store: JsonKvStore
|
lateinit var store: JsonKvStore
|
||||||
|
|
||||||
@Mock
|
|
||||||
private lateinit var parentLayout: RelativeLayout
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var savedInstanceState: Bundle
|
private lateinit var savedInstanceState: Bundle
|
||||||
|
|
||||||
|
|
@ -70,6 +68,8 @@ class BookmarkLocationFragmentUnitTests {
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var adapter: PlaceAdapter
|
private lateinit var adapter: PlaceAdapter
|
||||||
|
|
||||||
|
private lateinit var binding: FragmentBookmarksLocationsBinding
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Mock bookmark list.
|
* Get Mock bookmark list.
|
||||||
*/
|
*/
|
||||||
|
|
@ -109,20 +109,18 @@ class BookmarkLocationFragmentUnitTests {
|
||||||
layoutInflater = LayoutInflater.from(activity)
|
layoutInflater = LayoutInflater.from(activity)
|
||||||
view = layoutInflater
|
view = layoutInflater
|
||||||
.inflate(R.layout.fragment_bookmarks_locations, null) as View
|
.inflate(R.layout.fragment_bookmarks_locations, null) as View
|
||||||
|
binding = FragmentBookmarksLocationsBinding.bind(view)
|
||||||
|
|
||||||
statusTextView = view.findViewById(R.id.statusMessage)
|
statusTextView = view.findViewById(R.id.statusMessage)
|
||||||
progressBar = view.findViewById(R.id.loadingImagesProgressBar)
|
progressBar = view.findViewById(R.id.loadingImagesProgressBar)
|
||||||
recyclerView = view.findViewById(R.id.listView)
|
recyclerView = view.findViewById(R.id.listView)
|
||||||
commonPlaceClickActions = CommonPlaceClickActions(store,activity,contributionController)
|
commonPlaceClickActions = CommonPlaceClickActions(store,activity,contributionController)
|
||||||
|
|
||||||
fragment.statusTextView = statusTextView
|
|
||||||
fragment.progressBar = progressBar
|
|
||||||
fragment.recyclerView = recyclerView
|
|
||||||
fragment.parentLayout = parentLayout
|
|
||||||
fragment.bookmarkLocationDao = bookmarkLocationDao
|
fragment.bookmarkLocationDao = bookmarkLocationDao
|
||||||
fragment.controller = controller
|
fragment.controller = controller
|
||||||
fragment.commonPlaceClickActions = commonPlaceClickActions
|
fragment.commonPlaceClickActions = commonPlaceClickActions
|
||||||
Whitebox.setInternalState(fragment, "adapter", adapter)
|
Whitebox.setInternalState(fragment, "adapter", adapter)
|
||||||
|
Whitebox.setInternalState(fragment, "binding", binding)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,14 @@ import androidx.test.core.app.ApplicationProvider
|
||||||
import com.nhaarman.mockitokotlin2.any
|
import com.nhaarman.mockitokotlin2.any
|
||||||
import com.nhaarman.mockitokotlin2.times
|
import com.nhaarman.mockitokotlin2.times
|
||||||
import com.nhaarman.mockitokotlin2.verify
|
import com.nhaarman.mockitokotlin2.verify
|
||||||
|
import com.nhaarman.mockitokotlin2.whenever
|
||||||
import fr.free.nrw.commons.Media
|
import fr.free.nrw.commons.Media
|
||||||
import fr.free.nrw.commons.OkHttpConnectionFactory
|
import fr.free.nrw.commons.OkHttpConnectionFactory
|
||||||
import fr.free.nrw.commons.R
|
import fr.free.nrw.commons.R
|
||||||
import fr.free.nrw.commons.TestCommonsApplication
|
import fr.free.nrw.commons.TestCommonsApplication
|
||||||
import fr.free.nrw.commons.createTestClient
|
import fr.free.nrw.commons.createTestClient
|
||||||
import fr.free.nrw.commons.category.GridViewAdapter
|
import fr.free.nrw.commons.category.GridViewAdapter
|
||||||
|
import fr.free.nrw.commons.databinding.FragmentBookmarksPicturesBinding
|
||||||
import fr.free.nrw.commons.media.MediaClient
|
import fr.free.nrw.commons.media.MediaClient
|
||||||
import fr.free.nrw.commons.profile.ProfileActivity
|
import fr.free.nrw.commons.profile.ProfileActivity
|
||||||
import media
|
import media
|
||||||
|
|
@ -49,9 +51,9 @@ class BookmarkPicturesFragmentUnitTests {
|
||||||
|
|
||||||
private lateinit var fragment: BookmarkPicturesFragment
|
private lateinit var fragment: BookmarkPicturesFragment
|
||||||
|
|
||||||
private lateinit var context: Context
|
private lateinit var binding: FragmentBookmarksPicturesBinding
|
||||||
|
|
||||||
private lateinit var view: View
|
private lateinit var context: Context
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
lateinit var statusTextView: TextView
|
lateinit var statusTextView: TextView
|
||||||
|
|
@ -97,13 +99,7 @@ class BookmarkPicturesFragmentUnitTests {
|
||||||
fragmentTransaction.add(fragment, null)
|
fragmentTransaction.add(fragment, null)
|
||||||
fragmentTransaction.commit()
|
fragmentTransaction.commit()
|
||||||
|
|
||||||
view = LayoutInflater.from(activity)
|
binding = FragmentBookmarksPicturesBinding.inflate(LayoutInflater.from(activity))
|
||||||
.inflate(R.layout.fragment_bookmarks_pictures, null) as View
|
|
||||||
|
|
||||||
fragment.statusTextView = statusTextView
|
|
||||||
fragment.progressBar = progressBar
|
|
||||||
fragment.gridView = gridView
|
|
||||||
fragment.parentLayout = parentLayout
|
|
||||||
|
|
||||||
val bookmarkDao = BookmarkPicturesDao { client }
|
val bookmarkDao = BookmarkPicturesDao { client }
|
||||||
|
|
||||||
|
|
@ -116,6 +112,12 @@ class BookmarkPicturesFragmentUnitTests {
|
||||||
0,
|
0,
|
||||||
listOf(media())
|
listOf(media())
|
||||||
))
|
))
|
||||||
|
Whitebox.setInternalState(fragment, "binding", binding)
|
||||||
|
|
||||||
|
Whitebox.setInternalState(binding, "statusMessage", statusTextView)
|
||||||
|
Whitebox.setInternalState(binding, "loadingImagesProgressBar", progressBar)
|
||||||
|
Whitebox.setInternalState(binding, "bookmarkedPicturesList", gridView)
|
||||||
|
Whitebox.setInternalState(binding, "parentLayout", parentLayout)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -127,7 +129,7 @@ class BookmarkPicturesFragmentUnitTests {
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun testOnViewCreated() {
|
fun testOnViewCreated() {
|
||||||
fragment.onViewCreated(view, savedInstanceState)
|
fragment.onViewCreated(binding.root, savedInstanceState)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue