mirror of
https://gitlab.com/oeffi/oeffi.git
synced 2025-07-08 00:08:48 +00:00
NearestFavoriteStationWidgetService: Add dialog for requesting background location permission.
This commit is contained in:
parent
6f733e9ff6
commit
91ecaa6266
6 changed files with 56 additions and 8 deletions
|
@ -233,6 +233,10 @@
|
|||
android:authorities="de.schildbach.oeffi.stations.favorites"
|
||||
android:exported="false" />
|
||||
|
||||
<activity
|
||||
android:name=".stations.NearestFavoriteStationsWidgetPermissionActivity"
|
||||
android:theme="@style/My.Theme.Translucent" />
|
||||
|
||||
<receiver
|
||||
android:name=".stations.NearestFavoriteStationWidgetProvider"
|
||||
android:label="@string/nearest_favorite_station_widget_label">
|
||||
|
|
|
@ -66,8 +66,8 @@
|
|||
android:id="@+id/station_widget_message"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginLeft="12dp"
|
||||
android:layout_marginRight="12dp"
|
||||
android:layout_marginLeft="24dp"
|
||||
android:layout_marginRight="24dp"
|
||||
android:gravity="center"
|
||||
android:textColor="#fff"
|
||||
android:textStyle="bold"
|
||||
|
|
|
@ -155,6 +155,7 @@
|
|||
|
||||
<!-- stations widget -->
|
||||
<string name="nearest_favorite_station_widget_label">Abfahrtszeiten von nahegelegener favorisierter Haltestelle</string>
|
||||
<string name="nearest_favorite_station_widget_no_location_permission">Standortermittlung im Hintergrund ist nötig, um Haltestellen in deiner Nähe zu finden.\n\nTapp um die Erlaubnis zu geben.</string>
|
||||
<string name="nearest_favorite_station_widget_no_favorites">Keine Haltestellen favorisiert.</string>
|
||||
<string name="nearest_favorite_station_widget_loading">Lade Abfahrtszeiten…</string>
|
||||
<string name="nearest_favorite_station_widget_no_departures">Keine Abfahrten.</string>
|
||||
|
|
|
@ -156,6 +156,7 @@
|
|||
|
||||
<!-- stations widget -->
|
||||
<string name="nearest_favorite_station_widget_label">Departure times of nearest favorite station</string>
|
||||
<string name="nearest_favorite_station_widget_no_location_permission">Background Location Permission is needed for locating stations close to you.\n\nTap to grant permission.</string>
|
||||
<string name="nearest_favorite_station_widget_no_favorites">No station favorites defined.</string>
|
||||
<string name="nearest_favorite_station_widget_loading">Loading departures…</string>
|
||||
<string name="nearest_favorite_station_widget_no_departures">No departures.</string>
|
||||
|
|
|
@ -136,9 +136,11 @@ public class NearestFavoriteStationWidgetService extends JobIntentService {
|
|||
|
||||
views = new RemoteViews(getPackageName(), R.layout.station_widget_content);
|
||||
|
||||
if (ContextCompat.checkSelfPermission(this,
|
||||
Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
widgetsMessage(appWidgetIds, getString(R.string.acquire_location_no_permission));
|
||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED ||
|
||||
ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_BACKGROUND_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
final PendingIntent intent = PendingIntent.getActivity(this, 0, new Intent(this,
|
||||
NearestFavoriteStationsWidgetPermissionActivity.class), 0);
|
||||
widgetsMessage(appWidgetIds, getString(R.string.nearest_favorite_station_widget_no_location_permission), intent);
|
||||
log.info("No location permission");
|
||||
return;
|
||||
}
|
||||
|
@ -155,7 +157,7 @@ public class NearestFavoriteStationWidgetService extends JobIntentService {
|
|||
criteria.setPowerRequirement(Criteria.POWER_LOW);
|
||||
provider = locationManager.getBestProvider(criteria, true);
|
||||
if (provider == null || LocationManager.PASSIVE_PROVIDER.equals(provider)) {
|
||||
widgetsMessage(appWidgetIds, getString(R.string.acquire_location_no_provider));
|
||||
widgetsMessage(appWidgetIds, getString(R.string.acquire_location_no_provider), null);
|
||||
log.info("No location provider found");
|
||||
return;
|
||||
}
|
||||
|
@ -193,14 +195,15 @@ public class NearestFavoriteStationWidgetService extends JobIntentService {
|
|||
}
|
||||
}
|
||||
|
||||
private void widgetsMessage(final int[] appWidgetIds, final String message) {
|
||||
private void widgetsMessage(final int[] appWidgetIds, final String message, final PendingIntent intent) {
|
||||
setMessage(message);
|
||||
views.setTextViewText(R.id.station_widget_distance, null);
|
||||
views.setTextViewText(R.id.station_widget_lastupdated, null);
|
||||
for (final int appWidgetId : appWidgetIds) {
|
||||
views.setTextViewText(R.id.station_widget_header,
|
||||
getString(R.string.nearest_favorite_station_widget_label));
|
||||
views.setOnClickPendingIntent(R.id.station_widget_content, clickIntent(appWidgetId));
|
||||
views.setOnClickPendingIntent(R.id.station_widget_content,
|
||||
intent != null ? intent : clickIntent(appWidgetId));
|
||||
appWidgetManager.updateAppWidget(appWidgetId, views);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright the original author or authors.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.schildbach.oeffi.stations;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
|
||||
public class NearestFavoriteStationsWidgetPermissionActivity extends Activity {
|
||||
@Override
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION,
|
||||
Manifest.permission.ACCESS_BACKGROUND_LOCATION }, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(final int requestCode, final String[] permissions,
|
||||
final int[] grantResults) {
|
||||
FavoriteUtils.notifyFavoritesChanged(this);
|
||||
finish();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue