77
88package com.owncloud.android.ui.fragment.albums
99
10+ import android.annotation.SuppressLint
1011import android.app.Activity
1112import android.content.Context
1213import android.content.Intent
@@ -113,6 +114,7 @@ class AlbumItemsFragment : Fragment(), OCFileListFragmentInterface, Injectable {
113114 private var columnSize = 0
114115
115116 private lateinit var albumName: String
117+ private var isNewAlbum: Boolean = false
116118
117119 private var mMultiChoiceModeListener: MultiChoiceModeListener ? = null
118120
@@ -128,6 +130,7 @@ class AlbumItemsFragment : Fragment(), OCFileListFragmentInterface, Injectable {
128130 }
129131 arguments?.let {
130132 albumName = it.getString(ARG_ALBUM_NAME ) ? : " "
133+ isNewAlbum = it.getBoolean(ARG_IS_NEW_ALBUM )
131134 }
132135 }
133136
@@ -139,9 +142,9 @@ class AlbumItemsFragment : Fragment(), OCFileListFragmentInterface, Injectable {
139142 override fun onCreate (savedInstanceState : Bundle ? ) {
140143 super .onCreate(savedInstanceState)
141144 columnSize = if (resources.configuration.orientation == Configuration .ORIENTATION_LANDSCAPE ) {
142- maxColumnSizeLandscape;
145+ MAX_COLUMN_SIZE_LANDSCAPE
143146 } else {
144- maxColumnSizePortrait;
147+ MAX_COLUMN_SIZE_PORTRAIT
145148 }
146149 }
147150
@@ -159,6 +162,12 @@ class AlbumItemsFragment : Fragment(), OCFileListFragmentInterface, Injectable {
159162 createMenu()
160163 setupContainingList()
161164 setupContent()
165+
166+ // if fragment is opened when new albums is created
167+ // then open gallery to choose media to add
168+ if (isNewAlbum) {
169+ openGalleryToAddMedia()
170+ }
162171 }
163172
164173 private fun setUpActionMode () {
@@ -168,7 +177,7 @@ class AlbumItemsFragment : Fragment(), OCFileListFragmentInterface, Injectable {
168177 requireActivity(),
169178 adapter,
170179 viewThemeUtils
171- ) { filesCount, checkedFiles -> openActionsMenu(filesCount, checkedFiles, true ) }
180+ ) { filesCount, checkedFiles -> openActionsMenu(filesCount, checkedFiles) }
172181 (requireActivity() as FileDisplayActivity ).addDrawerListener(mMultiChoiceModeListener)
173182 }
174183
@@ -417,13 +426,14 @@ class AlbumItemsFragment : Fragment(), OCFileListFragmentInterface, Injectable {
417426 adapter?.cancelAllPendingTasks()
418427 }
419428
429+ @SuppressLint(" NotifyDataSetChanged" )
420430 override fun onConfigurationChanged (newConfig : Configuration ) {
421431 super .onConfigurationChanged(newConfig)
422432
423433 if (newConfig.orientation == Configuration .ORIENTATION_LANDSCAPE ) {
424- columnSize = maxColumnSizeLandscape
434+ columnSize = MAX_COLUMN_SIZE_LANDSCAPE
425435 } else if (newConfig.orientation == Configuration .ORIENTATION_PORTRAIT ) {
426- columnSize = maxColumnSizePortrait
436+ columnSize = MAX_COLUMN_SIZE_PORTRAIT
427437 }
428438 adapter?.changeColumn(columnSize)
429439 adapter?.notifyDataSetChanged()
@@ -519,7 +529,7 @@ class AlbumItemsFragment : Fragment(), OCFileListFragmentInterface, Injectable {
519529 requireActivity().supportFragmentManager.popBackStack()
520530 }
521531
522- private fun openActionsMenu (filesCount : Int , checkedFiles : Set <OCFile >, isOverflow : Boolean ) {
532+ private fun openActionsMenu (filesCount : Int , checkedFiles : Set <OCFile >) {
523533 throttler.run (" overflowClick" ) {
524534 var toHide: MutableList <Int >? = ArrayList ()
525535 for (file in checkedFiles) {
@@ -562,7 +572,7 @@ class AlbumItemsFragment : Fragment(), OCFileListFragmentInterface, Injectable {
562572 }
563573
564574 val childFragmentManager = childFragmentManager
565- val actionBottomSheet = newInstance(filesCount, checkedFiles, isOverflow , toHide)
575+ val actionBottomSheet = newInstance(filesCount, checkedFiles, true , toHide)
566576 .setResultListener(
567577 childFragmentManager, this
568578 ) { id: Int -> onFileActionChosen(id, checkedFiles) }
@@ -612,6 +622,7 @@ class AlbumItemsFragment : Fragment(), OCFileListFragmentInterface, Injectable {
612622 *
613623 * @param select `true` to select all, `false` to deselect all
614624 */
625+ @SuppressLint(" NotifyDataSetChanged" )
615626 private fun selectAllFiles (select : Boolean ) {
616627 adapter?.let {
617628 it.selectAll(select)
@@ -937,17 +948,19 @@ class AlbumItemsFragment : Fragment(), OCFileListFragmentInterface, Injectable {
937948 companion object {
938949 val TAG : String = AlbumItemsFragment ::class .java.simpleName
939950 private const val ARG_ALBUM_NAME = " album_name"
951+ private const val ARG_IS_NEW_ALBUM = " is_new_album"
940952 var lastMediaItemPosition: Int? = null
941953
942- private const val maxColumnSizeLandscape : Int = 5
943- private const val maxColumnSizePortrait : Int = 2
954+ private const val MAX_COLUMN_SIZE_LANDSCAPE : Int = 5
955+ private const val MAX_COLUMN_SIZE_PORTRAIT : Int = 2
944956
945- fun newInstance (albumName : String ): AlbumItemsFragment {
957+ fun newInstance (albumName : String , isNewAlbum : Boolean = false ): AlbumItemsFragment {
946958 val args = Bundle ()
947959
948960 val fragment = AlbumItemsFragment ()
949961 fragment.arguments = args
950962 args.putString(ARG_ALBUM_NAME , albumName)
963+ args.putBoolean(ARG_IS_NEW_ALBUM , isNewAlbum)
951964 return fragment
952965 }
953966 }
0 commit comments