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

Commit

Permalink
Merge pull request #76 from mananwason/search1
Browse files Browse the repository at this point in the history
#52 Search functionality completed
  • Loading branch information
creativepsyco committed Aug 19, 2015
2 parents a2324ae + 762ffbf commit f5a62c8
Show file tree
Hide file tree
Showing 49 changed files with 1,097 additions and 173 deletions.
19 changes: 6 additions & 13 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,21 @@
<activity
android:name=".activities.TracksActivity"
android:label="@string/title_section_tracks"/>
<activity
android:name=".activities.LocationActivtiy"
android:label="@string/title_section_location"/>
<activity
android:name=".activities.SpeakersActivity"
android:label="@string/title_section_speakerlist"/>

<activity
android:name=".activities.SearchResultsActivity"
android:label="@string/app_name"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.SEARCH"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
</intent-filter>

android:name=".activities.SessionDetailActivity"
android:label="@string/session">
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable"/>

</activity>
<activity
android:name=".activities.SessionDetailActivity"
android:label="@string/session"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package org.fossasia.openevent.activities;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;

import org.fossasia.openevent.R;
import org.fossasia.openevent.adapters.SessionsListAdapter;
import org.fossasia.openevent.data.Microlocation;
import org.fossasia.openevent.data.Session;
import org.fossasia.openevent.dbutils.DbSingleton;
import org.fossasia.openevent.utils.IntentStrings;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

/**
* Created by MananWason on 8/18/2015.
*/
public class LocationActivtiy extends AppCompatActivity implements SearchView.OnQueryTextListener {
SessionsListAdapter sessionsListAdapter;
private Microlocation selectedLocation;
private List<Session> mSessions;
private RecyclerView sessionRecyclerView;
private String location;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_locations);
DbSingleton dbSingleton = DbSingleton.getInstance();
location = getIntent().getStringExtra(IntentStrings.MICROLOCATIONS);
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_locations);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

try {
selectedLocation = dbSingleton.getLocationByLocationname(location);
} catch (ParseException e) {
e.printStackTrace();
}

sessionRecyclerView = (RecyclerView) findViewById(R.id.recyclerView_locations);
mSessions = dbSingleton.getSessionbyLocationName(location);
sessionsListAdapter = new SessionsListAdapter(mSessions);
sessionRecyclerView.setLayoutManager(new LinearLayoutManager(this));
sessionRecyclerView.setAdapter(sessionsListAdapter);
sessionRecyclerView.setItemAnimator(new DefaultItemAnimator());
}


@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;

}
return super.onOptionsItemSelected(item);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_speakers_activity, menu);
SearchView searchView =
(SearchView) menu.findItem(R.id.search_sessions).getActionView();
searchView.setOnQueryTextListener(this);
return true;
}

@Override
public boolean onQueryTextSubmit(String query) {
return false;
}

@Override
public boolean onQueryTextChange(String query) {
DbSingleton dbSingleton = DbSingleton.getInstance();

mSessions = dbSingleton.getSessionbyLocationName(location);
final List<Session> filteredModelList = filter(mSessions, query);
Log.d("xyz", mSessions.size() + " " + filteredModelList.size());

sessionsListAdapter.animateTo(filteredModelList);
sessionRecyclerView.scrollToPosition(0);
return false;
}

