Commit 664e9a37 authored by Sajal Narang's avatar Sajal Narang Committed by GitHub

Merge pull request #152 from pulsejet/patch1

Show counts in buttons, other fixes
parents 8f48523b 92af05f3
......@@ -274,7 +274,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
}
bundle.putString(Constants.SESSION_ID, session.pref.getString(Constants.SESSION_ID, "Error"));
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())
bundle.putString(Constants.USER_ID, currentUser.getUserID());
fragment.setArguments(bundle);
......
......@@ -68,6 +68,11 @@ public class FeedAdapter extends RecyclerView.Adapter<FeedAdapter.ViewHolder> {
if (!eventVenueName.toString().equals(""))
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);
}
......
......@@ -173,6 +173,7 @@ public class BodyFragment extends Fragment {
/* Check if user is already following
* Initialize follow button */
followButton.setBackgroundColor(getResources().getColor(body.getBodyUserFollows() ? R.color.colorAccent : R.color.colorWhite));
followButton.setText(EventFragment.getCountBadgeSpannable("Follow", body.getBodyFollowersCount()));
followButton.setOnClickListener(new View.OnClickListener() {
@Override
......
......@@ -2,6 +2,8 @@ package app.insti.fragment;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
......@@ -10,6 +12,11 @@ import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
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.view.LayoutInflater;
import android.view.View;
......@@ -101,6 +108,11 @@ public class EventFragment extends BaseFragment {
webEventButton = getActivity().findViewById(R.id.web_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);
eventTitle.setText(event.getEventName());
Markwon.setMarkdown(eventDescription, event.getEventDescription());
......@@ -141,8 +153,7 @@ public class EventFragment extends BaseFragment {
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));
setFollowButtonColors(event.getEventUserUes());
navigateButton.setOnClickListener(new View.OnClickListener() {
@Override
......@@ -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) {
return new View.OnClickListener() {
@Override
......@@ -193,8 +234,7 @@ public class EventFragment extends BaseFragment {
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));
setFollowButtonColors(endStatus);
}
}
......
......@@ -87,10 +87,13 @@ public class SettingsFragment extends Fragment {
}
private void populateViews() {
Button updateProfileButton = getActivity().findViewById(R.id.settings_update_profile);
Button feedbackButton = getActivity().findViewById(R.id.settings_feedback);
Button aboutButton = getActivity().findViewById(R.id.settings_about);
Button logoutButton = getActivity().findViewById(R.id.settings_logout);
// Check if we exist
if (getActivity() == null || getView() == null) return;
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() {
@Override
......@@ -118,30 +121,36 @@ public class SettingsFragment extends Fragment {
}
});
logoutButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class);
retrofitInterface.logout("sessionid=" + getArguments().getString(Constants.SESSION_ID)).enqueue(new Callback<Void>() {
@Override
public void onResponse(Call<Void> call, Response<Void> response) {
if (response.isSuccessful()) {
SessionManager sessionManager = new SessionManager(getContext());
sessionManager.logout();
Intent intent = new Intent(getContext(), LoginActivity.class);
startActivity(intent);
getActivity().finish();
// Logged in user vs Guest
final SessionManager sessionManager = new SessionManager(getContext());
if (sessionManager.isLoggedIn()) {
logoutButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class);
retrofitInterface.logout("sessionid=" + getArguments().getString(Constants.SESSION_ID)).enqueue(new Callback<Void>() {
@Override
public void onResponse(Call<Void> call, Response<Void> response) {
if (response.isSuccessful()) {
sessionManager.logout();
Intent intent = new Intent(getContext(), LoginActivity.class);
startActivity(intent);
getActivity().finish();
}
//Server Error
}
//Server Error
}
@Override
public void onFailure(Call<Void> call, Throwable t) {
//Network Error
}
});
}
});
@Override
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) {
......
......@@ -103,7 +103,7 @@
android:layout_margin="0dp"
android:layout_weight="1"
android:text="Follow"
android:textColor="@color/colorGray" />
android:textColor="@color/secondaryTextColor" />
</LinearLayout>
<View
......
......@@ -152,7 +152,7 @@
android:layout_margin="0dp"
android:layout_weight="1"
android:text="Going"
android:textColor="@color/colorGray" />
android:textColor="@color/secondaryTextColor" />
<View
android:layout_width="1dp"
......@@ -171,7 +171,7 @@
android:layout_margin="0dp"
android:layout_weight="1"
android:text="Interested"
android:textColor="@color/colorGray" />
android:textColor="@color/secondaryTextColor" />
</LinearLayout>
......
......@@ -12,13 +12,15 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
android:orientation="vertical"
android:layout_marginLeft="12dp">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" CMS"
android:textSize="25sp" />
android:text=" CMS"
android:textSize="25sp"
android:fontFamily="sans-serif-light" />
<TextView
android:id="@+id/button_CMS"
......@@ -44,8 +46,10 @@
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" Academics"
android:textSize="25sp" />
android:text=" Academics"
android:textSize="25sp"
android:layout_marginTop="14dp"
android:fontFamily="sans-serif-light" />
<TextView
android:id="@+id/button_ASC"
......@@ -92,8 +96,10 @@
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" Calendar"
android:textSize="25sp" />
android:text=" Calendar"
android:textSize="25sp"
android:layout_marginTop="14dp"
android:fontFamily="sans-serif-light" />
<TextView
android:id="@+id/button_Acad_calendar"
......@@ -133,8 +139,10 @@
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" Services"
android:textSize="25sp" />
android:text=" Services"
android:textSize="25sp"
android:layout_marginTop="14dp"
android:fontFamily="sans-serif-light" />
<TextView
android:id="@+id/button_GPO"
......@@ -167,8 +175,10 @@
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" Miscellaneous"
android:textSize="25sp" />
android:text=" Miscellaneous"
android:textSize="25sp"
android:layout_marginTop="14dp"
android:fontFamily="sans-serif-light" />
<TextView
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