Terminacion de la clase FragmentProfile que ya tiene toda la funcionalidad que a de tener y optimizacion de otras para que funcione y creacion de javas y xml!
This commit is contained in:
parent
85ec9155e4
commit
c7053368a2
|
|
@ -0,0 +1,58 @@
|
||||||
|
package com.santiparra.yomitrack.model;
|
||||||
|
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import com.santiparra.yomitrack.R;
|
||||||
|
import com.santiparra.yomitrack.api.ApiClient;
|
||||||
|
import com.santiparra.yomitrack.api.ApiService;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
|
import retrofit2.Call;
|
||||||
|
import retrofit2.Callback;
|
||||||
|
import retrofit2.Response;
|
||||||
|
|
||||||
|
public class CommentDialog extends Dialog {
|
||||||
|
|
||||||
|
public CommentDialog(@NonNull Context context, int userId, int activityId, Runnable onCommentPosted) {
|
||||||
|
super(context);
|
||||||
|
setContentView(R.layout.dialog_comment);
|
||||||
|
|
||||||
|
EditText commentInput = findViewById(R.id.commentInput);
|
||||||
|
Button sendButton = findViewById(R.id.sendComment);
|
||||||
|
|
||||||
|
sendButton.setOnClickListener(v -> {
|
||||||
|
String commentText = commentInput.getText().toString().trim();
|
||||||
|
if (commentText.isEmpty()) {
|
||||||
|
Toast.makeText(context, "Escribe un comentario", Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonObject body = new JsonObject();
|
||||||
|
body.addProperty("userId", userId);
|
||||||
|
body.addProperty("activityId", activityId);
|
||||||
|
body.addProperty("text", commentText);
|
||||||
|
|
||||||
|
ApiClient.getClient().create(ApiService.class).postComment(body).enqueue(new Callback<JsonObject>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
|
||||||
|
if (response.isSuccessful()) {
|
||||||
|
Toast.makeText(context, "Comentario enviado", Toast.LENGTH_SHORT).show();
|
||||||
|
dismiss();
|
||||||
|
onCommentPosted.run(); // recarga comentarios en FragmentProfile
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call<JsonObject> call, Throwable t) {
|
||||||
|
Toast.makeText(context, "Error al comentar", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.santiparra.yomitrack.model;
|
||||||
|
|
||||||
|
public class CommentModel {
|
||||||
|
public String text;
|
||||||
|
public boolean liked;
|
||||||
|
private String username;
|
||||||
|
private String avatarUrl;
|
||||||
|
private String created_at;
|
||||||
|
|
||||||
|
|
||||||
|
public CommentModel(String text) {
|
||||||
|
this.text = text;
|
||||||
|
this.liked = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getText() {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAvatarUrl() {
|
||||||
|
return avatarUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCreatedAt() {
|
||||||
|
return created_at;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,62 @@
|
||||||
|
package com.santiparra.yomitrack.utils;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class DateUtils {
|
||||||
|
|
||||||
|
public static String getRelativeTime(String isoDate) {
|
||||||
|
try {
|
||||||
|
// Convertir la fecha ISO
|
||||||
|
SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.getDefault());
|
||||||
|
inputFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
|
Date date = inputFormat.parse(isoDate);
|
||||||
|
|
||||||
|
// Obtener ahora y diferencia
|
||||||
|
Date now = new Date();
|
||||||
|
long diffMillis = now.getTime() - date.getTime();
|
||||||
|
long diffSeconds = diffMillis / 1000;
|
||||||
|
long diffMinutes = diffSeconds / 60;
|
||||||
|
long diffHours = diffMinutes / 60;
|
||||||
|
long diffDays = diffHours / 24;
|
||||||
|
|
||||||
|
if (diffSeconds < 60) {
|
||||||
|
return "Hace unos segundos";
|
||||||
|
} else if (diffMinutes < 60) {
|
||||||
|
return "Hace " + diffMinutes + " min";
|
||||||
|
} else if (diffHours < 24 && isSameDay(now, date)) {
|
||||||
|
return "Hace " + diffHours + " horas";
|
||||||
|
} else if (isYesterday(now, date)) {
|
||||||
|
return "Ayer";
|
||||||
|
} else if (diffDays < 7) {
|
||||||
|
return "Hace " + diffDays + " días";
|
||||||
|
} else {
|
||||||
|
SimpleDateFormat dateFormat = new SimpleDateFormat("d 'de' MMMM 'de' yyyy", new Locale("es"));
|
||||||
|
return dateFormat.format(date);
|
||||||
|
}
|
||||||
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return isoDate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isSameDay(Date now, Date date) {
|
||||||
|
Calendar cal1 = Calendar.getInstance();
|
||||||
|
Calendar cal2 = Calendar.getInstance();
|
||||||
|
cal1.setTime(now);
|
||||||
|
cal2.setTime(date);
|
||||||
|
return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
|
||||||
|
cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isYesterday(Date now, Date date) {
|
||||||
|
Calendar cal1 = Calendar.getInstance();
|
||||||
|
Calendar cal2 = Calendar.getInstance();
|
||||||
|
cal1.setTime(now);
|
||||||
|
cal2.setTime(date);
|
||||||
|
cal1.add(Calendar.DAY_OF_YEAR, -1);
|
||||||
|
return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
|
||||||
|
cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="@color/textPrimary"
|
||||||
|
android:pathData="M12.1,8.64l-.1.1-.1-.1C10.14,6.6 6.6,6.6 4.6,8.64c-2,2-2,5.24 0,7.24L12,23l7.4-7.12c2-2 2-5.24 0-7.24 -2-2-5.24-2-7.24,0z"
|
||||||
|
android:strokeWidth="1"
|
||||||
|
android:strokeColor="@color/textPrimary"
|
||||||
|
android:strokeLineJoin="round"
|
||||||
|
android:strokeLineCap="round" />
|
||||||
|
</vector>
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="@color/pink"
|
||||||
|
android:pathData="M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41 0.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z"/>
|
||||||
|
</vector>
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FF000000"
|
||||||
|
android:pathData="M16.5,3c-1.74,0 -3.41,0.81 -4.5,2.09C10.91,3.81 9.24,3 7.5,3 4.42,3 2,5.42 2,8.5c0,3.78 3.4,6.86 8.55,11.54L12,21.35l1.45,-1.32C18.6,15.36 22,12.28 22,8.5 22,5.42 19.58,3 16.5,3zM12.1,18.55l-0.1,0.1 -0.11,-0.1C7.14,14.24 4,11.39 4,8.5 4,6.5 5.5,5 7.5,5c1.54,0 3.04,1 3.57,2.36h1.87C13.46,6 14.96,5 16.5,5 18.5,5 20,6.5 20,8.5c0,2.89 -3.14,5.74 -7.9,10.05z" />
|
||||||
|
</vector>
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:padding="16dp"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/commentInput"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="Escribe tu comentario" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/sendComment"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Enviar"
|
||||||
|
android:layout_gravity="end"
|
||||||
|
android:layout_marginTop="8dp"/>
|
||||||
|
</LinearLayout>
|
||||||
|
|
@ -0,0 +1,69 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:padding="8dp"
|
||||||
|
android:background="@color/primary">
|
||||||
|
|
||||||
|
<!-- Avatar del usuario -->
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/commentAvatar"
|
||||||
|
android:layout_width="32dp"
|
||||||
|
android:layout_height="32dp"
|
||||||
|
android:scaleType="centerCrop"
|
||||||
|
android:src="@drawable/ic_profile"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:background="@drawable/circle_mask" />
|
||||||
|
|
||||||
|
<!-- Contenido del comentario -->
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1">
|
||||||
|
|
||||||
|
<!-- Nombre del usuario -->
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/commentUsername"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Username"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:textSize="13sp" />
|
||||||
|
|
||||||
|
<!-- Texto del comentario -->
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/commentText"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Comentario aquí"
|
||||||
|
android:textColor="@color/textPrimary"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:lineSpacingExtra="2dp"
|
||||||
|
android:maxLines="5"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:paddingEnd="8dp" />
|
||||||
|
|
||||||
|
<!-- Fecha -->
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/commentDate"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="hace 5 min"
|
||||||
|
android:textSize="11sp"
|
||||||
|
android:textColor="@color/gray" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<!-- Botón de like -->
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/commentLikeButton"
|
||||||
|
android:layout_width="32dp"
|
||||||
|
android:layout_height="32dp"
|
||||||
|
android:src="@drawable/ic_heart"
|
||||||
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
|
android:contentDescription="@string/like_comment"
|
||||||
|
app:tint="@color/gray" />
|
||||||
|
</LinearLayout>
|
||||||
Loading…
Reference in New Issue