commit
						3b25991a5d
					
				@ -1,4 +1,4 @@ | 
				
			||||
package io.legado.app.ui.changecover | 
				
			||||
package io.legado.app.ui.book.changecover | 
				
			||||
 | 
				
			||||
import android.app.Application | 
				
			||||
import androidx.lifecycle.MutableLiveData | 
				
			||||
@ -1,4 +1,4 @@ | 
				
			||||
package io.legado.app.ui.changecover | 
				
			||||
package io.legado.app.ui.book.changecover | 
				
			||||
 | 
				
			||||
import android.content.Context | 
				
			||||
import io.legado.app.R | 
				
			||||
@ -1,4 +1,4 @@ | 
				
			||||
package io.legado.app.ui.changesource | 
				
			||||
package io.legado.app.ui.book.changesource | 
				
			||||
 | 
				
			||||
import android.content.Context | 
				
			||||
import android.os.Bundle | 
				
			||||
@ -1,4 +1,4 @@ | 
				
			||||
package io.legado.app.ui.changesource | 
				
			||||
package io.legado.app.ui.book.changesource | 
				
			||||
 | 
				
			||||
import android.app.Application | 
				
			||||
import android.os.Bundle | 
				
			||||
@ -1,4 +1,4 @@ | 
				
			||||
package io.legado.app.ui.changesource | 
				
			||||
package io.legado.app.ui.book.changesource | 
				
			||||
 | 
				
			||||
import android.os.Bundle | 
				
			||||
import androidx.recyclerview.widget.DiffUtil | 
				
			||||
@ -1,4 +1,4 @@ | 
				
			||||
package io.legado.app.ui.chapterlist | 
				
			||||
package io.legado.app.ui.book.chapterlist | 
				
			||||
 | 
				
			||||
import android.os.AsyncTask.execute | 
				
			||||
import android.view.LayoutInflater | 
				
			||||
@ -1,4 +1,4 @@ | 
				
			||||
package io.legado.app.ui.chapterlist | 
				
			||||
package io.legado.app.ui.book.chapterlist | 
				
			||||
 | 
				
			||||
import android.app.Activity | 
				
			||||
import android.content.Intent | 
				
			||||
@ -1,4 +1,4 @@ | 
				
			||||
package io.legado.app.ui.chapterlist | 
				
			||||
package io.legado.app.ui.book.chapterlist | 
				
			||||
 | 
				
			||||
import android.os.Bundle | 
				
			||||
import android.view.Menu | 
				
			||||
@ -1,4 +1,4 @@ | 
				
			||||
package io.legado.app.ui.chapterlist | 
				
			||||
package io.legado.app.ui.book.chapterlist | 
				
			||||
 | 
				
			||||
import android.content.Context | 
				
			||||
import android.widget.TextView | 
				
			||||
@ -1,4 +1,4 @@ | 
				
			||||
package io.legado.app.ui.chapterlist | 
				
			||||
package io.legado.app.ui.book.chapterlist | 
				
			||||
 | 
				
			||||
import android.app.Activity.RESULT_OK | 
				
			||||
import android.content.Intent | 
				
			||||
@ -1,4 +1,4 @@ | 
				
			||||
package io.legado.app.ui.chapterlist | 
				
			||||
package io.legado.app.ui.book.chapterlist | 
				
			||||
 | 
				
			||||
 | 
				
			||||
import android.app.Application | 
				
			||||
@ -1,4 +1,4 @@ | 
				
			||||
package io.legado.app.ui.download | 
				
			||||
package io.legado.app.ui.book.download | 
				
			||||
 | 
				
			||||
import android.content.Context | 
				
			||||
import android.widget.ImageView | 
				
			||||
@ -1,4 +1,4 @@ | 
				
			||||
package io.legado.app.ui.download | 
				
			||||
package io.legado.app.ui.book.download | 
				
			||||
 | 
				
			||||
import android.app.Application | 
				
			||||
import android.net.Uri | 
				
			||||
@ -1,4 +1,4 @@ | 
				
			||||
package io.legado.app.ui.explore | 
				
			||||
package io.legado.app.ui.book.explore | 
				
			||||
 | 
				
			||||
import android.os.Bundle | 
				
			||||
import androidx.lifecycle.Observer | 
				
			||||
@ -1,4 +1,4 @@ | 
				
			||||
package io.legado.app.ui.explore | 
				
			||||
package io.legado.app.ui.book.explore | 
				
			||||
 | 
				
			||||
import android.content.Context | 
				
			||||
import io.legado.app.R | 
				
			||||
@ -1,4 +1,4 @@ | 
				
			||||
package io.legado.app.ui.explore | 
				
			||||
