mirror of
https://github.com/nextcloud/android.git
synced 2024-11-28 18:28:59 +03:00
some file list handling, action bar added
This commit is contained in:
parent
7d93f30346
commit
6deca0f9b1
7 changed files with 136 additions and 41 deletions
|
@ -25,7 +25,7 @@
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
|
||||||
|
|
||||||
<application android:icon="@drawable/icon" android:label="@string/app_name">
|
<application android:icon="@drawable/icon" android:label="@string/app_name">
|
||||||
<activity android:name=".ui.activity.FileDisplayActivity"></activity>
|
<activity android:name=".ui.activity.FileDisplayActivity" android:theme="@style/Theme.ownCloud" android:label="@string/app_name"></activity>
|
||||||
<activity android:name=".Uploader">
|
<activity android:name=".Uploader">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.SEND"></action>
|
<action android:name="android.intent.action.SEND"></action>
|
||||||
|
|
|
@ -5,14 +5,6 @@
|
||||||
android:background="#F7F7F7"
|
android:background="#F7F7F7"
|
||||||
android:orientation="vertical" >
|
android:orientation="vertical" >
|
||||||
|
|
||||||
<fragment
|
|
||||||
android:id="@+id/actionBar"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
class="eu.alefzero.owncloud.ui.fragment.ActionBar">
|
|
||||||
<!-- Preview: layout=@layout/action_bar -->
|
|
||||||
</fragment>
|
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/fileList"
|
android:id="@+id/fileList"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
|
|
|
@ -11,14 +11,6 @@
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:orientation="vertical" >
|
android:orientation="vertical" >
|
||||||
|
|
||||||
<fragment
|
|
||||||
android:id="@+id/actionBar"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
class="eu.alefzero.owncloud.ui.fragment.ActionBar">
|
|
||||||
<!-- Preview: layout=@layout/action_bar -->
|
|
||||||
</fragment>
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/linearLayout2"
|
android:id="@+id/linearLayout2"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
|
|
|
@ -11,9 +11,8 @@
|
||||||
<style name="ocActionBarTextStyle">
|
<style name="ocActionBarTextStyle">
|
||||||
<item name="android:textColor">#ffffff</item>
|
<item name="android:textColor">#ffffff</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- PopDownMenu -->
|
<!-- PopDownMenu -->
|
||||||
<style name="Animations.PopDownMenu" />
|
<style name="Animations.PopDownMenu" />
|
||||||
|
|
||||||
|
|
38
src/eu/alefzero/owncloud/ui/FragmentListView.java
Normal file
38
src/eu/alefzero/owncloud/ui/FragmentListView.java
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
package eu.alefzero.owncloud.ui;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.ListAdapter;
|
||||||
|
import android.widget.ListView;
|
||||||
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
|
|
||||||
|
public class FragmentListView extends Fragment implements OnItemClickListener {
|
||||||
|
ListView mList;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
mList = new ListView(getActivity());
|
||||||
|
mList.setOnItemClickListener(this);
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setListAdapter(ListAdapter listAdapter) {
|
||||||
|
mList.setAdapter(listAdapter);
|
||||||
|
mList.invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
|
return mList;
|
||||||
|
//return super.onCreateView(inflater, container, savedInstanceState);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -30,14 +30,17 @@ import android.accounts.AccountManager;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.ListActivity;
|
import android.app.ListActivity;
|
||||||
|
import android.app.ActionBar.OnNavigationListener;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.DialogInterface.OnCancelListener;
|
import android.content.DialogInterface.OnCancelListener;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
import android.database.DataSetObserver;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Matrix;
|
import android.graphics.Matrix;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
@ -49,9 +52,13 @@ import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
import android.widget.Spinner;
|
||||||
|
import android.widget.SpinnerAdapter;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import eu.alefzero.owncloud.R;
|
import eu.alefzero.owncloud.R;
|
||||||
import eu.alefzero.owncloud.R.id;
|
import eu.alefzero.owncloud.R.id;
|
||||||
|
@ -70,25 +77,42 @@ import eu.alefzero.owncloud.ui.fragment.ActionBar;
|
||||||
* @author Bartek Przybylski
|
* @author Bartek Przybylski
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class FileDisplayActivity extends FragmentActivity {
|
|
||||||
|
public class FileDisplayActivity extends android.support.v4.app.FragmentActivity implements OnNavigationListener {
|
||||||
private DbHandler mDBHandler;
|
private DbHandler mDBHandler;
|
||||||
private Stack<String> mParents;
|
private Stack<String> mParents;
|
||||||
private LinkedList<String> mPath;
|
private LinkedList<String> mPath;
|
||||||
private Account mAccount;
|
private Account mAccount;
|
||||||
private Cursor mCursor;
|
private Cursor mCursor;
|
||||||
private boolean mIsDisplayingFile;
|
private boolean mIsDisplayingFile;
|
||||||
|
private ArrayAdapter<String> mDirectories;
|
||||||
|
private FileList mFileList;
|
||||||
|
|
||||||
private static final int DIALOG_CHOOSE_ACCOUNT = 0;
|
private static final int DIALOG_CHOOSE_ACCOUNT = 0;
|
||||||
|
|
||||||
|
public void pushPath(String path) {
|
||||||
|
mDirectories.insert(path, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean popPath() {
|
||||||
|
mDirectories.remove(mDirectories.getItem(0));
|
||||||
|
Log.d("TAG", ""+getActionBar().getCustomView());
|
||||||
|
return !mDirectories.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
|
mDirectories = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item);
|
||||||
|
mDirectories.add("/");
|
||||||
|
mFileList = new FileList();
|
||||||
setContentView(R.layout.files);
|
setContentView(R.layout.files);
|
||||||
|
getActionBar().setNavigationMode(android.support.v4.app.ActionBar.NAVIGATION_MODE_LIST);
|
||||||
|
getActionBar().setDisplayShowTitleEnabled(false);
|
||||||
|
getActionBar().setListNavigationCallbacks(mDirectories, this);
|
||||||
|
|
||||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||||
//ft.add(R.id.actionBar, new ActionBar());
|
ft.add(R.id.fileList, mFileList);
|
||||||
ft.add(R.id.fileList, new FileList());
|
|
||||||
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||||
ft.add(R.id.fileDetail, new FileDetail());
|
ft.add(R.id.fileDetail, new FileDetail());
|
||||||
}
|
}
|
||||||
|
@ -344,6 +368,25 @@ public class FileDisplayActivity extends FragmentActivity {
|
||||||
// setListAdapter(new FileListListAdapter(mCursor, this));
|
// setListAdapter(new FileListListAdapter(mCursor, this));
|
||||||
// getListView().invalidate();
|
// getListView().invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
|
||||||
|
int i = itemPosition;
|
||||||
|
while (i-- != 0) {
|
||||||
|
popPath();
|
||||||
|
mFileList.onBackPressed();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
popPath();
|
||||||
|
if (mDirectories.isEmpty()) {
|
||||||
|
super.onBackPressed();
|
||||||
|
}
|
||||||
|
mFileList.onBackPressed();
|
||||||
|
}
|
||||||
|
|
||||||
//@Override
|
//@Override
|
||||||
/*protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
/*protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
|
|
@ -17,11 +17,17 @@
|
||||||
*/
|
*/
|
||||||
package eu.alefzero.owncloud.ui.fragment;
|
package eu.alefzero.owncloud.ui.fragment;
|
||||||
|
|
||||||
|
import java.util.ListIterator;
|
||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
|
import eu.alefzero.owncloud.DisplayUtils;
|
||||||
import eu.alefzero.owncloud.R;
|
import eu.alefzero.owncloud.R;
|
||||||
import eu.alefzero.owncloud.R.id;
|
import eu.alefzero.owncloud.R.id;
|
||||||
import eu.alefzero.owncloud.authenticator.AccountAuthenticator;
|
import eu.alefzero.owncloud.authenticator.AccountAuthenticator;
|
||||||
import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;
|
import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;
|
||||||
|
import eu.alefzero.owncloud.ui.FragmentListView;
|
||||||
import eu.alefzero.owncloud.ui.activity.FileDetailActivity;
|
import eu.alefzero.owncloud.ui.activity.FileDetailActivity;
|
||||||
|
import eu.alefzero.owncloud.ui.activity.FileDisplayActivity;
|
||||||
import eu.alefzero.owncloud.ui.adapter.FileListListAdapter;
|
import eu.alefzero.owncloud.ui.adapter.FileListListAdapter;
|
||||||
import eu.alefzero.owncloud.ui.fragment.ActionBar;
|
import eu.alefzero.owncloud.ui.fragment.ActionBar;
|
||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
|
@ -33,32 +39,39 @@ import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.FragmentTransaction;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.ListFragment;
|
import android.support.v4.app.ListFragment;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.AdapterView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Fragment that lists all files and folders in a given path.
|
* A Fragment that lists all files and folders in a given path.
|
||||||
* @author Bartek Przybylski
|
* @author Bartek Przybylski
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class FileList extends ListFragment {
|
public class FileList extends FragmentListView {
|
||||||
private Cursor mCursor;
|
private Cursor mCursor;
|
||||||
private Account mAccount;
|
private Account mAccount;
|
||||||
private AccountManager mAccountManager;
|
private AccountManager mAccountManager;
|
||||||
private View mheaderView;
|
private View mheaderView;
|
||||||
|
private Stack<String> mParentsIds;
|
||||||
|
private Stack<String> mDirNames;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
mParentsIds = new Stack<String>();
|
||||||
|
mDirNames = new Stack<String>();
|
||||||
mAccountManager = (AccountManager)getActivity().getSystemService(Service.ACCOUNT_SERVICE);
|
mAccountManager = (AccountManager)getActivity().getSystemService(Service.ACCOUNT_SERVICE);
|
||||||
mAccount = mAccountManager.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE)[0];
|
mAccount = mAccountManager.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE)[0];
|
||||||
populateFileList();
|
populateFileList();
|
||||||
|
@ -71,42 +84,40 @@ public class FileList extends ListFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
public void onItemClick(AdapterView<?> l, View v, int position, long id) {
|
||||||
FileDetail fd = (FileDetail) getFragmentManager().findFragmentById(R.id.fileDetail);
|
FileDetail fd = (FileDetail) getFragmentManager().findFragmentById(R.id.fileDetail);
|
||||||
ActionBar ab = (ActionBar) getFragmentManager().findFragmentById(R.id.actionBar);
|
|
||||||
|
|
||||||
if (!mCursor.moveToPosition(position)) {
|
if (!mCursor.moveToPosition(position)) {
|
||||||
throw new IndexOutOfBoundsException("Incorrect item selected");
|
throw new IndexOutOfBoundsException("Incorrect item selected");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)).equals("DIR")) {
|
if (mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)).equals("DIR")) {
|
||||||
String id_ = mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta._ID));
|
String id_ = mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta._ID));
|
||||||
|
mParentsIds.push(id_);
|
||||||
String dirname = mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_NAME));
|
String dirname = mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_NAME));
|
||||||
//ab..push(DisplayUtils.HtmlDecode(dirname));
|
mDirNames.push(dirname);
|
||||||
//mPath.addLast(DisplayUtils.HtmlDecode(dirname));
|
((FileDisplayActivity)getActivity()).pushPath(DisplayUtils.HtmlDecode(dirname));
|
||||||
//mParents.push(id_);
|
|
||||||
mCursor = getActivity().managedQuery(Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, id_),
|
mCursor = getActivity().managedQuery(Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, id_),
|
||||||
null,
|
null,
|
||||||
ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",
|
ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",
|
||||||
new String[]{mAccount.name}, null);
|
new String[]{mAccount.name}, null);
|
||||||
setListAdapter(new FileListListAdapter(mCursor, getActivity()));
|
setListAdapter(new FileListListAdapter(mCursor, getActivity()));
|
||||||
setListShown(false);
|
//super.onListItemClick(l, v, position, id);
|
||||||
setListShown(true);
|
|
||||||
super.onListItemClick(l, v, position, id);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Intent i = new Intent(getActivity(), FileDetailActivity.class);
|
Intent i = new Intent(getActivity(), FileDetailActivity.class);
|
||||||
i.putExtra("FILE_PATH", ab.getCurrentPath());
|
|
||||||
i.putExtra("FILE_NAME", ((TextView)v.findViewById(R.id.Filename)).getText());
|
i.putExtra("FILE_NAME", ((TextView)v.findViewById(R.id.Filename)).getText());
|
||||||
if (fd != null) {
|
if (fd != null) {
|
||||||
fd.setStuff(i);
|
fd.setStuff(i);
|
||||||
//fd.use(((TextView)v.findViewById(R.id.Filename)).getText());
|
//fd.use(((TextView)v.findViewById(R.id.Filename)).getText());
|
||||||
} else {
|
} else {
|
||||||
i.putExtra("FILE_PATH", ab.getCurrentPath());
|
|
||||||
i.putExtra("FILE_NAME", ((TextView)v.findViewById(R.id.Filename)).getText());
|
i.putExtra("FILE_NAME", ((TextView)v.findViewById(R.id.Filename)).getText());
|
||||||
startActivity(i);
|
startActivity(i);
|
||||||
}
|
}
|
||||||
super.onListItemClick(l, v, position, id);
|
FragmentTransaction ft = getFragmentManager().beginTransaction();
|
||||||
|
ft.replace(R.id.fileList, this);
|
||||||
|
ft.commitAllowingStateLoss();
|
||||||
|
//super.onListItemClick(l, v, position, id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -124,4 +135,24 @@ public class FileList extends ListFragment {
|
||||||
|
|
||||||
setListAdapter(new FileListListAdapter(mCursor, getActivity()));
|
setListAdapter(new FileListListAdapter(mCursor, getActivity()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onBackPressed() {
|
||||||
|
if (!mParentsIds.empty()) {
|
||||||
|
mParentsIds.pop();
|
||||||
|
mDirNames.pop();
|
||||||
|
}
|
||||||
|
if (!mParentsIds.empty()) {
|
||||||
|
|
||||||
|
String id_ = mParentsIds.peek();
|
||||||
|
String dirname = mDirNames.peek();
|
||||||
|
mCursor = getActivity().managedQuery(Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, id_),
|
||||||
|
null,
|
||||||
|
ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",
|
||||||
|
new String[]{mAccount.name}, null);
|
||||||
|
setListAdapter(new FileListListAdapter(mCursor, getActivity()));
|
||||||
|
} else {
|
||||||
|
populateFileList();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue