diff --git a/src/org/kde/kdeconnect/UserInterface/About/AboutFragment.kt b/src/org/kde/kdeconnect/UserInterface/About/AboutFragment.kt index e9a760ff..3e5da530 100644 --- a/src/org/kde/kdeconnect/UserInterface/About/AboutFragment.kt +++ b/src/org/kde/kdeconnect/UserInterface/About/AboutFragment.kt @@ -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!!) } diff --git a/src/org/kde/kdeconnect/UserInterface/List/EntryItemWithIcon.kt b/src/org/kde/kdeconnect/UserInterface/List/EntryItemWithIcon.kt index 22e47e1a..a7aa6829 100644 --- a/src/org/kde/kdeconnect/UserInterface/List/EntryItemWithIcon.kt +++ b/src/org/kde/kdeconnect/UserInterface/List/EntryItemWithIcon.kt @@ -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 } } diff --git a/src/org/kde/kdeconnect/UserInterface/List/ListAdapter.kt b/src/org/kde/kdeconnect/UserInterface/List/ListAdapter.kt index 4db173b0..1f3aa526 100644 --- a/src/org/kde/kdeconnect/UserInterface/List/ListAdapter.kt +++ b/src/org/kde/kdeconnect/UserInterface/List/ListAdapter.kt @@ -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 { + private val items: List + private val isEnabled: Boolean -import androidx.annotation.NonNull; - -import java.util.List; - -public class ListAdapter extends ArrayAdapter { - public interface Item { - @NonNull - View inflateView(@NonNull LayoutInflater layoutInflater); + @JvmOverloads + constructor(context: Context, items: List, isEnabled: Boolean = true) : super(context, 0, items) { + this.items = items + this.isEnabled = isEnabled } - private final List items; - private final boolean isEnabled; - - public ListAdapter(Context context, List items) { - this(context, items, true); + interface Item { + fun inflateView(layoutInflater: LayoutInflater): View } - public ListAdapter(Context context, List items, boolean isEnabled) { - super(context, 0, (List) 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 } } diff --git a/src/org/kde/kdeconnect/UserInterface/List/SectionItem.kt b/src/org/kde/kdeconnect/UserInterface/List/SectionItem.kt index 6823341b..c1a9aa50 100644 --- a/src/org/kde/kdeconnect/UserInterface/List/SectionItem.kt +++ b/src/org/kde/kdeconnect/UserInterface/List/SectionItem.kt @@ -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 } } diff --git a/src/org/kde/kdeconnect/UserInterface/List/SmallEntryItem.kt b/src/org/kde/kdeconnect/UserInterface/List/SmallEntryItem.kt index d3cc4239..f91e4c03 100644 --- a/src/org/kde/kdeconnect/UserInterface/List/SmallEntryItem.kt +++ b/src/org/kde/kdeconnect/UserInterface/List/SmallEntryItem.kt @@ -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(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 } }