Skip to content

Commit 4901012

Browse files
author
Anirudh S
committed
[Feature]: Save ticket and user details as drafts
1 parent 490429b commit 4901012

File tree

7 files changed

+225
-33
lines changed

7 files changed

+225
-33
lines changed

helpstack/src/com/tenmiles/helpstack/activities/NewIssueActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public class NewIssueActivity extends HSActivityParent {
3838
public static final String EXTRAS_USER = "user";
3939
public static final String RESULT_TICKET = "ticket";
4040

41-
public static final String EXTRAS_SUBJECT = "Subject";
42-
public static final String EXTRAS_MESSAGE = "Message";
41+
public static final String EXTRAS_SUBJECT = "subject";
42+
public static final String EXTRAS_MESSAGE = "message";
4343
public static final String EXTRAS_ATTACHMENT = "attachment";
4444

4545
@Override

helpstack/src/com/tenmiles/helpstack/fragments/HomeFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
111111
setHasOptionsMenu(true);
112112

113113
// Initialize gear
114-
gearSource = new HSSource (getActivity());
114+
gearSource = new HSSource(getActivity());
115115

116116
// handle orientation
117117
if (savedInstanceState == null) {

helpstack/src/com/tenmiles/helpstack/fragments/NewIssueFragment.java

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ public class NewIssueFragment extends HSFragmentParent {
6969

7070
public static final String EXTRAS_USER = NewIssueActivity.EXTRAS_USER;
7171
public static final String RESULT_TICKET = NewIssueActivity.RESULT_TICKET;
72-
private static final String EXTRAS_ATTACHMENT = NewIssueActivity.EXTRAS_ATTACHMENT;
72+
public static final String EXTRAS_SUBJECT = NewIssueActivity.EXTRAS_SUBJECT;
73+
public static final String EXTRAS_MESSAGE = NewIssueActivity.EXTRAS_MESSAGE;
74+
public static final String EXTRAS_ATTACHMENT = NewIssueActivity.EXTRAS_ATTACHMENT;
7375

7476
EditText subjectField, messageField;
7577
ImageView imageView1;
@@ -119,6 +121,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
119121

120122
gearSource = new HSSource(getActivity());
121123

124+
this.subjectField.setText(gearSource.getDraftSubject());
125+
this.messageField.setText(gearSource.getDraftMessage());
126+
122127
if (!HSHelpStack.getInstance(getActivity()).getShowCredits()) {
123128
rootView.findViewById(R.id.footerTextLabel).setVisibility(View.GONE);
124129
rootView.findViewById(R.id.footerDivider).setVisibility(View.GONE);
@@ -136,6 +141,20 @@ public void onSaveInstanceState(Bundle outState) {
136141
outState.putSerializable("attachment", selectedAttachment);
137142
}
138143

144+
@Override
145+
public void onPause() {
146+
super.onPause();
147+
148+
HSAttachment[] attachmentArray = null;
149+
150+
if (selectedAttachment != null) {
151+
attachmentArray = new HSAttachment[1];
152+
attachmentArray[0] = selectedAttachment;
153+
}
154+
155+
gearSource.saveTicketDetailsInDraft(subjectField.getText().toString(), messageField.getText().toString(), attachmentArray);
156+
}
157+
139158
@Override
140159
public void onActivityCreated(Bundle savedInstanceState) {
141160
super.onActivityCreated(savedInstanceState);
@@ -176,8 +195,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
176195
return false;
177196
}
178197

179-
180-
181198
HSAttachment[] attachmentArray = null;
182199

183200
if (selectedAttachment != null) {
@@ -198,6 +215,7 @@ public void onSuccess(HSUser udpatedUserDetail, HSTicket ticket) {
198215

199216
getHelpStackActivity().setSupportProgressBarIndeterminateVisibility(false);
200217
sendSuccessSignal(ticket);
218+
clearFormData();
201219
Toast.makeText(getActivity(), getResources().getString(R.string.hs_issue_created_raised), Toast.LENGTH_LONG).show();
202220
}
203221

@@ -211,7 +229,6 @@ public void onErrorResponse(VolleyError error) {
211229
});
212230
}
213231
else {
214-
Bundle bundle = new Bundle();
215232
HSActivityManager.startNewUserActivity(this, REQUEST_CODE_NEW_TICKET, getSubject(), formattedBody, attachmentArray);
216233
}
217234

@@ -246,7 +263,6 @@ public void onActivityResult(int requestCode, int resultCode, Intent intent) {
246263
selectedAttachment = HSAttachment.createAttachment(selectedImage.toString(), display_name, mime_type);
247264

248265
resetAttachmentImage();
249-
250266
}
251267
case REQUEST_CODE_NEW_TICKET:
252268
if (resultCode == HSActivityManager.resultCode_sucess) {
@@ -283,7 +299,6 @@ public void onClick(DialogInterface dialog, int which) {
283299
Intent intent = new Intent(getActivity(), EditAttachmentActivity.class);
284300
startActivityForResult(intent, REQUEST_CODE_PHOTO_PICKER);
285301
}
286-
287302
else if (which == 1) {
288303
selectedAttachment = null;
289304
resetAttachmentImage();
@@ -296,14 +311,11 @@ else if (which == 1) {
296311
}
297312
};
298313

299-
300-
301314
private void resetAttachmentImage() {
302315
if (selectedAttachment == null) {
303316
this.imageView1.setImageResource(R.drawable.hs_add_attachment_img);
304317
}
305318
else {
306-
307319
try {
308320
Uri uri = Uri.parse(selectedAttachment.getUrl());
309321
Bitmap selectedBitmap;
@@ -313,10 +325,14 @@ private void resetAttachmentImage() {
313325
// TODO Auto-generated catch block
314326
e.printStackTrace();
315327
}
316-
317-
318328
}
329+
}
330+
319331

332+
private void clearFormData() {
333+
this.subjectField.setText("");
334+
this.messageField.setText("");
335+
gearSource.clearTicketDraft();
320336
}
321337

322338
public String getSubject() {

helpstack/src/com/tenmiles/helpstack/fragments/NewUserFragment.java

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ public class NewUserFragment extends HSFragmentParent {
5252
private static final int NEW_TICKET_REQUEST_CODE = 1003;
5353

5454
private static final String RESULT_TICKET = NewIssueActivity.RESULT_TICKET;
55-
private static final String EXTRAS_ATTACHMENT = NewIssueActivity.EXTRAS_ATTACHMENT;
55+
private static final String EXTRAS_SUBJECT = NewIssueFragment.EXTRAS_SUBJECT;
56+
private static final String EXTRAS_MESSAGE = NewIssueFragment.EXTRAS_MESSAGE;
57+
private static final String EXTRAS_ATTACHMENT = NewIssueFragment.EXTRAS_ATTACHMENT;
5658

57-
private HSAttachment[] attachmentArray;
5859
private String subject;
5960
private String message;
61+
private HSAttachment[] attachmentArray;
6062

6163
public NewUserFragment() {
6264

@@ -83,13 +85,20 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
8385
args = getArguments();
8486

8587
if (args != null) {
86-
subject = args.getString("Subject");
87-
message = args.getString("Message");
88+
subject = args.getString(EXTRAS_SUBJECT);
89+
message = args.getString(EXTRAS_MESSAGE);
8890
attachmentArray = (HSAttachment[]) args.getSerializable(EXTRAS_ATTACHMENT);
8991
}
9092
}
9193

9294
gearSource = new HSSource(getActivity());
95+
96+
HSUser user = gearSource.getDraftUser();
97+
if (user != null) {
98+
this.firstNameField.setText(user.getFirstName());
99+
this.lastNameField.setText(user.getLastName());
100+
this.emailField.setText(user.getEmail());
101+
}
93102

94103
return rootView;
95104
}
@@ -101,6 +110,18 @@ public void onSaveInstanceState(Bundle outState) {
101110
outState.putString("last_name", lastNameField.getText().toString());
102111
outState.putString("email", emailField.getText().toString());
103112
}
113+
114+
@Override
115+
public void onPause() {
116+
super.onPause();
117+
118+
HSUser userDetails = HSUser.createNewUserWithDetails(
119+
this.firstNameField.getText().toString(),
120+
this.lastNameField.getText().toString(),
121+
this.emailField.getText().toString());
122+
123+
gearSource.saveUserDetailsInDraft(userDetails);
124+
}
104125

105126
@Override
106127
public void onActivityCreated(Bundle savedInstanceState) {
@@ -161,6 +182,7 @@ public void onSuccess(HSUser udpatedUserDetail, HSTicket ticket) {
161182

162183
getHelpStackActivity().setSupportProgressBarIndeterminateVisibility(false);
163184
sendSuccessSignal(ticket);
185+
gearSource.clearTicketDraft();
164186
Toast.makeText(getActivity(), getResources().getString(R.string.hs_issue_created_raised), Toast.LENGTH_LONG).show();
165187
}
166188

@@ -187,21 +209,21 @@ public void onErrorResponse(VolleyError error) {
187209

188210
return super.onOptionsItemSelected(item);
189211
}
190-
191-
@Override
212+
213+
@Override
192214
public void onDetach() {
193215
gearSource.cancelOperation("NEW_USER");
194216
super.onDetach();
195217
}
196-
218+
197219
public String getFirstName() {
198220
return firstNameField.getText().toString();
199221
}
200-
222+
201223
public String getLastName() {
202224
return lastNameField.getText().toString();
203225
}
204-
226+
205227
public String getEmailAdddress() {
206228
return emailField.getText().toString();
207229
}

0 commit comments

Comments
 (0)