Skip to content

Commit

Permalink
Implemented cinema list structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl26 committed Mar 23, 2017
1 parent f99e22e commit a52e4da
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
package org.example.team_pigeon.movie_pigeon;

import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.Spinner;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
Expand Down Expand Up @@ -62,6 +72,7 @@ public class CinemaFragment extends Fragment implements AdapterView.OnItemSelect
private ArrayList<Cinema> gvCinemas = new ArrayList<>();
private ArrayList<Cinema> sbCinemas = new ArrayList<>();
private ArrayList<Cinema> cathayCinemas = new ArrayList<>();
private ArrayList<Cinema> allCinemas;
private ArrayList<ArrayList<Movie>> oneWeekMovieList;
private ArrayList<Movie> movieList;
private ArrayList<Movie> moviesOfTheDay = new ArrayList<>();
Expand All @@ -73,6 +84,13 @@ public class CinemaFragment extends Fragment implements AdapterView.OnItemSelect
private boolean isCinemasLoaded = false;
private int currentDay;
private TimeUtil timeUtil = new TimeUtil();
private GlobalReceiver receiver;
private final int cinemasLoaded = 1;
private TableLayout cinemaTable;
private ScrollView sv;
private LinearLayout ll;
private CinemaListAdapter cinemaListAdapter;
private ListView cinemaList;


