Cleanup unused code

This commit is contained in:
tarsin committed 2023-05-11 13:59:31 +08:00
1 parent 6ec69ca989
commit 1bb0c1d537
4 files changed
-232

No files matched your search

@@ -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 <reified T : Parcelable> ContentLayout(
state: ContentState<T>,
modifier: Modifier = Modifier,
content: @Composable (LazyPagingItems<T>) -> 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<T : Any>(
val data: PagingSource<Int, T>,
_startPage: MutableState<Int>,
_endPage: MutableState<Int>,
) {
var startPage by _startPage
var endPage by _endPage
}
@Composable
fun <T : Any> rememberContentState(
source: PagingSource<Int, T>,
): ContentState<T> {
val startPage = rememberSaveable { mutableStateOf(0) }
val endPage = rememberSaveable { mutableStateOf(0) }
return remember { ContentState(source, startPage, endPage) }
}
@@ -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);
}
}
@@ -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)
}
}
@@ -1,5 +0,0 @@
package com.hippo.yorozuya
fun assertEquals(expected: Int, actual: Int) {
check(expected == actual)
}