Commit 5ac4a72e authored by yvsriram's avatar yvsriram Committed by GitHub

Merge branch 'master' into master

parents e90b89c4 96935707
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
</value> </value>
</option> </option>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="1.8 (1)" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">
......
...@@ -2,4 +2,5 @@ package in.ac.iitb.gymkhana.iitbapp; ...@@ -2,4 +2,5 @@ package in.ac.iitb.gymkhana.iitbapp;
public class Constants { public class Constants {
public static final String NOTIFICATIONS_RESPONSE_JSON = "notifications_json"; public static final String NOTIFICATIONS_RESPONSE_JSON = "notifications_json";
public static final String EVENT_JSON = "event_json";
} }
...@@ -51,6 +51,8 @@ public class MainActivity extends AppCompatActivity ...@@ -51,6 +51,8 @@ public class MainActivity extends AppCompatActivity
private static final String TAG = "MainActivity"; private static final String TAG = "MainActivity";
SessionManager session; SessionManager session;
NotificationsResponse notificationsResponse;
private boolean showNotifications = false;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -81,14 +83,11 @@ public class MainActivity extends AppCompatActivity ...@@ -81,14 +83,11 @@ public class MainActivity extends AppCompatActivity
@Override @Override
public void onResponse(Call<NotificationsResponse> call, Response<NotificationsResponse> response) { public void onResponse(Call<NotificationsResponse> call, Response<NotificationsResponse> response) {
if (response.isSuccessful()) { if (response.isSuccessful()) {
NotificationsResponse notificationsResponse = response.body(); notificationsResponse = response.body();
String notificationsResponseJson = new Gson().toJson(notificationsResponse); if (showNotifications) {
Bundle bundle = new Bundle(); showNotifications();
bundle.putString(Constants.NOTIFICATIONS_RESPONSE_JSON, notificationsResponseJson); showNotifications = false;
NotificationsFragment notificationsFragment = new NotificationsFragment(); }
notificationsFragment.setArguments(bundle);
updateFragment(notificationsFragment);
} }
//Server Error //Server Error
} }
...@@ -100,6 +99,15 @@ public class MainActivity extends AppCompatActivity ...@@ -100,6 +99,15 @@ public class MainActivity extends AppCompatActivity
}); });
} }
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 @Override
public void onBackPressed() { public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
...@@ -126,10 +134,11 @@ public class MainActivity extends AppCompatActivity ...@@ -126,10 +134,11 @@ public class MainActivity extends AppCompatActivity
int id = item.getItemId(); int id = item.getItemId();
//noinspection SimplifiableIfStatement //noinspection SimplifiableIfStatement
if (id == R.id.action_settings) { if (id == R.id.action_notifications) {
showNotifications = true;
fetchNotifications();
return true; return true;
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
...@@ -176,11 +185,8 @@ public class MainActivity extends AppCompatActivity ...@@ -176,11 +185,8 @@ public class MainActivity extends AppCompatActivity
if (ContextCompat.checkSelfPermission(MainActivity.this, if (ContextCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.ACCESS_FINE_LOCATION) Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) { == PackageManager.PERMISSION_GRANTED) {
} else } else
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 0); ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 0);
break; break;
case R.id.nav_contacts: case R.id.nav_contacts:
......
package in.ac.iitb.gymkhana.iitbapp.fragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.google.gson.Gson;
import com.squareup.picasso.Picasso;
import in.ac.iitb.gymkhana.iitbapp.Constants;
import in.ac.iitb.gymkhana.iitbapp.R;
import in.ac.iitb.gymkhana.iitbapp.api.model.Event;
/**
* A simple {@link Fragment} subclass.
*/
public class EventFragment extends Fragment {
public EventFragment() {
// 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_event, container, false);
}
@Override
public void onStart() {
super.onStart();
Bundle bundle = getArguments();
String eventJson = bundle.getString(Constants.EVENT_JSON);
Event event = new Gson().fromJson(eventJson, Event.class);
inflateViews(event);
}
private void inflateViews(Event event) {
ImageView eventPicture = (ImageView) getActivity().findViewById(R.id.event_picture_2);
TextView eventTitle = (TextView) getActivity().findViewById(R.id.event_title_2);
TextView eventDetails = (TextView) getActivity().findViewById(R.id.event_details_2);
TextView eventDescription = (TextView) getActivity().findViewById(R.id.event_description_2);
Picasso.with(getContext()).load(event.getEventImage()).into(eventPicture);
eventTitle.setText(event.getEventName());
eventDetails.setText(event.getEventDescription());
eventDescription.setText(event.getEventDescription());
}
}
...@@ -7,6 +7,7 @@ import android.os.Bundle; ...@@ -7,6 +7,7 @@ import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.SwipeRefreshLayout;
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.util.Log; import android.util.Log;
...@@ -16,7 +17,9 @@ import android.view.ViewGroup; ...@@ -16,7 +17,9 @@ import android.view.ViewGroup;
import com.google.gson.Gson; import com.google.gson.Gson;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import in.ac.iitb.gymkhana.iitbapp.Constants; import in.ac.iitb.gymkhana.iitbapp.Constants;
...@@ -38,7 +41,8 @@ import retrofit2.Response; ...@@ -38,7 +41,8 @@ import retrofit2.Response;
*/ */
public class FeedFragment extends Fragment { public class FeedFragment extends Fragment {
RecyclerView feedRecyclerView; private RecyclerView feedRecyclerView;
private SwipeRefreshLayout feedSwipeRefreshLayout;
public FeedFragment() { public FeedFragment() {
// Required empty public constructor // Required empty public constructor
...@@ -87,9 +91,21 @@ public class FeedFragment extends Fragment { ...@@ -87,9 +91,21 @@ public class FeedFragment extends Fragment {
} }
updateFeed();
feedSwipeRefreshLayout = (SwipeRefreshLayout) getActivity().findViewById(R.id.feed_swipe_refresh_layout);
feedSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
updateFeed();
}
});
}
private void updateFeed() {
NewsFeedRequest newsFeedRequest = new NewsFeedRequest(NewsFeedRequest.FOLLOWED, 0, 20); NewsFeedRequest newsFeedRequest = new NewsFeedRequest(NewsFeedRequest.FOLLOWED, 0, 20);
RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class); RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class);
retrofitInterface.getNewsFeed(newsFeedRequest).enqueue(new Callback<NewsFeedResponse>() { retrofitInterface.getNewsFeed().enqueue(new Callback<NewsFeedResponse>() {
@Override @Override
public void onResponse(Call<NewsFeedResponse> call, Response<NewsFeedResponse> response) { public void onResponse(Call<NewsFeedResponse> call, Response<NewsFeedResponse> response) {
if (response.isSuccessful()) { if (response.isSuccessful()) {
...@@ -131,11 +147,13 @@ public class FeedFragment extends Fragment { ...@@ -131,11 +147,13 @@ public class FeedFragment extends Fragment {
Log.d("FeedFragment", Integer.toString(insertCount) + " elements inserted"); Log.d("FeedFragment", Integer.toString(insertCount) + " elements inserted");
} }
//Server Error //Server Error
feedSwipeRefreshLayout.setRefreshing(false);
} }
@Override @Override
public void onFailure(Call<NewsFeedResponse> call, Throwable t) { public void onFailure(Call<NewsFeedResponse> call, Throwable t) {
//Network Error //Network Error
feedSwipeRefreshLayout.setRefreshing(false);
} }
}); });
} }
......
...@@ -36,14 +36,13 @@ public class MapFragment extends Fragment implements OnMapReadyCallback { ...@@ -36,14 +36,13 @@ public class MapFragment extends Fragment implements OnMapReadyCallback {
public void onMapReady(GoogleMap gMap) { public void onMapReady(GoogleMap gMap) {
googleMap = gMap; googleMap = gMap;
googleMap.setMyLocationEnabled(true); googleMap.setMyLocationEnabled(true);
googleMap.getUiSettings().setMyLocationButtonEnabled(true); googleMap.getUiSettings().setMyLocationButtonEnabled(false);
googleMap.getUiSettings().setZoomGesturesEnabled(true); googleMap.getUiSettings().setZoomGesturesEnabled(true);
LatLngBounds iitbBounds = new LatLngBounds(new LatLng(19.1249000, 72.9046000), new LatLng(19.143522, 72.920000)); LatLngBounds iitbBounds = new LatLngBounds(new LatLng(19.1249000, 72.9046000), new LatLng(19.143522, 72.920000));
googleMap.setLatLngBoundsForCameraTarget(iitbBounds); googleMap.setLatLngBoundsForCameraTarget(iitbBounds);
googleMap.setMaxZoomPreference(30); googleMap.setMaxZoomPreference(30);
googleMap.setMinZoomPreference((float) 14.5); googleMap.setMinZoomPreference(14.5f);
// Position the map's camera near Mumbai // Position the map's camera near Mumbai
LatLng iitb = new LatLng(19.1334, 72.9133); LatLng iitb = new LatLng(19.1334, 72.9133);
googleMap.addMarker(new MarkerOptions().position(iitb) googleMap.addMarker(new MarkerOptions().position(iitb)
......
<LinearLayout 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"
android:orientation="vertical"
tools:context="in.ac.iitb.gymkhana.iitbapp.fragment.EventFragment">
<ImageView
android:scaleType="centerCrop"
android:id="@+id/event_picture_2"
android:layout_width="match_parent"
android:layout_height="360dp" />
<TextView
android:id="@+id/event_title_2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/event_details_2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:background="@color/colorPrimary"
style="?android:attr/buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:text="Going"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:text="Interested"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:text="Not Going"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<TextView
android:id="@+id/event_description_2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/feed_swipe_refresh_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context="in.ac.iitb.gymkhana.iitbapp.fragment.FeedFragment"> tools:context="in.ac.iitb.gymkhana.iitbapp.fragment.FeedFragment">
...@@ -9,4 +10,4 @@ ...@@ -9,4 +10,4 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent" />
</FrameLayout> </android.support.v4.widget.SwipeRefreshLayout>
...@@ -7,10 +7,4 @@ ...@@ -7,10 +7,4 @@
android:icon="@drawable/ic_notifications_black_24dp" android:icon="@drawable/ic_notifications_black_24dp"
android:title="Notifications" android:title="Notifications"
app:showAsAction="always" /> app:showAsAction="always" />
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never" />
</menu> </menu>
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