Skip to content

Commit

Permalink
Fixed some images crashing
Browse files Browse the repository at this point in the history
Added auto pageturn timer
  • Loading branch information
tom5079 committed Aug 8, 2020
1 parent 647294d commit 9415ab4
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ android {
minSdkVersion 16
targetSdkVersion 29
versionCode 57
versionName "4.20-hotfix2"
versionName "4.21"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
Expand Down
2 changes: 1 addition & 1 deletion app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"filters": [],
"properties": [],
"versionCode": 57,
"versionName": "4.20-hotfix2",
"versionName": "4.21",
"enabled": true,
"outputFile": "app-release.apk"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
package xyz.quaver.pupil.adapters

import android.content.Context
import android.graphics.Color
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.graphics.drawable.Drawable
import android.util.Base64
import android.util.SparseBooleanArray
Expand Down Expand Up @@ -221,12 +224,16 @@ class GalleryBlockAdapter(private val glide: RequestManager, private val galleri
"male" -> {
setChipBackgroundColorResource(R.color.material_blue_700)
setTextColor(ContextCompat.getColor(context, android.R.color.white))
ContextCompat.getDrawable(context, R.drawable.gender_male)
ContextCompat.getDrawable(context, R.drawable.gender_male)?.apply {
colorFilter = PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP)
}
}
"female" -> {
setChipBackgroundColorResource(R.color.material_pink_600)
setTextColor(ContextCompat.getColor(context, android.R.color.white))
ContextCompat.getDrawable(context, R.drawable.gender_female)
ContextCompat.getDrawable(context, R.drawable.gender_female)?.apply {
colorFilter = PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP)
}
}
else -> null
}
Expand Down
26 changes: 26 additions & 0 deletions app/src/main/java/xyz/quaver/pupil/ui/ReaderActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import xyz.quaver.pupil.util.download.Cache
import xyz.quaver.pupil.util.download.DownloadWorker
import java.util.*
import kotlin.concurrent.schedule
import kotlin.concurrent.timer

class ReaderActivity : AppCompatActivity() {

Expand All @@ -71,6 +72,7 @@ class ReaderActivity : AppCompatActivity() {
}

private val timer = Timer()
private var autoTimer: Timer? = null

private val snapHelper = PagerSnapHelper()

Expand Down Expand Up @@ -380,6 +382,30 @@ class ReaderActivity : AppCompatActivity() {
}
}

with(reader_fab_auto) {
setImageResource(R.drawable.clock_start)
setOnClickListener {
if (autoTimer == null) {
autoTimer = timer(initialDelay = 10000L, period = 10000L) {
CoroutineScope(Dispatchers.Main).launch {
with(this@ReaderActivity.reader_recyclerview) {
val lastItem =
(layoutManager as LinearLayoutManager).findLastCompletelyVisibleItemPosition()

if (lastItem < adapter!!.itemCount - 1)
(layoutManager as LinearLayoutManager).scrollToPosition(lastItem + 1)
}
}
}
setImageResource(R.drawable.clock_end)
} else {
autoTimer?.cancel()
autoTimer = null
setImageResource(R.drawable.clock_start)
}
}
}

with(reader_fab_fullscreen) {
setImageResource(R.drawable.ic_fullscreen)
setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,16 @@ class SettingsFragment :
}

