Skip to content

Commit

Permalink
答辩完了 不更新了
Browse files Browse the repository at this point in the history
  • Loading branch information
iliweii committed Jun 19, 2021
1 parent 1ef37fb commit ec1fa97
Show file tree
Hide file tree
Showing 23 changed files with 1,603 additions and 42 deletions.
6 changes: 5 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
android:supportsRtl="true"
android:theme="@style/Theme.租客行"
android:usesCleartextTraffic="true">
<activity android:name=".ui.home.PostOrderActivity"></activity>
<activity android:name=".ui.dashboard.OrderDetailActivity"></activity>
<activity android:name=".ui.dashboard.OrderActivity" />
<activity android:name=".ui.home.PayDoneActivity" />
<activity android:name=".ui.home.PayActivity" />
<activity android:name=".ui.home.PostOrderActivity" />
<activity android:name=".ui.mine.VerifiedActivity" />
<activity android:name=".ui.mine.UserNickActivity" />
<activity android:name=".ui.mine.UserInfoActivity" />
Expand Down
175 changes: 175 additions & 0 deletions app/src/main/java/com/zukexing/app/pojo/Rented.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
package com.zukexing.app.pojo;

public class Rented {
private int rented_id;
private int user_id;
private int house_id;
private String start_time;
private String end_time;
private String create_time;
private double pay;
private double pay_h;
private double pay_d;
private int status;
private String house_title;
private String house_type;
private String house_area;
private String house_floor;
private String house_dir;
private String house_intro;
private String house_local;
private String house_require;
private String house_img;

public int getRented_id() {
return rented_id;
}

public void setRented_id(int rented_id) {
this.rented_id = rented_id;
}

public int getUser_id() {
return user_id;
}

public void setUser_id(int user_id) {
this.user_id = user_id;
}

public int getHouse_id() {
return house_id;
}

public void setHouse_id(int house_id) {
this.house_id = house_id;
}

public String getStart_time() {
return start_time;
}

public void setStart_time(String start_time) {
this.start_time = start_time;
}

public String getEnd_time() {
return end_time;
}

public void setEnd_time(String end_time) {
this.end_time = end_time;
}

public String getCreate_time() {
return create_time;
}

public void setCreate_time(String create_time) {
this.create_time = create_time;
}

public double getPay() {
return pay;
}

public void setPay(double pay) {
this.pay = pay;
}

public double getPay_h() {
return pay_h;
}

public void setPay_h(double pay_h) {
this.pay_h = pay_h;
}

public double getPay_d() {
return pay_d;
}

public void setPay_d(double pay_d) {
this.pay_d = pay_d;
}

public int getStatus() {
return status;
}

public void setStatus(int status) {
this.status = status;
}

public String getHouse_title() {
return house_title;
}

public void setHouse_title(String house_title) {
this.house_title = house_title;
}

public String getHouse_type() {
return house_type;
}

public void setHouse_type(String house_type) {
this.house_type = house_type;
}

public String getHouse_area() {
return house_area;
}

public void setHouse_area(String house_area) {
this.house_area = house_area;
}

public String getHouse_floor() {
return house_floor;
}

public void setHouse_floor(String house_floor) {
this.house_floor = house_floor;
}

public String getHouse_dir() {
return house_dir;
}

public void setHouse_dir(String house_dir) {
this.house_dir = house_dir;
}

public String getHouse_intro() {
return house_intro;
}

public void setHouse_intro(String house_intro) {
this.house_intro = house_intro;
}

public String getHouse_local() {
return house_local;
}

public void setHouse_local(String house_local) {
this.house_local = house_local;
}

public String getHouse_require() {
return house_require;
}

public void setHouse_require(String house_require) {
this.house_require = house_require;
}

public String getHouse_img() {
return house_img;
}

public void setHouse_img(String house_img) {
this.house_img = house_img;
}
}
140 changes: 136 additions & 4 deletions app/src/main/java/com/zukexing/app/ui/dashboard/DashboardFragment.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package com.zukexing.app.ui.dashboard;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

