Changeset View
Changeset View
Standalone View
Standalone View
app/src/main/java/it/reyboz/bustorino/ActivityPrincipal.java
| Show All 27 Lines | |||||
| import android.util.Log; | import android.util.Log; | ||||
| import android.view.*; | import android.view.*; | ||||
| import android.widget.Toast; | import android.widget.Toast; | ||||
| import androidx.activity.OnBackPressedCallback; | import androidx.activity.OnBackPressedCallback; | ||||
| import androidx.annotation.NonNull; | import androidx.annotation.NonNull; | ||||
| import androidx.annotation.Nullable; | import androidx.annotation.Nullable; | ||||
| import androidx.appcompat.app.ActionBarDrawerToggle; | import androidx.appcompat.app.ActionBarDrawerToggle; | ||||
| import androidx.appcompat.app.AppCompatDelegate; | |||||
| import androidx.appcompat.widget.Toolbar; | import androidx.appcompat.widget.Toolbar; | ||||
| import androidx.core.graphics.Insets; | import androidx.core.graphics.Insets; | ||||
| import androidx.core.view.*; | import androidx.core.view.*; | ||||
| import androidx.drawerlayout.widget.DrawerLayout; | import androidx.drawerlayout.widget.DrawerLayout; | ||||
| import androidx.fragment.app.Fragment; | import androidx.fragment.app.Fragment; | ||||
| import androidx.fragment.app.FragmentManager; | import androidx.fragment.app.FragmentManager; | ||||
| import androidx.fragment.app.FragmentTransaction; | import androidx.fragment.app.FragmentTransaction; | ||||
| import androidx.lifecycle.ViewModelProvider; | import androidx.lifecycle.ViewModelProvider; | ||||
| import androidx.preference.PreferenceManager; | import androidx.preference.PreferenceManager; | ||||
| import androidx.work.WorkInfo; | import androidx.work.WorkInfo; | ||||
| import com.google.android.material.navigation.NavigationView; | import com.google.android.material.navigation.NavigationView; | ||||
| import com.google.android.material.snackbar.Snackbar; | import com.google.android.material.snackbar.Snackbar; | ||||
| import java.util.Arrays; | import java.util.Arrays; | ||||
| import java.util.Map; | import java.util.Map; | ||||
| import java.util.Objects; | |||||
| import java.util.concurrent.LinkedBlockingDeque; | import java.util.concurrent.LinkedBlockingDeque; | ||||
| import java.util.function.Consumer; | import java.util.function.Consumer; | ||||
| import it.reyboz.bustorino.backend.Stop; | import it.reyboz.bustorino.backend.Stop; | ||||
| import it.reyboz.bustorino.data.DBUpdateCheckWorker; | import it.reyboz.bustorino.data.DBUpdateCheckWorker; | ||||
| import it.reyboz.bustorino.data.DBUpdateWorker; | import it.reyboz.bustorino.data.DBUpdateWorker; | ||||
| import it.reyboz.bustorino.data.PreferencesHolder; | import it.reyboz.bustorino.data.PreferencesHolder; | ||||
| import it.reyboz.bustorino.fragments.*; | import it.reyboz.bustorino.fragments.*; | ||||
| import it.reyboz.bustorino.middleware.GeneralActivity; | import it.reyboz.bustorino.middleware.GeneralActivity; | ||||
| import it.reyboz.bustorino.viewmodels.ServiceAlertsViewModel; | import it.reyboz.bustorino.viewmodels.ServiceAlertsViewModel; | ||||
| import static it.reyboz.bustorino.backend.utils.getBusStopIDFromUri; | import static it.reyboz.bustorino.backend.utils.getBusStopIDFromUri; | ||||
| import static it.reyboz.bustorino.backend.utils.openIceweasel; | import static it.reyboz.bustorino.backend.utils.openIceweasel; | ||||
| public class ActivityPrincipal extends GeneralActivity implements FragmentListenerMain { | public class ActivityPrincipal extends GeneralActivity implements FragmentListenerMain { | ||||
| private DrawerLayout mDrawer; | private DrawerLayout mDrawer; | ||||
| private NavigationView mNavView; | private NavigationView mNavView; | ||||
| private ActionBarDrawerToggle drawerToggle; | private ActionBarDrawerToggle drawerToggle; | ||||
| private final static String DEBUG_TAG="BusTO Act Principal"; | private final static String DEBUG_TAG="BusTO Act Principal"; | ||||
| private final static String TAG_FAVORITES="favorites_frag"; | private final static String TAG_FAVORITES="favorites_frag"; | ||||
| private Snackbar snackbar; | private Snackbar snackbar; | ||||
| private ServiceAlertsViewModel serviceAlertsViewModel; | private ServiceAlertsViewModel serviceAlertsViewModel; | ||||
| //private FragmentKind showingFragmentKind; | //private FragmentKind showingFragmentKind; | ||||
| private final Map<Integer, Runnable> menuActions = Map.of( | private final Map<Integer, Runnable> menuActions = Map.of( | ||||
| R.id.drawer_action_settings, () -> { | R.id.drawer_action_settings, () -> { | ||||
| Log.d("MAINBusTO", "Pressed button preferences"); | Log.d("MAINBusTO", "Pressed button preferences"); | ||||
| startActivity(new Intent(this, ActivitySettings.class)); | startActivity(new Intent(this, ActivitySettings.class)); | ||||
| }, | }, | ||||
| Show All 28 Lines | private final OnBackPressedCallback backPressedCallback = new OnBackPressedCallback(false) { | ||||
| } else{ | } else{ | ||||
| lastClosingAttempt = currentTime; | lastClosingAttempt = currentTime; | ||||
| Toast.makeText(getApplicationContext(),R.string.back_again_to_close,Toast.LENGTH_SHORT).show(); | Toast.makeText(getApplicationContext(),R.string.back_again_to_close,Toast.LENGTH_SHORT).show(); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| }; | }; | ||||
| @Override | @Override | ||||
| protected void onCreate(@Nullable Bundle savedInstanceState) { | protected void onCreate(@Nullable Bundle savedInstanceState) { | ||||
| super.onCreate(savedInstanceState); | super.onCreate(savedInstanceState); | ||||
| Log.d(DEBUG_TAG, "onCreate, savedInstanceState is: "+savedInstanceState); | Log.d(DEBUG_TAG, "onCreate, savedInstanceState is: "+savedInstanceState); | ||||
| setContentView(R.layout.activity_principal); | setContentView(R.layout.activity_principal); | ||||
| serviceAlertsViewModel = new ViewModelProvider(this).get(ServiceAlertsViewModel.class); | serviceAlertsViewModel = new ViewModelProvider(this).get(ServiceAlertsViewModel.class); | ||||
| //Use LiveModel to sync fragment state | //Use LiveModel to sync fragment state | ||||
| /*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { | |||||
| getWindow().setNavigationBarContrastEnforced(false); | |||||
| } | |||||
| */ | |||||
| //onBackPressed solution required from Android 16 | //onBackPressed solution required from Android 16 | ||||
| backPressedCallback.setEnabled(true); | backPressedCallback.setEnabled(true); | ||||
| this.getOnBackPressedDispatcher().addCallback(backPressedCallback); | this.getOnBackPressedDispatcher().addCallback(backPressedCallback); | ||||
| boolean showingArrivalsFromIntent = false; | boolean showingArrivalsFromIntent = false; | ||||
| final Toolbar mToolbar = findViewById(R.id.default_toolbar); | final Toolbar mToolbar = findViewById(R.id.default_toolbar); | ||||
| setSupportActionBar(mToolbar); | setSupportActionBar(mToolbar); | ||||
| ▲ Show 20 Lines • Show All 139 Lines • ▼ Show 20 Lines | protected void onCreate(@Nullable Bundle savedInstanceState) { | ||||
| case "favorites" -> checkAndShowFavoritesFragment(framan, false); | case "favorites" -> checkAndShowFavoritesFragment(framan, false); | ||||
| case "lines" -> showLinesFragment(framan, false, null); | case "lines" -> showLinesFragment(framan, false, null); | ||||
| case "nearby" -> createShowMainFragment(framan, MainScreenFragment.makeArgsNearby(), false); | case "nearby" -> createShowMainFragment(framan, MainScreenFragment.makeArgsNearby(), false); | ||||
| default -> createShowMainFragment(framan, MainScreenFragment.makeArgsButtonsScreen(), false); | default -> createShowMainFragment(framan, MainScreenFragment.makeArgsButtonsScreen(), false); | ||||
| } | } | ||||
| } | } | ||||
| //boolean onCreateComplete = true; | //boolean onCreateComplete = true; | ||||
| //last but not least, set the good default values | //default values are set in the BustoApp | ||||
| checkApplyDefaultSettingsValues(); | //checkApplyDefaultSettingsValues(); | ||||
| // handle the device "insets" | // handle the device "insets" | ||||
| /* | /* | ||||
| ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.rootRelativeLayout), (v, windowInsets) -> { | ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.rootRelativeLayout), (v, windowInsets) -> { | ||||
| Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()); | Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()); | ||||
| // Apply the insets as a margin to the view. This solution sets only the | // Apply the insets as a margin to the view. This solution sets only the | ||||
| // bottom, left, and right dimensions, but you can apply whichever insets are | // bottom, left, and right dimensions, but you can apply whichever insets are | ||||
| // appropriate to your layout. You can also update the view padding if that's | // appropriate to your layout. You can also update the view padding if that's | ||||
| // more appropriate. | // more appropriate. | ||||
| ▲ Show 20 Lines • Show All 623 Lines • Show Last 20 Lines | |||||
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register