private fun getDirSize(dir: File) : String {
return getString(R.string.settings_storage_usage,
Runtime.getRuntime().exec("du -hs " + dir.absolutePath).let {
BufferedReader(InputStreamReader(it.inputStream)).use { reader ->
reader.readLine()?.split('\t')?.firstOrNull() ?: "0"
return if (activity != null)
getString(R.string.settings_storage_usage,
Runtime.getRuntime().exec("du -hs " + dir.absolutePath).let {
BufferedReader(InputStreamReader(it.inputStream)).use { reader ->
reader.readLine()?.split('\t')?.firstOrNull() ?: "0"
}
}
}
)
)
else
""
}

override fun onPreferenceClick(preference: Preference?): Boolean {
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/drawable/clock_end.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!-- drawable/clock_end.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#fff" android:pathData="M12,1C8.14,1 5,4.14 5,8A7,7 0 0,0 12,15C15.86,15 19,11.87 19,8C19,4.14 15.86,1 12,1M12,3.15C14.67,3.15 16.85,5.32 16.85,8C16.85,10.68 14.67,12.85 12,12.85A4.85,4.85 0 0,1 7.15,8A4.85,4.85 0 0,1 12,3.15M11,5V8.69L14.19,10.53L14.94,9.23L12.5,7.82V5M15,16V19H3V21H15V24L19,20M19,20V24H21V16H19" />
</vector>
8 changes: 8 additions & 0 deletions app/src/main/res/drawable/clock_start.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!-- drawable/clock_start.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#fff" android:pathData="M12,1C8.14,1 5,4.14 5,8A7,7 0 0,0 12,15C15.86,15 19,11.87 19,8C19,4.14 15.86,1 12,1M12,3.15C14.67,3.15 16.85,5.32 16.85,8C16.85,10.68 14.67,12.85 12,12.85A4.85,4.85 0 0,1 7.15,8A4.85,4.85 0 0,1 12,3.15M11,5V8.69L14.19,10.53L14.94,9.23L12.5,7.82V5M4,16V24H6V21H18V24L22,20L18,16V19H6V16" />
</vector>
7 changes: 7 additions & 0 deletions app/src/main/res/layout/activity_reader.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@
app:fab_label="@string/reader_fab_retry"
app:fab_size="mini"/>

<com.github.clans.fab.FloatingActionButton
android:id="@+id/reader_fab_auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fab_label="@string/reader_fab_auto"
app:fab_size="mini"/>

<com.github.clans.fab.FloatingActionButton
android:id="@+id/reader_fab_fullscreen"
android:layout_width="wrap_content"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,5 @@
<string name="settings_user_id_toast">ユーザーIDをクリップボードにコピーしました</string>
<string name="reader_error_retry">ダウンロードエラーが発生しました。リトライしますか?</string>
<string name="reader_fab_retry">リトライ</string>
<string name="reader_fab_auto">自動スクロール</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-ko/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,5 @@
<string name="settings_user_id_toast">유저 ID를 클립보드에 복사했습니다</string>
<string name="reader_error_retry">다운로드 에러가 발생했습니. 재시도 하시겠습니까?</string>
<string name="reader_fab_retry">재시도</string>
<string name="reader_fab_auto">자동 스크롤</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
<string name="reader_go_to_page">Go to page</string>
<string name="reader_fab_fullscreen">Fullscreen</string>>
<string name="reader_fab_retry">Retry</string>
<string name="reader_fab_auto">Automatic scroll</string>
<string name="reader_fab_download">Background download</string>
<string name="reader_fab_download_cancel">Cancel background download</string>
<string name="reader_notification_text">Downloading&#8230;</string>
Expand Down
14 changes: 10 additions & 4 deletions libpupil/src/main/java/xyz/quaver/hitomi/common.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ fun getGalleryInfo(galleryID: Int) =

//common.js
var adapose = false
const val numberOfFrontends = 3
const val domain = "ltn.hitomi.la"
const val galleryblockdir = "galleryblock"
const val nozomiextension = ".nozomi"

fun subdomainFromGalleryID(g: Int) : String {
fun subdomainFromGalleryID(g: Int, numberOfFrontends: Int) : String {
if (adapose)
return "0"

Expand All @@ -53,13 +52,20 @@ fun subdomainFromURL(url: String, base: String? = null) : String {
if (!base.isNullOrBlank())
retval = base

var numberOfFrontends = 3
val b = 16

val r = Regex("""/[0-9a-f]/([0-9a-f]{2})/""")
val m = r.find(url) ?: return retval

val g = m.groupValues[1].toIntOrNull(b) ?: return retval
var g = m.groupValues[1].toIntOrNull(b) ?: return retval

when {
g < 0x30 -> numberOfFrontends = 2
g < 0x09 -> g = 1
}

retval = subdomainFromGalleryID(g) + retval
retval = subdomainFromGalleryID(g, numberOfFrontends) + retval

return retval
}
Expand Down
7 changes: 7 additions & 0 deletions libpupil/src/test/java/xyz/quaver/hitomi/UnitTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ class UnitTest {
print(reader)
}

@Test
fun test_getImages() {
val reader = getReader(1702206)

print(urlFromUrlFromHash(1702206, reader.galleryInfo.files.first(), "webp"))
}

@Test
fun test_hiyobi() {
val reader = xyz.quaver.hiyobi.getReader(1664762)
Expand Down

0 comments on commit 9415ab4

Please sign in to comment.