Commit 1c32c302 authored by Sajal Narang's avatar Sajal Narang Committed by GitHub

Merge pull request #158 from pulsejet/addevent

Implement Add Event
parents 439eef59 cc8e5c3f
......@@ -24,6 +24,7 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.webkit.WebChromeClient;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
......@@ -37,6 +38,8 @@ import app.insti.api.RetrofitInterface;
import app.insti.api.ServiceGenerator;
import app.insti.api.UnsafeOkHttpClient;
import app.insti.data.Body;
import app.insti.data.Event;
import app.insti.data.Role;
import app.insti.data.User;
import app.insti.fragment.BackHandledFragment;
import app.insti.fragment.BodyFragment;
......@@ -452,6 +455,23 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
return true;
}
public boolean editEventAccess(Event event) {
if (currentUser == null || currentUser.getUserRoles() == null || currentUser.getUserRoles().size() == 0)
return false;
for (Role role : currentUser.getUserRoles()) {
for (Body body : role.getRoleBodies()) {
for (Body eventBody : event.getEventBodies()) {
if (body.getBodyID().equals(eventBody.getBodyID())) {
return true;
}
}
}
}
return false;
}
public static void hideKeyboard(Activity activity) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
//Find the currently focused view, so we can grab the correct window token from it.
......
......@@ -9,6 +9,7 @@ import app.insti.api.model.ImageUploadRequest;
import app.insti.api.model.ImageUploadResponse;
import app.insti.api.model.LoginResponse;
import app.insti.api.model.NewsFeedResponse;
import app.insti.data.Event;
import app.insti.data.HostelMessMenu;
import app.insti.data.NewsArticle;
import app.insti.data.Notification;
......@@ -40,6 +41,9 @@ public interface RetrofitInterface {
@POST("events")
Call<EventCreateResponse> createEvent(@Header("Cookie") String sessionId, @Body EventCreateRequest eventCreateRequest);
@GET("events/{uuid}")
Call<Event> getEvent(@Header("Cookie") String sessionId, @Path("uuid") String uuid);
@GET("events")
Call<NewsFeedResponse> getNewsFeed(@Header("Cookie") String sessionId);
......
......@@ -93,8 +93,7 @@ public class CalendarFragment extends BaseFragment {
}
});
if (((MainActivity)getActivity()).createEventAccess()) {
/* TODO: Uncomment the following line when Add Event is completed */
// fab.setVisibility(View.VISIBLE);
fab.setVisibility(View.VISIBLE);
}
updateEvents();
......
......@@ -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.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
......@@ -228,6 +230,31 @@ public class EventFragment extends BackHandledFragment {
}
});
mShortAnimationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);
final FloatingActionButton fab = (FloatingActionButton) getView().findViewById(R.id.edit_fab);
if (((MainActivity) getActivity()).editEventAccess(event)) {
fab.setVisibility(View.VISIBLE);
NestedScrollView nsv = (NestedScrollView) getView().findViewById(R.id.event_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("id", event.getEventID());
addEventFragment.setArguments(bundle);
((MainActivity) getActivity()).updateFragment(addEventFragment);
}
});
}
void setFollowButtonColors(int status) {
......
......@@ -61,8 +61,6 @@ public class FeedFragment extends BaseFragment {
Toolbar toolbar = getActivity().findViewById(R.id.toolbar);
toolbar.setTitle("Feed");
fab = (FloatingActionButton) view.findViewById(R.id.fab);
feedSwipeRefreshLayout = view.findViewById(R.id.feed_swipe_refresh_layout);
feedSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
......@@ -71,33 +69,18 @@ public class FeedFragment extends BaseFragment {
}
});
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AddEventFragment addEventFragment = new AddEventFragment();
addEventFragment.setArguments(getArguments());
FragmentTransaction ft = getChildFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_left, R.anim.slide_in_right, R.anim.slide_out_right);
ft.replace(R.id.relative_layout, addEventFragment);
ft.addToBackStack("addEvent");
ft.commit();
}
});
return view;
}
@Override
public void onStart() {
super.onStart();
if (((MainActivity) getActivity()).createEventAccess()) {
/* TODO: Uncomment the following line when Add Event is completed */
// fab.setVisibility(View.VISIBLE);
}
appDatabase = AppDatabase.getAppDatabase(getContext());
new showEventsFromDB().execute();
fab = (FloatingActionButton) getView().findViewById(R.id.fab);
feedRecyclerView = getView().findViewById(R.id.feed_recycler_view);
updateFeed();
}
......@@ -130,6 +113,26 @@ public class FeedFragment extends BaseFragment {
/* Skip if we're already destroyed */
if (getActivity() == null || getView() == null) return;
if (((MainActivity) getActivity()).createEventAccess()) {
fab.setVisibility(View.VISIBLE);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AddEventFragment addEventFragment = new AddEventFragment();
Bundle bundle = new Bundle();
addEventFragment.setArguments(bundle);
((MainActivity) getActivity()).updateFragment(addEventFragment);
}
});
feedRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener(){
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy){
if (dy > 0) fab.hide();
else if (dy < 0) fab.show();
}
});
}
/* Make first event image big */
if (events.size() > 1) {
events.get(0).setEventBigImage(true);
......@@ -156,9 +159,9 @@ public class FeedFragment extends BaseFragment {
@Override
public void run(Activity pActivity) {
try {
feedRecyclerView = getActivity().findViewById(R.id.feed_recycler_view);
feedRecyclerView.setAdapter(feedAdapter);
feedRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
} catch (NullPointerException e) {
e.printStackTrace();
}
......
......@@ -58,11 +58,7 @@ public class MyEventsFragment extends BaseFragment {
@Override
public void onClick(View v) {
AddEventFragment addEventFragment = new AddEventFragment();
addEventFragment.setArguments(getArguments());
FragmentTransaction ft = getChildFragmentManager().beginTransaction();
ft.replace(R.id.relative_layout, addEventFragment);
ft.addToBackStack("addEvent");
ft.commit();
((MainActivity) getActivity()).updateFragment(addEventFragment);
}
});
return view;
......@@ -73,8 +69,7 @@ public class MyEventsFragment extends BaseFragment {
super.onStart();
if (((MainActivity)getActivity()).createEventAccess()) {
/* TODO: Uncomment the following line when Add Event is completed */
// fab.setVisibility(View.VISIBLE);
fab.setVisibility(View.VISIBLE);
}
appDatabase = AppDatabase.getAppDatabase(getContext());
......
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>
</vector>
......@@ -5,183 +5,12 @@
android:orientation="vertical"
tools:context="app.insti.fragment.AddEventFragment">
<ScrollView
<WebView
android:id="@+id/add_event_webview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
android:layout_height="match_parent"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="200dp">
<ImageView
android:id="@+id/iv_eventImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EEEEEE" />
<ImageButton
android:id="@+id/ib_eventImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EEEEEE"
android:src="@drawable/ic_input_add"
android:tint="@android:color/black" />
</RelativeLayout>
<EditText
android:id="@+id/et_eventName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:hint="Event Name"
android:padding="16dp"
android:paddingBottom="16dp"
android:textColorHint="#FFFFFF"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="16dp"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_start"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/editTextBackground"
android:gravity="bottom"
android:hint="From "
android:paddingRight="6dp"
android:paddingTop="8dp"
android:textSize="20sp" />
<View
android:layout_width="3dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="@color/common_google_signin_btn_text_dark_disabled" />
<TextView
android:id="@+id/tv_end"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/editTextBackground"
android:enabled="false"
android:gravity="bottom"
android:hint="To "
android:paddingRight="6dp"
android:paddingTop="8dp"
android:textSize="20sp" />
</LinearLayout>
<EditText
android:id="@+id/et_venue"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="16dp"
android:layout_marginTop="10dp"
android:hint="Venue"
android:paddingRight="6dp"
android:textSize="20sp" />
<EditText
android:id="@+id/et_eventDetails"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:layout_weight="1"
android:gravity="top"
android:hint="Details"
android:paddingRight="6dp"
android:textSize="20sp" />
<RelativeLayout
android:id="@+id/advanced_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:paddingLeft="18dp"
android:paddingRight="16dp"
android:text="Advanced Options"
android:textSize="20sp" />
<ImageView
android:id="@+id/close"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignParentEnd="true"
android:src="@mipmap/advanced_menu_close" />
<ImageView
android:id="@+id/open"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignParentEnd="true"
android:src="@mipmap/advanced_menu_open" />
</RelativeLayout>
<CheckBox
android:id="@+id/cb_public"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="12dp"
android:text="Outsiders Allowed " />
<EditText
android:id="@+id/map_location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="22dp"
android:layout_marginRight="12dp"
android:hint="Map Location" />
<CheckBox
android:id="@+id/cb_permission"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="12dp"
android:text="Request User Info" />
</LinearLayout>
</ScrollView>
<Button
android:id="@+id/button_createEvent"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_margin="8dp"
android:background="@drawable/round_text_box"
android:gravity="center"
android:text="Create" />
</WebView>
</LinearLayout>
\ No newline at end of file
......@@ -70,7 +70,7 @@
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="16dp"
android:src="@android:drawable/ic_input_add"
android:src="@drawable/ic_add_black_24dp"
android:tint="@android:color/black"
android:visibility="gone" />
......
This diff is collapsed.
......@@ -24,7 +24,7 @@
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="16dp"
android:src="@android:drawable/ic_input_add"
android:src="@drawable/ic_add_black_24dp"
android:tint="@android:color/black"
android:visibility="gone" />
......
......@@ -25,7 +25,7 @@
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="16dp"
android:src="@android:drawable/ic_input_add"
android:src="@drawable/ic_add_black_24dp"
android:tint="@android:color/black"
android:visibility="gone" />
......
......@@ -5,5 +5,4 @@
<item name="ic_menu_manage" type="drawable">@android:drawable/ic_menu_manage</item>
<item name="ic_menu_share" type="drawable">@android:drawable/ic_menu_share</item>
<item name="ic_menu_send" type="drawable">@android:drawable/ic_menu_send</item>
<item name="ic_input_add" type="drawable">@android:drawable/ic_input_add</item>
</resources>
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