Add getFileNameWithExtension functionality

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2023-10-20 11:31:27 +02:00 committed by Andy Scherzinger
parent a617008eca
commit 9b672d61a4
5 changed files with 17 additions and 14 deletions

View file

@ -24,14 +24,11 @@ package com.owncloud.android.datamodel;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.net.Uri; import android.net.Uri;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.text.TextUtils; import android.text.TextUtils;
import com.nextcloud.android.common.ui.theme.utils.ColorRole;
import com.owncloud.android.R; import com.owncloud.android.R;
import com.owncloud.android.lib.common.network.WebdavEntry; import com.owncloud.android.lib.common.network.WebdavEntry;
import com.owncloud.android.lib.common.network.WebdavUtils; 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.ImageDimension;
import com.owncloud.android.lib.resources.files.model.ServerFileInterface; import com.owncloud.android.lib.resources.files.model.ServerFileInterface;
import com.owncloud.android.lib.resources.shares.ShareeUser; 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.MimeType;
import com.owncloud.android.utils.theme.ViewThemeUtils;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -52,7 +47,6 @@ import java.util.List;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider; import androidx.core.content.FileProvider;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import third_parties.daveKoeller.AlphanumComparator; import third_parties.daveKoeller.AlphanumComparator;
@ -350,6 +344,13 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
return false; 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 * The path, where the file is stored locally
* *

View file

@ -380,7 +380,7 @@ public class FileDownloader extends Service
* @param listener Object to notify about progress of transfer. * @param listener Object to notify about progress of transfer.
* @param file {@link OCFile} of interest for listener. * @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) { if (file == null || listener == null) {
return; return;
} }
@ -394,7 +394,7 @@ public class FileDownloader extends Service
* @param listener Object to notify about progress of transfer. * @param listener Object to notify about progress of transfer.
* @param file {@link OCFile} of interest for listener. * @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) { if (file == null || listener == null) {
return; return;
} }
@ -564,7 +564,9 @@ public class FileDownloader extends Service
* @param download Download operation starting. * @param download Download operation starting.
*/ */
private void notifyDownloadStart(DownloadFileOperation download) { 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 /// update status notification with a progress bar
mLastPercent = 0; mLastPercent = 0;

View file

@ -694,7 +694,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
if (progressListener != null) { if (progressListener != null) {
if (containerActivity.getFileDownloaderBinder() != null) { if (containerActivity.getFileDownloaderBinder() != null) {
containerActivity.getFileDownloaderBinder(). containerActivity.getFileDownloaderBinder().
addDatatransferProgressListener(progressListener, getFile()); addDataTransferProgressListener(progressListener, getFile());
} }
if (containerActivity.getFileUploaderBinder() != null) { if (containerActivity.getFileUploaderBinder() != null) {
containerActivity.getFileUploaderBinder(). containerActivity.getFileUploaderBinder().
@ -709,7 +709,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
if (progressListener != null) { if (progressListener != null) {
if (containerActivity.getFileDownloaderBinder() != null) { if (containerActivity.getFileDownloaderBinder() != null) {
containerActivity.getFileDownloaderBinder(). containerActivity.getFileDownloaderBinder().
removeDatatransferProgressListener(progressListener, getFile()); removeDataTransferProgressListener(progressListener, getFile());
} }
if (containerActivity.getFileUploaderBinder() != null) { if (containerActivity.getFileUploaderBinder() != null) {
containerActivity.getFileUploaderBinder(). containerActivity.getFileUploaderBinder().

View file

@ -261,7 +261,7 @@ public class FileDownloadFragment extends FileFragment implements OnClickListene
public void listenForTransferProgress() { public void listenForTransferProgress() {
if (mProgressListener != null && !mListening && containerActivity.getFileDownloaderBinder() != null) { if (mProgressListener != null && !mListening && containerActivity.getFileDownloaderBinder() != null) {
containerActivity.getFileDownloaderBinder().addDatatransferProgressListener(mProgressListener, getFile()); containerActivity.getFileDownloaderBinder().addDataTransferProgressListener(mProgressListener, getFile());
mListening = true; mListening = true;
setButtonsForTransferring(); setButtonsForTransferring();
} }
@ -271,7 +271,7 @@ public class FileDownloadFragment extends FileFragment implements OnClickListene
public void leaveTransferProgress() { public void leaveTransferProgress() {
if (mProgressListener != null && containerActivity.getFileDownloaderBinder() != null) { if (mProgressListener != null && containerActivity.getFileDownloaderBinder() != null) {
containerActivity.getFileDownloaderBinder() containerActivity.getFileDownloaderBinder()
.removeDatatransferProgressListener(mProgressListener, getFile()); .removeDataTransferProgressListener(mProgressListener, getFile());
mListening = false; mListening = false;
} }
} }

View file

@ -162,7 +162,7 @@
<string name="uploads_view_upload_status_fetching_server_version">Fetching server version…</string> <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_later_waiting_to_upload">Waiting to upload</string>
<string name="uploads_view_group_header" translatable="false">%1$s (%2$d)</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_ticker">Downloading…</string>
<string name="downloader_download_in_progress_content">%1$d%% Downloading %2$s</string> <string name="downloader_download_in_progress_content">%1$d%% Downloading %2$s</string>
<string name="downloader_download_succeeded_ticker">Downloaded</string> <string name="downloader_download_succeeded_ticker">Downloaded</string>