package io.legado.app.ui.book.explore | 
				
			||||
 | 
				
			||||
import android.app.Application | 
				
			||||
import android.content.Intent | 
				
			||||
@ -1,4 +1,4 @@ | 
				
			||||
package io.legado.app.ui.importbook | 
				
			||||
package io.legado.app.ui.book.local | 
				
			||||
 | 
				
			||||
import android.annotation.SuppressLint | 
				
			||||
import android.app.Activity | 
				
			||||
@ -1,4 +1,4 @@ | 
				
			||||
package io.legado.app.ui.importbook | 
				
			||||
package io.legado.app.ui.book.local | 
				
			||||
 | 
				
			||||
import android.content.Context | 
				
			||||
import androidx.documentfile.provider.DocumentFile | 
				
			||||
@ -1,4 +1,4 @@ | 
				
			||||
package io.legado.app.ui.importbook | 
				
			||||
package io.legado.app.ui.book.local | 
				
			||||
 | 
				
			||||
import android.app.Application | 
				
			||||
import android.net.Uri | 
				
			||||
@ -0,0 +1,191 @@ | 
				
			||||
package io.legado.app.ui.filechooser | 
				
			||||
 | 
				
			||||
import android.content.Intent | 
				
			||||
import androidx.appcompat.app.AppCompatActivity | 
				
			||||
import androidx.fragment.app.Fragment | 
				
			||||
import io.legado.app.R | 
				
			||||
import io.legado.app.base.BaseActivity | 
				
			||||
import io.legado.app.help.permission.Permissions | 
				
			||||
import io.legado.app.help.permission.PermissionsCompat | 
				
			||||
import io.legado.app.lib.dialogs.alert | 
				
			||||
import io.legado.app.utils.toast | 
				
			||||
import org.jetbrains.anko.toast | 
				
			||||
 | 
				
			||||
@Suppress("unused") | 
				
			||||
object FilePicker { | 
				
			||||
 | 
				
