Skip to content

Commit

Permalink
compartir sismos por instagram (avances)
Browse files Browse the repository at this point in the history
Signed-off-by: figonzal1 <[email protected]>
  • Loading branch information
figonzal1 committed Jan 7, 2024
1 parent 18ccb9d commit 44c5c74
Show file tree
Hide file tree
Showing 17 changed files with 667 additions and 300 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ android {
signingConfig = signingConfigs.getByName("lastquakechilesign")
resValue("string", "app_name", "LastQuakeChile")

resValue("string", "ADMOB_ID_BANNER", "ca-app-pub-6355378855577476/5493893896")
resValue("string", "ADMOB_ID_NATIVE_FRAGMENT", "ca-app-pub-6355378855577476/2611250693")
resValue("string", "ADMOB_ID_NATIVE_DETAILS", "ca-app-pub-6355378855577476/2723765487")
resValue("string", "ADMOB_ID_BANNER", "ca-app-pub-3940256099942544/6300978111")
resValue("string", "ADMOB_ID_NATIVE_FRAGMENT", "ca-app-pub-3940256099942544/2247696110")
resValue("string", "ADMOB_ID_NATIVE_DETAILS", "ca-app-pub-3940256099942544/2247696110")
}

}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@
</provider> <!-- TODO: Habilitar para produccion -->
<meta-data
android:name="firebase_performance_collection_enabled"
android:value="true" /> <!-- TODO: Habilitar para produccion -->
android:value="false" /> <!-- TODO: Habilitar para produccion -->
<meta-data
android:name="firebase_crashlytics_collection_enabled"
android:value="true" />
android:value="false" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ import android.content.pm.PackageManager.ResolveInfoFlags
import android.content.res.Configuration
import android.net.Uri
import android.os.Build
import android.view.View
import cl.figonzal.lastquakechile.R
import cl.figonzal.lastquakechile.core.utils.views.*
import cl.figonzal.lastquakechile.core.utils.views.configSensitive
import cl.figonzal.lastquakechile.core.utils.views.formatFilterColor
import cl.figonzal.lastquakechile.core.utils.views.formatMagnitude
import cl.figonzal.lastquakechile.core.utils.views.formatQuakeTime
import cl.figonzal.lastquakechile.core.utils.views.getLocalBitmapUri
import cl.figonzal.lastquakechile.core.utils.views.getMagnitudeColor
import cl.figonzal.lastquakechile.core.utils.views.toast
import cl.figonzal.lastquakechile.databinding.QuakeBottomSheetBinding
import cl.figonzal.lastquakechile.quake_feature.domain.model.Quake
import com.google.android.gms.maps.GoogleMap
Expand Down Expand Up @@ -92,14 +97,16 @@ fun Circle.animate(body: Circle.() -> Unit): Circle {
/**
* Google maps take snapshot
*/
fun Context.makeSnapshot(googleMap: GoogleMap, quake: Quake) {
fun Context.makeSnapshot(googleMap: GoogleMap, quake: Quake, callback: (Uri?) -> Unit) {

googleMap.snapshot {
try {
Timber.d("Snapshot google map")

val bitMapUri = it?.let { it1 -> this.getLocalBitmapUri(it1) }
shareQuake(quake, bitMapUri)
callback(bitMapUri)

//shareQuake(quake, bitMapUri)
} catch (e: IOException) {
Timber.e(e, "Error screenshot map: %s", e.message)
}
Expand Down Expand Up @@ -146,6 +153,7 @@ private fun Context.shareQuake(quake: Quake, bitMapUri: Uri?) {
chooser,
ResolveInfoFlags.of(MATCH_DEFAULT_ONLY.toLong())
)

else -> packageManager.queryIntentActivities(chooser, MATCH_DEFAULT_ONLY)
}

Expand Down Expand Up @@ -176,26 +184,17 @@ fun Context.setBottomSheetQuakeData(
tvCity.text = quake.city
tvReference.text = quake.reference

tvMagnitude.text = String.format(
QUAKE_DETAILS_MAGNITUDE_FORMAT,
quake.magnitude
)
ivMagColor.setColorFilter(
resources.getColor(
getMagnitudeColor(quake.magnitude, false), theme
)
)
tvMagnitude.formatMagnitude(quake)

tvDate.timeToText(quake, true)
ivMagColor.formatFilterColor(applicationContext, quake)

//Verified status
ivVerified.visibility = when {
quake.isVerified -> View.VISIBLE
else -> View.GONE
}
tvDate.formatQuakeTime(quake, true)

ivVerified.setOnClickListener {
toast(R.string.quake_verified_toast)
with(ivVerified) {
configSensitive(quake)
setOnClickListener {
toast(R.string.quake_verified_toast)
}
}

root.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
package cl.figonzal.lastquakechile.core.utils.views

import android.content.Context
import android.widget.ImageView
import android.widget.TextView
import cl.figonzal.lastquakechile.R
import cl.figonzal.lastquakechile.core.utils.latLongToDMS
import cl.figonzal.lastquakechile.core.utils.localDateToDHMS
import cl.figonzal.lastquakechile.core.utils.stringToLocalDateTime
import cl.figonzal.lastquakechile.quake_feature.domain.model.Quake
import java.time.format.DateTimeFormatter
import java.util.Locale

/**
* Setting scale textview depending on the value of string
*
* @param quake Quake information
*/
fun TextView.formatScale(quake: Quake) {

text = when (quake.scale.lowercase()) {
"mw" -> String.format(
QUAKE_DETAILS_SCALE_FORMAT,
context.getString(R.string.moment_magnitude)
)

"mww" -> String.format(
QUAKE_DETAILS_SCALE_FORMAT,
context.getString(R.string.moment_magnitude_w)
)

else -> String.format(
QUAKE_DETAILS_SCALE_FORMAT,
context.getString(R.string.local_magnitude)
)
}
}

fun TextView.formatDepth(quake: Quake) {
text = String.format(QUAKE_DETAILS_DEPTH_FORMAT, quake.depth)
}

/**
* Format text for quake magnitude
*
* @param quake Quake information
*/
fun TextView.formatMagnitude(quake: Quake) {
text = String.format(
QUAKE_DETAILS_MAGNITUDE_FORMAT,
quake.magnitude
)
}

fun ImageView.formatFilterColor(context: Context, quake: Quake) =
this.setColorFilter(context.getColor(getMagnitudeColor(quake.magnitude, false)))


fun TextView.formatDateTime(quake: Quake) {
text = quake.localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
}

/**
* Transform localDateTime to a string text in (days or hours or minutes)
*/
fun TextView.formatQuakeTime(quake: Quake, isShortVersion: Boolean = false) {

val timeMap = quake.localDate.stringToLocalDateTime().localDateToDHMS()
val days = timeMap[DAYS]

text = when {
days != null && days == 0L -> {
calculateTextViewBelowDay(this.context, timeMap, isShortVersion)
}

days != null && days > 0 -> {
calculateTextViewAboveDay(this.context, timeMap, isShortVersion)
}

else -> ""
}
}

/**
* Coordinates to DMS
*/
fun TextView.formatDMS(quake: Quake) {

val latDMS = quake.coordinate.latitude.latLongToDMS()
val degreeLat = latDMS["grados"]
val minLat = latDMS["minutos"]
val segLat = latDMS["segundos"]

val dmsLat = String.format(
Locale.US,
"%.1f° %.1f' %.1f'' %s",
degreeLat,
minLat,
segLat,
when {
quake.coordinate.latitude < 0 -> this.context.getString(R.string.south_cords)
else -> this.context.getString(R.string.north_cords)
}
)

val longDMS = quake.coordinate.longitude.latLongToDMS()
val degreeLong = longDMS["grados"]
val minLong = longDMS["minutos"]
val segLong = longDMS["segundos"]

val dmsLong = String.format(
Locale.US,
"%.1f° %.1f' %.1f'' %s",
degreeLong,
minLong,
segLong,
when {
quake.coordinate.longitude < 0 -> this.context.getString(R.string.west_cords)
else -> this.context.getString(R.string.east_cords)
}
)

text = String.format(QUAKE_CORDS_FORMAT, dmsLat, dmsLong)
}

fun Context.getMonth(month: Int) = arrayOf(
getString(R.string.JAN),
getString(R.string.FEB),
getString(R.string.MAR),
getString(R.string.APR),
getString(R.string.MAY),
getString(R.string.JUN),
getString(R.string.JUL),
getString(R.string.AUG),
getString(R.string.SEP),
getString(R.string.OCT),
getString(R.string.NOV),
getString(R.string.DEC)
)[month - 1]

private fun calculateTextViewBelowDay(
context: Context,
timeMap: Map<String, Long>,
isShortVersion: Boolean
): String {

val hour = timeMap[HOURS]
val min = timeMap[MINUTES]
val seg = timeMap[SECONDS]

return when {
hour != null && hour >= 1 -> when {
isShortVersion -> String.format(QUAKETIME_H_FORMAT, hour)
else -> String.format(context.getString(R.string.quake_time_hour_info_windows), hour)
}

else -> when {
min != null && min < 1 -> when {
isShortVersion -> String.format(
QUAKETIME_S_FORMAT, seg
)

else -> String.format(
context.getString(R.string.quake_time_second_info_windows), seg
)
}

else -> when {
isShortVersion -> String.format(
QUAKETIME_M_FORMAT,
min
)

else -> String.format(
context.getString(R.string.quake_time_minute_info_windows),
min
)
}
}
}
}


private fun calculateTextViewAboveDay(
context: Context,
timeMap: Map<String, Long>,
isShortVersion: Boolean
): String {

val days = timeMap[DAYS]
val hour = timeMap[HOURS]

return when {
hour != null && hour == 0L -> when {
isShortVersion -> String.format(
QUAKETIME_D_FORMAT,
days
)

else -> String.format(
context.getString(R.string.quake_time_day_info_windows),
days
)
}

hour != null && hour >= 1 -> when {
isShortVersion -> String.format(
QUAKETIME_DH_FORMAT,
days,
hour / 24
)

else -> String.format(
context.getString(R.string.quake_time_day_hour_info_windows),
days,
hour / 24
)
}

else -> ""
}
}


Loading

0 comments on commit 44c5c74

Please sign in to comment.