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

@ -1,21 +1,20 @@
/** /**
* ownCloud Android client application * 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/>.
* *
* @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; 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,9 +143,9 @@ 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
mIgnoreFirstSavedState = args.getBoolean(ARG_IGNORE_FIRST); mIgnoreFirstSavedState = args.getBoolean(ARG_IGNORE_FIRST);
setHasOptionsMenu(true); setHasOptionsMenu(true);
@ -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;
} }
@ -273,10 +271,10 @@ public class PreviewImageFragment extends FileFragment {
setFile(mContainerActivity.getStorageManager().getFileById(getFile().getFileId())); setFile(mContainerActivity.getStorageManager().getFileById(getFile().getFileId()));
FileMenuFilter mf = new FileMenuFilter( FileMenuFilter mf = new FileMenuFilter(
getFile(), getFile(),
mContainerActivity.getStorageManager().getAccount(), mContainerActivity.getStorageManager().getAccount(),
mContainerActivity, mContainerActivity,
getActivity() getActivity()
); );
mf.filter(menu); mf.filter(menu);
} }
@ -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;
} }
@ -380,9 +378,9 @@ public class PreviewImageFragment extends FileFragment {
if (mBitmap != null) { if (mBitmap != null) {
mBitmap.recycle(); mBitmap.recycle();
System.gc(); System.gc();
// putting this in onStop() is just the same; the fragment is always destroyed by // putting this in onStop() is just the same; the fragment is always destroyed by
// {@link FragmentStatePagerAdapter} when the fragment in swiped further than the // {@link FragmentStatePagerAdapter} when the fragment in swiped further than the
// valid offscreen distance, and onStop() is never called before than that // valid offscreen distance, and onStop() is never called before than that
} }
super.onDestroy(); super.onDestroy();
} }
@ -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,33 +617,29 @@ 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()) {
layerOne = getResources().getDrawable(R.color.white); layerOne = getResources().getDrawable(R.color.white);
} else { } else {
layerOne = getResources().getDrawable(R.drawable.backrepeat); layerOne = getResources().getDrawable(R.drawable.backrepeat);
}
layerDrawable.setDrawableByLayerId(layerDrawable.getId(0), layerOne);
mImageView.setImageDrawable(layerDrawable);
}
} }
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(); 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;
} }