Commit 18d998ba authored by Varun Patil's avatar Varun Patil

Add edit body button (WebView)

parent 5bccc51a
......@@ -29,6 +29,7 @@ import app.insti.MainActivity;
import app.insti.R;
import app.insti.api.RetrofitInterface;
import app.insti.api.ServiceGenerator;
import app.insti.data.Body;
import app.insti.data.Event;
import retrofit2.Call;
import retrofit2.Callback;
......@@ -90,6 +91,9 @@ public class AddEventFragment extends BaseFragment {
String url = "https://" + host + "/add-event?sandbox=true";
if (getArguments().containsKey("id")) {
url = "https://" + host + "/edit-event/" + getArguments().getString("id") + "?sandbox=true";
} else if (getArguments().containsKey("bodyId")) {
url = "https://" + host + "/edit-body/" + getArguments().getString("bodyId") + "?sandbox=true";
toolbar.setTitle("Update Organization");
}
webView.loadUrl(url);
......@@ -145,6 +149,23 @@ public class AddEventFragment extends BaseFragment {
public void onFailure(Call<Event> call, Throwable t) { }
});
return true;
} else if (url.contains("/org/")) {
url = url.substring(url.lastIndexOf("/") + 1);
RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class);
retrofitInterface.getBody(((MainActivity) getActivity()).getSessionIDHeader(), url).enqueue(new Callback<Body>() {
@Override
public void onResponse(Call<Body> call, Response<Body> response) {
if (response.isSuccessful()) {
openBody(response.body());
}
}
@Override
public void onFailure(Call<Body> call, Throwable t) { }
});
return true;
}
// return true; //Indicates WebView to NOT load the url;
......@@ -202,6 +223,15 @@ public class AddEventFragment extends BaseFragment {
transaction.addToBackStack(eventFragment.getTag()).commit();
}
void openBody(Body body) {
BodyFragment bodyFragment = BodyFragment.newInstance(body);
FragmentManager manager = getActivity().getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_left, R.anim.slide_in_right, R.anim.slide_out_right);
transaction.replace(R.id.framelayout_for_fragment, bodyFragment, bodyFragment.getTag());
transaction.addToBackStack(bodyFragment.getTag()).commit();
}
public void onActivityResult(int requestCode, int resultCode, Intent data){
if (requestCode == 101) {
if (uploadMessage == null) return;
......
......@@ -12,8 +12,10 @@ import android.graphics.Rect;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.NestedScrollView;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
......@@ -345,6 +347,29 @@ public class BodyFragment extends BackHandledFragment {
childrenRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
getActivity().findViewById(R.id.loadingPanel).setVisibility(View.GONE);
/* Show update button if role */
final FloatingActionButton fab = (FloatingActionButton) getView().findViewById(R.id.edit_fab);
fab.setVisibility(View.VISIBLE);
NestedScrollView nsv = (NestedScrollView) getView().findViewById(R.id.body_scrollview);
nsv.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
@Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
if (scrollY > oldScrollY) fab.hide();
else fab.show();
}
});
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AddEventFragment addEventFragment = new AddEventFragment();
Bundle bundle = new Bundle();
bundle.putString("bodyId", body.getBodyID());
addEventFragment.setArguments(bundle);
((MainActivity) getActivity()).updateFragment(addEventFragment);
}
});
}
/**
......
This diff is collapsed.
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