|
@ -51,6 +51,7 @@ import androidx.recyclerview.widget.RecyclerView; |
|
|
public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.ViewHolder> { |
|
|
public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.ViewHolder> { |
|
|
private Context context; |
|
|
private Context context; |
|
|
private LifecycleOwner owner; |
|
|
private LifecycleOwner owner; |
|
|
|
|
|
private boolean readonly; |
|
|
private boolean debug; |
|
|
private boolean debug; |
|
|
|
|
|
|
|
|
private List<EntityAttachment> all = new ArrayList<>(); |
|
|
private List<EntityAttachment> all = new ArrayList<>(); |
|
@ -58,6 +59,7 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi |
|
|
|
|
|
|
|
|
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { |
|
|
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { |
|
|
View itemView; |
|
|
View itemView; |
|
|
|
|
|
ImageView ivDelete; |
|
|
TextView tvName; |
|
|
TextView tvName; |
|
|
TextView tvSize; |
|
|
TextView tvSize; |
|
|
ImageView ivStatus; |
|
|
ImageView ivStatus; |
|
@ -69,6 +71,7 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi |
|
|
super(itemView); |
|
|
super(itemView); |
|
|
|
|
|
|
|
|
this.itemView = itemView; |
|
|
this.itemView = itemView; |
|
|
|
|
|
ivDelete = itemView.findViewById(R.id.ivDelete); |
|
|
tvName = itemView.findViewById(R.id.tvName); |
|
|
tvName = itemView.findViewById(R.id.tvName); |
|
|
tvSize = itemView.findViewById(R.id.tvSize); |
|
|
tvSize = itemView.findViewById(R.id.tvSize); |
|
|
ivStatus = itemView.findViewById(R.id.ivStatus); |
|
|
ivStatus = itemView.findViewById(R.id.ivStatus); |
|
@ -79,10 +82,12 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi |
|
|
|
|
|
|
|
|
private void wire() { |
|
|
private void wire() { |
|
|
itemView.setOnClickListener(this); |
|
|
itemView.setOnClickListener(this); |
|
|
|
|
|
ivDelete.setOnClickListener(this); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void unwire() { |
|
|
private void unwire() { |
|
|
itemView.setOnClickListener(null); |
|
|
itemView.setOnClickListener(null); |
|
|
|
|
|
ivDelete.setOnClickListener(null); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void bindTo(EntityAttachment attachment) { |
|
|
private void bindTo(EntityAttachment attachment) { |
|
@ -103,6 +108,8 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi |
|
|
ivStatus.setVisibility(View.VISIBLE); |
|
|
ivStatus.setVisibility(View.VISIBLE); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ivDelete.setVisibility(readonly ? View.INVISIBLE : View.VISIBLE); |
|
|
|
|
|
|
|
|
if (attachment.progress != null) |
|
|
if (attachment.progress != null) |
|
|
progressbar.setProgress(attachment.progress); |
|
|
progressbar.setProgress(attachment.progress); |
|
|
progressbar.setVisibility( |
|
|
progressbar.setVisibility( |
|
@ -120,7 +127,24 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi |
|
|
if (pos == RecyclerView.NO_POSITION) |
|
|
if (pos == RecyclerView.NO_POSITION) |
|
|
return; |
|
|
return; |
|
|
final EntityAttachment attachment = filtered.get(pos); |
|
|
final EntityAttachment attachment = filtered.get(pos); |
|
|
if (attachment != null) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (view.getId() == R.id.ivDelete) { |
|
|
|
|
|
Bundle args = new Bundle(); |
|
|
|
|
|
args.putLong("id", attachment.id); |
|
|
|
|
|
|
|
|
|
|
|
new SimpleTask<Void>() { |
|
|
|
|
|
@Override |
|
|
|
|
|
protected Void onLoad(Context context, Bundle args) { |
|
|
|
|
|
DB.getInstance(context).attachment().deleteAttachment(attachment.id); |
|
|
|
|
|
File dir = new File(context.getFilesDir(), "attachments"); |
|
|
|
|
|
File file = new File(dir, attachment.filename); |
|
|
|
|
|
file.delete(); |
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
}.load(context, owner, args); |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
if (attachment.filename == null) { |
|
|
if (attachment.filename == null) { |
|
|
if (attachment.progress == null) { |
|
|
if (attachment.progress == null) { |
|
|
Bundle args = new Bundle(); |
|
|
Bundle args = new Bundle(); |
|
@ -183,12 +207,14 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi |
|
|
|
|
|
|
|
|
context.startActivity(intent); |
|
|
context.startActivity(intent); |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
AdapterAttachment(Context context, LifecycleOwner owner) { |
|
|
|
|
|
|
|
|
AdapterAttachment(Context context, LifecycleOwner owner, boolean readonly) { |
|
|
this.context = context; |
|
|
this.context = context; |
|
|
this.owner = owner; |
|
|
this.owner = owner; |
|
|
|
|
|
this.readonly = readonly; |
|
|
this.debug = PreferenceManager.getDefaultSharedPreferences(context).getBoolean("debug", false); |
|
|
this.debug = PreferenceManager.getDefaultSharedPreferences(context).getBoolean("debug", false); |
|
|
setHasStableIds(true); |
|
|
setHasStableIds(true); |
|
|
} |
|
|
} |
|
|