mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-25 17:40:33 +00:00
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;
|
continue;
|
||||||
|
|
||||||
if (mission.running)
|
if (mission.running)
|
||||||
paused = true;
|
|
||||||
else
|
|
||||||
running = true;
|
running = true;
|
||||||
|
else
|
||||||
|
paused = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,14 +122,8 @@ public class MissionAdapter extends Adapter<ViewHolder> {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mStartButton != null && mPauseButton != null) switch (msg.what) {
|
if (mStartButton != null && mPauseButton != null)
|
||||||
case DownloadManagerService.MESSAGE_DELETED:
|
|
||||||
case DownloadManagerService.MESSAGE_ERROR:
|
|
||||||
case DownloadManagerService.MESSAGE_FINISHED:
|
|
||||||
case DownloadManagerService.MESSAGE_PAUSED:
|
|
||||||
checkMasterButtonsVisibility();
|
checkMasterButtonsVisibility();
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -163,8 +157,7 @@ public class MissionAdapter extends Adapter<ViewHolder> {
|
|||||||
mPendingDownloadsItems.remove(h);
|
mPendingDownloadsItems.remove(h);
|
||||||
if (mPendingDownloadsItems.size() < 1) {
|
if (mPendingDownloadsItems.size() < 1) {
|
||||||
setAutoRefresh(false);
|
setAutoRefresh(false);
|
||||||
if (mStartButton != null) mStartButton.setVisible(false);
|
checkMasterButtonsVisibility();
|
||||||
if (mPauseButton != null) mPauseButton.setVisible(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -664,11 +657,11 @@ public class MissionAdapter extends Adapter<ViewHolder> {
|
|||||||
if (mEmptyMessage.getVisibility() != flag) mEmptyMessage.setVisibility(flag);
|
if (mEmptyMessage.getVisibility() != flag) mEmptyMessage.setVisibility(flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkMasterButtonsVisibility() {
|
public void checkMasterButtonsVisibility() {
|
||||||
boolean[] state = mIterator.hasValidPendingMissions();
|
boolean[] state = mIterator.hasValidPendingMissions();
|
||||||
|
|
||||||
mStartButton.setVisible(state[0]);
|
mPauseButton.setVisible(state[0]);
|
||||||
mPauseButton.setVisible(state[1]);
|
mStartButton.setVisible(state[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ensurePausedMissions() {
|
public void ensurePausedMissions() {
|
||||||
|
@ -7,6 +7,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.res.Configuration;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
@ -138,6 +139,7 @@ public class MissionsFragment extends Fragment {
|
|||||||
* deprecated in API level 23,
|
* deprecated in API level 23,
|
||||||
* but must remain to allow compatibility with api<23
|
* but must remain to allow compatibility with api<23
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Activity activity) {
|
public void onAttach(Activity activity) {
|
||||||
super.onAttach(activity);
|
super.onAttach(activity);
|
||||||
@ -169,6 +171,15 @@ public class MissionsFragment extends Fragment {
|
|||||||
|
|
||||||
if (mAdapter != null) setAdapterButtons();
|
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);
|
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
|
@Override
|
||||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
@ -273,6 +301,7 @@ public class MissionsFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mBinder.addMissionEventListener(mAdapter.getMessenger());
|
mBinder.addMissionEventListener(mAdapter.getMessenger());
|
||||||
|
mAdapter.checkMasterButtonsVisibility();
|
||||||
}
|
}
|
||||||
if (mBinder != null) mBinder.enableNotifications(false);
|
if (mBinder != null) mBinder.enableNotifications(false);
|
||||||
}
|
}
|
||||||
|
@ -1,29 +1,31 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?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">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
<item android:id="@+id/switch_mode"
|
<item android:id="@+id/switch_mode"
|
||||||
android:icon="?attr/ic_grid"
|
android:icon="?attr/ic_grid"
|
||||||
android:title="@string/grid"
|
android:title="@string/grid"
|
||||||
app:showAsAction="ifRoom" />
|
tools:ignore="AlwaysShowAction"
|
||||||
|
app:showAsAction="always" />
|
||||||
|
|
||||||
<item android:id="@+id/start_downloads"
|
<item android:id="@+id/start_downloads"
|
||||||
android:visible="false"
|
android:visible="false"
|
||||||
android:icon="?attr/play"
|
android:icon="?attr/play"
|
||||||
android:title="@string/start_downloads"
|
android:title="@string/start_downloads"
|
||||||
app:showAsAction="ifRoom" />
|
app:showAsAction="never" />
|
||||||
|
|
||||||
<item android:id="@+id/pause_downloads"
|
<item android:id="@+id/pause_downloads"
|
||||||
android:visible="false"
|
android:visible="false"
|
||||||
android:icon="?attr/pause"
|
android:icon="?attr/pause"
|
||||||
android:title="@string/pause_downloads"
|
android:title="@string/pause_downloads"
|
||||||
app:showAsAction="ifRoom" />
|
app:showAsAction="never" />
|
||||||
|
|
||||||
<item android:id="@+id/clear_list"
|
<item android:id="@+id/clear_list"
|
||||||
android:visible="false"
|
android:visible="false"
|
||||||
android:icon="?attr/ic_delete"
|
android:icon="?attr/ic_delete"
|
||||||
android:title="@string/clear_finished_download"
|
android:title="@string/clear_finished_download"
|
||||||
app:showAsAction="ifRoom" />
|
app:showAsAction="never" />
|
||||||
|
|
||||||
<item android:id="@+id/action_settings"
|
<item android:id="@+id/action_settings"
|
||||||
android:title="@string/settings"
|
android:title="@string/settings"
|
||||||
|
Loading…
Reference in New Issue
Block a user