Add edit button to folder items

This commit is contained in:
M66B 2018-08-11 18:04:50 +00:00
parent cdecb5e205
commit 850397c4fa
4 changed files with 27 additions and 32 deletions

View File

@ -26,6 +26,7 @@ import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
@ -48,14 +49,14 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
private List<TupleFolderEx> all = new ArrayList<>(); private List<TupleFolderEx> all = new ArrayList<>();
private List<TupleFolderEx> filtered = new ArrayList<>(); private List<TupleFolderEx> filtered = new ArrayList<>();
public class ViewHolder extends RecyclerView.ViewHolder public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
implements View.OnClickListener, View.OnLongClickListener {
View itemView; View itemView;
TextView tvName; TextView tvName;
TextView tvMessages; TextView tvMessages;
TextView tvType; TextView tvType;
TextView tvAfter; TextView tvAfter;
ImageView ivSync; ImageView ivSync;
ImageButton ibEdit;
TextView tvError; TextView tvError;
ViewHolder(View itemView) { ViewHolder(View itemView) {
@ -67,18 +68,18 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
tvType = itemView.findViewById(R.id.tvType); tvType = itemView.findViewById(R.id.tvType);
tvAfter = itemView.findViewById(R.id.tvAfter); tvAfter = itemView.findViewById(R.id.tvAfter);
ivSync = itemView.findViewById(R.id.ivSync); ivSync = itemView.findViewById(R.id.ivSync);
ibEdit = itemView.findViewById(R.id.ibEdit);
tvError = itemView.findViewById(R.id.tvError); tvError = itemView.findViewById(R.id.tvError);
} }
private void wire(boolean properties) { private void wire(boolean properties) {
itemView.setOnClickListener(this); itemView.setOnClickListener(this);
if (properties) if (properties)
itemView.setOnLongClickListener(this); ibEdit.setOnClickListener(this);
} }
private void unwire() { private void unwire() {
itemView.setOnClickListener(null); itemView.setOnClickListener(null);
itemView.setOnLongClickListener(null);
} }
private void bindTo(TupleFolderEx folder) { private void bindTo(TupleFolderEx folder) {
@ -112,30 +113,22 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
int pos = getAdapterPosition(); int pos = getAdapterPosition();
if (pos == RecyclerView.NO_POSITION) if (pos == RecyclerView.NO_POSITION)
return; return;
TupleFolderEx folder = filtered.get(pos); TupleFolderEx folder = filtered.get(pos);
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context); if (view.getId() == R.id.ibEdit) {
lbm.sendBroadcast( if (!EntityFolder.OUTBOX.equals(folder.type)) {
new Intent(ActivityView.ACTION_VIEW_MESSAGES) LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
.putExtra("folder", folder.id)); lbm.sendBroadcast(
} new Intent(ActivityView.ACTION_EDIT_FOLDER)
.putExtra("id", folder.id));
@Override }
public boolean onLongClick(View view) { } else {
int pos = getAdapterPosition();
if (pos == RecyclerView.NO_POSITION)
return false;
TupleFolderEx folder = filtered.get(pos);
if (!EntityFolder.OUTBOX.equals(folder.type)) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast( lbm.sendBroadcast(
new Intent(ActivityView.ACTION_EDIT_FOLDER) new Intent(ActivityView.ACTION_VIEW_MESSAGES)
.putExtra("id", folder.id)); .putExtra("folder", folder.id));
return true;
} }
return false;
} }
} }

View File

@ -24,7 +24,6 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.Toast;
import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.floatingactionbutton.FloatingActionButton;
@ -107,9 +106,5 @@ public class FragmentFolders extends FragmentEx {
grpReady.setVisibility(View.VISIBLE); grpReady.setVisibility(View.VISIBLE);
} }
}); });
// Show hint
// TODO: find better solution
Toast.makeText(getContext(), R.string.title_item_edit_hint, Toast.LENGTH_SHORT).show();
} }
} }

View File

@ -37,7 +37,7 @@
android:layout_height="24dp" android:layout_height="24dp"
android:layout_marginEnd="6dp" android:layout_marginEnd="6dp"
android:src="@drawable/baseline_mail_outline_24" android:src="@drawable/baseline_mail_outline_24"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toStartOf="@+id/ibEdit"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<TextView <TextView
@ -68,9 +68,18 @@
android:layout_height="24dp" android:layout_height="24dp"
android:layout_marginEnd="6dp" android:layout_marginEnd="6dp"
android:src="@drawable/baseline_sync_24" android:src="@drawable/baseline_sync_24"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toStartOf="@+id/ibEdit"
app:layout_constraintTop_toBottomOf="@id/ivMessages" /> app:layout_constraintTop_toBottomOf="@id/ivMessages" />
<ImageButton
android:id="@+id/ibEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="6dp"
android:src="@drawable/baseline_edit_24"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView <TextView
android:id="@+id/tvError" android:id="@+id/tvError"
android:layout_width="0dp" android:layout_width="0dp"

View File

@ -145,8 +145,6 @@
<string name="title_draft_saved">Draft saved</string> <string name="title_draft_saved">Draft saved</string>
<string name="title_queued">Sending message</string> <string name="title_queued">Sending message</string>
<string name="title_item_edit_hint">Long press item to edit properties</string>
<string name="title_debug_info">Debug info</string> <string name="title_debug_info">Debug info</string>
<string name="title_debug_info_remark">Please describe the problem and indicate the time of the problem:</string> <string name="title_debug_info_remark">Please describe the problem and indicate the time of the problem:</string>
</resources> </resources>