Skip to content

Commit

Permalink
Add empty layout when no hosts found
Browse files Browse the repository at this point in the history
  • Loading branch information
Nilhcem committed May 6, 2013
1 parent ad5cff4 commit bec8085
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 14 deletions.
32 changes: 32 additions & 0 deletions res/layout/list_hosts_empty.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.nilhcem.hostseditor"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >

<com.nilhcem.hostseditor.widget.TypefacedTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="@string/list_empty"
android:textSize="24sp"
app:typeface="fonts/Roboto-Regular.ttf" />

<com.nilhcem.hostseditor.widget.TypefacedTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="@string/list_empty_desc"
android:textSize="12sp"
app:typeface="fonts/Roboto-Italic.ttf" />
</LinearLayout>

</ScrollView>
21 changes: 21 additions & 0 deletions res/layout/list_hosts_fragment.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<!-- Hosts list -->
<ListView
android:id="@+id/listHosts"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<!-- Empty layout -->
<ViewStub
android:id="@+id/listEmptyLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout="@layout/list_hosts_empty"
android:visibility="gone" />

</FrameLayout>
6 changes: 5 additions & 1 deletion res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
<string name="action_add_comment">Add comment</string>
<string name="action_remove_comment">Remove comment</string>

<!-- List host (contextual menu) -->
<!-- List hosts (empty layout) -->
<string name="list_empty">No \'hosts\' records found.</string>
<string name="list_empty_desc">We couldn\'t find any host entry for this device.\nFeel free to add some!</string>

<!-- List hosts (contextual menu) -->
<string name="list_menu_selected">%d selected</string>
<string name="list_menu_edit">Edit</string>
<string name="list_menu_delete">Delete</string>
Expand Down
31 changes: 18 additions & 13 deletions src/com/nilhcem/hostseditor/list/ListHostsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ListView;
import butterknife.InjectView;
import butterknife.Views;

import com.actionbarsherlock.view.ActionMode;
import com.actionbarsherlock.view.Menu;
Expand All @@ -40,10 +42,10 @@ public class ListHostsFragment extends BaseFragment implements OnItemClickListen
private static final String TAG = "ListHostsFragment";

@Inject HostsManager mHostsManager;
@InjectView(R.id.listHosts) ListView mListView;
private ListHostsAdapter mAdapter;

private ActionMode mMode;
private ListView mListView;
private MenuItem mEditMenuItem;

@Override
Expand All @@ -54,19 +56,23 @@ public void onCreate(Bundle savedInstanceState) {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (mListView == null) {
mListView = new ListView(mActivity.getApplicationContext());
mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
mListView.setFastScrollEnabled(true);
mListView.setItemsCanFocus(false);
mListView.setOnItemClickListener(this);
mListView.setOnItemLongClickListener(this);
boolean firstCall = (mListView == null);

View view = inflater.inflate(R.layout.list_hosts_fragment, container, false);
Views.inject(this, view);

mListView.setAdapter(mAdapter);
mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
mListView.setEmptyView(view.findViewById(R.id.listEmptyLayout));
mListView.setFastScrollEnabled(true);
mListView.setItemsCanFocus(false);
mListView.setOnItemClickListener(this);
mListView.setOnItemLongClickListener(this);

if (firstCall) {
refreshHosts(false);
} else {
// detach from container and return the same view
((ViewGroup) mListView.getParent()).removeAllViews();
}
return mListView;
return view;
}

@Override
Expand Down Expand Up @@ -113,7 +119,6 @@ public void onHostsRefreshed(RefreshHostsEvent hosts) {
Log.d(TAG, "Refreshing listview");
finishActionMode();
mAdapter.updateHosts(hosts.get());
mListView.setAdapter(mAdapter);
mBus.post(new LoadingEvent(false));
}

Expand Down

0 comments on commit bec8085

Please sign in to comment.