fix start/pause buttons disappear when screen goes off
* fix start/pause buttons disappear, issued by RecyclerView re-draw * show start/pause buttons in pair to avoid confusions
This commit is contained in:
parent
5a6a6bcc78
commit
0375194e7d
|
@ -666,9 +666,9 @@ public class DownloadManager {
|
|||
continue;
|
||||
|
||||
if (mission.running)
|
||||
paused = true;
|
||||
else
|
||||
running = true;
|
||||
else
|
||||
paused = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -122,14 +122,8 @@ public class MissionAdapter extends Adapter<ViewHolder> {
|
|||
break;
|
||||
}
|
||||
|
||||
if (mStartButton != null && mPauseButton != null) switch (msg.what) {
|
||||
case DownloadManagerService.MESSAGE_DELETED:
|
||||
case DownloadManagerService.MESSAGE_ERROR:
|
||||
case DownloadManagerService.MESSAGE_FINISHED:
|
||||
case DownloadManagerService.MESSAGE_PAUSED:
|
||||
checkMasterButtonsVisibility();
|
||||
break;
|
||||
}
|
||||
if (mStartButton != null && mPauseButton != null)
|
||||
checkMasterButtonsVisibility();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -163,8 +157,7 @@ public class MissionAdapter extends Adapter<ViewHolder> {
|
|||
mPendingDownloadsItems.remove(h);
|
||||
if (mPendingDownloadsItems.size() < 1) {
|
||||
setAutoRefresh(false);
|
||||
if (mStartButton != null) mStartButton.setVisible(false);
|
||||
if (mPauseButton != null) mPauseButton.setVisible(false);
|
||||
checkMasterButtonsVisibility();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -664,11 +657,11 @@ public class MissionAdapter extends Adapter<ViewHolder> {
|
|||
if (mEmptyMessage.getVisibility() != flag) mEmptyMessage.setVisibility(flag);
|
||||
}
|
||||
|
||||
private void checkMasterButtonsVisibility() {
|
||||
public void checkMasterButtonsVisibility() {
|
||||
boolean[] state = mIterator.hasValidPendingMissions();
|
||||
|
||||
mStartButton.setVisible(state[0]);
|
||||
mPauseButton.setVisible(state[1]);
|
||||
mPauseButton.setVisible(state[0]);
|
||||
mStartButton.setVisible(state[1]);
|
||||
}
|
||||
|
||||
public void ensurePausedMissions() {
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.preference.PreferenceManager;
|
||||
|
@ -138,6 +139,7 @@ public class MissionsFragment extends Fragment {
|
|||
* deprecated in API level 23,
|
||||
* but must remain to allow compatibility with api<23
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
|
@ -169,6 +171,15 @@ public class MissionsFragment extends Fragment {
|
|||
|
||||
if (mAdapter != null) setAdapterButtons();
|
||||
|
||||
int max = getMaxActionButtons() - 1 /* grid button */;
|
||||
if (max >= 2) {
|
||||
// show start/pause downloads buttons in pair to avoid confusions
|
||||
mStart.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||
mPause.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||
|
||||
if (max > 3) mClear.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||
}
|
||||
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
}
|
||||
|
||||
|
@ -249,6 +260,23 @@ public class MissionsFragment extends Fragment {
|
|||
);
|
||||
}
|
||||
|
||||
public int getMaxActionButtons() {
|
||||
Configuration configuration = mContext.getResources().getConfiguration();
|
||||
int widthDp = configuration.screenWidthDp;
|
||||
int heightDp = configuration.screenHeightDp;
|
||||
int smallest = configuration.smallestScreenWidthDp;
|
||||
|
||||
if (smallest > 600 || widthDp > 600) {
|
||||
return 5;
|
||||
} else if (widthDp >= 500 || widthDp > 480 && heightDp > 640) {
|
||||
return 4;
|
||||
} else if (widthDp >= 360) {
|
||||
return 3;
|
||||
} else {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
|
@ -273,6 +301,7 @@ public class MissionsFragment extends Fragment {
|
|||
}
|
||||
|
||||
mBinder.addMissionEventListener(mAdapter.getMessenger());
|
||||
mAdapter.checkMasterButtonsVisibility();
|
||||
}
|
||||
if (mBinder != null) mBinder.enableNotifications(false);
|
||||
}
|
||||
|
|
|
@ -1,29 +1,31 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<menu xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item android:id="@+id/switch_mode"
|
||||
android:icon="?attr/ic_grid"
|
||||
android:title="@string/grid"
|
||||
app:showAsAction="ifRoom" />
|
||||
tools:ignore="AlwaysShowAction"
|
||||
app:showAsAction="always" />
|
||||
|
||||
<item android:id="@+id/start_downloads"
|
||||
android:visible="false"
|
||||
android:icon="?attr/play"
|
||||
android:title="@string/start_downloads"
|
||||
app:showAsAction="ifRoom" />
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item android:id="@+id/pause_downloads"
|
||||
android:visible="false"
|
||||
android:icon="?attr/pause"
|
||||
android:title="@string/pause_downloads"
|
||||
app:showAsAction="ifRoom" />
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item android:id="@+id/clear_list"
|
||||
android:visible="false"
|
||||
android:icon="?attr/ic_delete"
|
||||
android:title="@string/clear_finished_download"
|
||||
app:showAsAction="ifRoom" />
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item android:id="@+id/action_settings"
|
||||
android:title="@string/settings"
|
||||
|
|
Loading…
Reference in New Issue