Commit 7e17b3d6 authored by mayu's avatar mayu

Merge remote-tracking branch 'upstream/master'

parents f0607aff 4f2813e2
......@@ -84,15 +84,20 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
@Override
protected void onStart() {
super.onStart();
initNavigationView();
if (session.isLoggedIn()) {
currentUser = User.fromString(session.pref.getString(Constants.CURRENT_USER, "Error"));
updateNavigationView();
}
}
private void updateNavigationView() {
private void initNavigationView() {
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
private void updateNavigationView() {
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
View header = navigationView.getHeaderView(0);
header.setOnClickListener(new View.OnClickListener() {
@Override
......@@ -288,6 +293,10 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
}
}
public String getSessionIDHeader() {
return "sessionid=" + session.getSessionID();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
......
......@@ -41,6 +41,10 @@ public class SessionManager {
editor.commit();
}
public String getSessionID() {
return pref.getString(Constants.SESSION_ID, "");
}
public boolean isLoggedIn() {
return pref.getBoolean(Constants.IS_LOGGED_IN, false);
}
......
......@@ -28,6 +28,9 @@ public interface RetrofitInterface {
@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);
@POST("upload")
Call<ImageUploadResponse> uploadImage(@Header("Cookie") String sessionID, @Body ImageUploadRequest imageUploadRequest);
......
......@@ -9,7 +9,7 @@ import com.google.gson.annotations.SerializedName;
import java.util.List;
@Entity(tableName = "bodies")
class Body {
public class Body {
@PrimaryKey(autoGenerate = true)
int db_id;
......@@ -19,6 +19,9 @@ class Body {
@ColumnInfo(name = "name")
@SerializedName("name")
String bodyName;
@ColumnInfo(name = "short_description")
@SerializedName("short_description")
String bodyShortDescription;
@ColumnInfo(name = "description")
@SerializedName("description")
String bodyDescription;
......@@ -65,6 +68,14 @@ class Body {
this.bodyName = bodyName;
}
public String getBodyShortDescription() {
return bodyShortDescription;
}
public void setBodyShortDescription(String bodyShortDescription) {
this.bodyShortDescription = bodyShortDescription;
}
public String getBodyDescription() {
return bodyDescription;
}
......
......@@ -21,6 +21,9 @@ public interface DbDao {
@Query("SELECT * FROM venues")
List<Venue> getAllVenues();
@Query("SELECT * FROM bodies WHERE id == :id")
public Body[] getBody(String id);
@Query("SELECT COUNT(*) from events")
int countEvents();
......@@ -36,6 +39,9 @@ public interface DbDao {
@Insert
void insertBodies(List<Body> bodies);
@Insert
void insertBody(Body body);
@Insert
void insertVenues(List<Venue> venues);
......
package in.ac.iitb.gymkhana.iitbapp.fragment;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
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 android.widget.Toast;
import com.google.gson.Gson;
import com.squareup.picasso.Picasso;
import in.ac.iitb.gymkhana.iitbapp.MainActivity;
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.fragment_body_card, container, false);
}
}
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.TextView;
import com.google.gson.Gson;
import in.ac.iitb.gymkhana.iitbapp.Constants;
import in.ac.iitb.gymkhana.iitbapp.MainActivity;
import in.ac.iitb.gymkhana.iitbapp.R;
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 retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
* A simple {@link Fragment} subclass.
* Use the {@link BodyFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class BodyFragment 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";
private AppDatabase appDatabase;
String TAG = "BodyFragment";
// TODO: Rename and change types of parameters
private Body min_body;
public BodyFragment() {
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param arg_body Body for details
* @return A new instance of fragment BodyFragment.
*/
// TODO: Rename and change types and number of parameters
public static BodyFragment newInstance(Body arg_body) {
BodyFragment fragment = new BodyFragment();
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) {
min_body = new Gson().fromJson(getArguments().getString(ARG_BODY), Body.class);
}
}
@Override
public void onStart() {
super.onStart();
/* Initialize */
appDatabase = AppDatabase.getAppDatabase(getContext());
Body[] inLocalDb = appDatabase.dbDao().getBody(min_body.getBodyID());
if (inLocalDb.length > 0) {
displayBody(inLocalDb[0]);
} else {
updateBody();
}
}
private void updateBody() {
RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class);
retrofitInterface.getBody(((MainActivity)getActivity()).getSessionIDHeader(), min_body.getBodyID()).enqueue(new Callback<Body>() {
@Override
public void onResponse(Call<Body> call, Response<Body> response) {
if (response.isSuccessful()) {
Body body = response.body();
appDatabase.dbDao().insertBody(body);
displayBody(body);
}
}
@Override
public void onFailure(Call<Body> call, Throwable t) {
// Network Error
}
});
}
private void displayBody(Body body) {
TextView bodyName = (TextView) getView().findViewById(R.id.body_name);
TextView bodyDescription = (TextView) getView().findViewById(R.id.body_description);
bodyName.setText(body.getBodyName());
bodyDescription.setText(body.getBodyDescription());
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_body, container, false);
}
}
......@@ -4,6 +4,8 @@ package in.ac.iitb.gymkhana.iitbapp.fragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
......@@ -11,22 +13,27 @@ import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.google.gson.Gson;
import com.squareup.picasso.Picasso;
import org.w3c.dom.Text;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import in.ac.iitb.gymkhana.iitbapp.Constants;
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.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.Body;
import in.ac.iitb.gymkhana.iitbapp.data.Venue;
import retrofit2.Call;
import retrofit2.Callback;
......@@ -89,10 +96,21 @@ public class EventFragment extends BaseFragment implements View.OnClickListener
eventDate.setText(simpleDateFormatDate.format(Date));
eventTime.setText(simpleDateFormatTime.format(Date));
StringBuilder eventVenueName = new StringBuilder();
for (Venue venue : event.getEventVenues()) {
eventVenueName.append(", ").append(venue.getVenueName());
}
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();
}
}
if (!eventVenueName.toString().equals(""))
eventVenue.setText(eventVenueName.toString().substring(2));
goingButton.setOnClickListener(this);
......
......@@ -2,6 +2,7 @@ package in.ac.iitb.gymkhana.iitbapp.fragment;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
......@@ -13,6 +14,7 @@ import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import com.google.gson.Gson;
......@@ -75,8 +77,7 @@ public class FeedFragment extends BaseFragment {
super.onStart();
appDatabase = AppDatabase.getAppDatabase(getContext());
final List<Event> events = appDatabase.dbDao().getAllEvents();
displayEvents(events);
new showEventsFromDB().execute();
updateFeed();
......@@ -99,8 +100,7 @@ public class FeedFragment extends BaseFragment {
List<Event> events = newsFeedResponse.getEvents();
displayEvents(events);
appDatabase.dbDao().deleteEvents();
appDatabase.dbDao().insertEvents(events);
new updateDatabase().execute(events);
}
//Server Error
feedSwipeRefreshLayout.setRefreshing(false);
......@@ -114,6 +114,25 @@ public class FeedFragment extends BaseFragment {
});
}
private class updateDatabase extends AsyncTask<List<Event>, Void, Integer> {
@Override
protected Integer doInBackground(List<Event>... events) {
appDatabase.dbDao().deleteEvents();
appDatabase.dbDao().insertEvents(events[0]);
return 1;
}
}
private class showEventsFromDB extends AsyncTask<String, Void, List<Event>> {
@Override
protected List<Event> doInBackground(String... events) {
return appDatabase.dbDao().getAllEvents();
}
protected void onPostExecute(List<Event> result) {
displayEvents(result);
}
}
private void displayEvents(final List<Event> events) {
final FeedAdapter feedAdapter = new FeedAdapter(events, new ItemClickListener() {
@Override
......
<?xml version="1.0" encoding="utf-8"?>
<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=".fragment.BodyFragment">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<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" />
<TextView
android:id="@+id/body_description"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</ScrollView>
</FrameLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="4dp"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="4dp">
<LinearLayout
android:id="@+id/body_card_layout"
android:layout_width="match_parent"
android:layout_height="80dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/body_card_avatar"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center"
android:scaleType="centerCrop" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_weight="3"
android:orientation="vertical">
<TextView
android:id="@+id/body_card_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Organization"
android:textColor="@android:color/black"
android:textSize="18sp" />
<TextView
android:id="@+id/body_card_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Description" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
\ No newline at end of file
......@@ -6,12 +6,9 @@
android:orientation="vertical"
tools:context="in.ac.iitb.gymkhana.iitbapp.fragment.EventFragment">
<ImageView
android:id="@+id/event_picture_2"
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scaleType="centerCrop" />
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
......@@ -19,6 +16,14 @@
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:id="@+id/event_picture_2"
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"
......@@ -47,7 +52,8 @@
android:layout_weight="10"
android:text="Event Title"
android:textColor="#fff"
android:textSize="28sp" />
android:textSize="21sp"
android:textStyle="bold"/>
<ImageButton
android:id="@+id/share_event_button"
......@@ -174,18 +180,24 @@
</View>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/event_page_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="12dp"
android:layout_marginBottom="16dp"
android:textColor="#777"
android:textSize="16sp" />
</ScrollView>
<LinearLayout
android:id="@+id/body_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
......@@ -37,7 +37,7 @@
<item
android:id="@+id/nav_cms"
android:icon="@drawable/ic_announcement_black_48dp"
android:title="CMS" />e
android:title="CMS" />
<item
android:id="@+id/nav_map"
android:icon="@drawable/ic_map_black_48dp"
......
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