diff --git a/app/build.gradle b/app/build.gradle index 33e20202..da7ead4b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,12 +2,12 @@ apply plugin: 'com.android.application' apply plugin: 'android-apt' android { - compileSdkVersion 21 - buildToolsVersion '21.1.1' + compileSdkVersion 22 + buildToolsVersion '21.1.2' defaultConfig { minSdkVersion 15 - targetSdkVersion 21 + targetSdkVersion 22 versionCode 217 versionName '2.5.0-SNAPSHOT' } @@ -33,16 +33,16 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'org.androidannotations:androidannotations-api:3.1' + compile 'org.androidannotations:androidannotations-api:3.2' compile 'com.j256.ormlite:ormlite-core:4.48' compile 'com.j256.ormlite:ormlite-android:4.48' compile 'de.keyboardsurfer.android.widget:crouton:1.8.5@aar' - compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.+' - compile 'com.android.support:appcompat-v7:21.0.0' + compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3' + compile 'com.android.support:appcompat-v7:22.0.0' compile 'com.android.support:support-annotations:20.0.0' - compile 'com.getbase:floatingactionbutton:1.2.1' - compile 'com.afollestad:material-dialogs:0.3.6' - apt 'org.androidannotations:androidannotations:3.1' + compile 'com.getbase:floatingactionbutton:1.8.0' + compile 'com.afollestad:material-dialogs:0.6.3.3' + apt 'org.androidannotations:androidannotations:3.2' } apt { diff --git a/app/src/main/java/org/transdroid/core/app/settings/SystemSettings.java b/app/src/main/java/org/transdroid/core/app/settings/SystemSettings.java index 0a4b1af7..31449136 100644 --- a/app/src/main/java/org/transdroid/core/app/settings/SystemSettings.java +++ b/app/src/main/java/org/transdroid/core/app/settings/SystemSettings.java @@ -76,7 +76,7 @@ public class SystemSettings { * @param lastChecked The date/time at which the {@link AppUpdateService} last checked the server for updates */ public void setLastCheckedForAppUpdates(Date lastChecked) { - prefs.edit().putLong("system_lastappupdatecheck", lastChecked == null ? -1L : lastChecked.getTime()).commit(); + prefs.edit().putLong("system_lastappupdatecheck", lastChecked == null ? -1L : lastChecked.getTime()).apply(); } } diff --git a/app/src/main/java/org/transdroid/core/gui/DetailsActivity.java b/app/src/main/java/org/transdroid/core/gui/DetailsActivity.java index 38a32894..b87acaea 100644 --- a/app/src/main/java/org/transdroid/core/gui/DetailsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/DetailsActivity.java @@ -16,8 +16,14 @@ */ package org.transdroid.core.gui; -import java.util.ArrayList; -import java.util.List; +import android.annotation.TargetApi; +import android.content.Intent; +import android.os.Build; +import android.os.Bundle; +import android.support.v4.widget.SwipeRefreshLayout; +import android.support.v7.app.ActionBarActivity; +import android.support.v7.widget.Toolbar; +import android.widget.Toast; import org.androidannotations.annotations.AfterViews; import org.androidannotations.annotations.Background; @@ -29,8 +35,11 @@ import org.androidannotations.annotations.InstanceState; import org.androidannotations.annotations.OptionsItem; import org.androidannotations.annotations.OptionsMenu; import org.androidannotations.annotations.UiThread; +import org.androidannotations.annotations.ViewById; import org.transdroid.R; -import org.transdroid.core.app.settings.*; +import org.transdroid.core.app.settings.ApplicationSettings; +import org.transdroid.core.app.settings.ServerSetting; +import org.transdroid.core.app.settings.SystemSettings_; import org.transdroid.core.gui.lists.LocalTorrent; import org.transdroid.core.gui.log.Log; import org.transdroid.core.gui.navigation.Label; @@ -63,23 +72,19 @@ import org.transdroid.daemon.task.SetTrackersTask; import org.transdroid.daemon.task.StartTask; import org.transdroid.daemon.task.StopTask; -import android.annotation.TargetApi; -import android.content.Intent; -import android.os.Build; -import android.os.Bundle; -import android.support.v7.app.ActionBarActivity; -import android.view.View; -import android.widget.Toast; +import java.util.ArrayList; +import java.util.List; + import de.keyboardsurfer.android.widget.crouton.Crouton; /** - * An activity that holds a single torrents details fragment. It is used on devices (i.e. phones) where there is no room - * to show details in the {@link TorrentsActivity} directly. Task execution, such as loading of more details and - * updating file priorities, is performed in this activity via background methods. + * An activity that holds a single torrents details fragment. It is used on devices (i.e. phones) where there is no room to show details in the {@link + * TorrentsActivity} directly. Task execution, such as loading of more details and updating file priorities, is performed in this activity via + * background methods. * @author Eric Kok */ -@EActivity(resName = "activity_details") -@OptionsMenu(resName = "activity_details") +@EActivity(R.layout.activity_details) +@OptionsMenu(R.menu.activity_details) public class DetailsActivity extends ActionBarActivity implements TorrentTasksExecutor, RefreshableActivity { @Extra @@ -101,7 +106,9 @@ public class DetailsActivity extends ActionBarActivity implements TorrentTasksEx private IDaemonAdapter currentConnection = null; // Details view components - @FragmentById(resName = "torrentdetails_fragment") + @ViewById + protected Toolbar torrentsToolbar; + @FragmentById(R.id.torrentdetails_fragment) protected DetailsFragment fragmentDetails; @Override @@ -123,6 +130,7 @@ public class DetailsActivity extends ActionBarActivity implements TorrentTasksEx } // Simple action bar with up, torrent name as title and refresh button + setSupportActionBar(torrentsToolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setTitle(NavigationHelper.buildCondensedFontString(torrent.getName())); @@ -151,14 +159,19 @@ public class DetailsActivity extends ActionBarActivity implements TorrentTasksEx /** * Attaches some view (perhaps contained in a fragment) to this activity's pull to refresh support - * @param view The view to attach + * @param container The refresh container to handle user refresh requests and show the progress */ @Override - public void addRefreshableView(View view) { - // TODO Add new style pull to refresh library + public void addSwipeRefreshLayout(SwipeRefreshLayout container) { + container.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + refreshScreen(); + } + }); } - @OptionsItem(resName = "action_refresh") + @OptionsItem(R.id.action_refresh) public void refreshScreen() { fragmentDetails.updateIsLoading(true, null); refreshTorrent(); @@ -170,8 +183,7 @@ public class DetailsActivity extends ActionBarActivity implements TorrentTasksEx protected void refreshTorrent() { DaemonTaskResult result = RetrieveTask.create(currentConnection).execute(log); if (result instanceof RetrieveTaskSuccessResult) { - onTorrentsRetrieved(((RetrieveTaskSuccessResult) result).getTorrents(), - ((RetrieveTaskSuccessResult) result).getLabels()); + onTorrentsRetrieved(((RetrieveTaskSuccessResult) result).getTorrents(), ((RetrieveTaskSuccessResult) result).getLabels()); } else { onCommunicationError((DaemonTaskFailureResult) result, true); } @@ -179,8 +191,9 @@ public class DetailsActivity extends ActionBarActivity implements TorrentTasksEx @Background public void refreshTorrentDetails(Torrent torrent) { - if (!Daemon.supportsFineDetails(torrent.getDaemon())) + if (!Daemon.supportsFineDetails(torrent.getDaemon())) { return; + } DaemonTaskResult result = GetTorrentDetailsTask.create(currentConnection, torrent).execute(log); if (result instanceof GetTorrentDetailsTaskSuccessResult) { onTorrentDetailsRetrieved(torrent, ((GetTorrentDetailsTaskSuccessResult) result).getTorrentDetails()); @@ -191,8 +204,9 @@ public class DetailsActivity extends ActionBarActivity implements TorrentTasksEx @Background public void refreshTorrentFiles(Torrent torrent) { - if (!Daemon.supportsFileListing(torrent.getDaemon())) + if (!Daemon.supportsFileListing(torrent.getDaemon())) { return; + } DaemonTaskResult result = GetFileListTask.create(currentConnection, torrent).execute(log); if (result instanceof GetFileListTaskSuccessResult) { onTorrentFilesRetrieved(torrent, ((GetFileListTaskSuccessResult) result).getFiles()); @@ -255,8 +269,7 @@ public class DetailsActivity extends ActionBarActivity implements TorrentTasksEx DaemonTaskResult result = RemoveTask.create(currentConnection, torrent, withData).execute(log); if (result instanceof DaemonTaskSuccessResult) { // Close the details activity (as the torrent is now removed) - closeActivity(getString(withData ? R.string.result_removed_with_data : R.string.result_removed, - torrent.getName())); + closeActivity(getString(withData ? R.string.result_removed_with_data : R.string.result_removed, torrent.getName())); } else { onCommunicationError((DaemonTaskFailureResult) result, false); } @@ -264,19 +277,18 @@ public class DetailsActivity extends ActionBarActivity implements TorrentTasksEx @UiThread protected void closeActivity(String closeText) { - setResult(RESULT_OK, - new Intent().putExtra("torrent_removed", true).putExtra("affected_torrent", torrent)); + setResult(RESULT_OK, new Intent().putExtra("torrent_removed", true).putExtra("affected_torrent", torrent)); finish(); - if (closeText != null) + if (closeText != null) { Toast.makeText(this, closeText, Toast.LENGTH_LONG).show(); + } } @Background @Override public void updateLabel(Torrent torrent, String newLabel) { torrent.mimicNewLabel(newLabel); - DaemonTaskResult result = SetLabelTask.create(currentConnection, torrent, newLabel == null ? "" : newLabel) - .execute(log); + DaemonTaskResult result = SetLabelTask.create(currentConnection, torrent, newLabel == null ? "" : newLabel).execute(log); if (result instanceof DaemonTaskSuccessResult) { onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_labelset, newLabel)); } else { @@ -290,8 +302,7 @@ public class DetailsActivity extends ActionBarActivity implements TorrentTasksEx torrent.mimicCheckingStatus(); DaemonTaskResult result = ForceRecheckTask.create(currentConnection, torrent).execute(log); if (result instanceof DaemonTaskSuccessResult) { - onTaskSucceeded((DaemonTaskSuccessResult) result, - getString(R.string.result_recheckedstarted, torrent.getName())); + onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_recheckedstarted, torrent.getName())); } else { onCommunicationError((DaemonTaskFailureResult) result, false); } @@ -322,8 +333,7 @@ public class DetailsActivity extends ActionBarActivity implements TorrentTasksEx @Background @Override public void updatePriority(Torrent torrent, List files, Priority priority) { - DaemonTaskResult result = SetFilePriorityTask.create(currentConnection, torrent, priority, - new ArrayList(files)).execute(log); + DaemonTaskResult result = SetFilePriorityTask.create(currentConnection, torrent, priority, new ArrayList<>(files)).execute(log); if (result instanceof DaemonTaskSuccessResult) { onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_priotitiesset)); } else { @@ -334,8 +344,7 @@ public class DetailsActivity extends ActionBarActivity implements TorrentTasksEx @UiThread protected void onTaskSucceeded(DaemonTaskSuccessResult result, String successMessage) { // Set the activity result so the calling activity knows it needs to update its view - setResult(RESULT_OK, - new Intent().putExtra("torrent_updated", true).putExtra("affected_torrent", torrent)); + setResult(RESULT_OK, new Intent().putExtra("torrent_updated", true).putExtra("affected_torrent", torrent)); // Refresh the screen as well refreshTorrent(); refreshTorrentDetails(torrent); @@ -351,7 +360,7 @@ public class DetailsActivity extends ActionBarActivity implements TorrentTasksEx @UiThread protected void onTorrentFilesRetrieved(Torrent torrent, List torrentFiles) { // Update the details fragment with the newly retrieved list of files - fragmentDetails.updateTorrentFiles(torrent, new ArrayList(torrentFiles)); + fragmentDetails.updateTorrentFiles(torrent, new ArrayList<>(torrentFiles)); } @UiThread @@ -359,8 +368,7 @@ public class DetailsActivity extends ActionBarActivity implements TorrentTasksEx log.i(this, result.getException().toString()); String error = getString(LocalTorrent.getResourceForDaemonException(result.getException())); fragmentDetails.updateIsLoading(false, isCritical ? error : null); - Crouton.showText(this, getString(LocalTorrent.getResourceForDaemonException(result.getException())), - NavigationHelper.CROUTON_ERROR_STYLE); + Crouton.showText(this, getString(LocalTorrent.getResourceForDaemonException(result.getException())), NavigationHelper.CROUTON_ERROR_STYLE); } @UiThread @@ -368,8 +376,7 @@ public class DetailsActivity extends ActionBarActivity implements TorrentTasksEx // Update the details fragment accordingly fragmentDetails.updateIsLoading(false, null); fragmentDetails.perhapsUpdateTorrent(torrents); - fragmentDetails.updateLabels(Label.convertToNavigationLabels(labels, - getResources().getString(R.string.labels_unlabeled))); + fragmentDetails.updateLabels(Label.convertToNavigationLabels(labels, getResources().getString(R.string.labels_unlabeled))); } } diff --git a/app/src/main/java/org/transdroid/core/gui/DetailsFragment.java b/app/src/main/java/org/transdroid/core/gui/DetailsFragment.java index 013bbbab..0c921e49 100644 --- a/app/src/main/java/org/transdroid/core/gui/DetailsFragment.java +++ b/app/src/main/java/org/transdroid/core/gui/DetailsFragment.java @@ -16,9 +16,22 @@ */ package org.transdroid.core.gui; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import android.annotation.SuppressLint; +import android.app.Fragment; +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.support.v4.widget.SwipeRefreshLayout; +import android.view.ActionMode; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.AbsListView.MultiChoiceModeListener; +import android.widget.ListView; +import android.widget.ProgressBar; +import android.widget.TextView; import org.androidannotations.annotations.AfterViews; import org.androidannotations.annotations.Click; @@ -29,10 +42,16 @@ import org.androidannotations.annotations.OptionsItem; import org.androidannotations.annotations.OptionsMenu; import org.androidannotations.annotations.ViewById; import org.transdroid.R; -import org.transdroid.core.app.settings.*; +import org.transdroid.core.app.settings.ServerSetting; +import org.transdroid.core.app.settings.SystemSettings_; import org.transdroid.core.gui.lists.DetailsAdapter; import org.transdroid.core.gui.lists.SimpleListItemAdapter; -import org.transdroid.core.gui.navigation.*; +import org.transdroid.core.gui.navigation.Label; +import org.transdroid.core.gui.navigation.NavigationHelper; +import org.transdroid.core.gui.navigation.NavigationHelper_; +import org.transdroid.core.gui.navigation.RefreshableActivity; +import org.transdroid.core.gui.navigation.SelectionManagerMode; +import org.transdroid.core.gui.navigation.SetLabelDialog; import org.transdroid.core.gui.navigation.SetLabelDialog.OnLabelPickedListener; import org.transdroid.core.gui.navigation.SetStorageLocationDialog; import org.transdroid.core.gui.navigation.SetStorageLocationDialog.OnStorageLocationUpdatedListener; @@ -44,33 +63,21 @@ import org.transdroid.daemon.Torrent; import org.transdroid.daemon.TorrentDetails; import org.transdroid.daemon.TorrentFile; -import android.annotation.SuppressLint; -import android.app.Fragment; -import android.content.ClipData; -import android.content.ClipboardManager; -import android.content.Context; -import android.content.Intent; -import android.net.Uri; -import android.view.ActionMode; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.widget.AbsListView.MultiChoiceModeListener; -import android.widget.ListView; -import android.widget.ProgressBar; -import android.widget.TextView; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + import de.keyboardsurfer.android.widget.crouton.Crouton; /** - * Fragment that shows detailed statistics about some torrent. These come from some already fetched {@link Torrent} - * object, but it also retrieves further detailed statistics. The actual execution of tasks is performed by the activity - * that contains this fragment, as per the {@link TorrentTasksExecutor} interface. + * Fragment that shows detailed statistics about some torrent. These come from some already fetched {@link Torrent} object, but it also retrieves + * further detailed statistics. The actual execution of tasks is performed by the activity that contains this fragment, as per the {@link + * TorrentTasksExecutor} interface. * @author Eric Kok */ -@EFragment(resName = "fragment_details") -@OptionsMenu(resName = "fragment_details") -public class DetailsFragment extends Fragment implements OnTrackersUpdatedListener, OnLabelPickedListener, - OnStorageLocationUpdatedListener { +@EFragment(R.layout.fragment_details) +@OptionsMenu(R.menu.fragment_details) +public class DetailsFragment extends Fragment implements OnTrackersUpdatedListener, OnLabelPickedListener, OnStorageLocationUpdatedListener { // Local data @InstanceState @@ -90,9 +97,11 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen private ServerSetting currentServerSettings = null; // Views - @ViewById(resName = "details_container") + @ViewById protected View detailsContainer; - @ViewById(resName = "details_list") + @ViewById + protected SwipeRefreshLayout swipeRefreshLayout; + @ViewById protected ListView detailsList; @ViewById protected TextView emptyText, errorText; @@ -118,16 +127,19 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen detailsList.setMultiChoiceModeListener(onDetailsSelected); detailsList.setFastScrollEnabled(true); if (getActivity() != null && getActivity() instanceof RefreshableActivity) { - ((RefreshableActivity) getActivity()).addRefreshableView(detailsList); + ((RefreshableActivity) getActivity()).addSwipeRefreshLayout(swipeRefreshLayout); } // Restore the fragment state (on orientation changes et al.) - if (torrent != null) + if (torrent != null) { updateTorrent(torrent); - if (torrentDetails != null) + } + if (torrentDetails != null) { updateTorrentDetails(torrent, torrentDetails); - if (torrentFiles != null) + } + if (torrentFiles != null) { updateTorrentFiles(torrent, torrentFiles); + } } @@ -165,13 +177,14 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen */ public void updateTorrentDetails(Torrent checkTorrent, TorrentDetails newTorrentDetails) { // Check if these are actually the details of the torrent we are now showing - if (torrentId == null || !torrentId.equals(checkTorrent.getUniqueID())) + if (torrentId == null || !torrentId.equals(checkTorrent.getUniqueID())) { return; + } this.torrentDetails = newTorrentDetails; - ((DetailsAdapter) detailsList.getAdapter()).updateTrackers( - SimpleListItemAdapter.SimpleStringItem.wrapStringsList(newTorrentDetails.getTrackers())); - ((DetailsAdapter) detailsList.getAdapter()).updateErrors( - SimpleListItemAdapter.SimpleStringItem.wrapStringsList(newTorrentDetails.getErrors())); + ((DetailsAdapter) detailsList.getAdapter()) + .updateTrackers(SimpleListItemAdapter.SimpleStringItem.wrapStringsList(newTorrentDetails.getTrackers())); + ((DetailsAdapter) detailsList.getAdapter()) + .updateErrors(SimpleListItemAdapter.SimpleStringItem.wrapStringsList(newTorrentDetails.getErrors())); } /** @@ -181,22 +194,23 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen */ public void updateTorrentFiles(Torrent checkTorrent, ArrayList newTorrentFiles) { // Check if these are actually the details of the torrent we are now showing - if (torrentId == null || !torrentId.equals(checkTorrent.getUniqueID())) + if (torrentId == null || !torrentId.equals(checkTorrent.getUniqueID())) { return; + } Collections.sort(newTorrentFiles); this.torrentFiles = newTorrentFiles; ((DetailsAdapter) detailsList.getAdapter()).updateTorrentFiles(newTorrentFiles); } /** - * Can be called if some outside activity returned new torrents, so we can perhaps piggyback on this by update our - * data as well. + * Can be called if some outside activity returned new torrents, so we can perhaps piggyback on this by update our data as well. * @param torrents The last of retrieved torrents */ public void perhapsUpdateTorrent(List torrents) { // Only try to update if we actually were showing a torrent - if (this.torrentId == null || torrents == null) + if (this.torrentId == null || torrents == null) { return; + } for (Torrent newTorrent : torrents) { if (newTorrent.getUniqueID().equals(torrentId)) { // Found, so we can update our data as well @@ -207,12 +221,12 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen } /** - * Updates the locally maintained list of labels that are active on the server. Used in the label picking dialog and - * should be updated every time after the list of torrents was retrieved to keep it updated. + * Updates the locally maintained list of labels that are active on the server. Used in the label picking dialog and should be updated every time + * after the list of torrents was retrieved to keep it updated. * @param currentLabels The list of known server labels */ public void updateLabels(ArrayList