From e8e3542a2ba512cca3e6d6efa5fbedb1bcee9633 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 24 Jun 2019 13:08:08 +0200 Subject: [PATCH] Fixed adapter snackbar parent view --- .../java/eu/faircode/email/AdapterFolder.java | 15 +++++-------- .../java/eu/faircode/email/AdapterImage.java | 6 +++-- .../eu/faircode/email/AdapterMessage.java | 22 ++++++++----------- .../java/eu/faircode/email/AdapterRule.java | 6 +++-- .../eu/faircode/email/FragmentFolders.java | 2 +- .../eu/faircode/email/FragmentMessages.java | 4 ++-- .../java/eu/faircode/email/FragmentRules.java | 2 +- 7 files changed, 27 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterFolder.java b/app/src/main/java/eu/faircode/email/AdapterFolder.java index 4a6a9ff47f..3a02a74bc2 100644 --- a/app/src/main/java/eu/faircode/email/AdapterFolder.java +++ b/app/src/main/java/eu/faircode/email/AdapterFolder.java @@ -66,6 +66,7 @@ public class AdapterFolder extends RecyclerView.Adapter private Context context; private LayoutInflater inflater; private LifecycleOwner owner; + private View parentView; private List items = new ArrayList<>(); @@ -131,7 +132,7 @@ public class AdapterImage extends RecyclerView.Adapter // Check if viewer available if (ris.size() == 0) { Snackbar.make( - (View) itemView.getParent(), + parentView, context.getString(R.string.title_no_viewer, attachment.type), Snackbar.LENGTH_LONG).show(); return; @@ -177,10 +178,11 @@ public class AdapterImage extends RecyclerView.Adapter } } - AdapterImage(Context context, LifecycleOwner owner) { + AdapterImage(Context context, LifecycleOwner owner, View parentView) { this.context = context; this.inflater = LayoutInflater.from(context); this.owner = owner; + this.parentView = parentView; setHasStableIds(true); } diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 58b142522d..b67e914a83 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -138,6 +138,7 @@ public class AdapterMessage extends RecyclerView.Adapter answers) { if (answers == null || answers.size() == 0) { Snackbar snackbar = Snackbar.make( - (View) itemView.getParent(), + parentView, context.getString(R.string.title_no_answers), Snackbar.LENGTH_LONG); snackbar.setAction(R.string.title_fix, new View.OnClickListener() { @@ -3276,7 +3271,7 @@ public class AdapterMessage extends RecyclerView.Adapter { private Context context; private LifecycleOwner owner; private LayoutInflater inflater; + private View parentView; private List items = new ArrayList<>(); @@ -259,7 +260,7 @@ public class AdapterRule extends RecyclerView.Adapter { @Override protected void onExecuted(Bundle args, Integer applied) { Snackbar.make( - (View) itemView.getParent(), + parentView, context.getString(R.string.title_rule_applied, applied), Snackbar.LENGTH_LONG).show(); } @@ -278,10 +279,11 @@ public class AdapterRule extends RecyclerView.Adapter { } } - AdapterRule(Context context, LifecycleOwner owner) { + AdapterRule(Context context, LifecycleOwner owner, View parentView) { this.context = context; this.owner = owner; this.inflater = LayoutInflater.from(context); + this.parentView = parentView; setHasStableIds(true); } diff --git a/app/src/main/java/eu/faircode/email/FragmentFolders.java b/app/src/main/java/eu/faircode/email/FragmentFolders.java index 1d76f49a3f..6b0d28cbd5 100644 --- a/app/src/main/java/eu/faircode/email/FragmentFolders.java +++ b/app/src/main/java/eu/faircode/email/FragmentFolders.java @@ -144,7 +144,7 @@ public class FragmentFolders extends FragmentBase { itemDecorator.setDrawable(getContext().getDrawable(R.drawable.divider)); rvFolder.addItemDecoration(itemDecorator); - adapter = new AdapterFolder(getContext(), getViewLifecycleOwner(), account, show_hidden, null); + adapter = new AdapterFolder(getContext(), getViewLifecycleOwner(), view, account, show_hidden, null); rvFolder.setAdapter(adapter); fab.setOnClickListener(new View.OnClickListener() { diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index d52aa42fbd..77444167b6 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -501,7 +501,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. boolean filter_duplicates = prefs.getBoolean("filter_duplicates", false); adapter = new AdapterMessage( - getContext(), getViewLifecycleOwner(), + getContext(), getViewLifecycleOwner(), view, viewType, compact, zoom, sort, filter_duplicates, iProperties); rvMessage.setAdapter(adapter); @@ -1926,7 +1926,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. LinearLayoutManager llm = new LinearLayoutManager(getContext()); rvFolder.setLayoutManager(llm); - final AdapterFolder adapter = new AdapterFolder(getContext(), getViewLifecycleOwner(), account, false, + final AdapterFolder adapter = new AdapterFolder(getContext(), getViewLifecycleOwner(), view, account, false, new AdapterFolder.IFolderSelectedListener() { @Override public void onFolderSelected(TupleFolderEx folder) { diff --git a/app/src/main/java/eu/faircode/email/FragmentRules.java b/app/src/main/java/eu/faircode/email/FragmentRules.java index 15059f1793..d353ea3bd4 100644 --- a/app/src/main/java/eu/faircode/email/FragmentRules.java +++ b/app/src/main/java/eu/faircode/email/FragmentRules.java @@ -78,7 +78,7 @@ public class FragmentRules extends FragmentBase { LinearLayoutManager llm = new LinearLayoutManager(getContext()); rvRule.setLayoutManager(llm); - adapter = new AdapterRule(getContext(), getViewLifecycleOwner()); + adapter = new AdapterRule(getContext(), getViewLifecycleOwner(), view); rvRule.setAdapter(adapter); DividerItemDecoration itemDecorator = new DividerItemDecoration(getContext(), llm.getOrientation());