Merge pull request #1977 from nextcloud/hardenPreviewAdapter

Hardening preview adapter for null files
This commit is contained in:
Andy Scherzinger 2018-01-18 21:45:22 +01:00 committed by GitHub
commit c6a4bc3b24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 106 additions and 15 deletions

View file

@ -241,7 +241,7 @@ dependencies {
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.0.1'
// UIAutomator - for cross-app UI tests, and to grant screen is turned on in Espresso tests
androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.3'
// fix conflict in dependencies; see http://g.co/androidstudio/app-test-app-conflict for details
//androidTestImplementation "com.android.support:support-annotations:${supportLibraryVersion}"
implementation 'org.jetbrains:annotations:15.0'

View file

@ -36,7 +36,6 @@ import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;

View file

@ -352,18 +352,20 @@ public class PreviewImageActivity extends FileActivity implements
} else {
OCFile currentFile = mPreviewImagePagerAdapter.getFileAt(position);
if (getSupportActionBar() != null && currentFile != null) {
getSupportActionBar().setTitle(currentFile.getFileName());
}
setDrawerIndicatorEnabled(false);
if (currentFile != null) {
if (getSupportActionBar() != null) {
getSupportActionBar().setTitle(currentFile.getFileName());
}
setDrawerIndicatorEnabled(false);
if (currentFile.isEncrypted() && !currentFile.isDown() &&
!mPreviewImagePagerAdapter.pendingErrorAt(position)) {
requestForDownload(currentFile);
}
if (currentFile.isEncrypted() && !currentFile.isDown() &&
!mPreviewImagePagerAdapter.pendingErrorAt(position)) {
requestForDownload(currentFile);
}
// Call to reset image zoom to initial state
((PreviewImagePagerAdapter) mViewPager.getAdapter()).resetZoom();
// Call to reset image zoom to initial state
((PreviewImagePagerAdapter) mViewPager.getAdapter()).resetZoom();
}
}
}

View file

@ -0,0 +1,34 @@
package com.owncloud.android.ui.preview;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.owncloud.android.R;
import com.owncloud.android.ui.fragment.FileFragment;
import static com.owncloud.android.ui.activity.FileActivity.EXTRA_FILE;
/**
* A fragment showing an error message
*/
public class PreviewImageErrorFragment extends FileFragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.preview_image_error_fragment, container, false);
}
public static FileFragment newInstance() {
FileFragment fileFragment = new PreviewImageErrorFragment();
Bundle bundle = new Bundle();
bundle.putParcelable(EXTRA_FILE, null);
fileFragment.setArguments(bundle);
return fileFragment;
}
}

View file

@ -140,10 +140,13 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter {
public Fragment getItem(int i) {
OCFile file = mImageFiles.get(i);
OCFile file = getFileAt(i);
Fragment fragment;
if (file.isDown()) {
if (file == null) {
fragment = PreviewImageErrorFragment.newInstance();
} else if (file.isDown()) {
fragment = PreviewImageFragment.newInstance(file, mObsoletePositions.contains(i), false);
} else {
if (mDownloadErrors.contains(i)) {
@ -174,7 +177,13 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter {
@Override
public CharSequence getPageTitle(int position) {
return mImageFiles.get(position).getFileName();
OCFile file = getFileAt(position);
if (file != null) {
return file.getFileName();
} else {
return "";
}
}

View file

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?><!--
Nextcloud Android client application
Copyright (C) 2018 Tobias Kaminsky
Copyright (C) 2018 Nextcloud
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
License as published by the Free Software Foundation; either
version 3 of the License, or any later version.
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 AFFERO GENERAL PUBLIC LICENSE for more details.
You should have received a copy of the GNU Affero General Public
License along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="@dimen/standard_margin"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical"
android:paddingBottom="@dimen/standard_double_margin"
android:animateLayoutChanges="true">
<ImageView
android:id="@+id/preview_error_image"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_gravity="center"
android:contentDescription="@string/file_icon"
android:src="@drawable/file_image" />
<TextView
android:id="@+id/preview_error_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/preview_sorry"
android:textSize="26sp" />
</LinearLayout>