Skip to content
This repository was archived by the owner on Oct 9, 2020. It is now read-only.

Commit 762ffbf

Browse files
committed
added location fragment, search sessions by locations
1 parent 7c43bf9 commit 762ffbf

File tree

18 files changed

+627
-2
lines changed

18 files changed

+627
-2
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
<activity
3232
android:name=".activities.TracksActivity"
3333
android:label="@string/title_section_tracks"/>
34+
<activity
35+
android:name=".activities.LocationActivtiy"
36+
android:label="@string/title_section_location"/>
3437
<activity
3538
android:name=".activities.SpeakersActivity"
3639
android:label="@string/title_section_speakerlist"/>
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package org.fossasia.openevent.activities;
2+
3+
import android.os.Bundle;
4+
import android.support.v7.app.AppCompatActivity;
5+
import android.support.v7.widget.DefaultItemAnimator;
6+
import android.support.v7.widget.LinearLayoutManager;
7+
import android.support.v7.widget.RecyclerView;
8+
import android.support.v7.widget.SearchView;
9+
import android.support.v7.widget.Toolbar;
10+
import android.util.Log;
11+
import android.view.Menu;
12+
import android.view.MenuItem;
13+
14+
import org.fossasia.openevent.R;
15+
import org.fossasia.openevent.adapters.SessionsListAdapter;
16+
import org.fossasia.openevent.data.Microlocation;
17+
import org.fossasia.openevent.data.Session;
18+
import org.fossasia.openevent.dbutils.DbSingleton;
19+
import org.fossasia.openevent.utils.IntentStrings;
20+
21+
import java.text.ParseException;
22+
import java.util.ArrayList;
23+
import java.util.List;
24+
25+
/**
26+
* Created by MananWason on 8/18/2015.
27+
*/
28+
public class LocationActivtiy extends AppCompatActivity implements SearchView.OnQueryTextListener {
29+
SessionsListAdapter sessionsListAdapter;
30+
private Microlocation selectedLocation;
31+
private List<Session> mSessions;
32+
private RecyclerView sessionRecyclerView;
33+
private String location;
34+
35+
@Override
36+
protected void onCreate(Bundle savedInstanceState) {
37+
super.onCreate(savedInstanceState);
38+
setContentView(R.layout.activity_locations);
39+
DbSingleton dbSingleton = DbSingleton.getInstance();
40+
location = getIntent().getStringExtra(IntentStrings.MICROLOCATIONS);
41+
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_locations);
42+
setSupportActionBar(toolbar);
43+
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
44+
45+
try {
46+
selectedLocation = dbSingleton.getLocationByLocationname(location);
47+
} catch (ParseException e) {
48+
e.printStackTrace();
49+
}
50+
51+
sessionRecyclerView = (RecyclerView) findViewById(R.id.recyclerView_locations);
52+
mSessions = dbSingleton.getSessionbyLocationName(location);
53+
sessionsListAdapter = new SessionsListAdapter(mSessions);
54+
sessionRecyclerView.setLayoutManager(new LinearLayoutManager(this));
55+
sessionRecyclerView.setAdapter(sessionsListAdapter);
56+
sessionRecyclerView.setItemAnimator(new DefaultItemAnimator());
57+
}
58+
59+
60+
@Override
61+
public boolean onOptionsItemSelected(MenuItem item) {
62+
switch (item.getItemId()) {
63+
case android.R.id.home:
64+
finish();
65+
return true;
66+
67+
}
68+
return super.onOptionsItemSelected(item);
69+
}
70+
71+
72+
@Override
73+
public boolean onCreateOptionsMenu(Menu menu) {
74+
getMenuInflater().inflate(R.menu.menu_speakers_activity, menu);
75+
SearchView searchView =
76+
(SearchView) menu.findItem(R.id.search_sessions).getActionView();
77+
searchView.setOnQueryTextListener(this);
78+
return true;
79+
}
80+
81+
@Override
82+
public boolean onQueryTextSubmit(String query) {
83+
return false;
84+
}
85+
86+
@Override
87+
public boolean onQueryTextChange(String query) {
88+
DbSingleton dbSingleton = DbSingleton.getInstance();
89+
90+
mSessions = dbSingleton.getSessionbyLocationName(location);
91+
final List<Session> filteredModelList = filter(mSessions, query);
92+
Log.d("xyz", mSessions.size() + " " + filteredModelList.size());
93+
94+
sessionsListAdapter.animateTo(filteredModelList);
95+
sessionRecyclerView.scrollToPosition(0);
96+
return false;
97+
}
98+
99+
private List<Session> filter(List<Session> sessions, String query) {
100+
query = query.toLowerCase();
101+
102+
final List<Session> filteredTracksList = new ArrayList<>();
103+
for (Session session : sessions) {
104+
final String text = session.getTitle().toLowerCase();
105+
if (text.contains(query)) {
106+
filteredTracksList.add(session);
107+
}
108+
}
109+
return filteredTracksList;
110+
}
111+
}

