相关视频教程在某站上面(🔍浩宇软件开发)
1. 项目功能思维导图
2. 项目涉及到的技术点
- 使用CountDownTimer实现开屏页倒计时
- 使用SQLite数据库存储数据
- 使用BottomNavigationView实现底部导航栏
- 使用Activity+Fragment实现底部导航栏页面切换
- 使用RecyclerView+adapter实现首页,搜索页列表
- 使用AlertDialog实现置顶,编辑,删除单选功能
- 使用CardView实现卡片,头像圆角效果
- 使用Toolbar实现顶部标题栏
3. 项目运行效果图
4. 项目部分功能实现
- 新建页面
public class CreateNoteActivity extends BaseActivity {
private EditText et_note_title;
private EditText et_note_content;
private Toolbar toolbar;
private Button btn_submit;
private NoteInfo noteInfo;
@Override
protected int getLayoutResId() {
return R.layout.activity_create_note;
}
@Override
protected void initViews() {
et_note_title = findViewById(R.id.et_note_title);
et_note_content = findViewById(R.id.et_note_content);
toolbar = findViewById(R.id.toolbar);
btn_submit = findViewById(R.id.btn_submit);
}
@Override
protected void setListener() {
//返回
toolbar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
btn_submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String title = et_note_title.getText().toString();
String content = et_note_content.getText().toString();
if (TextUtils.isEmpty(title) || TextUtils.isEmpty(content)) {
Toast.makeText(CreateNoteActivity.this, "请完善信息~~", Toast.LENGTH_SHORT).show();
} else {
UserInfo userInfo = UserInfo.getUserInfo();
if (noteInfo == null) {
int row = NoteDbHelper.getInstance(CreateNoteActivity.this).createNote(userInfo.getUsername(), title, content);
if (row > 0) {
Toast.makeText(CreateNoteActivity.this, "创建成功~~", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(CreateNoteActivity.this, "创建失败~~", Toast.LENGTH_SHORT).show();
}
} else {
int row = NoteDbHelper.getInstance(CreateNoteActivity.this).editNote(noteInfo.getNote_id(), title, content);
if (row > 0) {
Toast.makeText(CreateNoteActivity.this, "修改成功~~", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(CreateNoteActivity.this, "修改成功~~", Toast.LENGTH_SHORT).show();
}
}
setResult(1000);
finish();
}
}
});
}
@Override
protected void initData() {
//跳转传值
noteInfo = (NoteInfo) getIntent().getSerializableExtra("noteInfo");
if (noteInfo != null) {
toolbar.setTitle("编辑备忘录");
btn_submit.setText("编辑");
et_note_title.setText(noteInfo.getNote_title());
et_note_content.setText(noteInfo.getNote_content());
}
}
}
- 搜索页面
public class SearchFragment extends BaseFragment {
private EditText et_search;
private RecyclerView recyclerView;
private LinearLayoutCompat ll_empty;
private SearchListAdapter mListAdapter;
@Override
protected int getLayoutResId() {
return R.layout.fragment_search;
}
@Override
protected void initView() {
et_search = rootView.findViewById(R.id.et_search);
ll_empty = rootView.findViewById(R.id.ll_empty);
recyclerView = rootView.findViewById(R.id.recyclerView);
//初始化适配器
mListAdapter = new SearchListAdapter();
//设置适配器
recyclerView.setAdapter(mListAdapter);
//mListAdapter点击事件
mListAdapter.setOnItemClickListener(new SearchListAdapter.onItemClickListener() {
@Override
public void onItemClick(int position, NoteInfo noteInfo) {
Intent intent = new Intent(getActivity(), NoteDetailsActivity.class);
intent.putExtra("noteInfo", noteInfo);
startActivity(intent);
}
});
}
@Override
protected void setListener() {
rootView.findViewById(R.id.btn_search).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String content = et_search.getText().toString();
if (TextUtils.isEmpty(content)) {
Toast.makeText(getActivity(), "搜索内容不能为空~", Toast.LENGTH_SHORT).show();
} else {
List<NoteInfo> noteInfoList = NoteDbHelper.getInstance(getActivity()).searchNote(content);
if (null != mListAdapter) {
mListAdapter.setNoteInfoList(noteInfoList);
}
if (noteInfoList.size() == 0) {
ll_empty.setVisibility(View.VISIBLE);
} else {
ll_empty.setVisibility(View.GONE);
}
}
}
});
}
@Override
protected void initData() {
}
}
- 修改密码页面
public class UpdatePwdActivity extends BaseActivity {
private EditText et_new_password;
private EditText et_confirm_password;
@Override
protected int getLayoutResId() {
return R.layout.activity_update_pwd;
}
@Override
protected void initViews() {
//初始化控件
et_new_password = findViewById(R.id.et_new_password);
et_confirm_password = findViewById(R.id.et_confirm_password);
}
@Override
protected void setListener() {
//返回
findViewById(R.id.toolbar).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
findViewById(R.id.btn_update_pwd).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String new_pwd = et_new_password.getText().toString();
String confirm_pwd = et_confirm_password.getText().toString();
if (TextUtils.isEmpty(new_pwd) || TextUtils.isEmpty(confirm_pwd)) {
Toast.makeText(UpdatePwdActivity.this, "信息不能为空", Toast.LENGTH_SHORT).show();
} else if (!new_pwd.equals(confirm_pwd)) {
Toast.makeText(UpdatePwdActivity.this, "新密码和确认密码不一致", Toast.LENGTH_SHORT).show();
} else {
UserInfo userInfo = UserInfo.getUserInfo();
if (null != userInfo) {
int row = UserDbHelper.getInstance(UpdatePwdActivity.this).updatePwd(userInfo.getUsername(), new_pwd);
if (row > 0) {
Toast.makeText(UpdatePwdActivity.this, "密码修改成功,请重新登录", Toast.LENGTH_SHORT).show();
//回传的时候要用 startActivityForResult启动一个页面,并且在该页面要设置setResult
setResult(2000);
finish();
} else {
Toast.makeText(UpdatePwdActivity.this, "修改失败", Toast.LENGTH_SHORT).show();
}
}
}
}
});
}
@Override
protected void initData() {
}
}