Skip to content
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

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
Draft

Photos new #14

wants to merge 12 commits into from

Conversation

Rembremmerdeng
Copy link
Contributor

No description provided.

@Rembremmerdeng Rembremmerdeng linked an issue May 24, 2020 that may be closed by this pull request
@Rembremmerdeng Rembremmerdeng removed a link to an issue May 24, 2020
@Rembremmerdeng Rembremmerdeng linked an issue May 24, 2020 that may be closed by this pull request

<uses-feature android:name="android.hardware.camera"
android:required="false" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

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

Copy link
Contributor Author

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 != "") {

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 {

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 {

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)

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

Copy link
Contributor

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")

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)!!

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 {

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

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 :)

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)

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(

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
Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to "photosStatusImage"

Copy link
Contributor

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
Copy link
Contributor

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
}
})

Copy link
Contributor

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 ->
Copy link
Contributor

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 ->
Copy link
Contributor

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())
Copy link
Contributor

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())
Copy link
Contributor

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 =
Copy link
Contributor

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 -> {
Copy link
Contributor

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())
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Photos Card
3 participants