Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
1.8.0 add Coil Image Loader
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaelZero committed Jul 27, 2021
1 parent a2b0368 commit 1d14e19
Show file tree
Hide file tree
Showing 73 changed files with 1,197 additions and 418 deletions.
2 changes: 1 addition & 1 deletion FrescoImageLoader/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ android {
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.5.0'
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation "com.facebook.fresco:fresco:2.1.0"
implementation "androidx.annotation:annotation:1.2.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public void loadImage(final int requestId, Uri uri, boolean onlyRetrieveFromCach
mExecutorSupplier.forLocalStorageRead().execute(new Runnable() {
@Override
public void run() {
callback.onCacheHit(ImageInfoExtractor.getImageType(localCache), localCache);
callback.onSuccess(localCache);
}
});
Expand All @@ -92,7 +91,6 @@ protected void onProgress(int progress) {
protected void onSuccess(final File image) {
rememberTempFile(requestId, image);
callback.onFinish();
callback.onCacheMiss(ImageInfoExtractor.getImageType(image), image);
callback.onSuccess(image);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
import java.io.FileOutputStream;
import java.io.IOException;

public abstract class ImageDownloadSubscriber
extends BaseDataSubscriber<CloseableReference<PooledByteBuffer>> {
public abstract class ImageDownloadSubscriber extends BaseDataSubscriber<CloseableReference<PooledByteBuffer>> {
private static int sCounter = 0;

private final File mTempFile;
Expand All @@ -24,8 +23,7 @@ public abstract class ImageDownloadSubscriber

public ImageDownloadSubscriber(Context context) {
// no need for any file extension, use a counter to avoid conflict.
mTempFile =
new File(context.getCacheDir(), System.currentTimeMillis() + "_" + nextCounter());
mTempFile = new File(context.getCacheDir(), System.currentTimeMillis() + "_" + nextCounter());
}

private static synchronized int nextCounter() {
Expand Down
2 changes: 1 addition & 1 deletion GlideImageLoader/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ android {
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.5.0'
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
api "com.github.bumptech.glide:okhttp3-integration:4.11.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,14 @@ import okhttp3.OkHttpClient
import java.io.File
import java.util.*

open class GlideImageLoader constructor(val context: Context, okHttpClient: OkHttpClient?) : ImageLoader {
open class GlideImageLoader private constructor(val context: Context, okHttpClient: OkHttpClient?) : ImageLoader {
private val mRequestManager: RequestManager
private val mFlyingRequestTargets: MutableMap<Int, ImageDownloadTarget> = HashMap(3)

override fun loadImage(requestId: Int, uri: Uri, onlyRetrieveFromCache: Boolean, callback: ImageLoader.Callback) {
val cacheMissed = BooleanArray(1)
val target: ImageDownloadTarget = object : ImageDownloadTarget(uri.toString()) {
override fun onResourceReady(resource: File, transition: Transition<in File>?) {
super.onResourceReady(resource, transition)
if (cacheMissed[0]) {
callback.onCacheMiss(ImageInfoExtractor.getImageType(resource), resource)
} else {
callback.onCacheHit(ImageInfoExtractor.getImageType(resource), resource)
}
callback.onSuccess(resource)
}

Expand All @@ -39,7 +33,6 @@ open class GlideImageLoader constructor(val context: Context, okHttpClient: OkHt
}

override fun onDownloadStart() {
cacheMissed[0] = true
callback.onStart()
}

Expand All @@ -51,7 +44,6 @@ open class GlideImageLoader constructor(val context: Context, okHttpClient: OkHt
callback.onFinish()
}
}
// cancel(requestId)
rememberTarget(requestId, target)
downloadImageInto(uri, target, onlyRetrieveFromCache)
}
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

[English](https://github.com/MikaelZero/mojito/blob/master/README_en.md)


## 功能列表

- 支持Coil图片加载器
- 支持Glide图片加载器
- 支持Fresco图片加载器
- 支持视频图片混合、GIF、图片预览
- 支持拖拽关闭
- 支持自定义页面索引指示器、进度条、Cover
- 支持原图加载策略

## 二维码下载体验

<img src="https://cdn.nlark.com/yuque/0/2020/png/252337/1592720888032-assets/web-upload/30908db5-767a-49f6-9564-5b8264b07c14.png" width="180">
Expand Down
11 changes: 4 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.google.android.material:material:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'com.github.bumptech.glide:glide:4.11.0'
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.4'
implementation 'com.gyf.immersionbar:immersionbar:3.0.0'
Expand All @@ -47,14 +47,11 @@ dependencies {
implementation 'org.salient.artvideoplayer:artplayer-core:1.1.0'
implementation 'org.salient.artvideoplayer:artplayer-ijk:1.1.0'
implementation "org.salient.artvideoplayer:artplayer-armv7a:1.1.0"
implementation("io.coil-kt:coil:1.3.0")

implementation project(':mojito')
implementation project(':GlideImageLoader')
implementation project(':FrescoImageLoader')
implementation project(':SketchImageViewLoader')

// implementation "com.github.mikaelzero.mojito:mojito:$mojito_version"
// implementation "com.github.mikaelzero.mojito:SketchImageViewLoader:$mojito_version"
// implementation "com.github.mikaelzero.mojito:GlideImageLoader:$mojito_version"
// implementation "com.github.mikaelzero.mojito:FrescoImageLoader:$mojito_version"
implementation project(':coilimageloader')
}
5 changes: 2 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="net.mikaelzero.app">

<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />
Expand All @@ -19,8 +20,7 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:requestLegacyExternalStorage="true"
android:theme="@style/AppTheme">
android:requestLegacyExternalStorage="true">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -36,7 +36,6 @@
<activity android:name=".ActivityCoverActivity" />
<activity android:name=".video.VideoActivity" />
<activity android:name=".stagger.StaggerActivity" />
<activity android:name=".TestMainActivity" />
<activity android:name=".DifferentScenesActivity" />
</application>

Expand Down
10 changes: 1 addition & 9 deletions app/src/main/java/net/mikaelzero/app/ActivityCoverActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ import kotlinx.android.synthetic.main.activity_target.*
import net.mikaelzero.mojito.Mojito
import net.mikaelzero.mojito.impl.DefaultPercentProgress
import net.mikaelzero.mojito.impl.DefaultTargetFragmentCover
import net.mikaelzero.mojito.impl.NumIndicator
import net.mikaelzero.mojito.interfaces.IProgress
import net.mikaelzero.mojito.loader.FragmentCoverLoader
import net.mikaelzero.mojito.loader.InstanceLoader
import net.mikaelzero.mojito.loader.fresco.FrescoImageLoader
import net.mikaelzero.mojito.loader.glide.GlideImageLoader
import net.mikaelzero.mojito.view.sketch.SketchImageLoadFactory

class ActivityCoverActivity : AppCompatActivity() {
var context: Context? = null
Expand All @@ -23,12 +19,8 @@ class ActivityCoverActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
context = this
setContentView(R.layout.activity_cover)
Mojito.initialize(
GlideImageLoader.with(this),
SketchImageLoadFactory()
)
recyclerView.layoutManager = GridLayoutManager(this, 3)
val adapter = GlideAdapter()
val adapter = ImageAdapter()
adapter.setList(SourceUtil.getTargetButtonSmall())
recyclerView.adapter = adapter
adapter.setOnItemClickListener { adapter, view, position ->
Expand Down
6 changes: 2 additions & 4 deletions app/src/main/java/net/mikaelzero/app/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ import net.mikaelzero.mojito.view.sketch.SketchImageLoadFactory


class App : Application() {

override fun attachBaseContext(base: Context?) {
super.attachBaseContext(base)
MultiDex.install(this)
}

override fun onCreate() {
super.onCreate()
Mojito.initialize(
GlideImageLoader.with(this),
SketchImageLoadFactory()
)

}
}
16 changes: 1 addition & 15 deletions app/src/main/java/net/mikaelzero/app/DifferentScenesActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,11 @@ package net.mikaelzero.app
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.GridLayoutManager
import com.bumptech.glide.Glide
import kotlinx.android.synthetic.main.activity_different_scenes.*
import net.mikaelzero.mojito.Mojito
import net.mikaelzero.mojito.impl.DefaultPercentProgress
import net.mikaelzero.mojito.impl.NumIndicator
import net.mikaelzero.mojito.impl.SimpleMojitoViewCallback
import net.mikaelzero.mojito.interfaces.IProgress
import net.mikaelzero.mojito.loader.InstanceLoader
import net.mikaelzero.mojito.loader.glide.GlideImageLoader
import net.mikaelzero.mojito.view.sketch.SketchImageLoadFactory

class DifferentScenesActivity : AppCompatActivity() {
var context: Context? = null
Expand All @@ -26,12 +16,8 @@ class DifferentScenesActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
context = this
setContentView(R.layout.activity_different_scenes)
Mojito.initialize(
GlideImageLoader.with(this),
SketchImageLoadFactory()
)
recyclerView.layoutManager = GridLayoutManager(this, 3)
val adapter = GlideAdapter2()
val adapter = DifferentScenesAdapter()
val list = mutableListOf<UrlBean>()
list.add(UrlBean("", 0))
list.add(UrlBean("", 0))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
package net.mikaelzero.app

import android.widget.FrameLayout
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.facebook.drawee.backends.pipeline.Fresco
import net.mikaelzero.mojito.tools.ScreenUtils

/**
* @Author: MikaelZero
* @CreateDate: 2020/6/19 8:43 PM
* @Description:
*/
class GlideAdapter2 : BaseQuickAdapter<UrlBean, BaseViewHolder>(R.layout.item_grid) {
class DifferentScenesAdapter : BaseQuickAdapter<UrlBean, BaseViewHolder>(R.layout.item_grid) {
override fun convert(holder: BaseViewHolder, item: UrlBean) {
val srcImageView = holder.getView<ImageView>(R.id.srcImageView)
val srcImageView = holder.getView<FrameLayout>(R.id.srcImageView)
(srcImageView.layoutParams as FrameLayout.LayoutParams).width = ScreenUtils.getScreenWidth(context) / 3
(srcImageView.layoutParams as FrameLayout.LayoutParams).height = ScreenUtils.getScreenWidth(context) / 3
if (item.type == 1) {
Glide.with(context).load(item.url).into(srcImageView)
srcImageView.addImg(item.url)
} else {
Glide.with(context).load(R.drawable.good).into(srcImageView)
srcImageView.addImgLocal(R.drawable.good)
}
}
}
24 changes: 0 additions & 24 deletions app/src/main/java/net/mikaelzero/app/GlideAdapter.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
package net.mikaelzero.app

import android.net.Uri
import android.widget.FrameLayout
import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import net.mikaelzero.mojito.tools.ScreenUtils


/**
* @Author: MikaelZero
* @CreateDate: 2020/6/19 8:43 PM
* @Description:
*/
class FrescoAdapter : BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_grid_fresco) {
class ImageAdapter : BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_grid) {
override fun convert(holder: BaseViewHolder, item: String) {
val srcImageView = holder.getView<ImageView>(R.id.srcImageView)
val srcImageView = holder.getView<FrameLayout>(R.id.srcImageView)
srcImageView.addImg(item)
(srcImageView.layoutParams as FrameLayout.LayoutParams).width = ScreenUtils.getScreenWidth(context) / 3
(srcImageView.layoutParams as FrameLayout.LayoutParams).height = ScreenUtils.getScreenWidth(context) / 3
val uri = Uri.parse(item)
srcImageView.setImageURI(uri)

}
}
Loading

0 comments on commit 1d14e19

Please sign in to comment.