1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package eu
.alefzero
.owncloud
.ui
.activity
;
22 import java
.util
.ArrayList
;
24 import android
.accounts
.Account
;
25 import android
.accounts
.AccountManager
;
26 import android
.app
.AlertDialog
;
27 import android
.app
.AlertDialog
.Builder
;
28 import android
.app
.Dialog
;
29 import android
.content
.BroadcastReceiver
;
30 import android
.content
.ContentResolver
;
31 import android
.content
.Context
;
32 import android
.content
.DialogInterface
;
33 import android
.content
.DialogInterface
.OnClickListener
;
34 import android
.content
.Intent
;
35 import android
.content
.IntentFilter
;
36 import android
.content
.pm
.PackageInfo
;
37 import android
.content
.pm
.PackageManager
.NameNotFoundException
;
38 import android
.database
.Cursor
;
39 import android
.net
.Uri
;
40 import android
.os
.Bundle
;
41 import android
.provider
.MediaStore
;
42 import android
.support
.v4
.app
.FragmentTransaction
;
43 import android
.util
.Log
;
44 import android
.view
.View
;
45 import android
.view
.ViewGroup
;
46 import android
.widget
.ArrayAdapter
;
47 import android
.widget
.EditText
;
48 import android
.widget
.TextView
;
50 import com
.actionbarsherlock
.app
.ActionBar
;
51 import com
.actionbarsherlock
.app
.ActionBar
.OnNavigationListener
;
52 import com
.actionbarsherlock
.app
.SherlockFragmentActivity
;
53 import com
.actionbarsherlock
.view
.Menu
;
54 import com
.actionbarsherlock
.view
.MenuInflater
;
55 import com
.actionbarsherlock
.view
.MenuItem
;
56 import com
.actionbarsherlock
.view
.Window
;
58 import eu
.alefzero
.owncloud
.AccountUtils
;
59 import eu
.alefzero
.owncloud
.CrashHandler
;
60 import eu
.alefzero
.owncloud
.R
;
61 import eu
.alefzero
.owncloud
.authenticator
.AccountAuthenticator
;
62 import eu
.alefzero
.owncloud
.datamodel
.DataStorageManager
;
63 import eu
.alefzero
.owncloud
.datamodel
.FileDataStorageManager
;
64 import eu
.alefzero
.owncloud
.datamodel
.OCFile
;
65 import eu
.alefzero
.owncloud
.files
.services
.FileDownloader
;
66 import eu
.alefzero
.owncloud
.files
.services
.FileUploader
;
67 import eu
.alefzero
.owncloud
.syncadapter
.FileSyncService
;
68 import eu
.alefzero
.owncloud
.ui
.fragment
.FileDetailFragment
;
69 import eu
.alefzero
.owncloud
.ui
.fragment
.FileListFragment
;
70 import eu
.alefzero
.webdav
.WebdavClient
;
73 * Displays, what files the user has available in his ownCloud.
75 * @author Bartek Przybylski
79 public class FileDisplayActivity
extends SherlockFragmentActivity
implements
80 FileListFragment
.ContainerActivity
, OnNavigationListener
, OnClickListener
, android
.view
.View
.OnClickListener
{
82 private ArrayAdapter
<String
> mDirectories
;
83 private OCFile mCurrentDir
;
84 private String
[] mDirs
= null
;
86 private DataStorageManager mStorageManager
;
87 private SyncBroadcastReceiver mSyncBroadcastReceiver
;
88 private UploadFinishReceiver mUploadFinishReceiver
;
90 private View mLayoutView
= null
;
91 private FileListFragment mFileList
;
93 private boolean mDualPane
;
95 private boolean mForcedLoginToCreateFirstAccount
= false
;
97 private static final String KEY_DIR_ARRAY
= "DIR_ARRAY";
98 private static final String KEY_CURRENT_DIR
= "DIR";
100 private static final int DIALOG_SETUP_ACCOUNT
= 0;
101 private static final int DIALOG_CREATE_DIR
= 1;
102 private static final int DIALOG_ABOUT_APP
= 2;
104 private static final int ACTION_SELECT_FILE
= 1;
107 public void onCreate(Bundle savedInstanceState
) {
108 Log
.i(getClass().toString(), "onCreate() start");
109 super.onCreate(savedInstanceState
);
111 requestWindowFeature(Window
.FEATURE_INDETERMINATE_PROGRESS
);
112 setSupportProgressBarIndeterminateVisibility(false
);
114 Thread
.setDefaultUncaughtExceptionHandler(new CrashHandler(getApplicationContext()));
116 if(savedInstanceState
!= null
) {
117 mDirs
= savedInstanceState
.getStringArray(KEY_DIR_ARRAY
);
118 mDirectories
= new CustomArrayAdapter
<String
>(this, R
.layout
.sherlock_spinner_dropdown_item
);
119 mDirectories
.add("/");
121 for (String s
: mDirs
)
122 mDirectories
.insert(s
, 0);
123 mCurrentDir
= savedInstanceState
.getParcelable(FileDetailFragment
.EXTRA_FILE
);
126 mLayoutView
= getLayoutInflater().inflate(R
.layout
.files
, null
); // always inflate this at onCreate() ; just once!
128 if (AccountUtils
.accountsAreSetup(this)) {
130 initDelayedTilAccountAvailabe();
134 setContentView(R
.layout
.no_account_available
);
135 getSupportActionBar().setNavigationMode(ActionBar
.DISPLAY_SHOW_TITLE
);
136 findViewById(R
.id
.setup_account
).setOnClickListener(this);
138 Intent intent
= new Intent(android
.provider
.Settings
.ACTION_ADD_ACCOUNT
);
139 intent
.putExtra(android
.provider
.Settings
.EXTRA_AUTHORITIES
, new String
[] { AccountAuthenticator
.AUTH_TOKEN_TYPE
});
140 startActivity(intent
); // although the code is here, the activity won't be created until this.onStart() and this.onResume() are finished;
141 mForcedLoginToCreateFirstAccount
= true
;
144 Log
.i(getClass().toString(), "onCreate() end");
148 public boolean onCreateOptionsMenu(Menu menu
) {
149 MenuInflater inflater
= getSherlock().getMenuInflater();
150 inflater
.inflate(R
.menu
.menu
, menu
);
155 public boolean onOptionsItemSelected(MenuItem item
) {
156 boolean retval
= true
;
157 switch (item
.getItemId()) {
158 case R
.id
.createDirectoryItem
: {
159 showDialog(DIALOG_CREATE_DIR
);
162 case R
.id
.startSync
: {
163 Bundle bundle
= new Bundle();
164 bundle
.putBoolean(ContentResolver
.SYNC_EXTRAS_MANUAL
, true
);
165 ContentResolver
.requestSync(
166 AccountUtils
.getCurrentOwnCloudAccount(this),
167 "org.owncloud", bundle
);
170 case R
.id
.action_upload
: {
171 Intent action
= new Intent(Intent
.ACTION_GET_CONTENT
);
172 action
= action
.setType("*/*")
173 .addCategory(Intent
.CATEGORY_OPENABLE
);
174 startActivityForResult(
175 Intent
.createChooser(action
, "Upload file from..."),
179 case R
.id
.action_settings
: {
180 Intent settingsIntent
= new Intent(this, Preferences
.class);
181 startActivity(settingsIntent
);
184 case R
.id
.about_app
: {
185 showDialog(DIALOG_ABOUT_APP
);
188 case android
.R
.id
.home
: {
189 if(mCurrentDir
!= null
&& mCurrentDir
.getParentId() != 0){
201 public boolean onNavigationItemSelected(int itemPosition
, long itemId
) {
202 int i
= itemPosition
;
210 * Called, when the user selected something for uploading
212 public void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
213 if (requestCode
== ACTION_SELECT_FILE
) {
214 if (resultCode
== RESULT_OK
) {
215 Uri selectedImageUri
= data
.getData();
217 String filemanagerstring
= selectedImageUri
.getPath();
218 String selectedImagePath
= getPath(selectedImageUri
);
221 if (selectedImagePath
!= null
)
222 filepath
= selectedImagePath
;
224 filepath
= filemanagerstring
;
226 if (filepath
== null
) {
227 Log
.e("FileDisplay", "Couldnt resolve path to file");
231 Intent i
= new Intent(this, FileUploader
.class);
232 i
.putExtra(FileUploader
.KEY_ACCOUNT
,
233 AccountUtils
.getCurrentOwnCloudAccount(this));
234 String remotepath
= new String();
235 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
236 remotepath
+= "/" + mDirectories
.getItem(j
);
238 if (!remotepath
.endsWith("/"))
240 remotepath
+= new File(filepath
).getName();
241 remotepath
= Uri
.encode(remotepath
, "/");
243 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filepath
);
244 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotepath
);
245 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_SINGLE_FILE
);
249 }/* dvelasco: WIP - not working as expected ... yet :)
250 else if (requestCode == ACTION_CREATE_FIRST_ACCOUNT) {
251 if (resultCode != RESULT_OK) {
252 finish(); // the user cancelled the AuthenticatorActivity
258 public void onBackPressed() {
259 if (mDirectories
== null
|| mDirectories
.getCount() <= 1) {
264 mFileList
.onNavigateUp();
265 mCurrentDir
= mFileList
.getCurrentFile();
267 if(mCurrentDir
.getParentId() == 0){
268 ActionBar actionBar
= getSupportActionBar();
269 actionBar
.setDisplayHomeAsUpEnabled(false
);
274 protected void onSaveInstanceState(Bundle outState
) {
275 // responsability of restore is prefered in onCreate() before than in onRestoreInstanceState when there are Fragments involved
276 Log
.i(getClass().toString(), "onSaveInstanceState() start");
277 super.onSaveInstanceState(outState
);
278 if(mDirectories
!= null
&& mDirectories
.getCount() != 0){
279 mDirs
= new String
[mDirectories
.getCount()-1];
280 for (int j
= mDirectories
.getCount() - 2, i
= 0; j
>= 0; --j
, ++i
) {
281 mDirs
[i
] = mDirectories
.getItem(j
);
284 outState
.putStringArray(KEY_DIR_ARRAY
, mDirs
);
285 outState
.putParcelable(FileDetailFragment
.EXTRA_FILE
, mCurrentDir
);
286 Log
.i(getClass().toString(), "onSaveInstanceState() end");
290 protected void onResume() {
291 Log
.i(getClass().toString(), "onResume() start");
294 if (AccountUtils
.accountsAreSetup(this)) {
295 // at least an account exist: normal operation
297 // set the layout only if it couldn't be set in onCreate
298 if (mForcedLoginToCreateFirstAccount
) {
299 initDelayedTilAccountAvailabe();
300 mForcedLoginToCreateFirstAccount
= false
;
303 // Listen for sync messages
304 IntentFilter syncIntentFilter
= new IntentFilter(FileSyncService
.SYNC_MESSAGE
);
305 mSyncBroadcastReceiver
= new SyncBroadcastReceiver();
306 registerReceiver(mSyncBroadcastReceiver
, syncIntentFilter
);
308 // Listen for upload messages
309 IntentFilter uploadIntentFilter
= new IntentFilter(FileUploader
.UPLOAD_FINISH_MESSAGE
);
310 mUploadFinishReceiver
= new UploadFinishReceiver();
311 registerReceiver(mUploadFinishReceiver
, uploadIntentFilter
);
313 // Storage manager initialization
314 mStorageManager
= new FileDataStorageManager(
315 AccountUtils
.getCurrentOwnCloudAccount(this),
316 getContentResolver());
318 // File list fragments
319 mFileList
= (FileListFragment
) getSupportFragmentManager().findFragmentById(R
.id
.fileList
);
322 // Figure out what directory to list.
323 // Priority: Intent (here), savedInstanceState (onCreate), root dir (dir is null)
324 if(getIntent().hasExtra(FileDetailFragment
.EXTRA_FILE
)){
325 mCurrentDir
= (OCFile
) getIntent().getParcelableExtra(FileDetailFragment
.EXTRA_FILE
);
326 if(mCurrentDir
!= null
&& !mCurrentDir
.isDirectory()){
327 mCurrentDir
= mStorageManager
.getFileById(mCurrentDir
.getParentId());
330 // Clear intent extra, so rotating the screen will not return us to this directory
331 getIntent().removeExtra(FileDetailFragment
.EXTRA_FILE
);
334 if (mCurrentDir
== null
)
335 mCurrentDir
= mStorageManager
.getFileByPath("/");
337 // Drop-Down navigation and file list restore
338 mDirectories
= new CustomArrayAdapter
<String
>(this, R
.layout
.sherlock_spinner_dropdown_item
);
341 // Given the case we have a file to display:
342 if(mCurrentDir
!= null
){
343 ArrayList
<OCFile
> files
= new ArrayList
<OCFile
>();
344 OCFile currFile
= mCurrentDir
;
345 while(currFile
!= null
){
347 currFile
= mStorageManager
.getFileById(currFile
.getParentId());
351 mDirs
= new String
[files
.size()];
352 for(int i
= files
.size() - 1; i
>= 0; i
--){
353 mDirs
[i
] = files
.get(i
).getFileName();
358 for (String s
: mDirs
)
361 mDirectories
.add("/");
365 ActionBar action_bar
= getSupportActionBar();
366 action_bar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_LIST
);
367 action_bar
.setDisplayShowTitleEnabled(false
);
368 action_bar
.setListNavigationCallbacks(mDirectories
, this);
369 if(mCurrentDir
!= null
&& mCurrentDir
.getParentId() != 0){
370 action_bar
.setDisplayHomeAsUpEnabled(true
);
372 action_bar
.setDisplayHomeAsUpEnabled(false
);
376 mFileList
.listDirectory(mCurrentDir
);
378 Log
.i(getClass().toString(), "onResume() end");
382 protected void onPause() {
383 Log
.i(getClass().toString(), "onPause() start");
385 if (mSyncBroadcastReceiver
!= null
) {
386 unregisterReceiver(mSyncBroadcastReceiver
);
387 mSyncBroadcastReceiver
= null
;
389 if (mUploadFinishReceiver
!= null
) {
390 unregisterReceiver(mUploadFinishReceiver
);
391 mUploadFinishReceiver
= null
;
393 getIntent().putExtra(FileDetailFragment
.EXTRA_FILE
, mCurrentDir
);
394 Log
.i(getClass().toString(), "onPause() end");
398 protected Dialog
onCreateDialog(int id
) {
399 Dialog dialog
= null
;
400 AlertDialog
.Builder builder
;
402 case DIALOG_SETUP_ACCOUNT
:
403 builder
= new AlertDialog
.Builder(this);
404 builder
.setTitle(R
.string
.main_tit_accsetup
);
405 builder
.setMessage(R
.string
.main_wrn_accsetup
);
406 builder
.setCancelable(false
);
407 builder
.setPositiveButton(android
.R
.string
.ok
, this);
408 builder
.setNegativeButton(android
.R
.string
.cancel
, this);
409 dialog
= builder
.create();
411 case DIALOG_ABOUT_APP
: {
412 builder
= new AlertDialog
.Builder(this);
413 builder
.setTitle("About");
416 pkg
= getPackageManager().getPackageInfo(getPackageName(), 0);
417 builder
.setMessage("ownCloud android client\n\nversion: " + pkg
.versionName
);
418 builder
.setIcon(android
.R
.drawable
.ic_menu_info_details
);
419 dialog
= builder
.create();
420 } catch (NameNotFoundException e
) {
427 case DIALOG_CREATE_DIR
: {
428 builder
= new Builder(this);
429 final EditText dirNameInput
= new EditText(getBaseContext());
430 final Account a
= AccountUtils
.getCurrentOwnCloudAccount(this);
431 builder
.setView(dirNameInput
);
432 builder
.setTitle(R
.string
.uploader_info_dirname
);
433 int typed_color
= getResources().getColor(R
.color
.setup_text_typed
);
434 dirNameInput
.setTextColor(typed_color
);
435 builder
.setPositiveButton(android
.R
.string
.ok
,
436 new OnClickListener() {
437 public void onClick(DialogInterface dialog
, int which
) {
438 String directoryName
= dirNameInput
.getText().toString();
439 if (directoryName
.trim().length() == 0) {
444 // Figure out the path where the dir needs to be created
446 if (mCurrentDir
== null
) {
447 // this is just a patch; we should ensure that mCurrentDir never is null
448 if (!mStorageManager
.fileExists("/")) {
449 OCFile file
= new OCFile("/");
450 mStorageManager
.saveFile(file
);
452 mCurrentDir
= mStorageManager
.getFileByPath("/");
454 path
= FileDisplayActivity
.this.mCurrentDir
.getRemotePath();
457 path
+= Uri
.encode(directoryName
) + "/";
458 Thread thread
= new Thread(new DirectoryCreator(path
, a
));
461 // Save new directory in local database
462 OCFile newDir
= new OCFile(path
);
463 newDir
.setMimetype("DIR");
464 newDir
.setParentId(mCurrentDir
.getFileId());
465 mStorageManager
.saveFile(newDir
);
467 // Display the new folder right away
469 mFileList
.listDirectory(mCurrentDir
);
472 builder
.setNegativeButton(R
.string
.common_cancel
,
473 new OnClickListener() {
474 public void onClick(DialogInterface dialog
, int which
) {
478 dialog
= builder
.create();
490 * Responds to the "There are no ownCloud Accounts setup" dialog
491 * TODO: Dialog is 100% useless -> Remove
494 public void onClick(DialogInterface dialog
, int which
) {
495 // In any case - we won't need it anymore
498 case DialogInterface
.BUTTON_POSITIVE
:
499 Intent intent
= new Intent("android.settings.ADD_ACCOUNT_SETTINGS");
500 intent
.putExtra("authorities",
501 new String
[] { AccountAuthenticator
.AUTH_TOKEN_TYPE
});
502 startActivity(intent
);
504 case DialogInterface
.BUTTON_NEGATIVE
:
511 * Translates a content URI of an image to a physical path
513 * @param uri The URI to resolve
514 * @return The path to the image or null if it could not be found
516 public String
getPath(Uri uri
) {
517 String
[] projection
= { MediaStore
.Images
.Media
.DATA
};
518 Cursor cursor
= managedQuery(uri
, projection
, null
, null
, null
);
519 if (cursor
!= null
) {
520 int column_index
= cursor
521 .getColumnIndexOrThrow(MediaStore
.Images
.Media
.DATA
);
522 cursor
.moveToFirst();
523 return cursor
.getString(column_index
);
529 * Pushes a directory to the drop down list
530 * @param directory to push
531 * @throws IllegalArgumentException If the {@link OCFile#isDirectory()} returns false.
533 public void pushDirname(OCFile directory
) {
534 if(!directory
.isDirectory()){
535 throw new IllegalArgumentException("Only directories may be pushed!");
537 mDirectories
.insert(directory
.getFileName(), 0);
538 mCurrentDir
= directory
;
542 * Pops a directory name from the drop down list
543 * @return True, unless the stack is empty
545 public boolean popDirname() {
546 mDirectories
.remove(mDirectories
.getItem(0));
547 return !mDirectories
.isEmpty();
550 private class DirectoryCreator
implements Runnable
{
551 private String mTargetPath
;
552 private Account mAccount
;
553 private AccountManager mAm
;
555 public DirectoryCreator(String targetPath
, Account account
) {
556 mTargetPath
= targetPath
;
558 mAm
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
563 WebdavClient wdc
= new WebdavClient(mAccount
, getApplicationContext());
565 String username
= mAccount
.name
.substring(0,
566 mAccount
.name
.lastIndexOf('@'));
567 String password
= mAm
.getPassword(mAccount
);
569 wdc
.setCredentials(username
, password
);
570 wdc
.allowSelfsignedCertificates();
571 wdc
.createDirectory(mTargetPath
);
576 // Custom array adapter to override text colors
577 private class CustomArrayAdapter
<T
> extends ArrayAdapter
<T
> {
579 public CustomArrayAdapter(FileDisplayActivity ctx
, int view
) {
583 public View
getView(int position
, View convertView
, ViewGroup parent
) {
584 View v
= super.getView(position
, convertView
, parent
);
586 ((TextView
) v
).setTextColor(getResources().getColorStateList(
587 android
.R
.color
.white
));
591 public View
getDropDownView(int position
, View convertView
,
593 View v
= super.getDropDownView(position
, convertView
, parent
);
595 ((TextView
) v
).setTextColor(getResources().getColorStateList(
596 android
.R
.color
.white
));
603 private class SyncBroadcastReceiver
extends BroadcastReceiver
{
605 * {@link BroadcastReceiver} to enable syncing feedback in UI
608 public void onReceive(Context context
, Intent intent
) {
609 boolean inProgress
= intent
.getBooleanExtra(
610 FileSyncService
.IN_PROGRESS
, false
);
611 String account_name
= intent
612 .getStringExtra(FileSyncService
.ACCOUNT_NAME
);
614 Log
.d("FileDisplay", "sync of account " + account_name
615 + " is in_progress: " + inProgress
);
617 //if (account_name.equals(AccountUtils.getCurrentOwnCloudAccount(context).name)) { // TODO - probably this check should be added, but won't push it until really tests are done; no time now
619 /// try to refresh the view with every message received from the FileSyncAdapter; brute, but more user friendly when there are a lot of files in the server
621 if (mCurrentDir
== null
)
622 currentDir
= mStorageManager
.getFileByPath("/");
624 currentDir
= mStorageManager
.getFileByPath(mCurrentDir
.getRemotePath());
626 if (currentDir
!= null
) {
627 mCurrentDir
= currentDir
;
628 FileListFragment fileListFragment
= (FileListFragment
) getSupportFragmentManager()
629 .findFragmentById(R
.id
.fileList
);
630 if (fileListFragment
!= null
) {
631 if (!mCurrentDir
.equals(fileListFragment
.getCurrentFile())) {
632 fileListFragment
.listDirectory(mCurrentDir
); // only set the directory in the fragment first time
634 fileListFragment
.listDirectory(); // enough to show new files in the current directory if they are added after
638 setSupportProgressBarIndeterminateVisibility(inProgress
);
644 private class UploadFinishReceiver
extends BroadcastReceiver
{
646 * Once the file upload has finished -> update view
647 * @author David A. Velasco
648 * {@link BroadcastReceiver} to enable upload feedback in UI
651 public void onReceive(Context context
, Intent intent
) {
652 long parentDirId
= intent
.getLongExtra(FileUploader
.EXTRA_PARENT_DIR_ID
, -1);
653 OCFile parentDir
= mStorageManager
.getFileById(parentDirId
);
655 if (parentDir
!= null
&& (
656 (mCurrentDir
== null
&& parentDir
.getFileName().equals("/")) ||
657 parentDir
.equals(mCurrentDir
))
659 FileListFragment fileListFragment
= (FileListFragment
) getSupportFragmentManager().findFragmentById(R
.id
.fileList
);
660 if (fileListFragment
!= null
) {
661 fileListFragment
.listDirectory();
670 public void onClick(View v
) {
671 if (v
.getId() == R
.id
.setup_account
) {
672 Intent intent
= new Intent(android
.provider
.Settings
.ACTION_ADD_ACCOUNT
);
673 intent
.putExtra(android
.provider
.Settings
.EXTRA_AUTHORITIES
, new String
[] { AccountAuthenticator
.AUTH_TOKEN_TYPE
});
674 startActivity(intent
);
675 mForcedLoginToCreateFirstAccount
= true
;
687 public DataStorageManager
getStorageManager() {
688 return mStorageManager
;
696 public void onDirectoryClick(OCFile directory
) {
697 pushDirname(directory
);
698 ActionBar actionBar
= getSupportActionBar();
699 actionBar
.setDisplayHomeAsUpEnabled(true
);
702 // Resets the FileDetailsFragment on Tablets so that it always displays
703 FileDetailFragment fileDetails
= (FileDetailFragment
) getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
704 if (fileDetails
!= null
) {
705 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
706 transaction
.remove(fileDetails
);
707 transaction
.add(R
.id
.file_details_container
, new FileDetailFragment(null
, null
));
708 transaction
.commit();
718 public void onFileClick(OCFile file
) {
720 // If we are on a large device -> update fragment
722 // buttons in the details view are problematic when trying to reuse an existing fragment; create always a new one solves some of them, BUT no all; downloads are 'dangerous'
723 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
724 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(file
, AccountUtils
.getCurrentOwnCloudAccount(this)), FileDetailFragment
.FTAG
);
725 transaction
.setTransition(FragmentTransaction
.TRANSIT_FRAGMENT_FADE
);
726 transaction
.commit();
728 } else { // small or medium screen device -> new Activity
729 Intent showDetailsIntent
= new Intent(this, FileDetailActivity
.class);
730 showDetailsIntent
.putExtra(FileDetailFragment
.EXTRA_FILE
, file
);
731 showDetailsIntent
.putExtra(FileDownloader
.EXTRA_ACCOUNT
, AccountUtils
.getCurrentOwnCloudAccount(this));
732 startActivity(showDetailsIntent
);
737 * Operations in this method should be preferably performed in onCreate to have a lighter onResume method.
739 * But we need to delay them to onResume for the first start of the application, when no account exists and the login activity must be shown; and
740 * put instead the ugly view that shows the 'Setup' button to restart the login activity.
742 * In other way, if the users cancels or presses BACK in the login page that first time (users can be cruel sometimes) would show a blank view (the
743 * FragmentList view empty).
745 * This is temporal, until we found out how to get a result in this activity after launching the ADD_ACCOUNT Intent with startActivityForResult (not trivial)
747 private void initDelayedTilAccountAvailabe() {
748 setContentView(mLayoutView
);
749 mDualPane
= (findViewById(R
.id
.file_details_container
) != null
);
750 if (mDualPane
&& getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
) == null
) {
751 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
752 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(null
, null
)); // empty FileDetailFragment
753 transaction
.commit();