Skip to content

Commit

Permalink
Merge pull request #31 from Samuel-Unknown/develop
Browse files Browse the repository at this point in the history
version 1.7.0
  • Loading branch information
Samuel-Unknown authored Dec 27, 2023
2 parents c9b16bd + 5ec3212 commit 0a98c2d
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 29 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ allprojects {
Add the following dependency in app build.gradle:
```
dependencies {
implementation 'io.github.samuel-unknown:gallery-image-picker:1.6.3'
implementation 'io.github.samuel-unknown:gallery-image-picker:1.7.0'
// if you want to use default Glide implementation for ImageLoaderFactory
implementation 'io.github.samuel-unknown:gallery-image-picker-glide:1.6.3'
implementation 'io.github.samuel-unknown:gallery-image-picker-glide:1.7.0'
// if you want to use default Coil implementation for ImageLoaderFactory
implementation 'io.github.samuel-unknown:gallery-image-picker-coil:1.6.3'
implementation 'io.github.samuel-unknown:gallery-image-picker-coil:1.7.0'
}
```

Expand Down Expand Up @@ -145,7 +145,7 @@ dependencies {
#### Version 1.6.*
- [x] New parameters for customization
#### Version 1.7.*
- [ ] Camera integration (preview and capture)
- [x] Popup menu customization

## License
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.samuelunknown.galleryImagePicker

object LibraryVersion {
private val major = 1 // change when you make incompatible API changes
private val minor = 6 // change when you add functionality in a backwards-compatible manner
private val build = 3 // change when you make backwards-compatible bug fixes
private val minor = 7 // change when you add functionality in a backwards-compatible manner
private val build = 0 // change when you make backwards-compatible bug fixes

val versionCode = major * 10000 + minor * 100 + build
val versionName = "${major}.${minor}.${build}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.samuelunknown.galleryImagePicker.extensions

import android.content.Intent
import android.os.Build
import com.samuelunknown.galleryImagePicker.domain.model.GalleryConfigurationDto
import com.samuelunknown.galleryImagePicker.domain.model.ImagesResultDto
import java.lang.Exception
Expand All @@ -9,18 +10,27 @@ private const val EXTRA_IMAGES_RESULT_DTO = "EXTRA_IMAGES_RESULT_DTO"
private const val EXTRA_CONFIGURATION_DTO = "EXTRA_CONFIGURATION_DTO"

internal fun Intent.getImagesResultDto(): ImagesResultDto? {
return this.getParcelableExtra(EXTRA_IMAGES_RESULT_DTO)
return this.getParcelableItem(EXTRA_IMAGES_RESULT_DTO)
}

internal fun Intent.putImagesResultDto(activityResultDto: ImagesResultDto): Intent {
return this.putExtra(EXTRA_IMAGES_RESULT_DTO, activityResultDto)
}

internal fun Intent.getGalleryConfigurationDto(): GalleryConfigurationDto {
return this.getParcelableExtra(EXTRA_CONFIGURATION_DTO)
return this.getParcelableItem(EXTRA_CONFIGURATION_DTO)
?: throw Exception("${GalleryConfigurationDto::class.java} not found.")
}

internal fun Intent.putGalleryConfigurationDto(activityResultDto: GalleryConfigurationDto): Intent {
return this.putExtra(EXTRA_CONFIGURATION_DTO, activityResultDto)
}
}

internal inline fun <reified T> Intent.getParcelableItem(key: String): T? {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
getParcelableExtra(key, T::class.java)
} else {
@Suppress("DEPRECATION")
getParcelableExtra(key)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import android.view.Menu
import android.view.View
import android.view.ViewGroup
import android.widget.PopupMenu
import androidx.appcompat.view.ContextThemeWrapper
import androidx.core.content.withStyledAttributes
import androidx.core.view.doOnLayout
import androidx.core.view.isVisible
import androidx.core.view.marginBottom
Expand Down Expand Up @@ -44,6 +46,7 @@ import com.samuelunknown.galleryImagePicker.presentation.ui.screen.gallery.fragm
import com.samuelunknown.galleryImagePicker.presentation.ui.screen.gallery.fragment.recycler.GridSpacingItemDecoration
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import com.samuelunknown.galleryImagePicker.R

internal class GalleryFragment private constructor(
private val configurationDto: GalleryConfigurationDto,
Expand Down Expand Up @@ -99,10 +102,6 @@ internal class GalleryFragment private constructor(
binding.pickupButton.marginBottom
}

private val popupMenu: PopupMenu by lazy(LazyThreadSafetyMode.NONE) {
PopupMenu(requireContext(), binding.toolbarTitle)
}

private val galleryAdapter: GalleryAdapter by lazy(LazyThreadSafetyMode.NONE) {
GalleryAdapter(
context = requireContext(),
Expand All @@ -117,6 +116,8 @@ internal class GalleryFragment private constructor(
)
}

private var popupMenu: PopupMenu? = null

private val vm: GalleryFragmentVm by savedStateViewModel {
val contentResolver = requireContext().contentResolver
GalleryFragmentVmFactory(
Expand All @@ -143,6 +144,7 @@ internal class GalleryFragment private constructor(
// NB: since vm must be initialized (for collecting actionFlow actions) before views send any actions
vm.run {
requireActivity().calculateScreenHeightWithoutSystemBars { height, width ->
initPopupMenu()
initRootView(screenHeight = height)
initBottomSheetDialog(screenHeight = height, screenWidth = width)
initToolbar()
Expand All @@ -159,6 +161,7 @@ internal class GalleryFragment private constructor(

override fun onDestroyView() {
super.onDestroyView()
popupMenu = null
binding.recycler.adapter = null
_binding = null
}
Expand Down Expand Up @@ -219,6 +222,18 @@ internal class GalleryFragment private constructor(
}
}

private fun initPopupMenu() {
requireContext().withStyledAttributes(configurationDto.themeResId, R.styleable.GalleryImagePickerAttributes) {
val popupMenuStyleResId = getResourceId(
R.styleable.GalleryImagePickerAttributes_gallery_image_picker__style_popup_menu,
R.style.GalleryImagePicker_Widget_PopupMenu
)

val contextWrapper = ContextThemeWrapper(requireContext(), popupMenuStyleResId)
popupMenu = PopupMenu(contextWrapper, binding.toolbarTitle)
}
}

private fun initToolbar() {
initActionBar(
toolbar = binding.toolbar,
Expand All @@ -228,7 +243,7 @@ internal class GalleryFragment private constructor(

binding.toolbarTitle.apply {
text = defaultToolbarTitle
setOnClickListener { popupMenu.show() }
setOnClickListener { popupMenu?.show() }
}

binding.toolbar.title = ""
Expand Down Expand Up @@ -319,13 +334,13 @@ internal class GalleryFragment private constructor(
.apply { add(0, FolderItem(id = "", name = defaultToolbarTitle)) }
.toList()

popupMenu.menu.clear()
popupMenu?.menu?.clear()

menuItems.forEachIndexed { index, item ->
popupMenu.menu.add(Menu.NONE, index, index, item.name)
popupMenu?.menu?.add(Menu.NONE, index, index, item.name)
}

popupMenu.setOnMenuItemClickListener {
popupMenu?.setOnMenuItemClickListener {
val selectedFolder = if (it.itemId == 0) null else menuItems[it.itemId]
vm.actionFlow.tryEmit(GalleryAction.GetImagesAction(selectedFolder))
true
Expand Down
2 changes: 1 addition & 1 deletion galleryImagePicker/src/main/res/values-night/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
<color name="gallery_image_picker__color_pickup_button">#FFFFFF</color>
<color name="gallery_image_picker__color_pickup_button_text">#000000</color>
<color name="gallery_image_picker__color_underlay">#66000000</color>
</resources>
</resources>
3 changes: 2 additions & 1 deletion galleryImagePicker/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
<item name="gallery_image_picker__theme_app_bar">@style/GalleryImagePicker.ThemeOverlay.AppBar</item>
<item name="gallery_image_picker__theme_bottom_sheet_dialog">@style/GalleryImagePicker.ThemeOverlay.BottomSheetDialog</item>
<item name="gallery_image_picker__style_toolbar">@style/GalleryImagePicker.Widget.Toolbar</item>
<item name="gallery_image_picker__style_popup_menu">@style/GalleryImagePicker.Widget.PopupMenu</item>
<item name="gallery_image_picker__style_button">@style/GalleryImagePicker.Widget.PickupButton</item>
<item name="gallery_image_picker__style_counter">@style/GalleryImagePicker.Widget.Counter</item>
<item name="gallery_image_picker__color_underlay">@color/gallery_image_picker__color_underlay</item>
<item name="gallery_image_picker__color_top_line">@color/gallery_image_picker__color_top_line</item>
</style>
</resources>
</resources>
3 changes: 2 additions & 1 deletion galleryImagePicker/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<attr name="gallery_image_picker__style_toolbar" format="reference" />
<attr name="gallery_image_picker__style_button" format="reference" />
<attr name="gallery_image_picker__style_counter" format="reference" />
<attr name="gallery_image_picker__style_popup_menu" format="reference" />
<attr name="gallery_image_picker__color_underlay" format="color|reference" />
<attr name="gallery_image_picker__color_top_line" format="color|reference" />
</declare-styleable>
</resources>
</resources>
2 changes: 1 addition & 1 deletion galleryImagePicker/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
<color name="gallery_image_picker__color_pickup_button">#1C1C1C</color>
<color name="gallery_image_picker__color_pickup_button_text">#FFFFFF</color>
<color name="gallery_image_picker__color_underlay">#B3FFFFFF</color>
</resources>
</resources>
5 changes: 3 additions & 2 deletions galleryImagePicker/src/main/res/values/style_widget.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<style name="GalleryImagePicker.Widget.Toolbar" parent="Widget.MaterialComponents.Toolbar.Primary">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">?attr/actionBarSize</item>
<item name="popupTheme">@style/GalleryImagePicker.ThemeOverlay.Popup</item>
<item name="titleTextColor">@color/gallery_image_picker__color_toolbar_text</item>
<item name="title">@string/gallery_image_picker__toolbar</item>
<item name="navigationIconTint">@color/gallery_image_picker__color_toolbar_icon</item>
Expand Down Expand Up @@ -45,4 +44,6 @@
<item name="autoSizeTextType">uniform</item>
<item name="autoSizeMinTextSize">8sp</item>
</style>
</resources>

<style name="GalleryImagePicker.Widget.PopupMenu" parent="Widget.MaterialComponents.PopupMenu" />
</resources>
4 changes: 1 addition & 3 deletions galleryImagePicker/src/main/res/values/theme_overlays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@
<item name="titleTextColor">@color/gallery_image_picker__color_toolbar_text</item>
<item name="titleTextAppearance">?attr/textAppearanceHeadline6</item>
</style>

<style name="GalleryImagePicker.ThemeOverlay.Popup" parent="ThemeOverlay.MaterialComponents.Light" />
</resources>
</resources>
3 changes: 2 additions & 1 deletion galleryImagePicker/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
<item name="gallery_image_picker__theme_app_bar">@style/GalleryImagePicker.ThemeOverlay.AppBar</item>
<item name="gallery_image_picker__theme_bottom_sheet_dialog">@style/GalleryImagePicker.ThemeOverlay.BottomSheetDialog</item>
<item name="gallery_image_picker__style_toolbar">@style/GalleryImagePicker.Widget.Toolbar</item>
<item name="gallery_image_picker__style_popup_menu">@style/GalleryImagePicker.Widget.PopupMenu</item>
<item name="gallery_image_picker__style_button">@style/GalleryImagePicker.Widget.PickupButton</item>
<item name="gallery_image_picker__style_counter">@style/GalleryImagePicker.Widget.Counter</item>
<item name="gallery_image_picker__color_underlay">@color/gallery_image_picker__color_underlay</item>
<item name="gallery_image_picker__color_top_line">@color/gallery_image_picker__color_top_line</item>
</style>
</resources>
</resources>
7 changes: 6 additions & 1 deletion sample/src/main/res/values/style_widget.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@
<item name="android:background">@drawable/bg_picker</item>
<item name="android:textColor">#000000</item>
</style>
</resources>

<style name="Widget.PopupMenu" parent="GalleryImagePicker.Widget.PopupMenu">
<item name="android:textColor">@color/color_accent_contrast</item>
<item name="android:itemBackground">@color/color_accent</item>
</style>
</resources>
3 changes: 2 additions & 1 deletion sample/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
<item name="gallery_image_picker__theme_app_bar">@style/ThemeOverlay.AppBar</item>
<item name="gallery_image_picker__theme_bottom_sheet_dialog">@style/ThemeOverlay.BottomSheetDialog</item>
<item name="gallery_image_picker__style_toolbar">@style/Widget.Toolbar</item>
<item name="gallery_image_picker__style_popup_menu">@style/Widget.PopupMenu</item>
<item name="gallery_image_picker__style_button">@style/Widget.PickupButton</item>
<item name="gallery_image_picker__style_counter">@style/Widget.Counter</item>
<item name="gallery_image_picker__color_underlay">@color/gallery_image_picker__color_underlay</item>
<item name="gallery_image_picker__color_top_line">@color/gallery_image_picker__color_top_line</item>
</style>
</resources>
</resources>

0 comments on commit 0a98c2d

Please # to comment.