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

Implemented Drawing Activity #9394

Merged
merged 4 commits into from Aug 25, 2021
Merged

Conversation

Akshay0701
Copy link
Member

@Akshay0701 Akshay0701 commented Aug 10, 2021

Pull Request template

Fixes

Fixes #9363

Done

  • created drawing activity
  • extracted createInstance in a method of whiteboard
  • change WeakReference to AnkiActivity in whiteboard to let other activities use whiteboard view.
  • added drawing button in BasicImageFieldController

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration (SDK version(s), emulator or physical, etc)

Learning (optional, can help others)

Describe the research stage

Links to blog posts, patterns, libraries or addons used to solve this problem

Checklist

Please, go through these checks before submitting the PR.

  • You have not changed whitespace unnecessarily (it makes diffs hard to read)
  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • Your code follows the style of the project (e.g. never omit braces in if statements)
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

@Akshay0701
Copy link
Member Author

Akshay0701 commented Aug 10, 2021

I think commits should split,
could please you suggest me order for small commits?

commit 1: created drawing activity
commit 2: extracted createInstance in a method of whiteboard
commit 3: change WeakReference to AnkiActivity in whiteboard to let other activities use whiteboard view.
commit 4: added drawing button in BasicImageFieldController

will this okay?

@Akshay0701 Akshay0701 mentioned this pull request Aug 10, 2021
14 tasks
@david-allison
Copy link
Member

I think these are good (only changed the order)

  1. extracted createInstance in a method of whiteboard
  2. change WeakReference to AnkiActivity in whiteboard to let other activities use whiteboard view.
  3. created drawing activity
  4. added drawing button in BasicImageFieldController

@Akshay0701 Akshay0701 force-pushed the drawing_activity branch 5 times, most recently from 218b03e to c94a5f1 Compare August 12, 2021 18:03
Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

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

This looks great! One comment regarding the cast to AbstractFlashcardViewer, the rest are nitpicks

Blocked by #9409

