From 5a6a6bcc78d2c5dfda255aa7478365b79ab7b8d6 Mon Sep 17 00:00:00 2001 From: kapodamy Date: Thu, 1 Aug 2019 18:55:37 -0300 Subject: [PATCH 1/4] clean-up: remove unused method --- .../java/org/schabi/newpipe/download/DownloadActivity.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java b/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java index 41971dfd4..2bc200f05 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java @@ -61,6 +61,7 @@ public class DownloadActivity extends AppCompatActivity { .commit(); } + @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); MenuInflater inflater = getMenuInflater(); @@ -86,9 +87,4 @@ public class DownloadActivity extends AppCompatActivity { return super.onOptionsItemSelected(item); } } - - @Override - public void onRestoreInstanceState(Bundle inState){ - super.onRestoreInstanceState(inState); - } } From 0375194e7d212334c68c23999f8cd6c2140a957d Mon Sep 17 00:00:00 2001 From: kapodamy Date: Thu, 1 Aug 2019 18:58:25 -0300 Subject: [PATCH 2/4] 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 --- .../giga/service/DownloadManager.java | 4 +-- .../giga/ui/adapter/MissionAdapter.java | 19 ++++-------- .../giga/ui/fragment/MissionsFragment.java | 29 +++++++++++++++++++ app/src/main/res/menu/download_menu.xml | 12 ++++---- 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/us/shandian/giga/service/DownloadManager.java b/app/src/main/java/us/shandian/giga/service/DownloadManager.java index c2bba7396..b168ef474 100644 --- a/app/src/main/java/us/shandian/giga/service/DownloadManager.java +++ b/app/src/main/java/us/shandian/giga/service/DownloadManager.java @@ -666,9 +666,9 @@ public class DownloadManager { continue; if (mission.running) - paused = true; - else running = true; + else + paused = true; } } diff --git a/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java b/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java index ebc6e94c2..e53ab4f1f 100644 --- a/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java +++ b/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java @@ -122,14 +122,8 @@ public class MissionAdapter extends Adapter { 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 { 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 { 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() { diff --git a/app/src/main/java/us/shandian/giga/ui/fragment/MissionsFragment.java b/app/src/main/java/us/shandian/giga/ui/fragment/MissionsFragment.java index f8cecbed9..2a93d20f4 100644 --- a/app/src/main/java/us/shandian/giga/ui/fragment/MissionsFragment.java +++ b/app/src/main/java/us/shandian/giga/ui/fragment/MissionsFragment.java @@ -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); } diff --git a/app/src/main/res/menu/download_menu.xml b/app/src/main/res/menu/download_menu.xml index 4e4549957..935399169 100644 --- a/app/src/main/res/menu/download_menu.xml +++ b/app/src/main/res/menu/download_menu.xml @@ -1,29 +1,31 @@ - + tools:ignore="AlwaysShowAction" + app:showAsAction="always" /> + app:showAsAction="never" /> + app:showAsAction="never" /> + app:showAsAction="never" /> Date: Sat, 3 Aug 2019 12:33:54 -0300 Subject: [PATCH 3/4] dont hardcode the buttons --- .../giga/ui/fragment/MissionsFragment.java | 27 ------------------- app/src/main/res/menu/download_menu.xml | 2 +- 2 files changed, 1 insertion(+), 28 deletions(-) diff --git a/app/src/main/java/us/shandian/giga/ui/fragment/MissionsFragment.java b/app/src/main/java/us/shandian/giga/ui/fragment/MissionsFragment.java index 2a93d20f4..69c8e8f50 100644 --- a/app/src/main/java/us/shandian/giga/ui/fragment/MissionsFragment.java +++ b/app/src/main/java/us/shandian/giga/ui/fragment/MissionsFragment.java @@ -7,7 +7,6 @@ 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; @@ -171,15 +170,6 @@ 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); } @@ -260,23 +250,6 @@ 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); diff --git a/app/src/main/res/menu/download_menu.xml b/app/src/main/res/menu/download_menu.xml index 935399169..6285352da 100644 --- a/app/src/main/res/menu/download_menu.xml +++ b/app/src/main/res/menu/download_menu.xml @@ -7,7 +7,7 @@ android:icon="?attr/ic_grid" android:title="@string/grid" tools:ignore="AlwaysShowAction" - app:showAsAction="always" /> + app:showAsAction="ifRoom" /> Date: Sat, 10 Aug 2019 15:56:59 -0300 Subject: [PATCH 4/4] update download_menu.xml use "ifRoom" and "always" in cases where is possible --- app/src/main/res/menu/download_menu.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/res/menu/download_menu.xml b/app/src/main/res/menu/download_menu.xml index 6285352da..f91f8ad7b 100644 --- a/app/src/main/res/menu/download_menu.xml +++ b/app/src/main/res/menu/download_menu.xml @@ -7,25 +7,25 @@ android:icon="?attr/ic_grid" android:title="@string/grid" tools:ignore="AlwaysShowAction" - app:showAsAction="ifRoom" /> + app:showAsAction="always" /> + app:showAsAction="ifRoom" /> + app:showAsAction="ifRoom" /> + app:showAsAction="ifRoom" />