public CinemaFragment() {
Expand All @@ -82,22 +100,73 @@ public CinemaFragment() {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_cinema, container, false);
bindViews(view);
dateList = timeUtil.getDateList();
dateListInString = timeUtil.getDateListToString_MMDDE(dateList);
brands = this.getActivity().getResources().getStringArray(R.array.cinemaBrands);
brandAdapter = new ArrayAdapter<>(this.getActivity(), R.layout.spinner_list_item,brands);
brandSpinner.setAdapter(brandAdapter);
nowShowingTask = new NowShowingTask();
nowShowingTask.execute(GET_CINEMAS);
if(!EventBus.getDefault().isRegistered(this)){
EventBus.getDefault().register(this);
// View view = inflater.inflate(R.layout.fragment_cinema, container, false);
// bindViews(view);
// dateList = timeUtil.getDateList();
// dateListInString = timeUtil.getDateListToString_MMDDE(dateList);
// brands = this.getActivity().getResources().getStringArray(R.array.cinemaBrands);
// brandAdapter = new ArrayAdapter<>(this.getActivity(), R.layout.spinner_list_item,brands);
// brandSpinner.setAdapter(brandAdapter);
// nowShowingTask = new NowShowingTask();
// nowShowingTask.execute(GET_CINEMAS);
// if(!EventBus.getDefault().isRegistered(this)){
// EventBus.getDefault().register(this);
// }
View view = inflater.inflate(R.layout.fragment_cinema_new, container, false);
// sv = (ScrollView) view.findViewById(R.id.cinema_scroll_view);
// ll = (LinearLayout) view.findViewById(R.id.ll);
// cinemaTable = new TableLayout(getContext());
// cinemaTable.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT));
// sv.addView(cinemaTable);
cinemaList = (ListView) view.findViewById(R.id.cinema_list);
if (!isCinemasLoaded) { // make sure cinemaTable is loaded
loadCinemaList();
}
receiver = new GlobalReceiver(new Handler() {
public void handleMessage(Message msg) {
final int what = msg.what;
switch(what) {
case cinemasLoaded:
Log.i(TAG, "Successfully loaded cinemas");
showCinemas();
break;
}
}
});
IntentFilter filter = new IntentFilter();
filter.addAction("cinemasLoaded");
getContext().registerReceiver(receiver, filter);
view.requestFocus();
return view;
}

private void loadCinemaList() {
allCinemas = new ArrayList<>();
nowShowingTask = new NowShowingTask();
nowShowingTask.execute(GET_CINEMAS);
}

@Override
public void onResume(){
super.onResume();
}

@Override
public void onPause() {
super.onPause();
Log.i(TAG, "Cinema fragment paused");
getContext().unregisterReceiver(receiver);
}

private void showCinemas() {
Log.i(TAG, "Preparing to generate cinema table");
// sort cinemas according to distance

// load table rows containing cinema name and distance
cinemaListAdapter = new CinemaListAdapter(allCinemas, getContext());
cinemaList.setAdapter(cinemaListAdapter);
}

private void bindViews(View view) {
brandSpinner = (Spinner) view.findViewById(R.id.spinner_cinema_brand);
outletSpinner = (Spinner) view.findViewById(R.id.spinner_cinema_outlet);
Expand Down Expand Up @@ -303,6 +372,8 @@ protected void onPostExecute(Void params) {
case SUCCESSFUL_CINEMALIST:
Log.i(TAG, "Requset is completed");
isCinemasLoaded = true;
Intent intent = new Intent("cinemasLoaded");
getContext().sendBroadcast(intent);
break;
case SUCCESSFUL_MOVIELIST:
Log.i(TAG,"Request is completed");
Expand Down Expand Up @@ -347,17 +418,18 @@ protected void getCinemas() {
} else {
status = SUCCESSFUL_CINEMALIST;
for (Cinema cinema : cinemas) {
switch (cinema.getProvider()) {
case PROVIDER_CATHAY:
cathayCinemas.add(cinema);
break;
case PROVIDER_GV:
gvCinemas.add(cinema);
break;
case PROVIDER_SB:
sbCinemas.add(cinema);
break;
}
// switch (cinema.getProvider()) {
// case PROVIDER_CATHAY:
// cathayCinemas.add(cinema);
// break;
// case PROVIDER_GV:
// gvCinemas.add(cinema);
// break;
// case PROVIDER_SB:
// sbCinemas.add(cinema);
// break;
// }
allCinemas.add(cinema);
}
}
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.example.team_pigeon.movie_pigeon;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import org.example.team_pigeon.movie_pigeon.models.Cinema;

import java.util.ArrayList;

/**
* Created by Guo Mingxuan on 23/3/2017.
*/

public class CinemaListAdapter extends BaseAdapter {
private ArrayList<Cinema> cinemaList;
private Cinema cinema;
private Context mContext;

public CinemaListAdapter(ArrayList<Cinema> cinemaList, Context context) {
this.cinemaList = cinemaList;
mContext = context;
}
@Override
public int getCount() {
int count = cinemaList.size();
return count;
}

@Override
public Cinema getItem(int position) {
return cinemaList.get(position);
}

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

@Override
public View getView(int position, View convertView, ViewGroup parent) {
cinema = cinemaList.get(position);
convertView = LayoutInflater.from(mContext).inflate(R.layout.cinema_list_item, null);
TextView name = (TextView) convertView.findViewById(R.id.cinema_name);
name.setText(cinema.getName());
TextView distance = (TextView) convertView.findViewById(R.id.cinema_distance);
// TODO set distance
distance.setText("Distance");
return convertView;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class GlobalReceiver extends BroadcastReceiver {
Handler uiHandler;
private final static int VCodeSuccess = 0;
private final static int ResetSuccess = 1;
private final static int changeUsername = 0;
private final static int cinemasLoaded = 1;
private static UserInfoSingleton userInfoBulk = UserInfoSingleton.getInstance();

GlobalReceiver() {
Expand Down Expand Up @@ -98,6 +98,11 @@ public void onReceive(Context context, Intent intent) {
Log.i(TAG, "Received msg to update username");
userInfoBulk.reset();
break;

case "cinemasLoaded":
Log.i(TAG, "Received msg that cinemas loaded");
uiHandler.sendEmptyMessage(cinemasLoaded);
break;
}
}
}
21 changes: 21 additions & 0 deletions frontend/Movie_Pigeon/app/src/main/res/layout/cinema_list_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Testing text"
android:textSize="16sp"
android:padding="5dp"
android:textColor="#000000"
android:id="@+id/cinema_name"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="distance"
android:layout_marginLeft="10dp"
android:id="@+id/cinema_distance"/>
</LinearLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true">
<ListView
android:id="@+id/cinema_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>

0 comments on commit a52e4da

Please sign in to comment.