app/src/main/java/org/fossasia/openevent/activities/MainActivity.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.fossasia.openevent.events.SponsorDownloadEvent;
4040
import org.fossasia.openevent.events.TracksDownloadEvent;
4141
import org.fossasia.openevent.fragments.BookmarksFragment;
42+
import org.fossasia.openevent.fragments.LocationsFragment;
4243
import org.fossasia.openevent.fragments.SpeakerFragment;
4344
import org.fossasia.openevent.fragments.SponsorsFragment;
4445
import org.fossasia.openevent.fragments.TracksFragment;
@@ -211,6 +212,11 @@ public boolean onNavigationItemSelected(MenuItem menuItem) {
211212
.replace(R.id.content_frame, new SponsorsFragment()).commit();
212213
getSupportActionBar().setTitle(R.string.menu_sponsor);
213214
break;
215+
case R.id.nav_locations:
216+
fragmentManager.beginTransaction()
217+
.replace(R.id.content_frame, new LocationsFragment()).commit();
218+
getSupportActionBar().setTitle(R.string.menu_locations);
219+
break;
214220
case R.id.nav_map:
215221
Bundle latlng = new Bundle();
216222
DbSingleton dbSingleton = DbSingleton.getInstance();
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
package org.fossasia.openevent.adapters;
2+
3+
import android.support.v7.widget.RecyclerView;
4+
import android.view.LayoutInflater;
5+
import android.view.View;
6+
import android.view.ViewGroup;
7+
import android.widget.TextView;
8+
9+
import org.fossasia.openevent.R;
10+
import org.fossasia.openevent.data.Microlocation;
11+
import org.fossasia.openevent.dbutils.DbSingleton;
12+
13+
import java.util.List;
14+
15+
/**
16+
* Created by MananWason on 8/18/2015.
17+
*/
18+
public class LocationsListAdapter extends RecyclerView.Adapter<LocationsListAdapter.Viewholder> {
19+
20+
List<Microlocation> microlocations;
21+
22+
public LocationsListAdapter(List<Microlocation> microlocations) {
23+
this.microlocations = microlocations;
24+
}
25+
26+
@Override
27+
public LocationsListAdapter.Viewholder onCreateViewHolder(ViewGroup parent, int viewType) {
28+
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
29+
View view = layoutInflater.inflate(R.layout.locations_item, parent, false);
30+
Viewholder viewholder = new Viewholder(view);
31+
return viewholder;
32+
}
33+
34+
35+
@Override
36+
public void onBindViewHolder(LocationsListAdapter.Viewholder holder, int position) {
37+
Microlocation current = microlocations.get(position);
38+
holder.name.setText(current.getName());
39+
holder.floor.setText("Floor : " + current.getFloor());
40+
41+
}
42+
43+
@Override
44+
public int getItemCount() {
45+
return microlocations.size();
46+
}
47+
48+
public void refresh() {
49+
50+
DbSingleton dbSingleton = DbSingleton.getInstance();
51+
microlocations.clear();
52+
microlocations = dbSingleton.getMicrolocationsList();
53+
notifyDataSetChanged();
54+
55+
}
56+
57+
public void animateTo(List<Microlocation> microlocations) {
58+
applyAndAnimateRemovals(microlocations);
59+
applyAndAnimateAdditions(microlocations);
60+
applyAndAnimateMovedItems(microlocations);
61+
}
62+
63+
private void applyAndAnimateRemovals(List<Microlocation> newMicrolocations) {
64+
for (int i = microlocations.size() - 1; i >= 0; i--) {
65+
final Microlocation microlocation = microlocations.get(i);
66+
if (!newMicrolocations.contains(microlocation)) {
67+
removeItem(i);
68+
}
69+
}
70+
}
71+
72+
private void applyAndAnimateAdditions(List<Microlocation> newMicrolocations) {
73+
for (int i = 0, count = newMicrolocations.size(); i < count; i++) {
74+
final Microlocation microlocation = newMicrolocations.get(i);
75+
if (!microlocations.contains(microlocation)) {
76+
addItem(i, microlocation);
77+
}
78+
}
79+
}
80+
81+
private void applyAndAnimateMovedItems(List<Microlocation> newMicrolocations) {
82+
for (int toPosition = newMicrolocations.size() - 1; toPosition >= 0; toPosition--) {
83+
final Microlocation microlocation = newMicrolocations.get(toPosition);
84+
final int fromPosition = microlocations.indexOf(microlocation);
85+
if (fromPosition >= 0 && fromPosition != toPosition) {
86+
moveItem(fromPosition, toPosition);
87+
}
88+
}
89+
}
90+
91+
public Microlocation removeItem(int position) {
92+
final Microlocation microlocation = microlocations.remove(position);
93+
notifyItemRemoved(position);
94+
return microlocation;
95+
}
96+
97+
public void addItem(int position, Microlocation microlocation) {
98+
microlocations.add(position, microlocation);
99+
notifyItemInserted(position);
100+
}
101+
102+
public void moveItem(int fromPosition, int toPosition) {
103+
final Microlocation location = microlocations.remove(fromPosition);
104+
microlocations.add(toPosition, location);
105+
notifyItemMoved(fromPosition, toPosition);
106+
}
107+
108+
class Viewholder extends RecyclerView.ViewHolder {
109+
TextView name;
110+
TextView floor;
111+
112+
public Viewholder(View itemView) {
113+
super(itemView);
114+
itemView.setClickable(true);
115+
116+
name = (TextView) itemView.findViewById(R.id.location_name);
117+
floor = (TextView) itemView.findViewById(R.id.location_floor);
118+
119+
}
120+
121+
}
122+
}

0 commit comments

Comments
 (0)