-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from kindnesswall/bugfix/upload-image-and-gallery
implement compress image feature and make fullscreen gallery
- Loading branch information
Showing
12 changed files
with
92 additions
and
36 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
17 changes: 0 additions & 17 deletions
17
app/src/main/java/ir/kindnesswall/data/remote/network/UploadFileApi.kt
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
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
56 changes: 56 additions & 0 deletions
56
app/src/main/java/ir/kindnesswall/utils/extentions/File.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,56 @@ | ||
package ir.kindnesswall.utils.extentions | ||
|
||
import android.content.Context | ||
import android.graphics.Bitmap | ||
import android.graphics.BitmapFactory | ||
import java.io.File | ||
import java.io.FileInputStream | ||
import java.io.FileOutputStream | ||
|
||
/** | ||
* @return reduced size file path address | ||
*/ | ||
fun File.reduceImageSizeAndSave(context: Context): String? { | ||
return try { | ||
// BitmapFactory options to downsize the image | ||
val file = File(this.path) | ||
val options = BitmapFactory.Options() | ||
options.inJustDecodeBounds = true | ||
options.inSampleSize = 4 | ||
// factor of downsizing the image | ||
var inputStream = FileInputStream(file) | ||
//Bitmap selectedBitmap = null; | ||
BitmapFactory.decodeStream(inputStream, null, options) | ||
inputStream.close() | ||
|
||
// The new size we want to scale to | ||
val reduceSizePercent = 75 | ||
|
||
// Find the correct scale value. It should be the power of 2. | ||
var scale = 1 | ||
while (options.outWidth / scale / 2 >= reduceSizePercent && | ||
options.outHeight / scale / 2 >= reduceSizePercent | ||
) { | ||
scale *= 2 | ||
} | ||
val newOptions = BitmapFactory.Options() | ||
newOptions.inSampleSize = scale | ||
inputStream = FileInputStream(file) | ||
val selectedBitmap = BitmapFactory.decodeStream(inputStream, null, newOptions) | ||
inputStream.close() | ||
|
||
// here i override the original image file | ||
val rootDir = File(context.filesDir.path + File.separator + "Photos") | ||
val newFile = | ||
File(rootDir.path + File.separator + file.name) | ||
if (!rootDir.exists()) | ||
rootDir.mkdir() | ||
|
||
newFile.createNewFile() | ||
val outputStream = FileOutputStream(newFile) | ||
selectedBitmap!!.compress(Bitmap.CompressFormat.JPEG, 100, outputStream) | ||
return newFile.path | ||
} catch (e: Exception) { | ||
null | ||
} | ||
} |
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