From b46bac998a9374ee591206ec76eeaa4251dae4e2 Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Thu, 21 Mar 2013 16:35:15 +0100 Subject: [PATCH] Fix various layout issues. --- core/res/drawable/loading_progress.xml | 16 ++--- core/res/layout/dialog_about.xml | 4 +- core/res/layout/fragment_details.xml | 11 +-- core/res/layout/fragment_torrents.xml | 17 ++++- core/res/menu/activity_torrents.xml | 2 +- core/res/menu/fragment_details_file.xml | 12 ++-- core/res/values/strings.xml | 10 ++- core/res/xml/pref_system.xml | 8 +++ .../transdroid/core/gui/TorrentsActivity.java | 22 +++--- .../transdroid/core/gui/TorrentsFragment.java | 67 +++++++++++++------ .../core/gui/lists/TorrentDetailsView.java | 1 + .../core/gui/lists/TorrentFileView.java | 4 +- .../core/gui/navigation/NavigationHelper.java | 28 +++----- .../gui/settings/SystemSettingsActivity.java | 18 +++++ full/AndroidManifest.xml | 2 +- lite/AndroidManifest.xml | 2 +- 16 files changed, 138 insertions(+), 86 deletions(-) diff --git a/core/res/drawable/loading_progress.xml b/core/res/drawable/loading_progress.xml index 3ac28bc2..222cc87e 100644 --- a/core/res/drawable/loading_progress.xml +++ b/core/res/drawable/loading_progress.xml @@ -1,13 +1,5 @@ - - - - - - - \ No newline at end of file + diff --git a/core/res/layout/dialog_about.xml b/core/res/layout/dialog_about.xml index 8866f1f0..ce92e4a2 100644 --- a/core/res/layout/dialog_about.xml +++ b/core/res/layout/dialog_about.xml @@ -32,7 +32,7 @@ android:layout_marginTop="@dimen/margin_default" android:fontFamily="sans-serif-condensed" android:gravity="center" - android:text="@string/app_developer" + android:text="@string/system_developer" android:textColor="@android:color/white" android:textSize="18sp" /> @@ -43,6 +43,6 @@ android:layout_marginBottom="@dimen/margin_default" android:layout_marginTop="4dip" android:gravity="center" - android:text="@string/app_license" /> + android:text="@string/system_license" /> \ No newline at end of file diff --git a/core/res/layout/fragment_details.xml b/core/res/layout/fragment_details.xml index 1aaefcce..5992426c 100644 --- a/core/res/layout/fragment_details.xml +++ b/core/res/layout/fragment_details.xml @@ -8,9 +8,9 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:choiceMode="multipleChoiceModal" - android:listSelector="@drawable/selectable_background_transdroid" android:divider="@null" android:dividerHeight="0dip" + android:listSelector="@drawable/selectable_background_transdroid" android:visibility="gone" /> - + - + \ No newline at end of file diff --git a/core/res/layout/fragment_torrents.xml b/core/res/layout/fragment_torrents.xml index a72b0fe4..0b050e73 100644 --- a/core/res/layout/fragment_torrents.xml +++ b/core/res/layout/fragment_torrents.xml @@ -17,8 +17,8 @@ android:layout_height="wrap_content" android:layout_gravity="center" android:indeterminate="true" - android:indeterminateOnly="true" android:indeterminateDrawable="@drawable/loading_progress" + android:indeterminateOnly="true" android:visibility="visible" /> + + diff --git a/core/res/menu/activity_torrents.xml b/core/res/menu/activity_torrents.xml index 1f081fe1..7f31ad68 100644 --- a/core/res/menu/activity_torrents.xml +++ b/core/res/menu/activity_torrents.xml @@ -15,7 +15,7 @@ android:id="@+id/action_search" android:icon="@drawable/ic_action_search" android:showAsAction="always" - android:title="@string/action_settings"/> + android:title="@string/action_search"/> \ No newline at end of file diff --git a/core/res/values/strings.xml b/core/res/values/strings.xml index 12b0e1cb..21b63d75 100644 --- a/core/res/values/strings.xml +++ b/core/res/values/strings.xml @@ -52,7 +52,7 @@ Active Inactive - Status: %1%s + Status: %1$s Waiting to check… Verifying local data… Waiting to download %s @@ -103,7 +103,6 @@ Torrent search Search for torrents - Servers Add new server @@ -257,10 +256,9 @@ File does not seem to contain Transdroid settings There is no settings file found - Transdroid - \u00A9 Eric Kok, 2312 development - Published under GNU General Public License v3 + Transdroid + \u00A9 Eric Kok, 2312 development + Published under GNU General Public License v3 Manage your torrents from your Android device - LIBRARIES \ No newline at end of file diff --git a/core/res/xml/pref_system.xml b/core/res/xml/pref_system.xml index 8968dc62..27bea173 100644 --- a/core/res/xml/pref_system.xml +++ b/core/res/xml/pref_system.xml @@ -16,6 +16,14 @@ android:key="system_installhelp" android:title="@string/pref_installhelp" /> + + + + diff --git a/core/src/org/transdroid/core/gui/TorrentsActivity.java b/core/src/org/transdroid/core/gui/TorrentsActivity.java index 17e0e8e1..d6b007b6 100644 --- a/core/src/org/transdroid/core/gui/TorrentsActivity.java +++ b/core/src/org/transdroid/core/gui/TorrentsActivity.java @@ -261,7 +261,11 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi // Update connection to the newly selected server and refresh currentConnection = server.createServerAdapter(); applicationSettings.setLastUsedServer(server); - clearScreens(); + // Clear the currently shown list of torrent and perhaps the details + fragmentTorrents.clear(); + if (fragmentDetails != null) { + fragmentDetails.clear(); + } updateFragmentVisibility(true); refreshTorrents(); return; @@ -311,7 +315,8 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @OptionsItem(resName = "action_refresh") protected void refreshScreen() { refreshTorrents(); - getAdditionalStats(); + if (Daemon.supportsStats(currentConnection.getType())) + getAdditionalStats(); } @OptionsItem(resName = "action_enableturtle") @@ -334,14 +339,6 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.transdroid.org/download/"))); } - private void clearScreens() { - // Clear the currently shown list of torrent and perhaps the details - fragmentTorrents.clear(); - if (fragmentDetails != null) { - fragmentDetails.clear(); - } - } - @Background protected void refreshTorrents() { fragmentTorrents.updateIsLoading(true); @@ -479,8 +476,9 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @UiThread protected void onCommunicationError(DaemonTaskFailureResult result) { Log.i(this, result.getException().toString()); - Crouton.showText(this, getString(LocalTorrent.getResourceForDaemonException(result.getException())), - navigationHelper.CROUTON_ERROR_STYLE); + String error = getString(LocalTorrent.getResourceForDaemonException(result.getException())); + Crouton.showText(this, error, navigationHelper.CROUTON_ERROR_STYLE); + fragmentTorrents.updateError(error); } @UiThread diff --git a/core/src/org/transdroid/core/gui/TorrentsFragment.java b/core/src/org/transdroid/core/gui/TorrentsFragment.java index 0a046aad..050079c4 100644 --- a/core/src/org/transdroid/core/gui/TorrentsFragment.java +++ b/core/src/org/transdroid/core/gui/TorrentsFragment.java @@ -25,7 +25,7 @@ import com.actionbarsherlock.view.MenuItem; import com.actionbarsherlock.view.SherlockListView; import com.actionbarsherlock.view.SherlockListView.MultiChoiceModeListenerCompat; -@EFragment(resName="fragment_torrents") +@EFragment(resName = "fragment_torrents") public class TorrentsFragment extends SherlockFragment { // Local data @@ -36,16 +36,20 @@ public class TorrentsFragment extends SherlockFragment { @InstanceState protected boolean hasAConnection = false; @InstanceState - protected boolean isLoading = false; + protected boolean isLoading = true; + @InstanceState + protected String connectionErrorMessage = null; // Views - @ViewById(resName="torrent_list") + @ViewById(resName = "torrent_list") protected SherlockListView torrentsList; @ViewById protected TextView emptyText; @ViewById protected TextView nosettingsText; @ViewById + protected TextView errorText; + @ViewById protected ProgressBar loadingProgress; @AfterViews @@ -69,6 +73,7 @@ public class TorrentsFragment extends SherlockFragment { * Clear currently visible list of torrents */ public void clear() { + this.connectionErrorMessage = null; updateTorrents(null); } @@ -89,26 +94,26 @@ public class TorrentsFragment extends SherlockFragment { } updateViewVisibility(); } - + private MultiChoiceModeListenerCompat onTorrentsSelected = new MultiChoiceModeListenerCompat() { - + @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { // Show contextual action bar to start/stop/remove/etc. torrents in batch mode mode.getMenuInflater().inflate(R.menu.fragment_torrents_cab, menu); return true; } - + @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { - + // Get checked torrents List checked = new ArrayList(); for (int i = 0; i < torrentsList.getCheckedItemPositions().size(); i++) { if (torrentsList.getCheckedItemPositions().get(i)) checked.add((Torrent) torrentsList.getAdapter().getItem(i)); } - + int itemId = item.getItemId(); if (itemId == R.id.action_resume) { for (Torrent torrent : checked) { @@ -142,7 +147,7 @@ public class TorrentsFragment extends SherlockFragment { return false; } } - + @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { // TODO: Update title or otherwise show number of selected torrents? @@ -152,14 +157,14 @@ public class TorrentsFragment extends SherlockFragment { public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } - + @Override public void onDestroyActionMode(ActionMode mode) { } - + }; - @ItemClick(resName="torrent_list") + @ItemClick(resName = "torrent_list") protected void torrentsListClicked(Torrent torrent) { DetailsActivity_.intent(getActivity()).torrent(torrent).start(); } @@ -171,8 +176,11 @@ public class TorrentsFragment extends SherlockFragment { */ public void updateConnectionStatus(boolean hasAConnection) { this.hasAConnection = hasAConnection; - if (!hasAConnection) - clear(); + if (!hasAConnection) { + clear(); // Indirectly also calls updateViewVisibility() + } else { + updateViewVisibility(); + } } /** @@ -181,8 +189,26 @@ public class TorrentsFragment extends SherlockFragment { */ public void updateIsLoading(boolean isLoading) { this.isLoading = isLoading; - if (isLoading) - clear(); + if (isLoading) { + clear(); // Indirectly also calls updateViewVisibility() + } else { + updateViewVisibility(); + } + } + + /** + * Updates the shown screen depending on whether a connection error occurred + * @param connectionErrorMessage The error message from the last failed connection attempt, or null to clear the + * visible error text + */ + public void updateError(String connectionErrorMessage) { + this.connectionErrorMessage = connectionErrorMessage; + errorText.setText(connectionErrorMessage); + if (connectionErrorMessage != null) { + clear(); // Indirectly also calls updateViewVisibility() + } else { + updateViewVisibility(); + } } @UiThread @@ -191,14 +217,17 @@ public class TorrentsFragment extends SherlockFragment { torrentsList.setVisibility(View.GONE); emptyText.setVisibility(View.GONE); loadingProgress.setVisibility(View.GONE); + errorText.setVisibility(View.GONE); nosettingsText.setVisibility(View.VISIBLE); return; } boolean isEmpty = torrents == null || torrentsList.getAdapter().isEmpty(); + boolean hasError = connectionErrorMessage == null; nosettingsText.setVisibility(View.GONE); - torrentsList.setVisibility(!isLoading && !isEmpty? View.GONE: View.VISIBLE); - loadingProgress.setVisibility(isLoading? View.VISIBLE: View.GONE); - emptyText.setVisibility(!isLoading && isEmpty? View.VISIBLE: View.GONE); + errorText.setVisibility(hasError? View.VISIBLE : View.GONE); + torrentsList.setVisibility(!hasError && !isLoading && !isEmpty ? View.GONE : View.VISIBLE); + loadingProgress.setVisibility(!hasError && isLoading ? View.VISIBLE : View.GONE); + emptyText.setVisibility(!hasError && !isLoading && isEmpty ? View.VISIBLE : View.GONE); } /** diff --git a/core/src/org/transdroid/core/gui/lists/TorrentDetailsView.java b/core/src/org/transdroid/core/gui/lists/TorrentDetailsView.java index 94b04601..61ce87d0 100644 --- a/core/src/org/transdroid/core/gui/lists/TorrentDetailsView.java +++ b/core/src/org/transdroid/core/gui/lists/TorrentDetailsView.java @@ -63,6 +63,7 @@ public class TorrentDetailsView extends RelativeLayout { } else { dateaddedText.setVisibility(View.INVISIBLE); } + statusText.setText(getResources().getString(R.string.status_status, local.getProgressStatusEta(getResources()))); ratioText.setText(getResources().getString(R.string.status_ratio, local.getRatioString())); // TODO: Implement separate numbers of seeders and leechers diff --git a/core/src/org/transdroid/core/gui/lists/TorrentFileView.java b/core/src/org/transdroid/core/gui/lists/TorrentFileView.java index bf00cb0e..d4eab7ff 100644 --- a/core/src/org/transdroid/core/gui/lists/TorrentFileView.java +++ b/core/src/org/transdroid/core/gui/lists/TorrentFileView.java @@ -33,11 +33,11 @@ public class TorrentFileView extends CheckableRelativeLayout { switch (torrentFile.getPriority()) { case Off: priorityImage.setImageResource(R.drawable.ic_priority_off); - priorityImage.setContentDescription(getResources().getString(R.string.status_priority_low)); + priorityImage.setContentDescription(getResources().getString(R.string.status_priority_off)); break; case Low: priorityImage.setImageResource(R.drawable.ic_priority_low); - priorityImage.setContentDescription(getResources().getString(R.string.status_priority_normal)); + priorityImage.setContentDescription(getResources().getString(R.string.status_priority_low)); break; case Normal: priorityImage.setImageResource(R.drawable.ic_priority_normal); diff --git a/core/src/org/transdroid/core/gui/navigation/NavigationHelper.java b/core/src/org/transdroid/core/gui/navigation/NavigationHelper.java index 54025480..431672d8 100644 --- a/core/src/org/transdroid/core/gui/navigation/NavigationHelper.java +++ b/core/src/org/transdroid/core/gui/navigation/NavigationHelper.java @@ -5,11 +5,10 @@ import org.androidannotations.annotations.RootContext; import org.transdroid.core.R; import android.annotation.SuppressLint; -import android.annotation.TargetApi; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager.NameNotFoundException; -import android.os.Build; +import de.keyboardsurfer.android.widget.crouton.Crouton; import de.keyboardsurfer.android.widget.crouton.Style; /** @@ -24,10 +23,17 @@ public class NavigationHelper { @RootContext protected Context context; + /** + * Use with {@link Crouton#showText(android.app.Activity, int, Style)} (and variants) to display error messages. + */ public Style CROUTON_ERROR_STYLE = new Style.Builder().setBackgroundColor(R.color.crouton_error).setTextSize(13) - .build(); + .setDuration(2500).build(); + + /** + * Use with {@link Crouton#showText(android.app.Activity, int, Style)} (and variants) to display info messages. + */ public Style CROUTON_INFO_STYLE = new Style.Builder().setBackgroundColor(R.color.crouton_info).setTextSize(13) - .build(); + .setDuration(1500).build(); /** * Whether any search-related UI components should be shown in the interface. At the moment returns false only if we @@ -72,18 +78,4 @@ public class NavigationHelper { return !context.getPackageName().equals("org.transdroid.lite"); } - /** - * Whether the navigation of server types and labels as filter are shown in a separate fragment. - * @return True if navigation is in a separate fragment, false if the items are shown in the action bar spinner - */ - @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2) - public boolean showFiltersInFragment() { - if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { - if (context.getResources().getConfiguration().screenWidthDp >= 600) { - return true; - } - } - return false; - } - } diff --git a/core/src/org/transdroid/core/gui/settings/SystemSettingsActivity.java b/core/src/org/transdroid/core/gui/settings/SystemSettingsActivity.java index 61768852..494da615 100644 --- a/core/src/org/transdroid/core/gui/settings/SystemSettingsActivity.java +++ b/core/src/org/transdroid/core/gui/settings/SystemSettingsActivity.java @@ -40,6 +40,8 @@ public class SystemSettingsActivity extends SherlockPreferenceActivity { findPreference("system_sendlog").setOnPreferenceClickListener(onSendLogClick); findPreference("system_installhelp").setOnPreferenceClickListener(onInstallHelpClick); findPreference("system_changelog").setOnPreferenceClickListener(onChangeLogClick); + findPreference("system_importsettings").setOnPreferenceClickListener(onImportSettingsClick); + findPreference("system_exportsettings").setOnPreferenceClickListener(onExportSettingsClick); findPreference("system_about").setOnPreferenceClickListener(onAboutClick); } @@ -59,6 +61,22 @@ public class SystemSettingsActivity extends SherlockPreferenceActivity { } }; + private OnPreferenceClickListener onImportSettingsClick = new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + // TODO: Allow import of settings + return true; + } + }; + + private OnPreferenceClickListener onExportSettingsClick = new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + // TODO: Allow export of settings + return true; + } + }; + private OnPreferenceClickListener onChangeLogClick = new OnPreferenceClickListener() { @SuppressWarnings("deprecation") @Override diff --git a/full/AndroidManifest.xml b/full/AndroidManifest.xml index 356bca80..3622d5fc 100644 --- a/full/AndroidManifest.xml +++ b/full/AndroidManifest.xml @@ -24,7 +24,7 @@ diff --git a/lite/AndroidManifest.xml b/lite/AndroidManifest.xml index d504abea..cfa672f5 100644 --- a/lite/AndroidManifest.xml +++ b/lite/AndroidManifest.xml @@ -24,7 +24,7 @@