[and] Progress, empty list, beauty

This commit is contained in:
d-kunin 2013-08-07 11:16:08 +03:00
parent c1d069b9a4
commit 14f8fb3200
11 changed files with 170 additions and 53 deletions

View file

@ -4,7 +4,5 @@
android:name="com.example.travelguide.ArticleInfoListFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
tools:context=".ArticleInfoListActivity"
tools:layout="@android:layout/list_content" />
tools:layout="@layout/fragment_articleinfo_list" />

View file

@ -2,8 +2,6 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:baselineAligned="false"
android:divider="?android:attr/dividerHorizontal"
android:orientation="horizontal"

View file

@ -7,8 +7,9 @@
<LinearLayout
android:id="@+id/searchBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_height="@dimen/search_bar"
android:background="@color/grey"
android:gravity="center_vertical"
android:orientation="horizontal" >
<ImageView
@ -16,31 +17,88 @@
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0"
android:paddingLeft="@dimen/pad_small"
android:paddingRight="@dimen/pad_small"
android:src="@android:drawable/ic_menu_search" />
<EditText
android:id="@+id/searchText"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Enter Search Term"
android:inputType="textCapWords"
android:singleLine="true"
android:textStyle="bold" />
android:layout_margin="@dimen/pad_small"
android:background="@color/dark_grey"
android:gravity="center_vertical" >
<ImageView
android:id="@+id/clearSearch"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0"
android:src="@android:drawable/ic_delete"
android:visibility="gone" />
<EditText
android:id="@+id/searchText"
style="@android:style/TextAppearance.Medium.Inverse"
android:layout_width="match_parent"
android:layout_height="@dimen/search_text"
android:layout_weight="1"
android:background="@null"
android:gravity="center_vertical"
android:hint="Enter Search Term"
android:inputType="textCapWords"
android:paddingLeft="@dimen/pad_small"
android:paddingRight="@dimen/pad_small"
android:singleLine="true"
android:textStyle="bold" />
<ImageView
android:id="@+id/clearSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:src="@android:drawable/ic_delete"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
<include
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
layout="@android:layout/list_content" />
android:layout_weight="0" >
<LinearLayout
android:id="@+id/progressContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone" >
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="4dip"
android:singleLine="true"
android:text="@string/searching"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<FrameLayout
android:id="@+id/listContainer"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false" />
<TextView
android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/nothing_found"
android:textAppearance="?android:attr/textAppearanceLarge" />
</FrameLayout>
</FrameLayout>
</LinearLayout>

View file

@ -1,25 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_height="@dimen/thumb_size"
android:gravity="center_vertical"
android:orientation="horizontal" >
<ImageView
android:id="@+id/thumbnail"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_weight="0"
android:scaleType="centerCrop"
android:src="@drawable/ic_launcher" />
<FrameLayout
android:layout_width="@dimen/thumb_size"
android:layout_height="@dimen/thumb_size"
android:layout_weight="0" >
<TextView
android:id="@+id/title"
style="@android:style/TextAppearance.Medium"
<ImageView
android:id="@+id/thumbnail"
android:layout_width="@dimen/thumb_size"
android:layout_height="@dimen/thumb_size"
android:layout_gravity="center"
android:scaleType="centerCrop"
android:src="@drawable/ic_launcher" />
<View
android:layout_width="match_parent"
android:layout_height="@dimen/thumb_sep"
android:layout_gravity="top"
android:background="@color/thumb_sep" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Hello World!"
android:textStyle="bold" />
android:gravity="center_vertical"
android:orientation="vertical" >
<TextView
android:id="@+id/title"
style="@android:style/TextAppearance.Medium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/pad_mid"
android:text="London"
android:textStyle="bold" />
<TextView
android:id="@+id/parent"
style="@android:style/TextAppearance.Small"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/pad_mid"
android:text="Europe -> UK" />
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="dark_grey">#333333</color>
<color name="grey">#666666</color>
<color name="thumb_sep">#FFFF00</color>
</resources>

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="thumb_size">67dp</dimen>
<dimen name="search_bar">50dp</dimen>
<dimen name="search_text">34dp</dimen>
<dimen name="pad_mid">8dp</dimen>
<dimen name="pad_small">4dp</dimen>
<dimen name="thumb_sep">3dp</dimen>
</resources>

