mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
@@ -26,8 +26,8 @@ import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.view.View
|
||||
import android.widget.RemoteViews
|
||||
import org.isoron.platform.utils.StringUtils
|
||||
import org.isoron.uhabits.core.models.Habit
|
||||
import org.isoron.uhabits.core.utils.StringUtils
|
||||
|
||||
class StackWidget(
|
||||
context: Context,
|
||||
|
||||
@@ -27,11 +27,11 @@ import android.util.Log
|
||||
import android.widget.RemoteViews
|
||||
import android.widget.RemoteViewsService
|
||||
import android.widget.RemoteViewsService.RemoteViewsFactory
|
||||
import org.isoron.platform.utils.StringUtils.Companion.splitLongs
|
||||
import org.isoron.uhabits.HabitsApplication
|
||||
import org.isoron.uhabits.core.models.Habit
|
||||
import org.isoron.uhabits.core.models.HabitNotFoundException
|
||||
import org.isoron.uhabits.core.preferences.Preferences
|
||||
import org.isoron.uhabits.core.utils.StringUtils.Companion.splitLongs
|
||||
import org.isoron.uhabits.utils.InterfaceUtils.dpToPixels
|
||||
import java.util.ArrayList
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.platform.utils
|
||||
|
||||
class StringUtils {
|
||||
|
||||
companion object {
|
||||
|
||||
fun joinLongs(values: LongArray): String = values.joinToString(separator = ",")
|
||||
|
||||
fun splitLongs(str: String): LongArray = str.split(",").map { it.toLong() }.toLongArray()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.platform.utils
|
||||
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertContentEquals
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class StringUtilsTest {
|
||||
|
||||
@Test
|
||||
fun testJoinLongs() {
|
||||
val string = StringUtils.joinLongs(longArrayOf(0, 1, 2))
|
||||
assertEquals(string, "0,1,2")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSplitLongs() {
|
||||
val longArray = StringUtils.splitLongs("0,1,2")
|
||||
assertContentEquals(longArray, longArrayOf(0, 1, 2))
|
||||
}
|
||||
}
|
||||
@@ -20,8 +20,6 @@ package org.isoron.uhabits.core.models
|
||||
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder
|
||||
import org.isoron.uhabits.core.utils.StringUtils.Companion.defaultToStringStyle
|
||||
import java.util.Arrays
|
||||
|
||||
class WeekdayList {
|
||||
@@ -71,11 +69,7 @@ class WeekdayList {
|
||||
return HashCodeBuilder(17, 37).append(weekdays).toHashCode()
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return ToStringBuilder(this, defaultToStringStyle())
|
||||
.append("weekdays", weekdays)
|
||||
.toString()
|
||||
}
|
||||
override fun toString() = "{weekdays: [${weekdays.joinToString(separator = ",")}]}"
|
||||
|
||||
companion object {
|
||||
val EVERY_DAY = WeekdayList(127)
|
||||
|
||||
@@ -19,12 +19,12 @@
|
||||
package org.isoron.uhabits.core.preferences
|
||||
|
||||
import org.isoron.platform.time.DayOfWeek
|
||||
import org.isoron.platform.utils.StringUtils.Companion.joinLongs
|
||||
import org.isoron.platform.utils.StringUtils.Companion.splitLongs
|
||||
import org.isoron.uhabits.core.models.HabitList
|
||||
import org.isoron.uhabits.core.models.Timestamp
|
||||
import org.isoron.uhabits.core.ui.ThemeSwitcher
|
||||
import org.isoron.uhabits.core.utils.DateUtils.Companion.getFirstWeekdayNumberAccordingToLocale
|
||||
import org.isoron.uhabits.core.utils.StringUtils.Companion.joinLongs
|
||||
import org.isoron.uhabits.core.utils.StringUtils.Companion.splitLongs
|
||||
import java.util.LinkedList
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.core.utils
|
||||
|
||||
import org.apache.commons.lang3.builder.StandardToStringStyle
|
||||
import org.apache.commons.lang3.builder.ToStringStyle
|
||||
import java.math.BigInteger
|
||||
import java.util.Random
|
||||
|
||||
class StringUtils {
|
||||
|
||||
companion object {
|
||||
private lateinit var toStringStyle: StandardToStringStyle
|
||||
|
||||
@JvmStatic
|
||||
fun getRandomId(): String {
|
||||
return BigInteger(260, Random()).toString(32).subSequence(0, 32).toString()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun defaultToStringStyle(): ToStringStyle {
|
||||
toStringStyle = StandardToStringStyle()
|
||||
toStringStyle.apply {
|
||||
fieldSeparator = ", "
|
||||
isUseClassName = false
|
||||
isUseIdentityHashCode = false
|
||||
contentStart = "{"
|
||||
contentEnd = "}"
|
||||
fieldNameValueSeparator = ": "
|
||||
arrayStart = "["
|
||||
arrayEnd = "]"
|
||||
}
|
||||
|
||||
return toStringStyle
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun joinLongs(values: LongArray): String {
|
||||
return org.apache.commons.lang3.StringUtils.join(values, ',')
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun splitLongs(str: String): LongArray {
|
||||
val parts: Array<String> = org.apache.commons.lang3.StringUtils.split(str, ',')
|
||||
return LongArray(parts.size) {
|
||||
i ->
|
||||
parts[i].toLong()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,4 +44,18 @@ class WeekdayListTest : BaseUnitTest() {
|
||||
assertTrue(list.isEmpty)
|
||||
assertFalse(WeekdayList.EVERY_DAY.isEmpty)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWeekdayList_IntConstructor_toString() {
|
||||
val string = WeekdayList(0).toString()
|
||||
assertThat(string, equalTo("{weekdays: [false,false,false,false,false,false,false]}"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWeekdayList_BooleanArrayConstructor_toString() {
|
||||
val string = WeekdayList(
|
||||
booleanArrayOf(false, false, true, true, true, true, true)
|
||||
).toString()
|
||||
assertThat(string, equalTo("{weekdays: [false,false,true,true,true,true,true]}"))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user