diff --git a/Friendly-plans/app/build.gradle b/Friendly-plans/app/build.gradle index 0e542452..5dd68779 100644 --- a/Friendly-plans/app/build.gradle +++ b/Friendly-plans/app/build.gradle @@ -47,6 +47,7 @@ android { testOptions { unitTests { includeAndroidResources = true + returnDefaultValues = true } } } @@ -66,6 +67,7 @@ dependencies { compile 'com.squareup.picasso:picasso:2.5.2' compile 'com.android.databinding:library:1.3.1' compile 'com.android.databinding:adapters:1.3.1' + compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.8' annotationProcessor "com.google.dagger:dagger-compiler:2.9" provided 'javax.annotation:jsr250-api:1.0' diff --git a/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/AppComponent.java b/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/AppComponent.java index 15b63220..d8092bd1 100644 --- a/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/AppComponent.java +++ b/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/AppComponent.java @@ -14,6 +14,8 @@ import pg.autyzm.friendly_plans.asset.AssetsHelperModule; import pg.autyzm.friendly_plans.file_picker.FilePickerModule; import pg.autyzm.friendly_plans.file_picker.FilePickerProxy; +import pg.autyzm.friendly_plans.manager_app.view.step_create.PictureManager; +import pg.autyzm.friendly_plans.manager_app.view.step_create.SoundManager; import pg.autyzm.friendly_plans.notifications.ToastUserNotifier; import pg.autyzm.friendly_plans.notifications.ToastUserNotifierModule; import pg.autyzm.friendly_plans.manager_app.view.child_list.ChildListActivity; @@ -97,4 +99,8 @@ public interface AppComponent { void inject(StepCreateFragment stepCreateFragment); void inject(SoundComponent soundComponent); + + void inject(SoundManager soundManager); + + void inject(PictureManager pictureManager); } 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 index 73fcb406..f769a916 100644 --- 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 @@ -1,5 +1,103 @@ -//package pg.autyzm.friendly_plans.manager_app.view.step_create; -// -//public class PictureManager { -// -//} +package pg.autyzm.friendly_plans.manager_app.view.step_create; + +import android.app.FragmentManager; +import android.content.Context; +import android.os.Bundle; +import android.view.View; +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 java.io.IOException; +import javax.inject.Inject; +import pg.autyzm.friendly_plans.AppComponent; +import pg.autyzm.friendly_plans.R; +import pg.autyzm.friendly_plans.asset.AssetType; +import pg.autyzm.friendly_plans.asset.AssetsHelper; +import pg.autyzm.friendly_plans.manager_app.view.task_create.ImagePreviewDialog; +import pg.autyzm.friendly_plans.notifications.ToastUserNotifier; + +public class PictureManager { + + @Inject + AssetRepository assetRepository; + @Inject + ToastUserNotifier toastUserNotifier; + + private final ImageButton clearPicture; + private final ImageView picturePreview; + private final Context context; + private final StepCreateData stepData; + + public static PictureManager getPictureManager(StepCreateData stepDate, ImageButton clearPicture, ImageView picturePreview, + Context context, AppComponent appComponent) { + final PictureManager pictureManager = new PictureManager(stepDate, clearPicture, picturePreview, context); + appComponent.inject(pictureManager); + return pictureManager; + } + + private PictureManager(StepCreateData stepDate, ImageButton clearPicture, ImageView picturePreview, Context context) { + this.stepData = stepDate; + this.clearPicture = clearPicture; + this.picturePreview = picturePreview; + this.context = context; + } + + public void showPicture() { + if (isPictureSet()) { + clearPicture.setVisibility(View.VISIBLE); + showPreview(); + } else { + clearPicture.setVisibility(View.INVISIBLE); + picturePreview.setImageDrawable(null); + } + } + + public void showPicturePreview(StepTemplate stepTemplate, + Context applicationContext, + FragmentManager fragmentManager) { + ImagePreviewDialog preview = new ImagePreviewDialog(); + Bundle args = new Bundle(); + args.putString("imgPath", retrieveImageFile(stepTemplate.getPictureId(), applicationContext)); + + preview.setArguments(args); + preview.show(fragmentManager, "preview"); + } + + public void clearPicture() { + stepData.setPicture(null); + showPicture(); + } + + public void handleAssetSelecting(String filePath) { + AssetsHelper assetsHelper = new AssetsHelper(context); + try { + String assetName = assetsHelper.makeSafeCopy(filePath); + Long assetId = assetRepository + .create(AssetType.getTypeByExtension(assetName), assetName); + stepData.setPicture(assetRepository.get(assetId)); + showPicture(); + } catch (IOException e) { + toastUserNotifier.displayNotifications(R.string.picking_file_error, context); + } + } + + private boolean isPictureSet() { + return stepData.getStepTemplate().getPictureId() != null; + } + + private void showPreview() { + Picasso.with(context) + .load(new File(retrieveImageFile(stepData.getStepTemplate().getPictureId(), context))) + .resize(0, picturePreview.getHeight()) + .into(picturePreview); + } + + private String retrieveImageFile(Long pictureId, Context applicationContext) { + String imageFileName = assetRepository.get(pictureId).getFilename(); + String fileDir = applicationContext.getFilesDir().toString(); + return fileDir + File.separator + imageFileName; + } +} 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 deleted file mode 100644 index 833d9cc5..00000000 --- a/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/step_create/SoudManager.java +++ /dev/null @@ -1,36 +0,0 @@ -//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/SoundManager.java b/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/step_create/SoundManager.java new file mode 100644 index 00000000..0a4efe53 --- /dev/null +++ b/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/step_create/SoundManager.java @@ -0,0 +1,150 @@ +package pg.autyzm.friendly_plans.manager_app.view.step_create; + +import android.content.Context; +import android.media.AudioManager; +import android.media.MediaPlayer; +import android.view.View; +import android.view.animation.Animation; +import android.view.animation.AnimationUtils; +import android.widget.ImageButton; +import database.entities.Asset; +import database.repository.AssetRepository; +import java.io.IOException; +import javax.inject.Inject; +import pg.autyzm.friendly_plans.AppComponent; +import pg.autyzm.friendly_plans.R; +import pg.autyzm.friendly_plans.asset.AssetType; +import pg.autyzm.friendly_plans.asset.AssetsHelper; +import pg.autyzm.friendly_plans.notifications.ToastUserNotifier; + +public final class SoundManager { + + @Inject + MediaPlayer mediaPlayer; + @Inject + AssetRepository assetRepository; + @Inject + ToastUserNotifier toastUserNotifier; + @Inject + AssetsHelper assetsHelper; + + private ImageButton playSoundIcon; + private Context context; + private ImageButton clearSound; + private StepCreateData stepData; + + public static SoundManager getSoundManager(StepCreateData stepData, ImageButton playSoundIcon, + ImageButton clearSound, + Context context, AppComponent appComponent) { + final SoundManager soundManager = new SoundManager(stepData, playSoundIcon, clearSound, + context); + appComponent.inject(soundManager); + soundManager.mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); + soundManager.mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { + public void onCompletion(MediaPlayer player) { + soundManager.handlePlayingCompletion(); + } + }); + return soundManager; + } + + private SoundManager(StepCreateData stepData, ImageButton playSoundIcon, + ImageButton clearSound, Context context) { + this.stepData = stepData; + this.clearSound = clearSound; + this.playSoundIcon = playSoundIcon; + this.context = context; + } + + public void onPlayStopSoundClick(View view) { + if (isSoundSet()) { + handleSoundPlaying(); + } else { + toastUserNotifier.displayNotifications(R.string.no_file_to_play_error, context); + } + } + + public void stopActions() { + stopSound(); + stopAnimation(); + } + + public void clearSound() { + stepData.setSound(null); + changeSoundSelected(false); + stopActions(); + } + + public void showSound() { + changeSoundSelected(isSoundSet()); + } + + public void handleAssetSelecting(String filePath) { + AssetsHelper assetsHelper = new AssetsHelper(context); + try { + String assetName = assetsHelper.makeSafeCopy(filePath); + Long soundId = assetRepository + .create(AssetType.getTypeByExtension(assetName), assetName); + stepData.setSound(assetRepository.get(soundId)); + } catch (IOException e) { + toastUserNotifier.displayNotifications(R.string.picking_file_error, context); + } + } + + private void changeSoundSelected(Boolean isSelected) { + if (isSelected) { + playSoundIcon.setVisibility(View.VISIBLE); + clearSound.setVisibility(View.VISIBLE); + } else { + playSoundIcon.setVisibility(View.INVISIBLE); + clearSound.setVisibility(View.INVISIBLE); + } + } + + private boolean isSoundSet() { + return stepData.getStepTemplate().getSoundId() != null; + } + + private void handleSoundPlaying() { + if (!mediaPlayer.isPlaying()) { + Asset sound = assetRepository.get(stepData.getStepTemplate().getSoundId()); + playSound(sound); + runAnimation(); + } else { + stopActions(); + } + } + + private void playSound(Asset sound) { + try { + String soundPath = assetsHelper.getFileFullPath(sound); + mediaPlayer.reset(); + mediaPlayer.setDataSource(soundPath); + mediaPlayer.prepare(); + mediaPlayer.start(); + } catch (IOException e) { + toastUserNotifier.displayNotifications(R.string.playing_file_error, context); + } + } + + private void runAnimation() { + playSoundIcon.setImageResource(R.drawable.ic_playing_sound); + Animation rotation = AnimationUtils.loadAnimation(context, R.anim.ic_play_sound_animation); + playSoundIcon.startAnimation(rotation); + } + + private void stopAnimation() { + playSoundIcon.clearAnimation(); + playSoundIcon.setImageResource(R.drawable.ic_play_sound); + } + + private void stopSound() { + mediaPlayer.stop(); + mediaPlayer.reset(); + } + + private void handlePlayingCompletion() { + mediaPlayer.reset(); + stopAnimation(); + } +} 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 47130201..0ec7757a 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 @@ -5,12 +5,12 @@ import android.databinding.Bindable; import database.entities.Asset; import database.entities.StepTemplate; +import org.apache.commons.lang3.StringUtils; import pg.autyzm.friendly_plans.BR; public class StepCreateData extends BaseObservable { private static final String REGEX_TRIM_NAME = "_([\\d]*)(?=\\.)"; - private static final String EMPTY_VALUE = ""; private StepTemplate stepTemplate = new StepTemplate(); @@ -34,12 +34,11 @@ public void setStepName(String stepName) { @Bindable public String getPictureName() { - return getAssetFileName(stepTemplate.getPictureId()); - } + if (stepTemplate.getPictureId() == null) { + return StringUtils.EMPTY; + } - public void setPictureName(String pictureName) { - this.stepTemplate.setPicture(getAsset(pictureName, this.stepTemplate.getPicture())); - notifyPropertyChanged(BR.pictureName); + return getAssetFileName(stepTemplate.getPicture()); } public void setPicture(Asset picture) { @@ -49,12 +48,11 @@ public void setPicture(Asset picture) { @Bindable public String getSoundName() { - return getAssetFileName(stepTemplate.getSoundId()); - } + if (stepTemplate.getSoundId() == null) { + return StringUtils.EMPTY; + } - public void setSoundName(String soundName) { - this.stepTemplate.setSound(getAsset(soundName, this.stepTemplate.getSound())); - notifyPropertyChanged(BR.soundName); + return getAssetFileName(stepTemplate.getSound()); } public void setSound(Asset sound) { @@ -64,11 +62,11 @@ public void setSound(Asset sound) { @Bindable public String getStepDuration() { - if(stepTemplate.getDurationTime() != null) { + if (stepTemplate.getDurationTime() != null) { return stepTemplate.getDurationTime().toString(); } - return EMPTY_VALUE; + return StringUtils.EMPTY; } public void setStepDuration(String stepDuration) { @@ -84,21 +82,11 @@ public void setStepTemplate(StepTemplate stepTemplate) { this.stepTemplate = stepTemplate; } - private Asset getAsset(String fileName, Asset asset) { - if (fileName == null && asset == null) { - return null; - } - - asset.setFilename(fileName); - - return asset; - } - - private String getAssetFileName(Long assetId) { - if (assetId == null) { - return EMPTY_VALUE; + private String getAssetFileName(Asset asset) { + if (asset == null) { + return StringUtils.EMPTY; } - return stepTemplate.getSound().getFilename().replace(REGEX_TRIM_NAME, ""); + 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/StepCreateEvents.java b/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/step_create/StepCreateEvents.java index df289f46..37b03d62 100644 --- a/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/step_create/StepCreateEvents.java +++ b/Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/manager_app/view/step_create/StepCreateEvents.java @@ -1,13 +1,8 @@ package pg.autyzm.friendly_plans.manager_app.view.step_create; - -import android.view.View; - public interface StepCreateEvents { - void onPlayStopSoundClick(View view); - - public interface StepData { + interface StepData { void saveStepData(StepCreateData stepCreateData); 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 406e234f..639838e8 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 @@ -2,7 +2,6 @@ import android.annotation.TargetApi; import android.app.Fragment; -import android.content.Context; import android.content.Intent; import android.databinding.DataBindingUtil; import android.media.MediaPlayer; @@ -16,28 +15,21 @@ import android.widget.ImageButton; import android.widget.ImageView; -import com.squareup.picasso.Picasso; +import android.widget.TextView; import database.entities.StepTemplate; -import database.repository.AssetRepository; -import java.io.File; -import java.io.IOException; import javax.inject.Inject; -import database.entities.Asset; import database.repository.StepTemplateRepository; import pg.autyzm.friendly_plans.ActivityProperties; import pg.autyzm.friendly_plans.App; import pg.autyzm.friendly_plans.AppComponent; import pg.autyzm.friendly_plans.R; import pg.autyzm.friendly_plans.asset.AssetType; -import pg.autyzm.friendly_plans.asset.AssetsHelper; 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.task_create.ImagePreviewDialog; import pg.autyzm.friendly_plans.notifications.ToastUserNotifier; public class StepCreateFragment extends Fragment implements StepCreateEvents.StepData { @@ -51,20 +43,19 @@ public class StepCreateFragment extends Fragment implements StepCreateEvents.Ste ToastUserNotifier toastUserNotifier; @Inject FilePickerProxy filePickerProxy; - @Inject - AssetRepository assetRepository; - private EditText soundFileName; + private TextView soundFileName; private ImageButton clearSound; - private EditText pictureFileName; + private TextView pictureFileName; private ImageView picturePreview; private ImageButton clearPicture; private EditText stepNameView; private EditText stepDurationView; private ImageButton playSoundIcon; - private SoundComponent soundComponent; private StepCreateData stepData; + private SoundManager soundManager; + private PictureManager pictureManager; @TargetApi(VERSION_CODES.M) @Override @@ -78,27 +69,31 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, ImageButton playSoundIcon = (ImageButton) view.findViewById(R.id.id_btn_play_step_sound); appComponent.inject(this); + registerViews(view); stepData = parseArguments(); - soundComponent = SoundComponent.getSoundComponent( - getSoundId(stepData.getStepTemplate()), playSoundIcon, getActivity().getApplicationContext(), appComponent); - - binding.setSoundComponent(soundComponent); + soundManager = SoundManager.getSoundManager( + stepData, + playSoundIcon, + clearPicture, + getActivity().getApplicationContext(), + appComponent); + + pictureManager = PictureManager.getPictureManager( + stepData, + clearPicture, + picturePreview, + getActivity().getApplicationContext(), + appComponent); + + binding.setSoundManager(soundManager); binding.setStepData(stepData); binding.setStepDataClick(this); return view; } - private static Long getSoundId(StepTemplate stepTemplate) { - if (stepTemplate == null) { - return null; - } - - return stepTemplate.getSoundId(); - } - private StepCreateData parseArguments() { Bundle arguments = getArguments(); @@ -112,67 +107,58 @@ private StepCreateData parseArguments() { return stepData; } + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + + if (filePickerProxy.isFilePicked(resultCode)) { + if (filePickerProxy.isPickFileRequested(requestCode, AssetType.PICTURE)) { + pictureManager.handleAssetSelecting(filePickerProxy.getFilePath(data)); + } else if (filePickerProxy.isPickFileRequested(requestCode, AssetType.SOUND)) { + soundManager.handleAssetSelecting(filePickerProxy.getFilePath(data)); + } + } + } + @Override public void onViewCreated(View view, Bundle savedInstanceState) { - registerViews(view); view.post(new Runnable() { @Override public void run() { if (stepData != null && stepData.getStepTemplate() != null) { - StepTemplate stepTemplate = stepData.getStepTemplate(); - - Long pictureId = stepTemplate.getPictureId(); - if (pictureId != null) { - clearPicture.setVisibility(View.VISIBLE); - showPreview(pictureId, picturePreview); - } - - Long soundId = stepTemplate.getSoundId(); - if (soundId != null) { - clearSound.setVisibility(View.VISIBLE); - } + pictureManager.showPicture(); + soundManager.showSound(); } } }); } - @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.setPicture(null); - picturePreview.setImageDrawable(null); - clearPicture.setVisibility(View.INVISIBLE); + pictureManager.clearPicture(); } - @Override public void clearStepSound() { - stepData.setSound(null); - clearSound.setVisibility(View.INVISIBLE); - soundComponent.setSoundId(null); - soundComponent.stopActions(); + soundManager.clearSound(); } - @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"); + pictureManager.showPicturePreview( + stepData.getStepTemplate(), + getActivity().getApplicationContext(), + getFragmentManager() + ); } - @Override public void saveStepData(StepCreateData stepCreateData) { - soundComponent.stopActions(); + soundManager.stopActions(); try { StepTemplate stepTemplate = stepCreateData.getStepTemplate(); @@ -187,69 +173,17 @@ public void saveStepData(StepCreateData stepCreateData) { } } - @Override - public void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - - if (filePickerProxy.isFilePicked(resultCode)) { - if (filePickerProxy.isPickFileRequested(requestCode, AssetType.PICTURE)) { - handleAssetSelecting(data, AssetType.PICTURE); - } else if (filePickerProxy.isPickFileRequested(requestCode, AssetType.SOUND)) { - handleAssetSelecting(data, AssetType.SOUND); - } - } - } - - protected void handleAssetSelecting(Intent data, AssetType assetType) { - Context context = getActivity().getApplicationContext(); - String filePath = filePickerProxy.getFilePath(data); - AssetsHelper assetsHelper = new AssetsHelper(context); - try { - String assetName = assetsHelper.makeSafeCopy(filePath); - Long assetId = assetRepository - .create(AssetType.getTypeByExtension(assetName), assetName); - setAssetValue(assetType, assetRepository.get(assetId)); - } catch (IOException e) { - showToastMessage(R.string.picking_file_error); - } - } - - private void setAssetValue(AssetType assetType, Asset asset) { - if (assetType.equals(AssetType.PICTURE)) { - stepData.setPicture(asset); - clearPicture.setVisibility(View.VISIBLE); - showPreview(asset.getId(), picturePreview); - } else { - stepData.setSound(asset); - soundComponent.setSoundId(asset.getId()); - clearSound.setVisibility(View.VISIBLE); - } - } - - private String retrieveImageFile(Long pictureId) { - String imageFileName = assetRepository.get(pictureId).getFilename(); - String fileDir = getActivity().getApplicationContext().getFilesDir().toString(); - return fileDir + File.separator + imageFileName; - } - 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); + pictureFileName = (TextView) 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); + soundFileName = (TextView) 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); } - private void showPreview(Long pictureId, ImageView picturePreview) { - Picasso.with(getActivity().getApplicationContext()) - .load(new File(retrieveImageFile(pictureId))) - .resize(0, picturePreview.getHeight()) - .into(picturePreview); - } - private void createStepTemplate(StepCreateData stepCreateData) { if (validateName(stepNameView, stepCreateData)) { StepTemplate stepTemplate = stepCreateData.getStepTemplate(); 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 66f43be9..d1d74083 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 @@ -17,6 +17,7 @@ import javax.inject.Inject; import database.repository.AssetRepository; +import org.apache.commons.lang3.StringUtils; import pg.autyzm.friendly_plans.R; import pg.autyzm.friendly_plans.asset.AssetType; import pg.autyzm.friendly_plans.asset.AssetsHelper; @@ -111,7 +112,7 @@ protected void showPicture(Long pictureId) { } protected void clearSound() { - soundFileName.setText(""); + soundFileName.setText(StringUtils.EMPTY); soundId = null; clearSound.setVisibility(View.INVISIBLE); soundComponent.setSoundId(null); @@ -119,7 +120,7 @@ protected void clearSound() { } protected void clearPicture() { - pictureFileName.setText(""); + pictureFileName.setText(StringUtils.EMPTY); pictureId = null; picturePreview.setImageDrawable(null); clearPicture.setVisibility(View.INVISIBLE); 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 0abbc71d..19e4d104 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 @@ -3,8 +3,11 @@ xmlns:app="http://schemas.android.com/apk/res-auto"> + name="soundManager" + type="pg.autyzm.friendly_plans.manager_app.view.step_create.SoundManager" /> + @@ -94,15 +97,13 @@ android:layout_column="0" android:text="@string/picture" /> - + android:text="@{stepData.pictureName}" />