Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yunlaboratory
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lihuaikun
yunlaboratory
Commits
98845562
Commit
98845562
authored
Jun 20, 2020
by
lihuaikun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:增加图片上传压缩 加长http连接时间
parent
5ce668d4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
31 deletions
+68
-31
build.gradle
app/build.gradle
+2
-1
app-release.apk
app/release/app-release.apk
+0
-0
PersonFragment.java
...a/cn/dankal/yunlaboratory/ui/fragment/PersonFragment.java
+62
-28
BaseApi.java
baselib/src/main/java/cn/dankal/basiclib/api/BaseApi.java
+4
-2
No files found.
app/build.gradle
View file @
98845562
...
@@ -45,6 +45,6 @@ android {
...
@@ -45,6 +45,6 @@ android {
dependencies
{
dependencies
{
implementation
fileTree
(
dir:
"libs"
,
include:
[
"*.jar"
])
implementation
fileTree
(
dir:
"libs"
,
include:
[
"*.jar"
])
implementation
project
(
":baselib"
)
implementation
project
(
":baselib"
)
implementation
'top.zibin:Luban:1.1.8'
annotationProcessor
deps
.
butterknife
.
butterknife_compiler
annotationProcessor
deps
.
butterknife
.
butterknife_compiler
}
}
\ No newline at end of file
app/release/app-release.apk
View file @
98845562
No preview for this file type
app/src/main/java/cn/dankal/yunlaboratory/ui/fragment/PersonFragment.java
View file @
98845562
...
@@ -59,6 +59,9 @@ import io.reactivex.functions.Consumer;
...
@@ -59,6 +59,9 @@ import io.reactivex.functions.Consumer;
import
okhttp3.MediaType
;
import
okhttp3.MediaType
;
import
okhttp3.MultipartBody
;
import
okhttp3.MultipartBody
;
import
okhttp3.RequestBody
;
import
okhttp3.RequestBody
;
import
top.zibin.luban.CompressionPredicate
;
import
top.zibin.luban.Luban
;
import
top.zibin.luban.OnCompressListener
;
public
class
PersonFragment
extends
BaseFragment
implements
View
.
OnClickListener
{
public
class
PersonFragment
extends
BaseFragment
implements
View
.
OnClickListener
{
...
@@ -324,45 +327,76 @@ public class PersonFragment extends BaseFragment implements View.OnClickListener
...
@@ -324,45 +327,76 @@ public class PersonFragment extends BaseFragment implements View.OnClickListener
*/
*/
private
void
updateAvatar
(
String
path
)
{
private
void
updateAvatar
(
String
path
)
{
if
(!
TextUtils
.
isEmpty
(
path
))
{
if
(!
TextUtils
.
isEmpty
(
path
)
&&
new
File
(
path
).
exists
()
)
{
HashMap
<
String
,
RequestBody
>
map
=
new
HashMap
<>();
Luban
.
with
(
getContext
())
.
load
(
path
)
.
ignoreBy
(
100
)
.
setTargetDir
(
new
File
(
path
).
getParentFile
().
getPath
())
.
filter
(
new
CompressionPredicate
()
{
@Override
public
boolean
apply
(
String
path
)
{
return
!(
TextUtils
.
isEmpty
(
path
)
||
path
.
toLowerCase
().
endsWith
(
".gif"
));
}
})
.
setCompressListener
(
new
OnCompressListener
()
{
@Override
public
void
onStart
()
{
// TODO 压缩开始前调用,可以在方法内启动 loading UI
showLoadingDialog
();
}
RequestBody
updateTypeBody
=
RequestBody
.
create
(
MediaType
.
parse
(
"application/json"
),
"avatar"
);
@Override
map
.
put
(
"update_type"
,
updateTypeBody
);
public
void
onSuccess
(
File
file
)
{
// TODO 压缩成功后调用,返回压缩后的图片文件
File
file
=
new
File
(
path
);
HashMap
<
String
,
RequestBody
>
map
=
new
HashMap
<>(
);
RequestBody
fileRQ
=
RequestBody
.
create
(
MediaType
.
parse
(
"image/png"
),
file
);
RequestBody
updateTypeBody
=
RequestBody
.
create
(
MediaType
.
parse
(
"application/json"
),
"avatar"
);
MultipartBody
.
Part
part
=
MultipartBody
.
Part
.
createFormData
(
"file"
,
file
.
getName
(),
fileRQ
);
map
.
put
(
"update_type"
,
updateTypeBody
);
RequestBody
fileRQ
=
RequestBody
.
create
(
MediaType
.
parse
(
"image/png"
),
file
);
MultipartBody
.
Part
part
=
MultipartBody
.
Part
.
createFormData
(
"file"
,
file
.
getName
(),
fileRQ
);
// map.put("file",fileRQ);
// map.put("file",fileRQ);
UserServiceFactory
.
updateInfo
(
map
,
part
).
map
(
new
MapFunc
<>()).
subscribe
(
new
NormalSubscriber
<
BaseModel
<
UserModel
>>()
{
UserServiceFactory
.
updateInfo
(
map
,
part
).
map
(
new
MapFunc
<>()).
subscribe
(
new
NormalSubscriber
<
BaseModel
<
UserModel
>>()
{
@Override
@Override
public
void
onSubscribe
(
Disposable
d
)
{
public
void
onSubscribe
(
Disposable
d
)
{
showLoadingDialog
();
}
@Override
}
public
void
onNext
(
BaseModel
<
UserModel
>
stringBaseModel
)
{
if
(
stringBaseModel
.
getData
()!=
null
){
String
avatar
=
stringBaseModel
.
getData
().
getAvatar
();
UserModel
userModel
=
DKUserManager
.
getUserInfo
();
userModel
.
setAvatar
(
avatar
);
@Override
DKUserManager
.
updateUserInfo
(
userModel
);
public
void
onNext
(
BaseModel
<
UserModel
>
stringBaseModel
)
{
GlideUtils
.
loadCircleImage
(
getContext
(),
avatar
,
ivAvatar
);
if
(
stringBaseModel
.
getData
()!=
null
){
}
String
avatar
=
stringBaseModel
.
getData
().
getAvatar
();
UserModel
userModel
=
DKUserManager
.
getUserInfo
();
userModel
.
setAvatar
(
avatar
);
DKUserManager
.
updateUserInfo
(
userModel
);
GlideUtils
.
loadCircleImage
(
getContext
(),
avatar
,
ivAvatar
);
}
}
@Override
public
void
onComplete
()
{
super
.
onComplete
();
dismissLoadingDialog
();
}
});
}
@Override
public
void
onError
(
Throwable
e
)
{
// TODO 当压缩过程出现问题时调用
Logger
.
e
(
e
.
getMessage
());
ToastUtils
.
showLong
(
"图片压缩失败"
);
dismissLoadingDialog
();
}
}).
launch
();
}
@Override
public
void
onComplete
()
{
super
.
onComplete
();
dismissLoadingDialog
();
}
});
}
}
}
}
...
...
baselib/src/main/java/cn/dankal/basiclib/api/BaseApi.java
View file @
98845562
...
@@ -29,6 +29,7 @@ public class BaseApi {
...
@@ -29,6 +29,7 @@ public class BaseApi {
:
"http://tp.lzdu.com/api/"
;
:
"http://tp.lzdu.com/api/"
;
public
static
final
String
OTHER_BASE_URL
=
"http://gd21262648.imwork.net:30110/"
;
public
static
final
String
OTHER_BASE_URL
=
"http://gd21262648.imwork.net:30110/"
;
public
static
final
int
TIME_OUT
=
60
;
private
static
LinkedHashMap
<
String
,
Retrofit
>
linkedHashMap
=
new
LinkedHashMap
<>(
3
);
private
static
LinkedHashMap
<
String
,
Retrofit
>
linkedHashMap
=
new
LinkedHashMap
<>(
3
);
...
@@ -80,8 +81,9 @@ public class BaseApi {
...
@@ -80,8 +81,9 @@ public class BaseApi {
httpLoggingInterceptor
.
setLevel
(
HttpLoggingInterceptor
.
Level
.
BODY
);
httpLoggingInterceptor
.
setLevel
(
HttpLoggingInterceptor
.
Level
.
BODY
);
OkHttpClient
OkHttpClient
okHttpClient
=
new
OkHttpClient
.
Builder
().
readTimeout
(
7000
,
TimeUnit
.
MILLISECONDS
)
okHttpClient
=
new
OkHttpClient
.
Builder
().
readTimeout
(
TIME_OUT
,
TimeUnit
.
SECONDS
)
.
connectTimeout
(
7000
,
TimeUnit
.
MILLISECONDS
)
.
connectTimeout
(
TIME_OUT
,
TimeUnit
.
SECONDS
)
.
writeTimeout
(
TIME_OUT
,
TimeUnit
.
SECONDS
)
.
addInterceptor
(
new
TokenInterceptor
())
.
addInterceptor
(
new
TokenInterceptor
())
.
addInterceptor
(
httpLoggingInterceptor
)
.
addInterceptor
(
httpLoggingInterceptor
)
.
hostnameVerifier
(
new
HostnameVerifier
()
{
.
hostnameVerifier
(
new
HostnameVerifier
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment