Skip to content

Refactor nearby classes mvp #2969

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 161 commits into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
161 commits
Select commit Hold shift + click to select a range
6483d21
Create parent contract
neslihanturan May 12, 2019
3b63d9c
Create map child contract and fill methods
neslihanturan May 12, 2019
24a85a1
Add javadocs and specific interfaces for list
neslihanturan May 12, 2019
c7533eb
Move general method to parent and add javadocs for parent
neslihanturan May 12, 2019
b9d9548
Add explanation for keeping an emty View interface under NearbyListCo…
neslihanturan May 12, 2019
7dec4af
Move constracts under contract package
neslihanturan May 12, 2019
48a550f
Create presenters for map and list and implement user actions accordi…
neslihanturan May 12, 2019
24aa7a2
Add javadocs
neslihanturan May 13, 2019
a1e3b2e
Add presenter, contract and fragment for parent Fragment of both Near…
neslihanturan May 14, 2019
3da8e30
Implement missing methods
neslihanturan May 14, 2019
11d1d00
Fix typo
neslihanturan May 14, 2019
6b6a697
Add main views on fragment
neslihanturan May 14, 2019
bfc0d88
İmplement child fragment logic and their retain
neslihanturan May 14, 2019
2aa5546
Relate parent presenter with parent fragment
neslihanturan May 14, 2019
f8926aa
Merge branch 'master' into refactorNearbyClassesMVP
neslihanturan May 15, 2019
8070802
Add all location permission related methods to view contract and impl…
neslihanturan May 16, 2019
1c27c3c
Define refreshView method as updateMapAndList which is a better namin…
neslihanturan May 16, 2019
a8190bb
Define a presenter variable in fragment and call updateMapAndList met…
neslihanturan May 16, 2019
f8e8d13
Add lock neabry method to unlisten nearby operations during updates
neslihanturan May 17, 2019
034a2e2
Add network connection established check on view side, check it from …
neslihanturan May 17, 2019
bcd7e64
try to simplify previous method during refactor
neslihanturan May 18, 2019
4bb83f7
Merge branch 'master' into refactorNearbyClassesMVP
neslihanturan May 20, 2019
95dd97a
Add missing methods for NearbyMap
neslihanturan May 20, 2019
297eb67
Connect child fragment and prent fragment with presenter
neslihanturan May 20, 2019
cdd6229
Change nearby design, first create views then register listeners
neslihanturan May 20, 2019
fd515de
AddnetworkBroadcatsReceiver on view side, call it from presenter
neslihanturan May 21, 2019
a77c3c4
Add comments
neslihanturan May 21, 2019
d055641
Change the old NearbyFragment by our new NearbyParentFragment for fir…
neslihanturan May 21, 2019
f4321d0
Prevent crash caused child fragment is actually null by checking if i…
neslihanturan May 21, 2019
771a9ec
Makes sure that initialize nearby operations method is called just af…
neslihanturan May 21, 2019
7080c3a
Make sure updateMAoAndList method is called when everything ready
neslihanturan May 22, 2019
b108049
Rename a method with prepoer name
neslihanturan May 23, 2019
786212f
Call update map and add required markers
neslihanturan May 23, 2019
a96bbb1
Find out zoom level problem
neslihanturan May 23, 2019
d4cee8b
Implement add nearby markers and add current marker methods
neslihanturan May 24, 2019
4ec1346
Fix conflicts with master
neslihanturan May 27, 2019
4253965
remove unneeded codes copied from previous implementation
neslihanturan May 27, 2019
5b69daa
Revert "remove unneeded codes copied from previous implementation"
neslihanturan May 27, 2019
97ab63e
add some commits and clear code
neslihanturan May 27, 2019
ceab7f4
Remove location listener implementation from view, handle them in pre…
neslihanturan May 27, 2019
f57d2cd
Style ,issues
neslihanturan May 27, 2019
69597b3
Refactor a variable name to camel case and bind search this area view
neslihanturan May 28, 2019
9a50f54
Search this area button action is added
neslihanturan May 28, 2019
e8ae344
Mostly implement search this area methods, not tested yet even once
neslihanturan May 28, 2019
4ff63a2
Merge branch 'master' into refactorNearbyClassesMVP
neslihanturan May 28, 2019
3f847fd
Make sure everything is called in required order and seach this area …
neslihanturan May 31, 2019
1b0d614
Rename methods accordingly and add Javadocs
neslihanturan May 31, 2019
05fba7d
Fix conflicts
neslihanturan May 31, 2019
a7d35ed
Add current location marker and remove circle around it
neslihanturan Jun 1, 2019
008e1f6
Remove unused methods
neslihanturan Jun 1, 2019
c2453cb
Add current location marker with object animator and remove previous …
neslihanturan Jun 3, 2019
5a8c137
include clear map into add markers method and reorder methods
neslihanturan Jun 3, 2019
ab7f352
Make search this area button appear at correct time
neslihanturan Jun 3, 2019
026a944
Try to load un search this area is called
neslihanturan Jun 4, 2019
c43b494
Merge remote-tracking branch 'upstream/master' into refactorNearbyCla…
neslihanturan Jun 5, 2019
627cdf7
Clear logs
neslihanturan Jun 8, 2019
2e1cb07
Fix conflixts
neslihanturan Jun 10, 2019
c84ecd1
Add changes for permission made by Vivek to newly added fragments alo…
neslihanturan Jun 10, 2019
c8b1ebb
Add a view to nearby map ragment and insert map view as an item insid…
neslihanturan Jun 12, 2019
edfa39a
Add logs to uınderstand why on meap ready callback is never called
neslihanturan Jun 12, 2019
8667917
Add list item clicked and bottom sheet for list of nearby items is ex…
neslihanturan Jun 13, 2019
22290af
Merge remote-tracking branch 'upstream/master' into refactorNearbyCla…
neslihanturan Jun 13, 2019
98be517
Merge remote-tracking branch 'upstream/master' into refactorNearbyCla…
neslihanturan Jun 25, 2019
3bb801b
Merge remote-tracking branch 'upstream/master' into refactorNearbyCla…
neslihanturan Jun 28, 2019
b8b524f
Make nearby map ready callback came
neslihanturan Jun 28, 2019
e808b0a
Merge remote-tracking branch 'upstream/master' into refactorNearbyCla…
neslihanturan Jul 1, 2019
f6c1d27
Add required methods to be called after map view is ready
neslihanturan Jul 2, 2019
2e7365e
State: Map ready call is not called but permissions and methods are i…
neslihanturan Jul 2, 2019
e0464fa
Merge remote-tracking branch 'upstream/master' into refactorNearbyCla…
neslihanturan Jul 3, 2019
0ec470b
Remove unused logs
neslihanturan Jul 4, 2019
f3694e3
Try to use SupportMapFragment instead, still no success...
neslihanturan Jul 6, 2019
3890ea5
use SupportMapFragment instead
neslihanturan Jul 10, 2019
52e9ef9
Merge remote-tracking branch 'upstream/master' into refactorNearbyCla…
neslihanturan Jul 10, 2019
b511112
Remove unused Near
neslihanturan Jul 10, 2019
1a9c20c
Merge remote-tracking branch 'upstream/master' into refactorNearbyCla…
neslihanturan Jul 12, 2019
2c98db8
Upgrade mapbox sdk versions
neslihanturan Jul 15, 2019
6d9c74f
Remove Style import from fragment/NearbyMapFragment
neslihanturan Jul 15, 2019
e1806c2
Remove Style import from **fragments/NearbyParentFragment
neslihanturan Jul 15, 2019
c0075ca
Remove nearby/NearbyMapFragment
neslihanturan Jul 15, 2019
341d6b7
Remove unused/old NearbyFragment and NearbyMapFragment
neslihanturan Jul 15, 2019
8c4b8c0
Remove import of already removed class
neslihanturan Jul 15, 2019
0b51c93
Make sure you removed everything related with mapbox implementation
neslihanturan Jul 15, 2019
54e3be9
Merge remote-tracking branch 'upstream/master' into refactorNearbyCla…
neslihanturan Jul 16, 2019
6ab2f03
Update mapbox map
neslihanturan Jul 17, 2019
e6f3633
Fix conflicts
neslihanturan Aug 16, 2019
ea2d0cf
Remove unused classes, do not forget centerMapToPlace doesn't work on…
neslihanturan Aug 16, 2019
14f08e2
Remove Style class it required updated version of mapbox map
neslihanturan Aug 18, 2019
6d18ca0
Add base codes for new activity
neslihanturan Aug 22, 2019
7356044
Prove that our mapbox sdk let us implement the map directly inside th…
neslihanturan Aug 22, 2019
dbd1ad2
Add base codes for testing mapbox activity in a single fragment insid…
neslihanturan Aug 24, 2019
5575d42
Add codes from mapbox demo repository to test support fragment, map w…
neslihanturan Aug 24, 2019
67af6d8
Add base codes for test layered fragment activity
neslihanturan Aug 26, 2019
ed796b4
Add Support fragment inside a fragment and proves that layered fragme…
neslihanturan Aug 26, 2019
ef0472b
Test view pager and tab layout with support map fragment to see it wo…
neslihanturan Aug 28, 2019
eeb03bf
Move Contributions Fragment related codes to test activity
neslihanturan Aug 29, 2019
65ca06c
Move nearby card methods
neslihanturan Aug 29, 2019
356c767
Inject location manager and implement NerabyParentFragmentContract.Vi…
neslihanturan Aug 30, 2019
8324e5d
Coppy the content of SupportMapFragment from mapbox repository, use t…
neslihanturan Aug 30, 2019
be42568
Implement NearbyMapContract.View on our new SupportMapFragment
neslihanturan Aug 31, 2019
53ee714
Start to mplement logic of checking permissions
neslihanturan Sep 1, 2019
aa7fb84
Fix small dagger issue to inject location manager properly
neslihanturan Sep 2, 2019
d858813
Request permission for nearby places if fragment is loaded and tab is…
neslihanturan Sep 2, 2019
a396821
Initialize map operations if map ready and tab is selected
neslihanturan Sep 2, 2019
b736087
Markers loads at correct time
neslihanturan Sep 3, 2019
c7261ca
Style the map according to new version of mapbox map
neslihanturan Sep 4, 2019
7a06073
Add some map elements like FABs and give their actions
neslihanturan Sep 5, 2019
32db7b3
Implement map marker click actions
neslihanturan Sep 6, 2019
22662ac
Implement nearby Fabs logic with a small issue
neslihanturan Sep 7, 2019
bf73948
fix FABs are not closing problem
neslihanturan Sep 8, 2019
3dc0844
Unkown problem occurs at map load when I try to use MainActivity again.
neslihanturan Sep 9, 2019
2094158
Revert "Unkown problem occurs at map load when I try to use MainActiv…
neslihanturan Sep 9, 2019
6011cc7
Search this area buttons are added but button function does not work …
neslihanturan Sep 10, 2019
43b4ac1
Fix issue with MainActivity with the help of Ashish
neslihanturan Sep 10, 2019
13695fd
Fix search this area button visibility issue
neslihanturan Sep 11, 2019
a3c6734
Fix the issues with updating search nearby markers and camera positio…
neslihanturan Sep 12, 2019
be1ca1a
Fix progress bar visibility issue
neslihanturan Sep 12, 2019
8c9c37a
Prevent loding map each time tab selected
neslihanturan Sep 13, 2019
c1403c1
Take toolbar back
neslihanturan Sep 13, 2019
9007ae5
Implement back button with presenter
neslihanturan Sep 14, 2019
7feed0a
Add click actoion to bottom sheet details
neslihanturan Sep 14, 2019
0725af2
Add nearby list into bottom sheeet
neslihanturan Sep 14, 2019
62eba39
Make reuse existing fragments if there is any
neslihanturan Sep 14, 2019
7659aec
Code cleanup
neslihanturan Sep 15, 2019
9d1412b
Cleanup
neslihanturan Sep 15, 2019
1677a4b
Code cleanup
neslihanturan Sep 15, 2019
230d62d
Add lifecyle codes to prevent leaks
neslihanturan Sep 15, 2019
c326cce
Cleanup
neslihanturan Sep 15, 2019
dff9ded
Code cleanup
neslihanturan Sep 15, 2019
6d41622
cleanup
neslihanturan Sep 15, 2019
9f8becc
Make list item clicked and map focus to same place
neslihanturan Sep 15, 2019
4304e3d
Add bookmark from list fragment
neslihanturan Sep 17, 2019
c5d4d55
Make nearby card click action work
neslihanturan Sep 17, 2019
f345174
Fix conflicts
neslihanturan Sep 17, 2019
148c891
Revert "Fix conflicts"
neslihanturan Sep 17, 2019
cff4086
Code cleanup
neslihanturan Sep 17, 2019
45d6f56
Cleanup
neslihanturan Sep 17, 2019
ee57f84
Make recenter button work when list sheet is expanded
neslihanturan Sep 17, 2019
cc0cb53
Cleanup
neslihanturan Sep 17, 2019
e9ebd23
Code cleanups
neslihanturan Sep 17, 2019
1b3ce38
NPE issue is not detected for now, can be solved on seperate PR
neslihanturan Sep 18, 2019
6425d3c
Update map after Wikidata edit
neslihanturan Sep 18, 2019
1351541
Fix conflicts
neslihanturan Sep 23, 2019
275181c
Cherry picked previously reverted merge, hoping this will fix enourmu…
neslihanturan Sep 17, 2019
8271504
Previous merge bringed an file which should be deleted. Delete it.
neslihanturan Sep 23, 2019
222b438
Revert irrelevant changes on build.gradle
neslihanturan Sep 23, 2019
3b26c00
Revert irrelevant changes
neslihanturan Sep 23, 2019
23c61bc
Merge remote-tracking branch 'upstream/master' into refactorNearbyCla…
neslihanturan Sep 23, 2019
838b492
Jetbrains annotation is not included to build gradle, this issue caus…
neslihanturan Sep 23, 2019
d0310b3
Rename ListView
neslihanturan Sep 26, 2019
2d64f4b
Use a singleton to access the presenter, instead of passing it to a v…
neslihanturan Oct 1, 2019
e435694
Fix code style issues
neslihanturan Oct 1, 2019
7e40d94
Move hardcoded colors to colors.xml file
neslihanturan Oct 1, 2019
25a88f3
Make larger methods smaller
neslihanturan Oct 1, 2019
1a816fd
Make current location marker follow
neslihanturan Oct 2, 2019
dbd6693
Do not track users position if user is searching around
neslihanturan Oct 2, 2019
5006067
Revert irrelevant shanges at build gradle
neslihanturan Oct 5, 2019
d4777e5
Remove unneeded variable
neslihanturan Oct 5, 2019
b580600
Remove mvp directory, add sub directories directly under nearby direc…
neslihanturan Oct 5, 2019
fa3a14e
Remove unneeded public definiton
neslihanturan Oct 5, 2019
4056811
Remove unneeded namespace
neslihanturan Oct 5, 2019
f903f55
Add public defiiton, it is needed to reach the constructor.
neslihanturan Oct 5, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ dependencies {
implementation 'fr.avianey.com.viewpagerindicator:library:2.4.1.1@aar'
implementation 'com.github.chrisbanes:PhotoView:2.0.0'
implementation 'com.github.pedrovgs:renderers:3.3.3'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-localization:0.6.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:7.2.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-localization-v7:0.7.0'
implementation 'com.github.deano2390:MaterialShowcaseView:1.2.0'
implementation 'com.dinuscxj:circleprogressbar:1.1.1'
implementation 'com.karumi:dexter:5.0.0'
Expand Down Expand Up @@ -158,7 +159,7 @@ android {
versionNameSuffix "-debug-" + getBranchName()
}
}

