commit c1a20995fd4e0854094528ffbe639d9627a0e023 Author: Fabio Mazza Date: Sat May 30 23:51:34 2026 +0200 Fix status and navigation bar colors, fix open by intent Summary: - Fix status and navigation bar colors in day and night mode on Xiaomi devices (because they follow different rules than standard android) - Make scanning by QR code (or another intent) working again (fix T1446) Test Plan: - Check that system (top) and navigation (bottom) bar colors are consistent and legible - Open stop 476 by scanning the QR Code: https://t.me/librebusto_dev/8567/9477 Reviewers: #libre_busto_hackers, valerio.bozzolan Reviewed By: #libre_busto_hackers, valerio.bozzolan Subscribers: valerio.bozzolan Project Tags: #libre_busto Maniphest Tasks: T1446 Differential Revision: https://gitpull.it/D251 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6ef7a91..8da5a23 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -56,7 +56,7 @@ - - - - - - - - - - - - - - - - - - - + + + + menuActions = Map.of( @@ -108,13 +129,17 @@ public class ActivityPrincipal extends GeneralActivity implements FragmentListen boolean isResolved = activityCustomBackPressed(); Log.d(DEBUG_TAG, "backpress resolved: " + isResolved); if(!isResolved){ - long currentTime = System.currentTimeMillis(); - if(currentTime - lastClosingAttempt < 2000){ - finish(); - } else{ - lastClosingAttempt = currentTime; - Toast.makeText(getApplicationContext(),R.string.back_again_to_close,Toast.LENGTH_SHORT).show(); - } + //if(startedFromIntent){ + // finish(); + //} else{ + long currentTime = System.currentTimeMillis(); + if (currentTime - lastClosingAttempt < 2000) + finish(); + else { + lastClosingAttempt = currentTime; + Toast.makeText(getApplicationContext(), R.string.back_again_to_close, Toast.LENGTH_SHORT).show(); + } + //} } } }; @@ -132,7 +157,6 @@ public class ActivityPrincipal extends GeneralActivity implements FragmentListen //onBackPressed solution required from Android 16 backPressedCallback.setEnabled(true); this.getOnBackPressedDispatcher().addCallback(backPressedCallback); - boolean showingArrivalsFromIntent = false; final Toolbar mToolbar = findViewById(R.id.default_toolbar); setSupportActionBar(mToolbar); @@ -150,27 +174,7 @@ public class ActivityPrincipal extends GeneralActivity implements FragmentListen drawerToggle.syncState(); mDrawer.addDrawerListener(drawerToggle); - mDrawer.addDrawerListener(new DrawerLayout.DrawerListener() { - @Override - public void onDrawerSlide(@NonNull View drawerView, float slideOffset) { - - } - - @Override - public void onDrawerOpened(@NonNull View drawerView) { - hideKeyboard(); - } - - @Override - public void onDrawerClosed(@NonNull View drawerView) { - - } - - @Override - public void onDrawerStateChanged(int newState) { - } - }); - + mDrawer.addDrawerListener(drawerListener); mNavView = findViewById(R.id.nvView); @@ -186,32 +190,38 @@ public class ActivityPrincipal extends GeneralActivity implements FragmentListen // Intercept calls from URL intent boolean tryedFromIntent = false; - String busStopID = null; - Uri data = getIntent().getData(); - if (data != null) { + String initialBusStopID = null; + var intent = getIntent(); + if(intent != null){ + var data = intent.getData(); + if(data != null){ + //var rest = data.getSchemeSpecificPart(); + //Log.d(DEBUG_TAG, "the rest is: "+rest); - busStopID = getBusStopIDFromUri(data); - Log.d(DEBUG_TAG, "Opening Intent: busStopID: "+busStopID); - tryedFromIntent = true; - } + initialBusStopID = getBusStopIDFromUri(data); + tryedFromIntent = true; + Log.d(DEBUG_TAG, "Opening Intent: initialBusStopID: "+initialBusStopID); - // Intercept calls from other activities - if (!tryedFromIntent) { - Bundle b = getIntent().getExtras(); - if (b != null) { - busStopID = b.getString("bus-stop-ID"); - - /* - * I'm not very sure if you are coming from an Intent. - * Some launchers work in strange ways. - */ - tryedFromIntent = busStopID != null; + } + // Intercept calls from other activities + if(!tryedFromIntent){ + Bundle b =intent.getExtras(); + if (b != null) { + initialBusStopID = b.getString("bus-stop-ID"); + + /* + * I'm not very sure if you are coming from an Intent. + * Some launchers work in strange ways. + */ + tryedFromIntent = initialBusStopID != null; + } } } + //---------------------------- END INTENT CHECK QUEUE -------------------------------------- - if (busStopID == null) { + if (initialBusStopID == null) { // Show keyboard if can't start from intent // JUST DON'T // showKeyboard(); @@ -223,20 +233,14 @@ public class ActivityPrincipal extends GeneralActivity implements FragmentListen Toast.makeText(getApplicationContext(), R.string.insert_bus_stop_number_error, Toast.LENGTH_SHORT).show(); } - } else { - // If you are here an intent has worked successfully - //setBusStopSearchByIDEditText(busStopID); - //Log.d(DEBUG_TAG, "Requesting arrivals for stop "+busStopID+" from intent"); - requestArrivalsForStopID(busStopID); //this shows the fragment, too - showingArrivalsFromIntent = true; } - //database check + //save whether we started from intent + startedFromIntent = tryedFromIntent; - // DatabaseUpdate.requestDBUpdateWithWork(this, false, false); + //period database check DBUpdateCheckWorker.Companion.schedulePeriodicCheck(this,false); - /* - Watch for database update - */ + + //Watch for database update DBUpdateWorker.getWorkInfoLiveData(this) .observe(this, workInfoList -> { // If there are no matching work info, do nothing @@ -268,10 +272,12 @@ public class ActivityPrincipal extends GeneralActivity implements FragmentListen String vl = PreferenceManager.getDefaultSharedPreferences(this).getString(SettingsFragment.PREF_KEY_STARTUP_SCREEN, ""); Log.d(DEBUG_TAG, "The default screen to open is: "+vl); - if (showingArrivalsFromIntent){ - //do nothing but exclude a case + var framan = getSupportFragmentManager(); + + if (initialBusStopID!=null) { + Log.d(DEBUG_TAG, "Opening Main Fragment on arrivals, bus Stop: "+initialBusStopID); + createShowMainFragment(framan, MainScreenFragment.makeArgsArrivals(initialBusStopID), false); }else if (savedInstanceState==null) { - var framan = getSupportFragmentManager(); //we are not restarting the activity from nothing switch (vl){ case "map" -> {requestMapFragment(false);} diff --git a/app/src/main/java/it/reyboz/bustorino/fragments/MainScreenFragment.java b/app/src/main/java/it/reyboz/bustorino/fragments/MainScreenFragment.java index b4724b3..82264ac 100644 --- a/app/src/main/java/it/reyboz/bustorino/fragments/MainScreenFragment.java +++ b/app/src/main/java/it/reyboz/bustorino/fragments/MainScreenFragment.java @@ -259,8 +259,10 @@ public class MainScreenFragment extends BarcodeFragment implements FragmentList internalScreen = (parsed != null) ? parsed : InternalScreen.HOME_BUTTONS; } String stopId = args.getString(ARG_STOP_ID); - if (stopId != null) pendingStopID = stopId; - pendingSearchQuery = args.getString(ARG_SEARCH_QUERY); + if (stopId != null) + pendingSearchQuery = stopId; + else + pendingSearchQuery = args.getString(ARG_SEARCH_QUERY); } fragmentHelper = new FragmentHelper(this, getChildFragmentManager(), getContext(), R.id.resultFrame); @@ -413,6 +415,13 @@ public class MainScreenFragment extends BarcodeFragment implements FragmentList break; case ARRIVALS: // pendingStopID is consumed in onResume → requestArrivalsForStopID + if(pendingSearchQuery != null && isResumed()) { + swipeRefreshLayout.setVisibility(View.VISIBLE); + Log.d(DEBUG_TAG, "Searching arrivals for initial stop: "+pendingSearchQuery); + requestsArrivalsInternal(pendingSearchQuery, false); + pendingSearchQuery = null; + } + break; case STOP_SEARCH: if (pendingSearchQuery != null && pendingSearchQuery.length() >= 2) { @@ -591,22 +600,6 @@ public class MainScreenFragment extends BarcodeFragment implements FragmentList //this is the second time we are attaching this fragment -> Log.d(DEBUG_TAG, "Waiting for new stop request: "+ suppressArrivalsReload); - if(!suppressArrivalsReload && pendingStopID==null){ - //none of the following cases are true - // check if we are showing any fragment - /* - //TODO: check if this is needed - final Fragment fragment = getChildFragmentManager().findFragmentById(R.id.resultFrame); - - if(fragment==null || swipeRefreshLayout.getVisibility() != View.VISIBLE){ - //we are not showing anything - if(Permissions.anyLocationPermissionsGranted(getContext())){ - showNearbyFragmentIfPossible(); - } - } - - */ - } if (suppressArrivalsReload){ // we have to suppress the reloading of the (possible) ArrivalsFragment Fragment fragment = getChildFragmentManager().findFragmentById(R.id.resultFrame); @@ -617,8 +610,12 @@ public class MainScreenFragment extends BarcodeFragment implements FragmentList //deactivate suppressArrivalsReload = false; } - - if(pendingStopID!=null){ + // check if the fragment start query is null + if(pendingSearchQuery!=null) { + requestsArrivalsInternal(pendingSearchQuery, false); + pendingSearchQuery = null; + } + else if(pendingStopID!=null){ Log.d(DEBUG_TAG, "Pending request for arrivals at stop ID: "+pendingStopID); requestArrivalsForStopID(pendingStopID); @@ -872,17 +869,11 @@ public class MainScreenFragment extends BarcodeFragment implements FragmentList if(mListener!=null) mListener.showMapCenteredOnStop(stop); } - - /** - * Main method for stops requests - * @param ID the Stop ID - */ - @Override - public void requestArrivalsForStopID(String ID) { + private void requestsArrivalsInternal(String stopID, boolean addToBackStack) { if (!isResumed()){ - //defer request - pendingStopID = ID; - Log.d(DEBUG_TAG, "Deferring update for stop "+ID+ " saved: "+pendingStopID); + //defer request to onResume - it will be added to the backstack + pendingStopID = stopID; + Log.d(DEBUG_TAG, "Deferring update for stop "+stopID+ " saved: "+pendingStopID); return; } final boolean delayedRequest = !(pendingStopID==null); @@ -891,12 +882,15 @@ public class MainScreenFragment extends BarcodeFragment implements FragmentList Log.e(DEBUG_TAG, "Asked for arrivals with null context"); return; } - if (ID == null || ID.isEmpty()) { + if (stopID == null || stopID.isEmpty()) { // we're still in UI thread, no need to mess with Progress showToastMessage(R.string.insert_bus_stop_number_error, true); toggleSpinner(false); } else{ - var palinaTrial = new Palina(ID); + // ensure that the new sub-fragment is gonna be visible + swipeRefreshLayout.setVisibility(View.VISIBLE); + + var palinaTrial = new Palina(stopID); if (framan.findFragmentById(R.id.resultFrame) instanceof ArrivalsFragment fragment) { if (fragment.isFragmentForTheSameStop(palinaTrial)){ // Run with previous fetchers @@ -904,18 +898,27 @@ public class MainScreenFragment extends BarcodeFragment implements FragmentList fragment.requestArrivalsForTheFragment(); } else{ // The rest of the case is handled by the fragment Helper - fragmentHelper.showArrivalsFragmentForStop(palinaTrial, true); + fragmentHelper.showArrivalsFragmentForStop(palinaTrial, addToBackStack); } } else { // this is not needed any more //prepareGUIForArrivals(); - fragmentHelper.showArrivalsFragmentForStop(palinaTrial, true); + fragmentHelper.showArrivalsFragmentForStop(palinaTrial, addToBackStack); } } } + /** + * Main method for stops requests + * @param ID the Stop ID + */ + @Override + public void requestArrivalsForStopID(String ID) { + requestsArrivalsInternal(ID, true); + } + private boolean checkLocationPermission(){ final Context context = getContext(); if(context==null) return false; diff --git a/app/src/main/java/it/reyboz/bustorino/fragments/NearbyStopsFragment.kt b/app/src/main/java/it/reyboz/bustorino/fragments/NearbyStopsFragment.kt index 458f800..523fc45 100644 --- a/app/src/main/java/it/reyboz/bustorino/fragments/NearbyStopsFragment.kt +++ b/app/src/main/java/it/reyboz/bustorino/fragments/NearbyStopsFragment.kt @@ -338,6 +338,9 @@ class NearbyStopsFragment : ScreenBaseFragment() { } FragType.ARRIVALS -> { + lastPosition?.let{ + Collections.sort(stops, StopSorterByDistance(loc)) + } viewModel.requestArrivalsForStops(stops) } } diff --git a/app/src/main/res/layout/activity_principal.xml b/app/src/main/res/layout/activity_principal.xml index ea5afc4..a42b3c6 100644 --- a/app/src/main/res/layout/activity_principal.xml +++ b/app/src/main/res/layout/activity_principal.xml @@ -41,7 +41,7 @@ android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" - android:theme="@style/ThemeOverlay.AppCompat.DayNight" + android:theme="@style/AppThemeDayNight" app:headerLayout="@layout/nav_header" app:itemIconTint="@color/teal_500" app:itemTextAppearance="?android:attr/textAppearanceMedium" diff --git a/app/src/main/res/values-night-v27/themes.xml b/app/src/main/res/values-night-v27/themes.xml new file mode 100644 index 0000000..7ebf668 --- /dev/null +++ b/app/src/main/res/values-night-v27/themes.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index 9bb257f..606ca61 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -1,11 +1,16 @@ + + - + \ No newline at end of file diff --git a/app/src/main/res/values-v19/styles.xml b/app/src/main/res/values-v19/styles.xml deleted file mode 100644 index 5f8f81e..0000000 --- a/app/src/main/res/values-v19/styles.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - \ No newline at end of file diff --git a/app/src/main/res/values-v27/styles.xml b/app/src/main/res/values-v27/styles.xml new file mode 100644 index 0000000..f521326 --- /dev/null +++ b/app/src/main/res/values-v27/styles.xml @@ -0,0 +1,22 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-v35/styles.xml b/app/src/main/res/values-v35/styles.xml deleted file mode 100644 index 1646d1b..0000000 --- a/app/src/main/res/values-v35/styles.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 83324ae..3c9bf34 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -8,6 +8,7 @@ #e66b00 #cc6600 #994d00 + #b35900 #2196F3 #0b6fc1 diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 43597e3..3c0d23d 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -79,15 +79,13 @@ @color/orange_700 @color/teal_500 @color/white + @color/black_800 - - + false + + + \ No newline at end of file