diff --git a/Readme.md b/Readme.md index fb75435..ee76704 100644 --- a/Readme.md +++ b/Readme.md @@ -35,7 +35,7 @@ Gradle ```groovy dependencies{ - compile 'com.youth.xframe:xframe:1.1.0' + compile 'com.youth.xframe:xframe:1.1.2' } ``` 或者引用本地lib @@ -62,8 +62,20 @@ compile project(':xframe') ## 更新说明 +#### v1.1.2 + XFrame 优化更新 + * XImage支持使用第三方框架来配置加载不同形状图片 + * XRecyclerViewAdapter修改数据操作中移动,交换,删除,替换等列表更新bug + * XToast解决重复创建显示问题 + * 修改优化了一些bug + +#### v1.1.1 + XFrame 优化更新 + * 增加XImage第三方图片加载框架隔离框架 + * 修改优化了一些bug + #### v1.1.0 - banner 优化更新 + XFrame 优化更新 * 增加Http网络隔离框架 * 修改优化了一些bug diff --git a/app/build.gradle b/app/build.gradle index c030d60..7a9cae7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -22,8 +22,7 @@ android { dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile project(':xframe') - compile 'com.android.support:design:25.3.1' - compile 'com.youth.banner:banner:+' + compile 'com.android.support:design:+' compile 'com.github.bumptech.glide:glide:3.7.0' compile 'cat.ereza:customactivityoncrash:1.5.0' diff --git a/app/src/main/java/com/youth/xf/App.java b/app/src/main/java/com/youth/xf/App.java index 7f8fec6..2ef6d46 100644 --- a/app/src/main/java/com/youth/xf/App.java +++ b/app/src/main/java/com/youth/xf/App.java @@ -2,6 +2,7 @@ import com.youth.xf.http.AsyncHttpEngine; import com.youth.xf.http.OKHttpEngine; +import com.youth.xf.loder.GlideImageLoader; import com.youth.xframe.base.XApplication; import com.youth.xframe.XFrame; @@ -13,7 +14,9 @@ public void onCreate() { super.onCreate(); CustomActivityOnCrash.install(this); + //初始化日志 XFrame.initXLog(); + //初始化多状态界面View XFrame.initXLoadingView() .setErrorViewResId(R.layout._loading_layout_error); @@ -23,5 +26,11 @@ public void onCreate() { AsyncHttpEngine、OKHttpEngine、VolleyHttpEngine */ XFrame.initXHttp(new AsyncHttpEngine()); + + /** + * 初始化全局图片加载框架 + * GlideImageLoader为你的图片加载框架实现类 + */ + XFrame.initXImageLoader(new GlideImageLoader(getApplicationContext())); } } diff --git a/app/src/main/java/com/youth/xf/http/OKHttpEngine.java b/app/src/main/java/com/youth/xf/http/OKHttpEngine.java index 08a8c6b..6403bc1 100644 --- a/app/src/main/java/com/youth/xf/http/OKHttpEngine.java +++ b/app/src/main/java/com/youth/xf/http/OKHttpEngine.java @@ -1,35 +1,56 @@ package com.youth.xf.http; +import android.os.Environment; + import com.alibaba.fastjson.JSON; +import com.youth.xframe.XFrame; import com.youth.xframe.utils.http.HttpCallBack; import com.youth.xframe.utils.http.IHttpEngine; import com.youth.xframe.utils.http.XHttp; +import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; +import okhttp3.Cache; import okhttp3.Call; import okhttp3.Callback; import okhttp3.FormBody; +import okhttp3.MediaType; +import okhttp3.MultipartBody; import okhttp3.OkHttpClient; import okhttp3.Request; +import okhttp3.RequestBody; import okhttp3.Response; +import static okhttp3.internal.Util.EMPTY_REQUEST; + /** * OKHttp简单实现,你可修改,这只是案例 - * */ public class OKHttpEngine implements IHttpEngine { private OkHttpClient client = null; + private int cacheSize = 10 * 1024 * 1024; public OKHttpEngine() { - client = new OkHttpClient(); + client = new OkHttpClient().newBuilder() + .retryOnConnectionFailure(true) + .connectTimeout(10, TimeUnit.SECONDS) + .readTimeout(10, TimeUnit.SECONDS) + .writeTimeout(10, TimeUnit.SECONDS) + .cache(new Cache(XFrame.getContext().getCacheDir(), cacheSize)) + .build(); } @Override public void get(String url, Map params, final HttpCallBack callBack) { - final Request request = new Request.Builder().url(url).build(); + Request request = new Request.Builder().url(url+getUrlParamsByMap(params)).build(); client.newCall(request).enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { @@ -44,7 +65,7 @@ public void onResponse(Call call, final Response response) throws IOException { @Override public void run() { //我这里使用的是fastjson,你也可以用gson,jackjson等 - callBack.onSuccess(JSON.parseObject(result,XHttp.analysisClassInfo(callBack))); + callBack.onSuccess(JSON.parseObject(result, XHttp.analysisClassInfo(callBack))); } }); } else { @@ -62,17 +83,35 @@ public void run() { @Override public void post(String url, Map params, final HttpCallBack callBack) { - FormBody.Builder body = new FormBody.Builder(); - if(null!=params) { - for (String key:params.keySet()) { - body.add(key, (String) params.get(key)); + RequestBody body = EMPTY_REQUEST; + if (null != params&&!params.isEmpty()) { + MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM); + for (String key : params.keySet()) { + Object value = params.get(key); + if (value instanceof File) { + File file = (File) value; + builder.addFormDataPart(key, file.getName(), + RequestBody.create(MediaType.parse("image/png"), file));//"application/octet-stream" + } + if (value instanceof ArrayList) { + ArrayList lists = (ArrayList) value; + for (Object obj : lists) { + if (obj instanceof File) { + File file = (File) obj; + builder.addFormDataPart(key, file.getName(), + RequestBody.create(MediaType.parse("image/png"), file)); + } + } + } else { + builder.addFormDataPart(key, value.toString()); + } } + body = builder.build(); } - OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url(url) - .post(body.build()) + .post(body) .build(); client.newCall(request).enqueue(new Callback() { @Override @@ -88,7 +127,7 @@ public void onResponse(Call call, final Response response) throws IOException { @Override public void run() { //我这里使用的是fastjson,你也可以用gson,jackjson等 - callBack.onSuccess(JSON.parseObject(result,XHttp.analysisClassInfo(callBack))); + callBack.onSuccess(JSON.parseObject(result, XHttp.analysisClassInfo(callBack))); } }); } else { @@ -99,9 +138,22 @@ public void run() { } }); } - } }); } + private String getUrlParamsByMap(Map map) { + if (map == null||map.isEmpty()) { + return ""; + } + StringBuffer params = new StringBuffer("?"); + for (Map.Entry entry : map.entrySet()) { + params.append(entry.getKey()); + params.append("="); + params.append(entry.getValue()); + params.append("&"); + } + String str=params.toString(); + return str.substring(0,str.length()-1); + } } diff --git a/app/src/main/java/com/youth/xf/loder/GlideImageLoader.java b/app/src/main/java/com/youth/xf/loder/GlideImageLoader.java index 7561f10..e8d4382 100644 --- a/app/src/main/java/com/youth/xf/loder/GlideImageLoader.java +++ b/app/src/main/java/com/youth/xf/loder/GlideImageLoader.java @@ -5,17 +5,46 @@ import android.widget.ImageView; import com.bumptech.glide.Glide; -import com.youth.banner.loader.ImageLoader; +import com.bumptech.glide.load.resource.bitmap.BitmapTransformation; +import com.youth.xf.view.GlideCircleTransform; import com.youth.xframe.XFrame; +import com.youth.xframe.utils.imageload.ImageLoader; -public class GlideImageLoader extends ImageLoader { +public class GlideImageLoader implements ImageLoader { + + private Context mContext; + + public static GlideCircleTransform circleTransform; + + public GlideImageLoader(Context context) { + this.mContext=context; + circleTransform=new GlideCircleTransform(mContext); + } + + @Override + public void load(ImageView imageView, Object imageUrl) { + Glide.with(mContext) + .load(imageUrl) + .crossFade() + .into(imageView); + } + + @Override + public void load(ImageView imageView, Object imageUrl, int defaultImage) { + Glide.with(mContext) + .load(imageUrl) + .crossFade() + .placeholder(defaultImage) + .into(imageView); + } + @Override - public void displayImage(Context context, Object path, ImageView imageView) { - //具体方法内容自己去选择,次方法是为了减少banner过多的依赖第三方包,所以将这个权限开放给使用者去选择 - Glide.with(XFrame.getContext()) - .load(path) + public void load(ImageView imageView, Object imageUrl, Object transformation) { + Glide.with(mContext) + .load(imageUrl) .crossFade() + .transform((BitmapTransformation) transformation) .into(imageView); } } diff --git a/app/src/main/java/com/youth/xf/ui/MainActivity.java b/app/src/main/java/com/youth/xf/ui/MainActivity.java index a6913cc..df2edee 100644 --- a/app/src/main/java/com/youth/xf/ui/MainActivity.java +++ b/app/src/main/java/com/youth/xf/ui/MainActivity.java @@ -6,15 +6,14 @@ import android.support.design.widget.TabLayout; import android.support.v4.app.Fragment; import android.support.v4.view.ViewPager; +import android.text.Html; import android.view.Menu; import android.view.MenuItem; +import android.webkit.WebView; -import com.youth.banner.Banner; import com.youth.xf.BaseActivity; import com.youth.xf.R; import com.youth.xf.ui.adapter.MyFragmentPagerAdapter; -import com.youth.xframe.XFrame; -import com.youth.xframe.utils.log.XLog; import java.util.ArrayList; import java.util.List; @@ -35,6 +34,7 @@ public void initData(Bundle savedInstanceState) { fragments=new ArrayList<>(); fragments.add(new DemoFragment()); fragments.add(new APIFragment()); + } @Override @@ -45,7 +45,6 @@ public void initView() { tabLayout.addTab(tabLayout.newTab().setText(titles[1])); viewPager.setAdapter(new MyFragmentPagerAdapter(getSupportFragmentManager(),fragments,titles)); tabLayout.setupWithViewPager(viewPager); - } @Override public boolean onCreateOptionsMenu(Menu menu) { diff --git a/app/src/main/java/com/youth/xf/ui/demo/XHttpActivity.java b/app/src/main/java/com/youth/xf/ui/demo/XHttpActivity.java index 6a77062..d82a717 100644 --- a/app/src/main/java/com/youth/xf/ui/demo/XHttpActivity.java +++ b/app/src/main/java/com/youth/xf/ui/demo/XHttpActivity.java @@ -9,11 +9,11 @@ import com.youth.xf.data.Weather; import com.youth.xframe.utils.http.HttpCallBack; import com.youth.xframe.utils.http.XHttp; -import com.youth.xframe.utils.log.XLog; +import java.io.File; +import java.util.ArrayList; import java.util.HashMap; import java.util.Map; -import java.util.Objects; public class XHttpActivity extends BaseActivity { @@ -38,10 +38,8 @@ public void onClick(View view) { request(); } - /** - * - */ public void request() { + //这里是公用接口,没有办法演示传参,谅解 String url = "http://wthrcdn.etouch.cn/weather_mini?citykey=101010100"; /** diff --git a/app/src/main/java/com/youth/xf/ui/demo/XLoadingDialogActivity.java b/app/src/main/java/com/youth/xf/ui/demo/XLoadingDialogActivity.java index 7c08f23..0985310 100644 --- a/app/src/main/java/com/youth/xf/ui/demo/XLoadingDialogActivity.java +++ b/app/src/main/java/com/youth/xf/ui/demo/XLoadingDialogActivity.java @@ -11,6 +11,7 @@ import com.youth.xf.BaseActivity; import com.youth.xf.R; import com.youth.xframe.widget.XLoadingDialog; +import com.youth.xframe.widget.XToast; public class XLoadingDialogActivity extends BaseActivity { private Handler handler=new Handler(){ @@ -42,7 +43,7 @@ public void show(View view) { XLoadingDialog.with(this).show(); break; case R.id.loading2: - Toast.makeText(this,"3秒后自动取消",Toast.LENGTH_SHORT).show(); + XToast.info("3秒后自动取消"); XLoadingDialog.with(this) .setBackgroundColor(Color.parseColor("#aa000000")) .setMessageColor(Color.WHITE) @@ -52,18 +53,20 @@ public void show(View view) { break; case R.id.loading3: XLoadingDialog.with(this) - .setOrientation(XLoadingDialog.HORIZONTAL) - .setMessage("我正在加载中...") + .setOrientation(XLoadingDialog.VERTICAL) + .setMessage("加载中...") .show(); break; case R.id.loading4: + XToast.info("3秒后自动取消"); XLoadingDialog.with(this) .setCanceled(false) - .setOrientation(XLoadingDialog.HORIZONTAL) + .setOrientation(XLoadingDialog.VERTICAL) .setBackgroundColor(Color.parseColor("#aa000000")) .setMessageColor(Color.WHITE) - .setMessage("我正在加载中...") + .setMessage("加载中...") .show(); + handler.sendEmptyMessageDelayed(1,3000); break; } diff --git a/app/src/main/java/com/youth/xf/ui/demo/XMultiTypeAdapterActivity.java b/app/src/main/java/com/youth/xf/ui/demo/XMultiTypeAdapterActivity.java index ba6dbf3..a121031 100644 --- a/app/src/main/java/com/youth/xf/ui/demo/XMultiTypeAdapterActivity.java +++ b/app/src/main/java/com/youth/xf/ui/demo/XMultiTypeAdapterActivity.java @@ -17,6 +17,7 @@ import com.youth.xf.R; import com.youth.xf.bean.News; import com.youth.xf.data.NewDataSource; +import com.youth.xf.loder.GlideImageLoader; import com.youth.xf.ui.adapter.StickyHeaderAdapter; import com.youth.xf.view.GlideCircleTransform; import com.youth.xframe.XFrame; @@ -25,6 +26,7 @@ import com.youth.xframe.adapter.decoration.DividerDecoration; import com.youth.xframe.adapter.decoration.SpaceDecoration; import com.youth.xframe.adapter.decoration.StickyHeaderDecoration; +import com.youth.xframe.utils.imageload.XImage; import java.util.ArrayList; import java.util.List; @@ -47,8 +49,11 @@ public void initView() { mSwipeLayout.setEnabled(false); RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView); recyclerView.addItemDecoration(new DividerDecoration(Color.parseColor("#f2f2f2"),15)); - recyclerView.setLayoutManager(new LinearLayoutManager(this)); + //解决NestedScrollView嵌套RecycleView的滑动冲突问题 +// recyclerView.setNestedScrollingEnabled(false); + + recyclerView.setLayoutManager(new LinearLayoutManager(this)); final MultiTypeAdapter adapter = new MultiTypeAdapter(recyclerView, NewDataSource.getNewsList()); recyclerView.setAdapter(adapter); @@ -99,12 +104,12 @@ public void bindData(XViewHolder holder, News data, int position) { holder.setText(R.id.newTitle, data.getTitle()) .setText(R.id.newAuthor,data.getAuthor()) .setText(R.id.newTime,data.getTime()); - ImageView view=holder.getView(R.id.newImage); - Glide.with(XFrame.getContext()) - .load(data.getImageUrl()) - .crossFade() - .transform(new GlideCircleTransform(XFrame.getContext())) - .into(view); + //holder.setImageUrl(R.id.newImage,data.getImageUrl(),GlideImageLoader.circleTransform) + ImageView imageView= holder.getView(R.id.newImage); + XImage.getInstance().load(imageView, + data.getImageUrl(), + GlideImageLoader.circleTransform); + break; } } diff --git a/app/src/main/java/com/youth/xf/ui/demo/XPermissionDemoActivity.java b/app/src/main/java/com/youth/xf/ui/demo/XPermissionDemoActivity.java index f911a90..e7eaee5 100644 --- a/app/src/main/java/com/youth/xf/ui/demo/XPermissionDemoActivity.java +++ b/app/src/main/java/com/youth/xf/ui/demo/XPermissionDemoActivity.java @@ -67,7 +67,6 @@ public void onClick(View view) { case R.id.button3: sendPermission(); break; - } } @@ -75,8 +74,7 @@ public void onClick(View view) { * 拨打电话 */ private void doCallPhone() { - XPermission.requestPermissions(this, 100, new String[]{Manifest.permission - .CALL_PHONE}, new XPermission.OnPermissionListener() { + XPermission.requestPermissions(this, 100,new String[]{Manifest.permission.CALL_PHONE}, new XPermission.OnPermissionListener() { //权限申请成功时调用 @Override public void onPermissionGranted() { @@ -133,4 +131,6 @@ public void onPermissionDenied() { } }); } + + } diff --git a/app/src/main/java/com/youth/xf/ui/demo/XRecyclerViewAdapterActivity.java b/app/src/main/java/com/youth/xf/ui/demo/XRecyclerViewAdapterActivity.java index 03f0c97..4bc3289 100644 --- a/app/src/main/java/com/youth/xf/ui/demo/XRecyclerViewAdapterActivity.java +++ b/app/src/main/java/com/youth/xf/ui/demo/XRecyclerViewAdapterActivity.java @@ -63,9 +63,9 @@ public void initView() { //添加分割线 recyclerView.addItemDecoration(new DividerDecoration(Color.parseColor("#C4C4C4"),1)); - recyclerView.setLayoutManager(new LinearLayoutManager(this)); -// recyclerView.setLayoutManager(new GridLayoutManager(this, 2)); -// recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)); +// recyclerView.setLayoutManager(new LinearLayoutManager(this)); +// recyclerView.setLayoutManager(new GridLayoutManager(this, 3)); + recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)); adapter = new TestAdapter(recyclerView, datas); //添加header,footer diff --git a/app/src/main/java/com/youth/xf/view/WrapContentHeightViewPager.java b/app/src/main/java/com/youth/xf/view/WrapContentHeightViewPager.java index 9baf5b2..a7e98ff 100644 --- a/app/src/main/java/com/youth/xf/view/WrapContentHeightViewPager.java +++ b/app/src/main/java/com/youth/xf/view/WrapContentHeightViewPager.java @@ -6,7 +6,9 @@ import android.view.MotionEvent; import android.view.View; - +/** + * ViewPager设置wrapContent显示全屏解决方案 + */ public class WrapContentHeightViewPager extends ViewPager { public WrapContentHeightViewPager(Context context) { super(context); diff --git a/app/src/main/res/layout/activity_xloading_dialog.xml b/app/src/main/res/layout/activity_xloading_dialog.xml index 355d559..48ef405 100644 --- a/app/src/main/res/layout/activity_xloading_dialog.xml +++ b/app/src/main/res/layout/activity_xloading_dialog.xml @@ -6,25 +6,25 @@