mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Make FrequencyPickerDialog translatable
This commit is contained in:
@@ -25,7 +25,9 @@ import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.EditText
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.RadioButton
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatDialogFragment
|
||||
import kotlinx.android.synthetic.main.frequency_picker_dialog.view.*
|
||||
@@ -45,6 +47,21 @@ class FrequencyPickerDialog(
|
||||
val inflater = LayoutInflater.from(activity!!)
|
||||
contentView = inflater.inflate(R.layout.frequency_picker_dialog, null)
|
||||
|
||||
addBeforeAfterText(
|
||||
this.getString(R.string.every_x_days),
|
||||
contentView.everyXDaysContainer,
|
||||
)
|
||||
|
||||
addBeforeAfterText(
|
||||
this.getString(R.string.x_times_per_week),
|
||||
contentView.xTimesPerWeekContainer,
|
||||
)
|
||||
|
||||
addBeforeAfterText(
|
||||
this.getString(R.string.x_times_per_month),
|
||||
contentView.xTimesPerMonthContainer,
|
||||
)
|
||||
|
||||
contentView.everyDayRadioButton.setOnClickListener {
|
||||
check(contentView.everyDayRadioButton)
|
||||
unfocusAll()
|
||||
@@ -84,6 +101,19 @@ class FrequencyPickerDialog(
|
||||
.create()
|
||||
}
|
||||
|
||||
private fun addBeforeAfterText(
|
||||
str: String,
|
||||
container: LinearLayout
|
||||
) {
|
||||
val parts = str.split("%d")
|
||||
container.addView(
|
||||
TextView(activity).apply { text = parts[0].trim() }, 1,
|
||||
)
|
||||
container.addView(
|
||||
TextView(activity).apply { text = parts[1].trim() }, 3,
|
||||
)
|
||||
}
|
||||
|
||||
private fun onSaveClicked() {
|
||||
var numerator = 1
|
||||
var denominator = 1
|
||||
|
||||
@@ -304,14 +304,14 @@ class EditHabitActivity : AppCompatActivity() {
|
||||
freqNum == 1 && freqDen == 7 -> getString(R.string.every_week)
|
||||
freqNum == 1 && freqDen > 1 -> getString(R.string.every_x_days, freqDen)
|
||||
freqDen == 7 -> getString(R.string.x_times_per_week, freqNum)
|
||||
freqDen == 31 -> getString(R.string.x_times_per_month, freqNum)
|
||||
else -> "Unknown"
|
||||
freqDen == 30 || freqDen == 31 -> getString(R.string.x_times_per_month, freqNum)
|
||||
else -> "$freqNum/$freqDen"
|
||||
}
|
||||
binding.numericalFrequencyPicker.text = when (freqDen) {
|
||||
1 -> getString(R.string.every_day)
|
||||
7 -> getString(R.string.every_week)
|
||||
30 -> getString(R.string.every_month)
|
||||
else -> "Unknown"
|
||||
else -> "$freqNum/$freqDen"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@ import org.isoron.uhabits.databinding.ShowHabitSubtitleBinding
|
||||
import org.isoron.uhabits.utils.InterfaceUtils
|
||||
import org.isoron.uhabits.utils.formatTime
|
||||
import org.isoron.uhabits.utils.toThemedAndroidColor
|
||||
import java.util.Locale
|
||||
|
||||
class SubtitleCardView(context: Context, attrs: AttributeSet) : LinearLayout(context, attrs) {
|
||||
|
||||
@@ -99,13 +98,6 @@ class SubtitleCardView(context: Context, attrs: AttributeSet) : LinearLayout(con
|
||||
}
|
||||
return resources.getString(R.string.every_x_days, den)
|
||||
}
|
||||
return String.format(
|
||||
Locale.US,
|
||||
"%d %s %d %s",
|
||||
num,
|
||||
resources.getString(R.string.times_every),
|
||||
den,
|
||||
resources.getString(R.string.days),
|
||||
)
|
||||
return "$num/$den"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/everyXDaysContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:gravity="center_vertical">
|
||||
@@ -54,11 +55,6 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Every" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/everyXDaysTextView"
|
||||
android:layout_width="50dp"
|
||||
@@ -71,14 +67,10 @@
|
||||
android:maxLength="2"
|
||||
android:text="3" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="days" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/xTimesPerWeekContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:gravity="center_vertical">
|
||||
@@ -98,16 +90,13 @@
|
||||
android:layout_marginEnd="8dp"
|
||||
android:inputType="number"
|
||||
android:maxLength="2"
|
||||
android:text="5" />
|
||||
android:text="3" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="times per week" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/xTimesPerMonthContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:gravity="center_vertical">
|
||||
@@ -129,11 +118,6 @@
|
||||
android:maxLength="2"
|
||||
android:text="10" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="times per month" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -53,8 +53,6 @@
|
||||
<string name="habit_strength">Habit strength</string>
|
||||
<string name="history">History</string>
|
||||
<string name="clear">Clear</string>
|
||||
<string name="times_every">times in</string>
|
||||
<string name="days">days</string>
|
||||
<string name="reminder">Reminder</string>
|
||||
<string name="save">Save</string>
|
||||
<string name="streaks">Streaks</string>
|
||||
|
||||
Reference in New Issue
Block a user