mirror of
https://github.com/nextcloud/android.git
synced 2024-12-20 16:02:01 +03:00
Combine Ifs
This commit is contained in:
parent
9cf274e1ca
commit
90ce5fcea1
1 changed files with 49 additions and 55 deletions
|
@ -1,21 +1,20 @@
|
|||
/**
|
||||
* ownCloud Android client application
|
||||
*
|
||||
* @author David A. Velasco
|
||||
* Copyright (C) 2015 ownCloud Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ownCloud Android client application
|
||||
*
|
||||
* @author David A. Velasco
|
||||
* Copyright (C) 2015 ownCloud Inc.
|
||||
* <p>
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2,
|
||||
* as published by the Free Software Foundation.
|
||||
* <p>
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* <p>
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui.preview;
|
||||
|
||||
|
@ -113,7 +112,7 @@ public class PreviewImageFragment extends FileFragment {
|
|||
* {@link FragmentStatePagerAdapter}
|
||||
* ; TODO better solution
|
||||
*/
|
||||
public static PreviewImageFragment newInstance(OCFile imageFile, boolean ignoreFirstSavedState){
|
||||
public static PreviewImageFragment newInstance(OCFile imageFile, boolean ignoreFirstSavedState) {
|
||||
PreviewImageFragment frag = new PreviewImageFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putParcelable(ARG_FILE, imageFile);
|
||||
|
@ -123,7 +122,6 @@ public class PreviewImageFragment extends FileFragment {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates an empty fragment for image previews.
|
||||
*
|
||||
|
@ -145,9 +143,9 @@ public class PreviewImageFragment extends FileFragment {
|
|||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Bundle args = getArguments();
|
||||
setFile((OCFile)args.getParcelable(ARG_FILE));
|
||||
// TODO better in super, but needs to check ALL the class extending FileFragment;
|
||||
// not right now
|
||||
setFile((OCFile) args.getParcelable(ARG_FILE));
|
||||
// TODO better in super, but needs to check ALL the class extending FileFragment;
|
||||
// not right now
|
||||
|
||||
mIgnoreFirstSavedState = args.getBoolean(ARG_IGNORE_FIRST);
|
||||
setHasOptionsMenu(true);
|
||||
|
@ -181,10 +179,10 @@ public class PreviewImageFragment extends FileFragment {
|
|||
}
|
||||
});
|
||||
|
||||
mMultiView = (RelativeLayout) view.findViewById(R.id.multi_view);
|
||||
|
||||
setupMultiView(view);
|
||||
setMultiListLoadingMessage();
|
||||
mMessageView = (TextView) view.findViewById(R.id.message);
|
||||
mMessageView.setVisibility(View.GONE);
|
||||
mProgressWheel = (ProgressBar) view.findViewById(R.id.progressWheel);
|
||||
mProgressWheel.setVisibility(View.VISIBLE);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
@ -273,10 +271,10 @@ public class PreviewImageFragment extends FileFragment {
|
|||
setFile(mContainerActivity.getStorageManager().getFileById(getFile().getFileId()));
|
||||
|
||||
FileMenuFilter mf = new FileMenuFilter(
|
||||
getFile(),
|
||||
mContainerActivity.getStorageManager().getAccount(),
|
||||
mContainerActivity,
|
||||
getActivity()
|
||||
getFile(),
|
||||
mContainerActivity.getStorageManager().getAccount(),
|
||||
mContainerActivity,
|
||||
getActivity()
|
||||
);
|
||||
mf.filter(menu);
|
||||
}
|
||||
|
@ -345,11 +343,11 @@ public class PreviewImageFragment extends FileFragment {
|
|||
mContainerActivity.getFileOperationsHelper().syncFile(getFile());
|
||||
return true;
|
||||
}
|
||||
case R.id.action_favorite_file:{
|
||||
case R.id.action_favorite_file: {
|
||||
mContainerActivity.getFileOperationsHelper().toggleFavorite(getFile(), true);
|
||||
return true;
|
||||
}
|
||||
case R.id.action_unfavorite_file:{
|
||||
case R.id.action_unfavorite_file: {
|
||||
mContainerActivity.getFileOperationsHelper().toggleFavorite(getFile(), false);
|
||||
return true;
|
||||
}
|
||||
|
@ -380,9 +378,9 @@ public class PreviewImageFragment extends FileFragment {
|
|||
if (mBitmap != null) {
|
||||
mBitmap.recycle();
|
||||
System.gc();
|
||||
// putting this in onStop() is just the same; the fragment is always destroyed by
|
||||
// {@link FragmentStatePagerAdapter} when the fragment in swiped further than the
|
||||
// valid offscreen distance, and onStop() is never called before than that
|
||||
// putting this in onStop() is just the same; the fragment is always destroyed by
|
||||
// {@link FragmentStatePagerAdapter} when the fragment in swiped further than the
|
||||
// valid offscreen distance, and onStop() is never called before than that
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
|
@ -559,7 +557,7 @@ public class PreviewImageFragment extends FileFragment {
|
|||
|
||||
if (result.ocFile.getMimetype().equalsIgnoreCase("image/gif")) {
|
||||
imageView.setGIFImageFromStoragePath(result.ocFile.getStoragePath());
|
||||
} else if (!result.ocFile.getMimetype().equalsIgnoreCase("image/png")){
|
||||
} else if (!result.ocFile.getMimetype().equalsIgnoreCase("image/png")) {
|
||||
imageView.setImageBitmap(bitmap);
|
||||
}
|
||||
|
||||
|
@ -619,33 +617,29 @@ public class PreviewImageFragment extends FileFragment {
|
|||
}
|
||||
|
||||
private void toggleImageBackground() {
|
||||
if (getFile() != null && getFile().getMimetype().equalsIgnoreCase("image/png")) {
|
||||
if (getActivity() != null && (getActivity() instanceof PreviewImageActivity)) {
|
||||
PreviewImageActivity previewImageActivity = (PreviewImageActivity) getActivity();
|
||||
if (getResources() != null) {
|
||||
LayerDrawable layerDrawable = (LayerDrawable)mImageView.getDrawable();
|
||||
Drawable layerOne;
|
||||
if (getFile() != null && getFile().getMimetype().equalsIgnoreCase("image/png") && getActivity() != null
|
||||
&& getActivity() instanceof PreviewImageActivity && getResources() != null) {
|
||||
PreviewImageActivity previewImageActivity = (PreviewImageActivity) getActivity();
|
||||
LayerDrawable layerDrawable = (LayerDrawable) mImageView.getDrawable();
|
||||
Drawable layerOne;
|
||||
|
||||
if (previewImageActivity.getSystemUIVisible()) {
|
||||
layerOne = getResources().getDrawable(R.color.white);
|
||||
} else {
|
||||
layerOne = getResources().getDrawable(R.drawable.backrepeat);
|
||||
}
|
||||
|
||||
layerDrawable.setDrawableByLayerId(layerDrawable.getId(0), layerOne);
|
||||
|
||||
mImageView.setImageDrawable(layerDrawable);
|
||||
}
|
||||
if (previewImageActivity.getSystemUIVisible()) {
|
||||
layerOne = getResources().getDrawable(R.color.white);
|
||||
} else {
|
||||
layerOne = getResources().getDrawable(R.drawable.backrepeat);
|
||||
}
|
||||
|
||||
layerDrawable.setDrawableByLayerId(layerDrawable.getId(0), layerOne);
|
||||
|
||||
mImageView.setImageDrawable(layerDrawable);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static float convertDpToPixel(float dp, Context context){
|
||||
private static float convertDpToPixel(float dp, Context context) {
|
||||
Resources resources = context.getResources();
|
||||
DisplayMetrics metrics = resources.getDisplayMetrics();
|
||||
float px = dp * ((float)metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
|
||||
float px = dp * ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
|
||||
return px;
|
||||
}
|
||||
|
||||
|
@ -658,7 +652,7 @@ public class PreviewImageFragment extends FileFragment {
|
|||
private Bitmap bitmap;
|
||||
private OCFile ocFile;
|
||||
|
||||
public LoadImage(Bitmap bitmap, OCFile ocFile){
|
||||
public LoadImage(Bitmap bitmap, OCFile ocFile) {
|
||||
this.bitmap = bitmap;
|
||||
this.ocFile = ocFile;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue