Skip to content

Commit 7310b97

Browse files
Sachin Aggarwalopticod
Sachin Aggarwal
authored andcommitted
Single Item not allowed in match
1 parent 1cf58ae commit 7310b97

File tree

1 file changed

+38
-33
lines changed

1 file changed

+38
-33
lines changed

source-code/app/src/main/java/org/buildmlearn/toolkit/activity/TemplateEditor.java

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -97,22 +97,21 @@ public void handleMessage(Message message) {
9797
private ProgressDialog mApkGenerationDialog;
9898

9999

100-
public void openBottomSheet (View v) {
101-
102-
View view = getLayoutInflater ().inflate (R.layout.bottom_sheet_view, null);
103-
TextView txtSaveApk = (TextView)view.findViewById( R.id.txt_save_apk);
104-
TextView txtSaveProject = (TextView)view.findViewById( R.id.txt_save_project);
105-
TextView txtShareApk = (TextView)view.findViewById( R.id.txt_share_apk);
106-
final TextView txtShareProject = (TextView)view.findViewById( R.id.txt_share_project);
107-
108-
final Dialog mBottomSheetDialog = new Dialog (TemplateEditor.this,
100+
public void openBottomSheet(View v) {
101+
102+
View view = getLayoutInflater().inflate(R.layout.bottom_sheet_view, null);
103+
TextView txtSaveApk = (TextView) view.findViewById(R.id.txt_save_apk);
104+
TextView txtSaveProject = (TextView) view.findViewById(R.id.txt_save_project);
105+
TextView txtShareApk = (TextView) view.findViewById(R.id.txt_share_apk);
106+
final TextView txtShareProject = (TextView) view.findViewById(R.id.txt_share_project);
107+
final Dialog mBottomSheetDialog = new Dialog(TemplateEditor.this,
109108
R.style.MaterialDialogSheet);
110-
mBottomSheetDialog.setContentView (view);
111-
mBottomSheetDialog.setCancelable (true);
112-
mBottomSheetDialog.getWindow ().setLayout (LinearLayout.LayoutParams.MATCH_PARENT,
109+
mBottomSheetDialog.setContentView(view);
110+
mBottomSheetDialog.setCancelable(true);
111+
mBottomSheetDialog.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT,
113112
LinearLayout.LayoutParams.WRAP_CONTENT);
114-
mBottomSheetDialog.getWindow ().setGravity (Gravity.BOTTOM);
115-
mBottomSheetDialog.show ();
113+
mBottomSheetDialog.getWindow().setGravity(Gravity.BOTTOM);
114+
mBottomSheetDialog.show();
116115

117116

118117
//save project
@@ -164,7 +163,7 @@ private void saveApk() {
164163
String aliasName = getString(R.string.alias_name);
165164
String aliaspassword = getString(R.string.alias_password);
166165
KeyStoreDetails keyStoreDetails = new KeyStoreDetails(keyPassword, aliasName, aliaspassword);
167-
if(saveProject().equals("File already exists")){
166+
if (saveProject().equals("File already exists")) {
168167
return;
169168
}
170169
SignerThread signer = new SignerThread(getApplicationContext(), selectedTemplate.getApkFilePath(), saveProject(), keyStoreDetails, selectedTemplate.getAssetsFilePath(), selectedTemplate.getAssetsFileName(TemplateEditor.this));
@@ -535,9 +534,7 @@ private void setUpTemplateEditor() {
535534

536535
} catch (InstantiationException e) {
537536
e.printStackTrace();
538-
}
539-
catch ( IllegalAccessException e)
540-
{
537+
} catch (IllegalAccessException e) {
541538
e.printStackTrace();
542539
}
543540
}
@@ -598,16 +595,16 @@ public boolean onOptionsItemSelected(MenuItem item) {
598595
switch (id) {
599596
case R.id.action_delete:
600597
final int restorePosition = selectedPosition;
601-
final Object object = selectedTemplate.deleteItem(TemplateEditor.this,selectedPosition);
598+
final Object object = selectedTemplate.deleteItem(TemplateEditor.this, selectedPosition);
602599
selectedPosition = -1;
603600
restoreSelectedView();
604601
Snackbar.make(findViewById(R.id.relative_layout),
605-
R.string.snackbar_deleted_message,Snackbar.LENGTH_LONG)
602+
R.string.snackbar_deleted_message, Snackbar.LENGTH_LONG)
606603
.setAction(R.string.snackbar_undo, new View.OnClickListener() {
607604
@Override
608605
public void onClick(View v) {
609-
selectedTemplate.restoreItem(TemplateEditor.this,restorePosition,object);
610-
Snackbar.make(v,R.string.snackbar_restored_message,Snackbar.LENGTH_LONG).show();
606+
selectedTemplate.restoreItem(TemplateEditor.this, restorePosition, object);
607+
Snackbar.make(v, R.string.snackbar_restored_message, Snackbar.LENGTH_LONG).show();
611608
}
612609
}).show();
613610
break;
@@ -694,10 +691,10 @@ private String saveProject() {
694691
EditText authorEditText = (EditText) findViewById(R.id.author_name);
695692
titleEditText = (EditText) findViewById(R.id.template_title);
696693
assert findViewById(R.id.author_name) != null;
697-
assert ( findViewById(R.id.author_name)) != null;
694+
assert (findViewById(R.id.author_name)) != null;
698695
String author = ((EditText) findViewById(R.id.author_name)).getText().toString();
699696
assert findViewById(R.id.template_title) != null;
700-
assert ( findViewById(R.id.template_title)) != null;
697+
assert (findViewById(R.id.template_title)) != null;
701698
String title = ((EditText) findViewById(R.id.template_title)).getText().toString();
702699
if ("".equals(author)) {
703700
assert authorEditText != null;
@@ -747,6 +744,12 @@ private String saveProject() {
747744
Toast.makeText(this, "Unable to perform action: Add Meta Details", Toast.LENGTH_SHORT).show();
748745
return null;
749746
}
747+
748+
if (templateId == 7 && selectedTemplate.getItems(doc).size() == 2) {
749+
Toast.makeText(this, "Please enter atleast 2 items", Toast.LENGTH_SHORT).show();
750+
return null;
751+
}
752+
750753
for (Element item : selectedTemplate.getItems(doc)) {
751754
dataElement.appendChild(item);
752755
}
@@ -759,13 +762,12 @@ private String saveProject() {
759762
saveFileName = saveFileName.replaceAll(" ", "-");
760763

761764

762-
boolean isSaved=FileUtils.saveXmlFile(toolkit.getSavedDir(), saveFileName, doc);
763-
if(isSaved) {
765+
boolean isSaved = FileUtils.saveXmlFile(toolkit.getSavedDir(), saveFileName, doc);
766+
if (isSaved) {
764767
oldFileName = toolkit.getSavedDir() + saveFileName;
765768
Toast.makeText(this, "Project Successfully Saved!", Toast.LENGTH_SHORT).show();
766769
return oldFileName;
767-
}
768-
else {
770+
} else {
769771
titleEditText.setError("File Already exists");
770772
return "File already exists";
771773
}
@@ -794,9 +796,9 @@ public void onBackPressed() {
794796
*/
795797
private String saveDraft() {
796798

797-
assert ( findViewById(R.id.author_name)) != null;
799+
assert (findViewById(R.id.author_name)) != null;
798800
String author = ((EditText) findViewById(R.id.author_name)).getText().toString();
799-
assert ( findViewById(R.id.template_title)) != null;
801+
assert (findViewById(R.id.template_title)) != null;
800802
String title = ((EditText) findViewById(R.id.template_title)).getText().toString();
801803

802804

@@ -826,6 +828,7 @@ private String saveDraft() {
826828
doc.appendChild(rootElement);
827829
Element dataElement = doc.createElement("data");
828830
rootElement.appendChild(dataElement);
831+
829832
if (selectedTemplate.getItems(doc).size() == 0) {
830833
Toast.makeText(this, "Unable to perform action: No Data", Toast.LENGTH_SHORT).show();
831834
return null;
@@ -834,6 +837,10 @@ private String saveDraft() {
834837
Toast.makeText(this, "Unable to perform action: No Meta Details", Toast.LENGTH_SHORT).show();
835838
return null;
836839
}
840+
if (templateId == 7 && selectedTemplate.getItems(doc).size() == 2) {
841+
Toast.makeText(this, "Please enter atleast 2 items", Toast.LENGTH_SHORT).show();
842+
return null;
843+
}
837844
for (Element item : selectedTemplate.getItems(doc)) {
838845
dataElement.appendChild(item);
839846
}
@@ -884,9 +891,7 @@ private void startSimulator() {
884891
if (message == null || message.equals("")) {
885892
Toast.makeText(this, "Build unsuccessful", Toast.LENGTH_SHORT).show();
886893
return;
887-
}
888-
else if("File already exists".equals(message))
889-
{
894+
} else if ("File already exists".equals(message)) {
890895
titleEditText.setError("Template Already exists");
891896
return;
892897
}

0 commit comments

Comments
 (0)