mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 23:28:42 +03:00
add ExpandableListFragment which is inherits from ExtendedListFragment
Only difference: it uses an ExpandableListView which supports dividing list into groups
This commit is contained in:
parent
4018af1373
commit
37d3a72960
3 changed files with 140 additions and 6 deletions
45
res/layout/list_fragment_expandable.xml
Executable file
45
res/layout/list_fragment_expandable.xml
Executable file
|
@ -0,0 +1,45 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
This must be a clone of list_fragment.xml
|
||||
|
||||
EXCEPT: ExpandableListView must be used for @+id/swipe_refresh_files_emptyView
|
||||
-->
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" >
|
||||
|
||||
<android.support.v4.widget.SwipeRefreshLayout
|
||||
android:id="@+id/swipe_refresh_files"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<ExpandableListView
|
||||
android:id="@+id/list_root"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
|
||||
<android.support.v4.widget.SwipeRefreshLayout
|
||||
android:id="@+id/swipe_refresh_files_emptyView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:visibility="gone" >
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/empty_list_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical|center_horizontal"
|
||||
android:text="@string/empty"
|
||||
android:layout_gravity="center"
|
||||
android:visibility="visible" />
|
||||
|
||||
</ScrollView>
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
</FrameLayout>
|
89
src/com/owncloud/android/ui/fragment/ExpandableListFragment.java
Executable file
89
src/com/owncloud/android/ui/fragment/ExpandableListFragment.java
Executable file
|
@ -0,0 +1,89 @@
|
|||
/* ownCloud Android client application
|
||||
* Copyright (C) 2012 Bartek Przybylski
|
||||
* Copyright (C) 2012-2013 ownCloud Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.owncloud.android.ui.fragment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.ExpandableListAdapter;
|
||||
import android.widget.ExpandableListView;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.actionbarsherlock.app.SherlockFragment;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.ui.ExtendedListView;
|
||||
import com.owncloud.android.ui.activity.OnEnforceableRefreshListener;
|
||||
|
||||
/**
|
||||
* Extending ExtendedListFragment. This allows dividing list in groups.
|
||||
*/
|
||||
public class ExpandableListFragment extends ExtendedListFragment
|
||||
{
|
||||
|
||||
protected ExpandableListView mList;
|
||||
|
||||
public void setListAdapter(ExpandableListAdapter listAdapter) {
|
||||
mList.setAdapter(listAdapter);
|
||||
mList.invalidate();
|
||||
}
|
||||
|
||||
public ExpandableListView getListView() {
|
||||
return mList;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
Log_OC.e(TAG, "onCreateView");
|
||||
|
||||
View v = inflater.inflate(R.layout.list_fragment_expandable, null);
|
||||
mEmptyListMessage = (TextView) v.findViewById(R.id.empty_list_view);
|
||||
mList = (ExpandableListView)(v.findViewById(R.id.list_root));
|
||||
mList.setOnItemClickListener(this);
|
||||
|
||||
mList.setDivider(getResources().getDrawable(R.drawable.uploader_list_separator));
|
||||
mList.setDividerHeight(1);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
int referencePosition = savedInstanceState.getInt(KEY_SAVED_LIST_POSITION);
|
||||
setReferencePosition(referencePosition);
|
||||
}
|
||||
|
||||
// Pull down refresh
|
||||
mRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.swipe_refresh_files);
|
||||
mRefreshEmptyLayout = (SwipeRefreshLayout) v.findViewById(R.id.swipe_refresh_files_emptyView);
|
||||
|
||||
onCreateSwipeToRefresh(mRefreshLayout);
|
||||
onCreateSwipeToRefresh(mRefreshEmptyLayout);
|
||||
|
||||
mList.setEmptyView(mRefreshEmptyLayout);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
}
|
|
@ -43,9 +43,9 @@ import com.owncloud.android.ui.activity.OnEnforceableRefreshListener;
|
|||
public class ExtendedListFragment extends SherlockFragment
|
||||
implements OnItemClickListener, OnEnforceableRefreshListener {
|
||||
|
||||
private static final String TAG = ExtendedListFragment.class.getSimpleName();
|
||||
protected static final String TAG = ExtendedListFragment.class.getSimpleName();
|
||||
|
||||
private static final String KEY_SAVED_LIST_POSITION = "SAVED_LIST_POSITION";
|
||||
protected static final String KEY_SAVED_LIST_POSITION = "SAVED_LIST_POSITION";
|
||||
private static final String KEY_INDEXES = "INDEXES";
|
||||
private static final String KEY_FIRST_POSITIONS= "FIRST_POSITIONS";
|
||||
private static final String KEY_TOPS = "TOPS";
|
||||
|
@ -54,9 +54,9 @@ implements OnItemClickListener, OnEnforceableRefreshListener {
|
|||
|
||||
protected ExtendedListView mList;
|
||||
|
||||
private SwipeRefreshLayout mRefreshLayout;
|
||||
private SwipeRefreshLayout mRefreshEmptyLayout;
|
||||
private TextView mEmptyListMessage;
|
||||
protected SwipeRefreshLayout mRefreshLayout;
|
||||
protected SwipeRefreshLayout mRefreshEmptyLayout;
|
||||
protected TextView mEmptyListMessage;
|
||||
|
||||
// Save the state of the scroll in browsing
|
||||
private ArrayList<Integer> mIndexes;
|
||||
|
@ -293,7 +293,7 @@ implements OnItemClickListener, OnEnforceableRefreshListener {
|
|||
return (mEmptyListMessage != null) ? mEmptyListMessage.getText().toString() : "";
|
||||
}
|
||||
|
||||
private void onCreateSwipeToRefresh(SwipeRefreshLayout refreshLayout) {
|
||||
protected void onCreateSwipeToRefresh(SwipeRefreshLayout refreshLayout) {
|
||||
// Colors in animations: background
|
||||
refreshLayout.setColorScheme(R.color.background_color, R.color.background_color, R.color.background_color,
|
||||
R.color.background_color);
|
||||
|
|
Loading…
Reference in a new issue