Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/ActivityMain.java
| Show First 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | public class ActivityMain extends GeneralActivity implements FragmentListener { | ||||
| /* | /* | ||||
| * Search mode | * Search mode | ||||
| */ | */ | ||||
| private static final int SEARCH_BY_NAME = 0; | private static final int SEARCH_BY_NAME = 0; | ||||
| private static final int SEARCH_BY_ID = 1; | private static final int SEARCH_BY_ID = 1; | ||||
| private static final int SEARCH_BY_ROUTE = 2; // TODO: implement this -- https://gitpull.it/T12 | private static final int SEARCH_BY_ROUTE = 2; // TODO: implement this -- https://gitpull.it/T12 | ||||
| private int searchMode; | private int searchMode; | ||||
| private ImageButton addToFavorites; | |||||
| /* | /* | ||||
| * Options | * Options | ||||
| */ | */ | ||||
| private final String OPTION_SHOW_LEGEND = "show_legend"; | private final String OPTION_SHOW_LEGEND = "show_legend"; | ||||
| private final String LOCATION_PERMISSION_GIVEN = "loc_permission"; | private final String LOCATION_PERMISSION_GIVEN = "loc_permission"; | ||||
| /* | /* | ||||
| * Status | * Status | ||||
| ▲ Show 20 Lines • Show All 546 Lines • ▼ Show 20 Lines | public String getLastSuccessfullySearchedBusStopID() { | ||||
| return stop == null ? null : stop.ID; | return stop == null ? null : stop.ID; | ||||
| } | } | ||||
| /** | /** | ||||
| * Update the star "Add to favorite" icon | * Update the star "Add to favorite" icon | ||||
| */ | */ | ||||
| @Override | @Override | ||||
| public void updateStarIconFromLastBusStop() { | public void updateStarIconFromLastBusStop() { | ||||
| // no favorites no party! | |||||
| addToFavorites = (ImageButton) findViewById(R.id.addToFavorites); | |||||
| if (addToFavorites == null) { | |||||
| Log.d("MainActivity", "Why the fuck the star is not here?!"); | |||||
| return; | |||||
| } | |||||
| // check if there is a last Stop | // check if there is a last Stop | ||||
| String stopID = getLastSuccessfullySearchedBusStopID(); | String stopID = getLastSuccessfullySearchedBusStopID(); | ||||
| if(stopID == null) { | if(stopID == null) { | ||||
| // TODO: hide the star | addToFavorites.setVisibility(View.INVISIBLE); | ||||
| } else { | } else { | ||||
| // filled or outline? | // filled or outline? | ||||
| if(isStopInFavorites(stopID)) { | if(isStopInFavorites(stopID)) { | ||||
| // TODO: fill star | addToFavorites.setImageResource(R.drawable.ic_star_filled); | ||||
| } else { | } else { | ||||
| // TODO: outline star | addToFavorites.setImageResource(R.drawable.ic_star_outline); | ||||
| } | } | ||||
| // TODO: show the star | addToFavorites.setVisibility(View.VISIBLE); | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Check if the last Bus Stop is in the favorites | * Check if the last Bus Stop is in the favorites | ||||
| * | * | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| Show All 23 Lines | public void toggleLastStopToFavorites() { | ||||
| /** | /** | ||||
| * Callback fired when the Stop is saved in the favorites | * Callback fired when the Stop is saved in the favorites | ||||
| * @param result | * @param result | ||||
| */ | */ | ||||
| @Override | @Override | ||||
| protected void onPostExecute(Boolean result) { | protected void onPostExecute(Boolean result) { | ||||
| super.onPostExecute(result); | super.onPostExecute(result); | ||||
| // update the star icon | // update the star icon | ||||
| updateStarIconFromLastBusStop(); | updateStarIconFromLastBusStop(); | ||||
| } | } | ||||
| }.execute(stop); | }.execute(stop); | ||||
| } else { | } else { | ||||
| // this case have no sense, but just immediately update the favorite icon | // this case have no sense, but just immediately update the favorite icon | ||||
| updateStarIconFromLastBusStop(); | updateStarIconFromLastBusStop(); | ||||
| ▲ Show 20 Lines • Show All 166 Lines • ▼ Show 20 Lines | public static String getBusStopIDFromUri(Uri uri) { | ||||
| break; | break; | ||||
| default: | default: | ||||
| Log.e("ActivityMain", "Unexpected intent URL: " + uri); | Log.e("ActivityMain", "Unexpected intent URL: " + uri); | ||||
| busStopID = null; | busStopID = null; | ||||
| } | } | ||||
| return busStopID; | return busStopID; | ||||
| } | } | ||||
| public void changeStarType(String stopID) { | |||||
| if(isStopInFavorites(stopID)) { | |||||
| changeStarFilled(); | |||||
| } else { | |||||
| changeStarOutline(); | |||||
| } | |||||
| } | |||||
| public void changeStarFilled() { | |||||
| addToFavorites.setImageResource(R.drawable.ic_star_filled); | |||||
| } | |||||
| public void changeStarOutline() { | |||||
| addToFavorites.setImageResource(R.drawable.ic_star_outline); | |||||
| } | |||||
| } | |||||
| 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