Skip to content

Commit

Permalink
1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
zeropercenthappy committed Oct 9, 2019
1 parent 4950817 commit ef02f3c
Show file tree
Hide file tree
Showing 13 changed files with 325 additions and 142 deletions.
65 changes: 39 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Glide for Android

## Step 1. Add it in your root build.gradle at the end of repositories
### Step 1. Add it in your root build.gradle at the end of repositories

```
allprojects {
Expand All @@ -13,48 +13,61 @@ allprojects {
}
```

## Step 2. Add the dependency
### Step 2. Add the dependency

```
dependencies {
implementation 'com.github.zeropercenthappy:GlideUtil:1.0.1'
implementation 'com.github.zeropercenthappy:GlideUtil:1.0.3'
}
```

## Usage

### kotlin
### load image into a ImageView:

```kotlin
loadImage {
this.url = url
this.imageView = iv
// required
context = ...
imageView = ...
url = ...
// options
// this.placeHolder = holder
// this.errorHolder = holder
// this.circleCrop = true
requestOptions = ...
transitionOptions = ...
thumbnail = ...
errorBuilder = ...
requestListener = ...
}
```

### java
or

```java
GlideUtils.loadImage();
```kotlin
loadImageWithBitmap {
// required
context = ...
imageView = ...
url = ...
// options
requestOptions = ...
transitionOptions = ...
thumbnail = ...
errorBuilder = ...
requestListener = ...
}
```

or (**not recommend**)

```java
GlideDSLKt.loadImage(new Function1<GlideWrapper, Unit>() {
@Override
public Unit invoke(GlideWrapper glideWrapper) {
glideWrapper.setUri();
glideWrapper.setImageView();
glideWrapper.setPlaceHolder();
glideWrapper.setErrorHolder();
glideWrapper.setCircleCrop();
return null;
}
});
### download image file:

```kotlin
// it's a suspend function, should be called only from a coroutine or another suspend function.
val result = downloadImage {
// required
context = ...
url = ...
storageFile = ...
// options
requestListener = ...
}
```

14 changes: 8 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 27
compileSdkVersion 28
defaultConfig {
applicationId "com.zeropercenthappy.glidesample"
minSdkVersion 14
targetSdkVersion 27
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -24,12 +24,14 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation "com.android.support:appcompat-v7:$android_support_version"
implementation 'com.android.support.constraint:constraint-layout:1.1.3'

implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0'

implementation "com.github.zeropercenthappy:ZPHAndroidUtils:1.2.2"

testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(path: ':glideutil')
}
19 changes: 10 additions & 9 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zeropercenthappy.glidesample">
package="com.zeropercenthappy.glidesample">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.zeropercenthappy.glidesample.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,62 @@
package com.zeropercenthappy.glidesample

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.bumptech.glide.request.RequestOptions
import com.zeropercenthappy.glideutil.downloadImage
import com.zeropercenthappy.glideutil.loadImage
import com.zeropercenthappy.utilslibrary.utils.CacheUtils
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch

class MainActivity : AppCompatActivity() {

private val mainScope = MainScope()
// private val imageUrl = "https://imgs.aixifan.com/2fJC0sJcLK-BZRZfa-Y3iqEz-Q7jmEv-6Rrmmq.jpg"
private val imageUrl = "https://imgs.aixifan.com/AcFccYdFRE-ZbAB7n-n2iymm-aEBFbu-mqIRni.gif"

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
load()
download()
}

private fun load() {
// options
val options = RequestOptions().apply {
placeholder(R.mipmap.ic_launcher)
error(R.mipmap.ic_launcher_round)
centerInside()
}
// load
loadImage {
context = this@MainActivity
imageView = iv
url = imageUrl
requestOptions = options
transitionOptions = DrawableTransitionOptions.withCrossFade(1500)
}
}

private fun download() = mainScope.launch {
val file = CacheUtils.createFormatedCacheFile(this@MainActivity, "gif") ?: return@launch
val downloadResult = downloadImage {
context = this@MainActivity
url = imageUrl
storageFile = file
}
val log = StringBuilder()
log.append("下载")
if (downloadResult) {
log.append("成功")
} else {
log.append("失败")
}
log.append("\n").append("路径:").append(file.absolutePath)
tv.text = log.toString()
}

}
41 changes: 27 additions & 14 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<ImageView
android:id="@+id/iv"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="H,1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="@android:color/holo_orange_dark" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
android:id="@+id/tv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/iv"
tools:text="Log" />

</android.support.constraint.ConstraintLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<string name="app_name">GlideUtil</string>
<string name="app_name">GlideSample</string>
</resources>
9 changes: 4 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.android_support_version = '27.1.1'
ext.kotlin_version = '1.3.41'
ext.glide_version = '4.7.1'
ext.android_support_version = '28.0.0'
ext.kotlin_version = '1.3.50'
ext.glide_version = '4.9.0'
repositories {
google()
jcenter()

}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
classpath 'com.android.tools.build:gradle:3.5.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
// NOTE: Do not place your application dependencies here; they belong
Expand Down
17 changes: 8 additions & 9 deletions glideutil/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ apply plugin: 'kotlin-kapt'
group = 'com.github.zeropercenthappy'

android {
compileSdkVersion 27
compileSdkVersion 28

defaultConfig {
minSdkVersion 14
targetSdkVersion 27
versionCode 102
versionName "1.0.2"
targetSdkVersion 28
versionCode 103
versionName "1.0.3"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand All @@ -30,15 +30,14 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0'

api "com.github.bumptech.glide:glide:$glide_version"
api "com.github.bumptech.glide:annotations:$glide_version"
kapt "com.github.bumptech.glide:compiler:$glide_version"

implementation "com.github.zeropercenthappy:ZPHAndroidUtils:1.2.2"
}

task sourcesJar(type: Jar) {
Expand Down
6 changes: 5 additions & 1 deletion glideutil/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zeropercenthappy.glideutil"/>
package="com.zeropercenthappy.glideutil">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
Loading

0 comments on commit ef02f3c

Please sign in to comment.