Skip to content

Fixes a part of #279. #399

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

Open
wants to merge 2 commits into
base: bug-fixes
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ protected void onCreate(Bundle savedInstanceState) {
pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
String version = pInfo.versionName;
assert findViewById(R.id.app_version) != null;
((TextView) findViewById(R.id.app_version)).setText(String.format(Locale.ENGLISH, "Version: %s", version));
((TextView) findViewById(R.id.app_version)).setText(String.format(Locale.ENGLISH, getString(R.string.version)+"%s", version));
} catch (PackageManager.NameNotFoundException e) {
assert findViewById(R.id.app_version) != null;
assert ( findViewById(R.id.app_version)) != null;
((TextView) findViewById(R.id.app_version)).setText("Version: 1.0");
((TextView) findViewById(R.id.app_version)).setText(getString(R.string.version)+"1.0");
e.printStackTrace();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.util.Log;
import android.widget.Toast;

import org.buildmlearn.toolkit.R;
import org.buildmlearn.toolkit.constant.Constants;
import org.buildmlearn.toolkit.model.SavedProject;
import org.buildmlearn.toolkit.model.Template;
Expand Down Expand Up @@ -57,7 +58,7 @@ protected void onCreate(Bundle savedInstanceState) {
return;
}
}
Toast.makeText(this, "Invalid project file", Toast.LENGTH_SHORT).show();
Toast.makeText(this, getString(R.string.project_invalid), Toast.LENGTH_SHORT).show();
finish();
} catch (ParserConfigurationException | IOException | SAXException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class TemplateEditor extends AppCompatActivity implements TemplateEditorI
private final Handler handlerToast = new Handler() {
public void handleMessage(Message message) {
if (message.arg1 == -1) {
Toast.makeText(TemplateEditor.this, "Build unsuccessful", Toast.LENGTH_SHORT).show();
Toast.makeText(TemplateEditor.this, getString(R.string.build_fail), Toast.LENGTH_SHORT).show();
}
}
};
Expand Down Expand Up @@ -188,15 +188,15 @@ private void saveApk() {
signer.setSignerThreadListener(new SignerThread.OnSignComplete() {
@Override
public void onSuccess(final String path) {
Log.d(TAG, "APK generated");
Log.d(TAG, getString(R.string.apk_generated));
mApkGenerationDialog.dismiss();
runOnUiThread(new Runnable() {
@Override
public void run() {
AlertDialog dialog = new AlertDialog.Builder(TemplateEditor.this)
.setTitle("Apk Generated")
.setMessage("Apk file saved at " + path + "\nFind it any time under Saved APKs\nInstall now?")
.setNegativeButton("later", new DialogInterface.OnClickListener() {
.setTitle(getString(R.string.apk_generated))
.setMessage(getString(R.string.apk_saved_at) + path)
.setPositiveButton(getString(R.string.info_template_ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
Expand Down Expand Up @@ -256,7 +256,7 @@ private void shareApk() {
signer.setSignerThreadListener(new SignerThread.OnSignComplete() {
@Override
public void onSuccess(final String path) {
Log.d(TAG, "APK generated");
Log.d(TAG, getString(R.string.apk_generated));
mApkGenerationDialog.dismiss();

Uri fileUri = Uri.fromFile(new File(path));
Expand Down Expand Up @@ -327,7 +327,7 @@ protected void onCreate(Bundle savedInstanceState) {
toolkit = (ToolkitApplication) getApplicationContext();
templateId = getIntent().getIntExtra(Constants.TEMPLATE_ID, -1);
if (templateId == -1) {
Toast.makeText(this, "Invalid template ID, closing Template Editor activity", Toast.LENGTH_LONG).show();
Toast.makeText(this, getString(R.string.invalid_template_id), Toast.LENGTH_LONG).show();
finish();
}

Expand Down Expand Up @@ -804,6 +804,87 @@ private String saveProject() {
} catch (ParserConfigurationException e) {
e.printStackTrace();

EditText authorEditText = (EditText) findViewById(R.id.author_name);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@octacode
Why you make changes here?
Travis is failing, check the log here : https://travis-ci.org/BuildmLearn/BuildmLearn-Toolkit-Android/builds/211018551

titleEditText = (EditText) findViewById(R.id.template_title);
assert findViewById(R.id.author_name) != null;
assert ( findViewById(R.id.author_name)) != null;
String author = ((EditText) findViewById(R.id.author_name)).getText().toString();
assert findViewById(R.id.template_title) != null;
assert ( findViewById(R.id.template_title)) != null;
String title = ((EditText) findViewById(R.id.template_title)).getText().toString();
if ("".equals(author)) {
assert authorEditText != null;
authorEditText.setError(getString(R.string.author_name_error));
} else if ("".equals(title)) {
assert titleEditText != null;
titleEditText.setError(getResources().getString(R.string.title_error));
} else if (!Character.isLetterOrDigit(author.charAt(0))) {
assert authorEditText != null;
authorEditText.setError(getResources().getString(R.string.valid_msg));
} else if (!Character.isLetterOrDigit(title.charAt(0))) {
assert titleEditText != null;
titleEditText.setError(getString(R.string.title_valid));
} else {

DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder;
try {

docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
Element rootElement = doc.createElement("buildmlearn_application");
Attr attr = doc.createAttribute("type");
attr.setValue(getResources().getString(template.getType()));
rootElement.setAttributeNode(attr);

Element authorElement = doc.createElement("author");
rootElement.appendChild(authorElement);

Element nameElement = doc.createElement("name");
nameElement.appendChild(doc.createTextNode(author));

authorElement.appendChild(nameElement);

Element titleElement = doc.createElement("title");
titleElement.appendChild(doc.createTextNode(title));
rootElement.appendChild(titleElement);

doc.appendChild(rootElement);
Element dataElement = doc.createElement("data");
rootElement.appendChild(dataElement);
if (selectedTemplate.getItems(doc).size() == 0 || (selectedTemplate.getItems(doc).size() < 2 && (templateId == 5 || templateId == 7))) {
Toast.makeText(this, getString(R.string.no_data), Toast.LENGTH_SHORT).show();
return null;
}
if (selectedTemplate.getItems(doc).get(0).getTagName().equals("item") && (templateId == 5 || templateId == 7)) {
Toast.makeText(this, getString(R.string.no_data_add_meta), Toast.LENGTH_SHORT).show();
return null;
}
for (Element item : selectedTemplate.getItems(doc)) {
dataElement.appendChild(item);
}
if (oldFileName != null) {
File tempFile = new File(oldFileName);
tempFile.delete();
oldFileName = null;
}
String saveFileName = title + " by " + author + ".buildmlearn";
saveFileName = saveFileName.replaceAll(" ", "-");


boolean isSaved=FileUtils.saveXmlFile(toolkit.getSavedDir(), saveFileName, doc);
if(isSaved) {
oldFileName = toolkit.getSavedDir() + saveFileName;
Toast.makeText(this, getString(R.string.project_saved), Toast.LENGTH_SHORT).show();
return oldFileName;
}
else {
titleEditText.setError(getString(R.string.file_already));
return getString(R.string.file_already);
}

} catch (ParserConfigurationException e) {
e.printStackTrace();
}
}
} catch (NullPointerException e) {
Expand All @@ -814,14 +895,14 @@ private String saveProject() {

@Override
public void onBackPressed() {

if (selectedView == null) {
super.onBackPressed();
if (saveDraft() != null)
Toast.makeText(getApplicationContext(), "Saved in Draft!", Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), getString(R.string.saved_in_drafts), Toast.LENGTH_SHORT).show();
} else {
restoreColorSchema();
}

}

/**
Expand Down Expand Up @@ -865,11 +946,11 @@ private String saveDraft() {
rootElement.appendChild(dataElement);

if (selectedTemplate.getItems(doc).size() == 0) {
Toast.makeText(this, "Unable to perform action: No Data", Toast.LENGTH_SHORT).show();
Toast.makeText(this, getString(R.string.no_data), Toast.LENGTH_SHORT).show();
return null;
}
if (selectedTemplate.getItems(doc).get(0).getTagName().equals("item") && (templateId == 5 || templateId == 7)) {
Toast.makeText(this, "Unable to perform action: No Meta Details", Toast.LENGTH_SHORT).show();
Toast.makeText(this, getString(R.string.no_data_add_meta), Toast.LENGTH_SHORT).show();
return null;
}
if (templateId == 7 && selectedTemplate.getItems(doc).size() == 2) {
Expand Down Expand Up @@ -924,10 +1005,12 @@ private String saveDraft() {
private void startSimulator() {
String message = saveProject();
if (message == null || message.equals("")) {
Toast.makeText(this, "Build unsuccessful", Toast.LENGTH_SHORT).show();
Toast.makeText(this, getString(R.string.build_fail), Toast.LENGTH_SHORT).show();
return;
} else if ("File already exists".equals(message)) {
titleEditText.setError("Template Already exists");
}
else if(getString(R.string.file_already).equals(message))
{
titleEditText.setError(getString(R.string.temp_already));
return;
}
Intent simulatorIntent = new Intent(getApplicationContext(), Simulator.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ public View getView(int position, View convertView, ViewGroup parent) {
}

SavedProject projectData = getItem(position);
holder.draftSubtitle.setText(String.format(Locale.ENGLISH, "Last Modified: %s", projectData.getTime()));
holder.draftTitle.setText(String.format(Locale.ENGLISH, "Drafted on %s", projectData.getDate()));
holder.draftSubtitle.setText(String.format(Locale.ENGLISH, mContext.getString(R.string.last_mod)+"%s", projectData.getTime()));
holder.draftTitle.setText(String.format(Locale.ENGLISH, mContext.getString(R.string.drafted_on)+"%s", projectData.getDate()));
holder.draftIcon.setText("D");
convertView.setTag(holder);
if (projectData.isSelected())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public boolean onMenuItemClick(MenuItem menuItem) {
new AlertDialog.Builder(getActivity());
builder.setTitle(String.format("%1$s", getString(R.string.comprehension_about_us)));
builder.setMessage(getResources().getText(R.string.comprehension_about_text));
builder.setPositiveButton("OK", null);
builder.setPositiveButton(getString(R.string.info_template_ok), null);
AlertDialog welcomeAlert = builder.create();
welcomeAlert.show();
assert welcomeAlert.findViewById(android.R.id.message) != null;
Expand All @@ -79,9 +79,9 @@ public boolean onMenuItemClick(MenuItem menuItem) {

db.close();

((TextView) rootView.findViewById(R.id.correct)).setText(String.format(Locale.getDefault(), "Total Correct : %1$d", stat[0]));
((TextView) rootView.findViewById(R.id.wrong)).setText(String.format(Locale.getDefault(), "Total Wrong : %1$d", stat[1]));
((TextView) rootView.findViewById(R.id.un_answered)).setText(String.format(Locale.getDefault(), "Total Unanswered : %1$d", stat[2]));
((TextView) rootView.findViewById(R.id.correct)).setText(String.format(Locale.getDefault(), getString(R.string.total_correct)+"%1$d", stat[0]));
((TextView) rootView.findViewById(R.id.wrong)).setText(String.format(Locale.getDefault(), getString(R.string.total_wrong)+"%1$d", stat[1]));
((TextView) rootView.findViewById(R.id.un_answered)).setText(String.format(Locale.getDefault(), getString(R.string.total_unanswered)+"%1$d", stat[2]));

rootView.findViewById(R.id.restart).setOnClickListener(new View.OnClickListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public boolean onMenuItemClick(MenuItem menuItem) {
new AlertDialog.Builder(getActivity());
builder.setTitle(String.format("%1$s", getString(R.string.comprehension_about_us)));
builder.setMessage(getResources().getText(R.string.comprehension_about_text));
builder.setPositiveButton("OK", null);
builder.setPositiveButton(getString(R.string.info_template_ok), null);
AlertDialog welcomeAlert = builder.create();
welcomeAlert.show();
assert welcomeAlert.findViewById(android.R.id.message) != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public boolean onMenuItemClick(MenuItem menuItem) {
new AlertDialog.Builder(getActivity());
builder.setTitle(String.format("%1$s", getString(R.string.comprehension_about_us)));
builder.setMessage(getResources().getText(R.string.comprehension_about_text));
builder.setPositiveButton("OK", null);
builder.setPositiveButton(getString(R.string.info_template_ok), null);
AlertDialog welcomeAlert = builder.create();
welcomeAlert.show();
assert welcomeAlert.findViewById(android.R.id.message) != null;
Expand Down Expand Up @@ -152,7 +152,7 @@ public boolean onMenuItemClick(MenuItem item) {
});
}

((TextView) rootView.findViewById(R.id.question_title)).setText(String.format(Locale.getDefault(), "Question No : %1$s", questionId));
((TextView) rootView.findViewById(R.id.question_title)).setText(String.format(Locale.getDefault(), getString(R.string.question_no)+"%1$s", questionId));
((TextView) rootView.findViewById(R.id.question)).setText(question);
if (optionOne != null) {
rootView.findViewById(R.id.radioButton1).setVisibility(View.VISIBLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public boolean onMenuItemClick(MenuItem menuItem) {
new AlertDialog.Builder(getActivity());
builder.setTitle(String.format("%1$s", getString(R.string.comprehension_about_us)));
builder.setMessage(getResources().getText(R.string.about_text_video));
builder.setPositiveButton("OK", null);
builder.setPositiveButton(getString(R.string.info_template_ok), null);
AlertDialog welcomeAlert = builder.create();
welcomeAlert.show();
assert welcomeAlert.findViewById(android.R.id.message) != null;
Expand Down Expand Up @@ -175,7 +175,7 @@ public void onLoadFinished(Loader<Cursor> loader, final Cursor data) {
public void onClick(View v) {
progress = new ProgressDialog(getActivity());
progress.setCancelable(false);
progress.setMessage("Loading TTS Engine...");
progress.setMessage(getString(R.string.loading_tts));
progress.show();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Expand Down Expand Up @@ -248,10 +248,10 @@ public void onInit(int status) {
int result = tts.setLanguage(Locale.US);
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
Toast.makeText(getContext(), "US English is not supported. Playing in device's default installed language.", Toast.LENGTH_SHORT).show();
Toast.makeText(getContext(), getString(R.string.tts_lang_not_supported), Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(getContext(), "Initialization Failed!", Toast.LENGTH_SHORT).show();
Toast.makeText(getContext(), getString(R.string.tts_failed), Toast.LENGTH_SHORT).show();
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
rootView = inflater.inflate(R.layout.fragment_main_dict, container, false);

Toolbar toolbar = (Toolbar) rootView.findViewById(R.id.card_toolbar);
toolbar.setTitle("List of Passages :");
toolbar.setTitle(getString(R.string.dict_toolbar_title));

Toolbar maintoolbar = (Toolbar) rootView.findViewById(R.id.toolbar_main);
final String result[] = DataUtils.readTitleAuthor();
Expand All @@ -99,7 +99,7 @@ public boolean onMenuItemClick(MenuItem menuItem) {
new AlertDialog.Builder(getActivity());
builder.setTitle(String.format("%1$s", getString(R.string.about_us_dict)));
builder.setMessage(getResources().getText(R.string.about_text_dict));
builder.setPositiveButton("OK", null);
builder.setPositiveButton(getString(R.string.info_template_ok), null);
AlertDialog welcomeAlert = builder.create();
welcomeAlert.show();
assert welcomeAlert.findViewById(android.R.id.message) != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public boolean onMenuItemClick(MenuItem menuItem) {
new AlertDialog.Builder(getActivity());
builder.setTitle(String.format("%1$s", getString(R.string.comprehension_about_us)));
builder.setMessage(getResources().getText(R.string.about_text_video));
builder.setPositiveButton("OK", null);
builder.setPositiveButton(getString(R.string.info_template_ok), null);
AlertDialog welcomeAlert = builder.create();
welcomeAlert.show();
assert welcomeAlert.findViewById(android.R.id.message) != null;
Expand Down Expand Up @@ -150,7 +150,7 @@ public void onLoadFinished(Loader<Cursor> loader, final Cursor data) {
String result[] = obj.diff_prettyHtml(llDiffs);

int numTWords = passage.split(" ").length;
((TextView) rootView.findViewById(R.id.score)).setText(String.format(Locale.ENGLISH, "SCORE : %s / %d", result[1], numTWords));
((TextView) rootView.findViewById(R.id.score)).setText(String.format(Locale.ENGLISH, getString(R.string.match_score)+"%s / %d", result[1], numTWords));

((TextView) rootView.findViewById(R.id.checked_text)).setText(Html.fromHtml(result[0]));

Expand Down
Loading