import androidx.annotation.NonNull;
Expand All @@ -12,24 +19,149 @@
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.zukexing.app.R;
import com.zukexing.app.pojo.House;
import com.zukexing.app.pojo.Rented;
import com.zukexing.app.ui.home.HomeFragment;
import com.zukexing.app.ui.home.HomeListviewAdapter;
import com.zukexing.app.ui.home.HouseDetailActivity;
import com.zukexing.app.ui.login.LoginActivity;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.lang.reflect.Type;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class DashboardFragment extends Fragment {

private DashboardViewModel dashboardViewModel;

private ListView dashboard_listview;

private List<Rented> renteds;
private DashboardListviewAdapter dashboardListviewAdapter;

private Handler handler = new Handler(){

@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case 1:
String obj = (String) msg.obj;
Gson gson = new Gson();
Type rentedListType = new TypeToken<ArrayList<Rented>>(){}.getType();
renteds = gson.fromJson(obj, rentedListType);
// 设置主页 数据
dashboardListviewAdapter = new DashboardListviewAdapter(getContext(), R.layout.dashboard_listview_item, renteds);
dashboard_listview.setAdapter(dashboardListviewAdapter);
setListViewHeightBasedOnChildren(dashboard_listview);
break;
}
}
};

public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
dashboardViewModel =
new ViewModelProvider(this).get(DashboardViewModel.class);
View root = inflater.inflate(R.layout.fragment_dashboard, container, false);
final TextView textView = root.findViewById(R.id.text_dashboard);
dashboardViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
// final TextView textView = root.findViewById(R.id.text_dashboard);
// dashboardViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
// @Override
// public void onChanged(@Nullable String s) {
// textView.setText(s);
// }
// });
dashboard_listview = root.findViewById(R.id.dashboard_listview);

SharedPreferences settings = getContext().getSharedPreferences("User", 0);
String phone = settings.getString("phone", "");
int userid = settings.getInt("userid", 0);

// 如果没有登录,跳转到登录界面
if (userid == 0) {
Intent intent = new Intent();
intent.setClass(DashboardFragment.this.getActivity(), LoginActivity.class);
startActivity(intent);

return root;
}

new Thread(new Runnable(){
@Override
public void run() {
String rentedJson = null;
try {
URL url = new URL(getString(R.string.host) + "api/rented/list?userId=" + userid);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(8000);
connection.connect();
InputStream in = connection.getInputStream();

byte[] buffer = new byte[1024];
int len = 0;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
while((len = in.read(buffer)) != -1) {
bos.write(buffer, 0, len);
}
rentedJson = new String(bos.toByteArray(), "utf-8");
bos.close();
connection.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
Message msg = new Message();
if (rentedJson != null ) {
msg.what = 1;
msg.obj = rentedJson;
handler.sendMessage(msg);
}
}
}).start();

dashboard_listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onChanged(@Nullable String s) {
textView.setText(s);
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Rented rented = renteds.get(position);
// Toast.makeText(HomeFragment.this.getActivity(), rented.getHouse_title(), Toast.LENGTH_SHORT).show();
Intent rented_detail_active = new Intent(DashboardFragment.this.getActivity(), OrderDetailActivity.class);
rented_detail_active.putExtra("rented", new Gson().toJson(rented));
startActivity(rented_detail_active);
}
});

return root;
}

public void setListViewHeightBasedOnChildren(ListView listView) {

ListAdapter listAdapter = listView.getAdapter();

if (listAdapter == null) {
return;
}

int totalHeight = 0;

for (int i = 0; i < listAdapter.getCount(); i++) {
View listItem = listAdapter.getView(i, null, listView);
listItem.measure(0, 0);
totalHeight += (listItem.getMeasuredHeight() + 100);

}

ViewGroup.LayoutParams params = listView.getLayoutParams();

params.height = totalHeight
+ (listView.getDividerHeight() * (listAdapter.getCount() - 1));

listView.setLayoutParams(params);
}
}
Loading

0 comments on commit ec1fa97

Please sign in to comment.