Browse Source

Prevent potential crashes (based on Play Store console reports).

pull/280/head
Eric Kok 9 years ago
parent
commit
92c8d9b142
  1. 37
      app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java
  2. 15
      app/src/main/java/org/transdroid/core/gui/DetailsFragment.java
  3. 7
      app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java

37
app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java

@ -43,6 +43,7 @@ import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor; import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.text.TextUtils;
/** /**
* Singleton object to access all application settings, including stored servers, web search sites and RSS feeds. * Singleton object to access all application settings, including stored servers, web search sites and RSS feeds.
@ -69,7 +70,7 @@ public class ApplicationSettings {
* @return A list of all stored server settings objects * @return A list of all stored server settings objects
*/ */
public List<ServerSetting> getAllServerSettings() { public List<ServerSetting> getAllServerSettings() {
List<ServerSetting> all = new ArrayList<ServerSetting>(); List<ServerSetting> all = new ArrayList<>();
all.addAll(getNormalServerSettings()); all.addAll(getNormalServerSettings());
for (SeedboxProvider provider : SeedboxProvider.values()) { for (SeedboxProvider provider : SeedboxProvider.values()) {
all.addAll(provider.getSettings().getAllServerSettings(prefs, all.size())); all.addAll(provider.getSettings().getAllServerSettings(prefs, all.size()));
@ -116,7 +117,7 @@ public class ApplicationSettings {
* @return A list of all stored server settings objects * @return A list of all stored server settings objects
*/ */
public List<ServerSetting> getNormalServerSettings() { public List<ServerSetting> getNormalServerSettings() {
List<ServerSetting> servers = new ArrayList<ServerSetting>(); List<ServerSetting> servers = new ArrayList<>();
for (int i = 0; i <= getMaxNormalServer(); i++) { for (int i = 0; i <= getMaxNormalServer(); i++) {
servers.add(getNormalServerSetting(i)); servers.add(getNormalServerSetting(i));
} }
@ -145,19 +146,19 @@ public class ApplicationSettings {
Daemon type = Daemon.fromCode(prefs.getString("server_type_" + order, null)); Daemon type = Daemon.fromCode(prefs.getString("server_type_" + order, null));
boolean ssl = prefs.getBoolean("server_sslenabled_" + order, false); boolean ssl = prefs.getBoolean("server_sslenabled_" + order, false);
String port = prefs.getString("server_port_" + order, ""); String port = prefs.getString("server_port_" + order, null);
if (port.equals("")) if (TextUtils.isEmpty(port))
port = Integer.toString(Daemon.getDefaultPortNumber(type, ssl)); port = Integer.toString(Daemon.getDefaultPortNumber(type, ssl));
String localPort = prefs.getString("server_localport_" + order, ""); String localPort = prefs.getString("server_localport_" + order, null);
if (localPort.equals("")) if (TextUtils.isEmpty(localPort))
localPort = port; // Default to the normal (non-local) port localPort = port; // Default to the normal (non-local) port
try { try {
Integer.parseInt(port); parseInt(port, Daemon.getDefaultPortNumber(type, ssl));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
port = Integer.toString(Daemon.getDefaultPortNumber(type, ssl)); port = Integer.toString(Daemon.getDefaultPortNumber(type, ssl));
} }
try { try {
Integer.parseInt(localPort); parseInt(localPort, parseInt(port, Daemon.getDefaultPortNumber(type, ssl)));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
localPort = port; localPort = port;
} }
@ -167,9 +168,9 @@ public class ApplicationSettings {
type, type,
trim(prefs.getString("server_address_" + order, null)), trim(prefs.getString("server_address_" + order, null)),
trim(prefs.getString("server_localaddress_" + order, null)), trim(prefs.getString("server_localaddress_" + order, null)),
Integer.parseInt(localPort), parseInt(localPort, parseInt(port, Daemon.getDefaultPortNumber(type, ssl))),
prefs.getString("server_localnetwork_" + order, null), prefs.getString("server_localnetwork_" + order, null),
Integer.parseInt(port), parseInt(port, Daemon.getDefaultPortNumber(type, ssl)),
ssl, ssl,
prefs.getBoolean("server_ssltrustall_" + order, false), prefs.getBoolean("server_ssltrustall_" + order, false),
prefs.getString("server_ssltrustkey_" + order, null), prefs.getString("server_ssltrustkey_" + order, null),
@ -182,7 +183,7 @@ public class ApplicationSettings {
prefs.getString("server_downloaddir_" + order, null), prefs.getString("server_downloaddir_" + order, null),
prefs.getString("server_ftpurl_" + order, null), prefs.getString("server_ftpurl_" + order, null),
prefs.getString("server_ftppass_" + order, null), prefs.getString("server_ftppass_" + order, null),
Integer.parseInt(prefs.getString("server_timeout_" + order, "8")), parseInt(prefs.getString("server_timeout_" + order, "8"), 8),
prefs.getBoolean("server_alarmfinished_" + order, true), prefs.getBoolean("server_alarmfinished_" + order, true),
prefs.getBoolean("server_alarmnew_" + order, false), prefs.getBoolean("server_alarmnew_" + order, false),
prefs.getString("server_alarmexclude_" + order, null), prefs.getString("server_alarmexclude_" + order, null),
@ -380,7 +381,7 @@ public class ApplicationSettings {
* @return A list of all stored web search site settings objects * @return A list of all stored web search site settings objects
*/ */
public List<WebsearchSetting> getWebsearchSettings() { public List<WebsearchSetting> getWebsearchSettings() {
List<WebsearchSetting> websearches = new ArrayList<WebsearchSetting>(); List<WebsearchSetting> websearches = new ArrayList<>();
for (int i = 0; i <= getMaxWebsearch(); i++) { for (int i = 0; i <= getMaxWebsearch(); i++) {
websearches.add(getWebsearchSetting(i)); websearches.add(getWebsearchSetting(i));
} }
@ -443,7 +444,7 @@ public class ApplicationSettings {
* @return A list of all stored RSS feed settings objects * @return A list of all stored RSS feed settings objects
*/ */
public List<RssfeedSetting> getRssfeedSettings() { public List<RssfeedSetting> getRssfeedSettings() {
List<RssfeedSetting> rssfeeds = new ArrayList<RssfeedSetting>(); List<RssfeedSetting> rssfeeds = new ArrayList<>();
for (int i = 0; i <= getMaxRssfeed(); i++) { for (int i = 0; i <= getMaxRssfeed(); i++) {
rssfeeds.add(getRssfeedSetting(i)); rssfeeds.add(getRssfeedSetting(i));
} }
@ -566,7 +567,7 @@ public class ApplicationSettings {
* @return A list of search settings, all of which are either a {@link SearchSite} or {@link WebsearchSetting} * @return A list of search settings, all of which are either a {@link SearchSite} or {@link WebsearchSetting}
*/ */
public List<SearchSetting> getSearchSettings() { public List<SearchSetting> getSearchSettings() {
List<SearchSetting> all = new ArrayList<SearchSetting>(); List<SearchSetting> all = new ArrayList<>();
all.addAll(searchHelper.getAvailableSites()); all.addAll(searchHelper.getAvailableSites());
all.addAll(getWebsearchSettings()); all.addAll(getWebsearchSettings());
return Collections.unmodifiableList(all); return Collections.unmodifiableList(all);
@ -733,4 +734,12 @@ public class ApplicationSettings {
return str.trim(); return str.trim();
} }
private int parseInt(String string, int defaultValue) {
try {
return Integer.parseInt(string);
} catch (NumberFormatException e) {
return defaultValue;
}
}
} }

15
app/src/main/java/org/transdroid/core/gui/DetailsFragment.java

@ -182,9 +182,11 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
// Refresh the detailed statistics (errors) and list of files // Refresh the detailed statistics (errors) and list of files
torrentDetails = null; torrentDetails = null;
torrentFiles = null; torrentFiles = null;
if (getTasksExecutor() != null) {
getTasksExecutor().refreshTorrentDetails(torrent); getTasksExecutor().refreshTorrentDetails(torrent);
getTasksExecutor().refreshTorrentFiles(torrent); getTasksExecutor().refreshTorrentFiles(torrent);
} }
}
/** /**
* Updates the details adapter to show the list of trackers and tracker errors. * Updates the details adapter to show the list of trackers and tracker errors.
@ -366,41 +368,49 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
@OptionsItem(R.id.action_resume) @OptionsItem(R.id.action_resume)
protected void resumeTorrent() { protected void resumeTorrent() {
if (getTasksExecutor() != null)
getTasksExecutor().resumeTorrent(torrent); getTasksExecutor().resumeTorrent(torrent);
} }
@OptionsItem(R.id.action_pause) @OptionsItem(R.id.action_pause)
protected void pauseTorrent() { protected void pauseTorrent() {
if (getTasksExecutor() != null)
getTasksExecutor().pauseTorrent(torrent); getTasksExecutor().pauseTorrent(torrent);
} }
@OptionsItem(R.id.action_start_direct) @OptionsItem(R.id.action_start_direct)
protected void startTorrentDirect() { protected void startTorrentDirect() {
if (getTasksExecutor() != null)
getTasksExecutor().startTorrent(torrent, false); getTasksExecutor().startTorrent(torrent, false);
} }
@OptionsItem(R.id.action_start_default) @OptionsItem(R.id.action_start_default)
protected void startTorrentDefault() { protected void startTorrentDefault() {
if (getTasksExecutor() != null)
getTasksExecutor().startTorrent(torrent, false); getTasksExecutor().startTorrent(torrent, false);
} }
@OptionsItem(R.id.action_start_forced) @OptionsItem(R.id.action_start_forced)
protected void startTorrentForced() { protected void startTorrentForced() {
if (getTasksExecutor() != null)
getTasksExecutor().startTorrent(torrent, true); getTasksExecutor().startTorrent(torrent, true);
} }
@OptionsItem(R.id.action_stop) @OptionsItem(R.id.action_stop)
protected void stopTorrent() { protected void stopTorrent() {
if (getTasksExecutor() != null)
getTasksExecutor().stopTorrent(torrent); getTasksExecutor().stopTorrent(torrent);
} }
@OptionsItem(R.id.action_remove_default) @OptionsItem(R.id.action_remove_default)
protected void removeTorrentDefault() { protected void removeTorrentDefault() {
if (getTasksExecutor() != null)
getTasksExecutor().removeTorrent(torrent, false); getTasksExecutor().removeTorrent(torrent, false);
} }
@OptionsItem(R.id.action_remove_withdata) @OptionsItem(R.id.action_remove_withdata)
protected void removeTorrentWithData() { protected void removeTorrentWithData() {
if (getTasksExecutor() != null)
getTasksExecutor().removeTorrent(torrent, true); getTasksExecutor().removeTorrent(torrent, true);
} }
@ -413,6 +423,7 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
@OptionsItem(R.id.action_forcerecheck) @OptionsItem(R.id.action_forcerecheck)
protected void setForceRecheck() { protected void setForceRecheck() {
if (getTasksExecutor() != null)
getTasksExecutor().forceRecheckTorrent(torrent); getTasksExecutor().forceRecheckTorrent(torrent);
} }
@ -435,6 +446,7 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
if (torrent == null) { if (torrent == null) {
return; return;
} }
if (getTasksExecutor() != null)
getTasksExecutor().updateLabel(torrent, newLabel); getTasksExecutor().updateLabel(torrent, newLabel);
} }
@ -443,6 +455,7 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
if (torrent == null) { if (torrent == null) {
return; return;
} }
if (getTasksExecutor() != null)
getTasksExecutor().updateTrackers(torrent, updatedTrackers); getTasksExecutor().updateTrackers(torrent, updatedTrackers);
} }
@ -451,6 +464,7 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
if (torrent == null) { if (torrent == null) {
return; return;
} }
if (getTasksExecutor() != null)
getTasksExecutor().updateLocation(torrent, newLocation); getTasksExecutor().updateLocation(torrent, newLocation);
} }
@ -613,6 +627,7 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
if (itemId == R.id.action_priority_high) { if (itemId == R.id.action_priority_high) {
priority = Priority.High; priority = Priority.High;
} }
if (getTasksExecutor() != null)
getTasksExecutor().updatePriority(torrent, checked, priority); getTasksExecutor().updatePriority(torrent, checked, priority);
mode.finish(); mode.finish();
return true; return true;

7
app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java

@ -25,6 +25,7 @@ import android.os.Bundle;
import android.provider.SearchRecentSuggestions; import android.provider.SearchRecentSuggestions;
import android.support.v4.view.MenuItemCompat; import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.view.ContextThemeWrapper;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -165,11 +166,11 @@ public class SearchActivity extends AppCompatActivity {
searchToolbar.inflateMenu(R.menu.activity_search); searchToolbar.inflateMenu(R.menu.activity_search);
// Add an expandable SearchView to the action bar // Add an expandable SearchView to the action bar
MenuItem item = menu.findItem(R.id.action_search); MenuItem item = menu.findItem(R.id.action_search);
final SearchView searchView = new SearchView(getSupportActionBar().getThemedContext()); final SearchView searchView = new SearchView(searchToolbar.getContext());
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setQueryRefinementEnabled(true); searchView.setQueryRefinementEnabled(true);
searchView.setIconified(false); //searchView.setIconified(false);
searchView.setIconifiedByDefault(false); //searchView.setIconifiedByDefault(false);
MenuItemCompat.setActionView(item, searchView); MenuItemCompat.setActionView(item, searchView);
searchMenu = item; searchMenu = item;
return true; return true;

Loading…
Cancel
Save