Skip to content

Commit c15fe96

Browse files
committed
Added SingleUserViewModel
1 parent f3f19b5 commit c15fe96

25 files changed

+932
-1115
lines changed

.idea/libraries/baseLibrary_2_1_0_beta1.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/libraries/compiler_2_1_0_beta1.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 547 additions & 959 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/AndroidManifest.xml

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="mobile.silong.mvvm">
3+
package="mobile.silong.mvvm">
44

5-
<application
6-
android:name=".App"
7-
android:allowBackup="true"
8-
android:icon="@mipmap/ic_launcher"
9-
android:label="@string/app_name"
10-
android:supportsRtl="true"
11-
android:theme="@style/AppTheme">
12-
<activity android:name=".view.listuser.ListUserActivity">
13-
<intent-filter>
14-
<action android:name="android.intent.action.MAIN"/>
5+
<uses-permission android:name="android.permission.INTERNET" />
156

16-
<category android:name="android.intent.category.LAUNCHER"/>
17-
</intent-filter>
18-
</activity>
19-
<activity android:name=".view.singleuser.SingleUserActivity">
7+
<application
8+
android:allowBackup="true"
9+
android:icon="@mipmap/ic_launcher"
10+
android:label="@string/app_name"
11+
android:name=".App"
12+
android:supportsRtl="true"
13+
android:theme="@style/AppTheme">
14+
<activity android:name=".view.listuser.ListUserActivity">
15+
<intent-filter>
16+
<action android:name="android.intent.action.MAIN" />
2017

21-
</activity>
22-
</application>
18+
<category android:name="android.intent.category.LAUNCHER" />
19+
</intent-filter>
20+
</activity>
21+
<activity android:name=".view.singleuser.SingleUserActivity">
22+
23+
</activity>
24+
</application>
2325

2426
</manifest>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package mobile.silong.mvvm.adapter;
2+
3+
import android.databinding.DataBindingUtil;
4+
import android.databinding.ViewDataBinding;
5+
import android.support.v7.widget.RecyclerView;
6+
import android.view.LayoutInflater;
7+
import android.view.ViewGroup;
8+
9+
import mobile.silong.mvvm.holder.BindingViewHolder;
10+
11+
/**
12+
* Created by lamtn on 4/15/16.
13+
*/
14+
public abstract class BindingAdapter<T extends ViewDataBinding> extends RecyclerView.Adapter<BindingViewHolder<T>> {
15+
16+
private final int mLayoutResourceId;
17+
18+
public BindingAdapter(int layoutResourceId) {
19+
mLayoutResourceId = layoutResourceId;
20+
}
21+
22+
@Override
23+
public BindingViewHolder<T> onCreateViewHolder(ViewGroup parent, int viewType) {
24+
T binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), mLayoutResourceId, parent, false);
25+
return new BindingViewHolder<>(binding);
26+
}
27+
28+
@Override
29+
public void onBindViewHolder(BindingViewHolder<T> holder, int position) {
30+
T binding = holder.getLayoutBinding();
31+
updateBinding(binding, position);
32+
}
33+
34+
protected abstract void updateBinding(T binding, int position);
35+
}
Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
package mobile.silong.mvvm.adapter;
22

33
import android.content.Context;
4+
import android.databinding.DataBindingUtil;
45
import android.support.v7.widget.RecyclerView;
5-
import android.view.View;
6+
import android.view.LayoutInflater;
67
import android.view.ViewGroup;
78

89
import java.util.ArrayList;
910
import java.util.List;
1011

12+
import mobile.silong.mvvm.R;
13+
import mobile.silong.mvvm.databinding.ItemUserBinding;
1114
import mobile.silong.mvvm.domain.model.User;
15+
import mobile.silong.mvvm.presentation.ItemUserViewModel;
1216

