Skip to content

Commit

Permalink
Fixed #1179 - Supported adding custom region using deep-links (#1182)
Browse files Browse the repository at this point in the history
* Fixed #1179 - Supported adding custom region using deep-links
  • Loading branch information
amrhossamdev authored Mar 27, 2024
1 parent 4191dc4 commit b67e8f5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
17 changes: 15 additions & 2 deletions onebusaway-android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">

<permission
android:name="${applicationId}.permission.TRIP_SERVICE"
Expand Down Expand Up @@ -203,7 +204,19 @@
<!-- ActionBarCompat library doesn't have an ActionBarPreferenceActivity, so define parent here-->
<activity
android:name="org.onebusaway.android.ui.PreferencesActivity"
android:parentActivityName="org.onebusaway.android.ui.HomeActivity">
android:parentActivityName="org.onebusaway.android.ui.HomeActivity"
android:exported="true"
tools:ignore="ExportedPreferenceActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="add-region"
android:scheme="onebusaway" />
</intent-filter>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="org.onebusaway.android.ui.HomeActivity"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ public void onCreate(Bundle savedInstanceState) {
if (showCheckRegionDialog) {
showCheckRegionDialog();
}

onAddCustomRegion();
}

@Override
Expand Down Expand Up @@ -534,7 +536,7 @@ protected void onDestroy() {
boolean currentValue = settings
.getBoolean(getString(R.string.preference_key_auto_select_region), true);

//If the use has selected to auto-select region, and the previous state of the setting was false,
//If the use has selected to auto-select region, and the previous state of the setting was false,
//then run the auto-select by going to HomeFragment
if ((currentValue && !mAutoSelectInitialValue)) {
Log.d(TAG,
Expand Down Expand Up @@ -690,4 +692,29 @@ public void onRegionTaskFinished(boolean currentRegionChanged) {
NavHelp.goHome(this, false);
}
}

/**
* The function will process deep links used for adding custom regions
*/
void onAddCustomRegion() {
Uri deepLink = getIntent().getData();
if(deepLink == null){
return;
}
String obaCustomUrl = deepLink.getQueryParameter("oba-url");
String otpCustomURl = deepLink.getQueryParameter("otp-url");

// onPreferenceChange is responsible for checking changes if it's valid
if (obaCustomUrl != null && onPreferenceChange(mCustomApiUrlPref, obaCustomUrl)) {
Application.get().setCustomApiUrl(obaCustomUrl);
}

if (otpCustomURl != null && onPreferenceChange(mCustomOtpApiUrlPref, otpCustomURl)) {
Application.get().setCustomOtpApiUrl(otpCustomURl);
}
Intent i = new Intent(this, HomeActivity.class);
startActivity(i);
finish();

}
}

0 comments on commit b67e8f5

Please sign in to comment.