Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

Commit

Permalink
removes popup
Browse files Browse the repository at this point in the history
  • Loading branch information
konishon committed Dec 20, 2019
1 parent 42630ab commit a721388
Showing 1 changed file with 30 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ public class SiteDashboardFragment extends Fragment /*implements View.OnClickLis

@BindView(R.id.site_option_frag_btn_send_form)
Button btnUpload;


private PopupMenu popupMenu;
private Menu menu;


public static SiteDashboardFragment newInstance(Site site, boolean isParent, Project project) {
Expand Down Expand Up @@ -176,7 +174,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
return;
}
this.loadedSite = site;
setupPopup();

updateUi(loadedSite);
setupToolbar();
});
Expand All @@ -191,7 +189,15 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
checkPermissionAndOpenMap();
break;
case R.id.menu_upload:
showSiteUploadConfirmationDialog();
boolean isOfflineSite = loadedSite.getIsSiteVerified() == Constant.SiteStatus.IS_OFFLINE;
boolean isEditedSite = loadedSite.getIsSiteVerified() == Constant.SiteStatus.IS_EDITED;

if (isOfflineSite) {
showSiteUploadConfirmationDialog();
} else if (isEditedSite) {
showEditedSiteUploadDialog();
}
break;
case R.id.menu_delete:
showDeleteWarningDialog();
break;
Expand Down Expand Up @@ -271,47 +277,32 @@ private void setupToolbar() {
}

private void setupPopup() {
popupMenu = new PopupMenu(requireActivity(), iv_more);
popupMenu.getMenuInflater().inflate(R.menu.menu_site_dashboard, popupMenu.getMenu());
if (this.menu == null) {
return;
}

boolean isOfflineSite = loadedSite.getIsSiteVerified() == Constant.SiteStatus.IS_OFFLINE;
boolean isEditedSite = loadedSite.getIsSiteVerified() == Constant.SiteStatus.IS_EDITED;
Menu menu = popupMenu.getMenu();


if (isOfflineSite) {
menu.findItem(R.id.menu_delete).setEnabled(true);
menu.findItem(R.id.menu_upload).setEnabled(true);
this.menu.findItem(R.id.menu_delete).setEnabled(true);
this.menu.findItem(R.id.menu_upload).setEnabled(true);

btnUpload.setEnabled(false);

} else if (isEditedSite) {
btnUpload.setEnabled(true);
menu.findItem(R.id.menu_delete).setEnabled(false);
menu.findItem(R.id.menu_upload).setEnabled(true);
this.menu.findItem(R.id.menu_delete).setEnabled(false);
this.menu.findItem(R.id.menu_upload).setEnabled(true);
} else {
btnUpload.setEnabled(true);
menu.findItem(R.id.menu_delete).setEnabled(false);
menu.findItem(R.id.menu_upload).setEnabled(false);
this.menu.findItem(R.id.menu_delete).setEnabled(false);
this.menu.findItem(R.id.menu_upload).setEnabled(false);
}
popupMenu.setOnMenuItemClickListener(item -> {
switch (item.getItemId()) {
case R.id.menu_site_map:
checkPermissionAndOpenMap();
break;
case R.id.menu_upload:
if (isOfflineSite) {
showSiteUploadConfirmationDialog();
} else if (isEditedSite) {
showEditedSiteUploadDialog();
}
break;
case R.id.menu_delete:
showDeleteWarningDialog();
break;

}
return true;
});
}


private void checkPermissionAndOpenMap() {
if (!checkIfLocationPermissionsGranted(requireActivity())) {
new PermissionUtils().requestLocationPermissions(requireActivity(), new PermissionListener() {
Expand Down Expand Up @@ -390,12 +381,6 @@ void sendForm() {
startActivity(intent);
}

@OnClick(R.id.iv_more)
void showMenuOption() {
Timber.i("SiteDashboardFragment, showMenu option selected");
popupMenu.show();
}


@Override
public void onDestroyView() {
Expand All @@ -404,7 +389,7 @@ public void onDestroyView() {
}


public void showSiteUploadConfirmationDialog() {
void showSiteUploadConfirmationDialog() {

DialogFactory.createActionDialog(requireActivity(), getString(R.string.dialog_title_upload_sites), getString(R.string.dialog_msg_upload_sites))
.setPositiveButton(R.string.dialog_action_upload_site_and_form, (dialog, which) -> {
Expand Down Expand Up @@ -541,7 +526,12 @@ public void onError(Throwable e) {
@Override
public void onPrepareOptionsMenu(@NonNull Menu menu) {
super.onPrepareOptionsMenu(menu);
disableMenuItems(menu);
this.menu = menu;
setupPopup();
}

private void disableMenuItems(Menu menu) {
Integer[] itemsToRemove = new Integer[]{
R.id.action_refresh,
R.id.action_logout,
Expand All @@ -555,8 +545,6 @@ public void onPrepareOptionsMenu(@NonNull Menu menu) {
menuItem.setVisible(false);
}
}


}

@Override
Expand Down

0 comments on commit a721388

Please sign in to comment.