Skip to content

Commit

Permalink
Use config file for strings
Browse files Browse the repository at this point in the history
  • Loading branch information
LucBerge committed Sep 13, 2023
1 parent 84953d5 commit 8bd8df6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,8 @@
import com.example.ideator.ui.ideas.IdeasViewModel;

public class EditIdeaActivity extends AppCompatActivity {
public static final int RESULT_DELETE = 1;
public static final long INVALID_ID = -1;
public static final String EXTRA_ID = "com.example.ideator.ui.edit_idea.EXTRA_ID";
public static final String EXTRA_TITLE = "com.example.ideator.ui.edit_idea.EXTRA_TITLE";
public static final String EXTRA_DESCRIPTION = "com.example.ideator.ui.edit_idea.EXTRA_DESCRIPTION";
public static final String EXTRA_PROBLEMATIC = "com.example.ideator.ui.edit_idea.EXTRA_PROBLEMATIC";
public static final String EXTRA_SOLUTION = "com.example.ideator.ui.edit_idea.EXTRA_SOLUTION";

private EditText titleText;
private EditText descriptionText;
Expand Down Expand Up @@ -81,6 +76,7 @@ protected void onCreate(Bundle savedInstanceState) {
}
});

//TODO load idea title and make in editable
setTitle("Edit idea");
}

Expand Down Expand Up @@ -116,21 +112,21 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
editIdeaViewModel.update(idea);
setResult(RESULT_OK);
finish();
Toast.makeText(this, "Idea saved", Toast.LENGTH_SHORT).show();
Toast.makeText(this, R.string.saved_idea, Toast.LENGTH_SHORT).show();
return true;
}
}

private void confirmDeleteIdea() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(true);
builder.setTitle("Delete");
builder.setMessage("Are you sure you want to delete the idea? This action cannot be reversed!");
builder.setPositiveButton("Confirm", (dialog, which) -> {
builder.setTitle(R.string.delete_idea);
builder.setMessage(R.string.delete_idea_confirm);
builder.setPositiveButton(android.R.string.ok, (dialog, which) -> {
editIdeaViewModel.delete(idea.idea);
setResult(RESULT_OK);
finish();
Toast.makeText(this, "Idea deleted", Toast.LENGTH_SHORT).show();
Toast.makeText(this, R.string.deleted_idea, Toast.LENGTH_SHORT).show();
});
builder.setNegativeButton(android.R.string.cancel, (dialog, which) -> {
//Nothing to do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
public void onClick(View view) {
final EditText descriptionText = new EditText(getActivity());
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("New idea");
builder.setMessage("Describe your idea in a short sentence");
builder.setTitle(R.string.new_idea);
builder.setMessage(R.string.new_idea_instruction);
builder.setView(descriptionText);
builder.setPositiveButton("Create", (DialogInterface.OnClickListener) (dialog, whichButton) -> {
builder.setPositiveButton(R.string.create_idea, (DialogInterface.OnClickListener) (dialog, whichButton) -> {
ProgressDialog progressDialog = new ProgressDialog(context);
progressDialog.setMessage("Enhancing your business idea...");
progressDialog.setMessage(getContext().getText(R.string.create_idea_loading));
progressDialog.setCancelable(false);
progressDialog.setInverseBackgroundForced(false);

Expand All @@ -109,7 +109,7 @@ public void onSuccess(String title, String description, String problematic, Stri
public void onError(Throwable error) {
error.printStackTrace();
Toast.makeText(getActivity(),
"Something went wrong. Are you connected to the internet?",
R.string.error_offline,
Toast.LENGTH_LONG).show();

progressDialog.hide();
Expand All @@ -121,9 +121,6 @@ public void onError(Throwable error) {
});
progressDialog.show();
});
builder.setNegativeButton("Cancel", (DialogInterface.OnClickListener) (dialog, whichButton) -> {
//Nothing to do
});
builder.create().show();
}
});
Expand All @@ -149,7 +146,7 @@ public void onActivityResult(int requestCode, int resultCode, @Nullable Intent d
super.onActivityResult(requestCode, resultCode, data);

if (resultCode != RESULT_OK) {
Toast.makeText(getActivity(), "Something went wrong", Toast.LENGTH_LONG).show();
Toast.makeText(getActivity(), R.string.error, Toast.LENGTH_LONG).show();
}
}
}
16 changes: 16 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,20 @@
<string name="menu_about">About</string>

<string name="empty_ideas">You do not have ideas yet. Click the "+" button to create your first idea.</string>


<string name="new_idea">New idea</string>
<string name="new_idea_instruction">Describe your idea in a short sentence</string>
<string name="create_idea">Create</string>
<string name="create_idea_loading">Enhancing your business idea...</string>

<string name="saved_idea">Idea deleted</string>

<string name="delete_idea">Delete</string>
<string name="delete_idea_confirm">You are about to definitely delete your idea. This action cannot be reversed!</string>
<string name="deleted_idea">Idea deleted</string>


<string name="error">Something went wrong</string>
<string name="error_offline">Something went wrong. Are you offline?</string>
</resources>

0 comments on commit 8bd8df6

Please sign in to comment.