Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project 3, Perry, Claire, Will, Chris #16

Open
wants to merge 79 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
784fe9d
Initial Commit
Mar 7, 2016
35bc68d
Functional Toolbar in Portrait Mode
Mar 7, 2016
2ca1d0c
Pretty colors
Mar 8, 2016
903c6d7
Passing to Perry
Mar 8, 2016
9c38299
built recycler view inside fragment 1 Perry and Chris. Added differe…
Mar 8, 2016
319d2ac
Add gitignore
Mar 8, 2016
d1fb400
Tweak
Mar 8, 2016
0bebe71
Finish things
Mar 8, 2016
208d363
Pass code
Mar 9, 2016
c37d002
2 cards working
Mar 9, 2016
aaf043b
Added sample reddit view and Selection Page View
Mar 9, 2016
09bbd0a
Merge branch 'master' of https://github.com/chris-shum/Project-3
Mar 9, 2016
096f231
Facebook
incepted Mar 9, 2016
6ee29b6
Narrowing down data featuers
Mar 9, 2016
44bc58b
added some layout adjustements
Mar 9, 2016
db336d7
Merge branch 'master' of https://github.com/chris-shum/Project-3
Mar 9, 2016
12fcc26
resolved merge conflicts
Mar 9, 2016
8359005
Weather API call implemented
WasabiMayo Mar 10, 2016
dac83e8
Reddit Api
WasabiMayo Mar 10, 2016
ee025f9
Merge pull request #1 from chris-shum/branch-claire
Mar 10, 2016
4366786
Added Singleton
Mar 10, 2016
37eded9
Resolved merge conflicts
Mar 10, 2016
d64990a
Merge?
Mar 10, 2016
3fbccc9
some card XML design additions
Mar 10, 2016
72f3666
Merge branch 'perrys_branch'
Mar 10, 2016
2c5afa9
weather card class created and built at end of API call in the MainAc…
Mar 10, 2016
d85d5c0
Reddit API is done
WasabiMayo Mar 10, 2016
4fe6758
Merge pull request #2 from chris-shum/branch-claire
WasabiMayo Mar 10, 2016
fb9a8d6
Added holder for weather and weather card. Adjusted some of the layo…
Mar 10, 2016
bdd1ade
Merge branch 'master' of https://github.com/chris-shum/Project-3
Mar 10, 2016
18aa347
commit?
Mar 10, 2016
22e94f2
Refresh
WasabiMayo Mar 10, 2016
14ed006
Merge branch 'master' of https://github.com/chris-shum/Project-3 into…
WasabiMayo Mar 10, 2016
d703d2c
Merge conflict solved
WasabiMayo Mar 10, 2016
aae0f56
Foursquare
WasabiMayo Mar 10, 2016
1a08301
Merge pull request #4 from chris-shum/branch-claire
WasabiMayo Mar 10, 2016
808eecc
Perry Added Singleton Logic for 11 individual arrays
Mar 10, 2016
027719c
solved merge conflicts
Mar 10, 2016
3253e43
All tabs added
Mar 10, 2016
43621b4
Resolved merge conflicts
Mar 10, 2016
87689f5
Most up to date code
Mar 10, 2016
db8d1f9
Added notes and possibly other things
Mar 10, 2016
d0d7a7e
added redditSwitcher and meetupSwitcher in Main Activity and Facebook…
Mar 10, 2016
16a9f3e
All tabs set
Mar 10, 2016
5c4feb8
Merge branch 'fourthBranch'
Mar 10, 2016
83a48a0
Update
WasabiMayo Mar 10, 2016
a021cad
FB implementation
incepted Mar 10, 2016
cead69c
Merge
WasabiMayo Mar 11, 2016
3478d4e
Refresh
WasabiMayo Mar 11, 2016
0d1fe1d
FB
incepted Mar 11, 2016
46b3136
refresh
incepted Mar 11, 2016
620c0db
Clean
incepted Mar 11, 2016
384bc81
Getting clean copy
Mar 11, 2016
6690df1
Something
Mar 11, 2016
521ff13
Trying to add selections page
Mar 11, 2016
c75d919
Selections Page
Mar 11, 2016
9dc0c1d
Files added
Mar 11, 2016
471020b
Merge branch 'fifthBranch'
Mar 11, 2016
e787f61
Merge branch 'master' into fifthBranch
Mar 11, 2016
a3fd954
Final commit for the evening
Mar 11, 2016
ef215a0
Fragments updated, notifcation added, and menubar option
Mar 11, 2016
fae2c70
Created more cards and objects. API Call completed.
WasabiMayo Mar 11, 2016
dfff2b1
Refresh
WasabiMayo Mar 11, 2016
89f9b87
Merge branch 'master' of https://github.com/chris-shum/Project-3
WasabiMayo Mar 11, 2016
687888c
Refresh
WasabiMayo Mar 11, 2016
a06822d
Updated files: added User Test cases, Readme.md
incepted Mar 11, 2016
7d83d9a
added holders for both fourswuare and reddit. added new reddit layou…
Mar 11, 2016
8675ea7
fixed merge conflicts
Mar 11, 2016
30d321b
FacebookFeed is done
WasabiMayo Mar 11, 2016
8cbcdd8
Merge branch 'master' of https://github.com/chris-shum/Project-3
incepted Mar 11, 2016
d8b2c26
Merge solved
WasabiMayo Mar 11, 2016
cfa1533
Merge branch 'master' of https://github.com/chris-shum/Project-3
WasabiMayo Mar 11, 2016
de23af2
Working
WasabiMayo Mar 11, 2016
8fe56c8
Working code
WasabiMayo Mar 11, 2016
49849c2
Really final
WasabiMayo Mar 11, 2016
0038ab4
Added files via upload
Mar 16, 2016
2adf068
Update README.md
chris-shum Jul 23, 2016
013c0ac
Update strings.xml
chris-shum Jul 23, 2016
1e052ab
Update MainActivity.java
chris-shum Jul 23, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Perry Added Singleton Logic for 11 individual arrays
  • Loading branch information
