Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/fragments/MainScreenFragment.java
Show All 9 Lines | |||||
import android.os.Bundle; | import android.os.Bundle; | ||||
import androidx.activity.result.ActivityResultCallback; | import androidx.activity.result.ActivityResultCallback; | ||||
import androidx.activity.result.ActivityResultLauncher; | import androidx.activity.result.ActivityResultLauncher; | ||||
import androidx.activity.result.contract.ActivityResultContracts; | import androidx.activity.result.contract.ActivityResultContracts; | ||||
import androidx.annotation.NonNull; | import androidx.annotation.NonNull; | ||||
import androidx.annotation.Nullable; | import androidx.annotation.Nullable; | ||||
import androidx.appcompat.widget.AppCompatImageButton; | import androidx.appcompat.widget.AppCompatImageButton; | ||||
import androidx.coordinatorlayout.widget.CoordinatorLayout; | |||||
import androidx.core.app.ActivityCompat; | import androidx.core.app.ActivityCompat; | ||||
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.swiperefreshlayout.widget.SwipeRefreshLayout; | import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; | ||||
import android.os.Handler; | import android.os.Handler; | ||||
import android.util.Log; | import android.util.Log; | ||||
Show All 27 Lines | |||||
import static it.reyboz.bustorino.util.Permissions.LOCATION_PERMISSION_GIVEN; | import static it.reyboz.bustorino.util.Permissions.LOCATION_PERMISSION_GIVEN; | ||||
/** | /** | ||||
* A simple {@link Fragment} subclass. | * A simple {@link Fragment} subclass. | ||||
* Use the {@link MainScreenFragment#newInstance} factory method to | * Use the {@link MainScreenFragment#newInstance} factory method to | ||||
* create an instance of this fragment. | * create an instance of this fragment. | ||||
*/ | */ | ||||
public class MainScreenFragment extends BaseFragment implements FragmentListenerMain{ | public class MainScreenFragment extends ScreenBaseFragment implements FragmentListenerMain{ | ||||
private static final String OPTION_SHOW_LEGEND = "show_legend"; | private static final String OPTION_SHOW_LEGEND = "show_legend"; | ||||
private static final String SAVED_FRAGMENT="saved_fragment"; | private static final String SAVED_FRAGMENT="saved_fragment"; | ||||
private static final String DEBUG_TAG = "BusTO - MainFragment"; | private static final String DEBUG_TAG = "BusTO - MainFragment"; | ||||
public final static String FRAGMENT_TAG = "MainScreenFragment"; | public final static String FRAGMENT_TAG = "MainScreenFragment"; | ||||
▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | private final ActivityResultLauncher<String[]> requestPermissionLauncher = | ||||
} | } | ||||
}); | }); | ||||
//// ACTIVITY ATTACHED (LISTENER /// | //// ACTIVITY ATTACHED (LISTENER /// | ||||
private CommonFragmentListener mListener; | private CommonFragmentListener mListener; | ||||
private String pendingStopID = null; | private String pendingStopID = null; | ||||
private CoordinatorLayout coordLayout; | |||||
public MainScreenFragment() { | public MainScreenFragment() { | ||||
// Required empty public constructor | // Required empty public constructor | ||||
} | } | ||||
public static MainScreenFragment newInstance() { | public static MainScreenFragment newInstance() { | ||||
MainScreenFragment fragment = new MainScreenFragment(); | MainScreenFragment fragment = new MainScreenFragment(); | ||||
Show All 12 Lines | public void onCreate(Bundle savedInstanceState) { | ||||
} | } | ||||
} | } | ||||
@Override | @Override | ||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, | public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||||
Bundle savedInstanceState) { | Bundle savedInstanceState) { | ||||
// Inflate the layout for this fragment | // Inflate the layout for this fragment | ||||
View root = inflater.inflate(R.layout.fragment_main_screen, container, false); | View root = inflater.inflate(R.layout.fragment_main_screen, container, false); | ||||
addToFavorites = (ImageButton) root.findViewById(R.id.addToFavorites); | addToFavorites = root.findViewById(R.id.addToFavorites); | ||||
busStopSearchByIDEditText = root.findViewById(R.id.busStopSearchByIDEditText); | busStopSearchByIDEditText = root.findViewById(R.id.busStopSearchByIDEditText); | ||||
busStopSearchByNameEditText = root.findViewById(R.id.busStopSearchByNameEditText); | busStopSearchByNameEditText = root.findViewById(R.id.busStopSearchByNameEditText); | ||||
progressBar = root.findViewById(R.id.progressBar); | progressBar = root.findViewById(R.id.progressBar); | ||||
howDoesItWorkTextView = root.findViewById(R.id.howDoesItWorkTextView); | howDoesItWorkTextView = root.findViewById(R.id.howDoesItWorkTextView); | ||||
hideHintButton = root.findViewById(R.id.hideHintButton); | hideHintButton = root.findViewById(R.id.hideHintButton); | ||||
swipeRefreshLayout = root.findViewById(R.id.listRefreshLayout); | swipeRefreshLayout = root.findViewById(R.id.listRefreshLayout); | ||||
floatingActionButton = root.findViewById(R.id.floatingActionButton); | floatingActionButton = root.findViewById(R.id.floatingActionButton); | ||||
busStopSearchByIDEditText.setSelectAllOnFocus(true); | busStopSearchByIDEditText.setSelectAllOnFocus(true); | ||||
Show All 15 Lines | public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||||
} | } | ||||
return false; | return false; | ||||
}); | }); | ||||
swipeRefreshLayout | swipeRefreshLayout | ||||
.setOnRefreshListener(() -> mainHandler.post(refreshStop)); | .setOnRefreshListener(() -> mainHandler.post(refreshStop)); | ||||
swipeRefreshLayout.setColorSchemeResources(R.color.blue_500, R.color.orange_500); | swipeRefreshLayout.setColorSchemeResources(R.color.blue_500, R.color.orange_500); | ||||
coordLayout = root.findViewById(R.id.coord_layout); | |||||
floatingActionButton.setOnClickListener((this::onToggleKeyboardLayout)); | floatingActionButton.setOnClickListener((this::onToggleKeyboardLayout)); | ||||
hideHintButton.setOnClickListener(this::onHideHint); | hideHintButton.setOnClickListener(this::onHideHint); | ||||
AppCompatImageButton qrButton = root.findViewById(R.id.QRButton); | AppCompatImageButton qrButton = root.findViewById(R.id.QRButton); | ||||
qrButton.setOnClickListener(this::onQRButtonClick); | qrButton.setOnClickListener(this::onQRButtonClick); | ||||
AppCompatImageButton searchButton = root.findViewById(R.id.searchButton); | AppCompatImageButton searchButton = root.findViewById(R.id.searchButton); | ||||
searchButton.setOnClickListener(this::onSearchClick); | searchButton.setOnClickListener(this::onSearchClick); | ||||
// Fragment stuff | // Fragment stuff | ||||
fragMan = getChildFragmentManager(); | fragMan = getChildFragmentManager(); | ||||
fragMan.addOnBackStackChangedListener(() -> Log.d("BusTO Main Fragment", "BACK STACK CHANGED")); | fragMan.addOnBackStackChangedListener(() -> Log.d("BusTO Main Fragment", "BACK STACK CHANGED")); | ||||
fragmentHelper = new FragmentHelper(this, getChildFragmentManager(), getContext(), R.id.resultFrame); | fragmentHelper = new FragmentHelper(this, getChildFragmentManager(), getContext(), R.id.resultFrame); | ||||
setSearchModeBusStopID(); | setSearchModeBusStopID(); | ||||
cr.setAccuracy(Criteria.ACCURACY_FINE); | cr.setAccuracy(Criteria.ACCURACY_FINE); | ||||
cr.setAltitudeRequired(false); | cr.setAltitudeRequired(false); | ||||
cr.setBearingRequired(false); | cr.setBearingRequired(false); | ||||
cr.setCostAllowed(true); | cr.setCostAllowed(true); | ||||
cr.setPowerRequirement(Criteria.NO_REQUIREMENT); | cr.setPowerRequirement(Criteria.NO_REQUIREMENT); | ||||
locationManager = AppLocationManager.getInstance(getContext()); | locationManager = AppLocationManager.getInstance(getContext()); | ||||
Log.d(DEBUG_TAG, "OnCreateView, savedInstanceState null: "+(savedInstanceState==null)); | Log.d(DEBUG_TAG, "OnCreateView, savedInstanceState null: "+(savedInstanceState==null)); | ||||
return root; | return root; | ||||
} | } | ||||
Show All 33 Lines | public void setSuppressArrivalsReload(boolean value){ | ||||
ArrivalsFragment frag = (ArrivalsFragment) fragment; | ArrivalsFragment frag = (ArrivalsFragment) fragment; | ||||
frag.setReloadOnResume(false); | frag.setReloadOnResume(false); | ||||
} | } | ||||
} | } | ||||
*/ | */ | ||||
} | } | ||||
/** | /** | ||||
* Cancel the reload of the arrival times | * Cancel the reload of the arrival times | ||||
* because we are going to pop the fragment | * because we are going to pop the fragment | ||||
*/ | */ | ||||
public void cancelReloadArrivalsIfNeeded(){ | public void cancelReloadArrivalsIfNeeded(){ | ||||
if(getContext()==null) return; //we are not attached | if(getContext()==null) return; //we are not attached | ||||
//Fragment fr = getChildFragmentManager().findFragmentById(R.id.resultFrame); | //Fragment fr = getChildFragmentManager().findFragmentById(R.id.resultFrame); | ||||
▲ Show 20 Lines • Show All 203 Lines • ▼ Show 20 Lines | public class MainScreenFragment extends ScreenBaseFragment implements FragmentListenerMain{ | ||||
} | } | ||||
private void hideHints() { | private void hideHints() { | ||||
howDoesItWorkTextView.setVisibility(View.GONE); | howDoesItWorkTextView.setVisibility(View.GONE); | ||||
hideHintButton.setVisibility(View.GONE); | hideHintButton.setVisibility(View.GONE); | ||||
//actionHelpMenuItem.setVisible(true); | //actionHelpMenuItem.setVisible(true); | ||||
} | } | ||||
@Nullable | |||||
@org.jetbrains.annotations.Nullable | |||||
@Override | |||||
public View getBaseViewForSnackBar() { | |||||
return coordLayout; | |||||
} | |||||
@Override | @Override | ||||
public void toggleSpinner(boolean enable) { | public void toggleSpinner(boolean enable) { | ||||
if (enable) { | if (enable) { | ||||
//already set by the RefreshListener when needed | //already set by the RefreshListener when needed | ||||
//swipeRefreshLayout.setRefreshing(true); | //swipeRefreshLayout.setRefreshing(true); | ||||
progressBar.setVisibility(View.VISIBLE); | progressBar.setVisibility(View.VISIBLE); | ||||
} else { | } else { | ||||
swipeRefreshLayout.setRefreshing(false); | swipeRefreshLayout.setRefreshing(false); | ||||
▲ Show 20 Lines • Show All 179 Lines • ▼ Show 20 Lines | class NearbyStopsRequester implements Runnable { | ||||
} else if(!haveProviders){ | } else if(!haveProviders){ | ||||
Log.e(DEBUG_TAG, "NO PROVIDERS FOR POSITION"); | Log.e(DEBUG_TAG, "NO PROVIDERS FOR POSITION"); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
No newline at end of file | No newline at end of file |
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