diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java b/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java index fa445643..76128f89 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java @@ -909,7 +909,9 @@ public class Helper { if (args != null) fragment.setArguments(args); ft.add(containerViewId, fragment, tag); if (backStackName != null) ft.addToBackStack(backStackName); - ft.commit(); + if(!fragmentManager.isDestroyed()) { + ft.commit(); + } } fragmentManager.executePendingTransactions(); return fragment; @@ -1138,11 +1140,13 @@ public class Helper { .toSquare() .setBackgroundColor(fetchAccentColor(activity)) .build(); - Glide.with(activity) - .asDrawable() - .load(avatar) - .apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(10))) - .into(view); + if (Helper.isValidContextForGlide(activity)) { + Glide.with(activity) + .asDrawable() + .load(avatar) + .apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(10))) + .into(view); + } return; } } diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/media/FragmentMediaProfile.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/media/FragmentMediaProfile.java index bea3e7b6..c1fdd45b 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/media/FragmentMediaProfile.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/media/FragmentMediaProfile.java @@ -64,36 +64,41 @@ public class FragmentMediaProfile extends Fragment { private ImageAdapter imageAdapter; private boolean checkRemotely; private String accountId; - + private Bundle arguments; @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { binding = FragmentPaginationBinding.inflate(inflater, container, false); + arguments = getArguments(); + return binding.getRoot(); + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); boolean displayScrollBar = sharedpreferences.getBoolean(getString(R.string.SET_TIMELINE_SCROLLBAR), false); binding.recyclerView.setVerticalScrollBarEnabled(displayScrollBar); - if (getArguments() != null) { - long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1); + if (arguments != null) { + long bundleId = arguments.getLong(Helper.ARG_INTENT_ID, -1); if (bundleId != -1) { new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, this::initializeAfterBundle); } else { - if (getArguments().containsKey(Helper.ARG_CACHED_ACCOUNT_ID)) { + if (arguments.containsKey(Helper.ARG_CACHED_ACCOUNT_ID)) { try { - accountTimeline = new CachedBundle(requireActivity()).getCachedAccount(currentAccount, getArguments().getString(Helper.ARG_CACHED_ACCOUNT_ID)); + accountTimeline = new CachedBundle(requireActivity()).getCachedAccount(currentAccount, arguments.getString(Helper.ARG_CACHED_ACCOUNT_ID)); } catch (DBException e) { e.printStackTrace(); } } - initializeAfterBundle(getArguments()); - + initializeAfterBundle(arguments); } - } else { - initializeAfterBundle(null); } - return binding.getRoot(); } + + private void initializeAfterBundle(Bundle bundle) { if (bundle != null) { @@ -102,7 +107,9 @@ public class FragmentMediaProfile extends Fragment { } checkRemotely = bundle.getBoolean(Helper.ARG_CHECK_REMOTELY, false); } - + if(accountTimeline == null) { + return; + } flagLoading = false; accountsVM = new ViewModelProvider(requireActivity()).get(AccountsVM.class); mediaStatuses = new ArrayList<>(); @@ -141,10 +148,6 @@ public class FragmentMediaProfile extends Fragment { } - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - } /** * Intialize the common view for statuses on different timelines diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonAccount.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonAccount.java index f55c7492..dafa63af 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonAccount.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonAccount.java @@ -76,6 +76,7 @@ public class FragmentMastodonAccount extends Fragment { private Boolean local; private boolean checkRemotely; private String instance, token, remoteAccountId; + private Bundle arguments; public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -84,27 +85,8 @@ public class FragmentMastodonAccount extends Fragment { token = currentToken; flagLoading = false; binding = FragmentPaginationBinding.inflate(inflater, container, false); - SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); - boolean displayScrollBar = sharedpreferences.getBoolean(getString(R.string.SET_TIMELINE_SCROLLBAR), false); - binding.recyclerView.setVerticalScrollBarEnabled(displayScrollBar); - if (getArguments() != null) { - long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1); - if (bundleId != -1) { - new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, this::initializeAfterBundle); - } else { - if (getArguments().containsKey(Helper.ARG_CACHED_ACCOUNT_ID)) { - try { - accountTimeline = new CachedBundle(requireActivity()).getCachedAccount(currentAccount, getArguments().getString(Helper.ARG_CACHED_ACCOUNT_ID)); - } catch (DBException e) { - e.printStackTrace(); - } - } - initializeAfterBundle(getArguments()); - } - } else { - initializeAfterBundle(null); - } + arguments = getArguments(); return binding.getRoot(); } @@ -149,7 +131,26 @@ public class FragmentMastodonAccount extends Fragment { super.onViewCreated(view, savedInstanceState); binding.loader.setVisibility(View.VISIBLE); binding.recyclerView.setVisibility(View.GONE); - + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); + boolean displayScrollBar = sharedpreferences.getBoolean(getString(R.string.SET_TIMELINE_SCROLLBAR), false); + binding.recyclerView.setVerticalScrollBarEnabled(displayScrollBar); + if (arguments != null) { + long bundleId = arguments.getLong(Helper.ARG_INTENT_ID, -1); + if (bundleId != -1) { + new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, this::initializeAfterBundle); + } else { + if (arguments.containsKey(Helper.ARG_CACHED_ACCOUNT_ID)) { + try { + accountTimeline = new CachedBundle(requireActivity()).getCachedAccount(currentAccount, arguments.getString(Helper.ARG_CACHED_ACCOUNT_ID)); + } catch (DBException e) { + e.printStackTrace(); + } + } + initializeAfterBundle(arguments); + } + } else { + initializeAfterBundle(null); + } } /** diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonContext.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonContext.java index e8d6bc38..fc4699a7 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonContext.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonContext.java @@ -28,6 +28,7 @@ import android.view.View; import android.view.ViewGroup; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import androidx.lifecycle.ViewModelProvider; @@ -157,6 +158,8 @@ public class FragmentMastodonContext extends Fragment { return found ? position : -1; } + private Bundle arguments; + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -165,13 +168,19 @@ public class FragmentMastodonContext extends Fragment { focusedStatusURI = null; refresh = true; binding = FragmentPaginationBinding.inflate(inflater, container, false); - if (getArguments() != null) { - long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1); + arguments = getArguments(); + return binding.getRoot(); + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + if (arguments != null) { + long bundleId = arguments.getLong(Helper.ARG_INTENT_ID, -1); new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, this::initializeAfterBundle); } else { initializeAfterBundle(null); } - return binding.getRoot(); } private void initializeAfterBundle(Bundle bundle) { diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java index 6a64147c..5a00bc8a 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java @@ -90,6 +90,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. private StatusAdapter statusAdapter; private Timeline.TimeLineEnum timelineType; private List timelineStatuses; + private Bundle arguments; //Handle actions that can be done in other fragments private final BroadcastReceiver receive_action = new BroadcastReceiver() { @Override @@ -348,16 +349,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. } } - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - binding.loader.setVisibility(View.VISIBLE); - binding.recyclerView.setVisibility(View.GONE); - if (search != null) { - binding.swipeContainer.setRefreshing(false); - binding.swipeContainer.setEnabled(false); - } - } + @Override public void onCreate(@Nullable Bundle savedInstanceState) { @@ -369,24 +361,37 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. timelineType = Timeline.TimeLineEnum.HOME; binding = FragmentPaginationBinding.inflate(inflater, container, false); - if (getArguments() != null) { - long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1); + arguments = getArguments(); + return binding.getRoot(); + } + + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + binding.loader.setVisibility(View.VISIBLE); + binding.recyclerView.setVisibility(View.GONE); + if (search != null) { + binding.swipeContainer.setRefreshing(false); + binding.swipeContainer.setEnabled(false); + } + + if (arguments != null) { + long bundleId = arguments.getLong(Helper.ARG_INTENT_ID, -1); if (bundleId != -1) { new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, this::initializeAfterBundle); } else { - if (getArguments().containsKey(Helper.ARG_CACHED_ACCOUNT_ID)) { + if (arguments.containsKey(Helper.ARG_CACHED_ACCOUNT_ID)) { try { - accountTimeline = new CachedBundle(requireActivity()).getCachedAccount(currentAccount, getArguments().getString(Helper.ARG_CACHED_ACCOUNT_ID)); + accountTimeline = new CachedBundle(requireActivity()).getCachedAccount(currentAccount, arguments.getString(Helper.ARG_CACHED_ACCOUNT_ID)); } catch (DBException e) { e.printStackTrace(); } } - initializeAfterBundle(getArguments()); + initializeAfterBundle(arguments); } } - return binding.getRoot(); } - private void initializeAfterBundle(Bundle bundle) { if (bundle != null) { timelineType = (Timeline.TimeLineEnum) bundle.get(Helper.ARG_TIMELINE_TYPE); diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentProfileTimeline.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentProfileTimeline.java index b1c1f9d7..e0b5bc73 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentProfileTimeline.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentProfileTimeline.java @@ -47,21 +47,26 @@ public class FragmentProfileTimeline extends Fragment { private FragmentProfileTimelinesBinding binding; private boolean checkRemotely; private boolean show_boosts = true, show_replies = true; - + private Bundle arguments; public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { binding = FragmentProfileTimelinesBinding.inflate(inflater, container, false); - if (getArguments() != null) { - String cached_account_id = getArguments().getString(Helper.ARG_CACHED_ACCOUNT_ID); + arguments = getArguments(); + return binding.getRoot(); + } + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + if (arguments != null) { + String cached_account_id = arguments.getString(Helper.ARG_CACHED_ACCOUNT_ID); try { account = new CachedBundle(requireActivity()).getCachedAccount(currentAccount, cached_account_id); } catch (DBException e) { e.printStackTrace(); } - checkRemotely = getArguments().getBoolean(Helper.ARG_CHECK_REMOTELY, false); + checkRemotely = arguments.getBoolean(Helper.ARG_CHECK_REMOTELY, false); initializeAfterBundle(); } - return binding.getRoot(); } @@ -163,10 +168,6 @@ public class FragmentProfileTimeline extends Fragment { } - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - } }