Ver código fonte

commented out fb api and did event listview

Yiupang 9 anos atrás
pai
commit
1fab194252

+ 4 - 0
app/build.gradle

@@ -25,6 +25,9 @@ dependencies {
     androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
         exclude group: 'com.android.support', module: 'support-annotations'
     })
+    repositories{
+        mavenCentral()
+    }
     compile 'com.android.support:appcompat-v7:25.3.1'
     compile 'com.android.support:multidex:1.0.1'
     compile 'com.android.support.constraint:constraint-layout:1.0.2'
@@ -33,4 +36,5 @@ dependencies {
     compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.0.1'
     testCompile 'junit:junit:4.12'
     compile 'com.google.android.gms:play-services-maps:10.2.4'
+    compile 'com.facebook.android:facebook-android-sdk:4.0.0'
 }

+ 9 - 0
app/src/main/java/com/example/yiupang/freefoodfinder/Event.java

@@ -68,6 +68,15 @@ public class Event
         }
     }
 
+    public String getDescription(){return this.description;}
+
+
+    public Event(String name, String foodType, String description)
+    {
+        this.name = name;
+        this.foodType = foodType;
+        this.description = description;
+    }
 }
 
 

+ 76 - 0
app/src/main/java/com/example/yiupang/freefoodfinder/EventArrayAdapter.java

@@ -0,0 +1,76 @@
+package com.example.yiupang.freefoodfinder;
+
+import android.app.Activity;
+import android.content.Context;
+import android.support.annotation.NonNull;
+import android.support.v7.widget.RecyclerView;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.TextView;
+
+import java.util.List;
+
+
+/**
+ * Created by yiupang on 5/20/2017.
+ *
+ */
+public class EventArrayAdapter extends ArrayAdapter<Event>
+{
+    private class ViewHolder{
+        TextView name;
+        TextView type;
+        TextView desc;
+    }
+
+    private Context context;
+    private int layoutResourceId;
+    List<Event> events;
+
+    public EventArrayAdapter(Context context, int layoutResourceId, List<Event> events)
+    {
+        super(context, layoutResourceId, events);
+        this.context = context;
+        this.layoutResourceId = layoutResourceId;
+        this.events = events;
+    }
+
+    @Override
+    public long getItemId(int position){return  events.indexOf(position);}
+
+    @Override
+    public int getCount(){
+        return events.size();
+    }
+
+    @NonNull
+    @Override
+    public View getView(int position, View convertView, ViewGroup parent)
+    {
+        ViewHolder holder = null;
+        LayoutInflater inflater = ((Activity) context).getLayoutInflater();
+
+        if(convertView == null) {
+            convertView = inflater.inflate(R.layout.events_list_item, parent, false);
+            holder = new ViewHolder();
+
+            holder.name = (TextView) convertView.findViewById(R.id.name);
+            holder.type = (TextView) convertView.findViewById(R.id.type);
+            holder.desc = (TextView) convertView.findViewById(R.id.desc);
+
+            Event row_pos = events.get(position);
+
+            holder.name.setText(row_pos.getName());
+            holder.type.setText(row_pos.getFoodType());
+            holder.desc.setText(row_pos.getDescription());
+
+            convertView.setTag(holder);
+        } else {
+            holder = (ViewHolder) convertView.getTag();
+        }
+
+        return convertView;
+    }
+}

+ 16 - 1
app/src/main/java/com/example/yiupang/freefoodfinder/EventsScreen.java

