-
Notifications
You must be signed in to change notification settings - Fork 527
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
Fixes part of #59: Translate binding adapter files to java [BLOCKED: #1514] #1568
Merged
+792
−633
Merged
Changes from 250 commits
Commits
Show all changes
284 commits
Select commit
Hold shift + click to select a range
6a9058a
Testing source files now build
miaboloix 12deabe
Test files are building
miaboloix a8fe758
Changed to java_lite
miaboloix 3295c12
Fixed merge conflicts
miaboloix 3f27b22
Added EOF newlines
miaboloix bb1b906
Each library now has its own build rule
miaboloix a1bd255
Merged with utility
miaboloix 3c6b257
Utility is now one module again
miaboloix 30a8ac2
Utility is now one rule
miaboloix a233e50
Merge branch 'stage1_bazel_utility' into stage1_bazel_testing
miaboloix 4df473d
Resolved merge conflicts
miaboloix ef3e857
Changed visibility for utility_lib
miaboloix d107b07
Added duplicate google-services.json file to please Gradle
miaboloix 560d2b9
Merge branch 'stage1_bazel_utility' of https://github.com/oppia/oppia…
miaboloix ae52338
Utility tests are building and passing (except in_memory_blocking_cac…
miaboloix 782cae9
Added android_local_test() rules for testing, building but not passing
miaboloix 1903609
Added a test manifest for testing module
miaboloix 67deaa7
Oppia_android_test is working
miaboloix af82414
Utility_test is now working
miaboloix 219ea6e
Testing_test.bzl is now working
miaboloix 8562a4d
changed all android_local_test rules to utility_test rules
miaboloix 5d6dd40
Named test rules correctly
miaboloix 3d21443
Added missing dependency, all tests now pass
miaboloix 761c0c5
Removed all unused dependencies
miaboloix d4d40c2
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
miaboloix 94213cd
Changed event_logger.proto to oppia_logger.proto
miaboloix 5aaf72f
Merge branch 'stage1_bazel' of https://github.com/oppia/oppia-android…
miaboloix b718dd1
Merge branch 'stage1_bazel_utility' of https://github.com/oppia/oppia…
miaboloix 6d8740d
Merge branch 'stage1_bazel_testing' of https://github.com/oppia/oppia…
miaboloix 24e8537
Added missing EOF newlines
miaboloix 7c1ddf8
Fixed visibility
miaboloix 33ff930
Initial BUILD file added
miaboloix 08ed2dc
Remove addressed TODOs
miaboloix 56227bf
Merge branch 'introduce-bazel-roboelectric-testing' of https://github…
miaboloix 9505de2
Started writing build rule
miaboloix e1ce0d1
Fixed bug in import statements for exploration.proto, topic.proto, an…
miaboloix 8f34cfe
Merge branch 'stage1_bazel' of https://github.com/oppia/oppia-android…
miaboloix 1999cf1
Merged with stage1_bazel_utility
miaboloix 23cd84a
Deleted DemoJava
miaboloix 788bcf3
Merge branch 'stage1_bazel_utility' of https://github.com/oppia/oppia…
miaboloix 1413ad1
Fixed merge conflicts
miaboloix 052f3cd
Domain source files build
miaboloix 2981277
Removed unused dependencies in domain_lib
miaboloix 17dc39a
Working on building domain test files
miaboloix 999b3f8
Added a test manifest
miaboloix 47d4e0c
Test files now build
miaboloix 89307b1
Added test rules, some tests not building or passing
miaboloix 25e9c73
Added data attribute to test macros
miaboloix 461d249
All tests now build, some do not pass
miaboloix 67fee18
CHanged rules_kotlin version
miaboloix 4865d01
All tests now pass
miaboloix ab9e295
Firebase dependency errors have been resolved
miaboloix c6bbbf4
Save firebase dependency fixes for new PR
miaboloix 5c1b4dd
Fixed typo
miaboloix 48eb9be
Added Firebase dependencies
miaboloix 31eb543
Merge branch 'stage1_bazel_utility' of https://github.com/oppia/oppia…
miaboloix c466d3c
Removed AsyncResultTest example
miaboloix a5e9039
Removed AsynchResultTest example
miaboloix 99d43f2
Merge branch 'stage1_bazel_utility' of https://github.com/oppia/oppia…
miaboloix 75c7774
Resolved merge conflicts
miaboloix b6240df
Firebase dependencies added
miaboloix 336237b
Resolve merge conflicts
miaboloix 8d6b28f
Removed unnecessary comments in WORKSPACE and moved rules_kotlin
miaboloix d712b5e
Added re-naming TODOs
miaboloix 3105144
Renamed java_proto rules java_proto_lite
miaboloix 2f50207
Added doc comments to model/BUILD.bazel and format_import_proto_library
miaboloix 323a0cb
Added comments to WORKSPACE file
miaboloix 7ce51a9
Merge branch 'stage1_bazel' of https://github.com/oppia/oppia-android…
miaboloix d87c95c
Fixed nits
miaboloix 20d2c5d
Added comment to kt_android_library() rule
miaboloix 9857eaf
Fixed more nits
miaboloix 1a35aad
Fixed merge conflicts
miaboloix 522993f
Added Firebase comment
miaboloix f5abd8e
Fixed merge conflicts
miaboloix dfa8e0b
Fixed merge conflicts and nits
miaboloix 9789204
Deleted unused dependencies from testing_main_lib
miaboloix 41d5ed1
Fixed merge conflicts
miaboloix ec75eda
Fixed nits and error with testing lib dependencies
miaboloix d8f54a7
Merge branch 'introduce-bazel-roboelectric-testing' of https://github…
miaboloix f9ac84f
Removed printStackTrace()
miaboloix a7c6a53
Removed addressed TODOs, all tests pass
miaboloix b618e18
Removed redundant public modifier
miaboloix 364435d
Changed library name to model
miaboloix 7e61655
Formatted WORKSPACE comment
miaboloix 9773e66
Formatted TODO statement
miaboloix 9fc0d53
Changed format_import_proto_library comment
miaboloix fdcb154
Added EOF newline
miaboloix 8185bdd
Created Issue and linked TODO in WORKSPACE
miaboloix 3d21d6f
Edited model BUILD file top comment
miaboloix 8e368b4
Addressed nits
miaboloix 29f19dd
Fixed merge conflicts
miaboloix af7832b
Fixed nits and added comments
miaboloix 8fb1541
Fixing nits
miaboloix 2b9d7c6
Deleted unnecessary dependencies and testing example file
miaboloix 980ca88
Fixed manifest issues
miaboloix a63ad7f
Move google json file
miaboloix fff3d89
Restore app version of json
miaboloix 54a7728
Merge branch 'test-git-copy' into stage1_bazel_utility
miaboloix c7cad13
Edit TODO
miaboloix 654328e
Deleted TODO
miaboloix a842aec
Changed Firebase comment
miaboloix 146f48a
Fixed merge conflicts
miaboloix 9360972
Added testing functionality from later PR
miaboloix 705d195
Added comments to bzl files
miaboloix 2b7be73
Added targetSDK to manifests
miaboloix 0621744
Changed crashlytics_lib to crashlytics
miaboloix 54ec7fb
Merge branch 'stage1_bazel_utility' of https://github.com/oppia/oppia…
miaboloix af931e9
Changed testing_tests visibility
miaboloix d5ae13c
Fixed merge conflicts
miaboloix 4f8e77f
Added comment to utility_test.bzl
miaboloix 0b9c14a
Changed type of comment ticks
miaboloix 0291f7a
Merge branch 'stage1_bazel_testing' of https://github.com/oppia/oppia…
miaboloix 17c92b3
Fixed typos and all tests pass
miaboloix fc7170f
Removed empty line
miaboloix acbd392
Fixed merge conflicts
miaboloix dc8ad13
Fixed errors from merge
miaboloix 53828c0
Added comments to data and domain BUILD files
miaboloix 578ef76
Fixed indentation in domain_test
miaboloix 65eaa1d
Removed commented-out dependencies
miaboloix 32ce87a
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
miaboloix 65f13c1
Fixed nits and added TODOs
miaboloix b6dd154
Merge branch 'stage1_bazel' of https://github.com/oppia/oppia-android…
miaboloix a4ec778
Merge branch 'stage1_bazel_utility' of https://github.com/oppia/oppia…
miaboloix f466e8f
Added Args to document comment
miaboloix 3638d43
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
miaboloix 58752b4
Changed targetSDK to 29
miaboloix 705355c
Merge branch 'stage1_bazel' of https://github.com/oppia/oppia-android…
miaboloix d152713
Formatted TODO
miaboloix fb515ec
Merge branch 'stage1_bazel_utility' of https://github.com/oppia/oppia…
miaboloix 11d84f4
Fixed merge conflicts
miaboloix e252feb
Fixed merge conflicts
miaboloix 01fd0c9
Added root BUILD file
miaboloix cc06b5a
Merge branch 'introduce-bazel-roboelectric-testing' of https://github…
miaboloix 74e4e52
Moved google-services.json
miaboloix 0c9d197
Added gogle-services.json back to app
miaboloix 72e0acd
Trying to remove combined testing library
miaboloix 0aa646d
Changed targetSDK to 29
miaboloix 7660d7d
Tests pass now with deps passed in.
miaboloix 8aa8c59
Created TEST_DEPS list to avoid duplicate list of dependencies
miaboloix d4f53c4
Removed unused resources and manifest
miaboloix a275d9c
Updated comments to reflect changes
miaboloix 56f0232
Merge branch 'stage1_bazel_testing' of https://github.com/oppia/oppia…
miaboloix b2b4e62
Changed deps to be a parameter, changed targetSDK back to 28 because …
miaboloix 7043491
Fixed indentation in utility/BUILD
miaboloix 7fa41db
Updated comment for utility_test.bzl
miaboloix 297cfa1
Updated comment for testing_test
miaboloix 51bcc06
Formatted dependencies and removed unused dependency
miaboloix ab8ea0b
Merge branch 'stage1_bazel_utility' of https://github.com/oppia/oppia…
miaboloix f906dd6
Merge branch 'stage1_bazel_testing' of https://github.com/oppia/oppia…
miaboloix fd4386f
Updated dependency list
miaboloix 0d1bd33
Merge branch 'stage1_bazel_utility' of https://github.com/oppia/oppia…
miaboloix 33d8e2a
Header for oppia_android_test now fits on one line
miaboloix 781fe7b
Merge branch 'stage1_bazel_testing' of https://github.com/oppia/oppia…
miaboloix 47e1592
Merge branch 'introduce-bazel-roboelectric-testing' of https://github…
miaboloix 02efdca
Simplifies comment on domain/BUILD file
miaboloix f02a1d7
Changed cache_store to persistent_cache_store
miaboloix b911cc2
Removed glob() from data BUILD file
miaboloix 1294d08
Edited documentation for oppia_android_test
miaboloix b0637dc
Updated documentation for utility and testing BUILD files
miaboloix 122f451
Changed src to srcs
miaboloix a019e5f
Merge branch 'stage1_bazel_testing' of https://github.com/oppia/oppia…
miaboloix c45f649
Changed src to srcs
miaboloix e236dac
Merge branch 'introduce-bazel-roboelectric-testing' of https://github…
miaboloix 02db08d
All dragAndDrop tests now pass, stateRetreiverTest fails
miaboloix 425049a
Created java files for binding adapters
miaboloix 28de63e
Translated DrawableDinsingAdapter
miaboloix e0b83f8
Traslated EditTextBindingAdapter
miaboloix c2a278f
Translated ImageViewBindingAdapters
miaboloix e3da795
Translated MarginBindingAdapters
miaboloix 6ed785b
Translated TextViewBindingAdapters
miaboloix b98fe78
Translated RecyclerViewBindingAdapter
miaboloix 84037cb
Deleted kotlin binding adapters
miaboloix ce92d0a
Translated GuidelineBindingAdapter
miaboloix 88c9492
Translated StateAssemblerMarginBindingAdapters
miaboloix d66af07
Translated StateAssemblerPaddingBindingAdapters
miaboloix fc51d3a
Almost finished translating ViewBindingAdapter
miaboloix 84e5051
Fixed the duplicate google-services.json issue
miaboloix 3c0932d
Created Issue and added TODO
miaboloix f1f7b1d
Translated ViewBindingAdapter
miaboloix b5b20f9
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
miaboloix 714ffa2
Merge branch 'stage1_bazel_utility' of https://github.com/oppia/oppia…
miaboloix 83747a1
Merge branch 'stage1_bazel_testing' of https://github.com/oppia/oppia…
miaboloix 62a2fa7
Added minSDK back
miaboloix 8eac40c
Alphabetized dependencies
miaboloix 48e4593
Merge branch 'stage1_bazel_testing' of https://github.com/oppia/oppia…
miaboloix 9578f27
Fixed firebase target
miaboloix 75aca29
Merge branch 'introduce-bazel-roboelectric-testing' of https://github…
miaboloix e72b6ef
Trying to fix StateRetreiverTest
miaboloix 3855305
Merge branch 'introduce-domain-bazel-build' of https://github.com/opp…
miaboloix 1a51990
Binding Adapter files are building with Gradle!
miaboloix dbb08ab
Fixed ktlint violation
miaboloix bc504b2
Merge branch 'introduce-domain-bazel-build' of https://github.com/opp…
miaboloix 3d1d42f
Revert "Deleted kotlin binding adapters"
miaboloix c6d34c7
Revert "Translated GuidelineBindingAdapter"
miaboloix 2dadc50
Revert "Translated StateAssemblerMarginBindingAdapters"
miaboloix b9e1283
Revert "Translated StateAssemblerPaddingBindingAdapters"
miaboloix 39d9bce
Git mv on DrawableBindingAdapters
miaboloix a3a852e
Translated DrawableBindingAdapters
miaboloix 8f16ca7
Deleted java files
miaboloix 5ba5d0f
Translated EditTextBA and GuidelineBA
miaboloix af81849
Translated ImageViewBA
miaboloix f5c4baa
Added missing semicolon
miaboloix 85e279c
Translated MarginBindingAdapters
miaboloix 7de67e3
Translated State AssemblerMarginBA
miaboloix 48ecefc
Translated StateAssemblerPaddingBA
miaboloix 849549d
Translated TextViewBA
miaboloix 6cfa75d
Revert "Translated TextViewBA"
miaboloix a1843d2
Changed targetSdk to 28
miaboloix 29a81df
Revert "Revert "Translated TextViewBA""
miaboloix 8c9f4b2
Fixed formatting issues and changed NotNull to NonNull
miaboloix 4a68e95
Refactored GuidelineBindingAdapter to be GuidelineBindingAdapters
miaboloix 0090709
Fixed some double space errors and other typos
miaboloix 5aa364f
Added missing ViewBindingAdapter
miaboloix 3be3193
Deleted extra spaces and fixed more nit issues
miaboloix 766d699
Made all classes final
miaboloix 96fbade
Added top level documentation
miaboloix 8881d0f
Reformatted some comments to fit java style
miaboloix 0f4ef4f
Reformatted imports
miaboloix 0cf3415
Merge branch 'develop' into stage1_bazel_utility
miaboloix 5f90f7b
Merge branch 'stage1_bazel_utility' of https://github.com/oppia/oppia…
miaboloix 44236da
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
miaboloix 00b9fb4
Merge branch 'stage1_bazel_testing' of https://github.com/oppia/oppia…
miaboloix c400b2c
Merge branch 'introduce-bazel-roboelectric-testing' of https://github…
miaboloix 7f5deea
Created Issue and added TODOs for re-restricitng access
miaboloix 2b1db0d
Added min and target SDK to domain manifest
miaboloix d0ba983
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
miaboloix ea31be3
Merge branch 'introduce-domain-bazel-build' of https://github.com/opp…
miaboloix 3129710
Added documentation comment
miaboloix 65e71cc
Deleted unused domain_tests library
miaboloix 67b467d
Revert "Deleted unused domain_tests library"
miaboloix 8c3d0f0
Removed unused domain)tests library
miaboloix 20aae5a
Merge branch 'introduce-domain-bazel-build' of https://github.com/opp…
miaboloix 84b6125
Formatted files and added missing @NonNull annotations
miaboloix b99d771
Revert "Formatted files and added missing @NonNull annotations"
miaboloix 2d81db0
Added documentation, created an issue, added a TODO
miaboloix 1d94b22
Merge branch 'introduce-domain-bazel-build' of https://github.com/opp…
miaboloix 55daaec
Formatted single line comments
miaboloix dfb244e
Fixing more nits
miaboloix bd4c9c5
Fixed more nits.
miaboloix e3f02a8
Fixed getTimeAgo() function
miaboloix 9558875
Suppressed warning in bindToRecyclerViewAdapter
miaboloix b16f979
Added assets
miaboloix 4e4aed7
Fixed nits in TextViewBA
miaboloix 9bd52af
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
miaboloix 78ffb0b
Testing module tests now pass, all domain tests pass except StateRetr…
miaboloix 16e1741
Merge branch 'introduce-domain-bazel-build' of https://github.com/opp…
miaboloix 26284cb
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
miaboloix 30ad075
Update app/src/main/java/org/oppia/app/databinding/TextViewBindingAda…
miaboloix 320e492
Made nit changes to TextViewBA
miaboloix 02fa684
Merge branch 'traslate-binding-adapters-to-java' of https://github.co…
miaboloix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
app/src/main/java/org/oppia/app/databinding/DrawableBindingAdapters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.oppia.app.databinding; | ||
|
||
import android.graphics.drawable.GradientDrawable; | ||
import android.view.View; | ||
import android.widget.Button; | ||
|
||
import androidx.annotation.ColorInt; | ||
import androidx.annotation.DrawableRes; | ||
import androidx.annotation.NonNull; | ||
import androidx.databinding.BindingAdapter; | ||
|
||
import org.oppia.app.R; | ||
|
||
/** | ||
* Holds all the custom binding adapters that set background drawables. | ||
BenHenning marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
public final class DrawableBindingAdapters { | ||
/** | ||
* Used to set a rounded-rect background drawable with a data-bound color. | ||
*/ | ||
@BindingAdapter("app:roundedRectDrawableWithColor") | ||
public static void setBackgroundDrawable(@NonNull View view, @ColorInt int colorRgb) { | ||
view.setBackgroundResource(R.drawable.rounded_rect_background); | ||
// The input color needs to have alpha channel prepended to it. | ||
GradientDrawable background = (GradientDrawable) view.getBackground(); | ||
background.setColor(0xff000000 | colorRgb); | ||
} | ||
|
||
@BindingAdapter("app:topRoundedRectDrawableWithColor") | ||
public static void setTopBackgroundDrawable(@NonNull View view, @ColorInt int colorRgb) { | ||
view.setBackgroundResource(R.drawable.top_rounded_rect_background); | ||
// The input color needs to have alpha channel prepended to it. | ||
GradientDrawable background = (GradientDrawable) view.getBackground(); | ||
background.setColor(0xff000000 | colorRgb); | ||
} | ||
|
||
@BindingAdapter("app:bottomRoundedRectDrawableWithColor") | ||
public static void setBottomBackgroundDrawable(@NonNull View view, @ColorInt int colorRgb) { | ||
view.setBackgroundResource(R.drawable.bottom_rounded_rect_background); | ||
// The input color needs to have alpha channel prepended to it. | ||
GradientDrawable background = (GradientDrawable) view.getBackground(); | ||
background.setColor(0xff000000 | colorRgb); | ||
} | ||
|
||
@BindingAdapter("app:rectangleDrawableWithColor") | ||
public static void setRectangleBackgroundDrawable(@NonNull View view, @ColorInt int colorRgb) { | ||
view.setBackgroundResource(R.drawable.rectangle_background); | ||
// The input color needs to have alpha channel prepended to it. | ||
GradientDrawable background = (GradientDrawable) view.getBackground(); | ||
background.setColor(0xff000000 | colorRgb); | ||
} | ||
|
||
@BindingAdapter("android:button") | ||
public static void setBackgroundResource(@NonNull Button button, @DrawableRes int resource) { | ||
button.setBackgroundResource(resource); | ||
} | ||
} |
43 changes: 0 additions & 43 deletions
43
app/src/main/java/org/oppia/app/databinding/DrawableBindingAdapters.kt
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
app/src/main/java/org/oppia/app/databinding/EditTextBindingAdapters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.oppia.app.databinding; | ||
|
||
import android.text.TextWatcher; | ||
import android.widget.EditText; | ||
|
||
BenHenning marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import androidx.annotation.NonNull; | ||
import androidx.databinding.BindingAdapter; | ||
|
||
/** | ||
* Holds all the custom binding adapters that bind to [EditText] adapters. | ||
BenHenning marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
public final class EditTextBindingAdapters { | ||
/** | ||
* Binding adapter for setting a [TextWatcher] as a change listener for an [EditText]. | ||
*/ | ||
@BindingAdapter("app:textChangedListener") | ||
public static void bindTextWatcher(@NonNull EditText editText, TextWatcher textWatcher) { | ||
editText.addTextChangedListener(textWatcher); | ||
} | ||
} |
11 changes: 0 additions & 11 deletions
11
app/src/main/java/org/oppia/app/databinding/EditTextBindingAdapters.kt
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
app/src/main/java/org/oppia/app/databinding/GuidelineBinding.kt
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
app/src/main/java/org/oppia/app/databinding/GuidelineBindingAdapters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.oppia.app.databinding; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.constraintlayout.widget.Guideline; | ||
import androidx.constraintlayout.widget.ConstraintLayout; | ||
anandwana001 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import androidx.databinding.BindingAdapter; | ||
|
||
/** | ||
* Holds all the custom binding adapters that bind to [Guideline]. | ||
*/ | ||
public final class GuidelineBindingAdapters { | ||
/** | ||
* Binding adapter for setting the `guidePercent` for a [Guideline]. | ||
*/ | ||
@BindingAdapter("app:layout_constraintGuide_percent") | ||
public static void setGuidelinePercentage(@NonNull Guideline guideline, float percentage) { | ||
ConstraintLayout.LayoutParams params = | ||
(ConstraintLayout.LayoutParams) guideline.getLayoutParams(); | ||
params.guidePercent = percentage; | ||
guideline.setLayoutParams(params); | ||
} | ||
} |
156 changes: 156 additions & 0 deletions
156
app/src/main/java/org/oppia/app/databinding/ImageViewBindingAdapters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
package org.oppia.app.databinding; | ||
|
||
import android.graphics.PorterDuff; | ||
import android.graphics.drawable.Drawable; | ||
import android.widget.ImageView; | ||
|
||
import androidx.annotation.DrawableRes; | ||
import androidx.annotation.NonNull; | ||
import androidx.databinding.BindingAdapter; | ||
|
||
import com.bumptech.glide.Glide; | ||
import com.bumptech.glide.load.DataSource; | ||
import com.bumptech.glide.load.engine.GlideException; | ||
import com.bumptech.glide.request.RequestListener; | ||
import com.bumptech.glide.request.RequestOptions; | ||
import com.bumptech.glide.request.target.Target; | ||
|
||
import org.oppia.app.R; | ||
import org.oppia.app.model.LessonThumbnailGraphic; | ||
import org.oppia.app.model.ProfileAvatar; | ||
|
||
/** | ||
* Holds all the custom binding adapters that bind to [ImageView] adapters. | ||
*/ | ||
public final class ImageViewBindingAdapters { | ||
/** | ||
* Allows binding drawables to an [ImageView] via "android:src". | ||
* Source: https://stackoverflow.com/a/35809319/3689782. | ||
BenHenning marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
@BindingAdapter("android:src") | ||
public static void setImageDrawable(@NonNull ImageView imageView, String imageUrl) { | ||
RequestOptions requestOptions = new RequestOptions().placeholder(R.drawable.review_placeholder); | ||
Glide.with(imageView.getContext()) | ||
.load(imageUrl) | ||
.apply(requestOptions) | ||
.into(imageView); | ||
} | ||
|
||
/** | ||
* Allows binding drawables to an [ImageView] via "android:src". | ||
* Source: https://stackoverflow.com/a/35809319/3689782. | ||
*/ | ||
@BindingAdapter("android:src") | ||
public static void setImageDrawable( | ||
@NonNull ImageView imageView, | ||
@DrawableRes int drawableResourceId | ||
) { | ||
imageView.setImageResource(drawableResourceId); | ||
} | ||
|
||
/** | ||
* Binds the specified [LessonThumbnailGraphic] as the source for the [ImageView]. | ||
* The view should be specified to have no width/height (when sized in a constraint layout), and | ||
BenHenning marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* use centerCrop for the image to appear correctly. | ||
*/ | ||
@BindingAdapter("android:src") | ||
public static void setImageDrawable( | ||
ImageView imageView, | ||
LessonThumbnailGraphic thumbnailGraphic | ||
) { | ||
int drawableResourceId; | ||
switch (thumbnailGraphic) { | ||
case BAKER: | ||
drawableResourceId = R.drawable.lesson_thumbnail_graphic_baker; | ||
case CHILD_WITH_BOOK: | ||
drawableResourceId = R.drawable.lesson_thumbnail_graphic_child_with_book; | ||
case CHILD_WITH_CUPCAKES: | ||
drawableResourceId = R.drawable.lesson_thumbnail_graphic_child_with_cupcakes; | ||
case CHILD_WITH_FRACTIONS_HOMEWORK: | ||
drawableResourceId = R.drawable.lesson_thumbnail_graphic_child_with_fractions_homework; | ||
case DUCK_AND_CHICKEN: | ||
drawableResourceId = R.drawable.lesson_thumbnail_graphic_duck_and_chicken; | ||
case PERSON_WITH_PIE_CHART: | ||
drawableResourceId = R.drawable.lesson_thumbnail_graphic_person_with_pie_chart; | ||
case IDENTIFYING_THE_PARTS_OF_A_FRACTION: | ||
drawableResourceId = R.drawable.topic_fractions_01; | ||
case WRITING_FRACTIONS: | ||
drawableResourceId = R.drawable.topic_fractions_02; | ||
case EQUIVALENT_FRACTIONS: | ||
drawableResourceId = R.drawable.topic_fractions_03; | ||
case MIXED_NUMBERS_AND_IMPROPER_FRACTIONS: | ||
drawableResourceId = R.drawable.topic_fractions_04; | ||
case COMPARING_FRACTIONS: | ||
drawableResourceId = R.drawable.topic_fractions_05; | ||
case ADDING_AND_SUBTRACTING_FRACTIONS: | ||
drawableResourceId = R.drawable.topic_fractions_06; | ||
case MULTIPLYING_FRACTIONS: | ||
drawableResourceId = R.drawable.topic_fractions_07; | ||
case DIVIDING_FRACTIONS: | ||
drawableResourceId = R.drawable.topic_fractions_08; | ||
case DERIVE_A_RATIO: | ||
drawableResourceId = R.drawable.topic_ratios_01; | ||
case WHAT_IS_A_FRACTION: | ||
drawableResourceId = R.drawable.topic_fractions_01; | ||
case FRACTION_OF_A_GROUP: | ||
drawableResourceId = R.drawable.topic_fractions_02; | ||
case ADDING_FRACTIONS: | ||
drawableResourceId = R.drawable.topic_fractions_03; | ||
case MIXED_NUMBERS: | ||
drawableResourceId = R.drawable.topic_fractions_04; | ||
default: | ||
drawableResourceId = R.drawable.topic_fractions_01; | ||
} | ||
setImageDrawable( | ||
imageView, | ||
drawableResourceId | ||
); | ||
} | ||
|
||
/** | ||
* Binding adapter for profile images. Used to either display a local image or custom | ||
* colored avatar. | ||
* | ||
* @param imageView View where the profile avatar will be loaded into. | ||
* @param profileAvatar Represents either a colorId or local image uri. | ||
*/ | ||
BenHenning marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@BindingAdapter("profile:src") | ||
public static void setProfileImage(ImageView imageView, ProfileAvatar profileAvatar) { | ||
if (profileAvatar != null) { | ||
if (profileAvatar.getAvatarTypeCase() == ProfileAvatar.AvatarTypeCase.AVATAR_COLOR_RGB) { | ||
Glide.with(imageView.getContext()) | ||
.load(R.drawable.ic_default_avatar) | ||
.listener(new RequestListener<Drawable>() { | ||
@Override | ||
public boolean onLoadFailed( | ||
GlideException e, | ||
Object model, | ||
Target<Drawable> target, | ||
boolean isFirstResource) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean onResourceReady( | ||
Drawable resource, | ||
Object model, | ||
Target<Drawable> target, | ||
DataSource dataSource, | ||
boolean isFirstResource | ||
) { | ||
imageView.setColorFilter( | ||
profileAvatar.getAvatarColorRgb(), | ||
PorterDuff.Mode.DST_OVER | ||
); | ||
return false; | ||
} | ||
}).into(imageView); | ||
} else { | ||
Glide.with(imageView.getContext()) | ||
.load(profileAvatar.getAvatarImageUri()) | ||
.placeholder(R.drawable.ic_default_avatar) | ||
.into(imageView); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If we do reformat java files, can we update the code style for Java?
Specifically import part as currently, we have an empty line separator there which will look like this after reformat.
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.
Just went ahead and reformatted all of the files. What do you mean by 'update the code style for Java'? Do you mean update the Wiki? :)
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.
With code style, I mean specific conventions for files like Java, Kotlin, XML and many more and specifying conventions for tabs and indents, spaces, wrapping and braces, and blank lines.
You can check in Android Studio -> File > Settings > Editor > Code Style (Android Studio > Preferences > Editor > Code Style on a Mac.)
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.
Ah I see. So, I am guessing we don't want the empty lines, right? I just edited the code style in my Android Studio to remove the empty lines.
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.
We should follow https://google.github.io/styleguide/javaguide.html for Java style.