Combine Ifs

This commit is contained in:
Mario Danic 2017-01-24 01:48:25 +01:00 committed by AndyScherzinger
parent 9cf274e1ca
commit 90ce5fcea1
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B

View file

@ -3,19 +3,18 @@
* *
* @author David A. Velasco * @author David A. Velasco
* Copyright (C) 2015 ownCloud Inc. * Copyright (C) 2015 ownCloud Inc.
* * <p>
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2, * it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation. * as published by the Free Software Foundation.
* * <p>
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* * <p>
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/ */
package com.owncloud.android.ui.preview; package com.owncloud.android.ui.preview;
@ -113,7 +112,7 @@ public class PreviewImageFragment extends FileFragment {
* {@link FragmentStatePagerAdapter} * {@link FragmentStatePagerAdapter}
* ; TODO better solution * ; TODO better solution
*/ */
public static PreviewImageFragment newInstance(OCFile imageFile, boolean ignoreFirstSavedState){ public static PreviewImageFragment newInstance(OCFile imageFile, boolean ignoreFirstSavedState) {
PreviewImageFragment frag = new PreviewImageFragment(); PreviewImageFragment frag = new PreviewImageFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putParcelable(ARG_FILE, imageFile); args.putParcelable(ARG_FILE, imageFile);
@ -123,7 +122,6 @@ public class PreviewImageFragment extends FileFragment {
} }
/** /**
* Creates an empty fragment for image previews. * Creates an empty fragment for image previews.
* *
@ -145,7 +143,7 @@ public class PreviewImageFragment extends FileFragment {
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Bundle args = getArguments(); Bundle args = getArguments();
setFile((OCFile)args.getParcelable(ARG_FILE)); setFile((OCFile) args.getParcelable(ARG_FILE));
// TODO better in super, but needs to check ALL the class extending FileFragment; // TODO better in super, but needs to check ALL the class extending FileFragment;
// not right now // not right now
@ -181,10 +179,10 @@ public class PreviewImageFragment extends FileFragment {
} }
}); });
mMultiView = (RelativeLayout) view.findViewById(R.id.multi_view); mMessageView = (TextView) view.findViewById(R.id.message);
mMessageView.setVisibility(View.GONE);
setupMultiView(view); mProgressWheel = (ProgressBar) view.findViewById(R.id.progressWheel);
setMultiListLoadingMessage(); mProgressWheel.setVisibility(View.VISIBLE);
return view; return view;
} }
@ -345,11 +343,11 @@ public class PreviewImageFragment extends FileFragment {
mContainerActivity.getFileOperationsHelper().syncFile(getFile()); mContainerActivity.getFileOperationsHelper().syncFile(getFile());
return true; return true;
} }
case R.id.action_favorite_file:{ case R.id.action_favorite_file: {
mContainerActivity.getFileOperationsHelper().toggleFavorite(getFile(), true); mContainerActivity.getFileOperationsHelper().toggleFavorite(getFile(), true);
return true; return true;
} }
case R.id.action_unfavorite_file:{ case R.id.action_unfavorite_file: {
mContainerActivity.getFileOperationsHelper().toggleFavorite(getFile(), false); mContainerActivity.getFileOperationsHelper().toggleFavorite(getFile(), false);
return true; return true;
} }
@ -559,7 +557,7 @@ public class PreviewImageFragment extends FileFragment {
if (result.ocFile.getMimetype().equalsIgnoreCase("image/gif")) { if (result.ocFile.getMimetype().equalsIgnoreCase("image/gif")) {
imageView.setGIFImageFromStoragePath(result.ocFile.getStoragePath()); imageView.setGIFImageFromStoragePath(result.ocFile.getStoragePath());
} else if (!result.ocFile.getMimetype().equalsIgnoreCase("image/png")){ } else if (!result.ocFile.getMimetype().equalsIgnoreCase("image/png")) {
imageView.setImageBitmap(bitmap); imageView.setImageBitmap(bitmap);
} }
@ -619,11 +617,10 @@ public class PreviewImageFragment extends FileFragment {
} }
private void toggleImageBackground() { private void toggleImageBackground() {
if (getFile() != null && getFile().getMimetype().equalsIgnoreCase("image/png")) { if (getFile() != null && getFile().getMimetype().equalsIgnoreCase("image/png") && getActivity() != null
if (getActivity() != null && (getActivity() instanceof PreviewImageActivity)) { && getActivity() instanceof PreviewImageActivity && getResources() != null) {
PreviewImageActivity previewImageActivity = (PreviewImageActivity) getActivity(); PreviewImageActivity previewImageActivity = (PreviewImageActivity) getActivity();
if (getResources() != null) { LayerDrawable layerDrawable = (LayerDrawable) mImageView.getDrawable();
LayerDrawable layerDrawable = (LayerDrawable)mImageView.getDrawable();
Drawable layerOne; Drawable layerOne;
if (previewImageActivity.getSystemUIVisible()) { if (previewImageActivity.getSystemUIVisible()) {
@ -637,15 +634,12 @@ public class PreviewImageFragment extends FileFragment {
mImageView.setImageDrawable(layerDrawable); mImageView.setImageDrawable(layerDrawable);
} }
} }
}
}
private static float convertDpToPixel(float dp, Context context) {
private static float convertDpToPixel(float dp, Context context){
Resources resources = context.getResources(); Resources resources = context.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics(); DisplayMetrics metrics = resources.getDisplayMetrics();
float px = dp * ((float)metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT); float px = dp * ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
return px; return px;
} }
@ -658,7 +652,7 @@ public class PreviewImageFragment extends FileFragment {
private Bitmap bitmap; private Bitmap bitmap;
private OCFile ocFile; private OCFile ocFile;
public LoadImage(Bitmap bitmap, OCFile ocFile){ public LoadImage(Bitmap bitmap, OCFile ocFile) {
this.bitmap = bitmap; this.bitmap = bitmap;
this.ocFile = ocFile; this.ocFile = ocFile;
} }