private List<Session> filter(List<Session> sessions, String query) {
query = query.toLowerCase();

final List<Session> filteredTracksList = new ArrayList<>();
for (Session session : sessions) {
final String text = session.getTitle().toLowerCase();
if (text.contains(query)) {
filteredTracksList.add(session);
}
}
return filteredTracksList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
Expand All @@ -40,6 +39,7 @@
import org.fossasia.openevent.events.SponsorDownloadEvent;
import org.fossasia.openevent.events.TracksDownloadEvent;
import org.fossasia.openevent.fragments.BookmarksFragment;
import org.fossasia.openevent.fragments.LocationsFragment;
import org.fossasia.openevent.fragments.SpeakerFragment;
import org.fossasia.openevent.fragments.SponsorsFragment;
import org.fossasia.openevent.fragments.TracksFragment;
Expand Down Expand Up @@ -183,7 +183,6 @@ private void downloadFailed() {
}

private void setupDrawerContent(NavigationView navigationView, final Menu menu) {
final MenuInflater inflater = getMenuInflater();
navigationView.setNavigationItemSelectedListener(
new NavigationView.OnNavigationItemSelectedListener() {
@Override
Expand All @@ -197,25 +196,26 @@ public boolean onNavigationItemSelected(MenuItem menuItem) {
fragmentManager.beginTransaction()
.replace(R.id.content_frame, new TracksFragment()).commit();
getSupportActionBar().setTitle(R.string.menu_tracks);
inflater.inflate(R.menu.menu_tracks, menu);
break;
case R.id.nav_bookmarks:
fragmentManager.beginTransaction()
.replace(R.id.content_frame, new BookmarksFragment()).commit();
getSupportActionBar().setTitle(R.string.menu_bookmarks);
inflater.inflate(R.menu.menu_bookmarks, menu);
break;
case R.id.nav_speakers:
fragmentManager.beginTransaction()
.replace(R.id.content_frame, new SpeakerFragment()).commit();
getSupportActionBar().setTitle(R.string.menu_speakers);
inflater.inflate(R.menu.menu_speakers, menu);
break;
case R.id.nav_sponsors:
fragmentManager.beginTransaction()
.replace(R.id.content_frame, new SponsorsFragment()).commit();
getSupportActionBar().setTitle(R.string.menu_sponsor);
inflater.inflate(R.menu.menu_sponsors, menu);
break;
case R.id.nav_locations:
fragmentManager.beginTransaction()
.replace(R.id.content_frame, new LocationsFragment()).commit();
getSupportActionBar().setTitle(R.string.menu_locations);
break;
case R.id.nav_map:
Bundle latlng = new Bundle();
Expand All @@ -238,7 +238,6 @@ public boolean onNavigationItemSelected(MenuItem menuItem) {
.provideMapModule()
.provideMapFragment()).commit();
getSupportActionBar().setTitle(R.string.menu_map);
inflater.inflate(R.menu.menu_map, menu);
break;
}
mDrawerLayout.closeDrawers();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import android.view.MenuItem;
import android.widget.TextView;

import org.fossasia.openevent.adapters.SpeakersListAdapter;
import org.fossasia.openevent.R;
import org.fossasia.openevent.adapters.SpeakersListAdapter;
import org.fossasia.openevent.data.Session;
import org.fossasia.openevent.data.Speaker;
import org.fossasia.openevent.dbutils.DbSingleton;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,40 @@
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;

import org.fossasia.openevent.adapters.SessionsListAdapter;
import org.fossasia.openevent.R;
import org.fossasia.openevent.adapters.SessionsListAdapter;
import org.fossasia.openevent.data.Session;
import org.fossasia.openevent.data.Speaker;
import org.fossasia.openevent.dbutils.DbSingleton;
import org.fossasia.openevent.utils.SpeakerIntent;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

/**
* Created by MananWason on 30-06-2015.
*/
public class SpeakersActivity extends AppCompatActivity {
public class SpeakersActivity extends AppCompatActivity implements SearchView.OnQueryTextListener{
SessionsListAdapter sessionsListAdapter;
private Speaker selectedSpeaker;


private List<Session> mSessions;
private RecyclerView sessionRecyclerView;
private String speaker;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_speakers);
DbSingleton dbSingleton = DbSingleton.getInstance();
String speaker = getIntent().getStringExtra(Speaker.SPEAKER);
speaker = getIntent().getStringExtra(Speaker.SPEAKER);
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_speakers);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Expand All @@ -60,16 +64,12 @@ protected void onCreate(Bundle savedInstanceState) {
speakerIntent.clickedImage(fb);
speakerIntent.clickedImage(twitter);

RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView_speakers);
try {
List<Session> sessionList = dbSingleton.getSessionbySpeakersName(speaker);
sessionsListAdapter = new SessionsListAdapter(sessionList);
} catch (ParseException e) {
e.printStackTrace();
}
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(sessionsListAdapter);
recyclerView.setItemAnimator(new DefaultItemAnimator());
sessionRecyclerView = (RecyclerView) findViewById(R.id.recyclerView_speakers);
mSessions = dbSingleton.getSessionbySpeakersName(speaker);
sessionsListAdapter = new SessionsListAdapter(mSessions);
sessionRecyclerView.setLayoutManager(new LinearLayoutManager(this));
sessionRecyclerView.setAdapter(sessionsListAdapter);
sessionRecyclerView.setItemAnimator(new DefaultItemAnimator());
}


Expand All @@ -92,6 +92,39 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_speakers_activity, menu);
SearchView searchView =
(SearchView) menu.findItem(R.id.search_sessions).getActionView();
searchView.setOnQueryTextListener(this);
return true;
}

@Override
public boolean onQueryTextSubmit(String query) {
return false;
}

@Override
public boolean onQueryTextChange(String query) {
DbSingleton dbSingleton = DbSingleton.getInstance();

mSessions = dbSingleton.getSessionbySpeakersName(speaker);
final List<Session> filteredModelList = filter(mSessions, query);
Log.d("xyz", mSessions.size() + " " + filteredModelList.size());

sessionsListAdapter.animateTo(filteredModelList);
sessionRecyclerView.scrollToPosition(0);
return false;
}
private List<Session> filter(List<Session> sessions, String query) {
query = query.toLowerCase();

final List<Session> filteredTracksList = new ArrayList<>();
for (Session session : sessions) {
final String text = session.getTitle().toLowerCase();
if (text.contains(query)) {
filteredTracksList.add(session);
}
}
return filteredTracksList;
}
}
Loading

0 comments on commit f5a62c8

Please sign in to comment.