pcooperman28 committed Mar 10, 2016
commit 808eeccc9d7e8dfe0591af8500314c51ae77e229
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
<<<<<<< HEAD
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
Expand All @@ -34,14 +34,13 @@
import com.example.android.lately.Fragments.DetailsFragment;
import com.example.android.lately.Reddit.RedditArticle.Comments.CommentProcessor;
import com.example.android.lately.Reddit.RedditArticle.Data;
=======

import android.widget.Toast;

import com.example.android.lately.Cards.CardAdapter;
import com.example.android.lately.Cards.WeatherCard;
import com.example.android.lately.Forecast.Weather;
import com.example.android.lately.Fragments.DetailsFragment;
>>>>>>> perrys_branch
import com.example.android.lately.Reddit.RedditArticle.RedditArticle;
import com.example.android.lately.Reddit.RedditArticle.RedditResult;
import com.google.android.gms.common.ConnectionResult;
Expand Down Expand Up @@ -70,7 +69,7 @@
import retrofit2.http.GET;
import retrofit2.http.Path;

public class MainActivity extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener{
public class MainActivity extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {

private GoogleApiClient mGoogleApiClient;
private Location mLastLocation;
Expand All @@ -79,6 +78,7 @@ public class MainActivity extends AppCompatActivity implements GoogleApiClient.C
boolean mPortrait;
ArrayList<RedditComment> mComments;
CommentAsyncTask commentAsyncTask;
Singleton mSingletonArrayOfParentCards;

ProgressBar progressbar;

Expand All @@ -91,6 +91,8 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mSingletonArrayOfParentCards = Singleton.getInstance();

mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
Expand Down Expand Up @@ -263,13 +265,13 @@ public void onTabReselected(TabLayout.Tab tab) {
}


}
}


