Convert BezelImageView, EndlessOnScrollListener, ComposeScheduleView, ProgressImageView to Kotlin (#3147)

* Convert BezelImageView to Kotlin

* Convert EndlessOnScrollListener to Kotlin

* Convert ComposeScheduleView to use view binding

* Convert ComposeScheduleView to Kotlin

* Convert ProgressImageView to Kotlin

* Apply reviewer feedback
This commit is contained in:
Nik Clayton 2023-01-13 19:49:56 +01:00 committed by GitHub
commit e5e076b0d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 410 additions and 485 deletions

View file

@ -1,61 +0,0 @@
/* Copyright 2019 Tusky contributors
*
* This file is a part of Tusky.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Tusky; if not,
* see <http://www.gnu.org/licenses>. */
package com.keylesspalace.tusky.view;
import android.content.Context;
import android.graphics.Outline;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewOutlineProvider;
/**
* override BezelImageView from MaterialDrawer library to provide custom outline
*/
public class BezelImageView extends com.mikepenz.materialdrawer.view.BezelImageView {
public BezelImageView(Context context) {
this(context, null);
}
public BezelImageView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public BezelImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onSizeChanged(int w, int h, int old_w, int old_h) {
setOutlineProvider(new CustomOutline(w, h));
}
private static class CustomOutline extends ViewOutlineProvider {
int width;
int height;
CustomOutline(int width, int height) {
this.width = width;
this.height = height;
}
@Override
public void getOutline(View view, Outline outline) {
outline.setRoundRect(0, 0, width, height, width < height ? width / 8f : height / 8f);
}
}
}

View file

@ -0,0 +1,48 @@
/* Copyright 2019 Tusky contributors
*
* This file is a part of Tusky.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Tusky; if not,
* see <http://www.gnu.org/licenses>. */
package com.keylesspalace.tusky.view
import android.content.Context
import android.graphics.Outline
import android.util.AttributeSet
import android.view.View
import android.view.ViewOutlineProvider
import com.mikepenz.materialdrawer.view.BezelImageView
/**
* override BezelImageView from MaterialDrawer library to provide custom outline
*/
class BezelImageView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyle: Int = 0
) : BezelImageView(context, attrs, defStyle) {
override fun onSizeChanged(w: Int, h: Int, old_w: Int, old_h: Int) {
outlineProvider = CustomOutline(w, h)
}
private class CustomOutline(var width: Int, var height: Int) :
ViewOutlineProvider() {
override fun getOutline(view: View, outline: Outline) {
outline.setRoundRect(
0,
0,
width,
height,
if (width < height) width / 8f else height / 8f
)
}
}
}

View file

@ -1,54 +0,0 @@
/* Copyright 2017 Andrew Dawson
*
* This file is a part of Tusky.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Tusky; if not,
* see <http://www.gnu.org/licenses>. */
package com.keylesspalace.tusky.view;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
public abstract class EndlessOnScrollListener extends RecyclerView.OnScrollListener {
private static final int VISIBLE_THRESHOLD = 15;
private int previousTotalItemCount;
private LinearLayoutManager layoutManager;
public EndlessOnScrollListener(LinearLayoutManager layoutManager) {
this.layoutManager = layoutManager;
previousTotalItemCount = 0;
}
@Override
public void onScrolled(@NonNull RecyclerView view, int dx, int dy) {
int totalItemCount = layoutManager.getItemCount();
int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition();
if (totalItemCount < previousTotalItemCount) {
previousTotalItemCount = totalItemCount;
}
if (totalItemCount != previousTotalItemCount) {
previousTotalItemCount = totalItemCount;
}
if (lastVisibleItemPosition + VISIBLE_THRESHOLD > totalItemCount) {
onLoadMore(totalItemCount, view);
}
}
public void reset() {
previousTotalItemCount = 0;
}
public abstract void onLoadMore(int totalItemsCount, RecyclerView view);
}

View file

@ -0,0 +1,48 @@
/* Copyright 2017 Andrew Dawson
*
* This file is a part of Tusky.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Tusky; if not,
* see <http://www.gnu.org/licenses>. */
package com.keylesspalace.tusky.view
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
abstract class EndlessOnScrollListener(private val layoutManager: LinearLayoutManager) :
RecyclerView.OnScrollListener() {
private var previousTotalItemCount = 0
override fun onScrolled(view: RecyclerView, dx: Int, dy: Int) {
val totalItemCount = layoutManager.itemCount
val lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition()
if (totalItemCount < previousTotalItemCount) {
previousTotalItemCount = totalItemCount
}
if (totalItemCount != previousTotalItemCount) {
previousTotalItemCount = totalItemCount
}
if (lastVisibleItemPosition + VISIBLE_THRESHOLD > totalItemCount) {
onLoadMore(totalItemCount, view)
}
}
fun reset() {
previousTotalItemCount = 0
}
abstract fun onLoadMore(totalItemsCount: Int, view: RecyclerView)
companion object {
private const val VISIBLE_THRESHOLD = 15
}
}