Skip to content
Snippets Groups Projects
Verified Commit 0c60098c authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Further work on channel creation UI

parent d3fe7f35
No related branches found
No related tags found
No related merge requests found
...@@ -23,17 +23,68 @@ import android.os.Bundle ...@@ -23,17 +23,68 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.EditText
import androidx.appcompat.widget.AppCompatSpinner
import androidx.appcompat.widget.SwitchCompat
import androidx.lifecycle.Observer
import butterknife.BindView
import butterknife.ButterKnife import butterknife.ButterKnife
import de.kuschku.libquassel.quassel.syncables.Network
import de.kuschku.libquassel.quassel.syncables.interfaces.INetwork
import de.kuschku.quasseldroid.R import de.kuschku.quasseldroid.R
import de.kuschku.quasseldroid.util.service.ServiceBoundFragment import de.kuschku.quasseldroid.util.helper.combineLatest
import de.kuschku.quasseldroid.util.helper.setDependent
import de.kuschku.quasseldroid.util.helper.toLiveData
import de.kuschku.quasseldroid.util.ui.settings.fragment.Savable
import de.kuschku.quasseldroid.util.ui.settings.fragment.ServiceBoundSettingsFragment
class ChannelCreateFragment : ServiceBoundFragment() { class ChannelCreateFragment : ServiceBoundSettingsFragment(), Savable {
@BindView(R.id.network)
lateinit var network: AppCompatSpinner
@BindView(R.id.name)
lateinit var name: EditText
@BindView(R.id.hidden)
lateinit var hidden: SwitchCompat
@BindView(R.id.invite_only)
lateinit var inviteOnly: SwitchCompat
@BindView(R.id.password_protected)
lateinit var passwordProtected: SwitchCompat
@BindView(R.id.password_group)
lateinit var passwordGroup: ViewGroup
@BindView(R.id.password)
lateinit var password: EditText
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? { savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.add_create, container, false) val view = inflater.inflate(R.layout.add_create, container, false)
ButterKnife.bind(this, view) ButterKnife.bind(this, view)
val networkAdapter = NetworkAdapter()
network.adapter = networkAdapter
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) {
networkAdapter.submitList(it)
}
})
passwordProtected.setDependent(passwordGroup)
return view return view
} }
override fun onSave(): Boolean {
// TODO: Implement
return false
}
} }
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2019 Janne Koschinski
* Copyright (c) 2019 The Quassel Project
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.quasseldroid.ui.chat.add.create
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.appcompat.widget.ThemedSpinnerAdapter
import androidx.recyclerview.widget.RecyclerView
import butterknife.BindView
import butterknife.ButterKnife
import de.kuschku.libquassel.protocol.NetworkId
import de.kuschku.libquassel.quassel.syncables.interfaces.INetwork
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 {
var data = listOf<INetwork.NetworkInfo>()
fun submitList(list: List<INetwork.NetworkInfo>) {
data = list
notifyDataSetChanged()
}
override fun isEmpty() = data.isEmpty()
override fun onBindViewHolder(holder: NetworkViewHolder, position: Int) =
holder.bind(getItem(position))
override fun onCreateViewHolder(parent: ViewGroup, dropDown: Boolean)
: NetworkViewHolder {
val inflater = LayoutInflater.from(
if (dropDown)
ContextThemeWrapper(parent.context, dropDownViewTheme)
else
parent.context
)
val view = inflater.inflate(R.layout.widget_spinner_item_material, parent, false)
return NetworkViewHolder(view)
}
fun indexOf(id: NetworkId): Int? {
for ((key, item) in data.withIndex()) {
if (item.networkId == id) {
return key
}
}
return null
}
override fun getItem(position: Int): INetwork.NetworkInfo = data[position]
override fun getItemId(position: Int) = getItem(position).networkId.id.toLong()
override fun hasStableIds() = true
override fun getCount() = data.size
class NetworkViewHolder(itemView: View) :
RecyclerView.ViewHolder(itemView) {
@BindView(android.R.id.text1)
lateinit var text: TextView
init {
ButterKnife.bind(this, itemView)
}
fun bind(network: INetwork.NetworkInfo) {
text.text = network.networkName
}
}
}
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.core.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" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:orientation="vertical"
android:padding="16dp"> <LinearLayout style="@style/Widget.CoreSettings.Wrapper">
<de.kuschku.ui.spinner.MaterialSpinnerLayout <de.kuschku.ui.spinner.MaterialSpinnerLayout
style="@style/Widget.CustomSpinnerLayout" style="@style/Widget.CustomSpinnerLayout"
...@@ -24,11 +26,77 @@ ...@@ -24,11 +26,77 @@
style="@style/Widget.CustomTextInput" style="@style/Widget.CustomTextInput"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/settings_aliasitem_name"> android:hint="@string/label_channel_name">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
android:id="@+id/name" android:id="@+id/name"
style="@style/Widget.CoreSettings.EditText" style="@style/Widget.CoreSettings.EditText"
tools:text="back" /> tools:text="#trees" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp">
<androidx.appcompat.widget.AppCompatImageView
style="@style/Widget.CoreSettings.PrimaryItemIcon"
app:srcCompat="@drawable/ic_eye_off" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/hidden"
style="@style/Widget.CoreSettings.PrimaryItemSwitch"
android:text="@string/addchat_channel_hidden" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp">
<androidx.appcompat.widget.AppCompatImageView
style="@style/Widget.CoreSettings.PrimaryItemIcon"
app:srcCompat="@drawable/ic_account_card" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/invite_only"
style="@style/Widget.CoreSettings.PrimaryItemSwitch"
android:text="@string/addchat_channel_invite_only" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp">
<androidx.appcompat.widget.AppCompatImageView
style="@style/Widget.CoreSettings.PrimaryItemIcon"
app:srcCompat="@drawable/ic_key_variant" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/password_protected"
style="@style/Widget.CoreSettings.PrimaryItemSwitch"
android:text="@string/addchat_channel_password_protected" />
</LinearLayout>
<LinearLayout
android:id="@+id/password_group"
style="@style/Widget.CoreSettings.DependentGroup"
tools:visibility="visible">
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.CustomTextInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/addchat_channel_password"
app:passwordToggleEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/password"
style="@style/Widget.CoreSettings.EditText"
android:inputType="textPassword"
tools:text="NickServ" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
</LinearLayout> </LinearLayout>
</androidx.core.widget.NestedScrollView>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="addchat_channel_hidden">Hidden</string>
<string name="addchat_channel_invite_only">Invite Only</string>
<string name="addchat_channel_password_protected">Password Protected</string>
<string name="addchat_channel_password">Password</string>
</resources>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment