private static final String KEY_TRY_SHARE_AGAIN = "TRY_SHARE_AGAIN";
private static final String KEY_ACTION_BAR_TITLE = "ACTION_BAR_TITLE";
- protected static final long DELAY_TO_REQUEST_OPERATION_ON_ACTIVITY_RESULTS = 200;
+ protected static final long DELAY_TO_REQUEST_OPERATIONS_LATER = 200;
/** OwnCloud {@link Account} where the main {@link OCFile} handled by the activity is located.*/
}
@Override
+ protected void onStop() {
+ Log_OC.v(TAG, "onStop() start");
+ super.onStop();
+ Log_OC.v(TAG, "onStop() end");
+ }
+
+ @Override
protected void onDestroy() {
Log_OC.v(TAG, "onDestroy() start");
super.onDestroy();
requestMoveOperation(fData, fResultCode);
}
},
- DELAY_TO_REQUEST_OPERATION_ON_ACTIVITY_RESULTS
+ DELAY_TO_REQUEST_OPERATIONS_LATER
);
} else if (requestCode == ACTION_COPY_FILES && resultCode == RESULT_OK) {
requestCopyOperation(fData, fResultCode);
}
},
- DELAY_TO_REQUEST_OPERATION_ON_ACTIVITY_RESULTS
+ DELAY_TO_REQUEST_OPERATIONS_LATER
);
} else {
}
}
+
}
removeStickyBroadcast(intent);
Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress);
return null;
}
- public void startSyncFolderOperation(OCFile folder, boolean ignoreETag) {
- long currentSyncTime = System.currentTimeMillis();
-
- mSyncInProgress = true;
-
- // perform folder synchronization
- RemoteOperation synchFolderOp = new RefreshFolderOperation( folder,
- currentSyncTime,
- false,
- getFileOperationsHelper().isSharedSupported(),
- ignoreETag,
- getStorageManager(),
- getAccount(),
- getApplicationContext()
+ /**
+ * Starts an operation to refresh the requested folder.
+ *
+ * The operation is run in a new background thread created on the fly.
+ *
+ * The refresh updates is a "light sync": properties of regular files in folder are updated (including
+ * associated shares), but not their contents. Only the contents of files marked to be kept-in-sync are
+ * synchronized too.
+ *
+ * @param folder Folder to refresh.
+ * @param ignoreETag If 'true', the data from the server will be fetched and sync'ed even if the eTag
+ * didn't change.
+ */
+ public void startSyncFolderOperation(final OCFile folder, final boolean ignoreETag) {
+
+ // the execution is slightly delayed to allow the activity get the window focus if it's being started
+ // or if the method is called from a dialog that is being dismissed
+ getHandler().postDelayed(
+ new Runnable() {
+ @Override
+ public void run() {
+ if (hasWindowFocus()) {
+ long currentSyncTime = System.currentTimeMillis();
+ mSyncInProgress = true;
+
+ // perform folder synchronization
+ RemoteOperation synchFolderOp = new RefreshFolderOperation(folder,
+ currentSyncTime,
+ false,
+ getFileOperationsHelper().isSharedSupported(),
+ ignoreETag,
+ getStorageManager(),
+ getAccount(),
+ getApplicationContext()
+ );
+ synchFolderOp.execute(
+ getAccount(),
+ MainApp.getAppContext(),
+ FileDisplayActivity.this,
+ null,
+ null
+ );
+
+ mProgressBar.setIndeterminate(true);
+
+ setBackgroundText();
+
+ } // else: NOTHING ; lets' not refresh when the user rotates the device but there is
+ // another window floating over
+ }
+ },
+ DELAY_TO_REQUEST_OPERATIONS_LATER
);
- synchFolderOp.execute(getAccount(), MainApp.getAppContext(), this, null, null);
-
- mProgressBar.setIndeterminate(true);
- setBackgroundText();
}
/**
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
+import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import com.owncloud.android.R;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.lib.resources.shares.ShareType;
-import com.owncloud.android.operations.CreateShareWithShareeOperation;
import com.owncloud.android.ui.fragment.SearchShareesFragment;
import com.owncloud.android.ui.fragment.ShareFileFragment;
import com.owncloud.android.utils.GetShareWithUsersAsyncTask;
-import java.util.ArrayList;
/**
* Activity for sharing files
private static final String TAG_SHARE_FRAGMENT = "SHARE_FRAGMENT";
private static final String TAG_SEARCH_FRAGMENT = "SEARCH_USER_AND_GROUPS_FRAGMENT";
- private static final String DIALOG_WAIT_LOAD_DATA = "DIALOG_WAIT_LOAD_DATA";
-
- private ShareFileFragment mShareFileFragment;
- private SearchShareesFragment mSearchFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- onAccountSet(false);
setContentView(R.layout.share_activity);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
- if (savedInstanceState != null) {
-
- mShareFileFragment = (ShareFileFragment) getSupportFragmentManager().
- getFragment(savedInstanceState, TAG_SHARE_FRAGMENT);
- mSearchFragment = (SearchShareesFragment) getSupportFragmentManager().
- getFragment(savedInstanceState, TAG_SEARCH_FRAGMENT);
-
- if (mShareFileFragment != null){
- ft.replace(R.id.share_fragment_container, mShareFileFragment, TAG_SHARE_FRAGMENT);
-
- if (mSearchFragment != null){
- ft.hide(mShareFileFragment);
- ft.add(R.id.share_fragment_container, mSearchFragment, TAG_SEARCH_FRAGMENT);
- }
- ft.commit();
- }
-
- } else {
- // Add Share fragment
- mShareFileFragment = ShareFileFragment.newInstance(getFile(), getAccount());
- ft.replace(R.id.share_fragment_container, mShareFileFragment, TAG_SHARE_FRAGMENT);
+ if (savedInstanceState == null) {
+ // Add Share fragment on first creation
+ Fragment fragment = ShareFileFragment.newInstance(getFile(), getAccount());
+ ft.replace(R.id.share_fragment_container, fragment, TAG_SHARE_FRAGMENT);
ft.commit();
-
- mSearchFragment = null;
}
- handleIntent(getIntent());
+ }
+
+ protected void onAccountSet(boolean stateWasRecovered) {
+ super.onAccountSet(stateWasRecovered);
+ // Load data into the list
+ Log_OC.d(TAG, "Refreshing lists on account set");
+ refreshUsersInLists();
+ // Request for a refresh of the data through the server (starts an Async Task)
+ refreshUsersOrGroupsListFromServer();
}
@Override
protected void onNewIntent(Intent intent) {
- setIntent(intent);
- handleIntent(intent);
- }
-
-
- private void handleIntent(Intent intent) {
// Verify the action and get the query
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
}
@Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- //Save the fragment's instance
- getSupportFragmentManager().putFragment(outState, TAG_SHARE_FRAGMENT, mShareFileFragment);
- if (mSearchFragment != null) {
- getSupportFragmentManager().putFragment(outState, TAG_SEARCH_FRAGMENT, mSearchFragment);
- }
-
- }
-
- @Override
public void showSearchUsersAndGroups() {
+ // replace ShareFragment with SearchFragment on demand
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
- mSearchFragment = SearchShareesFragment.newInstance(getFile(), getAccount());
- ft.hide(mShareFileFragment);
- ft.add(R.id.share_fragment_container, mSearchFragment, TAG_SEARCH_FRAGMENT);
- ft.addToBackStack(TAG_SEARCH_FRAGMENT);
+ Fragment searchFragment = SearchShareesFragment.newInstance(getFile(), getAccount());
+ ft.replace(R.id.share_fragment_container, searchFragment, TAG_SEARCH_FRAGMENT);
+ ft.addToBackStack(null); // BACK button will recover the ShareFragment
ft.commit();
}
@Override
// Call to Unshare operation
- public void unshareWith(OCShare share){
+ public void unshareWith(OCShare share) {
OCFile file = getFile();
getFileOperationsHelper().unshareFileWithUserOrGroup(file, share.getShareType(), share.getShareWith());
}
* Get users and groups from the server to fill in the "share with" list
*/
@Override
- public void refreshUsersOrGroupsListFromServer(){
+ public void refreshUsersOrGroupsListFromServer() {
// Show loading
showLoadingDialog(getString(R.string.common_loading));
// Get Users and Groups
GetShareWithUsersAsyncTask getTask = new GetShareWithUsersAsyncTask(this);
- Object[] params = { getFile(), getAccount(), getStorageManager()};
+ Object[] params = {getFile(), getAccount(), getStorageManager()};
getTask.execute(params);
}
- @Override
- public void onBackPressed() {
- super.onBackPressed();
- if (mSearchFragment != null){
- mSearchFragment = null;
- getSupportFragmentManager().popBackStackImmediate();
- mShareFileFragment.refreshUsersOrGroupsListFromDB();
- }
- }
-
/**
* Updates the view associated to the activity after the finish of some operation over files
* in the current account.
super.onRemoteOperationFinish(operation, result);
if (result.isSuccess()) {
+ Log_OC.d(TAG, "Refreshing lists on successful sync");
refreshUsersInLists();
- if (operation instanceof CreateShareWithShareeOperation) {
- // Clean action
- getIntent().setAction(null);
- }
}
}
- private void refreshUsersInLists(){
- if (mShareFileFragment != null){
- mShareFileFragment.refreshUsersOrGroupsListFromDB();
+ private void refreshUsersInLists() {
+ ShareFileFragment shareFileFragment = getShareFileFragment();
+ if (shareFileFragment != null) { // only if added to the view hierarchy!!
+ if (shareFileFragment.isAdded()) {
+ shareFileFragment.refreshUsersOrGroupsListFromDB();
+ }
}
- if (mSearchFragment != null) {
- mSearchFragment.refreshUsersOrGroupsListFromDB();
+
+ SearchShareesFragment searchShareesFragment = getSearchFragment();
+ if (searchShareesFragment != null) {
+ if (searchShareesFragment.isAdded()) { // only if added to the view hierarchy!!
+ searchShareesFragment.refreshUsersOrGroupsListFromDB();
+ }
}
}
+ /**
+ * Shortcut to get access to the {@link ShareFileFragment} instance, if any
+ *
+ * @return A {@link ShareFileFragment} instance, or null
+ */
+ private ShareFileFragment getShareFileFragment() {
+ return (ShareFileFragment) getSupportFragmentManager().findFragmentByTag(TAG_SHARE_FRAGMENT);
+ }
+
+ /**
+ * Shortcut to get access to the {@link SearchShareesFragment} instance, if any
+ *
+ * @return A {@link SearchShareesFragment} instance, or null
+ */
+ private SearchShareesFragment getSearchFragment() {
+ return (SearchShareesFragment) getSupportFragmentManager().findFragmentByTag(TAG_SEARCH_FRAGMENT);
+ }
+
}
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.shares.OCShare;
+import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.ui.activity.ShareActivity;
import com.owncloud.android.ui.adapter.ShareUserListAdapter;
import java.util.ArrayList;
/**
- * Fragment for Searching users and groups
+ * Fragment for Searching sharees (users and groups)
*
* A simple {@link Fragment} subclass.
+ *
* Activities that contain this fragment must implement the
* {@link SearchShareesFragment.OnSearchFragmentInteractionListener} interface
* to handle interaction events.
+ *
* Use the {@link SearchShareesFragment#newInstance} factory method to
* create an instance of this fragment.
*/
private OCFile mFile;
private Account mAccount;
+ // other members
private ArrayList<OCShare> mShares;
private ShareUserListAdapter mUserGroupsAdapter = null;
-
private OnSearchFragmentInteractionListener mListener;
+
/**
* Public factory method to create new SearchShareesFragment instances.
*
* @param fileToShare An {@link OCFile} to be shared
- * @param account An ownCloud account
+ * @param account The ownCloud account containing fileToShare
* @return A new instance of fragment SearchShareesFragment.
*/
public static SearchShareesFragment newInstance(OCFile fileToShare, Account account) {
// Required empty public constructor
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
/**
- * Get users and groups fromn the DB to fill in the "share with" list
+ * Get users and groups from the DB to fill in the "share with" list
+ *
+ * Depends on the parent Activity provides a {@link com.owncloud.android.datamodel.FileDataStorageManager}
+ * instance ready to use. If not ready, does nothing.
*/
public void refreshUsersOrGroupsListFromDB (){
// Get Users and Groups
- mShares = ((ShareActivity) mListener).getStorageManager().getSharesWithForAFile(mFile.getRemotePath(),
- mAccount.name);
-
- // Update list of users/groups
- updateListOfUserGroups();
+ if (((FileActivity) mListener).getStorageManager() != null) {
+ mShares = ((FileActivity) mListener).getStorageManager().getSharesWithForAFile(
+ mFile.getRemotePath(),
+ mAccount.name
+ );
+
+ // Update list of users/groups
+ updateListOfUserGroups();
+ }
}
private void updateListOfUserGroups() {
// Update list of users/groups
- mUserGroupsAdapter = new ShareUserListAdapter(getActivity().getApplicationContext(),
- R.layout.share_user_item, mShares, this);
+ // TODO Refactoring: create a new {@link ShareUserListAdapter} instance with every call should not be needed
+ mUserGroupsAdapter = new ShareUserListAdapter(
+ getActivity().getApplicationContext(),
+ R.layout.share_user_item, mShares, this
+ );
// Show data
ListView usersList = (ListView) getView().findViewById(R.id.searchUsersListView);
import com.owncloud.android.datamodel.ThumbnailsCacheManager;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.shares.OCShare;
+import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.ui.activity.ShareActivity;
import com.owncloud.android.ui.adapter.ShareUserListAdapter;
import com.owncloud.android.utils.DisplayUtils;
import java.util.ArrayList;
/**
- * Fragment for Sharing a file with users
+ * Fragment for Sharing a file with sharees (users or groups)
*
* A simple {@link Fragment} subclass.
+ *
* Activities that contain this fragment must implement the
* {@link ShareFileFragment.OnShareFragmentInteractionListener} interface
* to handle interaction events.
+ *
* Use the {@link ShareFileFragment#newInstance} factory method to
* create an instance of this fragment.
*/
private OCFile mFile;
private Account mAccount;
+ // other members
private ArrayList<OCShare> mShares;
private ShareUserListAdapter mUserGroupsAdapter = null;
-
private OnShareFragmentInteractionListener mListener;
/**
// Required empty public constructor
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Load data into the list
refreshUsersOrGroupsListFromDB();
-
- // Request for a refresh of the data through the server (starts an Async Task)
- if (mListener != null) {
- mListener.refreshUsersOrGroupsListFromServer();
- }
}
@Override
}
/**
- * Get users and groups fromn the DB to fill in the "share with" list
+ * Get users and groups from the DB to fill in the "share with" list
+ *
+ * Depends on the parent Activity provides a {@link com.owncloud.android.datamodel.FileDataStorageManager}
+ * instance ready to use. If not ready, does nothing.
*/
public void refreshUsersOrGroupsListFromDB (){
- // Get Users and Groups
- mShares = ((ShareActivity) mListener).getStorageManager().getSharesWithForAFile(mFile.getRemotePath(),
- mAccount.name);
-
- // Update list of users/groups
- updateListOfUserGroups();
+ if (((FileActivity) mListener).getStorageManager() != null) {
+ // Get Users and Groups
+ mShares = ((FileActivity) mListener).getStorageManager().getSharesWithForAFile(
+ mFile.getRemotePath(),
+ mAccount.name
+ );
+
+ // Update list of users/groups
+ updateListOfUserGroups();
+ }
}
private void updateListOfUserGroups() {
// Update list of users/groups
+ // TODO Refactoring: create a new {@link ShareUserListAdapter} instance with every call should not be needed
mUserGroupsAdapter = new ShareUserListAdapter(
getActivity(),
R.layout.share_user_item,