Android: Convert CustomTitleView to Kotlin
This commit is contained in:
parent
252d3f353a
commit
dff2d8111c
|
@ -1,85 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.ui.main;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.leanback.widget.TitleViewAdapter;
|
||||
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
|
||||
public class CustomTitleView extends LinearLayout implements TitleViewAdapter.Provider
|
||||
{
|
||||
private final TextView mTitleView;
|
||||
private final View mBadgeView;
|
||||
|
||||
private final TitleViewAdapter mTitleViewAdapter = new TitleViewAdapter()
|
||||
{
|
||||
@Override
|
||||
public View getSearchAffordanceView()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(CharSequence titleText)
|
||||
{
|
||||
CustomTitleView.this.setTitle(titleText);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBadgeDrawable(Drawable drawable)
|
||||
{
|
||||
CustomTitleView.this.setBadgeDrawable(drawable);
|
||||
}
|
||||
};
|
||||
|
||||
public CustomTitleView(Context context)
|
||||
{
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public CustomTitleView(Context context, AttributeSet attrs)
|
||||
{
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public CustomTitleView(Context context, AttributeSet attrs, int defStyle)
|
||||
{
|
||||
super(context, attrs, defStyle);
|
||||
View root = LayoutInflater.from(context).inflate(R.layout.tv_title, this);
|
||||
mTitleView = root.findViewById(R.id.title);
|
||||
mBadgeView = root.findViewById(R.id.badge);
|
||||
}
|
||||
|
||||
public void setTitle(CharSequence title)
|
||||
{
|
||||
if (title != null)
|
||||
{
|
||||
mTitleView.setText(title);
|
||||
mTitleView.setVisibility(View.VISIBLE);
|
||||
mBadgeView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
public void setBadgeDrawable(Drawable drawable)
|
||||
{
|
||||
if (drawable != null)
|
||||
{
|
||||
mTitleView.setVisibility(View.GONE);
|
||||
mBadgeView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TitleViewAdapter getTitleViewAdapter()
|
||||
{
|
||||
return mTitleViewAdapter;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.ui.main
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.leanback.widget.TitleViewAdapter
|
||||
import org.dolphinemu.dolphinemu.R
|
||||
|
||||
class CustomTitleView @JvmOverloads constructor(
|
||||
context: Context?,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyle: Int = 0
|
||||
) : LinearLayout(context, attrs, defStyle), TitleViewAdapter.Provider {
|
||||
private val titleView: TextView
|
||||
private val badgeView: View
|
||||
private val titleViewAdapter: TitleViewAdapter = object : TitleViewAdapter() {
|
||||
override fun getSearchAffordanceView(): View? = null
|
||||
|
||||
override fun setTitle(titleText: CharSequence?) = this@CustomTitleView.setTitle(titleText)
|
||||
|
||||
override fun setBadgeDrawable(drawable: Drawable?) =
|
||||
this@CustomTitleView.setBadgeDrawable(drawable)
|
||||
}
|
||||
|
||||
init {
|
||||
val root = LayoutInflater.from(context).inflate(R.layout.tv_title, this)
|
||||
titleView = root.findViewById(R.id.title)
|
||||
badgeView = root.findViewById(R.id.badge)
|
||||
}
|
||||
|
||||
fun setTitle(title: CharSequence?) {
|
||||
if (title != null) {
|
||||
titleView.text = title
|
||||
titleView.visibility = VISIBLE
|
||||
badgeView.visibility = VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
fun setBadgeDrawable(drawable: Drawable?) {
|
||||
if (drawable != null) {
|
||||
titleView.visibility = GONE
|
||||
badgeView.visibility = VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
override fun getTitleViewAdapter(): TitleViewAdapter = titleViewAdapter
|
||||
}
|
Loading…
Reference in New Issue