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
.SharedPreferences
;
37 import android
.content
.pm
.PackageInfo
;
38 import android
.content
.pm
.PackageManager
.NameNotFoundException
;
39 import android
.database
.Cursor
;
40 import android
.net
.Uri
;
41 import android
.os
.Bundle
;
42 import android
.preference
.PreferenceManager
;
43 import android
.provider
.MediaStore
;
44 import android
.support
.v4
.app
.FragmentTransaction
;
45 import android
.util
.Log
;
46 import android
.view
.View
;
47 import android
.view
.ViewGroup
;
48 import android
.widget
.ArrayAdapter
;
49 import android
.widget
.EditText
;
50 import android
.widget
.TextView
;
52 import com
.actionbarsherlock
.app
.ActionBar
;
53 import com
.actionbarsherlock
.app
.ActionBar
.OnNavigationListener
;
54 import com
.actionbarsherlock
.app
.SherlockFragmentActivity
;
55 import com
.actionbarsherlock
.view
.Menu
;
56 import com
.actionbarsherlock
.view
.MenuInflater
;
57 import com
.actionbarsherlock
.view
.MenuItem
;
58 import com
.actionbarsherlock
.view
.Window
;
60 import eu
.alefzero
.owncloud
.AccountUtils
;
61 import eu
.alefzero
.owncloud
.CrashHandler
;
62 import eu
.alefzero
.owncloud
.R
;
63 import eu
.alefzero
.owncloud
.authenticator
.AccountAuthenticator
;
64 import eu
.alefzero
.owncloud
.datamodel
.DataStorageManager
;
65 import eu
.alefzero
.owncloud
.datamodel
.FileDataStorageManager
;
66 import eu
.alefzero
.owncloud
.datamodel
.OCFile
;
67 import eu
.alefzero
.owncloud
.files
.services
.FileDownloader
;
68 import eu
.alefzero
.owncloud
.files
.services
.FileUploader
;
69 import eu
.alefzero
.owncloud
.syncadapter
.FileSyncService
;
70 import eu
.alefzero
.owncloud
.ui
.fragment
.FileDetailFragment
;
71 import eu
.alefzero
.owncloud
.ui
.fragment
.FileListFragment
;
72 import eu
.alefzero
.webdav
.WebdavClient
;
75 * Displays, what files the user has available in his ownCloud.
77 * @author Bartek Przybylski
81 public class FileDisplayActivity
extends SherlockFragmentActivity
implements
82 FileListFragment
.ContainerActivity
, OnNavigationListener
, OnClickListener
, android
.view
.View
.OnClickListener
{
84 private ArrayAdapter
<String
> mDirectories
;
85 private OCFile mCurrentDir
;
86 private String
[] mDirs
= null
;
88 private DataStorageManager mStorageManager
;
89 private SyncBroadcastReceiver mSyncBroadcastReceiver
;
90 private UploadFinishReceiver mUploadFinishReceiver
;
92 private View mLayoutView
= null
;
93 private FileListFragment mFileList
;
95 private boolean mDualPane
;
97 private boolean mForcedLoginToCreateFirstAccount
= false
;
99 private static final String KEY_DIR_ARRAY
= "DIR_ARRAY";
100 private static final String KEY_CURRENT_DIR
= "DIR";
102 private static final int DIALOG_SETUP_ACCOUNT
= 0;
103 private static final int DIALOG_CREATE_DIR
= 1;
104 private static final int DIALOG_ABOUT_APP
= 2;
106 private static final int ACTION_SELECT_FILE
= 1;
109 public void onCreate(Bundle savedInstanceState
) {
110 Log
.i(getClass().toString(), "onCreate() start");
111 super.onCreate(savedInstanceState
);
113 requestWindowFeature(Window
.FEATURE_INDETERMINATE_PROGRESS
);
115 Thread
.setDefaultUncaughtExceptionHandler(new CrashHandler(getApplicationContext()));
117 if(savedInstanceState
!= null
) {
118 mDirs
= savedInstanceState
.getStringArray(KEY_DIR_ARRAY
);
119 mDirectories
= new CustomArrayAdapter
<String
>(this, R
.layout
.sherlock_spinner_dropdown_item
);
120 mDirectories
.add("/");
122 for (String s
: mDirs
)
123 mDirectories
.insert(s
, 0);
124 mCurrentDir
= savedInstanceState
.getParcelable(FileDetailFragment
.EXTRA_FILE
);
127 mLayoutView
= getLayoutInflater().inflate(R
.layout
.files
, null
); // always inflate this at onCreate() ; just once!
129 if (AccountUtils
.accountsAreSetup(this)) {
131 initDelayedTilAccountAvailabe();
133 // PIN CODE request ; best location is to decide, let's try this first
134 //if (savedInstanceState == null) {
135 if (getIntent().getAction() != null
&& getIntent().getAction().equals(Intent
.ACTION_MAIN
) && savedInstanceState
== null
) {
142 setContentView(R
.layout
.no_account_available
);
143 getSupportActionBar().setNavigationMode(ActionBar
.DISPLAY_SHOW_TITLE
);
144 findViewById(R
.id
.setup_account
).setOnClickListener(this);
146 setSupportProgressBarIndeterminateVisibility(false
);
148 Intent intent
= new Intent(android
.provider
.Settings
.ACTION_ADD_ACCOUNT
);
149 intent
.putExtra(android
.provider
.Settings
.EXTRA_AUTHORITIES
, new String
[] { AccountAuthenticator
.AUTH_TOKEN_TYPE
});
150 startActivity(intent
); // although the code is here, the activity won't be created until this.onStart() and this.onResume() are finished;
151 mForcedLoginToCreateFirstAccount
= true
;
154 Log
.i(getClass().toString(), "onCreate() end");
158 public boolean onCreateOptionsMenu(Menu menu
) {
159 MenuInflater inflater
= getSherlock().getMenuInflater();
160 inflater
.inflate(R
.menu
.menu
, menu
);
165 public boolean onOptionsItemSelected(MenuItem item
) {
166 boolean retval
= true
;
167 switch (item
.getItemId()) {
168 case R
.id
.createDirectoryItem
: {
169 showDialog(DIALOG_CREATE_DIR
);
172 case R
.id
.startSync
: {
173 ContentResolver
.cancelSync(null
, "org.owncloud"); // cancel the current synchronizations of any ownCloud account
174 Bundle bundle
= new Bundle();
175 bundle
.putBoolean(ContentResolver
.SYNC_EXTRAS_MANUAL
, true
);
176 ContentResolver
.requestSync(
177 AccountUtils
.getCurrentOwnCloudAccount(this),
178 "org.owncloud", bundle
);
181 case R
.id
.action_upload
: {
182 Intent action
= new Intent(Intent
.ACTION_GET_CONTENT
);
183 action
= action
.setType("*/*")
184 .addCategory(Intent
.CATEGORY_OPENABLE
);
185 startActivityForResult(
186 Intent
.createChooser(action
, "Upload file from..."),
190 case R
.id
.action_settings
: {
191 Intent settingsIntent
= new Intent(this, Preferences
.class);
192 startActivity(settingsIntent
);
195 case R
.id
.about_app
: {
196 showDialog(DIALOG_ABOUT_APP
);
199 case android
.R
.id
.home
: {
200 if(mCurrentDir
!= null
&& mCurrentDir
.getParentId() != 0){
212 public boolean onNavigationItemSelected(int itemPosition
, long itemId
) {
213 int i
= itemPosition
;
221 * Called, when the user selected something for uploading
223 public void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
224 if (requestCode
== ACTION_SELECT_FILE
) {
225 if (resultCode
== RESULT_OK
) {
226 Uri selectedImageUri
= data
.getData();
228 String filemanagerstring
= selectedImageUri
.getPath();
229 String selectedImagePath
= getPath(selectedImageUri
);
232 if (selectedImagePath
!= null
)
233 filepath
= selectedImagePath
;
235 filepath
= filemanagerstring
;
237 if (filepath
== null
) {
238 Log
.e("FileDisplay", "Couldnt resolve path to file");
242 Intent i
= new Intent(this, FileUploader
.class);
243 i
.putExtra(FileUploader
.KEY_ACCOUNT
,
244 AccountUtils
.getCurrentOwnCloudAccount(this));
245 String remotepath
= new String();
246 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
247 remotepath
+= "/" + mDirectories
.getItem(j
);
249 if (!remotepath
.endsWith("/"))
251 remotepath
+= new File(filepath
).getName();
252 remotepath
= Uri
.encode(remotepath
, "/");
254 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filepath
);
255 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotepath
);
256 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_SINGLE_FILE
);
260 }/* dvelasco: WIP - not working as expected ... yet :)
261 else if (requestCode == ACTION_CREATE_FIRST_ACCOUNT) {
262 if (resultCode != RESULT_OK) {
263 finish(); // the user cancelled the AuthenticatorActivity
269 public void onBackPressed() {
270 if (mDirectories
== null
|| mDirectories
.getCount() <= 1) {
275 mFileList
.onNavigateUp();
276 mCurrentDir
= mFileList
.getCurrentFile();
278 if(mCurrentDir
.getParentId() == 0){
279 ActionBar actionBar
= getSupportActionBar();
280 actionBar
.setDisplayHomeAsUpEnabled(false
);
285 protected void onSaveInstanceState(Bundle outState
) {
286 // responsability of restore is prefered in onCreate() before than in onRestoreInstanceState when there are Fragments involved
287 Log
.i(getClass().toString(), "onSaveInstanceState() start");
288 super.onSaveInstanceState(outState
);
289 if(mDirectories
!= null
&& mDirectories
.getCount() != 0){
290 mDirs
= new String
[mDirectories
.getCount()-1];
291 for (int j
= mDirectories
.getCount() - 2, i
= 0; j
>= 0; --j
, ++i
) {
292 mDirs
[i
] = mDirectories
.getItem(j
);
295 outState
.putStringArray(KEY_DIR_ARRAY
, mDirs
);
296 outState
.putParcelable(FileDetailFragment
.EXTRA_FILE
, mCurrentDir
);
297 Log
.i(getClass().toString(), "onSaveInstanceState() end");
301 protected void onResume() {
302 Log
.i(getClass().toString(), "onResume() start");
305 if (AccountUtils
.accountsAreSetup(this)) {
306 // at least an account exist: normal operation
308 // set the layout only if it couldn't be set in onCreate
309 if (mForcedLoginToCreateFirstAccount
) {
310 initDelayedTilAccountAvailabe();
311 mForcedLoginToCreateFirstAccount
= false
;
314 // Listen for sync messages
315 IntentFilter syncIntentFilter
= new IntentFilter(FileSyncService
.SYNC_MESSAGE
);
316 mSyncBroadcastReceiver
= new SyncBroadcastReceiver();
317 registerReceiver(mSyncBroadcastReceiver
, syncIntentFilter
);
319 // Listen for upload messages
320 IntentFilter uploadIntentFilter
= new IntentFilter(FileUploader
.UPLOAD_FINISH_MESSAGE
);
321 mUploadFinishReceiver
= new UploadFinishReceiver();
322 registerReceiver(mUploadFinishReceiver
, uploadIntentFilter
);
324 // Storage manager initialization
325 mStorageManager
= new FileDataStorageManager(
326 AccountUtils
.getCurrentOwnCloudAccount(this),
327 getContentResolver());
329 // File list fragments
330 mFileList
= (FileListFragment
) getSupportFragmentManager().findFragmentById(R
.id
.fileList
);
333 // Figure out what directory to list.
334 // Priority: Intent (here), savedInstanceState (onCreate), root dir (dir is null)
335 if(getIntent().hasExtra(FileDetailFragment
.EXTRA_FILE
)){
336 mCurrentDir
= (OCFile
) getIntent().getParcelableExtra(FileDetailFragment
.EXTRA_FILE
);
337 if(mCurrentDir
!= null
&& !mCurrentDir
.isDirectory()){
338 mCurrentDir
= mStorageManager
.getFileById(mCurrentDir
.getParentId());
341 // Clear intent extra, so rotating the screen will not return us to this directory
342 getIntent().removeExtra(FileDetailFragment
.EXTRA_FILE
);
345 if (mCurrentDir
== null
)
346 mCurrentDir
= mStorageManager
.getFileByPath("/");
348 // Drop-Down navigation and file list restore
349 mDirectories
= new CustomArrayAdapter
<String
>(this, R
.layout
.sherlock_spinner_dropdown_item
);
352 // Given the case we have a file to display:
353 if(mCurrentDir
!= null
){
354 ArrayList
<OCFile
> files
= new ArrayList
<OCFile
>();
355 OCFile currFile
= mCurrentDir
;
356 while(currFile
!= null
){
358 currFile
= mStorageManager
.getFileById(currFile
.getParentId());
362 mDirs
= new String
[files
.size()];
363 for(int i
= files
.size() - 1; i
>= 0; i
--){
364 mDirs
[i
] = files
.get(i
).getFileName();
369 for (String s
: mDirs
)
372 mDirectories
.add("/");
376 ActionBar action_bar
= getSupportActionBar();
377 action_bar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_LIST
);
378 action_bar
.setDisplayShowTitleEnabled(false
);
379 action_bar
.setListNavigationCallbacks(mDirectories
, this);
380 if(mCurrentDir
!= null
&& mCurrentDir
.getParentId() != 0){
381 action_bar
.setDisplayHomeAsUpEnabled(true
);
383 action_bar
.setDisplayHomeAsUpEnabled(false
);
387 mFileList
.listDirectory(mCurrentDir
);
389 Log
.i(getClass().toString(), "onResume() end");
393 protected void onPause() {
394 Log
.i(getClass().toString(), "onPause() start");
396 if (mSyncBroadcastReceiver
!= null
) {
397 unregisterReceiver(mSyncBroadcastReceiver
);
398 mSyncBroadcastReceiver
= null
;
400 if (mUploadFinishReceiver
!= null
) {
401 unregisterReceiver(mUploadFinishReceiver
);
402 mUploadFinishReceiver
= null
;
404 getIntent().putExtra(FileDetailFragment
.EXTRA_FILE
, mCurrentDir
);
405 Log
.i(getClass().toString(), "onPause() end");
409 protected Dialog
onCreateDialog(int id
) {
410 Dialog dialog
= null
;
411 AlertDialog
.Builder builder
;
413 case DIALOG_SETUP_ACCOUNT
:
414 builder
= new AlertDialog
.Builder(this);
415 builder
.setTitle(R
.string
.main_tit_accsetup
);
416 builder
.setMessage(R
.string
.main_wrn_accsetup
);
417 builder
.setCancelable(false
);
418 builder
.setPositiveButton(android
.R
.string
.ok
, this);
419 builder
.setNegativeButton(android
.R
.string
.cancel
, this);
420 dialog
= builder
.create();
422 case DIALOG_ABOUT_APP
: {
423 builder
= new AlertDialog
.Builder(this);
424 builder
.setTitle("About");
427 pkg
= getPackageManager().getPackageInfo(getPackageName(), 0);
428 builder
.setMessage("ownCloud android client\n\nversion: " + pkg
.versionName
);
429 builder
.setIcon(android
.R
.drawable
.ic_menu_info_details
);
430 dialog
= builder
.create();
431 } catch (NameNotFoundException e
) {
438 case DIALOG_CREATE_DIR
: {
439 builder
= new Builder(this);
440 final EditText dirNameInput
= new EditText(getBaseContext());
441 final Account a
= AccountUtils
.getCurrentOwnCloudAccount(this);
442 builder
.setView(dirNameInput
);
443 builder
.setTitle(R
.string
.uploader_info_dirname
);
444 int typed_color
= getResources().getColor(R
.color
.setup_text_typed
);
445 dirNameInput
.setTextColor(typed_color
);
446 builder
.setPositiveButton(android
.R
.string
.ok
,
447 new OnClickListener() {
448 public void onClick(DialogInterface dialog
, int which
) {
449 String directoryName
= dirNameInput
.getText().toString();
450 if (directoryName
.trim().length() == 0) {
455 // Figure out the path where the dir needs to be created
457 if (mCurrentDir
== null
) {
458 // this is just a patch; we should ensure that mCurrentDir never is null
459 if (!mStorageManager
.fileExists("/")) {
460 OCFile file
= new OCFile("/");
461 mStorageManager
.saveFile(file
);
463 mCurrentDir
= mStorageManager
.getFileByPath("/");
465 path
= FileDisplayActivity
.this.mCurrentDir
.getRemotePath();
468 path
+= Uri
.encode(directoryName
) + "/";
469 Thread thread
= new Thread(new DirectoryCreator(path
, a
));
472 // Save new directory in local database
473 OCFile newDir
= new OCFile(path
);
474 newDir
.setMimetype("DIR");
475 newDir
.setParentId(mCurrentDir
.getFileId());
476 mStorageManager
.saveFile(newDir
);
478 // Display the new folder right away
480 mFileList
.listDirectory(mCurrentDir
);
483 builder
.setNegativeButton(R
.string
.common_cancel
,
484 new OnClickListener() {
485 public void onClick(DialogInterface dialog
, int which
) {
489 dialog
= builder
.create();
501 * Responds to the "There are no ownCloud Accounts setup" dialog
502 * TODO: Dialog is 100% useless -> Remove
505 public void onClick(DialogInterface dialog
, int which
) {
506 // In any case - we won't need it anymore
509 case DialogInterface
.BUTTON_POSITIVE
:
510 Intent intent
= new Intent("android.settings.ADD_ACCOUNT_SETTINGS");
511 intent
.putExtra("authorities",
512 new String
[] { AccountAuthenticator
.AUTH_TOKEN_TYPE
});
513 startActivity(intent
);
515 case DialogInterface
.BUTTON_NEGATIVE
:
522 * Translates a content URI of an image to a physical path
524 * @param uri The URI to resolve
525 * @return The path to the image or null if it could not be found
527 public String
getPath(Uri uri
) {
528 String
[] projection
= { MediaStore
.Images
.Media
.DATA
};
529 Cursor cursor
= managedQuery(uri
, projection
, null
, null
, null
);
530 if (cursor
!= null
) {
531 int column_index
= cursor
532 .getColumnIndexOrThrow(MediaStore
.Images
.Media
.DATA
);
533 cursor
.moveToFirst();
534 return cursor
.getString(column_index
);
540 * Pushes a directory to the drop down list
541 * @param directory to push
542 * @throws IllegalArgumentException If the {@link OCFile#isDirectory()} returns false.
544 public void pushDirname(OCFile directory
) {
545 if(!directory
.isDirectory()){
546 throw new IllegalArgumentException("Only directories may be pushed!");
548 mDirectories
.insert(directory
.getFileName(), 0);
549 mCurrentDir
= directory
;
553 * Pops a directory name from the drop down list
554 * @return True, unless the stack is empty
556 public boolean popDirname() {
557 mDirectories
.remove(mDirectories
.getItem(0));
558 return !mDirectories
.isEmpty();
561 private class DirectoryCreator
implements Runnable
{
562 private String mTargetPath
;
563 private Account mAccount
;
564 private AccountManager mAm
;
566 public DirectoryCreator(String targetPath
, Account account
) {
567 mTargetPath
= targetPath
;
569 mAm
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
574 WebdavClient wdc
= new WebdavClient(mAccount
, getApplicationContext());
576 String username
= mAccount
.name
.substring(0,
577 mAccount
.name
.lastIndexOf('@'));
578 String password
= mAm
.getPassword(mAccount
);
580 wdc
.setCredentials(username
, password
);
581 wdc
.allowSelfsignedCertificates();
582 wdc
.createDirectory(mTargetPath
);
587 // Custom array adapter to override text colors
588 private class CustomArrayAdapter
<T
> extends ArrayAdapter
<T
> {
590 public CustomArrayAdapter(FileDisplayActivity ctx
, int view
) {
594 public View
getView(int position
, View convertView
, ViewGroup parent
) {
595 View v
= super.getView(position
, convertView
, parent
);
597 ((TextView
) v
).setTextColor(getResources().getColorStateList(
598 android
.R
.color
.white
));
602 public View
getDropDownView(int position
, View convertView
,
604 View v
= super.getDropDownView(position
, convertView
, parent
);
606 ((TextView
) v
).setTextColor(getResources().getColorStateList(
607 android
.R
.color
.white
));
614 private class SyncBroadcastReceiver
extends BroadcastReceiver
{
616 * {@link BroadcastReceiver} to enable syncing feedback in UI
619 public void onReceive(Context context
, Intent intent
) {
620 boolean inProgress
= intent
.getBooleanExtra(
621 FileSyncService
.IN_PROGRESS
, false
);
622 String account_name
= intent
623 .getStringExtra(FileSyncService
.ACCOUNT_NAME
);
625 Log
.d("FileDisplay", "sync of account " + account_name
626 + " is in_progress: " + inProgress
);
628 if (account_name
.equals(AccountUtils
.getCurrentOwnCloudAccount(context
).name
)) {
630 String synchFolderRemotePath
= intent
.getStringExtra(FileSyncService
.SYNC_FOLDER_REMOTE_PATH
);
632 boolean fillBlankRoot
= false
;
633 if (mCurrentDir
== null
) {
634 mCurrentDir
= mStorageManager
.getFileByPath("/");
635 fillBlankRoot
= (mCurrentDir
!= null
);
638 if (synchFolderRemotePath
!= null
&& mCurrentDir
!= null
&& (mCurrentDir
.getRemotePath().equals(synchFolderRemotePath
) || fillBlankRoot
) ) {
639 FileListFragment fileListFragment
= (FileListFragment
) getSupportFragmentManager()
640 .findFragmentById(R
.id
.fileList
);
641 mCurrentDir
= getStorageManager().getFileByPath(synchFolderRemotePath
);
642 if (fileListFragment
!= null
) {
643 fileListFragment
.listDirectory(mCurrentDir
);
647 setSupportProgressBarIndeterminateVisibility(inProgress
);
654 private class UploadFinishReceiver
extends BroadcastReceiver
{
656 * Once the file upload has finished -> update view
657 * @author David A. Velasco
658 * {@link BroadcastReceiver} to enable upload feedback in UI
661 public void onReceive(Context context
, Intent intent
) {
662 long parentDirId
= intent
.getLongExtra(FileUploader
.EXTRA_PARENT_DIR_ID
, -1);
663 OCFile parentDir
= mStorageManager
.getFileById(parentDirId
);
665 if (parentDir
!= null
&& (
666 (mCurrentDir
== null
&& parentDir
.getFileName().equals("/")) ||
667 parentDir
.equals(mCurrentDir
))
669 FileListFragment fileListFragment
= (FileListFragment
) getSupportFragmentManager().findFragmentById(R
.id
.fileList
);
670 if (fileListFragment
!= null
) {
671 fileListFragment
.listDirectory();
680 public void onClick(View v
) {
681 if (v
.getId() == R
.id
.setup_account
) {
682 Intent intent
= new Intent(android
.provider
.Settings
.ACTION_ADD_ACCOUNT
);
683 intent
.putExtra(android
.provider
.Settings
.EXTRA_AUTHORITIES
, new String
[] { AccountAuthenticator
.AUTH_TOKEN_TYPE
});
684 startActivity(intent
);
685 mForcedLoginToCreateFirstAccount
= true
;
697 public DataStorageManager
getStorageManager() {
698 return mStorageManager
;
706 public void onDirectoryClick(OCFile directory
) {
707 pushDirname(directory
);
708 ActionBar actionBar
= getSupportActionBar();
709 actionBar
.setDisplayHomeAsUpEnabled(true
);
712 // Resets the FileDetailsFragment on Tablets so that it always displays
713 FileDetailFragment fileDetails
= (FileDetailFragment
) getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
714 if (fileDetails
!= null
) {
715 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
716 transaction
.remove(fileDetails
);
717 transaction
.add(R
.id
.file_details_container
, new FileDetailFragment(null
, null
));
718 transaction
.commit();
728 public void onFileClick(OCFile file
) {
730 // If we are on a large device -> update fragment
732 // 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'
733 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
734 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(file
, AccountUtils
.getCurrentOwnCloudAccount(this)), FileDetailFragment
.FTAG
);
735 transaction
.setTransition(FragmentTransaction
.TRANSIT_FRAGMENT_FADE
);
736 transaction
.commit();
738 } else { // small or medium screen device -> new Activity
739 Intent showDetailsIntent
= new Intent(this, FileDetailActivity
.class);
740 showDetailsIntent
.putExtra(FileDetailFragment
.EXTRA_FILE
, file
);
741 showDetailsIntent
.putExtra(FileDownloader
.EXTRA_ACCOUNT
, AccountUtils
.getCurrentOwnCloudAccount(this));
742 startActivity(showDetailsIntent
);
747 * Operations in this method should be preferably performed in onCreate to have a lighter onResume method.
749 * 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
750 * put instead the ugly view that shows the 'Setup' button to restart the login activity.
752 * 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
753 * FragmentList view empty).
755 * 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)
757 private void initDelayedTilAccountAvailabe() {
758 setContentView(mLayoutView
);
759 mDualPane
= (findViewById(R
.id
.file_details_container
) != null
);
760 if (mDualPane
&& getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
) == null
) {
761 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
762 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(null
, null
)); // empty FileDetailFragment
763 transaction
.commit();
765 setSupportProgressBarIndeterminateVisibility(false
);
770 * Launch an intent to request the PIN code to the user before letting him use the app
772 private void requestPinCode() {
773 boolean pinStart
= false
;
774 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
775 pinStart
= appPrefs
.getBoolean("set_pincode", false
);
777 Intent i
= new Intent(getApplicationContext(), PinCodeActivity
.class);
778 i
.putExtra(PinCodeActivity
.EXTRA_ACTIVITY
, "FileDisplayActivity");