Skip to content

Commit

Permalink
Merge branch 'feat/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
gleb7499 committed Dec 17, 2024
2 parents 3cfce4a + c3054bc commit c93f151
Show file tree
Hide file tree
Showing 24 changed files with 775 additions and 253 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
.cxx
local.properties
*.json
*~
**/build
**/reports
**/reports
**~
**.apk

3 changes: 3 additions & 0 deletions LifeLine/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
android:theme="@style/Theme.LifeLine"
android:usesCleartextTraffic="true"
tools:targetApi="31">
<activity
android:name=".dashboard.HistoryActivity"
android:exported="false" />
<activity
android:name=".dashboard.DashboardActivity"
android:exported="false" />
Expand Down
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);
}
}
}
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);
}
}
}

This file was deleted.

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";
}
Loading

0 comments on commit c93f151

Please sign in to comment.