Skip to content

Commit 5c1107b

Browse files
committed
scalability improvements
1 parent e8b17e8 commit 5c1107b

6 files changed

Lines changed: 328 additions & 174 deletions

File tree

.idea/markdown.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/shelf/Uncommitted_changes_before_Update_at_3_7_2026_9_03_PM__Changes_.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GeoTagImage/src/main/java/com/dangiashish/GTILocationUtility.kt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import android.Manifest
2828
import android.content.Context
2929
import android.content.pm.PackageManager
3030
import android.location.Location
31+
import android.location.LocationManager
3132
import android.os.Handler
3233
import android.os.Looper
3334
import android.util.Log
@@ -41,6 +42,8 @@ import com.google.android.gms.location.LocationResult
4142
import com.google.android.gms.location.LocationServices
4243
import com.google.android.gms.location.Priority
4344

45+
private const val TAG = "GTILocationUtility"
46+
4447
internal object GTILocationUtility {
4548
private var fusedLocationProviderClient: FusedLocationProviderClient? = null
4649

@@ -69,18 +72,24 @@ internal object GTILocationUtility {
6972
?.addOnSuccessListener { loc ->
7073
if (loc != null) {
7174
callback(loc)
72-
Log.e("LocationUtils", "fetchLocation: $loc")
7375
} else {
7476
requestLiveLocation(context, callback)
7577
}
7678
}
7779
?.addOnFailureListener { err ->
78-
Log.e("LocationUtils", "fetchLocation: ${err.message}")
7980
requestLiveLocation(context, callback)
8081
}
8182
}
8283

8384
private fun requestLiveLocation(context: Context, callback: (Location?) -> Unit) {
85+
if (!isLocationEnabled(context)){
86+
Handler(Looper.getMainLooper()).post {
87+
Toast.makeText(context, "Device GPS is not enabled", Toast.LENGTH_SHORT).show()
88+
}
89+
callback(null)
90+
return
91+
}
92+
8493
val locationRequest = LocationRequest.Builder(
8594
Priority.PRIORITY_HIGH_ACCURACY, 1000L
8695
).setMaxUpdates(1) // Get one update
@@ -103,12 +112,10 @@ internal object GTILocationUtility {
103112
fusedLocationProviderClient?.removeLocationUpdates(this)
104113
val location = locationResult.lastLocation
105114
callback(location)
106-
Log.e("LocationUtils", "Live Location: $location")
107115
}
108116

109117
override fun onLocationAvailability(locationAvailability: LocationAvailability) {
110118
if (!locationAvailability.isLocationAvailable) {
111-
Log.e("LocationUtils", "Location unavailable")
112119
callback(null)
113120

114121
}
@@ -118,4 +125,10 @@ internal object GTILocationUtility {
118125
)
119126
}
120127

128+
private fun isLocationEnabled(context: Context): Boolean {
129+
val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
130+
return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) ||
131+
locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
132+
}
133+
121134
}

GeoTagImage/src/main/java/com/dangiashish/GTIUtility.kt

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,11 @@ object GTIUtility {
9797
@JvmStatic
9898
fun generateOriginalFile(mContext: FragmentActivity, imageExtension: String): File? {
9999
var file: File? = null
100-
Log.i(TAG, "generateOriginalFile: Step 1")
101100
try {
102101
val mediaStorageDir = File(
103102
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM),
104103
"Camera"
105104
)
106-
Log.w(TAG, "generateOriginalFile: Step 2 : $mediaStorageDir", )
107105
if (!mediaStorageDir.exists()) {
108106
if (!mediaStorageDir.mkdirs()) {
109107
return null
@@ -118,7 +116,6 @@ object GTIUtility {
118116
if (file != null) {
119117
scanMediaFIle(mContext, file)
120118
}
121-
Log.w(TAG, "generateOriginalFile: Step 3 $file", )
122119
return file
123120
}
124121

@@ -157,38 +154,29 @@ object GTIUtility {
157154
return "$countryName $flag "
158155
}
159156

160-
val dateFormats = listOf(
161-
"dd/MM/yyyy",
162-
"dd-MM-yyyy",
163-
"yyyy-MM-dd",
164-
"MM/dd/yyyy",
165-
"dd MMM yyyy",
166-
"dd MMMM yyyy",
157+
fun decodeSampledBitmap(path: String, reqWidth: Int, reqHeight: Int): Bitmap {
158+
return BitmapFactory.Options().run {
159+
inJustDecodeBounds = true
160+
BitmapFactory.decodeFile(path, this)
167161

168-
"dd/MM/yyyy HH:mm",
169-
"dd/MM/yyyy hh:mm a",
170-
"dd/MM/yyyy HH:mm:ss",
171-
"dd/MM/yyyy hh:mm:ss a",
162+
inSampleSize = calculateInSampleSize(this, reqWidth, reqHeight)
172163

173-
"yyyy-MM-dd HH:mm:ss",
174-
"yyyy-MM-dd'T'HH:mm:ss",
175-
176-
"EEE, dd MMM yyyy",
177-
"EEEE, dd MMMM yyyy",
178-
179-
"dd/MM/yyyy hh:mm a z",
180-
"dd MMM yyyy hh:mm a z",
181-
182-
"HH:mm",
183-
"hh:mm a",
184-
185-
"HH:mm:ss",
186-
"hh:mm:ss a",
164+
inJustDecodeBounds = false
165+
BitmapFactory.decodeFile(path, this)
166+
}
167+
}
187168

188-
"yyyyMMdd",
189-
"ddMMyyyy",
169+
private fun calculateInSampleSize(options: BitmapFactory.Options, reqWidth: Int, reqHeight: Int): Int {
170+
val (height: Int, width: Int) = options.outHeight to options.outWidth
171+
var inSampleSize = 1
190172

191-
"yyyy-MM-dd HH:mm:ss.SSS",
192-
"yyyy-MM-dd'T'HH:mm:ss.SSSZ"
193-
)
173+
if (height > reqHeight || width > reqWidth) {
174+
val halfHeight = height / 2
175+
val halfWidth = width / 2
176+
while (halfHeight / inSampleSize >= reqHeight && halfWidth / inSampleSize >= reqWidth) {
177+
inSampleSize *= 2
178+
}
179+
}
180+
return inSampleSize
181+
}
194182
}

0 commit comments

Comments
 (0)