Commit 94c291abc5f8998cc896d99634f488e3bb706fbc

Authored by 王琳
1 parent 88165b3b

添加基础代码

.idea/modules.xml
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 <component name="ProjectModuleManager"> 3 <component name="ProjectModuleManager">
4 <modules> 4 <modules>
5 <module fileurl="file://$PROJECT_DIR$/CNLiveLibs.iml" filepath="$PROJECT_DIR$/CNLiveLibs.iml" /> 5 <module fileurl="file://$PROJECT_DIR$/CNLiveLibs.iml" filepath="$PROJECT_DIR$/CNLiveLibs.iml" />
  6 + <module fileurl="file://$PROJECT_DIR$/OPenCNLive_BaseLib.iml" filepath="$PROJECT_DIR$/OPenCNLive_BaseLib.iml" />
6 <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" /> 7 <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
7 <module fileurl="file://$PROJECT_DIR$/cnlive/cnlive.iml" filepath="$PROJECT_DIR$/cnlive/cnlive.iml" /> 8 <module fileurl="file://$PROJECT_DIR$/cnlive/cnlive.iml" filepath="$PROJECT_DIR$/cnlive/cnlive.iml" />
8 </modules> 9 </modules>
cnlive/build.gradle
@@ -20,12 +20,21 @@ android { @@ -20,12 +20,21 @@ android {
20 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 } 21 }
22 } 22 }
  23 +
  24 + dataBinding {
  25 + enabled true
  26 + }
