mirror of
				https://codeberg.org/tom79/Fedilab.git
				synced 2025-10-20 11:20:16 +03:00 
			
		
		
		
	Fix crashes
This commit is contained in:
		
							parent
							
								
									e8e5af7abe
								
							
						
					
					
						commit
						ea31842dba
					
				
					 6 changed files with 55 additions and 28 deletions
				
			
		|  | @ -164,7 +164,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt | ||||||
|     public static String regex_home, regex_local, regex_public; |     public static String regex_home, regex_local, regex_public; | ||||||
|     public static BaseAccount currentAccount; |     public static BaseAccount currentAccount; | ||||||
|     Fragment currentFragment; |     Fragment currentFragment; | ||||||
|     public static String slugOfFirstFragment; | 
 | ||||||
|     private AppBarConfiguration mAppBarConfiguration; |     private AppBarConfiguration mAppBarConfiguration; | ||||||
|     private ActivityMainBinding binding; |     private ActivityMainBinding binding; | ||||||
|     private final BroadcastReceiver broadcast_error_message = new BroadcastReceiver() { |     private final BroadcastReceiver broadcast_error_message = new BroadcastReceiver() { | ||||||
|  | @ -871,7 +871,6 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt | ||||||
|                         .observe(this, pinned -> { |                         .observe(this, pinned -> { | ||||||
|                             this.pinned = pinned; |                             this.pinned = pinned; | ||||||
|                             //Initialize the slug of the first fragment |                             //Initialize the slug of the first fragment | ||||||
|                             slugOfFirstFragment = PinnedTimelineHelper.firstTimelineSlug(BaseMainActivity.this, pinned, bottomMenu); |  | ||||||
|                             //First it's taken from db (last stored values) |                             //First it's taken from db (last stored values) | ||||||
|                             PinnedTimelineHelper.redrawTopBarPinned(BaseMainActivity.this, binding, pinned, bottomMenu, null); |                             PinnedTimelineHelper.redrawTopBarPinned(BaseMainActivity.this, binding, pinned, bottomMenu, null); | ||||||
|                             //Fetch remote lists for the authenticated account and update them |                             //Fetch remote lists for the authenticated account and update them | ||||||
|  |  | ||||||
|  | @ -153,6 +153,7 @@ import app.fedilab.android.client.entities.api.Status; | ||||||
| import app.fedilab.android.client.entities.app.Account; | import app.fedilab.android.client.entities.app.Account; | ||||||
| import app.fedilab.android.client.entities.app.BaseAccount; | import app.fedilab.android.client.entities.app.BaseAccount; | ||||||
| import app.fedilab.android.client.entities.app.ReleaseNote; | import app.fedilab.android.client.entities.app.ReleaseNote; | ||||||
|  | import app.fedilab.android.client.entities.app.Timeline; | ||||||
| import app.fedilab.android.databinding.PopupReleaseNotesBinding; | import app.fedilab.android.databinding.PopupReleaseNotesBinding; | ||||||
| import app.fedilab.android.exception.DBException; | import app.fedilab.android.exception.DBException; | ||||||
| import app.fedilab.android.interfaces.OnDownloadInterface; | import app.fedilab.android.interfaces.OnDownloadInterface; | ||||||
|  | @ -217,6 +218,7 @@ public class Helper { | ||||||
| 
 | 
 | ||||||
|     public static final String ARG_STATUS_DRAFT = "ARG_STATUS_DRAFT"; |     public static final String ARG_STATUS_DRAFT = "ARG_STATUS_DRAFT"; | ||||||
|     public static final String ARG_STATUS_SCHEDULED = "ARG_STATUS_SCHEDULED"; |     public static final String ARG_STATUS_SCHEDULED = "ARG_STATUS_SCHEDULED"; | ||||||
|  |     public static final String ARG_SLUG_OF_FIRST_FRAGMENT = "ARG_SLUG_OF_FIRST_FRAGMENT"; | ||||||
| 
 | 
 | ||||||
|     public static final String ARG_STATUS_DRAFT_ID = "ARG_STATUS_DRAFT_ID"; |     public static final String ARG_STATUS_DRAFT_ID = "ARG_STATUS_DRAFT_ID"; | ||||||
|     public static final String ARG_STATUS_REPLY = "ARG_STATUS_REPLY"; |     public static final String ARG_STATUS_REPLY = "ARG_STATUS_REPLY"; | ||||||
|  | @ -1871,4 +1873,26 @@ public class Helper { | ||||||
|     public interface OnAttachmentCopied { |     public interface OnAttachmentCopied { | ||||||
|         void onAttachmentCopied(Attachment attachment); |         void onAttachmentCopied(Attachment attachment); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     //Allow to store in shared preference first visible fragment when the app starts | ||||||
|  |     private static String slugOfFirstFragment; | ||||||
|  | 
 | ||||||
|  |     public static String getSlugOfFirstFragment(Context context, String userId, String instance) { | ||||||
|  |         if (slugOfFirstFragment != null) { | ||||||
|  |             return slugOfFirstFragment; | ||||||
|  |         } | ||||||
|  |         SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); | ||||||
|  |         return sharedpreferences.getString(Helper.ARG_SLUG_OF_FIRST_FRAGMENT + userId + instance, Timeline.TimeLineEnum.HOME.getValue()); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public static void setSlugOfFirstFragment(Context context, String slug, String userId, String instance) { | ||||||
|  |         if (slug != null) { | ||||||
|  |             SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); | ||||||
|  |             SharedPreferences.Editor editor = sharedpreferences.edit(); | ||||||
|  |             slugOfFirstFragment = slug; | ||||||
|  |             editor.putString(Helper.ARG_SLUG_OF_FIRST_FRAGMENT + userId + instance, slug); | ||||||
|  |             editor.apply(); | ||||||
|  |         } | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -102,11 +102,12 @@ public class PinnedTimelineHelper { | ||||||
|      * @return String - slug |      * @return String - slug | ||||||
|      */ |      */ | ||||||
|     public static String firstTimelineSlug(Context context, Pinned pinned, BottomMenu bottomMenu) { |     public static String firstTimelineSlug(Context context, Pinned pinned, BottomMenu bottomMenu) { | ||||||
|         String slug = null; |         String slug = Timeline.TimeLineEnum.HOME.getValue(); | ||||||
|         SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); |         SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); | ||||||
|         boolean singleBar = sharedpreferences.getBoolean(context.getString(R.string.SET_USE_SINGLE_TOPBAR), false); |         boolean singleBar = sharedpreferences.getBoolean(context.getString(R.string.SET_USE_SINGLE_TOPBAR), false); | ||||||
|         PinnedTimeline pinnedTimelineMin = null; |         PinnedTimeline pinnedTimelineMin = null; | ||||||
|         if (singleBar) { |         if (singleBar) { | ||||||
|  |             if (pinned != null && pinned.pinnedTimelines != null) { | ||||||
|                 for (PinnedTimeline pinnedTimeline : pinned.pinnedTimelines) { |                 for (PinnedTimeline pinnedTimeline : pinned.pinnedTimelines) { | ||||||
|                     if (pinnedTimeline.displayed) { |                     if (pinnedTimeline.displayed) { | ||||||
|                         if (pinnedTimelineMin == null) { |                         if (pinnedTimelineMin == null) { | ||||||
|  | @ -116,6 +117,7 @@ public class PinnedTimelineHelper { | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|  |             } | ||||||
|         } else { |         } else { | ||||||
|             if (bottomMenu != null && bottomMenu.bottom_menu != null && bottomMenu.bottom_menu.size() > 0) { |             if (bottomMenu != null && bottomMenu.bottom_menu != null && bottomMenu.bottom_menu.size() > 0) { | ||||||
|                 BottomMenu.MenuItem menuItem = bottomMenu.bottom_menu.get(0); |                 BottomMenu.MenuItem menuItem = bottomMenu.bottom_menu.get(0); | ||||||
|  | @ -155,6 +157,10 @@ public class PinnedTimelineHelper { | ||||||
|         if (pinned.pinnedTimelines == null) { |         if (pinned.pinnedTimelines == null) { | ||||||
|             pinned.pinnedTimelines = new ArrayList<>(); |             pinned.pinnedTimelines = new ArrayList<>(); | ||||||
|         } |         } | ||||||
|  |         //Set the slug of first visible fragment | ||||||
|  |         String slugOfFirstFragment = PinnedTimelineHelper.firstTimelineSlug(activity, pinned, bottomMenu); | ||||||
|  |         Helper.setSlugOfFirstFragment(activity, slugOfFirstFragment, currentUserID, currentInstance); | ||||||
|  | 
 | ||||||
|         SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity); |         SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity); | ||||||
|         boolean singleBar = sharedpreferences.getBoolean(activity.getString(R.string.SET_USE_SINGLE_TOPBAR), false); |         boolean singleBar = sharedpreferences.getBoolean(activity.getString(R.string.SET_USE_SINGLE_TOPBAR), false); | ||||||
|         boolean timeInList = sharedpreferences.getBoolean(activity.getString(R.string.SET_TIMELINES_IN_A_LIST), false); |         boolean timeInList = sharedpreferences.getBoolean(activity.getString(R.string.SET_TIMELINES_IN_A_LIST), false); | ||||||
|  |  | ||||||
|  | @ -15,7 +15,8 @@ package app.fedilab.android.ui.fragment.timeline; | ||||||
|  * see <http://www.gnu.org/licenses>. */ |  * see <http://www.gnu.org/licenses>. */ | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| import static app.fedilab.android.BaseMainActivity.slugOfFirstFragment; | import static app.fedilab.android.BaseMainActivity.currentInstance; | ||||||
|  | import static app.fedilab.android.BaseMainActivity.currentUserID; | ||||||
| 
 | 
 | ||||||
| import android.content.SharedPreferences; | import android.content.SharedPreferences; | ||||||
| import android.os.Bundle; | import android.os.Bundle; | ||||||
|  | @ -42,6 +43,7 @@ import app.fedilab.android.client.entities.app.StatusCache; | ||||||
| import app.fedilab.android.client.entities.app.Timeline; | import app.fedilab.android.client.entities.app.Timeline; | ||||||
| import app.fedilab.android.databinding.FragmentPaginationBinding; | import app.fedilab.android.databinding.FragmentPaginationBinding; | ||||||
| import app.fedilab.android.exception.DBException; | import app.fedilab.android.exception.DBException; | ||||||
|  | import app.fedilab.android.helper.Helper; | ||||||
| import app.fedilab.android.helper.MastodonHelper; | import app.fedilab.android.helper.MastodonHelper; | ||||||
| import app.fedilab.android.helper.ThemeHelper; | import app.fedilab.android.helper.ThemeHelper; | ||||||
| import app.fedilab.android.ui.drawer.ConversationAdapter; | import app.fedilab.android.ui.drawer.ConversationAdapter; | ||||||
|  | @ -83,7 +85,7 @@ public class FragmentMastodonConversation extends Fragment implements Conversati | ||||||
|     @Override |     @Override | ||||||
|     public void onResume() { |     public void onResume() { | ||||||
|         super.onResume(); |         super.onResume(); | ||||||
|         if (Timeline.TimeLineEnum.CONVERSATION.getValue().compareTo(slugOfFirstFragment) != 0 && !isViewInitialized) { |         if (Timeline.TimeLineEnum.CONVERSATION.getValue().compareTo(Helper.getSlugOfFirstFragment(requireActivity(), currentUserID, currentInstance)) != 0 && !isViewInitialized) { | ||||||
|             isViewInitialized = true; |             isViewInitialized = true; | ||||||
|             initializeConversationCommonView(initialConversations); |             initializeConversationCommonView(initialConversations); | ||||||
|         } |         } | ||||||
|  | @ -218,6 +220,7 @@ public class FragmentMastodonConversation extends Fragment implements Conversati | ||||||
|     public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { |     public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { | ||||||
|         super.onViewCreated(view, savedInstanceState); |         super.onViewCreated(view, savedInstanceState); | ||||||
| 
 | 
 | ||||||
|  |         isViewInitialized = Timeline.TimeLineEnum.CONVERSATION.getValue().compareTo(Helper.getSlugOfFirstFragment(requireActivity(), currentUserID, currentInstance)) == 0; | ||||||
|         int c1 = getResources().getColor(R.color.cyanea_accent_reference); |         int c1 = getResources().getColor(R.color.cyanea_accent_reference); | ||||||
|         binding.swipeContainer.setProgressBackgroundColorSchemeColor(getResources().getColor(R.color.cyanea_primary_reference)); |         binding.swipeContainer.setProgressBackgroundColorSchemeColor(getResources().getColor(R.color.cyanea_primary_reference)); | ||||||
|         binding.swipeContainer.setColorSchemeColors( |         binding.swipeContainer.setColorSchemeColors( | ||||||
|  |  | ||||||
|  | @ -14,7 +14,8 @@ package app.fedilab.android.ui.fragment.timeline; | ||||||
|  * You should have received a copy of the GNU General Public License along with Fedilab; if not, |  * You should have received a copy of the GNU General Public License along with Fedilab; if not, | ||||||
|  * see <http://www.gnu.org/licenses>. */ |  * see <http://www.gnu.org/licenses>. */ | ||||||
| 
 | 
 | ||||||
| import static app.fedilab.android.BaseMainActivity.slugOfFirstFragment; | import static app.fedilab.android.BaseMainActivity.currentInstance; | ||||||
|  | import static app.fedilab.android.BaseMainActivity.currentUserID; | ||||||
| 
 | 
 | ||||||
| import android.content.BroadcastReceiver; | import android.content.BroadcastReceiver; | ||||||
| import android.content.Context; | import android.content.Context; | ||||||
|  | @ -138,7 +139,7 @@ public class FragmentMastodonNotification extends Fragment implements Notificati | ||||||
|                              ViewGroup container, Bundle savedInstanceState) { |                              ViewGroup container, Bundle savedInstanceState) { | ||||||
| 
 | 
 | ||||||
|         flagLoading = false; |         flagLoading = false; | ||||||
|         isViewInitialized = Timeline.TimeLineEnum.NOTIFICATION.getValue().compareTo(slugOfFirstFragment) == 0; |         isViewInitialized = Timeline.TimeLineEnum.NOTIFICATION.getValue().compareTo(Helper.getSlugOfFirstFragment(requireActivity(), currentUserID, currentInstance)) == 0; | ||||||
|         binding = FragmentPaginationBinding.inflate(inflater, container, false); |         binding = FragmentPaginationBinding.inflate(inflater, container, false); | ||||||
|         View root = binding.getRoot(); |         View root = binding.getRoot(); | ||||||
|         if (getArguments() != null) { |         if (getArguments() != null) { | ||||||
|  | @ -294,7 +295,7 @@ public class FragmentMastodonNotification extends Fragment implements Notificati | ||||||
|     @Override |     @Override | ||||||
|     public void onResume() { |     public void onResume() { | ||||||
|         super.onResume(); |         super.onResume(); | ||||||
|         if (Timeline.TimeLineEnum.NOTIFICATION.getValue().compareTo(slugOfFirstFragment) != 0 && !isViewInitialized) { |         if (Timeline.TimeLineEnum.NOTIFICATION.getValue().compareTo(Helper.getSlugOfFirstFragment(requireActivity(), currentUserID, currentInstance)) != 0 && !isViewInitialized) { | ||||||
|             isViewInitialized = true; |             isViewInitialized = true; | ||||||
|             initializeNotificationView(initialNotifications); |             initializeNotificationView(initialNotifications); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  | @ -15,8 +15,9 @@ package app.fedilab.android.ui.fragment.timeline; | ||||||
|  * see <http://www.gnu.org/licenses>. */ |  * see <http://www.gnu.org/licenses>. */ | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | import static app.fedilab.android.BaseMainActivity.currentInstance; | ||||||
|  | import static app.fedilab.android.BaseMainActivity.currentUserID; | ||||||
| import static app.fedilab.android.BaseMainActivity.networkAvailable; | import static app.fedilab.android.BaseMainActivity.networkAvailable; | ||||||
| import static app.fedilab.android.BaseMainActivity.slugOfFirstFragment; |  | ||||||
| 
 | 
 | ||||||
| import android.content.BroadcastReceiver; | import android.content.BroadcastReceiver; | ||||||
| import android.content.Context; | import android.content.Context; | ||||||
|  | @ -145,7 +146,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. | ||||||
|     @Override |     @Override | ||||||
|     public void onResume() { |     public void onResume() { | ||||||
|         super.onResume(); |         super.onResume(); | ||||||
|         if (slug != null && slugOfFirstFragment != null && slug.compareTo(slugOfFirstFragment) != 0 && !isViewInitialized) { |         if (slug != null && slug.compareTo(Helper.getSlugOfFirstFragment(requireActivity(), currentUserID, currentInstance)) != 0 && !isViewInitialized) { | ||||||
|             isViewInitialized = true; |             isViewInitialized = true; | ||||||
|             initializeStatusesCommonView(initialStatuses); |             initializeStatusesCommonView(initialStatuses); | ||||||
|         } |         } | ||||||
|  | @ -255,10 +256,8 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. | ||||||
|         //Only fragment in main view pager should not have the view initialized |         //Only fragment in main view pager should not have the view initialized | ||||||
|         //AND Only the first fragment will initialize its view |         //AND Only the first fragment will initialize its view | ||||||
|         if (!isViewInitialized) { |         if (!isViewInitialized) { | ||||||
|             if (slug != null && slugOfFirstFragment != null) { |             if (slug != null) { | ||||||
|                 isViewInitialized = slug.compareTo(slugOfFirstFragment) == 0; |                 isViewInitialized = slug.compareTo(Helper.getSlugOfFirstFragment(requireActivity(), currentUserID, currentInstance)) == 0; | ||||||
|             } else if (timelineType != null) { |  | ||||||
|                 isViewInitialized = timelineType.compareTo(Timeline.TimeLineEnum.HOME) == 0; |  | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); |         SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); | ||||||
|  | @ -546,8 +545,8 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. | ||||||
|      * @param direction - DIRECTION null if first call, then is set to TOP or BOTTOM depending of scroll |      * @param direction - DIRECTION null if first call, then is set to TOP or BOTTOM depending of scroll | ||||||
|      */ |      */ | ||||||
|     private void routeCommon(DIRECTION direction, boolean fetchingMissing, Status status) { |     private void routeCommon(DIRECTION direction, boolean fetchingMissing, Status status) { | ||||||
|         if (direction == null && !isViewInitialized && slug != null && slugOfFirstFragment != null) { |         if (direction == null && !isViewInitialized && slug != null) { | ||||||
|             isViewInitialized = slug.compareTo(slugOfFirstFragment) == 0; |             isViewInitialized = slug.compareTo(Helper.getSlugOfFirstFragment(requireActivity(), currentUserID, currentInstance)) == 0; | ||||||
|         } |         } | ||||||
|         if (binding == null || getActivity() == null || !isAdded()) { |         if (binding == null || getActivity() == null || !isAdded()) { | ||||||
|             return; |             return; | ||||||
|  | @ -604,18 +603,13 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. | ||||||
|         boolean useCache = sharedpreferences.getBoolean(getString(R.string.SET_USE_CACHE), true); |         boolean useCache = sharedpreferences.getBoolean(getString(R.string.SET_USE_CACHE), true); | ||||||
| 
 | 
 | ||||||
|         Handler handler = new Handler(); |         Handler handler = new Handler(); | ||||||
|         //The action for fetching new messages is delayed for other timelines than HOME |  | ||||||
|         if (slugOfFirstFragment == null) { |  | ||||||
|             slugOfFirstFragment = slug; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         handler.postDelayed(() -> { |         handler.postDelayed(() -> { | ||||||
|             if (useCache && direction != DIRECTION.SCROLL_TOP && direction != DIRECTION.FETCH_NEW) { |             if (useCache && direction != DIRECTION.SCROLL_TOP && direction != DIRECTION.FETCH_NEW) { | ||||||
|                 getCachedStatus(direction, fetchingMissing, timelineParams); |                 getCachedStatus(direction, fetchingMissing, timelineParams); | ||||||
|             } else { |             } else { | ||||||
|                 getLiveStatus(direction, fetchingMissing, timelineParams, status); |                 getLiveStatus(direction, fetchingMissing, timelineParams, status); | ||||||
|             } |             } | ||||||
|         }, slug.compareTo(slugOfFirstFragment) == 0 ? 0 : 1000); |         }, slug.compareTo(Helper.getSlugOfFirstFragment(requireActivity(), currentUserID, currentInstance)) == 0 ? 0 : 1000); | ||||||
| 
 | 
 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue