Skip to content

Commit

Permalink
Merge pull request #70 from tom5079/dev
Browse files Browse the repository at this point in the history
Version 4.9
  • Loading branch information
tom5079 authored Feb 24, 2020
2 parents c9bde3c + 69e85f8 commit dfe435c
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 19 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ android {
applicationId "xyz.quaver.pupil"
minSdkVersion 16
targetSdkVersion 29
versionCode 44
versionName "4.8"
versionCode 45
versionName "4.9"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
Expand Down
2 changes: 1 addition & 1 deletion app/release/output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":44,"versionName":"4.8","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":45,"versionName":"4.9","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
24 changes: 12 additions & 12 deletions app/src/main/java/xyz/quaver/pupil/adapters/ReaderAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,9 @@ class ReaderAdapter(private val context: Context,
onItemClickListener?.invoke(position)
}

if (!isFullScreen) {
if (!isFullScreen)
(holder.view.container.layoutParams as ConstraintLayout.LayoutParams)
.dimensionRatio = "${reader!!.galleryInfo.files[position].width}:${reader!!.galleryInfo.files[position].height}"
}
.dimensionRatio = "W,${reader!!.galleryInfo.files[position].width}:${reader!!.galleryInfo.files[position].height}"

holder.view.reader_index.text = (position+1).toString()

Expand All @@ -123,18 +122,19 @@ class ReaderAdapter(private val context: Context,
if (progress?.isInfinite() == true && images != null) {
holder.view.reader_item_progressbar.visibility = View.INVISIBLE

glide
.load(images)
.fitCenter()
.error(R.drawable.image_broken_variant)
.apply {
if (BuildConfig.CENSOR)
override(5, 8)
}
.into(holder.view.image)
holder.view.image.post {
glide
.load(images)
.fitCenter()
.error(R.drawable.image_broken_variant)
.into(holder.view.image)
}

} else {
holder.view.reader_item_progressbar.visibility = View.VISIBLE

glide.clear(holder.view.image)

if (progress?.isNaN() == true) {
if (Fabric.isInitialized())
Crashlytics.logException(DownloadWorker.getInstance(context).exception[galleryID]?.get(position))
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/xyz/quaver/pupil/util/download/Cache.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import xyz.quaver.Code
import xyz.quaver.hitomi.GalleryBlock
import xyz.quaver.hitomi.Reader
import xyz.quaver.proxy
import xyz.quaver.pupil.util.copyRecursively
import xyz.quaver.pupil.util.getCachedGallery
import xyz.quaver.pupil.util.getDownloadDirectory
import xyz.quaver.pupil.util.json
Expand Down
63 changes: 63 additions & 0 deletions app/src/main/java/xyz/quaver/pupil/util/file.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import android.os.storage.StorageManager
import android.provider.DocumentsContract
import androidx.core.content.ContextCompat
import androidx.preference.PreferenceManager
import kotlinx.io.IOException
import java.io.File
import java.io.FileOutputStream
import java.lang.reflect.Array
Expand Down Expand Up @@ -211,4 +212,66 @@ fun Uri.toFile(context: Context): File? {
}

return File(context.getExternalFilesDir(null)?.canonicalPath?.substringBeforeLast("/Android/data") ?: return null, folderName)
}

fun File.copyRecursively(
target: File,
overwrite: Boolean = false,
onError: (File, IOException) -> OnErrorAction = { _, exception -> throw exception }
): Boolean {
if (!exists()) {
return onError(this, NoSuchFileException(file = this, reason = "The source file doesn't exist.")) !=
OnErrorAction.TERMINATE
}
try {
// We cannot break for loop from inside a lambda, so we have to use an exception here
for (src in walkTopDown().onFail { f, e -> if (onError(f, e) == OnErrorAction.TERMINATE) throw IOException("Walk failed") }) {
if (!src.exists()) {
if (onError(src, NoSuchFileException(file = src, reason = "The source file doesn't exist.")) ==
OnErrorAction.TERMINATE)
return false
} else {
val relPath = src.toRelativeString(this)
val dstFile = File(target, relPath)
if (dstFile.exists() && !(src.isDirectory && dstFile.isDirectory)) {
val stillExists = if (!overwrite) true else {
if (dstFile.isDirectory)
!dstFile.deleteRecursively()
else
!dstFile.delete()
}

if (stillExists) {
if (onError(dstFile, FileAlreadyExistsException(file = src,
other = dstFile,
reason = "The destination file already exists.")) == OnErrorAction.TERMINATE)
return false

continue
}
}

if (src.isDirectory) {
dstFile.mkdirs()
} else {
val length = try {
src.copyTo(dstFile, overwrite).length()
} catch (e: IOException) {
if (onError(src, e) == OnErrorAction.TERMINATE)
return false
else
-1
}

if (length != src.length()) {
if (onError(src, IOException("Source file wasn't copied completely, length of destination file differs.")) == OnErrorAction.TERMINATE)
return false
}
}
}
}
return true
} catch (e: IOException) {
return false
}
}
7 changes: 3 additions & 4 deletions app/src/main/res/layout/item_reader.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_default="wrap"
app:layout_constraintHeight_max="2000dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
Expand Down Expand Up @@ -65,12 +64,12 @@

<com.github.chrisbanes.photoview.PhotoView
android:id="@+id/image"
android:contentDescription="@string/reader_imageview_description"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:maxHeight="2000dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:paddingBottom="8dp"/>

</androidx.constraintlayout.widget.ConstraintLayout>
Expand Down

0 comments on commit dfe435c

Please sign in to comment.