2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-22 18:07:55 +00:00

Migrate list fragments to Kotlin

This commit is contained in:
TPJ Schikhof 2024-10-04 19:48:41 +02:00 committed by Philip Cohn-Cort
parent 7210fd8425
commit 8fea00a843
5 changed files with 85 additions and 109 deletions

View File

@ -95,7 +95,7 @@ class AboutFragment : Fragment() {
setupInfoButton(aboutData.websiteURL, binding!!.websiteButton)
// Update authors
binding!!.authorsList.adapter = ListAdapter(this.context, aboutData.authors.map { AboutPersonEntryItem(it) }, false)
binding!!.authorsList.adapter = ListAdapter(this.requireContext(), aboutData.authors.map { AboutPersonEntryItem(it) }, false)
if (aboutData.authorsFooterText != null) {
binding!!.authorsFooterText.text = context?.getString(aboutData.authorsFooterText!!)
}

View File

@ -3,34 +3,28 @@
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
package org.kde.kdeconnect.UserInterface.List
package org.kde.kdeconnect.UserInterface.List;
import android.graphics.drawable.Drawable
import android.view.LayoutInflater
import android.view.View
import org.kde.kdeconnect_tp.databinding.ListCardEntryBinding
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
open class EntryItemWithIcon : ListAdapter.Item {
protected val title: String
protected val icon: Drawable
import androidx.annotation.NonNull;
import org.kde.kdeconnect_tp.databinding.ListCardEntryBinding;
public class EntryItemWithIcon implements ListAdapter.Item {
protected final String title;
protected final Drawable icon;
public EntryItemWithIcon(String title, Drawable icon) {
this.title = title;
this.icon = icon;
constructor(title: String, icon: Drawable) {
this.title = title
this.icon = icon
}
@NonNull
@Override
public View inflateView(@NonNull LayoutInflater layoutInflater) {
final ListCardEntryBinding binding = ListCardEntryBinding.inflate(layoutInflater);
override fun inflateView(layoutInflater: LayoutInflater): View {
val binding = ListCardEntryBinding.inflate(layoutInflater)
binding.listItemEntryTitle.setText(title);
binding.listItemEntryIcon.setImageDrawable(icon);
binding.listItemEntryTitle.text = title
binding.listItemEntryIcon.setImageDrawable(icon)
return binding.getRoot();
return binding.root
}
}

View File

@ -3,47 +3,34 @@
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
package org.kde.kdeconnect.UserInterface.List
package org.kde.kdeconnect.UserInterface.List;
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
class ListAdapter : ArrayAdapter<ListAdapter.Item> {
private val items: List<Item>
private val isEnabled: Boolean
import androidx.annotation.NonNull;
import java.util.List;
public class ListAdapter extends ArrayAdapter<ListAdapter.Item> {
public interface Item {
@NonNull
View inflateView(@NonNull LayoutInflater layoutInflater);
@JvmOverloads
constructor(context: Context, items: List<Item>, isEnabled: Boolean = true) : super(context, 0, items) {
this.items = items
this.isEnabled = isEnabled
}
private final List<? extends Item> items;
private final boolean isEnabled;
public ListAdapter(Context context, List<? extends Item> items) {
this(context, items, true);
interface Item {
fun inflateView(layoutInflater: LayoutInflater): View
}
public ListAdapter(Context context, List<? extends Item> items, boolean isEnabled) {
super(context, 0, (List<Item>) items);
this.items = items;
this.isEnabled = isEnabled;
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
val i = items[position]
return i.inflateView(LayoutInflater.from(parent.context))
}
@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
final Item i = items.get(position);
return i.inflateView(LayoutInflater.from(parent.getContext()));
}
@Override
public boolean isEnabled(int position) {
return isEnabled;
override fun isEnabled(position: Int): Boolean {
return isEnabled
}
}

View File

@ -3,42 +3,37 @@
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
package org.kde.kdeconnect.UserInterface.List
package org.kde.kdeconnect.UserInterface.List;
import android.view.LayoutInflater
import android.view.View
import org.kde.kdeconnect_tp.databinding.ListItemCategoryBinding
import android.view.LayoutInflater;
import android.view.View;
class SectionItem : ListAdapter.Item {
private val title: String
import androidx.annotation.NonNull;
import org.kde.kdeconnect_tp.databinding.ListItemCategoryBinding;
public class SectionItem implements ListAdapter.Item {
private final String title;
public boolean isEmpty;
public SectionItem(String title) {
this.title = title;
this.isEmpty = true;
constructor(title: String) {
this.title = title
}
@NonNull
@Override
public View inflateView(@NonNull LayoutInflater layoutInflater) {
final ListItemCategoryBinding binding = ListItemCategoryBinding.inflate(layoutInflater);
@JvmField
var isEmpty: Boolean = true
//Make it not selectable
binding.getRoot().setOnClickListener(null);
binding.getRoot().setOnLongClickListener(null);
binding.getRoot().setFocusable(false);
binding.getRoot().setClickable(false);
override fun inflateView(layoutInflater: LayoutInflater): View {
val binding = ListItemCategoryBinding.inflate(layoutInflater)
binding.listItemCategoryText.setText(title);
// Make it not selectable
binding.root.setOnClickListener(null)
binding.root.setOnLongClickListener(null)
binding.root.isFocusable = false
binding.root.isClickable = false
binding.listItemCategoryText.text = title
if (isEmpty) {
binding.listItemCategoryEmptyPlaceholder.setVisibility(View.VISIBLE);
binding.listItemCategoryEmptyPlaceholder.visibility = View.VISIBLE
}
return binding.getRoot();
return binding.root
}
}

View File

@ -3,43 +3,43 @@
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
package org.kde.kdeconnect.UserInterface.List
package org.kde.kdeconnect.UserInterface.List;
import android.R
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
class SmallEntryItem : ListAdapter.Item {
private val title: String
private val clickListener: View.OnClickListener?
import androidx.annotation.NonNull;
public class SmallEntryItem implements ListAdapter.Item {
private final String title;
private final View.OnClickListener clickListener;
SmallEntryItem(String title, View.OnClickListener clickListener) {
this.title = title;
this.clickListener = clickListener;
constructor(title: String, clickListener: View.OnClickListener?) {
this.title = title
this.clickListener = clickListener
}
@NonNull
@Override
public View inflateView(@NonNull LayoutInflater layoutInflater) {
View v = layoutInflater.inflate(android.R.layout.simple_list_item_1, null);
final int padding = (int) (28 * layoutInflater.getContext().getResources().getDisplayMetrics().density);
v.setPadding(padding, 0, padding, 0);
override fun inflateView(layoutInflater: LayoutInflater): View {
val v = layoutInflater.inflate(R.layout.simple_list_item_1, null)
val padding = (28 * layoutInflater.context.resources.displayMetrics.density).toInt()
v.setPadding(padding, 0, padding, 0)
TextView titleView = v.findViewById(android.R.id.text1);
val titleView = v.findViewById<TextView>(R.id.text1)
if (titleView != null) {
titleView.setText(title);
titleView.text = title
if (clickListener != null) {
titleView.setOnClickListener(clickListener);
TypedValue outValue = new TypedValue();
layoutInflater.getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
v.setBackgroundResource(outValue.resourceId);
titleView.setOnClickListener(clickListener)
val outValue = TypedValue()
layoutInflater.context.theme.resolveAttribute(
R.attr.selectableItemBackground,
outValue,
true
)
v.setBackgroundResource(outValue.resourceId)
}
}
return v;
return v
}
}