1317
/**
1418
* Created by lamtn on 4/13/16.
@@ -25,20 +29,19 @@ public UserAdapter(Context mContext) {
2529

2630
@Override
2731
public UserBindingHolder onCreateViewHolder(ViewGroup parent, int viewType) {
28-
// ItemUserBinding userBinding = DataBindingUtil.inflate(
29-
// LayoutInflater.from(mContext),
30-
// R.layout.item_user,
31-
// parent,
32-
// false
33-
// );
34-
//
35-
// return new UserBindingHolder(userBinding);
36-
return null;
32+
ItemUserBinding userBinding = DataBindingUtil.inflate(
33+
LayoutInflater.from(mContext),
34+
R.layout.item_user,
35+
parent,
36+
false
37+
);
38+
39+
return new UserBindingHolder(userBinding);
3740
}
3841

3942
@Override
4043
public void onBindViewHolder(UserBindingHolder holder, int position) {
41-
// holder.binding.setUserViewModel(new UserViewModel(mContext, this.mUserList.get(position)));
44+
holder.binding.setItemUser(new ItemUserViewModel(mContext, this.mUserList.get(position)));
4245
}
4346

4447
public void setUserList(List<User> userList) {
@@ -48,15 +51,16 @@ public void setUserList(List<User> userList) {
4851

4952
@Override
5053
public int getItemCount() {
51-
return this.mUserList.size();
54+
return mUserList != null ? mUserList.size() : 0;
5255
}
5356

5457
public class UserBindingHolder extends RecyclerView.ViewHolder {
55-
public UserBindingHolder(View itemView) {
56-
super(itemView);
57-
}
5858

59-
// ItemUserBinding binding;
59+
ItemUserBinding binding;
6060

61+
public UserBindingHolder(ItemUserBinding binding) {
62+
super(binding.cardView);
63+
this.binding = binding;
64+
}
6165
}
6266
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package mobile.silong.mvvm.di;
2+
3+
import java.lang.annotation.Retention;
4+
5+
import javax.inject.Scope;
6+
7+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
8+
9+
/**
10+
* Created by lamtn on 4/15/16.
11+
*/
12+
@Scope
13+
@Retention(RUNTIME)
14+
public @interface PerActivity {}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package mobile.silong.mvvm.di;
2+
3+
import dagger.Component;
4+
import mobile.silong.mvvm.view.listuser.ListUserActivity;
5+
import mobile.silong.mvvm.view.singleuser.SingleUserActivity;
6+
7+
/**
8+
* Created by lamtn on 4/15/16.
9+
*/
10+
@PerActivity
11+
@Component(dependencies = AppComponent.class, modules = {UserModule.class})
12+
public interface UserComponent {
13+
14+
void inject(ListUserActivity listUserActivity);
15+
16+
void inject(SingleUserActivity singleUserActivity);
17+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package mobile.silong.mvvm.di;
2+
3+
import javax.inject.Singleton;
4+
5+
import dagger.Module;
6+
import dagger.Provides;
7+
import mobile.silong.mvvm.domain.usecase.ListUserUseCase;
8+
import mobile.silong.mvvm.domain.usecase.SingleUserUseCase;
9+
import mobile.silong.mvvm.presentation.ListUserViewModel;
10+
import mobile.silong.mvvm.presentation.SingleUserViewModel;
11+
12+
/**
13+
* Created by lamtn on 4/15/16.
14+
*/
15+
@Module
16+
public class UserModule {
17+
18+
private String mUserId;
19+
20+
public UserModule() {
21+
22+
}
23+
24+
public UserModule(String userId) {
25+
mUserId = userId;
26+
}
27+
28+
@Provides
29+
@Singleton
30+
public ListUserViewModel provideListUserViewModel(ListUserUseCase listUserUseCase) {
31+
return new ListUserViewModel(listUserUseCase);
32+
}
33+
34+
@Provides
35+
@Singleton
36+
public SingleUserViewModel provideSingleUserViewModel(SingleUserUseCase singleUserUseCase) {
37+
return new SingleUserViewModel(singleUserUseCase);
38+
}
39+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package mobile.silong.mvvm.holder;
2+
3+
import android.databinding.ViewDataBinding;
4+
import android.support.v7.widget.RecyclerView;
5+
6+
/**
7+
* Created by lamtn on 4/15/16.
8+
*/
9+
public class BindingViewHolder<T extends ViewDataBinding> extends RecyclerView.ViewHolder {
10+
11+
final T mLayoutBinding;
12+
13+
public BindingViewHolder(T layoutBinding) {
14+
super(layoutBinding.getRoot());
15+
mLayoutBinding = layoutBinding;
16+
}
17+
18+
public T getLayoutBinding() {
19+
return mLayoutBinding;
20+
}
21+
}

0 commit comments

Comments
 (0)