Skip to content
This repository has been archived by the owner on May 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #43 from MarcDonald/fix/42-file-picker-crash
Browse files Browse the repository at this point in the history
Fix #42 File Picker Crash
  • Loading branch information
MarcDonald committed Aug 20, 2020
2 parents 6fc73fe + 9911a70 commit c701f26
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 17 deletions.
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -86,6 +86,11 @@ Used for selecting file to restore from

Apache 2 License

### [Android Image Picker](https://github.com/esafirm/android-image-picker)
Used for selecting images

[License](https://github.com/esafirm/android-image-picker/blob/master/LICENSE)

### [M PLUS Rounded 1c Bold](https://fonts.google.com/specimen/M+PLUS+Rounded+1c)
Used as the icon font

Expand Down
15 changes: 9 additions & 6 deletions app/build.gradle
Expand Up @@ -31,8 +31,8 @@ android {
minSdkVersion 23
//noinspection OldTargetApi
targetSdkVersion 28
versionCode 36
versionName "1.4.0"
versionCode 37
versionName "1.4.1"
setProperty("archivesBaseName", "Hibi-v$versionName")
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -59,8 +59,8 @@ dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.4'

// AndroidX
implementation 'androidx.appcompat:appcompat:1.3.0-alpha01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta8'
implementation 'androidx.appcompat:appcompat:1.3.0-alpha02'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-rc1'
implementation 'androidx.preference:preference:1.1.1'
implementation 'com.google.android.material:material:1.2.0'
// TODO Updating these anymore breaks non-LiveData Room queries
Expand Down Expand Up @@ -106,9 +106,12 @@ dependencies {
// Android-FilePicker
implementation 'com.droidninja:filepicker:2.2.4'

// Android Image Picker
implementation 'com.github.esafirm:android-image-picker:2.3.2'

// Glide for image loading and caching
implementation 'com.github.bumptech.glide:glide:4.9.0'
kapt 'com.github.bumptech.glide:compiler:4.9.0'
implementation 'com.github.bumptech.glide:glide:4.11.0'
kapt 'com.github.bumptech.glide:compiler:4.11.0'

// Simple License Display
implementation 'com.marcdonald:simplelicensedisplay:1.1.1'
Expand Down
Expand Up @@ -55,6 +55,9 @@ class OpenSourceLicencesFragment : Fragment() {
view.findViewById<SimpleLicenseDisplay>(R.id.license_android_file_picker)
.setOnClickListener(openURLClickListener("https://github.com/DroidNinja/Android-FilePicker"))

view.findViewById<SimpleLicenseDisplay>(R.id.license_android_image_picker)
.setOnClickListener(openURLClickListener("https://github.com/esafirm/android-image-picker"))

view.findViewById<SimpleLicenseDisplay>(R.id.license_mplus)
.setOnClickListener(openURLClickListener("https://fonts.google.com/specimen/M+PLUS+Rounded+1c"))

Expand Down
Expand Up @@ -81,5 +81,6 @@ class ImageRecyclerViewHolder(itemView: View,
.apply(RequestOptions().centerCrop())
.apply(RequestOptions().error(itemView.resources.getDrawable(R.drawable.ic_error_24dp, theme)))
.into(imageDisplay)
imageDisplay.imageTintList = null
}
}
Expand Up @@ -23,6 +23,7 @@ import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.net.Uri
import android.os.Bundle
import android.preference.PreferenceManager
import android.view.*
Expand All @@ -36,6 +37,8 @@ import androidx.lifecycle.Observer
import androidx.navigation.Navigation
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.esafirm.imagepicker.features.ImagePicker
import com.esafirm.imagepicker.features.ReturnMode
import com.google.android.material.button.MaterialButton
import com.marcdonald.hibi.R
import com.marcdonald.hibi.internal.*
Expand All @@ -53,6 +56,7 @@ import com.marcdonald.hibi.uicomponents.TimePickerDialog
import com.marcdonald.hibi.uicomponents.views.SearchBar
import droidninja.filepicker.FilePickerBuilder
import droidninja.filepicker.FilePickerConst
import timber.log.Timber

class AddEntryFragment : HibiFragment() {

Expand Down Expand Up @@ -439,11 +443,15 @@ class AddEntryFragment : HibiFragment() {
if(ContextCompat.checkSelfPermission(requireContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
askForStoragePermissions()
} else {
FilePickerBuilder.instance
.setActivityTheme(R.style.AppTheme)
.setActivityTitle(resources.getString(R.string.add_images))
.setSelectedFiles(arrayListOf())
.pickPhoto(this, CHOOSE_IMAGE_TO_ADD_REQUEST_CODE)
ImagePicker.create(this)
.includeVideo(false)
.includeAnimation(false)
.toolbarImageTitle(resources.getString(R.string.add_images))
.toolbarFolderTitle(resources.getString(R.string.add_images))
.showCamera(false)
.folderMode(true)
.theme(R.style.Hibi_ImagePicker)
.start()
}
}

Expand All @@ -454,9 +462,9 @@ class AddEntryFragment : HibiFragment() {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)

if(requestCode == CHOOSE_IMAGE_TO_ADD_REQUEST_CODE && resultCode == Activity.RESULT_OK && data != null) {
val photoPathArray = data.getStringArrayListExtra(FilePickerConst.KEY_SELECTED_MEDIA)
viewModel.addImages(photoPathArray)
if(ImagePicker.shouldHandle(requestCode, resultCode, data)) {
val images = ImagePicker.getImages(data)
viewModel.addImages(images)
}
}

Expand Down
Expand Up @@ -18,6 +18,7 @@ package com.marcdonald.hibi.screens.entries.addentry
import android.app.Application
import android.preference.PreferenceManager
import androidx.lifecycle.*
import com.esafirm.imagepicker.model.Image
import com.marcdonald.hibi.data.entity.Entry
import com.marcdonald.hibi.data.entity.EntryImage
import com.marcdonald.hibi.data.repository.*
Expand Down Expand Up @@ -206,10 +207,10 @@ class AddEntryViewModel(application: Application,
return ld
}

fun addImages(pathList: List<String>) {
fun addImages(imageList: List<Image>) {
viewModelScope.launch {
pathList.forEach { path ->
val file = File(path)
imageList.forEach { image ->
val file = File(image.path)
val entryImage = EntryImage(file.name, entryId)
entryImageRepository.addEntryImage(entryImage)
fileUtils.saveImage(file)
Expand Down
Expand Up @@ -44,5 +44,6 @@ class FullscreenImageFragment : HibiFragment() {
.apply(RequestOptions().fitCenter())
.apply(RequestOptions().error(resources.getDrawable(R.drawable.ic_error_24dp, requireActivity().theme)))
.into(imageView)
imageView.imageTintList = null
}
}
12 changes: 12 additions & 0 deletions app/src/main/res/layout/fragment_oss.xml
Expand Up @@ -96,6 +96,18 @@
app:sldLicense="@string/apache"
app:sldTitle="@string/android_file_picker" />

<com.marcdonald.simplelicensedisplay.SimpleLicenseDisplay
android:id="@+id/license_android_image_picker"
style="@style/Widget.Hibi.LicenseDisplay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_standard"
android:layout_marginEnd="@dimen/margin_standard"
android:layout_marginBottom="@dimen/margin_standard"
app:sldDescription="@string/android_image_picker_description"
app:sldLicense="@string/see_license"
app:sldTitle="@string/android_image_picker" />

<com.marcdonald.simplelicensedisplay.SimpleLicenseDisplay
android:id="@+id/license_mplus"
style="@style/Widget.Hibi.LicenseDisplay"
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Expand Up @@ -313,6 +313,7 @@
<string name="ofl">Open Font License</string>
<string name="sil">SIL Open Font License 1.1</string>
<string name="glide_license">BSD, part MIT and Apache 2.0. See the LICENSE file for details</string>
<string name="see_license">See License File for Details</string>

<string name="timber">Timber</string>
<string name="timber_description">Used for logging</string>
Expand All @@ -329,6 +330,9 @@
<string name="android_file_picker">Android File Picker</string>
<string name="android_file_picker_description">Used for selecting file to restore from</string>

<string name="android_image_picker">Android Image Picker</string>
<string name="android_image_picker_description">Used for selecting images</string>

<string name="mplus">M PLUS Rounded 1c Bold</string>
<string name="mplus_description">Used as the icon font</string>

Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/values/styles.xml
Expand Up @@ -53,6 +53,13 @@
<item name="android:tint">@color/iconTint</item>
</style>

<style name="Hibi.ImagePicker" parent="ef_BaseTheme">
<item name="colorPrimary">@color/colorToolbar</item>
<item name="colorPrimaryDark">@color/colorToolbar</item>
<item name="colorAccent">@color/colorSecondary</item>
<item name="android:colorBackground">@color/colorBackground</item>
</style>

<!--region Widgets-->
<style name="Widget.Hibi" parent="@android:style/Widget" />

Expand Down

0 comments on commit c701f26

Please sign in to comment.