Skip to content

Commit

Permalink
Merge pull request #17 from CSGHackathon/android
Browse files Browse the repository at this point in the history
Finished the app
  • Loading branch information
mcasper3 committed Feb 27, 2016
2 parents 9bc1f34 + 2589895 commit d80f963
Show file tree
Hide file tree
Showing 39 changed files with 1,047 additions and 56 deletions.
2 changes: 1 addition & 1 deletion android/AndroidClient/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ dependencies {
compile 'de.hdodenhof:circleimageview:2.0.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'se.emilsjolander:stickylistheaders:2.7.0'
compile 'com.android.support:support-v13:22.2.1'
compile 'com.android.support:support-v4:22.2.1'
}
9 changes: 9 additions & 0 deletions android/AndroidClient/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
android:name=".AddFavoriteActivity"
android:label="@string/title_activity_add_favorite" >
</activity>
<activity
android:name=".ViewFavoriteActivity"
android:label="@string/title_activity_view_favorite" >
</activity>
<activity
android:name=".WatchContentActivity"
android:screenOrientation="landscape"
android:label="@string/title_activity_watch_content" >
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public class Constants {
private Constants() { }

public static final String IS_TEAM = "isTeam";
public static final String TEAM = "team";
public static final String SHOW = "show";
public static final String NAME = "name";
public static final String ID = "id";
public static final String NOTIFICATIONS = "notifications";
public static final String URI = "uri";
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.ScrollView;
import android.widget.TextView;

import com.squareup.otto.Subscribe;
Expand Down Expand Up @@ -58,6 +60,11 @@ public void onClick(View view) {

private void attemptLogin() {
apiCaller.obtainData(new GetUserRequest(2));
ScrollView loginView = (ScrollView) findViewById(R.id.login_form);
loginView.setVisibility(View.GONE);

ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress);
progressBar.setVisibility(View.VISIBLE);
}

@Override
Expand All @@ -77,6 +84,9 @@ public void onUserObtained(GetUserResponse response) {
((SwagApplication) getApplication()).setUser(response.getUser());

Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,14 @@ public void onPageScrolled(int position, float positionOffset, int positionOffse
public void onPageSelected(int position) {
// TODO make an animation
if (position == 0) {
mFab.setVisibility(View.VISIBLE);
} else {
mFab.setVisibility(View.GONE);
mFab.show();
setTitle("Favorites");
} else if (position == 1) {
mFab.hide();
setTitle("Events");
} else if (position == 2) {
mFab.hide();
setTitle("Account Settings");
}
}

Expand All @@ -76,8 +81,17 @@ public void onClick(View view) {
}
});

setTitle("Favorites");
}

@Override
public void onBackPressed() {
if (mViewPager.getCurrentItem() != 0) {
mViewPager.setCurrentItem(0);
} else {
super.onBackPressed();
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.swagoverflow.androidclient;

import android.content.Intent;
import android.os.Bundle;
import android.app.Activity;
import android.widget.Switch;

public class ViewFavoriteActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_favorite);

handleIntent(getIntent());
}

