Commit fe4b5615 authored by Varun Patil's avatar Varun Patil

Show edit body fab only when user has role

parent 18d998ba
...@@ -472,6 +472,20 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -472,6 +472,20 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
return false; return false;
} }
public boolean editBodyAccess(Body toEditBody) {
if (currentUser == null || currentUser.getUserRoles() == null || currentUser.getUserRoles().size() == 0)
return false;
for (Role role : currentUser.getUserRoles()) {
for (Body body : role.getRoleBodies()) {
if (body.getBodyID().equals(toEditBody.getBodyID())) {
return true;
}
}
}
return false;
}
public static void hideKeyboard(Activity activity) { public static void hideKeyboard(Activity activity) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE); InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
//Find the currently focused view, so we can grab the correct window token from it. //Find the currently focused view, so we can grab the correct window token from it.
......
...@@ -349,27 +349,29 @@ public class BodyFragment extends BackHandledFragment { ...@@ -349,27 +349,29 @@ public class BodyFragment extends BackHandledFragment {
getActivity().findViewById(R.id.loadingPanel).setVisibility(View.GONE); getActivity().findViewById(R.id.loadingPanel).setVisibility(View.GONE);
/* Show update button if role */ /* Show update button if role */
final FloatingActionButton fab = (FloatingActionButton) getView().findViewById(R.id.edit_fab); if (((MainActivity) getActivity()).editBodyAccess(body)) {
fab.setVisibility(View.VISIBLE); final FloatingActionButton fab = (FloatingActionButton) getView().findViewById(R.id.edit_fab);
NestedScrollView nsv = (NestedScrollView) getView().findViewById(R.id.body_scrollview); fab.setVisibility(View.VISIBLE);
nsv.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() { NestedScrollView nsv = (NestedScrollView) getView().findViewById(R.id.body_scrollview);
@Override nsv.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) { @Override
if (scrollY > oldScrollY) fab.hide(); public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
else fab.show(); if (scrollY > oldScrollY) fab.hide();
} else fab.show();
}); }
});
fab.setOnClickListener(new View.OnClickListener() { fab.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
AddEventFragment addEventFragment = new AddEventFragment(); AddEventFragment addEventFragment = new AddEventFragment();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("bodyId", body.getBodyID()); bundle.putString("bodyId", body.getBodyID());
addEventFragment.setArguments(bundle); addEventFragment.setArguments(bundle);
((MainActivity) getActivity()).updateFragment(addEventFragment); ((MainActivity) getActivity()).updateFragment(addEventFragment);
} }
}); });
}
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment