From a76489487e71f1a49a549a70709c46a0e46389c5 Mon Sep 17 00:00:00 2001 From: malsolec Date: Sat, 11 Aug 2018 22:53:56 +0200 Subject: [PATCH] #331: Step template view refactor --- .../java/database/entities/StepTemplate.java | 16 +- .../repository/StepTemplateRepository.java | 14 +- .../view/components/SoundComponent.java | 1 - .../view/step_create/PictureManager.java | 5 + .../view/step_create/SoudManager.java | 36 +++ .../view/step_create/StepCreateData.java | 74 ++++- .../view/step_create/StepCreateFragment.java | 264 +++++++++++------- .../view/step_list/StepListFragment.java | 2 +- .../view/view_fragment/CreateFragment.java | 1 - .../main/res/layout/fragment_step_create.xml | 30 +- .../app/src/main/res/values/strings.xml | 3 +- .../database/StepTemplateRepositoryTest.java | 3 +- .../view/StepCreateFragmentTest.java | 2 +- 13 files changed, 315 insertions(+), 136 deletions(-) create mode 100644 Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/step_create/PictureManager.java create mode 100644 Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/step_create/SoudManager.java diff --git a/Friendly-plans/app/src/main/java/database/entities/StepTemplate.java b/Friendly-plans/app/src/main/java/database/entities/StepTemplate.java index 9d700bcd..b402c9c3 100644 --- a/Friendly-plans/app/src/main/java/database/entities/StepTemplate.java +++ b/Friendly-plans/app/src/main/java/database/entities/StepTemplate.java @@ -25,6 +25,8 @@ public class StepTemplate { private Long soundId; + private Integer durationTime; + @ToOne(joinProperty = "taskTemplateId") private TaskTemplate taskTemplate; @@ -51,13 +53,15 @@ public class StepTemplate { @Generated(hash = 1320587426) private transient StepTemplateDao myDao; - @Generated(hash = 439029214) - public StepTemplate(Long id, String name, int order, Long pictureId, Long soundId, long taskTemplateId) { + @Generated(hash = 672659171) + public StepTemplate(Long id, String name, int order, Long pictureId, Long soundId, Integer durationTime, + long taskTemplateId) { this.id = id; this.name = name; this.order = order; this.pictureId = pictureId; this.soundId = soundId; + this.durationTime = durationTime; this.taskTemplateId = taskTemplateId; } @@ -114,6 +118,14 @@ public void setSoundId(Long soundId) { this.soundId = soundId; } + public Integer getDurationTime() { + return this.durationTime; + } + + public void setDurationTime(Integer durationTime) { + this.durationTime = durationTime; + } + @Generated(hash = 309141312) private transient Long taskTemplate__resolvedKey; diff --git a/Friendly-plans/app/src/main/java/database/repository/StepTemplateRepository.java b/Friendly-plans/app/src/main/java/database/repository/StepTemplateRepository.java index 92ea8979..e58dda13 100644 --- a/Friendly-plans/app/src/main/java/database/repository/StepTemplateRepository.java +++ b/Friendly-plans/app/src/main/java/database/repository/StepTemplateRepository.java @@ -14,18 +14,23 @@ public StepTemplateRepository(DaoSession daoSession) { this.daoSession = daoSession; } - public long create(String name, int order, Long pictureId, Long soundId, Long taskTemplateId) { + public long create(String name, int order, Long pictureId, Long soundId, Long taskTemplateId, Integer stepDuration) { StepTemplate stepTemplate = new StepTemplate(); stepTemplate.setName(name); stepTemplate.setOrder(order); stepTemplate.setSoundId(soundId); stepTemplate.setPictureId(pictureId); stepTemplate.setTaskTemplateId(taskTemplateId); + stepTemplate.setDurationTime(stepDuration); return daoSession.getStepTemplateDao().insert(stepTemplate); } - public void update(Long stepId, String name, int order, Long pictureId, Long soundId, Long taskTemplateId) { + public long create(StepTemplate stepTemplate) { + return daoSession.getStepTemplateDao().insert(stepTemplate); + } + + public void update(Long stepId, String name, int order, Long pictureId, Long soundId, Long taskTemplateId, Integer stepDuration) { StepTemplate stepTemplate = new StepTemplate(); stepTemplate.setId(stepId); stepTemplate.setName(name); @@ -33,7 +38,12 @@ public void update(Long stepId, String name, int order, Long pictureId, Long sou stepTemplate.setSoundId(soundId); stepTemplate.setPictureId(pictureId); stepTemplate.setTaskTemplateId(taskTemplateId); + stepTemplate.setDurationTime(stepDuration); + + daoSession.getStepTemplateDao().update(stepTemplate); + } + public void update(StepTemplate stepTemplate) { daoSession.getStepTemplateDao().update(stepTemplate); } diff --git a/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/components/SoundComponent.java b/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/components/SoundComponent.java index 36434c4d..d523916e 100644 --- a/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/components/SoundComponent.java +++ b/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/components/SoundComponent.java @@ -30,7 +30,6 @@ public final class SoundComponent { @Inject AssetsHelper assetsHelper; - private Long soundId; private ImageButton playSoundIcon; private Context context; diff --git a/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/step_create/PictureManager.java b/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/step_create/PictureManager.java new file mode 100644 index 00000000..73fcb406 --- /dev/null +++ b/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/step_create/PictureManager.java @@ -0,0 +1,5 @@ +//package pg.autyzm.friendly_plans.manager_app.view.step_create; +// +//public class PictureManager { +// +//} diff --git a/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/step_create/SoudManager.java b/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/step_create/SoudManager.java new file mode 100644 index 00000000..833d9cc5 --- /dev/null +++ b/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/step_create/SoudManager.java @@ -0,0 +1,36 @@ +//package pg.autyzm.friendly_plans.manager_app.view.step_create; +// +//import android.content.Context; +//import android.view.View; +//import android.widget.EditText; +//import android.widget.ImageButton; +//import pg.autyzm.friendly_plans.manager_app.view.components.SoundComponent; +// +//public class SoudManager { +// private final EditText soundFileName; +// private final ImageButton clearSound; +// +// private Long soundId; +// private SoundComponent soundComponent; +// +// +// public SoudManager(EditText soundFileName, +// ImageButton clearSound, +// ImageButton playSoundIcon, +// Context applicationContext) { +// this.soundFileName = soundFileName; +// this.clearSound = clearSound; +// +// soundComponent = SoundComponent.getSoundComponent( +// soundId, playSoundIcon, applicationContext, appComponent); +// } +// +// protected void clearSound() { +// soundFileName.setText(""); +// soundId = null; +// clearSound.setVisibility(View.INVISIBLE); +// soundComponent.setSoundId(null); +// soundComponent.stopActions(); +// } +// +//} diff --git a/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/step_create/StepCreateData.java b/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/step_create/StepCreateData.java index f871405f..89bf7fee 100644 --- a/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/step_create/StepCreateData.java +++ b/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/step_create/StepCreateData.java @@ -3,44 +3,92 @@ import android.databinding.BaseObservable; import android.databinding.Bindable; +import database.entities.Asset; +import database.entities.StepTemplate; import pg.autyzm.friendly_plans.BR; public class StepCreateData extends BaseObservable { - private String stepName; - private String pictureName; - private String soundName; + private static final String REGEX_TRIM_NAME = "_([\\d]*)(?=\\.)"; + private static final String EMPTY_VALUE = ""; - public StepCreateData(String stepName, String pictureName, String soundName) { - this.stepName = stepName; - this.pictureName = pictureName; - this.soundName = soundName; + private StepTemplate stepTemplate = new StepTemplate(); + private Long taskId; + + public StepCreateData(Long taskId) { + this.taskId = taskId; + } + + public Long getTaskId() { + return taskId; } @Bindable public String getStepName() { - return stepName; + return stepTemplate.getName(); } + public void setStepName(String stepName) { - this.stepName = stepName; + this.stepTemplate.setName(stepName); notifyPropertyChanged(BR.stepName); } @Bindable public String getPictureName() { - return pictureName; + return getAssetFileName(stepTemplate.getPicture()); } + public void setPictureName(String pictureName) { - this.pictureName = pictureName; + this.stepTemplate.setPicture(getAsset(pictureName, this.stepTemplate.getPicture())); notifyPropertyChanged(BR.pictureName); } @Bindable public String getSoundName() { - return soundName; + return getAssetFileName(stepTemplate.getSound()); } + public void setSoundName(String soundName) { - this.soundName = soundName; + this.stepTemplate.setSound(getAsset(soundName, this.stepTemplate.getSound())); notifyPropertyChanged(BR.soundName); } + + @Bindable + public String getStepDuration() { + return stepTemplate.getDurationTime().toString(); + } + + public void setStepDuration(String stepDuration) { + this.stepTemplate.setDurationTime(Integer.valueOf(stepDuration)); + notifyPropertyChanged(BR.stepDuration); + } + + public StepTemplate getStepTemplate() { + return stepTemplate; + } + + public void setStepTemplate(StepTemplate stepTemplate) { + this.stepTemplate = stepTemplate; + } + + private Asset getAsset(String fileName, Asset asset) { + if (fileName == null) { + return null; + } + + if (asset == null) { + asset = new Asset(); + } + asset.setFilename(fileName); + + return asset; + } + + private String getAssetFileName(Asset asset) { + if (asset == null) { + return EMPTY_VALUE; + } + + return asset.getFilename().replace(REGEX_TRIM_NAME, ""); + } } diff --git a/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/step_create/StepCreateFragment.java b/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/step_create/StepCreateFragment.java index e85c69a6..53ad42eb 100644 --- a/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/step_create/StepCreateFragment.java +++ b/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/step_create/StepCreateFragment.java @@ -1,6 +1,7 @@ package pg.autyzm.friendly_plans.manager_app.view.step_create; import android.annotation.TargetApi; +import android.app.Fragment; import android.databinding.DataBindingUtil; import android.media.MediaPlayer; import android.os.Build.VERSION_CODES; @@ -13,10 +14,13 @@ import android.widget.ImageButton; import android.widget.ImageView; +import com.squareup.picasso.Picasso; +import database.entities.StepTemplate; +import database.repository.AssetRepository; +import java.io.File; import javax.inject.Inject; import database.entities.Asset; -import database.entities.StepTemplate; import database.repository.StepTemplateRepository; import pg.autyzm.friendly_plans.ActivityProperties; import pg.autyzm.friendly_plans.App; @@ -24,27 +28,39 @@ import pg.autyzm.friendly_plans.R; import pg.autyzm.friendly_plans.asset.AssetType; import pg.autyzm.friendly_plans.databinding.FragmentStepCreateBinding; +import pg.autyzm.friendly_plans.file_picker.FilePickerProxy; import pg.autyzm.friendly_plans.manager_app.validation.StepValidation; import pg.autyzm.friendly_plans.manager_app.validation.ValidationResult; +import pg.autyzm.friendly_plans.manager_app.validation.ValidationStatus; import pg.autyzm.friendly_plans.manager_app.view.components.SoundComponent; -import pg.autyzm.friendly_plans.manager_app.view.view_fragment.CreateFragment; - -public class StepCreateFragment extends CreateFragment implements StepCreateEvents.StepData { +import pg.autyzm.friendly_plans.manager_app.view.task_create.ImagePreviewDialog; +import pg.autyzm.friendly_plans.notifications.ToastUserNotifier; +public class StepCreateFragment extends Fragment implements StepCreateEvents.StepData { @Inject MediaPlayer mediaPlayer; @Inject StepTemplateRepository stepTemplateRepository; @Inject StepValidation stepValidation; + @Inject + ToastUserNotifier toastUserNotifier; + @Inject + FilePickerProxy filePickerProxy; + @Inject + AssetRepository assetRepository; + private EditText soundFileName; + private ImageButton clearSound; + private EditText pictureFileName; + private ImageView picturePreview; + private ImageButton clearPicture; + private EditText stepNameView; + private EditText stepDurationView; + private ImageButton playSoundIcon; - private Long taskId; - private Long stepId; + private SoundComponent soundComponent; private StepCreateData stepData; - private StepTemplate step; - private static final String REGEX_TRIM_NAME = "_([\\d]*)(?=\\.)"; - private EditText stepNameView; @TargetApi(VERSION_CODES.M) @Override @@ -53,157 +69,193 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, FragmentStepCreateBinding binding = DataBindingUtil.inflate( inflater, R.layout.fragment_step_create, container, false); - View view = binding.getRoot(); - ImageButton playSoundIcon = (ImageButton) view.findViewById(R.id.id_btn_play_step_sound); - AppComponent appComponent = ((App) getActivity().getApplication()).getAppComponent(); + + stepData = parseArguments(); + soundComponent = SoundComponent.getSoundComponent( - soundId, playSoundIcon, getActivity().getApplicationContext(), appComponent); + getSoundId(stepData.getStepTemplate()), playSoundIcon, getActivity().getApplicationContext(), appComponent); appComponent.inject(this); + View view = binding.getRoot(); binding.setSoundComponent(soundComponent); + binding.setStepData(stepData); + binding.setStepDataClick(this); + + return view; + } + + private static Long getSoundId(StepTemplate stepTemplate) { + if (stepTemplate == null) { + return null; + } - String initialStepName = ""; + return stepTemplate.getSoundId(); + } + private StepCreateData parseArguments() { Bundle arguments = getArguments(); - if (arguments != null) { - if(arguments.containsKey(ActivityProperties.TASK_ID)) { - taskId = (Long) arguments.get(ActivityProperties.TASK_ID); - } - if(arguments.containsKey(ActivityProperties.STEP_ID)) { - stepId = (Long) arguments.get(ActivityProperties.STEP_ID); - step = stepTemplateRepository.get(stepId); - initialStepName = step.getName(); - } + + StepCreateData stepData = new StepCreateData( + (Long) arguments.get(ActivityProperties.TASK_ID)); + if (arguments.containsKey(ActivityProperties.STEP_ID)) { + Long stepId = (Long) arguments.get(ActivityProperties.STEP_ID); + stepData.setStepTemplate(stepTemplateRepository.get(stepId)); } - stepData = new StepCreateData(initialStepName, "", ""); - binding.setStepData(stepData); - binding.setStepDataClick(this); - return view; + return stepData; } @Override public void onViewCreated(View view, Bundle savedInstanceState) { registerViews(view); - view.post(new Runnable() { // Set assets only when the layout is completely built + view.post(new Runnable() { @Override public void run() { - if(step != null) { - Asset picture = step.getPicture(); - Asset sound = step.getSound(); + if (stepData != null && stepData.getStepTemplate() != null) { + StepTemplate stepTemplate = stepData.getStepTemplate(); + + Asset picture = stepTemplate.getPicture(); if (picture != null) { - setAssetValue(AssetType.PICTURE, picture.getFilename(), picture.getId()); + clearPicture.setVisibility(View.VISIBLE); + showPreview(picture.getId(), picturePreview); } + + Asset sound = stepTemplate.getSound(); if (sound != null) { - setAssetValue(AssetType.SOUND, sound.getFilename(), sound.getId()); + clearSound.setVisibility(View.VISIBLE); } + } } }); } - private void registerViews(View view) { - stepNameView = (EditText) view.findViewById(R.id.id_et_step_name); - pictureFileName = (EditText) view.findViewById(R.id.id_et_step_picture); - clearPicture = (ImageButton) view.findViewById(R.id.id_ib_step_clear_img_btn); - picturePreview = (ImageView) view.findViewById(R.id.iv_step_picture_preview); - soundFileName = (EditText) view.findViewById(R.id.id_et_step_sound); - clearSound = (ImageButton) view.findViewById(R.id.id_ib_clear_step_sound_btn); + @Override + public void selectStepPicture() { + filePickerProxy.openFilePicker(StepCreateFragment.this, AssetType.PICTURE); + } + + @Override + public void selectStepSound() { + filePickerProxy.openFilePicker(StepCreateFragment.this, AssetType.SOUND); + } + + @Override + public void cleanStepPicture() { + stepData.setPictureName(null); + picturePreview.setImageDrawable(null); + clearPicture.setVisibility(View.INVISIBLE); } - private Long addOrUpdateStepToTask(String stepName, int order) { + @Override + public void clearStepSound() { + stepData.setPictureName(null); + clearSound.setVisibility(View.INVISIBLE); + soundComponent.setSoundId(null); soundComponent.stopActions(); + } + + @Override + public void showPicture() { + ImagePreviewDialog preview = new ImagePreviewDialog(); + Bundle args = new Bundle(); + args.putString("imgPath", retrieveImageFile(stepData.getStepTemplate().getPictureId())); + preview.setArguments(args); + preview.show(getFragmentManager(), "preview"); + } + + @Override + public void saveStepData(StepCreateData stepCreateData) { + soundComponent.stopActions(); + try { - if (stepId != null) { - if(validateName(stepId, stepNameView)) { - - stepTemplateRepository.update(stepId, stepName, order, - pictureId, - soundId, taskId); - showToastMessage(R.string.step_saved_message); - return stepId; - } + StepTemplate stepTemplate = stepCreateData.getStepTemplate(); + if (stepTemplate != null) { + updateStepTemplate(stepTemplate); } else { - if(validateName(stepNameView)) { - long stepId = stepTemplateRepository.create(stepName, order, - pictureId, - soundId, taskId); - showToastMessage(R.string.step_saved_message); - return stepId; - } + createStepTemplate(stepCreateData); } } catch (RuntimeException exception) { Log.e("Step Create View", "Error saving step", exception); showToastMessage(R.string.save_step_error_message); } - return null; } - private boolean validateName(EditText stepName) { - ValidationResult validationResult = stepValidation - .isNewNameValid(taskId, stepName.getText().toString()); - return handleInvalidResult(stepName, validationResult); + private String retrieveImageFile(Long pictureId) { + String imageFileName = assetRepository.get(pictureId).getFilename(); + String fileDir = getActivity().getApplicationContext().getFilesDir().toString(); + return fileDir + File.separator + imageFileName; } - private boolean validateName(Long stepId, EditText stepName) { - ValidationResult validationResult = stepValidation - .isUpdateNameValid(stepId, taskId, stepName.getText().toString()); - return handleInvalidResult(stepName, validationResult); + private void registerViews(View view) { + stepNameView = (EditText) view.findViewById(R.id.id_et_step_name); + pictureFileName = (EditText) view.findViewById(R.id.id_et_step_picture); + clearPicture = (ImageButton) view.findViewById(R.id.id_ib_step_clear_img_btn); + picturePreview = (ImageView) view.findViewById(R.id.iv_step_picture_preview); + soundFileName = (EditText) view.findViewById(R.id.id_et_step_sound); + clearSound = (ImageButton) view.findViewById(R.id.id_ib_clear_step_sound_btn); + stepDurationView = (EditText) view.findViewById(R.id.id_et_step_duration); + playSoundIcon = (ImageButton) view.findViewById(R.id.id_btn_play_step_sound); } - @Override - public void selectStepPicture() { - filePickerProxy.openFilePicker(StepCreateFragment.this, AssetType.PICTURE); + private void showPreview(Long pictureId, ImageView picturePreview) { + Picasso.with(getActivity().getApplicationContext()) + .load(new File(retrieveImageFile(pictureId))) + .resize(0, picturePreview.getHeight()) + .into(picturePreview); } - @Override - protected void setAssetValue(AssetType assetType, String assetName, Long assetId) { - - String assetNameTrimed = assetName.replaceAll(REGEX_TRIM_NAME, ""); - - if (assetType.equals(AssetType.PICTURE)) { - stepData.setPictureName(assetNameTrimed); - clearPicture.setVisibility(View.VISIBLE); - pictureId = assetId; - showPreview(pictureId, picturePreview); - } else { - stepData.setSoundName(assetNameTrimed); - soundId = assetId; - soundComponent.setSoundId(assetId); - clearSound.setVisibility(View.VISIBLE); + private void createStepTemplate(StepCreateData stepCreateData) { + if (validateName(stepNameView, stepCreateData)) { + StepTemplate stepTemplate = stepCreateData.getStepTemplate(); + stepTemplate.setOrder(countStepOrder(stepCreateData.getTaskId())); + long stepId = stepTemplateRepository.create(stepTemplate); + + stepTemplate.setId(stepId); + + showToastMessage(R.string.step_saved_message); + getFragmentManager().popBackStack(); } } - @Override - public void selectStepSound() { - filePickerProxy.openFilePicker(StepCreateFragment.this, AssetType.SOUND); + private boolean validateName(EditText stepName, StepCreateData stepCreateData) { + ValidationResult validationResult = stepValidation + .isNewNameValid(stepCreateData.getTaskId(), stepCreateData.getStepName()); + return handleInvalidResult(stepName, validationResult); } - @Override - public void cleanStepPicture() { - clearPicture(); + private void updateStepTemplate(StepTemplate stepTemplate) { + if (validateName(stepNameView, stepTemplate)) { + stepTemplateRepository.update(stepTemplate); + showToastMessage(R.string.step_saved_message); + getFragmentManager().popBackStack(); + } } - @Override - public void clearStepSound() { - clearSound(); + private boolean validateName(EditText stepName, StepTemplate stepTemplate) { + ValidationResult validationResult = stepValidation + .isUpdateNameValid(stepTemplate.getId(), + stepTemplate.getTaskTemplateId(), + stepTemplate.getName()); + return handleInvalidResult(stepName, validationResult); } - @Override - public void showPicture() { - showPicture(pictureId); + private boolean handleInvalidResult(EditText editText, ValidationResult validationResult) { + if (validationResult.getValidationStatus().equals(ValidationStatus.INVALID)) { + editText.setError(validationResult.getValidationInfo()); + return false; + } + return true; } - @Override - public void saveStepData(StepCreateData stepCreateData) { - String name = stepCreateData.getStepName(); - String picture = stepCreateData.getPictureName(); - String sound = stepCreateData.getSoundName(); - int order = stepTemplateRepository.getAll(taskId).size(); - if(stepId != null) order = step.getOrder(); - Long stepId = addOrUpdateStepToTask(name, order); - Log.i("step data", name + " " + picture + " " + sound+ " " + stepId); - if(stepId != null) getFragmentManager().popBackStack(); + private void showToastMessage(int resourceStringId) { + toastUserNotifier.displayNotifications( + resourceStringId, + getActivity().getApplicationContext()); + } + + private int countStepOrder(Long taskId) { + return stepTemplateRepository.getAll(taskId).size(); } } diff --git a/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/step_list/StepListFragment.java b/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/step_list/StepListFragment.java index dd5e8ea9..292944bb 100644 --- a/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/step_list/StepListFragment.java +++ b/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/step_list/StepListFragment.java @@ -53,7 +53,7 @@ public void onMoveItem() { for(int i = 0; i < stepListRecyclerViewAdapter.getItemCount(); i++){ StepTemplate stepItem = stepListRecyclerViewAdapter.getStepTemplate(i); if(i != stepItem.getOrder()) { - stepTemplateRepository.update(stepItem.getId(), stepItem.getName(), i, stepItem.getPictureId(), stepItem.getSoundId(), stepItem.getTaskTemplateId()); + stepTemplateRepository.update(stepItem.getId(), stepItem.getName(), i, stepItem.getPictureId(), stepItem.getSoundId(), stepItem.getTaskTemplateId(), stepItem.getDurationTime()); reordered = true; } if(!removedStep && reordered){ diff --git a/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/view_fragment/CreateFragment.java b/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/view_fragment/CreateFragment.java index ad7f32bd..66f43be9 100644 --- a/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/view_fragment/CreateFragment.java +++ b/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/view_fragment/CreateFragment.java @@ -45,7 +45,6 @@ public abstract class CreateFragment extends Fragment { protected ImageView picturePreview; protected ImageButton clearPicture; - protected boolean handleInvalidResult(EditText editText, ValidationResult validationResult) { if (validationResult.getValidationStatus().equals(ValidationStatus.INVALID)) { editText.setError(validationResult.getValidationInfo()); diff --git a/Friendly-plans/app/src/main/res/layout/fragment_step_create.xml b/Friendly-plans/app/src/main/res/layout/fragment_step_create.xml index 760ddede..0abbc71d 100644 --- a/Friendly-plans/app/src/main/res/layout/fragment_step_create.xml +++ b/Friendly-plans/app/src/main/res/layout/fragment_step_create.xml @@ -21,8 +21,6 @@ android:stretchColumns="1" android:orientation="vertical"> - - @@ -63,6 +61,29 @@ + + + + + + + + @@ -212,11 +233,6 @@ - - - - - \ No newline at end of file diff --git a/Friendly-plans/app/src/main/res/values/strings.xml b/Friendly-plans/app/src/main/res/values/strings.xml index 4f1c2722..6b04e79a 100644 --- a/Friendly-plans/app/src/main/res/values/strings.xml +++ b/Friendly-plans/app/src/main/res/values/strings.xml @@ -23,6 +23,7 @@ Next Create Task Step name: + Step duration: List of Plans / Edit Plan List of Tasks / Edit Task Active Child Settings @@ -44,7 +45,7 @@ Step removed Step saved Steps reordered and saved - Search + Search Step 2.1: Add new tasks and put them in order Add tasks Select active plan diff --git a/Friendly-plans/app/src/test/java/pg/autyzm/friendly_plans/database/StepTemplateRepositoryTest.java b/Friendly-plans/app/src/test/java/pg/autyzm/friendly_plans/database/StepTemplateRepositoryTest.java index 6c842995..42406ced 100644 --- a/Friendly-plans/app/src/test/java/pg/autyzm/friendly_plans/database/StepTemplateRepositoryTest.java +++ b/Friendly-plans/app/src/test/java/pg/autyzm/friendly_plans/database/StepTemplateRepositoryTest.java @@ -26,6 +26,7 @@ public class StepTemplateRepositoryTest { private final static Long SOUND_ID = 3L; private final static Long TASK_TEMPLATE_ID = 4L; private final static Long STEP_ID = 5L; + private final static Integer STEP_DURATION = 4; @InjectMocks StepTemplateRepository stepTemplateRepository; @@ -41,7 +42,7 @@ public void setUp() { @Test public void whenCreatingAStepTemplateExpectInsertMethodBeCalled() { - stepTemplateRepository.create(STEP_NAME, ORDER, PICTURE_ID, SOUND_ID, TASK_TEMPLATE_ID); + stepTemplateRepository.create(STEP_NAME, ORDER, PICTURE_ID, SOUND_ID, TASK_TEMPLATE_ID, STEP_DURATION); ArgumentCaptor stepTemplateArgumentCaptor = ArgumentCaptor .forClass(StepTemplate.class); diff --git a/Friendly-plans/app/src/test/java/pg/autyzm/friendly_plans/manager_app/view/StepCreateFragmentTest.java b/Friendly-plans/app/src/test/java/pg/autyzm/friendly_plans/manager_app/view/StepCreateFragmentTest.java index 338261ff..ef90f427 100644 --- a/Friendly-plans/app/src/test/java/pg/autyzm/friendly_plans/manager_app/view/StepCreateFragmentTest.java +++ b/Friendly-plans/app/src/test/java/pg/autyzm/friendly_plans/manager_app/view/StepCreateFragmentTest.java @@ -154,7 +154,7 @@ private void checkRuntimeException(int buttonId) { .thenReturn(new ValidationResult(ValidationStatus.VALID)); when(stepTemplateRepository - .create(any(String.class), any(Integer.class), any(Long.class), any(Long.class), any(Long.class))) + .create(any(String.class), any(Integer.class), any(Long.class), any(Long.class), any(Long.class), any(Integer.class))) .thenThrow(new RuntimeException()); Button button = (Button) activity.findViewById(buttonId); button.performClick();