Skip to content

Commit

Permalink
Merge branch 'OneBusAway:main' into Fixed-OneBusAway#1153---Activity-…
Browse files Browse the repository at this point in the history
…restarts-on-switching-from-portrait-to-landscape-mode-and-vice-versa
  • Loading branch information
gourabsingha1 authored Mar 16, 2024
2 parents 78523c1 + a18606f commit b2fd29e
Show file tree
Hide file tree
Showing 15 changed files with 485 additions and 230 deletions.
4 changes: 2 additions & 2 deletions onebusaway-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ android {
defaultConfig {
minSdkVersion 21
targetSdkVersion 33
versionCode 138
versionName "2.12.1"
versionCode 139
versionName "2.12.2"

multiDexEnabled true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,6 @@ public synchronized void clear() {
mMarkerData.clear();
mMarkerData = null;
}
if (mCustomInfoWindowAdapter != null) {
mCustomInfoWindowAdapter.cancelUpdates();
}
}

/**
Expand Down Expand Up @@ -532,17 +529,12 @@ public void onInfoWindowClick(Marker marker) {
// Show trip details screen for the vehicle associated with this marker
ObaTripStatus status = mMarkerData.getStatusFromMarker(marker);
if (status != null) {
// Stop any callbacks to refresh the vehicle marker popup balloons
mCustomInfoWindowAdapter.cancelUpdates();

if (status != null) {
if (mController != null && mController.getFocusedStopId() != null) {
TripDetailsActivity.start(mActivity, status.getActiveTripId(),
mController.getFocusedStopId(), TripDetailsListFragment.SCROLL_MODE_VEHICLE);
} else {
TripDetailsActivity.start(mActivity, status.getActiveTripId(),
TripDetailsListFragment.SCROLL_MODE_VEHICLE);
}
if (mController != null && mController.getFocusedStopId() != null) {
TripDetailsActivity.start(mActivity, status.getActiveTripId(),
mController.getFocusedStopId(), TripDetailsListFragment.SCROLL_MODE_VEHICLE);
} else {
TripDetailsActivity.start(mActivity, status.getActiveTripId(),
TripDetailsListFragment.SCROLL_MODE_VEHICLE);
}
}
}
Expand Down Expand Up @@ -960,11 +952,6 @@ public View getInfoContents(Marker marker) {
}
lastUpdatedView.setText(lastUpdated);

if (mMarkerRefreshHandler != null) {
mMarkerRefreshHandler.removeCallbacks(mMarkerRefresh);
mMarkerRefreshHandler.postDelayed(mMarkerRefresh, MARKER_REFRESH_PERIOD);
}

if (status.getOccupancyStatus() != null) {
// Real-time occupancy data
UIUtils.setOccupancyVisibilityAndColor(occupancyView, status.getOccupancyStatus(), OccupancyState.REALTIME);
Expand All @@ -978,27 +965,6 @@ public View getInfoContents(Marker marker) {
return view;
}

private final long MARKER_REFRESH_PERIOD = TimeUnit.SECONDS.toMillis(1);

private final Handler mMarkerRefreshHandler = new Handler();

private final Runnable mMarkerRefresh = new Runnable() {
public void run() {
if (mCurrentFocusVehicleMarker != null &&
mCurrentFocusVehicleMarker.isInfoWindowShown()) {
// Force an update of the marker balloon, so "last updated" time ticks up
mCurrentFocusVehicleMarker.showInfoWindow();
}
}
};

/**
* Cancels any pending updates of the marker balloon contents
*/
public void cancelUpdates() {
if (mMarkerRefreshHandler != null) {
mMarkerRefreshHandler.removeCallbacks(mMarkerRefresh);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected void onPostExecute(Long result) {
return;
}

if (!mResponse.getPlan().getItinerary().isEmpty() && mResponse != null && mResponse.getPlan() != null
if (mResponse != null && mResponse.getPlan() != null && !mResponse.getPlan().getItinerary().isEmpty()
&& mResponse.getPlan().getItinerary().get(0) != null) {
mCallback.onTripRequestComplete(mResponse.getPlan(), mRequestUrl);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.text.Html;
import android.text.Spannable;
import android.widget.TextView;

import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.google.android.material.textview.MaterialTextView;

import org.onebusaway.android.R;

Expand Down Expand Up @@ -53,6 +56,7 @@ protected void onCreate(Bundle savedInstanceState) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

TextView tv = (TextView) findViewById(R.id.about_text);
MaterialTextView version = findViewById(R.id.version);
String versionString = "";
int versionCode = 0;
try {
Expand All @@ -65,16 +69,14 @@ protected void onCreate(Bundle savedInstanceState) {

StringBuilder builder = new StringBuilder();
// Version info
builder.append("v")
builder.append("Version: ")
.append(versionString)
.append(" (")
.append(versionCode)
.append(")\n\n");
.append(")\n");

// Majority of content from string resource
builder.append(getString(R.string.about_text));
builder.append("\n\n");

tv.setText(builder.toString());
// Majority of content comes from a string resource:
version.setText(builder.toString());
tv.setText((Spannable) Html.fromHtml(getString(R.string.about_content)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,8 @@ public void showRouteOnMap(ArrivalInfo arrivalInfo) {
if (mListener != null) {
handled = mListener.onShowRouteOnMapSelected(arrivalInfo);
}
// Save to recent routes
DBUtil.addRouteToDB(getActivity(),arrivalInfo);
// If the event hasn't been handled by the listener, start a new activity
if (!handled) {
HomeActivity.start(getActivity(), arrivalInfo.getInfo().getRouteId());
Expand Down Expand Up @@ -1429,6 +1431,10 @@ private void goToTrip(ArrivalInfo stop) {
}

private void goToTripDetails(ArrivalInfo stop) {

// Save to recent routes
DBUtil.addRouteToDB(getActivity(),stop);

TripDetailsActivity.start(getActivity(),
stop.getInfo().getTripId(), stop.getInfo().getStopId(),
TripDetailsListFragment.SCROLL_MODE_STOP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,9 @@ public void onRequestPermissionsResult(
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE_RESTORE_BACKUP) {
BackupUtils.restore(this, data.getData());
if(data != null){
BackupUtils.restore(this, data.getData());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.onebusaway.android.io.request.ObaStopsForLocationRequest;
import org.onebusaway.android.io.request.ObaStopsForLocationResponse;
import org.onebusaway.android.util.ArrayAdapter;
import org.onebusaway.android.util.DBUtil;
import org.onebusaway.android.util.LocationUtils;
import org.onebusaway.android.util.UIUtils;

Expand Down Expand Up @@ -196,6 +197,7 @@ private void clickRoute(ObaRoute route) {

builder.setItems(R.array.search_route_options, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
DBUtil.addRouteToDB(getActivity(),route);
switch (which) {
case 0:
// Show on list
Expand All @@ -205,6 +207,7 @@ public void onClick(DialogInterface dialog, int which) {
// Show on map
HomeActivity.start(getActivity(), routeId);
break;

}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,12 @@ public void onClick(DialogInterface dialog, int which) {
TextView title = (TextView) dialog.findViewById(R.id.alert_title);
title.setText(args.getString(TITLE));

TextView desc = (TextView) dialog.findViewById(R.id.alert_description);
TextView descTxtView = (TextView) dialog.findViewById(R.id.alert_description);

if (desc != null) {
desc.setText(Html.fromHtml(args.getString(DESCRIPTION)));
String desc = args.getString(DESCRIPTION);

if (descTxtView != null &&!TextUtils.isEmpty(desc)) {
descTxtView.setText(Html.fromHtml(desc));
}
TextView urlView = (TextView) dialog.findViewById(R.id.alert_url);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package org.onebusaway.android.util;

import org.onebusaway.android.app.Application;
import org.onebusaway.android.io.elements.ObaRoute;
import org.onebusaway.android.io.elements.ObaStop;
import org.onebusaway.android.provider.ObaContract;
import org.onebusaway.android.ui.ArrivalInfo;

import android.content.ContentValues;
import android.content.Context;
import android.text.TextUtils;

/**
* Created by azizmb9494 on 2/20/16.
Expand All @@ -25,4 +29,46 @@ public static void addToDB(ObaStop stop) {
}
ObaContract.Stops.insertOrUpdate(stop.getId(), values, true);
}

public static void addRouteToDB(Context ctx, ArrivalInfo arrivalInfo){
if (Application.get().getCurrentRegion() == null) return;

ContentValues routeValues = new ContentValues();

String shortName = arrivalInfo.getInfo().getShortName();
String longName = arrivalInfo.getInfo().getRouteLongName();

if (TextUtils.isEmpty(longName)) {
longName = UIUtils.formatDisplayText(arrivalInfo.getInfo().getHeadsign());
}

routeValues.put(ObaContract.Routes.SHORTNAME, shortName);
routeValues.put(ObaContract.Routes.LONGNAME, longName);
routeValues.put(ObaContract.Routes.REGION_ID, Application.get().getCurrentRegion().getId());

ObaContract.Routes.insertOrUpdate(ctx, arrivalInfo.getInfo().getRouteId(), routeValues, true);
}

public static void addRouteToDB(Context ctx, ObaRoute route){
if (Application.get().getCurrentRegion() == null) return;

ContentValues routeValues = new ContentValues();

String shortName = route.getShortName();
String longName = route.getLongName();

if (TextUtils.isEmpty(shortName)) {
shortName = longName;
}
if (TextUtils.isEmpty(longName) || shortName.equals(longName)) {
longName = route.getDescription();
}

routeValues.put(ObaContract.Routes.SHORTNAME, shortName);
routeValues.put(ObaContract.Routes.LONGNAME, longName);
routeValues.put(ObaContract.Routes.URL, route.getUrl());
routeValues.put(ObaContract.Routes.REGION_ID, Application.get().getCurrentRegion().getId());

ObaContract.Routes.insertOrUpdate(ctx, route.getId(), routeValues, true);
}
}
16 changes: 13 additions & 3 deletions onebusaway-android/src/main/res/layout/content_about.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.onebusaway.android.ui.AboutActivity">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<com.google.android.material.textview.MaterialTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/version"
android:text="Version"
android:textStyle="bold"
/>
<TextView
android:id="@+id/about_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/text_margin"
android:autoLink="web"/>

</LinearLayout>
</androidx.core.widget.NestedScrollView>
Loading

0 comments on commit b2fd29e

Please sign in to comment.