-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Photos new #14
base: master
Are you sure you want to change the base?
Photos new #14
Conversation
… button behaviour in order to behave correctly if take photo button is not available
…ertyChanged is needed since only a resetting of the collection would be notififed automatically by PropertyAwareLiveData, adding an item does not invoke this
…ng in Android.Q and above
…oRecycler locally
…ms, fix creation of thumbnails for new versions of Android
…ew picture temporarily and save it when the permission has been granted
|
||
<uses-feature android:name="android.hardware.camera" | ||
android:required="false" /> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Müssen wir wirklich im externen storage speichern? Können wir das nicht app-intern tun? Note: Bisher hab ich noch nie Fotos aufgenommen innerhalb einer App, hab da also keine Erfahrung :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was debating about this as well. I came to the conclusion that in some cases it might be useful to have to photos taken with the app also on external storage. For example you can't finish the transmission (due to network connection) and you want to do it with weg-li website mass-upload later.
setupCarTypeSpinner() | ||
setupViolationSpinner() | ||
durationText.setOnClickListener { | ||
} | ||
|
||
sendButton.setOnClickListener { mainViewModel.sendReport() } | ||
|
||
val licenseObserver = Observer<Report> { newName -> | ||
if(newName.license != "") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please reformat the file (use Android Studio's builtin way to do that). Also, you can use isEmpty
or isNotEmpty
here.
mainViewModel.propertyAwareReport.observe(this, photosCountObserver) | ||
} | ||
|
||
fun convertPixelsToDp(px: Float, context: Context): Float { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this out into an utils class or an extension class. Should not be declared in an activity.
.displayMetrics.densityDpi.toFloat() / DisplayMetrics.DENSITY_DEFAULT) | ||
} | ||
|
||
private fun Float.convertDpToPixel(context: Context): Float { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
|
||
|
||
private fun setupPhotoRecyclerView(context: Context) { | ||
val recyclerView = findViewById<RecyclerView>(R.id.photos_grid) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please either use kotlin synthetics or the new View Binding (which afaik is now the recommended way to do this), see https://medium.com/androiddevelopers/use-view-binding-to-replace-findviewbyid-c83942471fc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just use "photos_grid" (should be renamed to "photosRecyclerView"), kotlin will do the rest.
val resolver: ContentResolver = contentResolver | ||
val contentValues = ContentValues().apply { | ||
put(MediaStore.MediaColumns.DISPLAY_NAME, image_name) | ||
put(MediaStore.MediaColumns.MIME_TYPE, "image/jpeg") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please look up whether there is a constant for this MIME type and use it if possible.
} | ||
} | ||
val imageUri: Uri = | ||
resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues)!! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid all the !!
here.
private val mInflater: LayoutInflater = LayoutInflater.from(context) | ||
private var mClickListener: ItemClickListener? = null | ||
var deletePhotoSet: ObservableArrayList<Int> = ObservableArrayList() | ||
/*init { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please clear this up
) | ||
}*/ | ||
|
||
@NonNull |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nullable annotations are not needed on Kotlin-only code :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would also not be needed if we had both java + kotlin code. This is only useful to add on Java code.
|
||
} | ||
*/ | ||
@Throws(FileNotFoundException::class, IOException::class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use checked exceptions like this on Kotlin code.
val thumbnailSize = 120f.convertDpToPixel(context).toInt() | ||
val thumbnail: Bitmap? = | ||
uri?.let { | ||
context.contentResolver.loadThumbnail( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an API29 method, but our min sdk level is 19 or 21. It will always crash. Android Studio should also give you an error for this.
private lateinit var mainViewModel: MainViewModel | ||
private val pickImage = 1 | ||
private val takeImage = 2 | ||
private var mActionMode: ActionMode? = null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please let's not use the Hungarian notation, Android Studio tells us the type. Please change "mActionMode" to "actionMode"
|
||
val licenseObserver = Observer<Report> { newName -> | ||
if(newName.license != "") { | ||
status_image.setImageResource(R.drawable.ic_baseline_check_circle_24) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Kotlin it's better to name it "statusImage" instead of "status_image", since we're using these names just like here in code.
|
||
val pm: PackageManager = context.packageManager | ||
if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) { | ||
take_picture_button.visibility = View.GONE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to "takePictureButton"
|
||
val photosCountObserver = Observer<Report> { newName -> | ||
if(newName.violationPhotos.size >= 2) { | ||
photos_status_image.setImageResource(R.drawable.ic_baseline_check_circle_24) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to "photosStatusImage"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can import "R.drawable", this will shorten every use of drawables
override fun onGlobalLayout() { | ||
recyclerView.viewTreeObserver.removeOnGlobalLayoutListener(this) | ||
//layoutManager.setColumnWidth(convertPixelsToDp(recyclerView.width.toFloat(), context).toInt()) | ||
Timber.e(convertPixelsToDp(recyclerView.width.toFloat(), context).toString()) //height is ready |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you use this to debug? Should be removed, once this part is done.
Timber.e(convertPixelsToDp(recyclerView.width.toFloat(), context).toString()) //height is ready | ||
} | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove extra empty lines
photoAdapter.setClickListener(this) | ||
recyclerView.adapter = photoAdapter | ||
|
||
take_picture_button.setOnTouchListener { v, event -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to "takePictureButton"
false | ||
} | ||
|
||
add_picture_button.setOnTouchListener { v, event -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to addPictureButton
} | ||
|
||
override fun onItemLongClick(view: View?, position: Int) { | ||
Timber.e("You looong clicked number %s", position.toString()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you use this for debugging? Should be removed, once feature is done.
|
||
override fun onItemClick(view: View?, position: Int) { | ||
if(mActionMode != null) { | ||
Timber.e("You clicked number %s", position.toString()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you use this for debugging? Should be removed, once feature is done.
photoAdapter.notifyItemChanged(position) | ||
} | ||
|
||
private val mActionModeCallback: ActionMode.Callback = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use Hungarian notation, rename to "actionModeCallback"
item: MenuItem | ||
): Boolean { | ||
return when (item.itemId) { | ||
R.id.delete_button -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to "deleteButton"
): Boolean { | ||
return when (item.itemId) { | ||
R.id.delete_button -> { | ||
Timber.e("I'm here. Option1 selected, i will remove "+photoAdapter.deletePhotoSet.sorted().toString()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used for debugging? Remove once feature is done
No description provided.