Skip to content

Commit

Permalink
supplement
Browse files Browse the repository at this point in the history
supplement
  • Loading branch information
goldze committed Mar 15, 2019
1 parent 20290cb commit 004a286
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ android {
compileSdkVersion rootProject.ext.android.compileSdkVersion
buildToolsVersion rootProject.ext.android.buildToolsVersion
defaultConfig {
applicationId "com.goldze.component"
applicationId rootProject.ext.android.applicationId
minSdkVersion rootProject.ext.android.minSdkVersion
targetSdkVersion rootProject.ext.android.targetSdkVersion
versionCode rootProject.ext.android.versionCode
Expand Down
4 changes: 2 additions & 2 deletions config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ext {
android = [
compileSdkVersion: 27,
buildToolsVersion: "27.0.2",
applicationId : "com.goldze.mvvmhabit",
applicationId : "com.goldze.component",
minSdkVersion : 15,
targetSdkVersion : 27,
versionCode : 1,
Expand Down Expand Up @@ -58,7 +58,7 @@ ext {
"lifecycle-extensions" : "android.arch.lifecycle:extensions:1.1.1",
"lifecycle-compiler" : "android.arch.lifecycle:compiler:1.1.1",
//MVVMHabit
"MVVMHabit" : "com.github.goldze:MVVMHabit:3.0.7",
"MVVMHabit" : "com.github.goldze:MVVMHabit:3.0.8",
//阿里路由框架
"arouter-api" : "com.alibaba:arouter-api:1.4.1",
"arouter-compiler" : "com.alibaba:arouter-compiler:1.2.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package com.goldze.home.ui.adapter;

import android.arch.lifecycle.LifecycleOwner;
import android.arch.lifecycle.Observer;
import android.databinding.ViewDataBinding;
import android.support.annotation.Nullable;
import android.view.ViewGroup;

import com.goldze.home.databinding.ItemViewpagerBinding;
import com.goldze.home.ui.viewmodel.ViewPagerItemViewModel;

import me.goldze.mvvmhabit.utils.ToastUtils;
import me.tatarka.bindingcollectionadapter2.BindingViewPagerAdapter;

/**
Expand All @@ -22,12 +18,6 @@ public void onBindBinding(final ViewDataBinding binding, int variableId, int lay
super.onBindBinding(binding, variableId, layoutRes, position, item);
//这里可以强转成ViewPagerItemViewModel对应的ViewDataBinding,
ItemViewpagerBinding _binding = (ItemViewpagerBinding) binding;
item.clickEvent.observe((LifecycleOwner) _binding.getRoot().getContext(), new Observer<String>() {
@Override
public void onChanged(@Nullable String s) {
ToastUtils.showShort(s);
}
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.goldze.home.ui.fragment;

import android.arch.lifecycle.LifecycleOwner;
import android.arch.lifecycle.Observer;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
Expand All @@ -14,6 +16,7 @@
import com.goldze.home.ui.viewmodel.HomeViewModel;

import me.goldze.mvvmhabit.base.BaseFragment;
import me.goldze.mvvmhabit.utils.ToastUtils;

/**
* Created by goldze on 2018/6/21
Expand All @@ -35,10 +38,16 @@ public void initData() {
// 使用 TabLayout 和 ViewPager 相关联
binding.tabs.setupWithViewPager(binding.viewPager);
binding.viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(binding.tabs));
viewModel.addPage();
}

@Override
public void initViewObservable() {
viewModel.addPage();
viewModel.itemClickEvent.observe(this, new Observer<String>() {
@Override
public void onChanged(@Nullable String s) {
ToastUtils.showShort(s);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.binding.command.BindingConsumer;
import me.goldze.mvvmhabit.bus.event.SingleLiveEvent;
import me.goldze.mvvmhabit.utils.ToastUtils;
import me.tatarka.bindingcollectionadapter2.BindingViewPagerAdapter;
import me.tatarka.bindingcollectionadapter2.ItemBinding;
Expand All @@ -21,6 +22,7 @@
*/

public class HomeViewModel extends BaseViewModel {
public SingleLiveEvent<String> itemClickEvent = new SingleLiveEvent();
public HomeViewModel(@NonNull Application application) {
super(application);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
* Created by goldze on 2018/7/18.
*/

public class ViewPagerItemViewModel extends ItemViewModel {
public class ViewPagerItemViewModel extends ItemViewModel<HomeViewModel> {
public String text;
public SingleLiveEvent<String> clickEvent = new SingleLiveEvent();

public ViewPagerItemViewModel(@NonNull BaseViewModel viewModel, String text) {
public ViewPagerItemViewModel(@NonNull HomeViewModel viewModel, String text) {
super(viewModel);
this.text = text;
}
Expand All @@ -25,7 +24,7 @@ public ViewPagerItemViewModel(@NonNull BaseViewModel viewModel, String text) {
@Override
public void call() {
//点击之后将逻辑转到adapter中处理
clickEvent.setValue(text);
viewModel.itemClickEvent.setValue(text);
}
});
}

0 comments on commit 004a286

Please sign in to comment.