From 1bb0c1d537ed80c605bc6a0ccc8858db4e1e301e Mon Sep 17 00:00:00 2001 From: tarsin Date: Thu, 11 May 2023 13:59:31 +0800 Subject: [PATCH] Cleanup unused code --- .../com/hippo/widget/ComposeContentLayout.kt | 61 ------------ .../widget/SimpleGridAutoSpanLayout.java | 96 ------------------- .../recyclerview/AutoGridLayoutManager.kt | 70 -------------- .../java/com/hippo/yorozuya/AssertUtils.kt | 5 - 4 files changed, 232 deletions(-) delete mode 100644 app/src/main/java/com/hippo/widget/ComposeContentLayout.kt delete mode 100644 app/src/main/java/com/hippo/widget/SimpleGridAutoSpanLayout.java delete mode 100644 app/src/main/java/com/hippo/widget/recyclerview/AutoGridLayoutManager.kt delete mode 100644 app/src/main/java/com/hippo/yorozuya/AssertUtils.kt diff --git a/app/src/main/java/com/hippo/widget/ComposeContentLayout.kt b/app/src/main/java/com/hippo/widget/ComposeContentLayout.kt deleted file mode 100644 index db6cc69aa..000000000 --- a/app/src/main/java/com/hippo/widget/ComposeContentLayout.kt +++ /dev/null @@ -1,61 +0,0 @@ -package com.hippo.widget - -import android.os.Parcelable -import androidx.compose.foundation.layout.Box -import androidx.compose.runtime.Composable -import androidx.compose.runtime.MutableState -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.rememberCoroutineScope -import androidx.compose.runtime.saveable.rememberSaveable -import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.paging.PagingSource -import androidx.paging.compose.LazyPagingItems -import com.hippo.widget.pullrefresh.PullRefreshIndicator -import com.hippo.widget.pullrefresh.pullRefresh -import com.hippo.widget.pullrefresh.rememberPullRefreshState -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch - -@Composable -inline fun ContentLayout( - state: ContentState, - modifier: Modifier = Modifier, - content: @Composable (LazyPagingItems) -> Unit, -) { - var refreshing by rememberSaveable { mutableStateOf(false) } - val coroutineScope = rememberCoroutineScope { Dispatchers.IO } - val refreshState = rememberPullRefreshState(refreshing = refreshing, onRefresh = { - refreshing = true - if (state.startPage == 0) { - coroutineScope.launch { - }.invokeOnCompletion { refreshing = false } - } else { - TODO() - } - }) - Box(modifier = Modifier.pullRefresh(refreshState)) { - PullRefreshIndicator(refreshing = refreshing, state = refreshState, modifier = modifier.align(Alignment.TopCenter)) - } -} - -class ContentState( - val data: PagingSource, - _startPage: MutableState, - _endPage: MutableState, -) { - var startPage by _startPage - var endPage by _endPage -} - -@Composable -fun rememberContentState( - source: PagingSource, -): ContentState { - val startPage = rememberSaveable { mutableStateOf(0) } - val endPage = rememberSaveable { mutableStateOf(0) } - return remember { ContentState(source, startPage, endPage) } -} diff --git a/app/src/main/java/com/hippo/widget/SimpleGridAutoSpanLayout.java b/app/src/main/java/com/hippo/widget/SimpleGridAutoSpanLayout.java deleted file mode 100644 index 8f1f6ad65..000000000 --- a/app/src/main/java/com/hippo/widget/SimpleGridAutoSpanLayout.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2016 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.widget; - -import android.content.Context; -import android.util.AttributeSet; - -public class SimpleGridAutoSpanLayout extends SimpleGridLayout { - - public static final int STRATEGY_MIN_SIZE = 0; - public static final int STRATEGY_SUITABLE_SIZE = 1; - - private int mColumnSize = -1; - private boolean mColumnSizeChanged = true; - private int mStrategy; - - public SimpleGridAutoSpanLayout(Context context) { - super(context); - } - - public SimpleGridAutoSpanLayout(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public SimpleGridAutoSpanLayout(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - } - - public static int getSpanCountForSuitableSize(int total, int single) { - int span = total / single; - if (span <= 0) { - return 1; - } - int span2 = span + 1; - float deviation = Math.abs(1 - (total / span / (float) single)); - float deviation2 = Math.abs(1 - (total / span2 / (float) single)); - return deviation < deviation2 ? span : span2; - } - - public static int getSpanCountForMinSize(int total, int single) { - return Math.max(1, total / single); - } - - public void setColumnSize(int columnSize) { - if (columnSize == mColumnSize) { - return; - } - mColumnSize = columnSize; - mColumnSizeChanged = true; - } - - public void setStrategy(int strategy) { - if (strategy == mStrategy) { - return; - } - mStrategy = strategy; - mColumnSizeChanged = true; - } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - int widthMode = MeasureSpec.getMode(widthMeasureSpec); - int widthSize = MeasureSpec.getSize(widthMeasureSpec); - - if (mColumnSizeChanged && mColumnSize > 0 && widthMode == MeasureSpec.EXACTLY) { - int totalSpace = widthSize - getPaddingRight() - getPaddingLeft(); - int spanCount; - switch (mStrategy) { - default: - case STRATEGY_MIN_SIZE: - spanCount = getSpanCountForMinSize(totalSpace, mColumnSize); - break; - case STRATEGY_SUITABLE_SIZE: - spanCount = getSpanCountForSuitableSize(totalSpace, mColumnSize); - break; - } - setColumnCount(spanCount); - mColumnSizeChanged = false; - } - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - } -} diff --git a/app/src/main/java/com/hippo/widget/recyclerview/AutoGridLayoutManager.kt b/app/src/main/java/com/hippo/widget/recyclerview/AutoGridLayoutManager.kt deleted file mode 100644 index 0f0cd90d7..000000000 --- a/app/src/main/java/com/hippo/widget/recyclerview/AutoGridLayoutManager.kt +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2016 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.widget.recyclerview - -import android.content.Context -import androidx.recyclerview.widget.GridLayoutManager -import androidx.recyclerview.widget.RecyclerView -import androidx.recyclerview.widget.RecyclerView.Recycler - -class AutoGridLayoutManager(context: Context?, columnSize: Int, private var fakePadding: Int = 0) : - GridLayoutManager(context, 1) { - private var mColumnSize = columnSize - private var mColumnSizeChanged = true - private var mStrategy = 0 - - fun setColumnSize(columnSize: Int) { - if (columnSize == mColumnSize) { - return - } - mColumnSize = columnSize - mColumnSizeChanged = true - } - - fun setStrategy(strategy: Int) { - if (strategy == mStrategy) { - return - } - mStrategy = strategy - mColumnSizeChanged = true - } - - override fun onLayoutChildren(recycler: Recycler, state: RecyclerView.State) { - if (mColumnSizeChanged && mColumnSize > 0) { - val totalSpace = if (orientation == RecyclerView.VERTICAL) { - width - paddingRight - paddingLeft - fakePadding - } else { - height - paddingTop - paddingBottom - fakePadding - } - val spanCount = when (mStrategy) { - STRATEGY_MIN_SIZE -> getSpanCountForMinSize( - totalSpace, - mColumnSize, - ) - - STRATEGY_SUITABLE_SIZE -> getSpanCountForSuitableSize( - totalSpace, - mColumnSize, - ) - - else -> getSpanCountForMinSize(totalSpace, mColumnSize) - } - setSpanCount(spanCount) - mColumnSizeChanged = false - } - super.onLayoutChildren(recycler, state) - } -} diff --git a/app/src/main/java/com/hippo/yorozuya/AssertUtils.kt b/app/src/main/java/com/hippo/yorozuya/AssertUtils.kt deleted file mode 100644 index 184618fd7..000000000 --- a/app/src/main/java/com/hippo/yorozuya/AssertUtils.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.hippo.yorozuya - -fun assertEquals(expected: Int, actual: Int) { - check(expected == actual) -}