mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 17:46:37 +03:00
fix on click handler
added on long click handler
This commit is contained in:
parent
eaab185720
commit
397dd7b5b2
4 changed files with 176 additions and 26 deletions
|
@ -1,7 +1,5 @@
|
|||
package com.owncloud.android.ui.activity;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
|
@ -10,16 +8,14 @@ import com.actionbarsherlock.view.Menu;
|
|||
import com.actionbarsherlock.view.MenuInflater;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.authentication.AccountUtils;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.db.UploadDbHandler;
|
||||
import com.owncloud.android.db.UploadDbObject;
|
||||
import com.owncloud.android.db.UploadDbHandler.UploadStatus;
|
||||
import com.owncloud.android.db.UploadDbObject;
|
||||
import com.owncloud.android.files.services.FileUploadService;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.ui.errorhandling.ExceptionHandler;
|
||||
import com.owncloud.android.ui.fragment.UploadListFragment;
|
||||
import com.owncloud.android.utils.FileStorageUtils;
|
||||
|
||||
/**
|
||||
* Activity listing pending, active, and completed uploads. User can delete
|
||||
|
@ -47,7 +43,7 @@ public class UploadListActivity extends FileActivity implements UploadListFragme
|
|||
* TODO Without a menu this is a little un-intuitive.
|
||||
*/
|
||||
@Override
|
||||
public void onUploadItemClick(UploadDbObject file) {
|
||||
public boolean onUploadItemClick(UploadDbObject file) {
|
||||
OCFile ocFile = file.getOCFile();
|
||||
switch (file.getUploadStatus()) {
|
||||
case UPLOAD_IN_PROGRESS:
|
||||
|
@ -77,13 +73,7 @@ public class UploadListActivity extends FileActivity implements UploadListFragme
|
|||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getInitialFilter() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -112,6 +102,12 @@ public class UploadListActivity extends FileActivity implements UploadListFragme
|
|||
inflater.inflate(R.menu.upload_list_menu, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onUploadItemLongClick(UploadDbObject file) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -239,7 +239,7 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
|
|||
|
||||
@Override
|
||||
public long getChildId(int groupPosition, int childPosition) {
|
||||
return groupPosition * 1000l + childPosition;
|
||||
return childPosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -291,6 +291,6 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
|
|||
|
||||
@Override
|
||||
public boolean isChildSelectable(int groupPosition, int childPosition) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,32 +18,28 @@
|
|||
|
||||
package com.owncloud.android.ui.fragment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.AdapterView.OnItemLongClickListener;
|
||||
import android.widget.ExpandableListAdapter;
|
||||
import android.widget.ExpandableListView;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ExpandableListView.OnChildClickListener;
|
||||
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
|
||||
public class ExpandableListFragment extends ExtendedListFragment implements OnChildClickListener, OnItemLongClickListener
|
||||
{
|
||||
protected static final String TAG = ExpandableListFragment.class.getSimpleName();
|
||||
|
||||
protected ExpandableListView mList;
|
||||
|
||||
|
@ -56,7 +52,6 @@ public class ExpandableListFragment extends ExtendedListFragment
|
|||
return mList;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
Log_OC.e(TAG, "onCreateView");
|
||||
|
@ -64,7 +59,8 @@ public class ExpandableListFragment extends ExtendedListFragment
|
|||
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.setOnChildClickListener(this);
|
||||
mList.setOnItemLongClickListener(this);
|
||||
|
||||
mList.setDivider(getResources().getDrawable(R.drawable.uploader_list_separator));
|
||||
mList.setDividerHeight(1);
|
||||
|
@ -86,4 +82,18 @@ public class ExpandableListFragment extends ExtendedListFragment
|
|||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
|
||||
// to be @overriden
|
||||
Log_OC.e(TAG, "onChildClick(). This method should be overriden!");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
// to be @overriden
|
||||
Log_OC.e(TAG, "onItemLongClick(). This method should be overriden!");
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
144
src/com/owncloud/android/ui/fragment/UploadListFragment.java
Executable file
144
src/com/owncloud/android/ui/fragment/UploadListFragment.java
Executable file
|
@ -0,0 +1,144 @@
|
|||
/* ownCloud Android client application
|
||||
* Copyright (C) 2011 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 android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.BaseExpandableListAdapter;
|
||||
import android.widget.ExpandableListView;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.owncloud.android.db.UploadDbObject;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.ui.adapter.ExpandableUploadListAdapter;
|
||||
|
||||
/**
|
||||
* A Fragment that lists all files and folders in a given LOCAL path.
|
||||
*
|
||||
* @author LukeOwncloud
|
||||
*
|
||||
*/
|
||||
public class UploadListFragment extends ExpandableListFragment {
|
||||
static private String TAG = "UploadListFragment";
|
||||
|
||||
/**
|
||||
* Reference to the Activity which this fragment is attached to. For
|
||||
* callbacks
|
||||
*/
|
||||
private UploadListFragment.ContainerActivity mContainerActivity;
|
||||
|
||||
BaseExpandableListAdapter mAdapter;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View v = super.onCreateView(inflater, container, savedInstanceState);
|
||||
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
try {
|
||||
mContainerActivity = (ContainerActivity) activity;
|
||||
} catch (ClassCastException e) {
|
||||
throw new ClassCastException(activity.toString() + " must implement "
|
||||
+ UploadListFragment.ContainerActivity.class.getSimpleName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
Log_OC.d(TAG, "onActivityCreated() start");
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
mAdapter = new ExpandableUploadListAdapter(getActivity());
|
||||
setListAdapter(mAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
|
||||
boolean handled = false;
|
||||
UploadDbObject uploadDbObject = (UploadDbObject) mAdapter.getChild(groupPosition, childPosition);
|
||||
if (uploadDbObject != null) {
|
||||
// notify the click to container Activity
|
||||
handled = mContainerActivity.onUploadItemClick(uploadDbObject);
|
||||
} else {
|
||||
Log_OC.w(TAG, "Null object in ListAdapter!!");
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
Log_OC.d(TAG, "onItemLongClick() position: " + position + " id: " + id);
|
||||
int itemType = ExpandableListView.getPackedPositionType(id);
|
||||
|
||||
if (itemType == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
|
||||
int childPosition = ExpandableListView.getPackedPositionChild(id);
|
||||
int groupPosition = ExpandableListView.getPackedPositionGroup(id);
|
||||
UploadDbObject uploadDbObject = (UploadDbObject) mAdapter.getChild(groupPosition, childPosition);
|
||||
if (uploadDbObject != null) {
|
||||
return mContainerActivity.onUploadItemLongClick(uploadDbObject);
|
||||
} else {
|
||||
Log_OC.w(TAG, "Null object in ListAdapter!!");
|
||||
}
|
||||
} else if (itemType == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
|
||||
// clicked on group header. ignore.
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface to implement by any Activity that includes some instance of
|
||||
* UploadListFragment
|
||||
*
|
||||
* @author LukeOwncloud
|
||||
*/
|
||||
public interface ContainerActivity {
|
||||
|
||||
/**
|
||||
* Callback method invoked when an upload item is clicked by the user on
|
||||
* the upload list
|
||||
*
|
||||
* @param file
|
||||
* @return return true if click was handled.
|
||||
*/
|
||||
public boolean onUploadItemClick(UploadDbObject file);
|
||||
|
||||
/**
|
||||
* Callback method invoked when an upload item is long clicked by the user on
|
||||
* the upload list
|
||||
*
|
||||
* @param file
|
||||
* @return return true if click was handled.
|
||||
*/
|
||||
public boolean onUploadItemLongClick(UploadDbObject file);
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue