From 27353ab67593077ea44ee77846527c4acb70ccdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20D=C3=ADaz?= Date: Sun, 9 Oct 2016 16:35:06 -0400 Subject: [PATCH] Preference to enter custom format --- .../app/widget/SummaryEditTextPreference.java | 55 +++++++++++++++++++ .../feature/rename/RenamePreferences.java | 7 ++- app/src/main/res/values/strings.xml | 6 ++ app/src/main/res/xml/preferences.xml | 9 +++ .../feature/rename/RenameFormatTest.java | 20 ++++--- 5 files changed, 89 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/com/icecream/snorlax/app/widget/SummaryEditTextPreference.java diff --git a/app/src/main/java/com/icecream/snorlax/app/widget/SummaryEditTextPreference.java b/app/src/main/java/com/icecream/snorlax/app/widget/SummaryEditTextPreference.java new file mode 100644 index 0000000..7719a34 --- /dev/null +++ b/app/src/main/java/com/icecream/snorlax/app/widget/SummaryEditTextPreference.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2016. Pedro Diaz + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.icecream.snorlax.app.widget; + +import android.annotation.TargetApi; +import android.content.Context; +import android.os.Build; +import android.support.v7.preference.EditTextPreference; +import android.util.AttributeSet; + +@SuppressWarnings({"unused", "FieldCanBeLocal", "WeakerAccess"}) +public class SummaryEditTextPreference extends EditTextPreference { + + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public SummaryEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + + public SummaryEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + public SummaryEditTextPreference(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public SummaryEditTextPreference(Context context) { + super(context); + } + + @Override + public CharSequence getSummary() { + return getText(); + } + + @Override + public void setText(String text) { + super.setText(text); + setSummary(text); + } +} diff --git a/app/src/main/java/com/icecream/snorlax/module/feature/rename/RenamePreferences.java b/app/src/main/java/com/icecream/snorlax/module/feature/rename/RenamePreferences.java index 4ab7f55..7c6baba 100644 --- a/app/src/main/java/com/icecream/snorlax/module/feature/rename/RenamePreferences.java +++ b/app/src/main/java/com/icecream/snorlax/module/feature/rename/RenamePreferences.java @@ -39,7 +39,12 @@ final class RenamePreferences { } String getFormat() { - return "%IVP.0% %ATT%/%DEF%/%STA% %LVL%"; + mPreferences.reload(); + + return mPreferences.getString( + mResources.getString(R.string.preference_rename_format_enable_key), + mResources.getString(R.string.preference_rename_format_enable_default) + ); } boolean isEnabled() { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e52d8b7..c58c854 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -52,6 +52,12 @@ Show nicknamed pokemon stats Rename your already nicknamed pokemons with their stats + rename_format_key + Edit format + + %IVP.0% %ATT%/%DEF%/%STA% %LVL% + Enter a format + Catch Notifications catch_notification_key Enable catch notifications diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index e388cf3..56f7083 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -41,6 +41,15 @@ android:title="@string/preference_rename_already_enable_title" /> + + +