Skip to content

Commit

Permalink
Merge pull request #34 from tom5079/development
Browse files Browse the repository at this point in the history
Version 4.2-beta1
  • Loading branch information
tom5079 authored Dec 13, 2019
2 parents 678a8f0 + ceaa930 commit 3159c34
Show file tree
Hide file tree
Showing 25 changed files with 307 additions and 56 deletions.
12 changes: 6 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId "xyz.quaver.pupil"
minSdkVersion 16
targetSdkVersion 29
versionCode 30
versionName "4.1"
versionCode 31
versionName "4.2-beta1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
Expand Down Expand Up @@ -46,7 +46,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.2.1'
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.11.0"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.14.0"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.preference:preference:1.1.0'
Expand All @@ -55,12 +55,12 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation "androidx.biometric:biometric:1.0.0-rc02"
implementation "androidx.biometric:biometric:1.0.0"
implementation 'com.android.support:multidex:1.0.3'
implementation "com.daimajia.swipelayout:library:1.2.0@aar"
implementation 'com.google.android.material:material:1.2.0-alpha01'
implementation 'com.google.android.material:material:1.2.0-alpha02'
implementation 'com.google.firebase:firebase-core:17.2.1'
implementation 'com.google.firebase:firebase-perf:19.0.1'
implementation 'com.google.firebase:firebase-perf:19.0.3'
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
implementation 'com.github.arimorty:floatingsearchview:2.1.1'
implementation 'com.github.clans:fab:1.6.4'
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":30,"versionName":"4.1","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":31,"versionName":"4.2-beta1","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import android.util.Log
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.ActivityTestRule
import kotlinx.serialization.ImplicitReflectionSerializer
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonConfiguration
import kotlinx.serialization.json.JsonObject
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -33,6 +37,9 @@ import xyz.quaver.hiyobi.createImgList
import xyz.quaver.hiyobi.getReader
import xyz.quaver.hiyobi.user_agent
import xyz.quaver.pupil.ui.LockActivity
import xyz.quaver.pupil.util.getDownloadDirectory
import xyz.quaver.pupil.util.updateOldReaderGalleries
import java.io.File
import java.net.URL
import javax.net.ssl.HttpsURLConnection

Expand All @@ -48,6 +55,7 @@ class ExampleInstrumentedTest {
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
Log.i("PUPILD", getDownloadDirectory(appContext).absolutePath ?: "")
assertEquals("xyz.quaver.pupil", appContext.packageName)
}

Expand All @@ -57,13 +65,11 @@ class ExampleInstrumentedTest {
val appContext = InstrumentationRegistry.getInstrumentation().targetContext

activityTestRule.launchActivity(Intent())

while(true);
}

@Test
fun test_doSearch() {
val reader = getReader(1426382)
val reader = getReader( 1426382)

val data: ByteArray

Expand All @@ -76,4 +82,38 @@ class ExampleInstrumentedTest {

Log.d("Pupil", data.size.toString())
}
}

@UseExperimental(ImplicitReflectionSerializer::class)
@Test
fun test_deleteCodeFromReader() {
val context = InstrumentationRegistry.getInstrumentation().targetContext

val json = Json(JsonConfiguration.Stable)

listOf(
getDownloadDirectory(context),
File(context.cacheDir, "imageCache")
).forEach { root ->
root.listFiles()?.forEach gallery@{ gallery ->
val reader = json.parseJson(File(gallery, "reader.json").apply {
if (!exists())
return@gallery
}.readText())
.jsonObject.toMutableMap()

Log.d("PUPILD", gallery.name)

reader.remove("code")

File(gallery, "reader.json").writeText(JsonObject(reader).toString())
}
}
}

@Test
fun test_updateOldReader() {
val context = InstrumentationRegistry.getInstrumentation().targetContext

updateOldReaderGalleries(context)
}
}
12 changes: 12 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@
android:theme="@style/AppTheme"
tools:replace="android:theme">

