Merge pull request #3698 from nextcloud/ezaquarii/refactor-show-detailed-timestamp-preference

Move showDetailedTimestampPreference to AppPreferences interface
This commit is contained in:
Andy Scherzinger 2019-03-05 10:25:13 +01:00 committed by GitHub
commit b784d84121
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 96 additions and 81 deletions

View file

@ -24,5 +24,8 @@ public interface AppPreferences {
boolean instantPictureUploadEnabled();
boolean instantVideoUploadEnabled();
void setShowDetailedTimestampEnabled(boolean showDetailedTimestamp);
boolean isShowDetailedTimestampEnabled();
void removeLegacyPreferences();
}

View file

@ -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) {

View file

@ -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());
}
}

View file

@ -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();
}

View file

@ -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;

View file

@ -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();
}

View file

@ -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();
}

View file

@ -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();
}

View file

@ -20,6 +20,7 @@
-->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -56,10 +57,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="middle"
android:text="@string/placeholder_filename"
android:textColor="@color/black"
android:textSize="20sp"
android:textStyle="bold" />
android:textStyle="bold"
tools:text="@string/placeholder_filename"/>
<LinearLayout
android:id="@+id/filedetails"
@ -83,8 +84,8 @@
android:id="@+id/size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/placeholder_fileSize"
android:textSize="16sp" />
android:textSize="16sp"
tools:text="@string/placeholder_fileSize" />
<TextView
android:id="@+id/file_separator"
@ -100,12 +101,12 @@
android:textSize="@dimen/two_line_secondary_text_size" />
<TextView
android:id="@+id/modified"
android:id="@+id/last_modification_timestamp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="end"
android:text="@string/placeholder_media_time"
android:textSize="16sp" />
android:textSize="16sp"
tools:text="@string/placeholder_media_time" />
<ImageView
android:layout_width="wrap_content"