add History Adapter
This commit is contained in:
parent
a29cdbb5d5
commit
7802d39417
41
app/src/main/java/ru/myitschool/work/ui/History.java
Normal file
41
app/src/main/java/ru/myitschool/work/ui/History.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package ru.myitschool.work.ui;
|
||||||
|
|
||||||
|
public class History {
|
||||||
|
private Long time;
|
||||||
|
private String nameReader;
|
||||||
|
private int type; //1 - qr 2 - карта
|
||||||
|
|
||||||
|
|
||||||
|
public History(Long time, String nameReader, int passageType) {
|
||||||
|
this.time = time;
|
||||||
|
this.nameReader = nameReader;
|
||||||
|
this.type = passageType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getTime() {
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTime(Long time) {
|
||||||
|
this.time = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameReader() {
|
||||||
|
return nameReader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameReader(String nameReader) {
|
||||||
|
this.nameReader = nameReader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPassageType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassageType(int passageType) {
|
||||||
|
this.type = passageType;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
66
app/src/main/java/ru/myitschool/work/ui/HistoryAdapter.java
Normal file
66
app/src/main/java/ru/myitschool/work/ui/HistoryAdapter.java
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package ru.myitschool.work.ui;
|
||||||
|
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import ru.myitschool.work.databinding.ItemHistoryBinding;
|
||||||
|
|
||||||
|
public class HistoryAdapter extends RecyclerView.Adapter<HistoryAdapter.ViewHolder> {
|
||||||
|
|
||||||
|
private final List<History> data = new ArrayList<>();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
return new ViewHolder(
|
||||||
|
ItemHistoryBinding.inflate(
|
||||||
|
LayoutInflater.from(parent.getContext()),
|
||||||
|
parent,
|
||||||
|
false
|
||||||
|
).getRoot()
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||||
|
holder.bind(data.get(position));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return data.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateData(List<History> newData) {
|
||||||
|
data.clear();
|
||||||
|
data.addAll(newData);
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
private final ItemHistoryBinding binding;
|
||||||
|
|
||||||
|
public ViewHolder(@NonNull View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
binding = ItemHistoryBinding.bind(itemView);
|
||||||
|
}
|
||||||
|
public void bind(History item) {
|
||||||
|
binding.time.setText(item.getTime().toString());
|
||||||
|
binding.nameReader.setText(item.getNameReader());
|
||||||
|
if (item.getPassageType() == 1){
|
||||||
|
binding.type.setText("QR-code");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
binding.type.setText("Карта");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -15,6 +15,8 @@ import androidx.fragment.app.FragmentResultListener;
|
|||||||
|
|
||||||
import com.squareup.picasso.Picasso;
|
import com.squareup.picasso.Picasso;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
import retrofit2.Response;
|
import retrofit2.Response;
|
||||||
@ -28,6 +30,7 @@ import ru.myitschool.work.ui.qr.scan.QrScanFragment;
|
|||||||
public class InformationFragment extends Fragment {
|
public class InformationFragment extends Fragment {
|
||||||
FragmentInformationBinding binding;
|
FragmentInformationBinding binding;
|
||||||
SharedPreferences sharedPreferences;
|
SharedPreferences sharedPreferences;
|
||||||
|
ArrayList<History> history = new ArrayList<>();
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
@ -48,13 +51,17 @@ public class InformationFragment extends Fragment {
|
|||||||
onClickRefresh();
|
onClickRefresh();
|
||||||
});
|
});
|
||||||
|
|
||||||
binding.scan.setOnClickListener(view1 -> {
|
binding.scan.setOnClickListener(view2 -> {
|
||||||
onClickScan();
|
onClickScan();
|
||||||
});
|
});
|
||||||
|
|
||||||
binding.logout.setOnClickListener(view2 -> {
|
binding.logout.setOnClickListener(view3 -> {
|
||||||
onClickLogout();
|
onClickLogout();
|
||||||
});
|
});
|
||||||
|
//TODO: SERVER ZAGUZKA LISTAAAAAAAAAAAAAAA
|
||||||
|
HistoryAdapter adapter = new HistoryAdapter();
|
||||||
|
binding.historylist.setAdapter(adapter);
|
||||||
|
adapter.updateData(history);
|
||||||
|
|
||||||
//getParentFragmentManager()
|
//getParentFragmentManager()
|
||||||
requireActivity().getSupportFragmentManager().setFragmentResultListener(QrScanDestination.REQUEST_KEY, getViewLifecycleOwner(), (requestKey, result) -> {
|
requireActivity().getSupportFragmentManager().setFragmentResultListener(QrScanDestination.REQUEST_KEY, getViewLifecycleOwner(), (requestKey, result) -> {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package ru.myitschool.work.ui;
|
package ru.myitschool.work.ui;
|
||||||
|
|
||||||
public class User {
|
public class
|
||||||
|
User {
|
||||||
|
|
||||||
private int id;
|
private int id;
|
||||||
private String login;
|
private String login;
|
||||||
|
@ -48,5 +48,11 @@
|
|||||||
android:text="@string/error"
|
android:text="@string/error"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"/>
|
android:layout_height="wrap_content"/>
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:id="@+id/historylist"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
39
app/src/main/res/layout/item_history.xml
Normal file
39
app/src/main/res/layout/item_history.xml
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/time"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="24dp"
|
||||||
|
app:layout_constraintBottom_toTopOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
android:tag="iuroi"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/nameReader"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="24dp"
|
||||||
|
android:text="kijt"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@+id/time"
|
||||||
|
app:layout_constraintStart_toEndOf="@id/time"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/type"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="24dp"
|
||||||
|
android:text="hgfdfbjdhf"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@+id/time"
|
||||||
|
app:layout_constraintStart_toEndOf="@id/nameReader"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
x
Reference in New Issue
Block a user