enable multiple hashtags in one hashtag tab (#1790)

* enable multiple hashtags in one hashtag tab

* add comment explaining the code in TabAdapter

* delete unused drawables

* add padding to EditText in dialog
This commit is contained in:
Konrad Pozniak 2020-05-15 22:10:29 +02:00 committed by GitHub
commit df8dc3a198
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 105 additions and 121 deletions

View file

@ -18,13 +18,16 @@ package com.keylesspalace.tusky
import android.os.Bundle
import android.util.Log
import android.view.MenuItem
import android.widget.FrameLayout
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.AppCompatEditText
import androidx.core.view.updatePadding
import androidx.lifecycle.Lifecycle
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import at.connyduck.sparkbutton.helpers.Utils
import com.keylesspalace.tusky.adapter.ItemInteractionListener
import com.keylesspalace.tusky.adapter.ListSelectionAdapter
import com.keylesspalace.tusky.adapter.TabAdapter
@ -150,7 +153,7 @@ class TabPreferenceActivity : BaseActivity(), Injectable, ItemInteractionListene
actionButton.isExpanded = false
if (tab.id == HASHTAG) {
showEditHashtagDialog()
showAddHashtagDialog()
return
}
@ -173,19 +176,32 @@ class TabPreferenceActivity : BaseActivity(), Injectable, ItemInteractionListene
}
override fun onActionChipClicked(tab: TabData) {
showEditHashtagDialog(tab)
showAddHashtagDialog(tab)
}
private fun showEditHashtagDialog(tab: TabData? = null) {
override fun onChipClicked(tab: TabData, chipPosition: Int) {
val newArguments = tab.arguments.filterIndexed { i, _ -> i != chipPosition }
val newTab = tab.copy(arguments = newArguments)
val position = currentTabs.indexOf(tab)
currentTabs[position] = newTab
currentTabsAdapter.notifyItemChanged(position)
}
private fun showAddHashtagDialog(tab: TabData? = null) {
val frameLayout = FrameLayout(this)
val padding = Utils.dpToPx(this, 8)
frameLayout.updatePadding(left = padding, right = padding)
val editText = AppCompatEditText(this)
editText.setHint(R.string.edit_hashtag_hint)
editText.setText("")
editText.append(tab?.arguments?.first().orEmpty())
frameLayout.addView(editText)
val dialog = AlertDialog.Builder(this)
.setTitle(R.string.edit_hashtag_title)
.setView(editText)
.setTitle(R.string.add_hashtag_title)
.setView(frameLayout)
.setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(R.string.action_save) { _, _ ->
val input = editText.text.toString().trim()
@ -194,7 +210,7 @@ class TabPreferenceActivity : BaseActivity(), Injectable, ItemInteractionListene
currentTabs.add(newTab)
currentTabsAdapter.notifyItemInserted(currentTabs.size - 1)
} else {
val newTab = tab.copy(arguments = listOf(input))
val newTab = tab.copy(arguments = tab.arguments + input)
val position = currentTabs.indexOf(tab)
currentTabs[position] = newTab