Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <alper_ozturk@proton.me>
  • Loading branch information
alperozturk96 committed Aug 29, 2024
1 parent 45e3feb commit aa6f5c7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import com.nextcloud.client.network.ClientFactory;
import com.nextcloud.client.network.ConnectivityService;
import com.nextcloud.client.preferences.AppPreferences;
import com.nextcloud.model.WorkerState;
import com.nextcloud.model.WorkerStateLiveData;
import com.nextcloud.ui.fileactions.FileActionsBottomSheet;
import com.nextcloud.utils.MenuUtils;
import com.nextcloud.utils.extensions.BundleExtensionsKt;
Expand Down Expand Up @@ -578,7 +580,11 @@ public void updateFileDetails(boolean transferring, boolean refresh) {

setupViewPager();

getView().invalidate();
if (getView() != null) {
getView().invalidate();
}

observeWorkerState();
}

private void setFileModificationTimestamp(OCFile file, boolean showDetailedTimestamp) {
Expand Down Expand Up @@ -678,14 +684,19 @@ private void setButtonsForTransferring() {
// show the progress bar for the transfer
binding.progressBlock.setVisibility(View.VISIBLE);
binding.progressText.setVisibility(View.VISIBLE);
if (FileDownloadHelper.Companion.instance().isDownloading(user, getFile())) {
}
}

private void observeWorkerState() {
WorkerStateLiveData.Companion.instance().observe(getViewLifecycleOwner(), state -> {
if (state instanceof WorkerState.Download) {
binding.progressText.setText(R.string.downloader_download_in_progress_ticker);
} else if (state instanceof WorkerState.Upload) {
binding.progressText.setText(R.string.uploader_upload_in_progress_ticker);
} else {
if (FileUploadHelper.Companion.instance().isUploading(user, getFile())) {
binding.progressText.setText(R.string.uploader_upload_in_progress_ticker);
}
binding.progressBlock.setVisibility(View.GONE);
}
}
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import com.nextcloud.client.account.User;
import com.nextcloud.client.di.Injectable;
import com.nextcloud.client.jobs.download.FileDownloadHelper;
import com.nextcloud.model.WorkerState;
import com.nextcloud.model.WorkerStateLiveData;
import com.nextcloud.utils.extensions.BundleExtensionsKt;
import com.nextcloud.utils.extensions.FileExtensionsKt;
import com.owncloud.android.R;
Expand Down Expand Up @@ -152,11 +154,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,

if (mError) {
setButtonsForRemote();
}
else {
} else {
setButtonsForTransferring();
}

observeWorkerState();

return mView;
}

Expand Down Expand Up @@ -219,11 +222,26 @@ public void onClick(View v) {
}
}

private void observeWorkerState() {
WorkerStateLiveData.Companion.instance().observe(getViewLifecycleOwner(), state -> {
if (state instanceof WorkerState.Idle) {
if (getView() == null) return;

// TODO Open downloaded file immediately

}
});
}


/**
* Enables or disables buttons for a file being downloaded
*/
private void setButtonsForTransferring() {
if (getView() == null) {
return;
}

getView().findViewById(R.id.cancelBtn).setVisibility(View.VISIBLE);

// show the progress bar for the transfer
Expand All @@ -243,6 +261,10 @@ private void setButtonsForTransferring() {
* Currently, this is only used when a download was failed
*/
private void setButtonsForRemote() {
if (getView() == null) {
return;
}

getView().findViewById(R.id.cancelBtn).setVisibility(View.GONE);

// hides the progress bar and message
Expand Down

0 comments on commit aa6f5c7

Please sign in to comment.