From 92f605bca9aac93384c29624af1b5d491e4d32ec Mon Sep 17 00:00:00 2001 From: Zhanty Date: Thu, 19 Sep 2019 16:36:05 +0800 Subject: [PATCH] optimize code --- lib_base/build.gradle | 1 + .../com/android/base/adapter/DataManager.java | 18 +-- .../com/android/base/adapter/ItemHelper.java | 6 +- .../base/adapter/list/BaseListAdapter.java | 21 +-- .../adapter/list/ListDataManagerImpl.java | 7 +- .../base/adapter/list/SmartViewHolder.java | 4 +- .../android/base/adapter/list/ViewHolder.java | 2 +- .../pager/{recycler => }/RecycleBin.java | 6 +- .../{recycler => }/RecyclingPagerAdapter.java | 13 +- .../base/adapter/pager/ViewPagerAdapter.java | 5 +- .../adapter/recycler/DiffRecyclerAdapter.java | 11 +- .../adapter/recycler/MultiTypeAdapter.java | 8 +- .../adapter/recycler/RecyclerAdapter.java | 15 +- .../recycler/RecyclerDataManagerImpl.java | 2 +- .../adapter/recycler/SimpleRecyclerAdapter.kt | 4 +- .../adapter/recycler/SmartViewHolder.java | 3 +- .../android/base/app/ApplicationDelegate.java | 2 +- .../com/android/base/app/BaseAppContext.java | 12 +- .../com/android/base/app/CrashHandler.java | 4 +- .../base/app/{BaseKit.java => Sword.java} | 33 ++-- .../android/base/app/aac/SingleLiveData.java | 1 - .../base/app/activity/BaseActivity.java | 6 +- .../base/app/fragment/BaseDialogFragment.java | 8 +- .../base/app/fragment/BaseFragment.java | 8 +- .../base/app/fragment/FragmentInfo.java | 5 +- .../android/base/app/fragment/Fragments.kt | 24 +-- .../main/java/com/android/base/app/ui/UIEx.kt | 8 +- .../java/com/android/base/data/Resource.java | 152 ------------------ .../java/com/android/base/data/Resource.kt | 130 +++++++++++++++ .../base/data/{Status.java => Status.kt} | 6 +- .../base/imageloader/DisplayConfig.java | 1 - .../ActivityLifecycleCallbacksAdapter.java | 2 +- .../{adapter => }/DrawerListenerAdapter.java | 2 +- .../OnPageChangeListenerAdapter.java | 2 +- .../OnSeekBarChangeListenerAdapter.java | 2 +- .../OnTabSelectedListenerAdapter.java | 2 +- .../{adapter => }/TextWatcherAdapter.java | 2 +- .../TransitionListenerAdapter.java | 2 +- .../base/utils/android/SoftKeyboardUtils.java | 3 +- .../base/utils/android/VideoUtils.java | 2 +- .../base/utils/android/WebViewUtils.java | 2 +- .../base/utils/android/WindowUtils.java | 5 +- .../base/utils/android/XIntentUtils.java | 2 +- .../base/utils/android/views/ListViewEx.kt | 15 ++ .../base/utils/android/views/TextViewEx.kt | 2 +- .../base/utils/android/views/TintUtils.kt | 2 +- .../base/utils/android/views/ViewEx.kt | 52 ++++-- .../widget/ScrollChildSwipeRefreshLayout.java | 2 +- .../pulltozoom/PullToZoomScrollView.java | 3 +- .../{ZViewPager.java => BannerViewPager.java} | 16 +- .../widget/viewpager/IPagerNumberView.java | 2 +- .../base/widget/viewpager/PageNumberView.kt | 2 +- lib_base/src/main/res/values/base_attrs.xml | 5 +- .../com/android/base/rx/TestApplication.java | 4 +- .../com/android/base/rx/TestListFragment.java | 4 +- .../android/base/rx/TestStateFragment.java | 6 +- 56 files changed, 354 insertions(+), 315 deletions(-) rename lib_base/src/main/java/com/android/base/adapter/pager/{recycler => }/RecycleBin.java (98%) rename lib_base/src/main/java/com/android/base/adapter/pager/{recycler => }/RecyclingPagerAdapter.java (92%) rename lib_base/src/main/java/com/android/base/app/{BaseKit.java => Sword.java} (85%) delete mode 100644 lib_base/src/main/java/com/android/base/data/Resource.java rename lib_base/src/main/java/com/android/base/data/{Status.java => Status.kt} (68%) rename lib_base/src/main/java/com/android/base/interfaces/{adapter => }/ActivityLifecycleCallbacksAdapter.java (94%) rename lib_base/src/main/java/com/android/base/interfaces/{adapter => }/DrawerListenerAdapter.java (92%) rename lib_base/src/main/java/com/android/base/interfaces/{adapter => }/OnPageChangeListenerAdapter.java (91%) rename lib_base/src/main/java/com/android/base/interfaces/{adapter => }/OnSeekBarChangeListenerAdapter.java (91%) rename lib_base/src/main/java/com/android/base/interfaces/{adapter => }/OnTabSelectedListenerAdapter.java (89%) rename lib_base/src/main/java/com/android/base/interfaces/{adapter => }/TextWatcherAdapter.java (91%) rename lib_base/src/main/java/com/android/base/interfaces/{adapter => }/TransitionListenerAdapter.java (93%) create mode 100644 lib_base/src/main/java/com/android/base/utils/android/views/ListViewEx.kt rename lib_base/src/main/java/com/android/base/widget/viewpager/{ZViewPager.java => BannerViewPager.java} (92%) diff --git a/lib_base/build.gradle b/lib_base/build.gradle index 4ed366a..4d96246 100644 --- a/lib_base/build.gradle +++ b/lib_base/build.gradle @@ -83,6 +83,7 @@ dependencies { api androidLibraries.lifecycleViewModelKtx api androidLibraries.lifecycleExtensions api androidLibraries.lifecycleReactiveStreams + api androidLibraries.ktx //Kotlin api kotlinLibraries.kotlinStdlib diff --git a/lib_base/src/main/java/com/android/base/adapter/DataManager.java b/lib_base/src/main/java/com/android/base/adapter/DataManager.java index f35a37b..8534a4b 100644 --- a/lib_base/src/main/java/com/android/base/adapter/DataManager.java +++ b/lib_base/src/main/java/com/android/base/adapter/DataManager.java @@ -2,6 +2,8 @@ package com.android.base.adapter; import java.util.List; +import androidx.annotation.Nullable; + /** *
  *     注意数据源引用的替换,只有setDataSource方法会把elements替换掉之前的数据源引用,其他方法都是基于现有数据集合做删除与添加操作。
@@ -13,7 +15,6 @@ import java.util.List;
  */
 public interface DataManager {
 
-    //Add op
     void add(T element);
 
     void addAt(int location, T element);
@@ -21,7 +22,7 @@ public interface DataManager {
     void addItems(List elements);
 
     /**
-     * 添加元素前会使用equals方法进行比较,荣旧的数据集合中删除相同的数据在添加
+     * 添加元素前会使用equals方法进行比较。
      *
      * @param elements 元素
      */
@@ -29,7 +30,6 @@ public interface DataManager {
 
     void addItemsAt(int location, List elements);
 
-    //update op
     void replace(T oldElement, T newElement);
 
     void replaceAt(int index, T element);
@@ -42,14 +42,13 @@ public interface DataManager {
     void replaceAll(List elements);
 
     /**
-     * 此方法会使用elements替换掉之前的数据源,而不对之前的数据源做任何操作
+     * 此方法会使用 newDataSource 替换掉之前的数据源,而不对之前的数据源做任何操作。
      *
      * @param newDataSource        新的数据集
      * @param notifyDataSetChanged 是否调用adapter的notifyDataSetChanged方法
      */
     void setDataSource(List newDataSource, boolean notifyDataSetChanged);
 
-    //remove opt
     void remove(T element);
 
     void removeAt(int index);
@@ -58,26 +57,23 @@ public interface DataManager {
 
     void removeItems(List elements, boolean isSuccessive);
 
-    //get
+    @Nullable
     T getItem(int position);
 
     List getItems();
 
     int getDataSize();
 
-    //contains
     boolean contains(T element);
 
     boolean isEmpty();
 
-    //clear opt
     void clear();
 
-    //Utils
-
     /**
      * @param t element
      * @return -1 if not contains this element
      */
-    int getItemPosition(T t);
+    int indexItem(T t);
+
 }
diff --git a/lib_base/src/main/java/com/android/base/adapter/ItemHelper.java b/lib_base/src/main/java/com/android/base/adapter/ItemHelper.java
index 4be1188..e35ea79 100644
--- a/lib_base/src/main/java/com/android/base/adapter/ItemHelper.java
+++ b/lib_base/src/main/java/com/android/base/adapter/ItemHelper.java
@@ -11,8 +11,8 @@ import androidx.annotation.StringRes;
 
 /**
  * @author Ztiany
- *         Email :1169654504@qq.com
- *         Date :015-12-29 20:47
+ * Email :1169654504@qq.com
+ * Date :015-12-29 20:47
  */
 public class ItemHelper {
 
@@ -24,7 +24,7 @@ public class ItemHelper {
         views = new SparseArray<>();
     }
 
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings("unchecked,WeakerAccess")
     public  T getView(int viewId) {
         View view = views.get(viewId);
         if (view == null) {
diff --git a/lib_base/src/main/java/com/android/base/adapter/list/BaseListAdapter.java b/lib_base/src/main/java/com/android/base/adapter/list/BaseListAdapter.java
index 833adec..bfcc415 100644
--- a/lib_base/src/main/java/com/android/base/adapter/list/BaseListAdapter.java
+++ b/lib_base/src/main/java/com/android/base/adapter/list/BaseListAdapter.java
@@ -12,6 +12,7 @@ import com.android.base.adapter.DataManager;
 import java.util.List;
 
 import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
 
 /**
  * absListView通用的Adapter,注意:只有setDataSource才能替换原有数据源的引用。
@@ -22,7 +23,7 @@ import androidx.annotation.NonNull;
 @SuppressWarnings("unused")
 public abstract class BaseListAdapter extends BaseAdapter implements DataManager {
 
-    protected final Context mContext;
+    private final Context mContext;
     private final static int ITEM_ID = R.id.base_item_tag_view_id;
     private DataManager mDataManager;
     private final LayoutInflater mLayoutInflater;
@@ -38,6 +39,10 @@ public abstract class BaseListAdapter extends BaseAdap
         mDataManager = new ListDataManagerImpl<>(data, this);
     }
 
+    public Context getContext() {
+        return mContext;
+    }
+
     @Override
     public int getCount() {
         return getDataSize();
@@ -66,7 +71,6 @@ public abstract class BaseListAdapter extends BaseAdap
         return viewHolder.mItemView;
     }
 
-    @SuppressWarnings("all")
     protected abstract void onBindData(@NonNull VH viewHolder, T item);
 
     @NonNull
@@ -82,11 +86,6 @@ public abstract class BaseListAdapter extends BaseAdap
         return super.getViewTypeCount();
     }
 
-
-    ///////////////////////////////////////////////////////////////////////////
-    // DataManager
-    ///////////////////////////////////////////////////////////////////////////
-
     @Override
     public void add(T elem) {
         mDataManager.add(elem);
@@ -147,6 +146,7 @@ public abstract class BaseListAdapter extends BaseAdap
         mDataManager.removeAt(index);
     }
 
+    @Nullable
     @Override
     public T getItem(int position) {
         return mDataManager.getItem(position);
@@ -168,8 +168,8 @@ public abstract class BaseListAdapter extends BaseAdap
     }
 
     @Override
-    public int getItemPosition(T t) {
-        return mDataManager.getItemPosition(t);
+    public int indexItem(T t) {
+        return mDataManager.indexItem(t);
     }
 
     @Override
@@ -181,4 +181,5 @@ public abstract class BaseListAdapter extends BaseAdap
     public List getItems() {
         return mDataManager.getItems();
     }
-}
+
+}
\ No newline at end of file
diff --git a/lib_base/src/main/java/com/android/base/adapter/list/ListDataManagerImpl.java b/lib_base/src/main/java/com/android/base/adapter/list/ListDataManagerImpl.java
index 52221f0..1ec5690 100644
--- a/lib_base/src/main/java/com/android/base/adapter/list/ListDataManagerImpl.java
+++ b/lib_base/src/main/java/com/android/base/adapter/list/ListDataManagerImpl.java
@@ -8,6 +8,8 @@ import com.android.base.utils.common.Checker;
 import java.util.ArrayList;
 import java.util.List;
 
+import androidx.annotation.Nullable;
+
 
 final class ListDataManagerImpl implements DataManager {
 
@@ -137,6 +139,7 @@ final class ListDataManagerImpl implements DataManager {
     }
 
     @Override
+    @Nullable
     public T getItem(int position) {
         if (mData != null && mData.size() > position) {
             return mData.get(position);
@@ -168,7 +171,7 @@ final class ListDataManagerImpl implements DataManager {
     }
 
     @Override
-    public int getItemPosition(T t) {
+    public int indexItem(T t) {
         List items = getItems();
         if (items == null) {
             return -1;
@@ -185,4 +188,4 @@ final class ListDataManagerImpl implements DataManager {
         mBaseAdapter.notifyDataSetChanged();
     }
 
-}
+}
\ No newline at end of file
diff --git a/lib_base/src/main/java/com/android/base/adapter/list/SmartViewHolder.java b/lib_base/src/main/java/com/android/base/adapter/list/SmartViewHolder.java
index 71c0123..e849c9b 100644
--- a/lib_base/src/main/java/com/android/base/adapter/list/SmartViewHolder.java
+++ b/lib_base/src/main/java/com/android/base/adapter/list/SmartViewHolder.java
@@ -7,7 +7,7 @@ import com.android.base.adapter.ItemHelper;
 @SuppressWarnings("unused")
 public class SmartViewHolder extends ViewHolder {
 
-    protected final ItemHelper mHelper;
+    private final ItemHelper mHelper;
 
     public SmartViewHolder(View itemView) {
         super(itemView);
@@ -18,4 +18,4 @@ public class SmartViewHolder extends ViewHolder {
         return mHelper;
     }
 
-}
+}
\ No newline at end of file
diff --git a/lib_base/src/main/java/com/android/base/adapter/list/ViewHolder.java b/lib_base/src/main/java/com/android/base/adapter/list/ViewHolder.java
index ba9fc47..3387909 100644
--- a/lib_base/src/main/java/com/android/base/adapter/list/ViewHolder.java
+++ b/lib_base/src/main/java/com/android/base/adapter/list/ViewHolder.java
@@ -4,7 +4,6 @@ import android.view.View;
 
 public class ViewHolder {
 
-    @SuppressWarnings("all")
     protected final View mItemView;
     private int mPosition;
     private int mType;
@@ -32,4 +31,5 @@ public class ViewHolder {
     public View getItemView() {
         return mItemView;
     }
+
 }
diff --git a/lib_base/src/main/java/com/android/base/adapter/pager/recycler/RecycleBin.java b/lib_base/src/main/java/com/android/base/adapter/pager/RecycleBin.java
similarity index 98%
rename from lib_base/src/main/java/com/android/base/adapter/pager/recycler/RecycleBin.java
rename to lib_base/src/main/java/com/android/base/adapter/pager/RecycleBin.java
index 2b2d01e..b58784d 100644
--- a/lib_base/src/main/java/com/android/base/adapter/pager/recycler/RecycleBin.java
+++ b/lib_base/src/main/java/com/android/base/adapter/pager/RecycleBin.java
@@ -1,4 +1,4 @@
-package com.android.base.adapter.pager.recycler;
+package com.android.base.adapter.pager;
 
 import android.os.Build;
 import android.util.SparseArray;
@@ -15,6 +15,7 @@ import android.view.View;
  * is copyrighted 2006 The Android Open Source Project.
  */
 public class RecycleBin {
+
   /**
    * Views that were on screen at the start of layout. This array is populated at the start of
    * layout, and at the end of layout all view in activeViews are moved to scrapViews.
@@ -149,4 +150,5 @@ public class RecycleBin {
       return null;
     }
   }
-}
+
+}
\ No newline at end of file
diff --git a/lib_base/src/main/java/com/android/base/adapter/pager/recycler/RecyclingPagerAdapter.java b/lib_base/src/main/java/com/android/base/adapter/pager/RecyclingPagerAdapter.java
similarity index 92%
rename from lib_base/src/main/java/com/android/base/adapter/pager/recycler/RecyclingPagerAdapter.java
rename to lib_base/src/main/java/com/android/base/adapter/pager/RecyclingPagerAdapter.java
index 2a2b026..03d84db 100644
--- a/lib_base/src/main/java/com/android/base/adapter/pager/recycler/RecyclingPagerAdapter.java
+++ b/lib_base/src/main/java/com/android/base/adapter/pager/RecyclingPagerAdapter.java
@@ -1,9 +1,11 @@
-package com.android.base.adapter.pager.recycler;
+package com.android.base.adapter.pager;
 
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.AdapterView;
 
+import org.jetbrains.annotations.NotNull;
+
 import androidx.viewpager.widget.PagerAdapter;
 
 /**
@@ -33,7 +35,7 @@ public abstract class RecyclingPagerAdapter extends PagerAdapter {
     }
 
     @Override
-    public final Object instantiateItem(ViewGroup container, int position) {
+    public final Object instantiateItem(@NotNull ViewGroup container, int position) {
         int viewType = getItemViewType(position);
         View view = null;
         if (viewType != IGNORE_ITEM_VIEW_TYPE) {
@@ -45,7 +47,7 @@ public abstract class RecyclingPagerAdapter extends PagerAdapter {
     }
 
     @Override
-    public final void destroyItem(ViewGroup container, int position, Object object) {
+    public final void destroyItem(ViewGroup container, int position, @NotNull Object object) {
         View view = (View) object;
         container.removeView(view);
         int viewType = getItemViewType(position);
@@ -55,7 +57,7 @@ public abstract class RecyclingPagerAdapter extends PagerAdapter {
     }
 
     @Override
-    public final boolean isViewFromObject(View view, Object object) {
+    public final boolean isViewFromObject(@NotNull View view, @NotNull Object object) {
         return view == object;
     }
 
@@ -108,8 +110,9 @@ public abstract class RecyclingPagerAdapter extends PagerAdapter {
      *                    Heterogeneous lists can specify their number of view types, so that this View is
      *                    always of the right type (see {@link #getViewTypeCount()} and
      *                    {@link #getItemViewType(int)}).
-     * @param parent      The parent that this view will eventually be attached to
+     * @param container   The parent that this view will eventually be attached to
      * @return A View corresponding to the data at the specified position.
      */
     public abstract View getView(int position, View convertView, ViewGroup container);
+
 }
diff --git a/lib_base/src/main/java/com/android/base/adapter/pager/ViewPagerAdapter.java b/lib_base/src/main/java/com/android/base/adapter/pager/ViewPagerAdapter.java
index af92869..421f5c3 100644
--- a/lib_base/src/main/java/com/android/base/adapter/pager/ViewPagerAdapter.java
+++ b/lib_base/src/main/java/com/android/base/adapter/pager/ViewPagerAdapter.java
@@ -4,7 +4,6 @@ import android.view.View;
 import android.view.ViewGroup;
 
 import com.android.base.R;
-import com.android.base.adapter.pager.recycler.RecyclingPagerAdapter;
 import com.android.base.utils.common.Checker;
 
 import java.util.List;
@@ -13,7 +12,7 @@ import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 
 /**
- * 如果使用可缩放的 View 作为 pager,可能不适合使用此Adapter
+ * 如果使用可缩放的 View 作为 pager,可能不适合使用此 Adapter
  *
  * @param   数据
  * @param  View Holder类型
@@ -67,4 +66,4 @@ public abstract class ViewPagerAdapter extends RecyclerView.Adapter implements DataManager {
 
     @NonNull
-    protected Context mContext;
+    private Context mContext;
 
     private AsyncListDiffer mAsyncListDiffer;
 
@@ -67,6 +67,11 @@ public abstract class DiffRecyclerAdapter extends Recy
         }
     }
 
+    @NonNull
+    public Context getContext() {
+        return mContext;
+    }
+
     @Override
     public int getItemCount() {
         return getDataSize();
@@ -85,7 +90,7 @@ public abstract class DiffRecyclerAdapter extends Recy
     public abstract void onBindViewHolder(@NonNull VH viewHolder, int position);
 
     public void notifyEntryChanged(T t) {
-        int itemPosition = getItemPosition(t);
+        int itemPosition = indexItem(t);
         if (itemPosition != -1) {
             notifyItemChanged(itemPosition);
         }
@@ -246,7 +251,7 @@ public abstract class DiffRecyclerAdapter extends Recy
     }
 
     @Override
-    public int getItemPosition(T t) {
+    public int indexItem(T t) {
         return isEmpty() ? -1 : getItems().indexOf(t);
     }
 
diff --git a/lib_base/src/main/java/com/android/base/adapter/recycler/MultiTypeAdapter.java b/lib_base/src/main/java/com/android/base/adapter/recycler/MultiTypeAdapter.java
index 2c4bf64..7b93b18 100644
--- a/lib_base/src/main/java/com/android/base/adapter/recycler/MultiTypeAdapter.java
+++ b/lib_base/src/main/java/com/android/base/adapter/recycler/MultiTypeAdapter.java
@@ -8,6 +8,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
 
 
 /**
@@ -45,7 +46,7 @@ public class MultiTypeAdapter extends com.drakeet.multitype.MultiTypeAdapter imp
 
     @SuppressWarnings("unused")
     public void notifyEntryChanged(Object entry) {
-        int itemPosition = getItemPosition(entry);
+        int itemPosition = indexItem(entry);
         if (itemPosition != -1) {
             notifyItemChanged(itemPosition);
         }
@@ -117,6 +118,7 @@ public class MultiTypeAdapter extends com.drakeet.multitype.MultiTypeAdapter imp
         mRecyclerDataManager.removeItems(elements, isSuccessive);
     }
 
+    @Nullable
     @Override
     public Object getItem(int position) {
         return mRecyclerDataManager.getItem(position);
@@ -149,8 +151,8 @@ public class MultiTypeAdapter extends com.drakeet.multitype.MultiTypeAdapter imp
     }
 
     @Override
-    public int getItemPosition(Object o) {
-        return mRecyclerDataManager.getItemPosition(o);
+    public int indexItem(Object o) {
+        return mRecyclerDataManager.indexItem(o);
     }
 
     @Override
diff --git a/lib_base/src/main/java/com/android/base/adapter/recycler/RecyclerAdapter.java b/lib_base/src/main/java/com/android/base/adapter/recycler/RecyclerAdapter.java
index 6a3d7db..726c3be 100644
--- a/lib_base/src/main/java/com/android/base/adapter/recycler/RecyclerAdapter.java
+++ b/lib_base/src/main/java/com/android/base/adapter/recycler/RecyclerAdapter.java
@@ -8,6 +8,7 @@ import com.android.base.adapter.DataManager;
 import java.util.List;
 
 import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
 import androidx.recyclerview.widget.RecyclerView;
 
 /**
@@ -24,7 +25,7 @@ public abstract class RecyclerAdapter extends Recycler
     private RecyclerDataManagerImpl mDataManager;
 
     @NonNull
-    protected final Context mContext;
+    private final Context mContext;
 
     public RecyclerAdapter(@NonNull Context context, List data) {
         mDataManager = new RecyclerDataManagerImpl<>(data, this);
@@ -35,6 +36,11 @@ public abstract class RecyclerAdapter extends Recycler
         this(context, null);
     }
 
+    @NonNull
+    public Context getContext() {
+        return mContext;
+    }
+
     @Override
     public int getItemCount() {
         return getDataSize();
@@ -53,7 +59,7 @@ public abstract class RecyclerAdapter extends Recycler
     public abstract void onBindViewHolder(@NonNull VH viewHolder, int position);
 
     public void notifyEntryChanged(T t) {
-        int itemPosition = getItemPosition(t);
+        int itemPosition = indexItem(t);
         if (itemPosition != -1) {
             notifyItemChanged(itemPosition);
         }
@@ -123,6 +129,7 @@ public abstract class RecyclerAdapter extends Recycler
         mDataManager.removeAt(index);
     }
 
+    @Nullable
     @Override
     public T getItem(int position) {
         return mDataManager.getItem(position);
@@ -163,8 +170,8 @@ public abstract class RecyclerAdapter extends Recycler
     }
 
     @Override
-    public int getItemPosition(T t) {
-        return mDataManager.getItemPosition(t);
+    public int indexItem(T t) {
+        return mDataManager.indexItem(t);
     }
 
 }
\ No newline at end of file
diff --git a/lib_base/src/main/java/com/android/base/adapter/recycler/RecyclerDataManagerImpl.java b/lib_base/src/main/java/com/android/base/adapter/recycler/RecyclerDataManagerImpl.java
index 5b2b675..7654d96 100644
--- a/lib_base/src/main/java/com/android/base/adapter/recycler/RecyclerDataManagerImpl.java
+++ b/lib_base/src/main/java/com/android/base/adapter/recycler/RecyclerDataManagerImpl.java
@@ -218,7 +218,7 @@ final class RecyclerDataManagerImpl implements DataManager {
     }
 
     @Override
-    public int getItemPosition(T t) {
+    public int indexItem(T t) {
         List items = getItems();
         if (items == null) {
             return -1;
diff --git a/lib_base/src/main/java/com/android/base/adapter/recycler/SimpleRecyclerAdapter.kt b/lib_base/src/main/java/com/android/base/adapter/recycler/SimpleRecyclerAdapter.kt
index d36aa62..c749d88 100644
--- a/lib_base/src/main/java/com/android/base/adapter/recycler/SimpleRecyclerAdapter.kt
+++ b/lib_base/src/main/java/com/android/base/adapter/recycler/SimpleRecyclerAdapter.kt
@@ -14,7 +14,7 @@ import android.view.ViewGroup
  */
 abstract class SimpleRecyclerAdapter(context: Context, data: List? = null) : RecyclerAdapter(context, data) {
 
-    private var layoutInflater: LayoutInflater = LayoutInflater.from(mContext)
+    private var layoutInflater: LayoutInflater = LayoutInflater.from(context)
 
     final override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): KtViewHolder {
         val layout = provideLayout(parent, viewType)
@@ -33,7 +33,7 @@ abstract class SimpleRecyclerAdapter(context: Context, data: List? = null)
     abstract fun provideLayout(parent: ViewGroup, viewType: Int): Any
 
     override fun onBindViewHolder(viewHolder: KtViewHolder, position: Int) {
-        bind(viewHolder, getItem(position))
+        bind(viewHolder, getItem(position) ?: throw NullPointerException("SimpleRecyclerAdapter onBindViewHolder getItem return null"))
     }
 
     protected abstract fun bind(viewHolder: KtViewHolder, item: T)
diff --git a/lib_base/src/main/java/com/android/base/adapter/recycler/SmartViewHolder.java b/lib_base/src/main/java/com/android/base/adapter/recycler/SmartViewHolder.java
index b22d6d5..e84e14b 100644
--- a/lib_base/src/main/java/com/android/base/adapter/recycler/SmartViewHolder.java
+++ b/lib_base/src/main/java/com/android/base/adapter/recycler/SmartViewHolder.java
@@ -7,8 +7,7 @@ import com.android.base.adapter.ItemHelper;
 
 public class SmartViewHolder extends ViewHolder {
 
-    @SuppressWarnings("all")
-    protected final ItemHelper mHelper;
+    private final ItemHelper mHelper;
 
     public SmartViewHolder(View itemView) {
         super(itemView);
diff --git a/lib_base/src/main/java/com/android/base/app/ApplicationDelegate.java b/lib_base/src/main/java/com/android/base/app/ApplicationDelegate.java
index 67d09a9..b06284f 100644
--- a/lib_base/src/main/java/com/android/base/app/ApplicationDelegate.java
+++ b/lib_base/src/main/java/com/android/base/app/ApplicationDelegate.java
@@ -103,7 +103,7 @@ public final class ApplicationDelegate {
         return mAppStatus;
     }
 
-    void setCrashProcessor(BaseKit.CrashProcessor crashProcessor) {
+    void setCrashProcessor(Sword.CrashProcessor crashProcessor) {
         if (mCrashHandler != null) {
             mCrashHandler.setCrashProcessor(crashProcessor);
         }
diff --git a/lib_base/src/main/java/com/android/base/app/BaseAppContext.java b/lib_base/src/main/java/com/android/base/app/BaseAppContext.java
index 72a3d3c..cf879b8 100644
--- a/lib_base/src/main/java/com/android/base/app/BaseAppContext.java
+++ b/lib_base/src/main/java/com/android/base/app/BaseAppContext.java
@@ -10,37 +10,37 @@ public class BaseAppContext extends Application {
     @Override
     protected void attachBaseContext(Context base) {
         super.attachBaseContext(base);
-        BaseKit.get().getApplicationDelegate().attachBaseContext(base);
+        Sword.get().getApplicationDelegate().attachBaseContext(base);
     }
 
     @Override
     public void onCreate() {
         super.onCreate();
-        BaseKit.get().getApplicationDelegate().onCreate(this);
+        Sword.get().getApplicationDelegate().onCreate(this);
     }
 
     @Override
     public void onLowMemory() {
         super.onLowMemory();
-        BaseKit.get().getApplicationDelegate().onLowMemory();
+        Sword.get().getApplicationDelegate().onLowMemory();
     }
 
     @Override
     public void onTrimMemory(int level) {
         super.onTrimMemory(level);
-        BaseKit.get().getApplicationDelegate().onTrimMemory(level);
+        Sword.get().getApplicationDelegate().onTrimMemory(level);
     }
 
     @Override
     public void onConfigurationChanged(Configuration newConfig) {
         super.onConfigurationChanged(newConfig);
-        BaseKit.get().getApplicationDelegate().onConfigurationChanged(newConfig);
+        Sword.get().getApplicationDelegate().onConfigurationChanged(newConfig);
     }
 
     @Override
     public void onTerminate() {
         super.onTerminate();
-        BaseKit.get().getApplicationDelegate().onTerminate();
+        Sword.get().getApplicationDelegate().onTerminate();
     }
 
 }
\ No newline at end of file
diff --git a/lib_base/src/main/java/com/android/base/app/CrashHandler.java b/lib_base/src/main/java/com/android/base/app/CrashHandler.java
index 1509ee0..83e2c33 100644
--- a/lib_base/src/main/java/com/android/base/app/CrashHandler.java
+++ b/lib_base/src/main/java/com/android/base/app/CrashHandler.java
@@ -22,7 +22,7 @@ import timber.log.Timber;
 final class CrashHandler implements Thread.UncaughtExceptionHandler {
 
     private Context mContext;
-    private BaseKit.CrashProcessor mCrashProcessor;
+    private Sword.CrashProcessor mCrashProcessor;
 
     public static CrashHandler register(Application application) {
         CrashHandler crashHandler = new CrashHandler(application);
@@ -30,7 +30,7 @@ final class CrashHandler implements Thread.UncaughtExceptionHandler {
         return crashHandler;
     }
 
-    void setCrashProcessor(BaseKit.CrashProcessor crashProcessor) {
+    void setCrashProcessor(Sword.CrashProcessor crashProcessor) {
         mCrashProcessor = crashProcessor;
     }
 
diff --git a/lib_base/src/main/java/com/android/base/app/BaseKit.java b/lib_base/src/main/java/com/android/base/app/Sword.java
similarity index 85%
rename from lib_base/src/main/java/com/android/base/app/BaseKit.java
rename to lib_base/src/main/java/com/android/base/app/Sword.java
index 91d77be..5ebaae5 100644
--- a/lib_base/src/main/java/com/android/base/app/BaseKit.java
+++ b/lib_base/src/main/java/com/android/base/app/Sword.java
@@ -11,7 +11,7 @@ import com.android.base.app.fragment.LoadingViewFactory;
 import com.android.base.app.ui.PageNumber;
 import com.android.base.app.ui.RefreshLoadViewFactory;
 import com.android.base.app.ui.RefreshViewFactory;
-import com.android.base.interfaces.adapter.ActivityLifecycleCallbacksAdapter;
+import com.android.base.interfaces.ActivityLifecycleCallbacksAdapter;
 import com.android.base.receiver.NetworkState;
 import com.blankj.utilcode.util.ActivityUtils;
 import com.blankj.utilcode.util.AppUtils;
@@ -27,22 +27,23 @@ import dagger.android.support.AndroidSupportInjection;
 import io.reactivex.Flowable;
 
 /**
- * 基础库工具
+ * useful tools for android development, just like a sword.
  *
  * @author Ztiany
  * Email: ztiany3@gmail.com
  * Date : 2018-04-16 17:12
  */
+@SuppressWarnings("unused")
 @UiThread
-public final class BaseKit {
+public final class Sword {
 
-    private static final BaseKit ONLY_BASE = new BaseKit();
+    private static final Sword ONLY_BASE = new Sword();
 
-    private BaseKit() {
+    private Sword() {
         mApplicationDelegate = new ApplicationDelegate();
     }
 
-    public static BaseKit get() {
+    public static Sword get() {
         return ONLY_BASE;
     }
 
@@ -64,12 +65,11 @@ public final class BaseKit {
     /**
      * 获取 Application 代理
      */
-    @SuppressWarnings("WeakerAccess")
     public ApplicationDelegate getApplicationDelegate() {
         return mApplicationDelegate;
     }
 
-    public BaseKit registerLoadingFactory(LoadingViewFactory loadingViewFactory) {
+    public Sword registerLoadingFactory(LoadingViewFactory loadingViewFactory) {
         if (mLoadingViewFactory != null) {
             throw new UnsupportedOperationException("LoadingViewFactory had already set");
         }
@@ -93,17 +93,17 @@ public final class BaseKit {
         void uncaughtException(Thread thread, Throwable ex);
     }
 
-    public BaseKit setCrashProcessor(CrashProcessor crashProcessor) {
+    public Sword setCrashProcessor(CrashProcessor crashProcessor) {
         mApplicationDelegate.setCrashProcessor(crashProcessor);
         return this;
     }
 
-    public BaseKit setDefaultPageStart(int pageStart) {
+    public Sword setDefaultPageStart(int pageStart) {
         PageNumber.setDefaultPageStart(pageStart);
         return this;
     }
 
-    public BaseKit setDefaultPageSize(int defaultPageSize) {
+    public Sword setDefaultPageSize(int defaultPageSize) {
         PageNumber.setDefaultPageSize(defaultPageSize);
         return this;
     }
@@ -113,12 +113,12 @@ public final class BaseKit {
      *
      * @param defaultContainerId 容器id
      */
-    public BaseKit setDefaultFragmentContainerId(int defaultContainerId) {
+    public Sword setDefaultFragmentContainerId(int defaultContainerId) {
         FragmentConfig.setDefaultContainerId(defaultContainerId);
         return this;
     }
 
-    public BaseKit enableAutoInject() {
+    public Sword enableAutoInject() {
         Application.ActivityLifecycleCallbacks activityLifecycleCallbacks = new ActivityLifecycleCallbacksAdapter() {
 
             @Override
@@ -182,8 +182,7 @@ public final class BaseKit {
         boolean isServerError(Throwable throwable);
     }
 
-    @SuppressWarnings("all")
-    public BaseKit setErrorClassifier(ErrorClassifier errorClassifier) {
+    public Sword setErrorClassifier(ErrorClassifier errorClassifier) {
         if (mErrorClassifier != null) {
             throw new UnsupportedOperationException("ErrorClassifier had already set");
         }
@@ -195,12 +194,12 @@ public final class BaseKit {
         return mErrorClassifier;
     }
 
-    public BaseKit registerRefreshLoadViewFactory(RefreshLoadViewFactory.Factory factory) {
+    public Sword registerRefreshLoadViewFactory(RefreshLoadViewFactory.Factory factory) {
         RefreshLoadViewFactory.registerFactory(factory);
         return this;
     }
 
-    public BaseKit registerRefreshViewFactory(RefreshViewFactory.Factory factory) {
+    public Sword registerRefreshViewFactory(RefreshViewFactory.Factory factory) {
         RefreshViewFactory.registerFactory(factory);
         return this;
     }
diff --git a/lib_base/src/main/java/com/android/base/app/aac/SingleLiveData.java b/lib_base/src/main/java/com/android/base/app/aac/SingleLiveData.java
index 09be4bb..a2bca91 100644
--- a/lib_base/src/main/java/com/android/base/app/aac/SingleLiveData.java
+++ b/lib_base/src/main/java/com/android/base/app/aac/SingleLiveData.java
@@ -19,7 +19,6 @@ public class SingleLiveData extends MediatorLiveData {
 
     private final List>> mWrapperObserverList = new ArrayList<>();
 
-
     @Override
     public void setValue(T value) {
         mVersion++;
diff --git a/lib_base/src/main/java/com/android/base/app/activity/BaseActivity.java b/lib_base/src/main/java/com/android/base/app/activity/BaseActivity.java
index 48ff010..c4ff5d0 100644
--- a/lib_base/src/main/java/com/android/base/app/activity/BaseActivity.java
+++ b/lib_base/src/main/java/com/android/base/app/activity/BaseActivity.java
@@ -7,6 +7,8 @@ import android.view.View;
 import com.android.base.utils.android.compat.AndroidVersion;
 import com.github.dmstocking.optional.java.util.function.Predicate;
 
+import org.jetbrains.annotations.NotNull;
+
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 import androidx.annotation.UiThread;
@@ -121,7 +123,7 @@ public abstract class BaseActivity extends AppCompatActivity implements Activity
     }
 
     @Override
-    protected void onSaveInstanceState(Bundle outState) {
+    protected void onSaveInstanceState(@NotNull Bundle outState) {
         super.onSaveInstanceState(outState);
         mActivityDelegates.callOnSaveInstanceState(outState);
     }
@@ -219,4 +221,4 @@ public abstract class BaseActivity extends AppCompatActivity implements Activity
         }
     }
 
-}
+}
\ No newline at end of file
diff --git a/lib_base/src/main/java/com/android/base/app/fragment/BaseDialogFragment.java b/lib_base/src/main/java/com/android/base/app/fragment/BaseDialogFragment.java
index 87a2b7e..efbc09f 100644
--- a/lib_base/src/main/java/com/android/base/app/fragment/BaseDialogFragment.java
+++ b/lib_base/src/main/java/com/android/base/app/fragment/BaseDialogFragment.java
@@ -7,12 +7,14 @@ import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 
-import com.android.base.app.BaseKit;
+import com.android.base.app.Sword;
 import com.android.base.app.activity.BackHandlerHelper;
 import com.android.base.app.activity.OnBackPressListener;
 import com.android.base.app.ui.LoadingView;
 import com.github.dmstocking.optional.java.util.function.Predicate;
 
+import org.jetbrains.annotations.NotNull;
+
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 import androidx.annotation.StringRes;
@@ -49,7 +51,7 @@ public class BaseDialogFragment extends AppCompatDialogFragment implements Loadi
     }
 
     @Override
-    public void onAttach(Context context) {
+    public void onAttach(@NotNull Context context) {
         super.onAttach(context);
         Timber.tag(tag()).d("onAttach() called with: context = [" + context + "]");
         mFragmentDelegates.onAttach(context);
@@ -235,7 +237,7 @@ public class BaseDialogFragment extends AppCompatDialogFragment implements Loadi
 
     private LoadingView getLoadingViewImpl() {
         if (mLoadingViewImpl == null) {
-            mLoadingViewImpl = BaseKit.get().getLoadingViewFactory().createLoadingDelegate(getContext());
+            mLoadingViewImpl = Sword.get().getLoadingViewFactory().createLoadingDelegate(getContext());
         }
         return mLoadingViewImpl;
     }
diff --git a/lib_base/src/main/java/com/android/base/app/fragment/BaseFragment.java b/lib_base/src/main/java/com/android/base/app/fragment/BaseFragment.java
index 1574d36..da41900 100644
--- a/lib_base/src/main/java/com/android/base/app/fragment/BaseFragment.java
+++ b/lib_base/src/main/java/com/android/base/app/fragment/BaseFragment.java
@@ -8,12 +8,14 @@ import android.view.View;
 import android.view.ViewGroup;
 import android.view.ViewParent;
 
-import com.android.base.app.BaseKit;
+import com.android.base.app.Sword;
 import com.android.base.app.activity.BackHandlerHelper;
 import com.android.base.app.activity.OnBackPressListener;
 import com.android.base.app.ui.LoadingView;
 import com.github.dmstocking.optional.java.util.function.Predicate;
 
+import org.jetbrains.annotations.NotNull;
+
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 import androidx.annotation.StringRes;
@@ -50,7 +52,7 @@ public class BaseFragment extends Fragment implements LoadingView, OnBackPressLi
     }
 
     @Override
-    public void onAttach(Context context) {
+    public void onAttach(@NotNull Context context) {
         super.onAttach(context);
         Timber.tag(tag()).d("onAttach() called with: context = [" + context + "]");
         mFragmentDelegates.onAttach(context);
@@ -249,7 +251,7 @@ public class BaseFragment extends Fragment implements LoadingView, OnBackPressLi
             mLoadingViewImpl = onCreateLoadingView();
         }
         if (mLoadingViewImpl == null) {
-            mLoadingViewImpl = BaseKit.get().getLoadingViewFactory().createLoadingDelegate(getContext());
+            mLoadingViewImpl = Sword.get().getLoadingViewFactory().createLoadingDelegate(getContext());
         }
         return mLoadingViewImpl;
     }
diff --git a/lib_base/src/main/java/com/android/base/app/fragment/FragmentInfo.java b/lib_base/src/main/java/com/android/base/app/fragment/FragmentInfo.java
index f464a1c..002cfa2 100644
--- a/lib_base/src/main/java/com/android/base/app/fragment/FragmentInfo.java
+++ b/lib_base/src/main/java/com/android/base/app/fragment/FragmentInfo.java
@@ -2,10 +2,11 @@ package com.android.base.app.fragment;
 
 import android.content.Context;
 import android.os.Bundle;
-import androidx.fragment.app.Fragment;
 
 import java.lang.ref.WeakReference;
 
+import androidx.fragment.app.Fragment;
+
 @SuppressWarnings("WeakerAccess,unused")
 public class FragmentInfo {
 
@@ -129,4 +130,4 @@ public class FragmentInfo {
         }
     }
 
-}
+}
\ No newline at end of file
diff --git a/lib_base/src/main/java/com/android/base/app/fragment/Fragments.kt b/lib_base/src/main/java/com/android/base/app/fragment/Fragments.kt
index a63f3b4..80ea785 100644
--- a/lib_base/src/main/java/com/android/base/app/fragment/Fragments.kt
+++ b/lib_base/src/main/java/com/android/base/app/fragment/Fragments.kt
@@ -173,7 +173,7 @@ fun  T.inSafelyFragmentTransaction(
 
     var delegate = findDelegate {
         it is SafelyFragmentTransactionActivityDelegate
-    }as? SafelyFragmentTransactionActivityDelegate
+    } as? SafelyFragmentTransactionActivityDelegate
 
     if (delegate == null) {
         delegate = SafelyFragmentTransactionActivityDelegate()
@@ -241,22 +241,22 @@ private class SafelyFragmentTransactionActivityDelegate : ActivityDelegate {
 
-    private val mPendingTransactions = mutableListOf()
+    private val pendingTransactions = mutableListOf()
 
     fun safeCommit(@NonNull fragment: Fragment, @NonNull transaction: FragmentTransaction): Boolean {
         return if (fragment.isResumed) {
             transaction.commit()
             false
         } else {
-            mPendingTransactions.add(transaction)
+            pendingTransactions.add(transaction)
             true
         }
     }
 
     override fun onResume() {
-        if (mPendingTransactions.isNotEmpty()) {
-            mPendingTransactions.forEach { it.commit() }
-            mPendingTransactions.clear()
+        if (pendingTransactions.isNotEmpty()) {
+            pendingTransactions.forEach { it.commit() }
+            pendingTransactions.clear()
         }
     }
 
@@ -273,7 +273,7 @@ class EnhanceFragmentTransaction constructor(
 
     /**
      * 把 [fragment] 添加到回退栈中,并 hide 其他 fragment,
-     * 如果 [containerId]==0,则使用 [com.android.base.app.BaseKit.setDefaultFragmentContainerId] 中配置的 id,
+     * 如果 [containerId]==0,则使用 [com.android.base.app.Sword.setDefaultFragmentContainerId] 中配置的 id,
      * 如果 [tag] ==null 则使用 fragment 对应 class 的全限定类名。
      */
     fun addWithStack(containerId: Int = 0, fragment: Fragment, tag: String? = null, transition: Boolean = true): EnhanceFragmentTransaction {
@@ -292,7 +292,7 @@ class EnhanceFragmentTransaction constructor(
     }
 
     /**
-     * replace 方式把 [fragment] 添加到回退栈中,如果 [containerId]==0,则使用 [com.android.base.app.BaseKit.setDefaultFragmentContainerId] 中配置的 id,
+     * replace 方式把 [fragment] 添加到回退栈中,如果 [containerId]==0,则使用 [com.android.base.app.Sword.setDefaultFragmentContainerId] 中配置的 id,
      * 如果 [tag] ==null 则使用 fragment 对应 class 的全限定类名。
      */
     fun replaceWithStack(containerId: Int = 0, fragment: Fragment, tag: String? = null, transition: Boolean = true): EnhanceFragmentTransaction {
@@ -317,17 +317,17 @@ class EnhanceFragmentTransaction constructor(
     }
 
     /**
-     * 添加 [fragment],默认使用 [com.android.base.app.BaseKit.setDefaultFragmentContainerId] 中配置的 id,如果 [tag] 为null,则使用 [fragment] 的全限定类。
+     * 添加 [fragment],默认使用 [com.android.base.app.Sword.setDefaultFragmentContainerId] 中配置的 id,如果 [tag] 为null,则使用 [fragment] 的全限定类。
      */
-    fun addWithDefaultContainer(fragment: Fragment, tag: String? = null): FragmentTransaction {
+    fun addFragment(fragment: Fragment, tag: String? = null): FragmentTransaction {
         val nonnullTag = (tag ?: fragment.javaClassName())
         return fragmentTransaction.add(FragmentConfig.defaultContainerId(), fragment, nonnullTag)
     }
 
     /**
-     * 替换为 [fragment],id 使用 [com.android.base.app.BaseKit.setDefaultFragmentContainerId] 中配置的 id,如果 [tag] 为null,则使用 [fragment] 的全限定类名。
+     * 替换为 [fragment],id 使用 [com.android.base.app.Sword.setDefaultFragmentContainerId] 中配置的 id,如果 [tag] 为null,则使用 [fragment] 的全限定类名。
      */
-    fun replaceWithDefaultContainer(fragment: Fragment, tag: String? = null, transition: Boolean = true): FragmentTransaction {
+    fun replaceFragment(fragment: Fragment, tag: String? = null, transition: Boolean = true): FragmentTransaction {
         val nonnullTag = (tag ?: fragment.javaClassName())
         if (transition) {
             setOpeningTransition()
diff --git a/lib_base/src/main/java/com/android/base/app/ui/UIEx.kt b/lib_base/src/main/java/com/android/base/app/ui/UIEx.kt
index 2e9d427..e9e4413 100644
--- a/lib_base/src/main/java/com/android/base/app/ui/UIEx.kt
+++ b/lib_base/src/main/java/com/android/base/app/ui/UIEx.kt
@@ -2,7 +2,7 @@
 
 package com.android.base.app.ui
 
-import com.android.base.app.BaseKit
+import com.android.base.app.Sword
 import com.android.base.utils.common.isEmpty
 import timber.log.Timber
 
@@ -91,7 +91,7 @@ fun RefreshListLayout<*>.processListErrorWithStatus(throwable: Throwable) {
         loadMoreFailed()
     }
     if (isEmpty) {
-        val errorTypeClassifier = BaseKit.get().errorClassifier()
+        val errorTypeClassifier = Sword.get().errorClassifier()
         if (errorTypeClassifier != null) {
             when {
                 errorTypeClassifier.isNetworkError(throwable) -> showNetErrorLayout()
@@ -145,7 +145,7 @@ fun RefreshStateLayout.processErrorWithStatus(throwable: Throwable?) {
     if (isRefreshing) {
         refreshCompleted()
     }
-    val errorTypeClassifier = BaseKit.get().errorClassifier()
+    val errorTypeClassifier = Sword.get().errorClassifier()
     if (errorTypeClassifier != null) {
         when {
             errorTypeClassifier.isNetworkError(throwable) -> {
@@ -161,4 +161,4 @@ fun RefreshStateLayout.processErrorWithStatus(throwable: Throwable?) {
     } else {
         showErrorLayout()
     }
-}
+}
\ No newline at end of file
diff --git a/lib_base/src/main/java/com/android/base/data/Resource.java b/lib_base/src/main/java/com/android/base/data/Resource.java
deleted file mode 100644
index 5996635..0000000
--- a/lib_base/src/main/java/com/android/base/data/Resource.java
+++ /dev/null
@@ -1,152 +0,0 @@
-package com.android.base.data;
-
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-
-
-/**
- * @author Ztiany
- * Email: ztiany3@gmail.com
- * Date : 2018-05-15 16:23
- */
-public class Resource {
-
-    private final Throwable mError;
-    private final Status mStatus;
-    private final T mData; //data or default data
-
-    private Resource(Throwable error, T data, Status status) {
-        mError = error;
-        mStatus = status;
-        mData = data;
-    }
-
-    public boolean isSuccess() {
-        return mStatus == Status.SUCCESS;
-    }
-
-    public boolean isNoChange() {
-        return mStatus == Status.NOT_CHANGED;
-    }
-
-    public boolean isLoading() {
-        return mStatus == Status.LOADING;
-    }
-
-    public final boolean isError() {
-        return mStatus == Status.ERROR;
-    }
-
-    public final boolean hasData() {
-        return mData != null;
-    }
-
-    public static  Resource success() {
-        return new Resource<>(null, null, Status.SUCCESS);
-    }
-
-    public static  Resource success(@Nullable T data) {
-        return new Resource<>(null, data, Status.SUCCESS);
-    }
-
-    public static  Resource error(@NonNull Throwable error) {
-        return error(error, null);
-    }
-
-    /**
-     * 创建一个 error 状态,且设置一个默认的数据
-     */
-    public static  Resource error(@NonNull Throwable error, T defaultValue) {
-        return new Resource<>(error, defaultValue, Status.ERROR);
-    }
-
-    public static  Resource loading() {
-        return loading(null);
-    }
-
-    /**
-     * 创建一个 loading 状态,且设置一个默认的数据
-     */
-    public static  Resource loading(T defaultValue) {
-        return new Resource<>(null, defaultValue, Status.LOADING);
-    }
-
-    /**
-     * 如果数据源(比如 Repository)缓存了上一次请求的数据,然后对其当前请求返回的数据,发现数据是一样的,可以使用此状态表示
-     *
-     * @return Resource
-     */
-    public static Resource noChange() {
-        return new Resource<>(null, null, Status.NOT_CHANGED);
-    }
-
-    /**
-     * 获取 Resource 中保存的数据,只有在 success 状态并且存在数据时下才能调用此方法,否则将抛出异常。
-     *
-     * @return Resource 中保存的数据。
-     * @throws UnsupportedOperationException 非 success 状态调用此方法。
-     * @throws NullPointerException          Resource 中没有保存数据时调用此方法。
-     */
-    @NonNull
-    public T data() {
-        if (isError() || isLoading() || isNoChange()) {
-            throw new UnsupportedOperationException("This method can only be called when the state success");
-        }
-        if (mData == null) {
-            throw new NullPointerException("Data is null");
-        }
-        return mData;
-    }
-
-    /**
-     * 获取 Resource 中保存的数据,如果不存在数据则返回 defaultData 所设置的默认数据,在不同状态下获取的数据具有不同的意义:
-     *
-     * 
-     *     
  • success 状态下,返回一个成功操作所产生的数据
  • - *
  • error 状态下,返回一个默认的数据,如果存在的话
  • - *
  • loading 状态下,返回一个默认的数据,如果存在的话
  • - *
    - * - * @param defaultData 如果不存在数据则返回 defaultData 所设置的默认数据。 - * @return Resource 中保存的数据。 - */ - @Nullable - public T orElse(@Nullable T defaultData) { - if (mData == null) { - return defaultData; - } - return mData; - } - - /** - * 获取 Resource 中保存的数据,在不同状态下获取的数据具有不同的意义: - * - *
    -     *     
  • success 状态下,返回一个成功操作所产生的数据
  • - *
  • error 状态下,返回一个默认的数据,如果存在的话
  • - *
  • loading 状态下,返回一个默认的数据,如果存在的话
  • - *
    - * - * @return Resource 中保存的数据。 - */ - @Nullable - public T get() { - return mData; - } - - public Throwable error() { - return mError; - } - - @NonNull - @Override - public String toString() { - return "Resource{" + - "mError=" + mError + - ", mStatus=" + mStatus + - ", mData=" + mData + - '}'; - } - -} \ No newline at end of file diff --git a/lib_base/src/main/java/com/android/base/data/Resource.kt b/lib_base/src/main/java/com/android/base/data/Resource.kt index cbdc056..6ec7dc9 100644 --- a/lib_base/src/main/java/com/android/base/data/Resource.kt +++ b/lib_base/src/main/java/com/android/base/data/Resource.kt @@ -1,5 +1,135 @@ package com.android.base.data + +/** + * @author Ztiany + * Email: ztiany3@gmail.com + * Date : 2018-05-15 16:23 + */ +class Resource private constructor( + private val error: Throwable?, + //data or default data + private val data: T?, + private val status: Status +) { + + val isSuccess: Boolean + get() = status == Status.SUCCESS + + val isNoChange: Boolean + get() = status == Status.NOT_CHANGED + + val isLoading: Boolean + get() = status == Status.LOADING + + val isError: Boolean + get() = status == Status.ERROR + + fun hasData(): Boolean { + return data != null + } + + /** + * 获取 Resource 中保存的数据,只有在 success 状态并且存在数据时下才能调用此方法,否则将抛出异常。 + * + * @return Resource 中保存的数据。 + * @throws UnsupportedOperationException 非 success 状态调用此方法。 + * @throws NullPointerException Resource 中没有保存数据时调用此方法。 + */ + fun data(): T { + if (isError || isLoading || isNoChange) { + throw UnsupportedOperationException("This method can only be called when the is state success") + } + if (data == null) { + throw NullPointerException("Data is null") + } + return data + } + + /** + * 获取 Resource 中保存的数据,如果不存在数据则返回 defaultData 所设置的默认数据,在不同状态下获取的数据具有不同的意义: + * + * * success 状态下,返回一个成功操作所产生的数据 + * * error 状态下,返回一个默认的数据,如果存在的话 + * * loading 状态下,返回一个默认的数据,如果存在的话 + * + * @param defaultData 如果不存在数据则返回 defaultData 所设置的默认数据。 + * @return Resource 中保存的数据。 + */ + fun orElse(defaultData: T?): T? { + return data ?: defaultData + } + + /** + * 获取 Resource 中保存的数据,在不同状态下获取的数据具有不同的意义: + * + * * success 状态下,返回一个成功操作所产生的数据 + * * error 状态下,返回一个默认的数据,如果存在的话 + * * loading 状态下,返回一个默认的数据,如果存在的话 + * + * @return Resource 中保存的数据。 + */ + fun get(): T? { + return data + } + + fun error(): Throwable { + return error ?: throw NullPointerException("This method can only be called when the state is error") + } + + override fun toString(): String { + return "Resource{" + + "mError=" + error + + ", mStatus=" + status + + ", mData=" + data + + '}'.toString() + } + + companion object { + + fun success(): Resource { + return Resource(null, null, Status.SUCCESS) + } + + fun success(data: T?): Resource { + return Resource(null, data, Status.SUCCESS) + } + + fun error(error: Throwable): Resource { + return error(error, null) + } + + /** + * 创建一个 error 状态,且设置一个默认的数据 + */ + fun error(error: Throwable, defaultValue: T?): Resource { + return Resource(error, defaultValue, Status.ERROR) + } + + fun loading(): Resource { + return loading(null) + } + + /** + * 创建一个 loading 状态,且设置一个默认的数据 + */ + fun loading(defaultValue: T?): Resource { + return Resource(null, defaultValue, Status.LOADING) + } + + /** + * 如果数据源(比如 Repository)缓存了上一次请求的数据,然后对其当前请求返回的数据,发现数据是一样的,可以使用此状态表示 + * + * @return Resource + */ + fun noChange(): Resource { + return Resource(null, null, Status.NOT_CHANGED) + } + } + +} + + /**when in loading*/ inline fun Resource.onLoading(onLoading: () -> Unit): Resource { if (this.isLoading) { diff --git a/lib_base/src/main/java/com/android/base/data/Status.java b/lib_base/src/main/java/com/android/base/data/Status.kt similarity index 68% rename from lib_base/src/main/java/com/android/base/data/Status.java rename to lib_base/src/main/java/com/android/base/data/Status.kt index 9add2c2..c68eb77 100644 --- a/lib_base/src/main/java/com/android/base/data/Status.java +++ b/lib_base/src/main/java/com/android/base/data/Status.kt @@ -1,4 +1,4 @@ -package com.android.base.data; +package com.android.base.data /** * 用于表示各种状态 @@ -7,9 +7,9 @@ package com.android.base.data; * Email: ztiany3@gmail.com * Date : 2019-02-18 11:49 */ -public enum Status { +enum class Status { LOADING, ERROR, SUCCESS, - NOT_CHANGED, + NOT_CHANGED } diff --git a/lib_base/src/main/java/com/android/base/imageloader/DisplayConfig.java b/lib_base/src/main/java/com/android/base/imageloader/DisplayConfig.java index 8c8fe3c..266e042 100644 --- a/lib_base/src/main/java/com/android/base/imageloader/DisplayConfig.java +++ b/lib_base/src/main/java/com/android/base/imageloader/DisplayConfig.java @@ -30,7 +30,6 @@ public class DisplayConfig { public static final int ANIM_NONE = 1; private DisplayConfig() { - } public static DisplayConfig create() { diff --git a/lib_base/src/main/java/com/android/base/interfaces/adapter/ActivityLifecycleCallbacksAdapter.java b/lib_base/src/main/java/com/android/base/interfaces/ActivityLifecycleCallbacksAdapter.java similarity index 94% rename from lib_base/src/main/java/com/android/base/interfaces/adapter/ActivityLifecycleCallbacksAdapter.java rename to lib_base/src/main/java/com/android/base/interfaces/ActivityLifecycleCallbacksAdapter.java index 436fcd8..37cac1e 100644 --- a/lib_base/src/main/java/com/android/base/interfaces/adapter/ActivityLifecycleCallbacksAdapter.java +++ b/lib_base/src/main/java/com/android/base/interfaces/ActivityLifecycleCallbacksAdapter.java @@ -1,4 +1,4 @@ -package com.android.base.interfaces.adapter; +package com.android.base.interfaces; import android.app.Activity; import android.app.Application; diff --git a/lib_base/src/main/java/com/android/base/interfaces/adapter/DrawerListenerAdapter.java b/lib_base/src/main/java/com/android/base/interfaces/DrawerListenerAdapter.java similarity index 92% rename from lib_base/src/main/java/com/android/base/interfaces/adapter/DrawerListenerAdapter.java rename to lib_base/src/main/java/com/android/base/interfaces/DrawerListenerAdapter.java index c3806fe..1174a13 100644 --- a/lib_base/src/main/java/com/android/base/interfaces/adapter/DrawerListenerAdapter.java +++ b/lib_base/src/main/java/com/android/base/interfaces/DrawerListenerAdapter.java @@ -1,4 +1,4 @@ -package com.android.base.interfaces.adapter; +package com.android.base.interfaces; import android.view.View; diff --git a/lib_base/src/main/java/com/android/base/interfaces/adapter/OnPageChangeListenerAdapter.java b/lib_base/src/main/java/com/android/base/interfaces/OnPageChangeListenerAdapter.java similarity index 91% rename from lib_base/src/main/java/com/android/base/interfaces/adapter/OnPageChangeListenerAdapter.java rename to lib_base/src/main/java/com/android/base/interfaces/OnPageChangeListenerAdapter.java index 5ef966c..ac034c5 100644 --- a/lib_base/src/main/java/com/android/base/interfaces/adapter/OnPageChangeListenerAdapter.java +++ b/lib_base/src/main/java/com/android/base/interfaces/OnPageChangeListenerAdapter.java @@ -1,4 +1,4 @@ -package com.android.base.interfaces.adapter; +package com.android.base.interfaces; import androidx.viewpager.widget.ViewPager; diff --git a/lib_base/src/main/java/com/android/base/interfaces/adapter/OnSeekBarChangeListenerAdapter.java b/lib_base/src/main/java/com/android/base/interfaces/OnSeekBarChangeListenerAdapter.java similarity index 91% rename from lib_base/src/main/java/com/android/base/interfaces/adapter/OnSeekBarChangeListenerAdapter.java rename to lib_base/src/main/java/com/android/base/interfaces/OnSeekBarChangeListenerAdapter.java index 8f985df..0ce3654 100644 --- a/lib_base/src/main/java/com/android/base/interfaces/adapter/OnSeekBarChangeListenerAdapter.java +++ b/lib_base/src/main/java/com/android/base/interfaces/OnSeekBarChangeListenerAdapter.java @@ -1,4 +1,4 @@ -package com.android.base.interfaces.adapter; +package com.android.base.interfaces; import android.widget.SeekBar; diff --git a/lib_base/src/main/java/com/android/base/interfaces/adapter/OnTabSelectedListenerAdapter.java b/lib_base/src/main/java/com/android/base/interfaces/OnTabSelectedListenerAdapter.java similarity index 89% rename from lib_base/src/main/java/com/android/base/interfaces/adapter/OnTabSelectedListenerAdapter.java rename to lib_base/src/main/java/com/android/base/interfaces/OnTabSelectedListenerAdapter.java index 9ab1f68..9e32141 100644 --- a/lib_base/src/main/java/com/android/base/interfaces/adapter/OnTabSelectedListenerAdapter.java +++ b/lib_base/src/main/java/com/android/base/interfaces/OnTabSelectedListenerAdapter.java @@ -1,4 +1,4 @@ -package com.android.base.interfaces.adapter; +package com.android.base.interfaces; import com.google.android.material.tabs.TabLayout; diff --git a/lib_base/src/main/java/com/android/base/interfaces/adapter/TextWatcherAdapter.java b/lib_base/src/main/java/com/android/base/interfaces/TextWatcherAdapter.java similarity index 91% rename from lib_base/src/main/java/com/android/base/interfaces/adapter/TextWatcherAdapter.java rename to lib_base/src/main/java/com/android/base/interfaces/TextWatcherAdapter.java index a27d7c5..93b4daa 100644 --- a/lib_base/src/main/java/com/android/base/interfaces/adapter/TextWatcherAdapter.java +++ b/lib_base/src/main/java/com/android/base/interfaces/TextWatcherAdapter.java @@ -1,4 +1,4 @@ -package com.android.base.interfaces.adapter; +package com.android.base.interfaces; import android.text.Editable; import android.text.TextWatcher; diff --git a/lib_base/src/main/java/com/android/base/interfaces/adapter/TransitionListenerAdapter.java b/lib_base/src/main/java/com/android/base/interfaces/TransitionListenerAdapter.java similarity index 93% rename from lib_base/src/main/java/com/android/base/interfaces/adapter/TransitionListenerAdapter.java rename to lib_base/src/main/java/com/android/base/interfaces/TransitionListenerAdapter.java index f1a0b29..607cbe9 100644 --- a/lib_base/src/main/java/com/android/base/interfaces/adapter/TransitionListenerAdapter.java +++ b/lib_base/src/main/java/com/android/base/interfaces/TransitionListenerAdapter.java @@ -1,4 +1,4 @@ -package com.android.base.interfaces.adapter; +package com.android.base.interfaces; import android.os.Build; import android.transition.Transition; diff --git a/lib_base/src/main/java/com/android/base/utils/android/SoftKeyboardUtils.java b/lib_base/src/main/java/com/android/base/utils/android/SoftKeyboardUtils.java index af6bdf0..5eaebc2 100644 --- a/lib_base/src/main/java/com/android/base/utils/android/SoftKeyboardUtils.java +++ b/lib_base/src/main/java/com/android/base/utils/android/SoftKeyboardUtils.java @@ -81,5 +81,4 @@ public class SoftKeyboardUtils { } } - -} +} \ No newline at end of file diff --git a/lib_base/src/main/java/com/android/base/utils/android/VideoUtils.java b/lib_base/src/main/java/com/android/base/utils/android/VideoUtils.java index 901caff..d2ff16b 100644 --- a/lib_base/src/main/java/com/android/base/utils/android/VideoUtils.java +++ b/lib_base/src/main/java/com/android/base/utils/android/VideoUtils.java @@ -22,4 +22,4 @@ public class VideoUtils { return bitmap; } -} +} \ No newline at end of file diff --git a/lib_base/src/main/java/com/android/base/utils/android/WebViewUtils.java b/lib_base/src/main/java/com/android/base/utils/android/WebViewUtils.java index e259e0d..c46f722 100644 --- a/lib_base/src/main/java/com/android/base/utils/android/WebViewUtils.java +++ b/lib_base/src/main/java/com/android/base/utils/android/WebViewUtils.java @@ -121,4 +121,4 @@ public class WebViewUtils { }); } -} +} \ No newline at end of file diff --git a/lib_base/src/main/java/com/android/base/utils/android/WindowUtils.java b/lib_base/src/main/java/com/android/base/utils/android/WindowUtils.java index a1f60ea..b027080 100644 --- a/lib_base/src/main/java/com/android/base/utils/android/WindowUtils.java +++ b/lib_base/src/main/java/com/android/base/utils/android/WindowUtils.java @@ -34,8 +34,6 @@ public final class WindowUtils { */ public static int getDisplayRotation(Activity activity) { switch (activity.getWindowManager().getDefaultDisplay().getRotation()) { - case Surface.ROTATION_0: - return 0; case Surface.ROTATION_90: return 90; case Surface.ROTATION_180: @@ -154,5 +152,4 @@ public final class WindowUtils { return km != null && km.inKeyguardRestrictedInputMode(); } - -} +} \ No newline at end of file diff --git a/lib_base/src/main/java/com/android/base/utils/android/XIntentUtils.java b/lib_base/src/main/java/com/android/base/utils/android/XIntentUtils.java index dec71f0..27651ea 100644 --- a/lib_base/src/main/java/com/android/base/utils/android/XIntentUtils.java +++ b/lib_base/src/main/java/com/android/base/utils/android/XIntentUtils.java @@ -163,4 +163,4 @@ public class XIntentUtils { } } -} +} \ No newline at end of file diff --git a/lib_base/src/main/java/com/android/base/utils/android/views/ListViewEx.kt b/lib_base/src/main/java/com/android/base/utils/android/views/ListViewEx.kt new file mode 100644 index 0000000..ef044d7 --- /dev/null +++ b/lib_base/src/main/java/com/android/base/utils/android/views/ListViewEx.kt @@ -0,0 +1,15 @@ +package com.android.base.utils.android.views + +import android.view.View +import android.widget.ListView + +/**ListView 局部刷新*/ +fun ListView.updateItemView(position: Int, updater: (itemView: View) -> Unit) { + val firstPos = firstVisiblePosition + val lastPos = lastVisiblePosition + //可见才更新,不可见则在getView()时更新 + if (position in firstPos..lastPos) { + val view = getChildAt(position - firstPos) + updater(view) + } +} \ No newline at end of file diff --git a/lib_base/src/main/java/com/android/base/utils/android/views/TextViewEx.kt b/lib_base/src/main/java/com/android/base/utils/android/views/TextViewEx.kt index 15a894b..fcc0239 100644 --- a/lib_base/src/main/java/com/android/base/utils/android/views/TextViewEx.kt +++ b/lib_base/src/main/java/com/android/base/utils/android/views/TextViewEx.kt @@ -11,7 +11,7 @@ import android.widget.EditText import android.widget.TextView import androidx.annotation.DrawableRes import androidx.core.content.ContextCompat -import com.android.base.interfaces.adapter.TextWatcherAdapter +import com.android.base.interfaces.TextWatcherAdapter import com.google.android.material.textfield.TextInputLayout inline fun TextView.textWatcher(init: KTextWatcher.() -> Unit) = addTextChangedListener(KTextWatcher().apply(init)) diff --git a/lib_base/src/main/java/com/android/base/utils/android/views/TintUtils.kt b/lib_base/src/main/java/com/android/base/utils/android/views/TintUtils.kt index 98fd0b9..ba4d325 100644 --- a/lib_base/src/main/java/com/android/base/utils/android/views/TintUtils.kt +++ b/lib_base/src/main/java/com/android/base/utils/android/views/TintUtils.kt @@ -51,4 +51,4 @@ fun tint(originDrawable: Drawable, colorStateList: ColorStateList, tintMode: Por } DrawableCompat.setTintList(tintDrawable, colorStateList) return tintDrawable -} +} \ No newline at end of file diff --git a/lib_base/src/main/java/com/android/base/utils/android/views/ViewEx.kt b/lib_base/src/main/java/com/android/base/utils/android/views/ViewEx.kt index 1ca2826..ebc8c4b 100644 --- a/lib_base/src/main/java/com/android/base/utils/android/views/ViewEx.kt +++ b/lib_base/src/main/java/com/android/base/utils/android/views/ViewEx.kt @@ -131,59 +131,83 @@ fun View.setPaddingBottom(padding: Int) { this.setPadding(paddingLeft, paddingTop, paddingRight, padding) } -fun newLayoutParams(width: Int = ViewGroup.MarginLayoutParams.WRAP_CONTENT, height: Int = ViewGroup.MarginLayoutParams.WRAP_CONTENT): ViewGroup.LayoutParams { - return ViewGroup.LayoutParams(width, height) +fun newWWLayoutParams(): ViewGroup.LayoutParams { + return ViewGroup.LayoutParams(ViewGroup.MarginLayoutParams.WRAP_CONTENT, ViewGroup.MarginLayoutParams.WRAP_CONTENT) } -fun newMarginLayoutParams(width: Int = ViewGroup.MarginLayoutParams.WRAP_CONTENT, height: Int = ViewGroup.MarginLayoutParams.WRAP_CONTENT): ViewGroup.MarginLayoutParams { - return ViewGroup.MarginLayoutParams(width, height) +fun newWMLayoutParams(): ViewGroup.LayoutParams { + return ViewGroup.LayoutParams(ViewGroup.MarginLayoutParams.WRAP_CONTENT, ViewGroup.MarginLayoutParams.MATCH_PARENT) } -fun View.setTopMargin(topMargin: Int) { +fun newMWLayoutParams(): ViewGroup.LayoutParams { + return ViewGroup.LayoutParams(ViewGroup.MarginLayoutParams.MATCH_PARENT, ViewGroup.MarginLayoutParams.WRAP_CONTENT) +} + +fun newMMLayoutParams(): ViewGroup.LayoutParams { + return ViewGroup.LayoutParams(ViewGroup.MarginLayoutParams.MATCH_PARENT, ViewGroup.MarginLayoutParams.MATCH_PARENT) +} + +fun newWWMarginLayoutParams(): ViewGroup.MarginLayoutParams { + return ViewGroup.MarginLayoutParams(ViewGroup.MarginLayoutParams.WRAP_CONTENT, ViewGroup.MarginLayoutParams.WRAP_CONTENT) +} + +fun newWMMarginLayoutParams(): ViewGroup.MarginLayoutParams { + return ViewGroup.MarginLayoutParams(ViewGroup.MarginLayoutParams.WRAP_CONTENT, ViewGroup.MarginLayoutParams.MATCH_PARENT) +} + +fun newMWMarginLayoutParams(): ViewGroup.MarginLayoutParams { + return ViewGroup.MarginLayoutParams(ViewGroup.MarginLayoutParams.MATCH_PARENT, ViewGroup.MarginLayoutParams.WRAP_CONTENT) +} + +fun newMMMarginLayoutParams(): ViewGroup.MarginLayoutParams { + return ViewGroup.MarginLayoutParams(ViewGroup.MarginLayoutParams.MATCH_PARENT, ViewGroup.MarginLayoutParams.MATCH_PARENT) +} + +fun View.setTopMargin(topMargin: Int, layoutParamsCreator: (() -> ViewGroup.MarginLayoutParams)? = null) { val params: ViewGroup.LayoutParams? = layoutParams if (params is ViewGroup.MarginLayoutParams) { params.topMargin = topMargin } else { - layoutParams = newMarginLayoutParams().apply { + layoutParams = layoutParamsCreator?.invoke() ?: newWWMarginLayoutParams().apply { this.topMargin = topMargin } } } -fun View.setBottomMargin(bottomMargin: Int) { +fun View.setBottomMargin(bottomMargin: Int, layoutParamsCreator: (() -> ViewGroup.MarginLayoutParams)? = null) { val params: ViewGroup.LayoutParams? = layoutParams if (params is ViewGroup.MarginLayoutParams) { params.bottomMargin = bottomMargin } else { - layoutParams = newMarginLayoutParams().apply { + layoutParams = layoutParamsCreator?.invoke() ?: newWWMarginLayoutParams().apply { this.bottomMargin = bottomMargin } } } -fun View.setLeftMargin(leftMargin: Int) { +fun View.setLeftMargin(leftMargin: Int, layoutParamsCreator: (() -> ViewGroup.MarginLayoutParams)? = null) { val params: ViewGroup.LayoutParams? = layoutParams if (params is ViewGroup.MarginLayoutParams) { params.leftMargin = leftMargin } else { - layoutParams = newMarginLayoutParams().apply { + layoutParams = layoutParamsCreator?.invoke() ?: newWWMarginLayoutParams().apply { this.leftMargin = leftMargin } } } -fun View.setRightMargin(rightMargin: Int) { +fun View.setRightMargin(rightMargin: Int, layoutParamsCreator: (() -> ViewGroup.MarginLayoutParams)? = null) { val params: ViewGroup.LayoutParams? = layoutParams if (params is ViewGroup.MarginLayoutParams) { params.rightMargin = rightMargin } else { - layoutParams = newMarginLayoutParams().apply { + layoutParams = layoutParamsCreator?.invoke() ?: newWWMarginLayoutParams().apply { this.rightMargin = rightMargin } } } -fun View.setRightMargins(leftMargin: Int, topMargin: Int, rightMargin: Int, bottomMargin: Int) { +fun View.setMargins(leftMargin: Int, topMargin: Int, rightMargin: Int, bottomMargin: Int, layoutParamsCreator: (() -> ViewGroup.MarginLayoutParams)? = null) { val params: ViewGroup.LayoutParams? = layoutParams if (params is ViewGroup.MarginLayoutParams) { params.rightMargin = rightMargin @@ -191,7 +215,7 @@ fun View.setRightMargins(leftMargin: Int, topMargin: Int, rightMargin: Int, bott params.bottomMargin = bottomMargin params.topMargin = topMargin } else { - layoutParams = newMarginLayoutParams().apply { + layoutParams = layoutParamsCreator?.invoke() ?: newWWMarginLayoutParams().apply { this.rightMargin = rightMargin this.leftMargin = leftMargin this.bottomMargin = bottomMargin diff --git a/lib_base/src/main/java/com/android/base/widget/ScrollChildSwipeRefreshLayout.java b/lib_base/src/main/java/com/android/base/widget/ScrollChildSwipeRefreshLayout.java index 1075954..88ee72d 100644 --- a/lib_base/src/main/java/com/android/base/widget/ScrollChildSwipeRefreshLayout.java +++ b/lib_base/src/main/java/com/android/base/widget/ScrollChildSwipeRefreshLayout.java @@ -45,7 +45,7 @@ public class ScrollChildSwipeRefreshLayout extends SwipeRefreshLayout { TypedArray colorsTypeArray = getResources().obtainTypedArray(colorSchemeArrayId); int indexCount = colorsTypeArray.length(); if (indexCount != 0) { - int colors[] = new int[indexCount]; + int[] colors = new int[indexCount]; for (int i = 0; i < indexCount; i++) { colors[i] = colorsTypeArray.getColor(i, Color.BLACK); } diff --git a/lib_base/src/main/java/com/android/base/widget/pulltozoom/PullToZoomScrollView.java b/lib_base/src/main/java/com/android/base/widget/pulltozoom/PullToZoomScrollView.java index f5bdefc..acbd0c3 100644 --- a/lib_base/src/main/java/com/android/base/widget/pulltozoom/PullToZoomScrollView.java +++ b/lib_base/src/main/java/com/android/base/widget/pulltozoom/PullToZoomScrollView.java @@ -128,7 +128,6 @@ public class PullToZoomScrollView extends NestedScrollView { return mContainerView != null && mZoomView != null; } - @Override protected boolean overScrollByCompat(int deltaX, int deltaY, int scrollX, int scrollY, @@ -249,4 +248,4 @@ public class PullToZoomScrollView extends NestedScrollView { return (int) (dp * getContext().getResources().getDisplayMetrics().density + 0.5f); } -} +} \ No newline at end of file diff --git a/lib_base/src/main/java/com/android/base/widget/viewpager/ZViewPager.java b/lib_base/src/main/java/com/android/base/widget/viewpager/BannerViewPager.java similarity index 92% rename from lib_base/src/main/java/com/android/base/widget/viewpager/ZViewPager.java rename to lib_base/src/main/java/com/android/base/widget/viewpager/BannerViewPager.java index 839ac7f..fa7e63a 100644 --- a/lib_base/src/main/java/com/android/base/widget/viewpager/ZViewPager.java +++ b/lib_base/src/main/java/com/android/base/widget/viewpager/BannerViewPager.java @@ -19,7 +19,7 @@ import androidx.viewpager.widget.ViewPager; * * @author Ztiany */ -public class ZViewPager extends FrameLayout { +public class BannerViewPager extends FrameLayout { private final ViewPager mViewPager; private IPagerNumberView mPageNumberView; @@ -32,24 +32,24 @@ public class ZViewPager extends FrameLayout { private String mTransitionName; private OnPageClickListener mOnPageClickListener; - public ZViewPager(Context context) { + public BannerViewPager(Context context) { this(context, null); } - public ZViewPager(Context context, AttributeSet attrs) { + public BannerViewPager(Context context, AttributeSet attrs) { this(context, attrs, 0); } - public ZViewPager(Context context, AttributeSet attrs, int defStyleAttr) { + public BannerViewPager(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); - TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ZViewPager); + TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.BannerViewPager); /*是否可以缩放*/ - mScalable = typedArray.getBoolean(R.styleable.ZViewPager_zvp_scale, false); + mScalable = typedArray.getBoolean(R.styleable.BannerViewPager_zvp_scale_enable, false); /*用于支持5.0的transition动画*/ - mTransitionName = typedArray.getString(R.styleable.ZViewPager_zvp_item_transition_name); - int pageId = typedArray.getResourceId(R.styleable.ZViewPager_zvp_pager_number_id, -1); + mTransitionName = typedArray.getString(R.styleable.BannerViewPager_zvp_item_transition_name); + int pageId = typedArray.getResourceId(R.styleable.BannerViewPager_zvp_pager_number_id, -1); typedArray.recycle(); diff --git a/lib_base/src/main/java/com/android/base/widget/viewpager/IPagerNumberView.java b/lib_base/src/main/java/com/android/base/widget/viewpager/IPagerNumberView.java index af2a24a..26520bd 100644 --- a/lib_base/src/main/java/com/android/base/widget/viewpager/IPagerNumberView.java +++ b/lib_base/src/main/java/com/android/base/widget/viewpager/IPagerNumberView.java @@ -7,7 +7,7 @@ package com.android.base.widget.viewpager; */ public interface IPagerNumberView { - void setViewPager(ZViewPager viewPager); + void setViewPager(BannerViewPager viewPager); void setPageSize(int i); diff --git a/lib_base/src/main/java/com/android/base/widget/viewpager/PageNumberView.kt b/lib_base/src/main/java/com/android/base/widget/viewpager/PageNumberView.kt index d814a07..6e86016 100644 --- a/lib_base/src/main/java/com/android/base/widget/viewpager/PageNumberView.kt +++ b/lib_base/src/main/java/com/android/base/widget/viewpager/PageNumberView.kt @@ -83,7 +83,7 @@ class PageNumberView @JvmOverloads constructor( invalidate() } - override fun setViewPager(viewPager: ZViewPager) { + override fun setViewPager(viewPager: BannerViewPager) { //no op } diff --git a/lib_base/src/main/res/values/base_attrs.xml b/lib_base/src/main/res/values/base_attrs.xml index 2745c3e..fc60ef6 100644 --- a/lib_base/src/main/res/values/base_attrs.xml +++ b/lib_base/src/main/res/values/base_attrs.xml @@ -1,8 +1,9 @@ - - + + + diff --git a/lib_base/src/test/java/com/android/base/rx/TestApplication.java b/lib_base/src/test/java/com/android/base/rx/TestApplication.java index 39a453a..f627f89 100644 --- a/lib_base/src/test/java/com/android/base/rx/TestApplication.java +++ b/lib_base/src/test/java/com/android/base/rx/TestApplication.java @@ -3,7 +3,7 @@ package com.android.base.rx; import android.app.Application; import android.content.Context; -import com.android.base.app.BaseKit; +import com.android.base.app.Sword; /** * @author Ztiany @@ -15,7 +15,7 @@ public class TestApplication extends Application { @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); - BaseKit.get().getApplicationDelegate().attachBaseContext(base); + Sword.get().getApplicationDelegate().attachBaseContext(base); } } diff --git a/lib_base/src/test/java/com/android/base/rx/TestListFragment.java b/lib_base/src/test/java/com/android/base/rx/TestListFragment.java index 4244264..71f1e45 100644 --- a/lib_base/src/test/java/com/android/base/rx/TestListFragment.java +++ b/lib_base/src/test/java/com/android/base/rx/TestListFragment.java @@ -9,6 +9,8 @@ import com.android.base.adapter.recycler.MultiTypeAdapter; import com.android.base.app.fragment.BaseListFragment; import com.android.base.app.ui.AutoPageNumber; +import org.jetbrains.annotations.NotNull; + /** * @author Ztiany * Email: ztiany3@gmail.com @@ -17,7 +19,7 @@ import com.android.base.app.ui.AutoPageNumber; public class TestListFragment extends BaseListFragment { @Override - protected void onViewPrepared(@NonNull View view, @Nullable Bundle savedInstanceState) { + protected void onViewPrepared(@NotNull @NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewPrepared(view, savedInstanceState); MultiTypeAdapter recyclerAdapter = new MultiTypeAdapter(getContext()); setupLoadMore(recyclerAdapter, new AutoPageNumber(this,recyclerAdapter)); diff --git a/lib_base/src/test/java/com/android/base/rx/TestStateFragment.java b/lib_base/src/test/java/com/android/base/rx/TestStateFragment.java index 0145786..41d5d3c 100644 --- a/lib_base/src/test/java/com/android/base/rx/TestStateFragment.java +++ b/lib_base/src/test/java/com/android/base/rx/TestStateFragment.java @@ -8,6 +8,8 @@ import android.view.View; import com.android.base.app.fragment.BaseStateFragment; +import org.jetbrains.annotations.NotNull; + /** * @author Ztiany * Email: 1169654504@qq.com @@ -16,7 +18,7 @@ import com.android.base.app.fragment.BaseStateFragment; public class TestStateFragment extends BaseStateFragment { @Override - public void onAttach(Context context) { + public void onAttach(@NotNull Context context) { super.onAttach(context); } @@ -26,7 +28,7 @@ public class TestStateFragment extends BaseStateFragment { } @Override - protected void onViewPrepared(@NonNull View view, @Nullable Bundle savedInstanceState) { + protected void onViewPrepared(@NotNull @NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewPrepared(view, savedInstanceState); getStateLayoutConfig(); }