Bump org.jlleitschuh.gradle.ktlint from 11.0.0 to 11.4.2

Also run ./gradlew ktlintFormat to follow new format.
This commit is contained in:
Quentin Hibon
2023-07-03 23:40:16 +02:00
parent 7348ddeffa
commit 11ca993a75
138 changed files with 497 additions and 376 deletions

View File

@@ -39,6 +39,7 @@ open class BaseUserInterfaceTest {
private lateinit var prefs: Preferences
private lateinit var fixtures: HabitFixtures
private lateinit var cache: HabitCardListCache
@Before
@Throws(Exception::class)
fun setUp() {

View File

@@ -153,18 +153,22 @@ open class BaseViewTest : BaseAndroidTest() {
var filename = filename
var dir = getSDCardDir("test-screenshots")
if (dir == null) dir = AndroidDirFinder(targetContext).getFilesDir("test-screenshots")
if (dir == null) throw RuntimeException(
"Could not find suitable dir for screenshots"
)
if (dir == null) {
throw RuntimeException(
"Could not find suitable dir for screenshots"
)
}
filename = filename.replace("\\.png$".toRegex(), "$suffix.png")
val absolutePath = String.format("%s/%s", dir.absolutePath, filename)
val parent = File(absolutePath).parentFile
if (!parent.exists() && !parent.mkdirs()) throw RuntimeException(
String.format(
"Could not create dir: %s",
parent.absolutePath
if (!parent.exists() && !parent.mkdirs()) {
throw RuntimeException(
String.format(
"Could not create dir: %s",
parent.absolutePath
)
)
)
}
val out = FileOutputStream(absolutePath)
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out)
return absolutePath

View File

@@ -44,7 +44,7 @@ class ScoreChartTest : BaseViewTest() {
habit = habit,
firstWeekday = prefs.firstWeekdayInt,
spinnerPosition = 0,
theme = LightTheme(),
theme = LightTheme()
)
view = ScoreChart(targetContext).apply {
setScores(state.scores)

View File

@@ -30,6 +30,7 @@ import org.junit.runner.RunWith
@MediumTest
class StreakChartTest : BaseViewTest() {
private lateinit var view: StreakChart
@Before
override fun setUp() {
super.setUp()

View File

@@ -48,7 +48,7 @@ class FrequencyCardViewTest : BaseViewTest() {
FrequencyCardPresenter.buildState(
habit = habit,
firstWeekday = 0,
theme = LightTheme(),
theme = LightTheme()
)
)
measureView(view, 800f, 600f)

View File

@@ -49,7 +49,7 @@ class HistoryCardViewTest : BaseViewTest() {
HistoryCardPresenter.buildState(
habit = habit,
firstWeekday = SUNDAY,
theme = LightTheme(),
theme = LightTheme()
)
)
measureView(view, 800f, 600f)

View File

@@ -51,7 +51,7 @@ class OverviewCardViewTest : BaseViewTest() {
scoreYearDiff = 0.74f,
totalCount = 44,
color = PaletteColor(7),
theme = LightTheme(),
theme = LightTheme()
)
)
measureView(view, 800f, 300f)

View File

@@ -49,7 +49,7 @@ class ScoreCardViewTest : BaseViewTest() {
habit = habit,
firstWeekday = 0,
spinnerPosition = 0,
theme = LightTheme(),
theme = LightTheme()
)
)
measureView(view, 800f, 600f)

View File

@@ -48,7 +48,7 @@ class StreakCardViewTest : BaseViewTest() {
StreakCardState(
bestStreaks = habit.streaks.getBest(10),
color = habit.color,
theme = LightTheme(),
theme = LightTheme()
)
)
measureView(view, 800f, 600f)

View File

@@ -53,7 +53,7 @@ class SubtitleCardViewTest : BaseViewTest() {
isNumerical = false,
question = "Did you meditate this morning?",
reminder = Reminder(8, 30, EVERY_DAY),
theme = LightTheme(),
theme = LightTheme()
)
)
measureView(view, 800f, 200f)

View File

@@ -119,7 +119,7 @@ class ListHabitsRegressionTest : BaseUserInterfaceTest() {
"Wake up early",
"Meditate",
"Read books",
"Track time",
"Track time"
)
}
}

View File

@@ -33,6 +33,7 @@ import java.io.IOException
@MediumTest
class CheckmarkWidgetViewTest : BaseViewTest() {
private lateinit var view: CheckmarkWidgetView
@Before
override fun setUp() {
super.setUp()

View File

@@ -60,7 +60,7 @@ class AndroidCanvas : Canvas {
y1.toDp(),
x2.toDp(),
y2.toDp(),
paint,
paint
)
}
@@ -69,7 +69,7 @@ class AndroidCanvas : Canvas {
text,
x.toDp(),
y.toDp() + 0.6f * mHeight,
textPaint,
textPaint
)
}
@@ -83,7 +83,7 @@ class AndroidCanvas : Canvas {
y: Double,
width: Double,
height: Double,
cornerRadius: Double,
cornerRadius: Double
) {
paint.style = Paint.Style.FILL
innerCanvas.drawRoundRect(
@@ -93,7 +93,7 @@ class AndroidCanvas : Canvas {
(y + height).toDp(),
cornerRadius.toDp(),
cornerRadius.toDp(),
paint,
paint
)
}
@@ -108,7 +108,7 @@ class AndroidCanvas : Canvas {
y.toDp(),
(x + width).toDp(),
(y + height).toDp(),
paint,
paint
)
}
@@ -148,7 +148,7 @@ class AndroidCanvas : Canvas {
centerY: Double,
radius: Double,
startAngle: Double,
swipeAngle: Double,
swipeAngle: Double
) {
paint.style = Paint.Style.FILL
innerCanvas.drawArc(
@@ -159,14 +159,14 @@ class AndroidCanvas : Canvas {
-startAngle.toFloat(),
-swipeAngle.toFloat(),
true,
paint,
paint
)
}
override fun fillCircle(
centerX: Double,
centerY: Double,
radius: Double,
radius: Double
) {
paint.style = Paint.Style.FILL
innerCanvas.drawCircle(centerX.toDp(), centerY.toDp(), radius.toDp(), paint)

View File

@@ -33,7 +33,7 @@ import kotlin.math.max
*/
class AndroidDataView(
context: Context,
attrs: AttributeSet? = null,
attrs: AttributeSet? = null
) : AndroidView<DataView>(context, attrs),
GestureDetector.OnGestureListener,
ValueAnimator.AnimatorUpdateListener {
@@ -60,7 +60,7 @@ class AndroidDataView(
e1: MotionEvent?,
e2: MotionEvent?,
dx: Float,
dy: Float,
dy: Float
): Boolean {
if (abs(dx) > abs(dy)) {
val parent = parent
@@ -82,7 +82,7 @@ class AndroidDataView(
e1: MotionEvent?,
e2: MotionEvent?,
velocityX: Float,
velocityY: Float,
velocityY: Float
): Boolean {
scroller.fling(
scroller.currX,
@@ -140,8 +140,11 @@ class AndroidDataView(
// e.getPointerId.
return false
}
if (isSingleTap) view?.onClick(x / canvas.innerDensity, y / canvas.innerDensity)
else view?.onLongClick(x / canvas.innerDensity, y / canvas.innerDensity)
if (isSingleTap) {
view?.onClick(x / canvas.innerDensity, y / canvas.innerDensity)
} else {
view?.onLongClick(x / canvas.innerDensity, y / canvas.innerDensity)
}
return true
}
}

View File

@@ -47,6 +47,6 @@ fun Color.toInt(): Int {
(255 * this.alpha).roundToInt(),
(255 * this.red).roundToInt(),
(255 * this.green).roundToInt(),
(255 * this.blue).roundToInt(),
(255 * this.blue).roundToInt()
)
}

View File

@@ -24,7 +24,7 @@ import android.util.AttributeSet
open class AndroidView<T : View>(
context: Context,
attrs: AttributeSet? = null,
attrs: AttributeSet? = null
) : android.view.View(context, attrs) {
var view: T? = null

View File

@@ -39,7 +39,7 @@ import org.isoron.uhabits.inject.ActivityScope
class AndroidThemeSwitcher
constructor(
@ActivityContext val context: Context,
preferences: Preferences,
preferences: Preferences
) : ThemeSwitcher(preferences) {
override var currentTheme: Theme = LightTheme()

View File

@@ -27,7 +27,7 @@ import org.isoron.uhabits.utils.startActivitySafely
class AboutScreen(
private val activity: AboutActivity,
private val intents: IntentFactory,
private val prefs: Preferences,
private val prefs: Preferences
) {
private var developerCountdown = 5

View File

@@ -32,7 +32,7 @@ import org.isoron.uhabits.utils.setupToolbar
@SuppressLint("ViewConstructor")
class AboutView(
context: Context,
private val screen: AboutScreen,
private val screen: AboutScreen
) : FrameLayout(context) {
private var binding = AboutBinding.inflate(LayoutInflater.from(context))
@@ -43,7 +43,7 @@ class AboutView(
toolbar = binding.toolbar,
color = PaletteColor(11),
title = resources.getString(R.string.about),
theme = currentTheme(),
theme = currentTheme()
)
val version = resources.getString(R.string.version_n)
binding.tvContributors.setOnClickListener { screen.showCodeContributorsWebsite() }

View File

@@ -48,22 +48,22 @@ class FrequencyPickerDialog(
addBeforeAfterText(
this.getString(R.string.every_x_days),
contentView.everyXDaysContainer,
contentView.everyXDaysContainer
)
addBeforeAfterText(
this.getString(R.string.x_times_per_week),
contentView.xTimesPerWeekContainer,
contentView.xTimesPerWeekContainer
)
addBeforeAfterText(
this.getString(R.string.x_times_per_month),
contentView.xTimesPerMonthContainer,
contentView.xTimesPerMonthContainer
)
addBeforeAfterText(
this.getString(R.string.x_times_per_y_days),
contentView.xTimesPerYDaysContainer,
contentView.xTimesPerYDaysContainer
)
contentView.everyDayRadioButton.setOnClickListener {
@@ -124,7 +124,8 @@ class FrequencyPickerDialog(
val parts = str.split("%d")
for (i in parts.indices) {
container.addView(
TextView(activity).apply { text = parts[i].trim() }, 2 * i + 1,
TextView(activity).apply { text = parts[i].trim() },
2 * i + 1
)
}
}

View File

@@ -69,7 +69,7 @@ class HistoryEditorDialog : AppCompatDialogFragment(), CommandRunner.Listener {
theme = themeSwitcher.currentTheme,
today = DateUtils.getTodayWithOffset().toLocalDate(),
onDateClickedListener = onDateClickedListener ?: object : OnDateClickedListener {},
padding = 10.0,
padding = 10.0
)
dataView = AndroidDataView(requireContext(), null)
dataView.view = chart!!

View File

@@ -181,8 +181,9 @@ class FrequencyChart : ScrollableChart {
rect[0f, 0f, baseSize.toFloat()] = baseSize.toFloat()
rect.offset(prevRect!!.left, prevRect!!.top + baseSize * j)
val i = localeWeekdayList[j] % 7
if (values != null)
if (values != null) {
drawMarker(canvas, rect, values[i], weekDaysInMonth[i])
}
rect.offset(0f, rowHeight)
}
drawFooter(canvas, rect, date)
@@ -196,12 +197,14 @@ class FrequencyChart : ScrollableChart {
rect.centerY() - 0.1f * em,
pText!!
)
if (date[Calendar.MONTH] == 1) canvas.drawText(
dfYear!!.format(time),
rect.centerX(),
rect.centerY() + 0.9f * em,
pText!!
)
if (date[Calendar.MONTH] == 1) {
canvas.drawText(
dfYear!!.format(time),
rect.centerX(),
rect.centerY() + 0.9f * em,
pText!!
)
}
}
private fun drawGrid(canvas: Canvas, rGrid: RectF?) {

View File

@@ -148,8 +148,12 @@ class RingView : View {
pRing!!.color = inactiveColor!!
activeCanvas.drawArc(rect!!, angle - 90, 360 - angle, true, pRing!!)
if (thickness > 0) {
if (isTransparencyEnabled) pRing!!.xfermode = XFERMODE_CLEAR else pRing!!.color =
backgroundColor!!
if (isTransparencyEnabled) {
pRing!!.xfermode = XFERMODE_CLEAR
} else {
pRing!!.color =
backgroundColor!!
}
rect!!.inset(thickness, thickness)
activeCanvas.drawArc(rect!!, 0f, 360f, true, pRing!!)
pRing!!.xfermode = null

View File

@@ -94,7 +94,7 @@ class ListHabitsRootView @Inject constructor(
title = resources.getString(R.string.main_activity_title),
color = PaletteColor(17),
displayHomeAsUpEnabled = false,
theme = currentTheme(),
theme = currentTheme()
)
addView(rootView, MATCH_PARENT, MATCH_PARENT)
listAdapter.setListView(listView)

View File

@@ -96,7 +96,7 @@ class ListHabitsScreen
private val colorPickerFactory: ColorPickerDialogFactory,
private val behavior: Lazy<ListHabitsBehavior>,
private val preferences: Preferences,
private val rootView: Lazy<ListHabitsRootView>,
private val rootView: Lazy<ListHabitsRootView>
) : CommandRunner.Listener,
ListHabitsBehavior.Screen,
ListHabitsMenuBehavior.Screen,
@@ -321,8 +321,11 @@ class ListHabitsScreen
private fun onExportDB() {
taskRunner.execute(
exportDBFactory.create { filename ->
if (filename != null) activity.showSendFileScreen(filename)
else activity.showMessage(activity.resources.getString(R.string.could_not_export))
if (filename != null) {
activity.showSendFileScreen(filename)
} else {
activity.showMessage(activity.resources.getString(R.string.could_not_export))
}
}
)
}

View File

@@ -60,8 +60,11 @@ abstract class ButtonPanelView<T : View>(
repeat(buttonCount) { buttons.add(createButton()) }
removeAllViews()
if (reverse) buttons.reversed().forEach { addView(it) }
else buttons.forEach { addView(it) }
if (reverse) {
buttons.reversed().forEach { addView(it) }
} else {
buttons.forEach { addView(it) }
}
setupButtons()
requestLayout()
}

View File

@@ -100,13 +100,19 @@ class CheckmarkButtonView(
}
override fun onClick(v: View) {
if (preferences.isShortToggleEnabled) performToggle()
else onEdit()
if (preferences.isShortToggleEnabled) {
performToggle()
} else {
onEdit()
}
}
override fun onLongClick(v: View): Boolean {
if (preferences.isShortToggleEnabled) onEdit()
else performToggle()
if (preferences.isShortToggleEnabled) {
onEdit()
} else {
performToggle()
}
return true
}
@@ -140,8 +146,11 @@ class CheckmarkButtonView(
paint.color = when (value) {
YES_MANUAL, YES_AUTO, SKIP -> color
NO -> {
if (preferences.areQuestionMarksEnabled) mediumContrastColor
else lowContrastColor
if (preferences.areQuestionMarksEnabled) {
mediumContrastColor
} else {
lowContrastColor
}
}
else -> lowContrastColor
}
@@ -149,8 +158,11 @@ class CheckmarkButtonView(
SKIP -> R.string.fa_skipped
NO -> R.string.fa_times
UNKNOWN -> {
if (preferences.areQuestionMarksEnabled) R.string.fa_question
else R.string.fa_times
if (preferences.areQuestionMarksEnabled) {
R.string.fa_question
} else {
R.string.fa_times
}
}
else -> R.string.fa_check
}

View File

@@ -156,10 +156,11 @@ class HabitCardListController @Inject constructor(
}
private fun notifyListener() {
if (activeMode is SelectionMode)
if (activeMode is SelectionMode) {
selectionMenu.get().onSelectionChange()
else
} else {
selectionMenu.get().onSelectionFinish()
}
}
}
}

View File

@@ -225,7 +225,6 @@ class HabitCardView(
}
private fun copyAttributesFrom(h: Habit) {
fun getActiveColor(habit: Habit): Int {
return when (habit.isArchived) {
true -> sres.getColor(R.attr.contrast60)
@@ -271,7 +270,6 @@ class HabitCardView(
}
private fun updateBackground(isSelected: Boolean) {
val background = when (isSelected) {
true -> R.drawable.selected_box
false -> R.drawable.ripple

View File

@@ -124,15 +124,20 @@ class HeaderView(
rect.set(0f, 0f, width, height)
rect.offset(canvas.width.toFloat() - dp(3.0f), 0f)
if (isReversed) rect.offset(-(index + 1) * width, 0f)
else rect.offset((index - buttonCount) * width, 0f)
if (isReversed) {
rect.offset(-(index + 1) * width, 0f)
} else {
rect.offset((index - buttonCount) * width, 0f)
}
if (isRTL()) rect.set(
canvas.width - rect.right,
rect.top,
canvas.width - rect.left,
rect.bottom
)
if (isRTL()) {
rect.set(
canvas.width - rect.right,
rect.top,
canvas.width - rect.left,
rect.bottom
)
}
val y1 = rect.centerY() - 0.25 * em
val y2 = rect.centerY() + 1.25 * em

View File

@@ -88,7 +88,7 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
habit = habit,
habitList = habitList,
preferences = preferences,
screen = screen,
screen = screen
)
view = ShowHabitView(this)
@@ -99,13 +99,13 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
habitList = habitList,
screen = screen,
system = HabitsDirFinder(AndroidDirFinder(this)),
taskRunner = appComponent.taskRunner,
taskRunner = appComponent.taskRunner
)
menu = ShowHabitMenu(
activity = this,
presenter = menuPresenter,
preferences = preferences,
preferences = preferences
)
view.setListener(presenter)
@@ -150,7 +150,7 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
ShowHabitPresenter.buildState(
habit = habit,
preferences = preferences,
theme = themeSwitcher.currentTheme,
theme = themeSwitcher.currentTheme
)
)
}

View File

@@ -28,7 +28,7 @@ import org.isoron.uhabits.core.ui.screens.habits.show.ShowHabitMenuPresenter
class ShowHabitMenu(
val activity: ShowHabitActivity,
val presenter: ShowHabitMenuPresenter,
val preferences: Preferences,
val preferences: Preferences
) {
fun onCreateOptionsMenu(menu: Menu): Boolean {
activity.menuInflater.inflate(R.menu.show_habit, menu)

View File

@@ -39,7 +39,7 @@ class ShowHabitView(context: Context) : FrameLayout(context) {
binding.toolbar,
title = data.title,
color = data.color,
theme = data.theme,
theme = data.theme
)
binding.subtitleCard.setState(data.subtitle)
binding.overviewCard.setState(data.overview)

View File

@@ -63,7 +63,7 @@ class BarCardView(context: Context, attrs: AttributeSet) : LinearLayout(context,
parent: AdapterView<*>?,
view: View?,
position: Int,
id: Long,
id: Long
) {
presenter.onBoolSpinnerPosition(position)
}
@@ -77,7 +77,7 @@ class BarCardView(context: Context, attrs: AttributeSet) : LinearLayout(context,
parent: AdapterView<*>?,
view: View?,
position: Int,
id: Long,
id: Long
) {
presenter.onNumericalSpinnerPosition(position)
}

View File

@@ -45,7 +45,7 @@ class HistoryCardView(context: Context, attrs: AttributeSet) : LinearLayout(cont
series = state.series,
defaultSquare = state.defaultSquare,
notesIndicators = state.notesIndicators,
firstWeekday = state.firstWeekday,
firstWeekday = state.firstWeekday
)
binding.chart.postInvalidate()
}

View File

@@ -52,7 +52,7 @@ class SubtitleCardView(context: Context, attrs: AttributeSet) : LinearLayout(con
binding.frequencyLabel.text = formatFrequency(
state.frequency.numerator,
state.frequency.denominator,
resources,
resources
)
binding.questionLabel.setTextColor(color)
binding.questionLabel.text = state.question

View File

@@ -40,7 +40,7 @@ class SettingsActivity : AppCompatActivity() {
toolbar = binding.toolbar,
title = resources.getString(R.string.settings),
color = PaletteColor(11),
theme = themeSwitcher.currentTheme,
theme = themeSwitcher.currentTheme
)
setContentView(binding.root)
}

View File

@@ -32,7 +32,7 @@ class EditSettingActivity : AppCompatActivity() {
val habits = app.component.habitList.getFiltered(
HabitMatcher(
isArchivedAllowed = false,
isCompletedAllowed = true,
isCompletedAllowed = true
)
)
AndroidThemeSwitcher(this, app.component.preferences).apply()
@@ -43,7 +43,7 @@ class EditSettingActivity : AppCompatActivity() {
context = this,
habitList = app.component.habitList,
onSave = controller::onSave,
args = args,
args = args
)
setContentView(view)
}

View File

@@ -54,7 +54,7 @@ class EditSettingRootView(
title = resources.getString(R.string.app_name),
color = PaletteColor(11),
displayHomeAsUpEnabled = false,
theme = currentTheme(),
theme = currentTheme()
)
populateHabitSpinner()
binding.habitSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
@@ -69,7 +69,7 @@ class EditSettingRootView(
val habit = habitList.getByPosition(binding.habitSpinner.selectedItemPosition)
val action = mapSpinnerPositionToAction(
isNumerical = habit.isNumerical,
itemPosition = binding.actionSpinner.selectedItemPosition,
itemPosition = binding.actionSpinner.selectedItemPosition
)
onSave(habit, action)
}

View File

@@ -27,22 +27,34 @@ class AndroidCursor(private val cursor: android.database.Cursor) : Cursor {
override fun moveToNext() = cursor.moveToNext()
override fun getInt(index: Int): Int? {
return if (cursor.isNull(index)) null
else cursor.getInt(index)
return if (cursor.isNull(index)) {
null
} else {
cursor.getInt(index)
}
}
override fun getLong(index: Int): Long? {
return if (cursor.isNull(index)) null
else cursor.getLong(index)
return if (cursor.isNull(index)) {
null
} else {
cursor.getLong(index)
}
}
override fun getDouble(index: Int): Double? {
return if (cursor.isNull(index)) null
else cursor.getDouble(index)
return if (cursor.isNull(index)) {
null
} else {
cursor.getDouble(index)
}
}
override fun getString(index: Int): String? {
return if (cursor.isNull(index)) null
else cursor.getString(index)
return if (cursor.isNull(index)) {
null
} else {
cursor.getString(index)
}
}
}

View File

@@ -26,7 +26,7 @@ import java.io.File
class AndroidDatabase(
private val db: SQLiteDatabase,
override val file: File?,
override val file: File?
) : Database {
override fun beginTransaction() = db.beginTransaction()
@@ -45,7 +45,7 @@ class AndroidDatabase(
tableName: String,
values: Map<String, Any?>,
where: String,
vararg params: String,
vararg params: String
): Int {
val contValues = mapToContentValues(values)
return db.update(tableName, contValues, where, params)
@@ -59,7 +59,7 @@ class AndroidDatabase(
override fun delete(
tableName: String,
where: String,
vararg params: String,
vararg params: String
) {
db.delete(tableName, where, params)
}

View File

@@ -30,7 +30,7 @@ class AndroidDatabaseOpener @Inject constructor() : DatabaseOpener {
db = SQLiteDatabase.openDatabase(
file.absolutePath,
null,
SQLiteDatabase.OPEN_READWRITE,
SQLiteDatabase.OPEN_READWRITE
),
file = file
)

View File

@@ -25,5 +25,6 @@ import dagger.Provides
@Module
class ActivityContextModule(
@get:Provides
@get:ActivityContext val context: Context
@get:ActivityContext
val context: Context
)

View File

@@ -26,5 +26,6 @@ import dagger.Provides
class AppContextModule(
@get:Provides
@get:AppContext
@param:AppContext val context: Context
@param:AppContext
val context: Context
)

View File

@@ -53,8 +53,9 @@ class IntentParser
var timestamp = intent.getLongExtra("timestamp", today)
timestamp = DateUtils.getStartOfDay(timestamp)
if (timestamp < 0 || timestamp > today)
if (timestamp < 0 || timestamp > today) {
throw IllegalArgumentException("timestamp is not valid")
}
return Timestamp(timestamp)
}

View File

@@ -96,7 +96,6 @@ class AndroidNotificationTray
timestamp: Timestamp,
disableSound: Boolean = false
): Notification {
val addRepetitionAction = Action(
R.drawable.ic_action_check,
context.getString(R.string.yes),
@@ -146,8 +145,9 @@ class AndroidNotificationTray
.addAction(removeRepetitionAction)
}
if (!disableSound)
if (!disableSound) {
builder.setSound(ringtoneManager.getURI())
}
if (SDK_INT < Build.VERSION_CODES.S) {
val snoozeAction = Action(

View File

@@ -61,8 +61,9 @@ class RingtoneManager
"pref_ringtone_uri",
defaultRingtoneUri.toString()
)!!
if (prefRingtoneUri.isNotEmpty())
if (prefRingtoneUri.isNotEmpty()) {
ringtoneUri = Uri.parse(prefRingtoneUri)
}
return ringtoneUri
}

View File

@@ -103,7 +103,9 @@ class SnoozeDelayPickerActivity : FragmentActivity(), OnItemClickListener {
if (snoozeValues[position] >= 0) {
reminderController!!.onSnoozeDelayPicked(habit!!, snoozeValues[position])
finish()
} else showTimePicker()
} else {
showTimePicker()
}
}
override fun finish() {

View File

@@ -27,7 +27,7 @@ import javax.inject.Inject
class ExportDBTaskFactory
@Inject constructor(
@AppContext private val context: Context,
private val system: AndroidDirFinder,
private val system: AndroidDirFinder
) {
fun create(listener: ExportDBTask.Listener) = ExportDBTask(context, system, listener)
}

View File

@@ -27,7 +27,7 @@ import javax.inject.Inject
class ImportDataTaskFactory
@Inject constructor(
private val importer: GenericImporter,
private val modelFactory: ModelFactory,
private val modelFactory: ModelFactory
) {
fun create(file: File, listener: ImportDataTask.Listener) =
ImportDataTask(importer, modelFactory, file, listener)

View File

@@ -24,6 +24,7 @@ import org.jetbrains.annotations.Contract
object AttributeSetUtils {
const val ISORON_NAMESPACE = "http://isoron.org/android"
@JvmStatic
fun getAttribute(
context: Context,

View File

@@ -33,6 +33,7 @@ import java.text.SimpleDateFormat
object DatabaseUtils {
private var opener: HabitsDatabaseOpener? = null
@JvmStatic
fun getDatabaseFile(context: Context): File {
val databaseFilename = databaseFilename

View File

@@ -61,7 +61,6 @@ fun RelativeLayout.addBelow(
height: Int = WRAP_CONTENT,
applyCustomRules: (params: RelativeLayout.LayoutParams) -> Unit = {}
) {
view.layoutParams = RelativeLayout.LayoutParams(width, height).apply {
addRule(BELOW, subject.id)
applyCustomRules(this)
@@ -75,7 +74,6 @@ fun RelativeLayout.addAtBottom(
width: Int = MATCH_PARENT,
height: Int = WRAP_CONTENT
) {
view.layoutParams = RelativeLayout.LayoutParams(width, height).apply {
addRule(ALIGN_PARENT_BOTTOM)
}
@@ -88,7 +86,6 @@ fun RelativeLayout.addAtTop(
width: Int = MATCH_PARENT,
height: Int = WRAP_CONTENT
) {
view.layoutParams = RelativeLayout.LayoutParams(width, height).apply {
addRule(ALIGN_PARENT_TOP)
}
@@ -159,7 +156,7 @@ fun Activity.restartWithFade(cls: Class<*>?) {
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out)
startActivity(Intent(this, cls))
},
500,
500
) // HACK: Let the menu disappear first
}
@@ -168,7 +165,7 @@ fun View.setupToolbar(
title: String,
color: PaletteColor,
theme: Theme,
displayHomeAsUpEnabled: Boolean = true,
displayHomeAsUpEnabled: Boolean = true
) {
toolbar.elevation = InterfaceUtils.dpToPixels(context, 2f)
val res = StyledResources(context)

View File

@@ -147,10 +147,11 @@ abstract class BaseWidget(val context: Context, val id: Int, val stacked: Boolea
protected val preferedBackgroundAlpha: Int
get() {
return if (stacked)
return if (stacked) {
255
else
} else {
prefs.widgetOpacity
}
}
init {

View File

@@ -33,7 +33,7 @@ open class CheckmarkWidget(
context: Context,
widgetId: Int,
protected val habit: Habit,
stacked: Boolean = false,
stacked: Boolean = false
) : BaseWidget(context, widgetId, stacked) {
override val defaultHeight: Int = 125

View File

@@ -23,7 +23,10 @@ import android.content.Context
class CheckmarkWidgetProvider : BaseWidgetProvider() {
override fun getWidgetFromId(context: Context, id: Int): BaseWidget {
val habits = getHabitsFromWidgetId(id)
return if (habits.size == 1) CheckmarkWidget(context, id, habits[0])
else StackWidget(context, id, StackWidgetType.CHECKMARK, habits)
return if (habits.size == 1) {
CheckmarkWidget(context, id, habits[0])
} else {
StackWidget(context, id, StackWidgetType.CHECKMARK, habits)
}
}
}

View File

@@ -27,7 +27,7 @@ import org.isoron.uhabits.widgets.views.EmptyWidgetView
class EmptyWidget(
context: Context,
widgetId: Int,
stacked: Boolean = false,
stacked: Boolean = false
) : BaseWidget(context, widgetId, stacked) {
override val defaultHeight: Int = 200
override val defaultWidth: Int = 200

View File

@@ -33,7 +33,7 @@ class FrequencyWidget(
widgetId: Int,
private val habit: Habit,
private val firstWeekday: Int,
stacked: Boolean = false,
stacked: Boolean = false
) : BaseWidget(context, widgetId, stacked) {
override val defaultHeight: Int = 200
override val defaultWidth: Int = 200

View File

@@ -24,12 +24,15 @@ import android.content.Context
class FrequencyWidgetProvider : BaseWidgetProvider() {
override fun getWidgetFromId(context: Context, id: Int): BaseWidget {
val habits = getHabitsFromWidgetId(id)
return if (habits.size == 1) FrequencyWidget(
context,
id,
habits[0],
preferences.firstWeekdayInt
)
else StackWidget(context, id, StackWidgetType.FREQUENCY, habits)
return if (habits.size == 1) {
FrequencyWidget(
context,
id,
habits[0],
preferences.firstWeekdayInt
)
} else {
StackWidget(context, id, StackWidgetType.FREQUENCY, habits)
}
}
}

View File

@@ -36,7 +36,7 @@ class HistoryWidget(
context: Context,
id: Int,
private val habit: Habit,
stacked: Boolean = false,
stacked: Boolean = false
) : BaseWidget(context, id, stacked) {
override val defaultHeight: Int = 250
@@ -53,7 +53,7 @@ class HistoryWidget(
val model = HistoryCardPresenter.buildState(
habit = habit,
firstWeekday = prefs.firstWeekday,
theme = WidgetTheme(),
theme = WidgetTheme()
)
(widgetView.dataView as AndroidDataView).apply {
val historyChart = (this.view as HistoryChart)
@@ -75,7 +75,7 @@ class HistoryWidget(
firstWeekday = prefs.firstWeekday,
series = listOf(),
defaultSquare = HistoryChart.Square.OFF,
notesIndicators = listOf(),
notesIndicators = listOf()
)
}
).apply {

View File

@@ -23,11 +23,14 @@ import android.content.Context
class HistoryWidgetProvider : BaseWidgetProvider() {
override fun getWidgetFromId(context: Context, id: Int): BaseWidget {
val habits = getHabitsFromWidgetId(id)
return if (habits.size == 1) HistoryWidget(
context,
id,
habits[0]
)
else StackWidget(context, id, StackWidgetType.HISTORY, habits)
return if (habits.size == 1) {
HistoryWidget(
context,
id,
habits[0]
)
} else {
StackWidget(context, id, StackWidgetType.HISTORY, habits)
}
}
}

View File

@@ -33,7 +33,7 @@ class ScoreWidget(
context: Context,
id: Int,
private val habit: Habit,
stacked: Boolean = false,
stacked: Boolean = false
) : BaseWidget(context, id, stacked) {
override val defaultHeight: Int = 300
override val defaultWidth: Int = 300
@@ -46,7 +46,7 @@ class ScoreWidget(
habit = habit,
firstWeekday = prefs.firstWeekdayInt,
spinnerPosition = prefs.scoreCardSpinnerPosition,
theme = WidgetTheme(),
theme = WidgetTheme()
)
val widgetView = view as GraphWidgetView
widgetView.setBackgroundAlpha(preferedBackgroundAlpha)

View File

@@ -23,7 +23,10 @@ import android.content.Context
class ScoreWidgetProvider : BaseWidgetProvider() {
override fun getWidgetFromId(context: Context, id: Int): BaseWidget {
val habits = getHabitsFromWidgetId(id)
return if (habits.size == 1) ScoreWidget(context, id, habits[0])
else StackWidget(context, id, StackWidgetType.SCORE, habits)
return if (habits.size == 1) {
ScoreWidget(context, id, habits[0])
} else {
StackWidget(context, id, StackWidgetType.SCORE, habits)
}
}
}

View File

@@ -34,7 +34,7 @@ class StackWidget(
widgetId: Int,
private val widgetType: StackWidgetType,
private val habits: List<Habit>,
stacked: Boolean = true,
stacked: Boolean = true
) : BaseWidget(context, widgetId, stacked) {
override val defaultHeight: Int = 0
override val defaultWidth: Int = 0

View File

@@ -34,7 +34,7 @@ class StreakWidget(
context: Context,
id: Int,
private val habit: Habit,
stacked: Boolean = false,
stacked: Boolean = false
) : BaseWidget(context, id, stacked) {
override val defaultHeight: Int = 200
override val defaultWidth: Int = 200

View File

@@ -23,7 +23,10 @@ import android.content.Context
class StreakWidgetProvider : BaseWidgetProvider() {
override fun getWidgetFromId(context: Context, id: Int): BaseWidget {
val habits = getHabitsFromWidgetId(id)
return if (habits.size == 1) StreakWidget(context, id, habits[0])
else StackWidget(context, id, StackWidgetType.STREAKS, habits)
return if (habits.size == 1) {
StreakWidget(context, id, habits[0])
} else {
StackWidget(context, id, StackWidgetType.STREAKS, habits)
}
}
}

View File

@@ -37,7 +37,7 @@ class TargetWidget(
context: Context,
id: Int,
private val habit: Habit,
stacked: Boolean = false,
stacked: Boolean = false
) : BaseWidget(context, id, stacked) {
override val defaultHeight: Int = 200
override val defaultWidth: Int = 200
@@ -53,7 +53,7 @@ class TargetWidget(
val data = TargetCardPresenter.buildState(
habit = habit,
firstWeekday = prefs.firstWeekdayInt,
theme = WidgetTheme(),
theme = WidgetTheme()
)
chart.setColor(WidgetTheme().color(habit.color).toInt())
chart.setTargets(data.targets)

View File

@@ -23,7 +23,10 @@ import android.content.Context
class TargetWidgetProvider : BaseWidgetProvider() {
override fun getWidgetFromId(context: Context, id: Int): BaseWidget {
val habits = getHabitsFromWidgetId(id)
return if (habits.size == 1) TargetWidget(context, id, habits[0])
else StackWidget(context, id, StackWidgetType.TARGET, habits)
return if (habits.size == 1) {
TargetWidget(context, id, habits[0])
} else {
StackWidget(context, id, StackWidgetType.TARGET, habits)
}
}
}

View File

@@ -96,21 +96,23 @@ class CheckmarkWidgetView : HabitWidgetView {
private val text: String
get() = if (isNumerical) {
(max(0, entryValue) / 1000.0).toShortString()
} else when (entryState) {
YES_MANUAL, YES_AUTO -> resources.getString(R.string.fa_check)
SKIP -> resources.getString(R.string.fa_skipped)
UNKNOWN -> {
run {
if (preferences!!.areQuestionMarksEnabled) {
return resources.getString(R.string.fa_question)
} else {
resources.getString(R.string.fa_times)
} else {
when (entryState) {
YES_MANUAL, YES_AUTO -> resources.getString(R.string.fa_check)
SKIP -> resources.getString(R.string.fa_skipped)
UNKNOWN -> {
run {
if (preferences!!.areQuestionMarksEnabled) {
return resources.getString(R.string.fa_question)
} else {
resources.getString(R.string.fa_times)
}
}
resources.getString(R.string.fa_times)
}
resources.getString(R.string.fa_times)
NO -> resources.getString(R.string.fa_times)
else -> resources.getString(R.string.fa_times)
}
NO -> resources.getString(R.string.fa_times)
else -> resources.getString(R.string.fa_times)
}
override val innerLayoutId: Int