Skip to content

Commit

Permalink
Updated code so it compiles with the latest SDK
Browse files Browse the repository at this point in the history
Bug Number #5
  • Loading branch information
vivekjishtu committed Dec 26, 2024
1 parent f781138 commit 59cbfb2
Show file tree
Hide file tree
Showing 20 changed files with 68 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package jp.hazuki.yuzubrowser.legacy.action

import android.os.Build
import android.os.Parcel
import android.os.Parcelable
import com.squareup.moshi.JsonReader
Expand All @@ -42,7 +43,12 @@ class Action : ArrayList<SingleAction>, Parcelable, JsonConvertable {
constructor(actions: Collection<SingleAction>) : super(actions)

constructor(source: Parcel) : super() {
source.readList(this, SingleAction::class.java.classLoader)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
source.readList(this, SingleAction::class.java.classLoader, SingleAction::class.java)
} else {
@Suppress("DEPRECATION")
source.readList(this, SingleAction::class.java.classLoader)
}
}

override fun describeContents(): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package jp.hazuki.yuzubrowser.legacy.action

import android.os.Build
import android.os.Parcel
import android.os.Parcelable
import com.squareup.moshi.JsonEncodingException
Expand All @@ -36,7 +37,12 @@ class ActionList : ArrayList<Action>, Parcelable, JsonConvertable {
}

constructor(source: Parcel) : super() {
source.readList(this, Action::class.java.classLoader)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
source.readList(this, Action::class.java.classLoader, Action::class.java)
} else {
@Suppress("DEPRECATION")
source.readList(this, Action::class.java.classLoader)
}
}

override fun describeContents(): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package jp.hazuki.yuzubrowser.legacy.action.item

import android.os.Build
import android.os.Parcel
import android.os.Parcelable
import com.squareup.moshi.JsonReader
Expand Down Expand Up @@ -93,9 +94,15 @@ class CloseAutoSelectAction : SingleAction, Parcelable {
}

private constructor(source: Parcel) : super(source.readInt()) {
defaultAction = source.readParcelable(Action::class.java.classLoader)!!
intentAction = source.readParcelable(Action::class.java.classLoader)!!
windowAction = source.readParcelable(Action::class.java.classLoader)!!
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
defaultAction = source.readParcelable(Action::class.java.classLoader, Action::class.java)!!
intentAction = source.readParcelable(Action::class.java.classLoader, Action::class.java)!!
windowAction = source.readParcelable(Action::class.java.classLoader, Action::class.java)!!
} else @Suppress("DEPRECATION"){
defaultAction = source.readParcelable(Action::class.java.classLoader)!!
intentAction = source.readParcelable(Action::class.java.classLoader)!!
windowAction = source.readParcelable(Action::class.java.classLoader)!!
}
}

override fun showSubPreference(context: ActionActivity): StartActivityInfo? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package jp.hazuki.yuzubrowser.legacy.action.item

import android.os.Build
import android.os.Parcel
import android.os.Parcelable
import com.squareup.moshi.JsonReader
Expand Down Expand Up @@ -74,7 +75,12 @@ class CloseTabSingleAction : SingleAction, Parcelable {
}

private constructor(source: Parcel) : super(source.readInt()) {
defaultAction = source.readParcelable(Action::class.java.classLoader)!!
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
defaultAction = source.readParcelable(Action::class.java.classLoader, Action::class.java)!!
} else {
@Suppress("DEPRECATION")
defaultAction = source.readParcelable(Action::class.java.classLoader)!!
}
}

override fun showSubPreference(context: ActionActivity): StartActivityInfo? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@

package jp.hazuki.yuzubrowser.legacy.action.item

import android.os.Build
import android.os.Parcel
import android.os.Parcelable
import com.squareup.moshi.JsonReader
import com.squareup.moshi.JsonWriter
import jp.hazuki.yuzubrowser.legacy.R
import jp.hazuki.yuzubrowser.legacy.action.Action
import jp.hazuki.yuzubrowser.legacy.action.ActionList
import jp.hazuki.yuzubrowser.legacy.action.SingleAction
import jp.hazuki.yuzubrowser.legacy.action.view.ActionActivity
Expand Down Expand Up @@ -70,7 +72,12 @@ class CustomMenuSingleAction : SingleAction, Parcelable {
}