if (isRunningOnTravisAndIsNotPRBuild) {
// configure keystore based on env vars in Travis for automated alpha builds
signingConfigs.release.storeFile = file("../nr-commons.keystore")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
import fr.free.nrw.commons.auth.AuthenticatedActivity;
import fr.free.nrw.commons.auth.SessionManager;
import fr.free.nrw.commons.location.LocationServiceManager;
import fr.free.nrw.commons.nearby.NearbyFragment;
import fr.free.nrw.commons.nearby.NearbyNotificationCardView;
import fr.free.nrw.commons.nearby.fragments.NearbyParentFragment;
import fr.free.nrw.commons.nearby.presenter.NearbyParentFragmentPresenter;
import fr.free.nrw.commons.notification.Notification;
import fr.free.nrw.commons.notification.NotificationActivity;
import fr.free.nrw.commons.notification.NotificationController;
Expand All @@ -47,13 +48,15 @@

public class MainActivity extends AuthenticatedActivity implements FragmentManager.OnBackStackChangedListener {

@Inject
SessionManager sessionManager;
@Inject ContributionController controller;
@BindView(R.id.tab_layout)
TabLayout tabLayout;
@BindView(R.id.pager)
public UnswipableViewPager viewPager;

@Inject
SessionManager sessionManager;
@Inject
ContributionController controller;
@Inject
public LocationServiceManager locationManager;
@Inject
Expand All @@ -72,29 +75,16 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag
public boolean isContributionsFragmentVisible = true; // False means nearby fragment is visible
private Menu menu;

private boolean onOrientationChanged = false;

private MenuItem notificationsMenuItem;
private TextView notificationCount;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contributions);
ButterKnife.bind(this);

requestAuthToken();
initDrawer();
setTitle(getString(R.string.navigation_item_home)); // Should I create a new string variable with another name instead?


if (savedInstanceState != null ) {
onOrientationChanged = true; // Will be used in nearby fragment to determine significant update of map

//If nearby map was visible, call on Tab Selected to call all nearby operations
/*if (savedInstanceState.getInt("viewPagerCurrentItem") == 1) {
((NearbyFragment)contributionsActivityPagerAdapter.getItem(1)).onTabSelected(onOrientationChanged);
}*/
}
}

