mirror of
https://gitlab.com/oeffi/oeffi.git
synced 2025-07-07 22:08:49 +00:00
Application: Delete unused downloaded station databases.
This commit is contained in:
parent
62b50a5e58
commit
0932061274
4 changed files with 8 additions and 47 deletions
|
@ -18,8 +18,8 @@
|
|||
package de.schildbach.oeffi;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.osmdroid.config.Configuration;
|
||||
|
@ -32,7 +32,6 @@ import com.google.common.base.Stopwatch;
|
|||
import de.schildbach.oeffi.directions.QueryHistoryProvider;
|
||||
import de.schildbach.oeffi.stations.FavoriteStationsProvider;
|
||||
import de.schildbach.oeffi.stations.NearestFavoriteStationWidgetService;
|
||||
import de.schildbach.oeffi.util.Downloader;
|
||||
import de.schildbach.oeffi.util.ErrorReporter;
|
||||
import de.schildbach.pte.NetworkId;
|
||||
|
||||
|
@ -106,24 +105,26 @@ public class Application extends android.app.Application {
|
|||
// 2018-07-06: migrate IVB to use OEBB
|
||||
final String IVB = "IVB";
|
||||
migrateSelectedNetwork(IVB, NetworkId.OEBB);
|
||||
Downloader.deleteDownload(new File(getFilesDir(), IVB.toLowerCase(Locale.ENGLISH) + ".db"));
|
||||
FavoriteStationsProvider.deleteFavoriteStations(this, IVB);
|
||||
QueryHistoryProvider.deleteQueryHistory(this, IVB);
|
||||
|
||||
// 2018-11-05: migrate NRI to use RT
|
||||
final String NRI = "NRI";
|
||||
migrateSelectedNetwork(NRI, NetworkId.RT);
|
||||
Downloader.deleteDownload(new File(getFilesDir(), NRI.toLowerCase(Locale.ENGLISH) + ".db"));
|
||||
FavoriteStationsProvider.deleteFavoriteStations(this, NRI);
|
||||
QueryHistoryProvider.deleteQueryHistory(this, NRI);
|
||||
|
||||
// 2018-12-06: migrate VAGFR to use NVBW
|
||||
final String VAGFR = "VAGFR";
|
||||
migrateSelectedNetwork(VAGFR, NetworkId.NVBW);
|
||||
Downloader.deleteDownload(new File(getFilesDir(), VAGFR.toLowerCase(Locale.ENGLISH) + ".db"));
|
||||
FavoriteStationsProvider.migrateFavoriteStations(this, VAGFR, NetworkId.NVBW);
|
||||
QueryHistoryProvider.migrateQueryHistory(this, VAGFR, NetworkId.NVBW);
|
||||
|
||||
// 2020-11-22: delete unused downloaded station databases
|
||||
final FilenameFilter filter = (dir, name) -> name.endsWith(".db") || name.endsWith(".db.meta");
|
||||
for (final File file : getFilesDir().listFiles(filter))
|
||||
file.delete();
|
||||
|
||||
log.info("Migrations took {}", watch);
|
||||
|
||||
initNotificationManager();
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
package de.schildbach.oeffi.network;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Iterator;
|
||||
|
@ -41,9 +40,7 @@ import de.schildbach.oeffi.network.list.NetworkClickListener;
|
|||
import de.schildbach.oeffi.network.list.NetworkContextMenuItemListener;
|
||||
import de.schildbach.oeffi.network.list.NetworkListEntry;
|
||||
import de.schildbach.oeffi.network.list.NetworksAdapter;
|
||||
import de.schildbach.oeffi.stations.NetworkContentProvider;
|
||||
import de.schildbach.oeffi.util.DividerItemDecoration;
|
||||
import de.schildbach.oeffi.util.Downloader;
|
||||
import de.schildbach.oeffi.util.GeocoderThread;
|
||||
import de.schildbach.oeffi.util.LocationHelper;
|
||||
import de.schildbach.pte.AbstractNavitiaProvider;
|
||||
|
@ -322,8 +319,7 @@ public class NetworkPickerActivity extends Activity implements ActivityCompat.On
|
|||
|
||||
public boolean onNetworkContextMenuItemClick(final NetworkListEntry.Network entry, final int menuItemId) {
|
||||
if (menuItemId == R.id.network_picker_context_remove) {
|
||||
final File dbFile = new File(getFilesDir(), NetworkContentProvider.dbName(NetworkId.valueOf(entry.id)));
|
||||
Downloader.deleteDownload(dbFile);
|
||||
// placeholder for action
|
||||
listAdapter.notifyDataSetChanged();
|
||||
return true;
|
||||
} else {
|
||||
|
|
|
@ -17,13 +17,10 @@
|
|||
|
||||
package de.schildbach.oeffi.network.list;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import de.schildbach.oeffi.R;
|
||||
import de.schildbach.oeffi.stations.NetworkContentProvider;
|
||||
import de.schildbach.pte.NetworkId;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -89,12 +86,7 @@ public class NetworksAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
} else {
|
||||
final NetworkListEntry.Network entry = (NetworkListEntry.Network) entries.get(position);
|
||||
if (!NetworkListEntry.Network.STATE_DISABLED.equals(entry.state)) {
|
||||
final File dbFile = new File(context.getFilesDir(),
|
||||
NetworkContentProvider.dbName(NetworkId.valueOf(entry.id)));
|
||||
final long dbFileLength = dbFile.exists() ? dbFile.length() : 0;
|
||||
((NetworkViewHolder) holder).bind(entry, true, dbFileLength, clickListener,
|
||||
!entry.id.equals(previouslySelectedNetwork) && dbFile.exists() ? contextMenuItemListener
|
||||
: null);
|
||||
((NetworkViewHolder) holder).bind(entry, true, 0, clickListener, null);
|
||||
} else {
|
||||
((NetworkViewHolder) holder).bind(entry, false, 0, null, null);
|
||||
}
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
/*
|
||||
* 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 de.schildbach.pte.NetworkId;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class NetworkContentProvider {
|
||||
public static String dbName(final NetworkId networkId) {
|
||||
return networkId.name().toLowerCase(Locale.ENGLISH) + ".db";
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue