Converted UserInfo activity to fragment
This commit is contained in:
parent
15a86f0f5b
commit
9f17bf6378
6 changed files with 101 additions and 59 deletions
|
@ -112,7 +112,6 @@
|
|||
<activity android:name=".activities.tageditor.AlbumTagEditorActivity" />
|
||||
<activity android:name=".activities.tageditor.SongTagEditorActivity" />
|
||||
<activity android:name=".activities.LyricsActivity" />
|
||||
<activity android:name=".activities.UserInfoActivity" />
|
||||
<activity android:name=".activities.SupportDevelopmentActivity" />
|
||||
<activity android:name=".activities.LicenseActivity" />
|
||||
<activity android:name=".activities.PurchaseActivity" />
|
||||
|
|
|
@ -12,25 +12,33 @@
|
|||
* See the GNU General Public License for more details.
|
||||
*
|
||||
*/
|
||||
package code.name.monkey.retromusic.activities
|
||||
package code.name.monkey.retromusic.fragments
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Color
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.core.view.doOnPreDraw
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import code.name.monkey.appthemehelper.util.ColorUtil
|
||||
import code.name.monkey.appthemehelper.util.MaterialValueHelper
|
||||
import code.name.monkey.retromusic.Constants.USER_BANNER
|
||||
import code.name.monkey.retromusic.Constants.USER_PROFILE
|
||||
import code.name.monkey.retromusic.activities.base.AbsBaseActivity
|
||||
import code.name.monkey.retromusic.databinding.ActivityUserInfoBinding
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.databinding.FragmentUserInfoBinding
|
||||
import code.name.monkey.retromusic.extensions.accentColor
|
||||
import code.name.monkey.retromusic.extensions.applyToolbar
|
||||
import code.name.monkey.retromusic.extensions.resolveColor
|
||||
import code.name.monkey.retromusic.glide.GlideApp
|
||||
import code.name.monkey.retromusic.glide.RetroGlideExtension
|
||||
import code.name.monkey.retromusic.util.ImageUtil
|
||||
|
@ -43,6 +51,7 @@ import com.bumptech.glide.request.RequestListener
|
|||
import com.bumptech.glide.request.target.Target
|
||||
import com.github.dhaval2404.imagepicker.ImagePicker
|
||||
import com.github.dhaval2404.imagepicker.constant.ImageProvider
|
||||
import com.google.android.material.transition.MaterialContainerTransform
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
@ -52,16 +61,28 @@ import java.io.File
|
|||
import java.io.FileOutputStream
|
||||
import java.io.IOException
|
||||
|
||||
class UserInfoActivity : AbsBaseActivity() {
|
||||
class UserInfoFragment : Fragment() {
|
||||
|
||||
private lateinit var binding: ActivityUserInfoBinding
|
||||
private var _binding: FragmentUserInfoBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityUserInfoBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
setStatusbarColorAuto()
|
||||
setTaskDescriptionColorAuto()
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
sharedElementEnterTransition = MaterialContainerTransform().apply {
|
||||
drawingViewId = R.id.fragment_container
|
||||
duration = 300L
|
||||
scrimColor = Color.TRANSPARENT
|
||||
setAllContainerColors(requireContext().resolveColor(R.attr.colorSurface))
|
||||
}
|
||||
_binding = FragmentUserInfoBinding.inflate(layoutInflater)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
applyToolbar(binding.toolbar)
|
||||
|
||||
binding.nameContainer.accentColor()
|
||||
|
@ -78,20 +99,30 @@ class UserInfoActivity : AbsBaseActivity() {
|
|||
binding.next.setOnClickListener {
|
||||
val nameString = binding.name.text.toString().trim { it <= ' ' }
|
||||
if (TextUtils.isEmpty(nameString)) {
|
||||
Toast.makeText(this, "Umm you're name can't be empty!", Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
"Umm you're name can't be empty!",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
return@setOnClickListener
|
||||
}
|
||||
PreferenceUtil.userName = nameString
|
||||
setResult(Activity.RESULT_OK)
|
||||
finish()
|
||||
findNavController().navigateUp()
|
||||
}
|
||||
|
||||
val textColor =
|
||||
MaterialValueHelper.getPrimaryTextColor(this, ColorUtil.isColorLight(accentColor()))
|
||||
MaterialValueHelper.getPrimaryTextColor(
|
||||
requireContext(),
|
||||
ColorUtil.isColorLight(accentColor())
|
||||
)
|
||||
binding.next.backgroundTintList = ColorStateList.valueOf(accentColor())
|
||||
binding.next.iconTint = ColorStateList.valueOf(textColor)
|
||||
binding.next.setTextColor(textColor)
|
||||
loadProfile()
|
||||
postponeEnterTransition()
|
||||
view.doOnPreDraw {
|
||||
startPostponedEnterTransition()
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadProfile() {
|
||||
|
@ -110,7 +141,7 @@ class UserInfoActivity : AbsBaseActivity() {
|
|||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
if (item.itemId == android.R.id.home) {
|
||||
onBackPressed()
|
||||
findNavController().navigateUp()
|
||||
}
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
@ -131,7 +162,7 @@ class UserInfoActivity : AbsBaseActivity() {
|
|||
.start(PICK_IMAGE_REQUEST)
|
||||
}
|
||||
|
||||
public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if (resultCode == Activity.RESULT_OK && requestCode == PICK_IMAGE_REQUEST) {
|
||||
val fileUri = data?.data
|
||||
|
@ -140,9 +171,9 @@ class UserInfoActivity : AbsBaseActivity() {
|
|||
val fileUri = data?.data
|
||||
fileUri?.let { setAndSaveBannerImage(it) }
|
||||
} else if (resultCode == ImagePicker.RESULT_ERROR) {
|
||||
Toast.makeText(this, ImagePicker.getError(data), Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(requireContext(), ImagePicker.getError(data), Toast.LENGTH_SHORT).show()
|
||||
} else {
|
||||
Toast.makeText(this, "Task Cancelled", Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(requireContext(), "Task Cancelled", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -177,7 +208,7 @@ class UserInfoActivity : AbsBaseActivity() {
|
|||
|
||||
private fun saveImage(bitmap: Bitmap, fileName: String) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val appDir = applicationContext.filesDir
|
||||
val appDir = requireContext().filesDir
|
||||
val file = File(appDir, fileName)
|
||||
var successful = false
|
||||
try {
|
||||
|
@ -190,7 +221,7 @@ class UserInfoActivity : AbsBaseActivity() {
|
|||
}
|
||||
if (successful) {
|
||||
withContext(Dispatchers.Main) {
|
||||
Toast.makeText(this@UserInfoActivity, "Updated", Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(requireContext(), "Updated", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -225,6 +256,11 @@ class UserInfoActivity : AbsBaseActivity() {
|
|||
.into(binding.userImage)
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val PICK_IMAGE_REQUEST = 9002
|
||||
private const val PICK_BANNER_REQUEST = 9004
|
|
@ -14,7 +14,6 @@
|
|||
*/
|
||||
package code.name.monkey.retromusic.fragments.home
|
||||
|
||||
import android.app.ActivityOptions
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
|
@ -24,6 +23,7 @@ import android.view.View
|
|||
import androidx.core.os.bundleOf
|
||||
import androidx.core.text.HtmlCompat
|
||||
import androidx.core.view.doOnPreDraw
|
||||
import androidx.navigation.fragment.FragmentNavigatorExtras
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
|
@ -38,10 +38,9 @@ import code.name.monkey.retromusic.dialogs.ImportPlaylistDialog
|
|||
import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment
|
||||
import code.name.monkey.retromusic.glide.GlideApp
|
||||
import code.name.monkey.retromusic.glide.RetroGlideExtension
|
||||
import code.name.monkey.retromusic.util.NavigationUtil
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import com.google.android.gms.cast.framework.CastButtonFactory
|
||||
import com.google.android.material.transition.MaterialFadeThrough
|
||||
import com.google.android.material.shape.MaterialShapeDrawable
|
||||
import com.google.android.material.transition.MaterialSharedAxis
|
||||
|
||||
class HomeFragment :
|
||||
|
@ -55,14 +54,35 @@ class HomeFragment :
|
|||
_binding = getBinding(PreferenceUtil.isHomeBanner, view)
|
||||
mainActivity.setSupportActionBar(binding.toolbar)
|
||||
mainActivity.supportActionBar?.title = null
|
||||
setStatusBarColorAuto(view)
|
||||
setupListeners()
|
||||
binding.titleWelcome.text = String.format("%s", PreferenceUtil.userName)
|
||||
|
||||
val homeAdapter = HomeAdapter(mainActivity)
|
||||
binding.recyclerView.apply {
|
||||
layoutManager = LinearLayoutManager(mainActivity)
|
||||
adapter = homeAdapter
|
||||
}
|
||||
libraryViewModel.getHome().observe(viewLifecycleOwner, {
|
||||
homeAdapter.swapData(it)
|
||||
})
|
||||
|
||||
loadProfile()
|
||||
setupTitle()
|
||||
postponeEnterTransition()
|
||||
view.doOnPreDraw { startPostponedEnterTransition() }
|
||||
binding.appBarLayout.statusBarForeground =
|
||||
MaterialShapeDrawable.createWithElevationOverlay(requireContext())
|
||||
}
|
||||
|
||||
private fun setupListeners() {
|
||||
binding.bannerImage?.setOnClickListener {
|
||||
val options = ActivityOptions.makeSceneTransitionAnimation(
|
||||
mainActivity,
|
||||
binding.userImage,
|
||||
getString(R.string.transition_user_image)
|
||||
binding.userImage.transitionName = "userImage"
|
||||
findNavController().navigate(
|
||||
R.id.user_info_fragment, null, null, FragmentNavigatorExtras(
|
||||
binding.userImage to "userImage"
|
||||
)
|
||||
)
|
||||
NavigationUtil.goToUserInfo(requireActivity(), options)
|
||||
reenterTransition = null
|
||||
}
|
||||
|
||||
binding.lastAdded.setOnClickListener {
|
||||
|
@ -94,28 +114,12 @@ class HomeFragment :
|
|||
}
|
||||
|
||||
binding.userImage.setOnClickListener {
|
||||
val options = ActivityOptions.makeSceneTransitionAnimation(
|
||||
mainActivity,
|
||||
binding.userImage,
|
||||
getString(R.string.transition_user_image)
|
||||
findNavController().navigate(
|
||||
R.id.user_info_fragment, null, null, FragmentNavigatorExtras(
|
||||
binding.userImage to "user_image"
|
||||
)
|
||||
)
|
||||
NavigationUtil.goToUserInfo(requireActivity(), options)
|
||||
}
|
||||
binding.titleWelcome.text = String.format("%s", PreferenceUtil.userName)
|
||||
|
||||
val homeAdapter = HomeAdapter(mainActivity)
|
||||
binding.recyclerView.apply {
|
||||
layoutManager = LinearLayoutManager(mainActivity)
|
||||
adapter = homeAdapter
|
||||
}
|
||||
libraryViewModel.getHome().observe(viewLifecycleOwner, {
|
||||
homeAdapter.swapData(it)
|
||||
})
|
||||
|
||||
loadProfile()
|
||||
setupTitle()
|
||||
postponeEnterTransition()
|
||||
view.doOnPreDraw { startPostponedEnterTransition() }
|
||||
}
|
||||
|
||||
private fun getBinding(homeBanner: Boolean, view: View): HomeBindingAdapter {
|
||||
|
|
|
@ -34,7 +34,7 @@ import code.name.monkey.retromusic.activities.LyricsActivity;
|
|||
import code.name.monkey.retromusic.activities.PlayingQueueActivity;
|
||||
import code.name.monkey.retromusic.activities.PurchaseActivity;
|
||||
import code.name.monkey.retromusic.activities.SupportDevelopmentActivity;
|
||||
import code.name.monkey.retromusic.activities.UserInfoActivity;
|
||||
import code.name.monkey.retromusic.fragments.UserInfoFragment;
|
||||
import code.name.monkey.retromusic.activities.WhatsNewActivity;
|
||||
import code.name.monkey.retromusic.activities.bugreport.BugReportActivity;
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote;
|
||||
|
@ -70,8 +70,8 @@ public class NavigationUtil {
|
|||
|
||||
public static void goToUserInfo(
|
||||
@NonNull Activity activity, @NonNull ActivityOptions activityOptions) {
|
||||
ActivityCompat.startActivity(
|
||||
activity, new Intent(activity, UserInfoActivity.class), activityOptions.toBundle());
|
||||
ActivityCompat.startActivity(
|
||||
activity, new Intent(activity, UserInfoFragment.class), activityOptions.toBundle());
|
||||
}
|
||||
|
||||
public static void gotoDriveMode(@NotNull final Activity activity) {
|
||||
|
|
|
@ -16,13 +16,15 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
android:transitionGroup="true">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/appBarLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:liftOnScroll="true">
|
||||
app:liftOnScroll="true"
|
||||
android:fitsSystemWindows="true">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
|
@ -33,7 +35,6 @@
|
|||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/colorSurface"
|
||||
app:navigationIcon="@drawable/ic_search"
|
||||
app:popupTheme="?attr/toolbarPopupTheme"
|
||||
app:title="@null"
|
||||
|
@ -80,7 +81,8 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:retroCornerSize="21dp"
|
||||
tools:srcCompat="@tools:sample/avatars" />
|
||||
tools:srcCompat="@tools:sample/avatars"
|
||||
android:transitionName="user_image" />
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/text"
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:scaleType="centerCrop"
|
||||
android:transitionName="@string/transition_user_image"
|
||||
android:transitionName="user_image"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/bannerImage"
|
||||
app:retroCornerSize="36dp"
|
||||
|
@ -92,7 +92,8 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_margin="16dp"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:layout_marginBottom="70dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/save"
|
||||
app:icon="@drawable/ic_save"
|
Loading…
Reference in a new issue