Commit 41006f57 authored by Sajal Narang's avatar Sajal Narang Committed by GitHub

Merge branch 'master' into explore

parents 523354cf 664e9a37
...@@ -68,7 +68,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -68,7 +68,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
} }
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
session = new SessionManager(getApplicationContext()); session = new SessionManager(getApplicationContext());
session.checkLogin();
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
...@@ -284,7 +283,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -284,7 +283,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
} }
bundle.putString(Constants.SESSION_ID, session.pref.getString(Constants.SESSION_ID, "Error")); bundle.putString(Constants.SESSION_ID, session.pref.getString(Constants.SESSION_ID, "Error"));
if (fragment instanceof MessMenuFragment) if (fragment instanceof MessMenuFragment)
bundle.putString(Constants.USER_HOSTEL, session.isLoggedIn() ? currentUser.getHostel() : "1"); bundle.putString(Constants.USER_HOSTEL, session.isLoggedIn() && currentUser.getHostel() != null ? currentUser.getHostel() : "1");
if (fragment instanceof SettingsFragment && session.isLoggedIn()) if (fragment instanceof SettingsFragment && session.isLoggedIn())
bundle.putString(Constants.USER_ID, currentUser.getUserID()); bundle.putString(Constants.USER_ID, currentUser.getUserID());
fragment.setArguments(bundle); fragment.setArguments(bundle);
......
...@@ -68,6 +68,11 @@ public class FeedAdapter extends RecyclerView.Adapter<FeedAdapter.ViewHolder> { ...@@ -68,6 +68,11 @@ public class FeedAdapter extends RecyclerView.Adapter<FeedAdapter.ViewHolder> {
if (!eventVenueName.toString().equals("")) if (!eventVenueName.toString().equals(""))
viewHolder.eventVenue.setText(eventVenueName.toString().substring(2)); viewHolder.eventVenue.setText(eventVenueName.toString().substring(2));
// Fallback to image of first body if event has no image
if (currentEvent.getEventImageURL() == null) {
currentEvent.setEventImageURL(currentEvent.getEventBodies().get(0).getBodyImageURL());
}
Picasso.get().load(currentEvent.getEventImageURL()).into(viewHolder.eventPicture); Picasso.get().load(currentEvent.getEventImageURL()).into(viewHolder.eventPicture);
} }
......
...@@ -173,6 +173,7 @@ public class BodyFragment extends Fragment { ...@@ -173,6 +173,7 @@ public class BodyFragment extends Fragment {
/* Check if user is already following /* Check if user is already following
* Initialize follow button */ * Initialize follow button */
followButton.setBackgroundColor(getResources().getColor(body.getBodyUserFollows() ? R.color.colorAccent : R.color.colorWhite)); followButton.setBackgroundColor(getResources().getColor(body.getBodyUserFollows() ? R.color.colorAccent : R.color.colorWhite));
followButton.setText(EventFragment.getCountBadgeSpannable("Follow", body.getBodyFollowersCount()));
followButton.setOnClickListener(new View.OnClickListener() { followButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
......
...@@ -2,6 +2,8 @@ package app.insti.fragment; ...@@ -2,6 +2,8 @@ package app.insti.fragment;
import android.content.Intent; import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
...@@ -10,6 +12,11 @@ import android.support.v4.app.FragmentTransaction; ...@@ -10,6 +12,11 @@ import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
...@@ -101,6 +108,11 @@ public class EventFragment extends BaseFragment { ...@@ -101,6 +108,11 @@ public class EventFragment extends BaseFragment {
webEventButton = getActivity().findViewById(R.id.web_event_button); webEventButton = getActivity().findViewById(R.id.web_event_button);
shareEventButton = getActivity().findViewById(R.id.share_event_button); shareEventButton = getActivity().findViewById(R.id.share_event_button);
// Fallback to image of first body if event has no image
if (event.getEventImageURL() == null) {
event.setEventImageURL(event.getEventBodies().get(0).getBodyImageURL());
}
Picasso.get().load(event.getEventImageURL()).into(eventPicture); Picasso.get().load(event.getEventImageURL()).into(eventPicture);
eventTitle.setText(event.getEventName()); eventTitle.setText(event.getEventName());
Markwon.setMarkdown(eventDescription, event.getEventDescription()); Markwon.setMarkdown(eventDescription, event.getEventDescription());
...@@ -141,8 +153,7 @@ public class EventFragment extends BaseFragment { ...@@ -141,8 +153,7 @@ public class EventFragment extends BaseFragment {
goingButton.setOnClickListener(getUESOnClickListener(2)); goingButton.setOnClickListener(getUESOnClickListener(2));
interestedButton.setBackgroundColor(getResources().getColor(event.getEventUserUes() == Constants.STATUS_INTERESTED ? R.color.colorAccent : R.color.colorWhite)); setFollowButtonColors(event.getEventUserUes());
goingButton.setBackgroundColor(getResources().getColor(event.getEventUserUes() == Constants.STATUS_GOING ? R.color.colorAccent : R.color.colorWhite));
navigateButton.setOnClickListener(new View.OnClickListener() { navigateButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
...@@ -181,6 +192,36 @@ public class EventFragment extends BaseFragment { ...@@ -181,6 +192,36 @@ public class EventFragment extends BaseFragment {
} }
} }
void setFollowButtonColors(int status) {
interestedButton.setBackgroundColor(getResources().getColor(status == Constants.STATUS_INTERESTED ? R.color.colorAccent : R.color.colorWhite));
goingButton.setBackgroundColor(getResources().getColor(status == Constants.STATUS_GOING ? R.color.colorAccent : R.color.colorWhite));
// Show badges
interestedButton.setText(getCountBadgeSpannable("Interested", event.getEventInterestedCount()));
goingButton.setText(getCountBadgeSpannable("Going", event.getEventGoingCount()));
}
/**
* Get a spannable with a small count badge to set for an element text
* @param text Text to show in the spannable
* @param count integer count to show in the badge
* @return spannable to be used as view.setText(spannable)
*/
static Spannable getCountBadgeSpannable(String text, Integer count) {
// Check for nulls
if (count == null) return new SpannableString(text);
// Make a spannable
String countString = Integer.toString(count);
Spannable spannable = new SpannableString(text + " " + countString);
// Set font face and color of badge
spannable.setSpan(new RelativeSizeSpan(0.75f), text.length(), text.length() + 1 + countString.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
spannable.setSpan(new ForegroundColorSpan(Color.DKGRAY), text.length(), text.length() + 1 + countString.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
return spannable;
}
View.OnClickListener getUESOnClickListener(final int status) { View.OnClickListener getUESOnClickListener(final int status) {
return new View.OnClickListener() { return new View.OnClickListener() {
@Override @Override
...@@ -193,8 +234,7 @@ public class EventFragment extends BaseFragment { ...@@ -193,8 +234,7 @@ public class EventFragment extends BaseFragment {
if (response.isSuccessful()) { if (response.isSuccessful()) {
event.setEventUserUes(endStatus); event.setEventUserUes(endStatus);
new updateDbEvent().execute(event); new updateDbEvent().execute(event);
interestedButton.setBackgroundColor(getResources().getColor(endStatus == Constants.STATUS_INTERESTED ? R.color.colorAccent : R.color.colorWhite)); setFollowButtonColors(endStatus);
goingButton.setBackgroundColor(getResources().getColor(endStatus == Constants.STATUS_GOING ? R.color.colorAccent : R.color.colorWhite));
} }
} }
......
...@@ -34,7 +34,7 @@ public class QLinksFragment extends BaseFragment { ...@@ -34,7 +34,7 @@ public class QLinksFragment extends BaseFragment {
TextView Intern = getActivity().findViewById(R.id.button_Internship); TextView Intern = getActivity().findViewById(R.id.button_Internship);
TextView Placement = getActivity().findViewById(R.id.button_Placement); TextView Placement = getActivity().findViewById(R.id.button_Placement);
TextView Library = getActivity().findViewById(R.id.button_Library); TextView Library = getActivity().findViewById(R.id.button_Library);
TextView AcadCal = getActivity().findViewById(R.id.button_Acad_calender); TextView AcadCal = getActivity().findViewById(R.id.button_Acad_calendar);
TextView AcadTime = getActivity().findViewById(R.id.button_Acad_timetable); TextView AcadTime = getActivity().findViewById(R.id.button_Acad_timetable);
TextView Holidays = getActivity().findViewById(R.id.button_Holidays); TextView Holidays = getActivity().findViewById(R.id.button_Holidays);
TextView Circulars = getActivity().findViewById(R.id.button_Circulars); TextView Circulars = getActivity().findViewById(R.id.button_Circulars);
......
...@@ -87,10 +87,13 @@ public class SettingsFragment extends Fragment { ...@@ -87,10 +87,13 @@ public class SettingsFragment extends Fragment {
} }
private void populateViews() { private void populateViews() {
Button updateProfileButton = getActivity().findViewById(R.id.settings_update_profile); // Check if we exist
Button feedbackButton = getActivity().findViewById(R.id.settings_feedback); if (getActivity() == null || getView() == null) return;
Button aboutButton = getActivity().findViewById(R.id.settings_about);
Button logoutButton = getActivity().findViewById(R.id.settings_logout); Button updateProfileButton = getView().findViewById(R.id.settings_update_profile);
Button feedbackButton = getView().findViewById(R.id.settings_feedback);
Button aboutButton = getView().findViewById(R.id.settings_about);
Button logoutButton = getView().findViewById(R.id.settings_logout);
updateProfileButton.setOnClickListener(new View.OnClickListener() { updateProfileButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
...@@ -118,30 +121,36 @@ public class SettingsFragment extends Fragment { ...@@ -118,30 +121,36 @@ public class SettingsFragment extends Fragment {
} }
}); });
logoutButton.setOnClickListener(new View.OnClickListener() { // Logged in user vs Guest
@Override final SessionManager sessionManager = new SessionManager(getContext());
public void onClick(View v) { if (sessionManager.isLoggedIn()) {
RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class); logoutButton.setOnClickListener(new View.OnClickListener() {
retrofitInterface.logout("sessionid=" + getArguments().getString(Constants.SESSION_ID)).enqueue(new Callback<Void>() { @Override
@Override public void onClick(View v) {
public void onResponse(Call<Void> call, Response<Void> response) { RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class);
if (response.isSuccessful()) { retrofitInterface.logout("sessionid=" + getArguments().getString(Constants.SESSION_ID)).enqueue(new Callback<Void>() {
SessionManager sessionManager = new SessionManager(getContext()); @Override
sessionManager.logout(); public void onResponse(Call<Void> call, Response<Void> response) {
Intent intent = new Intent(getContext(), LoginActivity.class); if (response.isSuccessful()) {
startActivity(intent); sessionManager.logout();
getActivity().finish(); Intent intent = new Intent(getContext(), LoginActivity.class);
startActivity(intent);
getActivity().finish();
}
//Server Error
} }
//Server Error
} @Override
public void onFailure(Call<Void> call, Throwable t) {
@Override //Network Error
public void onFailure(Call<Void> call, Throwable t) { }
//Network Error });
} }
}); });
} } else {
}); logoutButton.setVisibility(View.GONE);
getView().findViewById(R.id.role_card_layout).setVisibility(View.GONE);
}
} }
private void openWebURL(String URL) { private void openWebURL(String URL) {
......
...@@ -103,7 +103,7 @@ ...@@ -103,7 +103,7 @@
android:layout_margin="0dp" android:layout_margin="0dp"
android:layout_weight="1" android:layout_weight="1"
android:text="Follow" android:text="Follow"
android:textColor="@color/colorGray" /> android:textColor="@color/secondaryTextColor" />
</LinearLayout> </LinearLayout>
<View <View
......
...@@ -152,7 +152,7 @@ ...@@ -152,7 +152,7 @@
android:layout_margin="0dp" android:layout_margin="0dp"
android:layout_weight="1" android:layout_weight="1"
android:text="Going" android:text="Going"
android:textColor="@color/colorGray" /> android:textColor="@color/secondaryTextColor" />
<View <View
android:layout_width="1dp" android:layout_width="1dp"
...@@ -171,7 +171,7 @@ ...@@ -171,7 +171,7 @@
android:layout_margin="0dp" android:layout_margin="0dp"
android:layout_weight="1" android:layout_weight="1"
android:text="Interested" android:text="Interested"
android:textColor="@color/colorGray" /> android:textColor="@color/secondaryTextColor" />
</LinearLayout> </LinearLayout>
......
...@@ -12,13 +12,15 @@ ...@@ -12,13 +12,15 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical"> android:orientation="vertical"
android:layout_marginLeft="12dp">
<TextView <TextView
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text=" CMS" android:text=" CMS"
android:textSize="25sp" /> android:textSize="25sp"
android:fontFamily="sans-serif-light" />
<TextView <TextView
android:id="@+id/button_CMS" android:id="@+id/button_CMS"
...@@ -44,8 +46,10 @@ ...@@ -44,8 +46,10 @@
<TextView <TextView
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text=" Academics" android:text=" Academics"
android:textSize="25sp" /> android:textSize="25sp"
android:layout_marginTop="14dp"
android:fontFamily="sans-serif-light" />
<TextView <TextView
android:id="@+id/button_ASC" android:id="@+id/button_ASC"
...@@ -92,14 +96,16 @@ ...@@ -92,14 +96,16 @@
<TextView <TextView
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text=" Calender" android:text=" Calendar"
android:textSize="25sp" /> android:textSize="25sp"
android:layout_marginTop="14dp"
android:fontFamily="sans-serif-light" />
<TextView <TextView
android:id="@+id/button_Acad_calender" android:id="@+id/button_Acad_calendar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Academic Calender" android:text="Academic Calendar"
android:textSize="@dimen/quick_links_size" /> android:textSize="@dimen/quick_links_size" />
<TextView <TextView
...@@ -133,8 +139,10 @@ ...@@ -133,8 +139,10 @@
<TextView <TextView
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text=" Services" android:text=" Services"
android:textSize="25sp" /> android:textSize="25sp"
android:layout_marginTop="14dp"
android:fontFamily="sans-serif-light" />
<TextView <TextView
android:id="@+id/button_GPO" android:id="@+id/button_GPO"
...@@ -167,8 +175,10 @@ ...@@ -167,8 +175,10 @@
<TextView <TextView
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text=" Miscellaneous" android:text=" Miscellaneous"
android:textSize="25sp" /> android:textSize="25sp"
android:layout_marginTop="14dp"
android:fontFamily="sans-serif-light" />
<TextView <TextView
android:id="@+id/button_Intercom" android:id="@+id/button_Intercom"
......
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