Utilizing Glide
Fixed Reader FAB icon Changed to use gallery id instead of galleryblock to open Reader
This commit is contained in:
@@ -55,6 +55,8 @@ import java.net.URL
|
||||
import java.util.*
|
||||
import javax.net.ssl.HttpsURLConnection
|
||||
import kotlin.collections.ArrayList
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.ceil
|
||||
import kotlin.math.min
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
@@ -72,8 +74,10 @@ class MainActivity : AppCompatActivity() {
|
||||
private var query = ""
|
||||
set(value) {
|
||||
field = value
|
||||
findViewById<SearchInputView>(R.id.search_bar_text)
|
||||
.setText(query, TextView.BufferType.EDITABLE)
|
||||
with(findViewById<SearchInputView>(R.id.search_bar_text)) {
|
||||
if (text.toString() != value)
|
||||
setText(query, TextView.BufferType.EDITABLE)
|
||||
}
|
||||
}
|
||||
|
||||
private var mode = Mode.SEARCH
|
||||
@@ -155,7 +159,7 @@ class MainActivity : AppCompatActivity() {
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
val preference = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
val perPage = preference.getString("per_page", "25")!!.toInt()
|
||||
val maxPage = Math.ceil(totalItems / perPage.toDouble()).roundToInt()
|
||||
val maxPage = ceil(totalItems / perPage.toDouble()).roundToInt()
|
||||
|
||||
return when(keyCode) {
|
||||
KeyEvent.KEYCODE_VOLUME_DOWN -> {
|
||||
@@ -380,9 +384,9 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
val intent = Intent(this@MainActivity, ReaderActivity::class.java)
|
||||
val gallery = galleries[position].first
|
||||
intent.putExtra("galleryblock", Json(JsonConfiguration.Stable).stringify(GalleryBlock.serializer(), gallery))
|
||||
intent.putExtra("galleryID", gallery.id)
|
||||
|
||||
//TODO: Maybe sprinke some transitions will be nice :D
|
||||
//TODO: Maybe sprinkling some transitions will be nice :D
|
||||
startActivity(intent)
|
||||
|
||||
histories.add(gallery.id)
|
||||
@@ -391,7 +395,7 @@ class MainActivity : AppCompatActivity() {
|
||||
if (v !is CardView)
|
||||
return@setOnItemLongClickListener true
|
||||
|
||||
val galleryBlock = galleries[position].first
|
||||
val gallery = galleries[position].first
|
||||
val view = LayoutInflater.from(this@MainActivity)
|
||||
.inflate(R.layout.dialog_galleryblock, recyclerView, false)
|
||||
|
||||
@@ -400,15 +404,15 @@ class MainActivity : AppCompatActivity() {
|
||||
}.create()
|
||||
|
||||
with(view.main_dialog_download) {
|
||||
text = when(GalleryDownloader.get(galleryBlock.id)) {
|
||||
text = when(GalleryDownloader.get(gallery.id)) {
|
||||
null -> getString(R.string.reader_fab_download)
|
||||
else -> getString(R.string.reader_fab_download_cancel)
|
||||
}
|
||||
isEnabled = !(adapter as GalleryBlockAdapter).completeFlag.get(galleryBlock.id, false)
|
||||
isEnabled = !(adapter as GalleryBlockAdapter).completeFlag.get(gallery.id, false)
|
||||
setOnClickListener {
|
||||
val downloader = GalleryDownloader.get(galleryBlock.id)
|
||||
val downloader = GalleryDownloader.get(gallery.id)
|
||||
if (downloader == null)
|
||||
GalleryDownloader(context, galleryBlock, true).start()
|
||||
GalleryDownloader(context, gallery.id, true).start()
|
||||
else {
|
||||
downloader.cancel()
|
||||
downloader.clearNotification()
|
||||
@@ -420,16 +424,16 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
view.main_dialog_delete.setOnClickListener {
|
||||
CoroutineScope(Dispatchers.Default).launch {
|
||||
with(GalleryDownloader[galleryBlock.id]) {
|
||||
with(GalleryDownloader[gallery.id]) {
|
||||
this?.cancelAndJoin()
|
||||
this?.clearNotification()
|
||||
}
|
||||
val cache = File(cacheDir, "imageCache/${galleryBlock.id}")
|
||||
val data = getCachedGallery(context, galleryBlock.id)
|
||||
val cache = File(cacheDir, "imageCache/${gallery.id}")
|
||||
val data = getCachedGallery(context, gallery.id)
|
||||
cache.deleteRecursively()
|
||||
data.deleteRecursively()
|
||||
|
||||
downloads.remove(galleryBlock.id)
|
||||
downloads.remove(gallery.id)
|
||||
|
||||
if (mode == Mode.DOWNLOAD) {
|
||||
runOnUiThread {
|
||||
@@ -440,7 +444,7 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
(adapter as GalleryBlockAdapter).completeFlag.put(galleryBlock.id, false)
|
||||
(adapter as GalleryBlockAdapter).completeFlag.put(gallery.id, false)
|
||||
}
|
||||
dialog.dismiss()
|
||||
}
|
||||
@@ -583,7 +587,7 @@ class MainActivity : AppCompatActivity() {
|
||||
//BOTTOM
|
||||
|
||||
//Scrolling DOWN
|
||||
if (dist < 0 && currentPage != Math.ceil(totalItems.toDouble()/perPage).roundToInt()-1) {
|
||||
if (dist < 0 && currentPage != ceil(totalItems.toDouble()/perPage).roundToInt()-1) {
|
||||
with(main_recyclerview.adapter as GalleryBlockAdapter) {
|
||||
if(!showNext) {
|
||||
showNext = true
|
||||
@@ -595,7 +599,7 @@ class MainActivity : AppCompatActivity() {
|
||||
getChildAt(childCount-1)
|
||||
}
|
||||
|
||||
val absDist = Math.abs(dist)
|
||||
val absDist = abs(dist)
|
||||
|
||||
if (next is LinearLayout) {
|
||||
val icon = next.findViewById<ImageView>(R.id.icon_next)
|
||||
@@ -701,7 +705,7 @@ class MainActivity : AppCompatActivity() {
|
||||
setMessage(getString(
|
||||
R.string.main_jump_message,
|
||||
currentPage+1,
|
||||
Math.ceil(totalItems / perPage.toDouble()).roundToInt()
|
||||
ceil(totalItems / perPage.toDouble()).roundToInt()
|
||||
))
|
||||
|
||||
setPositiveButton(android.R.string.ok) { _, _ ->
|
||||
@@ -729,10 +733,7 @@ class MainActivity : AppCompatActivity() {
|
||||
val intent = Intent(this@MainActivity, ReaderActivity::class.java)
|
||||
val gallery =
|
||||
getGalleryBlock(editText.text.toString().toInt()) ?: throw Exception()
|
||||
intent.putExtra(
|
||||
"galleryblock",
|
||||
Json(JsonConfiguration.Stable).stringify(GalleryBlock.serializer(), gallery)
|
||||
)
|
||||
intent.putExtra("galleryID", gallery.id)
|
||||
|
||||
startActivity(intent)
|
||||
} catch (e: Exception) {
|
||||
@@ -747,10 +748,17 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
setOnQueryChangeListener { _, query ->
|
||||
this@MainActivity.query = query
|
||||
|
||||
clearSuggestions()
|
||||
|
||||
if (query.isEmpty() or query.endsWith(' '))
|
||||
if (query.isEmpty() or query.endsWith(' ')) {
|
||||
swapSuggestions(json.parse(serializer, favoritesFile.readText()).map {
|
||||
TagSuggestion(it.tag, -1, "", it.area ?: "tag")
|
||||
})
|
||||
|
||||
return@setOnQueryChangeListener
|
||||
}
|
||||
|
||||
val currentQuery = query.split(" ").last().replace('_', ' ')
|
||||
|
||||
@@ -852,8 +860,6 @@ class MainActivity : AppCompatActivity() {
|
||||
delete(if (lastIndexOf(' ') == -1) 0 else lastIndexOf(' ')+1, length)
|
||||
append("${suggestion.n}:${suggestion.s.replace(Regex("\\s"), "_")} ")
|
||||
}
|
||||
|
||||
clearSuggestions()
|
||||
}
|
||||
|
||||
override fun onSearchAction(currentQuery: String?) {
|
||||
@@ -863,7 +869,7 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
setOnFocusChangeListener(object: FloatingSearchView.OnFocusChangeListener {
|
||||
override fun onFocus() {
|
||||
if (searchInputView.text.isEmpty())
|
||||
if (query.isEmpty() or query.endsWith(' '))
|
||||
swapSuggestions(json.parse(serializer, favoritesFile.readText()).map {
|
||||
TagSuggestion(it.tag, -1, "", it.area ?: "tag")
|
||||
})
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.os.Bundle
|
||||
import android.view.*
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.PagerSnapHelper
|
||||
@@ -21,13 +22,8 @@ import kotlinx.android.synthetic.main.dialog_numberpicker.view.*
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.io.IOException
|
||||
import kotlinx.serialization.ImplicitReflectionSerializer
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonConfiguration
|
||||
import xyz.quaver.hitomi.GalleryBlock
|
||||
import xyz.quaver.hitomi.getGalleryBlock
|
||||
import xyz.quaver.pupil.Pupil
|
||||
import xyz.quaver.pupil.R
|
||||
import xyz.quaver.pupil.adapters.ReaderAdapter
|
||||
@@ -37,8 +33,8 @@ import xyz.quaver.pupil.util.ItemClickSupport
|
||||
|
||||
class ReaderActivity : AppCompatActivity() {
|
||||
|
||||
private var galleryID = 0
|
||||
private val images = ArrayList<String>()
|
||||
private lateinit var galleryBlock: GalleryBlock
|
||||
private var gallerySize = 0
|
||||
private var currentPage = 0
|
||||
|
||||
@@ -66,6 +62,9 @@ class ReaderActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
title = getString(R.string.reader_loading)
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(false)
|
||||
|
||||
favorites = (application as Pupil).favorites
|
||||
|
||||
window.setFlags(
|
||||
@@ -76,16 +75,13 @@ class ReaderActivity : AppCompatActivity() {
|
||||
|
||||
handleIntent(intent)
|
||||
|
||||
Crashlytics.setInt("GalleryID", galleryBlock.id)
|
||||
Crashlytics.setInt("GalleryID", galleryID)
|
||||
|
||||
if (!::galleryBlock.isInitialized) {
|
||||
if (galleryID == 0) {
|
||||
onBackPressed()
|
||||
return
|
||||
}
|
||||
|
||||
supportActionBar?.title = galleryBlock.title
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(false)
|
||||
|
||||
initDownloader()
|
||||
|
||||
initView()
|
||||
@@ -106,25 +102,16 @@ class ReaderActivity : AppCompatActivity() {
|
||||
if (uri != null && lastPathSegment != null) {
|
||||
val nonNumber = Regex("[^-?0-9]+")
|
||||
|
||||
val galleryID = when (uri.host) {
|
||||
galleryID = when (uri.host) {
|
||||
"hitomi.la" -> lastPathSegment.replace(nonNumber, "").toInt()
|
||||
"히요비.asia" -> lastPathSegment.toInt()
|
||||
"xn--9w3b15m8vo.asia" -> lastPathSegment.toInt()
|
||||
"e-hentai.org" -> uri.pathSegments[1].toInt()
|
||||
else -> return
|
||||
}
|
||||
|
||||
runBlocking {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
galleryBlock = getGalleryBlock(galleryID) ?: return@launch
|
||||
}.join()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
galleryBlock = Json(JsonConfiguration.Stable).parse(
|
||||
GalleryBlock.serializer(),
|
||||
intent.getStringExtra("galleryblock")!!
|
||||
)
|
||||
galleryID = intent.getIntExtra("galleryID", 0)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,7 +135,7 @@ class ReaderActivity : AppCompatActivity() {
|
||||
with(menu?.findItem(R.id.reader_menu_favorite)) {
|
||||
this ?: return@with
|
||||
|
||||
if (favorites.contains(galleryBlock.id))
|
||||
if (favorites.contains(galleryID))
|
||||
(icon as Animatable).start()
|
||||
}
|
||||
|
||||
@@ -176,7 +163,7 @@ class ReaderActivity : AppCompatActivity() {
|
||||
dialog.show()
|
||||
}
|
||||
R.id.reader_menu_favorite -> {
|
||||
val id = galleryBlock.id
|
||||
val id = galleryID
|
||||
val favorite = menu?.findItem(R.id.reader_menu_favorite) ?: return true
|
||||
|
||||
if (favorites.contains(id)) {
|
||||
@@ -215,11 +202,11 @@ class ReaderActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun initDownloader() {
|
||||
var d: GalleryDownloader? = GalleryDownloader.get(galleryBlock.id)
|
||||
var d: GalleryDownloader? = GalleryDownloader.get(galleryID)
|
||||
|
||||
if (d == null) {
|
||||
try {
|
||||
d = GalleryDownloader(this, galleryBlock)
|
||||
d = GalleryDownloader(this, galleryID)
|
||||
} catch (e: IOException) {
|
||||
Snackbar.make(reader_layout, R.string.unable_to_connect, Snackbar.LENGTH_LONG).show()
|
||||
finish()
|
||||
@@ -230,17 +217,18 @@ class ReaderActivity : AppCompatActivity() {
|
||||
downloader = d.apply {
|
||||
onReaderLoadedHandler = {
|
||||
CoroutineScope(Dispatchers.Main).launch {
|
||||
title = it.title
|
||||
with(reader_download_progressbar) {
|
||||
max = it.size
|
||||
max = it.readerItems.size
|
||||
progress = 0
|
||||
}
|
||||
with(reader_progressbar) {
|
||||
max = it.size
|
||||
max = it.readerItems.size
|
||||
progress = 0
|
||||
}
|
||||
|
||||
gallerySize = it.size
|
||||
menu?.findItem(R.id.reader_menu_page_indicator)?.title = "$currentPage/${it.size}"
|
||||
gallerySize = it.readerItems.size
|
||||
menu?.findItem(R.id.reader_menu_page_indicator)?.title = "$currentPage/${it.readerItems.size}"
|
||||
}
|
||||
}
|
||||
onProgressHandler = {
|
||||
@@ -341,18 +329,24 @@ class ReaderActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
reader_fab_fullscreen.setOnClickListener {
|
||||
isFullscreen = true
|
||||
fullscreen(isFullscreen)
|
||||
with(reader_fab_download) {
|
||||
setImageResource(R.drawable.ic_download)
|
||||
setOnClickListener {
|
||||
downloader.download = !downloader.download
|
||||
|
||||
reader_fab.close(true)
|
||||
if (!downloader.download)
|
||||
downloader.clearNotification()
|
||||
}
|
||||
}
|
||||
|
||||
reader_fab_download.setOnClickListener {
|
||||
downloader.download = !downloader.download
|
||||
with(reader_fab_fullscreen) {
|
||||
setImageResource(R.drawable.ic_fullscreen)
|
||||
setOnClickListener {
|
||||
isFullscreen = true
|
||||
fullscreen(isFullscreen)
|
||||
|
||||
if (!downloader.download)
|
||||
downloader.clearNotification()
|
||||
this@ReaderActivity.reader_fab.close(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user