diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3ce26098061d50bcfc0e3438c69f7ce622fd753f..ad60aa2cb85740dbf91411502515aeaa56985494 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -14,7 +14,6 @@ <string name="requests">Requests</string> <string name="no_results">No results</string> <string name="invites">Invites</string> - <string name="create_new_circle">Create new circle</string> <string name="log_out">Log out</string> <string name="followed_by_format">Followed by %d</string> <string name="requests_format">Requests %d</string> diff --git a/core/src/main/java/org/futo/circles/core/feature/invite_to_follow/InviteToFollowMeDialogFragment.kt b/core/src/main/java/org/futo/circles/core/feature/invite_to_follow/InviteToFollowMeDialogFragment.kt new file mode 100644 index 0000000000000000000000000000000000000000..5f3bb4b10c3be14d73a50fc9ae8a246c0df66e83 --- /dev/null +++ b/core/src/main/java/org/futo/circles/core/feature/invite_to_follow/InviteToFollowMeDialogFragment.kt @@ -0,0 +1,76 @@ +package org.futo.circles.core.feature.invite_to_follow + + +import android.os.Bundle +import android.view.View +import androidx.fragment.app.Fragment +import androidx.fragment.app.viewModels +import androidx.navigation.fragment.findNavController +import dagger.hilt.android.AndroidEntryPoint +import org.futo.circles.core.R +import org.futo.circles.core.base.fragment.BaseFullscreenDialogFragment +import org.futo.circles.core.base.fragment.HasLoadingState +import org.futo.circles.core.databinding.DialogFragmentInviteToFollowMeBinding +import org.futo.circles.core.extensions.navigateSafe +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.room.select.SelectRoomsListener +import org.futo.circles.core.model.CircleRoomTypeArg +import org.futo.circles.core.model.SelectableRoomListItem + +@AndroidEntryPoint +class InviteToFollowMeDialogFragment : + BaseFullscreenDialogFragment<DialogFragmentInviteToFollowMeBinding>( + DialogFragmentInviteToFollowMeBinding::inflate + ), HasLoadingState, SelectRoomsListener, RoomsListener { + + override val fragment: Fragment = this + private val viewModel by viewModels<InviteToFollowMeViewModel>() + + private val selectRoomsFragment by lazy { SelectRoomsFragment.create(CircleRoomTypeArg.Circle) } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + if (savedInstanceState == null) addSelectCirclesFragment() + setupViews() + setupObservers() + } + + private fun addSelectCirclesFragment() { + childFragmentManager.beginTransaction() + .replace(R.id.lContainer, selectRoomsFragment) + .commitAllowingStateLoss() + } + + private fun setupViews() { + with(binding) { + btnInvite.setOnClickListener { + viewModel.acceptInvite(selectRoomsFragment.getSelectedRooms()) + startLoading(btnInvite) + } + fbAddRoom.setOnClickListener { navigateToCreateCircle() } + btnCreateCircle.setOnClickListener { navigateToCreateCircle() } + } + } + + private fun setupObservers() { + viewModel.acceptResultLiveData.observeResponse(this, + success = { onBackPressed() } + ) + } + + private fun navigateToCreateCircle() { + findNavController() + .navigateSafe(AcceptCircleInviteDialogFragmentDirections.toCreateCircleDialogFragment()) + } + + override fun onRoomsSelected(rooms: List<SelectableRoomListItem>) { + binding.btnInvite.isEnabled = rooms.isNotEmpty() + } + + override fun onRoomsListChanged(rooms: List<SelectableRoomListItem>) { + binding.createCircleGroup.setIsVisible(rooms.isEmpty()) + binding.selectCircleGroup.setIsVisible(rooms.isNotEmpty()) + } +} \ No newline at end of file diff --git a/core/src/main/java/org/futo/circles/core/feature/invite_to_follow/InviteToFollowMeViewModel.kt b/core/src/main/java/org/futo/circles/core/feature/invite_to_follow/InviteToFollowMeViewModel.kt new file mode 100644 index 0000000000000000000000000000000000000000..25d7f87ed11b57a0fee4290ae9055ab502285143 --- /dev/null +++ b/core/src/main/java/org/futo/circles/core/feature/invite_to_follow/InviteToFollowMeViewModel.kt @@ -0,0 +1,12 @@ +package org.futo.circles.core.feature.invite_to_follow + +import androidx.lifecycle.ViewModel +import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject + +@HiltViewModel +class InviteToFollowMeViewModel @Inject constructor( + +) : ViewModel() { + +} \ No newline at end of file diff --git a/core/src/main/res/layout/dialog_fragment_invite_to_follow_me.xml b/core/src/main/res/layout/dialog_fragment_invite_to_follow_me.xml new file mode 100644 index 0000000000000000000000000000000000000000..362515875cf0fb46cc052adb66e2439cb24736f5 --- /dev/null +++ b/core/src/main/res/layout/dialog_fragment_invite_to_follow_me.xml @@ -0,0 +1,128 @@ +<?xml version="1.0" encoding="utf-8"?> +<androidx.constraintlayout.widget.ConstraintLayout 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"> + + <com.google.android.material.appbar.MaterialToolbar + android:id="@+id/toolbar" + android:layout_width="0dp" + 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/invite_to_follow_me" + app:titleCentered="true" + app:titleMarginEnd="72dp"> + + <org.futo.circles.core.view.LoadingButton + android:id="@+id/btnInvite" + android:layout_width="56dp" + android:layout_height="match_parent" + android:layout_gravity="end" + android:layout_marginVertical="8dp" + android:layout_marginEnd="8dp" + android:enabled="false" + android:text="@string/invite" + android:textSize="13sp" + app:textPadding="1dp" /> + + </com.google.android.material.appbar.MaterialToolbar> + + <View + android:id="@+id/toolbarDivider" + android:layout_width="0dp" + android:layout_height="@dimen/divider_height" + android:background="@color/divider_color" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/toolbar" /> + + <TextView + android:id="@+id/tvTitle" + style="@style/headline" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_marginTop="8dp" + android:gravity="center" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/toolbarDivider" + tools:text="@string/select_circles_to_which_you_want_to_invite_format" /> + + <View + android:id="@+id/titleDivider" + android:layout_width="0dp" + android:layout_height="@dimen/divider_height" + android:layout_marginTop="8dp" + android:background="@color/divider_color" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/tvTitle" /> + + <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/titleDivider" /> + + <TextView + android:id="@+id/tvCreateCircle" + style="@style/headline" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:gravity="center" + android:paddingHorizontal="36dp" + android:text="@string/create_your_first_circle_to_be_able_to_invite" + app:layout_constraintBottom_toTopOf="@+id/btnCreateCircle" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintVertical_chainStyle="packed" /> + + <com.google.android.material.button.MaterialButton + android:id="@+id/btnCreateCircle" + style="@style/AccentButtonStyle" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="8dp" + android:text="@string/create_new_circle" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/tvCreateCircle" /> + + <com.google.android.material.floatingactionbutton.FloatingActionButton + android:id="@+id/fbAddRoom" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_margin="16dp" + app:fabSize="normal" + app:layout_anchor="@id/lContainer" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:srcCompat="@drawable/ic_add" + app:tint="@color/white" + tools:ignore="ContentDescription" /> + + <androidx.constraintlayout.widget.Group + android:id="@+id/selectCircleGroup" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + app:constraint_referenced_ids="tvTitle,titleDivider" /> + + <androidx.constraintlayout.widget.Group + android:id="@+id/createCircleGroup" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:visibility="gone" + app:constraint_referenced_ids="tvCreateCircle,btnCreateCircle" + tools:visibility="visible" /> + + +</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 13a2f4d1f744318f8728ba42cf080863c79bebda..3f842c18612a6a636140aadfb951491952af4fe4 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -253,6 +253,9 @@ <string name="remove_image">Remove image</string> <string name="remove_image_message">Are you sure you want to remove this image?</string> <string name="invite_to_follow_me">Invite to follow me</string> + <string name="select_circles_to_which_you_want_to_invite_format">Select circles to which you want to invite %s</string> + <string name="create_your_first_circle_to_be_able_to_invite">Create your first Circle to be able to invite</string> + <string name="create_new_circle">Create new circle</string> <plurals name="notification_compat_summary_line_for_room"> <item quantity="one">%1$s: %2$d message</item>