private constructor(source: Parcel) : super(source.readInt()) {
actionList = source.readParcelable(ActionList::class.java.classLoader)!!
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
actionList = source.readParcelable(ActionList::class.java.classLoader, ActionList::class.java)!!
} else {
@Suppress("DEPRECATION")
actionList = source.readParcelable(ActionList::class.java.classLoader)!!
}
}

override fun showMainPreference(context: ActionActivity): StartActivityInfo? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SoftButtonActionViewModel(
class Factory(
private val actionNames: ActionNameMap,
private val actionIcons: ActionIconMap,
) : ViewModelProvider.Factory {
) : ViewModelProvider.AndroidViewModelFactory() {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
@Suppress("UNCHECKED_CAST")
return SoftButtonActionViewModel(actionNames, actionIcons) as T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class FileBrowserViewModel(

class Factory(
private val root: File
) : ViewModelProvider.Factory {
) :ViewModelProvider.AndroidViewModelFactory(){
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return FileBrowserViewModel(root) as T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class FileEditViewModel(
}
}

class Factory(val file: File) : ViewModelProvider.Factory {
class Factory(val file: File) :ViewModelProvider.AndroidViewModelFactory(){
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return FileEditViewModel(file) as T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class WebPermissionActivity : ThemeActivity() {
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
android.R.id.home -> {
onBackPressed()
onBackPressedDispatcher.onBackPressed()
return true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ package jp.hazuki.yuzubrowser.legacy.webrtc.ui
import android.app.AlertDialog
import android.app.Dialog
import android.content.Context
import android.os.Build
import android.os.Bundle
import android.view.View
import android.widget.Spinner
import jp.hazuki.yuzubrowser.legacy.R
import jp.hazuki.yuzubrowser.legacy.webrtc.core.PermissionState
import jp.hazuki.yuzubrowser.legacy.webrtc.core.WebPermissions


class WebPermissionsEditDialog : androidx.fragment.app.DialogFragment() {

private var listener: OnPermissionEditedListener? = null
Expand All @@ -39,7 +41,13 @@ class WebPermissionsEditDialog : androidx.fragment.app.DialogFragment() {
val midi: Spinner = view.findViewById(R.id.midiSpinner)
val mediaId: Spinner = view.findViewById(R.id.mediaIdSpinner)

val permissions = arguments.getSerializable(ARG_PERMISSION) as WebPermissions

val permissions = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
arguments.getSerializable(ARG_PERMISSION, WebPermissions::class.java) as WebPermissions
} else {
@Suppress("DEPRECATION")
arguments.getSerializable(ARG_PERMISSION) as WebPermissions
}

camera.setSelection(permissions.camera.state)
mic.setSelection(permissions.microphone.state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private fun WebResourceRequest.getContentType(pageUri: Uri): Int {
val path = url.path ?: url.toString()
val lastDot = path.lastIndexOf('.')
if (lastDot >= 0) {
when (val extension = path.substring(lastDot + 1).toLowerCase(Locale.ENGLISH)) {
when (val extension = path.substring(lastDot + 1).lowercase(Locale.ENGLISH)) {
"js" -> return type or ContentRequest.TYPE_SCRIPT
"css" -> return type or ContentRequest.TYPE_STYLE_SHEET
"otf", "ttf", "ttc", "woff", "woff2" -> return type or ContentRequest.TYPE_FONT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class AbpFilterDecoder {
option = option.substring(1)
}

option = option.toLowerCase(Locale.ENGLISH)
option = option.lowercase(Locale.ENGLISH)
val type = option.getOptionBit()
if (type == -1) return

Expand Down Expand Up @@ -335,7 +335,7 @@ class AbpFilterDecoder {
val comment = split(':')
if (comment.size < 2) return null

when (comment[0].substring(1).trim().toLowerCase(Locale.getDefault())) {
when (comment[0].substring(1).trim().lowercase(Locale.getDefault())) {
"title" -> info.title = comment[1].trim()
"homepage" -> info.homePage = comment[1].trim()
"last updated" -> info.lastUpdate = comment[1].trim()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class PatternMatchFilter(
continue@loop
}
'^' -> if (!nu.checkSeparator()) continue@loop
else -> if (!ignoreCase || nu.toUpperCase() != np.toUpperCase()) {
else -> if (!ignoreCase || nu.uppercaseChar() != np.uppercaseChar()) {
if (isStartWith) {
val next = url.nextPoint(i)
if (next < 0) return false
Expand All @@ -133,14 +133,14 @@ class PatternMatchFilter(
for (i in start until length) {
val c2 = this[i]
if (c == c2) return i
if (ignoreCase && c.toUpperCase() == c2.toUpperCase()) return i
if (ignoreCase && c.uppercaseChar() == c2.uppercaseChar()) return i
}
return -1
}

private fun String.searchSeparator(start: Int): Int {
for (i in start until length) {
val it = this[i].toInt()
val it = this[i].code
if (it in 0..0x24 || it in 0x26..0x2c || it == 0x2f || it in 0x3a..0x40 ||
it in 0x5b..0x5e || it == 0x60 || it in 0x7b..0x7f) {
return i
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import java.util.*

object Tag {
fun create(url: String): List<String> {
return url.toLowerCase(Locale.ENGLISH).getTagCandidates().also {
return url.lowercase(Locale.ENGLISH).getTagCandidates().also {
it += ""
}
}
Expand All @@ -29,7 +29,7 @@ object Tag {
var maxLength = 0
var tag = ""

val candidates = pattern.toLowerCase(Locale.ENGLISH).getTagCandidates()
val candidates = pattern.lowercase(Locale.ENGLISH).getTagCandidates()
for (i in 0 until candidates.size) {
val candidate = candidates[i]
if (candidate.length > maxLength) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ abstract class UnifiedFilter(
}

protected fun Char.checkSeparator(): Boolean {
val it = this.toInt()
val it = this.code
return it in 0..0x24 || it in 0x26..0x2c || it == 0x2f || it in 0x3a..0x40 ||
it in 0x5b..0x5e || it == 0x60 || it in 0x7b..0x7f
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ElementContainer {
}

operator fun get(url: Uri, isUseGeneric: Boolean): List<ElementFilter> {
val host = (url.host ?: return emptyList()).toLowerCase(Locale.ROOT)
val host = (url.host ?: return emptyList()).lowercase(Locale.ROOT)
val tldRemoved = host.removeEffectiveTld()

val list = mutableListOf<ElementFilter>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class OverflowMenuViewModel @Inject constructor(
class Factory(
private val application: Application,
private val repository: HideMenuRepository
) : ViewModelProvider.Factory {
) :ViewModelProvider.AndroidViewModelFactory(){

override fun <T : ViewModel> create(modelClass: Class<T>): T {
@Suppress("UNCHECKED_CAST")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ class LiveEvent<T> {

private var isActive = true

override fun onStateChanged(owner: LifecycleOwner, event: Lifecycle.Event) {
if (owner.lifecycle.currentState == Lifecycle.State.DESTROYED) {
override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) {
if (source.lifecycle.currentState == Lifecycle.State.DESTROYED) {
remove(this)
return
}

isActive = isActive(owner)
isActive = isActive(source)
}

fun notify(data: T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ internal class SearchViewModel @Inject constructor(
class Factory(
private val application: Application,
private val useCase: SearchViewUseCase
) : ViewModelProvider.Factory {
) :ViewModelProvider.AndroidViewModelFactory(){

override fun <T : ViewModel> create(modelClass: Class<T>): T {
@Suppress("UNCHECKED_CAST")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ internal class SearchSettingsViewModel(
class Factory(
private val application: Application,
private val useCase: SearchSettingsViewUseCase
) : ViewModelProvider.Factory {
) :ViewModelProvider.AndroidViewModelFactory(){

override fun <T : ViewModel> create(modelClass: Class<T>): T {
@Suppress("UNCHECKED_CAST")
Expand Down

0 comments on commit 59cbfb2

Please sign in to comment.