diff --git a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/NotificationSettings.java b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/NotificationSettings.java index 3145cab..90d1704 100644 --- a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/NotificationSettings.java +++ b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/NotificationSettings.java @@ -1,11 +1,13 @@ package com.blackforestbytes.simplecloudnotifier.model; import android.graphics.Color; +import android.net.Uri; public class NotificationSettings { public boolean EnableSound = false; - public String SoundSource = ""; + public String SoundName = ""; + public String SoundSource = Uri.EMPTY.toString(); public boolean RepeatSound = false; public boolean EnableLED = false; diff --git a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/SCNSettings.java b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/SCNSettings.java index e319d65..5143482 100644 --- a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/SCNSettings.java +++ b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/SCNSettings.java @@ -51,27 +51,29 @@ public class SCNSettings { SharedPreferences sharedPref = SCNApp.getContext().getSharedPreferences("Config", Context.MODE_PRIVATE); - quota_curr = sharedPref.getInt("quota_curr", 0); - quota_max = sharedPref.getInt("quota_max", 0); - user_id = sharedPref.getInt("user_id", -1); - user_key = sharedPref.getString("user_key", ""); - fcm_token_local = sharedPref.getString("fcm_token_local", ""); + quota_curr = sharedPref.getInt( "quota_curr", 0); + quota_max = sharedPref.getInt( "quota_max", 0); + user_id = sharedPref.getInt( "user_id", -1); + user_key = sharedPref.getString("user_key", ""); + fcm_token_local = sharedPref.getString("fcm_token_local", ""); fcm_token_server = sharedPref.getString("fcm_token_server", ""); Enabled = sharedPref.getBoolean("app_enabled", Enabled); LocalCacheSize = sharedPref.getInt("local_cache_size", LocalCacheSize); - PriorityLow.EnableLED = sharedPref.getBoolean("priority_low:enabled_led", PriorityLow.EnableLED); - PriorityLow.EnableSound = sharedPref.getBoolean("priority_low:enabled_sound", PriorityLow.EnableSound); - PriorityLow.EnableVibration = sharedPref.getBoolean("priority_low:enabled_vibration", PriorityLow.EnableVibration); - PriorityLow.RepeatSound = sharedPref.getBoolean("priority_low:repeat_sound", PriorityLow.RepeatSound); - PriorityLow.SoundSource = sharedPref.getString( "priority_low:sound_source", PriorityLow.SoundSource); - PriorityLow.LEDColor = sharedPref.getInt( "priority_low:led_color", PriorityLow.LEDColor); + PriorityLow.EnableLED = sharedPref.getBoolean("priority_low:enabled_led", PriorityLow.EnableLED); + PriorityLow.EnableSound = sharedPref.getBoolean("priority_low:enabled_sound", PriorityLow.EnableSound); + PriorityLow.EnableVibration = sharedPref.getBoolean("priority_low:enabled_vibration", PriorityLow.EnableVibration); + PriorityLow.RepeatSound = sharedPref.getBoolean("priority_low:repeat_sound", PriorityLow.RepeatSound); + PriorityLow.SoundName = sharedPref.getString( "priority_low:sound_name", PriorityLow.SoundName); + PriorityLow.SoundSource = sharedPref.getString( "priority_low:sound_source", PriorityLow.SoundSource); + PriorityLow.LEDColor = sharedPref.getInt( "priority_low:led_color", PriorityLow.LEDColor); PriorityNorm.EnableLED = sharedPref.getBoolean("priority_norm:enabled_led", PriorityNorm.EnableLED); PriorityNorm.EnableSound = sharedPref.getBoolean("priority_norm:enabled_sound", PriorityNorm.EnableSound); PriorityNorm.EnableVibration = sharedPref.getBoolean("priority_norm:enabled_vibration", PriorityNorm.EnableVibration); PriorityNorm.RepeatSound = sharedPref.getBoolean("priority_norm:repeat_sound", PriorityNorm.RepeatSound); + PriorityNorm.SoundName = sharedPref.getString( "priority_norm:sound_name", PriorityNorm.SoundName); PriorityNorm.SoundSource = sharedPref.getString( "priority_norm:sound_source", PriorityNorm.SoundSource); PriorityNorm.LEDColor = sharedPref.getInt( "priority_norm:led_color", PriorityNorm.LEDColor); @@ -79,6 +81,7 @@ public class SCNSettings PriorityHigh.EnableSound = sharedPref.getBoolean("priority_high:enabled_sound", PriorityHigh.EnableSound); PriorityHigh.EnableVibration = sharedPref.getBoolean("priority_high:enabled_vibration", PriorityHigh.EnableVibration); PriorityHigh.RepeatSound = sharedPref.getBoolean("priority_high:repeat_sound", PriorityHigh.RepeatSound); + PriorityHigh.SoundName = sharedPref.getString( "priority_high:sound_name", PriorityHigh.SoundName); PriorityHigh.SoundSource = sharedPref.getString( "priority_high:sound_source", PriorityHigh.SoundSource); PriorityHigh.LEDColor = sharedPref.getInt( "priority_high:led_color", PriorityHigh.LEDColor); } @@ -88,22 +91,22 @@ public class SCNSettings SharedPreferences sharedPref = SCNApp.getContext().getSharedPreferences("Config", Context.MODE_PRIVATE); SharedPreferences.Editor e = sharedPref.edit(); - e.putInt( "quota_curr", quota_curr); - e.putInt( "quota_max", quota_max); - e.putInt( "user_id", user_id); - e.putString("user_key", user_key); - e.putString("fcm_token_local", fcm_token_local); - e.putString("fcm_token_server", fcm_token_server); + e.putInt( "quota_curr", quota_curr); + e.putInt( "quota_max", quota_max); + e.putInt( "user_id", user_id); + e.putString( "user_key", user_key); + e.putString( "fcm_token_local", fcm_token_local); + e.putString( "fcm_token_server", fcm_token_server); - e.putBoolean("app_enabled", Enabled); - e.putInt( "local_cache_size", LocalCacheSize); + e.putBoolean("app_enabled", Enabled); + e.putInt( "local_cache_size", LocalCacheSize); - e.putBoolean("priority_low:enabled_led", PriorityLow.EnableLED); - e.putBoolean("priority_low:enabled_sound", PriorityLow.EnableSound); - e.putBoolean("priority_low:enabled_vibration", PriorityLow.EnableVibration); - e.putBoolean("priority_low:repeat_sound", PriorityLow.RepeatSound); - e.putString( "priority_low:sound_source", PriorityLow.SoundSource); - e.putInt( "priority_low:led_color", PriorityLow.LEDColor); + e.putBoolean("priority_low:enabled_led", PriorityLow.EnableLED); + e.putBoolean("priority_low:enabled_sound", PriorityLow.EnableSound); + e.putBoolean("priority_low:enabled_vibration", PriorityLow.EnableVibration); + e.putBoolean("priority_low:repeat_sound", PriorityLow.RepeatSound); + e.putString( "priority_low:sound_source", PriorityLow.SoundSource); + e.putInt( "priority_low:led_color", PriorityLow.LEDColor); e.putBoolean("priority_norm:enabled_led", PriorityNorm.EnableLED); e.putBoolean("priority_norm:enabled_sound", PriorityNorm.EnableSound); diff --git a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/MainActivity.java b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/MainActivity.java index 4a18a04..9836113 100644 --- a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/MainActivity.java +++ b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/MainActivity.java @@ -16,9 +16,8 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import androidx.viewpager.widget.PagerAdapter; import androidx.viewpager.widget.ViewPager; -import xyz.aprildown.ultimatemusicpicker.MusicPickerListener; -public class MainActivity extends AppCompatActivity implements MusicPickerListener +public class MainActivity extends AppCompatActivity { public TabAdapter adpTabs; @@ -54,14 +53,4 @@ public class MainActivity extends AppCompatActivity implements MusicPickerListen CMessageList.inst().fullSave(); } - - @Override - public void onMusicPick(@NotNull Uri uri, @NotNull String s) { - - } - - @Override - public void onPickCanceled() { - - } } diff --git a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/SettingsFragment.java b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/SettingsFragment.java index e8ba65b..1227c58 100644 --- a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/SettingsFragment.java +++ b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/SettingsFragment.java @@ -1,57 +1,65 @@ package com.blackforestbytes.simplecloudnotifier.view; +import android.content.Context; import android.media.AudioManager; +import android.net.Uri; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; +import android.widget.Button; import android.widget.ImageView; import android.widget.Spinner; import android.widget.Switch; import android.widget.TextView; import com.blackforestbytes.simplecloudnotifier.R; -import com.blackforestbytes.simplecloudnotifier.SCNApp; import com.blackforestbytes.simplecloudnotifier.model.SCNSettings; +import org.jetbrains.annotations.NotNull; + import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; +import xyz.aprildown.ultimatemusicpicker.MusicPickerListener; import xyz.aprildown.ultimatemusicpicker.UltimateMusicPicker; -public class SettingsFragment extends Fragment +public class SettingsFragment extends Fragment implements MusicPickerListener { - private Switch prefAppEnabled; - private Spinner prefLocalCacheSize; + private Switch prefAppEnabled; + private Spinner prefLocalCacheSize; + private Button prefUpgradeAccount; private Switch prefMsgLowEnableSound; private TextView tvMsgLowRingtone_value; - private View prevMsgLowRingtone; + private View prefMsgLowRingtone; private Switch prefMsgLowRepeatSound; private Switch prefMsgLowEnableLED; - private TextView tvMsgLowLedColor; - private ImageView prefMsgLowLedColor; + private View prefMsgLowLedColor_container; + private ImageView prefMsgLowLedColor_value; private Switch prefMsgLowEnableVibrations; private Switch prefMsgNormEnableSound; private TextView tvMsgNormRingtone_value; - private View prevMsgNormRingtone; + private View prefMsgNormRingtone; private Switch prefMsgNormRepeatSound; private Switch prefMsgNormEnableLED; - private TextView tvMsgNormLedColor; - private ImageView prefMsgNormLedColor; + private View prefMsgNormLedColor_container; + private ImageView prefMsgNormLedColor_value; private Switch prefMsgNormEnableVibrations; private Switch prefMsgHighEnableSound; private TextView tvMsgHighRingtone_value; - private View prevMsgHighRingtone; + private View prefMsgHighRingtone; private Switch prefMsgHighRepeatSound; private Switch prefMsgHighEnableLED; - private TextView tvMsgHighLedColor; - private ImageView prefMsgHighLedColor; + private View prefMsgHighLedColor_container; + private ImageView prefMsgHighLedColor_value; private Switch prefMsgHighEnableVibrations; + private int musicPickerSwitch = -1; + public SettingsFragment() { // Required empty public constructor @@ -62,70 +70,102 @@ public class SettingsFragment extends Fragment { View v = inflater.inflate(R.layout.fragment_settings, container, false); - { - prefAppEnabled = v.findViewById(R.id.prefAppEnabled); - prefLocalCacheSize = v.findViewById(R.id.prefLocalCacheSize); - - prefMsgLowEnableSound = v.findViewById(R.id.prefMsgLowEnableSound); - tvMsgLowRingtone_value = v.findViewById(R.id.tvMsgLowRingtone_value); - prevMsgLowRingtone = v.findViewById(R.id.prevMsgLowRingtone); - prefMsgLowRepeatSound = v.findViewById(R.id.prefMsgLowRepeatSound); - prefMsgLowEnableLED = v.findViewById(R.id.prefMsgLowEnableLED); - tvMsgLowLedColor = v.findViewById(R.id.tvMsgLowLedColor); - prefMsgLowLedColor = v.findViewById(R.id.prefMsgLowLedColor); - prefMsgLowEnableVibrations = v.findViewById(R.id.prefMsgLowEnableVibrations); - - prefMsgNormEnableSound = v.findViewById(R.id.prefMsgNormEnableSound); - tvMsgNormRingtone_value = v.findViewById(R.id.tvMsgNormRingtone_value); - prevMsgNormRingtone = v.findViewById(R.id.prevMsgNormRingtone); - prefMsgNormRepeatSound = v.findViewById(R.id.prefMsgNormRepeatSound); - prefMsgNormEnableLED = v.findViewById(R.id.prefMsgNormEnableLED); - tvMsgNormLedColor = v.findViewById(R.id.tvMsgNormLedColor); - prefMsgNormLedColor = v.findViewById(R.id.prefMsgNormLedColor); - prefMsgNormEnableVibrations = v.findViewById(R.id.prefMsgNormEnableVibrations); - - prefMsgHighEnableSound = v.findViewById(R.id.prefMsgHighEnableSound); - tvMsgHighRingtone_value = v.findViewById(R.id.tvMsgHighRingtone_value); - prevMsgHighRingtone = v.findViewById(R.id.prevMsgHighRingtone); - prefMsgHighRepeatSound = v.findViewById(R.id.prefMsgHighRepeatSound); - prefMsgHighEnableLED = v.findViewById(R.id.prefMsgHighEnableLED); - tvMsgHighLedColor = v.findViewById(R.id.tvMsgHighLedColor); - prefMsgHighLedColor = v.findViewById(R.id.prefMsgHighLedColor); - prefMsgHighEnableVibrations = v.findViewById(R.id.prefMsgHighEnableVibrations); - } - - { - SCNSettings s = SCNSettings.inst(); - - prefAppEnabled.setChecked(s.Enabled); - prefAppEnabled.setOnCheckedChangeListener((a,b) -> onUpdate()); - - ArrayAdapter plcsa = new ArrayAdapter<>(v.getContext(), android.R.layout.simple_spinner_item, SCNSettings.CHOOSABLE_CACHE_SIZES); - plcsa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - prefLocalCacheSize.setAdapter(plcsa); - prefLocalCacheSize.setSelection(getCacheSizeIndex(s.LocalCacheSize)); - prefLocalCacheSize.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() - { - @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { onUpdate(); } - @Override public void onNothingSelected(AdapterView parent) { onUpdate(); } - }); - - //TODO ... - - prevMsgLowRingtone.setOnClickListener((a) -> chooseRingtoneLow()); - } + initFields(v); + updateUI(); + initListener(); return v; } - private void onUpdate() + private void initFields(View v) + { + prefAppEnabled = v.findViewById(R.id.prefAppEnabled); + prefLocalCacheSize = v.findViewById(R.id.prefLocalCacheSize); + prefUpgradeAccount = v.findViewById(R.id.prefUpgradeAccount); + + prefMsgLowEnableSound = v.findViewById(R.id.prefMsgLowEnableSound); + tvMsgLowRingtone_value = v.findViewById(R.id.tvMsgLowRingtone_value); + prefMsgLowRingtone = v.findViewById(R.id.prefMsgLowRingtone); + prefMsgLowRepeatSound = v.findViewById(R.id.prefMsgLowRepeatSound); + prefMsgLowEnableLED = v.findViewById(R.id.prefMsgLowEnableLED); + prefMsgLowLedColor_value = v.findViewById(R.id.prefMsgLowLedColor_value); + prefMsgLowLedColor_container = v.findViewById(R.id.prefMsgLowLedColor_container); + prefMsgLowEnableVibrations = v.findViewById(R.id.prefMsgLowEnableVibrations); + + prefMsgNormEnableSound = v.findViewById(R.id.prefMsgNormEnableSound); + tvMsgNormRingtone_value = v.findViewById(R.id.tvMsgNormRingtone_value); + prefMsgNormRingtone = v.findViewById(R.id.prefMsgNormRingtone); + prefMsgNormRepeatSound = v.findViewById(R.id.prefMsgNormRepeatSound); + prefMsgNormEnableLED = v.findViewById(R.id.prefMsgNormEnableLED); + prefMsgNormLedColor_value = v.findViewById(R.id.prefMsgNormLedColor_value); + prefMsgNormLedColor_container = v.findViewById(R.id.prefMsgNormLedColor_container); + prefMsgNormEnableVibrations = v.findViewById(R.id.prefMsgNormEnableVibrations); + + prefMsgHighEnableSound = v.findViewById(R.id.prefMsgHighEnableSound); + tvMsgHighRingtone_value = v.findViewById(R.id.tvMsgHighRingtone_value); + prefMsgHighRingtone = v.findViewById(R.id.prefMsgHighRingtone); + prefMsgHighRepeatSound = v.findViewById(R.id.prefMsgHighRepeatSound); + prefMsgHighEnableLED = v.findViewById(R.id.prefMsgHighEnableLED); + prefMsgHighLedColor_value = v.findViewById(R.id.prefMsgHighLedColor_value); + prefMsgHighLedColor_container = v.findViewById(R.id.prefMsgHighLedColor_container); + prefMsgHighEnableVibrations = v.findViewById(R.id.prefMsgHighEnableVibrations); + } + + private void updateUI() + { + SCNSettings s = SCNSettings.inst(); + Context c = getContext(); + if (c == null) return; + + prefAppEnabled.setChecked(s.Enabled); + + ArrayAdapter plcsa = new ArrayAdapter<>(c, android.R.layout.simple_spinner_item, SCNSettings.CHOOSABLE_CACHE_SIZES); + plcsa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + prefLocalCacheSize.setAdapter(plcsa); + prefLocalCacheSize.setSelection(getCacheSizeIndex(s.LocalCacheSize)); + + prefMsgLowEnableSound.setChecked(s.PriorityLow.EnableSound); + tvMsgLowRingtone_value.setText(s.PriorityLow.SoundName); + prefMsgLowRepeatSound.setChecked(s.PriorityLow.RepeatSound); + prefMsgLowEnableLED.setChecked(s.PriorityLow.EnableLED); + prefMsgLowLedColor_value.setColorFilter(s.PriorityLow.LEDColor); + prefMsgLowEnableVibrations.setChecked(s.PriorityLow.EnableVibration); + } + + private void initListener() { SCNSettings s = SCNSettings.inst(); - s.Enabled = prefAppEnabled.isChecked(); - s.LocalCacheSize = prefLocalCacheSize.getSelectedItemPosition()>=0 ? SCNSettings.CHOOSABLE_CACHE_SIZES[prefLocalCacheSize.getSelectedItemPosition()] : 100; + prefAppEnabled.setOnCheckedChangeListener((a,b) -> { s.Enabled=b; saveAndUpdate(); }); - s.save(); + prefLocalCacheSize.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() + { + @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { + s.LocalCacheSize = prefLocalCacheSize.getSelectedItemPosition()>=0 ? SCNSettings.CHOOSABLE_CACHE_SIZES[prefLocalCacheSize.getSelectedItemPosition()] : 100; + saveAndUpdate(); + } + @Override public void onNothingSelected(AdapterView parent) { /* */ } + }); + + prefUpgradeAccount.setOnClickListener(a -> onUpgradeAccount()); + + prefMsgLowEnableSound.setOnCheckedChangeListener((a,b) -> { s.PriorityLow.EnableSound=b; saveAndUpdate(); }); + prefMsgLowRingtone.setOnClickListener(a -> chooseRingtoneLow()); + prefMsgLowRepeatSound.setOnCheckedChangeListener((a,b) -> { s.PriorityLow.RepeatSound=b; saveAndUpdate(); }); + prefMsgLowEnableLED.setOnCheckedChangeListener((a,b) -> { s.PriorityLow.EnableLED=b; saveAndUpdate(); }); + prefMsgLowLedColor_container.setOnClickListener(a -> chooseLEDColorLow()); + prefMsgLowEnableVibrations.setOnCheckedChangeListener((a,b) -> { s.PriorityLow.EnableVibration=b; saveAndUpdate(); }); + } + + private void saveAndUpdate() + { + SCNSettings.inst().save(); + updateUI(); + } + + private void onUpgradeAccount() + { + //TODO } private int getCacheSizeIndex(int value) @@ -139,14 +179,64 @@ public class SettingsFragment extends Fragment private void chooseRingtoneLow() { + musicPickerSwitch = 1; new UltimateMusicPicker() - .windowTitle("Choose notification sound") - .removeSilent() - .streamType(AudioManager.STREAM_ALARM) - .ringtone() - .notification() - .alarm() - .music() - .goWithDialog(SCNApp.getMainActivity().getSupportFragmentManager()); + .windowTitle("Choose notification sound") + .removeSilent() + .streamType(AudioManager.STREAM_ALARM) + .ringtone() + .notification() + .alarm() + .music() + .goWithDialog(getChildFragmentManager()); + } + + private void chooseRingtoneNorm() + { + musicPickerSwitch = 2; + new UltimateMusicPicker() + .windowTitle("Choose notification sound") + .removeSilent() + .streamType(AudioManager.STREAM_ALARM) + .ringtone() + .notification() + .alarm() + .music() + .goWithDialog(getChildFragmentManager()); + } + + private void chooseRingtoneHigh() + { + musicPickerSwitch = 3; + new UltimateMusicPicker() + .windowTitle("Choose notification sound") + .removeSilent() + .streamType(AudioManager.STREAM_ALARM) + .ringtone() + .notification() + .alarm() + .music() + .goWithDialog(getChildFragmentManager()); + } + + private void chooseLEDColorLow() + { + // + } + + @Override + public void onMusicPick(@NotNull Uri uri, @NotNull String s) + { + if (musicPickerSwitch == 1) { SCNSettings.inst().PriorityLow.SoundSource =uri.toString(); SCNSettings.inst().PriorityLow.SoundName =s; saveAndUpdate(); } + if (musicPickerSwitch == 2) { SCNSettings.inst().PriorityNorm.SoundSource=uri.toString(); SCNSettings.inst().PriorityNorm.SoundName=s; saveAndUpdate(); } + if (musicPickerSwitch == 3) { SCNSettings.inst().PriorityHigh.SoundSource=uri.toString(); SCNSettings.inst().PriorityHigh.SoundName=s; saveAndUpdate(); } + + musicPickerSwitch = -1; + } + + @Override + public void onPickCanceled() + { + musicPickerSwitch = -1; } } \ No newline at end of file diff --git a/android/app/src/main/res/layout/fragment_settings.xml b/android/app/src/main/res/layout/fragment_settings.xml index a876dea..9816b77 100644 --- a/android/app/src/main/res/layout/fragment_settings.xml +++ b/android/app/src/main/res/layout/fragment_settings.xml @@ -26,6 +26,7 @@ @@ -273,7 +275,7 @@ @@ -470,7 +473,7 @@ @@ -667,7 +671,7 @@ #3F51B5 #303F9F #FF4081 - #67809F + #3F51B5 + #FFFFFF #000 diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml index e1d892d..f4d4172 100644 --- a/android/app/src/main/res/values/strings.xml +++ b/android/app/src/main/res/values/strings.xml @@ -27,4 +27,5 @@ Enable notification light Notification light color Enable notification vibration + Upgrade account