From 88049a201667e430bdfadc0102fe1c1436ff7d70 Mon Sep 17 00:00:00 2001 From: zjlong Date: Tue, 26 Apr 2016 11:41:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E6=B2=A1=E7=94=A8=E8=B5=84?= =?UTF-8?q?=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/encodings.xml | 2 +- app/build.gradle | 1 + app/src/main/AndroidManifest.xml | 2 +- .../com/matto/{App.java => AndroidApp.java} | 6 +- .../java/com/matto/adapter/CommonAdapter.java | 25 ++ ...{MainService.java => BaseHttpService.java} | 4 +- .../com/matto/model/http/BaseUserService.java | 8 + .../java/com/matto/model/http/Factory.java | 39 +++ .../com/matto/model/http/ServiceFactory.java | 25 -- .../matto/{ => model}/pojo/CommonRepo.java | 2 +- .../java/com/matto/{ => model}/pojo/Gank.java | 2 +- .../matto/{ => model}/pojo/GankDetails.java | 2 +- .../{model => presenter}/LoginLogic.java | 3 +- .../matto/{model => presenter}/MainLogic.java | 3 +- .../impl}/LoginLogicImpl.java | 13 +- .../impl}/MainLogicImpl.java | 3 +- .../ui/activity/AndroidSwipActivity.java | 2 +- .../com/matto/ui/activity/LoginActivity.java | 2 +- .../com/matto/ui/activity/MainActivity.java | 2 +- .../com/matto/ui/activity/SplashActivity.java | 2 +- .../com/matto/ui/adapter/MainAdapter.java | 27 -- basic/build.gradle | 7 +- .../java/com/common/BasicApplication.java | 1 - .../java/com/common/model/basic/ToastTip.java | 27 -- .../com/common/model/control/GlideProxy.java | 1 - .../com/common/model/control/LogicProxy.java | 4 - .../com/common/model/control/MvpLogic.java | 1 - .../com/common/model/http/HttpClient.java | 9 +- .../java/com/common/utils/ActivityUtils.java | 23 -- .../{view/base => utils}/StatusBarUtil.java | 2 +- .../java/com/common/utils/WebViewUtil.java | 53 ---- .../view/apdater/ArrayRecyclerAdapter.java | 295 ------------------ .../com/common/view/apdater/BasicAdapter.java | 60 ---- .../common/view/apdater/BasicViewHolder.java | 111 ------- .../view/apdater/MainFragmentAdapter.java | 47 --- .../common/view/apdater/RecyclerAdapter.java | 95 ------ .../view/apdater/RecyclerViewHolder.java | 251 --------------- .../common/view/base/SwipeBackActivity.java | 1 + .../{base => widget}/SwipeBackLayout.java | 2 +- 39 files changed, 114 insertions(+), 1051 deletions(-) rename app/src/main/java/com/matto/{App.java => AndroidApp.java} (72%) create mode 100644 app/src/main/java/com/matto/adapter/CommonAdapter.java rename app/src/main/java/com/matto/model/http/{MainService.java => BaseHttpService.java} (86%) create mode 100644 app/src/main/java/com/matto/model/http/BaseUserService.java create mode 100644 app/src/main/java/com/matto/model/http/Factory.java delete mode 100644 app/src/main/java/com/matto/model/http/ServiceFactory.java rename app/src/main/java/com/matto/{ => model}/pojo/CommonRepo.java (79%) rename app/src/main/java/com/matto/{ => model}/pojo/Gank.java (89%) rename app/src/main/java/com/matto/{ => model}/pojo/GankDetails.java (92%) rename app/src/main/java/com/matto/{model => presenter}/LoginLogic.java (81%) rename app/src/main/java/com/matto/{model => presenter}/MainLogic.java (80%) rename app/src/main/java/com/matto/{model => presenter/impl}/LoginLogicImpl.java (80%) rename app/src/main/java/com/matto/{model => presenter/impl}/MainLogicImpl.java (91%) delete mode 100644 app/src/main/java/com/matto/ui/adapter/MainAdapter.java delete mode 100644 basic/src/main/java/com/common/model/basic/ToastTip.java delete mode 100644 basic/src/main/java/com/common/utils/ActivityUtils.java rename basic/src/main/java/com/common/{view/base => utils}/StatusBarUtil.java (99%) delete mode 100644 basic/src/main/java/com/common/utils/WebViewUtil.java delete mode 100644 basic/src/main/java/com/common/view/apdater/ArrayRecyclerAdapter.java delete mode 100644 basic/src/main/java/com/common/view/apdater/BasicAdapter.java delete mode 100644 basic/src/main/java/com/common/view/apdater/BasicViewHolder.java delete mode 100644 basic/src/main/java/com/common/view/apdater/MainFragmentAdapter.java delete mode 100644 basic/src/main/java/com/common/view/apdater/RecyclerAdapter.java delete mode 100644 basic/src/main/java/com/common/view/apdater/RecyclerViewHolder.java rename basic/src/main/java/com/common/view/{base => widget}/SwipeBackLayout.java (99%) diff --git a/.idea/encodings.xml b/.idea/encodings.xml index ada076f..501d982 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -2,7 +2,7 @@ - + diff --git a/app/build.gradle b/app/build.gradle index 9725a14..e23182b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -29,4 +29,5 @@ dependencies { compile 'com.android.support:appcompat-v7:23.2.0' compile 'com.android.support:design:23.2.0' + } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1cc3bc3..96fb624 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -6,7 +6,7 @@ { + + public CommonAdapter(Context context, int layoutResId, List data) { + super(context, layoutResId, data); + } + + @Override + protected void convert(BaseAdapterHelper helper, Gank item) { + + } +} diff --git a/app/src/main/java/com/matto/model/http/MainService.java b/app/src/main/java/com/matto/model/http/BaseHttpService.java similarity index 86% rename from app/src/main/java/com/matto/model/http/MainService.java rename to app/src/main/java/com/matto/model/http/BaseHttpService.java index 46241de..ebe7530 100644 --- a/app/src/main/java/com/matto/model/http/MainService.java +++ b/app/src/main/java/com/matto/model/http/BaseHttpService.java @@ -1,7 +1,7 @@ package com.matto.model.http; -import com.matto.pojo.Gank; +import com.matto.model.pojo.Gank; import retrofit2.Call; import retrofit2.http.GET; @@ -12,7 +12,7 @@ * author miekoz on 2016/3/17. * email meikoz@126.com */ -public interface MainService { +public interface BaseHttpService { /** * 使用缓存机制 diff --git a/app/src/main/java/com/matto/model/http/BaseUserService.java b/app/src/main/java/com/matto/model/http/BaseUserService.java new file mode 100644 index 0000000..bda43e0 --- /dev/null +++ b/app/src/main/java/com/matto/model/http/BaseUserService.java @@ -0,0 +1,8 @@ +package com.matto.model.http; + +/** + * author meikoz on 2016/4/26. + * email meikoz@126.com + */ +public interface BaseUserService { +} diff --git a/app/src/main/java/com/matto/model/http/Factory.java b/app/src/main/java/com/matto/model/http/Factory.java new file mode 100644 index 0000000..d1916d6 --- /dev/null +++ b/app/src/main/java/com/matto/model/http/Factory.java @@ -0,0 +1,39 @@ +package com.matto.model.http; + +import com.common.model.http.HttpClient; +import com.matto.model.config.ApiConstant; + +import java.util.HashMap; +import java.util.Map; + + +/** + * author miekoz on 2016/3/21. + * email meikoz@126.com + */ +public class Factory { + + public static BaseUserService provideUserService() { + return provideService(BaseUserService.class); + } + + public static BaseHttpService provideHttpService() { + return provideService(BaseHttpService.class); + } + + private static Map m_service = new HashMap(); + + public static T provideService(Class cls) { + Object serv = m_service.get(cls); + if (serv == null) { + synchronized (cls) { + serv = m_service.get(cls); + if (serv == null) { + serv = HttpClient.getIns(ApiConstant.BASE_URL).createService(cls); + m_service.put(cls, serv); + } + } + } + return (T) serv; + } +} diff --git a/app/src/main/java/com/matto/model/http/ServiceFactory.java b/app/src/main/java/com/matto/model/http/ServiceFactory.java deleted file mode 100644 index 56dec21..0000000 --- a/app/src/main/java/com/matto/model/http/ServiceFactory.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.matto.model.http; - -import com.common.model.http.HttpClient; -import com.matto.model.config.ApiConstant; -import com.matto.pojo.Gank; - -import retrofit2.Call; - - -/** - * author miekoz on 2016/3/21. - * email meikoz@126.com - */ -public class ServiceFactory { - - private static MainService mService; - - public static MainService getMainIns(){ - if (mService == null){ - mService = HttpClient.getIns(ApiConstant.BASE_URL).createService(MainService.class); - } - return mService; - } - -} diff --git a/app/src/main/java/com/matto/pojo/CommonRepo.java b/app/src/main/java/com/matto/model/pojo/CommonRepo.java similarity index 79% rename from app/src/main/java/com/matto/pojo/CommonRepo.java rename to app/src/main/java/com/matto/model/pojo/CommonRepo.java index d45c6ad..3fd952f 100644 --- a/app/src/main/java/com/matto/pojo/CommonRepo.java +++ b/app/src/main/java/com/matto/model/pojo/CommonRepo.java @@ -1,4 +1,4 @@ -package com.matto.pojo; +package com.matto.model.pojo; /** * author miekoz on 2016/3/21. diff --git a/app/src/main/java/com/matto/pojo/Gank.java b/app/src/main/java/com/matto/model/pojo/Gank.java similarity index 89% rename from app/src/main/java/com/matto/pojo/Gank.java rename to app/src/main/java/com/matto/model/pojo/Gank.java index ad630d5..d973b1a 100644 --- a/app/src/main/java/com/matto/pojo/Gank.java +++ b/app/src/main/java/com/matto/model/pojo/Gank.java @@ -1,4 +1,4 @@ -package com.matto.pojo; +package com.matto.model.pojo; import java.util.List; diff --git a/app/src/main/java/com/matto/pojo/GankDetails.java b/app/src/main/java/com/matto/model/pojo/GankDetails.java similarity index 92% rename from app/src/main/java/com/matto/pojo/GankDetails.java rename to app/src/main/java/com/matto/model/pojo/GankDetails.java index 20008a2..62415d3 100644 --- a/app/src/main/java/com/matto/pojo/GankDetails.java +++ b/app/src/main/java/com/matto/model/pojo/GankDetails.java @@ -1,4 +1,4 @@ -package com.matto.pojo; +package com.matto.model.pojo; /** * author miekoz on 2016/3/17. diff --git a/app/src/main/java/com/matto/model/LoginLogic.java b/app/src/main/java/com/matto/presenter/LoginLogic.java similarity index 81% rename from app/src/main/java/com/matto/model/LoginLogic.java rename to app/src/main/java/com/matto/presenter/LoginLogic.java index fdfc44c..ecc274d 100644 --- a/app/src/main/java/com/matto/model/LoginLogic.java +++ b/app/src/main/java/com/matto/presenter/LoginLogic.java @@ -1,7 +1,8 @@ -package com.matto.model; +package com.matto.presenter; import com.common.model.control.MvpLogic; import com.common.model.annotation.Implement; +import com.matto.presenter.impl.LoginLogicImpl; import com.matto.ui.view.LoginView; diff --git a/app/src/main/java/com/matto/model/MainLogic.java b/app/src/main/java/com/matto/presenter/MainLogic.java similarity index 80% rename from app/src/main/java/com/matto/model/MainLogic.java rename to app/src/main/java/com/matto/presenter/MainLogic.java index bd22941..bbaccc3 100644 --- a/app/src/main/java/com/matto/model/MainLogic.java +++ b/app/src/main/java/com/matto/presenter/MainLogic.java @@ -1,7 +1,8 @@ -package com.matto.model; +package com.matto.presenter; import com.common.model.annotation.Implement; import com.common.model.control.MvpLogic; +import com.matto.presenter.impl.MainLogicImpl; import com.matto.ui.view.MainView; /** diff --git a/app/src/main/java/com/matto/model/LoginLogicImpl.java b/app/src/main/java/com/matto/presenter/impl/LoginLogicImpl.java similarity index 80% rename from app/src/main/java/com/matto/model/LoginLogicImpl.java rename to app/src/main/java/com/matto/presenter/impl/LoginLogicImpl.java index b9fef7a..ad13f22 100644 --- a/app/src/main/java/com/matto/model/LoginLogicImpl.java +++ b/app/src/main/java/com/matto/presenter/impl/LoginLogicImpl.java @@ -1,10 +1,11 @@ -package com.matto.model; +package com.matto.presenter.impl; import android.util.Log; -import com.matto.model.http.MainService; -import com.matto.model.http.ServiceFactory; -import com.matto.pojo.Gank; +import com.matto.model.http.BaseHttpService; +import com.matto.model.http.Factory; +import com.matto.model.pojo.Gank; +import com.matto.presenter.LoginLogic; import com.matto.ui.view.LoginView; import retrofit2.Call; @@ -17,7 +18,7 @@ */ public class LoginLogicImpl implements LoginLogic { - MainService mainService; + BaseHttpService mainService; LoginView mView; @Override @@ -43,7 +44,7 @@ public void onFailure(Call call, Throwable t) { @Override public void attachView(LoginView mvpView) { this.mView = mvpView; - this.mainService = ServiceFactory.getMainIns(); + this.mainService = Factory.getMainIns(); } } diff --git a/app/src/main/java/com/matto/model/MainLogicImpl.java b/app/src/main/java/com/matto/presenter/impl/MainLogicImpl.java similarity index 91% rename from app/src/main/java/com/matto/model/MainLogicImpl.java rename to app/src/main/java/com/matto/presenter/impl/MainLogicImpl.java index 3369dda..2992dcd 100644 --- a/app/src/main/java/com/matto/model/MainLogicImpl.java +++ b/app/src/main/java/com/matto/presenter/impl/MainLogicImpl.java @@ -1,6 +1,7 @@ -package com.matto.model; +package com.matto.presenter.impl; import com.matto.R; +import com.matto.presenter.MainLogic; import com.matto.ui.view.MainView; /** diff --git a/app/src/main/java/com/matto/ui/activity/AndroidSwipActivity.java b/app/src/main/java/com/matto/ui/activity/AndroidSwipActivity.java index eb931d6..0b9ad63 100644 --- a/app/src/main/java/com/matto/ui/activity/AndroidSwipActivity.java +++ b/app/src/main/java/com/matto/ui/activity/AndroidSwipActivity.java @@ -3,7 +3,7 @@ import android.os.Bundle; import com.common.view.base.SwipeBackActivity; -import com.common.view.base.SwipeBackLayout; +import com.common.view.widget.SwipeBackLayout; import com.matto.R; /** diff --git a/app/src/main/java/com/matto/ui/activity/LoginActivity.java b/app/src/main/java/com/matto/ui/activity/LoginActivity.java index 52f688e..528adfb 100644 --- a/app/src/main/java/com/matto/ui/activity/LoginActivity.java +++ b/app/src/main/java/com/matto/ui/activity/LoginActivity.java @@ -9,7 +9,7 @@ import com.matto.ui.widget.TitleBar; import com.matto.R; import com.common.model.control.LogicProxy; -import com.matto.model.LoginLogic; +import com.matto.presenter.LoginLogic; import com.matto.ui.view.LoginView; import butterknife.Bind; diff --git a/app/src/main/java/com/matto/ui/activity/MainActivity.java b/app/src/main/java/com/matto/ui/activity/MainActivity.java index bffdfcd..3f7707c 100644 --- a/app/src/main/java/com/matto/ui/activity/MainActivity.java +++ b/app/src/main/java/com/matto/ui/activity/MainActivity.java @@ -9,7 +9,7 @@ import com.common.model.control.LogicProxy; import com.common.view.base.BaseActivity; import com.matto.R; -import com.matto.model.MainLogic; +import com.matto.presenter.MainLogic; import com.matto.ui.fragment.DiscoveryFragment; import com.matto.ui.fragment.HomeFragment; import com.matto.ui.fragment.ShowMeFragment; diff --git a/app/src/main/java/com/matto/ui/activity/SplashActivity.java b/app/src/main/java/com/matto/ui/activity/SplashActivity.java index 96c293c..a31866f 100644 --- a/app/src/main/java/com/matto/ui/activity/SplashActivity.java +++ b/app/src/main/java/com/matto/ui/activity/SplashActivity.java @@ -6,7 +6,7 @@ import android.widget.ImageView; import com.common.view.base.BaseActivity; -import com.common.view.base.StatusBarUtil; +import com.common.utils.StatusBarUtil; import com.matto.R; import com.matto.util.AnimationUtil; diff --git a/app/src/main/java/com/matto/ui/adapter/MainAdapter.java b/app/src/main/java/com/matto/ui/adapter/MainAdapter.java deleted file mode 100644 index dfcba9a..0000000 --- a/app/src/main/java/com/matto/ui/adapter/MainAdapter.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.matto.ui.adapter; - -import android.content.Context; - -import com.common.view.apdater.BasicAdapter; -import com.common.view.apdater.BasicViewHolder; -import com.matto.R; -import com.matto.pojo.GankDetails; - -import java.util.List; - -/** - * author miekoz on 2016/3/18. - * email meikoz@126.com - */ -public class MainAdapter extends BasicAdapter { - - public MainAdapter(Context context, List mDatas, int itemLayoutId) { - super(context, mDatas, itemLayoutId); - } - - @Override - public void convert(BasicViewHolder helper, GankDetails item) { - helper.setText(R.id.tv_test, item.desc); - } - -} diff --git a/basic/build.gradle b/basic/build.gradle index 3bfe319..33646b7 100644 --- a/basic/build.gradle +++ b/basic/build.gradle @@ -26,9 +26,15 @@ dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.2.0' + + // butter knife compile 'com.android.support:recyclerview-v7:23.2.0' compile 'com.jakewharton:butterknife:7.0.1' + //adapter + compile 'com.joanzapata.android:base-adapter-helper:1.1.11' + + //squareup compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4' compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0-beta4' compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4' @@ -36,5 +42,4 @@ dependencies { // Glide compile 'com.github.bumptech.glide:glide:3.7.0' - compile files('libs/BaiduLBS_Android.jar') } diff --git a/basic/src/main/java/com/common/BasicApplication.java b/basic/src/main/java/com/common/BasicApplication.java index 711df6d..b419b81 100644 --- a/basic/src/main/java/com/common/BasicApplication.java +++ b/basic/src/main/java/com/common/BasicApplication.java @@ -27,5 +27,4 @@ public void onCreate() { mContext = getApplicationContext(); } - } diff --git a/basic/src/main/java/com/common/model/basic/ToastTip.java b/basic/src/main/java/com/common/model/basic/ToastTip.java deleted file mode 100644 index dfaf997..0000000 --- a/basic/src/main/java/com/common/model/basic/ToastTip.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.common.model.basic; - -import android.widget.Toast; - -import com.common.BasicApplication; - -/** - * author meikoz on 2016/4/13. - * email meikoz@126.com - */ -public class ToastTip { - - static Toast mToast; - - public static void show(CharSequence message) { - if (mToast == null) { - int duration = Toast.LENGTH_SHORT; - if (message.length() > 10) { - duration = Toast.LENGTH_LONG; - } - mToast = Toast.makeText(BasicApplication.getInstance(), message, duration); - } else { - mToast.setText(message); - } - mToast.show(); - } -} diff --git a/basic/src/main/java/com/common/model/control/GlideProxy.java b/basic/src/main/java/com/common/model/control/GlideProxy.java index a6449ce..080c1a7 100644 --- a/basic/src/main/java/com/common/model/control/GlideProxy.java +++ b/basic/src/main/java/com/common/model/control/GlideProxy.java @@ -86,5 +86,4 @@ public void loadCircleLocalImage(Context context, String path, ImageView imageVi .into(imageView); } - } diff --git a/basic/src/main/java/com/common/model/control/LogicProxy.java b/basic/src/main/java/com/common/model/control/LogicProxy.java index 85e68c3..5c79d17 100644 --- a/basic/src/main/java/com/common/model/control/LogicProxy.java +++ b/basic/src/main/java/com/common/model/control/LogicProxy.java @@ -1,7 +1,5 @@ package com.common.model.control; -import android.util.Log; - import com.common.model.annotation.Implement; import java.lang.annotation.Annotation; @@ -25,7 +23,6 @@ private LogicProxy() { } private Map m_objects; - //private Object m_proxy; public void init(Class... clss) { List list = new LinkedList(); @@ -48,7 +45,6 @@ public void init(Class... clss) { } public T getProxy(Class cls) { - //return (T) m_proxy; return (T) m_objects.get(cls); } diff --git a/basic/src/main/java/com/common/model/control/MvpLogic.java b/basic/src/main/java/com/common/model/control/MvpLogic.java index 9ee1185..b6c27eb 100644 --- a/basic/src/main/java/com/common/model/control/MvpLogic.java +++ b/basic/src/main/java/com/common/model/control/MvpLogic.java @@ -5,6 +5,5 @@ * email meikoz@126.com */ public interface MvpLogic { - void attachView(T mvpView); } diff --git a/basic/src/main/java/com/common/model/http/HttpClient.java b/basic/src/main/java/com/common/model/http/HttpClient.java index 50c0b82..f23a834 100644 --- a/basic/src/main/java/com/common/model/http/HttpClient.java +++ b/basic/src/main/java/com/common/model/http/HttpClient.java @@ -1,6 +1,8 @@ package com.common.model.http; import com.common.BasicApplication; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import java.io.File; import java.util.concurrent.TimeUnit; @@ -19,7 +21,7 @@ public class HttpClient { private static HttpClient mInstance; - private Retrofit retrofit; + private Retrofit singleton; public static HttpClient getIns(String base_url) { if (mInstance == null) { @@ -46,8 +48,7 @@ public HttpClient(String BASE_URL) { .cache(cache) .build(); - - retrofit = new Retrofit.Builder() + singleton = new Retrofit.Builder() .baseUrl(BASE_URL) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .addConverterFactory(GsonConverterFactory.create()) @@ -56,6 +57,6 @@ public HttpClient(String BASE_URL) { } public T createService(Class clz) { - return retrofit.create(clz); + return singleton.create(clz); } } diff --git a/basic/src/main/java/com/common/utils/ActivityUtils.java b/basic/src/main/java/com/common/utils/ActivityUtils.java deleted file mode 100644 index 85dfaee..0000000 --- a/basic/src/main/java/com/common/utils/ActivityUtils.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.common.utils; - -import android.support.annotation.NonNull; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentTransaction; - -/** - * author meikoz on 2016/4/14. - * email meikoz@126.com - */ -public class ActivityUtils { - - public static void addFragmentToActivity(@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment, int frameId) { - - if (fragment == null || fragment == fragmentManager.findFragmentById(frameId)) - return; - - FragmentTransaction transaction = fragmentManager.beginTransaction(); - transaction.replace(frameId, fragment); - transaction.commit(); - } -} diff --git a/basic/src/main/java/com/common/view/base/StatusBarUtil.java b/basic/src/main/java/com/common/utils/StatusBarUtil.java similarity index 99% rename from basic/src/main/java/com/common/view/base/StatusBarUtil.java rename to basic/src/main/java/com/common/utils/StatusBarUtil.java index 2345d86..387aee8 100644 --- a/basic/src/main/java/com/common/view/base/StatusBarUtil.java +++ b/basic/src/main/java/com/common/utils/StatusBarUtil.java @@ -1,4 +1,4 @@ -package com.common.view.base; +package com.common.utils; import android.annotation.TargetApi; import android.app.Activity; diff --git a/basic/src/main/java/com/common/utils/WebViewUtil.java b/basic/src/main/java/com/common/utils/WebViewUtil.java deleted file mode 100644 index 5409f8f..0000000 --- a/basic/src/main/java/com/common/utils/WebViewUtil.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.common.utils; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.os.Build; -import android.util.Base64; -import android.webkit.WebSettings; -import android.webkit.WebView; - -import java.io.InputStream; - -/** - * author miekoz on 2016/3/15. - * email meikoz@126.com - */ -public class WebViewUtil { - - // Inject CSS method: read style.css from assets folder - // Append stylesheet to document head - @SuppressLint("SetJavaScriptEnabled") - public static void injectCss(Context context, WebView webView, String filename) { - try { - webView.getSettings().setJavaScriptEnabled(true); - webView.getSettings().setAllowFileAccess(true); - webView.getSettings().setDatabaseEnabled(true); - webView.getSettings().setDomStorageEnabled(true); - webView.getSettings().setSaveFormData(false); - webView.getSettings().setAppCacheEnabled(true); - webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); - webView.getSettings().setLoadWithOverviewMode(false); - webView.getSettings().setUseWideViewPort(true); - InputStream inputStream = context.getAssets().open(filename); - byte[] buffer = new byte[inputStream.available()]; - inputStream.read(buffer); - inputStream.close(); - String encoded = Base64.encodeToString(buffer, Base64.NO_WRAP); - webView.loadUrl("javascript:(function() {" + - "var parent = document.getElementsByTagName('head').item(0);" + - "var style = document.createElement('style');" + - "style.type = 'text/css';" + - // Tell the browser to BASE64-decode the string into your script !!! - "style.innerHTML = window.atob('" + encoded + "');" + - "parent.appendChild(style)" + - "})()"); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - WebView.setWebContentsDebuggingEnabled(true); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - -} diff --git a/basic/src/main/java/com/common/view/apdater/ArrayRecyclerAdapter.java b/basic/src/main/java/com/common/view/apdater/ArrayRecyclerAdapter.java deleted file mode 100644 index d14b83c..0000000 --- a/basic/src/main/java/com/common/view/apdater/ArrayRecyclerAdapter.java +++ /dev/null @@ -1,295 +0,0 @@ -package com.common.view.apdater; - -import android.support.annotation.NonNull; -import android.support.v7.widget.RecyclerView; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.Objects; - -/** - * author miekoz on 2016/3/21. - * email meikoz@126.com - */ -public abstract class ArrayRecyclerAdapter - extends RecyclerView.Adapter implements List { - - private final Object lock = new Object(); - - private final List list; - - @SuppressWarnings("unused") - public ArrayRecyclerAdapter() { - list = new ArrayList<>(); - } - - @SuppressWarnings("unused") - public ArrayRecyclerAdapter(int capacity) { - list = new ArrayList<>(capacity); - } - - @SuppressWarnings("unused") - public ArrayRecyclerAdapter(Collection collection) { - list = new ArrayList<>(collection); - } - - @Override - public int getItemCount() { - return size(); - } - - @Override - public void add(int location, E object) { - synchronized (lock) { - list.add(location, object); - notifyItemInserted(location); - } - } - - @Override - public boolean add(E object) { - synchronized (lock) { - int lastIndex = list.size(); - if (list.add(object)) { - notifyItemInserted(lastIndex); - return true; - } else { - return false; - } - } - } - - @Override - public boolean addAll(int location, @NonNull Collection collection) { - synchronized (lock) { - if (list.addAll(location, collection)) { - notifyItemRangeInserted(location, collection.size()); - return true; - } else { - return false; - } - } - } - - @Override - public boolean addAll(@NonNull Collection collection) { - synchronized (lock) { - int lastIndex = list.size(); - if (list.addAll(collection)) { - notifyItemRangeInserted(lastIndex, collection.size()); - return true; - } else { - return false; - } - } - } - - @Override - public void clear() { - synchronized (lock) { - int size = list.size(); - if (size > 0) { - list.clear(); - notifyItemRangeRemoved(0, size); - } - } - } - - @Override - public boolean contains(Object object) { - return list.contains(object); - } - - @Override - public boolean containsAll(@NonNull Collection collection) { - return list.containsAll(collection); - } - - @Override - public E get(int location) { - return list.get(location); - } - - @Override - public int indexOf(Object object) { - return list.indexOf(object); - } - - @Override - public boolean isEmpty() { - return list.isEmpty(); - } - - @NonNull - @Override - public Iterator iterator() { - return list.iterator(); - } - - @Override - public int lastIndexOf(Object object) { - return list.lastIndexOf(object); - } - - @NonNull - @Override - public ListIterator listIterator() { - return list.listIterator(); - } - - @NonNull - @Override - public ListIterator listIterator(int location) { - return list.listIterator(location); - } - - @Override - public E remove(int location) { - synchronized (lock) { - E item = list.remove(location); - notifyItemRemoved(location); - return item; - } - } - - @Override - public boolean remove(Object object) { - synchronized (lock) { - int index = indexOf(object); - if (list.remove(object)) { - notifyItemRemoved(index); - return true; - } else { - return false; - } - } - } - - @Override - public boolean removeAll(@NonNull Collection collection) { - boolean modified = false; - - Iterator iterator = list.iterator(); - while (iterator.hasNext()) { - Object object = iterator.next(); - if (collection.contains(object)) { - synchronized (lock) { - int index = indexOf(object); - iterator.remove(); - notifyItemRemoved(index); - } - - modified = true; - } - } - - return modified; - } - - @Override - public boolean retainAll(@NonNull Collection collection) { - boolean modified = false; - - Iterator iterator = list.iterator(); - while (iterator.hasNext()) { - Object object = iterator.next(); - if (!collection.contains(object)) { - synchronized (lock) { - int index = indexOf(object); - iterator.remove(); - notifyItemRemoved(index); - } - - modified = true; - } - } - - return modified; - } - - @Override - public E set(int location, E object) { - synchronized (lock) { - E origin = list.set(location, object); - if (!Objects.equals(object, origin)) { - notifyItemChanged(location); - } - return origin; - } - } - - @Override - public int size() { - return list.size(); - } - - @NonNull - @Override - public List subList(int start, int end) { - return list.subList(start, end); - } - - @NonNull - @Override - public Object[] toArray() { - return list.toArray(); - } - - @NonNull - @Override - @SuppressWarnings("SuspiciousToArrayCall") - public T[] toArray(@NonNull T[] array) { - return list.toArray(array); - } - - public void replaceWith(List data) { - if (list.isEmpty() && data.isEmpty()) { - return; - } - - if (list.isEmpty()) { - addAll(data); - return; - } - - if (data.isEmpty()) { - clear(); - return; - } - - if (list.equals(data)) { - return; - } - - // 首先将旧列表有、新列表没有的从旧列表去除 - retainAll(data); - - // 如果列表被完全清空了,那就直接全部插入好了 - if (list.isEmpty()) { - addAll(data); - return; - } - - // 然后遍历新列表,对旧列表的数据更新、移动、增加 - for (int indexNew = 0; indexNew < data.size(); indexNew++) { - E item = data.get(indexNew); - - int indexOld = indexOf(item); - - if (indexOld == -1) { - add(indexNew, item); - } else if (indexOld == indexNew) { - set(indexNew, item); - } else { - list.remove(indexOld); - list.add(indexNew, item); - notifyItemMoved(indexOld, indexNew); - } - } - } - -} - diff --git a/basic/src/main/java/com/common/view/apdater/BasicAdapter.java b/basic/src/main/java/com/common/view/apdater/BasicAdapter.java deleted file mode 100644 index 02d1d5b..0000000 --- a/basic/src/main/java/com/common/view/apdater/BasicAdapter.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.common.view.apdater; - -import android.content.Context; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.BaseAdapter; - -import java.util.List; - -/** - * author miekoz on 2016/3/17. - * email meikoz@126.com - */ -public abstract class BasicAdapter extends BaseAdapter { - protected LayoutInflater mInflater; - protected Context mContext; - protected List mDatas; - protected final int mItemLayoutId; - - public BasicAdapter(Context context, List mDatas, int itemLayoutId) { - this.mContext = context; - this.mInflater = LayoutInflater.from(mContext); - this.mDatas = mDatas; - this.mItemLayoutId = itemLayoutId; - } - - @Override - public int getCount() { - return mDatas.size(); - } - - @Override - public T getItem(int position) { - return mDatas.get(position); - } - - @Override - public long getItemId(int position) { - return position; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - final BasicViewHolder viewHolder = getViewHolder(position, convertView, - parent); - convert(viewHolder, getItem(position)); - return viewHolder.getConvertView(); - - } - - public abstract void convert(BasicViewHolder helper, T item); - - private BasicViewHolder getViewHolder(int position, View convertView, - ViewGroup parent) { - return BasicViewHolder.get(mContext, convertView, parent, mItemLayoutId, - position); - } - -} \ No newline at end of file diff --git a/basic/src/main/java/com/common/view/apdater/BasicViewHolder.java b/basic/src/main/java/com/common/view/apdater/BasicViewHolder.java deleted file mode 100644 index bf6559d..0000000 --- a/basic/src/main/java/com/common/view/apdater/BasicViewHolder.java +++ /dev/null @@ -1,111 +0,0 @@ -package com.common.view.apdater; - -import android.content.Context; -import android.graphics.Bitmap; -import android.util.SparseArray; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; - -/** - * author meikoz on 2016/4/14. - * email meikoz@126.com - */ -public class BasicViewHolder { - private final SparseArray mViews; - private int mPosition; - private View mConvertView; - - private BasicViewHolder(Context context, ViewGroup parent, int layoutId, - int position) { - this.mPosition = position; - this.mViews = new SparseArray(); - mConvertView = LayoutInflater.from(context).inflate(layoutId, parent, - false); - // setTag - mConvertView.setTag(this); - } - - /** - * 拿到一个ViewHolder对象 - * - * @param context - * @param convertView - * @param parent - * @param layoutId - * @param position - * @return - */ - public static BasicViewHolder get(Context context, View convertView, - ViewGroup parent, int layoutId, int position) { - if (convertView == null) { - return new BasicViewHolder(context, parent, layoutId, position); - } - return (BasicViewHolder) convertView.getTag(); - } - - public View getConvertView() { - return mConvertView; - } - - /** - * 通过控件的Id获取对于的控件,如果没有则加入views - * - * @param viewId - * @return - */ - public T getView(int viewId) { - View view = mViews.get(viewId); - if (view == null) { - view = mConvertView.findViewById(viewId); - mViews.put(viewId, view); - } - return (T) view; - } - - /** - * 为TextView设置字符串 - * - * @param viewId - * @param text - * @return - */ - public BasicViewHolder setText(int viewId, String text) { - TextView view = getView(viewId); - view.setText(text); - return this; - } - - /** - * 为ImageView设置图片 - * - * @param viewId - * @param drawableId - * @return - */ - public BasicViewHolder setImageResource(int viewId, int drawableId) { - ImageView view = getView(viewId); - view.setImageResource(drawableId); - - return this; - } - - /** - * 为ImageView设置图片 - * - * @param viewId - * @param - * @return - */ - public BasicViewHolder setImageBitmap(int viewId, Bitmap bm) { - ImageView view = getView(viewId); - view.setImageBitmap(bm); - return this; - } - - public int getPosition() { - return mPosition; - } -} diff --git a/basic/src/main/java/com/common/view/apdater/MainFragmentAdapter.java b/basic/src/main/java/com/common/view/apdater/MainFragmentAdapter.java deleted file mode 100644 index a732525..0000000 --- a/basic/src/main/java/com/common/view/apdater/MainFragmentAdapter.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.common.view.apdater; - -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentPagerAdapter; - -import java.util.ArrayList; -import java.util.List; - -/** - * author miekoz on 2016/3/21. - * email meikoz@126.com - */ -public class MainFragmentAdapter extends FragmentPagerAdapter { - - private final List mFragments = new ArrayList<>(); - private final List mFragmentTitles = new ArrayList<>(); - - public MainFragmentAdapter(FragmentManager fm) { - super(fm); - } - - public void MainFragmentPagerAdapter(Fragment fragment, String title) { - mFragments.add(fragment); - mFragmentTitles.add(title); - } - - public void addFragment(Fragment fragment, String title) { - mFragments.add(fragment); - mFragmentTitles.add(title); - } - - @Override - public Fragment getItem(int position) { - return mFragments.get(position); - } - - @Override - public int getCount() { - return mFragments.size(); - } - - @Override - public CharSequence getPageTitle(int position) { - return mFragmentTitles.get(position); - } -} diff --git a/basic/src/main/java/com/common/view/apdater/RecyclerAdapter.java b/basic/src/main/java/com/common/view/apdater/RecyclerAdapter.java deleted file mode 100644 index 761ecfa..0000000 --- a/basic/src/main/java/com/common/view/apdater/RecyclerAdapter.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.common.view.apdater; - -import android.content.Context; -import android.support.v7.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - - -import java.util.List; - -/** - * Created by zhy on 16/4/9. - */ -public abstract class RecyclerAdapter extends RecyclerView.Adapter { - protected Context mContext; - protected int mLayoutId; - protected List mDatas; - protected LayoutInflater mInflater; - - private OnItemClickListener mOnItemClickListener; - - public void setOnItemClickListener(OnItemClickListener onItemClickListener) { - this.mOnItemClickListener = onItemClickListener; - } - - public RecyclerAdapter(Context context, int layoutId, List datas) { - mContext = context; - mInflater = LayoutInflater.from(context); - mLayoutId = layoutId; - mDatas = datas; - } - - @Override - public RecyclerViewHolder onCreateViewHolder(final ViewGroup parent, int viewType) { - RecyclerViewHolder viewHolder = RecyclerViewHolder.get(mContext, null, parent, mLayoutId, -1); - setListener(parent, viewHolder, viewType); - return viewHolder; - } - - protected int getPosition(RecyclerViewHolder viewHolder) { - return viewHolder.getAdapterPosition(); - } - - protected boolean isEnabled(int viewType) { - return true; - } - - - protected void setListener(final ViewGroup parent, final RecyclerViewHolder viewHolder, int viewType) { - if (!isEnabled(viewType)) return; - viewHolder.getConvertView().setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (mOnItemClickListener != null) { - int position = getPosition(viewHolder); - mOnItemClickListener.onItemClick(parent, v, mDatas.get(position), position); - } - } - }); - - - viewHolder.getConvertView().setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - if (mOnItemClickListener != null) { - int position = getPosition(viewHolder); - return mOnItemClickListener.onItemLongClick(parent, v, mDatas.get(position), position); - } - return false; - } - }); - } - - @Override - public void onBindViewHolder(RecyclerViewHolder holder, int position) { - holder.updatePosition(position); - convert(holder, mDatas.get(position)); - } - - public abstract void convert(RecyclerViewHolder holder, T t); - - @Override - public int getItemCount() { - return mDatas.size(); - } - - - interface OnItemClickListener { - void onItemClick(ViewGroup parent, View view, T t, int position); - - boolean onItemLongClick(ViewGroup parent, View view, T t, int position); - } - -} \ No newline at end of file diff --git a/basic/src/main/java/com/common/view/apdater/RecyclerViewHolder.java b/basic/src/main/java/com/common/view/apdater/RecyclerViewHolder.java deleted file mode 100644 index 387917b..0000000 --- a/basic/src/main/java/com/common/view/apdater/RecyclerViewHolder.java +++ /dev/null @@ -1,251 +0,0 @@ -package com.common.view.apdater; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.Paint; -import android.graphics.Typeface; -import android.graphics.drawable.Drawable; -import android.os.Build; -import android.support.v7.widget.RecyclerView; -import android.text.util.Linkify; -import android.util.SparseArray; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.view.animation.AlphaAnimation; -import android.widget.Checkable; -import android.widget.ImageView; -import android.widget.ProgressBar; -import android.widget.RatingBar; -import android.widget.TextView; - -/** - * author meikoz on 2016/4/14. - * email meikoz@126.com - */ -public class RecyclerViewHolder extends RecyclerView.ViewHolder { - private SparseArray mViews; - private int mPosition; - private View mConvertView; - private Context mContext; - private int mLayoutId; - - public RecyclerViewHolder(Context context, View itemView, ViewGroup parent, int position) { - super(itemView); - mContext = context; - mConvertView = itemView; - mPosition = position; - mViews = new SparseArray(); - mConvertView.setTag(this); - - } - - - public static RecyclerViewHolder get(Context context, View convertView, - ViewGroup parent, int layoutId, int position) { - if (convertView == null) { - View itemView = LayoutInflater.from(context).inflate(layoutId, parent, - false); - RecyclerViewHolder holder = new RecyclerViewHolder(context, itemView, parent, position); - holder.mLayoutId = layoutId; - return holder; - } else { - RecyclerViewHolder holder = (RecyclerViewHolder) convertView.getTag(); - holder.mPosition = position; - return holder; - } - } - - - /** - * 通过viewId获取控件 - * - * @param viewId - * @return - */ - public T getView(int viewId) { - View view = mViews.get(viewId); - if (view == null) { - view = mConvertView.findViewById(viewId); - mViews.put(viewId, view); - } - return (T) view; - } - - public View getConvertView() { - return mConvertView; - } - - /** - * 设置TextView的值 - * - * @param viewId - * @param text - * @return - */ - public RecyclerViewHolder setText(int viewId, String text) { - TextView tv = getView(viewId); - tv.setText(text); - return this; - } - - public RecyclerViewHolder setImageResource(int viewId, int resId) { - ImageView view = getView(viewId); - view.setImageResource(resId); - return this; - } - - public RecyclerViewHolder setImageBitmap(int viewId, Bitmap bitmap) { - ImageView view = getView(viewId); - view.setImageBitmap(bitmap); - return this; - } - - public RecyclerViewHolder setImageDrawable(int viewId, Drawable drawable) { - ImageView view = getView(viewId); - view.setImageDrawable(drawable); - return this; - } - - public RecyclerViewHolder setBackgroundColor(int viewId, int color) { - View view = getView(viewId); - view.setBackgroundColor(color); - return this; - } - - public RecyclerViewHolder setBackgroundRes(int viewId, int backgroundRes) { - View view = getView(viewId); - view.setBackgroundResource(backgroundRes); - return this; - } - - public RecyclerViewHolder setTextColor(int viewId, int textColor) { - TextView view = getView(viewId); - view.setTextColor(textColor); - return this; - } - - public RecyclerViewHolder setTextColorRes(int viewId, int textColorRes) { - TextView view = getView(viewId); - view.setTextColor(mContext.getResources().getColor(textColorRes)); - return this; - } - - @SuppressLint("NewApi") - public RecyclerViewHolder setAlpha(int viewId, float value) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - getView(viewId).setAlpha(value); - } else { - // Pre-honeycomb hack to set Alpha value - AlphaAnimation alpha = new AlphaAnimation(value, value); - alpha.setDuration(0); - alpha.setFillAfter(true); - getView(viewId).startAnimation(alpha); - } - return this; - } - - public RecyclerViewHolder setVisible(int viewId, boolean visible) { - View view = getView(viewId); - view.setVisibility(visible ? View.VISIBLE : View.GONE); - return this; - } - - public RecyclerViewHolder linkify(int viewId) { - TextView view = getView(viewId); - Linkify.addLinks(view, Linkify.ALL); - return this; - } - - public RecyclerViewHolder setTypeface(Typeface typeface, int... viewIds) { - for (int viewId : viewIds) { - TextView view = getView(viewId); - view.setTypeface(typeface); - view.setPaintFlags(view.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG); - } - return this; - } - - public RecyclerViewHolder setProgress(int viewId, int progress) { - ProgressBar view = getView(viewId); - view.setProgress(progress); - return this; - } - - public RecyclerViewHolder setProgress(int viewId, int progress, int max) { - ProgressBar view = getView(viewId); - view.setMax(max); - view.setProgress(progress); - return this; - } - - public RecyclerViewHolder setMax(int viewId, int max) { - ProgressBar view = getView(viewId); - view.setMax(max); - return this; - } - - public RecyclerViewHolder setRating(int viewId, float rating) { - RatingBar view = getView(viewId); - view.setRating(rating); - return this; - } - - public RecyclerViewHolder setRating(int viewId, float rating, int max) { - RatingBar view = getView(viewId); - view.setMax(max); - view.setRating(rating); - return this; - } - - public RecyclerViewHolder setTag(int viewId, Object tag) { - View view = getView(viewId); - view.setTag(tag); - return this; - } - - public RecyclerViewHolder setTag(int viewId, int key, Object tag) { - View view = getView(viewId); - view.setTag(key, tag); - return this; - } - - public RecyclerViewHolder setChecked(int viewId, boolean checked) { - Checkable view = (Checkable) getView(viewId); - view.setChecked(checked); - return this; - } - - /** - * 关于事件的 - */ - public RecyclerViewHolder setOnClickListener(int viewId, - View.OnClickListener listener) { - View view = getView(viewId); - view.setOnClickListener(listener); - return this; - } - - public RecyclerViewHolder setOnTouchListener(int viewId, - View.OnTouchListener listener) { - View view = getView(viewId); - view.setOnTouchListener(listener); - return this; - } - - public RecyclerViewHolder setOnLongClickListener(int viewId, - View.OnLongClickListener listener) { - View view = getView(viewId); - view.setOnLongClickListener(listener); - return this; - } - - public void updatePosition(int position) { - mPosition = position; - } - - public int getLayoutId() { - return mLayoutId; - } -} diff --git a/basic/src/main/java/com/common/view/base/SwipeBackActivity.java b/basic/src/main/java/com/common/view/base/SwipeBackActivity.java index 718ac48..e8c2698 100644 --- a/basic/src/main/java/com/common/view/base/SwipeBackActivity.java +++ b/basic/src/main/java/com/common/view/base/SwipeBackActivity.java @@ -10,6 +10,7 @@ import android.widget.RelativeLayout.LayoutParams; import com.common.R; +import com.common.view.widget.SwipeBackLayout; /** * Created by Eric on 15/3/3. diff --git a/basic/src/main/java/com/common/view/base/SwipeBackLayout.java b/basic/src/main/java/com/common/view/widget/SwipeBackLayout.java similarity index 99% rename from basic/src/main/java/com/common/view/base/SwipeBackLayout.java rename to basic/src/main/java/com/common/view/widget/SwipeBackLayout.java index e03cb0c..5de3147 100644 --- a/basic/src/main/java/com/common/view/base/SwipeBackLayout.java +++ b/basic/src/main/java/com/common/view/widget/SwipeBackLayout.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.common.view.base; +package com.common.view.widget; import android.app.Activity; import android.content.Context;