From 3ce36655462961b3781a370c6ed8ba0f43544adb Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Wed, 25 Apr 2018 22:43:34 -0400 Subject: [PATCH] - Received sound setting done --- app/build.gradle | 1 + .../fragments/GeneralSettingsFragment.java | 64 +++++++++++++++++++ .../crystalwallet/models/GeneralSetting.java | 1 + .../res/layout/fragment_general_settings.xml | 12 ++-- 4 files changed, 72 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1ba8d38..a80aac7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -67,4 +67,5 @@ dependencies { compile 'com.squareup.picasso:picasso:2.5.2' implementation 'com.github.esafirm.android-image-picker:imagepicker:1.11.1' compile 'id.zelory:compressor:2.1.0' + compile 'com.vincent.filepicker:MultiTypeFilePicker:1.0.7' } diff --git a/app/src/main/java/cy/agorise/crystalwallet/fragments/GeneralSettingsFragment.java b/app/src/main/java/cy/agorise/crystalwallet/fragments/GeneralSettingsFragment.java index f67ab5d..47bb866 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/GeneralSettingsFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/GeneralSettingsFragment.java @@ -15,8 +15,15 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; +import android.widget.EditText; import android.widget.Spinner; +import android.widget.TextView; +import com.vincent.filepicker.Constant; +import com.vincent.filepicker.activity.AudioPickActivity; +import com.vincent.filepicker.filter.entity.AudioFile; + +import java.io.File; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; @@ -29,6 +36,7 @@ import java.util.concurrent.TimeUnit; import butterknife.BindView; import butterknife.ButterKnife; +import butterknife.OnClick; import butterknife.OnItemSelected; import cy.agorise.crystalwallet.R; import cy.agorise.crystalwallet.dao.CrystalDatabase; @@ -37,6 +45,10 @@ import cy.agorise.crystalwallet.models.GeneralSetting; import cy.agorise.crystalwallet.viewmodels.GeneralSettingListViewModel; import cy.agorise.crystalwallet.views.TimeZoneAdapter; +import static android.app.Activity.RESULT_OK; +import static android.content.Context.CONSUMER_IR_SERVICE; +import static com.vincent.filepicker.activity.AudioPickActivity.IS_NEED_RECORDER; + /** * Created by xd on 12/28/17. @@ -57,6 +69,8 @@ public class GeneralSettingsFragment extends Fragment { Spinner spPreferredLanguage; @BindView (R.id.spDisplayDateTime) Spinner spDisplayDateTime; + @BindView (R.id.tvReceiveFundsSoundValue) + TextView tvReceiveFundsSound; public GeneralSettingsFragment() { this.spPreferredLanguageInitialized = false; @@ -152,6 +166,20 @@ public class GeneralSettingsFragment extends Fragment { } } + public void initReceiveFundsSound(GeneralSetting receiveFundsSoundSetting){ + if (receiveFundsSoundSetting != null){ + if (receiveFundsSoundSetting.getValue().equals("")){ + tvReceiveFundsSound.setText("Woohoo"); + } else { + File audioFile = new File(receiveFundsSoundSetting.getValue()); + + tvReceiveFundsSound.setText(audioFile.getName()); + } + } else { + tvReceiveFundsSound.setText("Woohoo"); + } + } + public GeneralSetting getSetting(String name){ for (GeneralSetting generalSetting:this.generalSettingListLiveData.getValue()) { if (generalSetting.getName().equals(name)) { @@ -162,6 +190,15 @@ public class GeneralSettingsFragment extends Fragment { return null; } + + @OnClick(R.id.tvReceiveFundsSoundValue) + void onReceiveFundsSoundSelected(){ + Intent intent3 = new Intent(this.getContext(), AudioPickActivity.class); + intent3.putExtra(IS_NEED_RECORDER, true); + intent3.putExtra(Constant.MAX_NUMBER, 1); + startActivityForResult(intent3, Constant.REQUEST_CODE_PICK_AUDIO); + } + @OnItemSelected(R.id.spTaxableCountry) void onItemSelected(int position) { if (position != 0) { @@ -246,5 +283,32 @@ public class GeneralSettingsFragment extends Fragment { initPreferredCountry(getSetting(GeneralSetting.SETTING_NAME_PREFERRED_COUNTRY)); initPreferredLanguage(getSetting(GeneralSetting.SETTING_NAME_PREFERRED_LANGUAGE)); initDateTimeFormat(getSetting(GeneralSetting.SETTING_NAME_TIME_ZONE)); + initReceiveFundsSound(getSetting(GeneralSetting.SETTING_NAME_RECEIVED_FUNDS_SOUND_PATH)); + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + + if (requestCode == Constant.REQUEST_CODE_PICK_AUDIO){ + if (resultCode == RESULT_OK) { + ArrayList list = data.getParcelableArrayListExtra(Constant.RESULT_PICK_AUDIO); + if (list.size() > 0) { + AudioFile audioSelected = list.get(0); + String audioSelectedPath = audioSelected.getPath(); + + GeneralSetting generalSettingReceivedFundsSoundPath = this.getSetting(GeneralSetting.SETTING_NAME_RECEIVED_FUNDS_SOUND_PATH); + + if (generalSettingReceivedFundsSoundPath == null){ + generalSettingReceivedFundsSoundPath = new GeneralSetting(); + generalSettingReceivedFundsSoundPath.setName(GeneralSetting.SETTING_NAME_RECEIVED_FUNDS_SOUND_PATH); + } + + generalSettingReceivedFundsSoundPath.setValue(audioSelectedPath); + this.generalSettingListViewModel.saveGeneralSettings(generalSettingReceivedFundsSoundPath); + tvReceiveFundsSound.setText(audioSelected.getName()); + } + } + } } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/models/GeneralSetting.java b/app/src/main/java/cy/agorise/crystalwallet/models/GeneralSetting.java index b990e68..62bab19 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/models/GeneralSetting.java +++ b/app/src/main/java/cy/agorise/crystalwallet/models/GeneralSetting.java @@ -20,6 +20,7 @@ public class GeneralSetting { public final static String SETTING_NAME_PREFERRED_LANGUAGE = "PREFERRED_LANGUAGE"; public final static String SETTING_NAME_TIME_ZONE = "TIME_ZONE"; public final static String SETTING_PASSWORD = "PASSWORD"; + public final static String SETTING_NAME_RECEIVED_FUNDS_SOUND_PATH = "RECEIVED_FUNDS_SOUND_PATH"; /** * The id on the database diff --git a/app/src/main/res/layout/fragment_general_settings.xml b/app/src/main/res/layout/fragment_general_settings.xml index 7e30113..c450b7a 100644 --- a/app/src/main/res/layout/fragment_general_settings.xml +++ b/app/src/main/res/layout/fragment_general_settings.xml @@ -127,7 +127,7 @@ app:layout_constraintEnd_toEndOf="@id/vPreferredLanguage"/> - @@ -150,7 +150,7 @@ android:layout_height="1dp" android:layout_marginTop="8dp" android:background="@color/gray" - app:layout_constraintTop_toBottomOf="@id/spSound" + app:layout_constraintTop_toBottomOf="@id/tvReceiveFundsSoundValue" app:layout_constraintStart_toStartOf="@id/vDisplayDateTime" app:layout_constraintEnd_toEndOf="@id/vDisplayDateTime"/> @@ -163,7 +163,7 @@ android:textSize="14sp" android:textStyle="bold" app:layout_constraintTop_toBottomOf="@id/vSound" - app:layout_constraintStart_toStartOf="@id/spSound" /> + app:layout_constraintStart_toStartOf="@id/tvReceiveFundsSoundValue" />