23 } 27 }
24 28
25 dependencies { 29 dependencies {
26 - compile fileTree(dir: 'libs', include: ['*.jar']) 30 + compile fileTree(include: ['*.jar'], dir: 'libs')
27 compile 'com.android.support:appcompat-v7:26.+' 31 compile 'com.android.support:appcompat-v7:26.+'
  32 + compile 'com.android.support:support-annotations:26.+'
28 testCompile 'junit:junit:4.12' 33 testCompile 'junit:junit:4.12'
  34 + //MVP
  35 + compile 'com.hannesdorfmann.mosby:mvp:2.0.1'
  36 + compile 'com.github.bumptech.glide:okhttp3-integration:4.0.0-RC1'
  37 +
29 } 38 }
30 39
31 ext { 40 ext {
@@ -41,7 +50,7 @@ ext { @@ -41,7 +50,7 @@ ext {
41 siteUrl = 'http://bj.gitlab.cnlive.com/cnlive-team/CNVideoDemo' 50 siteUrl = 'http://bj.gitlab.cnlive.com/cnlive-team/CNVideoDemo'
42 gitUrl = 'http://bj.gitlab.cnlive.com/cnlive-team/CNVideoDemo.git' 51 gitUrl = 'http://bj.gitlab.cnlive.com/cnlive-team/CNVideoDemo.git'
43 52
44 - libraryVersion = '0.0.1' 53 + libraryVersion = '0.0.2'
45 54
46 developerId = 'CNlive' 55 developerId = 'CNlive'
47 developerName = 'Granzon' 56 developerName = 'Granzon'
cnlive/from_bintrayv1.gradle
@@ -25,7 +25,7 @@ task javadocJar(type: Jar, dependsOn: javadoc) { @@ -25,7 +25,7 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
25 } 25 }
26 26
27 artifacts { 27 artifacts {
28 - archives javadocJar 28 +// archives javadocJar
29 archives sourcesJar 29 archives sourcesJar
30 } 30 }
31 31
@@ -34,8 +34,8 @@ Properties properties = new Properties() @@ -34,8 +34,8 @@ Properties properties = new Properties()
34 properties.load(project.rootProject.file('local.properties').newDataInputStream()) 34 properties.load(project.rootProject.file('local.properties').newDataInputStream())
35 35
36 bintray { 36 bintray {
37 - user = properties.getProperty("bintray.user")  
38 - key = properties.getProperty("bintray.apikey") 37 + user = 'granzon'
  38 + key = 'ea2c6b59950379867b6dfb24a5649941c13460eb'
39 39
40 configurations = ['archives'] 40 configurations = ['archives']
41 pkg { 41 pkg {
cnlive/src/main/java/com/cnlive/libs/base/ReflectUtil.java 0 → 100644
  1 +package com.cnlive.libs.base;
  2 +
  3 +
  4 +import com.cnlive.libs.base.util.LogUtil;
  5 +
  6 +import java.lang.reflect.Constructor;
  7 +import java.lang.reflect.Method;
  8 +import java.lang.reflect.ParameterizedType;
  9 +
  10 +public class ReflectUtil {
  11 +
  12 + private static final String TAG = "ReflectUtil";
  13 +
  14 + public static Object invoke(Object obj, String methodName, Object data) {
  15 + Object result = null;
  16 + try {
  17 + Method method = obj.getClass().getMethod(methodName, new Class[]{data.getClass()});
  18 + result = method.invoke(obj, data);
  19 + } catch (Exception e) {
  20 + LogUtil.e(TAG, "The page data type is not match ", e);
  21 + }
  22 + return result;
  23 + }
  24 +
  25 + public static <R> R instance(int position, Class type, Object data) {
  26 + R result = null;
  27 + try {
  28 + ParameterizedType pt = (ParameterizedType) type.getGenericSuperclass();
  29 + Class<R> clazz = (Class<R>) pt.getActualTypeArguments()[position];
  30 + Constructor constructor = clazz.getConstructor(new Class[]{data.getClass()});
  31 + result = (R) constructor.newInstance(data);
  32 + } catch (Exception e) {
  33 + LogUtil.e(TAG, "View Layer Unimplemented: Constructor (MvpActivity / MvpFragment)", e);
  34 + }
  35 + return result;
  36 + }
  37 +
  38 + public static <R> R instance(int position, Object object) {
  39 + R result = null;
  40 + try {
  41 + ParameterizedType pt = (ParameterizedType) object.getClass().getGenericSuperclass();
  42 + Class<R> clazz = (Class<R>) pt.getActualTypeArguments()[position];
  43 + result = clazz.newInstance();
  44 + } catch (Exception e) {
  45 + LogUtil.e(TAG, "Presenter or data need to implement the default constructor: constructor ()", e);
  46 + }
  47 + return result;
  48 + }
  49 +}
cnlive/src/main/java/com/cnlive/libs/base/activity/MvpBindingActivity.java 0 → 100644
  1 +package com.cnlive.libs.base.activity;
  2 +
  3 +import android.databinding.DataBindingUtil;
  4 +import android.databinding.ViewDataBinding;
  5 +import android.os.Bundle;
  6 +import android.support.annotation.NonNull;
  7 +
  8 +import com.cnlive.libs.base.ReflectUtil;
  9 +import com.hannesdorfmann.mosby.mvp.MvpActivity;
  10 +import com.hannesdorfmann.mosby.mvp.MvpPresenter;
  11 +import com.hannesdorfmann.mosby.mvp.MvpView;
  12 +
  13 +
  14 +public abstract class MvpBindingActivity<V extends MvpView, P extends MvpPresenter<V>, D, T extends ViewDataBinding> extends MvpActivity<V, P> {
  15 +
  16 + public V view;
  17 + public T binding;
  18 + public D data;
  19 +
  20 + @Override
  21 + protected void onCreate(Bundle savedInstanceState) {
  22 + super.onCreate(savedInstanceState);
  23 + binding = DataBindingUtil.setContentView(this, getLayoutId());
  24 + ReflectUtil.invoke(binding, "setData", getLayoutData());
  25 + }
  26 +
  27 + protected abstract int getLayoutId();
  28 +
  29 + protected D getLayoutData() {
  30 + return data = ReflectUtil.instance(2, this);
  31 + }
  32 +
  33 + @NonNull
  34 + public V createView() {
  35 + return ReflectUtil.instance(0, this.getClass(), this);
  36 + }
  37 +
  38 + @NonNull
  39 + @Override
  40 + public P createPresenter() {
  41 + return ReflectUtil.instance(1, this);
  42 + }
  43 +
  44 + @NonNull
  45 + @Override
  46 + public V getMvpView() {
  47 + if (view == null) view = createView();
  48 + return view;
  49 + }
  50 +
  51 +}
cnlive/src/main/java/com/cnlive/libs/base/activity/MvpLceBindingActivity.java 0 → 100644
  1 +package com.cnlive.libs.base.activity;
  2 +
  3 +
  4 +import android.databinding.DataBindingUtil;
  5 +import android.databinding.ViewDataBinding;
  6 +import android.os.Bundle;
  7 +import android.support.annotation.NonNull;
  8 +import android.view.View;
  9 +
  10 +import com.hannesdorfmann.mosby.mvp.MvpPresenter;
  11 +import com.hannesdorfmann.mosby.mvp.MvpView;
  12 +import com.hannesdorfmann.mosby.mvp.lce.MvpLceActivity;
  13 +import com.hannesdorfmann.mosby.mvp.lce.MvpLceView;
  14 +
  15 +/**
  16 + * Created by xiansong on 2017/7/19.
  17 + */
  18 +
  19 +public abstract class MvpLceBindingActivity<CV extends View, M, V extends MvpLceView<M>, P extends MvpPresenter<V>, T extends ViewDataBinding>
  20 + extends MvpLceActivity<CV, M, V, P> {
  21 +
  22 + public V view;
  23 + public T binding;
  24 +
  25 + @Override
  26 + protected void onCreate(Bundle savedInstanceState) {
  27 + super.onCreate(savedInstanceState);
  28 + binding = DataBindingUtil.setContentView(this, getLayoutId());
  29 + }
  30 +
  31 + protected abstract int getLayoutId();
  32 +
  33 + /**
  34 + * Instantiate a view instance
  35 + *
  36 + * @return The {@link MvpView} for this view
  37 + */
  38 + @NonNull
  39 + public abstract V createView();
  40 +
  41 + @NonNull
  42 + @Override
  43 + public V getMvpView() {
  44 + if (view == null) view = createView();
  45 + return view;
  46 + }
  47 +}
0 \ No newline at end of file 48 \ No newline at end of file
cnlive/src/main/java/com/cnlive/libs/base/fragment/MvpBindingFragment.java 0 → 100644
  1 +package com.cnlive.libs.base.fragment;
  2 +
  3 +import android.databinding.DataBindingUtil;
  4 +import android.databinding.ViewDataBinding;
  5 +import android.os.Bundle;
  6 +import android.support.annotation.NonNull;
  7 +import android.support.annotation.Nullable;
  8 +import android.view.LayoutInflater;
  9 +import android.view.View;
  10 +import android.view.ViewGroup;
  11 +
  12 +import com.cnlive.libs.base.ReflectUtil;
  13 +import com.hannesdorfmann.mosby.mvp.MvpFragment;
  14 +import com.hannesdorfmann.mosby.mvp.MvpPresenter;
  15 +import com.hannesdorfmann.mosby.mvp.MvpView;
  16 +
  17 +/**
  18 + * Created by xiansong on 2017/7/25.
  19 + */
  20 +
  21 +public abstract class MvpBindingFragment<V extends MvpView, P extends MvpPresenter<V>, D, T extends ViewDataBinding> extends MvpFragment<V, P> {
  22 +
  23 + public V view;
  24 + public T binding;
  25 + public D data;
  26 +
  27 + @Nullable
  28 + @Override
  29 + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  30 + binding = DataBindingUtil.inflate(inflater, getLayoutId(), container, false);
  31 + ReflectUtil.invoke(binding, "setData", getLayoutData());
  32 + return binding.getRoot();
  33 + }
  34 +
  35 + protected abstract int getLayoutId();
  36 +
  37 + protected D getLayoutData() {
  38 + return data = ReflectUtil.instance(2, this);
  39 + }
  40 +
  41 + @NonNull
  42 + public V createView() {
  43 + return ReflectUtil.instance(0, this.getClass(), this);
  44 + }
  45 +
  46 + @NonNull
  47 + @Override
  48 + public P createPresenter() {
  49 + return ReflectUtil.instance(1, this);
  50 + }
  51 +
  52 + @NonNull
  53 + @Override
  54 + public V getMvpView() {
  55 + if (view == null) view = createView();
  56 + return view;
  57 + }
  58 +
  59 +
  60 +}
0 \ No newline at end of file 61 \ No newline at end of file
cnlive/src/main/java/com/cnlive/libs/base/model/PageModelInfo.java 0 → 100644
  1 +package com.cnlive.libs.base.model;
  2 +
  3 +import java.io.Serializable;
  4 +import java.util.List;
  5 +
  6 +/**
  7 + * Created by xiansong on 2017/7/25.
  8 + */
  9 +
  10 +public class PageModelInfo {
  11 + private String title;
  12 + private String name;
  13 +
  14 + private List<PageModelGroup> modelGroup;
  15 +
  16 + public String getTitle() {
  17 + return title;
  18 + }
  19 +
  20 + public void setTitle(String title) {
  21 + this.title = title;
  22 + }
  23 +
  24 + public String getName() {
  25 + return name;
  26 + }
  27 +
  28 + public void setName(String name) {
  29 + this.name = name;
  30 + }
  31 +
  32 + public List<PageModelGroup> getModelGroup() {
  33 + return modelGroup;
  34 + }
  35 +
  36 + public void setModelGroup(List<PageModelGroup> modelGroup) {
  37 + this.modelGroup = modelGroup;
  38 + }
  39 +
  40 + public static class PageModelGroup implements Serializable{
  41 + private String title;
  42 + private String name;
  43 + private List<PageModelFields> modelFields;
  44 +
  45 + public String getTitle() {
  46 + return title;
  47 + }
  48 +
  49 + public void setTitle(String title) {
  50 + this.title = title;
  51 + }
  52 +
  53 + public String getName() {
  54 + return name;
  55 + }
  56 +
  57 + public void setName(String name) {
  58 + this.name = name;
  59 + }
  60 +
  61 + public List<PageModelFields> getModelFields() {
  62 + return modelFields;
  63 + }
  64 +
  65 + public void setModelFields(List<PageModelFields> modelFields) {
  66 + this.modelFields = modelFields;
  67 + }
  68 +
  69 + public static class PageModelFields implements Serializable{
  70 +
  71 + private String name;
  72 + private String value;
  73 + private String title;
  74 + private String type;
  75 + private int rows;
  76 + private boolean required;
  77 + private List<String> options;
  78 +
  79 + public String getValue() {
  80 + return value;
  81 + }
  82 +
  83 + public void setValue(String value) {
  84 + this.value = value;
  85 + }
  86 +
  87 + public String getName() {
  88 + return name;
  89 + }
  90 +
  91 + public void setName(String name) {
  92 + this.name = name;
  93 + }
  94 +
  95 + public String getTitle() {
  96 + return title;
  97 + }
  98 +
  99 + public void setTitle(String title) {
  100 + this.title = title;
  101 + }
  102 +
  103 + public String getType() {
  104 + return type;
  105 + }
  106 +
  107 + public void setType(String type) {
  108 + this.type = type;
  109 + }
  110 +
  111 + public int getRows() {
  112 + return rows;
  113 + }
  114 +
  115 + public void setRows(int rows) {
  116 + this.rows = rows;
  117 + }
  118 +
  119 + public boolean isRequired() {
  120 + return required;
  121 + }
  122 +
  123 + public void setRequired(boolean required) {
  124 + this.required = required;
  125 + }
  126 +
  127 + public List<String> getOptions() {
  128 + return options;
  129 + }
  130 +
  131 + public void setOptions(List<String> options) {
  132 + this.options = options;
  133 + }
  134 +
  135 + }
  136 + }
  137 +
  138 +}
cnlive/src/main/java/com/cnlive/libs/base/model/TitlePage.java 0 → 100644
  1 +package com.cnlive.libs.base.model;
  2 +
  3 +import android.databinding.BaseObservable;
  4 +import android.databinding.Bindable;
  5 +
  6 +import com.cnlive.libs.base.BR;
  7 +
  8 +
  9 +/**
  10 + * Created by Granzon on 2017/7/23.
  11 + */
  12 +
  13 +public abstract class TitlePage extends BaseObservable {
  14 +
  15 +
  16 + private int back;
  17 + private String title;
  18 +
  19 + public TitlePage() {
  20 + title = initTitle();
  21 + back = initBack();
  22 + }
  23 +
  24 + public abstract String initTitle();
  25 +
  26 + public abstract int initBack();
  27 +
  28 +
  29 + @Bindable
  30 + public String getTitle() {
  31 + return title;
  32 + }
  33 +
  34 + public void setTitle(String title) {
  35 + this.title = title;
  36 + notifyPropertyChanged(BR.title);
  37 + }
  38 +
  39 + @Bindable
  40 + public int getBack() {
  41 + return back;
  42 + }
  43 +
  44 + public void setBack(int back) {
  45 + this.back = back;
  46 + notifyPropertyChanged(BR.back);
  47 + }
  48 +}
cnlive/src/main/java/com/cnlive/libs/base/util/LogUtil.java 0 → 100644
  1 +package com.cnlive.libs.base.util;
  2 +
  3 +import android.util.Log;
  4 +
  5 +import com.cnlive.libs.base.BuildConfig;
  6 +
  7 +
  8 +public class LogUtil {
  9 +
  10 + public static void e(String tag, String msg) {
  11 + if (BuildConfig.DEBUG) Log.e(tag, msg);
  12 + }
  13 +
  14 + public static void e(String tag, String msg, Throwable tr) {
  15 + if (BuildConfig.DEBUG) Log.e(tag, msg, tr);
  16 + }
  17 +
  18 + public static void d(String tag, String msg) {
  19 + if (BuildConfig.DEBUG) Log.d(tag, msg);
  20 + }
  21 +
  22 + public static void d(String tag, String msg, Throwable tr) {
  23 + if (BuildConfig.DEBUG) Log.d(tag, msg, tr);
  24 + }
  25 +}
cnlive/src/main/java/com/cnlive/libs/base/util/ToastUtil.java 0 → 100644
  1 +package com.cnlive.libs.base.util;
  2 +
  3 +import android.content.Context;
  4 +import android.content.res.Resources;
  5 +import android.text.TextUtils;
  6 +import android.view.Gravity;
  7 +import android.widget.Toast;
  8 +
  9 +
  10 +public class ToastUtil {
  11 +
  12 + private static long back_pressed;
  13 + private static String show_msg = "";
  14 +
  15 + public static int dip2px(int dpValue) {
  16 + final float scale = Resources.getSystem().getDisplayMetrics().density;
  17 + return (int) (dpValue * scale + 0.5f);
  18 + }
  19 +
  20 + private Context mContext;
  21 +
  22 + public ToastUtil(Context context){
  23 + this.mContext = context;
  24 + }
  25 +
  26 + public void showToast(String str, int duration) {
  27 + if (TextUtils.isEmpty(str)) return;
  28 + if (back_pressed + 2000 < System.currentTimeMillis() || !show_msg.equals(str)) {
  29 + show_msg = str;
  30 +
  31 + Toast toast = Toast.makeText(mContext, str, duration);
  32 +
  33 + toast.setGravity(Gravity.BOTTOM, 0, dip2px(128));
  34 + toast.show();
  35 + }
  36 + back_pressed = System.currentTimeMillis();
  37 + }
  38 +
  39 +
  40 + public void showToast(String str) {
  41 + showToast(str, Toast.LENGTH_SHORT);
  42 + }
  43 +
  44 +
  45 +}