Converted BackupActivity to fragment

This commit is contained in:
Prathamesh More 2021-10-09 13:58:21 +05:30
parent 5a73565182
commit 6e3c1aa742
11 changed files with 134 additions and 177 deletions

View file

@ -120,7 +120,7 @@
<activity android:name=".activities.PermissionActivity" />
<activity android:name=".activities.LockScreenActivity" />
<activity
android:name=".activities.backup.RestoreActivity"
android:name="code.name.monkey.retromusic.fragments.backup.RestoreActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
@ -133,7 +133,7 @@
</intent-filter>
</activity>
<activity
android:name=".activities.backup.BackupActivity"
android:name="code.name.monkey.retromusic.fragments.backup.BackupFragment"
android:exported="true" />
<activity

View file

@ -64,6 +64,7 @@ class SettingsActivity : AbsThemeActivity(), ColorCallback, OnThemeChangedListen
R.id.personalizeSettingsFragment -> R.string.personalize
R.id.themeSettingsFragment -> R.string.general_settings_title
R.id.aboutActivity -> R.string.action_about
R.id.backup_restore_settings -> R.string.backup_restore_title
else -> R.id.action_settings
}
return getString(idRes)

View file

@ -1,36 +1,31 @@
package code.name.monkey.retromusic.activities.backup
package code.name.monkey.retromusic.fragments.backup
import android.os.Bundle
import android.widget.Toast
import androidx.activity.viewModels
import android.view.View
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.activities.base.AbsThemeActivity
import code.name.monkey.retromusic.adapter.backup.BackupAdapter
import code.name.monkey.retromusic.databinding.ActivityBackupBinding
import code.name.monkey.retromusic.databinding.FragmentBackupBinding
import code.name.monkey.retromusic.helper.BackupHelper
import com.google.android.material.shape.MaterialShapeDrawable
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.File
class BackupActivity : AbsThemeActivity(), BackupAdapter.BackupClickedListener {
class BackupFragment : Fragment(R.layout.fragment_backup), BackupAdapter.BackupClickedListener {
private val backupViewModel by viewModels<BackupViewModel>()
private var backupAdapter: BackupAdapter? = null
lateinit var binding: ActivityBackupBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityBackupBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.appBarLayout.statusBarForeground =
MaterialShapeDrawable.createWithElevationOverlay(this)
binding.toolbar.setNavigationIcon(R.drawable.ic_keyboard_backspace_black)
private var _binding: FragmentBackupBinding? = null
private val binding get() = _binding!!
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
_binding = FragmentBackupBinding.bind(view)
initAdapter()
setupRecyclerview()
backupViewModel.backupsLiveData.observe(this) {
@ -46,21 +41,14 @@ class BackupActivity : AbsThemeActivity(), BackupAdapter.BackupClickedListener {
private fun setupButtons() {
binding.createBackup.setOnClickListener {
lifecycleScope.launch {
BackupHelper.createBackup(this@BackupActivity)
BackupHelper.createBackup(requireContext())
backupViewModel.loadBackups()
withContext(Dispatchers.Main) {
Toast.makeText(
this@BackupActivity,
"Backup Completed Successfully",
Toast.LENGTH_SHORT
).show()
}
}
}
}
private fun initAdapter() {
backupAdapter = BackupAdapter(this@BackupActivity, ArrayList(), this)
backupAdapter = BackupAdapter(requireContext(), ArrayList(), this)
backupAdapter?.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
override fun onChanged() {
super.onChanged()
@ -86,7 +74,7 @@ class BackupActivity : AbsThemeActivity(), BackupAdapter.BackupClickedListener {
override fun onBackupClicked(file: File) {
lifecycleScope.launch {
backupViewModel.restoreBackup(this@BackupActivity, file)
backupViewModel.restoreBackup(requireActivity(), file)
}
}
}

View file

@ -1,4 +1,4 @@
package code.name.monkey.retromusic.activities.backup
package code.name.monkey.retromusic.fragments.backup
import android.app.Activity
import android.content.Intent

View file

@ -1,4 +1,4 @@
package code.name.monkey.retromusic.activities.backup
package code.name.monkey.retromusic.fragments.backup
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity

View file

@ -45,7 +45,7 @@ class MainSettingsFragment : Fragment(), View.OnClickListener {
R.id.otherSettings -> findNavController().navigate(R.id.action_mainSettingsFragment_to_otherSettingsFragment)
R.id.aboutSettings -> findNavController().navigate(R.id.action_mainSettingsFragment_to_aboutActivity)
R.id.nowPlayingSettings -> findNavController().navigate(R.id.action_mainSettingsFragment_to_nowPlayingSettingsFragment)
R.id.backup_restore_settings -> NavigationUtil.gotoBackup(requireActivity())
R.id.backup_restore_settings -> findNavController().navigate(R.id.action_mainSettingsFragment_to_backupFragment)
}
}

View file

@ -23,7 +23,6 @@ import androidx.core.app.ActivityCompat
import androidx.navigation.findNavController
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.activities.*
import code.name.monkey.retromusic.activities.backup.BackupActivity
import code.name.monkey.retromusic.activities.bugreport.BugReportActivity
import code.name.monkey.retromusic.helper.MusicPlayerRemote.audioSessionId
import com.google.android.material.bottomsheet.BottomSheetBehavior
@ -78,10 +77,6 @@ object NavigationUtil {
ActivityCompat.startActivity(activity, Intent(activity, WhatsNewActivity::class.java), null)
}
fun gotoBackup(activity: Activity) {
ActivityCompat.startActivity(activity, Intent(activity, BackupActivity::class.java), null)
}
fun openEqualizer(activity: Activity) {
stockEqualizer(activity)
}

View file

@ -1,139 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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:background="?colorSurface"
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"
android:fitsSystemWindows="true">
<FrameLayout
android:id="@+id/toolbar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:navigationIcon="@drawable/ic_search"
app:popupTheme="?attr/toolbarPopupTheme"
app:title="@null"
tools:ignore="UnusedAttribute">
<com.google.android.material.textview.MaterialTextView
android:id="@+id/appNameText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/backup_restore_title"
android:textAppearance="@style/TextViewHeadline6"
android:textStyle="bold" />
</androidx.appcompat.widget.Toolbar>
</FrameLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
<com.google.android.material.button.MaterialButton
android:id="@+id/create_backup"
style="@style/Widget.Material3.Button.OutlinedButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="4dp"
android:paddingVertical="10dp"
android:text="@string/create_new_backup"
android:textAppearance="@style/TextViewButton"
android:textColor="?android:attr/textColorPrimary"
app:backgroundTint="?attr/colorSurface"
app:icon="@drawable/ic_backup"
app:iconGravity="start"
app:layout_constraintEnd_toStartOf="@+id/restore_backup"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.button.MaterialButton
android:id="@+id/restore_backup"
style="@style/Widget.Material3.Button.Icon"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="4dp"
android:layout_marginEnd="16dp"
android:paddingVertical="10dp"
android:text="@string/restore"
android:textAppearance="@style/TextViewButton"
app:icon="@drawable/ic_restore"
app:iconGravity="start"
app:layout_constraintBottom_toBottomOf="@+id/create_backup"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/create_backup"
app:layout_constraintTop_toTopOf="@+id/create_backup" />
<TextView
android:id="@+id/backup_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="@string/backup_title"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/create_backup" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/backup_recyclerview"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/backup_title" />
<LinearLayout
android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible">
<com.google.android.material.textview.MaterialTextView
android:id="@+id/emptyEmoji"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="@string/empty_text_emoji"
android:textAppearance="@style/TextViewHeadline3" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/emptyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/empty"
android:textAppearance="@style/TextViewHeadline5"
android:textColor="?android:attr/textColorSecondary"
tools:visibility="visible" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -3,6 +3,6 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.backup.RestoreActivity">
tools:context=".fragments.backup.RestoreActivity">
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -0,0 +1,98 @@
<?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"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
<com.google.android.material.button.MaterialButton
android:id="@+id/create_backup"
style="@style/Widget.Material3.Button.OutlinedButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="4dp"
android:paddingVertical="10dp"
android:text="@string/create_new_backup"
android:textAppearance="@style/TextViewButton"
android:textColor="?android:attr/textColorPrimary"
app:backgroundTint="?attr/colorSurface"
app:icon="@drawable/ic_backup"
app:iconGravity="start"
app:layout_constraintEnd_toStartOf="@+id/restore_backup"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.button.MaterialButton
android:id="@+id/restore_backup"
style="@style/Widget.Material3.Button.Icon"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="4dp"
android:layout_marginEnd="16dp"
android:paddingVertical="10dp"
android:text="@string/restore"
android:textAppearance="@style/TextViewButton"
app:icon="@drawable/ic_restore"
app:iconGravity="start"
app:layout_constraintBottom_toBottomOf="@+id/create_backup"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/create_backup"
app:layout_constraintTop_toTopOf="@+id/create_backup" />
<TextView
android:id="@+id/backup_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="@string/backup_title"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/create_backup" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/backup_recyclerview"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/backup_title" />
<LinearLayout
android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible">
<com.google.android.material.textview.MaterialTextView
android:id="@+id/emptyEmoji"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="@string/empty_text_emoji"
android:textAppearance="@style/TextViewHeadline3" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/emptyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/empty"
android:textAppearance="@style/TextViewHeadline5"
android:textColor="?android:attr/textColorSecondary"
tools:visibility="visible" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -74,6 +74,15 @@
app:launchSingleTop="true"
app:popEnterAnim="@anim/retro_fragment_close_enter"
app:popExitAnim="@anim/retro_fragment_close_exit" />
<action
android:id="@+id/action_mainSettingsFragment_to_backupFragment"
app:destination="@id/backup_fragment"
app:enterAnim="@anim/retro_fragment_open_enter"
app:exitAnim="@anim/retro_fragment_open_exit"
app:launchSingleTop="true"
app:popEnterAnim="@anim/retro_fragment_close_enter"
app:popExitAnim="@anim/retro_fragment_close_exit" />
</fragment>
<fragment
@ -116,4 +125,9 @@
android:name="code.name.monkey.retromusic.fragments.about.AboutFragment"
android:label="About" />
<fragment
android:id="@+id/backup_fragment"
android:name="code.name.monkey.retromusic.fragments.backup.BackupFragment"
android:label="About" />
</navigation>