multiple bugs
edgarscr opened this issue · 4 comments
edgarscr commented
golovin47 commented
Hello @edgarscr. Couldn't reproduce such behavior. That means that the issue is most likely in your code. I can help you if you show me your adapter implementation. Transparency of a view is probably related to your layout implementation.
edgarscr commented
package com.carrera_brothers.parkowi.Adapters;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;
import com.carrera_brothers.parkowi.Classes.Ticket;
import com.carrera_brothers.parkowi.R;
import com.google.android.material.card.MaterialCardView;
import com.ramotion.foldingcell.FoldingCell;
import com.squareup.picasso.Picasso;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
public class TicketsAdapter extends ArrayAdapter<Ticket> {
private HashSet<Integer> unfoldedIndexes = new HashSet<>();
private View.OnClickListener defaultRequestBtnClickListener;
public TicketsAdapter(Context context, List<Ticket> objects) {
super(context, 0, objects);
}
@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
// get item for selected view
Ticket item = getItem(position);
// if cell is exists - reuse it, if not - create the new one from resource
FoldingCell cell = (FoldingCell) convertView;
ViewHolder viewHolder;
if (cell == null) {
viewHolder = new ViewHolder();
LayoutInflater vi = LayoutInflater.from(getContext());
cell = (FoldingCell) vi.inflate(R.layout.cell, parent, false);
// binding view parts to view holder
viewHolder.container = cell.findViewById(R.id.cell_ticket_content);
viewHolder.photo = cell.findViewById(R.id.cell_ticket_photo);
viewHolder.photoBig = cell.findViewById(R.id.cell_ticket_photo_big);
viewHolder.number = cell.findViewById(R.id.cell_ticket_number);
viewHolder.numberBig = cell.findViewById(R.id.cell_ticket_number_big);
viewHolder.license = cell.findViewById(R.id.cell_ticket_license);
viewHolder.licenseBig = cell.findViewById(R.id.cell_ticket_license_big);
viewHolder.date = cell.findViewById(R.id.cell_ticket_date);
viewHolder.dateBig = cell.findViewById(R.id.cell_ticket_date_big);
viewHolder.time = cell.findViewById(R.id.cell_ticket_time);
viewHolder.timeBig = cell.findViewById(R.id.cell_ticket_time_big);
viewHolder.customer = cell.findViewById(R.id.cell_ticket_customer);
viewHolder.customerBig = cell.findViewById(R.id.cell_ticket_customer_big);
viewHolder.brand = cell.findViewById(R.id.cell_ticket_brand);
viewHolder.reason1 = cell.findViewById(R.id.cell_ticket_reason1);
viewHolder.reason1Big = cell.findViewById(R.id.cell_ticket_reason1_big);
viewHolder.reason2 = cell.findViewById(R.id.cell_ticket_reason2);
viewHolder.textMessage = cell.findViewById(R.id.cell_ticket_message);
viewHolder.audioMessage = cell.findViewById(R.id.cell_ticket_audio);
viewHolder.editTicket = cell.findViewById(R.id.cell_ticket_edit);
cell.setTag(viewHolder);
} else {
// for existing cell set valid valid state(without animation)
if (unfoldedIndexes.contains(position)) {
cell.unfold(true);
} else {
cell.fold(true);
}
viewHolder = (ViewHolder) cell.getTag();
}
if (null == item)
return cell;
viewHolder.container.setVisibility(View.GONE);
// bind data from selected element to view through view holder
if (item.getPhotos().size() > 0) {
Picasso.get()
.load(item.getPhotos().get(0).getUrl())
//.resize(holder.vieww.getWidth(), holder.vieww.getHeight())
.fit()
.centerCrop()
.placeholder(R.drawable.ic_launcher_background)
.noFade()
//.error(R.drawable.ic_launcher_background)
.into(viewHolder.photo);
Picasso.get()
.load(item.getPhotos().get(0).getUrl())
//.resize(holder.vieww.getWidth(), holder.vieww.getHeight())
.fit()
.centerCrop()
.placeholder(R.drawable.ic_launcher_background)
.noFade()
//.error(R.drawable.ic_launcher_background)
.into(viewHolder.photoBig);
}
viewHolder.number.setText(String.valueOf(item.getTicket_number()));
viewHolder.numberBig.setText(String.valueOf(item.getTicket_number()));
viewHolder.license.setText(item.getLicense());
viewHolder.licenseBig.setText(item.getLicense());
viewHolder.date.setText(item.getTicket_date());
viewHolder.dateBig.setText(item.getTicket_date());
viewHolder.time.setText(item.getTime_watched());
viewHolder.timeBig.setText(item.getTime_watched());
// Customer
if (item.getCustomer() != null) {
viewHolder.customer.setText(item.getCustomer().getName());
viewHolder.customerBig.setText(item.getCustomer().getName());
} else {
viewHolder.customer.setText("Customer: empty");
viewHolder.customerBig.setText("Customer: empty");
}
// Brand
if (item.getCar_brand() != null) {
viewHolder.brand.setText(item.getCar_brand().getName());
} else {
viewHolder.brand.setText("Brand: empty");
}
// Reason 1
if (item.getReason1() != null) {
viewHolder.reason1.setText(String.valueOf(item.getReason1().getTitle()));
viewHolder.reason1Big.setText(String.valueOf(item.getReason1().getTitle()));
} else {
viewHolder.reason1.setText("Reason1: empty");
viewHolder.reason1Big.setText("Reason1: empty");
}
// Reason 2
if (item.getReason2() != null) {
viewHolder.reason2.setText(item.getReason2().getTitle());
} else {
viewHolder.reason2.setText("Reason2: empty");
}
// Message
if (item.getMessage() != null) {
viewHolder.textMessage.setText(item.getMessage());
} else {
viewHolder.textMessage.setText("message: empty");
}
// Audo Message
if (item.getMessage() != null) {
viewHolder.textMessage.setText(item.getMessage());
} else {
viewHolder.textMessage.setVisibility(View.GONE);
}
if (item.getAudioRecorded() != null) {
/*viewHolder.audioMessage.setText(String.valueOf(item.getMessage()));
if(formCheck.getAudioRecorded().getFile().exists()) {
buttonPlayAudio.setVisibility(View.GONE);
buttonStopAudio.setVisibility(View.VISIBLE);
mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource(formCheck.getAudioRecorded().getFile().getAbsolutePath());
mediaPlayer.prepare();
} catch (IOException e) {
e.printStackTrace();
}
mediaPlayer.start();
} else {
Helper.Alert(CreateTicketActivity.this, true, "Error!", "Audio not found");
}*/
} else {
viewHolder.audioMessage.setVisibility(View.GONE);
}
//viewHolder.audioMessage.setText(item.ticket_time);
// set custom btn handler for list item from that item
if (item.getRequestBtnClickListener() != null) {
viewHolder.editTicket.setOnClickListener(item.getRequestBtnClickListener());
} else {
// (optionally) add "default" handler if no handler found in item
viewHolder.editTicket.setOnClickListener(defaultRequestBtnClickListener);
}
return cell;
}
// simple methods for register cell state changes
public void registerToggle(int position) {
if (unfoldedIndexes.contains(position))
registerFold(position);
else
registerUnfold(position);
}
public void registerFold(int position) {
unfoldedIndexes.remove(position);
}
public void registerUnfold(int position) {
unfoldedIndexes.add(position);
}
public View.OnClickListener getDefaultRequestBtnClickListener() {
return defaultRequestBtnClickListener;
}
public void setDefaultRequestBtnClickListener(View.OnClickListener defaultRequestBtnClickListener) {
this.defaultRequestBtnClickListener = defaultRequestBtnClickListener;
}
// View lookup cache
private static class ViewHolder {
LinearLayout container;
ImageView photo;
ImageView photoBig;
TextView number;
TextView numberBig;
TextView license;
TextView licenseBig;
TextView date;
TextView dateBig;
TextView time;
TextView timeBig;
TextView customer;
TextView customerBig;
TextView brand;
TextView reason1;
TextView reason1Big;
TextView reason2;
TextView textMessage;
ImageView audioMessage;
ImageView editTicket;
}
}
cell_content_layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/cell_ticket_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="visible">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:paddingLeft="12dp"
android:paddingTop="7dp"
android:paddingRight="12dp"
android:paddingBottom="7dp">
<TextView
android:id="@+id/cell_ticket_number_big"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="number"
android:textColor="@android:color/white"
android:textSize="20sp" />
<TextView
android:id="@+id/cell_ticket_license_big"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:text="license"
android:textColor="@android:color/white"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/cell_ticket_photo_big"
android:layout_width="match_parent"
android:layout_height="250dp"
android:scaleType="centerCrop"
android:src="@color/colorPrimary" />
</RelativeLayout>
<!-- content body layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorSecondary"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingTop="9dp"
android:paddingRight="20dp"
android:paddingBottom="6dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/cell_ticket_date_big"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_weight="1"
android:text="date" />
<TextView
android:id="@+id/cell_ticket_time_big"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_weight="1"
android:text="time" />
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="9dp"
android:layout_marginBottom="6dp"
android:src="@color/colorPrimary" />
<TextView
android:id="@+id/cell_ticket_customer_big"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_weight="1"
android:hint="customer" />
<TextView
android:id="@+id/cell_ticket_reason1_big"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_weight="1"
android:hint="reason 1" />
<TextView
android:id="@+id/cell_ticket_reason2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_weight="1"
android:hint="reason 2" />
<TextView
android:id="@+id/cell_ticket_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_weight="1"
android:hint="Message" />
<ImageView
android:id="@+id/cell_ticket_audio"
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_marginTop="4dp"
android:src="@drawable/play_audio_ic" />
<ImageView
android:id="@+id/cell_ticket_edit"
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_marginTop="4dp"
android:src="@drawable/ic_create_ticket" />
</LinearLayout>
</LinearLayout>
cell_title_layout
<?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:background="@color/colorWhite"
android:baselineAligned="false"
android:orientation="horizontal">
<!-- LEFT TITLE PART -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="155dp"
android:layout_weight="3"
android:background="@color/colorPrimary"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingLeft="5dp"
android:paddingTop="20dp"
android:paddingRight="5dp"
android:paddingBottom="20dp">
<ImageView
android:id="@+id/cell_ticket_photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foregroundGravity="center"
app:srcCompat="@color/colorPrimary" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/cell_ticket_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="00000000"
android:textAlignment="center"
android:textColor="@android:color/white"
android:textSize="18sp" />
<TextView
android:id="@+id/cell_ticket_brand"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Opel"
android:textAlignment="center"
android:textColor="@android:color/white"
android:textSize="18sp" />
<TextView
android:id="@+id/cell_ticket_license"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="X-XX 000"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="@android:color/white"
android:textSize="14sp" />
</LinearLayout>
</RelativeLayout>
<!-- RIGHT TITLE PART -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingStart="15dp"
android:paddingTop="20dp"
android:paddingEnd="20dp"
android:paddingBottom="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|top"
android:orientation="horizontal">
<TextView
android:id="@+id/cell_ticket_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-5dp"
android:layout_weight="1"
android:ellipsize="marquee"
android:gravity="center|start"
android:singleLine="true"
android:text="0000-00-00 00:00:00"
android:textColor="@android:color/black"
android:textSize="16sp" />
<TextView
android:id="@+id/cell_ticket_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-5dp"
android:layout_weight="1"
android:ellipsize="marquee"
android:gravity="center|end"
android:singleLine="true"
android:text="@string/hint_time"
android:textColor="@android:color/black"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom|center"
android:orientation="vertical">
<ImageView
android:id="@+id/cell_ticket_date_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:src="@color/colorSecondary" />
<TextView
android:id="@+id/cell_ticket_customer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="Customer" />
<TextView
android:id="@+id/cell_ticket_reason1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Reason 1" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
golovin47 commented
The only strange thing i see is this in getView() ->
viewHolder.container.setVisibility(View.GONE);
I suggest you to debug getVIew() method step by step to see what is going on there.
edgarscr commented
the other bug fixed but the image dont appear i need to scroll to display