mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Migrated Explore Package From Butterknife to ViewBinding (#5592)
* Butterknife to ViewBinding * code cleanup and tests migrated to binding * tests fixed * adjustments and code cleanup
This commit is contained in:
parent
7b63185d5a
commit
2076bf9b29
15 changed files with 246 additions and 355 deletions
|
|
@ -11,12 +11,11 @@ import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.viewpager.widget.ViewPager.OnPageChangeListener;
|
import androidx.viewpager.widget.ViewPager.OnPageChangeListener;
|
||||||
import butterknife.BindView;
|
|
||||||
import butterknife.ButterKnife;
|
|
||||||
import com.google.android.material.tabs.TabLayout;
|
import com.google.android.material.tabs.TabLayout;
|
||||||
import fr.free.nrw.commons.R;
|
import fr.free.nrw.commons.R;
|
||||||
import fr.free.nrw.commons.ViewPagerAdapter;
|
import fr.free.nrw.commons.ViewPagerAdapter;
|
||||||
import fr.free.nrw.commons.contributions.MainActivity;
|
import fr.free.nrw.commons.contributions.MainActivity;
|
||||||
|
import fr.free.nrw.commons.databinding.FragmentExploreBinding;
|
||||||
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
||||||
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;
|
||||||
|
|
@ -33,10 +32,8 @@ public class ExploreFragment extends CommonsDaggerSupportFragment {
|
||||||
private static final String EXPLORE_MAP = "Map";
|
private static final String EXPLORE_MAP = "Map";
|
||||||
private static final String MEDIA_DETAILS_FRAGMENT_TAG = "MediaDetailsFragment";
|
private static final String MEDIA_DETAILS_FRAGMENT_TAG = "MediaDetailsFragment";
|
||||||
|
|
||||||
@BindView(R.id.tab_layout)
|
|
||||||
TabLayout tabLayout;
|
public FragmentExploreBinding binding;
|
||||||
@BindView(R.id.viewPager)
|
|
||||||
ParentViewPager viewPager;
|
|
||||||
ViewPagerAdapter viewPagerAdapter;
|
ViewPagerAdapter viewPagerAdapter;
|
||||||
private ExploreListRootFragment featuredRootFragment;
|
private ExploreListRootFragment featuredRootFragment;
|
||||||
private ExploreListRootFragment mobileRootFragment;
|
private ExploreListRootFragment mobileRootFragment;
|
||||||
|
|
@ -46,7 +43,10 @@ public class ExploreFragment extends CommonsDaggerSupportFragment {
|
||||||
public JsonKvStore applicationKvStore;
|
public JsonKvStore applicationKvStore;
|
||||||
|
|
||||||
public void setScroll(boolean canScroll){
|
public void setScroll(boolean canScroll){
|
||||||
viewPager.setCanScroll(canScroll);
|
if (binding != null)
|
||||||
|
{
|
||||||
|
binding.viewPager.setCanScroll(canScroll);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
|
@ -56,22 +56,17 @@ public class ExploreFragment extends CommonsDaggerSupportFragment {
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
|
||||||
@Nullable Bundle savedInstanceState) {
|
@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
View view = inflater.inflate(R.layout.fragment_explore, container, false);
|
binding = FragmentExploreBinding.inflate(inflater, container, false);
|
||||||
ButterKnife.bind(this, view);
|
|
||||||
viewPagerAdapter = new ViewPagerAdapter(getChildFragmentManager());
|
viewPagerAdapter = new ViewPagerAdapter(getChildFragmentManager());
|
||||||
viewPager.setAdapter(viewPagerAdapter);
|
binding.viewPager.setAdapter(viewPagerAdapter);
|
||||||
viewPager.setId(R.id.viewPager);
|
binding.viewPager.setId(R.id.viewPager);
|
||||||
tabLayout.setupWithViewPager(viewPager);
|
binding.tabLayout.setupWithViewPager(binding.viewPager);
|
||||||
viewPager.addOnPageChangeListener(new OnPageChangeListener() {
|
binding.viewPager.addOnPageChangeListener(new OnPageChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onPageScrolled(int position, float positionOffset,
|
public void onPageScrolled(int position, float positionOffset,
|
||||||
int positionOffsetPixels) {
|
int positionOffsetPixels) {
|
||||||
|
|
@ -81,9 +76,9 @@ public class ExploreFragment extends CommonsDaggerSupportFragment {
|
||||||
@Override
|
@Override
|
||||||
public void onPageSelected(int position) {
|
public void onPageSelected(int position) {
|
||||||
if (position == 2) {
|
if (position == 2) {
|
||||||
viewPager.setCanScroll(false);
|
binding.viewPager.setCanScroll(false);
|
||||||
} else {
|
} else {
|
||||||
viewPager.setCanScroll(true);
|
binding.viewPager.setCanScroll(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,7 +89,7 @@ public class ExploreFragment extends CommonsDaggerSupportFragment {
|
||||||
});
|
});
|
||||||
setTabs();
|
setTabs();
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
return view;
|
return binding.getRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -133,13 +128,13 @@ public class ExploreFragment extends CommonsDaggerSupportFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onBackPressed() {
|
public boolean onBackPressed() {
|
||||||
if (tabLayout.getSelectedTabPosition() == 0) {
|
if (binding.tabLayout.getSelectedTabPosition() == 0) {
|
||||||
if (featuredRootFragment.backPressed()) {
|
if (featuredRootFragment.backPressed()) {
|
||||||
((BaseActivity) getActivity()).getSupportActionBar()
|
((BaseActivity) getActivity()).getSupportActionBar()
|
||||||
.setDisplayHomeAsUpEnabled(false);
|
.setDisplayHomeAsUpEnabled(false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (tabLayout.getSelectedTabPosition() == 1) { //Mobile root fragment
|
} else if (binding.tabLayout.getSelectedTabPosition() == 1) { //Mobile root fragment
|
||||||
if (mobileRootFragment.backPressed()) {
|
if (mobileRootFragment.backPressed()) {
|
||||||
((BaseActivity) getActivity()).getSupportActionBar()
|
((BaseActivity) getActivity()).getSupportActionBar()
|
||||||
.setDisplayHomeAsUpEnabled(false);
|
.setDisplayHomeAsUpEnabled(false);
|
||||||
|
|
@ -180,6 +175,12 @@ public class ExploreFragment extends CommonsDaggerSupportFragment {
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
binding = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,11 @@ 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 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.category.CategoryImagesCallback;
|
import fr.free.nrw.commons.category.CategoryImagesCallback;
|
||||||
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.explore.categories.media.CategoriesMediaFragment;
|
import fr.free.nrw.commons.explore.categories.media.CategoriesMediaFragment;
|
||||||
import fr.free.nrw.commons.media.MediaDetailPagerFragment;
|
import fr.free.nrw.commons.media.MediaDetailPagerFragment;
|
||||||
|
|
@ -26,8 +25,7 @@ public class ExploreListRootFragment extends CommonsDaggerSupportFragment implem
|
||||||
private MediaDetailPagerFragment mediaDetails;
|
private MediaDetailPagerFragment mediaDetails;
|
||||||
private CategoriesMediaFragment listFragment;
|
private CategoriesMediaFragment listFragment;
|
||||||
|
|
||||||
@BindView(R.id.explore_container)
|
private FragmentFeaturedRootBinding binding;
|
||||||
FrameLayout container;
|
|
||||||
|
|
||||||
public ExploreListRootFragment() {
|
public ExploreListRootFragment() {
|
||||||
//empty constructor necessary otherwise crashes on recreate
|
//empty constructor necessary otherwise crashes on recreate
|
||||||
|
|
@ -47,9 +45,9 @@ public class ExploreListRootFragment extends CommonsDaggerSupportFragment implem
|
||||||
@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);
|
|
||||||
ButterKnife.bind(this, view);
|
binding = FragmentFeaturedRootBinding.inflate(inflater, container, false);
|
||||||
return view;
|
return binding.getRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -109,8 +107,12 @@ public class ExploreListRootFragment extends CommonsDaggerSupportFragment implem
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMediaClicked(int position) {
|
public void onMediaClicked(int position) {
|
||||||
container.setVisibility(View.VISIBLE);
|
if (binding!=null) {
|
||||||
((ExploreFragment) getParentFragment()).tabLayout.setVisibility(View.GONE);
|
binding.exploreContainer.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
if (((ExploreFragment) getParentFragment()).binding!=null) {
|
||||||
|
((ExploreFragment) getParentFragment()).binding.tabLayout.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
mediaDetails = MediaDetailPagerFragment.newInstance(false, true);
|
mediaDetails = MediaDetailPagerFragment.newInstance(false, true);
|
||||||
((ExploreFragment) getParentFragment()).setScroll(false);
|
((ExploreFragment) getParentFragment()).setScroll(false);
|
||||||
setFragment(mediaDetails, listFragment);
|
setFragment(mediaDetails, listFragment);
|
||||||
|
|
@ -185,16 +187,29 @@ public class ExploreListRootFragment extends CommonsDaggerSupportFragment implem
|
||||||
*/
|
*/
|
||||||
public boolean backPressed() {
|
public boolean backPressed() {
|
||||||
if (null != mediaDetails && mediaDetails.isVisible()) {
|
if (null != mediaDetails && mediaDetails.isVisible()) {
|
||||||
((ExploreFragment) getParentFragment()).tabLayout.setVisibility(View.VISIBLE);
|
if (((ExploreFragment) getParentFragment()).binding != null) {
|
||||||
|
((ExploreFragment) getParentFragment()).binding.tabLayout.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
removeFragment(mediaDetails);
|
removeFragment(mediaDetails);
|
||||||
((ExploreFragment) getParentFragment()).setScroll(true);
|
((ExploreFragment) getParentFragment()).setScroll(true);
|
||||||
setFragment(listFragment, mediaDetails);
|
setFragment(listFragment, mediaDetails);
|
||||||
((MainActivity) getActivity()).showTabs();
|
((MainActivity) getActivity()).showTabs();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
((MainActivity) getActivity()).setSelectedItemId(NavTab.CONTRIBUTIONS.code());
|
if (((MainActivity) getActivity()) != null) {
|
||||||
|
((MainActivity) getActivity()).setSelectedItemId(NavTab.CONTRIBUTIONS.code());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (((MainActivity) getActivity()) != null) {
|
||||||
|
((MainActivity) getActivity()).showTabs();
|
||||||
}
|
}
|
||||||
((MainActivity) getActivity()).showTabs();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
|
||||||
|
binding = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,11 @@ 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 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.category.CategoryImagesCallback;
|
import fr.free.nrw.commons.category.CategoryImagesCallback;
|
||||||
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.explore.map.ExploreMapFragment;
|
import fr.free.nrw.commons.explore.map.ExploreMapFragment;
|
||||||
import fr.free.nrw.commons.media.MediaDetailPagerFragment;
|
import fr.free.nrw.commons.media.MediaDetailPagerFragment;
|
||||||
|
|
@ -26,8 +25,7 @@ public class ExploreMapRootFragment extends CommonsDaggerSupportFragment impleme
|
||||||
private MediaDetailPagerFragment mediaDetails;
|
private MediaDetailPagerFragment mediaDetails;
|
||||||
private ExploreMapFragment mapFragment;
|
private ExploreMapFragment mapFragment;
|
||||||
|
|
||||||
@BindView(R.id.explore_container)
|
private FragmentFeaturedRootBinding binding;
|
||||||
FrameLayout container;
|
|
||||||
|
|
||||||
public ExploreMapRootFragment() {
|
public ExploreMapRootFragment() {
|
||||||
//empty constructor necessary otherwise crashes on recreate
|
//empty constructor necessary otherwise crashes on recreate
|
||||||
|
|
@ -54,9 +52,10 @@ public class ExploreMapRootFragment extends CommonsDaggerSupportFragment impleme
|
||||||
@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);
|
|
||||||
ButterKnife.bind(this, view);
|
binding = FragmentFeaturedRootBinding.inflate(inflater, container, false);
|
||||||
return view;
|
|
||||||
|
return binding.getRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -116,8 +115,8 @@ public class ExploreMapRootFragment extends CommonsDaggerSupportFragment impleme
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMediaClicked(int position) {
|
public void onMediaClicked(int position) {
|
||||||
container.setVisibility(View.VISIBLE);
|
binding.exploreContainer.setVisibility(View.VISIBLE);
|
||||||
((ExploreFragment) getParentFragment()).tabLayout.setVisibility(View.GONE);
|
((ExploreFragment) getParentFragment()).binding.tabLayout.setVisibility(View.GONE);
|
||||||
mediaDetails = MediaDetailPagerFragment.newInstance(false, true);
|
mediaDetails = MediaDetailPagerFragment.newInstance(false, true);
|
||||||
((ExploreFragment) getParentFragment()).setScroll(false);
|
((ExploreFragment) getParentFragment()).setScroll(false);
|
||||||
setFragment(mediaDetails, mapFragment);
|
setFragment(mediaDetails, mapFragment);
|
||||||
|
|
@ -192,7 +191,7 @@ public class ExploreMapRootFragment extends CommonsDaggerSupportFragment impleme
|
||||||
*/
|
*/
|
||||||
public boolean backPressed() {
|
public boolean backPressed() {
|
||||||
if (null != mediaDetails && mediaDetails.isVisible()) {
|
if (null != mediaDetails && mediaDetails.isVisible()) {
|
||||||
((ExploreFragment) getParentFragment()).tabLayout.setVisibility(View.VISIBLE);
|
((ExploreFragment) getParentFragment()).binding.tabLayout.setVisibility(View.VISIBLE);
|
||||||
removeFragment(mediaDetails);
|
removeFragment(mediaDetails);
|
||||||
((ExploreFragment) getParentFragment()).setScroll(true);
|
((ExploreFragment) getParentFragment()).setScroll(true);
|
||||||
setFragment(mapFragment, mediaDetails);
|
setFragment(mapFragment, mediaDetails);
|
||||||
|
|
@ -213,4 +212,11 @@ public class ExploreMapRootFragment extends CommonsDaggerSupportFragment impleme
|
||||||
((MainActivity) getActivity()).showTabs();
|
((MainActivity) getActivity()).showTabs();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
|
||||||
|
binding = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,23 +3,17 @@ package fr.free.nrw.commons.explore;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.FrameLayout;
|
|
||||||
import android.widget.SearchView;
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.fragment.app.FragmentTransaction;
|
import androidx.fragment.app.FragmentTransaction;
|
||||||
import androidx.viewpager.widget.ViewPager;
|
|
||||||
import butterknife.BindView;
|
|
||||||
import butterknife.ButterKnife;
|
|
||||||
import com.google.android.material.tabs.TabLayout;
|
|
||||||
import com.jakewharton.rxbinding2.view.RxView;
|
import com.jakewharton.rxbinding2.view.RxView;
|
||||||
import com.jakewharton.rxbinding2.widget.RxSearchView;
|
import com.jakewharton.rxbinding2.widget.RxSearchView;
|
||||||
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.ViewPagerAdapter;
|
import fr.free.nrw.commons.ViewPagerAdapter;
|
||||||
import fr.free.nrw.commons.category.CategoryImagesCallback;
|
import fr.free.nrw.commons.category.CategoryImagesCallback;
|
||||||
|
import fr.free.nrw.commons.databinding.ActivitySearchBinding;
|
||||||
import fr.free.nrw.commons.explore.categories.search.SearchCategoryFragment;
|
import fr.free.nrw.commons.explore.categories.search.SearchCategoryFragment;
|
||||||
import fr.free.nrw.commons.explore.depictions.search.SearchDepictionsFragment;
|
import fr.free.nrw.commons.explore.depictions.search.SearchDepictionsFragment;
|
||||||
import fr.free.nrw.commons.explore.media.SearchMediaFragment;
|
import fr.free.nrw.commons.explore.media.SearchMediaFragment;
|
||||||
|
|
@ -45,13 +39,6 @@ import timber.log.Timber;
|
||||||
public class SearchActivity extends BaseActivity
|
public class SearchActivity extends BaseActivity
|
||||||
implements MediaDetailPagerFragment.MediaDetailProvider, CategoryImagesCallback {
|
implements MediaDetailPagerFragment.MediaDetailProvider, CategoryImagesCallback {
|
||||||
|
|
||||||
@BindView(R.id.toolbar_search) Toolbar toolbar;
|
|
||||||
@BindView(R.id.searchHistoryContainer) FrameLayout searchHistoryContainer;
|
|
||||||
@BindView(R.id.mediaContainer) FrameLayout mediaContainer;
|
|
||||||
@BindView(R.id.searchBox) SearchView searchView;
|
|
||||||
@BindView(R.id.tab_layout) TabLayout tabLayout;
|
|
||||||
@BindView(R.id.viewPager) ViewPager viewPager;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
RecentSearchesDao recentSearchesDao;
|
RecentSearchesDao recentSearchesDao;
|
||||||
|
|
||||||
|
|
@ -63,25 +50,28 @@ public class SearchActivity extends BaseActivity
|
||||||
private MediaDetailPagerFragment mediaDetails;
|
private MediaDetailPagerFragment mediaDetails;
|
||||||
ViewPagerAdapter viewPagerAdapter;
|
ViewPagerAdapter viewPagerAdapter;
|
||||||
|
|
||||||
|
private ActivitySearchBinding binding;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_search);
|
binding = ActivitySearchBinding.inflate(getLayoutInflater());
|
||||||
ButterKnife.bind(this);
|
setContentView(binding.getRoot());
|
||||||
|
|
||||||
setTitle(getString(R.string.title_activity_search));
|
setTitle(getString(R.string.title_activity_search));
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(binding.toolbarSearch);
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
toolbar.setNavigationOnClickListener(v->onBackPressed());
|
binding.toolbarSearch.setNavigationOnClickListener(v->onBackPressed());
|
||||||
supportFragmentManager = getSupportFragmentManager();
|
supportFragmentManager = getSupportFragmentManager();
|
||||||
setSearchHistoryFragment();
|
setSearchHistoryFragment();
|
||||||
viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
|
viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
|
||||||
viewPager.setAdapter(viewPagerAdapter);
|
binding.viewPager.setAdapter(viewPagerAdapter);
|
||||||
viewPager.setOffscreenPageLimit(2); // Because we want all the fragments to be alive
|
binding.viewPager.setOffscreenPageLimit(2); // Because we want all the fragments to be alive
|
||||||
tabLayout.setupWithViewPager(viewPager);
|
binding.tabLayout.setupWithViewPager(binding.viewPager);
|
||||||
setTabs();
|
setTabs();
|
||||||
searchView.setQueryHint(getString(R.string.search_commons));
|
binding.searchBox.setQueryHint(getString(R.string.search_commons));
|
||||||
searchView.onActionViewExpanded();
|
binding.searchBox.onActionViewExpanded();
|
||||||
searchView.clearFocus();
|
binding.searchBox.clearFocus();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -113,8 +103,8 @@ public class SearchActivity extends BaseActivity
|
||||||
|
|
||||||
viewPagerAdapter.setTabData(fragmentList, titleList);
|
viewPagerAdapter.setTabData(fragmentList, titleList);
|
||||||
viewPagerAdapter.notifyDataSetChanged();
|
viewPagerAdapter.notifyDataSetChanged();
|
||||||
compositeDisposable.add(RxSearchView.queryTextChanges(searchView)
|
compositeDisposable.add(RxSearchView.queryTextChanges(binding.searchBox)
|
||||||
.takeUntil(RxView.detaches(searchView))
|
.takeUntil(RxView.detaches(binding.searchBox))
|
||||||
.debounce(500, TimeUnit.MILLISECONDS)
|
.debounce(500, TimeUnit.MILLISECONDS)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(this::handleSearch, Timber::e
|
.subscribe(this::handleSearch, Timber::e
|
||||||
|
|
@ -124,9 +114,9 @@ public class SearchActivity extends BaseActivity
|
||||||
private void handleSearch(final CharSequence query) {
|
private void handleSearch(final CharSequence query) {
|
||||||
if (!TextUtils.isEmpty(query)) {
|
if (!TextUtils.isEmpty(query)) {
|
||||||
saveRecentSearch(query.toString());
|
saveRecentSearch(query.toString());
|
||||||
viewPager.setVisibility(View.VISIBLE);
|
binding.viewPager.setVisibility(View.VISIBLE);
|
||||||
tabLayout.setVisibility(View.VISIBLE);
|
binding.tabLayout.setVisibility(View.VISIBLE);
|
||||||
searchHistoryContainer.setVisibility(View.GONE);
|
binding.searchHistoryContainer.setVisibility(View.GONE);
|
||||||
|
|
||||||
if (FragmentUtils.isFragmentUIActive(searchDepictionsFragment)) {
|
if (FragmentUtils.isFragmentUIActive(searchDepictionsFragment)) {
|
||||||
searchDepictionsFragment.onQueryUpdated(query.toString());
|
searchDepictionsFragment.onQueryUpdated(query.toString());
|
||||||
|
|
@ -144,10 +134,10 @@ public class SearchActivity extends BaseActivity
|
||||||
else {
|
else {
|
||||||
//Open RecentSearchesFragment
|
//Open RecentSearchesFragment
|
||||||
recentSearchesFragment.updateRecentSearches();
|
recentSearchesFragment.updateRecentSearches();
|
||||||
viewPager.setVisibility(View.GONE);
|
binding.viewPager.setVisibility(View.GONE);
|
||||||
tabLayout.setVisibility(View.GONE);
|
binding.tabLayout.setVisibility(View.GONE);
|
||||||
setSearchHistoryFragment();
|
setSearchHistoryFragment();
|
||||||
searchHistoryContainer.setVisibility(View.VISIBLE);
|
binding.searchHistoryContainer.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -215,10 +205,10 @@ public class SearchActivity extends BaseActivity
|
||||||
@Override
|
@Override
|
||||||
public void onMediaClicked(int index) {
|
public void onMediaClicked(int index) {
|
||||||
ViewUtil.hideKeyboard(this.findViewById(R.id.searchBox));
|
ViewUtil.hideKeyboard(this.findViewById(R.id.searchBox));
|
||||||
tabLayout.setVisibility(View.GONE);
|
binding.tabLayout.setVisibility(View.GONE);
|
||||||
viewPager.setVisibility(View.GONE);
|
binding.viewPager.setVisibility(View.GONE);
|
||||||
mediaContainer.setVisibility(View.VISIBLE);
|
binding.mediaContainer.setVisibility(View.VISIBLE);
|
||||||
searchView.setVisibility(View.GONE);// to remove searchview when mediaDetails fragment open
|
binding.searchBox.setVisibility(View.GONE);// to remove searchview when mediaDetails fragment open
|
||||||
if (mediaDetails == null || !mediaDetails.isVisible()) {
|
if (mediaDetails == null || !mediaDetails.isVisible()) {
|
||||||
// set isFeaturedImage true for featured images, to include author field on media detail
|
// set isFeaturedImage true for featured images, to include author field on media detail
|
||||||
mediaDetails = MediaDetailPagerFragment.newInstance(false, true);
|
mediaDetails = MediaDetailPagerFragment.newInstance(false, true);
|
||||||
|
|
@ -269,12 +259,12 @@ public class SearchActivity extends BaseActivity
|
||||||
}
|
}
|
||||||
if (getSupportFragmentManager().getBackStackEntryCount() == 1) {
|
if (getSupportFragmentManager().getBackStackEntryCount() == 1) {
|
||||||
// back to search so show search toolbar and hide navigation toolbar
|
// back to search so show search toolbar and hide navigation toolbar
|
||||||
searchView.setVisibility(View.VISIBLE);//set the searchview
|
binding.searchBox.setVisibility(View.VISIBLE);//set the searchview
|
||||||
tabLayout.setVisibility(View.VISIBLE);
|
binding.tabLayout.setVisibility(View.VISIBLE);
|
||||||
viewPager.setVisibility(View.VISIBLE);
|
binding.viewPager.setVisibility(View.VISIBLE);
|
||||||
mediaContainer.setVisibility(View.GONE);
|
binding.mediaContainer.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
toolbar.setVisibility(View.GONE);
|
binding.toolbarSearch.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
super.onBackPressed();
|
super.onBackPressed();
|
||||||
}
|
}
|
||||||
|
|
@ -284,15 +274,16 @@ public class SearchActivity extends BaseActivity
|
||||||
* @param query Recent Search Query
|
* @param query Recent Search Query
|
||||||
*/
|
*/
|
||||||
public void updateText(String query) {
|
public void updateText(String query) {
|
||||||
searchView.setQuery(query, true);
|
binding.searchBox.setQuery(query, true);
|
||||||
// Clear focus of searchView now. searchView.clearFocus(); does not seem to work Check the below link for more details.
|
// Clear focus of searchView now. searchView.clearFocus(); does not seem to work Check the below link for more details.
|
||||||
// https://stackoverflow.com/questions/6117967/how-to-remove-focus-without-setting-focus-to-another-control/15481511
|
// https://stackoverflow.com/questions/6117967/how-to-remove-focus-without-setting-focus-to-another-control/15481511
|
||||||
viewPager.requestFocus();
|
binding.viewPager.requestFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDestroy() {
|
@Override protected void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
//Dispose the disposables when the activity is destroyed
|
//Dispose the disposables when the activity is destroyed
|
||||||
compositeDisposable.dispose();
|
compositeDisposable.dispose();
|
||||||
|
binding = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,6 @@ import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.viewpager.widget.ViewPager;
|
import androidx.viewpager.widget.ViewPager;
|
||||||
import butterknife.BindView;
|
|
||||||
import butterknife.ButterKnife;
|
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
import com.google.android.material.tabs.TabLayout;
|
import com.google.android.material.tabs.TabLayout;
|
||||||
import fr.free.nrw.commons.Media;
|
import fr.free.nrw.commons.Media;
|
||||||
|
|
@ -23,6 +21,7 @@ import fr.free.nrw.commons.Utils;
|
||||||
import fr.free.nrw.commons.ViewPagerAdapter;
|
import fr.free.nrw.commons.ViewPagerAdapter;
|
||||||
import fr.free.nrw.commons.bookmarks.items.BookmarkItemsDao;
|
import fr.free.nrw.commons.bookmarks.items.BookmarkItemsDao;
|
||||||
import fr.free.nrw.commons.category.CategoryImagesCallback;
|
import fr.free.nrw.commons.category.CategoryImagesCallback;
|
||||||
|
import fr.free.nrw.commons.databinding.ActivityWikidataItemDetailsBinding;
|
||||||
import fr.free.nrw.commons.explore.depictions.child.ChildDepictionsFragment;
|
import fr.free.nrw.commons.explore.depictions.child.ChildDepictionsFragment;
|
||||||
import fr.free.nrw.commons.explore.depictions.media.DepictedImagesFragment;
|
import fr.free.nrw.commons.explore.depictions.media.DepictedImagesFragment;
|
||||||
import fr.free.nrw.commons.explore.depictions.parent.ParentDepictionsFragment;
|
import fr.free.nrw.commons.explore.depictions.parent.ParentDepictionsFragment;
|
||||||
|
|
@ -57,14 +56,7 @@ public class WikidataItemDetailsActivity extends BaseActivity implements MediaDe
|
||||||
@Inject
|
@Inject
|
||||||
DepictModel depictModel;
|
DepictModel depictModel;
|
||||||
private String wikidataItemName;
|
private String wikidataItemName;
|
||||||
@BindView(R.id.mediaContainer)
|
private ActivityWikidataItemDetailsBinding binding;
|
||||||
FrameLayout mediaContainer;
|
|
||||||
@BindView(R.id.tab_layout)
|
|
||||||
TabLayout tabLayout;
|
|
||||||
@BindView(R.id.viewPager)
|
|
||||||
ViewPager viewPager;
|
|
||||||
@BindView(R.id.toolbar)
|
|
||||||
Toolbar toolbar;
|
|
||||||
|
|
||||||
ViewPagerAdapter viewPagerAdapter;
|
ViewPagerAdapter viewPagerAdapter;
|
||||||
private DepictedItem wikidataItem;
|
private DepictedItem wikidataItem;
|
||||||
|
|
@ -72,19 +64,20 @@ public class WikidataItemDetailsActivity extends BaseActivity implements MediaDe
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_wikidata_item_details);
|
|
||||||
ButterKnife.bind(this);
|
binding = ActivityWikidataItemDetailsBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(binding.getRoot());
|
||||||
compositeDisposable = new CompositeDisposable();
|
compositeDisposable = new CompositeDisposable();
|
||||||
supportFragmentManager = getSupportFragmentManager();
|
supportFragmentManager = getSupportFragmentManager();
|
||||||
viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
|
viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
|
||||||
viewPager.setAdapter(viewPagerAdapter);
|
binding.viewPager.setAdapter(viewPagerAdapter);
|
||||||
viewPager.setOffscreenPageLimit(2);
|
binding.viewPager.setOffscreenPageLimit(2);
|
||||||
tabLayout.setupWithViewPager(viewPager);
|
binding.tabLayout.setupWithViewPager(binding.viewPager);
|
||||||
|
|
||||||
final DepictedItem depictedItem = getIntent().getParcelableExtra(
|
final DepictedItem depictedItem = getIntent().getParcelableExtra(
|
||||||
WikidataConstants.BOOKMARKS_ITEMS);
|
WikidataConstants.BOOKMARKS_ITEMS);
|
||||||
wikidataItem = depictedItem;
|
wikidataItem = depictedItem;
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(binding.toolbarBinding.toolbar);
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
setTabs();
|
setTabs();
|
||||||
setPageTitle();
|
setPageTitle();
|
||||||
|
|
@ -137,7 +130,7 @@ public class WikidataItemDetailsActivity extends BaseActivity implements MediaDe
|
||||||
fragmentList.add(parentDepictionsFragment);
|
fragmentList.add(parentDepictionsFragment);
|
||||||
titleList.add(getResources().getString(R.string.title_for_parent_classes));
|
titleList.add(getResources().getString(R.string.title_for_parent_classes));
|
||||||
viewPagerAdapter.setTabData(fragmentList, titleList);
|
viewPagerAdapter.setTabData(fragmentList, titleList);
|
||||||
viewPager.setOffscreenPageLimit(2);
|
binding.viewPager.setOffscreenPageLimit(2);
|
||||||
viewPagerAdapter.notifyDataSetChanged();
|
viewPagerAdapter.notifyDataSetChanged();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -148,9 +141,9 @@ public class WikidataItemDetailsActivity extends BaseActivity implements MediaDe
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onMediaClicked(int position) {
|
public void onMediaClicked(int position) {
|
||||||
tabLayout.setVisibility(View.GONE);
|
binding.tabLayout.setVisibility(View.GONE);
|
||||||
viewPager.setVisibility(View.GONE);
|
binding.viewPager.setVisibility(View.GONE);
|
||||||
mediaContainer.setVisibility(View.VISIBLE);
|
binding.mediaContainer.setVisibility(View.VISIBLE);
|
||||||
if (mediaDetailPagerFragment == null || !mediaDetailPagerFragment.isVisible()) {
|
if (mediaDetailPagerFragment == null || !mediaDetailPagerFragment.isVisible()) {
|
||||||
// set isFeaturedImage true for featured images, to include author field on media detail
|
// set isFeaturedImage true for featured images, to include author field on media detail
|
||||||
mediaDetailPagerFragment = MediaDetailPagerFragment.newInstance(false, true);
|
mediaDetailPagerFragment = MediaDetailPagerFragment.newInstance(false, true);
|
||||||
|
|
@ -183,9 +176,9 @@ public class WikidataItemDetailsActivity extends BaseActivity implements MediaDe
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
if (supportFragmentManager.getBackStackEntryCount() == 1){
|
if (supportFragmentManager.getBackStackEntryCount() == 1){
|
||||||
tabLayout.setVisibility(View.VISIBLE);
|
binding.tabLayout.setVisibility(View.VISIBLE);
|
||||||
viewPager.setVisibility(View.VISIBLE);
|
binding.viewPager.setVisibility(View.VISIBLE);
|
||||||
mediaContainer.setVisibility(View.GONE);
|
binding.mediaContainer.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
super.onBackPressed();
|
super.onBackPressed();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,10 +27,6 @@ import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.LinearLayout;
|
|
||||||
import android.widget.ProgressBar;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import androidx.activity.result.ActivityResultCallback;
|
import androidx.activity.result.ActivityResultCallback;
|
||||||
import androidx.activity.result.ActivityResultLauncher;
|
import androidx.activity.result.ActivityResultLauncher;
|
||||||
|
|
@ -39,8 +35,6 @@ import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.widget.AppCompatTextView;
|
import androidx.appcompat.widget.AppCompatTextView;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import butterknife.BindView;
|
|
||||||
import butterknife.ButterKnife;
|
|
||||||
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
|
|
@ -50,6 +44,7 @@ import fr.free.nrw.commons.Media;
|
||||||
import fr.free.nrw.commons.R;
|
import fr.free.nrw.commons.R;
|
||||||
import fr.free.nrw.commons.Utils;
|
import fr.free.nrw.commons.Utils;
|
||||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao;
|
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao;
|
||||||
|
import fr.free.nrw.commons.databinding.FragmentExploreMapBinding;
|
||||||
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
||||||
import fr.free.nrw.commons.explore.ExploreMapRootFragment;
|
import fr.free.nrw.commons.explore.ExploreMapRootFragment;
|
||||||
import fr.free.nrw.commons.explore.paging.LiveDataConverter;
|
import fr.free.nrw.commons.explore.paging.LiveDataConverter;
|
||||||
|
|
@ -130,31 +125,7 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
|
||||||
|
|
||||||
private ExploreMapPresenter presenter;
|
private ExploreMapPresenter presenter;
|
||||||
|
|
||||||
@BindView(R.id.map_view)
|
public FragmentExploreMapBinding binding;
|
||||||
org.osmdroid.views.MapView mapView;
|
|
||||||
@BindView(R.id.bottom_sheet_details)
|
|
||||||
View bottomSheetDetails;
|
|
||||||
@BindView(R.id.map_progress_bar)
|
|
||||||
ProgressBar progressBar;
|
|
||||||
@BindView(R.id.fab_recenter)
|
|
||||||
FloatingActionButton fabRecenter;
|
|
||||||
@BindView(R.id.search_this_area_button)
|
|
||||||
Button searchThisAreaButton;
|
|
||||||
@BindView(R.id.tv_attribution)
|
|
||||||
AppCompatTextView tvAttribution;
|
|
||||||
|
|
||||||
@BindView(R.id.directionsButton)
|
|
||||||
LinearLayout directionsButton;
|
|
||||||
@BindView(R.id.commonsButton)
|
|
||||||
LinearLayout commonsButton;
|
|
||||||
@BindView(R.id.mediaDetailsButton)
|
|
||||||
LinearLayout mediaDetailsButton;
|
|
||||||
@BindView(R.id.description)
|
|
||||||
TextView description;
|
|
||||||
@BindView(R.id.title)
|
|
||||||
TextView title;
|
|
||||||
@BindView(R.id.category)
|
|
||||||
TextView distance;
|
|
||||||
|
|
||||||
private ActivityResultLauncher<String[]> activityResultLauncher = registerForActivityResult(
|
private ActivityResultLauncher<String[]> activityResultLauncher = registerForActivityResult(
|
||||||
new ActivityResultContracts.RequestMultiplePermissions(),
|
new ActivityResultContracts.RequestMultiplePermissions(),
|
||||||
|
|
@ -200,27 +171,21 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(
|
public View onCreateView(
|
||||||
@NonNull LayoutInflater inflater,
|
@NonNull LayoutInflater inflater,
|
||||||
ViewGroup container,
|
ViewGroup container,
|
||||||
Bundle savedInstanceState
|
Bundle savedInstanceState
|
||||||
) {
|
) {
|
||||||
View v = inflater.inflate(R.layout.fragment_explore_map, container, false);
|
binding = FragmentExploreMapBinding.inflate(getLayoutInflater());
|
||||||
ButterKnife.bind(this, v);
|
return binding.getRoot();
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) {
|
public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
setSearchThisAreaButtonVisibility(false);
|
setSearchThisAreaButtonVisibility(false);
|
||||||
tvAttribution.setText(Html.fromHtml(getString(R.string.map_attribution)));
|
binding.tvAttribution.setText(Html.fromHtml(getString(R.string.map_attribution)));
|
||||||
initNetworkBroadCastReceiver();
|
initNetworkBroadCastReceiver();
|
||||||
|
|
||||||
if (presenter == null) {
|
if (presenter == null) {
|
||||||
|
|
@ -238,32 +203,32 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
|
||||||
org.osmdroid.config.Configuration.getInstance().load(this.getContext(),
|
org.osmdroid.config.Configuration.getInstance().load(this.getContext(),
|
||||||
PreferenceManager.getDefaultSharedPreferences(this.getContext()));
|
PreferenceManager.getDefaultSharedPreferences(this.getContext()));
|
||||||
|
|
||||||
mapView.setTileSource(TileSourceFactory.WIKIMEDIA);
|
binding.mapView.setTileSource(TileSourceFactory.WIKIMEDIA);
|
||||||
mapView.setTilesScaledToDpi(true);
|
binding.mapView.setTilesScaledToDpi(true);
|
||||||
|
|
||||||
org.osmdroid.config.Configuration.getInstance().getAdditionalHttpRequestProperties().put(
|
org.osmdroid.config.Configuration.getInstance().getAdditionalHttpRequestProperties().put(
|
||||||
"Referer", "http://maps.wikimedia.org/"
|
"Referer", "http://maps.wikimedia.org/"
|
||||||
);
|
);
|
||||||
|
|
||||||
ScaleBarOverlay scaleBarOverlay = new ScaleBarOverlay(mapView);
|
ScaleBarOverlay scaleBarOverlay = new ScaleBarOverlay(binding.mapView);
|
||||||
scaleBarOverlay.setScaleBarOffset(15, 25);
|
scaleBarOverlay.setScaleBarOffset(15, 25);
|
||||||
Paint barPaint = new Paint();
|
Paint barPaint = new Paint();
|
||||||
barPaint.setARGB(200, 255, 250, 250);
|
barPaint.setARGB(200, 255, 250, 250);
|
||||||
scaleBarOverlay.setBackgroundPaint(barPaint);
|
scaleBarOverlay.setBackgroundPaint(barPaint);
|
||||||
scaleBarOverlay.enableScaleBar();
|
scaleBarOverlay.enableScaleBar();
|
||||||
mapView.getOverlays().add(scaleBarOverlay);
|
binding.mapView.getOverlays().add(scaleBarOverlay);
|
||||||
mapView.getZoomController().setVisibility(CustomZoomButtonsController.Visibility.NEVER);
|
binding.mapView.getZoomController().setVisibility(CustomZoomButtonsController.Visibility.NEVER);
|
||||||
mapView.setMultiTouchControls(true);
|
binding.mapView.setMultiTouchControls(true);
|
||||||
mapView.getController().setZoom(ZOOM_LEVEL);
|
binding.mapView.getController().setZoom(ZOOM_LEVEL);
|
||||||
performMapReadyActions();
|
performMapReadyActions();
|
||||||
|
|
||||||
mapView.getOverlays().add(new MapEventsOverlay(new MapEventsReceiver() {
|
binding.mapView.getOverlays().add(new MapEventsOverlay(new MapEventsReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public boolean singleTapConfirmedHelper(GeoPoint p) {
|
public boolean singleTapConfirmedHelper(GeoPoint p) {
|
||||||
if (clickedMarker != null) {
|
if (clickedMarker != null) {
|
||||||
removeMarker(clickedMarker);
|
removeMarker(clickedMarker);
|
||||||
addMarkerToMap(clickedMarker);
|
addMarkerToMap(clickedMarker);
|
||||||
mapView.invalidate();
|
binding.mapView.invalidate();
|
||||||
} else {
|
} else {
|
||||||
Timber.e("CLICKED MARKER IS NULL");
|
Timber.e("CLICKED MARKER IS NULL");
|
||||||
}
|
}
|
||||||
|
|
@ -282,14 +247,14 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
mapView.addMapListener(new MapListener() {
|
binding.mapView.addMapListener(new MapListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onScroll(ScrollEvent event) {
|
public boolean onScroll(ScrollEvent event) {
|
||||||
if (getLastMapFocus() != null) {
|
if (getLastMapFocus() != null) {
|
||||||
Location mylocation = new Location("");
|
Location mylocation = new Location("");
|
||||||
Location dest_location = new Location("");
|
Location dest_location = new Location("");
|
||||||
dest_location.setLatitude(mapView.getMapCenter().getLatitude());
|
dest_location.setLatitude(binding.mapView.getMapCenter().getLatitude());
|
||||||
dest_location.setLongitude(mapView.getMapCenter().getLongitude());
|
dest_location.setLongitude(binding.mapView.getMapCenter().getLongitude());
|
||||||
mylocation.setLatitude(getLastMapFocus().getLatitude());
|
mylocation.setLatitude(getLastMapFocus().getLatitude());
|
||||||
mylocation.setLongitude(getLastMapFocus().getLongitude());
|
mylocation.setLongitude(getLastMapFocus().getLongitude());
|
||||||
Float distance = mylocation.distanceTo(dest_location);//in meters
|
Float distance = mylocation.distanceTo(dest_location);//in meters
|
||||||
|
|
@ -322,7 +287,7 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
mapView.onResume();
|
binding.mapView.onResume();
|
||||||
presenter.attachView(this);
|
presenter.attachView(this);
|
||||||
registerNetworkReceiver();
|
registerNetworkReceiver();
|
||||||
if (isResumed()) {
|
if (isResumed()) {
|
||||||
|
|
@ -351,7 +316,7 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
|
||||||
|
|
||||||
private void performMapReadyActions() {
|
private void performMapReadyActions() {
|
||||||
if (isDarkTheme) {
|
if (isDarkTheme) {
|
||||||
mapView.getOverlayManager().getTilesOverlay()
|
binding.mapView.getOverlayManager().getTilesOverlay()
|
||||||
.setColorFilter(TilesOverlay.INVERT_COLORS);
|
.setColorFilter(TilesOverlay.INVERT_COLORS);
|
||||||
}
|
}
|
||||||
if (!applicationKvStore.getBoolean("doNotAskForLocationPermission", false) ||
|
if (!applicationKvStore.getBoolean("doNotAskForLocationPermission", false) ||
|
||||||
|
|
@ -376,16 +341,16 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
|
||||||
*/
|
*/
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
private void initBottomSheets() {
|
private void initBottomSheets() {
|
||||||
bottomSheetDetailsBehavior = BottomSheetBehavior.from(bottomSheetDetails);
|
bottomSheetDetailsBehavior = BottomSheetBehavior.from(binding.bottomSheetDetailsBinding.getRoot());
|
||||||
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
||||||
bottomSheetDetails.setVisibility(View.VISIBLE);
|
binding.bottomSheetDetailsBinding.getRoot().setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines how bottom sheets will act on click
|
* Defines how bottom sheets will act on click
|
||||||
*/
|
*/
|
||||||
private void setBottomSheetCallbacks() {
|
private void setBottomSheetCallbacks() {
|
||||||
bottomSheetDetails.setOnClickListener(v -> {
|
binding.bottomSheetDetailsBinding.getRoot().setOnClickListener(v -> {
|
||||||
if (bottomSheetDetailsBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) {
|
if (bottomSheetDetailsBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) {
|
||||||
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
|
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
|
||||||
} else if (bottomSheetDetailsBehavior.getState()
|
} else if (bottomSheetDetailsBehavior.getState()
|
||||||
|
|
@ -496,7 +461,7 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
|
||||||
if (lastKnownLocation != null) {
|
if (lastKnownLocation != null) {
|
||||||
GeoPoint targetP = new GeoPoint(target.getLatitude(), target.getLongitude());
|
GeoPoint targetP = new GeoPoint(target.getLatitude(), target.getLongitude());
|
||||||
mapCenter = targetP;
|
mapCenter = targetP;
|
||||||
mapView.getController().setCenter(targetP);
|
binding.mapView.getController().setCenter(targetP);
|
||||||
recenterMarkerToPosition(targetP);
|
recenterMarkerToPosition(targetP);
|
||||||
moveCameraToPosition(targetP);
|
moveCameraToPosition(targetP);
|
||||||
} else if (locationManager.isGPSProviderEnabled()
|
} else if (locationManager.isGPSProviderEnabled()
|
||||||
|
|
@ -528,13 +493,13 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
recenterMarkerToPosition(new GeoPoint(curLatLng.getLatitude(), curLatLng.getLongitude()));
|
recenterMarkerToPosition(new GeoPoint(curLatLng.getLatitude(), curLatLng.getLongitude()));
|
||||||
mapView.getController()
|
binding.mapView.getController()
|
||||||
.animateTo(new GeoPoint(curLatLng.getLatitude(), curLatLng.getLongitude()));
|
.animateTo(new GeoPoint(curLatLng.getLatitude(), curLatLng.getLongitude()));
|
||||||
if (lastMapFocus != null) {
|
if (lastMapFocus != null) {
|
||||||
Location mylocation = new Location("");
|
Location mylocation = new Location("");
|
||||||
Location dest_location = new Location("");
|
Location dest_location = new Location("");
|
||||||
dest_location.setLatitude(mapView.getMapCenter().getLatitude());
|
dest_location.setLatitude(binding.mapView.getMapCenter().getLatitude());
|
||||||
dest_location.setLongitude(mapView.getMapCenter().getLongitude());
|
dest_location.setLongitude(binding.mapView.getMapCenter().getLongitude());
|
||||||
mylocation.setLatitude(lastMapFocus.getLatitude());
|
mylocation.setLatitude(lastMapFocus.getLatitude());
|
||||||
mylocation.setLongitude(lastMapFocus.getLongitude());
|
mylocation.setLongitude(lastMapFocus.getLongitude());
|
||||||
Float distance = mylocation.distanceTo(dest_location);//in meters
|
Float distance = mylocation.distanceTo(dest_location);//in meters
|
||||||
|
|
@ -598,60 +563,52 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
|
||||||
* @param place Place of clicked nearby marker
|
* @param place Place of clicked nearby marker
|
||||||
*/
|
*/
|
||||||
private void passInfoToSheet(final Place place) {
|
private void passInfoToSheet(final Place place) {
|
||||||
directionsButton.setOnClickListener(view -> Utils.handleGeoCoordinates(getActivity(),
|
binding.bottomSheetDetailsBinding.directionsButton.setOnClickListener(view -> Utils.handleGeoCoordinates(getActivity(),
|
||||||
place.getLocation()));
|
place.getLocation()));
|
||||||
|
|
||||||
commonsButton.setVisibility(place.hasCommonsLink() ? View.VISIBLE : View.GONE);
|
binding.bottomSheetDetailsBinding.commonsButton.setVisibility(place.hasCommonsLink() ? View.VISIBLE : View.GONE);
|
||||||
commonsButton.setOnClickListener(
|
binding.bottomSheetDetailsBinding.commonsButton.setOnClickListener(
|
||||||
view -> Utils.handleWebUrl(getContext(), place.siteLinks.getCommonsLink()));
|
view -> Utils.handleWebUrl(getContext(), place.siteLinks.getCommonsLink()));
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (Media media : mediaList) {
|
for (Media media : mediaList) {
|
||||||
if (media.getFilename().equals(place.name)) {
|
if (media.getFilename().equals(place.name)) {
|
||||||
int finalIndex = index;
|
int finalIndex = index;
|
||||||
mediaDetailsButton.setOnClickListener(view -> {
|
binding.bottomSheetDetailsBinding.mediaDetailsButton.setOnClickListener(view -> {
|
||||||
((ExploreMapRootFragment) getParentFragment()).onMediaClicked(finalIndex);
|
((ExploreMapRootFragment) getParentFragment()).onMediaClicked(finalIndex);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
title.setText(place.name.substring(5, place.name.lastIndexOf(".")));
|
binding.bottomSheetDetailsBinding.title.setText(place.name.substring(5, place.name.lastIndexOf(".")));
|
||||||
distance.setText(place.distance);
|
binding.bottomSheetDetailsBinding.category.setText(place.distance);
|
||||||
// Remove label since it is double information
|
// Remove label since it is double information
|
||||||
String descriptionText = place.getLongDescription()
|
String descriptionText = place.getLongDescription()
|
||||||
.replace(place.getName() + " (", "");
|
.replace(place.getName() + " (", "");
|
||||||
descriptionText = (descriptionText.equals(place.getLongDescription()) ? descriptionText
|
descriptionText = (descriptionText.equals(place.getLongDescription()) ? descriptionText
|
||||||
: descriptionText.replaceFirst(".$", ""));
|
: descriptionText.replaceFirst(".$", ""));
|
||||||
// Set the short description after we remove place name from long description
|
// Set the short description after we remove place name from long description
|
||||||
description.setText(descriptionText);
|
binding.bottomSheetDetailsBinding.description.setText(descriptionText);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addSearchThisAreaButtonAction() {
|
public void addSearchThisAreaButtonAction() {
|
||||||
searchThisAreaButton.setOnClickListener(presenter.onSearchThisAreaClicked());
|
binding.searchThisAreaButton.setOnClickListener(presenter.onSearchThisAreaClicked());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSearchThisAreaButtonVisibility(boolean isVisible) {
|
public void setSearchThisAreaButtonVisibility(boolean isVisible) {
|
||||||
if (isVisible) {
|
binding.searchThisAreaButton.setVisibility(isVisible ? View.VISIBLE : View.GONE);
|
||||||
searchThisAreaButton.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
searchThisAreaButton.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setProgressBarVisibility(boolean isVisible) {
|
public void setProgressBarVisibility(boolean isVisible) {
|
||||||
if (isVisible) {
|
binding.mapProgressBar.setVisibility(isVisible ? View.VISIBLE : View.GONE);
|
||||||
progressBar.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
progressBar.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isDetailsBottomSheetVisible() {
|
public boolean isDetailsBottomSheetVisible() {
|
||||||
if (bottomSheetDetails.getVisibility() == View.VISIBLE) {
|
if (binding.bottomSheetDetailsBinding.getRoot().getVisibility() == View.VISIBLE) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -660,11 +617,7 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSearchThisAreaButtonVisible() {
|
public boolean isSearchThisAreaButtonVisible() {
|
||||||
if (searchThisAreaButton.getVisibility() == View.VISIBLE) {
|
return binding.bottomSheetDetailsBinding.getRoot().getVisibility() == View.VISIBLE;
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -677,12 +630,12 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disableFABRecenter() {
|
public void disableFABRecenter() {
|
||||||
fabRecenter.setEnabled(false);
|
binding.fabRecenter.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enableFABRecenter() {
|
public void enableFABRecenter() {
|
||||||
fabRecenter.setEnabled(true);
|
binding.fabRecenter.setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -696,7 +649,7 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
|
||||||
for (int i = 0; i < nearbyBaseMarkers.size(); i++) {
|
for (int i = 0; i < nearbyBaseMarkers.size(); i++) {
|
||||||
addMarkerToMap(nearbyBaseMarkers.get(i));
|
addMarkerToMap(nearbyBaseMarkers.get(i));
|
||||||
}
|
}
|
||||||
mapView.invalidate();
|
binding.mapView.invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -738,7 +691,7 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
|
||||||
}, getContext());
|
}, getContext());
|
||||||
|
|
||||||
overlay.setFocusItemsOnTap(true);
|
overlay.setFocusItemsOnTap(true);
|
||||||
mapView.getOverlays().add(overlay); // Add the overlay to the map
|
binding.mapView.getOverlays().add(overlay); // Add the overlay to the map
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -748,7 +701,7 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
|
||||||
*/
|
*/
|
||||||
private void removeMarker(NearbyBaseMarker nearbyBaseMarker) {
|
private void removeMarker(NearbyBaseMarker nearbyBaseMarker) {
|
||||||
Place place = nearbyBaseMarker.getPlace();
|
Place place = nearbyBaseMarker.getPlace();
|
||||||
List<Overlay> overlays = mapView.getOverlays();
|
List<Overlay> overlays = binding.mapView.getOverlays();
|
||||||
ItemizedOverlayWithFocus item;
|
ItemizedOverlayWithFocus item;
|
||||||
|
|
||||||
for (int i = 0; i < overlays.size(); i++) {
|
for (int i = 0; i < overlays.size(); i++) {
|
||||||
|
|
@ -758,8 +711,8 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
|
||||||
|
|
||||||
if (place.location.getLatitude() == overlayItem.getPoint().getLatitude()
|
if (place.location.getLatitude() == overlayItem.getPoint().getLatitude()
|
||||||
&& place.location.getLongitude() == overlayItem.getPoint().getLongitude()) {
|
&& place.location.getLongitude() == overlayItem.getPoint().getLongitude()) {
|
||||||
mapView.getOverlays().remove(i);
|
binding.mapView.getOverlays().remove(i);
|
||||||
mapView.invalidate();
|
binding.mapView.invalidate();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -772,10 +725,10 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void clearAllMarkers() {
|
public void clearAllMarkers() {
|
||||||
mapView.getOverlayManager().clear();
|
binding.mapView.getOverlayManager().clear();
|
||||||
GeoPoint geoPoint = mapCenter;
|
GeoPoint geoPoint = mapCenter;
|
||||||
if (geoPoint != null) {
|
if (geoPoint != null) {
|
||||||
List<Overlay> overlays = mapView.getOverlays();
|
List<Overlay> overlays = binding.mapView.getOverlays();
|
||||||
ScaleDiskOverlay diskOverlay =
|
ScaleDiskOverlay diskOverlay =
|
||||||
new ScaleDiskOverlay(this.getContext(),
|
new ScaleDiskOverlay(this.getContext(),
|
||||||
geoPoint, 2000, GeoConstants.UnitOfMeasure.foot);
|
geoPoint, 2000, GeoConstants.UnitOfMeasure.foot);
|
||||||
|
|
@ -790,9 +743,9 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
|
||||||
diskOverlay.setCirclePaint1(diskPaint);
|
diskOverlay.setCirclePaint1(diskPaint);
|
||||||
diskOverlay.setDisplaySizeMin(900);
|
diskOverlay.setDisplaySizeMin(900);
|
||||||
diskOverlay.setDisplaySizeMax(1700);
|
diskOverlay.setDisplaySizeMax(1700);
|
||||||
mapView.getOverlays().add(diskOverlay);
|
binding.mapView.getOverlays().add(diskOverlay);
|
||||||
org.osmdroid.views.overlay.Marker startMarker = new org.osmdroid.views.overlay.Marker(
|
org.osmdroid.views.overlay.Marker startMarker = new org.osmdroid.views.overlay.Marker(
|
||||||
mapView);
|
binding.mapView);
|
||||||
startMarker.setPosition(geoPoint);
|
startMarker.setPosition(geoPoint);
|
||||||
startMarker.setAnchor(org.osmdroid.views.overlay.Marker.ANCHOR_CENTER,
|
startMarker.setAnchor(org.osmdroid.views.overlay.Marker.ANCHOR_CENTER,
|
||||||
org.osmdroid.views.overlay.Marker.ANCHOR_BOTTOM);
|
org.osmdroid.views.overlay.Marker.ANCHOR_BOTTOM);
|
||||||
|
|
@ -800,22 +753,22 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
|
||||||
ContextCompat.getDrawable(this.getContext(), R.drawable.current_location_marker));
|
ContextCompat.getDrawable(this.getContext(), R.drawable.current_location_marker));
|
||||||
startMarker.setTitle("Your Location");
|
startMarker.setTitle("Your Location");
|
||||||
startMarker.setTextLabelFontSize(24);
|
startMarker.setTextLabelFontSize(24);
|
||||||
mapView.getOverlays().add(startMarker);
|
binding.mapView.getOverlays().add(startMarker);
|
||||||
}
|
}
|
||||||
ScaleBarOverlay scaleBarOverlay = new ScaleBarOverlay(mapView);
|
ScaleBarOverlay scaleBarOverlay = new ScaleBarOverlay(binding.mapView);
|
||||||
scaleBarOverlay.setScaleBarOffset(15, 25);
|
scaleBarOverlay.setScaleBarOffset(15, 25);
|
||||||
Paint barPaint = new Paint();
|
Paint barPaint = new Paint();
|
||||||
barPaint.setARGB(200, 255, 250, 250);
|
barPaint.setARGB(200, 255, 250, 250);
|
||||||
scaleBarOverlay.setBackgroundPaint(barPaint);
|
scaleBarOverlay.setBackgroundPaint(barPaint);
|
||||||
scaleBarOverlay.enableScaleBar();
|
scaleBarOverlay.enableScaleBar();
|
||||||
mapView.getOverlays().add(scaleBarOverlay);
|
binding.mapView.getOverlays().add(scaleBarOverlay);
|
||||||
mapView.getOverlays().add(new MapEventsOverlay(new MapEventsReceiver() {
|
binding.mapView.getOverlays().add(new MapEventsOverlay(new MapEventsReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public boolean singleTapConfirmedHelper(GeoPoint p) {
|
public boolean singleTapConfirmedHelper(GeoPoint p) {
|
||||||
if (clickedMarker != null) {
|
if (clickedMarker != null) {
|
||||||
removeMarker(clickedMarker);
|
removeMarker(clickedMarker);
|
||||||
addMarkerToMap(clickedMarker);
|
addMarkerToMap(clickedMarker);
|
||||||
mapView.invalidate();
|
binding.mapView.invalidate();
|
||||||
} else {
|
} else {
|
||||||
Timber.e("CLICKED MARKER IS NULL");
|
Timber.e("CLICKED MARKER IS NULL");
|
||||||
}
|
}
|
||||||
|
|
@ -833,7 +786,7 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
mapView.setMultiTouchControls(true);
|
binding.mapView.setMultiTouchControls(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -844,13 +797,13 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
|
||||||
*/
|
*/
|
||||||
private void recenterMarkerToPosition(GeoPoint geoPoint) {
|
private void recenterMarkerToPosition(GeoPoint geoPoint) {
|
||||||
if (geoPoint != null) {
|
if (geoPoint != null) {
|
||||||
mapView.getController().setCenter(geoPoint);
|
binding.mapView.getController().setCenter(geoPoint);
|
||||||
List<Overlay> overlays = mapView.getOverlays();
|
List<Overlay> overlays = binding.mapView.getOverlays();
|
||||||
for (int i = 0; i < overlays.size(); i++) {
|
for (int i = 0; i < overlays.size(); i++) {
|
||||||
if (overlays.get(i) instanceof org.osmdroid.views.overlay.Marker) {
|
if (overlays.get(i) instanceof org.osmdroid.views.overlay.Marker) {
|
||||||
mapView.getOverlays().remove(i);
|
binding.mapView.getOverlays().remove(i);
|
||||||
} else if (overlays.get(i) instanceof ScaleDiskOverlay) {
|
} else if (overlays.get(i) instanceof ScaleDiskOverlay) {
|
||||||
mapView.getOverlays().remove(i);
|
binding.mapView.getOverlays().remove(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ScaleDiskOverlay diskOverlay =
|
ScaleDiskOverlay diskOverlay =
|
||||||
|
|
@ -867,9 +820,9 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
|
||||||
diskOverlay.setCirclePaint1(diskPaint);
|
diskOverlay.setCirclePaint1(diskPaint);
|
||||||
diskOverlay.setDisplaySizeMin(900);
|
diskOverlay.setDisplaySizeMin(900);
|
||||||
diskOverlay.setDisplaySizeMax(1700);
|
diskOverlay.setDisplaySizeMax(1700);
|
||||||
mapView.getOverlays().add(diskOverlay);
|
binding.mapView.getOverlays().add(diskOverlay);
|
||||||
org.osmdroid.views.overlay.Marker startMarker = new org.osmdroid.views.overlay.Marker(
|
org.osmdroid.views.overlay.Marker startMarker = new org.osmdroid.views.overlay.Marker(
|
||||||
mapView);
|
binding.mapView);
|
||||||
startMarker.setPosition(geoPoint);
|
startMarker.setPosition(geoPoint);
|
||||||
startMarker.setAnchor(org.osmdroid.views.overlay.Marker.ANCHOR_CENTER,
|
startMarker.setAnchor(org.osmdroid.views.overlay.Marker.ANCHOR_CENTER,
|
||||||
org.osmdroid.views.overlay.Marker.ANCHOR_BOTTOM);
|
org.osmdroid.views.overlay.Marker.ANCHOR_BOTTOM);
|
||||||
|
|
@ -877,7 +830,7 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
|
||||||
ContextCompat.getDrawable(this.getContext(), R.drawable.current_location_marker));
|
ContextCompat.getDrawable(this.getContext(), R.drawable.current_location_marker));
|
||||||
startMarker.setTitle("Your Location");
|
startMarker.setTitle("Your Location");
|
||||||
startMarker.setTextLabelFontSize(24);
|
startMarker.setTextLabelFontSize(24);
|
||||||
mapView.getOverlays().add(startMarker);
|
binding.mapView.getOverlays().add(startMarker);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -887,7 +840,7 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
|
||||||
* @param geoPoint The GeoPoint representing the new camera position for the map.
|
* @param geoPoint The GeoPoint representing the new camera position for the map.
|
||||||
*/
|
*/
|
||||||
private void moveCameraToPosition(GeoPoint geoPoint) {
|
private void moveCameraToPosition(GeoPoint geoPoint) {
|
||||||
mapView.getController().animateTo(geoPoint);
|
binding.mapView.getController().animateTo(geoPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -909,13 +862,13 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
|
||||||
@Override
|
@Override
|
||||||
public fr.free.nrw.commons.location.LatLng getMapFocus() {
|
public fr.free.nrw.commons.location.LatLng getMapFocus() {
|
||||||
fr.free.nrw.commons.location.LatLng mapFocusedLatLng = new fr.free.nrw.commons.location.LatLng(
|
fr.free.nrw.commons.location.LatLng mapFocusedLatLng = new fr.free.nrw.commons.location.LatLng(
|
||||||
mapView.getMapCenter().getLatitude(), mapView.getMapCenter().getLongitude(), 100);
|
binding.mapView.getMapCenter().getLatitude(), binding.mapView.getMapCenter().getLongitude(), 100);
|
||||||
return mapFocusedLatLng;
|
return mapFocusedLatLng;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setFABRecenterAction(OnClickListener onClickListener) {
|
public void setFABRecenterAction(OnClickListener onClickListener) {
|
||||||
fabRecenter.setOnClickListener(onClickListener);
|
binding.fabRecenter.setOnClickListener(onClickListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -7,15 +7,11 @@ import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.ListView;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import butterknife.BindView;
|
|
||||||
import butterknife.ButterKnife;
|
|
||||||
import fr.free.nrw.commons.R;
|
import fr.free.nrw.commons.R;
|
||||||
|
import fr.free.nrw.commons.databinding.FragmentSearchHistoryBinding;
|
||||||
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
||||||
import fr.free.nrw.commons.explore.SearchActivity;
|
import fr.free.nrw.commons.explore.SearchActivity;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -29,42 +25,39 @@ public class RecentSearchesFragment extends CommonsDaggerSupportFragment {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
RecentSearchesDao recentSearchesDao;
|
RecentSearchesDao recentSearchesDao;
|
||||||
@BindView(R.id.recent_searches_list)
|
|
||||||
ListView recentSearchesList;
|
|
||||||
List<String> recentSearches;
|
List<String> recentSearches;
|
||||||
ArrayAdapter adapter;
|
ArrayAdapter adapter;
|
||||||
@BindView(R.id.recent_searches_delete_button)
|
|
||||||
ImageView recent_searches_delete_button;
|
private FragmentSearchHistoryBinding binding;
|
||||||
@BindView(R.id.recent_searches_text_view)
|
|
||||||
TextView recent_searches_text_view;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
View rootView = inflater.inflate(R.layout.fragment_search_history, container, false);
|
binding = FragmentSearchHistoryBinding.inflate(inflater, container, false);
|
||||||
ButterKnife.bind(this, rootView);
|
|
||||||
recentSearches = recentSearchesDao.recentSearches(10);
|
recentSearches = recentSearchesDao.recentSearches(10);
|
||||||
|
|
||||||
if (recentSearches.isEmpty()) {
|
if (recentSearches.isEmpty()) {
|
||||||
recent_searches_delete_button.setVisibility(View.GONE);
|
binding.recentSearchesDeleteButton.setVisibility(View.GONE);
|
||||||
recent_searches_text_view.setText(R.string.no_recent_searches);
|
binding.recentSearchesTextView.setText(R.string.no_recent_searches);
|
||||||
}
|
}
|
||||||
|
|
||||||
recent_searches_delete_button.setOnClickListener(v -> {
|
binding.recentSearchesDeleteButton.setOnClickListener(v -> {
|
||||||
showDeleteRecentAlertDialog(requireContext());
|
showDeleteRecentAlertDialog(requireContext());
|
||||||
});
|
});
|
||||||
|
|
||||||
adapter = new ArrayAdapter<>(requireContext(), R.layout.item_recent_searches,
|
adapter = new ArrayAdapter<>(requireContext(), R.layout.item_recent_searches,
|
||||||
recentSearches);
|
recentSearches);
|
||||||
recentSearchesList.setAdapter(adapter);
|
binding.recentSearchesList.setAdapter(adapter);
|
||||||
recentSearchesList.setOnItemClickListener((parent, view, position, id) -> (
|
binding.recentSearchesList.setOnItemClickListener((parent, view, position, id) -> (
|
||||||
(SearchActivity) getContext()).updateText(recentSearches.get(position)));
|
(SearchActivity) getContext()).updateText(recentSearches.get(position)));
|
||||||
recentSearchesList.setOnItemLongClickListener((parent, view, position, id) -> {
|
binding.recentSearchesList.setOnItemLongClickListener((parent, view, position, id) -> {
|
||||||
showDeleteAlertDialog(requireContext(), position);
|
showDeleteAlertDialog(requireContext(), position);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
updateRecentSearches();
|
updateRecentSearches();
|
||||||
return rootView;
|
|
||||||
|
return binding.getRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showDeleteRecentAlertDialog(@NonNull final Context context) {
|
private void showDeleteRecentAlertDialog(@NonNull final Context context) {
|
||||||
|
|
@ -80,15 +73,17 @@ public class RecentSearchesFragment extends CommonsDaggerSupportFragment {
|
||||||
private void setDeleteRecentPositiveButton(@NonNull final Context context,
|
private void setDeleteRecentPositiveButton(@NonNull final Context context,
|
||||||
final DialogInterface dialog) {
|
final DialogInterface dialog) {
|
||||||
recentSearchesDao.deleteAll();
|
recentSearchesDao.deleteAll();
|
||||||
recent_searches_delete_button.setVisibility(View.GONE);
|
if (binding != null) {
|
||||||
recent_searches_text_view.setText(R.string.no_recent_searches);
|
binding.recentSearchesDeleteButton.setVisibility(View.GONE);
|
||||||
Toast.makeText(getContext(), getString(R.string.search_history_deleted),
|
binding.recentSearchesTextView.setText(R.string.no_recent_searches);
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.makeText(getContext(), getString(R.string.search_history_deleted),
|
||||||
recentSearches = recentSearchesDao.recentSearches(10);
|
Toast.LENGTH_SHORT).show();
|
||||||
adapter = new ArrayAdapter<>(context, R.layout.item_recent_searches,
|
recentSearches = recentSearchesDao.recentSearches(10);
|
||||||
recentSearches);
|
adapter = new ArrayAdapter<>(context, R.layout.item_recent_searches,
|
||||||
recentSearchesList.setAdapter(adapter);
|
recentSearches);
|
||||||
adapter.notifyDataSetChanged();
|
binding.recentSearchesList.setAdapter(adapter);
|
||||||
|
adapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,8 +103,10 @@ public class RecentSearchesFragment extends CommonsDaggerSupportFragment {
|
||||||
recentSearches = recentSearchesDao.recentSearches(10);
|
recentSearches = recentSearchesDao.recentSearches(10);
|
||||||
adapter = new ArrayAdapter<>(context, R.layout.item_recent_searches,
|
adapter = new ArrayAdapter<>(context, R.layout.item_recent_searches,
|
||||||
recentSearches);
|
recentSearches);
|
||||||
recentSearchesList.setAdapter(adapter);
|
if (binding != null){
|
||||||
adapter.notifyDataSetChanged();
|
binding.recentSearchesList.setAdapter(adapter);
|
||||||
|
adapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -131,8 +128,19 @@ public class RecentSearchesFragment extends CommonsDaggerSupportFragment {
|
||||||
adapter.notifyDataSetChanged();
|
adapter.notifyDataSetChanged();
|
||||||
|
|
||||||
if (!recentSearches.isEmpty()) {
|
if (!recentSearches.isEmpty()) {
|
||||||
recent_searches_delete_button.setVisibility(View.VISIBLE);
|
if (binding!= null) {
|
||||||
recent_searches_text_view.setText(R.string.search_recent_header);
|
binding.recentSearchesDeleteButton.setVisibility(View.VISIBLE);
|
||||||
|
binding.recentSearchesTextView.setText(R.string.search_recent_header);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
|
||||||
|
if (binding != null) {
|
||||||
|
binding = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,9 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?attr/mainBackground">
|
android:background="?attr/mainBackground">
|
||||||
|
|
||||||
<include layout="@layout/toolbar"/>
|
<include
|
||||||
|
android:id="@+id/toolbarBinding"
|
||||||
|
layout="@layout/toolbar"/>
|
||||||
|
|
||||||
<com.google.android.material.tabs.TabLayout
|
<com.google.android.material.tabs.TabLayout
|
||||||
android:id="@+id/tab_layout"
|
android:id="@+id/tab_layout"
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@
|
||||||
app:elevation="@dimen/dimen_6" />
|
app:elevation="@dimen/dimen_6" />
|
||||||
|
|
||||||
<include
|
<include
|
||||||
android:id="@+id/bottom_sheet_details"
|
android:id="@+id/bottom_sheet_details_binding"
|
||||||
layout="@layout/bottom_sheet_details_explore" />
|
layout="@layout/bottom_sheet_details_explore" />
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
|
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- Authors:
|
|
||||||
* Winston Sung
|
|
||||||
-->
|
|
||||||
<resources>
|
|
||||||
<string name="crash_dialog_title">同享壞咗</string>
|
|
||||||
<string name="crash_dialog_text">哎呀。出咗錯!</string>
|
|
||||||
<string name="crash_dialog_ok_toast">多謝你!</string>
|
|
||||||
</resources>
|
|
||||||
|
|
@ -14,6 +14,7 @@ import fr.free.nrw.commons.createTestClient
|
||||||
import fr.free.nrw.commons.contributions.MainActivity
|
import fr.free.nrw.commons.contributions.MainActivity
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
|
import org.junit.Ignore
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
|
|
@ -69,8 +70,6 @@ class ExploreFragmentUnitTest {
|
||||||
view = fragment.onCreateView(layoutInflater, null, null) as View
|
view = fragment.onCreateView(layoutInflater, null, null) as View
|
||||||
viewPager = view.findViewById(R.id.viewPager)
|
viewPager = view.findViewById(R.id.viewPager)
|
||||||
|
|
||||||
Whitebox.setInternalState(fragment, "viewPager", viewPager)
|
|
||||||
Whitebox.setInternalState(fragment, "tabLayout", tabLayout)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -102,7 +101,7 @@ class ExploreFragmentUnitTest {
|
||||||
Assert.assertEquals(fragment.onBackPressed(), true)
|
Assert.assertEquals(fragment.onBackPressed(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test @Ignore("TODO fix this test")
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun testOnBackPressedCaseTrueSelectedTabNonZero() {
|
fun testOnBackPressedCaseTrueSelectedTabNonZero() {
|
||||||
Whitebox.setInternalState(fragment, "mobileRootFragment", exploreRootFragment)
|
Whitebox.setInternalState(fragment, "mobileRootFragment", exploreRootFragment)
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,9 @@ package fr.free.nrw.commons.explore
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
|
||||||
import android.widget.FrameLayout
|
|
||||||
import androidx.fragment.app.FragmentManager
|
import androidx.fragment.app.FragmentManager
|
||||||
import androidx.fragment.app.FragmentTransaction
|
import androidx.fragment.app.FragmentTransaction
|
||||||
import androidx.test.core.app.ApplicationProvider
|
import androidx.test.core.app.ApplicationProvider
|
||||||
import com.google.android.material.tabs.TabLayout
|
|
||||||
import com.nhaarman.mockitokotlin2.any
|
import com.nhaarman.mockitokotlin2.any
|
||||||
import com.nhaarman.mockitokotlin2.times
|
import com.nhaarman.mockitokotlin2.times
|
||||||
import fr.free.nrw.commons.Media
|
import fr.free.nrw.commons.Media
|
||||||
|
|
@ -16,6 +13,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.MainActivity
|
import fr.free.nrw.commons.contributions.MainActivity
|
||||||
|
import fr.free.nrw.commons.databinding.FragmentFeaturedRootBinding
|
||||||
import fr.free.nrw.commons.explore.categories.media.CategoriesMediaFragment
|
import fr.free.nrw.commons.explore.categories.media.CategoriesMediaFragment
|
||||||
import fr.free.nrw.commons.media.MediaDetailPagerFragment
|
import fr.free.nrw.commons.media.MediaDetailPagerFragment
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
|
|
@ -42,11 +40,11 @@ class ExploreListRootFragmentUnitTest {
|
||||||
private lateinit var fragment: ExploreListRootFragment
|
private lateinit var fragment: ExploreListRootFragment
|
||||||
private lateinit var fragmentManager: FragmentManager
|
private lateinit var fragmentManager: FragmentManager
|
||||||
private lateinit var context: Context
|
private lateinit var context: Context
|
||||||
private lateinit var view: View
|
|
||||||
private lateinit var layoutInflater: LayoutInflater
|
|
||||||
private lateinit var activity: MainActivity
|
private lateinit var activity: MainActivity
|
||||||
private lateinit var exploreFragment: ExploreFragment
|
private lateinit var exploreFragment: ExploreFragment
|
||||||
|
|
||||||
|
private lateinit var binding: FragmentFeaturedRootBinding
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var mediaDetails: MediaDetailPagerFragment
|
private lateinit var mediaDetails: MediaDetailPagerFragment
|
||||||
|
|
||||||
|
|
@ -59,15 +57,6 @@ class ExploreListRootFragmentUnitTest {
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var childFragmentTransaction: FragmentTransaction
|
private lateinit var childFragmentTransaction: FragmentTransaction
|
||||||
|
|
||||||
@Mock
|
|
||||||
private lateinit var container: FrameLayout
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private lateinit var tabLayout: TabLayout
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private lateinit var viewPager: ParentViewPager
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var media: Media
|
private lateinit var media: Media
|
||||||
|
|
||||||
|
|
@ -87,16 +76,13 @@ class ExploreListRootFragmentUnitTest {
|
||||||
|
|
||||||
exploreFragment = ExploreFragment()
|
exploreFragment = ExploreFragment()
|
||||||
|
|
||||||
layoutInflater = LayoutInflater.from(activity)
|
binding = FragmentFeaturedRootBinding.inflate(LayoutInflater.from(activity))
|
||||||
view = fragment.onCreateView(layoutInflater, null, null) as View
|
|
||||||
|
|
||||||
Whitebox.setInternalState(fragment, "mChildFragmentManager", childFragmentManager)
|
Whitebox.setInternalState(fragment, "mChildFragmentManager", childFragmentManager)
|
||||||
Whitebox.setInternalState(fragment, "mParentFragment", exploreFragment)
|
Whitebox.setInternalState(fragment, "mParentFragment", exploreFragment)
|
||||||
Whitebox.setInternalState(fragment, "mediaDetails", mediaDetails)
|
Whitebox.setInternalState(fragment, "mediaDetails", mediaDetails)
|
||||||
Whitebox.setInternalState(fragment, "listFragment", listFragment)
|
Whitebox.setInternalState(fragment, "listFragment", listFragment)
|
||||||
Whitebox.setInternalState(fragment, "container", container)
|
|
||||||
Whitebox.setInternalState(exploreFragment, "tabLayout", tabLayout)
|
|
||||||
Whitebox.setInternalState(exploreFragment, "viewPager", viewPager)
|
|
||||||
|
|
||||||
`when`(childFragmentManager.beginTransaction()).thenReturn(childFragmentTransaction)
|
`when`(childFragmentManager.beginTransaction()).thenReturn(childFragmentTransaction)
|
||||||
`when`(childFragmentTransaction.hide(any())).thenReturn(childFragmentTransaction)
|
`when`(childFragmentTransaction.hide(any())).thenReturn(childFragmentTransaction)
|
||||||
|
|
@ -116,7 +102,7 @@ class ExploreListRootFragmentUnitTest {
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun testOnViewCreated() {
|
fun testOnViewCreated() {
|
||||||
fragment.onViewCreated(view, null)
|
fragment.onViewCreated(binding.root, null)
|
||||||
verify(childFragmentManager).beginTransaction()
|
verify(childFragmentManager).beginTransaction()
|
||||||
verify(childFragmentTransaction).hide(mediaDetails)
|
verify(childFragmentTransaction).hide(mediaDetails)
|
||||||
verify(childFragmentTransaction).add(R.id.explore_container, listFragment)
|
verify(childFragmentTransaction).add(R.id.explore_container, listFragment)
|
||||||
|
|
@ -179,8 +165,6 @@ class ExploreListRootFragmentUnitTest {
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun testOnMediaClicked() {
|
fun testOnMediaClicked() {
|
||||||
fragment.onMediaClicked(0)
|
fragment.onMediaClicked(0)
|
||||||
verify(container).visibility = View.VISIBLE
|
|
||||||
verify(tabLayout).visibility = View.GONE
|
|
||||||
verify(childFragmentManager).beginTransaction()
|
verify(childFragmentManager).beginTransaction()
|
||||||
verify(childFragmentTransaction).hide(listFragment)
|
verify(childFragmentTransaction).hide(listFragment)
|
||||||
verify(childFragmentTransaction).addToBackStack("CONTRIBUTION_LIST_FRAGMENT_TAG")
|
verify(childFragmentTransaction).addToBackStack("CONTRIBUTION_LIST_FRAGMENT_TAG")
|
||||||
|
|
@ -235,8 +219,6 @@ class ExploreListRootFragmentUnitTest {
|
||||||
verify(childFragmentTransaction).remove(mediaDetails)
|
verify(childFragmentTransaction).remove(mediaDetails)
|
||||||
verify(childFragmentTransaction, times(2)).commit()
|
verify(childFragmentTransaction, times(2)).commit()
|
||||||
verify(childFragmentManager, times(2)).executePendingTransactions()
|
verify(childFragmentManager, times(2)).executePendingTransactions()
|
||||||
verify(container).visibility = View.VISIBLE
|
|
||||||
verify(tabLayout).visibility = View.GONE
|
|
||||||
verify(childFragmentTransaction).hide(listFragment)
|
verify(childFragmentTransaction).hide(listFragment)
|
||||||
verify(childFragmentTransaction).addToBackStack("CONTRIBUTION_LIST_FRAGMENT_TAG")
|
verify(childFragmentTransaction).addToBackStack("CONTRIBUTION_LIST_FRAGMENT_TAG")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ 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.databinding.ActivityWikidataItemDetailsBinding
|
||||||
import fr.free.nrw.commons.explore.depictions.media.DepictedImagesFragment
|
import fr.free.nrw.commons.explore.depictions.media.DepictedImagesFragment
|
||||||
import fr.free.nrw.commons.media.MediaDetailPagerFragment
|
import fr.free.nrw.commons.media.MediaDetailPagerFragment
|
||||||
import fr.free.nrw.commons.upload.structure.depictions.DepictedItem
|
import fr.free.nrw.commons.upload.structure.depictions.DepictedItem
|
||||||
|
|
@ -36,7 +37,6 @@ import org.robolectric.fakes.RoboMenuItem
|
||||||
class WikidataItemDetailsActivityUnitTests {
|
class WikidataItemDetailsActivityUnitTests {
|
||||||
|
|
||||||
private lateinit var activity: WikidataItemDetailsActivity
|
private lateinit var activity: WikidataItemDetailsActivity
|
||||||
private lateinit var parent: View
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var mediaDetailPagerFragment: MediaDetailPagerFragment
|
private lateinit var mediaDetailPagerFragment: MediaDetailPagerFragment
|
||||||
|
|
@ -53,14 +53,6 @@ class WikidataItemDetailsActivityUnitTests {
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var wikidataItem: DepictedItem
|
private lateinit var wikidataItem: DepictedItem
|
||||||
|
|
||||||
@Mock
|
|
||||||
private lateinit var mediaContainer: FrameLayout
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private lateinit var tabLayout: TabLayout
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private lateinit var viewPager: ViewPager
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setUp() {
|
fun setUp() {
|
||||||
|
|
@ -83,17 +75,6 @@ class WikidataItemDetailsActivityUnitTests {
|
||||||
)
|
)
|
||||||
Whitebox.setInternalState(activity, "supportFragmentManager", supportFragmentManager)
|
Whitebox.setInternalState(activity, "supportFragmentManager", supportFragmentManager)
|
||||||
|
|
||||||
parent =
|
|
||||||
LayoutInflater.from(activity).inflate(R.layout.activity_wikidata_item_details, null)
|
|
||||||
|
|
||||||
mediaContainer = parent.findViewById(R.id.mediaContainer)
|
|
||||||
Whitebox.setInternalState(activity, "mediaContainer", mediaContainer)
|
|
||||||
|
|
||||||
tabLayout = parent.findViewById(R.id.tab_layout)
|
|
||||||
Whitebox.setInternalState(activity, "tabLayout", tabLayout)
|
|
||||||
|
|
||||||
viewPager = parent.findViewById(R.id.viewPager)
|
|
||||||
Whitebox.setInternalState(activity, "viewPager", viewPager)
|
|
||||||
|
|
||||||
Whitebox.setInternalState(activity, "wikidataItem", wikidataItem)
|
Whitebox.setInternalState(activity, "wikidataItem", wikidataItem)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,20 +38,11 @@ class RecentSearchesFragmentUnitTest {
|
||||||
private lateinit var fragment: RecentSearchesFragment
|
private lateinit var fragment: RecentSearchesFragment
|
||||||
private lateinit var fragmentManager: FragmentManager
|
private lateinit var fragmentManager: FragmentManager
|
||||||
private lateinit var context: Context
|
private lateinit var context: Context
|
||||||
private lateinit var view: View
|
|
||||||
private lateinit var layoutInflater: LayoutInflater
|
private lateinit var layoutInflater: LayoutInflater
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var recentSearchesDao: RecentSearchesDao
|
private lateinit var recentSearchesDao: RecentSearchesDao
|
||||||
|
|
||||||
@Mock
|
|
||||||
private lateinit var imageView: ImageView
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private lateinit var textView: TextView
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private lateinit var listView: ListView
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var adapter: ArrayAdapter<*>
|
private lateinit var adapter: ArrayAdapter<*>
|
||||||
|
|
@ -77,14 +68,9 @@ class RecentSearchesFragmentUnitTest {
|
||||||
fragmentTransaction.commitNowAllowingStateLoss()
|
fragmentTransaction.commitNowAllowingStateLoss()
|
||||||
|
|
||||||
layoutInflater = LayoutInflater.from(activity)
|
layoutInflater = LayoutInflater.from(activity)
|
||||||
view = LayoutInflater.from(activity)
|
|
||||||
.inflate(R.layout.fragment_leaderboard, null) as View
|
|
||||||
|
|
||||||
Whitebox.setInternalState(fragment, "recentSearchesDao", recentSearchesDao)
|
Whitebox.setInternalState(fragment, "recentSearchesDao", recentSearchesDao)
|
||||||
Whitebox.setInternalState(fragment, "recent_searches_delete_button", imageView)
|
|
||||||
Whitebox.setInternalState(fragment, "recent_searches_text_view", textView)
|
|
||||||
Whitebox.setInternalState(fragment, "adapter", adapter)
|
Whitebox.setInternalState(fragment, "adapter", adapter)
|
||||||
Whitebox.setInternalState(fragment, "recentSearchesList", listView)
|
|
||||||
Whitebox.setInternalState(fragment, "recentSearches", listOf("string"))
|
Whitebox.setInternalState(fragment, "recentSearches", listOf("string"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import com.nhaarman.mockitokotlin2.verify
|
||||||
import fr.free.nrw.commons.Media
|
import fr.free.nrw.commons.Media
|
||||||
import fr.free.nrw.commons.TestCommonsApplication
|
import fr.free.nrw.commons.TestCommonsApplication
|
||||||
import fr.free.nrw.commons.ViewPagerAdapter
|
import fr.free.nrw.commons.ViewPagerAdapter
|
||||||
|
import fr.free.nrw.commons.databinding.ActivitySearchBinding
|
||||||
import fr.free.nrw.commons.explore.SearchActivity
|
import fr.free.nrw.commons.explore.SearchActivity
|
||||||
import fr.free.nrw.commons.explore.categories.search.SearchCategoryFragment
|
import fr.free.nrw.commons.explore.categories.search.SearchCategoryFragment
|
||||||
import fr.free.nrw.commons.explore.depictions.search.SearchDepictionsFragment
|
import fr.free.nrw.commons.explore.depictions.search.SearchDepictionsFragment
|
||||||
|
|
@ -45,15 +46,6 @@ class SearchActivityUnitTests {
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var activity: SearchActivity
|
private lateinit var activity: SearchActivity
|
||||||
|
|
||||||
@Mock
|
|
||||||
private lateinit var searchView: SearchView
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private lateinit var viewPager: ViewPager
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private lateinit var context: Context
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var compositeDisposable: CompositeDisposable
|
private lateinit var compositeDisposable: CompositeDisposable
|
||||||
|
|
||||||
|
|
@ -81,6 +73,8 @@ class SearchActivityUnitTests {
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var searchCategoryFragment: SearchCategoryFragment
|
private lateinit var searchCategoryFragment: SearchCategoryFragment
|
||||||
|
|
||||||
|
private lateinit var context: Context
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setUp() {
|
fun setUp() {
|
||||||
MockitoAnnotations.openMocks(this)
|
MockitoAnnotations.openMocks(this)
|
||||||
|
|
@ -102,17 +96,6 @@ class SearchActivityUnitTests {
|
||||||
verify(viewPagerAdapter).notifyDataSetChanged()
|
verify(viewPagerAdapter).notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@Throws(Exception::class)
|
|
||||||
fun testUpdateText() {
|
|
||||||
val query = "test"
|
|
||||||
Whitebox.setInternalState(activity, "searchView", searchView)
|
|
||||||
Whitebox.setInternalState(activity, "viewPager", viewPager)
|
|
||||||
activity.updateText(query)
|
|
||||||
verify(searchView).setQuery(query, true)
|
|
||||||
verify(viewPager).requestFocus()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun testOnBackPressed() {
|
fun testOnBackPressed() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue