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; ...@@ -29,6 +29,7 @@ import app.insti.MainActivity;
import app.insti.R; import app.insti.R;
import app.insti.api.RetrofitInterface; import app.insti.api.RetrofitInterface;
import app.insti.api.ServiceGenerator; import app.insti.api.ServiceGenerator;
import app.insti.data.Body;
import app.insti.data.Event; import app.insti.data.Event;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Callback; import retrofit2.Callback;
...@@ -90,6 +91,9 @@ public class AddEventFragment extends BaseFragment { ...@@ -90,6 +91,9 @@ public class AddEventFragment extends BaseFragment {
String url = "https://" + host + "/add-event?sandbox=true"; String url = "https://" + host + "/add-event?sandbox=true";
if (getArguments().containsKey("id")) { if (getArguments().containsKey("id")) {
url = "https://" + host + "/edit-event/" + getArguments().getString("id") + "?sandbox=true"; 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); webView.loadUrl(url);
...@@ -145,6 +149,23 @@ public class AddEventFragment extends BaseFragment { ...@@ -145,6 +149,23 @@ public class AddEventFragment extends BaseFragment {
public void onFailure(Call<Event> call, Throwable t) { } 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;
} }
// return true; //Indicates WebView to NOT load the url; // return true; //Indicates WebView to NOT load the url;
...@@ -202,6 +223,15 @@ public class AddEventFragment extends BaseFragment { ...@@ -202,6 +223,15 @@ public class AddEventFragment extends BaseFragment {
transaction.addToBackStack(eventFragment.getTag()).commit(); 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){ public void onActivityResult(int requestCode, int resultCode, Intent data){
if (requestCode == 101) { if (requestCode == 101) {
if (uploadMessage == null) return; if (uploadMessage == null) return;
......
...@@ -12,8 +12,10 @@ import android.graphics.Rect; ...@@ -12,8 +12,10 @@ import android.graphics.Rect;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.NestedScrollView;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
...@@ -345,6 +347,29 @@ public class BodyFragment extends BackHandledFragment { ...@@ -345,6 +347,29 @@ public class BodyFragment extends BackHandledFragment {
childrenRecyclerView.setLayoutManager(new LinearLayoutManager(getContext())); childrenRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
getActivity().findViewById(R.id.loadingPanel).setVisibility(View.GONE); 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);
}
});
} }
/** /**
......
...@@ -8,12 +8,17 @@ ...@@ -8,12 +8,17 @@
android:orientation="vertical" android:orientation="vertical"
tools:context=".fragment.BodyFragment"> tools:context=".fragment.BodyFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout <android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/body_swipe_refresh_layout" android:id="@+id/body_swipe_refresh_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<android.support.v4.widget.NestedScrollView <android.support.v4.widget.NestedScrollView
android:id="@+id/body_scrollview"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1" android:layout_weight="1"
...@@ -202,8 +207,22 @@ ...@@ -202,8 +207,22 @@
</LinearLayout> </LinearLayout>
</android.support.v4.widget.NestedScrollView> </android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout> </android.support.v4.widget.SwipeRefreshLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/edit_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="16dp"
android:src="@drawable/ic_edit_black_24dp"
android:tint="@android:color/black"
android:visibility="gone"/>
</RelativeLayout>
<RelativeLayout <RelativeLayout
android:id="@+id/loadingPanel" android:id="@+id/loadingPanel"
android:layout_width="match_parent" android:layout_width="match_parent"
......
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