@@ -5,6 +5,11 @@ import android.support.annotation.Nullable;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.ListView;
+import java.util.ArrayList;
+
+import java.lang.reflect.Array;
 
 /**
  * Created by yiupang on 5/6/2017.
@@ -17,6 +22,16 @@ public class EventsScreen extends android.support.v4.app.Fragment
     @Override
     public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
     {
-        return inflater.inflate(R.layout.events_screen, container, false);
+        View view = inflater.inflate(R.layout.events_screen, container, false);
+        ArrayList<Event> dataArray = new ArrayList();
+        dataArray.add(new Event("Free Food 1", "Pizza", "Come !!"));
+        dataArray.add(new Event("Free Food 5", "GodPizza", "Come Again !!"));
+        dataArray.add(new Event("Free Food 4", "GodPizza", "Come Again !!"));
+        dataArray.add(new Event("Free Food 8", "GodPizza", "Come Again !!"));
+
+        EventArrayAdapter adapter = new EventArrayAdapter(view.getContext(), R.layout.events_list_item, dataArray);
+        ListView listView = (ListView) view.findViewById(R.id.events_screen);
+        listView.setAdapter(adapter);
+        return view;
     }
 }

+ 35 - 5
app/src/main/java/com/example/yiupang/freefoodfinder/MainActivity.java

@@ -11,18 +11,53 @@ import android.view.View;
 import com.roughike.bottombar.BottomBar;
 import android.view.Menu;
 import android.view.MenuItem;
+import android.widget.TextView;
 
 import com.roughike.bottombar.BottomBar;
 import com.roughike.bottombar.BottomBarBadge;
 import com.roughike.bottombar.OnMenuTabClickListener;
 
+import com.facebook.CallbackManager;
+import com.facebook.FacebookSdk;
+import com.facebook.login.widget.LoginButton;
+import com.facebook.login.LoginResult;
+import com.facebook.FacebookCallback;
+import com.facebook.FacebookException;
+
 public class MainActivity extends ActionBarActivity
 {
     BottomBar bottomBar;
+    private TextView info;
+    //private LoginButton loginButton;
+    private CallbackManager callbackManager;
+
     @Override
     protected void onCreate(Bundle savedInstanceState)
     {
         super.onCreate(savedInstanceState);
+/*        FacebookSdk.sdkInitialize(getApplicationContext());
+        callbackManager = CallbackManager.Factory.create();
+        info = (TextView) findViewById(R.id.info);
+        loginButton = (LoginButton) findViewById(R.id.login_button);
+
+        loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
+            @Override
+            public void onSuccess(LoginResult loginResult) {
+                info.setText("UserID:" + loginResult.getAccessToken().getUserId() + "\n" +
+                "Auth Token" +
+                loginResult.getAccessToken().getToken());
+            }
+
+            @Override
+            public void onCancel() {
+                info.setText("Login insuccessful");
+            }
+
+            @Override
+            public void onError(FacebookException error) {
+                info.setText("Login insuccessful");
+            }
+        });*/
         setContentView(R.layout.activity_main);
         bottomBar = BottomBar.attach(this, savedInstanceState);
         bottomBar.setItemsFromMenu(R.menu.menu_main, new OnMenuTabClickListener()
@@ -63,11 +98,6 @@ public class MainActivity extends ActionBarActivity
         bottomBar.mapColorForTab(1, "#ff0000");
         bottomBar.mapColorForTab(2, "#ff0000");
         bottomBar.mapColorForTab(3, "#ff0000");
-
-        BottomBarBadge unread;
-        unread = bottomBar.makeBadgeForTabAt(3, "#FF0000", 13);
-        unread.show();
-
     }
 
     @Override

+ 17 - 0
app/src/main/res/layout/activity_main.xml

@@ -6,8 +6,25 @@
     <include
         android:id="@+id/toolBar"
         layout="@layout/tool_bar" />
+
     <FrameLayout android:id="@+id/frame"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content" />
 
+    <TextView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:id="@+id/info"
+        android:layout_alignParentLeft="true"
+        android:layout_alignParentTop="true"
+        android:textSize="18sp"
+        />
+
+<!--    <com.facebook.login.widget.LoginButton
+        android:id="@+id/login_button"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_centerInParent="true"
+        />-->
+
 </RelativeLayout>

+ 38 - 0
app/src/main/res/layout/events_list_item.xml

@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    android:padding="10dip">
+
+    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
+        android:id="@+id/name"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentStart="true"
+        android:padding="10dip"
+        android:textSize="16sp"
+        android:textStyle="bold" >
+    </TextView>
+
+    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
+        android:id="@+id/type"
+        android:layout_width="wrap_content"
+        android:layout_alignParentEnd="true"
+        android:layout_height="wrap_content"
+        android:padding="10dip"
+        android:textSize="16sp"
+        android:textStyle="bold" >
+    </TextView>
+
+    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
+        android:id="@+id/desc"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_below="@+id/name"
+        android:padding="10dip"
+        android:textSize="16sp"
+        android:textStyle="bold" >
+    </TextView>
+</RelativeLayout>
+

+ 5 - 0
app/src/main/res/layout/events_screen.xml

@@ -12,4 +12,9 @@
 
         </TextView>
 
+    <ListView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:id="@+id/events_screen"/>
+
 </LinearLayout>

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -1,4 +1,5 @@
 <resources>
     <string name="app_name">FreeFoodFinder</string>
     <string name="action_settings">Settings</string>
+    <string name="facebook_app_id">169855136874779</string>
 </resources>