mirror of
https://github.com/rt-bishop/Look4Sat.git
synced 2026-10-03 03:27:24 +00:00
Reverted item_pass_leo.xml, updated Extensions.kt
This commit is contained in:
1 parent
0638539f3c
commit
187791f895
4 files changed
+173
-86
No files matched your search
@@ -17,8 +17,10 @@
|
||||
*/
|
||||
package com.rtbishop.look4sat.utility
|
||||
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.webkit.URLUtil
|
||||
import androidx.annotation.IdRes
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.Lifecycle
|
||||
@@ -29,21 +31,15 @@ import androidx.navigation.Navigator
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.rtbishop.look4sat.R
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
import java.security.MessageDigest
|
||||
import java.text.ParseException
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
fun Long.toTimerString(): String {
|
||||
val format = "%02d:%02d:%02d"
|
||||
val hours = TimeUnit.MILLISECONDS.toHours(this)
|
||||
val minutes = TimeUnit.MILLISECONDS.toMinutes(this) % 60
|
||||
val seconds = TimeUnit.MILLISECONDS.toSeconds(this) % 60
|
||||
return String.format(format, hours, minutes, seconds)
|
||||
}
|
||||
|
||||
fun Double.round(decimals: Int): Double {
|
||||
var multiplier = 1.0
|
||||
repeat(decimals) { multiplier *= 10 }
|
||||
return kotlin.math.round(this * multiplier) / multiplier
|
||||
}
|
||||
import java.util.regex.Pattern
|
||||
|
||||
fun View.showSnack(message: String, isAnchored: Boolean = true) {
|
||||
Snackbar.make(this, message, Snackbar.LENGTH_SHORT).apply {
|
||||
@@ -85,3 +81,134 @@ fun <T> Fragment.getNavResult(@IdRes id: Int, key: String, onResult: (result: T)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun Int.toDate(): Date = Date(this.toLong() * 1000L)
|
||||
|
||||
fun Long.toTimerString(): String {
|
||||
val format = "%02d:%02d:%02d"
|
||||
val hours = TimeUnit.MILLISECONDS.toHours(this)
|
||||
val minutes = TimeUnit.MILLISECONDS.toMinutes(this) % 60
|
||||
val seconds = TimeUnit.MILLISECONDS.toSeconds(this) % 60
|
||||
return String.format(format, hours, minutes, seconds)
|
||||
}
|
||||
|
||||
fun Double.round(decimals: Int): Double {
|
||||
var multiplier = 1.0
|
||||
repeat(decimals) { multiplier *= 10 }
|
||||
return kotlin.math.round(this * multiplier) / multiplier
|
||||
}
|
||||
|
||||
fun Date.toString(format: String): String {
|
||||
val dateFormatter = SimpleDateFormat(format, Locale.US)
|
||||
return dateFormatter.format(this)
|
||||
}
|
||||
|
||||
fun String.toDate(format: String): Date? {
|
||||
val dateFormatter = SimpleDateFormat(format, Locale.US)
|
||||
return try {
|
||||
dateFormatter.parse(this)
|
||||
} catch (e: ParseException) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun String.toUri(): Uri? {
|
||||
return try {
|
||||
if (URLUtil.isValidUrl(this))
|
||||
Uri.parse(this)
|
||||
else
|
||||
null
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun String.md5(): String {
|
||||
val bytes = MessageDigest.getInstance("MD5").digest(this.toByteArray())
|
||||
return bytes.joinToString("") { "%02x".format(it) }
|
||||
}
|
||||
|
||||
fun String.sha1(): String {
|
||||
val bytes = MessageDigest.getInstance("SHA-1").digest(this.toByteArray())
|
||||
return bytes.joinToString("") { "%02x".format(it) }
|
||||
}
|
||||
|
||||
fun String.isEmailValid(): Boolean {
|
||||
val expression = "^[\\w.-]+@([\\w\\-]+\\.)+[A-Z]{2,8}$"
|
||||
val pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE)
|
||||
val matcher = pattern.matcher(this)
|
||||
return matcher.matches()
|
||||
}
|
||||
|
||||
fun String.getJsonObjectOrNull(): JSONObject? {
|
||||
return try {
|
||||
JSONObject(this)
|
||||
} catch (e: JSONException) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun String.getJsonArrayOrNull(): JSONArray? {
|
||||
return try {
|
||||
JSONArray(this)
|
||||
} catch (e: JSONException) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun JSONObject.getIntOrNull(name: String): Int? =
|
||||
try {
|
||||
getInt(name)
|
||||
} catch (e: JSONException) {
|
||||
val strValue = getStringOrNull(name)
|
||||
strValue?.toIntOrNull()
|
||||
}
|
||||
|
||||
fun JSONObject.getDoubleOrNull(name: String): Double? =
|
||||
try {
|
||||
getDouble(name)
|
||||
} catch (e: JSONException) {
|
||||
null
|
||||
}
|
||||
|
||||
fun JSONObject.getLongOrNull(name: String): Long? =
|
||||
try {
|
||||
getLong(name)
|
||||
} catch (e: JSONException) {
|
||||
null
|
||||
}
|
||||
|
||||
fun JSONObject.getStringOrNull(name: String): String? =
|
||||
try {
|
||||
getString(name).trim()
|
||||
} catch (e: JSONException) {
|
||||
null
|
||||
}
|
||||
|
||||
fun JSONObject.getBooleanOrNull(name: String): Boolean? =
|
||||
try {
|
||||
getBoolean(name)
|
||||
} catch (e: JSONException) {
|
||||
null
|
||||
}
|
||||
|
||||
fun JSONObject.getObjectOrNull(name: String): JSONObject? =
|
||||
try {
|
||||
getJSONObject(name)
|
||||
} catch (e: JSONException) {
|
||||
null
|
||||
}
|
||||
|
||||
fun JSONObject.getArrayOrNull(name: String): JSONArray? =
|
||||
try {
|
||||
getJSONArray(name)
|
||||
} catch (e: JSONException) {
|
||||
null
|
||||
}
|
||||
|
||||
fun JSONObject.getArrayOrEmpty(name: String): JSONArray =
|
||||
try {
|
||||
getJSONArray(name)
|
||||
} catch (e: JSONException) {
|
||||
JSONArray()
|
||||
}
|
||||
@@ -24,12 +24,8 @@
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/pass_leo_satName"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:textAlignment="textStart"
|
||||
android:gravity="start"
|
||||
app:layout_constraintWidth_percent="0.50"
|
||||
app:layout_constraintHeight_percent="0.25"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="6dp"
|
||||
android:layout_marginTop="6dp"
|
||||
android:text="@string/pass_satName"
|
||||
@@ -39,12 +35,8 @@
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/pass_leo_satId"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:textAlignment="textEnd"
|
||||
android:gravity="end"
|
||||
app:layout_constraintWidth_percent="0.50"
|
||||
app:layout_constraintHeight_percent="0.25"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="6dp"
|
||||
android:text="@string/pass_satId"
|
||||
android:textColor="@color/themeLight"
|
||||
@@ -53,47 +45,28 @@
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/pass_leo_aosAz"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dp"
|
||||
android:text="@string/pass_aosAz"
|
||||
app:layout_constraintWidth_percent="0.30"
|
||||
app:layout_constraintHeight_percent="0.23"
|
||||
android:maxLines="1"
|
||||
android:autoSizeTextType="uniform"
|
||||
android:ellipsize="marquee"
|
||||
app:layout_constraintEnd_toStartOf="@+id/pass_leo_losAz"
|
||||
app:layout_constraintHorizontal_chainStyle="spread_inside"
|
||||
app:layout_constraintStart_toStartOf="@+id/pass_leo_satName"
|
||||
app:layout_constraintTop_toBottomOf="@+id/pass_leo_satName" />
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/pass_leo_tcaAz"
|
||||
android:layout_width="0dp"
|
||||
app:layout_constraintWidth_percent="0.30"
|
||||
app:layout_constraintHeight_percent="0.23"
|
||||
android:maxLines="1"
|
||||
android:gravity="center"
|
||||
android:textAlignment="center"
|
||||
android:autoSizeTextType="uniform"
|
||||
android:ellipsize="marquee"
|
||||
android:layout_height="0dp"
|
||||
android:text="@string/pass_tcaAz"
|
||||
app:layout_constraintBaseline_toBaselineOf="@+id/pass_leo_aosAz"
|
||||
app:layout_constraintEnd_toEndOf="@+id/pass_leo_losAz"
|
||||
app:layout_constraintStart_toStartOf="@+id/pass_leo_aosAz" />
|
||||
android:id="@+id/pass_leo_maxEl"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/pass_maxEl"
|
||||
app:layout_constraintBaseline_toBaselineOf="@+id/pass_leo_start"
|
||||
app:layout_constraintEnd_toEndOf="@+id/pass_leo_end"
|
||||
app:layout_constraintStart_toStartOf="@+id/pass_leo_start" />
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/pass_leo_losAz"
|
||||
android:layout_width="0dp"
|
||||
app:layout_constraintWidth_percent="0.30"
|
||||
app:layout_constraintHeight_percent="0.23"
|
||||
android:maxLines="1"
|
||||
android:textAlignment="textEnd"
|
||||
android:gravity="end"
|
||||
android:autoSizeTextType="uniform"
|
||||
android:ellipsize="marquee"
|
||||
android:layout_height="0dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/pass_losAz"
|
||||
app:layout_constraintBaseline_toBaselineOf="@+id/pass_leo_aosAz"
|
||||
app:layout_constraintEnd_toEndOf="@+id/pass_leo_satId"
|
||||
@@ -101,15 +74,10 @@
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/pass_leo_start"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintWidth_percent="0.30"
|
||||
app:layout_constraintHeight_percent="0.23"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dp"
|
||||
android:text="@string/pass_startTime"
|
||||
android:autoSizeTextType="uniform"
|
||||
android:ellipsize="marquee"
|
||||
android:maxLines="1"
|
||||
app:layout_constraintEnd_toStartOf="@+id/pass_leo_end"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintHorizontal_chainStyle="spread_inside"
|
||||
@@ -117,30 +85,18 @@
|
||||
app:layout_constraintTop_toBottomOf="@+id/pass_leo_aosAz" />
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/pass_leo_maxEl"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintWidth_percent="0.30"
|
||||
app:layout_constraintHeight_percent="0.23"
|
||||
android:autoSizeTextType="uniform"
|
||||
android:ellipsize="marquee"
|
||||
android:gravity="center"
|
||||
android:maxLines="1"
|
||||
android:text="@string/pass_maxEl"
|
||||
app:layout_constraintBaseline_toBaselineOf="@+id/pass_leo_start"
|
||||
app:layout_constraintEnd_toEndOf="@+id/pass_leo_end"
|
||||
app:layout_constraintStart_toStartOf="@+id/pass_leo_start" />
|
||||
android:id="@+id/pass_leo_tcaAz"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/pass_tcaAz"
|
||||
app:layout_constraintBaseline_toBaselineOf="@+id/pass_leo_aosAz"
|
||||
app:layout_constraintEnd_toEndOf="@+id/pass_leo_losAz"
|
||||
app:layout_constraintStart_toStartOf="@+id/pass_leo_aosAz" />
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/pass_leo_end"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintWidth_percent="0.30"
|
||||
app:layout_constraintHeight_percent="0.23"
|
||||
android:autoSizeTextType="uniform"
|
||||
android:gravity="end"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="marquee"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/pass_endTime"
|
||||
app:layout_constraintBaseline_toBaselineOf="@+id/pass_leo_start"
|
||||
app:layout_constraintEnd_toEndOf="@+id/pass_leo_losAz"
|
||||
|
||||
Reference in new issue
Block a user