From da690dda408410d7c29b2f1a6a9b736840c135d2 Mon Sep 17 00:00:00 2001 From: Taras Smakula <tarassmakula@gmail.com> Date: Mon, 4 Mar 2024 17:46:52 +0200 Subject: [PATCH] Create new ui --- app/src/main/res/values/strings.xml | 1 - .../room/create/CreateRoomDialogFragment.kt | 123 +++++++------- .../org/futo/circles/core/model/CircleType.kt | 8 + .../layout/dialog_fragment_create_room.xml | 151 +++++++++--------- .../src/main/res/layout/view_spinner_item.xml | 13 ++ core/src/main/res/values/dimen.xml | 1 - core/src/main/res/values/strings.xml | 9 +- .../circles/gallery/feature/PhotosFragment.kt | 1 + gallery/src/main/res/values/strings.xml | 1 - 9 files changed, 163 insertions(+), 145 deletions(-) create mode 100644 core/src/main/java/org/futo/circles/core/model/CircleType.kt create mode 100644 core/src/main/res/layout/view_spinner_item.xml diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 51facd4c3..ab5bee724 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -17,7 +17,6 @@ <string name="requests">Requests</string> <string name="no_results">No results</string> <string name="invites">Invites</string> - <string name="create_new_group">Create new group</string> <string name="create_new_circle">Create new circle</string> <string name="private_circles">Private Circles</string> <string name="log_out">Log out</string> diff --git a/core/src/main/java/org/futo/circles/core/feature/room/create/CreateRoomDialogFragment.kt b/core/src/main/java/org/futo/circles/core/feature/room/create/CreateRoomDialogFragment.kt index 67e625f1d..409d1ded3 100644 --- a/core/src/main/java/org/futo/circles/core/feature/room/create/CreateRoomDialogFragment.kt +++ b/core/src/main/java/org/futo/circles/core/feature/room/create/CreateRoomDialogFragment.kt @@ -1,8 +1,8 @@ package org.futo.circles.core.feature.room.create import android.os.Bundle -import android.util.Log import android.view.View +import android.widget.ArrayAdapter import androidx.core.os.BundleCompat.getParcelable import androidx.core.widget.doAfterTextChanged import androidx.fragment.app.Fragment @@ -16,9 +16,12 @@ import org.futo.circles.core.extensions.getText import org.futo.circles.core.extensions.observeData import org.futo.circles.core.extensions.observeResponse import org.futo.circles.core.extensions.onBackPressed +import org.futo.circles.core.extensions.setIsVisible import org.futo.circles.core.feature.picker.helper.MediaPickerHelper import org.futo.circles.core.feature.select_users.SelectUsersFragment import org.futo.circles.core.model.CircleRoomTypeArg +import org.futo.circles.core.model.CircleType + @AndroidEntryPoint class CreateRoomDialogFragment : @@ -37,31 +40,45 @@ class CreateRoomDialogFragment : } private var selectedUsersFragment: SelectUsersFragment? = null + private val circleTypeList = CircleType.entries.toTypedArray() + private val circleTypeAdapter by lazy { + ArrayAdapter( + requireContext(), + R.layout.view_spinner_item, + circleTypeList.map { getString(it.nameResId) }).apply { + setDropDownViewResource(R.layout.view_spinner_item) + } + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) if (savedInstanceState == null) addSelectUsersFragment() + setupViews() setupObservers() } - private fun changeCoverImage() { - mediaPickerHelper.showMediaPickerDialog(onImageSelected = { _, uri -> - viewModel.setImageUri(uri) - }) - } - - private fun createRoom( - type: CircleRoomTypeArg, - name: String, - topic: String? = null, - isPublicCircle: Boolean = false - ) { - viewModel.createRoom( - name, - topic ?: "", - selectedUsersFragment?.getSelectedUsersIds(), - type, - isPublicCircle - ) + private fun setupViews() { + with(binding) { + val roomTypeName = getRoomTypeName() + toolbar.title = getString(R.string.create_new_room_format, roomTypeName) + val nameHeader = "$roomTypeName ${getString(R.string.name)}" + tvNameHeader.text = nameHeader + tvTopicHeader.setIsVisible(roomType == CircleRoomTypeArg.Group) + tilTopic.setIsVisible(roomType == CircleRoomTypeArg.Group) + tvTypeHeader.setIsVisible(roomType == CircleRoomTypeArg.Circle) + circleTypeGroup.setIsVisible(roomType == CircleRoomTypeArg.Circle) + lCircleTypeExplanation.setIsVisible(roomType == CircleRoomTypeArg.Circle) + ivCover.setOnClickListener { changeCoverImage() } + tilName.editText?.doAfterTextChanged { + it?.let { btnCreate.isEnabled = it.isNotEmpty() } + } + btnCreate.setOnClickListener { + createRoom() + startLoading(btnCreate) + } + spUserRole.adapter = circleTypeAdapter + } } private fun setupObservers() { @@ -73,55 +90,35 @@ class CreateRoomDialogFragment : ) } - private fun addSelectUsersFragment() { - selectedUsersFragment = SelectUsersFragment.create(null).also { - childFragmentManager.beginTransaction() - .replace(R.id.lContainer, it) - .commitAllowingStateLoss() + private fun getRoomTypeName() = getString( + when (roomType) { + CircleRoomTypeArg.Circle -> R.string.circle + CircleRoomTypeArg.Group -> R.string.group_name + CircleRoomTypeArg.Photo -> R.string.gallery } - } + ) - private fun setupViewsCircle() { - with(binding) { - ivCover.setOnClickListener { changeCoverImage() } - tilName.editText?.doAfterTextChanged { - it?.let { btnCreate.isEnabled = it.isNotEmpty() } - } - btnCreate.setOnClickListener { - createRoom( - CircleRoomTypeArg.Circle, - tilName.getText(), - null, - binding.btnPublic.isChecked - ) - startLoading(btnCreate) - } - } + private fun changeCoverImage() { + mediaPickerHelper.showMediaPickerDialog(onImageSelected = { _, uri -> + viewModel.setImageUri(uri) + }) } - private fun setupViewsGroup() { - with(binding) { - ivCover.setOnClickListener { changeCoverImage() } - tilName.editText?.doAfterTextChanged { - it?.let { btnCreate.isEnabled = it.isNotEmpty() } - } - btnCreate.setOnClickListener { - createRoom(CircleRoomTypeArg.Group, tilName.getText(), tilTopic.getText()) - startLoading(btnCreate) - } - } + private fun createRoom() { + viewModel.createRoom( + binding.tilName.getText(), + binding.tilTopic.getText(), + selectedUsersFragment?.getSelectedUsersIds(), + roomType, + binding.btnPublic.isChecked + ) } - private fun setupViewsGallery() { - with(binding) { - ivCover.setOnClickListener { changeCoverImage() } - tilName.editText?.doAfterTextChanged { - it?.let { btnCreate.isEnabled = it.isNotEmpty() } - } - btnCreate.setOnClickListener { - createRoom(CircleRoomTypeArg.Photo, tilName.getText()) - startLoading(btnCreate) - } + private fun addSelectUsersFragment() { + selectedUsersFragment = SelectUsersFragment.create(null).also { + childFragmentManager.beginTransaction() + .replace(R.id.lContainer, it) + .commitAllowingStateLoss() } } } \ No newline at end of file diff --git a/core/src/main/java/org/futo/circles/core/model/CircleType.kt b/core/src/main/java/org/futo/circles/core/model/CircleType.kt new file mode 100644 index 000000000..1134b7cfd --- /dev/null +++ b/core/src/main/java/org/futo/circles/core/model/CircleType.kt @@ -0,0 +1,8 @@ +package org.futo.circles.core.model + +import org.futo.circles.core.R + +enum class CircleType(val nameResId: Int, val messageResId: Int) { + Public(R.string.public_type, R.string.public_circle_explanation), + Private(R.string.private_type, R.string.private_circle_explanation) +} \ No newline at end of file diff --git a/core/src/main/res/layout/dialog_fragment_create_room.xml b/core/src/main/res/layout/dialog_fragment_create_room.xml index 9a98127d7..f2b03c373 100644 --- a/core/src/main/res/layout/dialog_fragment_create_room.xml +++ b/core/src/main/res/layout/dialog_fragment_create_room.xml @@ -1,19 +1,20 @@ <?xml version="1.0" encoding="utf-8"?> -<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" +<LinearLayout 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:layout_height="match_parent" + android:orientation="vertical"> <com.google.android.material.appbar.MaterialToolbar android:id="@+id/toolbar" - android:layout_width="0dp" + android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:navigationIcon="?attr/homeAsUpIndicator" - app:title="@string/create_new_circle" app:titleCentered="true" app:titleMarginEnd="72dp"> @@ -34,7 +35,7 @@ <View android:id="@+id/toolbarDivider" - android:layout_width="0dp" + android:layout_width="match_parent" android:layout_height="@dimen/divider_height" android:background="@color/divider_color" app:layout_constraintEnd_toEndOf="parent" @@ -42,56 +43,36 @@ app:layout_constraintTop_toBottomOf="@id/toolbar" /> - <androidx.constraintlayout.widget.Guideline - android:id="@+id/guidelineStart" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:orientation="vertical" - app:layout_constraintGuide_begin="8dp" /> - - <androidx.constraintlayout.widget.Guideline - android:id="@+id/guidelineEnd" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:orientation="vertical" - app:layout_constraintGuide_end="8dp" /> - <com.google.android.material.imageview.ShapeableImageView android:id="@+id/ivCover" android:layout_width="@dimen/group_icon_size" android:layout_height="@dimen/group_icon_size" + android:layout_gravity="center_horizontal" android:layout_marginTop="16dp" android:clickable="true" android:focusable="true" android:scaleType="centerCrop" android:src="@drawable/add_image_placeholder" - app:layout_constraintEnd_toEndOf="@id/guidelineEnd" - app:layout_constraintStart_toStartOf="@id/guidelineStart" - app:layout_constraintTop_toBottomOf="@id/toolbarDivider" app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.App.GroupIconRadius" /> <TextView android:id="@+id/tvNameHeader" style="@style/headline" - android:layout_width="0dp" + android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginHorizontal="8dp" android:layout_marginTop="16dp" - android:text="@string/circle_name" - app:layout_constraintEnd_toEndOf="@id/guidelineEnd" - app:layout_constraintStart_toStartOf="@id/guidelineStart" - app:layout_constraintTop_toBottomOf="@id/ivCover" /> + tools:text="Room name" /> <com.google.android.material.textfield.TextInputLayout android:id="@+id/tilName" style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" - android:layout_width="0dp" + android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginHorizontal="8dp" android:layout_marginTop="8dp" - app:hintEnabled="false" - app:layout_constraintEnd_toEndOf="@id/guidelineEnd" - app:layout_constraintStart_toStartOf="@id/guidelineStart" - app:layout_constraintTop_toBottomOf="@id/tvNameHeader"> + app:hintEnabled="false"> <com.google.android.material.textfield.TextInputEditText android:id="@+id/etName" @@ -107,24 +88,20 @@ <TextView android:id="@+id/tvTopicHeader" style="@style/headline" - android:layout_width="0dp" + android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginHorizontal="8dp" android:layout_marginTop="16dp" - android:text="@string/group_topic_optional" - app:layout_constraintEnd_toEndOf="@id/guidelineEnd" - app:layout_constraintStart_toStartOf="@id/guidelineStart" - app:layout_constraintTop_toBottomOf="@id/tilName" /> + android:text="@string/group_topic_optional" /> <com.google.android.material.textfield.TextInputLayout android:id="@+id/tilTopic" style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" - android:layout_width="0dp" + android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginHorizontal="8dp" android:layout_marginTop="8dp" - app:hintEnabled="false" - app:layout_constraintEnd_toEndOf="@id/guidelineEnd" - app:layout_constraintStart_toStartOf="@id/guidelineStart" - app:layout_constraintTop_toBottomOf="@id/tvTopicHeader"> + app:hintEnabled="false"> <com.google.android.material.textfield.TextInputEditText android:id="@+id/etTopic" @@ -141,76 +118,98 @@ <TextView android:id="@+id/tvTypeHeader" style="@style/headline" - android:layout_width="0dp" + android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginHorizontal="8dp" android:layout_marginTop="16dp" - android:text="@string/circle_type" - app:layout_constraintEnd_toEndOf="@id/guidelineEnd" - app:layout_constraintStart_toStartOf="@id/guidelineStart" - app:layout_constraintTop_toBottomOf="@+id/tilTopic" /> + android:text="@string/circle_type" /> <RadioGroup android:id="@+id/circleTypeGroup" - android:layout_width="0dp" + android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginHorizontal="8dp" android:layout_marginTop="8dp" - android:orientation="vertical" + android:orientation="horizontal" app:layout_constraintEnd_toEndOf="@id/guidelineEnd" app:layout_constraintStart_toStartOf="@id/guidelineStart" app:layout_constraintTop_toBottomOf="@id/tvTypeHeader"> <com.google.android.material.radiobutton.MaterialRadioButton android:id="@+id/btnPublic" - android:layout_width="wrap_content" - android:layout_height="36dp" + android:layout_width="match_parent" + android:layout_weight="0.5" + android:paddingVertical="12dp" android:text="@string/public_type" android:textAppearance="@style/body" /> - <TextView - android:id="@+id/tvOpenHint" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginStart="32dp" - android:text="@string/public_circle_explanation" /> <com.google.android.material.radiobutton.MaterialRadioButton android:id="@+id/btnPrivate" - android:layout_width="wrap_content" - android:layout_height="36dp" - android:layout_marginTop="8dp" + android:layout_width="match_parent" + android:layout_weight="0.5" android:checked="true" + android:paddingVertical="12dp" android:text="@string/private_type" android:textAppearance="@style/body" /> + </RadioGroup> + + <LinearLayout + android:id="@+id/lCircleTypeExplanation" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginHorizontal="8dp" + android:orientation="horizontal"> + + <TextView + android:id="@+id/tvPublicHint" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_weight="0.5" + android:text="@string/public_circle_explanation" /> + <TextView - android:id="@+id/tvClosedHint" - android:layout_width="wrap_content" + android:id="@+id/tvPrivateHint" + android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginStart="32dp" + android:layout_weight="0.5" android:text="@string/private_circle_explanation" /> - </RadioGroup> + </LinearLayout> + + + <TextView + android:id="@+id/tvRoleHeader" + style="@style/headline" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginHorizontal="8dp" + android:layout_marginTop="16dp" + android:text="@string/default_user_role" /> + + + <Spinner + android:id="@+id/spUserRole" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginHorizontal="8dp" + android:layout_marginTop="8dp" /> <TextView android:id="@+id/tvInviteUsers" style="@style/headline" - android:layout_width="0dp" + android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginHorizontal="8dp" android:layout_marginTop="16dp" - android:text="@string/invite_members" - app:layout_constraintEnd_toEndOf="@id/guidelineEnd" - app:layout_constraintStart_toStartOf="@id/guidelineStart" - app:layout_constraintTop_toBottomOf="@id/circleTypeGroup" /> + android:text="@string/invite_members" /> <FrameLayout android:id="@+id/lContainer" - android:layout_width="0dp" - android:layout_height="0dp" - app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@id/tvInviteUsers" /> + android:layout_width="match_parent" + android:layout_height="match_parent" /> -</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file +</LinearLayout> \ No newline at end of file diff --git a/core/src/main/res/layout/view_spinner_item.xml b/core/src/main/res/layout/view_spinner_item.xml new file mode 100644 index 000000000..404be375d --- /dev/null +++ b/core/src/main/res/layout/view_spinner_item.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8"?> +<TextView xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/text" + style="@style/body" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:ellipsize="marquee" + android:gravity="center" + android:padding="16dp" + android:singleLine="true" + android:textAlignment="center" + tools:text="Some text" /> diff --git a/core/src/main/res/values/dimen.xml b/core/src/main/res/values/dimen.xml index 04e1c2008..cd503730b 100644 --- a/core/src/main/res/values/dimen.xml +++ b/core/src/main/res/values/dimen.xml @@ -1,7 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <resources> <dimen name="divider_height">1dp</dimen> - <dimen name="reply_post_item_margin">24dp</dimen> <dimen name="post_text_side_margin">24dp</dimen> <dimen name="circle_icon_size">100dp</dimen> <dimen name="group_icon_size">120dp</dimen> diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index c79f6eaee..6318eb90f 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -16,6 +16,8 @@ <string name="photo">Photo</string> <string name="video">Video</string> <string name="gallery">Gallery</string> + <string name="circle">Circle</string> + <string name="group">Group</string> <string name="cancel">Cancel</string> <string name="device">Device</string> <string name="admin">Admin</string> @@ -126,13 +128,14 @@ <string name="decline">Decline</string> <string name="invited_by_format">Invited by %s</string> <string name="circle_encryption_warning">NOTE: Circle name and cover image are not encrypted</string> - <string name="circle_name">Circle name</string> + <string name="name">name</string> + <string name="create_new_room_format">Create new %s</string> <string name="circle_type">Circle type</string> <string name="public_type">Public</string> <string name="group_topic_optional">Group topic (optional)</string> <string name="public_circle_explanation">Other users can ask to join</string> <string name="private_type">Private</string> - <string name="private_circle_explanation">Accessible only by your invitation</string> + <string name="private_circle_explanation">Accessible only by invitation</string> <string name="gallery_name">Gallery name</string> <string name="gallery_encryption_warning">NOTE: Gallery name and cover image are not encrypted</string> <string name="group_name">Group name</string> @@ -164,7 +167,6 @@ <string name="unignore_and_restart">Unignore and restart</string> <string name="unignore_message">Unignoring this user will show all messages from them again.\n\nNote that to take affect this action requires to restart the app and sync the session.</string> <string name="user_ignored">User ignored</string> - <string name="user_unignored">User un ignored</string> <string name="not_following_any_circles_format">Not following any Circles for %s</string> <string name="requests_to_follow_you">requests to follow you</string> <string name="invites_you_to_connect">invites you to connect</string> @@ -172,4 +174,5 @@ <string name="requests">Requests</string> <string name="invite_to_connect">Invite to connect</string> <string name="follow">Follow</string> + <string name="default_user_role">Default user role</string> </resources> \ No newline at end of file diff --git a/gallery/src/main/java/org/futo/circles/gallery/feature/PhotosFragment.kt b/gallery/src/main/java/org/futo/circles/gallery/feature/PhotosFragment.kt index 7d3fbb35f..9b63044ca 100644 --- a/gallery/src/main/java/org/futo/circles/gallery/feature/PhotosFragment.kt +++ b/gallery/src/main/java/org/futo/circles/gallery/feature/PhotosFragment.kt @@ -73,6 +73,7 @@ class PhotosFragment : Fragment(org.futo.circles.core.R.layout.fragment_rooms), binding.rvRooms.apply { setEmptyView(EmptyTabPlaceholderView(requireContext()).apply { setText(getString(R.string.photos_empty_message)) + setArrowVisible(true) }) adapter = listAdapter bindToFab(binding.fbAddRoom) diff --git a/gallery/src/main/res/values/strings.xml b/gallery/src/main/res/values/strings.xml index 6b0021488..7425306dc 100644 --- a/gallery/src/main/res/values/strings.xml +++ b/gallery/src/main/res/values/strings.xml @@ -14,7 +14,6 @@ <string name="compress_before_sending">Compress before sending</string> <string name="backup_device_folders">Backup device folders</string> <string name="backup_folders_hint">Choose folders to backup and view in your Gallery:</string> - <string name="create_new_gallery">Create new gallery</string> <string name="photos_empty_message">Create your first Gallery</string> </resources> \ No newline at end of file -- GitLab