Unkown problem occurs at map load when I try to use MainActivity again.

This commit is contained in:
neslihanturan 2019-09-09 14:24:35 +03:00
parent bf739485ea
commit 3dc084415b
6 changed files with 22 additions and 47 deletions

View file

@ -452,7 +452,7 @@ public class LoginActivity extends AccountAuthenticatorActivity {
}
public void startMainActivity() {
NavigationBaseActivity.startActivityWithFlags(this, NearbyTestFragmentLayersActivity.class, Intent.FLAG_ACTIVITY_SINGLE_TOP);
NavigationBaseActivity.startActivityWithFlags(this, MainActivity.class, Intent.FLAG_ACTIVITY_SINGLE_TOP);
finish();
}

View file

@ -45,7 +45,6 @@ import fr.free.nrw.commons.mwapi.MediaWikiApi;
import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient;
import fr.free.nrw.commons.nearby.NearbyController;
import fr.free.nrw.commons.nearby.NearbyNotificationCardView;
import fr.free.nrw.commons.nearby.NearbyTestFragmentLayersActivity;
import fr.free.nrw.commons.nearby.Place;
import fr.free.nrw.commons.settings.Prefs;
import fr.free.nrw.commons.upload.UploadService;
@ -258,8 +257,8 @@ public class ContributionsFragment
operations on first time fragment attached to an activity. Then they will be retained
until fragment life time ends.
*/
if (((NearbyTestFragmentLayersActivity)getActivity()).isAuthCookieAcquired && !isFragmentAttachedBefore) {
onAuthCookieAcquired(((NearbyTestFragmentLayersActivity)getActivity()).uploadServiceIntent);
if (((MainActivity)getActivity()).isAuthCookieAcquired && !isFragmentAttachedBefore) {
onAuthCookieAcquired(((MainActivity)getActivity()).uploadServiceIntent);
isFragmentAttachedBefore = true;
}
@ -271,7 +270,7 @@ public class ContributionsFragment
*/
public void showContributionsListFragment() {
// show tabs on contribution list is visible
((NearbyTestFragmentLayersActivity) getActivity()).showTabs();
((MainActivity) getActivity()).showTabs();
// show nearby card view on contributions list is visible
if (nearbyNotificationCardView != null) {
if (store.getBoolean("displayNearbyCardView", true)) {
@ -292,7 +291,7 @@ public class ContributionsFragment
*/
public void showMediaDetailPagerFragment() {
// hide tabs on media detail view is visible
((NearbyTestFragmentLayersActivity)getActivity()).hideTabs();
((MainActivity)getActivity()).hideTabs();
// hide nearby card view on media detail is visible
nearbyNotificationCardView.setVisibility(View.GONE);
@ -302,7 +301,7 @@ public class ContributionsFragment
@Override
public void onBackStackChanged() {
((NearbyTestFragmentLayersActivity)getActivity()).initBackButton();
((MainActivity)getActivity()).initBackButton();
}
/**
@ -352,7 +351,7 @@ public class ContributionsFragment
private void setUploadCount() {
compositeDisposable.add(okHttpJsonApiClient
.getUploadCount(((NearbyTestFragmentLayersActivity)getActivity()).sessionManager.getCurrentAccount().name)
.getUploadCount(((MainActivity)getActivity()).sessionManager.getCurrentAccount().name)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::displayUploadCount,
@ -366,7 +365,7 @@ public class ContributionsFragment
return;
}
((NearbyTestFragmentLayersActivity)getActivity()).setNumOfUploads(uploadCount);
((MainActivity)getActivity()).setNumOfUploads(uploadCount);
}
@ -421,7 +420,7 @@ public class ContributionsFragment
onLocationPermissionGranted();
} else if (shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_FINE_LOCATION)
&& store.getBoolean("displayLocationPermissionForCardView", true)
&& (((NearbyTestFragmentLayersActivity) getActivity()).viewPager.getCurrentItem() == CONTRIBUTIONS_TAB_POSITION)) {
&& (((MainActivity) getActivity()).viewPager.getCurrentItem() == CONTRIBUTIONS_TAB_POSITION)) {
nearbyNotificationCardView.permissionType = NearbyNotificationCardView.PermissionType.ENABLE_LOCATION_PERMISSION;
showNearbyCardPermissionRationale();
}

View file

@ -33,7 +33,7 @@ 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.NearbyNotificationCardView;
import fr.free.nrw.commons.nearby.mvp.fragments.NearbyParentFragment;
import fr.free.nrw.commons.nearby.NearbyTestLayersFragment;
import fr.free.nrw.commons.notification.Notification;
import fr.free.nrw.commons.notification.NotificationActivity;
import fr.free.nrw.commons.notification.NotificationController;
@ -73,8 +73,6 @@ 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;
@ -86,16 +84,6 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag
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
@ -268,7 +256,7 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag
}
} else if (getSupportFragmentManager().findFragmentByTag(nearbyFragmentTag) != null && !isContributionsFragmentVisible) {
// Means that nearby fragment is visible (not contributions fragment)
NearbyParentFragment nearbyFragment = (NearbyParentFragment) contributionsActivityPagerAdapter.getItem(1);
NearbyTestLayersFragment nearbyFragment = (NearbyTestLayersFragment) contributionsActivityPagerAdapter.getItem(1);
if(nearbyFragment.isBottomSheetExpanded()) {
// Back should first hide the bottom sheet if it is expanded
@ -352,7 +340,7 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag
return true;
case R.id.list_sheet:
if (contributionsActivityPagerAdapter.getItem(1) != null) {
((NearbyParentFragment)contributionsActivityPagerAdapter.getItem(1)).listOptionMenuItemClicked();
((NearbyTestLayersFragment)contributionsActivityPagerAdapter.getItem(1)).listOptionMenuItemClicked();
}
return true;
default:
@ -393,12 +381,12 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag
}
case 1:
NearbyParentFragment retainedNearbyFragment = getNearbyFragment(1);
NearbyTestLayersFragment retainedNearbyFragment = getNearbyFragment(1);
if (retainedNearbyFragment != null) {
return retainedNearbyFragment;
} else {
// If we reach here, retainedNearbyFragment is null
return new NearbyParentFragment();
return new NearbyTestLayersFragment();
}
default:
return null;
@ -420,9 +408,9 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag
* @param position index of tabs, in our case 0 or 1
* @return
*/
private NearbyParentFragment getNearbyFragment(int position) {
private NearbyTestLayersFragment getNearbyFragment(int position) {
String tag = makeFragmentName(R.id.pager, position);
return (NearbyParentFragment)fragmentManager.findFragmentByTag(tag);
return (NearbyTestLayersFragment)fragmentManager.findFragmentByTag(tag);
}
/**

View file

@ -74,7 +74,7 @@ public class NearbyNotificationCardView extends SwipableCardView {
protected void onAttachedToWindow() {
super.onAttachedToWindow();
// If you don't setVisibility after getting layout params, then you will se an empty space in place of nearby NotificationCardView
if (((NearbyTestFragmentLayersActivity)getContext()).defaultKvStore.getBoolean("displayNearbyCardView", true) && this.cardViewVisibilityState == NearbyNotificationCardView.CardViewVisibilityState.READY) {
if (((MainActivity)getContext()).defaultKvStore.getBoolean("displayNearbyCardView", true) && this.cardViewVisibilityState == NearbyNotificationCardView.CardViewVisibilityState.READY) {
this.setVisibility(VISIBLE);
} else {
this.setVisibility(GONE);
@ -97,7 +97,7 @@ public class NearbyNotificationCardView extends SwipableCardView {
@Override public boolean onSwipe(View view) {
view.setVisibility(GONE);
// Save shared preference for nearby card view accordingly
((NearbyTestFragmentLayersActivity) getContext()).defaultKvStore.putBoolean("displayNearbyCardView", false);
((MainActivity) getContext()).defaultKvStore.putBoolean("displayNearbyCardView", false);
ViewUtil.showLongToast(getContext(),
getResources().getString(R.string.nearby_notification_dismiss_message));
return true;

View file

@ -183,6 +183,7 @@ public class NearbyTestLayersFragment extends CommonsDaggerSupportFragment imple
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.d("denemeTest","NearbyTestLayersFragment create view");
view = inflater.inflate(R.layout.fragment_simple, container, false);
ButterKnife.bind(this, view);
// Inflate the layout for this fragment
@ -268,6 +269,7 @@ public class NearbyTestLayersFragment extends CommonsDaggerSupportFragment imple
}
public void setMapFragment(Bundle savedInstanceState) {
Log.d("denemeTest","this:"+this+", setMapFragment");
// Mapbox access token is configured here. This needs to be called either in your application
// object or in the same activity which contains the mapview.
Mapbox.getInstance(getActivity(), getString(R.string.mapbox_commons_app_token));
@ -467,7 +469,7 @@ public class NearbyTestLayersFragment extends CommonsDaggerSupportFragment imple
PermissionUtils.checkPermissionsAndPerformAction(getActivity(),
Manifest.permission.ACCESS_FINE_LOCATION,
runnable,
() -> ((NearbyTestFragmentLayersActivity) getActivity()).viewPager.setCurrentItem(CONTRIBUTIONS_TAB_POSITION),
() -> ((MainActivity) getActivity()).viewPager.setCurrentItem(CONTRIBUTIONS_TAB_POSITION),
R.string.location_permission_title,
R.string.location_permission_rationale_nearby);
}
@ -483,20 +485,6 @@ public class NearbyTestLayersFragment extends CommonsDaggerSupportFragment imple
@Override
public void animateFABs() {
if (fabPlus.isShown()){
/*if (isFabOpen) {
fabPlus.startAnimation(rotate_backward);
fabCamera.startAnimation(fab_close);
fabGallery.startAnimation(fab_close);
fabCamera.hide();
fabGallery.hide();
} else {
fabPlus.startAnimation(rotate_forward);
fabCamera.startAnimation(fab_open);
fabGallery.startAnimation(fab_open);
fabCamera.show();
fabGallery.show();
}
this.isFabOpen=!isFabOpen;*/
if (isFabOpen) {
closeFABs(isFabOpen);
} else {

View file

@ -191,7 +191,7 @@ public abstract class NavigationBaseActivity extends BaseActivity
return true;
case R.id.action_nearby_test_fragment_layers:
drawerLayout.closeDrawer(navigationView);
startActivityWithFlags(this, NearbyTestFragmentLayersActivity.class, Intent.FLAG_ACTIVITY_REORDER_TO_FRONT,
startActivityWithFlags(this, MainActivity.class, Intent.FLAG_ACTIVITY_REORDER_TO_FRONT,
Intent.FLAG_ACTIVITY_SINGLE_TOP);
return true;
case R.id.action_feedback: