|
@@ -22,7 +22,7 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
|
|
public class MainActivity extends AppCompatActivity implements WordCardDelegate, TextWatcher {
|
|
|
|
|
|
private RecyclerView wordListView;
|
|
|
- private FloatingActionButton plusButton;
|
|
|
+ private FloatingActionButton plusButton, helpButton;
|
|
|
private EditText findInput;
|
|
|
private DBHelper db;
|
|
|
private DBAdapter wordAdapter;
|
|
@@ -42,6 +42,16 @@ public class MainActivity extends AppCompatActivity implements WordCardDelegate,
|
|
|
wordListView.setLayoutManager(new LinearLayoutManager(this));
|
|
|
wordListView.addItemDecoration(new SpacesItemDecoration(dip2px(getBaseContext(), 20)));
|
|
|
plusButton.setOnClickListener(view -> plusButtonClicked());
|
|
|
+ helpButton = findViewById(R.id.helpButton);
|
|
|
+ helpButton.setOnClickListener(view -> {
|
|
|
+ TextView text = new TextView(this);
|
|
|
+ text.setText("这是帮助");
|
|
|
+ new AlertDialog.Builder(this)
|
|
|
+ .setTitle("帮助")
|
|
|
+ .setView(text)
|
|
|
+ .setPositiveButton("好", null)
|
|
|
+ .show();
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
private int dip2px(Context context, float dpValue) {
|
|
@@ -53,7 +63,7 @@ public class MainActivity extends AppCompatActivity implements WordCardDelegate,
|
|
|
void finish();
|
|
|
}
|
|
|
|
|
|
- private void showDialog(PreparedWord word, FinishCallBack finishCallBack) {
|
|
|
+ private void showDialog(PreparedWord word, String title, FinishCallBack finishCallBack) {
|
|
|
View view = LayoutInflater.from(this).inflate(R.layout.dialog_add_word, null, false);
|
|
|
EditText wordName = view.findViewById(R.id.addWordName),
|
|
|
wordTranslate = view.findViewById(R.id.addWordTranslate),
|
|
@@ -62,7 +72,7 @@ public class MainActivity extends AppCompatActivity implements WordCardDelegate,
|
|
|
wordTranslate.setText(word.getTranslate());
|
|
|
wordExample.setText(word.getExample());
|
|
|
new AlertDialog.Builder(this)
|
|
|
- .setTitle("新建单词")
|
|
|
+ .setTitle(title)
|
|
|
.setView(view)
|
|
|
.setPositiveButton("确定", (dialogInterface, i) -> {
|
|
|
word.setWord(wordName.getText().toString());
|
|
@@ -76,7 +86,7 @@ public class MainActivity extends AppCompatActivity implements WordCardDelegate,
|
|
|
|
|
|
private void plusButtonClicked() {
|
|
|
PreparedWord word = new PreparedWord();
|
|
|
- showDialog(word, () -> {
|
|
|
+ showDialog(word, "新建单词", () -> {
|
|
|
db.addWord(word);
|
|
|
this.wordAdapter.updateWordList();
|
|
|
this.wordAdapter.notifyDataSetChanged();
|
|
@@ -98,7 +108,7 @@ public class MainActivity extends AppCompatActivity implements WordCardDelegate,
|
|
|
|
|
|
@Override
|
|
|
public void onEdit(Word word, int position) {
|
|
|
- showDialog(word, () -> {
|
|
|
+ showDialog(word, "修改单词", () -> {
|
|
|
db.editWord(word.getId(), word);
|
|
|
this.wordAdapter.updateWordList();
|
|
|
this.wordAdapter.notifyItemChanged(position);
|