			||||
    fun selectFolder(activity: AppCompatActivity, requestCode: Int, default: (() -> Unit)? = null) { | 
				
			||||
        activity.alert(titleResource = R.string.select_folder) { | 
				
			||||
            val selectList = | 
				
			||||
                activity.resources.getStringArray(R.array.select_folder).toMutableList() | 
				
			||||
            default ?: let { | 
				
			||||
                selectList.removeAt(0) | 
				
			||||
            } | 
				
			||||
            items(selectList) { _, index -> | 
				
			||||
                when (if (default == null) index + 1 else index) { | 
				
			||||
                    0 -> default?.invoke() | 
				
			||||
                    1 -> { | 
				
			||||
                        try { | 
				
			||||
                            val intent = getSelectDirIntent() | 
				
			||||
                            activity.startActivityForResult(intent, requestCode) | 
				
			||||
                        } catch (e: java.lang.Exception) { | 
				
			||||
                            e.printStackTrace() | 
				
			||||
                            activity.toast(e.localizedMessage ?: "ERROR") | 
				
			||||
                        } | 
				
			||||
                    } | 
				
			||||
                    2 -> checkPermissions(activity) { | 
				
			||||
                        FileChooserDialog.show( | 
				
			||||
                            activity.supportFragmentManager, | 
				
			||||
                            requestCode, | 
				
			||||
                            mode = FileChooserDialog.DIRECTORY | 
				
			||||
                        ) | 
				
			||||
                    } | 
				
			||||
                } | 
				
			||||
            } | 
				
			||||
        }.show() | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    fun selectFolder(fragment: Fragment, requestCode: Int, default: (() -> Unit)? = null) { | 
				
			||||
        fragment.requireContext() | 
				
			||||
            .alert(titleResource = R.string.select_folder) { | 
				
			||||
                val selectList = | 
				
			||||
                    fragment.resources.getStringArray(R.array.select_folder).toMutableList() | 
				
			||||
                default ?: let { | 
				
			||||
                    selectList.removeAt(0) | 
				
			||||
                } | 
				
			||||
                items(selectList) { _, index -> | 
				
			||||
                    when (if (default == null) index + 1 else index) { | 
				
			||||
                        0 -> default?.invoke() | 
				
			||||
                        1 -> { | 
				
			||||
                            try { | 
				
			||||
                                val intent = getSelectDirIntent() | 
				
			||||
                                fragment.startActivityForResult(intent, requestCode) | 
				
			||||
                            } catch (e: java.lang.Exception) { | 
				
			||||
                                e.printStackTrace() | 
				
			||||
                                fragment.toast(e.localizedMessage ?: "ERROR") | 
				
			||||
                            } | 
				
			||||
                        } | 
				
			||||
                        2 -> checkPermissions(fragment) { | 
				
			||||
                            FileChooserDialog.show( | 
				
			||||
                                fragment.childFragmentManager, | 
				
			||||
                                requestCode, | 
				
			||||
                                mode = FileChooserDialog.DIRECTORY | 
				
			||||
                            ) | 
				
			||||
                        } | 
				
			||||
                    } | 
				
			||||
                } | 
				
			||||
            }.show() | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    fun selectFile( | 
				
			||||
        activity: BaseActivity, | 
				
			||||
        requestCode: Int, | 
				
			||||
        type: String, | 
				
			||||
        allowExtensions: Array<String>?, | 
				
			||||
        default: (() -> Unit)? = null | 
				
			||||
    ) { | 
				
			||||
        activity.alert(titleResource = R.string.select_file) { | 
				
			||||
            val selectList = | 
				
			||||
                activity.resources.getStringArray(R.array.select_folder).toMutableList() | 
				
			||||
            default ?: let { | 
				
			||||
                selectList.removeAt(0) | 
				
			||||
            } | 
				
			||||
            items(selectList) { _, index -> | 
				
			||||
                when (if (default == null) index + 1 else index) { | 
				
			||||
                    0 -> default?.invoke() | 
				
			||||
                    1 -> { | 
				
			||||
                        try { | 
				
			||||
                            val intent = getSelectFileIntent() | 
				
			||||
                            intent.type = type//设置类型 | 
				
			||||
                            activity.startActivityForResult(intent, requestCode) | 
				
			||||
                        } catch (e: java.lang.Exception) { | 
				
			||||
                            e.printStackTrace() | 
				
			||||
                            activity.toast(e.localizedMessage ?: "ERROR") | 
				
			||||
                        } | 
				
			||||
                    } | 
				
			||||
                    2 -> checkPermissions(activity) { | 
				
			||||
                        FileChooserDialog.show( | 
				
			||||
                            activity.supportFragmentManager, | 
				
			||||
                            requestCode, | 
				
			||||
                            mode = FileChooserDialog.FILE, | 
				
			||||
                            allowExtensions = allowExtensions | 
				
			||||
                        ) | 
				
			||||
                    } | 
				
			||||
                } | 
				
			||||
            } | 
				
			||||
        }.show() | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    fun selectFile( | 
				
			||||
        fragment: Fragment, | 
				
			||||
        requestCode: Int, | 
				
			||||
        type: String, | 
				
			||||
        allowExtensions: Array<String>, | 
				
			||||
        default: (() -> Unit)? = null | 
				
			||||
    ) { | 
				
			||||
        fragment.requireContext() | 
				
			||||
            .alert(titleResource = R.string.select_file) { | 
				
			||||
                val selectList = | 
				
			||||
                    fragment.resources.getStringArray(R.array.select_folder).toMutableList() | 
				
			||||
                default ?: let { | 
				
			||||
                    selectList.removeAt(0) | 
				
			||||
                } | 
				
			||||
                items(selectList) { _, index -> | 
				
			||||
                    when (if (default == null) index + 1 else index) { | 
				
			||||
                        0 -> default?.invoke() | 
				
			||||
                        1 -> { | 
				
			||||
                            try { | 
				
			||||
                                val intent = getSelectFileIntent() | 
				
			||||
                                intent.type = type//设置类型 | 
				
			||||
                                fragment.startActivityForResult(intent, requestCode) | 
				
			||||
                            } catch (e: java.lang.Exception) { | 
				
			||||
                                e.printStackTrace() | 
				
			||||
                                fragment.toast(e.localizedMessage ?: "ERROR") | 
				
			||||
                            } | 
				
			||||
                        } | 
				
			||||
                        2 -> checkPermissions(fragment) { | 
				
			||||
                            FileChooserDialog.show( | 
				
			||||
                                fragment.childFragmentManager, | 
				
			||||
                                requestCode, | 
				
			||||
                                mode = FileChooserDialog.FILE, | 
				
			||||
                                allowExtensions = allowExtensions | 
				
			||||
                            ) | 
				
			||||
                        } | 
				
			||||
                    } | 
				
			||||
                } | 
				
			||||
            }.show() | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    private fun getSelectFileIntent(): Intent { | 
				
			||||
        val intent = Intent(Intent.ACTION_GET_CONTENT) | 
				
			||||
        intent.addCategory(Intent.CATEGORY_OPENABLE) | 
				
			||||
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) | 
				
			||||
        return intent | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    private fun getSelectDirIntent(): Intent { | 
				
			||||
        val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) | 
				
			||||
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) | 
				
			||||
        return intent | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    private fun checkPermissions(fragment: Fragment, success: (() -> Unit)? = null) { | 
				
			||||
        PermissionsCompat.Builder(fragment) | 
				
			||||
            .addPermissions(*Permissions.Group.STORAGE) | 
				
			||||
            .rationale(R.string.tip_perm_request_storage) | 
				
			||||
            .onGranted { | 
				
			||||
                success?.invoke() | 
				
			||||
            } | 
				
			||||
            .request() | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    private fun checkPermissions(activity: AppCompatActivity, success: (() -> Unit)? = null) { | 
				
			||||
        PermissionsCompat.Builder(activity) | 
				
			||||
            .addPermissions(*Permissions.Group.STORAGE) | 
				
			||||
            .rationale(R.string.tip_perm_request_storage) | 
				
			||||
            .onGranted { | 
				
			||||
                success?.invoke() | 
				
			||||
            } | 
				
			||||
            .request() | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -1,4 +1,4 @@ | 
				
			||||
package io.legado.app.ui.filechooser; | 
				
			||||
package io.legado.app.ui.filechooser.utils; | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * Generated by https://github.com/gzu-liyujiang/Image2ByteVar
 | 
				
			||||
@ -1,14 +1,79 @@ | 
				
			||||
package io.legado.app.ui.login | 
				
			||||
 | 
				
			||||
import android.annotation.SuppressLint | 
				
			||||
import android.graphics.Bitmap | 
				
			||||
import android.os.Bundle | 
				
			||||
import android.view.Menu | 
				
			||||
import android.view.MenuItem | 
				
			||||
import android.webkit.CookieManager | 
				
			||||
import android.webkit.WebView | 
				
			||||
import android.webkit.WebViewClient | 
				
			||||
import io.legado.app.R | 
				
			||||
import io.legado.app.base.BaseActivity | 
				
			||||
import io.legado.app.help.http.CookieStore | 
				
			||||
import io.legado.app.utils.snackbar | 
				
			||||
import kotlinx.android.synthetic.main.activity_source_login.* | 
				
			||||
 | 
				
			||||
 | 
				
			||||
class SourceLogin : BaseActivity(R.layout.activity_source_login) { | 
				
			||||
 | 
				
			||||
    var sourceUrl: String? = null | 
				
			||||
    var loginUrl: String? = null | 
				
			||||
    var checking = false | 
				
			||||
 | 
				
			||||
    override fun onActivityCreated(savedInstanceState: Bundle?) { | 
				
			||||
        sourceUrl = intent.getStringExtra("sourceUrl") | 
				
			||||
        loginUrl = intent.getStringExtra("loginUrl") | 
				
			||||
        title = getString(R.string.login_source, sourceUrl) | 
				
			||||
        initWebView() | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    @SuppressLint("SetJavaScriptEnabled") | 
				
			||||
    private fun initWebView() { | 
				
			||||
        val settings = web_view.settings | 
				
			||||
        settings.setSupportZoom(true) | 
				
			||||
        settings.builtInZoomControls = true | 
				
			||||
        settings.javaScriptEnabled = true | 
				
			||||
        val cookieManager = CookieManager.getInstance() | 
				
			||||
        web_view.webViewClient = object : WebViewClient() { | 
				
			||||
            override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) { | 
				
			||||
                val cookie = cookieManager.getCookie(url) | 
				
			||||
                sourceUrl?.let { | 
				
			||||
                    CookieStore.setCookie(it, cookie) | 
				
			||||
                } | 
				
			||||
                super.onPageStarted(view, url, favicon) | 
				
			||||
            } | 
				
			||||
 | 
				
			||||
            override fun onPageFinished(view: WebView?, url: String?) { | 
				
			||||
                val cookie = cookieManager.getCookie(url) | 
				
			||||
                sourceUrl?.let { | 
				
			||||
                    CookieStore.setCookie(it, cookie) | 
				
			||||
                } | 
				
			||||
                if (checking) { | 
				
			||||
                    finish() | 
				
			||||
                } | 
				
			||||
                super.onPageFinished(view, url) | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
        web_view.loadUrl(loginUrl) | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { | 
				
			||||
        menuInflater.inflate(R.menu.source_login, menu) | 
				
			||||
        return super.onCompatCreateOptionsMenu(menu) | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { | 
				
			||||
        when (item.itemId) { | 
				
			||||
            R.id.menu_success -> { | 
				
			||||
                if (!checking) { | 
				
			||||
                    checking = true | 
				
			||||
                    title_bar.snackbar(R.string.check_host_cookie) | 
				
			||||
                    web_view.loadUrl(sourceUrl) | 
				
			||||
                } | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
        return super.onCompatOptionsItemSelected(item) | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
} | 
				
			||||
Some files were not shown because too many files have changed in this diff Show More
					Loading…
					
					
				
		Reference in new issue