Added ListView empty views (depending on current state).

This commit is contained in:
Felix Ableitner 2013-11-21 18:39:07 +01:00
parent d117a56fd4
commit fdf8f9c9c5
5 changed files with 64 additions and 7 deletions

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
@ -7,17 +7,25 @@
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
android:layout_height="wrap_content" >
</ListView>
<TextView
android:id="@id/android:empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dip"
android:text="@string/device_list_empty"
android:layout_centerInParent="true"
android:gravity="center" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:id="@+id/controls"
android:visibility="gone" >
android:visibility="visible" >
<SeekBar
android:id="@+id/progressBar"
@ -51,4 +59,4 @@
</LinearLayout>
</LinearLayout>
</RelativeLayout>

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@id/android:empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dip"
android:text="@string/device_list_empty"
android:layout_centerInParent="true"
android:gravity="center" />
</RelativeLayout>

View file

@ -15,5 +15,8 @@
<string name="warning_wifi_not_connected">Wifi needs to be connected for playback</string>
<string name="auto_enable_wifi">Enable Wifi automatically on start</string>
<string name="dont_show_dialog_again">"Do not show this dialog again"</string>
<string name="device_list_empty">No UPNP devices found. \nNew devices will be added automatically when they are available.</string>
<string name="folder_list_etmpy">Folder is empty</string>
<string name="playlist_empty">Playlist is empty</string>
</resources>

View file

@ -59,6 +59,7 @@ import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.Toast;
@ -149,6 +150,7 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements
mListView.setAdapter(mRouteAdapter);
mListView.setOnItemClickListener(this);
mListView.setOnScrollListener(this);
mListView.setEmptyView(getView().findViewById(android.R.id.empty));
mControls = getView().findViewById(R.id.controls);
mProgressBar = (SeekBar) getView().findViewById(R.id.progressBar);
@ -278,6 +280,8 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements
mMediaRouterPlayService.getService().play(mStartPlayingOnSelect);
mStartPlayingOnSelect = -1;
}
TextView emptyView = (TextView) mListView.getEmptyView();
emptyView.setText(R.string.playlist_empty);
}
else
mMediaRouterPlayService.getService().play(position);
@ -327,6 +331,8 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements
mListView.setAdapter(mRouteAdapter);
disableTrackHighlight();
mSelectedRoute = null;
TextView emptyView = (TextView) mListView.getEmptyView();
emptyView.setText(R.string.device_list_empty);
}
})
.setNegativeButton(android.R.string.no, null)
@ -337,6 +343,8 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements
mListView.setAdapter(mRouteAdapter);
disableTrackHighlight();
mSelectedRoute = null;
TextView emptyView = (TextView) mListView.getEmptyView();
emptyView.setText(R.string.device_list_empty);
}
return true;
}

View file

@ -59,9 +59,13 @@ import android.os.IBinder;
import android.os.Parcelable;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;
import com.github.nutomic.controldlna.R;
import com.github.nutomic.controldlna.gui.MainActivity.OnBackPressedListener;
import com.github.nutomic.controldlna.utility.DeviceArrayAdapter;
import com.github.nutomic.controldlna.utility.FileArrayAdapter;
@ -138,6 +142,13 @@ public class ServerFragment extends ListFragment implements OnBackPressedListene
}
};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.server_fragment, null);
};
/**
* Initializes ListView adapters, launches Cling UPNP service, registers
* wifi state change listener and restores instance state if possible.
@ -207,6 +218,8 @@ public class ServerFragment extends ListFragment implements OnBackPressedListene
setListAdapter(mFileAdapter);
mCurrentServer = mServerAdapter.getItem(position);
getFiles(ROOT_DIRECTORY);
TextView emptyView = (TextView) getListView().getEmptyView();
emptyView.setText(R.string.folder_list_etmpy);
}
else if (getListAdapter() == mFileAdapter) {
if (mFileAdapter.getItem(position) instanceof Container)
@ -297,6 +310,8 @@ public class ServerFragment extends ListFragment implements OnBackPressedListene
setListAdapter(mServerAdapter);
getListView().onRestoreInstanceState(mListState.peek());
mCurrentServer = null;
TextView emptyView = (TextView) getListView().getEmptyView();
emptyView.setText(R.string.device_list_empty);
}
else
getFiles(true);
@ -337,6 +352,8 @@ public class ServerFragment extends ListFragment implements OnBackPressedListene
setListAdapter(mServerAdapter);
getListView().onRestoreInstanceState(mListState.firstElement());
mCurrentServer = null;
TextView emptyView = (TextView) getListView().getEmptyView();
emptyView.setText(R.string.device_list_empty);
}
i--;
}