-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrated util module files from java to kotlin (#5935)
* Rename .java to .kt * Migrated the following files in util module to Kotlin - AbstractTextWatcher - ActivityUtils - CommonsDateUtil - DateUtil * Rename .java to .kt * Migrated the following files in util module to Kotlin - DeviceInfoUtil - ExecutorUtils - FragmentUtils
- Loading branch information
1 parent
248c7b0
commit 5c8c403
Showing
22 changed files
with
288 additions
and
290 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 0 additions & 31 deletions
31
app/src/main/java/fr/free/nrw/commons/utils/AbstractTextWatcher.java
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
app/src/main/java/fr/free/nrw/commons/utils/AbstractTextWatcher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package fr.free.nrw.commons.utils | ||
|
||
import android.text.Editable | ||
import android.text.TextWatcher | ||
|
||
class AbstractTextWatcher( | ||
private val textChange: TextChange | ||
) : TextWatcher { | ||
|
||
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) { | ||
// No-op | ||
} | ||
|
||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { | ||
textChange.onTextChanged(s.toString()) | ||
} | ||
|
||
override fun afterTextChanged(s: Editable?) { | ||
// No-op | ||
} | ||
|
||
interface TextChange { | ||
fun onTextChanged(value: String) | ||
} | ||
} |
15 changes: 0 additions & 15 deletions
15
app/src/main/java/fr/free/nrw/commons/utils/ActivityUtils.java
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
app/src/main/java/fr/free/nrw/commons/utils/ActivityUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package fr.free.nrw.commons.utils | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
|
||
object ActivityUtils { | ||
|
||
@JvmStatic | ||
fun <T> startActivityWithFlags(context: Context, cls: Class<T>, vararg flags: Int) { | ||
val intent = Intent(context, cls) | ||
for (flag in flags) { | ||
intent.addFlags(flag) | ||
} | ||
context.startActivity(intent) | ||
} | ||
} |
44 changes: 0 additions & 44 deletions
44
app/src/main/java/fr/free/nrw/commons/utils/CommonsDateUtil.java
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
app/src/main/java/fr/free/nrw/commons/utils/CommonsDateUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package fr.free.nrw.commons.utils | ||
|
||
import java.text.SimpleDateFormat | ||
import java.util.Locale | ||
import java.util.TimeZone | ||
|
||
/** | ||
* Provides util functions for formatting date time. | ||
* Most of our formatting needs are addressed by the data library's DateUtil class. | ||
* Methods should be added here only if DateUtil class doesn't provide for it already. | ||
*/ | ||
object CommonsDateUtil { | ||
|
||
/** | ||
* Gets SimpleDateFormat for short date pattern. | ||
* @return simpleDateFormat | ||
*/ | ||
@JvmStatic | ||
fun getIso8601DateFormatShort(): SimpleDateFormat { | ||
val simpleDateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.ROOT) | ||
simpleDateFormat.timeZone = TimeZone.getTimeZone("UTC") | ||
return simpleDateFormat | ||
} | ||
|
||
/** | ||
* Gets SimpleDateFormat for date pattern returned by Media object. | ||
* @return simpleDateFormat | ||
*/ | ||
@JvmStatic | ||
fun getMediaSimpleDateFormat(): SimpleDateFormat { | ||
val simpleDateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ROOT) | ||
simpleDateFormat.timeZone = TimeZone.getTimeZone("UTC") | ||
return simpleDateFormat | ||
} | ||
|
||
/** | ||
* Gets the timestamp pattern for a date. | ||
* @return timestamp | ||
*/ | ||
@JvmStatic | ||
fun getIso8601DateFormatTimestamp(): SimpleDateFormat { | ||
val simpleDateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT) | ||
simpleDateFormat.timeZone = TimeZone.getTimeZone("UTC") | ||
return simpleDateFormat | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package fr.free.nrw.commons.utils | ||
|
||
import android.text.format.DateFormat.getBestDateTimePattern | ||
import java.text.ParseException | ||
import java.text.SimpleDateFormat | ||
import java.util.Date | ||
import java.util.HashMap | ||
import java.util.Locale | ||
import java.util.TimeZone | ||
|
||
/** | ||
* Utility class for date formatting and parsing. | ||
* TODO: Switch to DateTimeFormatter when minSdk = 26. | ||
*/ | ||
object DateUtil { | ||
|
||
private val DATE_FORMATS: MutableMap<String, SimpleDateFormat> = HashMap() | ||
|
||
@JvmStatic | ||
@Synchronized | ||
fun iso8601DateFormat(date: Date): String { | ||
return getCachedDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT, true).format(date) | ||
} | ||
|
||
@JvmStatic | ||
@Synchronized | ||
@Throws(ParseException::class) | ||
fun iso8601DateParse(date: String): Date { | ||
return getCachedDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT, true).parse(date) | ||
} | ||
|
||
@JvmStatic | ||
fun getMonthOnlyDateString(date: Date): String { | ||
return getDateStringWithSkeletonPattern(date, "MMMM d") | ||
} | ||
|
||
@JvmStatic | ||
fun getExtraShortDateString(date: Date): String { | ||
return getDateStringWithSkeletonPattern(date, "MMM d") | ||
} | ||
|
||
@JvmStatic | ||
@Synchronized | ||
fun getDateStringWithSkeletonPattern(date: Date, pattern: String): String { | ||
return getCachedDateFormat( | ||
getBestDateTimePattern(Locale.getDefault(), pattern), | ||
Locale.getDefault(), false | ||
).format(date) | ||
} | ||
|
||
@JvmStatic | ||
private fun getCachedDateFormat(pattern: String, locale: Locale, utc: Boolean): SimpleDateFormat { | ||
if (!DATE_FORMATS.containsKey(pattern)) { | ||
val df = SimpleDateFormat(pattern, locale) | ||
if (utc) { | ||
df.timeZone = TimeZone.getTimeZone("UTC") | ||
} | ||
DATE_FORMATS[pattern] = df | ||
} | ||
return DATE_FORMATS[pattern]!! | ||
} | ||
} |
Oops, something went wrong.