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

[In-app updates] Analytics tracking fix #20935

Closed
wants to merge 121 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
a21ddae
Remove unnecessary logs from domain screen in the site creation flow
irfano Oct 24, 2023
d766d21
Add null check
aditi-bhatia May 18, 2024
fb5fa51
Gutenberg - Add onVoiceToContent
May 20, 2024
d3a8bf0
GutenbergEditorFragment - Call onVoiceToContent with test content
May 20, 2024
e0145b4
Update Gutenberg ref
May 20, 2024
f6a9534
Set targetSdk to 34.
notandyvee May 20, 2024
c7f5bce
Add NotNull annotations to ReaderActivityLauncher.java
aditi-bhatia May 22, 2024
9c1aabf
Call onPublishingPost() function for only the first publishing
irfano May 21, 2024
3f4b66f
Reset in-app reviews flow when positive button of rate dialog tapped
irfano May 21, 2024
e179b3f
Reset the in-app reviews counter when the rating dialog is shown
irfano May 21, 2024
d4c03f5
Don't show the in-app reviews prompt if the rating dialog is denied
irfano May 23, 2024
39c5359
Wait to show in-app reviews prompt if ask later is tapped
irfano May 23, 2024
1357c39
Reset counter and wait for 7 days after in-app review prompt is shown
irfano May 23, 2024
3329d74
[Bug] Remove flow and use callbacks instead. I know, pain.
notandyvee May 23, 2024
cb616f0
Add null checks to calling functions
aditi-bhatia May 23, 2024
b4ccda9
Merge branch 'trunk' into andy/target-sdk-34
notandyvee May 24, 2024
1522d33
Undo uneccessary lib change.
notandyvee May 24, 2024
50800dd
Update FluxC hash
zwarm May 24, 2024
ad7a4aa
Add the jetpack ai query call to the voice-to-content workflow
zwarm May 24, 2024
27b1e31
Capture the custom jetpack_ai_error from within the success response …
zwarm May 24, 2024
32484c4
Checkstyle
aditi-bhatia May 24, 2024
e73390a
Update to NonNull
aditi-bhatia May 24, 2024
01cf519
Merge branch 'trunk' into andy/target-sdk-34
notandyvee May 24, 2024
12bdeb5
Address checkstyle blank line
zwarm May 25, 2024
40d396f
Refactor: Drop the AI suffix from the actionType
zwarm May 25, 2024
b91211f
Update import statement to reflect JetpackAIQuery location move
zwarm May 26, 2024
12ac21b
Adjust import statements for response objects
zwarm May 26, 2024
f98105b
Update FluxC hash
zwarm May 26, 2024
662de3e
Add call to get ai assistant feature
zwarm May 26, 2024
bdde56d
Fix checkstyle empty line
zwarm May 26, 2024
c3ca799
update FluxC hash
zwarm May 26, 2024
d8768ac
Adds: RECORD_AUDIO permission
pantstamp May 27, 2024
887a7a9
Adds: AudioRecorder basic implementation
pantstamp May 27, 2024
ba982f2
Merge pull request #20887 from wordpress-mobile/merge/25.0-code-freez…
oguzkocer May 27, 2024
01c949a
Remove ReviewViewModel.kt
irfano May 27, 2024
5ab588a
Update resetPublishedPostCount() method
irfano May 27, 2024
982e79e
Track notification count for in-app reviews prompt logic
irfano May 27, 2024
c66623b
Rename AppRatingDialog to AppReviewManager
irfano May 27, 2024
0ac9699
Move `launchInAppReviews()`` functions inside AppReviewManager
irfano May 27, 2024
a796b5a
Add debug logs to `AppReviewManager`
irfano May 28, 2024
a83acfe
Update tests for the new `AppReviewsManager`
irfano May 28, 2024
38c58bc
Update FluxC version
pantstamp May 28, 2024
5eb2a46
Merge branch 'trunk' into issue/v2c-support-jetpack-ai-query
pantstamp May 28, 2024
c4d1cf6
Merge pull request #20878 from wordpress-mobile/issue/v2c-support-jet…
pantstamp May 28, 2024
3eabbe0
Merge branch 'trunk' into issue/v2c-support-jetpack-ai-assistant-feature
pantstamp May 28, 2024
8bcd84b
Update FluxC version
pantstamp May 28, 2024
291bf87
Merge branch 'trunk' into issue/20820-update-inapp-reviews-flow
irfano May 28, 2024
50f812e
Fix VoiceToContentViewModelTest
pantstamp May 28, 2024
4085bf7
Merge pull request #20885 from wordpress-mobile/issue/v2c-support-jet…
pantstamp May 28, 2024
c0f162f
Merge branch 'trunk' into issue/89-basic-media-recorder
pantstamp May 28, 2024
0fac4f8
Fix merge conflicts
pantstamp May 28, 2024
e01f455
Refactors: AudioRecorder
pantstamp May 28, 2024
b446a51
Fixes: temporary VoiceToContentViewModelTest
pantstamp May 28, 2024
91575ae
Fixes: minor AudioRecorder changes
pantstamp May 28, 2024
f56201e
Modify AudioRecorder max duration
pantstamp May 28, 2024
8a6c943
Add eligibility and limit checks
zwarm May 28, 2024
83d9c79
Add tests for eligibility and limit checks
zwarm May 28, 2024
aecf606
Refactor to address detekt ReturnCount
zwarm May 28, 2024
f100c30
Update naming
aditi-bhatia May 28, 2024
c79a3fc
Add annotation back
aditi-bhatia May 28, 2024
915584c
Detekt
aditi-bhatia May 29, 2024
9c10733
Merge pull request #20848 from wordpress-mobile/issue/20847-crash
aditi-bhatia May 29, 2024
026dd70
Merge pull request #20901 from wordpress-mobile/release/25.0
oguzkocer May 29, 2024
b801a33
Add renovate.json
renovate[bot] May 29, 2024
89a6d13
Add Renovate configuration for a8c dependencies only
wzieba May 29, 2024
ddab08a
Add wpreleasetoolkit to renovate whitelist configuration
wzieba May 29, 2024
e468965
Fix a typo in a comment in the `AppReviewManager`
irfano May 29, 2024
489074a
Fixes: AudioRecorder clean up
pantstamp May 29, 2024
b78b43d
Modifies: AudioRecorder recording output
pantstamp May 29, 2024
b54aeeb
VoiceToContentUseCase cleanup
pantstamp May 29, 2024
bdc0acd
Handles: permission denial for Audio recording
pantstamp May 29, 2024
7d01797
Merge pull request #20899 from wordpress-mobile/issue/v2c-eligibility…
pantstamp May 29, 2024
f8db3db
Merge pull request #20891 from wordpress-mobile/issue/20820-update-in…
irfano May 29, 2024
957e3a9
Moves: RECORD_AUDIO permission to debug manifest
pantstamp May 29, 2024
8777f2d
Merge branch 'trunk' into issue/89-basic-media-recorder
zwarm May 29, 2024
015786a
Properly resolve conflict.
zwarm May 29, 2024
29cc555
Update unit tests to check for debug build
zwarm May 29, 2024
0254e9e
Merge pull request #20886 from wordpress-mobile/issue/89-basic-media-…
zwarm May 29, 2024
a1f3c73
Increase Cursor Window Size to 20mb to load larger posts
May 29, 2024
04851b3
Merge pull request #20870 from wordpress-mobile/andy/sentry-issue-529…
ravishanker May 29, 2024
84df633
Merge pull request #20911 from wordpress-mobile/issue/18727-cursor-wi…
irfano May 30, 2024
c8c3aad
Configure renovate to prepare PRs for all wordpress Gradle dependencies
wzieba May 30, 2024
c5a0f96
Whitelist `gravatar` dependencies as well
wzieba May 30, 2024
bb64d96
Ignore case in regex for matching dependencies
wzieba May 30, 2024
b0a3cce
Fix invalid regex
wzieba May 30, 2024
28cc7fa
Add `dangermattic` to the whitelist.
wzieba May 30, 2024
6d992db
Specify version of dependencies in addition to version.strictly confi…
wzieba May 30, 2024
f7ef046
add missing coma
wzieba May 30, 2024
5fda76b
AudioRecorder improvements
pantstamp May 30, 2024
11dca7c
Fixes: Deprecation error
pantstamp May 30, 2024
a1f2a5c
Rename onVoiceToContent to onContentUpdate
May 30, 2024
d91c8df
Merge branch 'trunk' into gutenberg/voice-to-content
May 30, 2024
c42e9db
Adds: RecordingStrategy for AudioRecorder
pantstamp May 30, 2024
92830fa
Merge pull request #19440 from wordpress-mobile/remove-unnecessary-lo…
ravishanker May 30, 2024
53a007c
Merge pull request #20902 from wordpress-mobile/renovate/configure
wzieba May 31, 2024
e3718c0
Update Automattic/dangermattic action to v1.1.1
renovate[bot] May 31, 2024
91a4f5b
Adds: AudioRecorderResult for IAudioRecorder
pantstamp May 31, 2024
62d260a
Merge pull request #20915 from wordpress-mobile/issue/93-recorder-lef…
pantstamp May 31, 2024
1433c68
Merge branch 'trunk' into gutenberg/voice-to-content
May 31, 2024
50a8ae4
Remove test content
May 31, 2024
26d45c5
Update Gutenberg ref
May 31, 2024
7c41ee1
Update Release notes
May 31, 2024
ec01193
Merge pull request #20852 from wordpress-mobile/gutenberg/voice-to-co…
May 31, 2024
b080aac
Update automatticTracksVersion to v5.1.0
renovate[bot] May 31, 2024
8ac3b6d
Add log line for transcription error while building out the feature
zwarm May 31, 2024
405ccc8
Update FluxC hash
zwarm May 31, 2024
d15f662
Address detekt too long line error
zwarm May 31, 2024
2de0177
Update fluxC hash
zwarm May 31, 2024
db47af2
Merge pull request #20924 from wordpress-mobile/issue/v2c-transcripti…
zwarm May 31, 2024
13f5363
Use v1 for dangermattic GitHub Actions
wzieba May 31, 2024
5c8dc48
Revert "Use v1 for dangermattic GitHub Actions"
wzieba Jun 3, 2024
a3a9fe1
Merge pull request #20917 from wordpress-mobile/renovate/automattic-d…
wzieba Jun 3, 2024
3e362b5
Update Automattic/dangermattic action to v1.1.2
renovate[bot] Jun 3, 2024
4e29eeb
Merge pull request #20918 from wordpress-mobile/renovate/automattictr…
wzieba Jun 3, 2024
92397ef
Replaces OAuth2 section with self-hosted test instructions
Jun 3, 2024
b7e59d3
Merge pull request #20927 from wordpress-mobile/renovate/automattic-d…
wzieba Jun 3, 2024
2557cba
Fixes typo
Jun 3, 2024
01ab55f
Adds note on the wpcom features access limitation
Jun 3, 2024
0e05482
Merge pull request #20928 from wordpress-mobile/task/removed-wpcom-oa…
Jun 3, 2024
56f0686
Merge pull request #20854 from wordpress-mobile/andy/target-sdk-34
AjeshRPai Jun 4, 2024
08070c4
Adds: delays for app restart in InAppUpdateManagerImpl
pantstamp Jun 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/run-danger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
jobs:
dangermattic:
if: ${{ (github.event.pull_request.draft == false) }}
uses: Automattic/dangermattic/.github/workflows/reusable-retry-buildkite-step-on-events.yml@v1.1.0
uses: Automattic/dangermattic/.github/workflows/reusable-retry-buildkite-step-on-events.yml@v1.1.2
with:
org-slug: "automattic"
pipeline-slug: "wordpress-android"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validate-issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
check-labels-on-issues:
uses: Automattic/dangermattic/.github/workflows/reusable-check-labels-on-issues.yml@v1.0.0
uses: Automattic/dangermattic/.github/workflows/reusable-check-labels-on-issues.yml@v1.1.2
with:
label-format-list: '[
"^\[.+\]",
Expand Down
40 changes: 7 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,8 @@ If you're a developer wanting to contribute, read on.

Notes:

* To use WordPress.com features (login to WordPress.com, access Reader and Stats, etc) you need a WordPress.com OAuth2 ID and secret. Please read the [OAuth2 Authentication](#oauth2-authentication) section.
* While loading/building the app in Android Studio ignore the prompt to update the gradle plugin version as that will probably introduce build errors. On the other hand, feel free to update if you are planning to work on ensuring the compatibility of the newer version.


## OAuth2 Authentication ##

In order to use WordPress.com functions you will need a client ID and
a client secret key. These details will be used to authenticate your
application and verify that the API calls being made are valid. You can
create an application or view details for your existing applications with
our [WordPress.com applications manager][5].

When creating your application, you should select "Native client" for the application type.
The "**Website URL**", "**Redirect URLs**", and "**Javascript Origins**" fields are required but not used for
the mobile apps. Just use "**[https://localhost](https://localhost)**".

Once you've created your application in the [applications manager][5], you'll
need to edit the `./gradle.properties` file and change the
`wp.oauth.app_id` and `wp.oauth.app_secret` fields. Then you can compile and
run the app on a device or an emulator and try to login with a WordPress.com
account. Note that authenticating to WordPress.com via Google is not supported
in development builds of the app, only in the official release.

Note that credentials created with our [WordPress.com applications manager][5]
allow login only and not signup. New accounts must be created using the [official app][1]
or [on the web](https://wordpress.com/start). Login is restricted to the WordPress.com
account with which the credentials were created. In other words, if the credentials
were created with foo@email.com, you will only be able to login with foo@email.com.
Using another account like bar@email.com will cause the `Client cannot use "password" grant_type` error.

For security reasons, some account-related actions aren't supported for development
builds when using a WordPress.com account with 2-factor authentication enabled.

Read more about [OAuth2][6] and the [WordPress.com REST endpoint][7].

## Build and Test ##

To build, install, and test the project from the command line:
Expand All @@ -61,6 +28,13 @@ To build, install, and test the project from the command line:
$ ./gradlew :WordPress:testWordPressVanillaDebugUnitTest # assemble, install and run unit tests
$ ./gradlew :WordPress:connectedWordPressVanillaDebugAndroidTest # assemble, install and run Android tests

## Running the app ##

You can use your own WordPress site for developing and testing the app. If you don't have one, you can create a temporary test site for free at https://jurassic.ninja/.
On the app start up screen, choose "Enter your existing site address" and enter the URL of your site and your credentials.

Note: Access to WordPress.com features is temporarily disabled in the development environment.

## Directory structure ##
.
├── libs # dependencies used to build debug variants
Expand Down
2 changes: 1 addition & 1 deletion RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

25.1
-----

* [*] [internal] Block editor: Add onContentUpdate bridge functionality [https://github.com/wordpress-mobile/gutenberg-mobile/pull/20852]

25.0
-----
Expand Down
6 changes: 3 additions & 3 deletions WordPress/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -364,15 +364,15 @@ dependencies {
implementation (project(path:':libs:editor')) {
exclude group: 'org.wordpress', module: 'utils'
}
implementation("$gradle.ext.fluxCBinaryPath") {
implementation("$gradle.ext.fluxCBinaryPath:$wordPressFluxCVersion") {
version {
strictly wordPressFluxCVersion
}
exclude group: "com.android.volley"
exclude group: 'org.wordpress', module: 'utils'
exclude group: 'com.android.support', module: 'support-annotations'
}
implementation ("$gradle.ext.wputilsBinaryPath") {
implementation ("$gradle.ext.wputilsBinaryPath:$wordPressUtilsVersion") {
version {
strictly wordPressUtilsVersion
}
Expand All @@ -383,7 +383,7 @@ dependencies {
}
implementation "$gradle.ext.aboutAutomatticBinaryPath:$automatticAboutVersion"

implementation("$gradle.ext.tracksBinaryPath") {
implementation("$gradle.ext.tracksBinaryPath:$automatticTracksVersion") {
version {
strictly automatticTracksVersion
}
Expand Down
3 changes: 3 additions & 0 deletions WordPress/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
android:name="android.permission.DUMP"
tools:ignore="ProtectedPermissions" />

<!-- Adds this permission temporarily here until Voice to content project is released -->
<uses-permission android:name="android.permission.RECORD_AUDIO" />

<application
android:name=".WordPressDebug"
android:supportsRtl="true"
Expand Down
1 change: 1 addition & 0 deletions WordPress/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<!-- Required for storing and retrieving screenshots, taking photos, accessing media files -->
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ import org.wordpress.android.util.config.OpenWebLinksWithJetpackFlowFeatureConfi
import org.wordpress.android.util.enqueuePeriodicUploadWorkRequestForAllSites
import org.wordpress.android.util.experiments.ExPlat
import org.wordpress.android.util.image.ImageManager
import org.wordpress.android.widgets.AppRatingDialog
import org.wordpress.android.widgets.AppReviewManager
import org.wordpress.android.workers.WordPressWorkersFactory
import java.io.File
import java.io.IOException
Expand Down Expand Up @@ -303,7 +303,7 @@ class AppInitializer @Inject constructor(
initWpDb()
context?.let { enableHttpResponseCache(it) }

AppRatingDialog.init(application)
AppReviewManager.init(application)

if (!initialized) {
// EventBus setup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class InAppUpdateAnalyticsTracker @Inject constructor(
}

fun trackAppRestartToCompleteUpdate() {
tracker.track(AnalyticsTracker.Stat.IN_APP_UPDATE_COMPLETED_WITH_APP_RESTART)
tracker.track(AnalyticsTracker.Stat.IN_APP_UPDATE_COMPLETED_WITH_APP_RESTART_BY_USER)
}

private fun createPropertyMap(updateType: Int): Map<String, String> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import com.google.android.play.core.install.model.UpdateAvailability.DEVELOPER_T
import com.google.android.play.core.install.model.UpdateAvailability.UPDATE_AVAILABLE
import com.google.android.play.core.install.model.UpdateAvailability.UPDATE_NOT_AVAILABLE
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.wordpress.android.inappupdate.IInAppUpdateManager.Companion.APP_UPDATE_FLEXIBLE_REQUEST_CODE
import org.wordpress.android.inappupdate.IInAppUpdateManager.Companion.APP_UPDATE_IMMEDIATE_REQUEST_CODE

Expand All @@ -33,6 +37,7 @@ import javax.inject.Singleton
@Suppress("TooManyFunctions")
class InAppUpdateManagerImpl(
@ApplicationContext private val applicationContext: Context,
private val coroutineScope: CoroutineScope,
private val appUpdateManager: AppUpdateManager,
private val remoteConfigWrapper: RemoteConfigWrapper,
private val buildConfigWrapper: BuildConfigWrapper,
Expand All @@ -51,8 +56,16 @@ class InAppUpdateManagerImpl(
}

override fun completeAppUpdate() {
inAppUpdateAnalyticsTracker.trackAppRestartToCompleteUpdate()
appUpdateManager.completeUpdate()
coroutineScope.launch(Dispatchers.Main) {
// Track the app restart to complete update
inAppUpdateAnalyticsTracker.trackAppRestartToCompleteUpdate()

// Delay so the event above can be logged
delay(RESTART_DELAY_IN_MILLIS)

// Complete the update
appUpdateManager.completeUpdate()
}
}

override fun cancelAppUpdate(updateType: Int) {
Expand Down Expand Up @@ -226,5 +239,6 @@ class InAppUpdateManagerImpl(
private const val TAG = "AppUpdateChecker"
private const val PREF_NAME = "in_app_update_prefs"
private const val KEY_LAST_APP_UPDATE_CHECK_VERSION = "last_app_update_check_version"
private const val RESTART_DELAY_IN_MILLIS = 500L
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,28 @@
import org.wordpress.android.ui.sitecreation.SiteCreationStep;
import org.wordpress.android.ui.sitecreation.SiteCreationStepsProvider;
import org.wordpress.android.util.BuildConfigWrapper;
import org.wordpress.android.util.audio.AudioRecorder;
import org.wordpress.android.util.audio.IAudioRecorder;
import org.wordpress.android.util.audio.RecordingStrategy;
import org.wordpress.android.util.audio.RecordingStrategy.VoiceToContentRecordingStrategy;
import org.wordpress.android.util.audio.VoiceToContentStrategy;
import org.wordpress.android.util.config.InAppUpdatesFeatureConfig;
import org.wordpress.android.util.config.RemoteConfigWrapper;
import org.wordpress.android.util.wizard.WizardManager;
import org.wordpress.android.viewmodel.helpers.ConnectionStatus;
import org.wordpress.android.viewmodel.helpers.ConnectionStatusLiveData;

import javax.inject.Named;

import dagger.Binds;
import dagger.Module;
import dagger.Provides;
import dagger.android.AndroidInjectionModule;
import dagger.hilt.InstallIn;
import dagger.hilt.android.qualifiers.ApplicationContext;
import dagger.hilt.components.SingletonComponent;
import kotlinx.coroutines.CoroutineScope;
import static org.wordpress.android.modules.ThreadModuleKt.APPLICATION_SCOPE;

@InstallIn(SingletonComponent.class)
@Module(includes = AndroidInjectionModule.class)
Expand Down Expand Up @@ -93,6 +102,7 @@ public static AppUpdateManager provideAppUpdateManager(@ApplicationContext Conte
@Provides
public static IInAppUpdateManager provideInAppUpdateManager(
@ApplicationContext Context context,
@Named(APPLICATION_SCOPE) CoroutineScope appScope,
AppUpdateManager appUpdateManager,
RemoteConfigWrapper remoteConfigWrapper,
BuildConfigWrapper buildConfigWrapper,
Expand All @@ -103,6 +113,7 @@ public static IInAppUpdateManager provideInAppUpdateManager(
return inAppUpdatesFeatureConfig.isEnabled()
? new InAppUpdateManagerImpl(
context,
appScope,
appUpdateManager,
remoteConfigWrapper,
buildConfigWrapper,
Expand All @@ -121,4 +132,19 @@ public static ActivityNavigator provideActivityNavigator(@ApplicationContext Con
public static SensorManager provideSensorManager(@ApplicationContext Context context) {
return (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
}

@VoiceToContentStrategy
@Provides
public static IAudioRecorder provideAudioRecorder(
@ApplicationContext Context context,
@VoiceToContentStrategy RecordingStrategy recordingStrategy
) {
return new AudioRecorder(context, recordingStrategy);
}

@VoiceToContentStrategy
@Provides
public static RecordingStrategy provideVoiceToContentRecordingStrategy() {
return new VoiceToContentRecordingStrategy();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import org.wordpress.android.ui.reader.viewmodels.ReaderPostListViewModel;
import org.wordpress.android.ui.reader.viewmodels.ReaderViewModel;
import org.wordpress.android.ui.reader.viewmodels.SubfilterPageViewModel;
import org.wordpress.android.ui.review.ReviewViewModel;
import org.wordpress.android.ui.stats.refresh.lists.DaysListViewModel;
import org.wordpress.android.ui.stats.refresh.lists.InsightsDetailListViewModel;
import org.wordpress.android.ui.stats.refresh.lists.InsightsListViewModel;
Expand Down Expand Up @@ -461,11 +460,6 @@ abstract class ViewModelModule {
@ViewModelKey(UnifiedCommentListViewModel.class)
abstract ViewModel unifiedCommentListViewModel(UnifiedCommentListViewModel viewModel);

@Binds
@IntoMap
@ViewModelKey(ReviewViewModel.class)
abstract ViewModel reviewViewModel(ReviewViewModel viewModel);

@Binds
@IntoMap
@ViewModelKey(BloggingRemindersViewModel.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,20 @@ import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.viewinterop.AndroidView
import androidx.core.content.ContextCompat
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf
import org.wordpress.android.ui.compose.theme.AppTheme
import androidx.camera.core.Preview as CameraPreview

@Composable
fun BarcodeScanner(
codeScanner: CodeScanner,
onScannedResult: (Flow<CodeScannerStatus>) -> Unit
onScannedResult: CodeScannerCallback
) {
val context = LocalContext.current
val lifecycleOwner = LocalLifecycleOwner.current
val cameraProviderFuture = remember {
ProcessCameraProvider.getInstance(context)
}

Column(
modifier = Modifier.fillMaxSize()
) {
Expand All @@ -51,30 +50,27 @@ fun BarcodeScanner(
.setBackpressureStrategy(STRATEGY_KEEP_ONLY_LATEST)
.build()
imageAnalysis.setAnalyzer(ContextCompat.getMainExecutor(context)) { imageProxy ->
onScannedResult(codeScanner.startScan(imageProxy))
val callback = object : CodeScannerCallback {
override fun run(status: CodeScannerStatus?) {
status?.let { onScannedResult.run(it) }
}
}
codeScanner.startScan(imageProxy, callback)
}
try {
cameraProviderFuture.get().bindToLifecycle(lifecycleOwner, selector, preview, imageAnalysis)
} catch (e: IllegalStateException) {
onScannedResult(
flowOf(
CodeScannerStatus.Failure(
e.message
?: "Illegal state exception while binding camera provider to lifecycle",
CodeScanningErrorType.Other(e)
)
)
)
onScannedResult.run(CodeScannerStatus.Failure(
e.message
?: "Illegal state exception while binding camera provider to lifecycle",
CodeScanningErrorType.Other(e)
))
} catch (e: IllegalArgumentException) {
onScannedResult(
flowOf(
CodeScannerStatus.Failure(
e.message
?: "Illegal argument exception while binding camera provider to lifecycle",
CodeScanningErrorType.Other(e)
)
)
)
onScannedResult.run(CodeScannerStatus.Failure(
e.message
?: "Illegal argument exception while binding camera provider to lifecycle",
CodeScanningErrorType.Other(e)
))
}
previewView
},
Expand All @@ -84,8 +80,8 @@ fun BarcodeScanner(
}

class DummyCodeScanner : CodeScanner {
override fun startScan(imageProxy: ImageProxy): Flow<CodeScannerStatus> {
return flowOf(CodeScannerStatus.Success("", GoogleBarcodeFormatMapper.BarcodeFormat.FormatUPCA))
override fun startScan(imageProxy: ImageProxy, callback: CodeScannerCallback) {
callback.run(CodeScannerStatus.Success("", GoogleBarcodeFormatMapper.BarcodeFormat.FormatUPCA))
}
}

Expand All @@ -94,6 +90,10 @@ class DummyCodeScanner : CodeScanner {
@Composable
private fun BarcodeScannerScreenPreview() {
AppTheme {
BarcodeScanner(codeScanner = DummyCodeScanner(), onScannedResult = {})
BarcodeScanner(codeScanner = DummyCodeScanner(), onScannedResult = object : CodeScannerCallback {
override fun run(status: CodeScannerStatus?) {
// no-ops
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import org.wordpress.android.R
import kotlinx.coroutines.flow.Flow
import org.wordpress.android.ui.compose.theme.AppTheme

@Composable
fun BarcodeScannerScreen(
codeScanner: CodeScanner,
permissionState: BarcodeScanningViewModel.PermissionState,
onResult: (Boolean) -> Unit,
onScannedResult: (Flow<CodeScannerStatus>) -> Unit,
onScannedResult: CodeScannerCallback,
) {
val cameraPermissionLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.RequestPermission(),
Expand Down
Loading
Loading