-
Notifications
You must be signed in to change notification settings - Fork 626
Implement collectAndSendFeedback() #3816
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
Changes from 3 commits
792e775
51c8604
7307517
05d4642
a99baec
791c68f
edbbc6f
dd88656
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright 2022 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.firebase.appdistribution.impl; | ||
|
||
import android.graphics.Bitmap; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.EditText; | ||
import android.widget.Toast; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
import com.google.firebase.FirebaseApp; | ||
|
||
/** Activity for tester to compose and submit feedback. */ | ||
public class FeedbackActivity extends AppCompatActivity { | ||
|
||
private static final String TAG = "FeedbackActivity"; | ||
|
||
public static final String RELEASE_NAME_EXTRA_KEY = | ||
"com.google.firebase.appdistribution.FeedbackActivity.RELEASE_NAME"; | ||
public static final String SCREENSHOT_EXTRA_KEY = | ||
"com.google.firebase.appdistribution.FeedbackActivity.SCREENSHOT"; | ||
|
||
private FeedbackSender feedbackSender; | ||
private String releaseName; | ||
private Bitmap screenshot; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
releaseName = getIntent().getStringExtra(RELEASE_NAME_EXTRA_KEY); | ||
screenshot = getIntent().getParcelableExtra(SCREENSHOT_EXTRA_KEY); | ||
feedbackSender = FirebaseApp.getInstance().get(FeedbackSender.class); | ||
setContentView(R.layout.activity_feedback); | ||
} | ||
|
||
public void submitFeedback(View view) { | ||
setSubmittingStateEnabled(true); | ||
EditText feedbackText = (EditText) findViewById(R.id.feedbackText); | ||
feedbackSender | ||
.sendFeedback(releaseName, feedbackText.getText().toString(), screenshot) | ||
.addOnSuccessListener( | ||
unused -> { | ||
LogWrapper.getInstance().i(TAG, "Feedback submitted"); | ||
Toast.makeText(this, "Feedback submitted", Toast.LENGTH_LONG).show(); | ||
finish(); | ||
}) | ||
.addOnFailureListener( | ||
e -> { | ||
LogWrapper.getInstance().e(TAG, "Failed to submit feedback", e); | ||
Toast.makeText(this, "Error submitting feedback", Toast.LENGTH_LONG).show(); | ||
setSubmittingStateEnabled(false); | ||
}); | ||
} | ||
|
||
public void setSubmittingStateEnabled(boolean loading) { | ||
findViewById(R.id.submitButton).setVisibility(loading ? View.INVISIBLE : View.VISIBLE); | ||
findViewById(R.id.loadingLabel).setVisibility(loading ? View.VISIBLE : View.INVISIBLE); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2022 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.firebase.appdistribution.impl; | ||
|
||
import android.graphics.Bitmap; | ||
import com.google.android.gms.tasks.Task; | ||
|
||
/** Sends tester feedback to the Tester API. */ | ||
class FeedbackSender { | ||
|
||
private final FirebaseAppDistributionTesterApiClient testerApiClient; | ||
|
||
FeedbackSender(FirebaseAppDistributionTesterApiClient testerApiClient) { | ||
this.testerApiClient = testerApiClient; | ||
} | ||
|
||
/** Send feedback text and screenshot to the Tester API for the given release. */ | ||
Task<Void> sendFeedback(String releaseName, String feedbackText, Bitmap screenshot) { | ||
return testerApiClient | ||
.createFeedback(releaseName, feedbackText) | ||
.onSuccessTask(feedbackName -> testerApiClient.attachScreenshot(feedbackName, screenshot)) | ||
.onSuccessTask(testerApiClient::commitFeedback); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,23 +46,39 @@ public class FirebaseAppDistributionRegistrar implements ComponentRegistrar { | |
Component.builder(FirebaseAppDistribution.class) | ||
.add(Dependency.required(FirebaseApp.class)) | ||
.add(Dependency.requiredProvider(FirebaseInstallationsApi.class)) | ||
.add(Dependency.required(FeedbackSender.class)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is component registry intended as a general purpose dependency injection framework? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not. In this case the FeedbackActivity needs to get an instance of the class, which depends on a Provider and thus needs to be instantiated by the Firebase Components framework. Not sure if this is the best way to do this though. I'll reach out to the ACore folks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why does FirebaseAppDistribution actually depend on FeedbackSender? I don't see it used inside buildFirebaseAppDistribution There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking that this captures the dependency that FeedbackActivity (launched by FirebaseAppDistribution) has on FeedbackSender... (EDIT: thinking more now I guess that doesn't make sense, disregard) |
||
.factory(this::buildFirebaseAppDistribution) | ||
// construct FirebaseAppDistribution instance on startup so we can register for | ||
// activity lifecycle callbacks before the API is called | ||
.alwaysEager() | ||
.build(), | ||
Component.builder(FeedbackSender.class) | ||
kaibolay marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.add(Dependency.required(FirebaseApp.class)) | ||
.add(Dependency.requiredProvider(FirebaseInstallationsApi.class)) | ||
.factory(this::buildFeedbackSender) | ||
.build(), | ||
LibraryVersionComponent.create("fire-appdistribution", BuildConfig.VERSION_NAME)); | ||
} | ||
|
||
private FeedbackSender buildFeedbackSender(ComponentContainer container) { | ||
FirebaseApp firebaseApp = container.get(FirebaseApp.class); | ||
Provider<FirebaseInstallationsApi> firebaseInstallationsApiProvider = | ||
container.getProvider(FirebaseInstallationsApi.class); | ||
FirebaseAppDistributionTesterApiClient testerApiClient = | ||
new FirebaseAppDistributionTesterApiClient( | ||
firebaseApp, firebaseInstallationsApiProvider, new TesterApiHttpClient(firebaseApp)); | ||
return new FeedbackSender(testerApiClient); | ||
} | ||
|
||
private FirebaseAppDistribution buildFirebaseAppDistribution(ComponentContainer container) { | ||
FirebaseApp firebaseApp = container.get(FirebaseApp.class); | ||
Context context = firebaseApp.getApplicationContext(); | ||
Provider<FirebaseInstallationsApi> firebaseInstallationsApiProvider = | ||
container.getProvider(FirebaseInstallationsApi.class); | ||
SignInStorage signInStorage = new SignInStorage(context); | ||
FirebaseAppDistributionTesterApiClient testerApiClient = | ||
new FirebaseAppDistributionTesterApiClient( | ||
firebaseApp, firebaseInstallationsApiProvider, new TesterApiHttpClient(firebaseApp)); | ||
SignInStorage signInStorage = new SignInStorage(context); | ||
FirebaseAppDistributionLifecycleNotifier lifecycleNotifier = | ||
FirebaseAppDistributionLifecycleNotifier.getInstance(); | ||
ReleaseIdentifier releaseIdentifier = new ReleaseIdentifier(firebaseApp, testerApiClient); | ||
|
@@ -76,7 +92,8 @@ private FirebaseAppDistribution buildFirebaseAppDistribution(ComponentContainer | |
new AabUpdater(), | ||
signInStorage, | ||
lifecycleNotifier, | ||
releaseIdentifier); | ||
releaseIdentifier, | ||
new ScreenshotTaker()); | ||
|
||
if (context instanceof Application) { | ||
Application firebaseApplication = (Application) context; | ||
|
Uh oh!
There was an error while loading. Please reload this page.