Merge branch 'master' into devel
This commit is contained in:
@@ -56,16 +56,18 @@ abstract class BaseActivity<B : ViewBinding> : AppCompatActivity(), OnApplyWindo
|
||||
protected fun setContentView(binding: B) {
|
||||
this.binding = binding
|
||||
super.setContentView(binding.root)
|
||||
(binding.root.findViewById<View>(R.id.toolbar) as? Toolbar)?.let(this::setSupportActionBar)
|
||||
val toolbarParams = (binding.root.findViewById<View>(R.id.toolbar) as? Toolbar)?.layoutParams as? AppBarLayout.LayoutParams
|
||||
val persistentToolbarParams = (binding.root.findViewById<View>(R.id.toolbar_card))?.layoutParams as? AppBarLayout.LayoutParams
|
||||
val toolbar = (binding.root.findViewById<View>(R.id.toolbar) as? Toolbar)
|
||||
toolbar?.let(this::setSupportActionBar)
|
||||
ViewCompat.setOnApplyWindowInsetsListener(binding.root, this)
|
||||
if (get<AppSettings>().isToolbarHideWhenScrolling) {
|
||||
toolbarParams?.scrollFlags = SCROLL_FLAG_SCROLL or SCROLL_FLAG_ENTER_ALWAYS
|
||||
persistentToolbarParams?.scrollFlags = SCROLL_FLAG_SCROLL or SCROLL_FLAG_ENTER_ALWAYS
|
||||
} else {
|
||||
toolbarParams?.scrollFlags = SCROLL_FLAG_NO_SCROLL
|
||||
persistentToolbarParams?.scrollFlags = SCROLL_FLAG_NO_SCROLL
|
||||
|
||||
val toolbarParams = (toolbar ?: binding.root.findViewById<View>(R.id.toolbar_card))
|
||||
?.layoutParams as? AppBarLayout.LayoutParams
|
||||
if (toolbarParams != null) {
|
||||
if (get<AppSettings>().isToolbarHideWhenScrolling) {
|
||||
toolbarParams.scrollFlags = SCROLL_FLAG_SCROLL or SCROLL_FLAG_ENTER_ALWAYS
|
||||
} else {
|
||||
toolbarParams.scrollFlags = SCROLL_FLAG_NO_SCROLL
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -166,6 +166,7 @@ class AppSettings private constructor(private val prefs: SharedPreferences) :
|
||||
const val KEY_LOCAL_STORAGE = "local_storage"
|
||||
const val KEY_READER_SWITCHERS = "reader_switchers"
|
||||
const val KEY_TRACK_SOURCES = "track_sources"
|
||||
const val KEY_TRACK_WARNING = "track_warning"
|
||||
const val KEY_APP_UPDATE = "app_update"
|
||||
const val KEY_APP_UPDATE_AUTO = "app_update_auto"
|
||||
const val KEY_TRACKER_NOTIFICATIONS = "tracker_notifications"
|
||||
|
||||
@@ -220,7 +220,7 @@ class ReaderActivity : BaseFullscreenActivity<ActivityReaderBinding>(),
|
||||
}
|
||||
|
||||
override fun onGridTouch(area: Int) {
|
||||
controlDelegate.onGridTouch(area)
|
||||
controlDelegate.onGridTouch(area, binding.container)
|
||||
}
|
||||
|
||||
override fun onProcessTouch(rawX: Int, rawY: Int): Boolean {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.koitharu.kotatsu.reader.ui
|
||||
|
||||
import android.view.KeyEvent
|
||||
import android.view.SoundEffectConstants
|
||||
import android.view.View
|
||||
import androidx.lifecycle.LifecycleCoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.*
|
||||
@@ -30,18 +32,27 @@ class ReaderControlDelegate(
|
||||
}.launchIn(scope)
|
||||
}
|
||||
|
||||
fun onGridTouch(area: Int) {
|
||||
fun onGridTouch(area: Int, view: View) {
|
||||
when (area) {
|
||||
GridTouchHelper.AREA_CENTER -> {
|
||||
listener.toggleUiVisibility()
|
||||
view.playSoundEffect(SoundEffectConstants.CLICK)
|
||||
}
|
||||
GridTouchHelper.AREA_TOP -> if (isTapSwitchEnabled) {
|
||||
listener.switchPageBy(-1)
|
||||
view.playSoundEffect(SoundEffectConstants.NAVIGATION_UP)
|
||||
}
|
||||
GridTouchHelper.AREA_TOP,
|
||||
GridTouchHelper.AREA_LEFT -> if (isTapSwitchEnabled) {
|
||||
listener.switchPageBy(-1)
|
||||
view.playSoundEffect(SoundEffectConstants.NAVIGATION_LEFT)
|
||||
}
|
||||
GridTouchHelper.AREA_BOTTOM -> if (isTapSwitchEnabled) {
|
||||
listener.switchPageBy(1)
|
||||
view.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN)
|
||||
}
|
||||
GridTouchHelper.AREA_BOTTOM,
|
||||
GridTouchHelper.AREA_RIGHT -> if (isTapSwitchEnabled) {
|
||||
listener.switchPageBy(1)
|
||||
view.playSoundEffect(SoundEffectConstants.NAVIGATION_RIGHT)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import android.text.style.URLSpan
|
||||
import androidx.core.text.buildSpannedString
|
||||
import androidx.core.text.inSpans
|
||||
import androidx.preference.MultiSelectListPreference
|
||||
import androidx.preference.Preference
|
||||
import org.koitharu.kotatsu.R
|
||||
@@ -19,6 +22,17 @@ class TrackerSettingsFragment : BasePreferenceFragment(R.string.new_chapters_che
|
||||
|
||||
findPreference<MultiSelectListPreference>(AppSettings.KEY_TRACK_SOURCES)
|
||||
?.summaryProvider = MultiSummaryProvider(R.string.dont_check)
|
||||
val warningPreference = findPreference<Preference>(AppSettings.KEY_TRACK_WARNING)
|
||||
if (warningPreference != null) {
|
||||
warningPreference.summary = buildSpannedString {
|
||||
append(getString(R.string.tracker_warning))
|
||||
append(" ")
|
||||
inSpans(URLSpan("https://dontkillmyapp.com/")) {
|
||||
append(getString(R.string.read_more))
|
||||
}
|
||||
}
|
||||
warningPreference
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPreferenceTreeClick(preference: Preference?): Boolean {
|
||||
|
||||
@@ -1,27 +1,41 @@
|
||||
package org.koitharu.kotatsu.settings.backup
|
||||
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.view.isVisible
|
||||
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.base.ui.AlertDialogFragment
|
||||
import org.koitharu.kotatsu.databinding.DialogProgressBinding
|
||||
import org.koitharu.kotatsu.utils.ShareHelper
|
||||
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||
import org.koitharu.kotatsu.utils.progress.Progress
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
|
||||
class BackupDialogFragment : AlertDialogFragment<DialogProgressBinding>() {
|
||||
|
||||
private val viewModel by viewModel<BackupViewModel>(mode = LazyThreadSafetyMode.NONE)
|
||||
|
||||
private var backup: File? = null
|
||||
private val saveFileContract =
|
||||
registerForActivityResult(ActivityResultContracts.CreateDocument()) { uri ->
|
||||
val file = backup
|
||||
if (uri != null && file != null) {
|
||||
saveBackup(file, uri)
|
||||
} else {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onInflateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?
|
||||
container: ViewGroup?,
|
||||
) = DialogProgressBinding.inflate(inflater, container, false)
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
@@ -60,8 +74,22 @@ class BackupDialogFragment : AlertDialogFragment<DialogProgressBinding>() {
|
||||
}
|
||||
|
||||
private fun onBackupDone(file: File) {
|
||||
ShareHelper(context ?: return).shareBackup(file)
|
||||
dismiss()
|
||||
this.backup = file
|
||||
saveFileContract.launch(file.name)
|
||||
}
|
||||
|
||||
private fun saveBackup(file: File, output: Uri) {
|
||||
try {
|
||||
requireContext().contentResolver.openFileDescriptor(output, "w")?.use { fd ->
|
||||
FileOutputStream(fd.fileDescriptor).use {
|
||||
it.write(file.readBytes())
|
||||
}
|
||||
}
|
||||
Toast.makeText(requireContext(), R.string.backup_saved, Toast.LENGTH_LONG).show()
|
||||
dismiss()
|
||||
} catch (e: Exception) {
|
||||
onError(e)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.koitharu.kotatsu.settings.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.text.method.LinkMovementMethod
|
||||
import android.util.AttributeSet
|
||||
import android.widget.TextView
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceViewHolder
|
||||
|
||||
class LinksPreference @JvmOverloads constructor(
|
||||
context: Context?,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = androidx.preference.R.attr.preferenceStyle,
|
||||
defStyleRes: Int = 0,
|
||||
) : Preference(context, attrs, defStyleAttr, defStyleRes) {
|
||||
|
||||
|
||||
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
||||
super.onBindViewHolder(holder)
|
||||
val summaryView = holder.findViewById(android.R.id.summary) as TextView
|
||||
summaryView.movementMethod = LinkMovementMethod.getInstance()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user