X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/154bb85cf1cc5347333be1cea339907b13cc746a..2bc41ee3315feb483e4b92873df8f7dd3bb5499c:/src/eu/alefzero/owncloud/OwnCloudMainScreen.java diff --git a/src/eu/alefzero/owncloud/OwnCloudMainScreen.java b/src/eu/alefzero/owncloud/OwnCloudMainScreen.java index e30789a5..614058b4 100644 --- a/src/eu/alefzero/owncloud/OwnCloudMainScreen.java +++ b/src/eu/alefzero/owncloud/OwnCloudMainScreen.java @@ -18,6 +18,11 @@ package eu.alefzero.owncloud; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.LinkedList; import java.util.Stack; import android.accounts.Account; @@ -28,13 +33,16 @@ import android.app.ListActivity; import android.content.DialogInterface; import android.content.Intent; import android.content.DialogInterface.OnCancelListener; +import android.content.res.Configuration; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Matrix; import android.net.Uri; import android.os.Bundle; +import android.os.Environment; import android.text.TextUtils; +import android.util.Log; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -49,18 +57,28 @@ import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta; public class OwnCloudMainScreen extends ListActivity { private DbHandler mDBHandler; private Stack mParents; + private LinkedList mPath; private Account mAccount; private Cursor mCursor; private boolean mIsDisplayingFile; private static final int DIALOG_CHOOSE_ACCOUNT = 0; + @SuppressWarnings("unchecked") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + if (savedInstanceState != null) { + mParents = (Stack)savedInstanceState.getSerializable("parentsStack"); + mIsDisplayingFile = savedInstanceState.getBoolean("isDisplayingFile"); + mPath = (LinkedList)savedInstanceState.getSerializable("path"); + } else { + mParents = new Stack(); + mPath = new LinkedList(); + mIsDisplayingFile = false; + } - mParents = new Stack(); - mIsDisplayingFile = false; mDBHandler = new DbHandler(getBaseContext()); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); @@ -146,9 +164,11 @@ public class OwnCloudMainScreen extends ListActivity { @Override public void onBackPressed() { + PathLayout pl = (PathLayout) findViewById(R.id.pathLayout1); if (mIsDisplayingFile) { mIsDisplayingFile = false; setContentView(R.layout.main); + pl = (PathLayout) findViewById(R.id.pathLayout1); Uri uri; if (mParents.empty()) { uri = ProviderTableMeta.CONTENT_URI; @@ -161,8 +181,11 @@ public class OwnCloudMainScreen extends ListActivity { new String[]{mAccount.name}, null); if (mCursor.moveToFirst()) { - TextView tv = (TextView) findViewById(R.id.directory_name); - tv.setText(mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_PATH))); + String s = mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_PATH)); + for (String str : s.split("/")) { + if (!TextUtils.isEmpty(str)) + pl.push(DisplayUtils.HtmlDecode(str)); + } } getListView().setAdapter(new FileListListAdapter(mCursor, this)); getListView().invalidate(); @@ -173,6 +196,8 @@ public class OwnCloudMainScreen extends ListActivity { return; } else if (mParents.size() == 1) { mParents.pop(); + mPath.removeLast(); + pl.pop(); mCursor = managedQuery(ProviderTableMeta.CONTENT_URI, null, ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?", @@ -180,6 +205,8 @@ public class OwnCloudMainScreen extends ListActivity { null); } else { mParents.pop(); + mPath.removeLast(); + pl.pop(); mCursor = managedQuery(Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, mParents.peek()), null, ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?", @@ -189,19 +216,12 @@ public class OwnCloudMainScreen extends ListActivity { setListAdapter(new FileListListAdapter(mCursor, this)); getListView().invalidate(); - - TextView tv = (TextView) findViewById(R.id.directory_name); - String s = tv.getText().toString(); - if (s.endsWith("/")) { - s = s.substring(0, s.length() - 1); - } - s = s.substring(0, s.lastIndexOf('/') + 1); - tv.setText(s); } @Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); + PathLayout pl = (PathLayout) findViewById(R.id.pathLayout1); if (!mCursor.moveToPosition(position)) { throw new IndexOutOfBoundsException("Incorrect item selected"); } @@ -209,8 +229,8 @@ public class OwnCloudMainScreen extends ListActivity { if (mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)).equals("DIR")) { String id_ = mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta._ID)); String dirname = mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_NAME)); - TextView tv = (TextView) findViewById(R.id.directory_name); - tv.setText(tv.getText().toString()+dirname+"/"); + pl.push(DisplayUtils.HtmlDecode(dirname)); + mPath.addLast(DisplayUtils.HtmlDecode(dirname)); mParents.push(id_); mCursor = managedQuery(Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, id_), null, @@ -239,7 +259,8 @@ public class OwnCloudMainScreen extends ListActivity { // modified tv = (TextView) findViewById(R.id.textView4); tv.setText(mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_MODIFIED))); - if (!TextUtils.isEmpty(mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH)))) { + if (!TextUtils.isEmpty(mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH))) && + mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)).matches("image/*")) { ImageView iv = (ImageView) findViewById(R.id.imageView1); Bitmap bmp = BitmapFactory.decodeFile(mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH))); Matrix m = new Matrix(); @@ -259,23 +280,71 @@ public class OwnCloudMainScreen extends ListActivity { } else { try { Intent i = (Intent) getListAdapter().getItem(position); - startActivity(i); - } catch (ClassCastException e) {} + if (i.hasExtra("toDownload")) { + + Uri data = Uri.parse(Environment.getExternalStorageDirectory().getAbsolutePath() + "/owncloud/filename"); + Log.d("DUPA", data.toString()); + File f = new File(data.toString()); + FileInputStream fis = new FileInputStream(f); + byte buffer[] = new byte[512]; + fis.read(buffer); + Log.d("DUPA", new String(buffer)); + + //Intent intent = new Intent(this, FileDownloader.class); + /*intent.putExtra(FileDownloader.EXTRA_FILE_PATH, "/docsy.py"); + intent.putExtra(FileDownloader.EXTRA_ACCOUNT, mAccount); + startService(intent); + /* + if (i.getBooleanExtra("toDownload", false)) { + startActivityForResult(i, 200); + } else { + startActivity(i); + }*/ + } + } catch (ClassCastException e) {} catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } } private void populateFileList() { - TextView tv = (TextView) findViewById(R.id.directory_name); - tv.setText("/"); - mCursor = getContentResolver().query(ProviderTableMeta.CONTENT_URI, - null, - ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?", - new String[]{mAccount.name}, - null); + if (mParents.empty()) { + mCursor = getContentResolver().query(ProviderTableMeta.CONTENT_URI, + null, + ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?", + new String[]{mAccount.name}, + null); + } else { + mCursor = getContentResolver().query(Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, mParents.peek()), + null, + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?", + new String[]{mAccount.name}, null); + if (!mIsDisplayingFile) { + PathLayout pl = (PathLayout) findViewById(R.id.pathLayout1); + for (String s : mPath) { + pl.push(s); + } + } + } setListAdapter(new FileListListAdapter(mCursor, this)); getListView().invalidate(); } + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + } + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putSerializable("parentsStack", mParents); + outState.putSerializable("path", mPath); + outState.putBoolean("isDisplayingFile", mIsDisplayingFile); + } } \ No newline at end of file