Skip to content

Commit

Permalink
Create tab pager for repos/users search fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
atermenji committed Jul 30, 2013
1 parent f348374 commit cde7df7
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 10 deletions.
16 changes: 8 additions & 8 deletions app/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

<meta-data
android:name="android.app.default_searchable"
android:value=".ui.repo.RepositorySearchActivity" />
android:value=".ui.search.SearchActivity" />
</activity>
<activity
android:name=".ui.gist.CreateGistActivity"
Expand Down Expand Up @@ -99,18 +99,18 @@
</intent-filter>
</activity>
<activity
android:name=".ui.search.RepositorySearchActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:hardwareAccelerated="true"
android:label="@string/search_title"
android:launchMode="singleTop" >
android:name=".ui.search.SearchActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:hardwareAccelerated="true"
android:label="@string/search_title"
android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>

<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable_repos" />
android:name="android.app.searchable"
android:resource="@xml/searchable_repos" />
</activity>
<activity
android:name=".ui.gist.GistsActivity"
Expand Down
1 change: 1 addition & 0 deletions app/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<string name="issues">Issues</string>
<string name="gists">Gists</string>
<string name="commits">Commits</string>
<string name="global_search">GitHub search</string>
<string name="find_repositories">Find Repositories</string>
<string name="find_issues">Find Issues</string>
<string name="search_title">Search…</string>
Expand Down
2 changes: 1 addition & 1 deletion app/res/xml/searchable_repos.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
limitations under the License.
-->
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:hint="@string/find_repositories"
android:hint="@string/global_search"
android:label="@string/app_name"
android:searchSuggestAuthority="com.github.search.suggest.recent.repos"
android:searchSuggestSelection=" ?"
Expand Down
107 changes: 107 additions & 0 deletions app/src/main/java/com/github/mobile/ui/search/SearchActivity.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,129 @@
/*
* Copyright 2012 GitHub Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.mobile.ui.search;

import static android.app.SearchManager.QUERY;
import static android.content.Intent.ACTION_SEARCH;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP;
import static com.github.mobile.util.TypefaceUtils.ICON_PERSON;
import static com.github.mobile.util.TypefaceUtils.ICON_PUBLIC;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ProgressBar;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.github.kevinsawicki.wishlist.ViewUtils;
import com.github.mobile.R.id;
import com.github.mobile.R.layout;
import com.github.mobile.R.menu;
import com.github.mobile.R.string;
import com.github.mobile.ui.TabPagerActivity;
import com.github.mobile.ui.user.HomeActivity;
import com.github.mobile.util.ToastUtils;

/**
* Activity to view search results
*/
public class SearchActivity extends TabPagerActivity<SearchPagerAdapter> {

private ProgressBar loadingBar;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

loadingBar = finder.find(id.pb_loading);

ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);

handleIntent(getIntent());
}

@Override
public boolean onCreateOptionsMenu(Menu options) {
getSupportMenuInflater().inflate(menu.search, options);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case id.m_search:
onSearchRequested();
return true;
case id.m_clear:
RepositorySearchSuggestionsProvider.clear(this);
ToastUtils.show(this, string.search_history_cleared);
return true;
case android.R.id.home:
Intent intent = new Intent(this, HomeActivity.class);
intent.addFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
}
}

@Override
protected SearchPagerAdapter createAdapter() {
return new SearchPagerAdapter(this);
}

@Override
protected int getContentView() {
return layout.tabbed_progress_pager;
}

@Override
protected String getIcon(int position) {
switch (position) {
case 0:
return ICON_PUBLIC;
case 1:
return ICON_PERSON;
default:
return super.getIcon(position);
}
}

@Override
protected void onNewIntent(Intent intent) {
setIntent(intent);
handleIntent(intent);
}

private void handleIntent(Intent intent) {
if (ACTION_SEARCH.equals(intent.getAction()))
search(intent.getStringExtra(QUERY));
}

private void search(final String query) {
getSupportActionBar().setTitle(query);
RepositorySearchSuggestionsProvider.save(this, query);
configurePager();
}

private void configurePager() {
configureTabPager();
ViewUtils.setGone(loadingBar, true);
setGone(false);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2012 GitHub Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.mobile.ui.search;

import android.content.res.Resources;
Expand Down Expand Up @@ -29,7 +44,7 @@ public SearchPagerAdapter(SherlockFragmentActivity activity) {
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return resources.getString(string.tab_news);
return resources.getString(string.tab_repositories);
case 1:
return resources.getString(string.tab_users);
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.github.mobile.ui.search;

import static android.app.SearchManager.QUERY;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.content.Loader;
Expand Down Expand Up @@ -58,6 +59,13 @@ public void onActivityCreated(Bundle savedInstanceState) {
setEmptyText(string.no_repositories);
}

@Override
public void onAttach(Activity activity) {
super.onAttach(activity);

query = getStringExtra(QUERY);
}

/**
* @param query
* @return this fragment
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2012 GitHub Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.mobile.ui.search;

import android.os.Bundle;
Expand Down

0 comments on commit cde7df7

Please sign in to comment.