diff --git a/src/org/kde/kdeconnect/UserInterface/List/CustomItem.java b/src/org/kde/kdeconnect/UserInterface/List/CustomItem.java index 00ecf3a6..26cbe35e 100644 --- a/src/org/kde/kdeconnect/UserInterface/List/CustomItem.java +++ b/src/org/kde/kdeconnect/UserInterface/List/CustomItem.java @@ -1,39 +1,46 @@ /* * Copyright 2014 Albert Vaca Cintora * * 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 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program 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 this program. If not, see . */ package org.kde.kdeconnect.UserInterface.List; import android.view.LayoutInflater; import android.view.View; +import androidx.annotation.NonNull; + public class CustomItem implements ListAdapter.Item { private final View view; public CustomItem(View v) { + + if (v == null) + throw new IllegalArgumentException("View must not be null"); + this.view = v; } + @NonNull @Override public View inflateView(LayoutInflater layoutInflater) { return view; } } diff --git a/src/org/kde/kdeconnect/UserInterface/List/EntryItem.java b/src/org/kde/kdeconnect/UserInterface/List/EntryItem.java index 0b79b7b1..93b1b1ef 100644 --- a/src/org/kde/kdeconnect/UserInterface/List/EntryItem.java +++ b/src/org/kde/kdeconnect/UserInterface/List/EntryItem.java @@ -1,62 +1,65 @@ /* * Copyright 2014 Albert Vaca Cintora * * 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 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program 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 this program. If not, see . */ package org.kde.kdeconnect.UserInterface.List; import android.view.LayoutInflater; import android.view.View; import android.widget.TextView; +import androidx.annotation.NonNull; + import org.kde.kdeconnect_tp.R; public class EntryItem implements ListAdapter.Item { protected final String title; protected final String subtitle; public EntryItem(String title) { this.title = title; this.subtitle = null; } protected EntryItem(String title, String subtitle) { this.title = title; this.subtitle = subtitle; } + @NonNull @Override public View inflateView(LayoutInflater layoutInflater) { View v = layoutInflater.inflate(R.layout.list_item_entry, null); TextView titleView = v.findViewById(R.id.list_item_entry_title); if (titleView != null) titleView.setText(title); if (subtitle != null) { TextView subtitleView = v.findViewById(R.id.list_item_entry_summary); if (subtitleView != null) { subtitleView.setVisibility(View.VISIBLE); subtitleView.setText(subtitle); } } return v; } } diff --git a/src/org/kde/kdeconnect/UserInterface/List/ListAdapter.java b/src/org/kde/kdeconnect/UserInterface/List/ListAdapter.java index d883f99d..2200d5a3 100644 --- a/src/org/kde/kdeconnect/UserInterface/List/ListAdapter.java +++ b/src/org/kde/kdeconnect/UserInterface/List/ListAdapter.java @@ -1,55 +1,55 @@ /* * Copyright 2014 Albert Vaca Cintora * * 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 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program 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 this program. If not, see . */ 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 androidx.annotation.NonNull; import java.util.ArrayList; public class ListAdapter extends ArrayAdapter { public interface Item { + @NonNull View inflateView(LayoutInflater layoutInflater); } private final ArrayList items; private final LayoutInflater layoutInflater; public ListAdapter(Context context, ArrayList items) { super(context, 0, items); this.items = items; layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } - + @NonNull @Override public View getView(int position, View convertView, @NonNull ViewGroup parent) { final Item i = items.get(position); return i.inflateView(layoutInflater); } - } diff --git a/src/org/kde/kdeconnect/UserInterface/List/PairingDeviceItem.java b/src/org/kde/kdeconnect/UserInterface/List/PairingDeviceItem.java index 1446add3..d2224740 100644 --- a/src/org/kde/kdeconnect/UserInterface/List/PairingDeviceItem.java +++ b/src/org/kde/kdeconnect/UserInterface/List/PairingDeviceItem.java @@ -1,82 +1,85 @@ /* * Copyright 2014 Albert Vaca Cintora * * 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 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program 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 this program. If not, see . */ package org.kde.kdeconnect.UserInterface.List; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; import android.widget.TextView; +import androidx.annotation.NonNull; + import org.kde.kdeconnect.Device; import org.kde.kdeconnect_tp.R; public class PairingDeviceItem implements ListAdapter.Item { public interface Callback { void pairingClicked(Device d); } private final Callback callback; private final Device device; public PairingDeviceItem(Device device, Callback callback) { this.device = device; this.callback = callback; } public Device getDevice() { return this.device; } + @NonNull @Override public View inflateView(LayoutInflater layoutInflater) { final View v = layoutInflater.inflate(R.layout.list_item_with_icon_entry, null); ImageView icon = v.findViewById(R.id.list_item_entry_icon); icon.setImageDrawable(device.getIcon()); TextView titleView = v.findViewById(R.id.list_item_entry_title); titleView.setText(device.getName()); if (device.compareProtocolVersion() != 0) { TextView summaryView = v.findViewById(R.id.list_item_entry_summary); if (device.compareProtocolVersion() > 0) { summaryView.setText(R.string.protocol_version_newer); summaryView.setVisibility(View.VISIBLE); } else { //FIXME: Uncoment when we decide old versions are old enough to notify the user. summaryView.setVisibility(View.GONE); /* summaryView.setText(R.string.protocol_version_older); summaryView.setVisibility(View.VISIBLE); */ } } else { v.findViewById(R.id.list_item_entry_summary).setVisibility(View.GONE); } v.setOnClickListener(v1 -> callback.pairingClicked(device)); return v; } } diff --git a/src/org/kde/kdeconnect/UserInterface/List/PluginItem.java b/src/org/kde/kdeconnect/UserInterface/List/PluginItem.java index a7fa6d4d..25e860bd 100644 --- a/src/org/kde/kdeconnect/UserInterface/List/PluginItem.java +++ b/src/org/kde/kdeconnect/UserInterface/List/PluginItem.java @@ -1,57 +1,60 @@ /* * Copyright 2014 Albert Vaca Cintora * * 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 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program 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 this program. If not, see . */ package org.kde.kdeconnect.UserInterface.List; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; import android.widget.TextView; +import androidx.annotation.NonNull; + import org.kde.kdeconnect.Plugins.Plugin; import org.kde.kdeconnect_tp.R; public class PluginItem implements ListAdapter.Item { private final Plugin plugin; private final View.OnClickListener clickListener; public PluginItem(Plugin p, View.OnClickListener clickListener) { this.plugin = p; this.clickListener = clickListener; } + @NonNull @Override public View inflateView(final LayoutInflater layoutInflater) { View v = layoutInflater.inflate(R.layout.list_item_with_icon_entry, null); TextView titleView = v.findViewById(R.id.list_item_entry_title); titleView.setText(plugin.getActionName()); ImageView imageView = v.findViewById(R.id.list_item_entry_icon); imageView.setImageDrawable(plugin.getIcon()); v.setOnClickListener(clickListener); return v; } } diff --git a/src/org/kde/kdeconnect/UserInterface/List/SectionItem.java b/src/org/kde/kdeconnect/UserInterface/List/SectionItem.java index e16985cc..d566a239 100644 --- a/src/org/kde/kdeconnect/UserInterface/List/SectionItem.java +++ b/src/org/kde/kdeconnect/UserInterface/List/SectionItem.java @@ -1,58 +1,61 @@ /* * Copyright 2014 Albert Vaca Cintora * * 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 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program 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 this program. If not, see . */ package org.kde.kdeconnect.UserInterface.List; import android.view.LayoutInflater; import android.view.View; import android.widget.TextView; +import androidx.annotation.NonNull; + import org.kde.kdeconnect_tp.R; public class SectionItem implements ListAdapter.Item { private final String title; public boolean isEmpty; public SectionItem(String title) { this.title = title; this.isEmpty = true; } + @NonNull @Override public View inflateView(LayoutInflater layoutInflater) { View v = layoutInflater.inflate(R.layout.list_item_category, null); //Make it not selectable v.setOnClickListener(null); v.setOnLongClickListener(null); TextView sectionView = v.findViewById(R.id.list_item_category_text); sectionView.setText(title); if (isEmpty) { v.findViewById(R.id.list_item_category_empty_placeholder).setVisibility(View.VISIBLE); } return v; } } diff --git a/src/org/kde/kdeconnect/UserInterface/List/SmallEntryItem.java b/src/org/kde/kdeconnect/UserInterface/List/SmallEntryItem.java index 904af6eb..01b6a668 100644 --- a/src/org/kde/kdeconnect/UserInterface/List/SmallEntryItem.java +++ b/src/org/kde/kdeconnect/UserInterface/List/SmallEntryItem.java @@ -1,68 +1,70 @@ /* * Copyright 2014 Albert Vaca Cintora * * 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 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program 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 this program. If not, see . */ package org.kde.kdeconnect.UserInterface.List; import android.view.LayoutInflater; import android.view.View; import android.widget.TextView; import org.kde.kdeconnect_tp.R; +import androidx.annotation.NonNull; import androidx.core.content.ContextCompat; public class SmallEntryItem implements ListAdapter.Item { private final String title; private final View.OnClickListener clickListener; public SmallEntryItem(String title) { this.title = title; this.clickListener = null; } SmallEntryItem(String title, View.OnClickListener clickListener) { this.title = title; this.clickListener = clickListener; } + @NonNull @Override public View inflateView(LayoutInflater layoutInflater) { View v = layoutInflater.inflate(android.R.layout.simple_list_item_1, null); v.setPadding( ((int) (28 * layoutInflater.getContext().getResources().getDisplayMetrics().density)), 0, ((int) (28 * layoutInflater.getContext().getResources().getDisplayMetrics().density)), 0 ); TextView titleView = v.findViewById(android.R.id.text1); if (titleView != null) { titleView.setText(title); if (clickListener != null) { titleView.setOnClickListener(clickListener); v.setBackgroundDrawable(ContextCompat.getDrawable(layoutInflater.getContext(), R.drawable.abc_list_selector_holo_dark)); } } return v; } }