-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
775 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ | |
.cxx | ||
local.properties | ||
*.json | ||
*~ | ||
**/build | ||
**/reports | ||
**/reports | ||
**~ | ||
**.apk | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
LifeLine/app/src/main/java/com/example/lifeline/adapters/HistoryAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.example.lifeline.adapters; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.content.Context; | ||
import android.os.Bundle; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.TextView; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.fragment.app.FragmentActivity; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
|
||
import com.example.lifeline.R; | ||
import com.example.lifeline.dashboard.ViewFragment; | ||
import com.example.lifeline.interfaces.AddViewFragment; | ||
import com.example.lifeline.models.History; | ||
|
||
import java.util.List; | ||
|
||
public class HistoryAdapter extends RecyclerView.Adapter<HistoryAdapter.HistoryViewHolder> { | ||
|
||
private final Context context; | ||
private final List<History> list; | ||
|
||
public HistoryAdapter(Context context, List<History> list) { | ||
this.context = context; | ||
this.list = list; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public HistoryViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | ||
return new HistoryViewHolder(LayoutInflater.from(context).inflate(R.layout.recycler_view_history_item, parent, false)); | ||
} | ||
|
||
@SuppressLint("SetTextI18n") | ||
@Override | ||
public void onBindViewHolder(@NonNull HistoryViewHolder holder, int position) { | ||
holder.textViewDate.setText(list.get(position).getDate()); | ||
holder.textViewNumber.setText("#" + (position + 1)); | ||
holder.itemView.setOnClickListener(view -> { | ||
AddViewFragment viewFragment = new ViewFragment(); | ||
Bundle bundle = new Bundle(); | ||
bundle.putString("date", list.get(position).getDate()); | ||
viewFragment.setArguments(bundle); | ||
viewFragment.show(((FragmentActivity) context).getSupportFragmentManager(), "AddViewFragment"); | ||
}); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return list.size(); | ||
} | ||
|
||
public static final class HistoryViewHolder extends RecyclerView.ViewHolder { | ||
private final TextView textViewDate; | ||
private final TextView textViewNumber; | ||
|
||
public HistoryViewHolder(@NonNull View itemView) { | ||
super(itemView); | ||
textViewDate = itemView.findViewById(R.id.textViewDate); | ||
textViewNumber = itemView.findViewById(R.id.textViewNumber); | ||
} | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
LifeLine/app/src/main/java/com/example/lifeline/adapters/InfoAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package com.example.lifeline.adapters; | ||
|
||
import android.app.Activity; | ||
import android.app.ActivityOptions; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.util.Pair; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.cardview.widget.CardView; | ||
import androidx.core.app.ActivityOptionsCompat; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
|
||
import com.example.lifeline.R; | ||
import com.example.lifeline.dashboard.HistoryActivity; | ||
import com.example.lifeline.models.Info; | ||
|
||
import java.util.List; | ||
|
||
public class InfoAdapter extends RecyclerView.Adapter<InfoAdapter.InfoViewHolder> { | ||
|
||
private final Context context; | ||
private final List<Info> list; | ||
|
||
public InfoAdapter(Context context, List<Info> list) { | ||
this.context = context; | ||
this.list = list; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public InfoViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | ||
View InfoView = LayoutInflater.from(context).inflate(R.layout.recycler_view_info_item, parent, false); | ||
return new InfoViewHolder(InfoView); | ||
} | ||
|
||
private void setOnClickListenerForHistory(CardView cardView) { | ||
cardView.setOnClickListener(view1 -> { | ||
Intent intent = new Intent(context, HistoryActivity.class); | ||
ActivityOptionsCompat options = ActivityOptionsCompat .makeSceneTransitionAnimation((Activity) context, cardView, "shared_element_transition"); | ||
context.startActivity(intent, options.toBundle()); | ||
}); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return (int) Math.ceil((float) list.size() / InfoViewHolder.numberOfItemsInOneRow); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(@NonNull InfoViewHolder holder, int position) { | ||
int baseIndex = position * InfoViewHolder.numberOfItemsInOneRow; | ||
|
||
bindItem(holder.textView_1, holder.imageView_1, list.get(baseIndex)); | ||
|
||
if (baseIndex + 1 < list.size()) { | ||
bindItem(holder.textView_2, holder.imageView_2, list.get(baseIndex + 1)); | ||
if (isLastPosition(position)) { | ||
setOnClickListenerForHistory(holder.cardView_2); | ||
} | ||
} else { | ||
holder.cardView_2.setVisibility(View.GONE); | ||
if (isLastPosition(position)) { | ||
setOnClickListenerForHistory(holder.cardView_1); | ||
} | ||
} | ||
} | ||
|
||
private void bindItem(TextView textView, ImageView imageView, Info item) { | ||
textView.setText(item.getValue()); | ||
imageView.setImageResource(item.getImage()); | ||
} | ||
|
||
private boolean isLastPosition(int position) { | ||
return position + 1 == getItemCount(); | ||
} | ||
|
||
|
||
public static final class InfoViewHolder extends RecyclerView.ViewHolder { | ||
|
||
private final TextView textView_1; | ||
private final TextView textView_2; | ||
private final ImageView imageView_1; | ||
private final ImageView imageView_2; | ||
private final CardView cardView_2; | ||
private final CardView cardView_1; | ||
private static final int numberOfItemsInOneRow = 2; | ||
|
||
public InfoViewHolder(View view) { | ||
super(view); | ||
|
||
textView_1 = view.findViewById(R.id.textView_1); | ||
textView_2 = view.findViewById(R.id.textView_2); | ||
imageView_1 = view.findViewById(R.id.imageView_1); | ||
imageView_2 = view.findViewById(R.id.imageView_2); | ||
cardView_1 = view.findViewById(R.id.cardView_1); | ||
cardView_2 = view.findViewById(R.id.cardView_2); | ||
} | ||
} | ||
} |
73 changes: 0 additions & 73 deletions
73
LifeLine/app/src/main/java/com/example/lifeline/adapters/RecyclerViewParamAdapter.java
This file was deleted.
Oops, something went wrong.
122 changes: 4 additions & 118 deletions
122
LifeLine/app/src/main/java/com/example/lifeline/dashboard/AddFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,124 +1,10 @@ | ||
package com.example.lifeline.dashboard; | ||
|
||
import android.os.Bundle; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.AutoCompleteTextView; | ||
import android.widget.Button; | ||
import android.widget.LinearLayout; | ||
import com.example.lifeline.interfaces.AddViewFragment; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import com.example.lifeline.R; | ||
import com.example.lifeline.database.Database; | ||
import com.example.lifeline.database.DatabaseManager; | ||
import com.example.lifeline.models.Donations; | ||
import com.google.android.material.bottomsheet.BottomSheetBehavior; | ||
import com.google.android.material.bottomsheet.BottomSheetDialog; | ||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment; | ||
import com.google.android.material.datepicker.MaterialDatePicker; | ||
import com.google.android.material.textfield.TextInputEditText; | ||
import com.google.android.material.textfield.TextInputLayout; | ||
import com.google.firebase.auth.FirebaseAuth; | ||
|
||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
public class AddFragment extends BottomSheetDialogFragment { | ||
private MaterialDatePicker<Long> datePicker; | ||
private TextInputEditText textFieldDate; | ||
private TextInputLayout textInputLayoutDate; | ||
private AutoCompleteTextView autoCompleteTextViewDonationType; | ||
private String donationType; | ||
private TextInputEditText textInputEditTextQuantity; | ||
private Button buttonAddDonation; | ||
private Database database; | ||
private Donations donation; | ||
|
||
@Nullable | ||
public class AddFragment extends AddViewFragment { | ||
@Override | ||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | ||
View view = inflater.inflate(R.layout.fragment_add, container, false); | ||
|
||
database = DatabaseManager.getDatabase(); | ||
|
||
donation = new Donations(); | ||
|
||
// Установить начальное состояние | ||
LinearLayout standardBottomSheet = view.findViewById(R.id.standard_bottom_sheet); | ||
BottomSheetBehavior<LinearLayout> standardBottomSheetBehavior = BottomSheetBehavior.from(standardBottomSheet); | ||
standardBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); | ||
standardBottomSheetBehavior.setPeekHeight(BottomSheetBehavior.PEEK_HEIGHT_AUTO); | ||
|
||
BottomSheetDialog modalBottomSheet = (BottomSheetDialog) getDialog(); | ||
BottomSheetBehavior modalBottomSheetBehavior = modalBottomSheet.getBehavior(); | ||
|
||
datePicker = MaterialDatePicker.Builder.datePicker() | ||
.setSelection(MaterialDatePicker.todayInUtcMilliseconds()) | ||
.setTitleText("Дата кровосдачи") | ||
.build(); | ||
|
||
datePicker.addOnPositiveButtonClickListener(selection -> { | ||
// Получить выбранную дату в миллисекундах | ||
Long selectedDateInMillis = datePicker.getSelection(); | ||
|
||
// Создать объект Date из миллисекунд | ||
Date date = new Date(selectedDateInMillis); | ||
|
||
// Создать форматтер для преобразования даты в строку нужного формата | ||
SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy"); | ||
|
||
// Преобразовать дату в строку | ||
String formattedDate = dateFormat.format(date); | ||
|
||
// Установить отформатированную дату в текстовое поле | ||
textFieldDate.setFocusable(true); | ||
textFieldDate.setText(formattedDate); | ||
textFieldDate.setFocusable(false); | ||
}); | ||
|
||
textFieldDate = view.findViewById(R.id.textInputEditTextDate); | ||
textFieldDate.setOnFocusChangeListener((v, hasFocus) -> { | ||
if (hasFocus) { | ||
textFieldDate.setFocusable(false); | ||
textInputLayoutDate.setError(null); | ||
datePicker.show(getChildFragmentManager(), "datePicker"); | ||
} | ||
}); | ||
textFieldDate.setOnClickListener(v -> { | ||
textFieldDate.setFocusable(false); | ||
textInputLayoutDate.setError(null); | ||
datePicker.show(getChildFragmentManager(), "datePicker"); | ||
}); | ||
|
||
textInputLayoutDate = view.findViewById(R.id.textInputLayoutDate); | ||
|
||
autoCompleteTextViewDonationType = view.findViewById(R.id.autoCompleteTextViewDonationType); | ||
autoCompleteTextViewDonationType.setOnItemClickListener((parent, view1, position, id) -> { | ||
donationType = autoCompleteTextViewDonationType.getText().toString(); | ||
}); | ||
|
||
textInputEditTextQuantity = view.findViewById(R.id.textInputEditTextQuantity); | ||
|
||
buttonAddDonation = view.findViewById(R.id.buttonAddDonation); | ||
buttonAddDonation.setOnClickListener(v -> { | ||
|
||
donation.setUserFirebaseID(FirebaseAuth.getInstance().getCurrentUser().getUid()); | ||
donation.setDonationDate(textFieldDate.getText().toString()); | ||
donation.setDonationTypeID(database.getDonationTypeID(donationType)); | ||
donation.setQuantity(textInputEditTextQuantity.getText().toString()); | ||
|
||
if (!database.setDonation(donation)) { | ||
textInputLayoutDate.setError("Такая запись уже существует"); | ||
} else { | ||
modalBottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); | ||
} | ||
}); | ||
|
||
return view; | ||
protected void getExtraFromIntent() { | ||
super.whatsFragment(""); | ||
} | ||
|
||
public static final String TAG = "AddFragment"; | ||
} |
Oops, something went wrong.