Skip to content

Commit

Permalink
- add rule calculation indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
Balcan committed Aug 21, 2019
1 parent 7b7444e commit 50fc45b
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,13 @@ public EnrollmentFormRepository(@NonNull BriteDatabase briteDatabase,
rulesRepository.ruleVariables(program),
rulesRepository.enrollmentEvents(enrollmentUid),
rulesRepository.queryConstants(),
(rules, variables, events, constants) -> {
rulesRepository.getSuplementaryData(d2),
(rules, variables, events, constants,supplementaryData) -> {
RuleEngine.Builder builder = RuleEngineContext.builder(expressionEvaluator)
.rules(rules)
.ruleVariables(variables)
.calculatedValueMap(new HashMap<>())
.supplementaryData(new HashMap<>())
.supplementaryData(supplementaryData)
.constantsValue(constants)
.build().toEngineBuilder();
builder.triggerEnvironment(TriggerEnvironment.ANDROIDCLIENT);
Expand All @@ -254,12 +255,13 @@ public Flowable<RuleEngine> restartRuleEngine() {
rulesRepository.ruleVariables(program),
rulesRepository.enrollmentEvents(enrollmentUid),
rulesRepository.queryConstants(),
(rules, variables, events, constants) -> {
rulesRepository.getSuplementaryData(d2),
(rules, variables, events, constants,supplementaryData) -> {
RuleEngine.Builder builder = RuleEngineContext.builder(expressionEvaluator)
.rules(rules)
.ruleVariables(variables)
.calculatedValueMap(new HashMap<>())
.supplementaryData(new HashMap<>())
.supplementaryData(supplementaryData)
.constantsValue(constants)
.build().toEngineBuilder();
builder.triggerEnvironment(TriggerEnvironment.ANDROIDCLIENT);
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/java/org/dhis2/data/forms/EventRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,15 @@ public EventRepository(@NonNull BriteDatabase briteDatabase,
rulesRepository.otherEvents(eventUid),
rulesRepository.enrollment(eventUid),
rulesRepository.queryConstants(),
(rules, variables, events, enrollment, constants) -> {
rulesRepository.getSuplementaryData(d2),
(rules, variables, events, enrollment, constants,supplementaryData) -> {

RuleEngine.Builder builder = RuleEngineContext.builder(evaluator)
.rules(rules)
.ruleVariables(variables)
.constantsValue(constants)
.calculatedValueMap(new HashMap<>())
.supplementaryData(new HashMap<>())
.supplementaryData(supplementaryData)
.build().toEngineBuilder();
builder.triggerEnvironment(TriggerEnvironment.ANDROIDCLIENT);
builder.events(events);
Expand All @@ -215,14 +216,15 @@ public Flowable<RuleEngine> restartRuleEngine() {
rulesRepository.otherEvents(eventUid),
rulesRepository.enrollment(eventUid),
rulesRepository.queryConstants(),
(rules, variables, events, enrollment, constants) -> {
rulesRepository.getSuplementaryData(d2),
(rules, variables, events, enrollment, constants,supplementaryData) -> {

RuleEngine.Builder builder = RuleEngineContext.builder(evaluator)
.rules(rules)
.ruleVariables(variables)
.constantsValue(constants)
.calculatedValueMap(new HashMap<>())
.supplementaryData(new HashMap<>())
.supplementaryData(supplementaryData)
.build().toEngineBuilder();
builder.triggerEnvironment(TriggerEnvironment.ANDROIDCLIENT);
builder.events(events);
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/org/dhis2/data/forms/RulesRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.dhis2.data.tuples.Pair;
import org.dhis2.utils.DateUtils;
import org.hisp.dhis.android.core.D2;
import org.hisp.dhis.android.core.arch.helpers.UidsHelper;
import org.hisp.dhis.android.core.common.BaseIdentifiableObject;
import org.hisp.dhis.android.core.common.State;
import org.hisp.dhis.android.core.common.ValueType;
Expand Down Expand Up @@ -785,6 +786,10 @@ public Flowable<Map<String, List<String>>> getSuplementaryData(D2 d2) {
}
}

//USER ROLES
List<String> userRoleUids = UidsHelper.getUidsList(d2.userModule().userRoles.get());
supData.put("USER", userRoleUids);

return supData;
});
}
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/org/dhis2/data/server/ServerModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ OkHttpClient okHttpClient(Authenticator authenticator, Context context) {
Timber.d(originalRequest.url().encodedPath());
return chain.proceed(withUserAgent);
})
.readTimeout(2, TimeUnit.MINUTES)
.connectTimeout(2, TimeUnit.MINUTES)
.writeTimeout(2, TimeUnit.MINUTES)
.readTimeout(10, TimeUnit.MINUTES)
.connectTimeout(10, TimeUnit.MINUTES)
.writeTimeout(10, TimeUnit.MINUTES)
.addNetworkInterceptor(new StethoInterceptor())
.dispatcher(dispatcher);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.dhis2.databinding.WidgetDatepickerBinding;
import org.dhis2.usescases.eventsWithoutRegistration.eventInitial.EventInitialActivity;
import org.dhis2.usescases.general.ActivityGlobalAbstract;
import org.dhis2.utils.ColorUtils;
import org.dhis2.utils.Constants;
import org.dhis2.utils.DateUtils;
import org.dhis2.utils.DialogClickListener;
Expand Down Expand Up @@ -82,6 +83,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
binding.setPresenter(presenter);
gestureScanner = new GestureDetector(this, this);

binding.calculationIndicator.text.setTextColor(ColorUtils.getContrastColor(ColorUtils.getPrimaryColor(this, ColorUtils.ColorType.PRIMARY_LIGHT)));

presenter.init(this);

}
Expand Down Expand Up @@ -184,6 +187,11 @@ public void setProgramStage(String programStageUid) {
this.programStageUid = programStageUid;
}

@Override
public void showRuleCalculation(Boolean shouldShow) {
binding.calculationIndicator.getRoot().setVisibility(shouldShow ? View.VISIBLE : View.GONE);
}

private void setAction(FormBottomDialog.ActionType actionType) {
switch (actionType) {
case COMPLETE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public interface View extends AbstractActivityContracts.View {
void attemptToReschedule();

void setProgramStage(String programStageUid);

void showRuleCalculation(Boolean shouldShow);
}

public interface Presenter extends AbstractActivityContracts.Presenter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import io.reactivex.Flowable;
import io.reactivex.Observable;
Expand Down Expand Up @@ -64,6 +65,7 @@ public class EventCapturePresenterImpl implements EventCaptureContract.Presenter
private int currentPosition;
private ObservableField<String> currentSection;
private FlowableProcessor<Integer> currentSectionPosition;
private FlowableProcessor<Boolean> showCalculationProcessor;
private List<FormSectionViewModel> sectionList;
private Map<String, FieldViewModel> emptyMandatoryFields;
//Rules data
Expand Down Expand Up @@ -104,6 +106,7 @@ public EventCapturePresenterImpl(String eventUid, EventCaptureContract.EventCapt
this.sectionList = new ArrayList<>();
currentSectionPosition = PublishProcessor.create();
sectionProcessor = PublishProcessor.create();
showCalculationProcessor = PublishProcessor.create();

}

Expand All @@ -112,6 +115,18 @@ public void init(EventCaptureContract.View view) {
this.compositeDisposable = new CompositeDisposable();
this.view = view;

compositeDisposable.add(
showCalculationProcessor
.startWith(true)
.switchMap(shouldShow -> Flowable.just(shouldShow).delay(1, TimeUnit.SECONDS, Schedulers.io()))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
view::showRuleCalculation,
Timber::e
)
);

compositeDisposable.add(
Flowable.zip(
eventCaptureRepository.programStageName(),
Expand Down Expand Up @@ -253,6 +268,7 @@ public void init(EventCaptureContract.View view) {
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
updates -> {
showCalculationProcessor.onNext(false);
EventCaptureFormFragment.getInstance().showFields(updates, lastFocusItem);
checkProgress();
},
Expand Down Expand Up @@ -390,7 +406,10 @@ public void subscribeToSection() {
emptyMandatoryFields.remove(action.id());
return dataEntryStore.save(action.id(), action.value());
}
).subscribe(result -> Timber.d("SAVED VALUE AT %s", System.currentTimeMillis()),
).subscribe(result -> {
Timber.d("SAVED VALUE AT %s", System.currentTimeMillis());
showCalculationProcessor.onNext(true);
},
Timber::d)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,13 @@ public class ProgramStageSelectionRepositoryImpl implements ProgramStageSelectio
rulesRepository.rulesNew(programUid),
rulesRepository.ruleVariablesProgramStages(programUid),
ruleEvents(enrollmentUid),
(rules, variables, ruleEvents) -> {
rulesRepository.getSuplementaryData(d2),
(rules, variables, ruleEvents,supplementaryData) -> {
RuleEngine.Builder builder = RuleEngineContext.builder(evaluator)
.rules(rules)
.ruleVariables(variables)
.calculatedValueMap(new HashMap<>())
.supplementaryData(new HashMap<>())
.supplementaryData(supplementaryData)
.build().toEngineBuilder();
return builder.events(ruleEvents)
.triggerEnvironment(TriggerEnvironment.ANDROIDCLIENT)
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/indicator_progress_bg.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="?colorPrimaryLight"/>
<corners android:bottomLeftRadius="10dp" android:topLeftRadius="10dp"/>
</shape>
10 changes: 10 additions & 0 deletions app/src/main/res/layout/activity_event_capture.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,15 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/eventTabLayout" />

<include
android:id="@+id/calculationIndicator"
layout="@layout/indicator_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
app:layout_constraintEnd_toEndOf="parent"
android:visibility="gone"
app:layout_constraintTop_toTopOf="@id/eventViewPager" />

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
34 changes: 34 additions & 0 deletions app/src/main/res/layout/indicator_progress.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/indicator_progress_bg"
android:padding="2dp">

<com.airbnb.lottie.LottieAnimationView
android:id="@+id/lottieView"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginEnd="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/text"
app:layout_constraintTop_toTopOf="parent"
app:lottie_autoPlay="true"
app:lottie_loop="true"
app:lottie_rawRes="@raw/calculation_progress" />

<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calculating result..."
android:textColor="?colorAccent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Loading

0 comments on commit 50fc45b

Please sign in to comment.