Skip to content

Commit 45c6e86

Browse files
committed
fix album navigation and back icon
1 parent 7d4cb24 commit 45c6e86

6 files changed

Lines changed: 83 additions & 37 deletions

File tree

app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ private void onNavigationItemClicked(final MenuItem menuItem) {
528528
!(((FileDisplayActivity) this).getLeftFragment() instanceof SharedListFragment) &&
529529
!(((FileDisplayActivity) this).getLeftFragment() instanceof GroupfolderListFragment) &&
530530
!(((FileDisplayActivity) this).getLeftFragment() instanceof PreviewTextStringFragment) &&
531-
!isAlbumsFragmentVisible()) {
531+
!isAlbumsFragment() && !isAlbumItemsFragment()) {
532532
showFiles(false, itemId == R.id.nav_personal_files);
533533
((FileDisplayActivity) this).browseToRoot();
534534
EventBus.getDefault().post(new ChangeMenuEvent());
@@ -599,7 +599,7 @@ private void onNavigationItemClicked(final MenuItem menuItem) {
599599
}
600600

601601
private void replaceAlbumFragment() {
602-
if (isAlbumsFragmentVisible()) {
602+
if (isAlbumsFragment()) {
603603
return;
604604
}
605605
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
@@ -608,14 +608,14 @@ private void replaceAlbumFragment() {
608608
transaction.commit();
609609
}
610610

611-
public boolean isAlbumsFragmentVisible() {
611+
public boolean isAlbumsFragment() {
612612
Fragment albumsFragment = getSupportFragmentManager().findFragmentByTag(AlbumsFragment.Companion.getTAG());
613-
return albumsFragment != null && albumsFragment.isVisible();
613+
return albumsFragment instanceof AlbumsFragment && albumsFragment.isVisible();
614614
}
615615

616-
public boolean isAlbumItemsFragmentVisible() {
617-
Fragment albumsFragment = getSupportFragmentManager().findFragmentByTag(AlbumItemsFragment.Companion.getTAG());
618-
return albumsFragment != null && albumsFragment.isVisible();
616+
public boolean isAlbumItemsFragment() {
617+
Fragment albumItemsFragment = getSupportFragmentManager().findFragmentByTag(AlbumItemsFragment.Companion.getTAG());
618+
return albumItemsFragment instanceof AlbumItemsFragment && albumItemsFragment.isVisible();
619619
}
620620

621621
private void startComposeActivity(ComposeDestination destination, int titleId) {
@@ -680,7 +680,7 @@ private void handleSearchEvents(SearchEvent searchEvent, int menuItemId) {
680680
if (this instanceof FileDisplayActivity) {
681681
final Fragment leftFragment = ((FileDisplayActivity) this).getLeftFragment();
682682
if (leftFragment instanceof GalleryFragment || leftFragment instanceof SharedListFragment
683-
|| isAlbumsFragmentVisible()) {
683+
|| isAlbumsFragment() || isAlbumItemsFragment()) {
684684
launchActivityForSearch(searchEvent, menuItemId);
685685
} else {
686686
EventBus.getDefault().post(searchEvent);

app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,8 @@ public boolean onOptionsItemSelected(MenuItem item) {
954954
int itemId = item.getItemId();
955955

956956
if (itemId == android.R.id.home) {
957-
if (!isDrawerOpen() && !isSearchOpen() && isRoot(getCurrentDir()) && getLeftFragment() instanceof OCFileListFragment) {
957+
if (!isDrawerOpen() && !isSearchOpen() && isRoot(getCurrentDir()) && getLeftFragment() instanceof OCFileListFragment
958+
&& !isAlbumItemsFragment()) {
958959
openDrawer();
959960
} else {
960961
onBackPressed();
@@ -1151,8 +1152,8 @@ public void onBackPressed() {
11511152
return;
11521153
}
11531154

1154-
Fragment fragment = getSupportFragmentManager().findFragmentByTag(AlbumItemsFragment.Companion.getTAG());
1155-
if (fragment instanceof AlbumItemsFragment && fragment.isVisible()) {
1155+
// NMC Customization: pop back if current fragment is AlbumItemsFragment
1156+
if (isAlbumItemsFragment()) {
11561157
popBack();
11571158
return;
11581159
}
@@ -2140,7 +2141,7 @@ private void onCreateFolderOperationFinish(CreateFolderOperation operation, Remo
21402141
private void onCreateAlbumOperationFinish(CreateNewAlbumOperation operation, RemoteOperationResult result) {
21412142
if (result.isSuccess()) {
21422143
Fragment fragment = getSupportFragmentManager().findFragmentByTag(AlbumsFragment.Companion.getTAG());
2143-
if (isAlbumsFragmentVisible() && fragment instanceof AlbumsFragment albumsFragment) {
2144+
if (fragment instanceof AlbumsFragment albumsFragment) {
21442145
albumsFragment.newAlbumCreated(operation.getNewAlbumName());
21452146
}
21462147
} else {

app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,8 +2211,8 @@ public void setFabVisible(final boolean visible) {
22112211

22122212
// NMC Customizations: to hide the fab if user is on Albums Fragment
22132213
if (requireActivity() instanceof FileDisplayActivity fda
2214-
&& (fda.isAlbumsFragmentVisible()
2215-
|| fda.isAlbumItemsFragmentVisible())) {
2214+
&& (fda.isAlbumsFragment()
2215+
|| fda.isAlbumItemsFragment())) {
22162216
mFabMain.hide();
22172217
return;
22182218
}

app/src/main/java/com/owncloud/android/ui/fragment/albums/AlbumItemsFragment.kt

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ class AlbumItemsFragment : Fragment(), OCFileListFragmentInterface, Injectable {
176176
val menuHost: MenuHost = requireActivity()
177177
menuHost.addMenuProvider(object : MenuProvider {
178178
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
179+
menu.clear() // important: clears any existing activity menu
179180
menuInflater.inflate(R.menu.fragment_album_items, menu)
180181
}
181182

@@ -195,6 +196,28 @@ class AlbumItemsFragment : Fragment(), OCFileListFragmentInterface, Injectable {
195196
else -> false
196197
}
197198
}
199+
200+
override fun onPrepareMenu(menu: Menu) {
201+
super.onPrepareMenu(menu)
202+
val moreMenu = menu.findItem(R.id.action_three_dot_icon)
203+
moreMenu.icon?.let {
204+
moreMenu.setIcon(
205+
viewThemeUtils.platform.colorDrawable(
206+
it,
207+
ContextCompat.getColor(requireActivity(), R.color.black)
208+
)
209+
)
210+
}
211+
val add = menu.findItem(R.id.action_add_more_photos)
212+
add.icon?.let {
213+
add.setIcon(
214+
viewThemeUtils.platform.colorDrawable(
215+
it,
216+
ContextCompat.getColor(requireActivity(), R.color.black)
217+
)
218+
)
219+
}
220+
}
198221
}, viewLifecycleOwner, Lifecycle.State.RESUMED)
199222
}
200223

@@ -378,7 +401,9 @@ class AlbumItemsFragment : Fragment(), OCFileListFragmentInterface, Injectable {
378401
super.onResume()
379402
if (requireActivity() is FileDisplayActivity) {
380403
(requireActivity() as FileDisplayActivity).setupToolbar()
381-
(requireActivity() as FileDisplayActivity).updateActionBarTitleAndHomeButtonByString(albumName)
404+
(requireActivity() as FileDisplayActivity).supportActionBar?.let { actionBar ->
405+
viewThemeUtils.files.themeActionBar(requireContext(), actionBar, albumName)
406+
}
382407
(requireActivity() as FileDisplayActivity).showSortListGroup(false)
383408
(requireActivity() as FileDisplayActivity).setMainFabVisible(false)
384409

@@ -409,24 +434,6 @@ class AlbumItemsFragment : Fragment(), OCFileListFragmentInterface, Injectable {
409434
lastMediaItemPosition = 0
410435
}
411436

412-
companion object {
413-
val TAG: String = AlbumItemsFragment::class.java.simpleName
414-
private const val ARG_ALBUM_NAME = "album_name"
415-
var lastMediaItemPosition: Int? = null
416-
417-
private const val maxColumnSizeLandscape: Int = 5
418-
private const val maxColumnSizePortrait: Int = 2
419-
420-
fun newInstance(albumName: String): AlbumItemsFragment {
421-
val args = Bundle()
422-
423-
val fragment = AlbumItemsFragment()
424-
fragment.arguments = args
425-
args.putString(ARG_ALBUM_NAME, albumName)
426-
return fragment
427-
}
428-
}
429-
430437
override fun getColumnsCount(): Int {
431438
return columnSize
432439
}
@@ -923,7 +930,25 @@ class AlbumItemsFragment : Fragment(), OCFileListFragmentInterface, Injectable {
923930
}
924931
}
925932

926-
fun refreshData(){
933+
fun refreshData() {
927934
fetchAndSetData()
928935
}
936+
937+
companion object {
938+
val TAG: String = AlbumItemsFragment::class.java.simpleName
939+
private const val ARG_ALBUM_NAME = "album_name"
940+
var lastMediaItemPosition: Int? = null
941+
942+
private const val maxColumnSizeLandscape: Int = 5
943+
private const val maxColumnSizePortrait: Int = 2
944+
945+
fun newInstance(albumName: String): AlbumItemsFragment {
946+
val args = Bundle()
947+
948+
val fragment = AlbumItemsFragment()
949+
fragment.arguments = args
950+
args.putString(ARG_ALBUM_NAME, albumName)
951+
return fragment
952+
}
953+
}
929954
}

app/src/main/java/com/owncloud/android/ui/fragment/albums/AlbumsFragment.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ class AlbumsFragment : Fragment(), AlbumFragmentInterface, Injectable {
137137
val menuHost: MenuHost = requireActivity()
138138
menuHost.addMenuProvider(object : MenuProvider {
139139
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
140+
menu.clear() // important: clears any existing activity menu
140141
menuInflater.inflate(R.menu.fragment_create_album, menu)
141142
}
142143

@@ -299,7 +300,14 @@ class AlbumsFragment : Fragment(), AlbumFragmentInterface, Injectable {
299300
}
300301
if (requireActivity() is FileDisplayActivity) {
301302
(requireActivity() as FileDisplayActivity).setupToolbar()
302-
(requireActivity() as FileDisplayActivity).updateActionBarTitleAndHomeButtonByString(getString(R.string.drawer_item_album))
303+
(requireActivity() as FileDisplayActivity).supportActionBar?.let { actionBar ->
304+
viewThemeUtils.files.themeActionBar(
305+
requireContext(),
306+
actionBar,
307+
R.string.drawer_item_album,
308+
isMenu = true
309+
)
310+
}
303311
(requireActivity() as FileDisplayActivity).showSortListGroup(false)
304312
(requireActivity() as FileDisplayActivity).setMainFabVisible(false)
305313

app/src/main/java/com/owncloud/android/ui/fragment/albums/AlbumsPickerActivity.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package com.owncloud.android.ui.fragment.albums
1010
import android.content.Intent
1111
import android.content.res.Resources
1212
import android.os.Bundle
13+
import android.view.MenuItem
1314
import android.view.View
1415
import androidx.fragment.app.FragmentActivity
1516
import com.nextcloud.client.di.Injectable
@@ -66,6 +67,7 @@ class AlbumsPickerActivity : FileActivity(), FileFragment.ContainerActivity, OnE
6667
View.GONE
6768
findViewById<View>(R.id.switch_grid_view_button).visibility =
6869
View.GONE
70+
supportActionBar?.setDisplayHomeAsUpEnabled(true)
6971
}
7072

7173
private fun setupAction() {
@@ -104,8 +106,11 @@ class AlbumsPickerActivity : FileActivity(), FileFragment.ContainerActivity, OnE
104106

105107
private fun createGalleryFragment() {
106108
val photoFragment = GalleryFragment()
107-
val bundle = Bundle()
108-
bundle.putParcelable(OCFileListFragment.SEARCH_EVENT, SearchEvent("image/%", SearchRemoteOperation.SearchType.PHOTO_SEARCH))
109+
val bundle = Bundle()
110+
bundle.putParcelable(
111+
OCFileListFragment.SEARCH_EVENT,
112+
SearchEvent("image/%", SearchRemoteOperation.SearchType.PHOTO_SEARCH)
113+
)
109114
bundle.putBoolean(EXTRA_FROM_ALBUM, true)
110115
photoFragment.arguments = bundle
111116

@@ -200,4 +205,11 @@ class AlbumsPickerActivity : FileActivity(), FileFragment.ContainerActivity, OnE
200205
override fun onRefresh() {
201206
// do nothing
202207
}
208+
209+
override fun onOptionsItemSelected(item: MenuItem): Boolean {
210+
when (item.itemId) {
211+
android.R.id.home -> super.onBackPressed()
212+
}
213+
return super.onOptionsItemSelected(item)
214+
}
203215
}

0 commit comments

Comments
 (0)