-
Notifications
You must be signed in to change notification settings - Fork 674
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Rajan Maurya <[email protected]>
- Loading branch information
1 parent
0dfe892
commit c3f9985
Showing
27 changed files
with
467 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
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 @@ | ||
plugins { | ||
alias(libs.plugins.mifos.android.feature) | ||
alias(libs.plugins.mifos.android.library.compose) | ||
} | ||
|
||
android { | ||
namespace = "org.mifos.mobile.feature.home" | ||
} | ||
|
||
dependencies { | ||
implementation(projects.ui) | ||
implementation(projects.core.common) | ||
implementation(projects.core.model) | ||
implementation(projects.core.data) | ||
|
||
testImplementation(libs.junit) | ||
androidTestImplementation(libs.androidx.test.ext.junit) | ||
androidTestImplementation(libs.espresso.core) | ||
implementation(libs.squareup.okhttp) | ||
api(libs.androidx.compose.ui.util) | ||
implementation(libs.androidx.camera.camera2) | ||
implementation(libs.androidx.camera.lifecycle) | ||
implementation(libs.androidx.camera.view) | ||
implementation(libs.androidx.camera.core) | ||
} |
Empty file.
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,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
24 changes: 24 additions & 0 deletions
24
feature/home/src/androidTest/java/org/mifos/mobile/feature/home/ExampleInstrumentedTest.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,24 @@ | ||
package org.mifos.mobile.feature.home | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("org.mifos.mobile.feature.home.test", appContext.packageName) | ||
} | ||
} |
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,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</manifest> |
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
8 changes: 5 additions & 3 deletions
8
...va/org/mifos/mobile/ui/home/HomeScreen.kt → ...mobile/feature/home/screens/HomeScreen.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
16 changes: 16 additions & 0 deletions
16
feature/home/src/main/java/org/mifos/mobile/feature/home/utils/HomeUiState.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 org.mifos.mobile.feature.home.utils | ||
|
||
import android.graphics.Bitmap | ||
|
||
sealed class HomeUiState { | ||
data object Loading : HomeUiState() | ||
data class Error(val errorMessage: Int) : HomeUiState() | ||
data class Success(val homeState: HomeState) : HomeUiState() | ||
} | ||
|
||
data class HomeState( | ||
val username: String? = "", | ||
val image: Bitmap? = null, | ||
val loanAmount: Double = 0.0, | ||
val savingsAmount: Double = 0.0 | ||
) |
136 changes: 136 additions & 0 deletions
136
feature/home/src/main/java/org/mifos/mobile/feature/home/utils/ImageUtil.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,136 @@ | ||
package org.mifos.mobile.feature.home.utils | ||
|
||
import android.graphics.Bitmap | ||
import android.graphics.BitmapFactory | ||
import android.graphics.Canvas | ||
import android.graphics.Matrix | ||
import android.graphics.Paint | ||
import android.util.Log | ||
|
||
/** | ||
* Created by dilpreet on 10/8/17. | ||
*/ | ||
class ImageUtil { | ||
// Default width and height | ||
fun compressImage(decodedBytes: ByteArray): Bitmap? { | ||
return compress(decodedBytes, 816.0f, 612.0f) | ||
} | ||
|
||
fun compressImage(decodedBytes: ByteArray, maxHeight: Float, maxWidth: Float): Bitmap? { | ||
return compress(decodedBytes, maxHeight, maxWidth) | ||
} | ||
|
||
private fun compress(decodedBytes: ByteArray, maxHeight: Float, maxWidth: Float): Bitmap? { | ||
var scaledBitmap: Bitmap? = null | ||
val options = BitmapFactory.Options() | ||
|
||
// by setting this field as true, the actual bitmap pixels are not loaded in the memory. | ||
// Just the bounds are loaded. If | ||
// you try the use the bitmap here, you will get null. | ||
options.inJustDecodeBounds = true | ||
var bmp = BitmapFactory.decodeByteArray(decodedBytes, 0, decodedBytes.size, options) | ||
var actualHeight = options.outHeight | ||
var actualWidth = options.outWidth | ||
var imgRatio = actualWidth / actualHeight.toFloat() | ||
val maxRatio = maxWidth / maxHeight | ||
|
||
// width and height values are set maintaining the aspect ratio of the image | ||
if (actualHeight > maxHeight || actualWidth > maxWidth) { | ||
if (imgRatio < maxRatio) { | ||
imgRatio = maxHeight / actualHeight | ||
actualWidth = (imgRatio * actualWidth).toInt() | ||
actualHeight = maxHeight.toInt() | ||
} else if (imgRatio > maxRatio) { | ||
imgRatio = maxWidth / actualWidth | ||
actualHeight = (imgRatio * actualHeight).toInt() | ||
actualWidth = maxWidth.toInt() | ||
} else { | ||
actualHeight = maxHeight.toInt() | ||
actualWidth = maxWidth.toInt() | ||
} | ||
} | ||
|
||
// setting inSampleSize value allows to load a scaled down version of the original image | ||
options.inSampleSize = calculateInSampleSize(options, actualWidth, actualHeight) | ||
|
||
// inJustDecodeBounds set to false to load the actual bitmap | ||
options.inJustDecodeBounds = false | ||
|
||
// this options allow android to claim the bitmap memory if it runs low on memory | ||
options.inPurgeable = true | ||
options.inInputShareable = true | ||
options.inTempStorage = ByteArray(16 * 1024) | ||
try { | ||
bmp = BitmapFactory.decodeByteArray(decodedBytes, 0, decodedBytes.size, options) | ||
} catch (exception: OutOfMemoryError) { | ||
Log.e(ImageUtil::class.java.name, exception.toString()) | ||
} | ||
try { | ||
scaledBitmap = Bitmap.createBitmap(actualWidth, actualHeight, Bitmap.Config.ARGB_8888) | ||
} catch (exception: OutOfMemoryError) { | ||
Log.e(ImageUtil::class.java.name, exception.toString()) | ||
} | ||
val ratioX = actualWidth / options.outWidth.toFloat() | ||
val ratioY = actualHeight / options.outHeight.toFloat() | ||
val middleX = actualWidth / 2.0f | ||
val middleY = actualHeight / 2.0f | ||
val scaleMatrix = Matrix() | ||
scaleMatrix.setScale(ratioX, ratioY, middleX, middleY) | ||
val canvas = Canvas(scaledBitmap!!) | ||
canvas.setMatrix(scaleMatrix) | ||
canvas.drawBitmap( | ||
bmp, | ||
middleX - bmp.width / 2, | ||
middleY - bmp.height / 2, | ||
Paint(Paint.FILTER_BITMAP_FLAG), | ||
) | ||
scaledBitmap = Bitmap.createBitmap( | ||
scaledBitmap, | ||
0, | ||
0, | ||
scaledBitmap.width, | ||
scaledBitmap.height, | ||
null, | ||
true, | ||
) | ||
return scaledBitmap | ||
} | ||
|
||
private fun calculateInSampleSize( | ||
options: BitmapFactory.Options, | ||
reqWidth: Int, | ||
reqHeight: Int, | ||
): Int { | ||
val height = options.outHeight | ||
val width = options.outWidth | ||
var inSampleSize = 1 | ||
if (height > reqHeight || width > reqWidth) { | ||
val heightRatio = Math.round(height.toFloat() / reqHeight.toFloat()) | ||
val widthRatio = Math.round(width.toFloat() / reqWidth.toFloat()) | ||
inSampleSize = if (heightRatio < widthRatio) heightRatio else widthRatio | ||
} | ||
val totalPixels = width * height.toFloat() | ||
val totalReqPixelsCap = reqWidth * reqHeight * 2.toFloat() | ||
while (totalPixels / (inSampleSize * inSampleSize) > totalReqPixelsCap) { | ||
inSampleSize++ | ||
} | ||
return inSampleSize | ||
} | ||
|
||
companion object { | ||
/** | ||
* Reference : https://developer.android.com/topic/performance/graphics/load-bitmap.html | ||
* And for scaling : | ||
* https://stackoverflow.com/questions/8722359/scale-rotate-bitmap-using-matrix-in-android/8722592#8722592 | ||
*/ | ||
@JvmStatic | ||
var instance: ImageUtil? = null | ||
get() { | ||
if (field == null) { | ||
field = ImageUtil() | ||
} | ||
return field | ||
} | ||
private set | ||
} | ||
} |
Oops, something went wrong.