View file

@ -3,5 +3,8 @@
<string name="app_name">TravelGuide</string>
<string name="title_articleinfo_detail">ArticleInfo Detail</string>
<string name="loading">Loading ...</string>
<string name="searching">Searching ...</string>
<string name="nothing_found">Nothing Found</string>
</resources>

View file

@ -1,6 +1,6 @@
package com.example.travelguide;
import static com.example.travelguide.util.Utils.hideIf;
import static com.example.travelguide.util.Utils.*;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
@ -37,6 +37,8 @@ public class ArticleInfoListFragment extends ListFragment implements LoaderCallb
private TextView mSearchText;
private View mCross;
private View mListContainer;
private View mPorgressContainer;
/**
* The serialization (saved instance state) Bundle key representing the
@ -91,6 +93,11 @@ public class ArticleInfoListFragment extends ListFragment implements LoaderCallb
{
super.onViewCreated(view, savedInstanceState);
// Load initial data
final Bundle args = new Bundle(1);
args.putString(KEY_QUERY, "");
getLoaderManager().initLoader(SEARCH_LOADER, args, this).forceLoad();
// Restore the previously serialized activated item position.
if (savedInstanceState != null && savedInstanceState.containsKey(STATE_ACTIVATED_POSITION))
{
@ -110,11 +117,6 @@ public class ArticleInfoListFragment extends ListFragment implements LoaderCallb
}
mCallbacks = (Callbacks) activity;
// Load initial data
final Bundle args = new Bundle(1);
args.putString(KEY_QUERY, "");
getLoaderManager().initLoader(SEARCH_LOADER, args, this).forceLoad();
}
@Override
@ -175,6 +177,8 @@ public class ArticleInfoListFragment extends ListFragment implements LoaderCallb
mSearchText = (TextView) mRootView.findViewById(R.id.searchText);
mCross = mRootView.findViewById(R.id.clearSearch);
mListContainer = mRootView.findViewById(R.id.listContainer);
mPorgressContainer = mRootView.findViewById(R.id.progressContainer);
// setup listeners
mSearchText.addTextChangedListener(this);
mCross.setOnClickListener(this);
@ -183,9 +187,9 @@ public class ArticleInfoListFragment extends ListFragment implements LoaderCallb
}
/**
*
*
* LOADER
*
*
*/
private static int SEARCH_LOADER = 0x1;
@ -198,7 +202,9 @@ public class ArticleInfoListFragment extends ListFragment implements LoaderCallb
{
final String query = args.getString(KEY_QUERY);
// TODO: add location check
// TODO: add progress
hideView(mListContainer);
showView(mPorgressContainer);
return new QueryResultLoader(getActivity(), query);
}
return null;
@ -207,17 +213,23 @@ public class ArticleInfoListFragment extends ListFragment implements LoaderCallb
@Override
public void onLoadFinished(Loader<Storage> loader, Storage result)
{
setListAdapter(new StorageArticleInfoAdapter(result, getActivity()));
hideView(mPorgressContainer);
showView(mListContainer);
}
@Override
public void onLoaderReset(Loader<Storage> loader)
{}
{
hideView(mPorgressContainer);
showView(mListContainer);
}
/**
*
*
* TEXT WATCHER
*
*
*/
@Override
@ -239,9 +251,9 @@ public class ArticleInfoListFragment extends ListFragment implements LoaderCallb
{}
/**
*
*
* CLICK
*
*
*/
@Override

View file

@ -7,6 +7,7 @@ import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.TwoLineListItem;
import com.example.travelguide.R;
import com.example.travelguide.article.ArticleInfo;
@ -65,15 +66,17 @@ public class StorageArticleInfoAdapter extends BaseAdapter
class ViewHolder
{
final TextView mTitle;
final TextView mTitle;
final TextView mParent;
final ImageView mThumbnail;
ArticleInfo mInfo;
ViewHolder(View view)
{
mTitle = (TextView) view.findViewById(R.id.title);
mThumbnail = (ImageView) view.findViewById(R.id.thumbnail);
mTitle = (TextView) view.findViewById(R.id.title);
mParent = (TextView) view.findViewById(R.id.parent);
}
void fill(ArticleInfo info)