[and] Use location for queries.
This commit is contained in:
parent
fe65d3a286
commit
07ac827883
4 changed files with 21 additions and 25 deletions
|
@ -8,6 +8,8 @@
|
|||
android:minSdkVersion="9"
|
||||
android:targetSdkVersion="18" />
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
|
|
|
@ -48,6 +48,7 @@ public class ArticleInfoDetailActivity extends FragmentActivity
|
|||
|
||||
mArticleInfoDetailFragment = new ArticleInfoDetailFragment();
|
||||
mArticleInfoDetailFragment.setArguments(arguments);
|
||||
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.add(R.id.articleinfo_detail_container, mArticleInfoDetailFragment)
|
||||
|
@ -77,7 +78,7 @@ public class ArticleInfoDetailActivity extends FragmentActivity
|
|||
@Override
|
||||
public void onBackPressed()
|
||||
{
|
||||
if (mArticleInfoDetailFragment.canGoBack())
|
||||
if (mArticleInfoDetailFragment != null && mArticleInfoDetailFragment.canGoBack())
|
||||
mArticleInfoDetailFragment.goBack();
|
||||
else
|
||||
super.onBackPressed();
|
||||
|
|
|
@ -101,16 +101,16 @@ public class ArticleInfoDetailFragment extends Fragment implements OnClickListen
|
|||
public void onPageFinished(WebView view, String url)
|
||||
{
|
||||
super.onPageFinished(view, url);
|
||||
hideView(mProgressContainer);
|
||||
showView(mWebView);
|
||||
hideView(mProgressContainer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageStarted(WebView view, String url, Bitmap favicon)
|
||||
{
|
||||
super.onPageStarted(view, url, favicon);
|
||||
hideView(mWebView);
|
||||
showView(mProgressContainer);
|
||||
hideView(mWebView);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,9 @@ import static com.example.travelguide.util.Utils.hideIf;
|
|||
import static com.example.travelguide.util.Utils.hideView;
|
||||
import static com.example.travelguide.util.Utils.showView;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.location.Location;
|
||||
import android.location.LocationManager;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.support.v4.app.LoaderManager.LoaderCallbacks;
|
||||
|
@ -61,6 +64,8 @@ public class ArticleInfoListFragment extends ListFragment implements LoaderCallb
|
|||
private View mProgressContainer;
|
||||
private View mHeader;
|
||||
|
||||
private LocationManager mLocationManager;
|
||||
|
||||
/**
|
||||
* The serialization (saved instance state) Bundle key representing the
|
||||
* activated item position. Only used on tablets.
|
||||
|
@ -114,6 +119,8 @@ public class ArticleInfoListFragment extends ListFragment implements LoaderCallb
|
|||
{
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
mLocationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
|
||||
|
||||
// Load initial data
|
||||
final Bundle args = new Bundle(1);
|
||||
args.putString(KEY_QUERY, "");
|
||||
|
@ -213,12 +220,6 @@ public class ArticleInfoListFragment extends ListFragment implements LoaderCallb
|
|||
hideIf(!visible, mHeader);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* LOADER
|
||||
*
|
||||
*/
|
||||
|
||||
private static int SEARCH_LOADER = 0x1;
|
||||
private String KEY_QUERY = "key_query";
|
||||
|
||||
|
@ -228,11 +229,15 @@ public class ArticleInfoListFragment extends ListFragment implements LoaderCallb
|
|||
if (id == SEARCH_LOADER)
|
||||
{
|
||||
final String query = args.getString(KEY_QUERY);
|
||||
// TODO: add location check
|
||||
hideView(mListContainer);
|
||||
showView(mProgressContainer);
|
||||
hideView(mListContainer);
|
||||
|
||||
return new QueryResultLoader(getActivity(), query);
|
||||
final Location loc = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
|
||||
|
||||
if (loc != null)
|
||||
return new QueryResultLoader(getActivity(), query, loc.getLatitude(), loc.getLongitude());
|
||||
else
|
||||
return new QueryResultLoader(getActivity(), query);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -241,8 +246,8 @@ public class ArticleInfoListFragment extends ListFragment implements LoaderCallb
|
|||
public void onLoadFinished(Loader<Storage> loader, Storage result)
|
||||
{
|
||||
setListAdapter(new StorageArticleInfoAdapter(result, getActivity()));
|
||||
hideView(mProgressContainer);
|
||||
showView(mListContainer);
|
||||
hideView(mProgressContainer);
|
||||
|
||||
if (mFirstLoad && mOnFirstLoad != null && result.getResultSize() > 0)
|
||||
{
|
||||
|
@ -259,12 +264,6 @@ public class ArticleInfoListFragment extends ListFragment implements LoaderCallb
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* TEXT WATCHER
|
||||
*
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count)
|
||||
{
|
||||
|
@ -283,12 +282,6 @@ public class ArticleInfoListFragment extends ListFragment implements LoaderCallb
|
|||
public void beforeTextChanged(CharSequence s, int start, int count, int after)
|
||||
{}
|
||||
|
||||
/**
|
||||
*
|
||||
* CLICK
|
||||
*
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
|
|
Reference in a new issue