浏览代码

Add getFileNameWithExtension functionality

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 1 年之前
父节点
当前提交
9b672d61a4

+ 7 - 6
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<OCFile>, 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
      *

+ 5 - 3
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;

+ 2 - 2
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().

+ 2 - 2
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;
         }
     }

+ 1 - 1
app/src/main/res/values/strings.xml

@@ -162,7 +162,7 @@
     <string name="uploads_view_upload_status_fetching_server_version">Fetching server version…</string>
     <string name="uploads_view_later_waiting_to_upload">Waiting to upload</string>
     <string name="uploads_view_group_header" translatable="false">%1$s (%2$d)</string>
-    <string name="file_downloader_notification_title_suffix">\u0020download</string>
+    <string name="file_downloader_notification_title_prefix">Downloading \u0020</string>
     <string name="downloader_download_in_progress_ticker">Downloading…</string>
     <string name="downloader_download_in_progress_content">%1$d%% Downloading %2$s</string>
     <string name="downloader_download_succeeded_ticker">Downloaded</string>