Commit dd88abe61c0a0f0f617ea4cd44ad0557bacb3028

Authored by 朱显松
1 parent f8fe5b61

Fix Click type conversion problem.

.idea/misc.xml
1 1 <?xml version="1.0" encoding="UTF-8"?>
2 2 <project version="4">
3   - <component name="EntryPointsManager">
4   - <entry_points version="2.0" />
5   - </component>
6 3 <component name="MavenImportPreferences">
7 4 <option name="generalSettings">
8 5 <MavenGeneralSettings>
... ... @@ -34,17 +31,7 @@
34 31 </value>
35 32 </option>
36 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 35 <output url="file://$PROJECT_DIR$/build/classes" />
49 36 </component>
50 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 5 import android.content.Intent;
6 6  
7 7 import com.cnlive.libs.base.data.network.Subscriber;
8   -import com.cnlive.libs.base.util.LogUtil;
9 8 import com.cnlive.libs.base.util.TimerUtil;
10 9 import com.cnlive.libs.demo.Config;
11 10 import com.cnlive.libs.demo.MainActivity;
... ... @@ -62,24 +61,24 @@ public class LaunchPresenter extends MvpBasePresenter&lt;LaunchView&gt; {
62 61 public void startTimer(long totalTime) {
63 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 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 3  
4 4 import android.content.Intent;
5 5 import android.os.Bundle;
  6 +import android.util.Log;
6 7 import android.view.View;
7 8  
8 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 10 import com.cnlive.libs.demo.R;
12 11 import com.cnlive.libs.demo.ToastTest;
13 12 import com.cnlive.libs.demo.databinding.ActivityLaunchBinding;
14 13 import com.cnlive.libs.demo.mvptest.frame.presenter.LaunchPresenter;
15 14 import com.cnlive.libs.demo.mvptest.frame.view.LaunchView;
  15 +import com.cnlive.libs.demo.mvptest.model.LaunchListItemData;
16 16 import com.cnlive.libs.demo.mvptest.model.LaunchPage;
17 17  
18 18 public class LaunchActivity extends MvpViewStateBindingActivity<LaunchView, LaunchPresenter, LaunchPage, ActivityLaunchBinding> {
... ... @@ -30,11 +30,8 @@ public class LaunchActivity extends MvpViewStateBindingActivity&lt;LaunchView, Laun
30 30 @Override
31 31 protected void onPostCreate(Bundle savedInstanceState) {
32 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 7 <variable
8 8 name="data"
9 9 type="com.cnlive.libs.demo.mvptest.model.LaunchListItemData" />
  10 +
  11 + <variable
  12 + name="click"
  13 + type="android.view.View.OnClickListener" />
10 14 </data>
11 15  
12 16 <RelativeLayout
... ... @@ -17,11 +21,10 @@
17 21 android:layout_width="wrap_content"
18 22 android:layout_height="wrap_content"
19 23 android:layout_centerVertical="true"
20   - android:onClick="onMainItemClick"
21 24 android:padding="8dp"
22   -
23 25 android:text="@{data.name}"
24   - app:tag="@{data}" />
  26 + app:tag="@{data}"
  27 + android:onClick="@{click}"/>
25 28  
26 29 </RelativeLayout>
27 30  
... ...
cnlive/build.gradle
... ... @@ -78,7 +78,7 @@ ext {
78 78 siteUrl = 'http://bj.gitlab.cnlive.com/cnlive-team/CNVideoDemo'
79 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 83 developerId = 'CNlive'
84 84 developerName = 'Granzon'
... ...
cnlive/src/main/java/com/cnlive/libs/base/frame/ReflectUtil.java
1 1 package com.cnlive.libs.base.frame;
2 2  
3 3  
  4 +import android.util.Log;
  5 +
4 6 import com.cnlive.libs.base.util.LogUtil;
5 7  
6 8 import java.lang.reflect.Constructor;
... ... @@ -11,9 +13,30 @@ public class ReflectUtil {
11 13  
12 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 32 public static Object invoke(Object obj, String methodName, Object data) {
15 33 Object result = null;
16 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 40 Method method = obj.getClass().getMethod(methodName, new Class[]{data.getClass()});
18 41 result = method.invoke(obj, data);
19 42 } catch (Exception e) {
... ...
cnlive/src/main/java/com/cnlive/libs/base/frame/adapter/DataBindingRecyclerAdapter.java
... ... @@ -63,14 +63,13 @@ public abstract class DataBindingRecyclerAdapter&lt;D, T extends ViewDataBinding&gt; e
63 63  
64 64 @Override
65 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 68 @Override
68 69 public void onClick(View v) {
69 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 73 holder.binding.executePendingBindings();
75 74 }
76 75  
... ...