Commit f2a400e8 authored by Janne Koschinski's avatar Janne Koschinski

Fixes #181 and #183

- Setup Network window should sort networks alphabetically
- Setup Network window should rename "All Networks" -> "New Network…"
parent 165ac83f
......@@ -110,7 +110,7 @@ abstract class ChatListBaseFragment(private val initDefault: Boolean) :
))
minimumActivity.adapter = minimumActivityAdapter
val networkAdapter = NetworkAdapter()
val networkAdapter = NetworkAdapter(R.string.settings_chatlist_network_all)
networkId.adapter = networkAdapter
viewModel.networks.switchMap {
......
......@@ -23,6 +23,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.annotation.StringRes
import androidx.appcompat.widget.ThemedSpinnerAdapter
import androidx.recyclerview.widget.RecyclerView
import butterknife.BindView
......@@ -33,8 +34,8 @@ import de.kuschku.quasseldroid.R
import de.kuschku.quasseldroid.util.ui.ContextThemeWrapper
import de.kuschku.quasseldroid.util.ui.RecyclerSpinnerAdapter
class NetworkAdapter : RecyclerSpinnerAdapter<NetworkAdapter.NetworkViewHolder>(),
ThemedSpinnerAdapter {
class NetworkAdapter(@StringRes private val fallbackName: Int) : RecyclerSpinnerAdapter<NetworkAdapter.NetworkViewHolder>(),
ThemedSpinnerAdapter {
var data = listOf<INetwork.NetworkInfo?>(null)
fun submitList(list: List<INetwork.NetworkInfo?>) {
......@@ -56,9 +57,7 @@ class NetworkAdapter : RecyclerSpinnerAdapter<NetworkAdapter.NetworkViewHolder>(
parent.context
)
val view = inflater.inflate(R.layout.widget_spinner_item_inline, parent, false)
return NetworkViewHolder(
view
)
return NetworkViewHolder(fallbackName, view)
}
fun indexOf(id: NetworkId): Int? {
......@@ -74,7 +73,7 @@ class NetworkAdapter : RecyclerSpinnerAdapter<NetworkAdapter.NetworkViewHolder>(
override fun getItemId(position: Int) = getItem(position)?.networkId?.toLong() ?: -1
override fun hasStableIds() = true
override fun getCount() = data.size
class NetworkViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
class NetworkViewHolder(@StringRes private val fallbackName: Int, itemView: View) : RecyclerView.ViewHolder(itemView) {
@BindView(android.R.id.text1)
lateinit var text: TextView
......@@ -83,7 +82,7 @@ class NetworkAdapter : RecyclerSpinnerAdapter<NetworkAdapter.NetworkViewHolder>(
}
fun bind(network: INetwork.NetworkInfo?) {
text.text = network?.networkName ?: itemView.context.getString(R.string.settings_chatlist_network_all)
text.text = network?.networkName ?: itemView.context.getString(fallbackName)
}
}
}
......@@ -79,7 +79,7 @@ class NetworkSetupNetworkSlide : ServiceBoundSlideFragment() {
lateinit var sslEnabled: SwitchCompat
private val identityAdapter = IdentityAdapter()
private val networkAdapter = NetworkAdapter()
private val networkAdapter = NetworkAdapter(R.string.settings_chatlist_network_create)
override fun isValid(): Boolean {
return (this.network.selectedItemPosition != -1 &&
......@@ -188,9 +188,13 @@ class NetworkSetupNetworkSlide : ServiceBoundSlideFragment() {
}
})
viewModel.networks.toLiveData().observe(this, Observer {
viewModel.networks.switchMap {
combineLatest(it.values.map(Network::liveNetworkInfo)).map {
it.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER, INetwork.NetworkInfo::networkName))
}
}.toLiveData().observe(this, Observer {
if (it != null) {
this.networks = it.values.map(Network::networkInfo)
this.networks = it
update()
}
})
......
......@@ -84,6 +84,7 @@
<string name="settings_chatlist_add_new_buffers_automatically">Add new chats automatically</string>
<string name="settings_chatlist_network">Network</string>
<string name="settings_chatlist_network_all">All Networks</string>
<string name="settings_chatlist_network_create">Create Network…</string>
<string name="settings_chatlist_show_status_buffer">Show Status Buffer</string>
<string name="settings_chatlist_types">Chat Types</string>
<string name="settings_chatlist_show_channels">Show Channels</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment