Compare commits
6 Commits
main
...
UserActivi
| Author | SHA1 | Date |
|---|---|---|
|
|
32852c46b1 | 2 years ago |
|
|
1726dacc6d | 2 years ago |
|
|
6eedd1f9b7 | 2 years ago |
|
|
eda62b9d82 | 2 years ago |
|
|
1be98d1797 | 2 years ago |
|
|
0d16caf812 | 2 years ago |
@ -0,0 +1,32 @@
|
|||||||
|
package com.grassroots.booktracker.activity;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
|
||||||
|
import com.grassroots.booktracker.R;
|
||||||
|
|
||||||
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
private Button homeButton;
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_main);
|
||||||
|
//初始化
|
||||||
|
homeButton= (Button) findViewById(R.id.button);
|
||||||
|
//注册事件
|
||||||
|
homeButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
//创建Intent 对象
|
||||||
|
Intent intent=new Intent(MainActivity.this,LoginActivity.class);
|
||||||
|
//启动Activity
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,72 @@
|
|||||||
|
package com.grassroots.booktracker.activity;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import com.grassroots.booktracker.R;
|
||||||
|
|
||||||
|
public class NavActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_nav);
|
||||||
|
TextView tvBack = findViewById(R.id.tv_back);
|
||||||
|
tvBack.setVisibility(View.GONE);
|
||||||
|
TextView tvTitle = findViewById(R.id.tv_main_title);
|
||||||
|
tvTitle.setText("页面导航");
|
||||||
|
|
||||||
|
Button btnUserInfo = findViewById(R.id.btn_user_info);
|
||||||
|
btnUserInfo.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
//创建Intent 对象
|
||||||
|
Intent intent = new Intent(NavActivity.this, UserActivity.class);
|
||||||
|
//启动Activity
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Button btnBookRecommend = findViewById(R.id.btn_book_recommend);
|
||||||
|
btnBookRecommend.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
//创建Intent 对象
|
||||||
|
Intent intent = new Intent(NavActivity.this, SuggestActivity.class);
|
||||||
|
//启动Activity
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Button btnNoticeRemind = findViewById(R.id.btn_notice_remind);
|
||||||
|
btnNoticeRemind.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
Toast.makeText(NavActivity.this, "功能开发中", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Button btnPermissionManage = findViewById(R.id.btn_permission_manage);
|
||||||
|
btnPermissionManage.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
Toast.makeText(NavActivity.this, "功能开发中", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Button btnLogout = findViewById(R.id.btn_logout);
|
||||||
|
btnLogout.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
//创建Intent 对象
|
||||||
|
Intent intent = new Intent(NavActivity.this, LoginActivity.class);
|
||||||
|
//启动Activity
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,58 @@
|
|||||||
|
package com.grassroots.booktracker.activity;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import com.grassroots.booktracker.R;
|
||||||
|
import com.grassroots.booktracker.adapter.Suggest;
|
||||||
|
import com.grassroots.booktracker.adapter.SuggestAdapter;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class SuggestActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_suggest);
|
||||||
|
TextView tvTitle = findViewById(R.id.tv_main_title);
|
||||||
|
tvTitle.setText("图书推荐");
|
||||||
|
TextView tvBack = findViewById(R.id.tv_back);
|
||||||
|
tvBack.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
SuggestActivity.this.finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
RecyclerView rvSuggest = findViewById(R.id.rv_suggest);
|
||||||
|
SuggestAdapter suggestAdapter = new SuggestAdapter();
|
||||||
|
rvSuggest.setAdapter(suggestAdapter);
|
||||||
|
rvSuggest.setLayoutManager(new LinearLayoutManager(this));
|
||||||
|
|
||||||
|
List<Suggest> suggestList = new ArrayList<>();
|
||||||
|
suggestList.add(new Suggest(R.mipmap.book1, "梭罗著外国经典名著小说文学书籍八年级书目外国小说文学作品集名家名译 原著原版全中文完整版图书课外阅读知识读物"));
|
||||||
|
suggestList.add(new Suggest(R.mipmap.book2, "人性的弱点全集全本无删减版卡耐基著优点人生哲理书籍"));
|
||||||
|
suggestList.add(new Suggest(R.mipmap.book3, "厚黑学李宗吾著文学大师林语堂先生鼎力推荐说话的艺术成功学 成功励志高情商"));
|
||||||
|
suggestList.add(new Suggest(R.mipmap.book4, "彩图版中国历史书籍中华上下五千年全套古代史时间简史资治通鉴史记故事青少年成人历史书籍朝代故事"));
|
||||||
|
suggestList.add(new Suggest(R.mipmap.book1, "梭罗著外国经典名著小说文学书籍八年级书目外国小说文学作品集名家名译 原著原版全中文完整版图书课外阅读知识读物"));
|
||||||
|
suggestList.add(new Suggest(R.mipmap.book2, "人性的弱点全集全本无删减版卡耐基著优点人生哲理书籍"));
|
||||||
|
suggestList.add(new Suggest(R.mipmap.book3, "厚黑学李宗吾著文学大师林语堂先生鼎力推荐说话的艺术成功学 成功励志高情商"));
|
||||||
|
suggestList.add(new Suggest(R.mipmap.book4, "彩图版中国历史书籍中华上下五千年全套古代史时间简史资治通鉴史记故事青少年成人历史书籍朝代故事"));
|
||||||
|
suggestList.add(new Suggest(R.mipmap.book1, "梭罗著外国经典名著小说文学书籍八年级书目外国小说文学作品集名家名译 原著原版全中文完整版图书课外阅读知识读物"));
|
||||||
|
suggestList.add(new Suggest(R.mipmap.book2, "人性的弱点全集全本无删减版卡耐基著优点人生哲理书籍"));
|
||||||
|
suggestList.add(new Suggest(R.mipmap.book3, "厚黑学李宗吾著文学大师林语堂先生鼎力推荐说话的艺术成功学 成功励志高情商"));
|
||||||
|
suggestList.add(new Suggest(R.mipmap.book4, "彩图版中国历史书籍中华上下五千年全套古代史时间简史资治通鉴史记故事青少年成人历史书籍朝代故事"));
|
||||||
|
suggestList.add(new Suggest(R.mipmap.book1, "梭罗著外国经典名著小说文学书籍八年级书目外国小说文学作品集名家名译 原著原版全中文完整版图书课外阅读知识读物"));
|
||||||
|
suggestList.add(new Suggest(R.mipmap.book2, "人性的弱点全集全本无删减版卡耐基著优点人生哲理书籍"));
|
||||||
|
suggestList.add(new Suggest(R.mipmap.book3, "厚黑学李宗吾著文学大师林语堂先生鼎力推荐说话的艺术成功学 成功励志高情商"));
|
||||||
|
suggestList.add(new Suggest(R.mipmap.book4, "彩图版中国历史书籍中华上下五千年全套古代史时间简史资治通鉴史记故事青少年成人历史书籍朝代故事"));
|
||||||
|
suggestAdapter.setSuggestList(suggestList);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,226 @@
|
|||||||
|
package com.grassroots.booktracker.activity;
|
||||||
|
|
||||||
|
import android.content.ContentValues;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import com.grassroots.booktracker.R;
|
||||||
|
import com.grassroots.booktracker.adapter.BookInfo;
|
||||||
|
import com.grassroots.booktracker.adapter.BookInfoAdapter;
|
||||||
|
import com.grassroots.booktracker.utils.DatabaseHelper;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class UserActivity extends AppCompatActivity {
|
||||||
|
private Button insertButton, updateButton, searchButton, deleteButton;
|
||||||
|
private EditText name, day;
|
||||||
|
|
||||||
|
private RecyclerView rvBookInfo;
|
||||||
|
|
||||||
|
private TextView tvCount ,tvDays;
|
||||||
|
|
||||||
|
private BookInfoAdapter bookInfoAdapter;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_user);
|
||||||
|
TextView tvTitle = findViewById(R.id.tv_main_title);
|
||||||
|
tvTitle.setText("借阅信息");
|
||||||
|
TextView tvBack = findViewById(R.id.tv_back);
|
||||||
|
tvBack.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
TextView tvUsername = findViewById(R.id.tv_username);
|
||||||
|
String loginUserName = getSharedPreferences("loginInfo", MODE_PRIVATE).getString("loginUserName", "");
|
||||||
|
tvUsername.setText(loginUserName);
|
||||||
|
|
||||||
|
rvBookInfo = findViewById(R.id.rv_book_info);
|
||||||
|
insertButton = findViewById(R.id.btn_insert);
|
||||||
|
updateButton = findViewById(R.id.btn_update);
|
||||||
|
searchButton = findViewById(R.id.btn_search);
|
||||||
|
deleteButton = findViewById(R.id.btn_delete);
|
||||||
|
name = findViewById(R.id.name);
|
||||||
|
day = findViewById(R.id.day);
|
||||||
|
tvCount = findViewById(R.id.tv_count);
|
||||||
|
tvDays = findViewById(R.id.tv_days);
|
||||||
|
|
||||||
|
tvCount.setText("共借阅"+getCount()+"本");
|
||||||
|
tvDays.setText("共借阅"+getAllDays()+"天");
|
||||||
|
|
||||||
|
initRv();
|
||||||
|
|
||||||
|
SQLiteDatabase db = DatabaseHelper.getInstance().getReadableDatabase();
|
||||||
|
|
||||||
|
myShow();
|
||||||
|
|
||||||
|
|
||||||
|
insertButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (TextUtils.isEmpty(name.getText().toString())){
|
||||||
|
Toast.makeText(UserActivity.this, "请输入书名", Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (TextUtils.isEmpty(day.getText().toString())){
|
||||||
|
Toast.makeText(UserActivity.this, "请输入借阅天数", Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SQLiteDatabase db = DatabaseHelper.getInstance().getWritableDatabase();
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
values.put("name", name.getText().toString());
|
||||||
|
values.put("days", day.getText().toString());
|
||||||
|
long id = db.insert("information", null, values);
|
||||||
|
Log.d("myDeBug", "insert");
|
||||||
|
|
||||||
|
myShow();
|
||||||
|
|
||||||
|
|
||||||
|
db.close();
|
||||||
|
name.setText(null);
|
||||||
|
day.setText(null);
|
||||||
|
|
||||||
|
tvCount.setText("共借阅"+getCount()+"本");
|
||||||
|
tvDays.setText("共借阅"+getAllDays()+"天");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
updateButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
|
||||||
|
if (TextUtils.isEmpty(name.getText().toString())){
|
||||||
|
Toast.makeText(UserActivity.this, "请输入书名", Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (TextUtils.isEmpty(day.getText().toString())){
|
||||||
|
Toast.makeText(UserActivity.this, "请输入借阅天数", Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SQLiteDatabase db = DatabaseHelper.getInstance().getWritableDatabase();
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
values.put("days", day.getText().toString());
|
||||||
|
db.update("information", values, "name=?", new String[]{name.getText().toString()});
|
||||||
|
|
||||||
|
myShow();
|
||||||
|
|
||||||
|
|
||||||
|
db.close();
|
||||||
|
Log.d("myDebug", "update");
|
||||||
|
name.setText(null);
|
||||||
|
day.setText(null);
|
||||||
|
|
||||||
|
tvCount.setText("共借阅"+getCount()+"本");
|
||||||
|
tvDays.setText("共借阅"+getAllDays()+"天");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
searchButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
|
||||||
|
if (TextUtils.isEmpty(name.getText().toString())){
|
||||||
|
Toast.makeText(UserActivity.this, "请输入书名", Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SQLiteDatabase db = DatabaseHelper.getInstance().getWritableDatabase();
|
||||||
|
String name1 = name.getText().toString();
|
||||||
|
if (name1.equals("")) {
|
||||||
|
myShow();
|
||||||
|
db.close();
|
||||||
|
} else {
|
||||||
|
Cursor cursor = db.rawQuery("select * from information where name = ? ", new String[]{name1});
|
||||||
|
|
||||||
|
List<BookInfo> bookInfoList=new ArrayList<>();
|
||||||
|
while (cursor.moveToNext()) {
|
||||||
|
String newName = cursor.getString(1);
|
||||||
|
int newDays = cursor.getInt(2);
|
||||||
|
bookInfoList.add(new BookInfo(newName,newDays));
|
||||||
|
}
|
||||||
|
bookInfoAdapter.setBookInfoList(bookInfoList);
|
||||||
|
|
||||||
|
cursor.close();
|
||||||
|
db.close();
|
||||||
|
name.setText(null);
|
||||||
|
day.setText(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
deleteButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
|
||||||
|
if (TextUtils.isEmpty(name.getText().toString())){
|
||||||
|
Toast.makeText(UserActivity.this, "请输入书名", Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SQLiteDatabase db = DatabaseHelper.getInstance().getWritableDatabase();
|
||||||
|
db.delete("information", "name=?", new String[]{name.getText().toString()});
|
||||||
|
|
||||||
|
|
||||||
|
myShow();
|
||||||
|
|
||||||
|
|
||||||
|
db.close();
|
||||||
|
Log.d("myDeBug", "DeleteSuccess");
|
||||||
|
name.setText(null);
|
||||||
|
day.setText(null);
|
||||||
|
|
||||||
|
tvCount.setText("共借阅"+getCount()+"本");
|
||||||
|
tvDays.setText("共借阅"+getAllDays()+"天");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getCount(){
|
||||||
|
SQLiteDatabase db = DatabaseHelper.getInstance().getReadableDatabase();
|
||||||
|
Cursor cursor = db.rawQuery("select count(*) from information", null);
|
||||||
|
cursor.moveToFirst();
|
||||||
|
int count = cursor.getInt(0);
|
||||||
|
cursor.close();
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getAllDays(){
|
||||||
|
SQLiteDatabase db = DatabaseHelper.getInstance().getReadableDatabase();
|
||||||
|
Cursor cursor = db.rawQuery("select sum(days) from information", null);
|
||||||
|
cursor.moveToFirst();
|
||||||
|
int count = cursor.getInt(0);
|
||||||
|
cursor.close();
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initRv(){
|
||||||
|
bookInfoAdapter = new BookInfoAdapter();
|
||||||
|
rvBookInfo.setAdapter(bookInfoAdapter);
|
||||||
|
rvBookInfo.setLayoutManager(new LinearLayoutManager(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void myShow() {
|
||||||
|
SQLiteDatabase db = DatabaseHelper.getInstance().getReadableDatabase();
|
||||||
|
Cursor cursor = db.rawQuery("select * from information", null);
|
||||||
|
List<BookInfo> bookInfoList=new ArrayList<>();
|
||||||
|
while (cursor.moveToNext()) {
|
||||||
|
String newName = cursor.getString(1);
|
||||||
|
int newDays = cursor.getInt(2);
|
||||||
|
bookInfoList.add(new BookInfo(newName,newDays));
|
||||||
|
}
|
||||||
|
cursor.close();
|
||||||
|
bookInfoAdapter.setBookInfoList(bookInfoList);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in new issue