Drop ViewUtils

This commit is contained in:
FooIbar authored and tarsin committed 2023-06-22 10:01:41 +08:00
1 parent e2bf887b94
commit 5d8acd9577
5 files changed
+28 -70

No files matched your search

@@ -21,7 +21,6 @@ import android.view.View
import android.widget.CompoundButton
import android.widget.RadioButton
import androidx.annotation.IdRes
import com.hippo.ehviewer.yorozuya.ViewUtils
class RadioGridGroup : SimpleGridLayout {
/**
@@ -219,7 +218,7 @@ class RadioGridGroup : SimpleGridLayout {
var id = child.getId()
// generates an id if it's missing
if (id == NO_ID) {
id = ViewUtils.generateViewId()
id = generateViewId()
child.setId(id)
}
child.setOnCheckedChangeListener(
@@ -42,7 +42,7 @@ import com.hippo.ehviewer.client.exception.EhException
import com.hippo.ehviewer.databinding.SearchAdvanceBinding
import com.hippo.ehviewer.databinding.SearchCategoryBinding
import com.hippo.ehviewer.databinding.SearchNormalBinding
import com.hippo.ehviewer.yorozuya.ViewUtils
import com.hippo.ehviewer.yorozuya.removeFromParent
@SuppressLint("InflateParams")
class SearchLayout @JvmOverloads constructor(
@@ -285,7 +285,7 @@ class SearchLayout @JvmOverloads constructor(
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SimpleHolder {
val view: View?
if (viewType == ITEM_TYPE_ACTION) {
ViewUtils.removeFromParent(mActionView)
mActionView.removeFromParent()
view = mActionView
} else {
view = mInflater.inflate(R.layout.search_category, parent, false)
@@ -293,19 +293,19 @@ class SearchLayout @JvmOverloads constructor(
when (viewType) {
ITEM_TYPE_NORMAL -> {
categoryTitle.setText(R.string.search_normal)
ViewUtils.removeFromParent(binding.root)
binding.root.removeFromParent()
categoryContent.addView(binding.root)
}
ITEM_TYPE_NORMAL_ADVANCE -> {
categoryTitle.setText(R.string.search_advance)
ViewUtils.removeFromParent(advanceBinding.root)
advanceBinding.root.removeFromParent()
categoryContent.addView(advanceBinding.root)
}
ITEM_TYPE_IMAGE -> {
categoryTitle.setText(R.string.search_image)
ViewUtils.removeFromParent(mImageView)
mImageView.removeFromParent()
categoryContent.addView(mImageView)
}
}
@@ -19,7 +19,6 @@ import android.content.Context
import android.util.AttributeSet
import android.view.ViewGroup
import com.hippo.ehviewer.R
import com.hippo.ehviewer.yorozuya.ViewUtils
/**
* not scrollable
@@ -83,7 +82,7 @@ open class SimpleGridLayout : ViewGroup {
maxWidth = 300
}
if (heightMode == MeasureSpec.UNSPECIFIED) {
maxHeight = ViewUtils.MAX_SIZE
maxHeight = Int.MAX_VALUE and (0x3 shl 30).inv()
}
// Get item width MeasureSpec
@@ -1,61 +0,0 @@
/*
* Copyright 2015 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.yorozuya;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import java.util.concurrent.atomic.AtomicInteger;
public final class ViewUtils {
public static final int MAX_SIZE = Integer.MAX_VALUE & ~(0x3 << 30);
private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
private ViewUtils() {
}
/**
* Remove view from its parent
*
* @param view the view to remove
*/
public static void removeFromParent(View view) {
ViewParent vp = view.getParent();
if (vp instanceof ViewGroup)
((ViewGroup) vp).removeView(view);
}
/**
* Generate a value suitable for use in {@link View#setId(int)}.
* This value will not collide with ID values generated at build time by aapt for R.id.
*
* @return a generated ID value
*/
public static int generateViewId() {
for (; ; ) {
final int result = sNextGeneratedId.get();
// aapt-generated IDs have the high byte nonzero; clamp to the range under that.
int newValue = result + 1;
if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
if (sNextGeneratedId.compareAndSet(result, newValue)) {
return result;
}
}
}
}
@@ -0,0 +1,21 @@
/*
* Copyright 2015 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.yorozuya
import android.view.View
import android.view.ViewGroup
fun View.removeFromParent() = (parent as? ViewGroup)?.removeView(this)