mirror of
https://github.com/nextcloud/android.git
synced 2024-11-22 05:05:31 +03:00
favorite/unfavorite in details view
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
parent
8f6c7fe4d9
commit
4c62ee6c5a
1 changed files with 39 additions and 4 deletions
|
@ -44,6 +44,7 @@ import com.google.android.material.tabs.TabLayout;
|
|||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.nextcloud.client.network.ConnectivityService;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
import com.owncloud.android.MainApp;
|
||||
|
@ -55,8 +56,11 @@ import com.owncloud.android.datamodel.ThumbnailsCacheManager;
|
|||
import com.owncloud.android.files.FileMenuFilter;
|
||||
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
|
||||
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.lib.resources.files.ToggleFavoriteRemoteOperation;
|
||||
import com.owncloud.android.lib.resources.shares.OCShare;
|
||||
import com.owncloud.android.lib.resources.shares.ShareType;
|
||||
import com.owncloud.android.ui.activity.FileDisplayActivity;
|
||||
|
@ -64,12 +68,17 @@ import com.owncloud.android.ui.activity.ToolbarActivity;
|
|||
import com.owncloud.android.ui.adapter.FileDetailTabAdapter;
|
||||
import com.owncloud.android.ui.dialog.RemoveFilesDialogFragment;
|
||||
import com.owncloud.android.ui.dialog.RenameFileDialogFragment;
|
||||
import com.owncloud.android.ui.events.FavoriteEvent;
|
||||
import com.owncloud.android.utils.DisplayUtils;
|
||||
import com.owncloud.android.utils.MimeTypeUtil;
|
||||
import com.owncloud.android.utils.theme.ThemeBarUtils;
|
||||
import com.owncloud.android.utils.theme.ThemeColorUtils;
|
||||
import com.owncloud.android.utils.theme.ThemeLayoutUtils;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
@ -101,15 +110,17 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
|
|||
@Inject AppPreferences preferences;
|
||||
@Inject ConnectivityService connectivityService;
|
||||
@Inject UserAccountManager accountManager;
|
||||
@Inject ClientFactory clientFactory;
|
||||
@Inject FileDataStorageManager storageManager;
|
||||
|
||||
/**
|
||||
* Public factory method to create new FileDetailFragment instances.
|
||||
*
|
||||
* <p>
|
||||
* When 'fileToDetail' or 'ocAccount' are null, creates a dummy layout (to use when a file wasn't tapped before).
|
||||
*
|
||||
* @param fileToDetail An {@link OCFile} to show in the fragment
|
||||
* @param user Currently active user
|
||||
* @return New fragment with arguments set
|
||||
* @param fileToDetail An {@link OCFile} to show in the fragment
|
||||
* @param user Currently active user
|
||||
* @return New fragment with arguments set
|
||||
*/
|
||||
public static FileDetailFragment newInstance(OCFile fileToDetail, User user) {
|
||||
FileDetailFragment frag = new FileDetailFragment();
|
||||
|
@ -286,6 +297,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
|
|||
public void onStart() {
|
||||
super.onStart();
|
||||
listenForTransferProgress();
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -315,6 +327,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
|
|||
toolbarActivity.hidePreviewImage();
|
||||
}
|
||||
|
||||
EventBus.getDefault().unregister(this);
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
|
@ -719,6 +732,28 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
|
|||
showHideFragmentView(true);
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.BACKGROUND)
|
||||
public void onMessageEvent(FavoriteEvent event) {
|
||||
try {
|
||||
User user = accountManager.getUser();
|
||||
OwnCloudClient client = clientFactory.create(user);
|
||||
|
||||
ToggleFavoriteRemoteOperation toggleFavoriteOperation = new ToggleFavoriteRemoteOperation(
|
||||
event.shouldFavorite, event.remotePath);
|
||||
RemoteOperationResult remoteOperationResult = toggleFavoriteOperation.execute(client);
|
||||
|
||||
if (remoteOperationResult.isSuccess()) {
|
||||
getFile().setFavorite(event.shouldFavorite);
|
||||
OCFile file = storageManager.getFileByEncryptedRemotePath(event.remotePath);
|
||||
file.setFavorite(event.shouldFavorite);
|
||||
storageManager.saveFile(file);
|
||||
}
|
||||
|
||||
} catch (ClientFactory.CreationException e) {
|
||||
Log_OC.e(TAG, "Error processing event", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper class responsible for updating the progress bar shown for file downloading.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue