Skip to content
This repository was archived by the owner on Feb 19, 2020. It is now read-only.

Commit 7c84b10

Browse files
brentwatsonmatthiaswenz
authored andcommitted
Add forceNewThread flag which allows Feedback to always create a new message thread (#189)
* Add forceNewThread flag which allows Feedback to always create a new message thread * Set force new feedback thread through listener
1 parent fee5bae commit 7c84b10

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

hockeysdk/src/main/java/net/hockeyapp/android/FeedbackActivity.java

+22-7
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ public class FeedbackActivity extends Activity implements OnClickListener {
6767
*/
6868
public static final String EXTRA_URL = "url";
6969

70+
/**
71+
* Optional extra that can be passed as {@code true} to force a new feedback message thread.
72+
*/
73+
public static final String EXTRA_FORCE_NEW_THREAD = "forceNewThread";
74+
7075
/**
7176
* Extra for initial username to set for the feedback message.
7277
*/
@@ -165,6 +170,12 @@ public class FeedbackActivity extends Activity implements OnClickListener {
165170
**/
166171
private boolean mInSendFeedback;
167172

173+
/**
174+
* Indicates if a new thread should be created for each new feedback message as opposed to
175+
* the default resume thread behaviour.
176+
*/
177+
private boolean mForceNewThread;
178+
168179
/**
169180
* True when the view was initialized
170181
**/
@@ -193,6 +204,7 @@ public void onCreate(Bundle savedInstanceState) {
193204
Bundle extras = getIntent().getExtras();
194205
if (extras != null) {
195206
mUrl = extras.getString(EXTRA_URL);
207+
mForceNewThread = extras.getBoolean(EXTRA_FORCE_NEW_THREAD);
196208
initialUserName = extras.getString(EXTRA_INITIAL_USER_NAME);
197209
initialUserEmail = extras.getString(EXTRA_INITIAL_USER_EMAIL);
198210

@@ -316,8 +328,8 @@ public void onClick(View v) {
316328
openContextMenu(v);
317329
}
318330
} else if (viewId == R.id.button_add_response) {
319-
configureFeedbackView(false);
320331
mInSendFeedback = true;
332+
configureFeedbackView(false);
321333
} else if (viewId == R.id.button_refresh) {
322334
sendFetchFeedback(mUrl, null, null, null, null, null, PrefsUtil.getInstance().getFeedbackTokenFromPrefs(mContext), mFeedbackHandler, true);
323335
}
@@ -494,7 +506,7 @@ protected void configureFeedbackView(boolean haveToken) {
494506
mNameInput.setText(nameEmailSubjectArray[0]);
495507
mEmailInput.setText(nameEmailSubjectArray[1]);
496508

497-
if (nameEmailSubjectArray.length >= 3) {
509+
if (!mForceNewThread && nameEmailSubjectArray.length >= 3) {
498510
mSubjectInput.setText(nameEmailSubjectArray[2]);
499511
mTextInput.requestFocus();
500512
} else {
@@ -524,8 +536,8 @@ protected void configureFeedbackView(boolean haveToken) {
524536
/** Reset the remaining fields if previously populated */
525537
mTextInput.setText("");
526538

527-
/** Check to see if the Feedback Token is availabe */
528-
if (PrefsUtil.getInstance().getFeedbackTokenFromPrefs(mContext) != null) {
539+
/** Check to see if the Feedback Token is available */
540+
if ((!mForceNewThread || mInSendFeedback) && PrefsUtil.getInstance().getFeedbackTokenFromPrefs(mContext) != null) {
529541
/** If Feedback Token is available, hide the Subject Input field */
530542
mSubjectInput.setVisibility(View.GONE);
531543
} else {
@@ -586,8 +598,11 @@ private boolean addAttachment(int request) {
586598

587599
private void configureAppropriateView() {
588600
/** Try to retrieve the Feedback Token from {@link SharedPreferences} */
589-
mToken = PrefsUtil.getInstance().getFeedbackTokenFromPrefs(this);
590-
if ((mToken == null) || (mInSendFeedback)) {
601+
if (!mForceNewThread || mInSendFeedback) {
602+
mToken = PrefsUtil.getInstance().getFeedbackTokenFromPrefs(this);
603+
}
604+
605+
if (mToken == null || mInSendFeedback) {
591606
/** If Feedback Token is NULL, show the usual feedback view */
592607
configureFeedbackView(false);
593608
} else {
@@ -708,7 +723,7 @@ private void sendFeedback() {
708723
enableDisableSendFeedbackButton(false);
709724
hideKeyboard();
710725

711-
String token = PrefsUtil.getInstance().getFeedbackTokenFromPrefs(mContext);
726+
String token = mForceNewThread && !mInSendFeedback ? null : PrefsUtil.getInstance().getFeedbackTokenFromPrefs(mContext);
712727

713728
String name = mNameInput.getText().toString().trim();
714729
String email = mEmailInput.getText().toString().trim();

hockeysdk/src/main/java/net/hockeyapp/android/FeedbackManager.java

+2
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ public static void showFeedbackActivity(Context context, Bundle extras, Uri... a
183183
if (activityClass == null) {
184184
activityClass = FeedbackActivity.class;
185185
}
186+
boolean forceNewThread = lastListener != null && lastListener.shouldCreateNewFeedbackThread();
186187

187188
Intent intent = new Intent();
188189
if (extras != null && !extras.isEmpty()) {
@@ -191,6 +192,7 @@ public static void showFeedbackActivity(Context context, Bundle extras, Uri... a
191192
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
192193
intent.setClass(context, activityClass);
193194
intent.putExtra(FeedbackActivity.EXTRA_URL, getURLString(context));
195+
intent.putExtra(FeedbackActivity.EXTRA_FORCE_NEW_THREAD, forceNewThread);
194196
intent.putExtra(FeedbackActivity.EXTRA_INITIAL_USER_NAME, userName);
195197
intent.putExtra(FeedbackActivity.EXTRA_INITIAL_USER_EMAIL, userEmail);
196198
intent.putExtra(FeedbackActivity.EXTRA_INITIAL_ATTACHMENTS, attachments);

hockeysdk/src/main/java/net/hockeyapp/android/FeedbackManagerListener.java

+8
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,12 @@ public Class<? extends FeedbackActivity> getFeedbackActivityClass() {
2626
* and false if not and a notification should be fired.
2727
*/
2828
public abstract boolean feedbackAnswered(FeedbackMessage latestMessage);
29+
30+
/**
31+
* Called when posting a new feedback message.
32+
* @return Whether a new feedback thread should be created or not. Defaults to false.
33+
*/
34+
public boolean shouldCreateNewFeedbackThread() {
35+
return false;
36+
}
2937
}

0 commit comments

Comments
 (0)