From 9b672d61a4552dcf5b8e4d7fe1c2c3955e7ddf44 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Fri, 20 Oct 2023 11:31:27 +0200 Subject: [PATCH] Add getFileNameWithExtension functionality Signed-off-by: alperozturk --- .../java/com/owncloud/android/datamodel/OCFile.java | 13 +++++++------ .../android/files/services/FileDownloader.java | 8 +++++--- .../android/ui/fragment/FileDetailFragment.java | 4 ++-- .../android/ui/preview/FileDownloadFragment.java | 4 ++-- app/src/main/res/values/strings.xml | 2 +- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/datamodel/OCFile.java b/app/src/main/java/com/owncloud/android/datamodel/OCFile.java index b6c42dbe60..097c7808de 100644 --- a/app/src/main/java/com/owncloud/android/datamodel/OCFile.java +++ b/app/src/main/java/com/owncloud/android/datamodel/OCFile.java @@ -24,14 +24,11 @@ package com.owncloud.android.datamodel; import android.content.ContentResolver; import android.content.Context; -import android.graphics.drawable.Drawable; -import android.graphics.drawable.LayerDrawable; import android.net.Uri; import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; -import com.nextcloud.android.common.ui.theme.utils.ColorRole; import com.owncloud.android.R; import com.owncloud.android.lib.common.network.WebdavEntry; import com.owncloud.android.lib.common.network.WebdavUtils; @@ -41,9 +38,7 @@ import com.owncloud.android.lib.resources.files.model.GeoLocation; import com.owncloud.android.lib.resources.files.model.ImageDimension; import com.owncloud.android.lib.resources.files.model.ServerFileInterface; import com.owncloud.android.lib.resources.shares.ShareeUser; -import com.owncloud.android.utils.DrawableUtil; import com.owncloud.android.utils.MimeType; -import com.owncloud.android.utils.theme.ViewThemeUtils; import java.io.File; import java.util.ArrayList; @@ -52,7 +47,6 @@ import java.util.List; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; -import androidx.core.content.ContextCompat; import androidx.core.content.FileProvider; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import third_parties.daveKoeller.AlphanumComparator; @@ -350,6 +344,13 @@ public class OCFile implements Parcelable, Comparable, ServerFileInterfa return false; } + public String getFileNameWithExtension(int fileNameLength) { + String fileName = getFileName(); + String shortFileName = fileName.substring(0, Math.min(fileName.length(), fileNameLength)); + String extension = "." + fileName.substring(fileName.lastIndexOf('.') + 1); + return shortFileName + extension; + } + /** * The path, where the file is stored locally * diff --git a/app/src/main/java/com/owncloud/android/files/services/FileDownloader.java b/app/src/main/java/com/owncloud/android/files/services/FileDownloader.java index 701cbb1555..6327a13974 100644 --- a/app/src/main/java/com/owncloud/android/files/services/FileDownloader.java +++ b/app/src/main/java/com/owncloud/android/files/services/FileDownloader.java @@ -380,7 +380,7 @@ public class FileDownloader extends Service * @param listener Object to notify about progress of transfer. * @param file {@link OCFile} of interest for listener. */ - public void addDatatransferProgressListener(OnDatatransferProgressListener listener, OCFile file) { + public void addDataTransferProgressListener(OnDatatransferProgressListener listener, OCFile file) { if (file == null || listener == null) { return; } @@ -394,7 +394,7 @@ public class FileDownloader extends Service * @param listener Object to notify about progress of transfer. * @param file {@link OCFile} of interest for listener. */ - public void removeDatatransferProgressListener(OnDatatransferProgressListener listener, OCFile file) { + public void removeDataTransferProgressListener(OnDatatransferProgressListener listener, OCFile file) { if (file == null || listener == null) { return; } @@ -564,7 +564,9 @@ public class FileDownloader extends Service * @param download Download operation starting. */ private void notifyDownloadStart(DownloadFileOperation download) { - String title = download.getFile().getFileName() + getString(R.string.file_downloader_notification_title_suffix); + String fileName = download.getFile().getFileNameWithExtension(10); + String titlePrefix = getString(R.string.file_downloader_notification_title_prefix); + String title = titlePrefix + fileName; /// update status notification with a progress bar mLastPercent = 0; diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java b/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java index 76b5393ecf..04ac544538 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java @@ -694,7 +694,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener, if (progressListener != null) { if (containerActivity.getFileDownloaderBinder() != null) { containerActivity.getFileDownloaderBinder(). - addDatatransferProgressListener(progressListener, getFile()); + addDataTransferProgressListener(progressListener, getFile()); } if (containerActivity.getFileUploaderBinder() != null) { containerActivity.getFileUploaderBinder(). @@ -709,7 +709,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener, if (progressListener != null) { if (containerActivity.getFileDownloaderBinder() != null) { containerActivity.getFileDownloaderBinder(). - removeDatatransferProgressListener(progressListener, getFile()); + removeDataTransferProgressListener(progressListener, getFile()); } if (containerActivity.getFileUploaderBinder() != null) { containerActivity.getFileUploaderBinder(). diff --git a/app/src/main/java/com/owncloud/android/ui/preview/FileDownloadFragment.java b/app/src/main/java/com/owncloud/android/ui/preview/FileDownloadFragment.java index ffca7c685a..62a098e37d 100644 --- a/app/src/main/java/com/owncloud/android/ui/preview/FileDownloadFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/preview/FileDownloadFragment.java @@ -261,7 +261,7 @@ public class FileDownloadFragment extends FileFragment implements OnClickListene public void listenForTransferProgress() { if (mProgressListener != null && !mListening && containerActivity.getFileDownloaderBinder() != null) { - containerActivity.getFileDownloaderBinder().addDatatransferProgressListener(mProgressListener, getFile()); + containerActivity.getFileDownloaderBinder().addDataTransferProgressListener(mProgressListener, getFile()); mListening = true; setButtonsForTransferring(); } @@ -271,7 +271,7 @@ public class FileDownloadFragment extends FileFragment implements OnClickListene public void leaveTransferProgress() { if (mProgressListener != null && containerActivity.getFileDownloaderBinder() != null) { containerActivity.getFileDownloaderBinder() - .removeDatatransferProgressListener(mProgressListener, getFile()); + .removeDataTransferProgressListener(mProgressListener, getFile()); mListening = false; } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 917c6c0ec1..99aed7f9de 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -162,7 +162,7 @@ Fetching server version… Waiting to upload %1$s (%2$d) - \u0020download + Downloading \u0020 Downloading… %1$d%% Downloading %2$s Downloaded