Fix usage of singular/plural in alert messages

Closes #405
Closes #131
pull/699/head
Alinson S. Xavier 5 years ago
parent fcdb400edf
commit 2e4a82418f

@ -53,7 +53,7 @@ class AboutScreen(
developerCountdown--
if (developerCountdown == 0) {
prefs.isDeveloper = true
activity.showMessage(R.string.you_are_now_a_developer)
activity.showMessage(activity.resources.getString(R.string.you_are_now_a_developer))
}
}
}

@ -38,12 +38,13 @@ import org.isoron.uhabits.inject.*;
public class ConfirmDeleteDialog extends AlertDialog
{
protected ConfirmDeleteDialog(@Provided @ActivityContext Context context,
@NonNull OnConfirmedCallback callback)
@NonNull OnConfirmedCallback callback,
int quantity)
{
super(context);
setTitle(R.string.delete_habits);
Resources res = context.getResources();
setMessage(res.getString(R.string.delete_habits_message));
setTitle(res.getQuantityString(R.plurals.delete_habits_title, quantity));
setMessage(res.getQuantityString(R.plurals.delete_habits_message, quantity));
setButton(BUTTON_POSITIVE,
res.getString(R.string.yes),
(dialog, which) -> callback.onConfirmed()

@ -91,9 +91,8 @@ class ListHabitsScreen
}
override fun onCommandFinished(command: Command) {
val stringId = getExecuteString(command)
if (stringId != null)
activity.showMessage(stringId)
val msg = getExecuteString(command)
if (msg != null) activity.showMessage(msg)
}
fun onResult(requestCode: Int, resultCode: Int, data: Intent?) {
@ -113,7 +112,7 @@ class ListHabitsScreen
inStream.copyTo(tempFile)
onImportData(tempFile) { tempFile.delete() }
} catch (e: IOException) {
activity.showMessage(R.string.could_not_import)
activity.showMessage(activity.resources.getString(R.string.could_not_import))
e.printStackTrace()
}
}
@ -143,8 +142,8 @@ class ListHabitsScreen
dialog.show(activity.supportFragmentManager, "habitType")
}
override fun showDeleteConfirmationScreen(callback: OnConfirmedCallback) {
confirmDeleteDialogFactory.create(callback).show()
override fun showDeleteConfirmationScreen(callback: OnConfirmedCallback, quantity: Int) {
confirmDeleteDialogFactory.create(callback, quantity).show()
}
override fun showEditHabitsScreen(habits: List<Habit>) {
@ -173,7 +172,7 @@ class ListHabitsScreen
}
override fun showMessage(m: ListHabitsBehavior.Message) {
activity.showMessage(when (m) {
activity.showMessage(activity.resources.getString(when (m) {
COULD_NOT_EXPORT -> R.string.could_not_export
IMPORT_SUCCESSFUL -> R.string.habits_imported
IMPORT_FAILED -> R.string.could_not_import
@ -182,7 +181,7 @@ class ListHabitsScreen
FILE_NOT_RECOGNIZED -> R.string.file_not_recognized
SYNC_ENABLED -> R.string.sync_enabled
SYNC_KEY_ALREADY_INSTALLED -> R.string.sync_key_already_installed
})
}))
}
override fun showSendBugReportToDeveloperScreen(log: String) {
@ -217,15 +216,30 @@ class ListHabitsScreen
confirmSyncKeyDialogFactory.create(callback).show()
}
@StringRes
private fun getExecuteString(command: Command): Int? {
private fun getExecuteString(command: Command): String? {
when (command) {
is ArchiveHabitsCommand -> return R.string.toast_habit_archived
is ChangeHabitColorCommand -> return R.string.toast_habit_changed
is CreateHabitCommand -> return R.string.toast_habit_created
is DeleteHabitsCommand -> return R.string.toast_habit_deleted
is EditHabitCommand -> return R.string.toast_habit_changed
is UnarchiveHabitsCommand -> return R.string.toast_habit_unarchived
is ArchiveHabitsCommand -> {
return activity.resources.getQuantityString(R.plurals.toast_habits_archived,
command.selected.size)
}
is ChangeHabitColorCommand -> {
return activity.resources.getQuantityString(R.plurals.toast_habits_changed,
command.selected.size)
}
is CreateHabitCommand -> {
return activity.resources.getString(R.string.toast_habit_created)
}
is DeleteHabitsCommand -> {
return activity.resources.getQuantityString(R.plurals.toast_habits_deleted,
command.selected.size)
}
is EditHabitCommand -> {
return activity.resources.getQuantityString(R.plurals.toast_habits_changed, 1)
}
is UnarchiveHabitsCommand -> {
return activity.resources.getQuantityString(R.plurals.toast_habits_unarchived,
command.selected.size)
}
else -> return null
}
}
@ -234,11 +248,11 @@ class ListHabitsScreen
taskRunner.execute(importTaskFactory.create(file) { result ->
if (result == ImportDataTask.SUCCESS) {
adapter.refresh()
activity.showMessage(R.string.habits_imported)
activity.showMessage(activity.resources.getString(R.string.habits_imported))
} else if (result == ImportDataTask.NOT_RECOGNIZED) {
activity.showMessage(R.string.file_not_recognized)
activity.showMessage(activity.resources.getString(R.string.file_not_recognized))
} else {
activity.showMessage(R.string.could_not_import)
activity.showMessage(activity.resources.getString(R.string.could_not_import))
}
onFinished()
})
@ -247,7 +261,7 @@ class ListHabitsScreen
private fun onExportDB() {
taskRunner.execute(exportDBFactory.create { filename ->
if (filename != null) activity.showSendFileScreen(filename)
else activity.showMessage(R.string.could_not_export)
else activity.showMessage(activity.resources.getString(R.string.could_not_export))
})
}
}

@ -77,7 +77,7 @@ class CheckmarkButtonView(
override fun onClick(v: View) {
if (preferences.isShortToggleEnabled) performToggle()
else showMessage(R.string.long_press_to_toggle)
else showMessage(resources.getString(R.string.long_press_to_toggle))
}
override fun onLongClick(v: View): Boolean {

@ -90,7 +90,7 @@ class NumberButtonView(
override fun onClick(v: View) {
if (preferences.isShortToggleEnabled) onEdit()
else showMessage(R.string.long_press_to_edit)
else showMessage(resources.getString(R.string.long_press_to_edit))
}
override fun onLongClick(v: View): Boolean {

@ -19,6 +19,7 @@
package org.isoron.uhabits.activities.habits.show
import org.isoron.uhabits.*
import org.isoron.uhabits.activities.common.dialogs.*
import org.isoron.uhabits.core.models.*
import org.isoron.uhabits.core.ui.callbacks.*
@ -64,7 +65,7 @@ class ShowHabitScreen(
override fun showMessage(m: ShowHabitMenuBehavior.Message?) {
when (m) {
ShowHabitMenuBehavior.Message.COULD_NOT_EXPORT -> {
activity.showMessage(org.isoron.uhabits.R.string.could_not_export)
activity.showMessage(activity.resources.getString(R.string.could_not_export))
}
}
}
@ -74,7 +75,7 @@ class ShowHabitScreen(
}
override fun showDeleteConfirmationScreen(callback: OnConfirmedCallback) {
confirmDeleteDialogFactory.create(callback).show()
confirmDeleteDialogFactory.create(callback, 1).show()
}
override fun close() {

@ -76,7 +76,7 @@ class SyncActivity : AppCompatActivity(), SyncBehavior.Screen {
private fun copyToClipboard() {
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
clipboard.setPrimaryClip(ClipData.newPlainText("Loop Sync Link", binding.syncLink.text))
showMessage(R.string.copied_to_the_clipboard)
showMessage(resources.getString(R.string.copied_to_the_clipboard))
}
suspend fun generateQR(msg: String): Bitmap = Dispatchers.IO {

@ -78,9 +78,9 @@ fun ViewGroup.buildToolbar(): Toolbar {
return inflater.inflate(R.layout.toolbar, null) as Toolbar
}
fun View.showMessage(@StringRes stringId: Int) {
fun View.showMessage(msg: String) {
try {
val snackbar = Snackbar.make(this, stringId, Snackbar.LENGTH_SHORT)
val snackbar = Snackbar.make(this, msg, Snackbar.LENGTH_SHORT)
val tvId = R.id.snackbar_text
val tv = snackbar.view.findViewById<TextView>(tvId)
tv?.setTextColor(Color.WHITE)
@ -90,8 +90,8 @@ fun View.showMessage(@StringRes stringId: Int) {
}
}
fun Activity.showMessage(@StringRes stringId: Int) {
this.findViewById<View>(android.R.id.content).showMessage(stringId)
fun Activity.showMessage(msg: String) {
this.findViewById<View>(android.R.id.content).showMessage(msg)
}
fun Activity.showSendFileScreen(archiveFilename: String) {
@ -109,7 +109,7 @@ fun Activity.startActivitySafely(intent: Intent) {
try {
startActivity(intent)
} catch (e: ActivityNotFoundException) {
this.showMessage(R.string.activity_not_found)
this.showMessage(resources.getString(R.string.activity_not_found))
}
}

@ -18,8 +18,11 @@
~ with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<resources>
<string name="app_name">Loop Habit Tracker</string>
<resources
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="MissingTranslation">
<string name="app_name" >Loop Habit Tracker</string>
<string name="main_activity_title">Habits</string>
<string name="action_settings">Settings</string>
<string name="edit">Edit</string>
@ -29,10 +32,22 @@
<string name="add_habit">Add habit</string>
<string name="color_picker_default_title">Change color</string>
<string name="toast_habit_created">Habit created</string>
<string name="toast_habit_deleted">Habits deleted</string>
<string name="toast_habit_changed">Habit changed</string>
<string name="toast_habit_archived">Habits archived</string>
<string name="toast_habit_unarchived">Habits unarchived</string>
<plurals name="toast_habits_changed">
<item quantity="one">Habit changed</item>
<item quantity="other">Habits changed</item>
</plurals>
<plurals name="toast_habits_deleted">
<item quantity="one">Habit deleted</item>
<item quantity="other">Habits deleted</item>
</plurals>
<plurals name="toast_habits_archived">
<item quantity="one">Habit archived</item>
<item quantity="other">Habits archived</item>
</plurals>
<plurals name="toast_habits_unarchived">
<item quantity="one">Habit unarchived</item>
<item quantity="other">Habits unarchived</item>
</plurals>
<string name="title_activity_show_habit" translatable="false"/>
<string name="overview">Overview</string>
<string name="habit_strength">Habit strength</string>
@ -79,8 +94,14 @@
<string name="hint_title">Did you know?</string>
<string name="hint_drag">To rearrange the entries, press-and-hold on the name of the habit, then drag it to the correct place.</string>
<string name="hint_landscape">You can see more days by putting your phone in landscape mode.</string>
<string name="delete_habits">Delete Habits</string>
<string name="delete_habits_message">The habits will be permanently deleted. This action cannot be undone.</string>
<plurals name="delete_habits_title">
<item quantity="one">Delete habit?</item>
<item quantity="other">Delete habits?</item>
</plurals>
<plurals name="delete_habits_message">
<item quantity="one">The habit will be permanently deleted. This action cannot be undone.</item>
<item quantity="other">The habits will be permanently deleted. This action cannot be undone.</item>
</plurals>
<string name="habit_not_found">Habit deleted / not found</string>
<string name="weekends">Weekends</string>
<string name="any_weekday">Monday to Friday</string>

@ -106,7 +106,7 @@ public class ListHabitsSelectionMenuBehavior
commandRunner.run(new DeleteHabitsCommand(habitList, selected)
);
adapter.clearSelection();
});
}, selected.size());
}
public void onEditHabits()
@ -137,7 +137,8 @@ public class ListHabitsSelectionMenuBehavior
@NonNull OnColorPickedCallback callback);
void showDeleteConfirmationScreen(
@NonNull OnConfirmedCallback callback);
@NonNull OnConfirmedCallback callback,
int quantity);
void showEditHabitsScreen(@NonNull List<Habit> selected);
}

Loading…
Cancel
Save