Skip to content

Commit

Permalink
[MOD] ❤️ 图片来源更改
Browse files Browse the repository at this point in the history
  • Loading branch information
miaoMiaoDaShi committed Dec 28, 2018
1 parent bc0ed53 commit 357761c
Show file tree
Hide file tree
Showing 50 changed files with 364 additions and 571 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import java.io.File
* Description :
*/
object Constant {
val API_HOST = "http://m.xxxiao.com/"
val API_HOST = "https://api.meizitu.net/wp-json/wp/v2/"
val BMOB_APPLICATION_KEY = "39a0df90ea32771643ead11e26508d90"
val SPLASH_IMAGE_URL = "http://gank.io/api/data/%E7%A6%8F%E5%88%A9/1/1"
//splash图片的位置
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.jess.arms.http.log.RequestInterceptor
import com.jess.arms.integration.ConfigModule
import com.yangyan.xxp.yangyannew.BuildConfig
import retrofit2.converter.scalars.ScalarsConverterFactory
import java.util.concurrent.TimeUnit

/**
* Author : zhongwenpeng
Expand All @@ -31,13 +32,20 @@ class GlobalConfiguration : ConfigModule {
baseurl(Constant.API_HOST)
imageLoaderStrategy(YangYanGlideImageLoaderStrategy())
responseErrorListener(ResponseErrorListenerImpl())

retrofitConfiguration { context, builder ->
builder.addConverterFactory(ScalarsConverterFactory.create())
}
// .okhttpConfiguration { context, builder ->
// builder.sslSocketFactory(SSLSocketClient.getSSLSocketFactory(), SSLSocketClient.getTrustManager()) //支持 Https,详情请百度
// builder.writeTimeout(30, TimeUnit.SECONDS)
// builder.hostnameVerifier(SSLSocketClient.getHostnameVerifier())
// }
gsonConfiguration { context, builder ->
builder.serializeNulls()
.enableComplexMapKeySerialization()
}
globalHttpHandler(GlobalHttpHandlerImpl(context))
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Copyright 2017 JessYan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.yangyan.xxp.yangyannew.app

import android.content.Context
import android.text.TextUtils
import com.google.gson.Gson

import com.google.gson.reflect.TypeToken
import com.jess.arms.http.GlobalHttpHandler
import com.jess.arms.http.log.RequestInterceptor
import okhttp3.HttpUrl

import okhttp3.Interceptor
import okhttp3.Request
import okhttp3.Response
import timber.log.Timber

/**
* ================================================
* 展示 [GlobalHttpHandler] 的用法
*
*
* Created by JessYan on 04/09/2017 17:06
* [Contact me](mailto:[email protected])
* [Follow me](https://github.com/JessYanCoding)
* ================================================
*/
class GlobalHttpHandlerImpl(private val context: Context) : GlobalHttpHandler {

/**
* 用户信息
*/
private val mUserInfoString by Preference("userInfo", "")

/**
* 这里可以先客户端一步拿到每一次 Http 请求的结果, 可以先解析成 Json, 再做一些操作, 如检测到 token 过期后
* 重新请求 token, 并重新执行请求
*
* @param httpResult 服务器返回的结果 (已被框架自动转换为字符串)
* @param chain [Interceptor.Chain]
* @param response [Response]
* @return
*/
override fun onHttpResultResponse(httpResult: String?, chain: Interceptor.Chain, response: Response): Response {
if (!TextUtils.isEmpty(httpResult) && RequestInterceptor.isJson(response.body()!!.contentType())) {

}

/* 这里如果发现 token 过期, 可以先请求最新的 token, 然后在拿新的 token 放入 Request 里去重新请求
注意在这个回调之前已经调用过 proceed(), 所以这里必须自己去建立网络请求, 如使用 Okhttp 使用新的 Request 去请求
create a new request and modify it accordingly using the new token
Request newRequest = chain.request().newBuilder().header("token", newToken)
.build();
retry the request
response.body().close();
如果使用 Okhttp 将新的请求, 请求成功后, 再将 Okhttp 返回的 Response return 出去即可
如果不需要返回新的结果, 则直接把参数 response 返回出去即可 */
return response
}

/**
* 这里可以在请求服务器之前拿到 [Request], 做一些操作比如给 [Request] 统一添加 token 或者 header 以及参数加密等操作
*
* @param chain [Interceptor.Chain]
* @param request [Request]
* @return
*/
override fun onHttpRequestBefore(chain: Interceptor.Chain, request: Request): Request {
/* 如果需要再请求服务器之前做一些操作, 则重新返回一个做过操作的的 Request 如增加 Header, 不做操作则直接返回参数 request
return chain.request().newBuilder().header("token", tokenId)
.build(); */


return if (request.url().host().equals(HttpUrl.get(Constant.API_HOST).host())) request.newBuilder()
.header("Referer", "https://app.mmzztt.com")
.build()
else request

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.yangyan.xxp.yangyannew.app;

import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

/**
* Author : zhongwenpeng
* Email : [email protected]
* Time : 2018/2/26
* Description :
*/

public class SSLSocketClient {

//获取这个SSLSocketFactory
public static javax.net.ssl.SSLSocketFactory getSSLSocketFactory() {
try {
SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, getTrustManagers(), new SecureRandom());
return sslContext.getSocketFactory();
} catch (Exception e) {
throw new RuntimeException(e);
}
}

//获取TrustManager
private static TrustManager[] getTrustManagers() {
TrustManager[] trustAllCerts = new TrustManager[]{getTrustManager()};
return trustAllCerts;
}

//获取HostnameVerifier
public static HostnameVerifier getHostnameVerifier() {
HostnameVerifier hostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify(String s, SSLSession sslSession) {
return true;
}
};
return hostnameVerifier;
}

public static X509TrustManager getTrustManager(){
return new MyTrustManager();
}

private static final class MyTrustManager implements X509TrustManager {

@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {

}

@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {

}

@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
package com.yangyan.xxp.yangyannew.di.module

import android.support.v7.widget.LinearLayoutManager
import com.jess.arms.di.scope.ActivityScope
import com.jess.arms.di.scope.FragmentScope
import com.yangyan.xxp.yangyannew.mvp.contract.CategoryChildContract
import com.yangyan.xxp.yangyannew.mvp.contract.HomeContract
import com.yangyan.xxp.yangyannew.mvp.contract.MainContract
import com.yangyan.xxp.yangyannew.mvp.model.CategoryChildModel
import com.yangyan.xxp.yangyannew.mvp.model.HomeModel
import com.yangyan.xxp.yangyannew.mvp.model.MainModel
import com.yangyan.xxp.yangyannew.mvp.model.entity.ImagesInfo
import com.yangyan.xxp.yangyannew.mvp.ui.adapter.HomeAdapter
import dagger.Module
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
package com.yangyan.xxp.yangyannew.di.module

import android.support.v7.widget.LinearLayoutManager
import com.jess.arms.di.scope.ActivityScope
import com.jess.arms.di.scope.FragmentScope
import com.yangyan.xxp.yangyannew.mvp.contract.CategoryContract
import com.yangyan.xxp.yangyannew.mvp.contract.HomeContract
import com.yangyan.xxp.yangyannew.mvp.contract.MainContract
import com.yangyan.xxp.yangyannew.mvp.model.CategoryModel
import com.yangyan.xxp.yangyannew.mvp.model.HomeModel
import com.yangyan.xxp.yangyannew.mvp.model.MainModel
import com.yangyan.xxp.yangyannew.mvp.model.entity.ImagesInfo
import com.yangyan.xxp.yangyannew.mvp.ui.adapter.CategoryFragmentPageAdapter
import com.yangyan.xxp.yangyannew.mvp.ui.adapter.HomeAdapter
import dagger.Module
import dagger.Provides
import javax.inject.Inject

/**
* Author : zhongwenpeng
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ package com.yangyan.xxp.yangyannew.di.module

import android.support.v7.widget.LinearLayoutManager
import com.jess.arms.di.scope.ActivityScope
import com.jess.arms.di.scope.FragmentScope
import com.yangyan.xxp.yangyannew.mvp.contract.FavoriteImageListContract
import com.yangyan.xxp.yangyannew.mvp.contract.HomeContract
import com.yangyan.xxp.yangyannew.mvp.model.FavoriteImageListModel
import com.yangyan.xxp.yangyannew.mvp.model.HomeModel
import com.yangyan.xxp.yangyannew.mvp.model.entity.ImagesInfo
import com.yangyan.xxp.yangyannew.mvp.ui.adapter.HomeAdapter
import com.yangyan.xxp.yangyannew.mvp.ui.fragment.SearchFragment
import dagger.Module
import dagger.Provides

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.yangyan.xxp.yangyannew.di.module

import com.jess.arms.di.scope.FragmentScope
import com.yangyan.xxp.yangyannew.di.scope.FavoriteScope
import com.yangyan.xxp.yangyannew.mvp.model.entity.FavoriteInfo
import com.yangyan.xxp.yangyannew.mvp.model.entity.ImagesInfo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
package com.yangyan.xxp.yangyannew.di.module

import android.support.v7.widget.GridLayoutManager
import android.view.LayoutInflater
import android.view.View
import com.jess.arms.di.scope.ActivityScope
import com.yangyan.xxp.yangyannew.R
import com.yangyan.xxp.yangyannew.mvp.contract.GalleryContract
import com.yangyan.xxp.yangyannew.mvp.contract.ImageCollectionContract
import com.yangyan.xxp.yangyannew.mvp.model.GalleryModel
import com.yangyan.xxp.yangyannew.mvp.model.ImageCollectionModel
import com.yangyan.xxp.yangyannew.mvp.model.entity.ImagesInfo
import com.yangyan.xxp.yangyannew.mvp.ui.adapter.GalleryPageAdapter
import com.yangyan.xxp.yangyannew.mvp.ui.adapter.ImageCollectionAdapter
import dagger.Module
import dagger.Provides

Expand Down Expand Up @@ -44,9 +39,9 @@ class GalleryModule(val view: GalleryContract.View) {

@ActivityScope
@Provides
internal fun provideDatas() = mutableListOf<ImagesInfo>()
internal fun provideDatas() = mutableListOf<String>()

@ActivityScope
@Provides
internal fun provideAdapter(datas: MutableList<ImagesInfo>) = GalleryPageAdapter(datas)
internal fun provideAdapter(datas: MutableList<String>) = GalleryPageAdapter(datas)
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package com.yangyan.xxp.yangyannew.di.module

import android.support.v7.widget.LinearLayoutManager
import com.jess.arms.di.scope.ActivityScope
import com.jess.arms.di.scope.FragmentScope
import com.yangyan.xxp.yangyannew.mvp.contract.HomeContract
import com.yangyan.xxp.yangyannew.mvp.contract.MainContract
import com.yangyan.xxp.yangyannew.mvp.model.HomeModel
import com.yangyan.xxp.yangyannew.mvp.model.MainModel
import com.yangyan.xxp.yangyannew.mvp.model.entity.ImagesInfo
import com.yangyan.xxp.yangyannew.mvp.ui.adapter.HomeAdapter
import com.yangyan.xxp.yangyannew.mvp.ui.fragment.SearchFragment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@ package com.yangyan.xxp.yangyannew.di.module
import android.support.v7.widget.GridLayoutManager
import android.support.v7.widget.LinearLayoutManager
import com.jess.arms.di.scope.ActivityScope
import com.jess.arms.di.scope.FragmentScope
import com.yangyan.xxp.yangyannew.mvp.contract.HomeContract
import com.yangyan.xxp.yangyannew.mvp.contract.ImageCollectionContract
import com.yangyan.xxp.yangyannew.mvp.contract.MainContract
import com.yangyan.xxp.yangyannew.mvp.model.HomeModel
import com.yangyan.xxp.yangyannew.mvp.model.ImageCollectionModel
import com.yangyan.xxp.yangyannew.mvp.model.MainModel
import com.yangyan.xxp.yangyannew.mvp.model.entity.ImagesInfo
import com.yangyan.xxp.yangyannew.mvp.ui.adapter.HomeAdapter
import com.yangyan.xxp.yangyannew.mvp.ui.adapter.ImageCollectionAdapter
import dagger.Module
import dagger.Provides
Expand Down Expand Up @@ -49,10 +43,10 @@ constructor(private val view: ImageCollectionContract.View) {
@ActivityScope
@Provides
@Named("ImageCollectionImagesDatas")
internal fun provideDatas() = mutableListOf<ImagesInfo>()
internal fun provideDatas() = mutableListOf<String>()

@ActivityScope
@Provides
@Named("ImageCollectionImagesAdapter")
internal fun provideAdapter( @Named("ImageCollectionImagesDatas") datas: MutableList<ImagesInfo>) = ImageCollectionAdapter(datas)
internal fun provideAdapter( @Named("ImageCollectionImagesDatas") datas: MutableList<String>) = ImageCollectionAdapter(datas)
}

This file was deleted.

Loading

0 comments on commit 357761c

Please sign in to comment.