<provider
android:authorities="${applicationId}.fileprovider"
android:name="androidx.core.content.FileProvider"
android:exported="false"
android:grantUriPermissions="true">

<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"/>

</provider>

<activity android:name=".ui.LockActivity"/>
<activity
android:name=".ui.ReaderActivity"
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/xyz/quaver/pupil/Pupil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ import androidx.preference.PreferenceManager
import com.google.android.gms.common.GooglePlayServicesNotAvailableException
import com.google.android.gms.common.GooglePlayServicesRepairableException
import com.google.android.gms.security.ProviderInstaller
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import xyz.quaver.pupil.util.Histories
import xyz.quaver.pupil.util.updateOldReaderGalleries
import java.io.File

class Pupil : MultiDexApplication() {
Expand Down Expand Up @@ -78,6 +82,10 @@ class Pupil : MultiDexApplication() {
false -> AppCompatDelegate.MODE_NIGHT_NO
})

CoroutineScope(Dispatchers.IO).launch {
updateOldReaderGalleries(this@Pupil)
}

super.onCreate()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class GalleryBlockAdapter(private val glide: RequestManager, private val galleri
if (BuildConfig.CENSOR)
override(5, 8)
}
.fitCenter()
.into(galleryblock_thumbnail)
}

Expand Down Expand Up @@ -337,7 +338,7 @@ class GalleryBlockAdapter(private val glide: RequestManager, private val galleri

holder.view.galleryblock_download.text = when(GalleryDownloader.get(gallery.first.id)) {
null -> holder.view.context.getString(R.string.main_download)
else -> holder.view.context.getString(R.string.main_cancel_download)
else -> holder.view.context.getString(android.R.string.cancel)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ReaderAdapter(private val glide: RequestManager,
if (BuildConfig.CENSOR)
override(5, 8)
}
.fitCenter()
.into(holder.view)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class ThumbnailAdapter(private val glide: RequestManager, private val thumbnails
if (BuildConfig.CENSOR)
override(5, 8)
}
.fitCenter()
.into(holder.view)
}

Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/xyz/quaver/pupil/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,17 @@ class MainActivity : AppCompatActivity() {
}
}

histories.remove(galleryID)

if (this@MainActivity.mode == Mode.HISTORY) {
runOnUiThread {
cancelFetch()
clearGalleries()
fetchGalleries(query, sortMode)
loadBlocks()
}
}

completeFlag.put(galleryID, false)
}

Expand Down
71 changes: 69 additions & 2 deletions app/src/main/java/xyz/quaver/pupil/ui/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,29 @@ import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.ContextCompat
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager
import com.google.android.material.snackbar.Snackbar
import kotlinx.android.synthetic.main.dialog_default_query.view.*
import kotlinx.serialization.ImplicitReflectionSerializer
import kotlinx.serialization.json.Json
import kotlinx.serialization.parseList
import xyz.quaver.pupil.Pupil
import xyz.quaver.pupil.R
import xyz.quaver.pupil.types.Tags
import xyz.quaver.pupil.util.Lock
import xyz.quaver.pupil.util.LockManager
import xyz.quaver.pupil.util.getDownloadDirectory
import java.io.File
import java.nio.charset.Charset
import java.util.*

class SettingsActivity : AppCompatActivity() {

val REQUEST_LOCK = 38238
val REQUEST_RESTORE = 16546

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -154,7 +162,7 @@ class SettingsActivity : AppCompatActivity() {
with(findPreference<Preference>("delete_downloads")) {
this!!

val dir = getDownloadDirectory(context)!!
val dir = getDownloadDirectory(context)

summary = getDirSize(dir)

Expand Down Expand Up @@ -278,7 +286,7 @@ class SettingsActivity : AppCompatActivity() {
s ?: return

if (s.any { it.isUpperCase() })
s.replace(0, s.length, s.toString().toLowerCase())
s.replace(0, s.length, s.toString().toLowerCase(Locale.getDefault()))
}
})
}
Expand Down Expand Up @@ -352,6 +360,37 @@ class SettingsActivity : AppCompatActivity() {
true
}
}

