From 27f1d079e3c7a1a4b573cceacc55356797aa3967 Mon Sep 17 00:00:00 2001 From: Janne Koschinski <janne@kuschku.de> Date: Sat, 14 Apr 2018 00:50:54 +0200 Subject: [PATCH] Implement ignore list UI --- app/src/main/AndroidManifest.xml | 60 +++-- .../quasseldroid/dagger/ActivityModule.kt | 10 + .../about/AboutSettingsFragment.kt | 14 +- .../ui/coresettings/CoreSettingsFragment.kt | 5 + .../DragSortItemTouchHelperCallback.kt | 29 ++ .../coresettings/identity/IdentityFragment.kt | 65 ++--- .../ignoreitem/IgnoreItemActivity.kt | 5 + .../ignoreitem/IgnoreItemFragment.kt | 144 ++++++++++ .../ignoreitem/IgnoreItemFragmentProvider.kt | 10 + .../ignoreitem/IgnoreTypeAdapter.kt | 71 +++++ .../coresettings/ignoreitem/IgnoreTypeItem.kt | 6 + .../ignoreitem/ScopeTypeAdapter.kt | 71 +++++ .../coresettings/ignoreitem/ScopeTypeItem.kt | 6 + .../ignoreitem/StrictnessTypeAdapter.kt | 71 +++++ .../ignoreitem/StrictnessTypeItem.kt | 6 + .../DragSortItemTouchHelperCallback.kt | 28 ++ .../ignorelist/IgnoreListActivity.kt | 5 + .../ignorelist/IgnoreListAdapter.kt | 115 ++++++++ .../ignorelist/IgnoreListFragment.kt | 101 +++++++ .../ignorelist/IgnoreListFragmentProvider.kt | 10 + .../networkconfig/NetworkConfigFragment.kt | 6 +- .../main/res/layout/settings_ignoreitem.xml | 107 ++++++++ .../main/res/layout/settings_ignorelist.xml | 27 ++ .../res/layout/settings_ignorelist_item.xml | 54 ++++ .../main/res/values-de/strings_settings.xml | 17 ++ app/src/main/res/values/strings_licenses.xml | 51 +++- app/src/main/res/values/strings_settings.xml | 19 +- app/src/main/res/values/styles_widgets.xml | 11 +- .../quassel/syncables/IgnoreListManager.kt | 247 +++++++++++++++++- .../libquassel/quassel/syncables/Network.kt | 8 +- .../quassel/syncables/interfaces/INetwork.kt | 5 +- .../libquassel/util/GlobTransformer.kt | 77 ++++++ .../viewmodel/QuasselViewModel.kt | 12 +- 33 files changed, 1375 insertions(+), 98 deletions(-) create mode 100644 app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/identity/DragSortItemTouchHelperCallback.kt create mode 100644 app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/IgnoreItemActivity.kt create mode 100644 app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/IgnoreItemFragment.kt create mode 100644 app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/IgnoreItemFragmentProvider.kt create mode 100644 app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/IgnoreTypeAdapter.kt create mode 100644 app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/IgnoreTypeItem.kt create mode 100644 app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/ScopeTypeAdapter.kt create mode 100644 app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/ScopeTypeItem.kt create mode 100644 app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/StrictnessTypeAdapter.kt create mode 100644 app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/StrictnessTypeItem.kt create mode 100644 app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignorelist/DragSortItemTouchHelperCallback.kt create mode 100644 app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignorelist/IgnoreListActivity.kt create mode 100644 app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignorelist/IgnoreListAdapter.kt create mode 100644 app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignorelist/IgnoreListFragment.kt create mode 100644 app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignorelist/IgnoreListFragmentProvider.kt create mode 100644 app/src/main/res/layout/settings_ignoreitem.xml create mode 100644 app/src/main/res/layout/settings_ignorelist.xml create mode 100644 app/src/main/res/layout/settings_ignorelist_item.xml create mode 100644 lib/src/main/java/de/kuschku/libquassel/util/GlobTransformer.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e9fa358c1..4ceb73f87 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -54,56 +54,68 @@ android:parentActivityName=".ui.chat.info.channel.ChannelInfoActivity" android:windowSoftInputMode="adjustResize" /> - <!-- Client Settings --> + <!-- Core Settings --> <activity - android:name=".ui.clientsettings.app.AppSettingsActivity" + android:name=".ui.coresettings.CoreSettingsActivity" android:exported="false" - android:label="@string/label_settings_client" + android:label="@string/label_settings_core" android:parentActivityName=".ui.chat.ChatActivity" android:windowSoftInputMode="adjustResize" /> <activity - android:name=".ui.clientsettings.crash.CrashSettingsActivity" + android:name=".ui.coresettings.identity.IdentityActivity" android:exported="false" - android:label="@string/label_crashes" - android:parentActivityName=".ui.clientsettings.app.AppSettingsActivity" + android:label="@string/settings_identity_title" + android:parentActivityName=".ui.coresettings.CoreSettingsActivity" android:windowSoftInputMode="adjustResize" /> <activity - android:name=".ui.clientsettings.about.AboutSettingsActivity" + android:name=".ui.coresettings.chatlist.ChatListActivity" android:exported="false" - android:label="@string/label_about" - android:parentActivityName=".ui.clientsettings.app.AppSettingsActivity" + android:label="@string/settings_chatlist_title" + android:parentActivityName=".ui.coresettings.CoreSettingsActivity" android:windowSoftInputMode="adjustResize" /> <activity - android:name=".ui.clientsettings.license.LicenseSettingsActivity" + android:name=".ui.coresettings.ignorelist.IgnoreListActivity" android:exported="false" - android:label="@string/label_license" - android:parentActivityName=".ui.clientsettings.about.AboutSettingsActivity" + android:label="@string/settings_ignorelist_title" + android:parentActivityName=".ui.coresettings.CoreSettingsActivity" + android:windowSoftInputMode="adjustResize" /> + <activity + android:name=".ui.coresettings.ignoreitem.IgnoreItemActivity" + android:exported="false" + android:label="@string/settings_ignoreitem_title" + android:parentActivityName=".ui.coresettings.ignorelist.IgnoreListActivity" + android:windowSoftInputMode="adjustResize" /> + <activity + android:name=".ui.coresettings.networkconfig.NetworkConfigActivity" + android:exported="false" + android:label="@string/settings_networkconfig_title" + android:parentActivityName=".ui.coresettings.CoreSettingsActivity" android:windowSoftInputMode="adjustResize" /> - <!-- Core Settings --> + <!-- Client Settings --> <activity - android:name=".ui.coresettings.CoreSettingsActivity" + android:name=".ui.clientsettings.app.AppSettingsActivity" android:exported="false" - android:label="@string/label_settings_core" + android:label="@string/label_settings_client" android:parentActivityName=".ui.chat.ChatActivity" android:windowSoftInputMode="adjustResize" /> <activity - android:name=".ui.coresettings.identity.IdentityActivity" + android:name=".ui.clientsettings.crash.CrashSettingsActivity" android:exported="false" - android:label="@string/settings_identity_title" - android:parentActivityName=".ui.coresettings.CoreSettingsActivity" + android:label="@string/label_crashes" + android:parentActivityName=".ui.clientsettings.app.AppSettingsActivity" android:windowSoftInputMode="adjustResize" /> <activity - android:name=".ui.coresettings.chatlist.ChatListActivity" + android:name=".ui.clientsettings.about.AboutSettingsActivity" android:exported="false" - android:label="@string/settings_chatlist_title" - android:parentActivityName=".ui.coresettings.CoreSettingsActivity" + android:label="@string/label_about" + android:parentActivityName=".ui.clientsettings.app.AppSettingsActivity" android:windowSoftInputMode="adjustResize" /> <activity - android:name=".ui.coresettings.networkconfig.NetworkConfigActivity" + android:name=".ui.clientsettings.license.LicenseSettingsActivity" android:exported="false" - android:label="@string/settings_networkconfig_title" - android:parentActivityName=".ui.coresettings.CoreSettingsActivity" + android:label="@string/label_license" + android:parentActivityName=".ui.clientsettings.about.AboutSettingsActivity" android:windowSoftInputMode="adjustResize" /> <!-- Client Setup Flow --> diff --git a/app/src/main/java/de/kuschku/quasseldroid/dagger/ActivityModule.kt b/app/src/main/java/de/kuschku/quasseldroid/dagger/ActivityModule.kt index 4ad51f943..1f8d98d5c 100644 --- a/app/src/main/java/de/kuschku/quasseldroid/dagger/ActivityModule.kt +++ b/app/src/main/java/de/kuschku/quasseldroid/dagger/ActivityModule.kt @@ -26,6 +26,10 @@ import de.kuschku.quasseldroid.ui.coresettings.chatlist.ChatListActivity import de.kuschku.quasseldroid.ui.coresettings.chatlist.ChatListFragmentProvider import de.kuschku.quasseldroid.ui.coresettings.identity.IdentityActivity import de.kuschku.quasseldroid.ui.coresettings.identity.IdentityFragmentProvider +import de.kuschku.quasseldroid.ui.coresettings.ignoreitem.IgnoreItemActivity +import de.kuschku.quasseldroid.ui.coresettings.ignoreitem.IgnoreItemFragmentProvider +import de.kuschku.quasseldroid.ui.coresettings.ignorelist.IgnoreListActivity +import de.kuschku.quasseldroid.ui.coresettings.ignorelist.IgnoreListFragmentProvider import de.kuschku.quasseldroid.ui.coresettings.networkconfig.NetworkConfigActivity import de.kuschku.quasseldroid.ui.coresettings.networkconfig.NetworkConfigFragmentProvider import de.kuschku.quasseldroid.ui.setup.accounts.edit.AccountEditActivity @@ -69,6 +73,12 @@ abstract class ActivityModule { @ContributesAndroidInjector(modules = [ChatListFragmentProvider::class]) abstract fun bindChatListActivity(): ChatListActivity + @ContributesAndroidInjector(modules = [IgnoreListFragmentProvider::class]) + abstract fun bindIgnoreActivity(): IgnoreListActivity + + @ContributesAndroidInjector(modules = [IgnoreItemFragmentProvider::class]) + abstract fun bindIgnoreItemActivity(): IgnoreItemActivity + @ContributesAndroidInjector(modules = [NetworkConfigFragmentProvider::class]) abstract fun bindNetworkConfigActivity(): NetworkConfigActivity diff --git a/app/src/main/java/de/kuschku/quasseldroid/ui/clientsettings/about/AboutSettingsFragment.kt b/app/src/main/java/de/kuschku/quasseldroid/ui/clientsettings/about/AboutSettingsFragment.kt index 88c1d69bc..c0217f6c6 100644 --- a/app/src/main/java/de/kuschku/quasseldroid/ui/clientsettings/about/AboutSettingsFragment.kt +++ b/app/src/main/java/de/kuschku/quasseldroid/ui/clientsettings/about/AboutSettingsFragment.kt @@ -149,6 +149,16 @@ class AboutSettingsFragment : DaggerFragment() { license = apache2, url = "https://bumptech.github.io/glide/" ), + Library( + name = "GlobTransformer", + version = "4.6.1", + license = License( + shortName = "CC BY-SA 3.0", + fullName = "Creative Commons Attribution-ShareAlike 3.0 Unported", + text = R.string.license_cc_by_sa_3_0 + ), + url = "https://bumptech.github.io/glide/" + ), Library( name = "Gson", version = "2.8.2", @@ -215,8 +225,8 @@ class AboutSettingsFragment : DaggerFragment() { version = "1.0.2", license = License( shortName = "CC0", - fullName = "Public Domain (CC0)", - text = R.string.license_cc0 + fullName = "Creative Commons CC0 1.0 Universal", + text = R.string.license_cc_0 ), url = "https://github.com/ReactiveX/RxJava" ), diff --git a/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/CoreSettingsFragment.kt b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/CoreSettingsFragment.kt index f5e89cdd3..27f54e693 100644 --- a/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/CoreSettingsFragment.kt +++ b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/CoreSettingsFragment.kt @@ -18,6 +18,7 @@ import de.kuschku.libquassel.quassel.syncables.Network import de.kuschku.quasseldroid.R import de.kuschku.quasseldroid.ui.coresettings.chatlist.ChatListActivity import de.kuschku.quasseldroid.ui.coresettings.identity.IdentityActivity +import de.kuschku.quasseldroid.ui.coresettings.ignorelist.IgnoreListActivity import de.kuschku.quasseldroid.ui.coresettings.networkconfig.NetworkConfigActivity import de.kuschku.quasseldroid.util.helper.combineLatest import de.kuschku.quasseldroid.util.helper.toLiveData @@ -121,6 +122,10 @@ class CoreSettingsFragment : ServiceBoundFragment() { startActivity(Intent(requireContext(), NetworkConfigActivity::class.java)) } + ignorelist.setOnClickListener { + startActivity(Intent(requireContext(), IgnoreListActivity::class.java)) + } + return view } } diff --git a/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/identity/DragSortItemTouchHelperCallback.kt b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/identity/DragSortItemTouchHelperCallback.kt new file mode 100644 index 000000000..a18747e3b --- /dev/null +++ b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/identity/DragSortItemTouchHelperCallback.kt @@ -0,0 +1,29 @@ +package de.kuschku.quasseldroid.ui.coresettings.identity + +import android.support.v7.widget.RecyclerView +import android.support.v7.widget.helper.ItemTouchHelper + +class DragSortItemTouchHelperCallback(private val adapter: IdentityNicksAdapter) : + ItemTouchHelper.Callback() { + override fun isLongPressDragEnabled() = true + + override fun isItemViewSwipeEnabled() = true + + override fun getMovementFlags(recyclerView: RecyclerView, + viewHolder: RecyclerView.ViewHolder): Int { + val dragFlags = ItemTouchHelper.UP or ItemTouchHelper.DOWN + val swipeFlags = ItemTouchHelper.START or ItemTouchHelper.END + return makeMovementFlags(dragFlags, + swipeFlags) + } + + override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, + target: RecyclerView.ViewHolder): Boolean { + adapter.moveNick(viewHolder.adapterPosition, target.adapterPosition) + return true + } + + override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { + adapter.removeNick(viewHolder.adapterPosition) + } +} diff --git a/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/identity/IdentityFragment.kt b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/identity/IdentityFragment.kt index 6d16e5f6b..e3aa0a3b9 100644 --- a/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/identity/IdentityFragment.kt +++ b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/identity/IdentityFragment.kt @@ -5,7 +5,6 @@ import android.os.Bundle import android.support.v4.view.ViewCompat import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.RecyclerView -import android.support.v7.widget.RecyclerView.ViewHolder import android.support.v7.widget.SwitchCompat import android.support.v7.widget.helper.ItemTouchHelper import android.view.LayoutInflater @@ -73,27 +72,6 @@ class IdentityFragment : SettingsFragment() { val identityId = arguments?.getInt("identity", -1) ?: -1 - viewModel.identities.switchMap { - it[identityId]?.liveUpdates() ?: Observable.empty() - }.firstElement() - .toLiveData().observe(this, Observer { - if (it != null) { - this.identity = Pair(it, it.copy()) - this.identity?.let { (_, data) -> - identityName.text = data.identityName() - realName.text = data.realName() - ident.text = data.ident() - kickReason.text = data.kickReason() - partReason.text = data.partReason() - quitReason.text = data.quitReason() - awayReason.text = data.awayReason() - detachAway.isChecked = data.detachAwayEnabled() - detachAwayReason.text = data.detachAwayReason() - adapter.nicks = data.nicks() - } - } - }) - adapter = IdentityNicksAdapter(::nickClick, ::startDrag) nicks.layoutManager = LinearLayoutManager(requireContext()) nicks.adapter = adapter @@ -118,6 +96,27 @@ class IdentityFragment : SettingsFragment() { }.build().show() } + viewModel.identities.switchMap { + it[identityId]?.liveUpdates() ?: Observable.empty() + }.firstElement() + .toLiveData().observe(this, Observer { + if (it != null) { + this.identity = Pair(it, it.copy()) + this.identity?.let { (_, data) -> + identityName.text = data.identityName() + realName.text = data.realName() + ident.text = data.ident() + kickReason.text = data.kickReason() + partReason.text = data.partReason() + quitReason.text = data.quitReason() + awayReason.text = data.awayReason() + detachAway.isChecked = data.detachAwayEnabled() + detachAwayReason.text = data.detachAwayReason() + adapter.nicks = data.nicks() + } + } + }) + detachAway.setDependent(detachAwayGroup) return view @@ -156,26 +155,4 @@ class IdentityFragment : SettingsFragment() { true } ?: false - class DragSortItemTouchHelperCallback(private val adapter: IdentityNicksAdapter) : - ItemTouchHelper.Callback() { - override fun isLongPressDragEnabled() = true - - override fun isItemViewSwipeEnabled() = true - - override fun getMovementFlags(recyclerView: RecyclerView, viewHolder: ViewHolder): Int { - val dragFlags = ItemTouchHelper.UP or ItemTouchHelper.DOWN - val swipeFlags = ItemTouchHelper.START or ItemTouchHelper.END - return ItemTouchHelper.Callback.makeMovementFlags(dragFlags, swipeFlags) - } - - override fun onMove(recyclerView: RecyclerView, viewHolder: ViewHolder, - target: ViewHolder): Boolean { - adapter.moveNick(viewHolder.adapterPosition, target.adapterPosition) - return true - } - - override fun onSwiped(viewHolder: ViewHolder, direction: Int) { - adapter.removeNick(viewHolder.adapterPosition) - } - } } diff --git a/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/IgnoreItemActivity.kt b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/IgnoreItemActivity.kt new file mode 100644 index 000000000..1d75e1602 --- /dev/null +++ b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/IgnoreItemActivity.kt @@ -0,0 +1,5 @@ +package de.kuschku.quasseldroid.ui.coresettings.ignoreitem + +import de.kuschku.quasseldroid.util.ui.SettingsActivity + +class IgnoreItemActivity : SettingsActivity(IgnoreItemFragment()) diff --git a/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/IgnoreItemFragment.kt b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/IgnoreItemFragment.kt new file mode 100644 index 000000000..7c7f3241f --- /dev/null +++ b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/IgnoreItemFragment.kt @@ -0,0 +1,144 @@ +package de.kuschku.quasseldroid.ui.coresettings.ignoreitem + +import android.app.Activity +import android.content.Intent +import android.os.Bundle +import android.support.v7.widget.SwitchCompat +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.AdapterView +import android.widget.EditText +import android.widget.Spinner +import butterknife.BindView +import butterknife.ButterKnife +import de.kuschku.libquassel.quassel.syncables.IgnoreListManager +import de.kuschku.quasseldroid.R +import de.kuschku.quasseldroid.ui.coresettings.SettingsFragment +import de.kuschku.quasseldroid.util.ui.AnimationHelper + +class IgnoreItemFragment : SettingsFragment() { + @BindView(R.id.enabled) + lateinit var enabled: SwitchCompat + + @BindView(R.id.ignorerule) + lateinit var ignoreRule: EditText + + @BindView(R.id.isregex) + lateinit var isRegEx: SwitchCompat + + @BindView(R.id.type) + lateinit var type: Spinner + + @BindView(R.id.strictness) + lateinit var strictness: Spinner + + @BindView(R.id.scope) + lateinit var scope: Spinner + + @BindView(R.id.scoperule) + lateinit var scopeRule: EditText + + @BindView(R.id.scopegroup) + lateinit var scopegroup: ViewGroup + + private var item: IgnoreListManager.IgnoreListItem? = null + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle?): View? { + val view = inflater.inflate(R.layout.settings_ignoreitem, container, false) + ButterKnife.bind(this, view) + + (arguments?.getSerializable("item") as? IgnoreListManager.IgnoreListItem)?.let { + item = it + } + + val typeAdapter = IgnoreTypeAdapter(listOf( + IgnoreTypeItem( + value = IgnoreListManager.IgnoreType.SenderIgnore, + name = R.string.settings_ignoreitem_type_sender + ), + IgnoreTypeItem( + value = IgnoreListManager.IgnoreType.MessageIgnore, + name = R.string.settings_ignoreitem_type_message + ), + IgnoreTypeItem( + value = IgnoreListManager.IgnoreType.CtcpIgnore, + name = R.string.settings_ignoreitem_type_ctcp + ) + )) + type.adapter = typeAdapter + + val strictnessAdapter = StrictnessTypeAdapter(listOf( + StrictnessTypeItem( + value = IgnoreListManager.StrictnessType.SoftStrictness, + name = R.string.settings_ignoreitem_strictness_soft + ), + StrictnessTypeItem( + value = IgnoreListManager.StrictnessType.HardStrictness, + name = R.string.settings_ignoreitem_strictness_hard + ) + )) + strictness.adapter = strictnessAdapter + + val scopeAdapter = ScopeTypeAdapter(listOf( + ScopeTypeItem( + value = IgnoreListManager.ScopeType.GlobalScope, + name = R.string.settings_ignoreitem_scope_global + ), + ScopeTypeItem( + value = IgnoreListManager.ScopeType.NetworkScope, + name = R.string.settings_ignoreitem_scope_network + ), + ScopeTypeItem( + value = IgnoreListManager.ScopeType.ChannelScope, + name = R.string.settings_ignoreitem_scope_channel + ) + )) + scope.adapter = scopeAdapter + + item?.let { data -> + enabled.isChecked = data.isActive + ignoreRule.setText(data.ignoreRule) + isRegEx.isChecked = data.isRegEx + type.setSelection(typeAdapter.indexOf(data.type) ?: 0) + strictness.setSelection(strictnessAdapter.indexOf(data.strictness) ?: 0) + scope.setSelection(scopeAdapter.indexOf(data.scope) ?: 0) + scopeRule.setText(data.scopeRule) + } + + scope.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onNothingSelected(parent: AdapterView<*>?) { + AnimationHelper.collapse(scopegroup) + } + + override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { + if (id.toInt() == IgnoreListManager.ScopeType.GlobalScope.value) { + AnimationHelper.collapse(scopegroup) + } else { + AnimationHelper.expand(scopegroup) + } + } + } + + return view + } + + override fun onSave() = item?.let { data -> + val intent = Intent() + intent.putExtra("old", data) + val new = IgnoreListManager.IgnoreListItem( + isActive = enabled.isChecked, + ignoreRule = ignoreRule.text.toString(), + isRegEx = isRegEx.isChecked, + type = type.selectedItemId.toInt(), + strictness = strictness.selectedItemId.toInt(), + scope = scope.selectedItemId.toInt(), + scopeRule = scopeRule.text.toString() + ) + intent.putExtra("new", new) + requireActivity().setResult(Activity.RESULT_OK, intent) + true + } ?: false + +} diff --git a/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/IgnoreItemFragmentProvider.kt b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/IgnoreItemFragmentProvider.kt new file mode 100644 index 000000000..cdafd5a9d --- /dev/null +++ b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/IgnoreItemFragmentProvider.kt @@ -0,0 +1,10 @@ +package de.kuschku.quasseldroid.ui.coresettings.ignoreitem + +import dagger.Module +import dagger.android.ContributesAndroidInjector + +@Module +abstract class IgnoreItemFragmentProvider { + @ContributesAndroidInjector + abstract fun bindIgnoreItemFragment(): IgnoreItemFragment +} diff --git a/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/IgnoreTypeAdapter.kt b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/IgnoreTypeAdapter.kt new file mode 100644 index 000000000..b86e2ee16 --- /dev/null +++ b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/IgnoreTypeAdapter.kt @@ -0,0 +1,71 @@ +package de.kuschku.quasseldroid.ui.coresettings.ignoreitem + +import android.support.v7.widget.RecyclerView +import android.support.v7.widget.ThemedSpinnerAdapter +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import butterknife.BindView +import butterknife.ButterKnife +import de.kuschku.libquassel.quassel.syncables.IgnoreListManager +import de.kuschku.quasseldroid.R +import de.kuschku.quasseldroid.util.ui.ContextThemeWrapper +import de.kuschku.quasseldroid.util.ui.RecyclerSpinnerAdapter + +class IgnoreTypeAdapter(val data: List<IgnoreTypeItem>) : + RecyclerSpinnerAdapter<IgnoreTypeAdapter.IgnoreTypeViewHolder>(), + ThemedSpinnerAdapter { + + override fun isEmpty() = data.isEmpty() + + override fun onBindViewHolder(holder: IgnoreTypeViewHolder, position: Int) = + holder.bind(getItem(position)) + + override fun onCreateViewHolder(parent: ViewGroup, dropDown: Boolean) + : IgnoreTypeViewHolder { + val inflater = LayoutInflater.from( + if (dropDown) + ContextThemeWrapper(parent.context, dropDownViewTheme) + else + parent.context + ) + val view = inflater.inflate(R.layout.widget_spinner_item_toolbar, parent, false) + return IgnoreTypeViewHolder( + view + ) + } + + override fun getItem(position: Int) = data[position] + + override fun getItemId(position: Int) = getItem(position).value.value.toLong() + + override fun hasStableIds() = true + + override fun getCount() = data.size + + fun indexOf(value: IgnoreListManager.IgnoreType): Int? { + for ((key, item) in data.withIndex()) { + if (item.value.value == value.value) { + return key + } + } + return null + } + + class IgnoreTypeViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + @BindView(android.R.id.text1) + lateinit var text: TextView + + init { + ButterKnife.bind(this, itemView) + } + + fun bind(activity: IgnoreTypeItem?) { + activity?.let { + text.setText(it.name) + } + } + } +} + diff --git a/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/IgnoreTypeItem.kt b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/IgnoreTypeItem.kt new file mode 100644 index 000000000..ff9c4e29f --- /dev/null +++ b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/IgnoreTypeItem.kt @@ -0,0 +1,6 @@ +package de.kuschku.quasseldroid.ui.coresettings.ignoreitem + +import android.support.annotation.StringRes +import de.kuschku.libquassel.quassel.syncables.IgnoreListManager + +data class IgnoreTypeItem(val value: IgnoreListManager.IgnoreType, @StringRes val name: Int) diff --git a/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/ScopeTypeAdapter.kt b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/ScopeTypeAdapter.kt new file mode 100644 index 000000000..21eec1e61 --- /dev/null +++ b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/ScopeTypeAdapter.kt @@ -0,0 +1,71 @@ +package de.kuschku.quasseldroid.ui.coresettings.ignoreitem + +import android.support.v7.widget.RecyclerView +import android.support.v7.widget.ThemedSpinnerAdapter +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import butterknife.BindView +import butterknife.ButterKnife +import de.kuschku.libquassel.quassel.syncables.IgnoreListManager +import de.kuschku.quasseldroid.R +import de.kuschku.quasseldroid.util.ui.ContextThemeWrapper +import de.kuschku.quasseldroid.util.ui.RecyclerSpinnerAdapter + +class ScopeTypeAdapter(val data: List<ScopeTypeItem>) : + RecyclerSpinnerAdapter<ScopeTypeAdapter.ScopeTypeViewHolder>(), + ThemedSpinnerAdapter { + + override fun isEmpty() = data.isEmpty() + + override fun onBindViewHolder(holder: ScopeTypeViewHolder, position: Int) = + holder.bind(getItem(position)) + + override fun onCreateViewHolder(parent: ViewGroup, dropDown: Boolean) + : ScopeTypeViewHolder { + val inflater = LayoutInflater.from( + if (dropDown) + ContextThemeWrapper(parent.context, dropDownViewTheme) + else + parent.context + ) + val view = inflater.inflate(R.layout.widget_spinner_item_toolbar, parent, false) + return ScopeTypeViewHolder( + view + ) + } + + override fun getItem(position: Int) = data[position] + + override fun getItemId(position: Int) = getItem(position).value.value.toLong() + + override fun hasStableIds() = true + + override fun getCount() = data.size + + fun indexOf(value: IgnoreListManager.ScopeType): Int? { + for ((key, item) in data.withIndex()) { + if (item.value.value == value.value) { + return key + } + } + return null + } + + class ScopeTypeViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + @BindView(android.R.id.text1) + lateinit var text: TextView + + init { + ButterKnife.bind(this, itemView) + } + + fun bind(activity: ScopeTypeItem?) { + activity?.let { + text.setText(it.name) + } + } + } +} + diff --git a/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/ScopeTypeItem.kt b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/ScopeTypeItem.kt new file mode 100644 index 000000000..b8f4e482f --- /dev/null +++ b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/ScopeTypeItem.kt @@ -0,0 +1,6 @@ +package de.kuschku.quasseldroid.ui.coresettings.ignoreitem + +import android.support.annotation.StringRes +import de.kuschku.libquassel.quassel.syncables.IgnoreListManager + +data class ScopeTypeItem(val value: IgnoreListManager.ScopeType, @StringRes val name: Int) diff --git a/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/StrictnessTypeAdapter.kt b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/StrictnessTypeAdapter.kt new file mode 100644 index 000000000..a30682a30 --- /dev/null +++ b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/StrictnessTypeAdapter.kt @@ -0,0 +1,71 @@ +package de.kuschku.quasseldroid.ui.coresettings.ignoreitem + +import android.support.v7.widget.RecyclerView +import android.support.v7.widget.ThemedSpinnerAdapter +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import butterknife.BindView +import butterknife.ButterKnife +import de.kuschku.libquassel.quassel.syncables.IgnoreListManager +import de.kuschku.quasseldroid.R +import de.kuschku.quasseldroid.util.ui.ContextThemeWrapper +import de.kuschku.quasseldroid.util.ui.RecyclerSpinnerAdapter + +class StrictnessTypeAdapter(val data: List<StrictnessTypeItem>) : + RecyclerSpinnerAdapter<StrictnessTypeAdapter.StrictnessTypeViewHolder>(), + ThemedSpinnerAdapter { + + override fun isEmpty() = data.isEmpty() + + override fun onBindViewHolder(holder: StrictnessTypeViewHolder, position: Int) = + holder.bind(getItem(position)) + + override fun onCreateViewHolder(parent: ViewGroup, dropDown: Boolean) + : StrictnessTypeViewHolder { + val inflater = LayoutInflater.from( + if (dropDown) + ContextThemeWrapper(parent.context, dropDownViewTheme) + else + parent.context + ) + val view = inflater.inflate(R.layout.widget_spinner_item_toolbar, parent, false) + return StrictnessTypeViewHolder( + view + ) + } + + override fun getItem(position: Int) = data[position] + + override fun getItemId(position: Int) = getItem(position).value.value.toLong() + + override fun hasStableIds() = true + + override fun getCount() = data.size + + fun indexOf(value: IgnoreListManager.StrictnessType): Int? { + for ((key, item) in data.withIndex()) { + if (item.value.value == value.value) { + return key + } + } + return null + } + + class StrictnessTypeViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + @BindView(android.R.id.text1) + lateinit var text: TextView + + init { + ButterKnife.bind(this, itemView) + } + + fun bind(activity: StrictnessTypeItem?) { + activity?.let { + text.setText(it.name) + } + } + } +} + diff --git a/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/StrictnessTypeItem.kt b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/StrictnessTypeItem.kt new file mode 100644 index 000000000..756798538 --- /dev/null +++ b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignoreitem/StrictnessTypeItem.kt @@ -0,0 +1,6 @@ +package de.kuschku.quasseldroid.ui.coresettings.ignoreitem + +import android.support.annotation.StringRes +import de.kuschku.libquassel.quassel.syncables.IgnoreListManager + +data class StrictnessTypeItem(val value: IgnoreListManager.StrictnessType, @StringRes val name: Int) diff --git a/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignorelist/DragSortItemTouchHelperCallback.kt b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignorelist/DragSortItemTouchHelperCallback.kt new file mode 100644 index 000000000..06fc9335c --- /dev/null +++ b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignorelist/DragSortItemTouchHelperCallback.kt @@ -0,0 +1,28 @@ +package de.kuschku.quasseldroid.ui.coresettings.ignorelist + +import android.support.v7.widget.RecyclerView +import android.support.v7.widget.helper.ItemTouchHelper + +class DragSortItemTouchHelperCallback(private val adapter: IgnoreListAdapter) : + ItemTouchHelper.Callback() { + override fun isLongPressDragEnabled() = true + + override fun isItemViewSwipeEnabled() = true + + override fun getMovementFlags(recyclerView: RecyclerView, + viewHolder: RecyclerView.ViewHolder): Int { + val dragFlags = ItemTouchHelper.UP or ItemTouchHelper.DOWN + val swipeFlags = ItemTouchHelper.START or ItemTouchHelper.END + return makeMovementFlags(dragFlags, swipeFlags) + } + + override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, + target: RecyclerView.ViewHolder): Boolean { + adapter.move(viewHolder.adapterPosition, target.adapterPosition) + return true + } + + override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { + adapter.remove(viewHolder.adapterPosition) + } +} diff --git a/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignorelist/IgnoreListActivity.kt b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignorelist/IgnoreListActivity.kt new file mode 100644 index 000000000..e5effd234 --- /dev/null +++ b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignorelist/IgnoreListActivity.kt @@ -0,0 +1,5 @@ +package de.kuschku.quasseldroid.ui.coresettings.ignorelist + +import de.kuschku.quasseldroid.util.ui.SettingsActivity + +class IgnoreListActivity : SettingsActivity(IgnoreListFragment()) diff --git a/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignorelist/IgnoreListAdapter.kt b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignorelist/IgnoreListAdapter.kt new file mode 100644 index 000000000..2c204b871 --- /dev/null +++ b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignorelist/IgnoreListAdapter.kt @@ -0,0 +1,115 @@ +package de.kuschku.quasseldroid.ui.coresettings.ignorelist + +import android.support.v7.widget.RecyclerView +import android.support.v7.widget.SwitchCompat +import android.view.LayoutInflater +import android.view.MotionEvent +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import butterknife.BindView +import butterknife.ButterKnife +import de.kuschku.libquassel.quassel.syncables.IgnoreListManager +import de.kuschku.quasseldroid.R +import java.util.* + +class IgnoreListAdapter( + private val clickListener: (IgnoreListManager.IgnoreListItem) -> Unit, + private val dragListener: (IgnoreItemViewHolder) -> Unit +) : RecyclerView.Adapter<IgnoreListAdapter.IgnoreItemViewHolder>() { + private val data = mutableListOf<IgnoreListManager.IgnoreListItem>() + var list: List<IgnoreListManager.IgnoreListItem> + get() = data + set(value) { + val length = data.size + data.clear() + notifyItemRangeRemoved(0, length) + data.addAll(value) + notifyItemRangeInserted(0, list.size) + } + + fun add(item: IgnoreListManager.IgnoreListItem) { + val index = data.size + data.add(item) + notifyItemInserted(index) + } + + fun replace(index: Int, item: IgnoreListManager.IgnoreListItem) { + data[index] = item + notifyItemChanged(index) + } + + fun indexOf(rule: String) = data.map(IgnoreListManager.IgnoreListItem::ignoreRule).indexOf(rule) + + fun remove(index: Int) { + data.removeAt(index) + notifyItemRemoved(index) + } + + fun move(from: Int, to: Int) { + Collections.swap(data, from, to) + notifyItemMoved(from, to) + } + + fun toggle(item: IgnoreListManager.IgnoreListItem, isActive: Boolean) { + val index = indexOf(item.ignoreRule) + data[index] = data[index].copy(isActive = isActive) + } + + override fun getItemCount() = data.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = IgnoreItemViewHolder( + LayoutInflater.from(parent.context).inflate(R.layout.settings_ignorelist_item, parent, false), + clickListener, + ::toggle, + dragListener + ) + + override fun onBindViewHolder(holder: IgnoreItemViewHolder, position: Int) { + holder.bind(data[position]) + } + + class IgnoreItemViewHolder( + itemView: View, + clickListener: (IgnoreListManager.IgnoreListItem) -> Unit, + toggleListener: (IgnoreListManager.IgnoreListItem, Boolean) -> Unit, + dragListener: (IgnoreItemViewHolder) -> Unit + ) : RecyclerView.ViewHolder(itemView) { + @BindView(R.id.title) + lateinit var title: TextView + + @BindView(R.id.toggle) + lateinit var toggle: SwitchCompat + + @BindView(R.id.handle) + lateinit var handle: View + + private var item: IgnoreListManager.IgnoreListItem? = null + + init { + ButterKnife.bind(this, itemView) + itemView.setOnClickListener { + item?.let { + clickListener(it) + } + } + toggle.setOnCheckedChangeListener { _, isChecked -> + item?.let { + toggleListener.invoke(it, isChecked) + } + } + handle.setOnTouchListener { _, event -> + if (event.action == MotionEvent.ACTION_DOWN) { + dragListener.invoke(this) + } + false + } + } + + fun bind(item: IgnoreListManager.IgnoreListItem) { + this.item = item + title.text = item.ignoreRule + toggle.isChecked = item.isActive + } + } +} diff --git a/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignorelist/IgnoreListFragment.kt b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignorelist/IgnoreListFragment.kt new file mode 100644 index 000000000..751141e0d --- /dev/null +++ b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignorelist/IgnoreListFragment.kt @@ -0,0 +1,101 @@ +package de.kuschku.quasseldroid.ui.coresettings.ignorelist + +import android.app.Activity +import android.arch.lifecycle.Observer +import android.content.Intent +import android.os.Bundle +import android.support.design.widget.FloatingActionButton +import android.support.v7.widget.DefaultItemAnimator +import android.support.v7.widget.LinearLayoutManager +import android.support.v7.widget.RecyclerView +import android.support.v7.widget.helper.ItemTouchHelper +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import butterknife.BindView +import butterknife.ButterKnife +import de.kuschku.libquassel.quassel.syncables.IgnoreListManager +import de.kuschku.libquassel.util.Optional +import de.kuschku.quasseldroid.R +import de.kuschku.quasseldroid.ui.coresettings.SettingsFragment +import de.kuschku.quasseldroid.ui.coresettings.ignoreitem.IgnoreItemActivity +import de.kuschku.quasseldroid.util.helper.toLiveData + +class IgnoreListFragment : SettingsFragment() { + @BindView(R.id.list) + lateinit var list: RecyclerView + + @BindView(R.id.add) + lateinit var add: FloatingActionButton + + private var ignoreListManager: Pair<IgnoreListManager, IgnoreListManager>? = null + + lateinit var helper: ItemTouchHelper + + private val adapter = IgnoreListAdapter(::itemClick, ::startDrag) + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle?): View? { + val view = inflater.inflate(R.layout.settings_ignorelist, container, false) + ButterKnife.bind(this, view) + + list.adapter = adapter + list.layoutManager = LinearLayoutManager(requireContext()) + list.itemAnimator = DefaultItemAnimator() + + val callback = DragSortItemTouchHelperCallback(adapter) + helper = ItemTouchHelper(callback) + helper.attachToRecyclerView(list) + + viewModel.ignoreListManager + .filter(Optional<IgnoreListManager>::isPresent) + .map(Optional<IgnoreListManager>::get) + .toLiveData().observe(this, Observer { + if (it != null) { + this.ignoreListManager = Pair(it, it.copy()) + this.ignoreListManager?.let { (_, data) -> + if (adapter.list.isEmpty()) adapter.list = data.ignoreList() + } + } + }) + + return view + } + + fun itemClick(item: IgnoreListManager.IgnoreListItem) { + val intent = Intent(requireContext(), IgnoreItemActivity::class.java) + intent.putExtra("item", item) + startActivityForResult(intent, REQUEST_UPDATE_RULE) + } + + fun startDrag(holder: IgnoreListAdapter.IgnoreItemViewHolder) = helper.startDrag(holder) + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + if (resultCode == Activity.RESULT_OK && data != null) { + when (requestCode) { + REQUEST_UPDATE_RULE -> { + val oldRule = data.getSerializableExtra("old") as? IgnoreListManager.IgnoreListItem + val newRule = data.getSerializableExtra("new") as? IgnoreListManager.IgnoreListItem + + println(oldRule) + println(newRule) + + if (oldRule != null && newRule != null) { + val index = adapter.indexOf(oldRule.ignoreRule) + adapter.replace(index, newRule) + } + } + } + } + } + + override fun onSave() = ignoreListManager?.let { (it, data) -> + data.setIgnoreList(adapter.list) + it.requestUpdate(data.toVariantMap()) + true + } ?: false + + companion object { + private const val REQUEST_UPDATE_RULE = 1 + } +} diff --git a/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignorelist/IgnoreListFragmentProvider.kt b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignorelist/IgnoreListFragmentProvider.kt new file mode 100644 index 000000000..b2ee2d7e7 --- /dev/null +++ b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/ignorelist/IgnoreListFragmentProvider.kt @@ -0,0 +1,10 @@ +package de.kuschku.quasseldroid.ui.coresettings.ignorelist + +import dagger.Module +import dagger.android.ContributesAndroidInjector + +@Module +abstract class IgnoreListFragmentProvider { + @ContributesAndroidInjector + abstract fun bindIgnoreFragment(): IgnoreListFragment +} diff --git a/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/networkconfig/NetworkConfigFragment.kt b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/networkconfig/NetworkConfigFragment.kt index 8ef966015..ceac297b1 100644 --- a/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/networkconfig/NetworkConfigFragment.kt +++ b/app/src/main/java/de/kuschku/quasseldroid/ui/coresettings/networkconfig/NetworkConfigFragment.kt @@ -55,8 +55,8 @@ class NetworkConfigFragment : SettingsFragment() { ButterKnife.bind(this, view) viewModel.networkConfig - .filter(Optional<NetworkConfig?>::isPresent) - .map(Optional<NetworkConfig?>::get) + .filter(Optional<NetworkConfig>::isPresent) + .map(Optional<NetworkConfig>::get) .firstElement() .toLiveData().observe(this, Observer { if (it != null) { @@ -97,4 +97,4 @@ class NetworkConfigFragment : SettingsFragment() { it.requestUpdate(data.toVariantMap()) true } ?: false -} \ No newline at end of file +} diff --git a/app/src/main/res/layout/settings_ignoreitem.xml b/app/src/main/res/layout/settings_ignoreitem.xml new file mode 100644 index 000000000..cec671aa9 --- /dev/null +++ b/app/src/main/res/layout/settings_ignoreitem.xml @@ -0,0 +1,107 @@ +<?xml version="1.0" encoding="utf-8"?> +<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:scrollbars="vertical"> + + <LinearLayout style="@style/Widget.CoreSettings.Wrapper"> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:minHeight="48dp"> + + <android.support.v7.widget.AppCompatImageView + style="@style/Widget.CoreSettings.PrimaryItemIcon" + app:srcCompat="@drawable/ic_filter" /> + + <android.support.v7.widget.SwitchCompat + android:id="@+id/enabled" + style="@style/Widget.CoreSettings.PrimaryItemSwitch" + android:text="@string/settings_ignoreitem_enabled" /> + </LinearLayout> + + <LinearLayout + style="@style/Widget.CoreSettings.DependentGroup" + android:visibility="visible"> + + <android.support.design.widget.TextInputLayout + style="@style/Widget.CoreSettings.EditTextLayout" + android:hint="@string/settings_ignoreitem_ignorerule"> + + <android.support.design.widget.TextInputEditText + android:id="@+id/ignorerule" + style="@style/Widget.CoreSettings.EditText" + tools:text="https://clbin.com/*.jpg*" /> + </android.support.design.widget.TextInputLayout> + + <android.support.v7.widget.SwitchCompat + android:id="@+id/isregex" + style="@style/Widget.CoreSettings.PrimaryItemSwitch" + android:text="@string/settings_ignoreitem_isregex" /> + + <TextView + style="@style/Widget.CoreSettings.EditTextHeader" + android:text="@string/settings_ignoreitem_type" /> + + <Spinner + android:id="@+id/type" + android:layout_width="match_parent" + android:layout_height="wrap_content" + tools:listitem="@layout/settings_item" /> + + <TextView + style="@style/Widget.CoreSettings.EditTextHeader" + android:text="@string/settings_ignoreitem_strictness" /> + + <Spinner + android:id="@+id/strictness" + android:layout_width="match_parent" + android:layout_height="wrap_content" + tools:listitem="@layout/settings_item" /> + </LinearLayout> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:minHeight="48dp"> + + <android.support.v7.widget.AppCompatImageView + style="@style/Widget.CoreSettings.PrimaryItemIcon" + app:srcCompat="@drawable/ic_tag_text" /> + + <TextView + style="@style/Widget.CoreSettings.PrimaryItemSwitch" + android:text="@string/settings_ignoreitem_scope" /> + </LinearLayout> + + <LinearLayout + style="@style/Widget.CoreSettings.DependentGroup" + android:visibility="visible"> + + <Spinner + android:id="@+id/scope" + android:layout_width="match_parent" + android:layout_height="wrap_content" + tools:listitem="@layout/settings_item" /> + </LinearLayout> + + <LinearLayout + android:id="@+id/scopegroup" + style="@style/Widget.CoreSettings.DependentGroup" + android:visibility="visible"> + + <android.support.design.widget.TextInputLayout + style="@style/Widget.CoreSettings.EditTextLayout" + android:hint="@string/settings_ignoreitem_scoperule"> + + <android.support.design.widget.TextInputEditText + android:id="@+id/scoperule" + style="@style/Widget.CoreSettings.EditText" + tools:text="https://clbin.com/*.jpg*" /> + </android.support.design.widget.TextInputLayout> + </LinearLayout> + </LinearLayout> +</android.support.v4.widget.NestedScrollView> diff --git a/app/src/main/res/layout/settings_ignorelist.xml b/app/src/main/res/layout/settings_ignorelist.xml new file mode 100644 index 000000000..f389ea637 --- /dev/null +++ b/app/src/main/res/layout/settings_ignorelist.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8"?> +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <android.support.v7.widget.RecyclerView + android:id="@+id/list" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:paddingLeft="2dp" + android:paddingRight="2dp" + tools:listitem="@layout/settings_item" /> + + <android.support.design.widget.FloatingActionButton + android:id="@+id/add" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="end|bottom" + android:layout_margin="16dp" + android:visibility="gone" + app:fabSize="normal" + app:srcCompat="@drawable/ic_add" + app:tint="?colorTextPrimaryInverse" /> + +</FrameLayout> diff --git a/app/src/main/res/layout/settings_ignorelist_item.xml b/app/src/main/res/layout/settings_ignorelist_item.xml new file mode 100644 index 000000000..e38964f53 --- /dev/null +++ b/app/src/main/res/layout/settings_ignorelist_item.xml @@ -0,0 +1,54 @@ +<?xml version="1.0" encoding="utf-8"?> +<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_margin="2dp" + app:cardElevation="2dp"> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="?selectableItemBackground" + android:focusable="true" + android:gravity="center_vertical" + android:minHeight="?listPreferredItemHeightSmall"> + + <android.support.v7.widget.AppCompatImageView + android:id="@+id/handle" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:layout_gravity="center_vertical" + android:paddingEnd="32dp" + android:paddingLeft="?listPreferredItemPaddingRight" + android:paddingRight="32dp" + android:paddingStart="?listPreferredItemPaddingRight" + app:srcCompat="@drawable/ic_reorder" + app:tint="?colorTextSecondary" /> + + <TextView + android:id="@+id/title" + android:layout_width="0dip" + android:layout_height="wrap_content" + android:layout_weight="1" + android:ellipsize="marquee" + android:orientation="vertical" + android:paddingBottom="16dp" + android:paddingTop="16dp" + android:singleLine="true" + android:textAppearance="?android:textAppearanceMedium" + android:textColor="?colorTextPrimary" + android:textSize="16sp" + tools:text="https://clbin.com/*.jpg*" /> + + <android.support.v7.widget.SwitchCompat + android:id="@+id/toggle" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:paddingEnd="?listPreferredItemPaddingRight" + android:paddingLeft="?listPreferredItemPaddingLeft" + android:paddingRight="?listPreferredItemPaddingRight" + android:paddingStart="?listPreferredItemPaddingLeft" /> + </LinearLayout> +</android.support.v7.widget.CardView> diff --git a/app/src/main/res/values-de/strings_settings.xml b/app/src/main/res/values-de/strings_settings.xml index 39270f26f..e2f2eaa83 100644 --- a/app/src/main/res/values-de/strings_settings.xml +++ b/app/src/main/res/values-de/strings_settings.xml @@ -41,6 +41,23 @@ <string name="settings_ignorelist_title">Ignorieren-Liste</string> + <string name="settings_ignoreitem_title">Ignorieren-Regel</string> + <string name="settings_ignoreitem_enabled">Aktiviert</string> + <string name="settings_ignoreitem_ignorerule">Ignorier-Regel</string> + <string name="settings_ignoreitem_isregex">Regulärer Ausdruck</string> + <string name="settings_ignoreitem_type">Regeltyp</string> + <string name="settings_ignoreitem_type_sender">Absender</string> + <string name="settings_ignoreitem_type_message">Mitteilung</string> + <string name="settings_ignoreitem_type_ctcp">CTCP</string> + <string name="settings_ignoreitem_strictness">Striktheit</string> + <string name="settings_ignoreitem_strictness_soft">Dynamisch</string> + <string name="settings_ignoreitem_strictness_hard">Permanent</string> + <string name="settings_ignoreitem_scope">Gültigkeitsbereich</string> + <string name="settings_ignoreitem_scope_global">Global</string> + <string name="settings_ignoreitem_scope_network">Netzwerk</string> + <string name="settings_ignoreitem_scope_channel">Raum</string> + <string name="settings_ignoreitem_scoperule">Gültigkeitsregel</string> + <string name="settings_highlightlist_title">Hervorhebungen</string> <string name="settings_aliaslist_title">Aliase</string> diff --git a/app/src/main/res/values/strings_licenses.xml b/app/src/main/res/values/strings_licenses.xml index 43a1a979b..8fac7ecea 100644 --- a/app/src/main/res/values/strings_licenses.xml +++ b/app/src/main/res/values/strings_licenses.xml @@ -28,7 +28,8 @@ <p><strong>8. Limitation of Liability</strong>. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.</p> <p><strong>9. Accepting Warranty or Additional Liability</strong>. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.</p> ]]></string> - <string name="license_cc0" translatable="false" tools:ignore="TypographyOther"><![CDATA[ + <string name="license_cc_0" translatable="false" tools:ignore="TypographyOther"><![CDATA[ + <h2>Creative Commons</h2> <h2>CC0 1.0 Universal</h2> <h3><em>Statement of Purpose</em></h3> <p>The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work").</p> @@ -50,6 +51,54 @@ <p>c. Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work.</p> <p>d. Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work.</p> ]]></string> + <string name="license_cc_by_sa_3.0" translatable="false" tools:ignore="TypographyOther"><![CDATA[ + <h2>Creative Commons</h2> + <h2>Attribution-ShareAlike 3.0 Unported</h2> + <h3><em>License</em></h3> + <p>THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.</p> + <p>BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.</p> + <p><strong>1. Definitions</strong></p> + <p>a. <strong>"Adaptation"</strong>means a work based upon the Work, or upon the Work and other pre-existing works, such as a translation, adaptation, derivative work, arrangement of music or other alterations of a literary or artistic work, or phonogram or performance and includes cinematographic adaptations or any other form in which the Work may be recast, transformed, or adapted including in any form recognizably derived from the original, except that a work that constitutes a Collection will not be considered an Adaptation for the purpose of this License. For the avoidance of doubt, where the Work is a musical work, performance or phonogram, the synchronization of the Work in timed-relation with a moving image ("synching") will be considered an Adaptation for the purpose of this License.</p> + <p>b. <strong>"Collection"</strong>means a collection of literary or artistic works, such as encyclopedias and anthologies, or performances, phonograms or broadcasts, or other works or subject matter other than works listed in Section 1(f) below, which, by reason of the selection and arrangement of their contents, constitute intellectual creations, in which the Work is included in its entirety in unmodified form along with one or more other contributions, each constituting separate and independent works in themselves, which together are assembled into a collective whole. A work that constitutes a Collection will not be considered an Adaptation (as defined below) for the purposes of this License.</p> + <p>c. <strong>"Creative Commons Compatible License"</strong>means a license that is listed at https://creativecommons.org/compatiblelicenses that has been approved by Creative Commons as being essentially equivalent to this License, including, at a minimum, because that license: (i) contains terms that have the same purpose, meaning and effect as the License Elements of this License; and, (ii) explicitly permits the relicensing of adaptations of works made available under that license under this License or a Creative Commons jurisdiction license with the same License Elements as this License.</p> + <p>d. <strong>"Distribute"</strong>means to make available to the public the original and copies of the Work or Adaptation, as appropriate, through sale or other transfer of ownership.</p> + <p>e. <strong>"License Elements"</strong>means the following high-level license attributes as selected by Licensor and indicated in the title of this License: Attribution, ShareAlike.</p> + <p>f. <strong>"Licensor"</strong>means the individual, individuals, entity or entities that offer(s) the Work under the terms of this License.</p> + <p>g. <strong>"Original Author"</strong>means, in the case of a literary or artistic work, the individual, individuals, entity or entities who created the Work or if no individual or entity can be identified, the publisher; and in addition (i) in the case of a performance the actors, singers, musicians, dancers, and other persons who act, sing, deliver, declaim, play in, interpret or otherwise perform literary or artistic works or expressions of folklore; (ii) in the case of a phonogram the producer being the person or legal entity who first fixes the sounds of a performance or other sounds; and, (iii) in the case of broadcasts, the organization that transmits the broadcast.</p> + <p>h. <strong>"Work"</strong>means the literary and/or artistic work offered under the terms of this License including without limitation any production in the literary, scientific and artistic domain, whatever may be the mode or form of its expression including digital form, such as a book, pamphlet and other writing; a lecture, address, sermon or other work of the same nature; a dramatic or dramatico-musical work; a choreographic work or entertainment in dumb show; a musical composition with or without words; a cinematographic work to which are assimilated works expressed by a process analogous to cinematography; a work of drawing, painting, architecture, sculpture, engraving or lithography; a photographic work to which are assimilated works expressed by a process analogous to photography; a work of applied art; an illustration, map, plan, sketch or three-dimensional work relative to geography, topography, architecture or science; a performance; a broadcast; a phonogram; a compilation of data to the extent it is protected as a copyrightable work; or a work performed by a variety or circus performer to the extent it is not otherwise considered a literary or artistic work.</p> + <p>i. <strong>"You"</strong>means an individual or entity exercising rights under this License who has not previously violated the terms of this License with respect to the Work, or who has received express permission from the Licensor to exercise rights under this License despite a previous violation.</p> + <p>j. <strong>"Publicly Perform"</strong>means to perform public recitations of the Work and to communicate to the public those public recitations, by any means or process, including by wire or wireless means or public digital performances; to make available to the public Works in such a way that members of the public may access these Works from a place and at a place individually chosen by them; to perform the Work to the public by any means or process and the communication to the public of the performances of the Work, including by public digital performance; to broadcast and rebroadcast the Work by any means including signs, sounds or images.</p> + <p>k. <strong>"Reproduce"</strong>means to make copies of the Work by any means including without limitation by sound or visual recordings and the right of fixation and reproducing fixations of the Work, including storage of a protected performance or phonogram in digital form or other electronic medium.</p> + <p><strong>2. Fair Dealing Rights.</strong>Nothing in this License is intended to reduce, limit, or restrict any uses free from copyright or rights arising from limitations or exceptions that are provided for in connection with the copyright protection under copyright law or other applicable laws.</p> + <p><strong>3. License Grant.</strong>Subject to the terms and conditions of this License, Licensor hereby grants You a worldwide, royalty-free, non-exclusive, perpetual (for the duration of the applicable copyright) license to exercise the rights in the Work as stated below:</p> + <p>a. to Reproduce the Work, to incorporate the Work into one or more Collections, and to Reproduce the Work as incorporated in the Collections;</p> + <p>b. to create and Reproduce Adaptations provided that any such Adaptation, including any translation in any medium, takes reasonable steps to clearly label, demarcate or otherwise identify that changes were made to the original Work. For example, a translation could be marked "The original work was translated from English to Spanish," or a modification could indicate "The original work has been modified.";</p> + <p>c. to Distribute and Publicly Perform the Work including as incorporated in Collections; and,</p> + <p>d. to Distribute and Publicly Perform Adaptations.</p> + <p>e. For the avoidance of doubt:</p> + <p>i. <strong>Non-waivable Compulsory License Schemes</strong>. In those jurisdictions in which the right to collect royalties through any statutory or compulsory licensing scheme cannot be waived, the Licensor reserves the exclusive right to collect such royalties for any exercise by You of the rights granted under this License;</p> + <p>ii. <strong>Waivable Compulsory License Schemes</strong>. In those jurisdictions in which the right to collect royalties through any statutory or compulsory licensing scheme can be waived, the Licensor waives the exclusive right to collect such royalties for any exercise by You of the rights granted under this License; and,</p> + <p>iii. <strong>Voluntary License Schemes</strong>. The Licensor waives the right to collect royalties, whether individually or, in the event that the Licensor is a member of a collecting society that administers voluntary licensing schemes, via that society, from any exercise by You of the rights granted under this License.</p> + <p>The above rights may be exercised in all media and formats whether now known or hereafter devised. The above rights include the right to make such modifications as are technically necessary to exercise the rights in other media and formats. Subject to Section 8(f), all rights not expressly granted by Licensor are hereby reserved.</p> + <p><strong>4. Restrictions.</strong>The license granted in Section 3 above is expressly made subject to and limited by the following restrictions:</p> + <p>a. You may Distribute or Publicly Perform the Work only under the terms of this License. You must include a copy of, or the Uniform Resource Identifier (URI) for, this License with every copy of the Work You Distribute or Publicly Perform. You may not offer or impose any terms on the Work that restrict the terms of this License or the ability of the recipient of the Work to exercise the rights granted to that recipient under the terms of the License. You may not sublicense the Work. You must keep intact all notices that refer to this License and to the disclaimer of warranties with every copy of the Work You Distribute or Publicly Perform. When You Distribute or Publicly Perform the Work, You may not impose any effective technological measures on the Work that restrict the ability of a recipient of the Work from You to exercise the rights granted to that recipient under the terms of the License. This Section 4(a) applies to the Work as incorporated in a Collection, but this does not require the Collection apart from the Work itself to be made subject to the terms of this License. If You create a Collection, upon notice from any Licensor You must, to the extent practicable, remove from the Collection any credit as required by Section 4(c), as requested. If You create an Adaptation, upon notice from any Licensor You must, to the extent practicable, remove from the Adaptation any credit as required by Section 4(c), as requested.</p> + <p>b. You may Distribute or Publicly Perform an Adaptation only under the terms of: (i) this License; (ii) a later version of this License with the same License Elements as this License; (iii) a Creative Commons jurisdiction license (either this or a later license version) that contains the same License Elements as this License (e.g., Attribution-ShareAlike 3.0 US)); (iv) a Creative Commons Compatible License. If you license the Adaptation under one of the licenses mentioned in (iv), you must comply with the terms of that license. If you license the Adaptation under the terms of any of the licenses mentioned in (i), (ii) or (iii) (the "Applicable License"), you must comply with the terms of the Applicable License generally and the following provisions: (I) You must include a copy of, or the URI for, the Applicable License with every copy of each Adaptation You Distribute or Publicly Perform; (II) You may not offer or impose any terms on the Adaptation that restrict the terms of the Applicable License or the ability of the recipient of the Adaptation to exercise the rights granted to that recipient under the terms of the Applicable License; (III) You must keep intact all notices that refer to the Applicable License and to the disclaimer of warranties with every copy of the Work as included in the Adaptation You Distribute or Publicly Perform; (IV) when You Distribute or Publicly Perform the Adaptation, You may not impose any effective technological measures on the Adaptation that restrict the ability of a recipient of the Adaptation from You to exercise the rights granted to that recipient under the terms of the Applicable License. This Section 4(b) applies to the Adaptation as incorporated in a Collection, but this does not require the Collection apart from the Adaptation itself to be made subject to the terms of the Applicable License.</p> + <p>c. If You Distribute, or Publicly Perform the Work or any Adaptations or Collections, You must, unless a request has been made pursuant to Section 4(a), keep intact all copyright notices for the Work and provide, reasonable to the medium or means You are utilizing: (i) the name of the Original Author (or pseudonym, if applicable) if supplied, and/or if the Original Author and/or Licensor designate another party or parties (e.g., a sponsor institute, publishing entity, journal) for attribution ("Attribution Parties") in Licensor's copyright notice, terms of service or by other reasonable means, the name of such party or parties; (ii) the title of the Work if supplied; (iii) to the extent reasonably practicable, the URI, if any, that Licensor specifies to be associated with the Work, unless such URI does not refer to the copyright notice or licensing information for the Work; and (iv) , consistent with Ssection 3(b), in the case of an Adaptation, a credit identifying the use of the Work in the Adaptation (e.g., "French translation of the Work by Original Author," or "Screenplay based on original Work by Original Author"). The credit required by this Section 4(c) may be implemented in any reasonable manner; provided, however, that in the case of a Adaptation or Collection, at a minimum such credit will appear, if a credit for all contributing authors of the Adaptation or Collection appears, then as part of these credits and in a manner at least as prominent as the credits for the other contributing authors. For the avoidance of doubt, You may only use the credit required by this Section for the purpose of attribution in the manner set out above and, by exercising Your rights under this License, You may not implicitly or explicitly assert or imply any connection with, sponsorship or endorsement by the Original Author, Licensor and/or Attribution Parties, as appropriate, of You or Your use of the Work, without the separate, express prior written permission of the Original Author, Licensor and/or Attribution Parties.</p> + <p>d. Except as otherwise agreed in writing by the Licensor or as may be otherwise permitted by applicable law, if You Reproduce, Distribute or Publicly Perform the Work either by itself or as part of any Adaptations or Collections, You must not distort, mutilate, modify or take other derogatory action in relation to the Work which would be prejudicial to the Original Author's honor or reputation. Licensor agrees that in those jurisdictions (e.g. Japan), in which any exercise of the right granted in Section 3(b) of this License (the right to make Adaptations) would be deemed to be a distortion, mutilation, modification or other derogatory action prejudicial to the Original Author's honor and reputation, the Licensor will waive or not assert, as appropriate, this Section, to the fullest extent permitted by the applicable national law, to enable You to reasonably exercise Your right under Section 3(b) of this License (right to make Adaptations) but not otherwise.</p> + <p><strong>5. Representations, Warranties and Disclaimer</strong></p> + <p>UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING, LICENSOR OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU.</p> + <p><strong>6. Limitation on Liability.</strong>EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.</p> + <p><strong>7. Termination</strong></p> + <p>a. This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License. Individuals or entities who have received Adaptations or Collections from You under this License, however, will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will survive any termination of this License.</p> + <p>b. Subject to the above terms and conditions, the license granted here is perpetual (for the duration of the applicable copyright in the Work). Notwithstanding the above, Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time; provided, however that any such election will not serve to withdraw this License (or any other license that has been, or is required to be, granted under the terms of this License), and this License will continue in full force and effect unless terminated as stated above.</p> + <p><strong>8. Miscellaneous</strong></p> + <p>a. Each time You Distribute or Publicly Perform the Work or a Collection, the Licensor offers to the recipient a license to the Work on the same terms and conditions as the license granted to You under this License.</p> + <p>b. Each time You Distribute or Publicly Perform an Adaptation, Licensor offers to the recipient a license to the original Work on the same terms and conditions as the license granted to You under this License.</p> + <p>c. If any provision of this License is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this License, and without further action by the parties to this agreement, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.</p> + <p>d. No term or provision of this License shall be deemed waived and no breach consented to unless such waiver or consent shall be in writing and signed by the party to be charged with such waiver or consent.</p> + <p>e. This License constitutes the entire agreement between the parties with respect to the Work licensed here. There are no understandings, agreements or representations with respect to the Work not specified here. Licensor shall not be bound by any additional provisions that may appear in any communication from You. This License may not be modified without the mutual written agreement of the Licensor and You.</p> + <p>f. The rights granted under, and the subject matter referenced, in this License were drafted utilizing the terminology of the Berne Convention for the Protection of Literary and Artistic Works (as amended on September 28, 1979), the Rome Convention of 1961, the WIPO Copyright Treaty of 1996, the WIPO Performances and Phonograms Treaty of 1996 and the Universal Copyright Convention (as revised on July 24, 1971). These rights and subject matter take effect in the relevant jurisdiction in which the License terms are sought to be enforced according to the corresponding provisions of the implementation of those treaty provisions in the applicable national law. If the standard suite of rights granted under applicable copyright law includes additional rights not granted under this License, such additional rights are deemed to be included in the License; this License is not intended to restrict the license of any rights under applicable law.</p> + ]]></string> <string name="license_emojijava" translatable="false" tools:ignore="TypographyOther"><![CDATA[ <h2>The MIT License (MIT)</h2> <p>Copyright (c) 2014-present Vincent DURMONT vdurmont@gmail.com</p> diff --git a/app/src/main/res/values/strings_settings.xml b/app/src/main/res/values/strings_settings.xml index 4500437c6..c124cb405 100644 --- a/app/src/main/res/values/strings_settings.xml +++ b/app/src/main/res/values/strings_settings.xml @@ -39,7 +39,24 @@ <string name="settings_chatlist_hide_inactive_buffers">Hide Inactive Chats</string> <string name="settings_chatlist_hide_inactive_networks">Hide Inactive Networks</string> - <string name="settings_ignorelist_title">Ignorelist</string> + <string name="settings_ignorelist_title">Ignore List</string> + + <string name="settings_ignoreitem_title">Ignore Rule</string> + <string name="settings_ignoreitem_enabled">Enabled</string> + <string name="settings_ignoreitem_ignorerule">Ignore Rule</string> + <string name="settings_ignoreitem_isregex">Regular Expression</string> + <string name="settings_ignoreitem_type">Type</string> + <string name="settings_ignoreitem_type_sender">Sender</string> + <string name="settings_ignoreitem_type_message">Message</string> + <string name="settings_ignoreitem_type_ctcp">Ctcp</string> + <string name="settings_ignoreitem_strictness">Strictness</string> + <string name="settings_ignoreitem_strictness_soft">Dynamic</string> + <string name="settings_ignoreitem_strictness_hard">Permanent</string> + <string name="settings_ignoreitem_scope">Scope</string> + <string name="settings_ignoreitem_scope_global">Global Scope</string> + <string name="settings_ignoreitem_scope_network">Network Scope</string> + <string name="settings_ignoreitem_scope_channel">Channel Scope</string> + <string name="settings_ignoreitem_scoperule">Scope Rule</string> <string name="settings_highlightlist_title">Highlights</string> diff --git a/app/src/main/res/values/styles_widgets.xml b/app/src/main/res/values/styles_widgets.xml index c162deec9..3aa0809a3 100644 --- a/app/src/main/res/values/styles_widgets.xml +++ b/app/src/main/res/values/styles_widgets.xml @@ -89,7 +89,7 @@ <style name="Widget.CoreSettings.PrimaryItemSwitch" parent=""> <item name="android:layout_width">match_parent</item> <item name="android:layout_height">wrap_content</item> - <item name="android:layout_gravity">fill_vertical</item> + <item name="android:layout_gravity">center_vertical</item> <item name="android:paddingTop">10dp</item> <item name="android:paddingBottom">10dp</item> <item name="android:gravity">center_vertical</item> @@ -135,6 +135,15 @@ <item name="android:textColor">?colorTextSecondary</item> </style> + <style name="Widget.CoreSettings.EditTextHeader" parent=""> + <item name="android:layout_width">match_parent</item> + <item name="android:layout_height">wrap_content</item> + <item name="android:paddingBottom">8dp</item> + <item name="android:paddingLeft">3dp</item> + <item name="android:paddingRight">3dp</item> + <item name="android:textSize">12sp</item> + </style> + <style name="Widget.Info.Header" parent=""> <item name="android:layout_width">match_parent</item> <item name="android:layout_height">wrap_content</item> diff --git a/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/IgnoreListManager.kt b/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/IgnoreListManager.kt index 8d262696e..5003a00ef 100644 --- a/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/IgnoreListManager.kt +++ b/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/IgnoreListManager.kt @@ -1,11 +1,12 @@ package de.kuschku.libquassel.quassel.syncables -import de.kuschku.libquassel.protocol.QVariant -import de.kuschku.libquassel.protocol.QVariantMap -import de.kuschku.libquassel.protocol.Type -import de.kuschku.libquassel.protocol.valueOr +import de.kuschku.libquassel.protocol.* import de.kuschku.libquassel.quassel.syncables.interfaces.IIgnoreListManager import de.kuschku.libquassel.session.SignalProxy +import de.kuschku.libquassel.util.GlobTransformer +import de.kuschku.libquassel.util.flag.and +import io.reactivex.subjects.BehaviorSubject +import java.io.Serializable class IgnoreListManager constructor( proxy: SignalProxy @@ -18,19 +19,251 @@ class IgnoreListManager constructor( initSetIgnoreList(properties["IgnoreList"].valueOr(::emptyMap)) } - override fun initIgnoreList(): QVariantMap = emptyMap() + override fun initIgnoreList() = mapOf( + "ignoreType" to QVariant.of(_ignoreList.map { + QVariant.of(it.type.value, Type.Int) + }, Type.QVariantList), + "ignoreRule" to QVariant.of(_ignoreList.map { + it.ignoreRule + }, Type.QStringList), + "isRegEx" to QVariant.of(_ignoreList.map { + QVariant.of(it.isRegEx, Type.Bool) + }, Type.QVariantList), + "strictness" to QVariant.of(_ignoreList.map { + QVariant.of(it.strictness.value, Type.Int) + }, Type.QVariantList), + "scope" to QVariant.of(_ignoreList.map { + QVariant.of(it.scope.value, Type.Int) + }, Type.QVariantList), + "scopeRule" to QVariant.of(_ignoreList.map { + it.scopeRule + }, Type.QStringList), + "isActive" to QVariant.of(_ignoreList.map { + QVariant.of(it.isActive, Type.Bool) + }, Type.QVariantList) + ) override fun initSetIgnoreList(ignoreList: QVariantMap) { + val ignoreTypeList = ignoreList["ignoreType"].valueOr<QVariantList>(::emptyList) + val ignoreRuleList = ignoreList["ignoreRule"].valueOr<QStringList>(::emptyList) + val isRegExList = ignoreList["isRegEx"].valueOr<QVariantList>(::emptyList) + val strictnessList = ignoreList["strictness"].valueOr<QVariantList>(::emptyList) + val scopeList = ignoreList["scope"].valueOr<QVariantList>(::emptyList) + val scopeRuleList = ignoreList["scopeRule"].valueOr<QStringList>(::emptyList) + val isActiveList = ignoreList["isActive"].valueOr<QVariantList>(::emptyList) + val size = ignoreTypeList.size + if (ignoreRuleList.size != size || isRegExList.size != size || strictnessList.size != size || + scopeList.size != size || scopeRuleList.size != size || isActiveList.size != size) + return + + _ignoreList = List(size, { + IgnoreListItem( + type = ignoreTypeList[it].value(0), + ignoreRule = ignoreRuleList[it] ?: "", + isRegEx = isRegExList[it].value(false), + strictness = strictnessList[it].value(0), + scope = scopeList[it].value(0), + scopeRule = scopeRuleList[it] ?: "", + isActive = isActiveList[it].value(false) + ) + }) } override fun addIgnoreListItem(type: Int, ignoreRule: String, isRegEx: Boolean, strictness: Int, scope: Int, scopeRule: String, isActive: Boolean) { - } + if (contains(ignoreRule)) return - override fun removeIgnoreListItem(ignoreRule: String) { + _ignoreList += IgnoreListItem(type, ignoreRule, isRegEx, strictness, scope, scopeRule, isActive) } + override fun removeIgnoreListItem(ignoreRule: String) = removeAt(indexOf(ignoreRule)) + override fun toggleIgnoreRule(ignoreRule: String) { + _ignoreList = _ignoreList.map { + if (it.ignoreRule == ignoreRule) it.toggleActive() else it + } + } + + fun indexOf(ignore: String): Int = _ignoreList.map(IgnoreListItem::ignoreRule).indexOf(ignore) + fun contains(ignore: String) = _ignoreList.map(IgnoreListItem::ignoreRule).contains(ignore) + fun isEmpty() = _ignoreList.isEmpty() + fun count() = _ignoreList.count() + fun removeAt(index: Int) { + _ignoreList = _ignoreList.drop(index) + } + + operator fun get(index: Int) = _ignoreList[index] + fun ignoreList() = _ignoreList + fun setIgnoreList(list: List<IgnoreListItem>) { + _ignoreList = list + } + + fun updates() = live_updates.map { this } + + fun copy() = IgnoreListManager(proxy).also { + it.fromVariantMap(toVariantMap()) + } + + enum class IgnoreType(val value: Int) { + SenderIgnore(0), + MessageIgnore(1), + CtcpIgnore(2); + + companion object { + private val byId = enumValues<IgnoreType>().associateBy(IgnoreType::value) + fun of(value: Int) = byId[value] ?: IgnoreType.SenderIgnore + } + } + + enum class StrictnessType(val value: Int) { + UnmatchedStrictness(0), + SoftStrictness(1), + HardStrictness(2); + + companion object { + private val byId = enumValues<StrictnessType>().associateBy(StrictnessType::value) + fun of(value: Int) = byId[value] ?: StrictnessType.UnmatchedStrictness + } + } + + enum class ScopeType(val value: Int) { + GlobalScope(0), + NetworkScope(1), + ChannelScope(2); + + companion object { + private val byId = enumValues<ScopeType>().associateBy(ScopeType::value) + fun of(value: Int) = byId[value] ?: ScopeType.GlobalScope + } + } + + class IgnoreListItem private constructor( + val type: IgnoreType, + val ignoreRule: String, + val isRegEx: Boolean, + val strictness: StrictnessType, + val scope: ScopeType, + val scopeRule: String, + val isActive: Boolean, + val regEx: Regex, + val scopeRegEx: Set<Regex> + ) : Serializable { + constructor(type: Int, ignoreRule: String, isRegEx: Boolean, strictness: Int, scope: Int, + scopeRule: String, isActive: Boolean) : this( + IgnoreType.of(type), ignoreRule, isRegEx, StrictnessType.of(strictness), ScopeType.of(scope), + scopeRule, isActive + ) + + constructor(type: IgnoreType, ignoreRule: String, isRegEx: Boolean, strictness: StrictnessType, + scope: ScopeType, scopeRule: String, isActive: Boolean) : this( + type, ignoreRule, isRegEx, strictness, scope, scopeRule, isActive, + Regex(ignoreRule.let { + if (isRegEx) it else GlobTransformer.convertGlobToRegex(it) + }, RegexOption.IGNORE_CASE), + scopeRule.split(';') + .map(String::trim) + .map(GlobTransformer::convertGlobToRegex) + .map { Regex(it, RegexOption.IGNORE_CASE) } + .toSet() + ) + + fun toggleActive(isActive: Boolean = !this.isActive) = IgnoreListItem( + type = type, + ignoreRule = ignoreRule, + isRegEx = isRegEx, + strictness = strictness, + scope = scope, + scopeRule = scopeRule, + isActive = isActive, + scopeRegEx = scopeRegEx, + regEx = regEx + ) + + fun copy( + type: IgnoreType = this.type, + ignoreRule: String = this.ignoreRule, + isRegEx: Boolean = this.isRegEx, + strictness: StrictnessType = this.strictness, + scope: ScopeType = this.scope, + scopeRule: String = this.scopeRule, + isActive: Boolean = this.isActive + ) = IgnoreListItem( + type = type, + ignoreRule = ignoreRule, + isRegEx = isRegEx, + strictness = strictness, + scope = scope, + scopeRule = scopeRule, + isActive = isActive, + regEx = if (ignoreRule == this.ignoreRule) this.regEx else Regex(ignoreRule.let { + if (isRegEx) it else GlobTransformer.convertGlobToRegex(it) + }, RegexOption.IGNORE_CASE), + scopeRegEx = if (scopeRule == this.scopeRule) this.scopeRegEx else scopeRule.split(';') + .map(String::trim) + .map(GlobTransformer::convertGlobToRegex) + .map { Regex(it, RegexOption.IGNORE_CASE) } + .toSet() + ) + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as IgnoreListItem + + if (type != other.type) return false + if (ignoreRule != other.ignoreRule) return false + if (isRegEx != other.isRegEx) return false + if (strictness != other.strictness) return false + if (scope != other.scope) return false + if (scopeRule != other.scopeRule) return false + if (isActive != other.isActive) return false + + return true + } + + override fun hashCode(): Int { + var result = type.hashCode() + result = 31 * result + ignoreRule.hashCode() + result = 31 * result + isRegEx.hashCode() + result = 31 * result + strictness.hashCode() + result = 31 * result + scope.hashCode() + result = 31 * result + scopeRule.hashCode() + result = 31 * result + isActive.hashCode() + return result + } + + override fun toString(): String { + return "IgnoreListItem(type=$type, ignoreRule='$ignoreRule', isRegEx=$isRegEx, strictness=$strictness, scope=$scope, scopeRule='$scopeRule', isActive=$isActive)" + } + } + + fun match(msgContents: String, msgSender: String, msgType: Message_Types, network: String, + bufferName: String): StrictnessType { + if ((Message_Type.of(Message_Type.Plain, Message_Type.Notice, Message_Type.Action) and msgType) + .isEmpty()) return StrictnessType.UnmatchedStrictness + + return _ignoreList.filter { + it.isActive && it.type != IgnoreType.CtcpIgnore + }.filter { + it.scope == ScopeType.GlobalScope || + it.scope == ScopeType.NetworkScope && it.scopeRegEx.any { it matches network } || + it.scope == ScopeType.ChannelScope && it.scopeRegEx.any { it matches bufferName } + }.filter { + val content = if (it.type == IgnoreType.MessageIgnore) msgContents else msgSender + !it.isRegEx && it.regEx.matches(content) || + it.isRegEx && it.regEx.containsMatchIn(content) + }.map { + it.strictness + }.sortedByDescending { + it.value + }.firstOrNull() ?: StrictnessType.UnmatchedStrictness } + private val live_updates = BehaviorSubject.createDefault(Unit) + private var _ignoreList = emptyList<IgnoreListItem>() + set(value) { + field = value + live_updates.onNext(Unit) + } } diff --git a/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/Network.kt b/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/Network.kt index 0cbe0a820..b44f15101 100644 --- a/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/Network.kt +++ b/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/Network.kt @@ -676,14 +676,14 @@ class Network constructor( override fun initIrcUsersAndChannels(): QVariantMap { return mapOf( "Users" to QVariant.of( - _ircUsers.values.map { it.toVariantMap() }.transpose().map { - QVariant.of(it, Type.QVariantList) + _ircUsers.values.map { it.toVariantMap() }.transpose().mapValues { (_, value) -> + QVariant.of(value, Type.QVariantList) }, Type.QVariantMap ), "Channels" to QVariant.of( - _ircChannels.values.map { it.toVariantMap() }.transpose().map { - QVariant.of(it, Type.QVariantList) + _ircChannels.values.map { it.toVariantMap() }.transpose().mapValues { (_, value) -> + QVariant.of(value, Type.QVariantList) }, Type.QVariantMap ) diff --git a/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/interfaces/INetwork.kt b/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/interfaces/INetwork.kt index 5f9832f01..8e0a302c0 100644 --- a/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/interfaces/INetwork.kt +++ b/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/interfaces/INetwork.kt @@ -263,10 +263,7 @@ interface INetwork : ISyncableObject { FtpCachingProxy(5); companion object { - private val byId = enumValues<ProxyType>().associateBy( - ProxyType::value - ) - + private val byId = enumValues<ProxyType>().associateBy(ProxyType::value) fun of(value: Int) = byId[value] ?: DefaultProxy } } diff --git a/lib/src/main/java/de/kuschku/libquassel/util/GlobTransformer.kt b/lib/src/main/java/de/kuschku/libquassel/util/GlobTransformer.kt new file mode 100644 index 000000000..c8aece750 --- /dev/null +++ b/lib/src/main/java/de/kuschku/libquassel/util/GlobTransformer.kt @@ -0,0 +1,77 @@ +package de.kuschku.libquassel.util + +object GlobTransformer { + /** + * Converts a standard POSIX Shell globbing pattern into a regular expression + * pattern. The result can be used with the standard {@link java.util.regex} API to + * recognize strings which match the glob pattern. + * <p/> + * See also, the POSIX Shell language: + * http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_13_01 + * + * @param pattern A glob pattern. + * @return A regex pattern to recognize the given glob pattern. + */ + fun convertGlobToRegex(pattern: String): String { + val sb = StringBuilder(pattern.length) + var inGroup = 0 + var inClass = 0 + var firstIndexInClass = -1 + val arr = pattern.toCharArray() + var i = 0 + while (i < arr.size) { + val ch = arr[i] + when (ch) { + '\\' -> + if (++i >= arr.size) { + sb.append('\\') + } else { + val next = arr[i] + when (next) { + ',' -> { + } + 'Q', 'E' -> { + // extra escape needed + sb.append('\\') + sb.append('\\') + } + else -> sb.append('\\') + }// escape not needed + sb.append(next) + } + '*' -> sb.append(if (inClass == 0) ".*" else '*') + '?' -> sb.append(if (inClass == 0) '.' else '?') + '[' -> { + inClass++ + firstIndexInClass = i + 1 + sb.append('[') + } + ']' -> { + inClass-- + sb.append(']') + } + '.', '(', ')', + '+', '|', '^', + '$', '@', '%' -> { + if (inClass == 0 || firstIndexInClass == i && ch == '^') + sb.append('\\') + sb.append(ch) + } + '!' -> + sb.append(if (firstIndexInClass == i) '^' else '!') + '{' -> { + inGroup++ + sb.append('(') + } + '}' -> { + inGroup-- + sb.append(')') + } + ',' -> sb.append(if (inGroup > 0) '|' else ',') + else -> sb.append(ch) + } + i++ + } + return sb.toString() + } +} diff --git a/viewmodel/src/main/java/de/kuschku/quasseldroid/viewmodel/QuasselViewModel.kt b/viewmodel/src/main/java/de/kuschku/quasseldroid/viewmodel/QuasselViewModel.kt index 576041eb9..86e9b29ba 100644 --- a/viewmodel/src/main/java/de/kuschku/quasseldroid/viewmodel/QuasselViewModel.kt +++ b/viewmodel/src/main/java/de/kuschku/quasseldroid/viewmodel/QuasselViewModel.kt @@ -69,9 +69,9 @@ class QuasselViewModel : ViewModel() { val errors = sessionManager.mapSwitchMap(SessionManager::error) - val networkConfig = session.map { - it.map(ISession::networkConfig) - } + val networkConfig = session.mapMapNullable(ISession::networkConfig) + + val ignoreListManager = session.mapMapNullable(ISession::ignoreListManager) val networks = session.switchMap { it.map(ISession::liveNetworks).orElse(Observable.just(emptyMap())) @@ -86,10 +86,8 @@ class QuasselViewModel : ViewModel() { it.liveBufferInfos().map(Map<BufferId, BufferInfo>::values) }.mapOrElse(emptyList()) - val network = combineLatest(bufferSyncer, - networks, - buffer).map { (bufferSyncer, networks, buffer) -> - Optional.ofNullable(bufferSyncer.orNull()?.bufferInfo(buffer)?.let { networks[it.networkId] }) + val network = combineLatest(bufferSyncer, networks, buffer).map { (syncer, networks, buffer) -> + Optional.ofNullable(syncer.orNull()?.bufferInfo(buffer)?.let { networks[it.networkId] }) } /** -- GitLab