X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/bf23f0b5e906f5adb96cb59bc4c10232ff28e4ed..4b9190baeacb49dd53f25d2225e451765d99fe98:/src/com/owncloud/android/ui/activity/FileDisplayActivity.java diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 2b07fa4a..d8967647 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -49,16 +49,16 @@ import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.support.v4.view.GravityCompat; -import android.support.v7.app.ActionBar; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; -import android.view.Window; +import android.widget.ProgressBar; import android.widget.Toast; import com.owncloud.android.MainApp; 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; @@ -120,6 +120,7 @@ public class FileDisplayActivity extends HookActivity private boolean mDualPane; private View mLeftFragmentContainer; private View mRightFragmentContainer; + private ProgressBar mProgressBar; private static final String KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW"; private static final String KEY_SYNC_IN_PROGRESS = "SYNC_IN_PROGRESS"; @@ -151,7 +152,7 @@ public class FileDisplayActivity extends HookActivity @Override protected void onCreate(Bundle savedInstanceState) { Log_OC.v(TAG, "onCreate() start"); - requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); + //requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); super.onCreate(savedInstanceState); // this calls onAccountChanged() when ownCloud Account // is valid @@ -184,6 +185,8 @@ public class FileDisplayActivity extends HookActivity // Navigation Drawer initDrawer(); + mProgressBar = (ProgressBar) findViewById(R.id.progressBar); + mDualPane = getResources().getBoolean(R.bool.large_land_layout); mLeftFragmentContainer = findViewById(R.id.left_fragment_container); mRightFragmentContainer = findViewById(R.id.right_fragment_container); @@ -195,13 +198,17 @@ public class FileDisplayActivity extends HookActivity getSupportActionBar().setHomeButtonEnabled(true); // mandatory since Android ICS, // according to the official // documentation - if (getFile() != null) { - updateActionBarTitle(); - } - setSupportProgressBarIndeterminateVisibility(mSyncInProgress - /*|| mRefreshSharesInProgress*/); + // enable ActionBar app icon to behave as action to toggle nav drawer + //getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setHomeButtonEnabled(true); + + mProgressBar.setVisibility((mSyncInProgress) ? View.VISIBLE : View.INVISIBLE); + //setSupportProgressBarIndeterminateVisibility(mSyncInProgress + /*|| mRefreshSharesInProgress*/ //); // always AFTER setContentView(...) ; to work around bug in its implementation + + initDrawer(); setBackgroundText(); @@ -212,7 +219,6 @@ public class FileDisplayActivity extends HookActivity protected void onStart() { Log_OC.v(TAG, "onStart() start"); super.onStart(); - getSupportActionBar().setIcon(DisplayUtils.getSeasonalIconId()); Log_OC.v(TAG, "onStart() end"); } @@ -263,7 +269,7 @@ public class FileDisplayActivity extends HookActivity } else { updateFragmentsVisibility(!file.isFolder()); - updateNavigationElementsInActionBar(file.isFolder() ? null : file); + updateActionBarTitleAndHomeButton(file.isFolder() ? null : file); } } } @@ -294,7 +300,7 @@ public class FileDisplayActivity extends HookActivity if (secondFragment != null) { setSecondFragment(secondFragment); updateFragmentsVisibility(true); - updateNavigationElementsInActionBar(file); + updateActionBarTitleAndHomeButton(file); } else { cleanSecondFragment(); @@ -325,7 +331,7 @@ public class FileDisplayActivity extends HookActivity startPlaybackPosition, autoplay); } else { - secondFragment = new FileDetailFragment(file, getAccount()); + secondFragment = FileDetailFragment.newInstance(file, getAccount()); } } return secondFragment; @@ -402,7 +408,7 @@ public class FileDisplayActivity extends HookActivity tr.commit(); } updateFragmentsVisibility(false); - updateNavigationElementsInActionBar(null); + updateActionBarTitleAndHomeButton(null); } protected void refreshListOfFilesFragment() { @@ -624,10 +630,7 @@ public class FileDisplayActivity extends HookActivity String[] filePaths = data.getStringArrayExtra(UploadFilesActivity.EXTRA_CHOSEN_FILES); if (filePaths != null) { String[] remotePaths = new String[filePaths.length]; - String remotePathBase = ""; - - if (!remotePathBase.endsWith(OCFile.PATH_SEPARATOR)) - remotePathBase += OCFile.PATH_SEPARATOR; + String remotePathBase = getCurrentDir().getRemotePath(); for (int j = 0; j< remotePaths.length; j++) { remotePaths[j] = remotePathBase + (new File(filePaths[j])).getName(); } @@ -734,22 +737,25 @@ public class FileDisplayActivity extends HookActivity @Override public void onBackPressed() { - OCFileListFragment listOfFiles = getListOfFilesFragment(); - if (mDualPane || getSecondFragment() == null) { - if (getFile() != null && getFile().getParentId() == 0) { - finish(); - return; + if (!isDrawerOpen()){ + OCFileListFragment listOfFiles = getListOfFilesFragment(); + if (mDualPane || getSecondFragment() == null) { + OCFile currentDir = getCurrentDir(); + if (currentDir == null || currentDir.getParentId() == FileDataStorageManager.ROOT_PARENT_ID) { + finish(); + return; + } + if (listOfFiles != null) { // should never be null, indeed + listOfFiles.onBrowseUp(); + } } if (listOfFiles != null) { // should never be null, indeed - listOfFiles.onBrowseUp(); + setFile(listOfFiles.getCurrentFile()); } + cleanSecondFragment(); + } else { + super.onBackPressed(); } - if (listOfFiles != null) { // should never be null, indeed - setFile(listOfFiles.getCurrentFile()); - } - updateActionBarTitle(); - cleanSecondFragment(); - } @Override @@ -937,8 +943,9 @@ public class FileDisplayActivity extends HookActivity } removeStickyBroadcast(intent); Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress); - setSupportProgressBarIndeterminateVisibility(mSyncInProgress - /*|| mRefreshSharesInProgress*/); + mProgressBar.setVisibility((mSyncInProgress) ? View.VISIBLE : View.INVISIBLE); + //setSupportProgressBarIndeterminateVisibility(mSyncInProgress + /*|| mRefreshSharesInProgress*/ //); setBackgroundText(); @@ -1034,7 +1041,10 @@ public class FileDisplayActivity extends HookActivity startImagePreview(getFile()); } // TODO what about other kind of previews? } - + + //setSupportProgressBarIndeterminate(false); + mProgressBar.setVisibility(View.INVISIBLE); + } finally { if (intent != null) { removeStickyBroadcast(intent); @@ -1126,7 +1136,6 @@ public class FileDisplayActivity extends HookActivity // listOfFiles.listDirectory(root, MainApp.getOnlyOnDevice()); setFile(listOfFiles.getCurrentFile()); startSyncFolderOperation(root, false); - updateActionBarTitle(); } cleanSecondFragment(); @@ -1140,12 +1149,10 @@ public class FileDisplayActivity extends HookActivity */ @Override public void onBrowsedDownTo(OCFile directory) { - cleanSecondFragment(); setFile(directory); - updateActionBarTitle(); + cleanSecondFragment(); // Sync Folder startSyncFolderOperation(directory, false); - } /** @@ -1156,54 +1163,24 @@ public class FileDisplayActivity extends HookActivity */ @Override public void showDetails(OCFile file) { - Fragment detailFragment = new FileDetailFragment(file, getAccount()); + Fragment detailFragment = FileDetailFragment.newInstance(file, getAccount()); setSecondFragment(detailFragment); updateFragmentsVisibility(true); - updateNavigationElementsInActionBar(file); + updateActionBarTitleAndHomeButton(file); setFile(file); } - - /** - * TODO - */ - private void updateNavigationElementsInActionBar(OCFile chosenFile) { - ActionBar actionBar = getSupportActionBar(); - - // For adding content description tag to a title field in the action bar - int actionBarTitleId = getResources().getIdentifier("action_bar_title", "id", "android"); - - if (chosenFile == null || mDualPane) { - // only list of files - set for browsing through folders - OCFile currentDir = getCurrentDir(); - boolean noRoot = (currentDir != null && currentDir.getParentId() != 0); -// actionBar.setDisplayHomeAsUpEnabled(noRoot); -// actionBar.setDisplayShowTitleEnabled(!noRoot); - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setDisplayShowTitleEnabled(true); - if (!noRoot) { - actionBar.setTitle(getString(R.string.default_display_name_for_root_folder)); - View actionBarTitleView = getWindow().getDecorView().findViewById(actionBarTitleId); - if (actionBarTitleView != null) { // it's null in Android 2.x - actionBarTitleView.setContentDescription( - getString(R.string.default_display_name_for_root_folder)); - } - } - actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); + @Override + protected void updateActionBarTitleAndHomeButton(OCFile chosenFile) { + if (mDualPane) { + // in dual pane mode, keep the focus of title an action bar in the current folder + super.updateActionBarTitleAndHomeButton(getCurrentDir()); } else { - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setDisplayShowTitleEnabled(true); - actionBar.setTitle(chosenFile.getFileName()); - actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); - View actionBarTitleView = getWindow().getDecorView().findViewById(actionBarTitleId); - if (actionBarTitleView != null) { // it's null in Android 2.x - getWindow().getDecorView().findViewById(actionBarTitleId). - setContentDescription(chosenFile.getFileName()); - } + super.updateActionBarTitleAndHomeButton(chosenFile); } - } + } @Override protected ServiceConnection newTransferenceServiceConnection() { @@ -1495,6 +1472,7 @@ public class FileDisplayActivity extends HookActivity operation, getResources()), Toast.LENGTH_LONG); msg.show(); } + invalidateOptionsMenu(); } } @@ -1590,8 +1568,9 @@ public class FileDisplayActivity extends HookActivity getApplicationContext() ); synchFolderOp.execute(getAccount(), MainApp.getAppContext(), this, null, null); - - setSupportProgressBarIndeterminateVisibility(true); + + mProgressBar.setVisibility(View.VISIBLE); + //setSupportProgressBarIndeterminateVisibility(true); setBackgroundText(); } @@ -1665,7 +1644,7 @@ public class FileDisplayActivity extends HookActivity autoplay); setSecondFragment(mediaFragment); updateFragmentsVisibility(true); - updateNavigationElementsInActionBar(file); + updateActionBarTitleAndHomeButton(file); setFile(file); } @@ -1677,12 +1656,12 @@ public class FileDisplayActivity extends HookActivity * @param file {@link OCFile} to download and preview. */ public void startDownloadForPreview(OCFile file) { - Fragment detailFragment = new FileDetailFragment(file, getAccount()); + Fragment detailFragment = FileDetailFragment.newInstance(file, getAccount()); setSecondFragment(detailFragment); mWaitingToPreview = file; requestForDownload(); updateFragmentsVisibility(true); - updateNavigationElementsInActionBar(file); + updateActionBarTitleAndHomeButton(file); setFile(file); }