Loading app/src/main/java/foundation/e/apps/settings/LongPressPreference.kt 0 → 100644 +51 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019-2022 E FOUNDATION * * 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 3 of the License, or * (at your option) any later version. * * 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 <https://www.gnu.org/licenses/>. */ package foundation.e.apps.settings import android.content.Context import android.util.AttributeSet import android.view.View import androidx.preference.Preference import androidx.preference.PreferenceViewHolder /** * Custom class to enable long pressing preferences. * Inspired from: https://www.joehxblog.com/how-to-add-a-long-click-to-an-androidx-preference */ class LongPressPreference : Preference { private var longClickListener: View.OnLongClickListener = View.OnLongClickListener { v -> true } constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super( context, attrs, defStyle ) constructor(context: Context, attrs: AttributeSet? = null) : super(context, attrs) override fun onBindViewHolder(holder: PreferenceViewHolder) { super.onBindViewHolder(holder) val itemView: View = holder.itemView itemView.setOnLongClickListener(longClickListener) } fun setOnLongClickListener(longClickBody: (view: View?) -> Boolean) { this.longClickListener = View.OnLongClickListener { v -> longClickBody(v) } } } No newline at end of file app/src/main/java/foundation/e/apps/settings/SettingsFragment.kt +29 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package foundation.e.apps.settings import android.content.ClipboardManager import android.content.Intent import android.os.Bundle import android.os.Handler Loading @@ -34,9 +35,11 @@ import coil.load import com.aurora.gplayapi.data.models.AuthData import com.google.gson.Gson import dagger.hilt.android.AndroidEntryPoint import foundation.e.apps.BuildConfig import foundation.e.apps.MainActivity import foundation.e.apps.MainActivityViewModel import foundation.e.apps.R import foundation.e.apps.utils.modules.CommonUtilsFunctions import foundation.e.apps.databinding.CustomPreferenceBinding import foundation.e.apps.setup.signin.SignInViewModel import foundation.e.apps.updates.manager.UpdatesWorkManager Loading @@ -55,6 +58,9 @@ class SettingsFragment : PreferenceFragmentCompat() { @Inject lateinit var gson: Gson @Inject lateinit var clipboardManager: ClipboardManager companion object { private const val TAG = "SettingsFragment" } Loading Loading @@ -101,6 +107,29 @@ class SettingsFragment : PreferenceFragmentCompat() { backToMainActivity() true } val versionInfo = findPreference<LongPressPreference>("versionInfo") versionInfo?.apply { summary = BuildConfig.VERSION_NAME setOnLongClickListener { val osVersion = CommonUtilsFunctions.getSystemProperty("ro.lineage.version") val appVersionLabel = getString(R.string.app_version_label) var contents = "$appVersionLabel: $summary" if (!osVersion.isNullOrBlank()) { contents += "\n${context.getString(R.string.os_version)}: $osVersion" } CommonUtilsFunctions.copyTextToClipboard( clipboardManager, appVersionLabel, contents ) Toast.makeText(context, R.string.copied, Toast.LENGTH_SHORT).show() true } } } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { Loading app/src/main/java/foundation/e/apps/utils/modules/CommonUtilsFunctions.kt 0 → 100644 +51 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019-2022 E FOUNDATION * * 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 3 of the License, or * (at your option) any later version. * * 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 <https://www.gnu.org/licenses/>. */ package foundation.e.apps.utils.modules import android.annotation.SuppressLint import android.content.ClipData import android.content.ClipboardManager object CommonUtilsFunctions { /** * Copy anything to system clipboard. * Issue: https://gitlab.e.foundation/e/backlog/-/issues/5653 */ fun copyTextToClipboard( clipboard: ClipboardManager, label: String, text: String, ) { // https://developer.android.com/guide/topics/text/copy-paste#Copying val clip = ClipData.newPlainText(label, text) clipboard.setPrimaryClip(clip) } @SuppressLint("PrivateApi") fun getSystemProperty(key: String?): String? { var value: String? = null try { value = Class.forName("android.os.SystemProperties") .getMethod("get", String::class.java).invoke(null, key) as String } catch (e: java.lang.Exception) { e.printStackTrace() } return value } } No newline at end of file app/src/main/java/foundation/e/apps/utils/modules/CommonUtilsModule.kt +11 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,9 @@ package foundation.e.apps.utils.modules import android.annotation.SuppressLint import android.content.ClipData import android.content.ClipboardManager import android.content.Context import android.net.ConnectivityManager import android.net.NetworkCapabilities Loading @@ -34,6 +37,8 @@ import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.components.SingletonComponent import foundation.e.apps.BuildConfig import foundation.e.apps.R import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob Loading Loading @@ -165,4 +170,10 @@ object CommonUtilsModule { fun getIOCoroutineScope(): CoroutineScope { return CoroutineScope(SupervisorJob() + Dispatchers.IO) } @Singleton @Provides fun provideClipboardService(@ApplicationContext context: Context): ClipboardManager { return context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager } } app/src/main/res/values/strings.xml +4 −0 Original line number Diff line number Diff line Loading @@ -64,6 +64,10 @@ <string name="Show_all_apps">Show all apps</string> <string name="show_only_open_source_apps">Show only open-source apps</string> <string name="show_only_pwa_apps">Show only PWAs</string> <string name="about">About</string> <string name="app_version_label">App Lounge version</string> <string name="os_version">/e/ OS version</string> <string name="copied">Copied</string> <string name="account">Account</string> <string name="terms_services">Terms of Services</string> <string name="user_anonymous">Anonymous</string> Loading Loading
app/src/main/java/foundation/e/apps/settings/LongPressPreference.kt 0 → 100644 +51 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019-2022 E FOUNDATION * * 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 3 of the License, or * (at your option) any later version. * * 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 <https://www.gnu.org/licenses/>. */ package foundation.e.apps.settings import android.content.Context import android.util.AttributeSet import android.view.View import androidx.preference.Preference import androidx.preference.PreferenceViewHolder /** * Custom class to enable long pressing preferences. * Inspired from: https://www.joehxblog.com/how-to-add-a-long-click-to-an-androidx-preference */ class LongPressPreference : Preference { private var longClickListener: View.OnLongClickListener = View.OnLongClickListener { v -> true } constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super( context, attrs, defStyle ) constructor(context: Context, attrs: AttributeSet? = null) : super(context, attrs) override fun onBindViewHolder(holder: PreferenceViewHolder) { super.onBindViewHolder(holder) val itemView: View = holder.itemView itemView.setOnLongClickListener(longClickListener) } fun setOnLongClickListener(longClickBody: (view: View?) -> Boolean) { this.longClickListener = View.OnLongClickListener { v -> longClickBody(v) } } } No newline at end of file
app/src/main/java/foundation/e/apps/settings/SettingsFragment.kt +29 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package foundation.e.apps.settings import android.content.ClipboardManager import android.content.Intent import android.os.Bundle import android.os.Handler Loading @@ -34,9 +35,11 @@ import coil.load import com.aurora.gplayapi.data.models.AuthData import com.google.gson.Gson import dagger.hilt.android.AndroidEntryPoint import foundation.e.apps.BuildConfig import foundation.e.apps.MainActivity import foundation.e.apps.MainActivityViewModel import foundation.e.apps.R import foundation.e.apps.utils.modules.CommonUtilsFunctions import foundation.e.apps.databinding.CustomPreferenceBinding import foundation.e.apps.setup.signin.SignInViewModel import foundation.e.apps.updates.manager.UpdatesWorkManager Loading @@ -55,6 +58,9 @@ class SettingsFragment : PreferenceFragmentCompat() { @Inject lateinit var gson: Gson @Inject lateinit var clipboardManager: ClipboardManager companion object { private const val TAG = "SettingsFragment" } Loading Loading @@ -101,6 +107,29 @@ class SettingsFragment : PreferenceFragmentCompat() { backToMainActivity() true } val versionInfo = findPreference<LongPressPreference>("versionInfo") versionInfo?.apply { summary = BuildConfig.VERSION_NAME setOnLongClickListener { val osVersion = CommonUtilsFunctions.getSystemProperty("ro.lineage.version") val appVersionLabel = getString(R.string.app_version_label) var contents = "$appVersionLabel: $summary" if (!osVersion.isNullOrBlank()) { contents += "\n${context.getString(R.string.os_version)}: $osVersion" } CommonUtilsFunctions.copyTextToClipboard( clipboardManager, appVersionLabel, contents ) Toast.makeText(context, R.string.copied, Toast.LENGTH_SHORT).show() true } } } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { Loading
app/src/main/java/foundation/e/apps/utils/modules/CommonUtilsFunctions.kt 0 → 100644 +51 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019-2022 E FOUNDATION * * 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 3 of the License, or * (at your option) any later version. * * 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 <https://www.gnu.org/licenses/>. */ package foundation.e.apps.utils.modules import android.annotation.SuppressLint import android.content.ClipData import android.content.ClipboardManager object CommonUtilsFunctions { /** * Copy anything to system clipboard. * Issue: https://gitlab.e.foundation/e/backlog/-/issues/5653 */ fun copyTextToClipboard( clipboard: ClipboardManager, label: String, text: String, ) { // https://developer.android.com/guide/topics/text/copy-paste#Copying val clip = ClipData.newPlainText(label, text) clipboard.setPrimaryClip(clip) } @SuppressLint("PrivateApi") fun getSystemProperty(key: String?): String? { var value: String? = null try { value = Class.forName("android.os.SystemProperties") .getMethod("get", String::class.java).invoke(null, key) as String } catch (e: java.lang.Exception) { e.printStackTrace() } return value } } No newline at end of file
app/src/main/java/foundation/e/apps/utils/modules/CommonUtilsModule.kt +11 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,9 @@ package foundation.e.apps.utils.modules import android.annotation.SuppressLint import android.content.ClipData import android.content.ClipboardManager import android.content.Context import android.net.ConnectivityManager import android.net.NetworkCapabilities Loading @@ -34,6 +37,8 @@ import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.components.SingletonComponent import foundation.e.apps.BuildConfig import foundation.e.apps.R import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob Loading Loading @@ -165,4 +170,10 @@ object CommonUtilsModule { fun getIOCoroutineScope(): CoroutineScope { return CoroutineScope(SupervisorJob() + Dispatchers.IO) } @Singleton @Provides fun provideClipboardService(@ApplicationContext context: Context): ClipboardManager { return context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager } }
app/src/main/res/values/strings.xml +4 −0 Original line number Diff line number Diff line Loading @@ -64,6 +64,10 @@ <string name="Show_all_apps">Show all apps</string> <string name="show_only_open_source_apps">Show only open-source apps</string> <string name="show_only_pwa_apps">Show only PWAs</string> <string name="about">About</string> <string name="app_version_label">App Lounge version</string> <string name="os_version">/e/ OS version</string> <string name="copied">Copied</string> <string name="account">Account</string> <string name="terms_services">Terms of Services</string> <string name="user_anonymous">Anonymous</string> Loading