From 79da94ad628656b11a5e918c8d57eed900c27f27 Mon Sep 17 00:00:00 2001 From: Chris Narkiewicz Date: Mon, 4 Mar 2019 21:50:22 +0000 Subject: [PATCH] Move showDetailedTimestampPreference to AppPreferences interface Signed-off-by: Chris Narkiewicz --- .../client/preferences/AppPreferences.java | 3 + .../client/preferences/PreferenceManager.java | 10 ++- .../ui/fragment/FileDetailFragment.java | 73 +++++++++++-------- .../android/ui/fragment/FileFragment.java | 14 ++-- .../ui/preview/FileDownloadFragment.java | 10 +-- .../ui/preview/PreviewImageFragment.java | 24 +++--- .../ui/preview/PreviewMediaFragment.java | 14 ++-- .../ui/preview/PreviewTextFragment.java | 14 ++-- src/main/res/layout/file_details_fragment.xml | 15 ++-- 9 files changed, 96 insertions(+), 81 deletions(-) diff --git a/src/main/java/com/nextcloud/client/preferences/AppPreferences.java b/src/main/java/com/nextcloud/client/preferences/AppPreferences.java index f009a56e89..f247d1b2bc 100644 --- a/src/main/java/com/nextcloud/client/preferences/AppPreferences.java +++ b/src/main/java/com/nextcloud/client/preferences/AppPreferences.java @@ -24,5 +24,8 @@ public interface AppPreferences { boolean instantPictureUploadEnabled(); boolean instantVideoUploadEnabled(); + void setShowDetailedTimestampEnabled(boolean showDetailedTimestamp); + boolean isShowDetailedTimestampEnabled(); + void removeLegacyPreferences(); } diff --git a/src/main/java/com/nextcloud/client/preferences/PreferenceManager.java b/src/main/java/com/nextcloud/client/preferences/PreferenceManager.java index e902838b0c..6601312c7f 100644 --- a/src/main/java/com/nextcloud/client/preferences/PreferenceManager.java +++ b/src/main/java/com/nextcloud/client/preferences/PreferenceManager.java @@ -553,12 +553,14 @@ public final class PreferenceManager implements AppPreferences { saveLongPreference(context, PREF__LOCK_TIMESTAMP, timestamp); } - public static boolean isShowDetailedTimestamp(Context context) { - return getDefaultSharedPreferences(context).getBoolean(AUTO_PREF__SHOW_DETAILED_TIMESTAMP, false); + @Override + public boolean isShowDetailedTimestampEnabled() { + return preferences.getBoolean(AUTO_PREF__SHOW_DETAILED_TIMESTAMP, false); } - public static void setShowDetailedTimestamp(Context context, boolean showDetailedTimestamp) { - saveBooleanPreference(context, AUTO_PREF__SHOW_DETAILED_TIMESTAMP, showDetailedTimestamp); + @Override + public void setShowDetailedTimestampEnabled(boolean showDetailedTimestamp) { + preferences.edit().putBoolean(AUTO_PREF__SHOW_DETAILED_TIMESTAMP, showDetailedTimestamp).apply(); } public static boolean isShowMediaScanNotifications(Context context) { diff --git a/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java b/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java index c27905066a..d5441ff951 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java @@ -23,6 +23,7 @@ package com.owncloud.android.ui.fragment; import android.accounts.Account; +import android.app.Activity; import android.content.Context; import android.graphics.Bitmap; import android.os.Bundle; @@ -40,6 +41,7 @@ import android.widget.ProgressBar; import android.widget.TextView; import com.google.android.material.tabs.TabLayout; +import com.nextcloud.client.preferences.AppPreferences; import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.datamodel.FileDataStorageManager; @@ -103,7 +105,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener @BindView(R.id.size) TextView fileSize; - @BindView(R.id.modified) + @BindView(R.id.last_modification_timestamp) TextView fileModifiedTimestamp; @BindView(R.id.favorite) @@ -139,6 +141,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener private ProgressListener progressListener; private ToolbarActivity activity; private int activeTab; + private AppPreferences preferences; /** * Public factory method to create new FileDetailFragment instances. @@ -209,6 +212,12 @@ public class FileDetailFragment extends FileFragment implements OnClickListener return ((FileDetailTabAdapter) viewPager.getAdapter()).getFileDetailActivitiesFragment(); } + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + preferences = PreferenceManager.fromContext(activity); + } + @Override public void onResume() { super.onResume(); @@ -396,11 +405,11 @@ public class FileDetailFragment extends FileFragment implements OnClickListener } private void prepareOptionsMenu(Menu menu) { - if (mContainerActivity.getStorageManager() != null) { + if (containerActivity.getStorageManager() != null) { FileMenuFilter mf = new FileMenuFilter( getFile(), - mContainerActivity.getStorageManager().getAccount(), - mContainerActivity, + containerActivity.getStorageManager().getAccount(), + containerActivity, getActivity(), false ); @@ -423,11 +432,11 @@ public class FileDetailFragment extends FileFragment implements OnClickListener private boolean optionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_send_file: { - mContainerActivity.getFileOperationsHelper().sendShareFile(getFile(), true); + containerActivity.getFileOperationsHelper().sendShareFile(getFile(), true); return true; } case R.id.action_open_file_with: { - mContainerActivity.getFileOperationsHelper().openFile(getFile()); + containerActivity.getFileOperationsHelper().openFile(getFile()); return true; } case R.id.action_remove_file: { @@ -441,12 +450,12 @@ public class FileDetailFragment extends FileFragment implements OnClickListener return true; } case R.id.action_cancel_sync: { - ((FileDisplayActivity)mContainerActivity).cancelTransference(getFile()); + ((FileDisplayActivity) containerActivity).cancelTransference(getFile()); return true; } case R.id.action_download_file: case R.id.action_sync_file: { - mContainerActivity.getFileOperationsHelper().syncFile(getFile()); + containerActivity.getFileOperationsHelper().syncFile(getFile()); return true; } case R.id.action_encrypted: { @@ -466,14 +475,14 @@ public class FileDetailFragment extends FileFragment implements OnClickListener public void onClick(View v) { switch (v.getId()) { case R.id.cancelBtn: { - ((FileDisplayActivity) mContainerActivity).cancelTransference(getFile()); + ((FileDisplayActivity) containerActivity).cancelTransference(getFile()); break; } case R.id.favorite: { if (getFile().isFavorite()) { - mContainerActivity.getFileOperationsHelper().toggleFavoriteFile(getFile(), false); + containerActivity.getFileOperationsHelper().toggleFavoriteFile(getFile(), false); } else { - mContainerActivity.getFileOperationsHelper().toggleFavoriteFile(getFile(), true); + containerActivity.getFileOperationsHelper().toggleFavoriteFile(getFile(), true); } setFavoriteIconStatus(!getFile().isFavorite()); break; @@ -482,10 +491,10 @@ public class FileDetailFragment extends FileFragment implements OnClickListener onOverflowIconClicked(v); break; } - case R.id.modified: { - boolean flag = !PreferenceManager.isShowDetailedTimestamp(getContext()); - PreferenceManager.setShowDetailedTimestamp(getContext(), flag); - setFileModificationTimestamp(getFile(), flag); + case R.id.last_modification_timestamp: { + boolean showDetailedTimestamp = !preferences.isShowDetailedTimestampEnabled(); + preferences.setShowDetailedTimestampEnabled(showDetailedTimestamp); + setFileModificationTimestamp(getFile(), showDetailedTimestamp); } default: Log_OC.e(TAG, "Incorrect view clicked!"); @@ -525,7 +534,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener */ public void updateFileDetails(boolean transferring, boolean refresh) { if (readyToShow()) { - FileDataStorageManager storageManager = mContainerActivity.getStorageManager(); + FileDataStorageManager storageManager = containerActivity.getStorageManager(); if (storageManager == null) { return; @@ -544,15 +553,15 @@ public class FileDetailFragment extends FileFragment implements OnClickListener } fileSize.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength())); - boolean showDetailedTimestamp = PreferenceManager.isShowDetailedTimestamp(getContext()); + boolean showDetailedTimestamp = preferences.isShowDetailedTimestampEnabled(); setFileModificationTimestamp(file, showDetailedTimestamp); setFilePreview(file); setFavoriteIconStatus(file.isFavorite()); // configure UI for depending upon local state of the file - FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder(); - FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder(); + FileDownloaderBinder downloaderBinder = containerActivity.getFileDownloaderBinder(); + FileUploaderBinder uploaderBinder = containerActivity.getFileUploaderBinder(); if (transferring || (downloaderBinder != null && downloaderBinder.isDownloading(account, file)) || (uploaderBinder != null && uploaderBinder.isUploading(account, file))) { @@ -629,12 +638,12 @@ public class FileDetailFragment extends FileFragment implements OnClickListener // generate new resized image if (ThumbnailsCacheManager.cancelPotentialThumbnailWork(getFile(), activity.getPreviewImageView()) && - mContainerActivity.getStorageManager() != null) { + containerActivity.getStorageManager() != null) { final ThumbnailsCacheManager.ResizedImageGenerationTask task = new ThumbnailsCacheManager.ResizedImageGenerationTask(this, activity.getPreviewImageView(), - mContainerActivity.getStorageManager(), - mContainerActivity.getStorageManager().getAccount()); + containerActivity.getStorageManager(), + containerActivity.getStorageManager().getAccount()); if (resizedImage == null) { resizedImage = thumbnail; @@ -664,8 +673,8 @@ public class FileDetailFragment extends FileFragment implements OnClickListener // show the progress bar for the transfer downloadProgressContainer.setVisibility(View.VISIBLE); progressText.setVisibility(View.VISIBLE); - FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder(); - FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder(); + FileDownloaderBinder downloaderBinder = containerActivity.getFileDownloaderBinder(); + FileUploaderBinder uploaderBinder = containerActivity.getFileUploaderBinder(); //if (getFile().isDownloading()) { if (downloaderBinder != null && downloaderBinder.isDownloading(account, getFile())) { progressText.setText(R.string.downloader_download_in_progress_ticker); @@ -700,12 +709,12 @@ public class FileDetailFragment extends FileFragment implements OnClickListener public void listenForTransferProgress() { if (progressListener != null) { - if (mContainerActivity.getFileDownloaderBinder() != null) { - mContainerActivity.getFileDownloaderBinder(). + if (containerActivity.getFileDownloaderBinder() != null) { + containerActivity.getFileDownloaderBinder(). addDatatransferProgressListener(progressListener, account, getFile()); } - if (mContainerActivity.getFileUploaderBinder() != null) { - mContainerActivity.getFileUploaderBinder(). + if (containerActivity.getFileUploaderBinder() != null) { + containerActivity.getFileUploaderBinder(). addDatatransferProgressListener(progressListener, account, getFile()); } } else { @@ -715,12 +724,12 @@ public class FileDetailFragment extends FileFragment implements OnClickListener private void leaveTransferProgress() { if (progressListener != null) { - if (mContainerActivity.getFileDownloaderBinder() != null) { - mContainerActivity.getFileDownloaderBinder(). + if (containerActivity.getFileDownloaderBinder() != null) { + containerActivity.getFileDownloaderBinder(). removeDatatransferProgressListener(progressListener, account, getFile()); } - if (mContainerActivity.getFileUploaderBinder() != null) { - mContainerActivity.getFileUploaderBinder(). + if (containerActivity.getFileUploaderBinder() != null) { + containerActivity.getFileUploaderBinder(). removeDatatransferProgressListener(progressListener, account, getFile()); } } diff --git a/src/main/java/com/owncloud/android/ui/fragment/FileFragment.java b/src/main/java/com/owncloud/android/ui/fragment/FileFragment.java index 187a13611d..3138282aea 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/FileFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/FileFragment.java @@ -41,9 +41,9 @@ import static com.owncloud.android.ui.activity.FileActivity.EXTRA_FILE; */ public class FileFragment extends Fragment { - private OCFile mFile; + private OCFile file; - protected ContainerActivity mContainerActivity; + protected ContainerActivity containerActivity; /** @@ -53,7 +53,7 @@ public class FileFragment extends Fragment { * tries to reinstantiate a fragment automatically. */ public FileFragment() { - mFile = null; + file = null; } @Override @@ -85,12 +85,12 @@ public class FileFragment extends Fragment { * @return The {@link OCFile} hold */ public OCFile getFile() { - return mFile; + return file; } protected void setFile(OCFile file) { - mFile = file; + this.file = file; } @@ -101,7 +101,7 @@ public class FileFragment extends Fragment { public void onAttach(Activity activity) { super.onAttach(activity); try { - mContainerActivity = (ContainerActivity) activity; + containerActivity = (ContainerActivity) activity; } catch (ClassCastException e) { throw new IllegalArgumentException(activity.toString() + " must implement " + @@ -115,7 +115,7 @@ public class FileFragment extends Fragment { */ @Override public void onDetach() { - mContainerActivity = null; + containerActivity = null; super.onDetach(); } diff --git a/src/main/java/com/owncloud/android/ui/preview/FileDownloadFragment.java b/src/main/java/com/owncloud/android/ui/preview/FileDownloadFragment.java index 4a683392d5..a2f7b4cce3 100644 --- a/src/main/java/com/owncloud/android/ui/preview/FileDownloadFragment.java +++ b/src/main/java/com/owncloud/android/ui/preview/FileDownloadFragment.java @@ -213,7 +213,7 @@ public class FileDownloadFragment extends FileFragment implements OnClickListene public void onClick(View v) { switch (v.getId()) { case R.id.cancelBtn: { - mContainerActivity.getFileOperationsHelper().cancelTransference(getFile()); + containerActivity.getFileOperationsHelper().cancelTransference(getFile()); getActivity().finish(); break; } @@ -260,8 +260,8 @@ public class FileDownloadFragment extends FileFragment implements OnClickListene public void listenForTransferProgress() { - if (mProgressListener != null && !mListening && mContainerActivity.getFileDownloaderBinder() != null) { - mContainerActivity.getFileDownloaderBinder().addDatatransferProgressListener( + if (mProgressListener != null && !mListening && containerActivity.getFileDownloaderBinder() != null) { + containerActivity.getFileDownloaderBinder().addDatatransferProgressListener( mProgressListener, mAccount, getFile() ); mListening = true; @@ -271,8 +271,8 @@ public class FileDownloadFragment extends FileFragment implements OnClickListene public void leaveTransferProgress() { - if (mProgressListener != null && mContainerActivity.getFileDownloaderBinder() != null) { - mContainerActivity.getFileDownloaderBinder().removeDatatransferProgressListener( + if (mProgressListener != null && containerActivity.getFileDownloaderBinder() != null) { + containerActivity.getFileDownloaderBinder().removeDatatransferProgressListener( mProgressListener, mAccount, getFile() ); mListening = false; diff --git a/src/main/java/com/owncloud/android/ui/preview/PreviewImageFragment.java b/src/main/java/com/owncloud/android/ui/preview/PreviewImageFragment.java index 69e3b9f81a..f3e85957b4 100644 --- a/src/main/java/com/owncloud/android/ui/preview/PreviewImageFragment.java +++ b/src/main/java/com/owncloud/android/ui/preview/PreviewImageFragment.java @@ -251,12 +251,12 @@ public class PreviewImageFragment extends FileFragment { // generate new resized image if (ThumbnailsCacheManager.cancelPotentialThumbnailWork(getFile(), mImageView) && - mContainerActivity.getStorageManager() != null) { + containerActivity.getStorageManager() != null) { final ThumbnailsCacheManager.ResizedImageGenerationTask task = new ThumbnailsCacheManager.ResizedImageGenerationTask(this, mImageView, - mContainerActivity.getStorageManager(), - mContainerActivity.getStorageManager().getAccount()); + containerActivity.getStorageManager(), + containerActivity.getStorageManager().getAccount()); if (resizedImage == null) { resizedImage = thumbnail; } @@ -309,14 +309,14 @@ public class PreviewImageFragment extends FileFragment { public void onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); - if (mContainerActivity.getStorageManager() != null && getFile() != null) { + if (containerActivity.getStorageManager() != null && getFile() != null) { // Update the file - setFile(mContainerActivity.getStorageManager().getFileById(getFile().getFileId())); + setFile(containerActivity.getStorageManager().getFileById(getFile().getFileId())); FileMenuFilter mf = new FileMenuFilter( getFile(), - mContainerActivity.getStorageManager().getAccount(), - mContainerActivity, + containerActivity.getStorageManager().getAccount(), + containerActivity, getActivity(), false ); @@ -356,7 +356,7 @@ public class PreviewImageFragment extends FileFragment { ) .show(); } else { - mContainerActivity.getFileOperationsHelper().sendShareFile(getFile()); + containerActivity.getFileOperationsHelper().sendShareFile(getFile()); } return true; @@ -375,11 +375,11 @@ public class PreviewImageFragment extends FileFragment { case R.id.action_download_file: case R.id.action_sync_file: - mContainerActivity.getFileOperationsHelper().syncFile(getFile()); + containerActivity.getFileOperationsHelper().syncFile(getFile()); return true; case R.id.action_set_as_wallpaper: - mContainerActivity.getFileOperationsHelper().setPictureAs(getFile(), getImageView()); + containerActivity.getFileOperationsHelper().setPictureAs(getFile(), getImageView()); return true; default: @@ -389,7 +389,7 @@ public class PreviewImageFragment extends FileFragment { private void seeDetails() { - mContainerActivity.showDetails(getFile()); + containerActivity.showDetails(getFile()); } @SuppressFBWarnings("Dm") @@ -409,7 +409,7 @@ public class PreviewImageFragment extends FileFragment { * Opens the previewed image with an external application. */ private void openFile() { - mContainerActivity.getFileOperationsHelper().openFile(getFile()); + containerActivity.getFileOperationsHelper().openFile(getFile()); finish(); } diff --git a/src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.java b/src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.java index d761a8709d..5dccc190a6 100644 --- a/src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.java +++ b/src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.java @@ -372,11 +372,11 @@ public class PreviewMediaFragment extends FileFragment implements public void onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); - if (mContainerActivity.getStorageManager() != null) { + if (containerActivity.getStorageManager() != null) { FileMenuFilter mf = new FileMenuFilter( getFile(), - mContainerActivity.getStorageManager().getAccount(), - mContainerActivity, + containerActivity.getStorageManager().getAccount(), + containerActivity, getActivity(), false ); @@ -462,7 +462,7 @@ public class PreviewMediaFragment extends FileFragment implements return true; } case R.id.action_sync_file: { - mContainerActivity.getFileOperationsHelper().syncFile(getFile()); + containerActivity.getFileOperationsHelper().syncFile(getFile()); return true; } default: @@ -482,12 +482,12 @@ public class PreviewMediaFragment extends FileFragment implements private void seeDetails() { stopPreview(false); - mContainerActivity.showDetails(getFile()); + containerActivity.showDetails(getFile()); } private void sendShareFile() { stopPreview(false); - mContainerActivity.getFileOperationsHelper().sendShareFile(getFile()); + containerActivity.getFileOperationsHelper().sendShareFile(getFile()); } private void prepareVideo() { @@ -793,7 +793,7 @@ public class PreviewMediaFragment extends FileFragment implements */ private void openFile() { stopPreview(true); - mContainerActivity.getFileOperationsHelper().openFile(getFile()); + containerActivity.getFileOperationsHelper().openFile(getFile()); finish(); } diff --git a/src/main/java/com/owncloud/android/ui/preview/PreviewTextFragment.java b/src/main/java/com/owncloud/android/ui/preview/PreviewTextFragment.java index 1a21c3e2ee..76edc66a63 100644 --- a/src/main/java/com/owncloud/android/ui/preview/PreviewTextFragment.java +++ b/src/main/java/com/owncloud/android/ui/preview/PreviewTextFragment.java @@ -364,11 +364,11 @@ public class PreviewTextFragment extends FileFragment implements SearchView.OnQu public void onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); - if (mContainerActivity.getStorageManager() != null) { + if (containerActivity.getStorageManager() != null) { FileMenuFilter mf = new FileMenuFilter( getFile(), - mContainerActivity.getStorageManager().getAccount(), - mContainerActivity, + containerActivity.getStorageManager().getAccount(), + containerActivity, getActivity(), false ); @@ -410,7 +410,7 @@ public class PreviewTextFragment extends FileFragment implements SearchView.OnQu if(getFile().isSharedWithMe() && !getFile().canReshare()){ DisplayUtils.showSnackMessage(getView(), R.string.resharing_is_not_allowed); } else { - mContainerActivity.getFileOperationsHelper().sendShareFile(getFile()); + containerActivity.getFileOperationsHelper().sendShareFile(getFile()); } return true; } @@ -428,7 +428,7 @@ public class PreviewTextFragment extends FileFragment implements SearchView.OnQu return true; } case R.id.action_sync_file: { - mContainerActivity.getFileOperationsHelper().syncFile(getFile()); + containerActivity.getFileOperationsHelper().syncFile(getFile()); return true; } @@ -447,7 +447,7 @@ public class PreviewTextFragment extends FileFragment implements SearchView.OnQu } private void seeDetails() { - mContainerActivity.showDetails(getFile()); + containerActivity.showDetails(getFile()); } @Override @@ -463,7 +463,7 @@ public class PreviewTextFragment extends FileFragment implements SearchView.OnQu * Opens the previewed file with an external application. */ private void openFile() { - mContainerActivity.getFileOperationsHelper().openFile(getFile()); + containerActivity.getFileOperationsHelper().openFile(getFile()); finish(); } diff --git a/src/main/res/layout/file_details_fragment.xml b/src/main/res/layout/file_details_fragment.xml index c9dc1848d7..0d21dc8a7d 100644 --- a/src/main/res/layout/file_details_fragment.xml +++ b/src/main/res/layout/file_details_fragment.xml @@ -20,6 +20,7 @@ --> + android:textStyle="bold" + tools:text="@string/placeholder_filename"/> + android:textSize="16sp" + tools:text="@string/placeholder_fileSize" /> + android:textSize="16sp" + tools:text="@string/placeholder_media_time" />