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,201 +8,220 @@ ...@@ -8,201 +8,220 @@
android:orientation="vertical" android:orientation="vertical"
tools:context=".fragment.BodyFragment"> tools:context=".fragment.BodyFragment">
<android.support.v4.widget.SwipeRefreshLayout <RelativeLayout
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="match_parent">
<android.support.v4.widget.NestedScrollView <android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/body_swipe_refresh_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="wrap_content">
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout <android.support.v4.widget.NestedScrollView
android:id="@+id/body_scrollview"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"> android:orientation="vertical">
<ImageView <LinearLayout
android:id="@+id/body_picture"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:scaleType="fitCenter" />
<android.support.v7.widget.CardView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:cardBackgroundColor="@color/colorPrimary"> android:orientation="vertical">
<LinearLayout <ImageView
android:id="@+id/body_picture"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:scaleType="fitCenter" />
<android.support.v7.widget.CardView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" app:cardBackgroundColor="@color/colorPrimary">
android:layout_marginBottom="12dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="12dp"
android:layout_weight="3"
android:orientation="vertical">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"> android:layout_gravity="center_vertical"
android:layout_marginBottom="12dp"
<TextView android:layout_marginEnd="16dp"
android:id="@+id/body_name" android:layout_marginStart="16dp"
android:layout_width="0dp" android:layout_marginTop="12dp"
android:layout_height="wrap_content" android:layout_weight="3"
android:layout_weight="10" android:orientation="vertical">
android:text="Org Title"
android:textColor="#fff" <LinearLayout
android:textSize="21sp" android:layout_width="match_parent"
android:textStyle="bold" />
<ImageButton
android:id="@+id/web_body_button"
android:layout_width="10dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:orientation="horizontal">
android:layout_weight="1"
android:background="?attr/selectableItemBackgroundBorderless" <TextView
android:contentDescription="Org Website" android:id="@+id/body_name"
android:src="@drawable/ic_language_black_24dp" android:layout_width="0dp"
android:tint="@color/colorWhite" android:layout_height="wrap_content"
android:visibility="invisible" /> android:layout_weight="10"
android:text="Org Title"
<ImageButton android:textColor="#fff"
android:id="@+id/share_body_button" android:textSize="21sp"
android:layout_width="0dp" android:textStyle="bold" />
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" <ImageButton
android:layout_weight="1" android:id="@+id/web_body_button"
android:background="?attr/selectableItemBackgroundBorderless" android:layout_width="10dp"
android:contentDescription="Share Body" android:layout_height="wrap_content"
android:src="@drawable/ic_menu_share" android:layout_gravity="center_vertical"
android:tint="@color/colorWhite" /> android:layout_weight="1"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="Org Website"
android:src="@drawable/ic_language_black_24dp"
android:tint="@color/colorWhite"
android:visibility="invisible" />
<ImageButton
android:id="@+id/share_body_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="Share Body"
android:src="@drawable/ic_menu_share"
android:tint="@color/colorWhite" />
</LinearLayout>
</LinearLayout> </LinearLayout>
</android.support.v7.widget.CardView>
<LinearLayout
style="?android:attr/buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/follow_button"
style="?android:attr/buttonBarButtonStyle"
android:textAllCaps="false"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:layout_weight="1"
android:text="FOLLOW"
android:textColor="@color/secondaryTextColor"
android:foreground="?attr/selectableItemBackground"
android:clickable="true" />
</LinearLayout> </LinearLayout>
</android.support.v7.widget.CardView>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#aaa">
<LinearLayout </View>
style="?android:attr/buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button <TextView
android:id="@+id/follow_button" android:id="@+id/body_description"
style="?android:attr/buttonBarButtonStyle" android:layout_width="match_parent"
android:textAllCaps="false"
android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="0dp" android:layout_marginBottom="16dp"
android:layout_weight="1" android:layout_marginEnd="10dp"
android:text="FOLLOW" android:layout_marginStart="10dp"
android:textColor="@color/secondaryTextColor" android:layout_marginTop="12dp"
android:foreground="?attr/selectableItemBackground" android:textColor="#333"
android:clickable="true" /> android:textSize="16sp" />
</LinearLayout>
<View <TextView
android:layout_width="match_parent" android:id="@+id/body_events_title"
android:layout_height="1dp" android:layout_width="match_parent"
android:background="#aaa"> android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:fontFamily="sans-serif-light"
android:text="Events"
android:textSize="20sp"
android:visibility="gone" />
<android.support.v7.widget.RecyclerView
android:id="@+id/event_card_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:nestedScrollingEnabled="false"
android:visibility="gone" />
</View> <TextView
android:id="@+id/body_orgs_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:fontFamily="sans-serif-light"
android:text="Organizations"
android:textSize="20sp"
android:visibility="gone" />
<android.support.v7.widget.RecyclerView
android:id="@+id/org_card_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:nestedScrollingEnabled="false"
android:visibility="gone" />
<TextView <TextView
android:id="@+id/body_description" android:id="@+id/body_people_title"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="16dp" android:layout_marginLeft="15dp"
android:layout_marginEnd="10dp" android:fontFamily="sans-serif-light"
android:layout_marginStart="10dp" android:text="People"
android:layout_marginTop="12dp" android:textSize="20sp"
android:textColor="#333" android:visibility="gone" />
android:textSize="16sp" />
<android.support.v7.widget.RecyclerView
<TextView android:id="@+id/people_card_recycler_view"
android:id="@+id/body_events_title" android:layout_width="match_parent"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:layout_marginBottom="10dp"
android:layout_marginLeft="15dp" android:nestedScrollingEnabled="false"
android:fontFamily="sans-serif-light" android:visibility="gone" />
android:text="Events"
android:textSize="20sp"
android:visibility="gone" />
<android.support.v7.widget.RecyclerView
android:id="@+id/event_card_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:nestedScrollingEnabled="false"
android:visibility="gone" />
<TextView <TextView
android:id="@+id/body_orgs_title" android:id="@+id/body_parents_title"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="15dp" android:layout_marginLeft="15dp"
android:fontFamily="sans-serif-light" android:fontFamily="sans-serif-light"
android:text="Organizations" android:text="Part of"
android:textSize="20sp" android:textSize="20sp"
android:visibility="gone" /> android:visibility="gone" />
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:id="@+id/org_card_recycler_view" android:id="@+id/parentorg_card_recycler_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="10dp" android:layout_marginBottom="10dp"
android:nestedScrollingEnabled="false" android:nestedScrollingEnabled="false"
android:visibility="gone" /> android:visibility="gone" />
<TextView </LinearLayout>
android:id="@+id/body_people_title" </android.support.v4.widget.NestedScrollView>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:fontFamily="sans-serif-light"
android:text="People"
android:textSize="20sp"
android:visibility="gone" />
<android.support.v7.widget.RecyclerView
android:id="@+id/people_card_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:nestedScrollingEnabled="false"
android:visibility="gone" />
<TextView </android.support.v4.widget.SwipeRefreshLayout>
android:id="@+id/body_parents_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:fontFamily="sans-serif-light"
android:text="Part of"
android:textSize="20sp"
android:visibility="gone" />
<android.support.v7.widget.RecyclerView
android:id="@+id/parentorg_card_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:nestedScrollingEnabled="false"
android:visibility="gone" />
</LinearLayout> <android.support.design.widget.FloatingActionButton
</android.support.v4.widget.NestedScrollView> android:id="@+id/edit_fab"
</android.support.v4.widget.SwipeRefreshLayout> 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"
......
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