Skip to content

Commit

Permalink
Merge branch 'hotfix/1.2.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
leonlatsch committed Jan 27, 2021
2 parents b4b0558 + 67e10c2 commit 83433e3
Show file tree
Hide file tree
Showing 14 changed files with 148 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 1.2.3
- UI Fixes
- Fix exif orientation bug

### 1.2.2
- UI Fixes

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ Alternative 2: [F-Droid (IzzyOnDroid)](https://apt.izzysoft.de/fdroid/index/apk/
![English](https://img.shields.io/badge/English-100%25-brightgreen)
Maintained by @leonlatsch

![Chinese (China)](https://img.shields.io/badge/Chinese%20(China)-99%25-brightgreen)
Maintained by @sr093906

![German](https://img.shields.io/badge/German-100%25-brightgreen)
Maintained by @leonlatsch

![Spanish](https://img.shields.io/badge/Spanish-85%25-yellow)
Maintained by @Ismael034

![Portuguese (Brazil)](https://img.shields.io/badge/Portuguese%20(Brazil)-85%25-yellow)
Maintained by @mezysinc

![Chinese (China)](https://img.shields.io/badge/Chinese%20(China)-99%25-brightgreen)
Maintained by @sr093906
![Spanish](https://img.shields.io/badge/Spanish-85%25-yellow)
Maintained by @Ismael034

<!-- END-TRANSLATIONS -->

Expand Down
7 changes: 5 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ android {
applicationId = "dev.leonlatsch.photok"
minSdkVersion(24)
targetSdkVersion(30)
versionCode = 11
versionName = "1.2.2"
versionCode = 12
versionName = "1.2.3"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand Down Expand Up @@ -120,6 +120,9 @@ dependencies {
// Gson
implementation("com.google.code.gson", "gson", "2.8.6")

// Androidx ExifInterface
implementation("androidx.exifinterface", "exifinterface", "1.3.0-alpha01")

implementation(fileTree("libs").matching {
include("*.jar")
})
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/assets/licenseReleaseReport.json
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,23 @@
],
"dependency": "androidx.cardview:cardview:1.0.0"
},
{
"project": "Android Support ExifInterface",
"description": "Android Support ExifInterface",
"version": "1.3.0-alpha01",
"developers": [
"The Android Open Source Project"
],
"url": "https://developer.android.com/jetpack/androidx",
"year": "2016",
"licenses": [
{
"license": "The Apache Software License, Version 2.0",
"license_url": "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
],
"dependency": "androidx.exifinterface:exifinterface:1.3.0-alpha01"
},
{
"project": "Android Support Library Annotations",
"description": "The Support Library is a static library that you can add to your Android application in order to use APIs that are either not available for older platform versions or utility APIs that aren\u0027t a part of the framework APIs.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import android.graphics.BitmapFactory
import android.media.ThumbnailUtils
import android.net.Uri
import dev.leonlatsch.photok.model.database.entity.Photo
import dev.leonlatsch.photok.other.normalizeExifOrientation
import dev.leonlatsch.photok.security.EncryptionManager
import timber.log.Timber
import java.io.ByteArrayOutputStream
Expand Down Expand Up @@ -159,8 +160,15 @@ class PhotoStorage @Inject constructor(
password: String? = null
): Boolean {
return try {
val normalizedFullBitmap = normalizeExifOrientation(
BitmapFactory.decodeByteArray(
origBytes,
0,
origBytes.size
), origBytes
)
val thumbnail = ThumbnailUtils.extractThumbnail(
BitmapFactory.decodeByteArray(origBytes, 0, origBytes.size),
normalizedFullBitmap,
THUMBNAIL_SIZE,
THUMBNAIL_SIZE
)
Expand Down
56 changes: 56 additions & 0 deletions app/src/main/java/dev/leonlatsch/photok/other/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ package dev.leonlatsch.photok.other
import android.content.ContentResolver
import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.Matrix
import android.net.Uri
import android.os.Handler
import android.os.Looper
import android.provider.MediaStore
import androidx.appcompat.app.AppCompatDelegate
import androidx.exifinterface.media.ExifInterface
import timber.log.Timber
import java.io.ByteArrayInputStream

/**
* Get a file's name.
Expand Down Expand Up @@ -73,3 +78,54 @@ fun openUrl(context: Context, url: String?) {
intent.data = Uri.parse(url)
context.startActivity(intent)
}

/**
* Reset all orientation exif tags for creating thumbnails
* and displaying photos with exif data properly.
*/
fun normalizeExifOrientation(bitmap: Bitmap, bytesWithExif: ByteArray): Bitmap {
val orientation = ExifInterface(ByteArrayInputStream(bytesWithExif)).getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL
)
val matrix = Matrix()
when (orientation) {
ExifInterface.ORIENTATION_NORMAL -> return bitmap

ExifInterface.ORIENTATION_ROTATE_90 -> matrix.setRotate(90f)
ExifInterface.ORIENTATION_ROTATE_180 -> matrix.setRotate(180f)
ExifInterface.ORIENTATION_ROTATE_270 -> matrix.setRotate(-90f)

ExifInterface.ORIENTATION_FLIP_HORIZONTAL -> matrix.setScale(-1f, 1f)
ExifInterface.ORIENTATION_FLIP_VERTICAL -> {
matrix.setRotate(180f)
matrix.postScale(-1f, 1f)
}

ExifInterface.ORIENTATION_TRANSPOSE -> {
matrix.setRotate(90f)
matrix.postScale(-1f, 1f)
}
ExifInterface.ORIENTATION_TRANSVERSE -> {
matrix.setRotate(-90f)
matrix.postScale(-1f, 1f)
}
else -> return bitmap
}
return try {
val bmRotated: Bitmap = Bitmap.createBitmap(
bitmap,
0,
0,
bitmap.width,
bitmap.height,
matrix,
true
)
bitmap.recycle()
bmRotated
} catch (e: OutOfMemoryError) {
Timber.e(e)
bitmap
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import dev.leonlatsch.photok.R

/**
* Adapter for oss page.
*
* @since 1.2.1
* @author Leon Latsch
*/
class OssAdapter(
private val ossEntries: List<OssEntry>
) : RecyclerView.Adapter<OssViewHolder>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@

package dev.leonlatsch.photok.ui.settings.thirdparty

/**
* Entry for representing a open source project.
*
* @since 1.2.1
* @author Leon Latsch
*/
data class OssEntry(
val project: String,
val description: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ package dev.leonlatsch.photok.ui.settings.thirdparty

import com.google.gson.annotations.SerializedName

/**
* Sub entry for license information from json.
*
* @since 1.2.1
* @author Leon Latsch
*/
data class OssLicenseSubEntry(
val license: String,
@SerializedName("license_url") val licenseUrl: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ import dev.leonlatsch.photok.R
import dev.leonlatsch.photok.databinding.FragmentOssLicensesBinding
import dev.leonlatsch.photok.ui.components.bindings.BindableFragment

/**
* Fragment for displaying open source licenses.
*
* @since 1.2.1
* @author Leon Latsch
*/
class OssLicensesFragment :
BindableFragment<FragmentOssLicensesBinding>(R.layout.fragment_oss_licenses) {

Expand All @@ -35,7 +41,7 @@ class OssLicensesFragment :
requireActivity().onBackPressed()
}

requireActivity().assets.open("licenseReleaseReport.json").let {
requireActivity().assets.open(LICENSE_REPORT_FILE).let {
val json = String(it.readBytes())
val listType = object : TypeToken<ArrayList<OssEntry?>?>() {}.type
val licenses: ArrayList<OssEntry> = Gson().fromJson(json, listType)
Expand All @@ -45,4 +51,8 @@ class OssLicensesFragment :
binding.ossRecycler.adapter = OssAdapter(licenses)
}
}

companion object {
const val LICENSE_REPORT_FILE = "licenseReleaseReport.json"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ import androidx.recyclerview.widget.RecyclerView
import dev.leonlatsch.photok.R
import dev.leonlatsch.photok.other.openUrl

/**
* View Holder for displaying a [OssEntry].
*
* @since 1.2.1
* @author Leon Latsch
*/
class OssViewHolder(
private val context: Context,
view: View
Expand All @@ -35,7 +41,6 @@ class OssViewHolder(
private val license = itemView.findViewById<AppCompatTextView>(R.id.itemOssLicense)

private val licenseDetails = itemView.findViewById<LinearLayout>(R.id.itemOssDetails)
private val details = itemView.findViewById<LinearLayout>(R.id.itemOssDetails)
private val packageName = itemView.findViewById<AppCompatTextView>(R.id.itemOssPackageName)

fun bindTo(ossEntry: OssEntry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ package dev.leonlatsch.photok.ui.viewphoto

import android.content.Context
import android.graphics.BitmapFactory
import android.os.Handler
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.ortiz.touchview.TouchImageView
import dev.leonlatsch.photok.R
import dev.leonlatsch.photok.model.repositories.PhotoRepository
import dev.leonlatsch.photok.other.normalizeExifOrientation
import dev.leonlatsch.photok.other.runOnMain
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import timber.log.Timber
Expand Down Expand Up @@ -76,14 +78,21 @@ class PhotoViewHolder(
}

private fun loadPhoto() {
GlobalScope.launch {
GlobalScope.launch(Dispatchers.IO) {
val photoBytes = photoRepository.readPhotoFileFromInternal(context, photoId)
if (photoBytes == null) {
Timber.d("Error loading photo data for photo: $photoId")
return@launch
}
val bitmap = BitmapFactory.decodeByteArray(photoBytes, 0, photoBytes.size)
Handler(context.mainLooper).post {

val bitmap = normalizeExifOrientation(
BitmapFactory.decodeByteArray(
photoBytes,
0,
photoBytes.size
), photoBytes
)
runOnMain {
imageView.setImageBitmap(bitmap)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ class ViewPhotoActivity : BindableActivity<ActivityViewPhotoBinding>(R.layout.ac
window.addSystemUIVisibilityListener {
systemUiVisible = it
if (it) {
binding.viewPhotoToolbar.show()
binding.viewPhotoAppBarLayout.show()
binding.viewPhotoBottomToolbarLayout.show()
} else {
binding.viewPhotoToolbar.hide()
binding.viewPhotoAppBarLayout.hide()
binding.viewPhotoBottomToolbarLayout.hide()
}
}
Expand Down
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ tasks.register("updateTranslations") {
} // READ strings.xml

if (badges.isNotEmpty()) {
badges.sort()

val readmeString = String(java.io.FileInputStream(File("README.md")).readBytes())
val readmeLines = readmeString.split("\n")

Expand Down

0 comments on commit 83433e3

Please sign in to comment.