添加了用户查看捐款记录功能

my
盛洁 5 years ago
parent c1bd6ae582
commit bfe8acad30

@ -2,6 +2,8 @@
<dictionary name="盛洁"> <dictionary name="盛洁">
<words> <words>
<w>descri</w> <w>descri</w>
<w>donatemon</w>
<w>recordlist</w>
<w>sttmt</w> <w>sttmt</w>
</words> </words>
</dictionary> </dictionary>

@ -1,15 +1,52 @@
package hunnu.sj.raise_money; package hunnu.sj.raise_money;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle; 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<Record> 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 @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_browse_record); 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);
}
} }
} }

@ -10,7 +10,8 @@ import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.ArrayList; 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.R;
import hunnu.sj.raise_money.User; import hunnu.sj.raise_money.User;
@ -96,7 +97,7 @@ public class UserService {
} }
public void getAllNews(Context context,ArrayList<News> list){ public void getAllNews(Context context,ArrayList<News> list){
ArrayList<News> mlist = list; //ArrayList<News> mlist = list;
String sql = "select * from stu_info"; String sql = "select * from stu_info";
conn = db.getConnection(); conn = db.getConnection();
try{ try{
@ -109,9 +110,31 @@ public class UserService {
news.setHead_icon(ContextCompat.getDrawable(context, R.drawable.ic_launcher_background)); news.setHead_icon(ContextCompat.getDrawable(context, R.drawable.ic_launcher_background));
list.add(news); list.add(news);
} }
rs.close();
sttmt.close();
}catch(SQLException e){ }catch(SQLException e){
e.printStackTrace(); e.printStackTrace();
} }
} }
public void getDonateRecords(ArrayList<Record> 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();
}
}
} }

@ -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<News> list){//从数据库获取信息到本地
UserService uService = new UserService();
uService.getAllNews(context,list);
return 1;
}
public static int getDonateRecords(ArrayList<Record> recordlist,String username){
UserService uService = new UserService();
uService.getDonateRecords(recordlist,username);
return 1;
}
}

@ -5,9 +5,6 @@ import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; 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.Handler;
import android.os.Message; import android.os.Message;
import android.view.MenuItem; import android.view.MenuItem;
@ -16,11 +13,7 @@ import android.view.View;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBarDrawerToggle; import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.core.content.ContextCompat; 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.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;
import com.google.android.material.navigation.NavigationView; import com.google.android.material.navigation.NavigationView;
@ -36,6 +29,9 @@ import android.widget.TextView;
import java.util.ArrayList; 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{ public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener{
private AppBarConfiguration mAppBarConfiguration; private AppBarConfiguration mAppBarConfiguration;
private Toolbar toolbar; private Toolbar toolbar;
@ -45,6 +41,7 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
private private
TextView menu_name; TextView menu_name;
TextView menu_role; TextView menu_role;
private User user;
ArrayList<News> list = new ArrayList<>(); ArrayList<News> list = new ArrayList<>();
Context mContext; Context mContext;
private NewsAdapter newsAdapter; private NewsAdapter newsAdapter;
@ -64,7 +61,6 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Intent intent = getIntent(); Intent intent = getIntent();
User user;
user = (User) intent.getSerializableExtra("user"); user = (User) intent.getSerializableExtra("user");
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
mContext = this; mContext = this;
@ -114,7 +110,7 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
//new UploadThread().start(); //new UploadThread().start();
lv_news = findViewById(R.id.list); lv_news = findViewById(R.id.list);
lv_news.setAdapter(newsAdapter); lv_news.setAdapter(newsAdapter);
lv_news.setOnItemClickListener(this); //lv_news.setOnItemClickListener(this);
News news = new News(); News news = new News();
news.setTitle("火箭发射成功"); news.setTitle("火箭发射成功");
news.setDes("地方上的房贷首付读书首付第三方的手房贷首付第三方的手负担"); news.setDes("地方上的房贷首付读书首付第三方的手房贷首付第三方的手负担");
@ -156,10 +152,9 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
@Override @Override
public void run() { public void run() {
Message message = mhandler.obtainMessage(); Message message = mhandler.obtainMessage();
int isload = NewsUtils.getAllNews(mContext,list); int isload = InfoUtils.getAllNews(mContext,list);
message.what = isload; message.what = isload;
mhandler.sendMessage(message); mhandler.sendMessage(message);//加载数据库成功返回1并且给handler发送信息刷新list的变量
//newsAdapter.notifyDataSetChanged();
} }
} }
@ -177,6 +172,8 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
public void onBrowseDonateRecord(MenuItem item){ public void onBrowseDonateRecord(MenuItem item){
Intent intent = new Intent(this,BrowseRecordActivity.class); Intent intent = new Intent(this,BrowseRecordActivity.class);
String username = user.getName();
intent.putExtra("username",username);
startActivity(intent); startActivity(intent);
} }

@ -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<News> 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);
}*/
}
}

@ -1,30 +1,22 @@
package hunnu.sj.raise_money; package hunnu.sj.raise_money;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.FileProvider;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Looper; import android.os.Looper;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.view.View; import android.view.View;
import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast; 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.DataBase.UserService;
import hunnu.sj.raise_money.R; import hunnu.sj.raise_money.news.News;
public class UploadActivity extends AppCompatActivity { public class UploadActivity extends AppCompatActivity {
public static final int TAKE_PHOTO = 1; public static final int TAKE_PHOTO = 1;

@ -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;
}
}

@ -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<Record> recordlist;
private Context context;
public RecordAdapter(Context context,ArrayList<Record> 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;
}
}

@ -1,7 +1,6 @@
package hunnu.sj.raise_money; package hunnu.sj.raise_money.news;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.widget.ImageView;
public class News {//主界面浏览的信息的类 public class News {//主界面浏览的信息的类
private String title; private String title;
@ -19,11 +18,9 @@ public class News {//主界面浏览的信息的类
public void setDes(String content) { public void setDes(String content) {
this.des = content; this.des = content;
} }
public Drawable getHead_icon() { public Drawable getHead_icon() {
return head_icon; return head_icon;
} }
public void setHead_icon(Drawable head_icon) { public void setHead_icon(Drawable head_icon) {
this.head_icon = head_icon; this.head_icon = head_icon;
} }

@ -1,4 +1,4 @@
package hunnu.sj.raise_money; package hunnu.sj.raise_money.news;
import android.content.Context; import android.content.Context;
import android.view.View; import android.view.View;
@ -8,6 +8,9 @@ import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import java.util.ArrayList; import java.util.ArrayList;
import hunnu.sj.raise_money.R;
//信息的适配器 //信息的适配器
public class NewsAdapter extends BaseAdapter { public class NewsAdapter extends BaseAdapter {
private ArrayList<News> list; private ArrayList<News> list;
@ -39,7 +42,7 @@ public class NewsAdapter extends BaseAdapter {
if(convertView != null){ if(convertView != null){
view = convertView; view = convertView;
}else{ }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); ImageView item_icon = (ImageView) view.findViewById(R.id.item_head_icon);
TextView item_title = (TextView) view.findViewById(R.id.item_info_title); TextView item_title = (TextView) view.findViewById(R.id.item_info_title);

@ -22,12 +22,4 @@
<include layout="@layout/content_main" /> <include layout="@layout/content_main" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/record_descri"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|top"
android:layout_marginStart="5sp"
android:layout_marginTop="5sp"
android:layout_marginBottom="5sp"
android:layout_weight="1"
android:text="record"
android:textColor="@android:color/background_dark"
android:textSize="24sp" />
</LinearLayout>
</LinearLayout>
Loading…
Cancel
Save