with(findPreference<Preference>("backup")) {
this!!

onPreferenceClickListener = Preference.OnPreferenceClickListener {
File(ContextCompat.getDataDir(context), "favorites.json").copyTo(
File(getDownloadDirectory(context), "favorites.json"),
true
)

Snackbar.make(this@SettingsFragment.listView, R.string.settings_backup_snackbar, Snackbar.LENGTH_LONG)
.show()

true
}
}

with(findPreference<Preference>("restore")) {
this!!

onPreferenceClickListener = Preference.OnPreferenceClickListener {
val intent = Intent(Intent.ACTION_GET_CONTENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = "*/*"
}

activity?.startActivityForResult(intent, (activity as SettingsActivity).REQUEST_RESTORE)

true
}
}
}
}

Expand Down Expand Up @@ -415,6 +454,7 @@ class SettingsActivity : AppCompatActivity() {
return true
}

@UseExperimental(ImplicitReflectionSerializer::class)
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when(requestCode) {
REQUEST_LOCK -> {
Expand All @@ -426,6 +466,33 @@ class SettingsActivity : AppCompatActivity() {
.commitAllowingStateLoss()
}
}
REQUEST_RESTORE -> {
if (resultCode == Activity.RESULT_OK) {
val uri = data?.data ?: return

try {
val json = contentResolver.openInputStream(uri).use { inputStream ->
inputStream!!

inputStream.readBytes().toString(Charset.defaultCharset())
}

(application as Pupil).favorites.addAll(Json.parseList<Int>(json).also {
Snackbar.make(
window.decorView,
getString(R.string.settings_restore_successful, it.size),
Snackbar.LENGTH_LONG
).show()
})
} catch (e: Exception) {
Snackbar.make(
window.decorView,
R.string.settings_restore_failed,
Snackbar.LENGTH_LONG
).show()
}
}
}
else -> super.onActivityResult(requestCode, resultCode, data)
}
}
Expand Down
17 changes: 6 additions & 11 deletions app/src/main/java/xyz/quaver/pupil/util/GalleryDownloader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import com.crashlytics.android.Crashlytics
import kotlinx.coroutines.*
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonConfiguration
import xyz.quaver.availableInHiyobi
import xyz.quaver.hitomi.Reader
import xyz.quaver.hitomi.getReader
import xyz.quaver.hitomi.getReferer
Expand Down Expand Up @@ -124,7 +123,7 @@ class GalleryDownloader(
val cached = json.parse(serializer, cache.readText())

if (cached.galleryInfo.isNotEmpty()) {
useHiyobi = availableInHiyobi(galleryID)
useHiyobi = cached.code == Reader.Code.HIYOBI

onReaderLoadedHandler?.invoke(cached)

Expand Down Expand Up @@ -187,15 +186,11 @@ class GalleryDownloader(
async(Dispatchers.IO) {
val url = when(useHiyobi) {
true -> createImgList(galleryID, reader)[index].path
false -> when (galleryInfo.haswebp) {
1 -> webpUrlFromUrl(
urlFromUrlFromHash(
galleryID,
galleryInfo,
true
)
)
else -> urlFromUrlFromHash(galleryID, galleryInfo)
false -> when {
(!galleryInfo.hash.isNullOrBlank()) and (galleryInfo.haswebp == 1) ->
urlFromUrlFromHash(galleryID, galleryInfo, "webp")
else ->
urlFromUrlFromHash(galleryID, galleryInfo)
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/xyz/quaver/pupil/util/file.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ fun getCachedGallery(context: Context, galleryID: Int): File {
}

@Suppress("DEPRECATION")
fun getDownloadDirectory(context: Context): File? {
fun getDownloadDirectory(context: Context): File {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
context.getExternalFilesDir("Pupil")
context.getExternalFilesDir("Pupil")!!
else
File(Environment.getExternalStorageDirectory(), "Pupil")
}
Loading

0 comments on commit 3159c34

Please sign in to comment.