diff --git a/build.gradle b/build.gradle --- a/build.gradle +++ b/build.gradle @@ -34,6 +34,7 @@ targetSdkVersion 25 versionCode 27 versionName "1.11" + vectorDrawables.useSupportLibrary = true } compileOptions { diff --git a/gradlew.bat b/gradlew.bat --- a/gradlew.bat +++ b/gradlew.bat @@ -1,84 +1,84 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/res/drawable-xxxhdpi/qrcode_button_custom.xml b/res/drawable-xxxhdpi/qrcode_button_custom.xml --- a/res/drawable-xxxhdpi/qrcode_button_custom.xml +++ b/res/drawable-xxxhdpi/qrcode_button_custom.xml @@ -1,8 +1,8 @@ - - - - - - - + + + + + + + \ No newline at end of file diff --git a/res/drawable/ic_star_filled.xml b/res/drawable/ic_star_filled.xml new file mode 100644 --- /dev/null +++ b/res/drawable/ic_star_filled.xml @@ -0,0 +1,9 @@ + + + diff --git a/res/drawable/ic_star_outline.xml b/res/drawable/ic_star_outline.xml new file mode 100644 --- /dev/null +++ b/res/drawable/ic_star_outline.xml @@ -0,0 +1,9 @@ + + + diff --git a/res/layout/fragment_list_view.xml b/res/layout/fragment_list_view.xml --- a/res/layout/fragment_list_view.xml +++ b/res/layout/fragment_list_view.xml @@ -2,20 +2,38 @@ xmlns:fab="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="match_parent" - > + android:layout_height="match_parent"> + + + android:id="@+id/messageTextView" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginStart="16dp" + android:layout_marginLeft="16dp" + android:layout_marginTop="10dp" + android:layout_marginEnd="307dp" + android:layout_marginRight="10dp" + android:layout_marginBottom="10dp" + android:layout_toStartOf="@+id/addToFavorites" + android:layout_toLeftOf="@+id/addToFavorites" + android:gravity="center_vertical" + android:minHeight="48dp" + android:textAppearance="?android:attr/textAppearanceMedium" /> + + + - - - + + + + \ No newline at end of file diff --git a/src/it/reyboz/bustorino/ActivityMain.java b/src/it/reyboz/bustorino/ActivityMain.java --- a/src/it/reyboz/bustorino/ActivityMain.java +++ b/src/it/reyboz/bustorino/ActivityMain.java @@ -76,6 +76,7 @@ private static final int SEARCH_BY_ID = 1; private static final int SEARCH_BY_ROUTE = 2; // TODO: implement this -- https://gitpull.it/T12 private int searchMode; + private ImageButton addToFavorites; /* * Options @@ -638,19 +639,27 @@ */ @Override 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 String stopID = getLastSuccessfullySearchedBusStopID(); if(stopID == null) { - // TODO: hide the star + addToFavorites.setVisibility(View.INVISIBLE); } else { // filled or outline? if(isStopInFavorites(stopID)) { - // TODO: fill star + addToFavorites.setImageResource(R.drawable.ic_star_filled); } else { - // TODO: outline star + addToFavorites.setImageResource(R.drawable.ic_star_outline); } - // TODO: show the star + addToFavorites.setVisibility(View.VISIBLE); } } @@ -690,6 +699,7 @@ protected void onPostExecute(Boolean result) { super.onPostExecute(result); + // update the star icon updateStarIconFromLastBusStop(); } @@ -872,6 +882,21 @@ 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 diff --git a/src/it/reyboz/bustorino/fragments/ArrivalsFragment.java b/src/it/reyboz/bustorino/fragments/ArrivalsFragment.java --- a/src/it/reyboz/bustorino/fragments/ArrivalsFragment.java +++ b/src/it/reyboz/bustorino/fragments/ArrivalsFragment.java @@ -26,6 +26,7 @@ import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; import android.util.Log; +import android.widget.ImageButton; import android.widget.TextView; import it.reyboz.bustorino.R; @@ -46,6 +47,8 @@ private DBStatusManager prefs; private DBStatusManager.OnDBUpdateStatusChangeListener listener; private boolean justCreated = false; + private ImageButton addToFavorites; + public static ArrivalsFragment newInstance(String stopID){ Bundle args = new Bundle(); diff --git a/src/it/reyboz/bustorino/fragments/ResultListFragment.java b/src/it/reyboz/bustorino/fragments/ResultListFragment.java --- a/src/it/reyboz/bustorino/fragments/ResultListFragment.java +++ b/src/it/reyboz/bustorino/fragments/ResultListFragment.java @@ -20,6 +20,7 @@ package it.reyboz.bustorino.fragments; import android.content.Context; +import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.os.Parcelable; import android.support.annotation.Nullable; @@ -38,6 +39,7 @@ import it.reyboz.bustorino.backend.Palina; import it.reyboz.bustorino.backend.Route; import it.reyboz.bustorino.backend.Stop; +import it.reyboz.bustorino.middleware.UserDB; /** * This is a generalized fragment that can be used both for @@ -57,6 +59,7 @@ private boolean adapterSet = false; protected FragmentListener mListener; private TextView messageTextView; + private ImageButton addToFavorites; private FloatingActionButton fabutton; private ListView resultsListView; @@ -102,12 +105,28 @@ } } + /** + * Check if the last Bus Stop is in the favorites + * @return + */ + public boolean isStopInFavorites(String busStopId) { + boolean found = false; + + // no stop no party + if(busStopId != null) { + SQLiteDatabase userDB = new UserDB(getContext()).getReadableDatabase(); + found = UserDB.isStopInFavorites(userDB, busStopId); + } + + return found; + } + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View root = inflater.inflate(R.layout.fragment_list_view, container, false); messageTextView = (TextView) root.findViewById(R.id.messageTextView); - + addToFavorites = (ImageButton) root.findViewById(R.id.addToFavorites); if (adapterKind != null) { resultsListView = (ListView) root.findViewById(R.id.resultsListView); switch (adapterKind) { @@ -275,8 +294,8 @@ messageTextView.setText(message); switch (adapterKind) { case ARRIVALS: - messageTextView.setClickable(true); - messageTextView.setOnClickListener(new View.OnClickListener() { + addToFavorites.setClickable(true); + addToFavorites.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // add/remove the stop in the favorites @@ -285,10 +304,11 @@ }); break; case STOPS: - messageTextView.setClickable(false); + addToFavorites.setClickable(false); break; } + messageTextView.setVisibility(View.VISIBLE); } -} +} \ No newline at end of file