Commit 944871dd authored by Sajal Narang's avatar Sajal Narang Committed by GitHub

Merge branch 'master' into creatEventApi

parents c2671292 987407ef
......@@ -3,6 +3,7 @@
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/IITB-App.iml" filepath="$PROJECT_DIR$/IITB-App.iml" />
<module fileurl="file://$PROJECT_DIR$/IITBApp.iml" filepath="$PROJECT_DIR$/IITBApp.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
</modules>
</component>
......
......@@ -28,6 +28,7 @@ ext {
appAuthVersion = '0.2.0'
retrofitVersion = '2.1.0'
okhttpVersion = '3.4.1'
picassoVersion = '2.5.0'
}
......@@ -43,11 +44,13 @@ dependencies {
compile "com.google.android.gms:play-services-maps:${playServicesVersion}"
compile "com.android.support:support-v4:${supportLibVersion}"
compile "com.jakewharton:butterknife:${butterKnifeVersion}"
compile "com.google.android.gms:play-services-gcm:11.0.2"
compile "com.google.android.gms:play-services-gcm:${playServicesVersion}"
annotationProcessor "com.jakewharton:butterknife-compiler:${butterKnifeVersion}"
compile "com.squareup.retrofit2:retrofit:${retrofitVersion}"
compile "com.squareup.retrofit2:converter-gson:${retrofitVersion}"
compile "com.squareup.okhttp3:okhttp:${okhttpVersion}"
compile "com.squareup.okhttp3:logging-interceptor:${okhttpVersion}"
compile "com.squareup.picasso:picasso:${picassoVersion}"
implementation 'com.android.support:support-v4:25.4.0'
}
apply plugin: 'com.google.gms.google-services'
package in.ac.iitb.gymkhana.iitbapp;
public class Constants {
public static final String NOTIFICATIONS_RESPONSE_JSON = "notifications_json";
}
package in.ac.iitb.gymkhana.iitbapp;
import android.view.View;
public interface ItemClickListener {
void onItemClick(View v, int position);
}
......@@ -18,6 +18,15 @@ import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
import com.google.gson.Gson;
import java.util.List;
import in.ac.iitb.gymkhana.iitbapp.api.RetrofitInterface;
import in.ac.iitb.gymkhana.iitbapp.api.ServiceGenerator;
import in.ac.iitb.gymkhana.iitbapp.api.model.AppNotification;
import in.ac.iitb.gymkhana.iitbapp.api.model.NotificationsRequest;
import in.ac.iitb.gymkhana.iitbapp.api.model.NotificationsResponse;
import in.ac.iitb.gymkhana.iitbapp.fragment.AboutFragment;
import in.ac.iitb.gymkhana.iitbapp.fragment.CMSFragment;
import in.ac.iitb.gymkhana.iitbapp.fragment.CalendarFragment;
......@@ -27,8 +36,13 @@ import in.ac.iitb.gymkhana.iitbapp.fragment.GCRankingsFragment;
import in.ac.iitb.gymkhana.iitbapp.fragment.MapFragment;
import in.ac.iitb.gymkhana.iitbapp.fragment.MessMenuFragment;
import in.ac.iitb.gymkhana.iitbapp.fragment.MyEventsFragment;
import in.ac.iitb.gymkhana.iitbapp.fragment.NotificationsFragment;
import in.ac.iitb.gymkhana.iitbapp.fragment.PTCellFragment;
import in.ac.iitb.gymkhana.iitbapp.fragment.PeopleFragment;
import in.ac.iitb.gymkhana.iitbapp.fragment.TimetableFragment;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class MainActivity extends AppCompatActivity
......@@ -37,6 +51,7 @@ public class MainActivity extends AppCompatActivity
private static final String TAG = "MainActivity";
SessionManager session;
NotificationsResponse notificationsResponse;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -57,7 +72,35 @@ public class MainActivity extends AppCompatActivity
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
fetchNotifications();
}
private void fetchNotifications() {
NotificationsRequest notificationsRequest = new NotificationsRequest(0, 20);
RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class);
retrofitInterface.getNotifications(notificationsRequest).enqueue(new Callback<NotificationsResponse>() {
@Override
public void onResponse(Call<NotificationsResponse> call, Response<NotificationsResponse> response) {
if (response.isSuccessful()) {
notificationsResponse = response.body();
}
//Server Error
}
@Override
public void onFailure(Call<NotificationsResponse> call, Throwable t) {
//Network Error
}
});
}
public void showNotifications() {
String notificationsResponseJson = new Gson().toJson(notificationsResponse);
Bundle bundle = new Bundle();
bundle.putString(Constants.NOTIFICATIONS_RESPONSE_JSON, notificationsResponseJson);
NotificationsFragment notificationsFragment = new NotificationsFragment();
notificationsFragment.setArguments(bundle);
updateFragment(notificationsFragment);
}
@Override
......@@ -86,7 +129,9 @@ public class MainActivity extends AppCompatActivity
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
if (id == R.id.action_notifications) {
fetchNotifications();
showNotifications();
return true;
}
......@@ -136,11 +181,8 @@ public class MainActivity extends AppCompatActivity
if (ContextCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
} else
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 0);
break;
case R.id.nav_contacts:
......@@ -151,6 +193,11 @@ public class MainActivity extends AppCompatActivity
AboutFragment aboutFragment = new AboutFragment();
updateFragment(aboutFragment);
break;
case R.id.nav_people:
PeopleFragment peopleFragment = new PeopleFragment();
updateFragment(peopleFragment);
break;
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
......@@ -164,8 +211,8 @@ public class MainActivity extends AppCompatActivity
transaction.replace(R.id.framelayout_for_fragment, fragment, fragment.getTag());
transaction.commit();
}
public void onRequestPermissionsResult(int requestCode,
public void onRequestPermissionsResult(int requestCode,
String[] permissions,
int[] grantResults) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
......
package in.ac.iitb.gymkhana.iitbapp;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
/**
* Created by mrunz on 6/7/17.
*/
public class PeopleSuggestionAdapter extends BaseAdapter implements Filterable {
List mData;
List mStringFilterList;
ValueFilter valueFilter;
private LayoutInflater inflater;
public PeopleSuggestionAdapter(List cancel_type) {
mData = cancel_type;
mStringFilterList = cancel_type;
}
@Override
public int getCount() {
return mData.size();
}
@Override
public Object getItem(int position) {
return mData.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, final ViewGroup parent) {
if (inflater == null) {
inflater = (LayoutInflater) parent.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
View view = inflater.inflate(R.layout.ppl_search_suggestion_item_view, parent, false);
TextView tv_suggestion = (TextView) view.findViewById(R.id.suggestion_item);
tv_suggestion.setText(mData.get(position).toString());
return view;
}
@Override
public Filter getFilter() {
if (valueFilter == null) {
valueFilter = new ValueFilter();
}
return valueFilter;
}
private class ValueFilter extends Filter {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults results = new FilterResults();
if (constraint != null && constraint.length() > 0) {
List filterList = new ArrayList();
for (int i = 0; i < mStringFilterList.size(); i++) {
if ((mStringFilterList.get(i).toString().toUpperCase()).contains(constraint.toString().toUpperCase())) {
filterList.add(mStringFilterList.get(i));
}
}
results.count = filterList.size();
results.values = filterList;
} else {
results.count = mStringFilterList.size();
results.values = mStringFilterList;
}
return results;
}
@Override
protected void publishResults(CharSequence constraint,
FilterResults results) {
mData = (List) results.values;
notifyDataSetChanged();
}
}
}
\ No newline at end of file
package in.ac.iitb.gymkhana.iitbapp.adapter;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import java.util.List;
import in.ac.iitb.gymkhana.iitbapp.ItemClickListener;
import in.ac.iitb.gymkhana.iitbapp.R;
import in.ac.iitb.gymkhana.iitbapp.api.model.Event;
public class FeedAdapter extends RecyclerView.Adapter<FeedAdapter.ViewHolder> {
private List<Event> posts;
private Context context;
private ItemClickListener itemClickListener;
public FeedAdapter(List<Event> posts, ItemClickListener itemClickListener) {
this.posts = posts;
this.itemClickListener = itemClickListener;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
context = viewGroup.getContext();
LayoutInflater inflater = LayoutInflater.from(context);
View postView = inflater.inflate(R.layout.post, viewGroup, false);
final ViewHolder postViewHolder = new ViewHolder(postView);
postView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
itemClickListener.onItemClick(v, postViewHolder.getAdapterPosition());
}
});
return postViewHolder;
}
@Override
public void onBindViewHolder(ViewHolder viewHolder, int i) {
Event currentEvent = posts.get(i);
viewHolder.eventTitle.setText(currentEvent.getEventName());
viewHolder.eventDetails.setText(currentEvent.getEventDescription());
Picasso.with(context).load(currentEvent.getEventImage()).into(viewHolder.eventPicture);
}
@Override
public int getItemCount() {
return posts.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
private ImageView eventPicture;
private TextView eventTitle;
private TextView eventDetails;
private ImageView eventEnthu;
public ViewHolder(View itemView) {
super(itemView);
eventPicture = (ImageView) itemView.findViewById(R.id.event_picture);
eventTitle = (TextView) itemView.findViewById(R.id.event_title);
eventDetails = (TextView) itemView.findViewById(R.id.event_details);
eventEnthu = (ImageView) itemView.findViewById(R.id.event_enthu);
}
}
}
package in.ac.iitb.gymkhana.iitbapp.adapter;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.List;
import in.ac.iitb.gymkhana.iitbapp.ItemClickListener;
import in.ac.iitb.gymkhana.iitbapp.R;
import in.ac.iitb.gymkhana.iitbapp.api.model.AppNotification;
public class NotificationsAdapter extends RecyclerView.Adapter<NotificationsAdapter.Viewholder> {
private List<AppNotification> notifications;
private Context context;
private ItemClickListener itemClickListener;
public NotificationsAdapter(List<AppNotification> notifications, ItemClickListener itemClickListener) {
this.notifications = notifications;
this.itemClickListener = itemClickListener;
}
@Override
public Viewholder onCreateViewHolder(ViewGroup viewGroup, int i) {
context = viewGroup.getContext();
LayoutInflater inflater = LayoutInflater.from(context);
View notificationView = inflater.inflate(R.layout.notification, viewGroup, false);
final Viewholder notificationsViewHolder = new Viewholder(notificationView);
notificationView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
itemClickListener.onItemClick(v, notificationsViewHolder.getAdapterPosition());
}
});
return notificationsViewHolder;
}
@Override
public void onBindViewHolder(Viewholder viewholder, int i) {
AppNotification appNotification = notifications.get(i);
viewholder.notificationTitle.setText(appNotification.getNotificationName());
}
@Override
public int getItemCount() {
return notifications.size();
}
public class Viewholder extends RecyclerView.ViewHolder {
private TextView notificationTitle;
public Viewholder(View itemView) {
super(itemView);
notificationTitle = (TextView) itemView.findViewById(R.id.notification_title);
}
}
}
......@@ -4,14 +4,24 @@ import in.ac.iitb.gymkhana.iitbapp.api.model.EventCreateRequest;
import in.ac.iitb.gymkhana.iitbapp.api.model.EventCreateResponse;
import in.ac.iitb.gymkhana.iitbapp.api.model.LoginRequest;
import in.ac.iitb.gymkhana.iitbapp.api.model.LoginResponse;
import in.ac.iitb.gymkhana.iitbapp.api.model.NewsFeedRequest;
import in.ac.iitb.gymkhana.iitbapp.api.model.NewsFeedResponse;
import in.ac.iitb.gymkhana.iitbapp.api.model.NotificationsRequest;
import in.ac.iitb.gymkhana.iitbapp.api.model.NotificationsResponse;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.POST;
public interface RetrofitInterface {
@POST("/login/")
@POST("login/")
Call<LoginResponse> login(@Body LoginRequest loginRequest);
@POST("/createEvent/")
Call<EventCreateResponse> eventCreate(@Body EventCreateRequest eventCreateRequest);
@POST("getNewsFeed/")
Call<NewsFeedResponse> getNewsFeed(@Body NewsFeedRequest newsFeedRequest);
@POST("getNotifications/")
Call<NotificationsResponse> getNotifications(@Body NotificationsRequest notificationsRequest);
}
package in.ac.iitb.gymkhana.iitbapp.api.model;
import com.google.gson.annotations.SerializedName;
public class AppNotification {
@SerializedName("notification_type")
private int notificationType;
@SerializedName("notification_id")
private String notificationId;
@SerializedName("notification_related_id")
private String notificationRelatedId;
@SerializedName("notification_name")
private String notificationName;
@SerializedName("notification_description")
private String notificationDescription;
@SerializedName("notification_image")
private String notificationImage;
public AppNotification(int notificationType, String notificationId, String notificationRelatedId, String notificationName, String notificationDescription, String notificationImage) {
this.notificationType = notificationType;
this.notificationId = notificationId;
this.notificationRelatedId = notificationRelatedId;
this.notificationName = notificationName;
this.notificationDescription = notificationDescription;
this.notificationImage = notificationImage;
}
public int getNotificationType() {
return notificationType;
}
public void setNotificationType(int notificationType) {
this.notificationType = notificationType;
}
public String getNotificationId() {
return notificationId;
}
public void setNotificationId(String notificationId) {
this.notificationId = notificationId;
}
public String getNotificationRelatedId() {
return notificationRelatedId;
}
public void setNotificationRelatedId(String notificationRelatedId) {
this.notificationRelatedId = notificationRelatedId;
}
public String getNotificationName() {
return notificationName;
}
public void setNotificationName(String notificationName) {
this.notificationName = notificationName;
}
public String getNotificationDescription() {
return notificationDescription;
}
public void setNotificationDescription(String notificationDescription) {
this.notificationDescription = notificationDescription;
}
public String getNotificationImage() {
return notificationImage;
}
public void setNotificationImage(String notificationImage) {
this.notificationImage = notificationImage;
}
}
package in.ac.iitb.gymkhana.iitbapp.api.model;
import com.google.gson.annotations.SerializedName;
public class Event {
@SerializedName("event_name")
String eventName;
@SerializedName("event_description")
String eventDescription;
@SerializedName("event_image")
String eventImage;
@SerializedName("event_creator_name")
String eventCreatorName;
@SerializedName("event_creator_id")
String eventCreatorId;
@SerializedName("event_going_status")
int eventEnthu;
public Event(String eventName, String eventDescription, String eventImage, String eventCreatorName, String eventCreatorId, int eventEnthu) {
this.eventName = eventName;
this.eventDescription = eventDescription;
this.eventImage = eventImage;
this.eventCreatorName = eventCreatorName;
this.eventCreatorId = eventCreatorId;
this.eventEnthu = eventEnthu;
}
public String getEventName() {
return eventName;
}
public void setEventName(String eventName) {
this.eventName = eventName;
}
public String getEventDescription() {
return eventDescription;
}
public void setEventDescription(String eventDescription) {
this.eventDescription = eventDescription;
}
public String getEventImage() {
return eventImage;
}
public void setEventImage(String eventImage) {
this.eventImage = eventImage;
}
public String getEventCreatorName() {
return eventCreatorName;
}
public void setEventCreatorName(String eventCreatorName) {
this.eventCreatorName = eventCreatorName;
}
public String getEventCreatorId() {
return eventCreatorId;
}
public void setEventCreatorId(String eventCreatorId) {
this.eventCreatorId = eventCreatorId;
}
public int getEventEnthu() {
return eventEnthu;
}
public void setEventEnthu(int eventEnthu) {
this.eventEnthu = eventEnthu;
}
}
package in.ac.iitb.gymkhana.iitbapp.api.model;
public class NewsFeedRequest {
public static final int FOLLOWED = 0;
public static final int POPULAR = 1;
private int type;
private int from;
private int to;
public NewsFeedRequest(int type, int from, int to) {
this.type = type;
this.from = from;
this.to = to;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public int getFrom() {
return from;
}
public void setFrom(int from) {
this.from = from;
}
public int getTo() {
return to;
}
public void setTo(int to) {
this.to = to;
}
}
package in.ac.iitb.gymkhana.iitbapp.api.model;
import com.google.gson.annotations.SerializedName;
import java.util.List;
public class NewsFeedResponse {
@SerializedName("posts")
private List<Event> events;
public NewsFeedResponse(List<Event> events) {
this.events = events;
}
public List<Event> getEvents() {
return events;
}
public void setEvents(List<Event> events) {
this.events = events;
}
}
package in.ac.iitb.gymkhana.iitbapp.api.model;
public class NotificationsRequest {
private int from;
private int to;
public NotificationsRequest(int from, int to) {
this.from = from;
this.to = to;
}
public int getFrom() {
return from;
}
public void setFrom(int from) {
this.from = from;
}
public int getTo() {
return to;
}
public void setTo(int to) {
this.to = to;
}
}
package in.ac.iitb.gymkhana.iitbapp.api.model;
import java.util.List;
public class NotificationsResponse {
private String result;
private List<AppNotification> notifications;
public NotificationsResponse(String result, List<AppNotification> notifications) {
this.result = result;
this.notifications = notifications;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
public List<AppNotification> getNotifications() {
return notifications;
}
public void setNotifications(List<AppNotification> notifications) {
this.notifications = notifications;
}
}
......@@ -3,17 +3,32 @@ package in.ac.iitb.gymkhana.iitbapp.fragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
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 java.util.List;
import in.ac.iitb.gymkhana.iitbapp.ItemClickListener;
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.Event;
import in.ac.iitb.gymkhana.iitbapp.api.model.NewsFeedRequest;
import in.ac.iitb.gymkhana.iitbapp.api.model.NewsFeedResponse;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
* A simple {@link Fragment} subclass.
*/
public class FeedFragment extends Fragment {
RecyclerView feedRecyclerView;
public FeedFragment() {
// Required empty public constructor
......@@ -27,4 +42,36 @@ public class FeedFragment extends Fragment {
return inflater.inflate(R.layout.fragment_feed, container, false);
}
@Override
public void onStart() {
super.onStart();
NewsFeedRequest newsFeedRequest = new NewsFeedRequest(NewsFeedRequest.FOLLOWED, 0, 20);
RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class);
retrofitInterface.getNewsFeed(newsFeedRequest).enqueue(new Callback<NewsFeedResponse>() {
@Override
public void onResponse(Call<NewsFeedResponse> call, Response<NewsFeedResponse> response) {
if (response.isSuccessful()) {
NewsFeedResponse newsFeedResponse = response.body();
List<Event> events = newsFeedResponse.getEvents();
FeedAdapter feedAdapter = new FeedAdapter(events, new ItemClickListener() {
@Override
public void onItemClick(View v, int position) {
// TODO: Launch EventFragment
}
});
feedRecyclerView = (RecyclerView) getActivity().findViewById(R.id.feed_recycler_view);
feedRecyclerView.setAdapter(feedAdapter);
feedRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
}
//Server Error
}
@Override
public void onFailure(Call<NewsFeedResponse> call, Throwable t) {
//Network Error
}
});
}
}
package in.ac.iitb.gymkhana.iitbapp.fragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
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 com.google.gson.Gson;
import java.util.List;
import in.ac.iitb.gymkhana.iitbapp.Constants;
import in.ac.iitb.gymkhana.iitbapp.ItemClickListener;
import in.ac.iitb.gymkhana.iitbapp.R;
import in.ac.iitb.gymkhana.iitbapp.adapter.NotificationsAdapter;
import in.ac.iitb.gymkhana.iitbapp.api.model.AppNotification;
import in.ac.iitb.gymkhana.iitbapp.api.model.NotificationsResponse;
/**
* A simple {@link Fragment} subclass.
*/
public class NotificationsFragment extends Fragment {
RecyclerView notificationsRecyclerView;
public NotificationsFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_notifications, container, false);
}
@Override
public void onStart() {
super.onStart();
Bundle bundle = getArguments();
String notificationsResponseJson = bundle.getString(Constants.NOTIFICATIONS_RESPONSE_JSON);
NotificationsResponse notificationsResponse = new Gson().fromJson(notificationsResponseJson, NotificationsResponse.class);
showNotifications(notificationsResponse);
}
private void showNotifications(NotificationsResponse notificationsResponse) {
List<AppNotification> notifications = notificationsResponse.getNotifications();
NotificationsAdapter notificationsAdapter = new NotificationsAdapter(notifications, new ItemClickListener() {
@Override
public void onItemClick(View v, int position) {
//TODO: What to do?
}
});
notificationsRecyclerView = (RecyclerView) getActivity().findViewById(R.id.notifications_recycler_view);
notificationsRecyclerView.setAdapter(notificationsAdapter);
notificationsRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
}
}
package in.ac.iitb.gymkhana.iitbapp.fragment;
import android.app.SearchManager;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.MenuItemCompat;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.support.v7.widget.SearchView;
import java.util.ArrayList;
import in.ac.iitb.gymkhana.iitbapp.PeopleSuggestionAdapter;
import in.ac.iitb.gymkhana.iitbapp.R;
public class PeopleFragment extends Fragment {
View view;
SearchView searchView;
PeopleSuggestionAdapter adapter;
ArrayList<String> suggestionList=new ArrayList<String>();
ListView listView;
public PeopleFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
view=inflater.inflate(R.layout.fragment_people, container, false);
setHasOptionsMenu(true);
suggestionList.add("Web and Coding Club");
suggestionList.add("Electronics and Robotics Club");
suggestionList.add("Krittika");
suggestionList.add("Maths and Physics Club");
suggestionList.add("Aeromodelling Club");
suggestionList.add("Literati");
suggestionList.add("Roots");
suggestionList.add("Staccato");
suggestionList.add("Saaz");
suggestionList.add("InSync");
suggestionList.add("Pixels");
suggestionList.add("Rang");
suggestionList.add("FourthWall");
suggestionList.add("WeSpeak and Vaani");
suggestionList.add("SilverScreen");
suggestionList.add("IIT-BBC");
suggestionList.add("Design Club");
suggestionList.add("LifeStyleClub");
suggestionList.add("MoodIndigo");
suggestionList.add("Techfest");
suggestionList.add("SARC");
suggestionList.add("Academic Council");
listView= (ListView) view.findViewById(R.id.list_view);
listView.setVisibility(View.GONE);
adapter=new PeopleSuggestionAdapter(suggestionList);
listView.setAdapter(adapter);
//TODO SuggestionClickListener
return view;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
menu.clear();
inflater.inflate(R.menu.search_view_menu, menu);
MenuItem searchItem = menu.findItem(R.id.action_search);
final SearchManager searchManager =
(SearchManager) getContext().getSystemService(Context.SEARCH_SERVICE);
searchView =
(SearchView) MenuItemCompat.getActionView(searchItem);
searchView.setSearchableInfo(
searchManager.getSearchableInfo(getActivity().getComponentName()));
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
searchView.clearFocus();
listView.setVisibility(View.GONE);
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
listView.setVisibility(View.VISIBLE);
adapter.getFilter().filter(newText);
return false;
}
});
}
}
......@@ -7,4 +7,5 @@
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="in.ac.iitb.gymkhana.iitbapp.MainActivity"
tools:showIn="@layout/app_bar_main" />
tools:showIn="@layout/app_bar_main"
android:orientation="vertical"/>
......@@ -4,10 +4,9 @@
android:layout_height="match_parent"
tools:context="in.ac.iitb.gymkhana.iitbapp.fragment.FeedFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
<android.support.v7.widget.RecyclerView
android:id="@+id/feed_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
android:layout_height="match_parent" />
</FrameLayout>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="in.ac.iitb.gymkhana.iitbapp.fragment.NotificationsFragment">
<android.support.v7.widget.RecyclerView
android:id="@+id/notifications_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="in.ac.iitb.gymkhana.iitbapp.fragment.PeopleFragment">
<!-- TODO: Update blank fragment layout -->
<!--<android.support.v7.widget.SearchView-->
<!--android:id="@+id/search"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--app:defaultQueryHint="Search"-->
<!--android:clickable="true"/>-->
<ListView
android:id="@+id/list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:visibility="gone"
android:layout_alignParentStart="true"
android:layout_below="@+id/search" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/notification_title"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:orientation="horizontal">
<ImageView
android:layout_weight="1"
android:layout_width="0dp"
android:id="@+id/event_picture"
android:layout_height="50dp" />
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="wrap_content">
<TextView
android:textColor="@android:color/black"
android:textSize="24sp"
android:id="@+id/event_title"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/event_details"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<ImageView
android:src="@drawable/ic_input_add"
android:id="@+id/event_enthu"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="suggestion"
android:padding="8dp"
android:textSize="20sp"
android:id="@+id/suggestion_item"/>
</LinearLayout>
\ No newline at end of file
......@@ -42,6 +42,9 @@
android:id="@+id/nav_map"
android:icon="@drawable/ic_map"
android:title="Map" />
<item
android:id="@+id/nav_people"
android:title="People" />
</group>
<item android:title="Communicate">
......
......@@ -2,8 +2,9 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never" />
android:id="@+id/action_notifications"
android:orderInCategory="1"
android:icon="@drawable/ic_notifications_black_24dp"
android:title="Notifications"
app:showAsAction="always" />
</menu>
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_search"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="always|collapseActionView"
android:icon="@android:drawable/ic_menu_search"
android:title="Search" />
</menu>
\ No newline at end of file
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