Commit dd88abe61c0a0f0f617ea4cd44ad0557bacb3028
1 parent
f8fe5b61
Fix Click type conversion problem.
Showing
7 changed files
with
56 additions
and
48 deletions
.idea/misc.xml
| 1 | <?xml version="1.0" encoding="UTF-8"?> | 1 | <?xml version="1.0" encoding="UTF-8"?> |
| 2 | <project version="4"> | 2 | <project version="4"> |
| 3 | - <component name="EntryPointsManager"> | ||
| 4 | - <entry_points version="2.0" /> | ||
| 5 | - </component> | ||
| 6 | <component name="MavenImportPreferences"> | 3 | <component name="MavenImportPreferences"> |
| 7 | <option name="generalSettings"> | 4 | <option name="generalSettings"> |
| 8 | <MavenGeneralSettings> | 5 | <MavenGeneralSettings> |
| @@ -34,17 +31,7 @@ | @@ -34,17 +31,7 @@ | ||
| 34 | </value> | 31 | </value> |
| 35 | </option> | 32 | </option> |
| 36 | </component> | 33 | </component> |
| 37 | - <component name="ProjectLevelVcsManager" settingsEditedManually="false"> | ||
| 38 | - <OptionsSetting value="true" id="Add" /> | ||
| 39 | - <OptionsSetting value="true" id="Remove" /> | ||
| 40 | - <OptionsSetting value="true" id="Checkout" /> | ||
| 41 | - <OptionsSetting value="true" id="Update" /> | ||
| 42 | - <OptionsSetting value="true" id="Status" /> | ||
| 43 | - <OptionsSetting value="true" id="Edit" /> | ||
| 44 | - <ConfirmationsSetting value="0" id="Add" /> | ||
| 45 | - <ConfirmationsSetting value="0" id="Remove" /> | ||
| 46 | - </component> | ||
| 47 | - <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> | 34 | + <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> |
| 48 | <output url="file://$PROJECT_DIR$/build/classes" /> | 35 | <output url="file://$PROJECT_DIR$/build/classes" /> |
| 49 | </component> | 36 | </component> |
| 50 | <component name="ProjectType"> | 37 | <component name="ProjectType"> |
app/src/main/java/com/cnlive/libs/demo/mvptest/frame/presenter/LaunchPresenter.java
| @@ -5,7 +5,6 @@ import android.content.Context; | @@ -5,7 +5,6 @@ import android.content.Context; | ||
| 5 | import android.content.Intent; | 5 | import android.content.Intent; |
| 6 | 6 | ||
| 7 | import com.cnlive.libs.base.data.network.Subscriber; | 7 | import com.cnlive.libs.base.data.network.Subscriber; |
| 8 | -import com.cnlive.libs.base.util.LogUtil; | ||
| 9 | import com.cnlive.libs.base.util.TimerUtil; | 8 | import com.cnlive.libs.base.util.TimerUtil; |
| 10 | import com.cnlive.libs.demo.Config; | 9 | import com.cnlive.libs.demo.Config; |
| 11 | import com.cnlive.libs.demo.MainActivity; | 10 | import com.cnlive.libs.demo.MainActivity; |
| @@ -62,24 +61,24 @@ public class LaunchPresenter extends MvpBasePresenter<LaunchView> { | @@ -62,24 +61,24 @@ public class LaunchPresenter extends MvpBasePresenter<LaunchView> { | ||
| 62 | public void startTimer(long totalTime) { | 61 | public void startTimer(long totalTime) { |
| 63 | if (timerUtil != null) timerUtil.cancel(); | 62 | if (timerUtil != null) timerUtil.cancel(); |
| 64 | 63 | ||
| 65 | - timerUtil = new TimerUtil(); | ||
| 66 | - timerUtil.setTotalTime(totalTime);//设置毫秒数 | ||
| 67 | - timerUtil.setIntervalTime(1000);//设置间隔数 | ||
| 68 | - timerUtil.start(); | ||
| 69 | - timerUtil.setTimerLiener(new TimerUtil.TimeListener() { | ||
| 70 | - @Override | ||
| 71 | - public void onFinish() { | ||
| 72 | - ILaunchView view = getView(); | ||
| 73 | - if (view != null) view.onTimerFinish(); | ||
| 74 | - } | ||
| 75 | - | ||
| 76 | - @Override | ||
| 77 | - public void onInterval(long remainTime) { | ||
| 78 | - ILaunchView view = getView(); | ||
| 79 | - if (view != null) view.onTimerInterval(remainTime / 1000); | ||
| 80 | - LogUtil.d("LaunchView", "剩余时间" + remainTime); | ||
| 81 | - } | ||
| 82 | - }); | 64 | +// timerUtil = new TimerUtil(); |
| 65 | +// timerUtil.setTotalTime(totalTime);//设置毫秒数 | ||
| 66 | +// timerUtil.setIntervalTime(1000);//设置间隔数 | ||
| 67 | +// timerUtil.start(); | ||
| 68 | +// timerUtil.setTimerLiener(new TimerUtil.TimeListener() { | ||
| 69 | +// @Override | ||
| 70 | +// public void onFinish() { | ||
| 71 | +// ILaunchView view = getView(); | ||
| 72 | +// if (view != null) view.onTimerFinish(); | ||
| 73 | +// } | ||
| 74 | +// | ||
| 75 | +// @Override | ||
| 76 | +// public void onInterval(long remainTime) { | ||
| 77 | +// ILaunchView view = getView(); | ||
| 78 | +// if (view != null) view.onTimerInterval(remainTime / 1000); | ||
| 79 | +// LogUtil.d("LaunchView", "剩余时间" + remainTime); | ||
| 80 | +// } | ||
| 81 | +// }); | ||
| 83 | } | 82 | } |
| 84 | 83 | ||
| 85 | public void startMainPage(Activity activity) { | 84 | public void startMainPage(Activity activity) { |
app/src/main/java/com/cnlive/libs/demo/mvptest/ui/activity/LaunchActivity.java
| @@ -3,16 +3,16 @@ package com.cnlive.libs.demo.mvptest.ui.activity; | @@ -3,16 +3,16 @@ package com.cnlive.libs.demo.mvptest.ui.activity; | ||
| 3 | 3 | ||
| 4 | import android.content.Intent; | 4 | import android.content.Intent; |
| 5 | import android.os.Bundle; | 5 | import android.os.Bundle; |
| 6 | +import android.util.Log; | ||
| 6 | import android.view.View; | 7 | import android.view.View; |
| 7 | 8 | ||
| 8 | import com.cnlive.libs.base.frame.activity.MvpViewStateBindingActivity; | 9 | import com.cnlive.libs.base.frame.activity.MvpViewStateBindingActivity; |
| 9 | -import com.cnlive.libs.base.frame.adapter.DataBindingRecyclerAdapter; | ||
| 10 | -import com.cnlive.libs.demo.mvptest.model.LaunchListItemData; | ||
| 11 | import com.cnlive.libs.demo.R; | 10 | import com.cnlive.libs.demo.R; |
| 12 | import com.cnlive.libs.demo.ToastTest; | 11 | import com.cnlive.libs.demo.ToastTest; |
| 13 | import com.cnlive.libs.demo.databinding.ActivityLaunchBinding; | 12 | import com.cnlive.libs.demo.databinding.ActivityLaunchBinding; |
| 14 | import com.cnlive.libs.demo.mvptest.frame.presenter.LaunchPresenter; | 13 | import com.cnlive.libs.demo.mvptest.frame.presenter.LaunchPresenter; |
| 15 | import com.cnlive.libs.demo.mvptest.frame.view.LaunchView; | 14 | import com.cnlive.libs.demo.mvptest.frame.view.LaunchView; |
| 15 | +import com.cnlive.libs.demo.mvptest.model.LaunchListItemData; | ||
| 16 | import com.cnlive.libs.demo.mvptest.model.LaunchPage; | 16 | import com.cnlive.libs.demo.mvptest.model.LaunchPage; |
| 17 | 17 | ||
| 18 | public class LaunchActivity extends MvpViewStateBindingActivity<LaunchView, LaunchPresenter, LaunchPage, ActivityLaunchBinding> { | 18 | public class LaunchActivity extends MvpViewStateBindingActivity<LaunchView, LaunchPresenter, LaunchPage, ActivityLaunchBinding> { |
| @@ -30,11 +30,8 @@ public class LaunchActivity extends MvpViewStateBindingActivity<LaunchView, Laun | @@ -30,11 +30,8 @@ public class LaunchActivity extends MvpViewStateBindingActivity<LaunchView, Laun | ||
| 30 | @Override | 30 | @Override |
| 31 | protected void onPostCreate(Bundle savedInstanceState) { | 31 | protected void onPostCreate(Bundle savedInstanceState) { |
| 32 | super.onPostCreate(savedInstanceState); | 32 | super.onPostCreate(savedInstanceState); |
| 33 | - getViewData().getAdapter().setItemClickListener(new DataBindingRecyclerAdapter.OnItemClickListener<LaunchListItemData>() { | ||
| 34 | - @Override | ||
| 35 | - public void onItemClick(LaunchListItemData item) { | ||
| 36 | - | ||
| 37 | - } | 33 | + getViewData().getAdapter().setItemClickListener(item -> { |
| 34 | + Log.e("DemoView", "Click " + item.getName()); | ||
| 38 | }); | 35 | }); |
| 39 | } | 36 | } |
| 40 | 37 |
app/src/main/res/layout/listitem_main.xml
| @@ -7,6 +7,10 @@ | @@ -7,6 +7,10 @@ | ||
| 7 | <variable | 7 | <variable |
| 8 | name="data" | 8 | name="data" |
| 9 | type="com.cnlive.libs.demo.mvptest.model.LaunchListItemData" /> | 9 | type="com.cnlive.libs.demo.mvptest.model.LaunchListItemData" /> |
| 10 | + | ||
| 11 | + <variable | ||
| 12 | + name="click" | ||
| 13 | + type="android.view.View.OnClickListener" /> | ||
| 10 | </data> | 14 | </data> |
| 11 | 15 | ||
| 12 | <RelativeLayout | 16 | <RelativeLayout |
| @@ -17,11 +21,10 @@ | @@ -17,11 +21,10 @@ | ||
| 17 | android:layout_width="wrap_content" | 21 | android:layout_width="wrap_content" |
| 18 | android:layout_height="wrap_content" | 22 | android:layout_height="wrap_content" |
| 19 | android:layout_centerVertical="true" | 23 | android:layout_centerVertical="true" |
| 20 | - android:onClick="onMainItemClick" | ||
| 21 | android:padding="8dp" | 24 | android:padding="8dp" |
| 22 | - | ||
| 23 | android:text="@{data.name}" | 25 | android:text="@{data.name}" |
| 24 | - app:tag="@{data}" /> | 26 | + app:tag="@{data}" |
| 27 | + android:onClick="@{click}"/> | ||
| 25 | 28 | ||
| 26 | </RelativeLayout> | 29 | </RelativeLayout> |
| 27 | 30 |
cnlive/build.gradle
| @@ -78,7 +78,7 @@ ext { | @@ -78,7 +78,7 @@ ext { | ||
| 78 | siteUrl = 'http://bj.gitlab.cnlive.com/cnlive-team/CNVideoDemo' | 78 | siteUrl = 'http://bj.gitlab.cnlive.com/cnlive-team/CNVideoDemo' |
| 79 | gitUrl = 'http://bj.gitlab.cnlive.com/cnlive-team/CNVideoDemo.git' | 79 | gitUrl = 'http://bj.gitlab.cnlive.com/cnlive-team/CNVideoDemo.git' |
| 80 | 80 | ||
| 81 | - libraryVersion = '0.2.8' | 81 | + libraryVersion = '0.2.9' |
| 82 | 82 | ||
| 83 | developerId = 'CNlive' | 83 | developerId = 'CNlive' |
| 84 | developerName = 'Granzon' | 84 | developerName = 'Granzon' |
cnlive/src/main/java/com/cnlive/libs/base/frame/ReflectUtil.java
| 1 | package com.cnlive.libs.base.frame; | 1 | package com.cnlive.libs.base.frame; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | +import android.util.Log; | ||
| 5 | + | ||
| 4 | import com.cnlive.libs.base.util.LogUtil; | 6 | import com.cnlive.libs.base.util.LogUtil; |
| 5 | 7 | ||
| 6 | import java.lang.reflect.Constructor; | 8 | import java.lang.reflect.Constructor; |
| @@ -11,9 +13,30 @@ public class ReflectUtil { | @@ -11,9 +13,30 @@ public class ReflectUtil { | ||
| 11 | 13 | ||
| 12 | private static final String TAG = "ReflectUtil"; | 14 | private static final String TAG = "ReflectUtil"; |
| 13 | 15 | ||
| 16 | + public static Object invoke(Object obj, String methodName, Object data, Class clazz) { | ||
| 17 | + Object result = null; | ||
| 18 | + try { | ||
| 19 | + Log.e("DemOView", "--------------------Test " + methodName + " : " + data.getClass()); | ||
| 20 | + for (Method method : obj.getClass().getMethods()) { | ||
| 21 | + Log.e("DemOView", "Test " + method.getName() + " : " + method.getParameterAnnotations().toString()); | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + Method method = obj.getClass().getMethod(methodName, clazz); | ||
| 25 | + result = method.invoke(obj, data); | ||
| 26 | + } catch (Exception e) { | ||
| 27 | + LogUtil.e(TAG, "The page data type is not match ", e); | ||
| 28 | + } | ||
| 29 | + return result; | ||
| 30 | + } | ||
| 31 | + | ||
| 14 | public static Object invoke(Object obj, String methodName, Object data) { | 32 | public static Object invoke(Object obj, String methodName, Object data) { |
| 15 | Object result = null; | 33 | Object result = null; |
| 16 | try { | 34 | try { |
| 35 | + Log.e("DemOView", "--------------------Test " + methodName + " : " + data.getClass()); | ||
| 36 | + for (Method method : obj.getClass().getMethods()) { | ||
| 37 | + Log.e("DemOView", "Test " + method.getName() + " : " + method.getParameterAnnotations().toString()); | ||
| 38 | + } | ||
| 39 | + | ||
| 17 | Method method = obj.getClass().getMethod(methodName, new Class[]{data.getClass()}); | 40 | Method method = obj.getClass().getMethod(methodName, new Class[]{data.getClass()}); |
| 18 | result = method.invoke(obj, data); | 41 | result = method.invoke(obj, data); |
| 19 | } catch (Exception e) { | 42 | } catch (Exception e) { |
cnlive/src/main/java/com/cnlive/libs/base/frame/adapter/DataBindingRecyclerAdapter.java
| @@ -63,14 +63,13 @@ public abstract class DataBindingRecyclerAdapter<D, T extends ViewDataBinding> e | @@ -63,14 +63,13 @@ public abstract class DataBindingRecyclerAdapter<D, T extends ViewDataBinding> e | ||
| 63 | 63 | ||
| 64 | @Override | 64 | @Override |
| 65 | public void onBindViewHolder(DataBindingViewHolder holder, int position) { | 65 | public void onBindViewHolder(DataBindingViewHolder holder, int position) { |
| 66 | - View.OnClickListener click = new Click(position) { | 66 | + ReflectUtil.invoke(holder.binding, "setData", getList().get(position)); |
| 67 | + ReflectUtil.invoke(holder.binding, "setClick", new Click(position) { | ||
| 67 | @Override | 68 | @Override |
| 68 | public void onClick(View v) { | 69 | public void onClick(View v) { |
| 69 | if (listener != null) listener.onItemClick(getList().get(position)); | 70 | if (listener != null) listener.onItemClick(getList().get(position)); |
| 70 | } | 71 | } |
| 71 | - }; | ||
| 72 | - ReflectUtil.invoke(holder.binding, "setData", getList().get(position)); | ||
| 73 | - ReflectUtil.invoke(holder.binding, "setClick", click); | 72 | + }, View.OnClickListener.class); |
| 74 | holder.binding.executePendingBindings(); | 73 | holder.binding.executePendingBindings(); |
| 75 | } | 74 | } |
| 76 | 75 |