diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsNotificationsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsNotificationsFragment.java index a9abbeebd..098995f91 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsNotificationsFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsNotificationsFragment.java @@ -26,10 +26,14 @@ import android.support.v7.widget.SwitchCompat; 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.CheckBox; import android.widget.CompoundButton; +import android.widget.Spinner; +import android.widget.TextView; import android.widget.TimePicker; import android.widget.Toast; @@ -49,6 +53,9 @@ public class SettingsNotificationsFragment extends Fragment { private Context context; private int style; + + int count = 0; + @Override public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) { @@ -217,6 +224,10 @@ public class SettingsNotificationsFragment extends Fragment { } }); + + final Spinner led_colour_spinner = (Spinner) rootView.findViewById(R.id.led_colour_spinner); + final TextView ledLabel = (TextView) rootView.findViewById(R.id.set_led_colour_label); + switchCompatSilent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { @@ -224,8 +235,55 @@ public class SettingsNotificationsFragment extends Fragment { SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putBoolean(Helper.SET_NOTIF_SILENT, isChecked); editor.apply(); + + if (isChecked) { + ledLabel.setEnabled(true); + led_colour_spinner.setEnabled(true); + } else { + ledLabel.setEnabled(false); + for (View lol : led_colour_spinner.getTouchables()) { + lol.setEnabled(false); + } + } } }); + + if (sharedpreferences.getBoolean(Helper.SET_NOTIF_SILENT, false)) { + + ledLabel.setEnabled(true); + led_colour_spinner.setEnabled(true); + + ArrayAdapter adapterLEDColour = ArrayAdapter.createFromResource(getActivity(), + R.array.led_colours, android.R.layout.simple_spinner_item); + led_colour_spinner.setAdapter(adapterLEDColour); + int positionSpinnerLEDColour = (sharedpreferences.getInt(Helper.SET_LED_COLOUR, Helper.LED_COLOUR)); + led_colour_spinner.setSelection(positionSpinnerLEDColour); + + led_colour_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + if (count > 0) { + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putInt(Helper.SET_LED_COLOUR, position); + editor.apply(); + } else { + count++; + } + } + + @Override + public void onNothingSelected(AdapterView parent) { + } + }); + } + + else { + ledLabel.setEnabled(false); + for (View lol : led_colour_spinner.getTouchables()) { + lol.setEnabled(false); + } + } + if( theme == Helper.THEME_LIGHT) { settings_time_from.setTextColor(ContextCompat.getColor(context, R.color.white)); settings_time_to.setTextColor(ContextCompat.getColor(context, R.color.white)); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java index e937253ac..cf2378028 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java @@ -200,6 +200,7 @@ public class Helper { public static final String SET_PREVIEW_REPLIES = "set_preview_replies"; public static final String SET_PREVIEW_REPLIES_PP = "set_preview_replies_pp"; public static final String SET_TRANSLATOR = "set_translator"; + public static final String SET_LED_COLOUR = "set_led_colour"; public static final int ATTACHMENT_ALWAYS = 1; public static final int ATTACHMENT_WIFI = 2; @@ -210,6 +211,8 @@ public class Helper { public static final int THEME_MENU = 2; public static final int THEME_MENU_TABS = 3; + public static final int LED_COLOUR = 0; + public static final int TRANS_YANDEX = 0; public static final int TRANS_GOOGLE = 1; public static final int TRANS_NONE = 2; @@ -234,7 +237,6 @@ public class Helper { public static final String EP_AUTHORIZE = "/oauth/authorize"; - //Refresh job //Refresh job public static final int MINUTES_BETWEEN_NOTIFICATIONS_REFRESH = 15; public static final int MINUTES_BETWEEN_HOME_TIMELINE = 30; @@ -599,7 +601,34 @@ public class Helper { String soundUri = ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + context.getPackageName() +"/"; notificationBuilder.setSound(Uri.parse(soundUri + R.raw.boop)); } - notificationBuilder.setLights(Color.BLUE, 500, 1000); + + int ledColour = Color.BLUE; + + switch (sharedpreferences.getInt(Helper.SET_LED_COLOUR, Helper.LED_COLOUR)) { + case 0: // BLUE + ledColour = Color.BLUE; + break; + case 1: // CYAN + ledColour = Color.CYAN; + break; + case 2: // MAGENTA + ledColour = Color.MAGENTA; + break; + case 3: // GREEN + ledColour = Color.GREEN; + break; + case 4: // RED + ledColour = Color.RED; + break; + case 5: // YELLOW + ledColour = Color.YELLOW; + break; + case 6: // WHITE + ledColour = Color.WHITE; + break; + } + + notificationBuilder.setLights(ledColour, 500, 1000); notificationBuilder.setContentTitle(title); notificationBuilder.setLargeIcon(icon); notificationManager.notify(notificationId, notificationBuilder.build()); diff --git a/app/src/main/res/layout/fragment_settings_notifications.xml b/app/src/main/res/layout/fragment_settings_notifications.xml index b33ba6336..0772b7fcd 100644 --- a/app/src/main/res/layout/fragment_settings_notifications.xml +++ b/app/src/main/res/layout/fragment_settings_notifications.xml @@ -173,6 +173,25 @@ android:layout_height="wrap_content" /> + + + + + diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index cffc0e456..bc0d17203 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -335,6 +335,18 @@ Nein + Set LED colour: + + + Blue + Cyan + Magenta + Green + Red + Yellow + White + + Blockiere Nicht mehr blockieren Stummschalten diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 66e3aa8db..0cb7eccaf 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -329,6 +329,19 @@ Google Non + + Set LED colour: + + + Blue + Cyan + Magenta + Green + Red + Yellow + White + + Actualités Notifier lors de nouveaux pouets sur la page d\'accueil Afficher les messages d\'erreur diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5c5cfe75b..bdcebd66d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -336,6 +336,18 @@ No + Set LED colour: + + + Blue + Cyan + Magenta + Green + Red + Yellow + White + + News Notify for new toots on the home timeline Display error messages