Proxy implemented
This commit is contained in:
@@ -31,7 +31,9 @@ import com.google.android.gms.common.GooglePlayServicesNotAvailableException
|
||||
import com.google.android.gms.common.GooglePlayServicesRepairableException
|
||||
import com.google.android.gms.security.ProviderInstaller
|
||||
import com.google.firebase.analytics.FirebaseAnalytics
|
||||
import xyz.quaver.proxy
|
||||
import xyz.quaver.pupil.util.Histories
|
||||
import xyz.quaver.pupil.util.getProxy
|
||||
import java.io.File
|
||||
|
||||
class Pupil : MultiDexApplication() {
|
||||
@@ -46,6 +48,8 @@ class Pupil : MultiDexApplication() {
|
||||
override fun onCreate() {
|
||||
val preference = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
|
||||
proxy = getProxy(this)
|
||||
|
||||
try {
|
||||
preference.getString("dl_location", null)
|
||||
} catch (e: Exception) {
|
||||
|
||||
@@ -83,15 +83,6 @@ class ReaderAdapter(private val context: Context,
|
||||
|
||||
var onItemClickListener : ((Int) -> (Unit))? = null
|
||||
|
||||
init {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
reader = Cache(context).getReader(galleryID)
|
||||
launch(Dispatchers.Main) {
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ViewHolder(val view: View) : RecyclerView.ViewHolder(view)
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.content.Intent
|
||||
import android.graphics.drawable.Animatable
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.*
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
@@ -238,9 +239,11 @@ class ReaderActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
timer.schedule(1000, 1000) {
|
||||
Log.i("PUPILD", "TIMER")
|
||||
if (worker.progress.indexOfKey(galleryID) < 0) //loading
|
||||
return@schedule
|
||||
|
||||
Log.i("PUPILD", "LOADEND")
|
||||
if (worker.progress[galleryID] == null) { //Gallery not found
|
||||
timer.cancel()
|
||||
Snackbar
|
||||
@@ -248,15 +251,25 @@ class ReaderActivity : AppCompatActivity() {
|
||||
.show()
|
||||
}
|
||||
|
||||
Log.i("PUPILD", "GALLERY")
|
||||
runOnUiThread {
|
||||
Log.i("PUPILD", "UI")
|
||||
reader_download_progressbar.max = reader_recyclerview.adapter?.itemCount ?: 0
|
||||
reader_download_progressbar.progress = worker.progress[galleryID]?.count { !it.isFinite() } ?: 0
|
||||
reader_progressbar.max = reader_recyclerview.adapter?.itemCount ?: 0
|
||||
|
||||
Log.i("PUPILD", "COUNTEND")
|
||||
if (title == getString(R.string.reader_loading)) {
|
||||
val reader = (reader_recyclerview.adapter as ReaderAdapter).reader
|
||||
Log.i("PUPILD", "LOADING")
|
||||
val reader = Cache(this@ReaderActivity).getReaderOrNull(galleryID)
|
||||
|
||||
Log.i("PUPILD", "READER")
|
||||
if (reader != null) {
|
||||
Log.i("PUPILD", "NOTNULL")
|
||||
with (reader_recyclerview?.adapter as ReaderAdapter) {
|
||||
this.reader = reader
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
title = reader.title
|
||||
menu?.findItem(R.id.reader_menu_page_indicator)?.title = "$currentPage/${reader.galleryInfo.size}"
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import android.widget.AdapterView
|
||||
import android.widget.ArrayAdapter
|
||||
import androidx.preference.PreferenceManager
|
||||
import kotlinx.android.synthetic.main.dialog_proxy.view.*
|
||||
import xyz.quaver.proxy
|
||||
import xyz.quaver.pupil.R
|
||||
import xyz.quaver.pupil.util.ProxyInfo
|
||||
import xyz.quaver.pupil.util.getProxyInfo
|
||||
@@ -114,9 +115,14 @@ class ProxyDialog(context: Context) : Dialog(context) {
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putString("proxy",
|
||||
json.stringify(ProxyInfo.serializer(), ProxyInfo(type, addr, port, username, password))
|
||||
).apply()
|
||||
ProxyInfo(type, addr, port, username, password).let {
|
||||
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putString("proxy",
|
||||
json.stringify(ProxyInfo.serializer(), it)
|
||||
).apply()
|
||||
|
||||
proxy = it.proxy()
|
||||
}
|
||||
|
||||
dismiss()
|
||||
}
|
||||
|
||||
@@ -155,9 +155,11 @@ class Cache(context: Context) : ContextWrapper(context) {
|
||||
var retval: Reader? = null
|
||||
|
||||
for (source in sources) {
|
||||
retval = kotlin.runCatching {
|
||||
retval = try {
|
||||
source.value.invoke()
|
||||
}.getOrNull()
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
|
||||
if (retval != null)
|
||||
break
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.content.Context
|
||||
import android.content.ContextWrapper
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.util.Log
|
||||
import android.util.SparseArray
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
@@ -40,9 +41,9 @@ import xyz.quaver.hitomi.urlFromUrlFromHash
|
||||
import xyz.quaver.hiyobi.cookie
|
||||
import xyz.quaver.hiyobi.createImgList
|
||||
import xyz.quaver.hiyobi.user_agent
|
||||
import xyz.quaver.proxy
|
||||
import xyz.quaver.pupil.R
|
||||
import xyz.quaver.pupil.ui.ReaderActivity
|
||||
import xyz.quaver.pupil.util.getProxy
|
||||
import java.io.IOException
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.LinkedBlockingQueue
|
||||
@@ -160,7 +161,7 @@ class DownloadWorker private constructor(context: Context) : ContextWrapper(cont
|
||||
OkHttpClient.Builder()
|
||||
.addInterceptor(interceptor)
|
||||
.dispatcher(Dispatcher(Executors.newFixedThreadPool(4)))
|
||||
.proxy(getProxy(this))
|
||||
.proxy(proxy)
|
||||
.build()
|
||||
|
||||
fun stop() {
|
||||
@@ -263,6 +264,8 @@ class DownloadWorker private constructor(context: Context) : ContextWrapper(cont
|
||||
}.toMutableList())
|
||||
exception.put(galleryID, reader.galleryInfo.map { null }.toMutableList())
|
||||
|
||||
Log.i("PUPILD", "READER HERE!")
|
||||
|
||||
if (notification[galleryID] == null)
|
||||
initNotification(galleryID)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user