mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-09-03 23:55:08 +00:00
Replace StubTextPlugin.kt with PluginItem.kt
This commit is contained in:
@@ -4,7 +4,7 @@ import com.android.build.gradle.api.ApplicationVariant
|
|||||||
import com.github.jk1.license.render.TextReportRenderer
|
import com.github.jk1.license.render.TextReportRenderer
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
ext.kotlin_version = '1.8.10'
|
ext.kotlin_version = '1.8.0'
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:7.4.2'
|
classpath 'com.android.tools.build:gradle:7.4.2'
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
@@ -2,10 +2,8 @@
|
|||||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:maxWidth="400dp"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?selectableItemBackground"
|
android:background="?selectableItemBackground"
|
||||||
android:paddingHorizontal="@dimen/activity_horizontal_margin"
|
android:padding="@dimen/view_default_padding"
|
||||||
android:paddingVertical="@dimen/activity_vertical_margin"
|
|
||||||
tools:background="@android:color/darker_gray"
|
tools:background="@android:color/darker_gray"
|
||||||
tools:text="@tools:sample/lorem"/>
|
tools:text="@tools:sample/lorem"/>
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="4dp"
|
android:layout_margin="4dp"
|
||||||
style="@style/KdeConnectCardStyle.Filled"
|
style="@style/KdeConnectCardStyle.Filled"
|
||||||
app:contentPadding="12dp"
|
app:contentPadding="@dimen/view_default_padding"
|
||||||
tools:layout_width="240dp">
|
tools:layout_width="240dp">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||||
|
<dimen name="view_default_padding">16dp</dimen>
|
||||||
<dimen name="key_height">48dip</dimen>
|
<dimen name="key_height">48dip</dimen>
|
||||||
<dimen name="fab_margin">16dp</dimen>
|
<dimen name="fab_margin">16dp</dimen>
|
||||||
<dimen name="fab_elevation">6dp</dimen>
|
<dimen name="fab_elevation">6dp</dimen>
|
||||||
|
@@ -1,15 +0,0 @@
|
|||||||
package org.kde.kdeconnect.Plugins
|
|
||||||
|
|
||||||
class StubTextPlugin(private val description: String) : Plugin() {
|
|
||||||
override fun getDisplayName() = description
|
|
||||||
|
|
||||||
override fun getDescription() = description
|
|
||||||
|
|
||||||
override fun getSupportedPacketTypes(): Array<String> {
|
|
||||||
throw UnsupportedOperationException("StubTextPlugin is used only with displayName and description")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getOutgoingPacketTypes(): Array<String> {
|
|
||||||
throw UnsupportedOperationException("StubTextPlugin is used only with displayName and description")
|
|
||||||
}
|
|
||||||
}
|
|
@@ -25,8 +25,8 @@ import org.kde.kdeconnect.Device.PluginsChangedListener
|
|||||||
import org.kde.kdeconnect.Helpers.SecurityHelpers.SslHelper
|
import org.kde.kdeconnect.Helpers.SecurityHelpers.SslHelper
|
||||||
import org.kde.kdeconnect.Plugins.BatteryPlugin.BatteryPlugin
|
import org.kde.kdeconnect.Plugins.BatteryPlugin.BatteryPlugin
|
||||||
import org.kde.kdeconnect.Plugins.Plugin
|
import org.kde.kdeconnect.Plugins.Plugin
|
||||||
import org.kde.kdeconnect.Plugins.StubTextPlugin
|
|
||||||
import org.kde.kdeconnect.UserInterface.List.PluginAdapter
|
import org.kde.kdeconnect.UserInterface.List.PluginAdapter
|
||||||
|
import org.kde.kdeconnect.UserInterface.List.PluginItem
|
||||||
import org.kde.kdeconnect_tp.R
|
import org.kde.kdeconnect_tp.R
|
||||||
import org.kde.kdeconnect_tp.databinding.ActivityDeviceBinding
|
import org.kde.kdeconnect_tp.databinding.ActivityDeviceBinding
|
||||||
import org.kde.kdeconnect_tp.databinding.ViewPairErrorBinding
|
import org.kde.kdeconnect_tp.databinding.ViewPairErrorBinding
|
||||||
@@ -45,8 +45,8 @@ class DeviceFragment : Fragment() {
|
|||||||
private val mActivity: MainActivity? by lazy { activity as MainActivity? }
|
private val mActivity: MainActivity? by lazy { activity as MainActivity? }
|
||||||
|
|
||||||
//TODO use LinkedHashMap and delete irrelevant records when plugins changed
|
//TODO use LinkedHashMap and delete irrelevant records when plugins changed
|
||||||
private val pluginListItems: ArrayList<Pair<Plugin, (() -> Unit)?>> = ArrayList()
|
private val pluginListItems: ArrayList<PluginItem> = ArrayList()
|
||||||
private val permissionListItems: ArrayList<Pair<Plugin, (() -> Unit)?>> = ArrayList()
|
private val permissionListItems: ArrayList<PluginItem> = ArrayList()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Top-level ViewBinding for this fragment.
|
* Top-level ViewBinding for this fragment.
|
||||||
@@ -259,9 +259,13 @@ class DeviceFragment : Fragment() {
|
|||||||
if (paired && !reachable) {
|
if (paired && !reachable) {
|
||||||
requireErrorBinding().errorMessageContainer.visibility = View.VISIBLE
|
requireErrorBinding().errorMessageContainer.visibility = View.VISIBLE
|
||||||
requireErrorBinding().notReachableMessage.visibility = View.VISIBLE
|
requireErrorBinding().notReachableMessage.visibility = View.VISIBLE
|
||||||
|
requireDeviceBinding().buttonsList.visibility = View.GONE
|
||||||
|
requireDeviceBinding().pluginsList.visibility = View.GONE
|
||||||
} else {
|
} else {
|
||||||
requireErrorBinding().errorMessageContainer.visibility = View.GONE
|
requireErrorBinding().errorMessageContainer.visibility = View.GONE
|
||||||
requireErrorBinding().notReachableMessage.visibility = View.GONE
|
requireErrorBinding().notReachableMessage.visibility = View.GONE
|
||||||
|
requireDeviceBinding().buttonsList.visibility = View.VISIBLE
|
||||||
|
requireDeviceBinding().pluginsList.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (paired && reachable) {
|
if (paired && reachable) {
|
||||||
@@ -275,7 +279,9 @@ class DeviceFragment : Fragment() {
|
|||||||
//Fill enabled plugins ArrayList
|
//Fill enabled plugins ArrayList
|
||||||
for (p in plugins) {
|
for (p in plugins) {
|
||||||
if (!p.hasMainActivity(context) || p.displayInContextMenu()) continue
|
if (!p.hasMainActivity(context) || p.displayInContextMenu()) continue
|
||||||
pluginListItems.add(p to { p.startMainActivity(mActivity) })
|
pluginListItems.add(
|
||||||
|
PluginItem(requireContext(), p, { p.startMainActivity(mActivity) })
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Fill permissionListItems with permissions plugins
|
//Fill permissionListItems with permissions plugins
|
||||||
@@ -358,10 +364,18 @@ class DeviceFragment : Fragment() {
|
|||||||
) {
|
) {
|
||||||
if (plugins.isEmpty()) return
|
if (plugins.isEmpty()) return
|
||||||
val device = device ?: return
|
val device = device ?: return
|
||||||
permissionListItems.add(StubTextPlugin(requireContext().getString(headerText)) to null)
|
permissionListItems.add(
|
||||||
|
PluginItem(
|
||||||
|
context = requireContext(),
|
||||||
|
header = requireContext().getString(headerText),
|
||||||
|
textStyleRes = R.style.TextAppearance_Material3_BodyMedium,
|
||||||
|
)
|
||||||
|
)
|
||||||
for (plugin in plugins.values) {
|
for (plugin in plugins.values) {
|
||||||
if (device.isPluginEnabled(plugin.pluginKey)) {
|
if (device.isPluginEnabled(plugin.pluginKey)) {
|
||||||
permissionListItems.add(plugin to { action(plugin) })
|
permissionListItems.add(
|
||||||
|
PluginItem(requireContext(), plugin, action, R.style.TextAppearance_Material3_LabelLarge)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,19 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2018 Nicolas Fella <nicolas.fella@gmx.de>
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
|
||||||
*/
|
|
||||||
package org.kde.kdeconnect.UserInterface.List;
|
|
||||||
|
|
||||||
import org.kde.kdeconnect.Plugins.Plugin;
|
|
||||||
|
|
||||||
public class FailedPluginListItem extends SmallEntryItem {
|
|
||||||
|
|
||||||
public interface Action {
|
|
||||||
void action(Plugin plugin);
|
|
||||||
}
|
|
||||||
|
|
||||||
public FailedPluginListItem(Plugin plugin, Action action) {
|
|
||||||
super(plugin.getDisplayName(), (view) -> action.action(plugin));
|
|
||||||
}
|
|
||||||
}
|
|
@@ -8,8 +8,6 @@ import android.view.ViewGroup
|
|||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import org.kde.kdeconnect.Plugins.Plugin
|
|
||||||
import org.kde.kdeconnect.Plugins.StubTextPlugin
|
|
||||||
import org.kde.kdeconnect_tp.R
|
import org.kde.kdeconnect_tp.R
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -20,30 +18,24 @@ import org.kde.kdeconnect_tp.R
|
|||||||
* Any other TextView layout
|
* Any other TextView layout
|
||||||
*/
|
*/
|
||||||
class PluginAdapter(
|
class PluginAdapter(
|
||||||
private val pluginList: ArrayList<Pair<Plugin, (() -> Unit)?>>,
|
private val pluginList: ArrayList<PluginItem>,
|
||||||
private val layout: Int,
|
private val layoutRes: Int,
|
||||||
) : RecyclerView.Adapter<PluginAdapter.PluginViewHolder>() {
|
) : RecyclerView.Adapter<PluginAdapter.PluginViewHolder>() {
|
||||||
|
|
||||||
override fun onCreateViewHolder(viewGroup: ViewGroup, type: Int) =
|
override fun onCreateViewHolder(viewGroup: ViewGroup, type: Int) =
|
||||||
PluginViewHolder(LayoutInflater.from(viewGroup.context).inflate(layout, viewGroup, false))
|
PluginViewHolder(LayoutInflater.from(viewGroup.context).inflate(layoutRes, viewGroup, false))
|
||||||
|
|
||||||
override fun getItemCount() = pluginList.size
|
override fun getItemCount() = pluginList.size
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.M)
|
@TargetApi(Build.VERSION_CODES.M)
|
||||||
override fun onBindViewHolder(holder: PluginViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: PluginViewHolder, position: Int) {
|
||||||
pluginList[position].let { (plugin, action) ->
|
pluginList[position].let { plugin ->
|
||||||
holder.pluginTitle.text = plugin.displayName
|
holder.pluginTitle.text = plugin.header
|
||||||
holder.pluginIcon?.setImageDrawable(plugin.icon)
|
holder.pluginIcon?.setImageDrawable(plugin.icon)
|
||||||
|
|
||||||
//Set regular text for unclickable StubTextPlugin and bold for supposedly clickable TextView items
|
plugin.textStyleRes?.let { holder.pluginTitle.setTextAppearance(it) }
|
||||||
when {
|
|
||||||
plugin is StubTextPlugin ->
|
|
||||||
holder.pluginTitle.setTextAppearance(R.style.TextAppearance_Material3_BodyMedium)
|
|
||||||
holder.itemView is TextView ->
|
|
||||||
holder.pluginTitle.setTextAppearance(R.style.TextAppearance_Material3_LabelLarge)
|
|
||||||
}
|
|
||||||
|
|
||||||
action?.let { holder.itemView.setOnClickListener { action.invoke() } }
|
plugin.action?.let { action -> holder.itemView.setOnClickListener { action.invoke() } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,31 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2014 Albert Vaca Cintora <albertvaka@gmail.com>
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.kde.kdeconnect.UserInterface.List;
|
|
||||||
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import org.kde.kdeconnect.Plugins.Plugin;
|
|
||||||
|
|
||||||
public class PluginItem extends EntryItemWithIcon {
|
|
||||||
private final View.OnClickListener clickListener;
|
|
||||||
|
|
||||||
public PluginItem(Plugin p, View.OnClickListener clickListener) {
|
|
||||||
super(p.getActionName(), p.getIcon());
|
|
||||||
this.clickListener = clickListener;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public View inflateView(@NonNull LayoutInflater layoutInflater) {
|
|
||||||
final View root = super.inflateView(layoutInflater);
|
|
||||||
root.setOnClickListener(clickListener);
|
|
||||||
return root;
|
|
||||||
}
|
|
||||||
}
|
|
29
src/org/kde/kdeconnect/UserInterface/List/PluginItem.kt
Normal file
29
src/org/kde/kdeconnect/UserInterface/List/PluginItem.kt
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package org.kde.kdeconnect.UserInterface.List
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
|
import org.kde.kdeconnect.Plugins.Plugin
|
||||||
|
|
||||||
|
class PluginItem(
|
||||||
|
val context: Context,
|
||||||
|
val header: String,
|
||||||
|
val textStyleRes: Int? = null,
|
||||||
|
) {
|
||||||
|
|
||||||
|
var action: (() -> Unit)? = null
|
||||||
|
var icon: Drawable? = null
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
context: Context,
|
||||||
|
plugin: Plugin,
|
||||||
|
action: (Plugin) -> Unit,
|
||||||
|
textStyleRes: Int? = null,
|
||||||
|
) : this(
|
||||||
|
context = context,
|
||||||
|
header = plugin.displayName,
|
||||||
|
textStyleRes = textStyleRes,
|
||||||
|
) {
|
||||||
|
this.action = { action(plugin) }
|
||||||
|
this.icon = plugin.icon
|
||||||
|
}
|
||||||
|
}
|
@@ -1,33 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2014 Albert Vaca Cintora <albertvaka@gmail.com>
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
|
||||||
*/
|
|
||||||
|
|
||||||
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.databinding.ListItemPluginHeaderBinding;
|
|
||||||
|
|
||||||
public class PluginListHeaderItem implements ListAdapter.Item {
|
|
||||||
private final int text;
|
|
||||||
|
|
||||||
public PluginListHeaderItem(int text) {
|
|
||||||
this.text = text;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public View inflateView(@NonNull LayoutInflater layoutInflater) {
|
|
||||||
TextView textView = ListItemPluginHeaderBinding.inflate(layoutInflater).getRoot();
|
|
||||||
textView.setText(text);
|
|
||||||
textView.setOnClickListener(null);
|
|
||||||
textView.setOnLongClickListener(null);
|
|
||||||
return textView;
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user