@Override
Expand Down Expand Up @@ -161,9 +151,7 @@ public void setNumOfUploads(int uploadCount) {
* tab won't change and vice versa. So we have to notify each of them.
*/
private void setTabAndViewPagerSynchronisation() {
//viewPager.canScrollHorizontally(false);
viewPager.setFocusableInTouchMode(true);

viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Expand All @@ -178,15 +166,14 @@ public void onPageSelected(int position) {
tabLayout.getTabAt(CONTRIBUTIONS_TAB_POSITION).select();
isContributionsFragmentVisible = true;
updateMenuItem();

break;
case NEARBY_TAB_POSITION:
Timber.d("Nearby tab selected");
tabLayout.getTabAt(NEARBY_TAB_POSITION).select();
isContributionsFragmentVisible = false;
updateMenuItem();
// Do all permission and GPS related tasks on tab selected, not on create
((NearbyFragment)contributionsActivityPagerAdapter.getItem(1)).onTabSelected(onOrientationChanged);
NearbyParentFragmentPresenter.getInstance().onTabSelected();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we use callbacks for this thing, that way code would be cleaner and by defining contracts even novice contributors would know the intended use case

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I agree with @ashishkumar468. Let us use callbacks.

break;
default:
tabLayout.getTabAt(CONTRIBUTIONS_TAB_POSITION).select();
Expand Down Expand Up @@ -267,15 +254,7 @@ public void onBackPressed() {
}
} else if (getSupportFragmentManager().findFragmentByTag(nearbyFragmentTag) != null && !isContributionsFragmentVisible) {
// Means that nearby fragment is visible (not contributions fragment)
NearbyFragment nearbyFragment = (NearbyFragment) contributionsActivityPagerAdapter.getItem(1);

if(nearbyFragment.isBottomSheetExpanded()) {
// Back should first hide the bottom sheet if it is expanded
nearbyFragment.listOptionMenuItemClicked();
} else {
// Otherwise go back to contributions fragment
viewPager.setCurrentItem(0);
}
NearbyParentFragmentPresenter.getInstance().backButtonClicked();
} else {
super.onBackPressed();
}
Expand Down Expand Up @@ -332,12 +311,12 @@ private void updateMenuItem() {
// Display notifications menu item
menu.findItem(R.id.notifications).setVisible(true);
menu.findItem(R.id.list_sheet).setVisible(false);
Timber.d("Contributions activity notifications menu item is visible");
Timber.d("Contributions fragment notifications menu item is visible");
} else {
// Display bottom list menu item
menu.findItem(R.id.notifications).setVisible(false);
menu.findItem(R.id.list_sheet).setVisible(true);
Timber.d("Contributions activity list sheet menu item is visible");
Timber.d("Nearby fragment list sheet menu item is visible");
}
}
}
Expand All @@ -351,7 +330,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
return true;
case R.id.list_sheet:
if (contributionsActivityPagerAdapter.getItem(1) != null) {
((NearbyFragment)contributionsActivityPagerAdapter.getItem(1)).listOptionMenuItemClicked();
((NearbyParentFragment)contributionsActivityPagerAdapter.getItem(1)).listOptionMenuItemClicked();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As explained above, please use callback here as well.

}
return true;
default:
Expand All @@ -361,8 +340,6 @@ public boolean onOptionsItemSelected(MenuItem item) {

public class ContributionsActivityPagerAdapter extends FragmentPagerAdapter {
FragmentManager fragmentManager;
private boolean isContributionsListFragment = true; // to know what to put in first tab, Contributions of Media Details


public ContributionsActivityPagerAdapter(FragmentManager fragmentManager) {
super(fragmentManager);
Expand Down Expand Up @@ -392,12 +369,12 @@ public Fragment getItem(int position) {
}

case 1:
NearbyFragment retainedNearbyFragment = getNearbyFragment(1);
NearbyParentFragment retainedNearbyFragment = getNearbyFragment(1);
if (retainedNearbyFragment != null) {
return retainedNearbyFragment;
} else {
// If we reach here, retainedNearbyFragment is null
return new NearbyFragment();
return new NearbyParentFragment();
}
default:
return null;
Expand All @@ -419,9 +396,9 @@ private ContributionsFragment getContributionsFragment(int position) {
* @param position index of tabs, in our case 0 or 1
* @return
*/
private NearbyFragment getNearbyFragment(int position) {
private NearbyParentFragment getNearbyFragment(int position) {
String tag = makeFragmentName(R.id.pager, position);
return (NearbyFragment)fragmentManager.findFragmentByTag(tag);
return (NearbyParentFragment)fragmentManager.findFragmentByTag(tag);
}

/**
Expand All @@ -444,7 +421,6 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
controller.handleActivityResult(this, requestCode, resultCode, data);
}

@Override
protected void onResume() {
super.onResume();
setNotificationCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import fr.free.nrw.commons.explore.recentsearches.RecentSearchesFragment;
import fr.free.nrw.commons.media.MediaDetailFragment;
import fr.free.nrw.commons.media.MediaDetailPagerFragment;
import fr.free.nrw.commons.nearby.NearbyFragment;
import fr.free.nrw.commons.nearby.NearbyListFragment;
import fr.free.nrw.commons.nearby.NearbyMapFragment;
import fr.free.nrw.commons.nearby.fragments.NearbyListFragment;
import fr.free.nrw.commons.nearby.fragments.NearbyMapFragment;
import fr.free.nrw.commons.nearby.fragments.NearbyParentFragment;
import fr.free.nrw.commons.review.ReviewImageFragment;
import fr.free.nrw.commons.settings.SettingsFragment;
import fr.free.nrw.commons.upload.categories.UploadCategoriesFragment;
Expand All @@ -38,9 +38,6 @@ public abstract class FragmentBuilderModule {
@ContributesAndroidInjector
abstract NearbyListFragment bindNearbyListFragment();

@ContributesAndroidInjector
abstract NearbyMapFragment bindNearbyMapFragment();

@ContributesAndroidInjector
abstract SettingsFragment bindSettingsFragment();

Expand All @@ -63,7 +60,10 @@ public abstract class FragmentBuilderModule {
abstract ContributionsFragment bindContributionsFragment();

@ContributesAndroidInjector
abstract NearbyFragment bindNearbyFragment();
abstract NearbyMapFragment bindNearbyMapFragment();

@ContributesAndroidInjector
abstract NearbyParentFragment bindNearbyParentFragment();

@ContributesAndroidInjector
abstract BookmarkPicturesFragment bindBookmarkPictureListFragment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -222,6 +221,7 @@ public enum LocationChangeType{
LOCATION_MEDIUM_CHANGED, //Between slight and significant changes, will be used for nearby card view updates.
LOCATION_NOT_CHANGED,
PERMISSION_JUST_GRANTED,
MAP_UPDATED
MAP_UPDATED,
SEARCH_CUSTOM_AREA
}
}
2 changes: 0 additions & 2 deletions app/src/main/java/fr/free/nrw/commons/mwapi/UploadResult.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package fr.free.nrw.commons.mwapi;

import org.jetbrains.annotations.NotNull;

import java.util.Date;

Expand Down Expand Up @@ -36,7 +35,6 @@ public class UploadResult {
this.imageUrl = imageUrl;
}

@NotNull
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you briefly explain why this annotation was removed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The annotation import causes build error.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you share the build error that was caused by this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/apps-android-commons/app/src/main/java/fr/free/nrw/commons/mwapi/UploadResult.java:39: error: cannot find symbol
    @NotNull
     ^
  symbol:   class NotNull
  location: class UploadResult

It seems like this on master too:
Screenshot from 2019-10-05 21-59-10

But somehow it does not cause a build issue on master.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import is incorrect. You can use

import android.support.annotation.NonNull

@Override
public String toString() {
return "UploadResult{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public NearbyBaseMarker[] newArray(int size) {

private Place place;

NearbyBaseMarker() {
public NearbyBaseMarker() {
}

private NearbyBaseMarker(Parcel in) {
Expand Down
40 changes: 28 additions & 12 deletions app/src/main/java/fr/free/nrw/commons/nearby/NearbyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
public class NearbyController {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we have a presenter for Nearby, we should remove this class and shift the functionalities to the presenter

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nearby controller controls our map logic (ie. how wide area is queried) while NearbyPresenter controls fragments and views. So I think we should keep them separated, but renaming NearbyController can be a better approach to eliminate confusion. What do you say @ashishkumar468 ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@neslihanturan any logic, be it controlling the map logic should go in the corresponding view presenter, we should not ideally have classes other than the presenter to have logics. If we talk in terms of unit testing, it would just be the presenter which would need to be tested.

Copy link
Collaborator Author

@neslihanturan neslihanturan Sep 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, but I can say that these two classes has really different responsibilities. Merging them not only makes the presenter class too long but also causes a semantic confusion. NearbyController decides which places will be displayed and what their included information is while presenter decides how to display them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The presenter is solely responsible for deciding how to display a view. If the view is complex then the presenter will become longer but the controller doesn't fit into the MVP semantics.

If you are inclined towards having smaller presenters, you can try to break down the views into smaller logical views and have presenters for each of them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please read what does NearbyController method do, it does not intended to control views, it does not decide how to display views either. It controls our search operation. It controls how we fetch data from Wikidata. Ie. storing our previously searched radius, our max number of results and accordingly giving us list of data in form of lets say Place type. It is not the same thing which is described in MVP documentation IMO. What do you say?

private static final int MAX_RESULTS = 1000;
private final NearbyPlaces nearbyPlaces;
public static double searchedRadius = 10.0; //in kilometers
public static LatLng currentLocation;
public static double currentLocationSearchRadius = 10.0; //in kilometers
public static LatLng currentLocation; // Users latest fetched location
public static LatLng latestSearchLocation; // Can be current and camera target on search this area button is used
public static double latestSearchRadius = 10.0; // Any last search radius except closest result search

@Inject
public NearbyController(NearbyPlaces nearbyPlaces) {
Expand All @@ -41,21 +43,21 @@ public NearbyController(NearbyPlaces nearbyPlaces) {
* Prepares Place list to make their distance information update later.
*
* @param curLatLng current location for user
* @param latLangToSearchAround the location user wants to search around
* @param searchLatLng the location user wants to search around
* @param returnClosestResult if this search is done to find closest result or all results
* @return NearbyPlacesInfo a variable holds Place list without distance information
* and boundary coordinates of current Place List
*/
public NearbyPlacesInfo loadAttractionsFromLocation(LatLng curLatLng, LatLng latLangToSearchAround, boolean returnClosestResult, boolean checkingAroundCurrentLocation) throws IOException {
public NearbyPlacesInfo loadAttractionsFromLocation(LatLng curLatLng, LatLng searchLatLng, boolean returnClosestResult, boolean checkingAroundCurrentLocation) throws IOException {

Timber.d("Loading attractions near %s", latLangToSearchAround);
Timber.d("Loading attractions near %s", searchLatLng);
NearbyPlacesInfo nearbyPlacesInfo = new NearbyPlacesInfo();

if (latLangToSearchAround == null) {
if (searchLatLng == null) {
Timber.d("Loading attractions nearby, but curLatLng is null");
return null;
}
List<Place> places = nearbyPlaces.radiusExpander(latLangToSearchAround, Locale.getDefault().getLanguage(), returnClosestResult);
List<Place> places = nearbyPlaces.radiusExpander(searchLatLng, Locale.getDefault().getLanguage(), returnClosestResult);

if (null != places && places.size() > 0) {
LatLng[] boundaryCoordinates = {places.get(0).location, // south
Expand Down Expand Up @@ -91,13 +93,25 @@ public NearbyPlacesInfo loadAttractionsFromLocation(LatLng curLatLng, LatLng lat
}
);
}
nearbyPlacesInfo.curLatLng = curLatLng;
nearbyPlacesInfo.searchLatLng = searchLatLng;
nearbyPlacesInfo.placeList = places;
nearbyPlacesInfo.boundaryCoordinates = boundaryCoordinates;
if (!returnClosestResult && checkingAroundCurrentLocation) {
// Do not update searched radius, if controller is used for nearby card notification
searchedRadius = nearbyPlaces.radius;
currentLocation = curLatLng;

// Returning closes result means we use the controller for nearby card. So no need to set search this area flags
if (!returnClosestResult) {
// To remember latest search either around user or any point on map
latestSearchLocation = searchLatLng;
latestSearchRadius = nearbyPlaces.radius*1000; // to meter

// Our radius searched around us, will be used to understand when user search their own location, we will follow them
if (checkingAroundCurrentLocation) {
currentLocationSearchRadius = nearbyPlaces.radius*1000; // to meter
currentLocation = curLatLng;
}
}


return nearbyPlacesInfo;
}
else {
Expand All @@ -112,7 +126,7 @@ public NearbyPlacesInfo loadAttractionsFromLocation(LatLng curLatLng, LatLng lat
* @param placeList list of nearby places in Place data type
* @return Place list that holds nearby places
*/
static List<Place> loadAttractionsFromLocationToPlaces(
public static List<Place> loadAttractionsFromLocationToPlaces(
LatLng curLatLng,
List<Place> placeList) {
placeList = placeList.subList(0, Math.min(placeList.size(), MAX_RESULTS));
Expand Down Expand Up @@ -212,5 +226,7 @@ public static List<NearbyBaseMarker> loadAttractionsFromLocationToBaseMarkerOpti
public class NearbyPlacesInfo {
public List<Place> placeList; // List of nearby places
public LatLng[] boundaryCoordinates; // Corners of nearby area
public LatLng curLatLng; // Current location when this places are populated
public LatLng searchLatLng; // Search location for finding this places
}
}
Loading