Commit 78f18cfb authored by Sajal Narang's avatar Sajal Narang Committed by GitHub

Merge pull request #116 from pulsejet/morestuff

Make Body Fragment, fix some things
parents b5c1aa9d aa89fa7d
......@@ -62,5 +62,6 @@ dependencies {
implementation "com.android.support:cardview-v7:${supportLibVersion}"
implementation "de.hdodenhof:circleimageview:${circleImageViewVersion}"
implementation "ru.noties:markwon:${markwonVersion}"
implementation 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
}
apply plugin: 'com.google.gms.google-services'
......@@ -24,8 +24,10 @@ import android.widget.TextView;
import android.widget.Toast;
import com.google.gson.Gson;
import com.jakewharton.picasso.OkHttp3Downloader;
import com.squareup.picasso.Picasso;
import in.ac.iitb.gymkhana.iitbapp.api.UnsafeOkHttpClient;
import in.ac.iitb.gymkhana.iitbapp.api.model.NotificationsResponse;
import in.ac.iitb.gymkhana.iitbapp.data.User;
import in.ac.iitb.gymkhana.iitbapp.fragment.AboutFragment;
......@@ -118,7 +120,16 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
ImageView profilePictureImageView = header.findViewById(R.id.user_profile_picture_nav_header);
nameTextView.setText(currentUser.getUserName());
rollNoTextView.setText(currentUser.getUserRollNumber());
Picasso.with(this).load(currentUser.getUserProfilePictureUrl()).into(profilePictureImageView);
Picasso.Builder picassoBuilder = new Picasso.Builder(this);
picassoBuilder.downloader(
new OkHttp3Downloader((
UnsafeOkHttpClient.getUnsafeOkHttpClient()
)
));
Picasso picasso = picassoBuilder.build();
picasso.load(currentUser.getUserProfilePictureUrl()).into(profilePictureImageView);
}
// private void fetchNotifications() {
......
package in.ac.iitb.gymkhana.iitbapp;
import in.ac.iitb.gymkhana.iitbapp.data.Body;
import in.ac.iitb.gymkhana.iitbapp.data.Event;
/**
......@@ -12,4 +13,8 @@ public final class ShareURLMaker {
public static final String getEventURL(Event event) {
return WEB_HOST + "event/" + event.getEventStrID();
}
public static final String getBodyURL(Body body) {
return WEB_HOST + "org/" + body.getBodyStrID();
}
}
package in.ac.iitb.gymkhana.iitbapp.api;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import in.ac.iitb.gymkhana.iitbapp.api.model.EventCreateRequest;
......@@ -31,12 +33,18 @@ public interface RetrofitInterface {
@GET("events")
Call<NewsFeedResponse> getNewsFeed(@Header("Cookie") String sessionId);
@GET("events")
Call<NewsFeedResponse> getEventsBetweenDates(@Header("Cookie") String sessionId, @Query("start") String start, @Query("end") String end);
@GET("users/{uuid}")
Call<User> getUser(@Header("Cookie") String sessionId, @Path("uuid") String uuid);
@GET("bodies/{uuid}")
Call<in.ac.iitb.gymkhana.iitbapp.data.Body> getBody(@Header("Cookie") String sessionId, @Path("uuid") String uuid);
@GET("bodies/{bodyID}/follow")
Call<Void> updateBodyFollowing(@Header("Cookie") String sessionID, @Path("bodyID") String eventID, @Query("action") int action);
@POST("upload")
Call<ImageUploadResponse> uploadImage(@Header("Cookie") String sessionID, @Body ImageUploadRequest imageUploadRequest);
......
package in.ac.iitb.gymkhana.iitbapp.api;
import java.security.cert.CertificateException;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import okhttp3.OkHttpClient;
public class UnsafeOkHttpClient {
public static OkHttpClient getUnsafeOkHttpClient() {
try {
// Create a trust manager that does not validate certificate chains
final TrustManager[] trustAllCerts = new TrustManager[] {
new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[]{};
}
}
};
// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.sslSocketFactory(sslSocketFactory, (X509TrustManager)trustAllCerts[0]);
builder.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
OkHttpClient okHttpClient = builder.build();
return okHttpClient;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
......@@ -49,8 +49,11 @@ public class Body {
@ColumnInfo(name = "blog_url")
@SerializedName("blog_url")
String bodyBlogURL;
@ColumnInfo(name = "user_follows")
@SerializedName("user_follows")
boolean bodyUserFollows;
public Body(String bodyID, String bodyStrID, String bodyName, String bodyShortDescription, String bodyDescription, String bodyImageURL, List<Body> bodyChildren, List<Body> bodyParents, List<Event> bodyEvents, int bodyFollowersCount, String bodyWebsiteURL, String bodyBlogURL) {
public Body(String bodyID, String bodyStrID, String bodyName, String bodyShortDescription, String bodyDescription, String bodyImageURL, List<Body> bodyChildren, List<Body> bodyParents, List<Event> bodyEvents, int bodyFollowersCount, String bodyWebsiteURL, String bodyBlogURL, Boolean bodyUserFollows) {
this.bodyID = bodyID;
this.bodyStrID = bodyStrID;
this.bodyName = bodyName;
......@@ -63,6 +66,7 @@ public class Body {
this.bodyFollowersCount = bodyFollowersCount;
this.bodyWebsiteURL = bodyWebsiteURL;
this.bodyBlogURL = bodyBlogURL;
this.bodyUserFollows = bodyUserFollows;
}
public String getBodyID() {
......@@ -161,4 +165,11 @@ public class Body {
this.bodyBlogURL = bodyBlogURL;
}
public boolean getBodyUserFollows() {
return bodyUserFollows;
}
public void setBodyUserFollows(boolean bodyUserFollows) {
this.bodyUserFollows = bodyUserFollows;
}
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Delete;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.Query;
import android.arch.persistence.room.Update;
import java.util.List;
......@@ -63,12 +64,18 @@ public interface DbDao {
@Insert
void insertEvent(Event event);
@Update
void updateEvent(Event event);
@Insert
void insertBodies(List<Body> bodies);
@Insert
void insertBody(Body body);
@Update
void updateBody(Body body);
@Insert
void insertVenues(List<Venue> venues);
......
......@@ -60,8 +60,11 @@ public class Event {
@ColumnInfo(name = "website_url")
@SerializedName("website_url")
String eventWebsiteURL;
public Event(String eventID, String eventStrID, String eventName, String eventDescription, String eventImageURL, Timestamp eventStartTime, Timestamp eventEndTime, boolean allDayEvent, List<Venue> eventVenues, List<Body> eventBodies, int eventInterestedCount, int eventGoingCount, List<User> eventInterested, List<User> eventGoing, String eventWebsiteURL) {
@ColumnInfo(name = "user_ues")
@SerializedName("user_ues")
int eventUserUes;
public Event(String eventID, String eventStrID, String eventName, String eventDescription, String eventImageURL, Timestamp eventStartTime, Timestamp eventEndTime, boolean allDayEvent, List<Venue> eventVenues, List<Body> eventBodies, int eventInterestedCount, int eventGoingCount, List<User> eventInterested, List<User> eventGoing, String eventWebsiteURL, int eventUserUes) {
this.eventID = eventID;
this.eventStrID = eventStrID;
this.eventName = eventName;
......@@ -77,6 +80,7 @@ public class Event {
this.eventInterested = eventInterested;
this.eventGoing = eventGoing;
this.eventWebsiteURL = eventWebsiteURL;
this.eventUserUes = eventUserUes;
}
public String getEventID() {
......@@ -198,4 +202,12 @@ public class Event {
public void setEventWebsiteURL(String eventWebsiteURL) {
this.eventWebsiteURL = eventWebsiteURL;
}
public int getEventUserUes() {
return eventUserUes;
}
public void setEventUserUes(int eventUserUes) {
this.eventUserUes = eventUserUes;
}
}
package in.ac.iitb.gymkhana.iitbapp.fragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.google.gson.Gson;
import com.squareup.picasso.Picasso;
import in.ac.iitb.gymkhana.iitbapp.R;
import in.ac.iitb.gymkhana.iitbapp.data.Body;
/**
* A simple {@link Fragment} subclass.
* Activities that contain this fragment must implement the
* to handle interaction events.
* Use the {@link BodyCardFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class BodyCardFragment extends Fragment {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_BODY = "body";
// TODO: Rename and change types of parameters
private Body body;
public BodyCardFragment() {
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param arg_body Body passed.
* @return A new instance of fragment BodyCardFragment.
*/
// TODO: Rename and change types and number of parameters
public static BodyCardFragment newInstance(Body arg_body) {
BodyCardFragment fragment = new BodyCardFragment();
Bundle args = new Bundle();
args.putString(ARG_BODY, new Gson().toJson(arg_body));
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
body = new Gson().fromJson(getArguments().getString(ARG_BODY), Body.class);
}
}
@Override
public void onStart() {
super.onStart();
LinearLayout linearLayout = (LinearLayout) getView().findViewById(R.id.body_card_layout);
ImageView bodyAvatar = (ImageView) getView().findViewById(R.id.body_card_avatar);
TextView bodyName = (TextView) getView().findViewById(R.id.body_card_name);
TextView bodyDescription = (TextView) getView().findViewById(R.id.body_card_description);
bodyName.setText(body.getBodyName());
bodyDescription.setText(body.getBodyShortDescription());
Picasso.with(getContext()).load(body.getBodyImageURL()).into(bodyAvatar);
linearLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
/* Show the next fragment and destroy the page */
BodyFragment bodyFragment = BodyFragment.newInstance(body);
bodyFragment.setArguments(getArguments());
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.replace(R.id.framelayout_for_fragment, bodyFragment, bodyFragment.getTag());
ft.addToBackStack(bodyFragment.getTag());
ft.commit();
}
});
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.body_card_view, container, false);
}
}
package in.ac.iitb.gymkhana.iitbapp.fragment;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.google.gson.Gson;
import com.squareup.picasso.Picasso;
import java.util.List;
import in.ac.iitb.gymkhana.iitbapp.Constants;
import in.ac.iitb.gymkhana.iitbapp.ItemClickListener;
import in.ac.iitb.gymkhana.iitbapp.MainActivity;
import in.ac.iitb.gymkhana.iitbapp.R;
import in.ac.iitb.gymkhana.iitbapp.ShareURLMaker;
import in.ac.iitb.gymkhana.iitbapp.adapter.FeedAdapter;
import in.ac.iitb.gymkhana.iitbapp.api.RetrofitInterface;
import in.ac.iitb.gymkhana.iitbapp.api.ServiceGenerator;
import in.ac.iitb.gymkhana.iitbapp.data.AppDatabase;
import in.ac.iitb.gymkhana.iitbapp.data.Body;
import in.ac.iitb.gymkhana.iitbapp.data.Event;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import ru.noties.markwon.Markwon;
/**
* A simple {@link Fragment} subclass.
......@@ -113,12 +131,99 @@ public class BodyFragment extends Fragment {
});
}
private void displayBody(Body body) {
private void displayBody(final Body body) {
TextView bodyName = (TextView) getView().findViewById(R.id.body_name);
TextView bodyDescription = (TextView) getView().findViewById(R.id.body_description);
ImageView eventPicture = (ImageView) getActivity().findViewById(R.id.body_picture);
ImageButton webBodyButton = getActivity().findViewById(R.id.web_body_button);
ImageButton shareBodyButton = getActivity().findViewById(R.id.share_body_button);
final Button followButton = getActivity().findViewById(R.id.follow_button);
/* Set body information */
bodyName.setText(body.getBodyName());
bodyDescription.setText(body.getBodyDescription());
Markwon.setMarkdown(bodyDescription, body.getBodyDescription());
Picasso.with(getContext()).load(body.getBodyImageURL()).into(eventPicture);
/* Check if user is already following
* Initialize follow button */
followButton.setBackgroundColor(getResources().getColor(body.getBodyUserFollows() ? R.color.colorAccent : R.color.colorWhite));
followButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class);
retrofitInterface.updateBodyFollowing(((MainActivity) getActivity()).getSessionIDHeader(), body.getBodyID(), body.getBodyUserFollows() ? 0:1).enqueue(new Callback<Void>() {
@Override
public void onResponse(Call<Void> call, Response<Void> response) {
if (response.isSuccessful()) {
body.setBodyUserFollows(!body.getBodyUserFollows());
new updateDbBody().execute(body);
followButton.setBackgroundColor(getResources().getColor(body.getBodyUserFollows() ? R.color.colorAccent : R.color.colorWhite));
}
}
@Override
public void onFailure(Call<Void> call, Throwable t) {
Toast.makeText(getContext(), "Network Error", Toast.LENGTH_LONG).show();
}
});
}
});
/* Initialize web button */
if (body.getBodyWebsiteURL() != null && !body.getBodyWebsiteURL().isEmpty())
{
webBodyButton.setVisibility(View.VISIBLE);
webBodyButton.setOnClickListener(new View.OnClickListener() {
String bodywebURL = body.getBodyWebsiteURL();
@Override
public void onClick(View view) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(bodywebURL));
startActivity(browserIntent);
}
});
}
/* Initialize share button */
shareBodyButton.setOnClickListener(new View.OnClickListener() {
String shareUrl = ShareURLMaker.getBodyURL(body);
@Override
public void onClick(View view) {
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_SUBJECT, "Sharing URL");
i.putExtra(Intent.EXTRA_TEXT, shareUrl);
startActivity(Intent.createChooser(i, "Share URL"));
}
});
/* Initialize events */
final List<Event> eventList = body.getBodyEvents();
RecyclerView eventRecyclerView = (RecyclerView) getActivity().findViewById(R.id.event_card_recycler_view);
FeedAdapter eventAdapter = new FeedAdapter(eventList, new ItemClickListener() {
@Override
public void onItemClick(View v, int position) {
Event event = eventList.get(position);
Bundle bundle = new Bundle();
bundle.putString(Constants.EVENT_JSON, new Gson().toJson(event));
EventFragment eventFragment = new EventFragment();
eventFragment.setArguments(bundle);
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.replace(R.id.framelayout_for_fragment, eventFragment, eventFragment.getTag());
ft.addToBackStack(eventFragment.getTag());
ft.commit();
}
});
eventRecyclerView.setAdapter(eventAdapter);
eventRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
}
private class updateDbBody extends AsyncTask<Body, Void, Integer> {
@Override
protected Integer doInBackground(Body... body) {
appDatabase.dbDao().updateBody(body[0]);
return 1;
}
}
@Override
......
......@@ -5,14 +5,38 @@ 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.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CalendarView;
import android.widget.Toast;
import com.google.gson.Gson;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
import in.ac.iitb.gymkhana.iitbapp.Constants;
import in.ac.iitb.gymkhana.iitbapp.ItemClickListener;
import in.ac.iitb.gymkhana.iitbapp.MainActivity;
import in.ac.iitb.gymkhana.iitbapp.R;
import in.ac.iitb.gymkhana.iitbapp.adapter.FeedAdapter;
import in.ac.iitb.gymkhana.iitbapp.api.RetrofitInterface;
import in.ac.iitb.gymkhana.iitbapp.api.ServiceGenerator;
import in.ac.iitb.gymkhana.iitbapp.api.model.NewsFeedResponse;
import in.ac.iitb.gymkhana.iitbapp.data.Event;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
* A simple {@link Fragment} subclass.
......@@ -22,6 +46,7 @@ public class CalendarFragment extends BaseFragment {
FloatingActionButton fab;
private View view;
private Toast toast;
private List<Event> events;
public CalendarFragment() {
// Required empty public constructor
......@@ -39,18 +64,17 @@ public class CalendarFragment extends BaseFragment {
simpleCalendarView.setFirstDayOfWeek(1); // set Sunday as the first day of the week
simpleCalendarView.setWeekNumberColor(getResources().getColor(R.color.colorCalendarWeek));//setWeekNumberColor
simpleCalendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth) {
if (toast != null) {
toast.cancel();
String sdate = dayOfMonth + "/" + (month + 1) + "/" + year;
try {
Date showDate = new SimpleDateFormat("dd/M/yyyy").parse(sdate);
showEventsForDate(showDate);
} catch (ParseException e) {
e.printStackTrace();
}
toast = Toast.makeText(getContext(), "Date: (" + dayOfMonth + "/" + (month + 1) + "/" + year + ")", Toast.LENGTH_LONG);
toast.show();
}
});
fab.setOnClickListener(new View.OnClickListener() {
......@@ -62,8 +86,81 @@ public class CalendarFragment extends BaseFragment {
((MainActivity) getActivity()).updateFragment(addEventFragment);
}
});
updateEvents();
return view;
}
private void updateEvents() {
String ISO_FORMAT = "yyyy-MM-dd HH:mm:ss";
final TimeZone utc = TimeZone.getTimeZone("UTC");
final SimpleDateFormat isoFormatter = new SimpleDateFormat(ISO_FORMAT);
isoFormatter.setTimeZone(utc);
final Date today = new Date();
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MONTH, -1);
final Date oneMonthBackDate = cal.getTime();
cal.add(Calendar.MONTH, 2);
final Date oneMonthOnDate = cal.getTime();
final String oneMonthBack = isoFormatter.format(oneMonthBackDate).toString();
final String oneMonthOn = isoFormatter.format(oneMonthOnDate).toString();
RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class);
retrofitInterface.getEventsBetweenDates(((MainActivity)getActivity()).getSessionIDHeader(), oneMonthBack, oneMonthOn).enqueue(new Callback<NewsFeedResponse>() {
@Override
public void onResponse(Call<NewsFeedResponse> call, Response<NewsFeedResponse> response) {
if (response.isSuccessful()) {
NewsFeedResponse newsFeedResponse = response.body();
events = newsFeedResponse.getEvents();
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
try {
Date todayWithZeroTime = formatter.parse(formatter.format(today));
showEventsForDate(todayWithZeroTime);
} catch (ParseException e) {
e.printStackTrace();
}
}
}
@Override
public void onFailure(Call<NewsFeedResponse> call, Throwable t) {
//Network Error
Toast.makeText(getContext(), "Failed to fetch events!", Toast.LENGTH_SHORT).show();
}
});
}
private void showEventsForDate(Date date) {
final List<Event> filteredEvents = new ArrayList<Event>();
for( Event event : events) {
Date nextDay = new Date(date.getTime() + (1000 * 60 * 60 * 24));
Timestamp start = event.getEventStartTime();
if (start.after(date) && start.before(nextDay)) {
filteredEvents.add(event);
}
}
RecyclerView eventRecyclerView = (RecyclerView) getActivity().findViewById(R.id.calendar_event_card_recycler_view);
FeedAdapter eventAdapter = new FeedAdapter(filteredEvents, new ItemClickListener() {
@Override
public void onItemClick(View v, int position) {
Event event = filteredEvents.get(position);
Bundle bundle = new Bundle();
bundle.putString(Constants.EVENT_JSON, new Gson().toJson(event));
EventFragment eventFragment = new EventFragment();
eventFragment.setArguments(bundle);
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.replace(R.id.framelayout_for_fragment, eventFragment, eventFragment.getTag());
ft.addToBackStack(eventFragment.getTag());
ft.commit();
}
});
eventRecyclerView.setAdapter(eventAdapter);
eventRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
}
}
......@@ -3,6 +3,7 @@ package in.ac.iitb.gymkhana.iitbapp.fragment;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
......@@ -28,13 +29,15 @@ import java.util.List;
import in.ac.iitb.gymkhana.iitbapp.Constants;
import in.ac.iitb.gymkhana.iitbapp.ItemClickListener;
import in.ac.iitb.gymkhana.iitbapp.MainActivity;
import in.ac.iitb.gymkhana.iitbapp.R;
import in.ac.iitb.gymkhana.iitbapp.ShareURLMaker;
import in.ac.iitb.gymkhana.iitbapp.adapter.BodyAdapter;
import in.ac.iitb.gymkhana.iitbapp.api.RetrofitInterface;
import in.ac.iitb.gymkhana.iitbapp.api.ServiceGenerator;
import in.ac.iitb.gymkhana.iitbapp.data.Event;
import in.ac.iitb.gymkhana.iitbapp.data.AppDatabase;
import in.ac.iitb.gymkhana.iitbapp.data.Body;
import in.ac.iitb.gymkhana.iitbapp.data.Event;
import in.ac.iitb.gymkhana.iitbapp.data.Venue;
import retrofit2.Call;
import retrofit2.Callback;
......@@ -44,7 +47,7 @@ import ru.noties.markwon.Markwon;
/**
* A simple {@link Fragment} subclass.
*/
public class EventFragment extends BaseFragment implements View.OnClickListener {
public class EventFragment extends BaseFragment {
Event event;
Button goingButton;
Button interestedButton;
......@@ -52,6 +55,7 @@ public class EventFragment extends BaseFragment implements View.OnClickListener
ImageButton shareEventButton;
ImageButton webEventButton;
RecyclerView bodyRecyclerView;
private AppDatabase appDatabase;
String TAG = "EventFragment";
public EventFragment() {
......@@ -70,6 +74,9 @@ public class EventFragment extends BaseFragment implements View.OnClickListener
public void onStart() {
super.onStart();
/* Initialize */
appDatabase = AppDatabase.getAppDatabase(getContext());
Bundle bundle = getArguments();
String eventJson = bundle.getString(Constants.EVENT_JSON);
Log.d(TAG, "onStart: " + eventJson);
......@@ -86,7 +93,6 @@ public class EventFragment extends BaseFragment implements View.OnClickListener
TextView eventDescription = (TextView) getActivity().findViewById(R.id.event_page_description);
goingButton = getActivity().findViewById(R.id.going_button);
interestedButton = getActivity().findViewById(R.id.interested_button);
notGoingButton = getActivity().findViewById(R.id.not_going_button);
shareEventButton = getActivity().findViewById(R.id.share_event_button);
webEventButton = getActivity().findViewById(R.id.web_event_button);
......@@ -105,25 +111,13 @@ public class EventFragment extends BaseFragment implements View.OnClickListener
eventVenueName.append(", ").append(venue.getVenueShortName());
}
/* if(((LinearLayout) getActivity().findViewById(R.id.body_container)).getChildCount() == 0) {
for (Body body : event.getEventBodies()) {
Fragment bodyCardFragment = BodyCardFragment.newInstance(body);
getChildFragmentManager().beginTransaction()
.add(R.id.body_container, bodyCardFragment, getTag())
.disallowAddToBackStack()
.commit();
}
}*/
final List<Body> bodyList = event.getEventBodies();
bodyRecyclerView= (RecyclerView) getActivity().findViewById(R.id.body_card_recycler_view);
bodyRecyclerView = (RecyclerView) getActivity().findViewById(R.id.body_card_recycler_view);
BodyAdapter bodyAdapter = new BodyAdapter(bodyList, new ItemClickListener() {
@Override
public void onItemClick(View v, int position) {
Body body = bodyList.get(position);
BodyFragment bodyFragment = BodyFragment.newInstance(body);
Bundle arguments=getArguments();
arguments.putString(Constants.BODY_JSON,new Gson().toJson(body));
bodyFragment.setArguments(getArguments());
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.replace(R.id.framelayout_for_fragment, bodyFragment, bodyFragment.getTag());
ft.addToBackStack(bodyFragment.getTag());
......@@ -136,9 +130,14 @@ public class EventFragment extends BaseFragment implements View.OnClickListener
if (!eventVenueName.toString().equals(""))
eventVenue.setText(eventVenueName.toString().substring(2));
goingButton.setOnClickListener(this);
interestedButton.setOnClickListener(this);
notGoingButton.setOnClickListener(this);
interestedButton.setOnClickListener(getUESOnClickListener(1));
goingButton.setOnClickListener(getUESOnClickListener(2));
interestedButton.setBackgroundColor(getResources().getColor(event.getEventUserUes() == Constants.STATUS_INTERESTED ? R.color.colorAccent : R.color.colorWhite));
goingButton.setBackgroundColor(getResources().getColor(event.getEventUserUes() == Constants.STATUS_GOING ? R.color.colorAccent : R.color.colorWhite));
shareEventButton.setOnClickListener(new View.OnClickListener() {
String shareUrl = ShareURLMaker.getEventURL(event);
@Override
......@@ -150,52 +149,52 @@ public class EventFragment extends BaseFragment implements View.OnClickListener
startActivity(Intent.createChooser(i, "Share URL"));
}
});
if (event.getEventWebsiteURL() != null)
if (event.getEventWebsiteURL() != null && !event.getEventWebsiteURL().isEmpty())
{
webEventButton.setVisibility(View.VISIBLE);
webEventButton.setVisibility(View.VISIBLE);
webEventButton.setOnClickListener(new View.OnClickListener() {
String eventwebURL = event.getEventWebsiteURL();
@Override
public void onClick(View view) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(eventwebURL));
startActivity(browserIntent);
}
});
}
webEventButton.setOnClickListener(new View.OnClickListener() {
String eventwebURL = event.getEventWebsiteURL();
}
View.OnClickListener getUESOnClickListener(final int status) {
return new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(eventwebURL));
startActivity(browserIntent);
final int endStatus = event.getEventUserUes() == status ? 0 : status;
RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class);
retrofitInterface.updateUserEventStatus(((MainActivity) getActivity()).getSessionIDHeader(), event.getEventID(), endStatus).enqueue(new Callback<Void>() {
@Override
public void onResponse(Call<Void> call, Response<Void> response) {
if (response.isSuccessful()) {
event.setEventUserUes(endStatus);
new updateDbEvent().execute(event);
interestedButton.setBackgroundColor(getResources().getColor(endStatus == Constants.STATUS_INTERESTED ? R.color.colorAccent : R.color.colorWhite));
goingButton.setBackgroundColor(getResources().getColor(endStatus == Constants.STATUS_GOING ? R.color.colorAccent : R.color.colorWhite));
}
}
@Override
public void onFailure(Call<Void> call, Throwable t) {
Toast.makeText(getContext(), "Network Error", Toast.LENGTH_LONG).show();
}
});
}
});
};
}
@Override
public void onClick(View view) {
goingButton.setBackgroundColor(getResources().getColor(R.color.colorWhite));
interestedButton.setBackgroundColor(getResources().getColor(R.color.colorWhite));
notGoingButton.setBackgroundColor(getResources().getColor(R.color.colorWhite));
view.setBackgroundColor(getResources().getColor(R.color.colorAccent));
int status = 0;
switch (view.getId()) {
case R.id.going_button:
status = Constants.STATUS_GOING;
break;
case R.id.interested_button:
status = Constants.STATUS_INTERESTED;
break;
case R.id.not_going_button:
status = Constants.STATUS_NOT_GOING;
break;
private class updateDbEvent extends AsyncTask<Event, Void, Integer> {
@Override
protected Integer doInBackground(Event... event) {
appDatabase.dbDao().updateEvent(event[0]);
return 1;
}
RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class);
retrofitInterface.updateUserEventStatus("sessionid=" + getArguments().getString(Constants.SESSION_ID), event.getEventID(), status).enqueue(new Callback<Void>() {
@Override
public void onResponse(Call<Void> call, Response<Void> response) {
if (response.isSuccessful()) {
//TODO: Set flag for details updated so as to not try again when connected
}
}
@Override
public void onFailure(Call<Void> call, Throwable t) {
//TODO: Store the status offline and update when connected
Toast.makeText(getContext(), "Network Error", Toast.LENGTH_LONG).show();
}
});
}
}
......@@ -2,8 +2,8 @@
android:shape="rectangle">
<gradient
android:angle="135"
android:centerColor="#009688"
android:endColor="#00695C"
android:startColor="#4DB6AC"
android:centerColor="#536dfe"
android:endColor="#536dfe"
android:startColor="#536dfe"
android:type="linear" />
</shape>
\ No newline at end of file
......@@ -30,14 +30,15 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EEEEEE"
android:src="@drawable/ic_input_add" />
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="#81d2cb"
android:background="@color/colorPrimary"
android:hint="Event Name"
android:padding="16dp"
android:paddingBottom="16dp"
......
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".fragment.BodyFragment">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/body_swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ScrollView
android:layout_height="wrap_content">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/body_name"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<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_height="wrap_content"
app:cardBackgroundColor="@color/colorPrimary">
<TextView
android:id="@+id/body_description"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginBottom="12dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="12dp"
android:layout_weight="3"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/body_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="10"
android:text="Org Title"
android:textColor="#fff"
android:textSize="21sp"
android:textStyle="bold"/>
<ImageButton
android:id="@+id/web_body_button"
android:layout_width="10dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
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>
</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:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:layout_weight="1"
android:text="Follow"
android:textColor="@color/colorGray" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="#aaa">
</View>
<TextView
android:id="@+id/body_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="12dp"
android:layout_marginBottom="16dp"
android:textColor="#777"
android:textSize="16sp" />
<android.support.v7.widget.RecyclerView
android:id="@+id/event_card_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:nestedScrollingEnabled="false" />
</LinearLayout>
</ScrollView>
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
\ No newline at end of file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/calendar_layout"
android:layout_width="match_parent"
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E0E0E0"
android:theme="@style/CalendarTheme">
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v4.widget.NestedScrollView android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- TODO: Update blank fragment layout -->
<View
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#00BCD4" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/calendar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fafafa"
android:theme="@style/CalendarTheme"
android:orientation="vertical">
<CalendarView
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
android:id="@+id/simpleCalendarView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusedMonthDateColor="#000000"
android:unfocusedMonthDateColor="#FFFFFF" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@id/simpleCalendarView"
android:layout_marginBottom="19.5dp"
android:layout_marginTop="19.5dp"
android:background="@android:color/darker_gray" />
<TextView
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_below="@id/simpleCalendarView"
android:layout_centerHorizontal="true"
android:background="@drawable/round_text_box"
android:gravity="center"
android:text="# Events Today" />
<!-- TODO: Update blank fragment layout -->
<View
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@color/colorPrimary" />
<CalendarView
android:id="@+id/simpleCalendarView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusedMonthDateColor="#000000"
android:unfocusedMonthDateColor="#FFFFFF" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@id/simpleCalendarView"
android:layout_marginBottom="19.5dp"
android:layout_marginTop="19.5dp"
android:background="@android:color/darker_gray" />
<TextView
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_below="@id/simpleCalendarView"
android:layout_centerHorizontal="true"
android:background="@drawable/round_text_box"
android:gravity="center"
android:text="# Events Today"
android:textColor="@color/primaryTextColor"/>
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/calendar_event_card_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:nestedScrollingEnabled="false" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
......@@ -44,7 +69,7 @@
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="16dp"
android:src="@android:drawable/ic_input_add" />
android:src="@android:drawable/ic_input_add"
android:tint="@android:color/white" />
</RelativeLayout>
</RelativeLayout>
\ No newline at end of file
......@@ -163,24 +163,6 @@
android:text="Interested"
android:textColor="@color/colorGray" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginBottom="6dp"
android:layout_marginTop="10dp"
android:background="#aaa">
</View>
<Button
android:id="@+id/not_going_button"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:layout_weight="1"
android:text="Not Going"
android:textColor="@color/colorGray" />
</LinearLayout>
<View
......
......@@ -25,5 +25,6 @@
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="16dp"
android:src="@android:drawable/ic_input_add" />
android:src="@android:drawable/ic_input_add"
android:tint="@android:color/white" />
</RelativeLayout>
\ No newline at end of file
......@@ -10,5 +10,6 @@
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="16dp"
android:src="@android:drawable/ic_input_add" />
android:src="@android:drawable/ic_input_add"
android:tint="@android:color/white" />
</RelativeLayout>
......@@ -29,7 +29,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Breakfast"
android:textColor="@color/colorAccent"
android:textColor="@color/colorPrimaryDark"
android:textSize="16sp" />
<TextView
......@@ -43,7 +43,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Lunch"
android:textColor="@color/colorAccent"
android:textColor="@color/colorPrimaryDark"
android:textSize="16sp" />
<TextView
......@@ -57,7 +57,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Tiffin"
android:textColor="@color/colorAccent"
android:textColor="@color/colorPrimaryDark"
android:textSize="16sp" />
<TextView
......@@ -71,7 +71,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Dinner"
android:textColor="@color/colorAccent"
android:textColor="@color/colorPrimaryDark"
android:textSize="16sp" />
<TextView
......
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#81D2CB</color>
<color name="colorPrimaryDark">#44C0CA</color>
<color name="colorAccent">#ECF833</color>
<color name="colorPrimary">#536dfe</color>
<color name="primaryLightColor">#8f9bff</color>
<color name="colorPrimaryDark">#0043ca</color>
<color name="colorAccent">#0043ca</color>
<color name="colorSecondary">#ffd740</color>
<color name="secondaryLightColor">#ffff74</color>
<color name="secondaryDarkColor">#c8a600</color>
<color name="primaryTextColor">#fafafa</color>
<color name="secondaryTextColor">#000000</color>
<color name="colorCalendarWeek">#000000</color>
<color name="colorGray">#757575</color>
<color name="colorWhite">#FFFFFF</color>
......
<resources>
<string name="app_name">IITB App</string>
<string name="app_name">InstiApp</string>
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
......
......@@ -21,7 +21,7 @@
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">#ecf833</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:colorBackground">@android:color/darker_gray</item>
<item name="android:textColorPrimaryInverse">@android:color/darker_gray</item>
<item name="android:windowBackground">@android:color/darker_gray</item>
......
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