commit 701d51b2bda092f7ce12dff659c9060152a36dd6 Author: Fabio Mazza Date: Fri Dec 20 18:01:01 2024 +0100 Make more explicit message in line fragment diff --git a/app/src/main/java/it/reyboz/bustorino/ActivityPrincipal.java b/app/src/main/java/it/reyboz/bustorino/ActivityPrincipal.java index e593268..7a9f1fb 100644 --- a/app/src/main/java/it/reyboz/bustorino/ActivityPrincipal.java +++ b/app/src/main/java/it/reyboz/bustorino/ActivityPrincipal.java @@ -27,15 +27,18 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.util.Log; +import android.view.Gravity; import android.view.Menu; import android.view.MenuItem; import android.view.View; +import android.widget.FrameLayout; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBarDrawerToggle; import androidx.appcompat.widget.Toolbar; +import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.view.GravityCompat; import androidx.drawerlayout.widget.DrawerLayout; import androidx.fragment.app.Fragment; @@ -433,14 +436,24 @@ public class ActivityPrincipal extends GeneralActivity implements FragmentListen private void createDefaultSnackbar() { View baseView = null; + boolean showSnackbar = true; final Fragment frag = getSupportFragmentManager().findFragmentById(R.id.mainActContentFrame); if (frag instanceof ScreenBaseFragment){ baseView = ((ScreenBaseFragment) frag).getBaseViewForSnackBar(); + showSnackbar = ((ScreenBaseFragment) frag).showSnackbarOnDBUpdate(); } if (baseView == null) baseView = findViewById(R.id.mainActContentFrame); - if (baseView == null) Log.e(DEBUG_TAG, "baseView null for default snackbar, probably exploding now"); - snackbar = Snackbar.make(baseView, R.string.database_update_msg_inapp, Snackbar.LENGTH_INDEFINITE); - snackbar.show(); + //if (baseView == null) Log.e(DEBUG_TAG, "baseView null for default snackbar, probably exploding now"); + if (baseView !=null && showSnackbar) { + this.snackbar = Snackbar.make(baseView, R.string.database_update_msg_inapp, Snackbar.LENGTH_INDEFINITE); + if (frag instanceof ScreenBaseFragment){ + ((ScreenBaseFragment) frag).setSnackbarPropertiesBeforeShowing(this.snackbar); + } + this.snackbar.show(); + + } else{ + Log.e(DEBUG_TAG, "Asked to show the snackbar but the baseView is null"); + } } /** diff --git a/app/src/main/java/it/reyboz/bustorino/data/MatoTripsDownloadWorker.kt b/app/src/main/java/it/reyboz/bustorino/data/MatoTripsDownloadWorker.kt index 0f03a28..ba37750 100644 --- a/app/src/main/java/it/reyboz/bustorino/data/MatoTripsDownloadWorker.kt +++ b/app/src/main/java/it/reyboz/bustorino/data/MatoTripsDownloadWorker.kt @@ -57,7 +57,7 @@ class MatoTripsDownloadWorker(appContext: Context, workerParams: WorkerParameter for(trip in tripsList){ queriedMatoTrips.add(trip) matoRepository.requestTripUpdate(trip,{error-> - Log.e(DEBUG_TAG, "Cannot download Gtfs Trip $trip", error) + Log.e(DEBUG_TAG, "Cannot download Gtfs Trip $trip, error: $error") //val stacktrace = error.stackTrace.take(5) //Log.w(DEBUG_TAG, "Stacktrace:\n$stacktrace") failedMatoTripsDownload.add(trip) diff --git a/app/src/main/java/it/reyboz/bustorino/fragments/FavoritesFragment.java b/app/src/main/java/it/reyboz/bustorino/fragments/FavoritesFragment.java index 900e401..a7117ba 100644 --- a/app/src/main/java/it/reyboz/bustorino/fragments/FavoritesFragment.java +++ b/app/src/main/java/it/reyboz/bustorino/fragments/FavoritesFragment.java @@ -256,7 +256,7 @@ public class FavoritesFragment extends ScreenBaseFragment { // If no data is found show a friendly message if(BuildConfig.DEBUG) Log.d("BusTO - Favorites", "We have "+busStops.size()+" favorites in the list"); - if (busStops.size() == 0) { + if (busStops.isEmpty()) { favoriteRecyclerView.setVisibility(View.INVISIBLE); // TextView favoriteTipTextView = (TextView) findViewById(R.id.favoriteTipTextView); //assert favoriteTipTextView != null; @@ -298,7 +298,7 @@ public class FavoritesFragment extends ScreenBaseFragment { String oldUserName = busStop.getStopUserName(); // changed to none - if(busStopUsername.length() == 0) { + if(busStopUsername.isEmpty()) { // unless it was already empty, set new if(oldUserName != null) { busStop.setStopUserName(null); @@ -330,4 +330,14 @@ public class FavoritesFragment extends ScreenBaseFragment { //Toast.makeText(getApplicationContext(), R.string.tip_add_favorite, Toast.LENGTH_SHORT).show(); }).execute(busStop); } + /* + THIS LOOKS TERRIBLE + @Override + public void setSnackbarPropertiesBeforeShowing(Snackbar snackbar) { + final View view = snackbar.getView(); + FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) view.getLayoutParams(); + params.gravity = Gravity.TOP; + view.setLayoutParams(params); + } + */ } diff --git a/app/src/main/java/it/reyboz/bustorino/fragments/LinesGridShowingFragment.kt b/app/src/main/java/it/reyboz/bustorino/fragments/LinesGridShowingFragment.kt index e234f2e..f6a9cb9 100644 --- a/app/src/main/java/it/reyboz/bustorino/fragments/LinesGridShowingFragment.kt +++ b/app/src/main/java/it/reyboz/bustorino/fragments/LinesGridShowingFragment.kt @@ -15,11 +15,14 @@ import androidx.core.view.MenuProvider import androidx.fragment.app.viewModels import androidx.lifecycle.Lifecycle import androidx.recyclerview.widget.RecyclerView +import androidx.work.WorkInfo +import androidx.work.WorkManager import it.reyboz.bustorino.R import it.reyboz.bustorino.adapters.RouteAdapter import it.reyboz.bustorino.adapters.RouteOnlyLineAdapter import it.reyboz.bustorino.adapters.StringListAdapter import it.reyboz.bustorino.backend.utils +import it.reyboz.bustorino.data.DBUpdateWorker import it.reyboz.bustorino.data.PreferencesHolder import it.reyboz.bustorino.data.gtfs.GtfsRoute import it.reyboz.bustorino.middleware.AutoFitGridLayoutManager @@ -43,6 +46,7 @@ class LinesGridShowingFragment : ScreenBaseFragment() { private lateinit var urbanLinesTitle: TextView private lateinit var extrurbanLinesTitle: TextView private lateinit var touristLinesTitle: TextView + private lateinit var updateMessageTextView: TextView //private lateinit var searchBar: SearchView @@ -69,6 +73,7 @@ class LinesGridShowingFragment : ScreenBaseFragment() { private val lastQueryEmptyForAgency = HashMap(3) private var openRecyclerView = "AG_URBAN" + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? @@ -79,6 +84,7 @@ class LinesGridShowingFragment : ScreenBaseFragment() { urbanRecyclerView = rootView.findViewById(R.id.urbanLinesRecyclerView) extraurbanRecyclerView = rootView.findViewById(R.id.extraurbanLinesRecyclerView) touristRecyclerView = rootView.findViewById(R.id.touristLinesRecyclerView) + updateMessageTextView = rootView.findViewById(R.id.updateMessageTextView) favoritesTitle = rootView.findViewById(R.id.favoritesTitleView) urbanLinesTitle = rootView.findViewById(R.id.urbanLinesTitleView) @@ -178,6 +184,24 @@ class LinesGridShowingFragment : ScreenBaseFragment() { //k is either AG_TOUR, AG_EXTRAURBAN, AG_URBAN arrows[k]?.setOnClickListener { openLinesAndCloseOthersIfNeeded(k) } } + // watch for the db update + WorkManager.getInstance(requireContext()).getWorkInfosForUniqueWorkLiveData(DBUpdateWorker.DEBUG_TAG).observe(viewLifecycleOwner){ + workInfoList -> + if (workInfoList == null || workInfoList.isEmpty()) { + return@observe + } + + var showProgress = false + for (workInfo in workInfoList) { + if (workInfo.state == WorkInfo.State.RUNNING) { + updateMessageTextView.visibility = View.VISIBLE + + } else{ + updateMessageTextView.visibility = View.GONE + } + break + } + } return rootView @@ -400,4 +424,7 @@ class LinesGridShowingFragment : ScreenBaseFragment() { } } + override fun showSnackbarOnDBUpdate(): Boolean { + return false + } } \ No newline at end of file diff --git a/app/src/main/java/it/reyboz/bustorino/fragments/ScreenBaseFragment.java b/app/src/main/java/it/reyboz/bustorino/fragments/ScreenBaseFragment.java index b99ff4f..70b262c 100644 --- a/app/src/main/java/it/reyboz/bustorino/fragments/ScreenBaseFragment.java +++ b/app/src/main/java/it/reyboz/bustorino/fragments/ScreenBaseFragment.java @@ -4,6 +4,7 @@ import android.Manifest; import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; +import android.view.Gravity; import android.view.View; import android.view.inputmethod.InputMethodManager; import android.widget.Toast; @@ -14,6 +15,7 @@ import androidx.activity.result.contract.ActivityResultContracts; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; +import com.google.android.material.snackbar.Snackbar; import it.reyboz.bustorino.BuildConfig; import java.util.Map; @@ -59,6 +61,17 @@ public abstract class ScreenBaseFragment extends Fragment { @Nullable public abstract View getBaseViewForSnackBar(); + /** + * Empty method to override properties of the Snackbar before showing it + * @param snackbar the Snackbar to be possibly modified + */ + public void setSnackbarPropertiesBeforeShowing(Snackbar snackbar){ + + } + public boolean showSnackbarOnDBUpdate() { + return true; + } + public static boolean getOption(Context context, String optionName, boolean optDefault){ SharedPreferences preferences = context.getSharedPreferences(PREF_FILE, MODE_PRIVATE); return preferences.getBoolean(optionName, optDefault); diff --git a/app/src/main/res/drawable/backgroud_box_round.xml b/app/src/main/res/drawable/backgroud_box_round.xml new file mode 100644 index 0000000..9218f3f --- /dev/null +++ b/app/src/main/res/drawable/backgroud_box_round.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_lines_grid.xml b/app/src/main/res/layout/fragment_lines_grid.xml index 99df4c5..bb14f8e 100644 --- a/app/src/main/res/layout/fragment_lines_grid.xml +++ b/app/src/main/res/layout/fragment_lines_grid.xml @@ -15,6 +15,25 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:animateLayoutChanges="true" > + + \ No newline at end of file