Skip to content

Commit

Permalink
grep架构搭好
Browse files Browse the repository at this point in the history
  • Loading branch information
Zane96 committed Dec 3, 2017
1 parent 475f317 commit 4c6347b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,16 @@ public static LogcatContentRepository getInstance(@NonNull AppExecutors executor
/**
* 向上层抛出LiveData
* 根据grep来决策是否过滤数据
* @param id
* @param grep
* @return
*/
public LiveData<LogcatContent> getLogcatContent(int id, String grep) {
public LiveData<LogcatContent> getLogcatContent(String grep) {
return DataCreator.creat(source.asLiveData(), grep);
}

public void fetchFromData(int id) {
source.init(id);
source.initData();
return DataCreator.creat(source.asLiveData(), grep);
}

public void fetchData(String options, String filter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,16 @@ public class LogcatContentViewModel extends AndroidViewModel{
public LogcatContentViewModel(@NonNull Application application, LogcatContentRepository repository) {
super(application);
this.repository = repository;
contentLiveData = Transformations.switchMap(isStartLiveData, grep -> repository.getLogcatContent(id, grep));
contentLiveData = Transformations.switchMap(isStartLiveData, repository::getLogcatContent);
}

//---------------------------------action binding---------------------------------
void init(int id, String grep, ActivityLogcatBinding binding) {
this.binding = binding;
this.id = id;
isStartLiveData.setValue(grep);
insertIfNotExits(new LogcatContent(id, "init fairy"));
repository.fetchFromData(id);
isStartLiveData.setValue(grep);
}

public void onOptionsChanged(CharSequence s) {
Expand Down

0 comments on commit 4c6347b

Please sign in to comment.