resultData.putExtra(EXTRA_RESULT_WHITEBOARD, savedWhiteboardFileName)
setResult(RESULT_OK, resultData)
} catch (e: FileNotFoundException) {
Timber.e(e)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Timber.e(e)
Timber.w(e)

AnkiDroid/src/main/java/com/ichi2/anki/Whiteboard.java Outdated Show resolved Hide resolved

private void handleDrawingResult(Uri imageUri) {
if (imageUri == null) {
Timber.e("handleDrawingResult() no image path provided");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Timber.e("handleDrawingResult() no image path provided");
Timber.w("handleDrawingResult() no image path provided");


Timber.i("handleDrawingResult() Decoded image: '%s'", drewImagePath);
} catch (IOException e) {
Timber.e("");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Timber.e("");
Timber.w(e);

@@ -22,6 +22,7 @@
-->
<!-- App name -->
<string name="app_name" comment="The name of the app">AnkiDroid</string>
<string name="drawing">Drawing</string>
Copy link
Member

Choose a reason for hiding this comment

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

Let's move this to 01-core

@david-allison david-allison added Blocked by dependency Currently blocked by some other dependent / related change Needs Author Reply Waiting for a reply from the original author labels Aug 17, 2021
Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

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

Much nicer!

AnkiDroid/src/main/java/com/ichi2/anki/Whiteboard.java Outdated Show resolved Hide resolved

package com.ichi2.anki;

public interface WhiteboardMethods {
Copy link
Member

Choose a reason for hiding this comment

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

Could do with a better name and javadocs, but this is exactly what we need code-wise

Copy link
Member Author

Choose a reason for hiding this comment

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

/**
 * WhiteboardMethods interface will provide abstract methods to override by abstractflascardviewer class
 * for handling multi touch while whiteboard is on.
 */
public interface WhiteboardMultiTouchMethods {

see this, is this doc correct?

it would be great if you could suggest me some names...

Copy link
Member

Choose a reason for hiding this comment

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

Sounds great!

Slight change to the documentation. You want to try to avoid referencing a concrete implementation for an interface (although it's often useful to provide an example).

/**
 * Provides callbacks for multi touch handling on a whiteboard
 */
public interface WhiteboardMultiTouchMethods {

AnkiDroid/src/main/java/com/ichi2/anki/Whiteboard.java Outdated Show resolved Hide resolved
@david-allison david-allison removed the Blocked by dependency Currently blocked by some other dependent / related change label Aug 18, 2021
@david-allison
Copy link
Member

unblocked, awaiting de-conflict

@Akshay0701
Copy link
Member Author

sorry, I didn't get much time last week, but now I am free so let's get this done...

@david-allison david-allison self-assigned this Aug 20, 2021
@david-allison david-allison added Needs Review and removed Needs Author Reply Waiting for a reply from the original author labels Aug 20, 2021
@Akshay0701 Akshay0701 force-pushed the drawing_activity branch 2 times, most recently from 52c2f0d to c8c9da8 Compare August 20, 2021 18:48
Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

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

Two very minor things, but LGTM!


package com.ichi2.anki;

public interface WhiteboardMethods {
Copy link
Member

Choose a reason for hiding this comment

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

Sounds great!

Slight change to the documentation. You want to try to avoid referencing a concrete implementation for an interface (although it's often useful to provide an example).

/**
 * Provides callbacks for multi touch handling on a whiteboard
 */
public interface WhiteboardMultiTouchMethods {

AnkiDroid/src/main/res/menu/drawing_menu.xml Outdated Show resolved Hide resolved
@david-allison david-allison removed their assignment Aug 21, 2021
@Akshay0701
Copy link
Member Author

Akshay0701 commented Aug 22, 2021

@mikehardy what do you say,

do we have a userbase of API 21 or below?

should we rescale the image before saving it(in API 21 or below)?

@mikehardy
Copy link
Member

Yes, minsdkversion is still 21, won't move for a while, the whole android ecosystem just moved up to it in fact. Probably a year or more before it goes higher. Still tens of thousands of users

Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

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

Discussed with @Akshay0701, moving the issue of the image size to #9439

Could we find out which API version this issue is resolved with, and limit the feature to API versions that are working correctly (likely via @Requires() with a comment, and make the button gone if it's not available).

Note that since we haven't diagnosed the issue, it may be screen size related, in which case we should get it fixed before getting this feature in.

@Akshay0701 Akshay0701 force-pushed the drawing_activity branch 2 times, most recently from cb61578 to 27c7043 Compare August 23, 2021 11:52
@Akshay0701
Copy link
Member Author

Akshay0701 commented Aug 23, 2021

Note that since we haven't diagnosed the issue, it may be screen size related, in which case we should get it fixed before getting this feature in.

David, I am sure this issue is not related to screen size, because
I tried pixel 1(1080 x 1920: 420 dpi) with API version 21,22,23 and this issue occurred at all times.
and I tried again with the same devices pixel 1 with API version 24 and the issue didn't occur there.

@david-allison
Copy link
Member

Could you add a comment on the API restriction listing the issue number, then good to go!

@Akshay0701
Copy link
Member Author

i think i already did comment with issue number

Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

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

Ah, was missed in the GitHub preview. LGTM!

@david-allison david-allison added Needs Second Approval Has one approval, one more approval to merge and removed Needs Author Reply Waiting for a reply from the original author labels Aug 24, 2021
Comment on lines 480 to 481
public String getPathFromUri(Uri uri) throws IOException {
String filename = ContentResolverUtil.getFileName(mActivity.getContentResolver(), uri);
InputStream fd = mActivity.getContentResolver().openInputStream(uri);
Map.Entry<String, String> fileNameAndExtension = FileUtil.getFileNameAndExtension(filename);
filename = fileNameAndExtension.getKey();
File clipCopy = File.createTempFile(filename, fileNameAndExtension.getValue());
CompatHelper.getCompat().copyFile(fd, clipCopy.getAbsolutePath());
return clipCopy.getAbsolutePath();
}
Copy link
Member

Choose a reason for hiding this comment

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

This to me is return internalizeUri(uri).getAbsolutePath(), which is defined just below this method
In fact, there is a proliferation of methods like this:

  • MediaRegistration::loadImageIntoCollection does it
  • FileUtil::internalizeUri does it

Why are we duplicating the process of "take a URI, copy the contents of it into our local area and give me a file" in so many places? 🤔

I may be missing something, but I would love for this logic to be in one spot

Copy link
Member Author

Choose a reason for hiding this comment

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

Great review, Thank you for letting me know about the internalizeUri method, I was unaware of this method,
Done now.

Copy link
Member

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

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

I like this a lot - it appears to me that all the things required for it to actually work, are working. Which is awesome. My only concern is that I've seen this URI-->File logic in so many places and it looks like this is adding another? Can we avoid it at all?

@mikehardy mikehardy added the Needs Author Reply Waiting for a reply from the original author label Aug 24, 2021
@Akshay0701 Akshay0701 force-pushed the drawing_activity branch 3 times, most recently from 1adb1c1 to 177fe70 Compare August 25, 2021 12:06
Copy link
Member

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

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

Nice! thanks for the shift to internalizeUri

@mikehardy mikehardy removed Needs Author Reply Waiting for a reply from the original author Needs Second Approval Has one approval, one more approval to merge labels Aug 25, 2021
@mikehardy mikehardy added this to the 2.16 release milestone Aug 25, 2021
@mikehardy mikehardy merged commit 4587fed into ankidroid:master Aug 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add built-in canvas🎨
4 participants