public void getForecastApi(){
public void getForecastApi() {
String latitude = String.valueOf(mLastLocation.getLatitude()).substring(0, 7);
String longitude = String.valueOf(mLastLocation.getLongitude()).substring(0, 8);
String latlon = latitude+","+longitude;
String latlon = latitude + "," + longitude;

Retrofit retrofit = new Retrofit.Builder()
.baseUrl(mForecastUrl)
Expand All @@ -289,8 +291,8 @@ public void onResponse(Call<Weather> call, Response<Weather> response) {
String currentLocation = response.body().getTimezone();

SimpleDateFormat format = new SimpleDateFormat("MMM dd, yyyy hha z, EEE");
format.setTimeZone(TimeZone.getTimeZone("GMT"+response.body().getOffset()));
Date currentDate = new Date((long)(response.body().getCurrently().getTime() * 1000L));
format.setTimeZone(TimeZone.getTimeZone("GMT" + response.body().getOffset()));
Date currentDate = new Date((long) (response.body().getCurrently().getTime() * 1000L));
String formattedCurrentDate = format.format(currentDate);


Expand All @@ -299,32 +301,33 @@ public void onResponse(Call<Weather> call, Response<Weather> response) {
String[] nextFiveDaysSummary = new String[5];
String[] nextFiveDaysHighTemp = new String[5];
String[] nextFiveDaysLowTemp = new String[5];
for(int i=0; i<5; i++){
Date nextDayTime = new Date((long)(response.body().getDaily().getData().get(i+1).getTime() * 1000L));
for (int i = 0; i < 5; i++) {
Date nextDayTime = new Date((long) (response.body().getDaily().getData().get(i + 1).getTime() * 1000L));
String formattedDate = format.format(nextDayTime);
nextFiveDaysDates[i] = formattedDate;
//If you want to just extract day names(i.e. Tue), comment out the line above this and uncomment the below one.
//nextFiveDaysDates[i] = formattedDate.substring(formattedDate.length()-3,formattedDate.length());

nextFiveDaysSummary[i] = response.body().getDaily().getData().get(i+1).getSummary();
nextFiveDaysSummary[i] = response.body().getDaily().getData().get(i + 1).getSummary();
nextFiveDaysHighTemp[i] = String.valueOf(response.body().getDaily().getData().get(i + 1).getTemperatureMax());
nextFiveDaysHighTemp[i] = String.valueOf(response.body().getDaily().getData().get(i+1).getTemperatureMin());
nextFiveDaysHighTemp[i] = String.valueOf(response.body().getDaily().getData().get(i + 1).getTemperatureMin());

WeatherCard weatherCard = new WeatherCard(currentTemperature, currentSummary, currentLocation,
formattedCurrentDate, nextFiveDaysDates, nextFiveDaysSummary, nextFiveDaysHighTemp, nextFiveDaysLowTemp, CardAdapter.TAB_MAINPAGE,
CardAdapter.TYPE_WEATHER, 0);

//TODO: Add WeatherCard to Singleton
mSingletonArrayOfParentCards.addParentCard(weatherCard, CardAdapter.TAB_MAINPAGE);
}
}

@Override
public void onFailure(Call<Weather> call, Throwable t) {
Toast.makeText(MainActivity.this, "Failed", Toast.LENGTH_SHORT).show();
}
});
}

public void getRedditApi(String subreddit){
public void getRedditApi(String subreddit) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(mRedditUrl)
.addConverterFactory(GsonConverterFactory.create())
Expand All @@ -339,9 +342,9 @@ public void getRedditApi(String subreddit){
public void onResponse(Call<RedditResult> call, Response<RedditResult> response) {

List<RedditArticle> result = response.body().getData().getChildren();
String articleAuthor,articleUrl,articleSubreddit,articleContent, articleTitle, articleTime;
String articleAuthor, articleUrl, articleSubreddit, articleContent, articleTitle, articleTime;
int articleScore, articleNumOfComment, idNumber;
for(int i=0; i<result.size(); i++){
for (int i = 0; i < result.size(); i++) {
articleAuthor = result.get(i).getData().getAuthor();
articleSubreddit = result.get(i).getData().getSubreddit();
articleTitle = result.get(i).getData().getTitle();
Expand All @@ -350,10 +353,10 @@ public void onResponse(Call<RedditResult> call, Response<RedditResult> response)
articleNumOfComment = result.get(i).getData().getNumComments();
articleScore = result.get(i).getData().getScore();
SimpleDateFormat format = new SimpleDateFormat("MMM dd, yyyy hha, EEE");
Date currentDate = new Date((long)(result.get(i).getData().getCreated() * 1000L));
Date currentDate = new Date((long) (result.get(i).getData().getCreated() * 1000L));
articleTime = format.format(currentDate);
articleSubreddit = result.get(i).getData().getSubreddit();
idNumber = i+1;
idNumber = i + 1;


//This background method clears the mComments ArrayList(member variable) and stuffs new comment lists.
Expand All @@ -375,7 +378,7 @@ public class CommentAsyncTask extends AsyncTask<String, Void, Void> {
@Override
protected Void doInBackground(String... params) {
String data = "";
try{
try {
URL url = new URL(params[0]);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.connect();
Expand All @@ -384,7 +387,7 @@ protected Void doInBackground(String... params) {
CommentProcessor commentProcessor = new CommentProcessor(data);
mComments = new ArrayList<>();
mComments = commentProcessor.fetchComments();
}catch (Throwable e){
} catch (Throwable e) {
e.printStackTrace();
}
return null;
Expand All @@ -398,7 +401,7 @@ protected void onPreExecute() {
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
Log.d("REDDITARTICLE",mComments.get(1).getmAuthor() +" "+ mComments.get(1).getmContent());
Log.d("REDDITARTICLE", mComments.get(1).getmAuthor() + " " + mComments.get(1).getmContent());
}
}

Expand Down Expand Up @@ -464,7 +467,7 @@ public void onConnected(Bundle bundle) {
} else {
Toast.makeText(MainActivity.this, "Turn on GPS and try again", Toast.LENGTH_SHORT).show();
}
}else{
} else {
Toast.makeText(MainActivity.this, "No network connection", Toast.LENGTH_SHORT).show();
}
}
Expand All @@ -479,12 +482,12 @@ public void onConnectionFailed(ConnectionResult connectionResult) {

}

public interface WeatherRequest{
public interface WeatherRequest {
@GET("{latlon}/")
Call<Weather> getWeather(@Path("latlon") String latlon);
}

public interface RedditRequest{
public interface RedditRequest {
@GET("{subreddit}/.json")
Call<RedditResult> getRedditFeed(@Path("subreddit") String subreddit);
}
Expand All @@ -501,4 +504,5 @@ public interface RedditRequest{
// }



}
132 changes: 121 additions & 11 deletions Late.ly/app/src/main/java/com/example/android/lately/Singleton.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.android.lately;

import com.example.android.lately.Cards.CardAdapter;
import com.example.android.lately.Cards.ParentCard;

import java.util.ArrayList;
Expand All @@ -9,26 +10,135 @@
*/
public class Singleton {

ArrayList<ParentCard> parentCardArrayList;
ArrayList<ParentCard> mMainPageArray;
ArrayList<ParentCard> mPoliticsArray;
ArrayList<ParentCard> mTechArray;
ArrayList<ParentCard> mCareerArray;
ArrayList<ParentCard> mFoodArray;
ArrayList<ParentCard> mDancingArray;
ArrayList<ParentCard> mAnimalsArray;
ArrayList<ParentCard> mLanguageArray;
ArrayList<ParentCard> mNatureArray;
ArrayList<ParentCard> mSportsArray;
ArrayList<ParentCard> mDatingArray;

public Singleton(ArrayList<ParentCard> parentCardArrayList) {
this.parentCardArrayList = parentCardArrayList;

private static Singleton singleton = new Singleton();

public Singleton() {
this.mMainPageArray = new ArrayList<ParentCard>();
this.mPoliticsArray = new ArrayList<ParentCard>();
this.mTechArray = new ArrayList<ParentCard>();
this.mCareerArray = new ArrayList<ParentCard>();
this.mFoodArray = new ArrayList<ParentCard>();
this.mDancingArray = new ArrayList<ParentCard>();
this.mAnimalsArray = new ArrayList<ParentCard>();
this.mLanguageArray = new ArrayList<ParentCard>();
this.mNatureArray = new ArrayList<ParentCard>();
this.mSportsArray = new ArrayList<ParentCard>();
this.mDatingArray = new ArrayList<ParentCard>();
}

public ArrayList<ParentCard> getParentCardArrayList() {
return parentCardArrayList;
public ArrayList<ParentCard> getArrayList(int TAB) {
switch (TAB){
case CardAdapter.TAB_MAINPAGE:
return mMainPageArray;
case CardAdapter.TAB_POLITICS:
return mPoliticsArray;
case CardAdapter.TAB_TECH:
return mTechArray;
case CardAdapter.TAB_CAREER:
return mCareerArray;
case CardAdapter.TAB_FOOD:
return mFoodArray;
case CardAdapter.TAB_DANCING:
return mDancingArray;
case CardAdapter.TAB_ANIMALS:
return mAnimalsArray;
case CardAdapter.TAB_LANGUAGE:
return mLanguageArray;
case CardAdapter.TAB_NATURE:
return mNatureArray;
case CardAdapter.TAB_SPORTS:
return mSportsArray;
case CardAdapter.TAB_DATING:
return mDatingArray;
default:
return mMainPageArray;
}
}

public void setParentCardArrayList(ArrayList<ParentCard> parentCardArrayList) {
this.parentCardArrayList = parentCardArrayList;
public ParentCard getParentCard(int TAB, int position){
switch (TAB){
case CardAdapter.TAB_MAINPAGE:
return mMainPageArray.get(position);
case CardAdapter.TAB_POLITICS:
return mPoliticsArray.get(position);
case CardAdapter.TAB_TECH:
return mTechArray.get(position);
case CardAdapter.TAB_CAREER:
return mCareerArray.get(position);
case CardAdapter.TAB_FOOD:
return mFoodArray.get(position);
case CardAdapter.TAB_DANCING:
return mDancingArray.get(position);
case CardAdapter.TAB_ANIMALS:
return mAnimalsArray.get(position);
case CardAdapter.TAB_LANGUAGE:
return mLanguageArray.get(position);
case CardAdapter.TAB_NATURE:
return mNatureArray.get(position);
case CardAdapter.TAB_SPORTS:
return mSportsArray.get(position);
case CardAdapter.TAB_DATING:
return mDatingArray.get(position);
default:
return mMainPageArray.get(position);
}
}

public ParentCard getParentCard(int position){
return parentCardArrayList.get(position);
public void addParentCard(ParentCard parentCard, int TAB){
switch (TAB){
case CardAdapter.TAB_MAINPAGE:
mMainPageArray.add(parentCard);
break;
case CardAdapter.TAB_POLITICS:
mPoliticsArray.add(parentCard);
break;
case CardAdapter.TAB_TECH:
mTechArray.add(parentCard);
break;
case CardAdapter.TAB_CAREER:
mCareerArray.add(parentCard);
break;
case CardAdapter.TAB_FOOD:
mFoodArray.add(parentCard);
break;
case CardAdapter.TAB_DANCING:
mDancingArray.add(parentCard);
break;
case CardAdapter.TAB_ANIMALS:
mAnimalsArray.add(parentCard);
break;
case CardAdapter.TAB_LANGUAGE:
mLanguageArray.add(parentCard);
break;
case CardAdapter.TAB_NATURE:
mNatureArray.add(parentCard);
break;
case CardAdapter.TAB_SPORTS:
mSportsArray.add(parentCard);
break;
case CardAdapter.TAB_DATING:
mDatingArray.add(parentCard);
break;
default:
mMainPageArray.add(parentCard);
}
}

public void addToArrayList(ParentCard parentCard){
parentCardArrayList.add(parentCard);
public static Singleton getInstance() {
return singleton;
}

}