diff --git a/.idea/dictionaries/.xml b/.idea/dictionaries/.xml index 8ef0265..6273c96 100644 --- a/.idea/dictionaries/.xml +++ b/.idea/dictionaries/.xml @@ -2,6 +2,8 @@ descri + donatemon + recordlist sttmt diff --git a/app/src/main/java/hunnu/sj/raise_money/BrowseRecordActivity.java b/app/src/main/java/hunnu/sj/raise_money/BrowseRecordActivity.java index 97250df..0672c6a 100644 --- a/app/src/main/java/hunnu/sj/raise_money/BrowseRecordActivity.java +++ b/app/src/main/java/hunnu/sj/raise_money/BrowseRecordActivity.java @@ -1,15 +1,52 @@ package hunnu.sj.raise_money; +import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; +import android.content.Intent; import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.widget.ListView; -public class BrowseRecordActivity extends AppCompatActivity { +import java.util.ArrayList; + +import hunnu.sj.raise_money.donate_record.Record; +import hunnu.sj.raise_money.donate_record.RecordAdapter; +public class BrowseRecordActivity extends AppCompatActivity { + private ArrayList records = new ArrayList<>(); + private ListView lv_record; + private RecordAdapter recordAdapter; + private String username; + private Handler mhandler = new Handler(){ + @Override + public void handleMessage(@NonNull Message msg) { + super.handleMessage(msg); + if(msg.what==1){ + recordAdapter.notifyDataSetChanged(); + } + } + }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_browse_record); + Intent intent = getIntent(); + username = intent.getStringExtra("username"); + recordAdapter = new RecordAdapter(this,records); + lv_record = findViewById(R.id.lv_browse_denate_record); + lv_record.setAdapter(recordAdapter); + new BrowseRecordThread().start(); + } + class BrowseRecordThread extends Thread{ + @Override + public void run() { + Message msg =mhandler.obtainMessage(); + int flags = InfoUtils.getDonateRecords(records,username); + msg.what = flags; + mhandler.sendMessage(msg); + } } } diff --git a/app/src/main/java/hunnu/sj/raise_money/DataBase/UserService.java b/app/src/main/java/hunnu/sj/raise_money/DataBase/UserService.java index 9478733..8b2c3bf 100644 --- a/app/src/main/java/hunnu/sj/raise_money/DataBase/UserService.java +++ b/app/src/main/java/hunnu/sj/raise_money/DataBase/UserService.java @@ -10,7 +10,8 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; -import hunnu.sj.raise_money.News; +import hunnu.sj.raise_money.donate_record.Record; +import hunnu.sj.raise_money.news.News; import hunnu.sj.raise_money.R; import hunnu.sj.raise_money.User; @@ -96,7 +97,7 @@ public class UserService { } public void getAllNews(Context context,ArrayList list){ - ArrayList mlist = list; + //ArrayList mlist = list; String sql = "select * from stu_info"; conn = db.getConnection(); try{ @@ -109,9 +110,31 @@ public class UserService { news.setHead_icon(ContextCompat.getDrawable(context, R.drawable.ic_launcher_background)); list.add(news); } + rs.close(); + sttmt.close(); }catch(SQLException e){ e.printStackTrace(); } } + public void getDonateRecords(ArrayList recordlist,String username){ + String sql = "select * from record where username = '"+username+"'"; + conn = db.getConnection(); + try{ + Statement sttmt = conn.createStatement(); + ResultSet rs = sttmt.executeQuery(sql); + while(rs.next()){ + Record record = new Record(); + record.setStu_name(rs.getNString("stu_name")); + record.setTime(rs.getNString("time")); + record.setDonatemon(rs.getFloat("donatemon")); + recordlist.add(record); + } + rs.close(); + sttmt.close(); + }catch (SQLException e){ + e.printStackTrace(); + } + } + } diff --git a/app/src/main/java/hunnu/sj/raise_money/InfoUtils.java b/app/src/main/java/hunnu/sj/raise_money/InfoUtils.java new file mode 100644 index 0000000..bdb8d1b --- /dev/null +++ b/app/src/main/java/hunnu/sj/raise_money/InfoUtils.java @@ -0,0 +1,23 @@ +package hunnu.sj.raise_money; + +import android.content.Context; + +import java.util.ArrayList; + +import hunnu.sj.raise_money.DataBase.UserService; +import hunnu.sj.raise_money.donate_record.Record; +import hunnu.sj.raise_money.news.News; + +public class InfoUtils { + public static int getAllNews(Context context,ArrayList list){//从数据库获取信息到本地 + UserService uService = new UserService(); + uService.getAllNews(context,list); + return 1; + } + + public static int getDonateRecords(ArrayList recordlist,String username){ + UserService uService = new UserService(); + uService.getDonateRecords(recordlist,username); + return 1; + } +} diff --git a/app/src/main/java/hunnu/sj/raise_money/MainActivity.java b/app/src/main/java/hunnu/sj/raise_money/MainActivity.java index aea043b..2d9149e 100644 --- a/app/src/main/java/hunnu/sj/raise_money/MainActivity.java +++ b/app/src/main/java/hunnu/sj/raise_money/MainActivity.java @@ -5,9 +5,6 @@ import android.content.Intent; import android.net.Uri; import android.os.Bundle; -import com.google.android.material.floatingactionbutton.FloatingActionButton; -import com.google.android.material.snackbar.Snackbar; - import android.os.Handler; import android.os.Message; import android.view.MenuItem; @@ -16,11 +13,7 @@ import android.view.View; import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBarDrawerToggle; import androidx.core.content.ContextCompat; -import androidx.fragment.app.ListFragment; -import androidx.navigation.NavController; -import androidx.navigation.Navigation; import androidx.navigation.ui.AppBarConfiguration; -import androidx.navigation.ui.NavigationUI; import com.google.android.material.navigation.NavigationView; @@ -36,6 +29,9 @@ import android.widget.TextView; import java.util.ArrayList; +import hunnu.sj.raise_money.news.News; +import hunnu.sj.raise_money.news.NewsAdapter; + public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener{ private AppBarConfiguration mAppBarConfiguration; private Toolbar toolbar; @@ -45,6 +41,7 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte private TextView menu_name; TextView menu_role; + private User user; ArrayList list = new ArrayList<>(); Context mContext; private NewsAdapter newsAdapter; @@ -64,7 +61,6 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte super.onCreate(savedInstanceState); Intent intent = getIntent(); - User user; user = (User) intent.getSerializableExtra("user"); setContentView(R.layout.activity_main); mContext = this; @@ -114,7 +110,7 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte //new UploadThread().start(); lv_news = findViewById(R.id.list); lv_news.setAdapter(newsAdapter); - lv_news.setOnItemClickListener(this); + //lv_news.setOnItemClickListener(this); News news = new News(); news.setTitle("火箭发射成功"); news.setDes("地方上的房贷首付读书首付第三方的手房贷首付第三方的手负担"); @@ -156,10 +152,9 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte @Override public void run() { Message message = mhandler.obtainMessage(); - int isload = NewsUtils.getAllNews(mContext,list); + int isload = InfoUtils.getAllNews(mContext,list); message.what = isload; - mhandler.sendMessage(message); - //newsAdapter.notifyDataSetChanged(); + mhandler.sendMessage(message);//加载数据库成功返回1,并且给handler发送信息,刷新list的变量 } } @@ -177,6 +172,8 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte public void onBrowseDonateRecord(MenuItem item){ Intent intent = new Intent(this,BrowseRecordActivity.class); + String username = user.getName(); + intent.putExtra("username",username); startActivity(intent); } diff --git a/app/src/main/java/hunnu/sj/raise_money/NewsUtils.java b/app/src/main/java/hunnu/sj/raise_money/NewsUtils.java deleted file mode 100644 index 91e10a8..0000000 --- a/app/src/main/java/hunnu/sj/raise_money/NewsUtils.java +++ /dev/null @@ -1,25 +0,0 @@ -package hunnu.sj.raise_money; - -import android.content.Context; - -import androidx.core.content.ContextCompat; - -import java.util.ArrayList; - -import hunnu.sj.raise_money.DataBase.UserService; - -public class NewsUtils { - public static int getAllNews(Context context,ArrayList list){//从数据库获取信息到本地 - UserService uService = new UserService(); - uService.getAllNews(context,list); - return 1; - /*for(int i = 0 ;i <100;i++) - { - News news = new News(); - news.setTitle("火箭发射成功"); - news.setDes("地方上的房贷首付读书首付第三方的手房贷首付第三方的手负担"); - news.setHead_icon(ContextCompat.getDrawable(context, R.drawable.ic_launcher_background)); - list.add(news); - }*/ - } -} diff --git a/app/src/main/java/hunnu/sj/raise_money/UploadActivity.java b/app/src/main/java/hunnu/sj/raise_money/UploadActivity.java index 857aeda..843a311 100644 --- a/app/src/main/java/hunnu/sj/raise_money/UploadActivity.java +++ b/app/src/main/java/hunnu/sj/raise_money/UploadActivity.java @@ -1,30 +1,22 @@ package hunnu.sj.raise_money; import androidx.appcompat.app.AppCompatActivity; -import androidx.core.content.FileProvider; import android.content.Context; import android.content.Intent; import android.net.Uri; -import android.os.Build; import android.os.Bundle; import android.os.Looper; import android.provider.MediaStore; import android.view.View; -import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; -import android.widget.TextView; import android.widget.Toast; -import java.io.File; -import java.io.IOException; -import java.net.URI; - import hunnu.sj.raise_money.DataBase.UserService; -import hunnu.sj.raise_money.R; +import hunnu.sj.raise_money.news.News; public class UploadActivity extends AppCompatActivity { public static final int TAKE_PHOTO = 1; diff --git a/app/src/main/java/hunnu/sj/raise_money/donate_record/Record.java b/app/src/main/java/hunnu/sj/raise_money/donate_record/Record.java new file mode 100644 index 0000000..3b475c1 --- /dev/null +++ b/app/src/main/java/hunnu/sj/raise_money/donate_record/Record.java @@ -0,0 +1,49 @@ +package hunnu.sj.raise_money.donate_record; + +public class Record { + private long id = 0; + private String stu_name = null; + private String username = null; + private float donatemon = 0; + private String time = null; + + public float getDonatemon() { + return donatemon; + } + + public void setDonatemon(float donatemon) { + this.donatemon = donatemon; + } + + public String getStu_name() { + return stu_name; + } + + public void setStu_name(String stu_name) { + this.stu_name = stu_name; + } + + public String getTime() { + return time; + } + + public void setTime(String time) { + this.time = time; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } +} diff --git a/app/src/main/java/hunnu/sj/raise_money/donate_record/RecordAdapter.java b/app/src/main/java/hunnu/sj/raise_money/donate_record/RecordAdapter.java new file mode 100644 index 0000000..13d4a70 --- /dev/null +++ b/app/src/main/java/hunnu/sj/raise_money/donate_record/RecordAdapter.java @@ -0,0 +1,50 @@ +package hunnu.sj.raise_money.donate_record; + +import android.content.Context; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.TextView; + +import java.util.ArrayList; + +import hunnu.sj.raise_money.R; + +public class RecordAdapter extends BaseAdapter { + private ArrayList recordlist; + private Context context; + public RecordAdapter(Context context,ArrayList recordlist) { + + this.context = context; + this.recordlist = recordlist; + } + @Override + public int getCount() { + return recordlist.size(); + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public Object getItem(int position) { + return recordlist.get(position); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + View view = null; + if(convertView != null){ + view = convertView; + }else{ + view = View.inflate(context, R.layout.donate_record_item,null); + } + Record record = recordlist.get(position); + TextView record_vw = view.findViewById(R.id.record_descri); + String descri = "您于"+record.getTime()+"给"+record.getStu_name()+"捐赠"+record.getDonatemon()+"元"; + record_vw.setText(descri); + return view; + } +} diff --git a/app/src/main/java/hunnu/sj/raise_money/News.java b/app/src/main/java/hunnu/sj/raise_money/news/News.java similarity index 90% rename from app/src/main/java/hunnu/sj/raise_money/News.java rename to app/src/main/java/hunnu/sj/raise_money/news/News.java index ce50abe..63488af 100644 --- a/app/src/main/java/hunnu/sj/raise_money/News.java +++ b/app/src/main/java/hunnu/sj/raise_money/news/News.java @@ -1,7 +1,6 @@ -package hunnu.sj.raise_money; +package hunnu.sj.raise_money.news; import android.graphics.drawable.Drawable; -import android.widget.ImageView; public class News {//主界面浏览的信息的类 private String title; @@ -19,11 +18,9 @@ public class News {//主界面浏览的信息的类 public void setDes(String content) { this.des = content; } - public Drawable getHead_icon() { return head_icon; } - public void setHead_icon(Drawable head_icon) { this.head_icon = head_icon; } diff --git a/app/src/main/java/hunnu/sj/raise_money/NewsAdapter.java b/app/src/main/java/hunnu/sj/raise_money/news/NewsAdapter.java similarity index 90% rename from app/src/main/java/hunnu/sj/raise_money/NewsAdapter.java rename to app/src/main/java/hunnu/sj/raise_money/news/NewsAdapter.java index 918ed9e..c238e40 100644 --- a/app/src/main/java/hunnu/sj/raise_money/NewsAdapter.java +++ b/app/src/main/java/hunnu/sj/raise_money/news/NewsAdapter.java @@ -1,4 +1,4 @@ -package hunnu.sj.raise_money; +package hunnu.sj.raise_money.news; import android.content.Context; import android.view.View; @@ -8,6 +8,9 @@ import android.widget.ImageView; import android.widget.TextView; import java.util.ArrayList; + +import hunnu.sj.raise_money.R; + //信息的适配器 public class NewsAdapter extends BaseAdapter { private ArrayList list; @@ -39,7 +42,7 @@ public class NewsAdapter extends BaseAdapter { if(convertView != null){ view = convertView; }else{ - view = View.inflate(context,R.layout.info_item_layout,null); + view = View.inflate(context, R.layout.info_item_layout,null); } ImageView item_icon = (ImageView) view.findViewById(R.id.item_head_icon); TextView item_title = (TextView) view.findViewById(R.id.item_info_title); diff --git a/app/src/main/res/layout/app_bar_main.xml b/app/src/main/res/layout/app_bar_main.xml index e9fa907..9c96440 100644 --- a/app/src/main/res/layout/app_bar_main.xml +++ b/app/src/main/res/layout/app_bar_main.xml @@ -22,12 +22,4 @@ - - \ No newline at end of file diff --git a/app/src/main/res/layout/donate_record_item.xml b/app/src/main/res/layout/donate_record_item.xml new file mode 100644 index 0000000..7a93c77 --- /dev/null +++ b/app/src/main/res/layout/donate_record_item.xml @@ -0,0 +1,26 @@ + + + + + + + + \ No newline at end of file