mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 13:45:35 +03:00
Merge pull request #7333 from nextcloud/shimmer
Add shimmer to preview image fragment
This commit is contained in:
commit
183efcbe89
7 changed files with 70 additions and 29 deletions
|
@ -42,7 +42,9 @@ import android.os.AsyncTask;
|
|||
import android.provider.MediaStore;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Display;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.nextcloud.client.network.ConnectivityService;
|
||||
|
@ -253,21 +255,27 @@ public final class ThumbnailsCacheManager {
|
|||
private FileDataStorageManager storageManager;
|
||||
private Account account;
|
||||
private WeakReference<ImageView> imageViewReference;
|
||||
private WeakReference<FrameLayout> frameLayoutReference;
|
||||
private OCFile file;
|
||||
private ConnectivityService connectivityService;
|
||||
private int backgroundColor;
|
||||
|
||||
|
||||
public ResizedImageGenerationTask(FileFragment fileFragment,
|
||||
ImageView imageView,
|
||||
FrameLayout emptyListProgress,
|
||||
FileDataStorageManager storageManager,
|
||||
ConnectivityService connectivityService,
|
||||
Account account)
|
||||
Account account,
|
||||
int backgroundColor)
|
||||
throws IllegalArgumentException {
|
||||
this.fileFragment = fileFragment;
|
||||
imageViewReference = new WeakReference<>(imageView);
|
||||
frameLayoutReference = new WeakReference<>(emptyListProgress);
|
||||
this.storageManager = storageManager;
|
||||
this.connectivityService = connectivityService;
|
||||
this.account = account;
|
||||
this.backgroundColor = backgroundColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -280,7 +288,7 @@ public final class ThumbnailsCacheManager {
|
|||
if (account != null) {
|
||||
OwnCloudAccount ocAccount = new OwnCloudAccount(account, MainApp.getAppContext());
|
||||
mClient = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount,
|
||||
MainApp.getAppContext());
|
||||
MainApp.getAppContext());
|
||||
}
|
||||
|
||||
thumbnail = doResizedImageInBackground();
|
||||
|
@ -375,6 +383,7 @@ public final class ThumbnailsCacheManager {
|
|||
protected void onPostExecute(Bitmap bitmap) {
|
||||
if (imageViewReference != null) {
|
||||
final ImageView imageView = imageViewReference.get();
|
||||
final FrameLayout frameLayout = frameLayoutReference.get();
|
||||
|
||||
if (bitmap != null) {
|
||||
final ResizedImageGenerationTask bitmapWorkerTask = getResizedImageGenerationWorkerTask(imageView);
|
||||
|
@ -383,7 +392,13 @@ public final class ThumbnailsCacheManager {
|
|||
String tagId = String.valueOf(file.getFileId());
|
||||
|
||||
if (String.valueOf(imageView.getTag()).equals(tagId)) {
|
||||
imageView.setVisibility(View.VISIBLE);
|
||||
imageView.setImageBitmap(bitmap);
|
||||
imageView.setBackgroundColor(backgroundColor);
|
||||
|
||||
if (frameLayout != null) {
|
||||
frameLayout.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -270,4 +270,8 @@ public abstract class ToolbarActivity extends BaseActivity {
|
|||
public ImageView getPreviewImageView() {
|
||||
return mPreviewImage;
|
||||
}
|
||||
|
||||
public FrameLayout getPreviewImageContainer() {
|
||||
return mPreviewImageContainer;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -128,7 +128,11 @@ public class DiskLruImageCache {
|
|||
options.inMutable = false;
|
||||
options.inJustDecodeBounds = true;
|
||||
|
||||
bitmap = BitmapFactory.decodeStream(buffIn, null, options);
|
||||
BitmapFactory.decodeStream(buffIn, null, options);
|
||||
|
||||
snapshot = mDiskCache.get(validKey);
|
||||
inputStream = snapshot.getInputStream(0);
|
||||
buffIn = new BufferedInputStream(inputStream, IO_BUFFER_SIZE);
|
||||
|
||||
// Calculate inSampleSize
|
||||
options.inSampleSize = BitmapUtils.calculateSampleFactor(options, width, height);
|
||||
|
|
|
@ -579,11 +579,14 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
|
|||
if (ThumbnailsCacheManager.cancelPotentialThumbnailWork(getFile(), toolbarActivity.getPreviewImageView()) &&
|
||||
containerActivity.getStorageManager() != null) {
|
||||
final ThumbnailsCacheManager.ResizedImageGenerationTask task =
|
||||
new ThumbnailsCacheManager.ResizedImageGenerationTask(this,
|
||||
toolbarActivity.getPreviewImageView(),
|
||||
containerActivity.getStorageManager(),
|
||||
connectivityService,
|
||||
containerActivity.getStorageManager().getAccount());
|
||||
new ThumbnailsCacheManager.ResizedImageGenerationTask(this,
|
||||
toolbarActivity.getPreviewImageView(),
|
||||
toolbarActivity.getPreviewImageContainer(),
|
||||
containerActivity.getStorageManager(),
|
||||
connectivityService,
|
||||
containerActivity.getStorageManager().getAccount(),
|
||||
getResources().getColor(R.color.background_color_inverse)
|
||||
);
|
||||
|
||||
if (resizedImage == null) {
|
||||
resizedImage = thumbnail;
|
||||
|
|
|
@ -89,6 +89,8 @@ import androidx.fragment.app.FragmentStatePagerAdapter;
|
|||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import pl.droidsonroids.gif.GifDrawable;
|
||||
|
||||
import static com.owncloud.android.datamodel.ThumbnailsCacheManager.PREFIX_THUMBNAIL;
|
||||
|
||||
|
||||
/**
|
||||
* This fragment shows a preview of a downloaded image.
|
||||
|
@ -237,34 +239,44 @@ public class PreviewImageFragment extends FileFragment implements Injectable {
|
|||
int width = screenSize.x;
|
||||
int height = screenSize.y;
|
||||
|
||||
// show thumbnail while loading image
|
||||
binding.image.setVisibility(View.GONE);
|
||||
binding.emptyListProgress.setVisibility(View.VISIBLE);
|
||||
|
||||
Bitmap thumbnail = getThumbnailBitmap(getFile());
|
||||
if (thumbnail != null) {
|
||||
binding.shimmer.setVisibility(View.VISIBLE);
|
||||
binding.shimmerThumbnail.setImageBitmap(thumbnail);
|
||||
binding.image.setVisibility(View.GONE);
|
||||
bitmap = thumbnail;
|
||||
} else {
|
||||
thumbnail = ThumbnailsCacheManager.mDefaultImg;
|
||||
}
|
||||
|
||||
if (showResizedImage) {
|
||||
Bitmap resizedImage = getResizedBitmap(getFile(), width, height);
|
||||
|
||||
if (resizedImage != null && !getFile().isUpdateThumbnailNeeded()) {
|
||||
binding.image.setImageBitmap(resizedImage);
|
||||
binding.image.setVisibility(View.VISIBLE);
|
||||
binding.emptyListView.setVisibility(View.GONE);
|
||||
binding.emptyListProgress.setVisibility(View.GONE);
|
||||
binding.image.setBackgroundColor(getResources().getColor(R.color.background_color_inverse));
|
||||
|
||||
bitmap = resizedImage;
|
||||
} else {
|
||||
// show thumbnail while loading resized image
|
||||
Bitmap thumbnail = getResizedBitmap(getFile(), width, height);
|
||||
|
||||
if (thumbnail != null) {
|
||||
binding.image.setImageBitmap(thumbnail);
|
||||
binding.image.setVisibility(View.VISIBLE);
|
||||
bitmap = thumbnail;
|
||||
} else {
|
||||
thumbnail = ThumbnailsCacheManager.mDefaultImg;
|
||||
}
|
||||
|
||||
// generate new resized image
|
||||
if (ThumbnailsCacheManager.cancelPotentialThumbnailWork(getFile(), binding.image) &&
|
||||
containerActivity.getStorageManager() != null) {
|
||||
final ThumbnailsCacheManager.ResizedImageGenerationTask task =
|
||||
new ThumbnailsCacheManager.ResizedImageGenerationTask(this,
|
||||
binding.image,
|
||||
binding.emptyListProgress,
|
||||
containerActivity.getStorageManager(),
|
||||
connectivityService,
|
||||
containerActivity.getStorageManager().getAccount());
|
||||
containerActivity.getStorageManager().getAccount(),
|
||||
getResources().getColor(R.color.background_color_inverse)
|
||||
);
|
||||
if (resizedImage == null) {
|
||||
resizedImage = thumbnail;
|
||||
}
|
||||
|
@ -278,11 +290,6 @@ public class PreviewImageFragment extends FileFragment implements Injectable {
|
|||
task.execute(getFile());
|
||||
}
|
||||
}
|
||||
binding.emptyListView.setVisibility(View.GONE);
|
||||
binding.emptyListProgress.setVisibility(View.GONE);
|
||||
binding.image.setBackgroundColor(getResources().getColor(R.color.background_color_inverse));
|
||||
binding.image.setVisibility(View.VISIBLE);
|
||||
|
||||
} else {
|
||||
loadBitmapTask = new LoadBitmapTask(binding.image, binding.emptyListView, binding.emptyListProgress);
|
||||
binding.image.setVisibility(View.GONE);
|
||||
|
@ -316,6 +323,11 @@ public class PreviewImageFragment extends FileFragment implements Injectable {
|
|||
return cachedImage;
|
||||
}
|
||||
|
||||
private @Nullable
|
||||
Bitmap getThumbnailBitmap(OCFile file) {
|
||||
return ThumbnailsCacheManager.getBitmapFromDiskCache(PREFIX_THUMBNAIL + file.getRemoteId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
Log_OC.d(TAG, "onStop starts");
|
||||
|
|
|
@ -89,19 +89,20 @@
|
|||
android:layout_height="match_parent">
|
||||
|
||||
<com.elyeproj.loaderviewlibrary.LoaderImageView
|
||||
android:layout_width="@dimen/empty_list_icon_layout_width"
|
||||
android:layout_height="@dimen/empty_list_icon_layout_width"
|
||||
android:id="@+id/shimmer"
|
||||
android:layout_width="96dp"
|
||||
android:layout_height="96dp"
|
||||
android:layout_gravity="center"
|
||||
android:contentDescription="@null"
|
||||
app:corners="24" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/shimmerThumbnail"
|
||||
android:layout_width="@dimen/empty_list_icon_layout_width"
|
||||
android:layout_height="@dimen/empty_list_icon_layout_height"
|
||||
android:layout_gravity="center"
|
||||
android:contentDescription="@null"
|
||||
android:src="@drawable/ic_image_outline"
|
||||
app:tint="@color/bg_default" />
|
||||
android:src="@drawable/ic_image_outline" />
|
||||
|
||||
</FrameLayout>
|
||||
</FrameLayout>
|
||||
|
|
|
@ -91,6 +91,8 @@
|
|||
android:layout_height="@dimen/nav_drawer_header_height"
|
||||
android:visibility="gone">
|
||||
|
||||
<!-- TODO add shimmer -->
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/preview_image"
|
||||
android:layout_width="match_parent"
|
||||
|
|
Loading…
Reference in a new issue