WIP editar perfil, no permitir entrar en modo eliminar fotos al no ser perfil propio

This commit is contained in:
erik-everardo 2024-01-07 23:51:18 -06:00
parent 75b621ba0b
commit 458de335d4
11 changed files with 105 additions and 11 deletions

View File

@ -39,6 +39,7 @@
<activity android:name=".sign_up.ui.SignUpActivity" android:theme="@style/Theme.Isolaatti"/>
<activity android:name=".images.image_maker.ui.ImageMakerActivity" android:theme="@style/Theme.Isolaatti"/>
<activity android:name=".images.image_chooser.ui.ImageChooserActivity" android:theme="@style/Theme.Isolaatti"/>
<activity android:name=".profile.ui.EditProfileActivity" android:theme="@style/Theme.Isolaatti" />
<provider
android:authorities="com.isolaatti.provider"
android:name="androidx.core.content.FileProvider"

View File

@ -4,6 +4,7 @@ import com.isolaatti.audio.common.data.AudioDto
import com.isolaatti.common.Ownable
import com.isolaatti.connectivity.RetrofitClient.Companion.BASE_URL
import com.isolaatti.utils.UrlGen
import java.io.Serializable
import java.time.ZonedDateTime
data class Audio(
@ -12,7 +13,7 @@ data class Audio(
val creationTime: ZonedDateTime,
override val userId: Int,
val userName: String
): Ownable {
): Ownable, Serializable {
var playing: Boolean = false
val downloadUrl: String get() {
return "${BASE_URL}audios/$id.webm"

View File

@ -32,7 +32,7 @@ class ImageListViewModel @Inject constructor(private val imagesRepository: Image
private var loadedFirstTime = false
var userId by Delegates.notNull<Int>()
val isUserItself: MutableLiveData<Boolean> = MutableLiveData()
val isUserItself: MutableLiveData<Boolean> = MutableLiveData(false)
private val list: List<Image> get() {
return liveList.value ?: listOf()

View File

@ -191,6 +191,7 @@ class ImagesFragment : Fragment() {
actionMode?.menu?.findItem(R.id.delete_item)?.isEnabled = it > 0
},
onDeleteMode = {
if(viewModel.isUserItself.value == false) return@ImagesAdapter
adapter.deleteMode = it
actionMode = requireActivity().startActionMode(contextBarCallback)
},

View File

@ -4,6 +4,7 @@ import com.isolaatti.audio.common.domain.Audio
import com.isolaatti.common.Ownable
import com.isolaatti.profile.data.remote.UserProfileDto
import com.isolaatti.utils.UrlGen
import java.io.Serializable
data class UserProfile(
override val userId: Int,
@ -20,7 +21,7 @@ data class UserProfile(
val descriptionText: String?,
val descriptionAudioId: String?,
val descriptionAudio: Audio?
) : Ownable {
) : Ownable, Serializable {
val profileAvatarPictureUrl: String get() = UrlGen.userProfileImage(userId)
val profilePictureUrl: String get() = UrlGen.userProfileImageFullQuality(userId)

View File

@ -1,4 +1,23 @@
package com.isolaatti.profile.presentation
class EditProfileContract {
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Build
import androidx.activity.result.contract.ActivityResultContract
import com.isolaatti.profile.domain.entity.UserProfile
import com.isolaatti.profile.ui.EditProfileActivity
class EditProfileContract : ActivityResultContract<Void?, UserProfile?>() {
override fun createIntent(context: Context, input: Void?): Intent {
return Intent(context, EditProfileActivity::class.java)
}
override fun parseResult(resultCode: Int, intent: Intent?): UserProfile? {
if(intent == null || resultCode != Activity.RESULT_OK) return null
return if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
intent.extras?.getSerializable(EditProfileActivity.EXTRA_OUT_USER_PROFILE, UserProfile::class.java)
else
intent.extras?.getSerializable(EditProfileActivity.EXTRA_OUT_USER_PROFILE) as UserProfile
}
}

View File

@ -16,4 +16,8 @@ class EditProfileActivity : IsolaattiBaseActivity() {
setContentView(binding.root)
}
companion object {
const val EXTRA_OUT_USER_PROFILE = "user_profile"
}
}

View File

@ -18,6 +18,7 @@ import androidx.lifecycle.repeatOnLifecycle
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import coil.load
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.isolaatti.BuildConfig
import com.isolaatti.R
import com.isolaatti.audio.audios_list.ui.AudiosFragment
@ -35,6 +36,7 @@ import com.isolaatti.databinding.FragmentDiscussionsBinding
import com.isolaatti.followers.domain.FollowingState
import com.isolaatti.images.image_chooser.ui.ImageChooserContract
import com.isolaatti.images.image_list.ui.ImagesFragment
import com.isolaatti.images.picture_viewer.ui.PictureViewerActivity
import com.isolaatti.posting.comments.ui.BottomSheetPostComments
import com.isolaatti.posting.posts.domain.entity.Post
import com.isolaatti.posting.posts.presentation.CreatePostContract
@ -44,6 +46,7 @@ import com.isolaatti.posting.posts.presentation.PostsRecyclerViewAdapter
import com.isolaatti.posting.posts.presentation.UpdateEvent
import com.isolaatti.posting.posts.viewer.ui.PostViewerActivity
import com.isolaatti.profile.domain.entity.UserProfile
import com.isolaatti.profile.presentation.EditProfileContract
import com.isolaatti.profile.presentation.ProfileViewModel
import com.isolaatti.utils.UrlGen
import dagger.hilt.android.AndroidEntryPoint
@ -96,6 +99,10 @@ class ProfileMainFragment : Fragment() {
}
}
private val editProfile = registerForActivityResult(EditProfileContract()) {
}
private val audioPlayerConnectorListener = object: AudioPlayerConnector.Listener {
override fun onPlaying(isPlaying: Boolean, audio: Audio) {
viewBinding.playButton.icon = AppCompatResources.getDrawable(requireContext(), if(isPlaying) R.drawable.baseline_pause_circle_24 else R.drawable.baseline_play_circle_24)
@ -190,11 +197,13 @@ class ProfileMainFragment : Fragment() {
Options.Option.OPTION_PROFILE_PHOTO_CHANGE_PHOTO -> {
chooseImageLauncher.launch(ImageChooserContract.Requester.UserPost)
}
Options.Option.OPTION_PROFILE_PHOTO_REMOVE_PHOTO -> {}
Options.Option.OPTION_PROFILE_PHOTO_REMOVE_PHOTO -> {
showRemoveProfileImageDialog()
}
Options.Option.OPTION_PROFILE_PHOTO_VIEW_PHOTO -> {
val profilePictureUrl = profile?.profilePictureUrl
if(profilePictureUrl != null) {
//PictureViewerActivity.startActivityWithUrls(requireContext(), arrayOf(profilePictureUrl))
// TODO show image
}
}
}
@ -228,6 +237,17 @@ class ProfileMainFragment : Fragment() {
}
}
private fun showRemoveProfileImageDialog() {
MaterialAlertDialogBuilder(requireContext())
.setMessage(R.string.remove_image_message_confirmation)
.setTitle(R.string.remove_photo)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.yes_continue) { _, _ ->
// remove image here
}
.show()
}
private lateinit var postListingRecyclerViewAdapterWiring: PostListingRecyclerViewAdapterWiring
@ -255,6 +275,25 @@ class ProfileMainFragment : Fragment() {
requireActivity().finish()
}
viewBinding.topAppBar.setOnMenuItemClickListener {
when(it.itemId) {
R.id.edit_profile -> {
editProfile.launch(null)
true
}
R.id.user_link_menu_item -> {
true
}
R.id.report_profile_menu_item -> {
true
}
R.id.block_profile_menu_item -> {
true
}
else -> false
}
}
viewBinding.audiosButton.setOnClickListener {
findNavController().navigate(ProfileMainFragmentDirections.actionDiscussionsFragmentToAudiosFragment(AudiosFragment.SOURCE_PROFILE, userId.toString()))
}
@ -340,8 +379,13 @@ class ProfileMainFragment : Fragment() {
private fun setupUiForUserType(isOwnProfile: Boolean) {
if(isOwnProfile) {
viewBinding.followButton.visibility = View.GONE
viewBinding.topAppBar.menu?.run {
removeItem(R.id.block_profile_menu_item)
removeItem(R.id.report_profile_menu_item)
}
} else {
viewBinding.createPostButton.visibility = View.GONE
viewBinding.topAppBar.menu.removeItem(R.id.edit_profile)
}
}

View File

@ -0,0 +1,15 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M3,11h8V3H3V11zM5,5h4v4H5V5z"/>
<path android:fillColor="@android:color/white" android:pathData="M3,21h8v-8H3V21zM5,15h4v4H5V15z"/>
<path android:fillColor="@android:color/white" android:pathData="M13,3v8h8V3H13zM19,9h-4V5h4V9z"/>
<path android:fillColor="@android:color/white" android:pathData="M19,19h2v2h-2z"/>
<path android:fillColor="@android:color/white" android:pathData="M13,13h2v2h-2z"/>
<path android:fillColor="@android:color/white" android:pathData="M15,15h2v2h-2z"/>
<path android:fillColor="@android:color/white" android:pathData="M13,17h2v2h-2z"/>
<path android:fillColor="@android:color/white" android:pathData="M15,19h2v2h-2z"/>
<path android:fillColor="@android:color/white" android:pathData="M17,17h2v2h-2z"/>
<path android:fillColor="@android:color/white" android:pathData="M17,13h2v2h-2z"/>
<path android:fillColor="@android:color/white" android:pathData="M19,15h2v2h-2z"/>
</vector>

View File

@ -2,10 +2,16 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/edit_profile"
android:title="@string/edit_profile"
android:icon="@drawable/baseline_edit_24"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/user_link_menu_item"
android:title="@string/user_link"
app:showAsAction="never" />
android:icon="@drawable/baseline_qr_code_24"
app:showAsAction="ifRoom" />
<item
android:id="@+id/report_profile_menu_item"

View File

@ -84,10 +84,10 @@
<string name="comments">Comments</string>
<string name="likes_info">Claps: %d</string>
<string name="comments_info">Comments: %d</string>
<string name="view_photo">View photo</string>
<string name="change_profile_photo">Change profile photo</string>
<string name="profile_photo">Profile photo</string>
<string name="remove_photo">Remove photo</string>
<string name="view_photo">View image</string>
<string name="change_profile_photo">Change profile image</string>
<string name="profile_photo">Profile image</string>
<string name="remove_photo">Remove image</string>
<string name="get_code_info">The first step to create an account is to provide your email address. We will send a code that you will need to enter in the next step.</string>
<string name="send">Send</string>
<string name="already_have_a_code">Already have a code?</string>
@ -134,4 +134,6 @@
<string name="insert_url">Insert url</string>
<string name="enlarge_text_box">Enlarge text box</string>
<string name="create_a_new_discussion">Create a new discussion</string>
<string name="edit_profile">Edit profile</string>
<string name="remove_image_message_confirmation">Remove image? This will not delete your image, but only unset it as profile image</string>
</resources>