Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormHierarchy cleanup #2730

Merged
merged 19 commits into from
Nov 21, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

Expand Down Expand Up @@ -92,41 +91,10 @@ public void onCreate(Bundle savedInstanceState) {
path = findViewById(R.id.pathtext);

jumpPreviousButton = findViewById(R.id.jumpPreviousButton);
jumpPreviousButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
goUpLevel();
}
});

jumpBeginningButton = findViewById(R.id.jumpBeginningButton);
jumpBeginningButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
FormController fc = Collect.getInstance().getFormController();
if (fc != null) {
fc.getTimerLogger().exitView();
fc.jumpToIndex(FormIndex.createBeginningOfFormIndex());
}
setResult(RESULT_OK);
finish();
}
});

jumpEndButton = findViewById(R.id.jumpEndButton);
jumpEndButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
FormController fc = Collect.getInstance().getFormController();
if (fc != null) {
fc.getTimerLogger().exitView();
fc.jumpToIndex(FormIndex.createEndOfFormIndex());
}
setResult(RESULT_OK);
finish();
}
});

configureButtons(formController);
refreshView();

// Kinda slow, but works. This scrolls to the last question the user was looking at.
Expand All @@ -145,6 +113,30 @@ public void onClick(View v) {
}
}


/**
* Configure the navigation buttons at the bottom of the screen.
*/
void configureButtons(FormController formController) {
jumpPreviousButton.setOnClickListener(v -> goUpLevel());

jumpBeginningButton.setOnClickListener(v -> {
formController.getTimerLogger().exitView();
formController.jumpToIndex(FormIndex.createBeginningOfFormIndex());

setResult(RESULT_OK);
finish();
});

jumpEndButton.setOnClickListener(v -> {
formController.getTimerLogger().exitView();
formController.jumpToIndex(FormIndex.createEndOfFormIndex());

setResult(RESULT_OK);
finish();
});
}

private boolean shouldScrollToTheGivenIndex(FormIndex formIndex, FormController formController) {
return startIndex.equals(formIndex)
|| (formController.indexIsInFieldList(startIndex) && formIndex.toString().startsWith(startIndex.toString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

package org.odk.collect.android.activities;

import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
Expand All @@ -25,33 +24,27 @@
import org.odk.collect.android.adapters.HierarchyListAdapter;
import org.odk.collect.android.application.Collect;
import org.odk.collect.android.exception.JavaRosaException;
import org.odk.collect.android.logic.FormController;
import org.odk.collect.android.logic.HierarchyElement;

import java.util.ArrayList;

import timber.log.Timber;

public class ViewFormHierarchyActivity extends FormHierarchyActivity {

/**
* A view-only hierarchy doesn't allow the user to jump into the form-filling view so the
* buttons to jump to the beginning and to the end of the form are hidden. There is an extra
* button that allows the user to exit to the previous activity.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// super.onCreate() can call finish() if it finds the FormController to be null
// in that case, we want to shortcut this method, and let the Activity finish itself
if (isFinishing()) {
return;
}

Collect.getInstance().getFormController().stepToOuterScreenEvent();
void configureButtons(FormController formController) {
jumpPreviousButton.setOnClickListener(v -> goUpLevel());

Button exitButton = findViewById(R.id.exitButton);
exitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setResult(RESULT_OK);
finish();
}
exitButton.setOnClickListener(v -> {
setResult(RESULT_OK);
finish();
});

exitButton.setVisibility(View.VISIBLE);
Expand Down