<activity
android:name=".ui.activity.FileDisplayActivity"
android:label="@string/app_name"
- android:configChanges="orientation|screenSize">
+ >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<service android:name=".files.services.FileUploader" />
<service android:name=".media.MediaService" />
- <activity android:name=".ui.activity.FileDetailActivity" android:configChanges="orientation|screenSize"/>
<activity android:name=".ui.activity.PinCodeActivity" />
<activity android:name=".extensions.ExtensionsAvailableActivity"></activity>
<activity android:name=".extensions.ExtensionsListActivity"></activity>
GNU General Public License for more details.\r
\r
You should have received a copy of the GNU General Public License\r
- along with this program. If not, see <http://www.gnu.org/licenses/>.\r\r
+ along with this program. If not, see <http://www.gnu.org/licenses/>.\r
-->\r
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
- android:layout_width="fill_parent"\r
- android:layout_height="fill_parent"\r
+ android:layout_width="match_parent"\r
+ android:layout_height="match_parent"\r
android:background="@color/owncloud_white"\r
- android:orientation="horizontal" >\r
-\r
- <LinearLayout\r
- android:id="@+id/file_list_container"\r
- android:layout_width="0dp"\r
- android:layout_height="fill_parent"\r
- android:layout_weight="1" >\r
-\r
- <fragment\r
- android:id="@+id/fileList"\r
- android:layout_width="fill_parent"\r
- android:layout_height="fill_parent"\r
- class="com.owncloud.android.ui.fragment.OCFileListFragment" >\r
-\r
- <!-- Preview: layout=@layout/list_layout -->\r
- </fragment>\r
- </LinearLayout>\r
-\r
- <LinearLayout android:id="@+id/file_details_container"\r
+ android:orientation="horizontal"\r
+ android:baselineAligned="false" \r
+ >\r
+\r
+ <fragment\r
+ android:id="@+id/list_of_files_fragment"\r
+ android:layout_width="0dp"\r
+ android:layout_height="match_parent"\r
+ android:layout_weight="1"\r
+ class="com.owncloud.android.ui.fragment.OCFileListFragment" \r
+ />\r
+\r
+ <FrameLayout android:id="@+id/right_fragment_container"\r
android:layout_width="0dp"\r
- android:layout_height="fill_parent"\r
- android:layout_weight="2" >\r
-\r
- <!-- Preview: layout=@layout/file_details_empty -->\r
- </LinearLayout>\r
+ android:layout_weight="2" \r
+ android:layout_height="match_parent"\r
+ />\r
\r
</LinearLayout>\r
You should have received a copy of the GNU General Public License\r
along with this program. If not, see <http://www.gnu.org/licenses/>.\r
-->\r
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
- android:layout_width="fill_parent"\r
- android:layout_height="fill_parent"\r
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
+ android:layout_width="match_parent"\r
+ android:layout_height="match_parent"\r
android:background="@color/owncloud_white"\r
- android:orientation="vertical"\r
- android:id="@+id/file_list_view">\r
+ android:id="@+id/single_fragment_container">\r
\r
+ <!-- \r
<fragment\r
android:id="@+id/fileList"\r
android:layout_width="fill_parent"\r
android:layout_height="fill_parent"\r
class="com.owncloud.android.ui.fragment.OCFileListFragment" >\r
-\r
- <!-- Preview: layout=@layout/list_layout -->\r
</fragment>\r
+ -->\r
\r
-</LinearLayout>\r
+</FrameLayout>\r
import com.owncloud.android.operations.RemoteOperationResult;
import com.owncloud.android.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.ui.activity.FileActivity;
-import com.owncloud.android.ui.activity.FileDetailActivity;
+import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.preview.PreviewImageActivity;
import com.owncloud.android.ui.preview.PreviewImageFragment;
if (PreviewImageFragment.canBePreviewed(download.getFile())) {
showDetailsIntent = new Intent(this, PreviewImageActivity.class);
} else {
- showDetailsIntent = new Intent(this, FileDetailActivity.class);
+ showDetailsIntent = new Intent(this, FileDisplayActivity.class);
}
showDetailsIntent.putExtra(FileActivity.EXTRA_FILE, download.getFile());
showDetailsIntent.putExtra(FileActivity.EXTRA_ACCOUNT, download.getAccount());
if (PreviewImageFragment.canBePreviewed(download.getFile())) {
showDetailsIntent = new Intent(this, PreviewImageActivity.class);
} else {
- showDetailsIntent = new Intent(this, FileDetailActivity.class);
+ showDetailsIntent = new Intent(this, FileDisplayActivity.class);
}
showDetailsIntent.putExtra(FileActivity.EXTRA_FILE, download.getFile());
showDetailsIntent.putExtra(FileActivity.EXTRA_ACCOUNT, download.getAccount());
import com.owncloud.android.operations.RemoteOperationResult;
import com.owncloud.android.operations.UploadFileOperation;
import com.owncloud.android.operations.RemoteOperationResult.ResultCode;
-import com.owncloud.android.ui.activity.FileDetailActivity;
import com.owncloud.android.utils.OwnCloudVersion;
import eu.alefzero.webdav.OnDatatransferProgressListener;
import com.owncloud.android.db.DbHandler;
import com.owncloud.android.ui.activity.FailedUploadActivity;
import com.owncloud.android.ui.activity.FileActivity;
+import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.activity.InstantUploadActivity;
import com.owncloud.android.ui.preview.PreviewImageActivity;
import com.owncloud.android.ui.preview.PreviewImageFragment;
if (PreviewImageFragment.canBePreviewed(upload.getFile())) {
showDetailsIntent = new Intent(this, PreviewImageActivity.class);
} else {
- showDetailsIntent = new Intent(this, FileDetailActivity.class);
- showDetailsIntent.putExtra(FileDetailActivity.EXTRA_MODE, FileDetailActivity.MODE_DETAILS);
+ showDetailsIntent = new Intent(this, FileDisplayActivity.class);
}
showDetailsIntent.putExtra(FileActivity.EXTRA_FILE, upload.getFile());
showDetailsIntent.putExtra(FileActivity.EXTRA_ACCOUNT, upload.getAccount());
if (PreviewImageFragment.canBePreviewed(upload.getFile())) {
showDetailsIntent = new Intent(this, PreviewImageActivity.class);
} else {
- showDetailsIntent = new Intent(this, FileDetailActivity.class);
- showDetailsIntent.putExtra(FileDetailActivity.EXTRA_MODE, FileDetailActivity.MODE_DETAILS);
+ showDetailsIntent = new Intent(this, FileDisplayActivity.class);
}
showDetailsIntent.putExtra(FileActivity.EXTRA_FILE, upload.getFile());
showDetailsIntent.putExtra(FileActivity.EXTRA_ACCOUNT, upload.getAccount());
import com.owncloud.android.R;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.ui.activity.FileActivity;
-import com.owncloud.android.ui.activity.FileDetailActivity;
+import com.owncloud.android.ui.activity.FileDisplayActivity;
/**
* Service that handles media playback, both audio and video.
@SuppressWarnings("deprecation")
private void updateNotification(String content) {
// TODO check if updating the Intent is really necessary
- Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);
+ Intent showDetailsIntent = new Intent(this, FileDisplayActivity.class);
showDetailsIntent.putExtra(FileActivity.EXTRA_FILE, mFile);
showDetailsIntent.putExtra(FileActivity.EXTRA_ACCOUNT, mAccount);
showDetailsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
/// includes a pending intent in the notification showing the details view of the file
- Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);
+ Intent showDetailsIntent = new Intent(this, FileDisplayActivity.class);
showDetailsIntent.putExtra(FileActivity.EXTRA_FILE, mFile);
showDetailsIntent.putExtra(FileActivity.EXTRA_ACCOUNT, mAccount);
showDetailsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+++ /dev/null
-/* 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;
-
-import com.actionbarsherlock.app.SherlockFragment;
-import com.owncloud.android.R;
-import com.owncloud.android.ui.fragment.LocalFileListFragment;
-
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.AdapterView;
-import android.widget.AdapterView.OnItemLongClickListener;
-import android.widget.ListAdapter;
-import android.widget.AdapterView.OnItemClickListener;
-import android.widget.ListView;
-
-public class FragmentListView extends SherlockFragment implements
- OnItemClickListener, OnItemLongClickListener {
- protected ExtendedListView mList;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- }
-
- public void setListAdapter(ListAdapter listAdapter) {
- mList.setAdapter(listAdapter);
- mList.invalidate();
- }
-
- public ListView getListView() {
- return mList;
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- //mList = new ExtendedListView(getActivity());
- View v = inflater.inflate(R.layout.list_fragment, null);
- mList = (ExtendedListView)(v.findViewById(R.id.list_root));
- mList.setOnItemClickListener(this);
- mList.setOnItemLongClickListener(this);
- //mList.setEmptyView(v.findViewById(R.id.empty_list_view)); // looks like it's not a cool idea
- mList.setDivider(getResources().getDrawable(R.drawable.uploader_list_separator));
- mList.setDividerHeight(1);
- return v;
- }
-
- public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
- }
-
- @Override
- public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2,
- long arg3) {
- return false;
- }
-
-
- /**
- * Calculates the position of the item that will be used as a reference to reposition the visible items in the list when
- * the device is turned to other position.
- *
- * THe current policy is take as a reference the visible item in the center of the screen.
- *
- * @return The position in the list of the visible item in the center of the screen.
- */
- protected int getReferencePosition() {
- return (mList.getFirstVisiblePosition() + mList.getLastVisiblePosition()) / 2;
- }
-
-
- /**
- * Sets the visible part of the list from the reference position.
- *
- * @param position Reference position previously returned by {@link LocalFileListFragment#getReferencePosition()}
- */
- protected void setReferencePosition(int position) {
- mList.setAndCenterSelection(position);
- }
-
-
-}
import com.owncloud.android.R;
import com.owncloud.android.authentication.AccountAuthenticator;
import com.owncloud.android.datamodel.OCFile;
-import com.owncloud.android.files.FileHandler;
import eu.alefzero.webdav.WebdavUtils;
*
* @author David A. Velasco
*/
-public abstract class FileActivity extends SherlockFragmentActivity implements FileHandler {
+public abstract class FileActivity extends SherlockFragmentActivity {
public static final String EXTRA_FILE = "com.owncloud.android.ui.activity.FILE";
public static final String EXTRA_ACCOUNT = "com.owncloud.android.ui.activity.ACCOUNT";
/** Flag to signal that the activity will is finishing to enforce the creation of an ownCloud {@link Account} */
private boolean mRedirectingToSetupAccount = false;
- private FileHandlerImpl mFileHandler;
-
@Override
protected void onCreate(Bundle savedInstanceState) {
onAccountChanged();
}
- mFileHandler = new FileHandlerImpl();
}
*/
@Override
protected void onStart() {
- Log_OC.e(TAG, "onStart en FileActivity");
+ Log_OC.d(TAG, "onStart en FileActivity");
super.onStart();
/// Validate account, and try to fix if wrong
if (mAccount == null || !AccountUtils.setCurrentOwnCloudAccount(getApplicationContext(), mAccount.name)) {
}
- public void openFile(OCFile file) {
- mFileHandler.openFile(file);
- }
-
-
/**
* Called when the ownCloud {@link Account} associated to the Activity was just updated.
*
protected abstract void onAccountChanged();
- public class FileHandlerImpl implements FileHandler {
-
- public void openFile(OCFile file) {
- if (file != null) {
- String storagePath = file.getStoragePath();
- String encodedStoragePath = WebdavUtils.encodePath(storagePath);
-
- Intent intentForSavedMimeType = new Intent(Intent.ACTION_VIEW);
- intentForSavedMimeType.setDataAndType(Uri.parse("file://"+ encodedStoragePath), file.getMimetype());
- intentForSavedMimeType.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
-
- Intent intentForGuessedMimeType = null;
- if (storagePath.lastIndexOf('.') >= 0) {
- String guessedMimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1));
- if (guessedMimeType != null && !guessedMimeType.equals(file.getMimetype())) {
- intentForGuessedMimeType = new Intent(Intent.ACTION_VIEW);
- intentForGuessedMimeType.setDataAndType(Uri.parse("file://"+ encodedStoragePath), guessedMimeType);
- intentForGuessedMimeType.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
- }
- }
-
- Intent chooserIntent = null;
- if (intentForGuessedMimeType != null) {
- chooserIntent = Intent.createChooser(intentForGuessedMimeType, getString(R.string.actionbar_open_with));
- } else {
- chooserIntent = Intent.createChooser(intentForSavedMimeType, getString(R.string.actionbar_open_with));
+
+ public void openFile(OCFile file) {
+ if (file != null) {
+ String storagePath = file.getStoragePath();
+ String encodedStoragePath = WebdavUtils.encodePath(storagePath);
+
+ Intent intentForSavedMimeType = new Intent(Intent.ACTION_VIEW);
+ intentForSavedMimeType.setDataAndType(Uri.parse("file://"+ encodedStoragePath), file.getMimetype());
+ intentForSavedMimeType.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
+
+ Intent intentForGuessedMimeType = null;
+ if (storagePath.lastIndexOf('.') >= 0) {
+ String guessedMimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1));
+ if (guessedMimeType != null && !guessedMimeType.equals(file.getMimetype())) {
+ intentForGuessedMimeType = new Intent(Intent.ACTION_VIEW);
+ intentForGuessedMimeType.setDataAndType(Uri.parse("file://"+ encodedStoragePath), guessedMimeType);
+ intentForGuessedMimeType.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
}
-
- startActivity(chooserIntent);
-
+ }
+
+ Intent chooserIntent = null;
+ if (intentForGuessedMimeType != null) {
+ chooserIntent = Intent.createChooser(intentForGuessedMimeType, getString(R.string.actionbar_open_with));
} else {
- Log_OC.wtf(TAG, "Trying to open a NULL OCFile");
+ chooserIntent = Intent.createChooser(intentForSavedMimeType, getString(R.string.actionbar_open_with));
}
+
+ startActivity(chooserIntent);
+
+ } else {
+ Log_OC.wtf(TAG, "Trying to open a NULL OCFile");
}
}
+
}
+++ /dev/null
-/* 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.activity;
-
-import android.accounts.Account;
-import android.app.Dialog;
-import android.app.ProgressDialog;
-import android.content.BroadcastReceiver;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.ServiceConnection;
-import android.content.res.Configuration;
-import android.os.Bundle;
-import android.os.IBinder;
-import android.support.v4.app.Fragment;
-import android.support.v4.app.FragmentTransaction;
-
-import com.actionbarsherlock.app.ActionBar;
-import com.actionbarsherlock.view.MenuItem;
-import com.owncloud.android.AccountUtils;
-import com.owncloud.android.Log_OC;
-import com.owncloud.android.R;
-import com.owncloud.android.datamodel.FileDataStorageManager;
-import com.owncloud.android.datamodel.OCFile;
-import com.owncloud.android.files.services.FileDownloader;
-import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
-import com.owncloud.android.files.services.FileUploader;
-import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
-import com.owncloud.android.ui.fragment.FileDetailFragment;
-import com.owncloud.android.ui.fragment.FileFragment;
-import com.owncloud.android.ui.preview.PreviewMediaFragment;
-import com.owncloud.android.ui.preview.PreviewVideoActivity;
-
-/**
- * This activity displays the details of a file like its name, its size and so
- * on.
- *
- * @author Bartek Przybylski
- * @author David A. Velasco
- */
-public class FileDetailActivity extends FileActivity implements FileFragment.ContainerActivity {
-
- public static final int DIALOG_SHORT_WAIT = 0;
-
- public static final String TAG = FileDetailActivity.class.getSimpleName();
-
- public static final String EXTRA_MODE = "MODE";
- public static final int MODE_DETAILS = 0;
- public static final int MODE_PREVIEW = 1;
-
- public static final String KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW";
-
- private FileDownloaderBinder mDownloaderBinder = null;
- private ServiceConnection mDownloadConnection, mUploadConnection = null;
- private FileUploaderBinder mUploaderBinder = null;
- private boolean mWaitingToPreview;
-
- private FileDataStorageManager mStorageManager;
- private DownloadFinishReceiver mDownloadFinishReceiver;
-
- private Configuration mNewConfigurationChangeToApplyOnStart;
-
- private boolean mStarted;
-
- private boolean mDualPane;
-
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- mStarted = false;
-
- // check if configuration is proper for this activity; tablets in landscape should pass the torch to FileDisplayActivity
- Configuration conf = getResources().getConfiguration();
- mDualPane = (conf.orientation == Configuration.ORIENTATION_LANDSCAPE &&
- (conf.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE
- );
-
- if (mDualPane) {
- // only happens when notifications (downloads, uploads) are clicked at the notification bar
- backToDisplayActivity(false);
-
- } else {
- setContentView(R.layout.file_activity_details);
-
- ActionBar actionBar = getSupportActionBar();
- actionBar.setDisplayHomeAsUpEnabled(true);
-
- if (savedInstanceState == null) {
- mWaitingToPreview = false;
- createChildFragment();
- } else {
- mWaitingToPreview = savedInstanceState.getBoolean(KEY_WAITING_TO_PREVIEW);
- }
-
- mDownloadConnection = new DetailsServiceConnection();
- bindService(new Intent(this, FileDownloader.class), mDownloadConnection, Context.BIND_AUTO_CREATE);
- mUploadConnection = new DetailsServiceConnection();
- bindService(new Intent(this, FileUploader.class), mUploadConnection, Context.BIND_AUTO_CREATE);
- }
- }
-
- /**
- * Creates the proper fragment depending upon the state of the handled {@link OCFile} and
- * the requested {@link Intent}.
- */
- private void createChildFragment() {
- int mode = getIntent().getIntExtra(EXTRA_MODE, MODE_PREVIEW);
-
- Fragment newFragment = null;
- OCFile file = getFile();
- Account account = getAccount();
- if (mode == MODE_DETAILS) {
- newFragment = new FileDetailFragment(file, account);
-
- } else if (file.isDown()) {
- if (PreviewMediaFragment.canBePreviewed(file)) {
- int startPlaybackPosition = getIntent().getIntExtra(PreviewVideoActivity.EXTRA_START_POSITION, 0);
- boolean autoplay = getIntent().getBooleanExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, true);
- newFragment = new PreviewMediaFragment(file, account, startPlaybackPosition, autoplay);
-
- } else {
- newFragment = new FileDetailFragment(file, account);
- // TODO open with
- }
-
- } else {
- newFragment = new FileDetailFragment(file, account);
- mWaitingToPreview = true; // download will requested
- }
- FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
- ft.replace(R.id.fragment, newFragment, FileDetailFragment.FTAG);
- ft.commit();
- }
-
- @Override
- public void onActivityResult (int requestCode, int resultCode, Intent data) {
- Log_OC.e(TAG, "onActivityResult");
- super.onActivityResult(requestCode, resultCode, data);
- }
-
- @Override
- public void onConfigurationChanged (Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
- if (mStarted) {
- checkConfigurationChange(newConfig);
- } else {
- mNewConfigurationChangeToApplyOnStart = newConfig;
- }
- }
-
-
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- outState.putBoolean(KEY_WAITING_TO_PREVIEW, mWaitingToPreview);
- }
-
-
- @Override
- public void onStart() {
- super.onStart();
- Log_OC.e(TAG, "onStart");
- if (mNewConfigurationChangeToApplyOnStart != null && !isRedirectingToSetupAccount()) {
- checkConfigurationChange(mNewConfigurationChangeToApplyOnStart);
- mNewConfigurationChangeToApplyOnStart = null;
- }
- mStarted = true;
- }
-
- private void checkConfigurationChange(Configuration newConfig) {
- finish();
- Intent intent = null;
- OCFile file = getFile();
- Account account = getAccount();
- if ((newConfig.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE
- && newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
-
- intent = new Intent(this, FileDisplayActivity.class);
- intent.putExtra(EXTRA_FILE, file);
- intent.putExtra(EXTRA_ACCOUNT, account);
- intent.putExtra(EXTRA_MODE, getIntent().getIntExtra(EXTRA_MODE, MODE_PREVIEW));
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- Fragment fragment = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
- if (fragment != null && file != null && fragment instanceof PreviewMediaFragment && file.isVideo()) {
- PreviewMediaFragment videoFragment = (PreviewMediaFragment)fragment;
- intent.putExtra(PreviewVideoActivity.EXTRA_START_POSITION, videoFragment.getPosition());
- intent.putExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, videoFragment.isPlaying());
- }
- if (mWaitingToPreview) {
- intent.putExtra(FileDisplayActivity.EXTRA_WAITING_TO_PREVIEW, mWaitingToPreview);
- }
-
- } else {
- intent = new Intent(this, FileDetailActivity.class);
- intent .putExtra(EXTRA_FILE, file);
- intent .putExtra(EXTRA_ACCOUNT, account);
- intent.putExtra(EXTRA_MODE, getIntent().getIntExtra(EXTRA_MODE, MODE_PREVIEW));
- Fragment fragment = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
- if (fragment != null && file != null && fragment instanceof PreviewMediaFragment && file.isVideo()) {
- PreviewMediaFragment videoFragment = (PreviewMediaFragment)fragment;
- intent.putExtra(PreviewVideoActivity.EXTRA_START_POSITION, videoFragment.getPosition());
- intent.putExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, videoFragment.isPlaying());
- }
- // and maybe 'waiting to preview' flag
- }
- startActivity(intent);
- }
-
- @Override
- public void onStop() {
- super.onStop();
- Log_OC.e(TAG, "onStop");
- mStarted = false;
- }
- @Override
- public void onPause() {
- super.onPause();
- Log_OC.e(TAG, "onPause");
- if (mDownloadFinishReceiver != null) {
- unregisterReceiver(mDownloadFinishReceiver);
- mDownloadFinishReceiver = null;
- }
- }
-
-
- @Override
- public void onResume() {
- super.onResume();
- Log_OC.e(TAG, "onResume");
- // TODO this is probably unnecessary
- Fragment fragment = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
- if (fragment != null && fragment instanceof FileDetailFragment) {
- ((FileDetailFragment) fragment).updateFileDetails(false, false);
- }
-
- // Listen for download messages
- IntentFilter downloadIntentFilter = new IntentFilter(FileDownloader.DOWNLOAD_ADDED_MESSAGE);
- downloadIntentFilter.addAction(FileDownloader.DOWNLOAD_FINISH_MESSAGE);
- mDownloadFinishReceiver = new DownloadFinishReceiver();
- registerReceiver(mDownloadFinishReceiver, downloadIntentFilter);
- }
-
-
- /** Defines callbacks for service binding, passed to bindService() */
- private class DetailsServiceConnection implements ServiceConnection {
-
- @Override
- public void onServiceConnected(ComponentName component, IBinder service) {
-
- if (component.equals(new ComponentName(FileDetailActivity.this, FileDownloader.class))) {
- Log_OC.d(TAG, "Download service connected");
- mDownloaderBinder = (FileDownloaderBinder) service;
- if (mWaitingToPreview) {
- requestForDownload();
- }
-
- } else if (component.equals(new ComponentName(FileDetailActivity.this, FileUploader.class))) {
- Log_OC.d(TAG, "Upload service connected");
- mUploaderBinder = (FileUploaderBinder) service;
- } else {
- return;
- }
-
- Fragment fragment = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
- FileDetailFragment detailsFragment = (fragment instanceof FileDetailFragment) ? (FileDetailFragment) fragment : null;
- if (detailsFragment != null) {
- detailsFragment.listenForTransferProgress();
- detailsFragment.updateFileDetails(mWaitingToPreview, false); // let the fragment gets the mDownloadBinder through getDownloadBinder() (see FileDetailFragment#updateFileDetais())
- }
- }
-
- @Override
- public void onServiceDisconnected(ComponentName component) {
- if (component.equals(new ComponentName(FileDetailActivity.this, FileDownloader.class))) {
- Log_OC.d(TAG, "Download service disconnected");
- mDownloaderBinder = null;
- } else if (component.equals(new ComponentName(FileDetailActivity.this, FileUploader.class))) {
- Log_OC.d(TAG, "Upload service disconnected");
- mUploaderBinder = null;
- }
- }
- };
-
-
- @Override
- public void onDestroy() {
- super.onDestroy();
- Log_OC.e(TAG, "onDestroy");
- if (mDownloadConnection != null) {
- unbindService(mDownloadConnection);
- mDownloadConnection = null;
- }
- if (mUploadConnection != null) {
- unbindService(mUploadConnection);
- mUploadConnection = null;
- }
- }
-
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- boolean returnValue = false;
-
- switch(item.getItemId()){
- case android.R.id.home:
- backToDisplayActivity(true);
- returnValue = true;
- break;
- default:
- returnValue = super.onOptionsItemSelected(item);
- }
-
- return returnValue;
- }
-
- @Override
- public void onBackPressed() {
- backToDisplayActivity(true);
- }
-
- private void backToDisplayActivity(boolean moveToParent) {
- Intent intent = new Intent(this, FileDisplayActivity.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- OCFile targetFile = null;
- OCFile file = getFile();
- if (file != null) {
- targetFile = moveToParent ? mStorageManager.getFileById(file.getParentId()) : file;
- }
- intent.putExtra(EXTRA_FILE, targetFile);
- intent.putExtra(EXTRA_ACCOUNT, getAccount());
- startActivity(intent);
- finish();
- }
-
- @Override
- protected Dialog onCreateDialog(int id) {
- Dialog dialog = null;
- switch (id) {
- case DIALOG_SHORT_WAIT: {
- ProgressDialog working_dialog = new ProgressDialog(this);
- working_dialog.setMessage(getResources().getString(
- R.string.wait_a_moment));
- working_dialog.setIndeterminate(true);
- working_dialog.setCancelable(false);
- dialog = working_dialog;
- break;
- }
- default:
- dialog = null;
- }
- return dialog;
- }
-
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onFileStateChanged() {
- // nothing to do here!
- }
-
-
- /**
- * {@inheritDoc}
- */
- @Override
- public FileDownloaderBinder getFileDownloaderBinder() {
- return mDownloaderBinder;
- }
-
-
- @Override
- public FileUploaderBinder getFileUploaderBinder() {
- return mUploaderBinder;
- }
-
-
- @Override
- public void showFragmentWithDetails(OCFile file) {
- FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
- transaction.replace(R.id.fragment, new FileDetailFragment(file, getAccount()), FileDetailFragment.FTAG);
- transaction.commit();
- }
-
-
- private void requestForDownload() {
- if (!mDownloaderBinder.isDownloading(getAccount(), getFile())) {
- Intent i = new Intent(this, FileDownloader.class);
- i.putExtra(FileDownloader.EXTRA_ACCOUNT, getAccount());
- i.putExtra(FileDownloader.EXTRA_FILE, getFile());
- startService(i);
- }
- }
-
-
- /**
- * Class waiting for broadcast events from the {@link FielDownloader} service.
- *
- * Updates the UI when a download is started or finished, provided that it is relevant for the
- * current file.
- */
- private class DownloadFinishReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- boolean sameAccount = isSameAccount(context, intent);
- String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
- boolean samePath = (getFile() != null && getFile().getRemotePath().equals(downloadedRemotePath));
-
- if (sameAccount && samePath) {
- updateChildFragment(intent.getAction(), downloadedRemotePath, intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false));
- }
-
- removeStickyBroadcast(intent);
- }
-
- private boolean isSameAccount(Context context, Intent intent) {
- String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME);
- return (accountName != null && accountName.equals(AccountUtils.getCurrentOwnCloudAccount(context).name));
- }
- }
-
-
- public void updateChildFragment(String downloadEvent, String downloadedRemotePath, boolean success) {
- Fragment fragment = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
- if (fragment != null && fragment instanceof FileDetailFragment) {
- FileDetailFragment detailsFragment = (FileDetailFragment) fragment;
- OCFile fileInFragment = detailsFragment.getFile();
- if (fileInFragment != null && !downloadedRemotePath.equals(fileInFragment.getRemotePath())) {
- // this never should happen; fileInFragment should be always equals to mFile, that was compared to downloadedRemotePath in DownloadReceiver
- mWaitingToPreview = false;
-
- } else if (downloadEvent.equals(FileDownloader.DOWNLOAD_ADDED_MESSAGE)) {
- // grants that the progress bar is updated
- detailsFragment.listenForTransferProgress();
- detailsFragment.updateFileDetails(true, false);
-
- } else if (downloadEvent.equals(FileDownloader.DOWNLOAD_FINISH_MESSAGE)) {
- // refresh the details fragment
- if (success && mWaitingToPreview) {
- setFile(mStorageManager.getFileById(getFile().getFileId())); // update the file from database, for the local storage path
- if (PreviewMediaFragment.canBePreviewed(getFile())) {
- FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
- transaction.replace(R.id.fragment, new PreviewMediaFragment(getFile(), getAccount(), 0, true), FileDetailFragment.FTAG);
- transaction.commit();
- } else {
- detailsFragment.updateFileDetails(false, (success));
- openFile(getFile());
- }
- mWaitingToPreview = false;
-
- } else {
- detailsFragment.updateFileDetails(false, (success));
- }
- }
- } // TODO else if (fragment != null && fragment )
-
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onAccountChanged() {
- mStorageManager = new FileDataStorageManager(getAccount(), getContentResolver());
-
- FileFragment fragment = (FileFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
- if (fragment != null && mStorageManager.getFileById(fragment.getFile().getFileId()) == null) {
- /// the account was forced to be changed; probably was deleted from system settings
- backToDisplayActivity(false);
- }
- }
-
-}
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
-import android.content.res.Configuration;
import android.content.res.Resources.NotFoundException;
import android.database.Cursor;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.ViewGroup;
import com.owncloud.android.ui.fragment.FileFragment;
import com.owncloud.android.ui.fragment.OCFileListFragment;
import com.owncloud.android.ui.preview.PreviewImageActivity;
-import com.owncloud.android.ui.preview.PreviewImageFragment;
import com.owncloud.android.ui.preview.PreviewMediaFragment;
import com.owncloud.android.ui.preview.PreviewVideoActivity;
OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener, OnSslValidatorListener, OnRemoteOperationListener, EditNameDialogListener {
private ArrayAdapter<String> mDirectories;
- //private OCFile mCurrentDir = null;
private OCFile mChosenFile = null;
/** Access point to the cached database for the current ownCloud {@link Account} */
private ServiceConnection mDownloadConnection = null, mUploadConnection = null;
private RemoteOperationResult mLastSslUntrustedServerResult = null;
- private OCFileListFragment mFileList;
-
private boolean mDualPane;
+ private static final String KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW";
+
public static final int DIALOG_SHORT_WAIT = 0;
private static final int DIALOG_CHOOSE_UPLOAD_SOURCE = 1;
private static final int DIALOG_SSL_VALIDATOR = 2;
private static final int DIALOG_CERT_NOT_SAVED = 3;
+ public static final String ACTION_DETAILS = "com.owncloud.android.ui.activity.action.DETAILS";
+
private static final int ACTION_SELECT_CONTENT_FROM_APPS = 1;
private static final int ACTION_SELECT_MULTIPLE_FILES = 2;
private OCFile mWaitingToPreview;
private Handler mHandler;
- private Configuration mNewConfigurationChangeToApplyOnStart;
- private boolean mStarted;
-
@Override
protected void onCreate(Bundle savedInstanceState) {
Log_OC.d(TAG, "onCreate() start");
super.onCreate(savedInstanceState);
- mStarted = false;
mHandler = new Handler();
- /// Load of saved instance state: keep this always before initDataFromCurrentAccount()
- if(savedInstanceState != null) {
- mWaitingToPreview = (OCFile) savedInstanceState.getParcelable(FileDetailActivity.KEY_WAITING_TO_PREVIEW);
-
- } else {
- mWaitingToPreview = null;
- }
-
/// bindings to transference services
mUploadConnection = new ListServiceConnection();
mDownloadConnection = new ListServiceConnection();
observer_intent.putExtra(FileObserverService.KEY_FILE_CMD, FileObserverService.CMD_INIT_OBSERVED_LIST);
startService(observer_intent);
+ /// Load of saved instance state
+ if(savedInstanceState != null) {
+ mWaitingToPreview = (OCFile) savedInstanceState.getParcelable(FileDisplayActivity.KEY_WAITING_TO_PREVIEW);
+
+ } else {
+ mWaitingToPreview = null;
+ }
+
/// USER INTERFACE
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
- // Drop-down navigation
- mDirectories = new CustomArrayAdapter<String>(this, R.layout.sherlock_spinner_dropdown_item);
- OCFile currFile = getFile();
- while(mStorageManager != null && currFile != null && currFile.getFileName() != OCFile.PATH_SEPARATOR) {
- mDirectories.add(currFile.getFileName());
- currFile = mStorageManager.getFileById(currFile.getParentId());
- }
- mDirectories.add(OCFile.PATH_SEPARATOR);
-
// Inflate and set the layout view
setContentView(R.layout.files);
- mFileList = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);
- mDualPane = (findViewById(R.id.file_details_container) != null);
- if (mDualPane && savedInstanceState == null) {
- initFileDetailsInDualPane();
+ mDualPane = (findViewById(R.id.right_fragment_container) != null);
+ if (savedInstanceState == null) {
+ Fragment secondFragment = chooseSecondFragment(mChosenFile);
+ mChosenFile = null;
+ initFragments(secondFragment);
}
-
+
// Action bar setup
+ mDirectories = new CustomArrayAdapter<String>(this, R.layout.sherlock_spinner_dropdown_item);
+ OCFile currFile = getFile();
+ if (mStorageManager != null) {
+ while(currFile != null && currFile.getFileName() != OCFile.PATH_SEPARATOR) {
+ mDirectories.add(currFile.getFileName());
+ currFile = mStorageManager.getFileById(currFile.getParentId());
+ }
+ }
+ mDirectories.add(OCFile.PATH_SEPARATOR);
ActionBar actionBar = getSupportActionBar();
actionBar.setHomeButtonEnabled(true); // mandatory since Android ICS, according to the official documentation
- actionBar.setDisplayHomeAsUpEnabled(getFile() != null && getFile().getParentId() != 0);
- actionBar.setDisplayShowTitleEnabled(false);
- actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
- actionBar.setListNavigationCallbacks(mDirectories, this);
setSupportProgressBarIndeterminateVisibility(false); // always AFTER setContentView(...) ; to workaround bug in its implementation
Log_OC.d(TAG, "onCreate() end");
}
- @Override
- public void onConfigurationChanged (Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
- if (mStarted) {
- checkConfigurationChange(newConfig);
- } else {
- mNewConfigurationChangeToApplyOnStart = newConfig;
+ private void initFragments(Fragment secondFragment) {
+ FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
+ if (!mDualPane) {
+ transaction.add(R.id.single_fragment_container, new OCFileListFragment());
+ } // else: for dual pane, the fragment for list of files is inflated directly from the layout ; see res\larg-land\files.xml
+
+ /// Second fragment
+ if (secondFragment != null) {
+ if (mDualPane) {
+ transaction.add(R.id.right_fragment_container, secondFragment);
+ } else {
+ transaction.replace(R.id.single_fragment_container, secondFragment);
+ transaction.addToBackStack(null);
+ }
}
+ transaction.commit();
}
-
-
- private void initFileDetailsInDualPane() {
- if (mDualPane && getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG) == null) {
- FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
- if (mChosenFile != null) {
- if (!mChosenFile.isDown()) {
- transaction.replace(R.id.file_details_container, new FileDetailFragment(mChosenFile, getAccount()), FileDetailFragment.FTAG);
- if (getIntent().getBooleanExtra(EXTRA_WAITING_TO_PREVIEW, false)) {
- mWaitingToPreview = mChosenFile;
- }
- } else if (PreviewMediaFragment.canBePreviewed(mChosenFile)) {
- int startPlaybackPosition = getIntent().getIntExtra(PreviewVideoActivity.EXTRA_START_POSITION, 0);
- boolean autoplay = getIntent().getBooleanExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, true);
- transaction.replace(R.id.file_details_container, new PreviewMediaFragment(mChosenFile, getAccount(), startPlaybackPosition, autoplay), FileDetailFragment.FTAG);
- }
- mChosenFile = null;
+
+
+ private Fragment chooseSecondFragment(OCFile file) {
+ Fragment secondFragment = null;
+ if (file != null) {
+ if (file.isDown() && PreviewMediaFragment.canBePreviewed(file)) {
+ int startPlaybackPosition = getIntent().getIntExtra(PreviewVideoActivity.EXTRA_START_POSITION, 0);
+ boolean autoplay = getIntent().getBooleanExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, true);
+ secondFragment = new PreviewMediaFragment(file, getAccount(), startPlaybackPosition, autoplay);
} else {
- transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null), FileDetailFragment.FTAG); // empty FileDetailFragment
+ secondFragment = new FileDetailFragment(file, getAccount());
}
- transaction.commit();
- }
- }
-
-
- @Override
- protected void onStart() {
- super.onStart();
- if (mNewConfigurationChangeToApplyOnStart != null) {
- checkConfigurationChange(mNewConfigurationChangeToApplyOnStart);
- mNewConfigurationChangeToApplyOnStart = null;
- }
- mStarted = true;
- }
-
- @Override
- protected void onStop() {
- super.onStop();
- mStarted = false;
- }
-
-
- private void checkConfigurationChange(Configuration newConfig) {
- FileFragment fragment = (FileFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
- if (fragment != null
- && fragment.getFile() != null
- && (newConfig.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE
- && newConfig.orientation != Configuration.ORIENTATION_LANDSCAPE) {
-
- onFileClick(fragment.getFile(), true);
- FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
- transaction.remove((Fragment)fragment);
- transaction.commit();
-
- } else {
- finish();
- Intent intent = new Intent(this, FileDisplayActivity.class);
- intent.putExtra(EXTRA_FILE, getFile());
- intent.putExtra(EXTRA_ACCOUNT, getAccount());
- startActivity(intent);
+
+ } else if (mDualPane) {
+ secondFragment = new FileDetailFragment(null, null); // empty FileDetailFragment
}
+ return secondFragment;
}
break;
}
case android.R.id.home: {
- if(getFile() != null && getFile().getParentId() != 0){
+ FileFragment second = getSecondFragment();
+ if((getFile() != null && getFile().getParentId() != 0) ||
+ (second != null && second.getFile() != null)) {
onBackPressed();
}
break;
startService(i);
} else {
- Log_OC.d("FileDisplay", "User clicked on 'Update' with no selection");
+ Log_OC.d(TAG, "User clicked on 'Update' with no selection");
Toast t = Toast.makeText(this, getString(R.string.filedisplay_no_file_selected), Toast.LENGTH_LONG);
t.show();
return;
filepath = filemanagerstring;
} catch (Exception e) {
- Log_OC.e("FileDisplay", "Unexpected exception when trying to read the result of Intent.ACTION_GET_CONTENT", e);
+ Log_OC.e(TAG, "Unexpected exception when trying to read the result of Intent.ACTION_GET_CONTENT", e);
e.printStackTrace();
} finally {
if (filepath == null) {
- Log_OC.e("FileDisplay", "Couldnt resolve path to file");
+ Log_OC.e(TAG, "Couldnt resolve path to file");
Toast t = Toast.makeText(this, getString(R.string.filedisplay_unexpected_bad_get_content), Toast.LENGTH_LONG);
t.show();
return;
startService(i);
}
+ private OCFileListFragment getListOfFilesFragment() {
+ if (mDualPane) {
+ return (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.list_of_files_fragment);
+ } else {
+ Fragment singleFragment = getSupportFragmentManager().findFragmentById(R.id.single_fragment_container);
+ if (singleFragment instanceof OCFileListFragment) {
+ return (OCFileListFragment)singleFragment;
+ } else {
+ return null;
+ }
+ }
+ }
+
+ protected FileFragment getSecondFragment() {
+ if (mDualPane) {
+ return (FileFragment) getSupportFragmentManager().findFragmentById(R.id.right_fragment_container);
+ } else {
+ Fragment singleFragment = getSupportFragmentManager().findFragmentById(R.id.single_fragment_container);
+ if (singleFragment != null && !(singleFragment instanceof OCFileListFragment)) {
+ return (FileFragment)singleFragment;
+ } else {
+ return null;
+ }
+ }
+ }
@Override
public void onBackPressed() {
- if (mDirectories.getCount() <= 1) {
- finish();
- return;
+ OCFileListFragment listOfFiles = getListOfFilesFragment();
+ if (listOfFiles != null) {
+ if (mDirectories.getCount() <= 1) {
+ finish();
+ return;
+ }
+ popDirname();
+ listOfFiles.onBrowseUp();
+ setFile(listOfFiles.getCurrentFile());
+ cleanSecondFragment();
+
+ } else {
+ super.onBackPressed();
}
- popDirname();
- mFileList.onNavigateUp();
- setFile(mFileList.getCurrentFile());
-
+ updateNavigationElementsInActionBar(getFile(), null);
+ }
+
+ private void cleanSecondFragment() {
if (mDualPane) {
- // Resets the FileDetailsFragment on Tablets so that it always displays
- Fragment fileFragment = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
+ // Resets the FileDetailsFragment on tablets
+ Fragment fileFragment = getSupportFragmentManager().findFragmentById(R.id.right_fragment_container);
if (fileFragment != null && (fileFragment instanceof PreviewMediaFragment || !((FileDetailFragment) fileFragment).isEmpty())) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
- transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null), FileDetailFragment.FTAG); // empty FileDetailFragment
+ transaction.replace(R.id.right_fragment_container, new FileDetailFragment(null, null)); // empty FileDetailFragment
transaction.commit();
}
}
-
- if(getFile().getParentId() == 0){
- ActionBar actionBar = getSupportActionBar();
- actionBar.setDisplayHomeAsUpEnabled(false);
- }
}
+
@Override
protected void onSaveInstanceState(Bundle outState) {
// responsibility of restore is preferred in onCreate() before than in onRestoreInstanceState when there are Fragments involved
- Log_OC.d(TAG, "onSaveInstanceState() start");
+ Log_OC.e(TAG, "onSaveInstanceState() start");
super.onSaveInstanceState(outState);
- if (mDualPane) {
- FileFragment fragment = (FileFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
- if (fragment != null) {
- OCFile file = fragment.getFile();
- if (file != null) {
- outState.putParcelable(EXTRA_FILE, file);
- }
- }
- }
- outState.putParcelable(FileDetailActivity.KEY_WAITING_TO_PREVIEW, mWaitingToPreview);
+ outState.putParcelable(FileDisplayActivity.KEY_WAITING_TO_PREVIEW, mWaitingToPreview);
Log_OC.d(TAG, "onSaveInstanceState() end");
}
@Override
+ protected void onStart() {
+ super.onStart();
+ FileFragment second = getSecondFragment();
+ updateNavigationElementsInActionBar(getFile(), (second == null) ? null : second.getFile());
+ }
+
+ @Override
protected void onResume() {
- Log_OC.d(TAG, "onResume() start");
super.onResume();
+ Log_OC.e(TAG, "onResume() start");
// Listen for sync messages
IntentFilter syncIntentFilter = new IntentFilter(FileSyncService.SYNC_MESSAGE);
registerReceiver(mDownloadFinishReceiver, downloadIntentFilter);
// List current directory
- mFileList.listDirectory(getFile()); // TODO we should find the way to avoid the need of this (maybe it's not necessary yet; to check)
+ OCFileListFragment listOfFiles = getListOfFilesFragment();
+ if (listOfFiles != null) {
+ listOfFiles.listDirectory(getFile()); // TODO we should find the way to avoid the need of this (maybe it's not necessary yet; to check)
+ }
Log_OC.d(TAG, "onResume() end");
}
@Override
protected void onPause() {
- Log_OC.d(TAG, "onPause() start");
super.onPause();
+ Log_OC.e(TAG, "onPause() start");
if (mSyncBroadcastReceiver != null) {
unregisterReceiver(mSyncBroadcastReceiver);
mSyncBroadcastReceiver = null;
boolean inProgress = intent.getBooleanExtra(FileSyncService.IN_PROGRESS, false);
String accountName = intent.getStringExtra(FileSyncService.ACCOUNT_NAME);
- Log_OC.d("FileDisplay", "sync of account " + accountName + " is in_progress: " + inProgress);
+ Log_OC.d(TAG, "sync of account " + accountName + " is in_progress: " + inProgress);
if (getAccount() != null && accountName.equals(getAccount().name)) {
|| fillBlankRoot ) {
if (!fillBlankRoot)
currentDir = getStorageManager().getFileByPath(synchFolderRemotePath);
- OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager()
- .findFragmentById(R.id.fileList);
+ OCFileListFragment fileListFragment = getListOfFilesFragment();
if (fileListFragment != null) {
fileListFragment.listDirectory(currentDir);
}
boolean sameAccount = getAccount() != null && accountName.equals(getAccount().name);
boolean isDescendant = (getFile() != null) && (uploadedRemotePath != null) && (uploadedRemotePath.startsWith(getFile().getRemotePath()));
if (sameAccount && isDescendant) {
- OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);
- if (fileListFragment != null) {
- fileListFragment.listDirectory();
- }
+ refeshListOfFilesFragment();
}
}
boolean isDescendant = isDescendant(downloadedRemotePath);
if (sameAccount && isDescendant) {
- updateLeftPanel();
- if (mDualPane) {
- updateRightPanel(intent.getAction(), downloadedRemotePath, intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false));
- }
+ refeshListOfFilesFragment();
+ updateSecondFragment(intent.getAction(), downloadedRemotePath, intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false));
}
removeStickyBroadcast(intent);
}
- protected void updateLeftPanel() {
- OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);
+ protected void refeshListOfFilesFragment() {
+ OCFileListFragment fileListFragment = getListOfFilesFragment();
if (fileListFragment != null) {
fileListFragment.listDirectory();
}
}
- protected void updateRightPanel(String downloadEvent, String downloadedRemotePath, boolean success) {
- Fragment fragment = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
+ protected void updateSecondFragment(String downloadEvent, String downloadedRemotePath, boolean success) {
+ FileFragment secondFragment = getSecondFragment();
boolean waitedPreview = (mWaitingToPreview != null && mWaitingToPreview.getRemotePath().equals(downloadedRemotePath));
- if (fragment != null && fragment instanceof FileDetailFragment) {
- FileDetailFragment detailsFragment = (FileDetailFragment) fragment;
+ if (secondFragment != null && secondFragment instanceof FileDetailFragment) {
+ FileDetailFragment detailsFragment = (FileDetailFragment) secondFragment;
OCFile fileInFragment = detailsFragment.getFile();
if (fileInFragment != null && !downloadedRemotePath.equals(fileInFragment.getRemotePath())) {
// the user browsed to other file ; forget the automatic preview
if (success && waitedPreview) {
mWaitingToPreview = mStorageManager.getFileById(mWaitingToPreview.getFileId()); // update the file from database, for the local storage path
if (PreviewMediaFragment.canBePreviewed(mWaitingToPreview)) {
- FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
- transaction.replace(R.id.file_details_container, new PreviewMediaFragment(mWaitingToPreview, getAccount(), 0, true), FileDetailFragment.FTAG);
- transaction.commit();
+ startMediaPreview(mWaitingToPreview, 0, true);
+
} else {
detailsFragment.updateFileDetails(false, (success));
openFile(mWaitingToPreview);
-
}
mWaitingToPreview = null;
/**
* {@inheritDoc}
+ *
+ * Updates action bar and second fragment, if in dual pane mode.
*/
@Override
- public void onDirectoryClick(OCFile directory) {
+ public void onBrowsedDownTo(OCFile directory) {
pushDirname(directory);
- ActionBar actionBar = getSupportActionBar();
- actionBar.setDisplayHomeAsUpEnabled(true);
-
- if (mDualPane) {
- // Resets the FileDetailsFragment on Tablets so that it always displays
- Fragment fileFragment = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
- if (fileFragment != null && (fileFragment instanceof PreviewMediaFragment || !((FileDetailFragment) fileFragment).isEmpty())) {
- FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
- transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null), FileDetailFragment.FTAG); // empty FileDetailFragment
- transaction.commit();
- }
- }
+ cleanSecondFragment();
+ updateNavigationElementsInActionBar(directory, null);
}
-
/**
- * {@inheritDoc}
+ * Opens the image gallery showing the image {@link OCFile} received as parameter.
+ *
+ * @param file Image {@link OCFile} to show.
*/
@Override
- public void onFileClick(OCFile file, boolean onOrientationChange) {
- if (file != null) {
- if (PreviewImageFragment.canBePreviewed(file)) {
- // preview image - it handles the download, if needed
- startPreviewImage(file);
-
- } else if (PreviewMediaFragment.canBePreviewed(file)) {
- if (file.isDown()) {
- // general preview
- if (!onOrientationChange) {
- startMediaPreview(file, 0, true, onOrientationChange);
- } else {
- int startPlaybackPosition = 0;
- boolean autoplay = true;
- Fragment fragment = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
- if (fragment != null && file.isVideo()) {
- PreviewMediaFragment videoFragment = (PreviewMediaFragment)fragment;
- startPlaybackPosition = videoFragment.getPosition();
- autoplay = videoFragment.isPlaying();
- }
- startMediaPreview(file, startPlaybackPosition, autoplay, onOrientationChange);
- }
-
- } else {
- // automatic download, preview on finish
- startDownloadForPreview(file, onOrientationChange);
-
- }
-
- } else if (file.isDown() && !onOrientationChange) {
- openFile(file);
-
- } else {
- startDownloadForPreview(file, onOrientationChange);
- }
- }
- }
-
- private void startPreviewImage(OCFile file) {
+ public void startImagePreview(OCFile file) {
Intent showDetailsIntent = new Intent(this, PreviewImageActivity.class);
showDetailsIntent.putExtra(EXTRA_FILE, file);
showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
startActivity(showDetailsIntent);
}
- private void startMediaPreview(OCFile file, int startPlaybackPosition, boolean autoplay, boolean onOrientationChange) {
- if (mDualPane && !onOrientationChange) {
- FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
- transaction.replace(R.id.file_details_container, new PreviewMediaFragment(file, getAccount(), startPlaybackPosition, autoplay), FileDetailFragment.FTAG);
- transaction.commit();
-
- } else {
- Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);
- showDetailsIntent.putExtra(EXTRA_FILE, file);
- showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
- showDetailsIntent.putExtra(PreviewVideoActivity.EXTRA_START_POSITION, startPlaybackPosition);
- showDetailsIntent.putExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, autoplay);
- startActivity(showDetailsIntent);
- }
+ /**
+ * Stars the preview of an already down media {@link OCFile}.
+ *
+ * @param file Media {@link OCFile} to preview.
+ * @param startPlaybackPosition Media position where the playback will be started, in milliseconds.
+ * @param autoplay When 'true', the playback will start without user interactions.
+ */
+ @Override
+ public void startMediaPreview(OCFile file, int startPlaybackPosition, boolean autoplay) {
+ Fragment mediaFragment = new PreviewMediaFragment(file, getAccount(), startPlaybackPosition, autoplay);
+ setSecondFragment(mediaFragment);
+ updateNavigationElementsInActionBar(getFile(), file);
}
- private void startDownloadForPreview(OCFile file, boolean onOrientationChange) {
- if (mDualPane && !onOrientationChange) {
- FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
- transaction.replace(R.id.file_details_container, new FileDetailFragment(file, getAccount()), FileDetailFragment.FTAG);
- transaction.commit();
- mWaitingToPreview = file;
- requestForDownload();
-
+ /**
+ * Requests the download of the received {@link OCFile} , updates the UI
+ * to monitor the download progress and prepares the activity to preview
+ * or open the file when the download finishes.
+ *
+ * @param file {@link OCFile} to download and preview.
+ */
+ @Override
+ public void startDownloadForPreview(OCFile file) {
+ Fragment detailFragment = new FileDetailFragment(file, getAccount());
+ setSecondFragment(detailFragment);
+ mWaitingToPreview = file;
+ requestForDownload();
+ updateNavigationElementsInActionBar(getFile(), file);
+ }
+
+
+ /**
+ * Shows the information of the {@link OCFile} received as a
+ * parameter in the second fragment.
+ *
+ * @param file {@link OCFile} whose details will be shown
+ */
+ @Override
+ public void showDetails(OCFile file) {
+ Fragment detailFragment = new FileDetailFragment(file, getAccount());
+ setSecondFragment(detailFragment);
+ updateNavigationElementsInActionBar(getFile(), file);
+ }
+
+
+ /**
+ * Replaces the second fragment managed by the activity with the received as
+ * a parameter.
+ *
+ * Assumes never will be more than two fragments managed at the same time.
+ *
+ * @param fragment New second Fragment to set.
+ */
+ private void setSecondFragment(Fragment fragment) {
+ FragmentManager fm = getSupportFragmentManager();
+ FragmentTransaction transaction = fm.beginTransaction();
+ if (mDualPane) {
+ transaction.replace(R.id.right_fragment_container, fragment);
} else {
- Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);
- showDetailsIntent.putExtra(EXTRA_FILE, file);
- showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
- startActivity(showDetailsIntent);
+ transaction.replace(R.id.single_fragment_container, fragment);
+ while (fm.getBackStackEntryCount() > 0) {
+ fm.popBackStackImmediate();
+ }
+ transaction.addToBackStack(null);
}
+ transaction.commit();
+
+ /// TODO UPDATE ACTION BAR ACCORDING TO SECONDFRAGMENT!!
}
-
- private void startDetails(OCFile file, boolean onOrientationChange) {
- if (mDualPane && !file.isImage() && !onOrientationChange) {
- FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
- transaction.replace(R.id.file_details_container, new FileDetailFragment(file, getAccount()), FileDetailFragment.FTAG);
- transaction.commit();
+
+ /**
+ * TODO
+ */
+ private void updateNavigationElementsInActionBar(OCFile currentDir, OCFile currentFile) {
+ ActionBar actionBar = getSupportActionBar();
+ if (currentFile == null) {
+ // only list of files - set for browsing through folders
+ actionBar.setDisplayHomeAsUpEnabled(currentDir != null && currentDir.getParentId() != 0);
+ actionBar.setDisplayShowTitleEnabled(false);
+ actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
+ actionBar.setListNavigationCallbacks(mDirectories, this); // assuming mDirectoris is updated
+
} else {
- Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);
- showDetailsIntent.putExtra(EXTRA_FILE, file);
- showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
- startActivity(showDetailsIntent);
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ actionBar.setDisplayShowTitleEnabled(true);
+ actionBar.setTitle(currentFile.getFileName());
+ actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
}
}
-
-
+
+
/**
* {@inheritDoc}
*/
*/
@Override
public void onFileStateChanged() {
- OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);
- if (fileListFragment != null) {
- fileListFragment.listDirectory();
- }
+ refeshListOfFilesFragment();
}
return;
}
// a new chance to get the mDownloadBinder through getFileDownloadBinder() - THIS IS A MESS
- if (mFileList != null)
- mFileList.listDirectory();
- if (mDualPane) {
- Fragment fragment = getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
- if (fragment != null && fragment instanceof FileDetailFragment) {
- FileDetailFragment detailFragment = (FileDetailFragment)fragment;
- detailFragment.listenForTransferProgress();
- detailFragment.updateFileDetails(false, false);
- }
+ OCFileListFragment listOfFiles = getListOfFilesFragment();
+ if (listOfFiles != null) {
+ listOfFiles.listDirectory();
+ }
+ FileFragment secondFragment = getSecondFragment();
+ if (secondFragment != null && secondFragment instanceof FileDetailFragment) {
+ FileDetailFragment detailFragment = (FileDetailFragment)secondFragment;
+ detailFragment.listenForTransferProgress();
+ detailFragment.updateFileDetails(false, false);
}
}
Toast msg = Toast.makeText(this, R.string.remove_success_msg, Toast.LENGTH_LONG);
msg.show();
OCFile removedFile = operation.getFile();
+ getSecondFragment();
if (mDualPane) {
- FileFragment details = (FileFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
- if (details != null && removedFile.equals(details.getFile())) {
- FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
- transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null)); // empty FileDetailFragment
- transaction.commit();
+ FileFragment second = getSecondFragment();
+ if (second != null && removedFile.equals(second.getFile())) {
+ cleanSecondFragment(); // TODO this only cleans in DUAL PANE!!
}
}
if (mStorageManager.getFileById(removedFile.getParentId()).equals(getFile())) {
- mFileList.listDirectory();
+ refeshListOfFilesFragment();
}
} else {
private void onCreateFolderOperationFinish(CreateFolderOperation operation, RemoteOperationResult result) {
if (result.isSuccess()) {
dismissDialog(DIALOG_SHORT_WAIT);
- mFileList.listDirectory();
+ refeshListOfFilesFragment();
} else {
dismissDialog(DIALOG_SHORT_WAIT);
OCFile renamedFile = operation.getFile();
if (result.isSuccess()) {
if (mDualPane) {
- FileFragment details = (FileFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
+ FileFragment details = (FileFragment) getSupportFragmentManager().findFragmentById(R.id.right_fragment_container);
if (details != null && details instanceof FileDetailFragment && renamedFile.equals(details.getFile()) ) {
((FileDetailFragment) details).updateFileDetails(renamedFile, getAccount());
}
}
if (mStorageManager.getFileById(renamedFile.getParentId()).equals(getFile())) {
- mFileList.listDirectory();
+ refeshListOfFilesFragment();
}
} else {
} else {
if (operation.transferWasRequested()) {
- mFileList.listDirectory();
+ refeshListOfFilesFragment();
onTransferStateChanged(syncedFile, true, true);
} else {
*/
@Override
public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading) {
- /*OCFileListFragment fileListFragment = (OCFileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);
- if (fileListFragment != null) {
- fileListFragment.listDirectory();
- }*/
if (mDualPane) {
- FileFragment details = (FileFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
+ FileFragment details = (FileFragment) getSupportFragmentManager().findFragmentById(R.id.right_fragment_container);
if (details != null && details instanceof FileDetailFragment && file.equals(details.getFile()) ) {
if (downloading || uploading) {
((FileDetailFragment)details).updateFileDetails(file, getAccount());
}
- @Override
- public void showFragmentWithDetails(OCFile file) {
- if (mDualPane) {
- FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
- transaction.replace(R.id.file_details_container, new FileDetailFragment(file, getAccount()), FileDetailFragment.FTAG);
- transaction.commit();
-
- } else {
- Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);
- showDetailsIntent.putExtra(EXTRA_FILE, file);
- showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
- showDetailsIntent.putExtra(FileDetailActivity.EXTRA_MODE, FileDetailActivity.MODE_DETAILS);
- startActivity(showDetailsIntent);
- }
- }
-
public void onDismiss(EditNameDialog dialog) {
if (dialog.getResult()) {
String newDirectoryName = dialog.getNewFilename().trim();
--- /dev/null
+/* 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 com.actionbarsherlock.app.SherlockFragment;
+import com.owncloud.android.Log_OC;
+import com.owncloud.android.R;
+import com.owncloud.android.ui.ExtendedListView;
+
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.ListAdapter;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.ListView;
+
+/**
+ * TODO extending SherlockListFragment instead of SherlockFragment
+ */
+public class ExtendedListFragment extends SherlockFragment implements OnItemClickListener {
+
+ private static final String TAG = ExtendedListFragment.class.getSimpleName();
+
+ private static final String KEY_SAVED_LIST_POSITION = "SAVED_LIST_POSITION";
+
+ protected ExtendedListView mList;
+
+ public void setListAdapter(ListAdapter listAdapter) {
+ mList.setAdapter(listAdapter);
+ mList.invalidate();
+ }
+
+ public ListView getListView() {
+ return mList;
+ }
+
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ Log_OC.e(TAG, "onCreateView");
+ //mList = new ExtendedListView(getActivity());
+ View v = inflater.inflate(R.layout.list_fragment, null);
+ mList = (ExtendedListView)(v.findViewById(R.id.list_root));
+ mList.setOnItemClickListener(this);
+ //mList.setEmptyView(v.findViewById(R.id.empty_list_view)); // looks like it's not a cool idea
+ 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);
+ }
+
+ return v;
+ }
+
+
+ @Override
+ public void onSaveInstanceState(Bundle savedInstanceState) {
+ super.onSaveInstanceState(savedInstanceState);
+ Log_OC.e(TAG, "onSaveInstanceState()");
+ savedInstanceState.putInt(KEY_SAVED_LIST_POSITION, getReferencePosition());
+ }
+
+
+ /**
+ * Calculates the position of the item that will be used as a reference to reposition the visible items in the list when
+ * the device is turned to other position.
+ *
+ * THe current policy is take as a reference the visible item in the center of the screen.
+ *
+ * @return The position in the list of the visible item in the center of the screen.
+ */
+ protected int getReferencePosition() {
+ if (mList != null) {
+ return (mList.getFirstVisiblePosition() + mList.getLastVisiblePosition()) / 2;
+ } else {
+ return 0;
+ }
+ }
+
+
+ /**
+ * Sets the visible part of the list from the reference position.
+ *
+ * @param position Reference position previously returned by {@link LocalFileListFragment#getReferencePosition()}
+ */
+ protected void setReferencePosition(int position) {
+ if (mList != null) {
+ mList.setAndCenterSelection(position);
+ }
+ }
+
+ @Override
+ public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
+ // to be @overriden
+ }
+
+
+}
import android.widget.TextView;
import android.widget.Toast;
-import com.actionbarsherlock.app.SherlockFragment;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.owncloud.android.operations.SynchronizeFileOperation;
import com.owncloud.android.ui.activity.ConflictsResolveActivity;
import com.owncloud.android.ui.activity.FileActivity;
-import com.owncloud.android.ui.activity.FileDetailActivity;
import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.dialog.EditNameDialog;
import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener;
* @author Bartek Przybylski
* @author David A. Velasco
*/
-public class FileDetailFragment extends SherlockFragment implements
+public class FileDetailFragment extends FileFragment implements
OnClickListener,
- ConfirmationDialogFragment.ConfirmationDialogFragmentListener, OnRemoteOperationListener, EditNameDialogListener,
- FileFragment {
+ ConfirmationDialogFragment.ConfirmationDialogFragmentListener, OnRemoteOperationListener, EditNameDialogListener {
private FileFragment.ContainerActivity mContainerActivity;
private int mLayout;
private View mView;
- private OCFile mFile;
private Account mAccount;
private FileDataStorageManager mStorageManager;
private RemoteOperation mLastRemoteOperation;
private static final String TAG = FileDetailFragment.class.getSimpleName();
- public static final String FTAG = "FileDetails";
public static final String FTAG_CONFIRMATION = "REMOVE_CONFIRMATION_FRAGMENT";
* It's necessary to keep a public constructor without parameters; the system uses it when tries to reinstantiate a fragment automatically.
*/
public FileDetailFragment() {
- mFile = null;
+ super();
mAccount = null;
mStorageManager = null;
mLayout = R.layout.file_details_empty;
* @param ocAccount An ownCloud account; needed to start downloads
*/
public FileDetailFragment(OCFile fileToDetail, Account ocAccount) {
- mFile = fileToDetail;
+ super(fileToDetail);
mAccount = ocAccount;
mStorageManager = null; // we need a context to init this; the container activity is not available yet at this moment
mLayout = R.layout.file_details_empty;
super.onCreateView(inflater, container, savedInstanceState);
if (savedInstanceState != null) {
- mFile = savedInstanceState.getParcelable(FileActivity.EXTRA_FILE);
+ setFile((OCFile)savedInstanceState.getParcelable(FileActivity.EXTRA_FILE));
mAccount = savedInstanceState.getParcelable(FileActivity.EXTRA_ACCOUNT);
}
- if(mFile != null && mAccount != null) {
+ if(getFile() != null && mAccount != null) {
mLayout = R.layout.file_details_fragment;
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
- outState.putParcelable(FileActivity.EXTRA_FILE, mFile);
+ outState.putParcelable(FileActivity.EXTRA_FILE, getFile());
outState.putParcelable(FileActivity.EXTRA_ACCOUNT, mAccount);
}
List<Integer> toHide = new ArrayList<Integer>();
List<Integer> toShow = new ArrayList<Integer>();
+ OCFile file = getFile();
FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
- boolean downloading = downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile);
+ boolean downloading = downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file);
FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
- boolean uploading = uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile);
+ boolean uploading = uploaderBinder != null && uploaderBinder.isUploading(mAccount, getFile());
if (downloading || uploading) {
toHide.add(R.id.action_download_file);
toShow.add(R.id.action_cancel_download);
}
- } else if (mFile != null && mFile.isDown()) {
+ } else if (file != null && file.isDown()) {
toHide.add(R.id.action_download_file);
toHide.add(R.id.action_cancel_download);
toHide.add(R.id.action_cancel_upload);
toShow.add(R.id.action_open_file_with);
toShow.add(R.id.action_sync_file);
- } else if (mFile != null) {
+ } else if (file != null) {
toHide.add(R.id.action_open_file_with);
toHide.add(R.id.action_cancel_download);
toHide.add(R.id.action_cancel_upload);
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_open_file_with: {
- mContainerActivity.openFile(mFile);
+ mContainerActivity.openFile(getFile());
return true;
}
case R.id.action_remove_file: {
private void toggleKeepInSync() {
CheckBox cb = (CheckBox) getView().findViewById(R.id.fdKeepInSync);
- mFile.setKeepInSync(cb.isChecked());
- mStorageManager.saveFile(mFile);
+ OCFile file = getFile();
+ file.setKeepInSync(cb.isChecked());
+ mStorageManager.saveFile(file);
/// register the OCFile instance in the observer service to monitor local updates;
/// if necessary, the file is download
(cb.isChecked()?
FileObserverService.CMD_ADD_OBSERVED_FILE:
FileObserverService.CMD_DEL_OBSERVED_FILE));
- intent.putExtra(FileObserverService.KEY_CMD_ARG_FILE, mFile);
+ intent.putExtra(FileObserverService.KEY_CMD_ARG_FILE, file);
intent.putExtra(FileObserverService.KEY_CMD_ARG_ACCOUNT, mAccount);
getActivity().startService(intent);
- if (mFile.keepInSync()) {
+ if (file.keepInSync()) {
synchronizeFile(); // force an immediate synchronization
}
}
private void removeFile() {
+ OCFile file = getFile();
ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance(
R.string.confirmation_remove_alert,
- new String[]{mFile.getFileName()},
- mFile.isDown() ? R.string.confirmation_remove_remote_and_local : R.string.confirmation_remove_remote,
- mFile.isDown() ? R.string.confirmation_remove_local : -1,
+ new String[]{file.getFileName()},
+ file.isDown() ? R.string.confirmation_remove_remote_and_local : R.string.confirmation_remove_remote,
+ file.isDown() ? R.string.confirmation_remove_local : -1,
R.string.common_cancel);
confDialog.setOnConfirmationListener(this);
confDialog.show(getFragmentManager(), FTAG_CONFIRMATION);
private void renameFile() {
- String fileName = mFile.getFileName();
- int extensionStart = mFile.isDirectory() ? -1 : fileName.lastIndexOf(".");
+ OCFile file = getFile();
+ String fileName = file.getFileName();
+ int extensionStart = file.isDirectory() ? -1 : fileName.lastIndexOf(".");
int selectionEnd = (extensionStart >= 0) ? extensionStart : fileName.length();
EditNameDialog dialog = EditNameDialog.newInstance(getString(R.string.rename_dialog_title), fileName, 0, selectionEnd, this);
dialog.show(getFragmentManager(), "nameeditdialog");
}
private void synchronizeFile() {
+ OCFile file = getFile();
FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
- if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) {
- downloaderBinder.cancel(mAccount, mFile);
- if (mFile.isDown()) {
+ if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) {
+ downloaderBinder.cancel(mAccount, file);
+ if (file.isDown()) {
setButtonsForDown();
} else {
setButtonsForRemote();
}
- } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile)) {
- uploaderBinder.cancel(mAccount, mFile);
- if (!mFile.fileExists()) {
+ } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file)) {
+ uploaderBinder.cancel(mAccount, file);
+ if (!file.fileExists()) {
// TODO make something better
if (getActivity() instanceof FileDisplayActivity) {
// double pane
FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
- transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null), FTAG); // empty FileDetailFragment
+ transaction.replace(R.id.right_fragment_container, new FileDetailFragment(null, null)); // empty FileDetailFragment
transaction.commit();
mContainerActivity.onFileStateChanged();
} else {
getActivity().finish();
}
- } else if (mFile.isDown()) {
+ } else if (file.isDown()) {
setButtonsForDown();
} else {
setButtonsForRemote();
}
} else {
- mLastRemoteOperation = new SynchronizeFileOperation(mFile, null, mStorageManager, mAccount, true, false, getActivity());
+ mLastRemoteOperation = new SynchronizeFileOperation(file, null, mStorageManager, mAccount, true, false, getActivity());
mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
// update ui
boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
- getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
+ getActivity().showDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
}
}
@Override
public void onConfirmation(String callerTag) {
+ OCFile file = getFile();
if (callerTag.equals(FTAG_CONFIRMATION)) {
- if (mStorageManager.getFileById(mFile.getFileId()) != null) {
- mLastRemoteOperation = new RemoveFileOperation( mFile,
+ if (mStorageManager.getFileById(file.getFileId()) != null) {
+ mLastRemoteOperation = new RemoveFileOperation( file,
true,
mStorageManager);
mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
- getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
+ getActivity().showDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
}
}
}
@Override
public void onNeutral(String callerTag) {
File f = null;
- if (mFile.isDown() && (f = new File(mFile.getStoragePath())).exists()) {
+ OCFile file = getFile();
+ if (file.isDown() && (f = new File(file.getStoragePath())).exists()) {
f.delete();
- mFile.setStoragePath(null);
- mStorageManager.saveFile(mFile);
- updateFileDetails(mFile, mAccount);
+ file.setStoragePath(null);
+ mStorageManager.saveFile(file);
+ updateFileDetails(file, mAccount);
}
}
* @return True when the fragment was created with the empty layout.
*/
public boolean isEmpty() {
- return (mLayout == R.layout.file_details_empty || mFile == null || mAccount == null);
+ return (mLayout == R.layout.file_details_empty || getFile() == null || mAccount == null);
}
/**
- * {@inheritDoc}
- */
- public OCFile getFile(){
- return mFile;
- }
-
- /**
* Use this method to signal this Activity that it shall update its view.
*
* @param file : An {@link OCFile}
*/
public void updateFileDetails(OCFile file, Account ocAccount) {
- mFile = file;
+ setFile(file);
if (ocAccount != null && (
mStorageManager == null ||
(mAccount != null && !mAccount.equals(ocAccount))
if (readyToShow()) {
if (refresh && mStorageManager != null) {
- mFile = mStorageManager.getFileByPath(mFile.getRemotePath());
+ setFile(mStorageManager.getFileByPath(getFile().getRemotePath()));
}
+ OCFile file = getFile();
// set file details
- setFilename(mFile.getFileName());
- setFiletype(mFile.getMimetype());
- setFilesize(mFile.getFileLength());
+ setFilename(file.getFileName());
+ setFiletype(file.getMimetype());
+ setFilesize(file.getFileLength());
if(ocVersionSupportsTimeCreated()){
- setTimeCreated(mFile.getCreationTimestamp());
+ setTimeCreated(file.getCreationTimestamp());
}
- setTimeModified(mFile.getModificationTimestamp());
+ setTimeModified(file.getModificationTimestamp());
CheckBox cb = (CheckBox)getView().findViewById(R.id.fdKeepInSync);
- cb.setChecked(mFile.keepInSync());
+ cb.setChecked(file.keepInSync());
// configure UI for depending upon local state of the file
//if (FileDownloader.isDownloading(mAccount, mFile.getRemotePath()) || FileUploader.isUploading(mAccount, mFile.getRemotePath())) {
FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
- if (transferring || (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) || (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile))) {
+ if (transferring || (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) || (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file))) {
setButtonsForTransferring();
- } else if (mFile.isDown()) {
+ } else if (file.isDown()) {
setButtonsForDown();
* @return 'True' when the fragment is ready to show details of a file
*/
private boolean readyToShow() {
- return (mFile != null && mAccount != null && mLayout == R.layout.file_details_fragment);
+ return (getFile() != null && mAccount != null && mLayout == R.layout.file_details_fragment);
}
progressText.setVisibility(View.VISIBLE);
FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
- if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) {
+ if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, getFile())) {
progressText.setText(R.string.downloader_download_in_progress_ticker);
- } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile)) {
+ } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, getFile())) {
progressText.setText(R.string.uploader_upload_in_progress_ticker);
}
}
if (!isEmpty() && accountName.equals(mAccount.name)) {
boolean uploadWasFine = intent.getBooleanExtra(FileUploader.EXTRA_UPLOAD_RESULT, false);
String uploadRemotePath = intent.getStringExtra(FileUploader.EXTRA_REMOTE_PATH);
- boolean renamedInUpload = mFile.getRemotePath().equals(intent.getStringExtra(FileUploader.EXTRA_OLD_REMOTE_PATH));
- if (mFile.getRemotePath().equals(uploadRemotePath) ||
+ boolean renamedInUpload = getFile().getRemotePath().equals(intent.getStringExtra(FileUploader.EXTRA_OLD_REMOTE_PATH));
+ if (getFile().getRemotePath().equals(uploadRemotePath) ||
renamedInUpload) {
if (uploadWasFine) {
- mFile = mStorageManager.getFileByPath(uploadRemotePath);
+ setFile(mStorageManager.getFileByPath(uploadRemotePath));
}
if (renamedInUpload) {
String newName = (new File(uploadRemotePath)).getName();
if (dialog.getResult()) {
String newFilename = dialog.getNewFilename();
Log_OC.d(TAG, "name edit dialog dismissed with new name " + newFilename);
- mLastRemoteOperation = new RenameFileOperation( mFile,
+ mLastRemoteOperation = new RenameFileOperation( getFile(),
mAccount,
newFilename,
new FileDataStorageManager(mAccount, getActivity().getContentResolver()));
mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
- getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
+ getActivity().showDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
}
}
private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) {
boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
- getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
+ getActivity().dismissDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
if (result.isSuccess()) {
Toast msg = Toast.makeText(getActivity().getApplicationContext(), R.string.remove_success_msg, Toast.LENGTH_LONG);
if (inDisplayActivity) {
// double pane
FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
- transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null)); // empty FileDetailFragment
+ transaction.replace(R.id.right_fragment_container, new FileDetailFragment(null, null)); // empty FileDetailFragment
transaction.commit();
mContainerActivity.onFileStateChanged();
} else {
private void onRenameFileOperationFinish(RenameFileOperation operation, RemoteOperationResult result) {
boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
- getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
+ getActivity().dismissDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
if (result.isSuccess()) {
updateFileDetails(((RenameFileOperation)operation).getFile(), mAccount);
private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation, RemoteOperationResult result) {
boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
- getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
-
+ getActivity().dismissDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
+ OCFile file = getFile();
if (!result.isSuccess()) {
if (result.getCode() == ResultCode.SYNC_CONFLICT) {
Intent i = new Intent(getActivity(), ConflictsResolveActivity.class);
- i.putExtra(ConflictsResolveActivity.EXTRA_FILE, mFile);
+ i.putExtra(ConflictsResolveActivity.EXTRA_FILE, file);
i.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, mAccount);
startActivity(i);
msg.show();
}
- if (mFile.isDown()) {
+ if (file.isDown()) {
setButtonsForDown();
} else {
} else {
Toast msg = Toast.makeText(getActivity(), R.string.sync_file_nothing_to_do_msg, Toast.LENGTH_LONG);
msg.show();
- if (mFile.isDown()) {
+ if (file.isDown()) {
setButtonsForDown();
} else {
public void listenForTransferProgress() {
if (mProgressListener != null) {
if (mContainerActivity.getFileDownloaderBinder() != null) {
- mContainerActivity.getFileDownloaderBinder().addDatatransferProgressListener(mProgressListener, mAccount, mFile);
+ mContainerActivity.getFileDownloaderBinder().addDatatransferProgressListener(mProgressListener, mAccount, getFile());
}
if (mContainerActivity.getFileUploaderBinder() != null) {
- mContainerActivity.getFileUploaderBinder().addDatatransferProgressListener(mProgressListener, mAccount, mFile);
+ mContainerActivity.getFileUploaderBinder().addDatatransferProgressListener(mProgressListener, mAccount, getFile());
}
}
}
public void leaveTransferProgress() {
if (mProgressListener != null) {
if (mContainerActivity.getFileDownloaderBinder() != null) {
- mContainerActivity.getFileDownloaderBinder().removeDatatransferProgressListener(mProgressListener, mAccount, mFile);
+ mContainerActivity.getFileDownloaderBinder().removeDatatransferProgressListener(mProgressListener, mAccount, getFile());
}
if (mContainerActivity.getFileUploaderBinder() != null) {
- mContainerActivity.getFileUploaderBinder().removeDatatransferProgressListener(mProgressListener, mAccount, mFile);
+ mContainerActivity.getFileUploaderBinder().removeDatatransferProgressListener(mProgressListener, mAccount, getFile());
}
}
}
};
- /*
- // this is a temporary class for sharing purposes, it need to be replaced in transfer service
- @SuppressWarnings("unused")
- private class ShareRunnable implements Runnable {
- private String mPath;
-
- public ShareRunnable(String path) {
- mPath = path;
- }
-
- public void run() {
- AccountManager am = AccountManager.get(getActivity());
- Account account = AccountUtils.getCurrentOwnCloudAccount(getActivity());
- OwnCloudVersion ocv = new OwnCloudVersion(am.getUserData(account, AccountAuthenticator.KEY_OC_VERSION));
- String url = am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + AccountUtils.getWebdavPath(ocv);
-
- Log_OC.d("share", "sharing for version " + ocv.toString());
-
- if (ocv.compareTo(new OwnCloudVersion(0x040000)) >= 0) {
- String APPS_PATH = "/apps/files_sharing/";
- String SHARE_PATH = "ajax/share.php";
-
- String SHARED_PATH = "/apps/files_sharing/get.php?token=";
-
- final String WEBDAV_SCRIPT = "webdav.php";
- final String WEBDAV_FILES_LOCATION = "/files/";
-
- WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(account, getActivity().getApplicationContext());
- HttpConnectionManagerParams params = new HttpConnectionManagerParams();
- params.setMaxConnectionsPerHost(wc.getHostConfiguration(), 5);
-
- //wc.getParams().setParameter("http.protocol.single-cookie-header", true);
- //wc.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
-
- PostMethod post = new PostMethod(am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + APPS_PATH + SHARE_PATH);
-
- post.addRequestHeader("Content-type","application/x-www-form-urlencoded; charset=UTF-8" );
- post.addRequestHeader("Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL));
- List<NameValuePair> formparams = new ArrayList<NameValuePair>();
- Log_OC.d("share", mPath+"");
- formparams.add(new BasicNameValuePair("sources",mPath));
- formparams.add(new BasicNameValuePair("uid_shared_with", "public"));
- formparams.add(new BasicNameValuePair("permissions", "0"));
- post.setRequestEntity(new StringRequestEntity(URLEncodedUtils.format(formparams, HTTP.UTF_8)));
-
- int status;
- try {
- PropFindMethod find = new PropFindMethod(url+"/");
- find.addRequestHeader("Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL));
- Log_OC.d("sharer", ""+ url+"/");
-
- for (org.apache.commons.httpclient.Header a : find.getRequestHeaders()) {
- Log_OC.d("sharer-h", a.getName() + ":"+a.getValue());
- }
-
- int status2 = wc.executeMethod(find);
-
- Log_OC.d("sharer", "propstatus "+status2);
-
- GetMethod get = new GetMethod(am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + "/");
- get.addRequestHeader("Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL));
-
- status2 = wc.executeMethod(get);
-
- Log_OC.d("sharer", "getstatus "+status2);
- Log_OC.d("sharer", "" + get.getResponseBodyAsString());
-
- for (org.apache.commons.httpclient.Header a : get.getResponseHeaders()) {
- Log_OC.d("sharer", a.getName() + ":"+a.getValue());
- }
-
- status = wc.executeMethod(post);
- for (org.apache.commons.httpclient.Header a : post.getRequestHeaders()) {
- Log_OC.d("sharer-h", a.getName() + ":"+a.getValue());
- }
- for (org.apache.commons.httpclient.Header a : post.getResponseHeaders()) {
- Log_OC.d("sharer", a.getName() + ":"+a.getValue());
- }
- String resp = post.getResponseBodyAsString();
- Log_OC.d("share", ""+post.getURI().toString());
- Log_OC.d("share", "returned status " + status);
- Log_OC.d("share", " " +resp);
-
- if(status != HttpStatus.SC_OK ||resp == null || resp.equals("") || resp.startsWith("false")) {
- return;
- }
-
- JSONObject jsonObject = new JSONObject (resp);
- String jsonStatus = jsonObject.getString("status");
- if(!jsonStatus.equals("success")) throw new Exception("Error while sharing file status != success");
-
- String token = jsonObject.getString("data");
- String uri = am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + SHARED_PATH + token;
- Log_OC.d("Actions:shareFile ok", "url: " + uri);
-
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- } else if (ocv.compareTo(new OwnCloudVersion(0x030000)) >= 0) {
-
- }
- }
- }
- */
-
}
package com.owncloud.android.ui.fragment;
-import android.content.Intent;
import android.support.v4.app.Fragment;
+import com.actionbarsherlock.app.SherlockFragment;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.files.FileHandler;
import com.owncloud.android.ui.activity.TransferServiceGetter;
* @author David A. Velasco
*
*/
-public interface FileFragment {
+public class FileFragment extends SherlockFragment {
+
+ private OCFile mFile;
+
+
+ /**
+ * Creates an empty fragment.
+ *
+ * It's necessary to keep a public constructor without parameters; the system uses it when tries to reinstantiate a fragment automatically.
+ */
+ public FileFragment() {
+ mFile = null;
+ }
/**
+ * Creates an instance for a given {@OCFile}.
+ *
+ * @param file
+ */
+ public FileFragment(OCFile file) {
+ mFile = file;
+ }
+
+ /**
* Getter for the hold {@link OCFile}
*
* @return The {@link OCFile} hold
*/
- public OCFile getFile();
+ public OCFile getFile() {
+ return mFile;
+ }
+ protected void setFile(OCFile file) {
+ mFile = file;
+ }
+
/**
* Interface to implement by any Activity that includes some instance of FileFragment
*
*
* @param file File to show details
*/
- public void showFragmentWithDetails(OCFile file);
+ public void showDetails(OCFile file);
}
import java.io.File;
-import com.owncloud.android.ui.FragmentListView;
import com.owncloud.android.ui.adapter.LocalFileListAdapter;
import android.app.Activity;
* @author David A. Velasco
*
*/
-public class LocalFileListFragment extends FragmentListView {
+public class LocalFileListFragment extends ExtendedListFragment {
private static final String TAG = "LocalFileListFragment";
- private static final String SAVED_LIST_POSITION = "LIST_POSITION";
/** Reference to the Activity which this fragment is attached to. For callbacks */
private LocalFileListFragment.ContainerActivity mContainerActivity;
mAdapter = new LocalFileListAdapter(mContainerActivity.getInitialDirectory(), getActivity());
setListAdapter(mAdapter);
- if (savedInstanceState != null) {
- Log_OC.i(TAG, "savedInstanceState is not null");
- int position = savedInstanceState.getInt(SAVED_LIST_POSITION);
- setReferencePosition(position);
- }
-
Log_OC.i(TAG, "onActivityCreated() stop");
}
- @Override
- public void onSaveInstanceState(Bundle savedInstanceState) {
- Log_OC.i(TAG, "onSaveInstanceState() start");
-
- savedInstanceState.putInt(SAVED_LIST_POSITION, getReferencePosition());
-
-
- Log_OC.i(TAG, "onSaveInstanceState() stop");
- }
-
-
/**
* Checks the file clicked over. Browses inside if it is a directory. Notifies the container activity in any case.
*/
import com.owncloud.android.operations.RemoveFileOperation;
import com.owncloud.android.operations.RenameFileOperation;
import com.owncloud.android.operations.SynchronizeFileOperation;
-import com.owncloud.android.ui.FragmentListView;
import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.activity.TransferServiceGetter;
import com.owncloud.android.ui.adapter.FileListListAdapter;
import com.owncloud.android.ui.dialog.EditNameDialog;
import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener;
import com.owncloud.android.ui.fragment.ConfirmationDialogFragment.ConfirmationDialogFragmentListener;
+import com.owncloud.android.ui.preview.PreviewImageFragment;
+import com.owncloud.android.ui.preview.PreviewMediaFragment;
import android.accounts.Account;
import android.app.Activity;
* @author Bartek Przybylski
*
*/
-public class OCFileListFragment extends FragmentListView implements EditNameDialogListener, ConfirmationDialogFragmentListener {
- private static final String TAG = "FileListFragment";
+public class OCFileListFragment extends ExtendedListFragment implements EditNameDialogListener, ConfirmationDialogFragmentListener {
+ private static final String TAG = OCFileListFragment.class.getSimpleName();
private static final String SAVED_LIST_POSITION = "LIST_POSITION";
private OCFileListFragment.ContainerActivity mContainerActivity;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
+ Log_OC.e(TAG, "onAttach");
try {
mContainerActivity = (ContainerActivity) activity;
} catch (ClassCastException e) {
*/
@Override
public void onActivityCreated(Bundle savedInstanceState) {
- Log_OC.i(TAG, "onActivityCreated() start");
-
super.onActivityCreated(savedInstanceState);
+ Log_OC.e(TAG, "onActivityCreated() start");
mAdapter = new FileListListAdapter(mContainerActivity.getInitialDirectory(), mContainerActivity.getStorageManager(), getActivity(), mContainerActivity);
setListAdapter(mAdapter);
- if (savedInstanceState != null) {
- Log_OC.i(TAG, "savedInstanceState is not null");
- int position = savedInstanceState.getInt(SAVED_LIST_POSITION);
- setReferencePosition(position);
- }
-
registerForContextMenu(getListView());
getListView().setOnCreateContextMenuListener(this);
mHandler = new Handler();
-
- Log_OC.i(TAG, "onActivityCreated() stop");
}
-
- @Override
- public void onSaveInstanceState(Bundle savedInstanceState) {
- Log_OC.i(TAG, "onSaveInstanceState() start");
-
- savedInstanceState.putInt(SAVED_LIST_POSITION, getReferencePosition());
+ /**
+ * Call this, when the user presses the up button
+ */
+ public void onBrowseUp() {
+ OCFile parentDir = null;
- Log_OC.i(TAG, "onSaveInstanceState() stop");
+ if(mFile != null){
+ DataStorageManager storageManager = mContainerActivity.getStorageManager();
+ parentDir = storageManager.getFileById(mFile.getParentId());
+ mFile = parentDir;
+ }
+ listDirectory(parentDir);
}
-
@Override
public void onItemClick(AdapterView<?> l, View v, int position, long id) {
OCFile file = (OCFile) mAdapter.getItem(position);
if (file != null) {
- /// Click on a directory
- if (file.getMimetype().equals("DIR")) {
- // just local updates
+ if (file.isDirectory()) {
+ // update state and view of this fragment
mFile = file;
listDirectory(file);
- // any other updates are let to the container Activity
- mContainerActivity.onDirectoryClick(file);
-
- } else { /// Click on a file
- mContainerActivity.onFileClick(file, false);
+ // then, notify parent activity to let it update its state and view, and other fragments
+ mContainerActivity.onBrowsedDownTo(file);
+
+ } else { /// Click on a file
+ if (PreviewImageFragment.canBePreviewed(file)) {
+ // preview image - it handles the download, if needed
+ mContainerActivity.startImagePreview(file);
+
+ } else if (file.isDown()) {
+ if (PreviewMediaFragment.canBePreviewed(file)) {
+ // media preview
+ mContainerActivity.startMediaPreview(file, 0, true);
+ } else {
+ // open with
+ mContainerActivity.openFile(file);
+ }
+
+ } else {
+ // automatic download, preview on finish
+ mContainerActivity.startDownloadForPreview(file);
+ }
+
}
} else {
return true;
}
case R.id.action_see_details: {
- ((FileFragment.ContainerActivity)getActivity()).showFragmentWithDetails(mTargetFile);
+ ((FileFragment.ContainerActivity)getActivity()).showDetails(mTargetFile);
return true;
}
default:
/**
- * Call this, when the user presses the up button
- */
- public void onNavigateUp() {
- OCFile parentDir = null;
-
- if(mFile != null){
- DataStorageManager storageManager = mContainerActivity.getStorageManager();
- parentDir = storageManager.getFileById(mFile.getParentId());
- mFile = parentDir;
- }
- listDirectory(parentDir);
- }
-
- /**
* Use this to query the {@link OCFile} that is currently
* being displayed by this fragment
* @return The currently viewed OCFile
public interface ContainerActivity extends TransferServiceGetter, OnRemoteOperationListener, FileHandler {
/**
- * Callback method invoked when a directory is clicked by the user on the files list
+ * Callback method invoked when a the user browsed into a different folder through the list of files
*
* @param file
*/
- public void onDirectoryClick(OCFile file);
+ public void onBrowsedDownTo(OCFile folder);
- /**
- * Callback method invoked when a file (non directory) is clicked by the user on the files list
- *
- * @param file
- */
- public void onFileClick(OCFile file, boolean realClick);
+ public void startDownloadForPreview(OCFile file);
+
+ public void startMediaPreview(OCFile file, int i, boolean b);
+
+ public void startImagePreview(OCFile file);
/**
* Getter for the current DataStorageManager in the container activity
import android.widget.ProgressBar;
import android.widget.TextView;
-import com.actionbarsherlock.app.SherlockFragment;
-import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
import com.owncloud.android.ui.fragment.FileFragment;
*
* @author David A. Velasco
*/
-public class FileDownloadFragment extends SherlockFragment implements OnClickListener, FileFragment {
+public class FileDownloadFragment extends FileFragment implements OnClickListener {
public static final String EXTRA_FILE = "FILE";
public static final String EXTRA_ACCOUNT = "ACCOUNT";
private FileFragment.ContainerActivity mContainerActivity;
private View mView;
- private OCFile mFile;
private Account mAccount;
- private FileDataStorageManager mStorageManager;
public ProgressListener mProgressListener;
private boolean mListening;
* It's necessary to keep a public constructor without parameters; the system uses it when tries to reinstantiate a fragment automatically.
*/
public FileDownloadFragment() {
- mFile = null;
+ super();
mAccount = null;
- mStorageManager = null;
mProgressListener = null;
mListening = false;
mIgnoreFirstSavedState = false;
* @param ignoreFirstSavedState Flag to work around an unexpected behaviour of {@link FragmentStatePagerAdapter}; TODO better solution
*/
public FileDownloadFragment(OCFile fileToDetail, Account ocAccount, boolean ignoreFirstSavedState) {
- mFile = fileToDetail;
+ super(fileToDetail);
mAccount = ocAccount;
- mStorageManager = null; // we need a context to init this; the container activity is not available yet at this moment
mProgressListener = null;
mListening = false;
mIgnoreFirstSavedState = ignoreFirstSavedState;
if (savedInstanceState != null) {
if (!mIgnoreFirstSavedState) {
- mFile = savedInstanceState.getParcelable(FileDownloadFragment.EXTRA_FILE);
+ setFile((OCFile)savedInstanceState.getParcelable(FileDownloadFragment.EXTRA_FILE));
mAccount = savedInstanceState.getParcelable(FileDownloadFragment.EXTRA_ACCOUNT);
mError = savedInstanceState.getBoolean(FileDownloadFragment.EXTRA_ERROR);
} else {
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (mAccount != null) {
- mStorageManager = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver());;
+ //mStorageManager = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver());;
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
- outState.putParcelable(FileDownloadFragment.EXTRA_FILE, mFile);
+ outState.putParcelable(FileDownloadFragment.EXTRA_FILE, getFile());
outState.putParcelable(FileDownloadFragment.EXTRA_ACCOUNT, mAccount);
outState.putBoolean(FileDownloadFragment.EXTRA_ERROR, mError);
}
switch (v.getId()) {
case R.id.cancelBtn: {
FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
- if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) {
- downloaderBinder.cancel(mAccount, mFile);
+ if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, getFile())) {
+ downloaderBinder.cancel(mAccount, getFile());
getActivity().finish(); // :)
/*
leaveTransferProgress();
/**
- * {@inheritDoc}
- */
- public OCFile getFile(){
- return mFile;
- }
-
-
- /**
* Updates the view depending upon the state of the downloading file.
*
* @param transferring When true, the view must be updated assuming that the holded file is
public void updateView(boolean transferring) {
// configure UI for depending upon local state of the file
FileDownloaderBinder downloaderBinder = (mContainerActivity == null) ? null : mContainerActivity.getFileDownloaderBinder();
- if (transferring || (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile))) {
+ if (transferring || (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, getFile()))) {
setButtonsForTransferring();
- } else if (mFile.isDown()) {
+ } else if (getFile().isDown()) {
setButtonsForDown();
public void listenForTransferProgress() {
if (mProgressListener != null && !mListening) {
if (mContainerActivity.getFileDownloaderBinder() != null) {
- mContainerActivity.getFileDownloaderBinder().addDatatransferProgressListener(mProgressListener, mAccount, mFile);
+ mContainerActivity.getFileDownloaderBinder().addDatatransferProgressListener(mProgressListener, mAccount, getFile());
mListening = true;
setButtonsForTransferring();
}
public void leaveTransferProgress() {
if (mProgressListener != null) {
if (mContainerActivity.getFileDownloaderBinder() != null) {
- mContainerActivity.getFileDownloaderBinder().removeDatatransferProgressListener(mProgressListener, mAccount, mFile);
+ mContainerActivity.getFileDownloaderBinder().removeDatatransferProgressListener(mProgressListener, mAccount, getFile());
mListening = false;
}
}
import com.owncloud.android.files.services.FileUploader;
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
import com.owncloud.android.ui.activity.FileActivity;
-import com.owncloud.android.ui.activity.FileDetailActivity;
+import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.fragment.FileFragment;
import com.owncloud.android.AccountUtils;
@Override
- public void showFragmentWithDetails(OCFile file) {
- Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);
+ public void showDetails(OCFile file) {
+ Intent showDetailsIntent = new Intent(this, FileDisplayActivity.class);
+ showDetailsIntent.setAction(FileDisplayActivity.ACTION_DETAILS);
showDetailsIntent.putExtra(FileActivity.EXTRA_FILE, file);
showDetailsIntent.putExtra(FileActivity.EXTRA_ACCOUNT, AccountUtils.getCurrentOwnCloudAccount(this));
- showDetailsIntent.putExtra(FileDetailActivity.EXTRA_MODE, FileDetailActivity.MODE_DETAILS);
startActivity(showDetailsIntent);
int pos = mPreviewImagePagerAdapter.getFilePosition(file);
file = mPreviewImagePagerAdapter.getFileAt(pos);
import android.widget.TextView;
import android.widget.Toast;
-import com.actionbarsherlock.app.SherlockFragment;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
*
* @author David A. Velasco
*/
-public class PreviewImageFragment extends SherlockFragment implements FileFragment,
- OnRemoteOperationListener,
+public class PreviewImageFragment extends FileFragment implements OnRemoteOperationListener,
ConfirmationDialogFragment.ConfirmationDialogFragmentListener {
public static final String EXTRA_FILE = "FILE";
public static final String EXTRA_ACCOUNT = "ACCOUNT";
private View mView;
- private OCFile mFile;
private Account mAccount;
private FileDataStorageManager mStorageManager;
private ImageView mImageView;
* @param ignoreFirstSavedState Flag to work around an unexpected behaviour of {@link FragmentStatePagerAdapter}; TODO better solution
*/
public PreviewImageFragment(OCFile fileToDetail, Account ocAccount, boolean ignoreFirstSavedState) {
- mFile = fileToDetail;
+ super(fileToDetail);
mAccount = ocAccount;
mStorageManager = null; // we need a context to init this; the container activity is not available yet at this moment
mIgnoreFirstSavedState = ignoreFirstSavedState;
* DO NOT CALL IT: an {@link OCFile} and {@link Account} must be provided for a successful construction
*/
public PreviewImageFragment() {
- mFile = null;
+ super();
mAccount = null;
mStorageManager = null;
mIgnoreFirstSavedState = false;
mStorageManager = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver());
if (savedInstanceState != null) {
if (!mIgnoreFirstSavedState) {
- mFile = savedInstanceState.getParcelable(PreviewImageFragment.EXTRA_FILE);
+ setFile((OCFile)savedInstanceState.getParcelable(PreviewImageFragment.EXTRA_FILE));
mAccount = savedInstanceState.getParcelable(PreviewImageFragment.EXTRA_ACCOUNT);
} else {
mIgnoreFirstSavedState = false;
}
}
- if (mFile == null) {
+ if (getFile() == null) {
throw new IllegalStateException("Instanced with a NULL OCFile");
}
if (mAccount == null) {
throw new IllegalStateException("Instanced with a NULL ownCloud Account");
}
- if (!mFile.isDown()) {
+ if (!getFile().isDown()) {
throw new IllegalStateException("There is no local file to preview");
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
- outState.putParcelable(PreviewImageFragment.EXTRA_FILE, mFile);
+ outState.putParcelable(PreviewImageFragment.EXTRA_FILE, getFile());
outState.putParcelable(PreviewImageFragment.EXTRA_ACCOUNT, mAccount);
}
@Override
public void onStart() {
super.onStart();
- if (mFile != null) {
+ if (getFile() != null) {
BitmapLoader bl = new BitmapLoader(mImageView, mMessageView, mProgressWheel);
- bl.execute(new String[]{mFile.getStoragePath()});
+ bl.execute(new String[]{getFile().getStoragePath()});
}
}
private void seeDetails() {
- ((FileFragment.ContainerActivity)getActivity()).showFragmentWithDetails(mFile);
+ ((FileFragment.ContainerActivity)getActivity()).showDetails(getFile());
}
@Override
public void onResume() {
super.onResume();
- //Log.e(TAG, "FRAGMENT, ONRESUME");
- /*
- mDownloadFinishReceiver = new DownloadFinishReceiver();
- IntentFilter filter = new IntentFilter(
- FileDownloader.DOWNLOAD_FINISH_MESSAGE);
- getActivity().registerReceiver(mDownloadFinishReceiver, filter);
-
- mUploadFinishReceiver = new UploadFinishReceiver();
- filter = new IntentFilter(FileUploader.UPLOAD_FINISH_MESSAGE);
- getActivity().registerReceiver(mUploadFinishReceiver, filter);
- */
-
}
@Override
public void onPause() {
super.onPause();
- /*
- if (mVideoPreview.getVisibility() == View.VISIBLE) {
- mSavedPlaybackPosition = mVideoPreview.getCurrentPosition();
- }*/
- /*
- getActivity().unregisterReceiver(mDownloadFinishReceiver);
- mDownloadFinishReceiver = null;
-
- getActivity().unregisterReceiver(mUploadFinishReceiver);
- mUploadFinishReceiver = null;
- */
}
* available apps for the MIME type known from the file extension, to let the user choose
*/
private void openFile() {
- String storagePath = mFile.getStoragePath();
+ OCFile file = getFile();
+ String storagePath = file.getStoragePath();
String encodedStoragePath = WebdavUtils.encodePath(storagePath);
try {
Intent i = new Intent(Intent.ACTION_VIEW);
- i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), mFile.getMimetype());
+ i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), file.getMimetype());
i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
startActivity(i);
} catch (Throwable t) {
- Log_OC.e(TAG, "Fail when trying to open with the mimeType provided from the ownCloud server: " + mFile.getMimetype());
+ Log_OC.e(TAG, "Fail when trying to open with the mimeType provided from the ownCloud server: " + file.getMimetype());
boolean toastIt = true;
String mimeType = "";
try {
Intent i = new Intent(Intent.ACTION_VIEW);
mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1));
- if (mimeType == null || !mimeType.equals(mFile.getMimetype())) {
+ if (mimeType == null || !mimeType.equals(file.getMimetype())) {
if (mimeType != null) {
i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), mimeType);
} else {
} finally {
if (toastIt) {
- Toast.makeText(getActivity(), "There is no application to handle file " + mFile.getFileName(), Toast.LENGTH_SHORT).show();
+ Toast.makeText(getActivity(), "There is no application to handle file " + file.getFileName(), Toast.LENGTH_SHORT).show();
}
}
private void removeFile() {
ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance(
R.string.confirmation_remove_alert,
- new String[]{mFile.getFileName()},
+ new String[]{getFile().getFileName()},
R.string.confirmation_remove_remote_and_local,
R.string.confirmation_remove_local,
R.string.common_cancel);
*/
@Override
public void onConfirmation(String callerTag) {
- if (mStorageManager.getFileById(mFile.getFileId()) != null) { // check that the file is still there;
- mLastRemoteOperation = new RemoveFileOperation( mFile, // TODO we need to review the interface with RemoteOperations, and use OCFile IDs instead of OCFile objects as parameters
+ if (mStorageManager.getFileById(getFile().getFileId()) != null) { // check that the file is still there;
+ mLastRemoteOperation = new RemoveFileOperation( getFile(), // TODO we need to review the interface with RemoteOperations, and use OCFile IDs instead of OCFile objects as parameters
true,
mStorageManager);
mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
@Override
public void onNeutral(String callerTag) {
// TODO this code should be made in a secondary thread,
- if (mFile.isDown()) { // checks it is still there
- File f = new File(mFile.getStoragePath());
+ OCFile file = getFile();
+ if (file.isDown()) { // checks it is still there
+ File f = new File(file.getStoragePath());
f.delete();
- mFile.setStoragePath(null);
- mStorageManager.saveFile(mFile);
+ file.setStoragePath(null);
+ mStorageManager.saveFile(file);
finish();
}
}
}
- /**
- * {@inheritDoc}
- */
- public OCFile getFile(){
- return mFile;
- }
-
- /*
- /**
- * Use this method to signal this Activity that it shall update its view.
- *
- * @param file : An {@link OCFile}
- *-/
- public void updateFileDetails(OCFile file, Account ocAccount) {
- mFile = file;
- if (ocAccount != null && (
- mStorageManager == null ||
- (mAccount != null && !mAccount.equals(ocAccount))
- )) {
- mStorageManager = new FileDataStorageManager(ocAccount, getActivity().getApplicationContext().getContentResolver());
- }
- mAccount = ocAccount;
- updateFileDetails(false);
- }
- */
-
-
private class BitmapLoader extends AsyncTask<String, Void, Bitmap> {
/**
} catch (Throwable t) {
mErrorMessageId = R.string.common_error_unknown;
- Log_OC.e(TAG, "Unexpected error loading " + mFile.getStoragePath(), t);
+ Log_OC.e(TAG, "Unexpected error loading " + getFile().getStoragePath(), t);
}
return result;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
-import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;
import android.widget.VideoView;
-import com.actionbarsherlock.app.SherlockFragment;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.owncloud.android.operations.RemoteOperation;
import com.owncloud.android.operations.RemoteOperationResult;
import com.owncloud.android.operations.RemoveFileOperation;
-import com.owncloud.android.ui.activity.FileDetailActivity;
import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.fragment.ConfirmationDialogFragment;
-import com.owncloud.android.ui.fragment.FileDetailFragment;
import com.owncloud.android.ui.fragment.FileFragment;
import com.owncloud.android.Log_OC;
*
* @author David A. Velasco
*/
-public class PreviewMediaFragment extends SherlockFragment implements
- OnTouchListener , FileFragment,
+public class PreviewMediaFragment extends FileFragment implements
+ OnTouchListener,
ConfirmationDialogFragment.ConfirmationDialogFragmentListener, OnRemoteOperationListener {
public static final String EXTRA_FILE = "FILE";
private static final String EXTRA_PLAYING = "PLAYING";
private View mView;
- private OCFile mFile;
private Account mAccount;
private FileDataStorageManager mStorageManager;
private ImageView mImagePreview;
* @param ocAccount An ownCloud account; needed to start downloads
*/
public PreviewMediaFragment(OCFile fileToDetail, Account ocAccount, int startPlaybackPosition, boolean autoplay) {
- mFile = fileToDetail;
+ super(fileToDetail);
mAccount = ocAccount;
mSavedPlaybackPosition = startPlaybackPosition;
mStorageManager = null; // we need a context to init this; the container activity is not available yet at this moment
* DO NOT CALL IT: an {@link OCFile} and {@link Account} must be provided for a successful construction
*/
public PreviewMediaFragment() {
- mFile = null;
+ super();
mAccount = null;
mSavedPlaybackPosition = 0;
mStorageManager = null;
mStorageManager = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver());
if (savedInstanceState != null) {
- mFile = savedInstanceState.getParcelable(PreviewMediaFragment.EXTRA_FILE);
+ setFile((OCFile)savedInstanceState.getParcelable(PreviewMediaFragment.EXTRA_FILE));
mAccount = savedInstanceState.getParcelable(PreviewMediaFragment.EXTRA_ACCOUNT);
mSavedPlaybackPosition = savedInstanceState.getInt(PreviewMediaFragment.EXTRA_PLAY_POSITION);
mAutoplay = savedInstanceState.getBoolean(PreviewMediaFragment.EXTRA_PLAYING);
}
- if (mFile == null) {
+ OCFile file = getFile();
+ if (file == null) {
throw new IllegalStateException("Instanced with a NULL OCFile");
}
if (mAccount == null) {
throw new IllegalStateException("Instanced with a NULL ownCloud Account");
}
- if (!mFile.isDown()) {
+ if (!file.isDown()) {
throw new IllegalStateException("There is no local file to preview");
}
- if (mFile.isVideo()) {
+ if (file.isVideo()) {
mVideoPreview.setVisibility(View.VISIBLE);
mImagePreview.setVisibility(View.GONE);
prepareVideo();
super.onSaveInstanceState(outState);
Log_OC.e(TAG, "onSaveInstanceState");
- outState.putParcelable(PreviewMediaFragment.EXTRA_FILE, mFile);
+ outState.putParcelable(PreviewMediaFragment.EXTRA_FILE, getFile());
outState.putParcelable(PreviewMediaFragment.EXTRA_ACCOUNT, mAccount);
- if (mFile.isVideo()) {
+ if (getFile().isVideo()) {
mSavedPlaybackPosition = mVideoPreview.getCurrentPosition();
mAutoplay = mVideoPreview.isPlaying();
outState.putInt(PreviewMediaFragment.EXTRA_PLAY_POSITION , mSavedPlaybackPosition);
super.onStart();
Log_OC.e(TAG, "onStart");
- if (mFile != null) {
- if (mFile.isAudio()) {
+ OCFile file = getFile();
+ if (file != null) {
+ if (file.isAudio()) {
bindMediaService();
- } else if (mFile.isVideo()) {
+ } else if (file.isVideo()) {
stopAudio();
playVideo();
}
private void seeDetails() {
stopPreview(false);
- ((FileFragment.ContainerActivity)getActivity()).showFragmentWithDetails(mFile);
+ ((FileFragment.ContainerActivity)getActivity()).showDetails(getFile());
}
mMediaController.setMediaPlayer(mVideoPreview);
// load the video file in the video player ; when done, VideoHelper#onPrepared() will be called
- mVideoPreview.setVideoPath(mFile.getStoragePath());
+ mVideoPreview.setVideoPath(getFile().getStoragePath());
}
mVideoPreview.stopPlayback();
mAutoplay = false;
mSavedPlaybackPosition = 0;
- mVideoPreview.setVideoPath(mFile.getStoragePath());
+ mVideoPreview.setVideoPath(getFile().getStoragePath());
}
} // else : called from onError()
mMediaController.updatePausePlay();
private void startFullScreenVideo() {
Intent i = new Intent(getActivity(), PreviewVideoActivity.class);
i.putExtra(PreviewVideoActivity.EXTRA_ACCOUNT, mAccount);
- i.putExtra(PreviewVideoActivity.EXTRA_FILE, mFile);
+ i.putExtra(PreviewVideoActivity.EXTRA_FILE, getFile());
i.putExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, mVideoPreview.isPlaying());
mVideoPreview.pause();
i.putExtra(PreviewVideoActivity.EXTRA_START_POSITION, mVideoPreview.getCurrentPosition());
private void playAudio() {
- if (!mMediaServiceBinder.isPlaying(mFile)) {
- Log_OC.d(TAG, "starting playback of " + mFile.getStoragePath());
- mMediaServiceBinder.start(mAccount, mFile, mAutoplay, mSavedPlaybackPosition);
+ OCFile file = getFile();
+ if (!mMediaServiceBinder.isPlaying(file)) {
+ Log_OC.d(TAG, "starting playback of " + file.getStoragePath());
+ mMediaServiceBinder.start(mAccount, file, mAutoplay, mSavedPlaybackPosition);
} else {
if (!mMediaServiceBinder.isPlaying() && mAutoplay) {
* available apps for the MIME type known from the file extension, to let the user choose
*/
private void openFile() {
+ OCFile file = getFile();
stopPreview(true);
- String storagePath = mFile.getStoragePath();
+ String storagePath = file.getStoragePath();
String encodedStoragePath = WebdavUtils.encodePath(storagePath);
try {
Intent i = new Intent(Intent.ACTION_VIEW);
- i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), mFile.getMimetype());
+ i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), file.getMimetype());
i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
startActivity(i);
} catch (Throwable t) {
- Log_OC.e(TAG, "Fail when trying to open with the mimeType provided from the ownCloud server: " + mFile.getMimetype());
+ Log_OC.e(TAG, "Fail when trying to open with the mimeType provided from the ownCloud server: " + file.getMimetype());
boolean toastIt = true;
String mimeType = "";
try {
Intent i = new Intent(Intent.ACTION_VIEW);
mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1));
- if (mimeType == null || !mimeType.equals(mFile.getMimetype())) {
+ if (mimeType == null || !mimeType.equals(file.getMimetype())) {
if (mimeType != null) {
i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), mimeType);
} else {
} finally {
if (toastIt) {
- Toast.makeText(getActivity(), "There is no application to handle file " + mFile.getFileName(), Toast.LENGTH_SHORT).show();
+ Toast.makeText(getActivity(), "There is no application to handle file " + file.getFileName(), Toast.LENGTH_SHORT).show();
}
}
private void removeFile() {
ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance(
R.string.confirmation_remove_alert,
- new String[]{mFile.getFileName()},
+ new String[]{getFile().getFileName()},
R.string.confirmation_remove_remote_and_local,
R.string.confirmation_remove_local,
R.string.common_cancel);
*/
@Override
public void onConfirmation(String callerTag) {
- if (mStorageManager.getFileById(mFile.getFileId()) != null) { // check that the file is still there;
+ OCFile file = getFile();
+ if (mStorageManager.getFileById(file.getFileId()) != null) { // check that the file is still there;
stopPreview(true);
- mLastRemoteOperation = new RemoveFileOperation( mFile, // TODO we need to review the interface with RemoteOperations, and use OCFile IDs instead of OCFile objects as parameters
+ mLastRemoteOperation = new RemoveFileOperation( file, // TODO we need to review the interface with RemoteOperations, and use OCFile IDs instead of OCFile objects as parameters
true,
mStorageManager);
mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
- getActivity().showDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
+ getActivity().showDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
}
}
@Override
public void onNeutral(String callerTag) {
// TODO this code should be made in a secondary thread,
- if (mFile.isDown()) { // checks it is still there
+ OCFile file = getFile();
+ if (file.isDown()) { // checks it is still there
stopPreview(true);
- File f = new File(mFile.getStoragePath());
+ File f = new File(file.getStoragePath());
f.delete();
- mFile.setStoragePath(null);
- mStorageManager.saveFile(mFile);
+ file.setStoragePath(null);
+ mStorageManager.saveFile(file);
finish();
}
}
/**
- * {@inheritDoc}
- */
- public OCFile getFile(){
- return mFile;
- }
-
- /*
- /**
- * Use this method to signal this Activity that it shall update its view.
- *
- * @param file : An {@link OCFile}
- *-/
- public void updateFileDetails(OCFile file, Account ocAccount) {
- mFile = file;
- if (ocAccount != null && (
- mStorageManager == null ||
- (mAccount != null && !mAccount.equals(ocAccount))
- )) {
- mStorageManager = new FileDataStorageManager(ocAccount, getActivity().getApplicationContext().getContentResolver());
- }
- mAccount = ocAccount;
- updateFileDetails(false);
- }
- */
-
-
- /**
* Helper method to test if an {@link OCFile} can be passed to a {@link PreviewMediaFragment} to be previewed.
*
* @param file File to test if can be previewed.
private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) {
boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
- getActivity().dismissDialog((inDisplayActivity)? FileDisplayActivity.DIALOG_SHORT_WAIT : FileDetailActivity.DIALOG_SHORT_WAIT);
+ getActivity().dismissDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
if (result.isSuccess()) {
Toast msg = Toast.makeText(getActivity().getApplicationContext(), R.string.remove_success_msg, Toast.LENGTH_LONG);
}
private void stopPreview(boolean stopAudio) {
- if (mFile.isAudio() && stopAudio) {
+ OCFile file = getFile();
+ if (file.isAudio() && stopAudio) {
mMediaServiceBinder.pause();
- } else if (mFile.isVideo()) {
+ } else if (file.isVideo()) {
mVideoPreview.stopPlayback();
}
}
* Finishes the preview
*/
private void finish() {
- Activity container = getActivity();
- if (container instanceof FileDisplayActivity) {
- // double pane
- FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
- transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null), FileDetailFragment.FTAG); // empty FileDetailFragment
- transaction.commit();
- ((FileFragment.ContainerActivity)container).onFileStateChanged();
- } else {
- container.finish();
- }
+ getActivity().onBackPressed();
}