private void handleIntent(Intent intent) {
boolean isTeam = intent.getBooleanExtra(Constants.IS_TEAM, false);
boolean notifications = intent.getBooleanExtra(Constants.NOTIFICATIONS, true);

Switch notificationsEnabled = (Switch) findViewById(R.id.notificationEnabled);
notificationsEnabled.setChecked(notifications);

if (isTeam) {
// TODO get team info
} else {
// TODO get show info
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.swagoverflow.androidclient;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.widget.MediaController;
import android.widget.VideoView;

public class WatchContentActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_watch_content);

Intent intent = getIntent();
String uri = intent.getStringExtra(Constants.URI);

VideoView videoView = (VideoView) findViewById(R.id.videoView);
videoView.setMediaController(new MediaController(this));
videoView.setVideoURI(Uri.parse(uri));
videoView.requestFocus();
videoView.start();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package com.swagoverflow.androidclient.adapters;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.SectionIndexer;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.swagoverflow.androidclient.R;
import com.swagoverflow.androidclient.models.Episode;
import com.swagoverflow.androidclient.models.Game;
import com.swagoverflow.androidclient.utilities.Utility;

import java.text.SimpleDateFormat;
import java.util.List;

import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter;

/**
* Created by Mike on 2/27/2016.
*/
public class EventListAdapter extends BaseAdapter implements StickyListHeadersAdapter, SectionIndexer {

private Activity context;
private List<Game> games;
private List<Episode> episodes;
private String[] mSections = new String[] { "Games", "Episodes" };

public EventListAdapter(Activity context, List<Game> games, List<Episode> episodes) {
this.context = context;
this.games = games;
this.episodes = episodes;
}

@Override
public View getHeaderView(int position, View convertView, ViewGroup parent) {
HeaderViewHolder holder;

if (convertView == null) {
holder = new HeaderViewHolder();
convertView = LayoutInflater.from(context).inflate(R.layout.header, parent, false);
holder.textView = (TextView) convertView.findViewById(R.id.title);
convertView.setTag(holder);
} else {
holder = (HeaderViewHolder) convertView.getTag();
}

if (position < games.size()) {
holder.textView.setText(mSections[0]);
} else {
holder.textView.setText(mSections[1]);
}

return convertView;
}

@Override
public long getHeaderId(int position) {
if (position < games.size()) {
return 0;
} else {
return 1;
}
}

@Override
public int getCount() {
return games.size() + episodes.size() + 1;
}

@Override
public Object getItem(int i) {
if (i < games.size()) {
return games.get(i);
} else if (i < episodes.size() + games.size()) {
return episodes.get(i - games.size());
}

return null;
}

@Override
public long getItemId(int i) {
return 0;
}

@Override
public View getView(int position, View v, ViewGroup parent) {
View view = LayoutInflater.from(context).inflate(R.layout.layout_event, parent, false);

ImageView thumbnail = (ImageView) view.findViewById(R.id.thumbnail);
TextView name = (TextView) view.findViewById(R.id.name);
TextView date = (TextView) view.findViewById(R.id.date);
TextView channel = (TextView) view.findViewById(R.id.channel);

SimpleDateFormat sdf = new SimpleDateFormat("EEE, MMM d 'at' h:mm a");

if (position < games.size()) {
Game game = games.get(position);
Picasso.with(context).load(game.getThumbnailUrl()).into(thumbnail);
name.setText(game.getDescription());
date.setText(sdf.format(game.getDate()));
channel.setText(game.getChannel());
} else if (position < games.size() + episodes.size()) {
Episode episode = episodes.get(position - games.size());
Picasso.with(context).load(episode.getThumbnailUrl()).into(thumbnail);
name.setText(episode.getShow().getName());
date.setText(sdf.format(episode.getDate()));
channel.setText(episode.getChannel());
} else {
view.setMinimumHeight(Utility.convertDpToPx(context.getWindowManager().getDefaultDisplay(), 10));
}

return view;
}

@Override
public Object[] getSections() {
return mSections;
}

@Override
public int getPositionForSection(int i) {
if (games.size() == 0 && episodes.size() == 0) {
return 0;
}

if (i <= 0) {
return 0;
} else {
return games.size();
}
}

@Override
public int getSectionForPosition(int i) {
return 0;
}

class HeaderViewHolder {
TextView textView;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@

import com.squareup.picasso.Picasso;
import com.swagoverflow.androidclient.R;
import com.swagoverflow.androidclient.SwagApplication;
import com.swagoverflow.androidclient.api.IApiCaller;
import com.swagoverflow.androidclient.api.requests.DeleteFavoriteShowRequest;
import com.swagoverflow.androidclient.api.requests.DeleteFavoriteTeamRequest;
import com.swagoverflow.androidclient.models.Show;
import com.swagoverflow.androidclient.models.ShowFavorite;
import com.swagoverflow.androidclient.models.Team;
import com.swagoverflow.androidclient.models.TeamFavorite;
import com.swagoverflow.androidclient.models.User;
import com.swagoverflow.androidclient.utilities.Utility;

import java.util.List;
Expand All @@ -28,11 +33,13 @@ public class PreferenceListAdapter extends BaseAdapter implements StickyListHead
private List<ShowFavorite> shows;
private Activity activity;
private String[] mSections;
private IApiCaller apiCaller;

public PreferenceListAdapter(Activity activity, List<TeamFavorite> teams, List<ShowFavorite> shows) {
public PreferenceListAdapter(Activity activity, List<TeamFavorite> teams, List<ShowFavorite> shows, IApiCaller apiCaller) {
this.teams = teams;
this.shows = shows;
this.activity = activity;
this.apiCaller = apiCaller;

mSections = new String[] { "Teams", "Shows" };
}
Expand All @@ -59,31 +66,33 @@ public long getItemId(int i) {
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
public View getView(final int position, View convertView, ViewGroup parent) {
View view = LayoutInflater.from(activity).inflate(R.layout.layout_preference_item, parent, false);

ImageView logo = (ImageView) view.findViewById(R.id.logo);
TextView name = (TextView) view.findViewById(R.id.name);
ImageView delete = (ImageView) view.findViewById(R.id.delete);

final User user = ((SwagApplication) activity.getApplication()).getUser();

if (position < teams.size()) {
Team team = teams.get(position).getTeam();
final Team team = teams.get(position).getTeam();
Picasso.with(activity).load(team.getImageUrl()).into(logo);
name.setText(team.getName());
delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.i("AS", "delete clicked");
apiCaller.obtainData(new DeleteFavoriteTeamRequest(user.getId(), teams.get(position).getId()));
}
});
} else if (position < teams.size() + shows.size()) {
Show show = shows.get(position - teams.size()).getShow();
final Show show = shows.get(position - teams.size()).getShow();
Picasso.with(activity).load(show.getImageUrl()).into(logo);
name.setText(show.getName());
delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.i("AS", "delete clicked");
apiCaller.obtainData(new DeleteFavoriteShowRequest(user.getId(), shows.get(position - teams.size()).getId()));
}
});
} else {
Expand Down
Loading

0 comments on commit d80f963

Please sign in to comment.