mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-12-22 14:48:23 -05:00
Add UI skeleton for searching
This commit is contained in:
parent
e3651f9e31
commit
5bb4e1a033
@ -11,6 +11,11 @@
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/MinimalBible">
|
||||
|
||||
<meta-data
|
||||
android:name="android.app.searchable"
|
||||
android:resource="@xml/searchable" />
|
||||
|
||||
<activity
|
||||
android:name=".activity.downloader.DownloadActivity"
|
||||
android:label="@string/app_name" />
|
||||
@ -21,11 +26,30 @@
|
||||
<activity
|
||||
android:name=".activity.viewer.BibleViewer"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
|
||||
<!-- Searching is weird - make sure you add the right metadata for each activity.
|
||||
http://stackoverflow.com/a/11704661 -->
|
||||
<meta-data
|
||||
android:name="android.app.default-searchable"
|
||||
android:value=".activity.search.BasicSearch" />
|
||||
</activity>
|
||||
|
||||
<!-- TODO: Launch basic search as singleTop? -->
|
||||
<activity
|
||||
android:name=".activity.search.BasicSearch"
|
||||
android:label="@string/title_activity_search_results">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEARCH" />
|
||||
</intent-filter>
|
||||
<meta-data
|
||||
android:name="android.app.searchable"
|
||||
android:resource="@xml/searchable" />
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
@ -0,0 +1,70 @@
|
||||
package org.bspeice.minimalbible.activity.search;
|
||||
|
||||
import android.app.SearchManager;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.bspeice.minimalbible.Injector;
|
||||
import org.bspeice.minimalbible.MinimalBible;
|
||||
import org.bspeice.minimalbible.OGHolder;
|
||||
import org.bspeice.minimalbible.R;
|
||||
import org.bspeice.minimalbible.activity.BaseActivity;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.ObjectGraph;
|
||||
|
||||
|
||||
public class BasicSearch extends BaseActivity
|
||||
implements Injector {
|
||||
|
||||
@Inject
|
||||
SearchProvider searchProvider;
|
||||
|
||||
private ObjectGraph searchObjGraph;
|
||||
|
||||
private void buildObjGraph() {
|
||||
if (searchObjGraph == null) {
|
||||
OGHolder holder = OGHolder.get(this);
|
||||
searchObjGraph = holder.fetchGraph();
|
||||
if (searchObjGraph == null) {
|
||||
searchObjGraph = MinimalBible.get(this)
|
||||
.plus(new SearchModules());
|
||||
holder.persistGraph(searchObjGraph);
|
||||
}
|
||||
}
|
||||
searchObjGraph.inject(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inject(Object o) {
|
||||
buildObjGraph();
|
||||
searchObjGraph.inject(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_search_results);
|
||||
inject(this);
|
||||
|
||||
handleSearch(getIntent());
|
||||
}
|
||||
|
||||
// Used for launchMode="singleTop"
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
handleSearch(intent);
|
||||
}
|
||||
|
||||
public void handleSearch(Intent intent) {
|
||||
if (!Intent.ACTION_SEARCH.equals(intent.getAction()))
|
||||
return;
|
||||
|
||||
String query = intent.getStringExtra(SearchManager.QUERY);
|
||||
Toast.makeText(this, "Searching for: " + query, Toast.LENGTH_SHORT).show();
|
||||
searchProvider.basicTextSearch(query);
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package org.bspeice.minimalbible.activity.search;
|
||||
|
||||
import org.bspeice.minimalbible.MinimalBibleModules;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
@Module(
|
||||
injects = BasicSearch.class,
|
||||
addsTo = MinimalBibleModules.class
|
||||
)
|
||||
public class SearchModules {
|
||||
|
||||
@Provides
|
||||
SearchProvider searchProvider() {
|
||||
return new SearchProvider();
|
||||
}
|
||||
}
|
@ -1,9 +1,14 @@
|
||||
package org.bspeice.minimalbible.activity.viewer;
|
||||
|
||||
import android.app.SearchManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
import android.support.v7.widget.SearchView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
@ -14,6 +19,7 @@ import org.bspeice.minimalbible.OGHolder;
|
||||
import org.bspeice.minimalbible.R;
|
||||
import org.bspeice.minimalbible.activity.BaseActivity;
|
||||
import org.bspeice.minimalbible.activity.downloader.DownloadActivity;
|
||||
import org.bspeice.minimalbible.activity.search.BasicSearch;
|
||||
import org.bspeice.minimalbible.activity.settings.MinimalBibleSettings;
|
||||
import org.crosswire.jsword.book.Book;
|
||||
|
||||
@ -136,6 +142,21 @@ public class BibleViewer extends BaseActivity implements Injector {
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.viewer, menu);
|
||||
|
||||
// Set up search - most of it is handled by the SearchView itself, but
|
||||
// we do have some work so that it knows which activity to start
|
||||
SearchManager searchManager =
|
||||
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
|
||||
|
||||
// And we can't call getActionView() directly, because it needs API 11+
|
||||
MenuItem item = menu.findItem(R.id.action_search);
|
||||
SearchView searchView = (SearchView) MenuItemCompat.getActionView(item);
|
||||
|
||||
// The Android docs instruct you to set up search in the current activity.
|
||||
// We want the search to actually run elsewhere.
|
||||
ComponentName cN = new ComponentName(this, BasicSearch.class);
|
||||
searchView.setSearchableInfo(searchManager.getSearchableInfo(cN));
|
||||
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,13 @@
|
||||
package org.bspeice.minimalbible.activity.search
|
||||
|
||||
import org.crosswire.jsword.passage.Verse
|
||||
|
||||
/**
|
||||
* This is the entry point for handling the actual bible search. Likely will support
|
||||
* an "advanced" search in the future, but for now, basicTextSearch is what you get.
|
||||
*/
|
||||
class SearchProvider() {
|
||||
|
||||
public fun basicTextSearch(text: String): List<Verse> =
|
||||
listOf()
|
||||
}
|
11
app/src/main/res/layout/activity_search_results.xml
Normal file
11
app/src/main/res/layout/activity_search_results.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context="org.bspeice.minimalbible.activity.search.BasicSearch">
|
||||
|
||||
</RelativeLayout>
|
@ -8,11 +8,12 @@
|
||||
<string name="activity_downloader">Downloads</string>
|
||||
<string name="book_removal_failure">Could not remove, please restart application</string>
|
||||
<string name="action_download_title_categories">Categories</string>
|
||||
|
||||
<string name="error_book_refresh">Error refreshing. Try again later</string>
|
||||
|
||||
<string name="contact_developer_address">bspeice.nc@gmail.com</string>
|
||||
<string name="contact_developer_subject">MinimalBible Feedback</string>
|
||||
<string name="action_search_title">Search</string>
|
||||
<string name="title_activity_search_results">SearchResults</string>
|
||||
<string name="hello_world">Hello world!</string>
|
||||
<string name="action_search_hint">Verse Content</string>
|
||||
|
||||
</resources>
|
||||
|
@ -10,6 +10,8 @@
|
||||
<item name="android:textColor">@color/textColor</item>
|
||||
<!-- Hamburger bar animation -->
|
||||
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
|
||||
<!-- SearchView hint text -->
|
||||
<item name="android:textColorHint">@color/textColorPrimary</item>
|
||||
</style>
|
||||
|
||||
<!-- Almost re-use style from Widget.Holo.Button.Borderless -->
|
||||
|
4
app/src/main/res/xml/searchable.xml
Normal file
4
app/src/main/res/xml/searchable.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:hint="@string/action_search_hint"
|
||||
android:label="@string/app_name" />
|
Loading…
Reference in New Issue
Block a user