From e136a6f91538bf3a7f4710ab1b9f206a55835b90 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Mon, 8 Aug 2022 07:10:16 +0530 Subject: [PATCH 01/35] Use range-limiting methods in more places. --- .../org/schabi/newpipe/local/feed/FeedFragment.kt | 3 ++- .../player/gesture/MainPlayerGestureListener.kt | 5 ++--- .../schabi/newpipe/player/ui/PopupPlayerUi.java | 2 +- .../org/schabi/newpipe/util/ReleaseVersionUtil.kt | 14 ++++++-------- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt index 899163050..c76e69e2a 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt @@ -40,6 +40,7 @@ import androidx.annotation.Nullable import androidx.appcompat.app.AlertDialog import androidx.appcompat.content.res.AppCompatResources import androidx.core.content.edit +import androidx.core.math.MathUtils import androidx.core.os.bundleOf import androidx.core.view.isVisible import androidx.lifecycle.ViewModelProvider @@ -584,7 +585,7 @@ class FeedFragment : BaseStateFragment() { // state until the user scrolls them out of the visible area which causes a update/bind-call groupAdapter.notifyItemRangeChanged( 0, - minOf(groupAdapter.itemCount, maxOf(highlightCount, lastNewItemsCount)) + MathUtils.clamp(highlightCount, lastNewItemsCount, groupAdapter.itemCount) ) if (highlightCount > 0) { diff --git a/app/src/main/java/org/schabi/newpipe/player/gesture/MainPlayerGestureListener.kt b/app/src/main/java/org/schabi/newpipe/player/gesture/MainPlayerGestureListener.kt index 095b3ccdb..a6dba0dd5 100644 --- a/app/src/main/java/org/schabi/newpipe/player/gesture/MainPlayerGestureListener.kt +++ b/app/src/main/java/org/schabi/newpipe/player/gesture/MainPlayerGestureListener.kt @@ -7,6 +7,7 @@ import android.view.View.OnTouchListener import android.widget.ProgressBar import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.content.res.AppCompatResources +import androidx.core.math.MathUtils import androidx.core.view.isVisible import org.schabi.newpipe.MainActivity import org.schabi.newpipe.R @@ -18,8 +19,6 @@ import org.schabi.newpipe.player.helper.PlayerHelper import org.schabi.newpipe.player.ui.MainPlayerUi import org.schabi.newpipe.util.ThemeHelper.getAndroidDimenPx import kotlin.math.abs -import kotlin.math.max -import kotlin.math.min /** * GestureListener for the player @@ -114,7 +113,7 @@ class MainPlayerGestureListener( // Update progress bar val oldBrightness = layoutParams.screenBrightness - bar.progress = (bar.max * max(0f, min(1f, oldBrightness))).toInt() + bar.progress = (bar.max * MathUtils.clamp(oldBrightness, 0f, 1f)).toInt() bar.incrementProgressBy(distanceY.toInt()) // Update brightness diff --git a/app/src/main/java/org/schabi/newpipe/player/ui/PopupPlayerUi.java b/app/src/main/java/org/schabi/newpipe/player/ui/PopupPlayerUi.java index aa36a6a5a..90c24c0c6 100644 --- a/app/src/main/java/org/schabi/newpipe/player/ui/PopupPlayerUi.java +++ b/app/src/main/java/org/schabi/newpipe/player/ui/PopupPlayerUi.java @@ -291,7 +291,7 @@ public final class PopupPlayerUi extends VideoPlayerUi { } final float minimumWidth = context.getResources().getDimension(R.dimen.popup_minimum_width); - final int actualWidth = Math.min((int) Math.max(width, minimumWidth), screenWidth); + final int actualWidth = MathUtils.clamp(width, (int) minimumWidth, screenWidth); final int actualHeight = (int) getMinimumVideoHeight(width); if (DEBUG) { Log.d(TAG, "updatePopupSize() updated values:" diff --git a/app/src/main/java/org/schabi/newpipe/util/ReleaseVersionUtil.kt b/app/src/main/java/org/schabi/newpipe/util/ReleaseVersionUtil.kt index 0c66cc6d4..5a54b29d2 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ReleaseVersionUtil.kt +++ b/app/src/main/java/org/schabi/newpipe/util/ReleaseVersionUtil.kt @@ -100,13 +100,11 @@ object ReleaseVersionUtil { * @return Epoch second of expiry date time */ fun coerceUpdateCheckExpiry(expiryString: String?): Long { - val now = ZonedDateTime.now() - return expiryString?.let { - var expiry = - ZonedDateTime.from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(expiryString)) - expiry = maxOf(expiry, now.plusHours(6)) - expiry = minOf(expiry, now.plusHours(72)) - expiry.toEpochSecond() - } ?: now.plusHours(6).toEpochSecond() + val nowPlus6Hours = ZonedDateTime.now().plusHours(6) + val expiry = expiryString?.let { + ZonedDateTime.from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(it)) + .coerceIn(nowPlus6Hours, nowPlus6Hours.plusHours(66)) + } ?: nowPlus6Hours + return expiry.toEpochSecond() } } From 697b8411dfe8a8a0e62f7f0225e00944d5d01d14 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Fri, 12 Aug 2022 21:17:42 +0530 Subject: [PATCH 02/35] Use Okio's ByteString. --- .../giga/ui/adapter/MissionAdapter.java | 56 ++++++++----------- .../java/us/shandian/giga/util/Utility.java | 55 +++++------------- 2 files changed, 39 insertions(+), 72 deletions(-) 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 343b13ef8..808928370 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 @@ -1,5 +1,25 @@ package us.shandian.giga.ui.adapter; +import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; +import static android.content.Intent.FLAG_GRANT_PREFIX_URI_PERMISSION; +import static android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION; +import static us.shandian.giga.get.DownloadMission.ERROR_CONNECT_HOST; +import static us.shandian.giga.get.DownloadMission.ERROR_FILE_CREATION; +import static us.shandian.giga.get.DownloadMission.ERROR_HTTP_NO_CONTENT; +import static us.shandian.giga.get.DownloadMission.ERROR_INSUFFICIENT_STORAGE; +import static us.shandian.giga.get.DownloadMission.ERROR_NOTHING; +import static us.shandian.giga.get.DownloadMission.ERROR_PATH_CREATION; +import static us.shandian.giga.get.DownloadMission.ERROR_PERMISSION_DENIED; +import static us.shandian.giga.get.DownloadMission.ERROR_POSTPROCESSING; +import static us.shandian.giga.get.DownloadMission.ERROR_POSTPROCESSING_HOLD; +import static us.shandian.giga.get.DownloadMission.ERROR_POSTPROCESSING_STOPPED; +import static us.shandian.giga.get.DownloadMission.ERROR_PROGRESS_LOST; +import static us.shandian.giga.get.DownloadMission.ERROR_RESOURCE_GONE; +import static us.shandian.giga.get.DownloadMission.ERROR_SSL_EXCEPTION; +import static us.shandian.giga.get.DownloadMission.ERROR_TIMEOUT; +import static us.shandian.giga.get.DownloadMission.ERROR_UNKNOWN_EXCEPTION; +import static us.shandian.giga.get.DownloadMission.ERROR_UNKNOWN_HOST; + import android.annotation.SuppressLint; import android.app.NotificationManager; import android.content.Context; @@ -10,7 +30,6 @@ import android.os.Build; import android.os.Handler; import android.os.Message; import android.util.Log; -import android.util.SparseArray; import android.view.HapticFeedbackConstants; import android.view.LayoutInflater; import android.view.Menu; @@ -38,10 +57,11 @@ import com.google.android.material.snackbar.Snackbar; import org.schabi.newpipe.BuildConfig; import org.schabi.newpipe.R; -import org.schabi.newpipe.error.ErrorUtil; -import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.error.ErrorInfo; +import org.schabi.newpipe.error.ErrorUtil; import org.schabi.newpipe.error.UserAction; +import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.streams.io.StoredFileHelper; import org.schabi.newpipe.util.Localization; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.external_communication.ShareUtils; @@ -60,47 +80,19 @@ import us.shandian.giga.get.DownloadMission; import us.shandian.giga.get.FinishedMission; import us.shandian.giga.get.Mission; import us.shandian.giga.get.MissionRecoveryInfo; -import org.schabi.newpipe.streams.io.StoredFileHelper; import us.shandian.giga.service.DownloadManager; import us.shandian.giga.service.DownloadManagerService; import us.shandian.giga.ui.common.Deleter; import us.shandian.giga.ui.common.ProgressDrawable; import us.shandian.giga.util.Utility; -import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; -import static android.content.Intent.FLAG_GRANT_PREFIX_URI_PERMISSION; -import static android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION; -import static us.shandian.giga.get.DownloadMission.ERROR_CONNECT_HOST; -import static us.shandian.giga.get.DownloadMission.ERROR_FILE_CREATION; -import static us.shandian.giga.get.DownloadMission.ERROR_HTTP_NO_CONTENT; -import static us.shandian.giga.get.DownloadMission.ERROR_INSUFFICIENT_STORAGE; -import static us.shandian.giga.get.DownloadMission.ERROR_NOTHING; -import static us.shandian.giga.get.DownloadMission.ERROR_PATH_CREATION; -import static us.shandian.giga.get.DownloadMission.ERROR_PERMISSION_DENIED; -import static us.shandian.giga.get.DownloadMission.ERROR_POSTPROCESSING; -import static us.shandian.giga.get.DownloadMission.ERROR_POSTPROCESSING_HOLD; -import static us.shandian.giga.get.DownloadMission.ERROR_POSTPROCESSING_STOPPED; -import static us.shandian.giga.get.DownloadMission.ERROR_PROGRESS_LOST; -import static us.shandian.giga.get.DownloadMission.ERROR_RESOURCE_GONE; -import static us.shandian.giga.get.DownloadMission.ERROR_SSL_EXCEPTION; -import static us.shandian.giga.get.DownloadMission.ERROR_TIMEOUT; -import static us.shandian.giga.get.DownloadMission.ERROR_UNKNOWN_EXCEPTION; -import static us.shandian.giga.get.DownloadMission.ERROR_UNKNOWN_HOST; - public class MissionAdapter extends Adapter implements Handler.Callback { - private static final SparseArray ALGORITHMS = new SparseArray<>(); private static final String TAG = "MissionAdapter"; private static final String UNDEFINED_PROGRESS = "--.-%"; private static final String DEFAULT_MIME_TYPE = "*/*"; private static final String UNDEFINED_ETA = "--:--"; - private static final int HASH_NOTIFICATION_ID = 123790; - static { - ALGORITHMS.put(R.id.md5, "MD5"); - ALGORITHMS.put(R.id.sha1, "SHA1"); - } - private final Context mContext; private final LayoutInflater mInflater; private final DownloadManager mDownloadManager; @@ -697,7 +689,7 @@ public class MissionAdapter extends Adapter implements Handler.Callb .build()); final StoredFileHelper storage = h.item.mission.storage; compositeDisposable.add( - Observable.fromCallable(() -> Utility.checksum(storage, ALGORITHMS.get(id))) + Observable.fromCallable(() -> Utility.checksum(storage, id)) .subscribeOn(Schedulers.computation()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(result -> { diff --git a/app/src/main/java/us/shandian/giga/util/Utility.java b/app/src/main/java/us/shandian/giga/util/Utility.java index 9e6787d5d..4cd424ab9 100644 --- a/app/src/main/java/us/shandian/giga/util/Utility.java +++ b/app/src/main/java/us/shandian/giga/util/Utility.java @@ -13,8 +13,11 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.content.ContextCompat; +import com.google.android.exoplayer2.util.Util; + import org.schabi.newpipe.R; -import org.schabi.newpipe.streams.io.SharpStream; +import org.schabi.newpipe.streams.io.SharpInputStream; +import org.schabi.newpipe.streams.io.StoredFileHelper; import java.io.BufferedOutputStream; import java.io.File; @@ -25,11 +28,9 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.net.HttpURLConnection; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; import java.util.Locale; -import org.schabi.newpipe.streams.io.StoredFileHelper; +import okio.ByteString; public class Utility { @@ -203,44 +204,18 @@ public class Utility { Toast.makeText(context, R.string.msg_copied, Toast.LENGTH_SHORT).show(); } - public static String checksum(StoredFileHelper source, String algorithm) { - MessageDigest md; - - try { - md = MessageDigest.getInstance(algorithm); - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException(e); + public static String checksum(final StoredFileHelper source, final int algorithmId) + throws IOException { + ByteString byteString; + try (var inputStream = new SharpInputStream(source.getStream())) { + byteString = ByteString.of(Util.toByteArray(inputStream)); } - - SharpStream i; - - try { - i = source.getStream(); - } catch (Exception e) { - throw new RuntimeException(e); + if (algorithmId == R.id.md5) { + byteString = byteString.md5(); + } else if (algorithmId == R.id.sha1) { + byteString = byteString.sha1(); } - - byte[] buf = new byte[1024]; - int len; - - try { - while ((len = i.read(buf)) != -1) { - md.update(buf, 0, len); - } - } catch (IOException e) { - // nothing to do - } - - byte[] digest = md.digest(); - - // HEX - StringBuilder sb = new StringBuilder(); - for (byte b : digest) { - sb.append(Integer.toString((b & 0xff) + 0x100, 16).substring(1)); - } - - return sb.toString(); - + return byteString.hex(); } @SuppressWarnings("ResultOfMethodCallIgnored") From 02deaa0f1ab829181aec4291c0da94ef6ccb7b07 Mon Sep 17 00:00:00 2001 From: opusforlife2 <53176348+opusforlife2@users.noreply.github.com> Date: Fri, 14 Oct 2022 17:02:24 +0000 Subject: [PATCH 03/35] Update label to 'feature request' --- .github/ISSUE_TEMPLATE/feature_request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml index 52b2a4241..31ef92c44 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yml +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -1,6 +1,6 @@ name: Feature request description: Suggest an idea for this project -labels: [enhancement, needs triage] +labels: [feature request, needs triage] body: - type: markdown attributes: From 6277d4981c6260ff5fac36608f9a868458c48b8b Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sat, 17 Sep 2022 19:17:03 +0530 Subject: [PATCH 04/35] Update Android Gradle Plugin to 7.3.0. --- app/build.gradle | 2 +- app/src/debug/AndroidManifest.xml | 6 ++---- app/src/main/AndroidManifest.xml | 4 +++- build.gradle | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 9d941d5a7..7d9eafdd0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,7 +9,7 @@ plugins { android { compileSdk 31 - buildToolsVersion '31.0.0' + namespace 'org.schabi.newpipe' defaultConfig { applicationId "org.schabi.newpipe" diff --git a/app/src/debug/AndroidManifest.xml b/app/src/debug/AndroidManifest.xml index 5cc2fa66a..02a0f6c74 100644 --- a/app/src/debug/AndroidManifest.xml +++ b/app/src/debug/AndroidManifest.xml @@ -1,8 +1,6 @@ - + @@ -14,6 +13,9 @@ + Date: Sun, 23 Oct 2022 23:43:52 +1100 Subject: [PATCH 05/35] Created a non-functional button in HeaderWithMenuItem.kt --- .../newpipe/local/subscription/SubscriptionFragment.kt | 1 + .../newpipe/local/subscription/item/HeaderWithMenuItem.kt | 8 +++++++- app/src/main/res/layout/header_with_menu_item.xml | 8 ++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt index 20f8a01c1..a804b0ff3 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt @@ -269,6 +269,7 @@ class SubscriptionFragment : BaseStateFragment() { feedGroupsCarousel = FeedGroupCarouselItem(requireContext(), carouselAdapter) feedGroupsSortMenuItem = HeaderWithMenuItem( getString(R.string.feed_groups_header_title), + R.drawable.ic_list, R.drawable.ic_sort, menuItemOnClickListener = ::openReorderDialog ) diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/item/HeaderWithMenuItem.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/item/HeaderWithMenuItem.kt index 79a272178..cb312b023 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/item/HeaderWithMenuItem.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/item/HeaderWithMenuItem.kt @@ -11,8 +11,10 @@ import org.schabi.newpipe.databinding.HeaderWithMenuItemBinding class HeaderWithMenuItem( val title: String, @DrawableRes val itemIcon: Int = 0, + @DrawableRes val itemIconListView: Int = 0, var showMenuItem: Boolean = true, private val onClickListener: (() -> Unit)? = null, + private val onClickListenerListView: (() -> Unit)? = null, private val menuItemOnClickListener: (() -> Unit)? = null ) : BindableItem() { companion object { @@ -32,11 +34,15 @@ class HeaderWithMenuItem( override fun bind(viewBinding: HeaderWithMenuItemBinding, position: Int) { viewBinding.headerTitle.text = title - viewBinding.headerMenuItem.setImageResource(itemIcon) + viewBinding.headerMenuItem2.setImageResource(itemIcon) + viewBinding.headerMenuItem.setImageResource(itemIconListView) val listener = onClickListener?.let { OnClickListener { onClickListener.invoke() } } viewBinding.root.setOnClickListener(listener) + val listenerListView = onClickListenerListView?.let { OnClickListener { onClickListenerListView.invoke() } } + viewBinding.root.setOnClickListener(listenerListView) + val menuItemListener = menuItemOnClickListener?.let { OnClickListener { menuItemOnClickListener.invoke() } } viewBinding.headerMenuItem.setOnClickListener(menuItemListener) updateMenuItemVisibility(viewBinding) diff --git a/app/src/main/res/layout/header_with_menu_item.xml b/app/src/main/res/layout/header_with_menu_item.xml index fcf888ed5..170c40098 100644 --- a/app/src/main/res/layout/header_with_menu_item.xml +++ b/app/src/main/res/layout/header_with_menu_item.xml @@ -22,6 +22,14 @@ android:textStyle="bold" tools:text="Header" /> + + Date: Mon, 24 Oct 2022 16:55:12 +1100 Subject: [PATCH 06/35] Created a button in SubscriptionFragment.kt that reads whether button is clicked --- .../newpipe/local/subscription/SubscriptionFragment.kt | 5 +++++ .../newpipe/local/subscription/item/HeaderWithMenuItem.kt | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt index a804b0ff3..bf4941e8e 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt @@ -221,6 +221,10 @@ class SubscriptionFragment : BaseStateFragment() { FeedGroupReorderDialog().show(parentFragmentManager, null) } + private fun temp() { + println("This button is clicked") + } + private fun requestExportResult(result: ActivityResult) { if (result.data != null && result.resultCode == Activity.RESULT_OK) { activity.startService( @@ -271,6 +275,7 @@ class SubscriptionFragment : BaseStateFragment() { getString(R.string.feed_groups_header_title), R.drawable.ic_list, R.drawable.ic_sort, + listViewOnClickListener = ::temp, menuItemOnClickListener = ::openReorderDialog ) add(Section(feedGroupsSortMenuItem, listOf(feedGroupsCarousel))) diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/item/HeaderWithMenuItem.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/item/HeaderWithMenuItem.kt index cb312b023..338083c87 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/item/HeaderWithMenuItem.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/item/HeaderWithMenuItem.kt @@ -14,7 +14,7 @@ class HeaderWithMenuItem( @DrawableRes val itemIconListView: Int = 0, var showMenuItem: Boolean = true, private val onClickListener: (() -> Unit)? = null, - private val onClickListenerListView: (() -> Unit)? = null, + private val listViewOnClickListener: (() -> Unit)? = null, private val menuItemOnClickListener: (() -> Unit)? = null ) : BindableItem() { companion object { @@ -40,8 +40,8 @@ class HeaderWithMenuItem( val listener = onClickListener?.let { OnClickListener { onClickListener.invoke() } } viewBinding.root.setOnClickListener(listener) - val listenerListView = onClickListenerListView?.let { OnClickListener { onClickListenerListView.invoke() } } - viewBinding.root.setOnClickListener(listenerListView) + val listViewListener = listViewOnClickListener?.let { OnClickListener { listViewOnClickListener.invoke() } } + viewBinding.headerMenuItem2.setOnClickListener(listViewListener) val menuItemListener = menuItemOnClickListener?.let { OnClickListener { menuItemOnClickListener.invoke() } } viewBinding.headerMenuItem.setOnClickListener(menuItemListener) From 78547b4fa464cac863e63e07f30529528703dad7 Mon Sep 17 00:00:00 2001 From: Samuel Wu Date: Mon, 24 Oct 2022 18:55:08 +1100 Subject: [PATCH 07/35] Created a list view for channel group. --- .../decoration/FeedGroupCarouselDecoration.kt | 2 +- .../subscription/item/FeedGroupCardItem.kt | 2 +- .../item/FeedGroupCarouselItem.kt | 2 +- .../main/res/layout/feed_group_list_item.xml | 43 +++++++++++++++++++ 4 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 app/src/main/res/layout/feed_group_list_item.xml diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/decoration/FeedGroupCarouselDecoration.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/decoration/FeedGroupCarouselDecoration.kt index 7b7490eaa..a113a8b41 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/decoration/FeedGroupCarouselDecoration.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/decoration/FeedGroupCarouselDecoration.kt @@ -26,7 +26,7 @@ class FeedGroupCarouselDecoration(context: Context) : RecyclerView.ItemDecoratio outRect.set(marginBetweenItems, marginTopBottom, 0, marginTopBottom) - if (childAdapterPosition == 0) { + if (childAdapterPosition >= 0) { outRect.left = marginStartEnd } else if (childAdapterPosition == childAdapterCount - 1) { outRect.right = marginStartEnd diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCardItem.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCardItem.kt index 7b78b3d95..fd8a75da1 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCardItem.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCardItem.kt @@ -21,7 +21,7 @@ data class FeedGroupCardItem( } } - override fun getLayout(): Int = R.layout.feed_group_card_item + override fun getLayout(): Int = R.layout.feed_group_list_item override fun bind(viewBinding: FeedGroupCardItemBinding, position: Int) { viewBinding.title.text = name diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCarouselItem.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCarouselItem.kt index 44af16280..031eb9b18 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCarouselItem.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCarouselItem.kt @@ -36,7 +36,7 @@ class FeedGroupCarouselItem( override fun initializeViewBinding(view: View): FeedItemCarouselBinding { val viewHolder = FeedItemCarouselBinding.bind(view) - linearLayoutManager = LinearLayoutManager(view.context, RecyclerView.HORIZONTAL, false) + linearLayoutManager = LinearLayoutManager(view.context, RecyclerView.VERTICAL, false) viewHolder.recyclerView.apply { layoutManager = linearLayoutManager diff --git a/app/src/main/res/layout/feed_group_list_item.xml b/app/src/main/res/layout/feed_group_list_item.xml new file mode 100644 index 000000000..c49da1eab --- /dev/null +++ b/app/src/main/res/layout/feed_group_list_item.xml @@ -0,0 +1,43 @@ + + + + + + + + + + From f37d869ea2c2474985a1386af9fbed67abf092ef Mon Sep 17 00:00:00 2001 From: Samuel Wu Date: Mon, 24 Oct 2022 23:01:02 +1100 Subject: [PATCH 08/35] Button can be toggled but not all strings have been fed --- .../5.json | 26 +++-- .../database/feed/model/FeedGroupEntity.kt | 2 +- .../subscription/SubscriptionFragment.kt | 101 ++++++++++++++++-- .../subscription/item/FeedGroupCardItem.kt | 4 +- .../item/FeedGroupCardVerticalItem.kt | 32 ++++++ .../item/FeedGroupCarouselItem.kt | 6 +- ....xml => feed_group_card_vertical_item.xml} | 7 +- 7 files changed, 155 insertions(+), 23 deletions(-) create mode 100644 app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCardVerticalItem.kt rename app/src/main/res/layout/{feed_group_list_item.xml => feed_group_card_vertical_item.xml} (92%) diff --git a/app/schemas/org.schabi.newpipe.database.AppDatabase/5.json b/app/schemas/org.schabi.newpipe.database.AppDatabase/5.json index 9a1c62995..eeebdeb49 100644 --- a/app/schemas/org.schabi.newpipe.database.AppDatabase/5.json +++ b/app/schemas/org.schabi.newpipe.database.AppDatabase/5.json @@ -71,6 +71,7 @@ "service_id", "url" ], + "orders": [], "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_subscriptions_service_id_url` ON `${TABLE_NAME}` (`service_id`, `url`)" } ], @@ -78,14 +79,8 @@ }, { "tableName": "search_history", - "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `creation_date` INTEGER, `service_id` INTEGER NOT NULL, `search` TEXT)", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`creation_date` INTEGER, `service_id` INTEGER NOT NULL, `search` TEXT, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)", "fields": [ - { - "fieldPath": "id", - "columnName": "id", - "affinity": "INTEGER", - "notNull": true - }, { "fieldPath": "creationDate", "columnName": "creation_date", @@ -103,6 +98,12 @@ "columnName": "search", "affinity": "TEXT", "notNull": false + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true } ], "primaryKey": { @@ -118,6 +119,7 @@ "columnNames": [ "search" ], + "orders": [], "createSql": "CREATE INDEX IF NOT EXISTS `index_search_history_search` ON `${TABLE_NAME}` (`search`)" } ], @@ -220,6 +222,7 @@ "service_id", "url" ], + "orders": [], "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_streams_service_id_url` ON `${TABLE_NAME}` (`service_id`, `url`)" } ], @@ -262,6 +265,7 @@ "columnNames": [ "stream_id" ], + "orders": [], "createSql": "CREATE INDEX IF NOT EXISTS `index_stream_history_stream_id` ON `${TABLE_NAME}` (`stream_id`)" } ], @@ -353,6 +357,7 @@ "columnNames": [ "name" ], + "orders": [], "createSql": "CREATE INDEX IF NOT EXISTS `index_playlists_name` ON `${TABLE_NAME}` (`name`)" } ], @@ -396,6 +401,7 @@ "playlist_id", "join_index" ], + "orders": [], "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_playlist_stream_join_playlist_id_join_index` ON `${TABLE_NAME}` (`playlist_id`, `join_index`)" }, { @@ -404,6 +410,7 @@ "columnNames": [ "stream_id" ], + "orders": [], "createSql": "CREATE INDEX IF NOT EXISTS `index_playlist_stream_join_stream_id` ON `${TABLE_NAME}` (`stream_id`)" } ], @@ -492,6 +499,7 @@ "columnNames": [ "name" ], + "orders": [], "createSql": "CREATE INDEX IF NOT EXISTS `index_remote_playlists_name` ON `${TABLE_NAME}` (`name`)" }, { @@ -501,6 +509,7 @@ "service_id", "url" ], + "orders": [], "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_remote_playlists_service_id_url` ON `${TABLE_NAME}` (`service_id`, `url`)" } ], @@ -537,6 +546,7 @@ "columnNames": [ "subscription_id" ], + "orders": [], "createSql": "CREATE INDEX IF NOT EXISTS `index_feed_subscription_id` ON `${TABLE_NAME}` (`subscription_id`)" } ], @@ -607,6 +617,7 @@ "columnNames": [ "sort_order" ], + "orders": [], "createSql": "CREATE INDEX IF NOT EXISTS `index_feed_group_sort_order` ON `${TABLE_NAME}` (`sort_order`)" } ], @@ -643,6 +654,7 @@ "columnNames": [ "subscription_id" ], + "orders": [], "createSql": "CREATE INDEX IF NOT EXISTS `index_feed_group_subscription_join_subscription_id` ON `${TABLE_NAME}` (`subscription_id`)" } ], diff --git a/app/src/main/java/org/schabi/newpipe/database/feed/model/FeedGroupEntity.kt b/app/src/main/java/org/schabi/newpipe/database/feed/model/FeedGroupEntity.kt index 1dd26946a..c7415ace0 100644 --- a/app/src/main/java/org/schabi/newpipe/database/feed/model/FeedGroupEntity.kt +++ b/app/src/main/java/org/schabi/newpipe/database/feed/model/FeedGroupEntity.kt @@ -24,7 +24,7 @@ data class FeedGroupEntity( var icon: FeedGroupIcon, @ColumnInfo(name = SORT_ORDER) - var sortOrder: Long = -1 + var sortOrder: Long = -1, ) { companion object { const val FEED_GROUP_TABLE = "feed_group" diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt index bf4941e8e..659187ffa 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt @@ -20,6 +20,7 @@ import androidx.annotation.StringRes import androidx.appcompat.app.AlertDialog import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.GridLayoutManager +import androidx.recyclerview.widget.RecyclerView import com.xwray.groupie.Group import com.xwray.groupie.GroupAdapter import com.xwray.groupie.Item @@ -45,6 +46,7 @@ import org.schabi.newpipe.local.subscription.item.ChannelItem import org.schabi.newpipe.local.subscription.item.EmptyPlaceholderItem import org.schabi.newpipe.local.subscription.item.FeedGroupAddItem import org.schabi.newpipe.local.subscription.item.FeedGroupCardItem +import org.schabi.newpipe.local.subscription.item.FeedGroupCardVerticalItem import org.schabi.newpipe.local.subscription.item.FeedGroupCarouselItem import org.schabi.newpipe.local.subscription.item.HeaderWithMenuItem import org.schabi.newpipe.local.subscription.item.HeaderWithMenuItem.Companion.PAYLOAD_UPDATE_VISIBILITY_MENU_ITEM @@ -76,6 +78,7 @@ class SubscriptionFragment : BaseStateFragment() { private val groupAdapter = GroupAdapter>() private val feedGroupsSection = Section() private var feedGroupsCarousel: FeedGroupCarouselItem? = null + private var feedGroupsCarouselVertical: FeedGroupCarouselItem? = feedGroupsCarousel private lateinit var feedGroupsSortMenuItem: HeaderWithMenuItem private val subscriptionsSection = Section() @@ -92,6 +95,10 @@ class SubscriptionFragment : BaseStateFragment() { @JvmField var feedGroupsListState: Parcelable? = null + @State + @JvmField + var feedGroupsListVerticalState: Parcelable? = null + init { setHasOptionsMenu(true) } @@ -118,6 +125,7 @@ class SubscriptionFragment : BaseStateFragment() { super.onPause() itemsListState = binding.itemsList.layoutManager?.onSaveInstanceState() feedGroupsListState = feedGroupsCarousel?.onSaveInstanceState() + feedGroupsListVerticalState = feedGroupsCarouselVertical?.onSaveInstanceState() } override fun onDestroy() { @@ -221,10 +229,6 @@ class SubscriptionFragment : BaseStateFragment() { FeedGroupReorderDialog().show(parentFragmentManager, null) } - private fun temp() { - println("This button is clicked") - } - private fun requestExportResult(result: ActivityResult) { if (result.data != null && result.resultCode == Activity.RESULT_OK) { activity.startService( @@ -270,16 +274,16 @@ class SubscriptionFragment : BaseStateFragment() { return@setOnItemLongClickListener true } - feedGroupsCarousel = FeedGroupCarouselItem(requireContext(), carouselAdapter) + feedGroupsCarousel = FeedGroupCarouselItem(requireContext(), carouselAdapter, RecyclerView.HORIZONTAL) feedGroupsSortMenuItem = HeaderWithMenuItem( getString(R.string.feed_groups_header_title), R.drawable.ic_list, R.drawable.ic_sort, - listViewOnClickListener = ::temp, + listViewOnClickListener = ::changeLayout, menuItemOnClickListener = ::openReorderDialog ) add(Section(feedGroupsSortMenuItem, listOf(feedGroupsCarousel))) - + groupAdapter.clear() groupAdapter.add(this) } @@ -296,6 +300,62 @@ class SubscriptionFragment : BaseStateFragment() { ) } + private fun changeLayout() { + Section().apply { + val carouselAdapter = GroupAdapter>() + + carouselAdapter.add(FeedGroupCardVerticalItem(-1, getString(R.string.all), FeedGroupIcon.RSS)) + carouselAdapter.add(feedGroupsSection) + carouselAdapter.add(FeedGroupAddItem()) // change this button later + carouselAdapter.setOnItemClickListener { item, _ -> + listenerFeedVerticalGroups.selected(item) + } + carouselAdapter.setOnItemLongClickListener { item, _ -> + if (item is FeedGroupCardVerticalItem) { + if (item.groupId == FeedGroupEntity.GROUP_ALL_ID) { + return@setOnItemLongClickListener false + } + } + listenerFeedVerticalGroups.held(item) + return@setOnItemLongClickListener true + } + + feedGroupsCarouselVertical = FeedGroupCarouselItem(requireContext(), carouselAdapter, RecyclerView.VERTICAL) + feedGroupsSortMenuItem = HeaderWithMenuItem( + getString(R.string.feed_groups_header_title), + R.drawable.ic_apps, + R.drawable.ic_sort, + listViewOnClickListener = ::setupInitialLayout, + menuItemOnClickListener = ::openReorderDialog + ) + add(Section(feedGroupsSortMenuItem, listOf(feedGroupsCarouselVertical))) + groupAdapter.clear() + groupAdapter.add(this) + } + subscriptionsSection.setPlaceholder(EmptyPlaceholderItem()) + subscriptionsSection.setHideWhenEmpty(true) + + groupAdapter.add( + Section( + HeaderWithMenuItem( + getString(R.string.tab_subscriptions) + ), + listOf(subscriptionsSection) + ) + ) + + // TODO: remove this + groupAdapter.spanCount = if (shouldUseGridLayout(context)) getGridSpanCountChannels(context) else 1 + binding.itemsList.layoutManager = GridLayoutManager(requireContext(), groupAdapter.spanCount).apply { + spanSizeLookup = groupAdapter.spanSizeLookup + } + binding.itemsList.adapter = groupAdapter + + viewModel = ViewModelProvider(this).get(SubscriptionViewModel::class.java) + viewModel.stateLiveData.observe(viewLifecycleOwner) { it?.let(this::handleResult) } + viewModel.feedGroupsLiveData.observe(viewLifecycleOwner) { it?.let(this::handleFeedVerticalGroups) } + } + override fun initViews(rootView: View, savedInstanceState: Bundle?) { super.initViews(rootView, savedInstanceState) _binding = FragmentSubscriptionBinding.bind(rootView) @@ -367,6 +427,21 @@ class SubscriptionFragment : BaseStateFragment() { } } + private val listenerFeedVerticalGroups = object : OnClickGesture> { + override fun selected(selectedItem: Item<*>?) { + when (selectedItem) { + is FeedGroupCardVerticalItem -> NavigationHelper.openFeedFragment(fm, selectedItem.groupId, selectedItem.name) + is FeedGroupAddItem -> FeedGroupDialog.newInstance().show(fm, null) + } + } + + override fun held(selectedItem: Item<*>?) { + when (selectedItem) { + is FeedGroupCardVerticalItem -> FeedGroupDialog.newInstance(selectedItem.groupId).show(fm, null) + } + } + } + private val listenerChannelItem = object : OnClickGesture { override fun selected(selectedItem: ChannelInfoItem) = NavigationHelper.openChannelFragment( fm, @@ -420,6 +495,18 @@ class SubscriptionFragment : BaseStateFragment() { binding.itemsList.post { feedGroupsSortMenuItem.notifyChanged(PAYLOAD_UPDATE_VISIBILITY_MENU_ITEM) } } + private fun handleFeedVerticalGroups(groups: List) { + feedGroupsSection.update(groups) + + if (feedGroupsListState != null) { + feedGroupsCarouselVertical?.onRestoreInstanceState(feedGroupsListVerticalState) + feedGroupsListVerticalState = null + } + + feedGroupsSortMenuItem.showMenuItem = groups.size > 1 + binding.itemsList.post { feedGroupsSortMenuItem.notifyChanged(PAYLOAD_UPDATE_VISIBILITY_MENU_ITEM) } + } + // ///////////////////////////////////////////////////////////////////////// // Contract // ///////////////////////////////////////////////////////////////////////// diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCardItem.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCardItem.kt index fd8a75da1..a4fa84798 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCardItem.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCardItem.kt @@ -10,7 +10,7 @@ import org.schabi.newpipe.local.subscription.FeedGroupIcon data class FeedGroupCardItem( val groupId: Long = FeedGroupEntity.GROUP_ALL_ID, val name: String, - val icon: FeedGroupIcon + val icon: FeedGroupIcon, ) : BindableItem() { constructor (feedGroupEntity: FeedGroupEntity) : this(feedGroupEntity.uid, feedGroupEntity.name, feedGroupEntity.icon) @@ -21,7 +21,7 @@ data class FeedGroupCardItem( } } - override fun getLayout(): Int = R.layout.feed_group_list_item + override fun getLayout(): Int = R.layout.feed_group_card_item override fun bind(viewBinding: FeedGroupCardItemBinding, position: Int) { viewBinding.title.text = name diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCardVerticalItem.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCardVerticalItem.kt new file mode 100644 index 000000000..9750da7b4 --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCardVerticalItem.kt @@ -0,0 +1,32 @@ +package org.schabi.newpipe.local.subscription.item + +import android.view.View +import com.xwray.groupie.viewbinding.BindableItem +import org.schabi.newpipe.R +import org.schabi.newpipe.database.feed.model.FeedGroupEntity +import org.schabi.newpipe.databinding.FeedGroupCardVerticalItemBinding +import org.schabi.newpipe.local.subscription.FeedGroupIcon + +data class FeedGroupCardVerticalItem( + val groupId: Long = FeedGroupEntity.GROUP_ALL_ID, + val name: String, + val icon: FeedGroupIcon +) : BindableItem() { + constructor (feedGroupEntity: FeedGroupEntity) : this(feedGroupEntity.uid, feedGroupEntity.name, feedGroupEntity.icon) + + override fun getId(): Long { + return when (groupId) { + FeedGroupEntity.GROUP_ALL_ID -> super.getId() + else -> groupId + } + } + + override fun getLayout(): Int = R.layout.feed_group_card_vertical_item + + override fun bind(viewBinding: FeedGroupCardVerticalItemBinding, position: Int) { + viewBinding.title.text = name + viewBinding.icon.setImageResource(icon.getDrawableRes()) + } + + override fun initializeViewBinding(view: View) = FeedGroupCardVerticalItemBinding.bind(view) +} diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCarouselItem.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCarouselItem.kt index 031eb9b18..a574fa01b 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCarouselItem.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCarouselItem.kt @@ -4,7 +4,6 @@ import android.content.Context import android.os.Parcelable import android.view.View import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView import com.xwray.groupie.GroupAdapter import com.xwray.groupie.viewbinding.BindableItem import com.xwray.groupie.viewbinding.GroupieViewHolder @@ -14,7 +13,8 @@ import org.schabi.newpipe.local.subscription.decoration.FeedGroupCarouselDecorat class FeedGroupCarouselItem( context: Context, - private val carouselAdapter: GroupAdapter> + private val carouselAdapter: GroupAdapter>, + private var listView: Int ) : BindableItem() { private val feedGroupCarouselDecoration = FeedGroupCarouselDecoration(context) @@ -36,7 +36,7 @@ class FeedGroupCarouselItem( override fun initializeViewBinding(view: View): FeedItemCarouselBinding { val viewHolder = FeedItemCarouselBinding.bind(view) - linearLayoutManager = LinearLayoutManager(view.context, RecyclerView.VERTICAL, false) + linearLayoutManager = LinearLayoutManager(view.context, listView, false) viewHolder.recyclerView.apply { layoutManager = linearLayoutManager diff --git a/app/src/main/res/layout/feed_group_list_item.xml b/app/src/main/res/layout/feed_group_card_vertical_item.xml similarity index 92% rename from app/src/main/res/layout/feed_group_list_item.xml rename to app/src/main/res/layout/feed_group_card_vertical_item.xml index c49da1eab..aadfc95a8 100644 --- a/app/src/main/res/layout/feed_group_list_item.xml +++ b/app/src/main/res/layout/feed_group_card_vertical_item.xml @@ -2,7 +2,7 @@ + From 3bfcb16f9a5929ef5ace7d34960cfe22a372bc90 Mon Sep 17 00:00:00 2001 From: Samuel Wu Date: Tue, 25 Oct 2022 00:32:21 +1100 Subject: [PATCH 09/35] Bug: SubscriptionViewModel.kt did not map values for FeedGroupCardVerticalItem in line 26 --- .../subscription/SubscriptionFragment.kt | 45 +++++-------------- 1 file changed, 12 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt index 659187ffa..eafa9f62c 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt @@ -78,7 +78,6 @@ class SubscriptionFragment : BaseStateFragment() { private val groupAdapter = GroupAdapter>() private val feedGroupsSection = Section() private var feedGroupsCarousel: FeedGroupCarouselItem? = null - private var feedGroupsCarouselVertical: FeedGroupCarouselItem? = feedGroupsCarousel private lateinit var feedGroupsSortMenuItem: HeaderWithMenuItem private val subscriptionsSection = Section() @@ -125,7 +124,6 @@ class SubscriptionFragment : BaseStateFragment() { super.onPause() itemsListState = binding.itemsList.layoutManager?.onSaveInstanceState() feedGroupsListState = feedGroupsCarousel?.onSaveInstanceState() - feedGroupsListVerticalState = feedGroupsCarouselVertical?.onSaveInstanceState() } override fun onDestroy() { @@ -275,6 +273,7 @@ class SubscriptionFragment : BaseStateFragment() { } feedGroupsCarousel = FeedGroupCarouselItem(requireContext(), carouselAdapter, RecyclerView.HORIZONTAL) + feedGroupsSortMenuItem = HeaderWithMenuItem( getString(R.string.feed_groups_header_title), R.drawable.ic_list, @@ -282,6 +281,7 @@ class SubscriptionFragment : BaseStateFragment() { listViewOnClickListener = ::changeLayout, menuItemOnClickListener = ::openReorderDialog ) + add(Section(feedGroupsSortMenuItem, listOf(feedGroupsCarousel))) groupAdapter.clear() groupAdapter.add(this) @@ -302,15 +302,16 @@ class SubscriptionFragment : BaseStateFragment() { private fun changeLayout() { Section().apply { - val carouselAdapter = GroupAdapter>() + val carouselAdapter2 = GroupAdapter>() - carouselAdapter.add(FeedGroupCardVerticalItem(-1, getString(R.string.all), FeedGroupIcon.RSS)) - carouselAdapter.add(feedGroupsSection) - carouselAdapter.add(FeedGroupAddItem()) // change this button later - carouselAdapter.setOnItemClickListener { item, _ -> + carouselAdapter2.add(FeedGroupCardVerticalItem(-1, getString(R.string.all), FeedGroupIcon.RSS)) + carouselAdapter2.add(feedGroupsSection) + carouselAdapter2.add(FeedGroupAddItem()) + + carouselAdapter2.setOnItemClickListener { item, _ -> listenerFeedVerticalGroups.selected(item) } - carouselAdapter.setOnItemLongClickListener { item, _ -> + carouselAdapter2.setOnItemLongClickListener { item, _ -> if (item is FeedGroupCardVerticalItem) { if (item.groupId == FeedGroupEntity.GROUP_ALL_ID) { return@setOnItemLongClickListener false @@ -319,8 +320,8 @@ class SubscriptionFragment : BaseStateFragment() { listenerFeedVerticalGroups.held(item) return@setOnItemLongClickListener true } + feedGroupsCarousel = FeedGroupCarouselItem(requireContext(), carouselAdapter2, RecyclerView.VERTICAL) - feedGroupsCarouselVertical = FeedGroupCarouselItem(requireContext(), carouselAdapter, RecyclerView.VERTICAL) feedGroupsSortMenuItem = HeaderWithMenuItem( getString(R.string.feed_groups_header_title), R.drawable.ic_apps, @@ -328,7 +329,7 @@ class SubscriptionFragment : BaseStateFragment() { listViewOnClickListener = ::setupInitialLayout, menuItemOnClickListener = ::openReorderDialog ) - add(Section(feedGroupsSortMenuItem, listOf(feedGroupsCarouselVertical))) + add(Section(feedGroupsSortMenuItem, listOf(feedGroupsCarousel))) groupAdapter.clear() groupAdapter.add(this) } @@ -343,17 +344,6 @@ class SubscriptionFragment : BaseStateFragment() { listOf(subscriptionsSection) ) ) - - // TODO: remove this - groupAdapter.spanCount = if (shouldUseGridLayout(context)) getGridSpanCountChannels(context) else 1 - binding.itemsList.layoutManager = GridLayoutManager(requireContext(), groupAdapter.spanCount).apply { - spanSizeLookup = groupAdapter.spanSizeLookup - } - binding.itemsList.adapter = groupAdapter - - viewModel = ViewModelProvider(this).get(SubscriptionViewModel::class.java) - viewModel.stateLiveData.observe(viewLifecycleOwner) { it?.let(this::handleResult) } - viewModel.feedGroupsLiveData.observe(viewLifecycleOwner) { it?.let(this::handleFeedVerticalGroups) } } override fun initViews(rootView: View, savedInstanceState: Bundle?) { @@ -366,6 +356,7 @@ class SubscriptionFragment : BaseStateFragment() { } binding.itemsList.adapter = groupAdapter + //TODO: change viewModel or create another one viewModel = ViewModelProvider(this).get(SubscriptionViewModel::class.java) viewModel.stateLiveData.observe(viewLifecycleOwner) { it?.let(this::handleResult) } viewModel.feedGroupsLiveData.observe(viewLifecycleOwner) { it?.let(this::handleFeedGroups) } @@ -495,18 +486,6 @@ class SubscriptionFragment : BaseStateFragment() { binding.itemsList.post { feedGroupsSortMenuItem.notifyChanged(PAYLOAD_UPDATE_VISIBILITY_MENU_ITEM) } } - private fun handleFeedVerticalGroups(groups: List) { - feedGroupsSection.update(groups) - - if (feedGroupsListState != null) { - feedGroupsCarouselVertical?.onRestoreInstanceState(feedGroupsListVerticalState) - feedGroupsListVerticalState = null - } - - feedGroupsSortMenuItem.showMenuItem = groups.size > 1 - binding.itemsList.post { feedGroupsSortMenuItem.notifyChanged(PAYLOAD_UPDATE_VISIBILITY_MENU_ITEM) } - } - // ///////////////////////////////////////////////////////////////////////// // Contract // ///////////////////////////////////////////////////////////////////////// From 1aa1a0287e47ddddaf19bcdcafcb9c3e3f3ecc8b Mon Sep 17 00:00:00 2001 From: Samuel Wu Date: Tue, 25 Oct 2022 02:01:57 +1100 Subject: [PATCH 10/35] Could toggle between list view and grid view...once. Requires bug fixing on refreshing --- .../local/subscription/SubscriptionFragment.kt | 15 ++++++++++++++- .../local/subscription/SubscriptionViewModel.kt | 13 +++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt index eafa9f62c..d282e58c1 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt @@ -356,10 +356,11 @@ class SubscriptionFragment : BaseStateFragment() { } binding.itemsList.adapter = groupAdapter - //TODO: change viewModel or create another one + // TODO: change viewModel or create another one viewModel = ViewModelProvider(this).get(SubscriptionViewModel::class.java) viewModel.stateLiveData.observe(viewLifecycleOwner) { it?.let(this::handleResult) } viewModel.feedGroupsLiveData.observe(viewLifecycleOwner) { it?.let(this::handleFeedGroups) } + viewModel.feedGroupsVerticalLiveData.observe(viewLifecycleOwner) { it?.let(this::handleFeedGroupsVertical) } } private fun showLongTapDialog(selectedItem: ChannelInfoItem) { @@ -486,6 +487,18 @@ class SubscriptionFragment : BaseStateFragment() { binding.itemsList.post { feedGroupsSortMenuItem.notifyChanged(PAYLOAD_UPDATE_VISIBILITY_MENU_ITEM) } } + private fun handleFeedGroupsVertical(groups: List) { + feedGroupsSection.update(groups) + + if (feedGroupsListState != null) { + feedGroupsCarousel?.onRestoreInstanceState(feedGroupsListState) + feedGroupsListVerticalState = null + } + + feedGroupsSortMenuItem.showMenuItem = groups.size > 1 + binding.itemsList.post { feedGroupsSortMenuItem.notifyChanged(PAYLOAD_UPDATE_VISIBILITY_MENU_ITEM) } + } + // ///////////////////////////////////////////////////////////////////////// // Contract // ///////////////////////////////////////////////////////////////////////// diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionViewModel.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionViewModel.kt index da009e1a0..3f378929e 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionViewModel.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionViewModel.kt @@ -9,6 +9,7 @@ import io.reactivex.rxjava3.schedulers.Schedulers import org.schabi.newpipe.local.feed.FeedDatabaseManager import org.schabi.newpipe.local.subscription.item.ChannelItem import org.schabi.newpipe.local.subscription.item.FeedGroupCardItem +import org.schabi.newpipe.local.subscription.item.FeedGroupCardVerticalItem import org.schabi.newpipe.util.DEFAULT_THROTTLE_TIMEOUT import java.util.concurrent.TimeUnit @@ -18,8 +19,10 @@ class SubscriptionViewModel(application: Application) : AndroidViewModel(applica private val mutableStateLiveData = MutableLiveData() private val mutableFeedGroupsLiveData = MutableLiveData>() + private val mutableFeedGroupsVerticalLiveData = MutableLiveData>() val stateLiveData: LiveData = mutableStateLiveData val feedGroupsLiveData: LiveData> = mutableFeedGroupsLiveData + val feedGroupsVerticalLiveData: LiveData> = mutableFeedGroupsVerticalLiveData private var feedGroupItemsDisposable = feedDatabaseManager.groups() .throttleLatest(DEFAULT_THROTTLE_TIMEOUT, TimeUnit.MILLISECONDS) @@ -30,6 +33,15 @@ class SubscriptionViewModel(application: Application) : AndroidViewModel(applica { mutableStateLiveData.postValue(SubscriptionState.ErrorState(it)) } ) + private var feedGroupVerticalItemsDisposable = feedDatabaseManager.groups() + .throttleLatest(DEFAULT_THROTTLE_TIMEOUT, TimeUnit.MILLISECONDS) + .map { it.map(::FeedGroupCardVerticalItem) } + .subscribeOn(Schedulers.io()) + .subscribe( + { mutableFeedGroupsVerticalLiveData.postValue(it) }, + { mutableStateLiveData.postValue(SubscriptionState.ErrorState(it)) } + ) + private var stateItemsDisposable = subscriptionManager.subscriptions() .throttleLatest(DEFAULT_THROTTLE_TIMEOUT, TimeUnit.MILLISECONDS) .map { it.map { entity -> ChannelItem(entity.toChannelInfoItem(), entity.uid, ChannelItem.ItemVersion.MINI) } } @@ -43,6 +55,7 @@ class SubscriptionViewModel(application: Application) : AndroidViewModel(applica super.onCleared() stateItemsDisposable.dispose() feedGroupItemsDisposable.dispose() + feedGroupVerticalItemsDisposable.dispose() } sealed class SubscriptionState { From 6eddaa0d38d4c49136f3e3572e9555364884a209 Mon Sep 17 00:00:00 2001 From: Samuel Wu Date: Tue, 25 Oct 2022 02:20:14 +1100 Subject: [PATCH 11/35] Added boolean to handle feed groups. May need a better solution for this --- .../subscription/SubscriptionFragment.kt | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt index d282e58c1..667243c83 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt @@ -80,6 +80,7 @@ class SubscriptionFragment : BaseStateFragment() { private var feedGroupsCarousel: FeedGroupCarouselItem? = null private lateinit var feedGroupsSortMenuItem: HeaderWithMenuItem private val subscriptionsSection = Section() + private var listView: Boolean = false private val requestExportLauncher = registerForActivityResult(StartActivityForResult(), this::requestExportResult) @@ -124,6 +125,7 @@ class SubscriptionFragment : BaseStateFragment() { super.onPause() itemsListState = binding.itemsList.layoutManager?.onSaveInstanceState() feedGroupsListState = feedGroupsCarousel?.onSaveInstanceState() + feedGroupsListVerticalState = feedGroupsCarousel?.onSaveInstanceState() } override fun onDestroy() { @@ -252,6 +254,7 @@ class SubscriptionFragment : BaseStateFragment() { // //////////////////////////////////////////////////////////////////////// private fun setupInitialLayout() { + listView = false Section().apply { val carouselAdapter = GroupAdapter>() @@ -301,6 +304,7 @@ class SubscriptionFragment : BaseStateFragment() { } private fun changeLayout() { + listView = true Section().apply { val carouselAdapter2 = GroupAdapter>() @@ -476,27 +480,31 @@ class SubscriptionFragment : BaseStateFragment() { } private fun handleFeedGroups(groups: List) { - feedGroupsSection.update(groups) + if (!listView) { + feedGroupsSection.update(groups) - if (feedGroupsListState != null) { - feedGroupsCarousel?.onRestoreInstanceState(feedGroupsListState) - feedGroupsListState = null + if (feedGroupsListState != null) { + feedGroupsCarousel?.onRestoreInstanceState(feedGroupsListState) + feedGroupsListState = null + } + + feedGroupsSortMenuItem.showMenuItem = groups.size > 1 + binding.itemsList.post { feedGroupsSortMenuItem.notifyChanged(PAYLOAD_UPDATE_VISIBILITY_MENU_ITEM) } } - - feedGroupsSortMenuItem.showMenuItem = groups.size > 1 - binding.itemsList.post { feedGroupsSortMenuItem.notifyChanged(PAYLOAD_UPDATE_VISIBILITY_MENU_ITEM) } } private fun handleFeedGroupsVertical(groups: List) { - feedGroupsSection.update(groups) + if (listView) { + feedGroupsSection.update(groups) - if (feedGroupsListState != null) { - feedGroupsCarousel?.onRestoreInstanceState(feedGroupsListState) - feedGroupsListVerticalState = null + if (feedGroupsListVerticalState != null) { + feedGroupsCarousel?.onRestoreInstanceState(feedGroupsListVerticalState) + feedGroupsListVerticalState = null + } + + feedGroupsSortMenuItem.showMenuItem = groups.size > 1 + binding.itemsList.post { feedGroupsSortMenuItem.notifyChanged(PAYLOAD_UPDATE_VISIBILITY_MENU_ITEM) } } - - feedGroupsSortMenuItem.showMenuItem = groups.size > 1 - binding.itemsList.post { feedGroupsSortMenuItem.notifyChanged(PAYLOAD_UPDATE_VISIBILITY_MENU_ITEM) } } // ///////////////////////////////////////////////////////////////////////// From 082d7a3f187c46ab5a69412701934e2b2247f782 Mon Sep 17 00:00:00 2001 From: Samuel Wu Date: Tue, 25 Oct 2022 02:38:31 +1100 Subject: [PATCH 12/35] Added working binding for a "new" button that works in the list layout. --- .../subscription/SubscriptionFragment.kt | 18 ++++---- .../item/FeedGroupAddItemVertical.kt | 12 +++++ .../feed_group_add_new_item_vertical.xml | 45 +++++++++++++++++++ 3 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupAddItemVertical.kt create mode 100644 app/src/main/res/layout/feed_group_add_new_item_vertical.xml diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt index 667243c83..84e63554f 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt @@ -45,6 +45,7 @@ import org.schabi.newpipe.local.subscription.dialog.FeedGroupReorderDialog import org.schabi.newpipe.local.subscription.item.ChannelItem import org.schabi.newpipe.local.subscription.item.EmptyPlaceholderItem import org.schabi.newpipe.local.subscription.item.FeedGroupAddItem +import org.schabi.newpipe.local.subscription.item.FeedGroupAddItemVertical import org.schabi.newpipe.local.subscription.item.FeedGroupCardItem import org.schabi.newpipe.local.subscription.item.FeedGroupCardVerticalItem import org.schabi.newpipe.local.subscription.item.FeedGroupCarouselItem @@ -306,16 +307,16 @@ class SubscriptionFragment : BaseStateFragment() { private fun changeLayout() { listView = true Section().apply { - val carouselAdapter2 = GroupAdapter>() + val carouselAdapter = GroupAdapter>() - carouselAdapter2.add(FeedGroupCardVerticalItem(-1, getString(R.string.all), FeedGroupIcon.RSS)) - carouselAdapter2.add(feedGroupsSection) - carouselAdapter2.add(FeedGroupAddItem()) + carouselAdapter.add(FeedGroupCardVerticalItem(-1, getString(R.string.all), FeedGroupIcon.RSS)) + carouselAdapter.add(feedGroupsSection) + carouselAdapter.add(FeedGroupAddItemVertical()) - carouselAdapter2.setOnItemClickListener { item, _ -> + carouselAdapter.setOnItemClickListener { item, _ -> listenerFeedVerticalGroups.selected(item) } - carouselAdapter2.setOnItemLongClickListener { item, _ -> + carouselAdapter.setOnItemLongClickListener { item, _ -> if (item is FeedGroupCardVerticalItem) { if (item.groupId == FeedGroupEntity.GROUP_ALL_ID) { return@setOnItemLongClickListener false @@ -324,7 +325,7 @@ class SubscriptionFragment : BaseStateFragment() { listenerFeedVerticalGroups.held(item) return@setOnItemLongClickListener true } - feedGroupsCarousel = FeedGroupCarouselItem(requireContext(), carouselAdapter2, RecyclerView.VERTICAL) + feedGroupsCarousel = FeedGroupCarouselItem(requireContext(), carouselAdapter, RecyclerView.VERTICAL) feedGroupsSortMenuItem = HeaderWithMenuItem( getString(R.string.feed_groups_header_title), @@ -360,7 +361,6 @@ class SubscriptionFragment : BaseStateFragment() { } binding.itemsList.adapter = groupAdapter - // TODO: change viewModel or create another one viewModel = ViewModelProvider(this).get(SubscriptionViewModel::class.java) viewModel.stateLiveData.observe(viewLifecycleOwner) { it?.let(this::handleResult) } viewModel.feedGroupsLiveData.observe(viewLifecycleOwner) { it?.let(this::handleFeedGroups) } @@ -427,7 +427,7 @@ class SubscriptionFragment : BaseStateFragment() { override fun selected(selectedItem: Item<*>?) { when (selectedItem) { is FeedGroupCardVerticalItem -> NavigationHelper.openFeedFragment(fm, selectedItem.groupId, selectedItem.name) - is FeedGroupAddItem -> FeedGroupDialog.newInstance().show(fm, null) + is FeedGroupAddItemVertical -> FeedGroupDialog.newInstance().show(fm, null) } } diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupAddItemVertical.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupAddItemVertical.kt new file mode 100644 index 000000000..deb126219 --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupAddItemVertical.kt @@ -0,0 +1,12 @@ +package org.schabi.newpipe.local.subscription.item + +import android.view.View +import com.xwray.groupie.viewbinding.BindableItem +import org.schabi.newpipe.R +import org.schabi.newpipe.databinding.FeedGroupAddNewItemVerticalBinding + +class FeedGroupAddItemVertical : BindableItem() { + override fun getLayout(): Int = R.layout.feed_group_add_new_item_vertical + override fun bind(viewBinding: FeedGroupAddNewItemVerticalBinding, position: Int) {} + override fun initializeViewBinding(view: View) = FeedGroupAddNewItemVerticalBinding.bind(view) +} diff --git a/app/src/main/res/layout/feed_group_add_new_item_vertical.xml b/app/src/main/res/layout/feed_group_add_new_item_vertical.xml new file mode 100644 index 000000000..43427f291 --- /dev/null +++ b/app/src/main/res/layout/feed_group_add_new_item_vertical.xml @@ -0,0 +1,45 @@ + + + + + + + + + + From ed68e3bd46dafbc36952f22b776d50de5076b238 Mon Sep 17 00:00:00 2001 From: Samuel Wu Date: Tue, 25 Oct 2022 10:54:27 +1100 Subject: [PATCH 13/35] Fully working toggle button that change between vertical and horizontal view --- .../subscription/SubscriptionFragment.kt | 30 +++++++++++-------- ...ertical.kt => FeedGroupAddVerticalItem.kt} | 2 +- 2 files changed, 18 insertions(+), 14 deletions(-) rename app/src/main/java/org/schabi/newpipe/local/subscription/item/{FeedGroupAddItemVertical.kt => FeedGroupAddVerticalItem.kt} (89%) diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt index 84e63554f..89d394a4a 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt @@ -45,7 +45,7 @@ import org.schabi.newpipe.local.subscription.dialog.FeedGroupReorderDialog import org.schabi.newpipe.local.subscription.item.ChannelItem import org.schabi.newpipe.local.subscription.item.EmptyPlaceholderItem import org.schabi.newpipe.local.subscription.item.FeedGroupAddItem -import org.schabi.newpipe.local.subscription.item.FeedGroupAddItemVertical +import org.schabi.newpipe.local.subscription.item.FeedGroupAddVerticalItem import org.schabi.newpipe.local.subscription.item.FeedGroupCardItem import org.schabi.newpipe.local.subscription.item.FeedGroupCardVerticalItem import org.schabi.newpipe.local.subscription.item.FeedGroupCarouselItem @@ -78,10 +78,12 @@ class SubscriptionFragment : BaseStateFragment() { private val groupAdapter = GroupAdapter>() private val feedGroupsSection = Section() + private val feedGroupsVerticalSection = Section() private var feedGroupsCarousel: FeedGroupCarouselItem? = null + private var feedGroupsVerticalCarousel: FeedGroupCarouselItem? = null private lateinit var feedGroupsSortMenuItem: HeaderWithMenuItem private val subscriptionsSection = Section() - private var listView: Boolean = false + private var defaultListView: Boolean = true private val requestExportLauncher = registerForActivityResult(StartActivityForResult(), this::requestExportResult) @@ -255,7 +257,7 @@ class SubscriptionFragment : BaseStateFragment() { // //////////////////////////////////////////////////////////////////////// private fun setupInitialLayout() { - listView = false + defaultListView = true Section().apply { val carouselAdapter = GroupAdapter>() @@ -302,16 +304,17 @@ class SubscriptionFragment : BaseStateFragment() { listOf(subscriptionsSection) ) ) + view?.let { initViews(it, savedInstanceState = Bundle()) } } private fun changeLayout() { - listView = true + defaultListView = false Section().apply { val carouselAdapter = GroupAdapter>() carouselAdapter.add(FeedGroupCardVerticalItem(-1, getString(R.string.all), FeedGroupIcon.RSS)) - carouselAdapter.add(feedGroupsSection) - carouselAdapter.add(FeedGroupAddItemVertical()) + carouselAdapter.add(feedGroupsVerticalSection) + carouselAdapter.add(FeedGroupAddVerticalItem()) carouselAdapter.setOnItemClickListener { item, _ -> listenerFeedVerticalGroups.selected(item) @@ -325,7 +328,7 @@ class SubscriptionFragment : BaseStateFragment() { listenerFeedVerticalGroups.held(item) return@setOnItemLongClickListener true } - feedGroupsCarousel = FeedGroupCarouselItem(requireContext(), carouselAdapter, RecyclerView.VERTICAL) + feedGroupsVerticalCarousel = FeedGroupCarouselItem(requireContext(), carouselAdapter, RecyclerView.VERTICAL) feedGroupsSortMenuItem = HeaderWithMenuItem( getString(R.string.feed_groups_header_title), @@ -334,7 +337,7 @@ class SubscriptionFragment : BaseStateFragment() { listViewOnClickListener = ::setupInitialLayout, menuItemOnClickListener = ::openReorderDialog ) - add(Section(feedGroupsSortMenuItem, listOf(feedGroupsCarousel))) + add(Section(feedGroupsSortMenuItem, listOf(feedGroupsVerticalCarousel))) groupAdapter.clear() groupAdapter.add(this) } @@ -349,6 +352,7 @@ class SubscriptionFragment : BaseStateFragment() { listOf(subscriptionsSection) ) ) + view?.let { initViews(it, savedInstanceState = Bundle()) } } override fun initViews(rootView: View, savedInstanceState: Bundle?) { @@ -427,7 +431,7 @@ class SubscriptionFragment : BaseStateFragment() { override fun selected(selectedItem: Item<*>?) { when (selectedItem) { is FeedGroupCardVerticalItem -> NavigationHelper.openFeedFragment(fm, selectedItem.groupId, selectedItem.name) - is FeedGroupAddItemVertical -> FeedGroupDialog.newInstance().show(fm, null) + is FeedGroupAddVerticalItem -> FeedGroupDialog.newInstance().show(fm, null) } } @@ -480,7 +484,7 @@ class SubscriptionFragment : BaseStateFragment() { } private fun handleFeedGroups(groups: List) { - if (!listView) { + if (defaultListView) { feedGroupsSection.update(groups) if (feedGroupsListState != null) { @@ -494,11 +498,11 @@ class SubscriptionFragment : BaseStateFragment() { } private fun handleFeedGroupsVertical(groups: List) { - if (listView) { - feedGroupsSection.update(groups) + if (!defaultListView) { + feedGroupsVerticalSection.update(groups) if (feedGroupsListVerticalState != null) { - feedGroupsCarousel?.onRestoreInstanceState(feedGroupsListVerticalState) + feedGroupsVerticalCarousel?.onRestoreInstanceState(feedGroupsListVerticalState) feedGroupsListVerticalState = null } diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupAddItemVertical.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupAddVerticalItem.kt similarity index 89% rename from app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupAddItemVertical.kt rename to app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupAddVerticalItem.kt index deb126219..eae8bd5f2 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupAddItemVertical.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupAddVerticalItem.kt @@ -5,7 +5,7 @@ import com.xwray.groupie.viewbinding.BindableItem import org.schabi.newpipe.R import org.schabi.newpipe.databinding.FeedGroupAddNewItemVerticalBinding -class FeedGroupAddItemVertical : BindableItem() { +class FeedGroupAddVerticalItem : BindableItem() { override fun getLayout(): Int = R.layout.feed_group_add_new_item_vertical override fun bind(viewBinding: FeedGroupAddNewItemVerticalBinding, position: Int) {} override fun initializeViewBinding(view: View) = FeedGroupAddNewItemVerticalBinding.bind(view) From 28464344c14425ebfdc80c653c48a8a4380f6dfe Mon Sep 17 00:00:00 2001 From: Samuel Wu Date: Tue, 25 Oct 2022 11:43:25 +1100 Subject: [PATCH 14/35] Finalized design for vertical card view and removed unneeded variables in SubscriptionFragment.kt --- .../local/subscription/SubscriptionFragment.kt | 16 +++++++--------- .../item/FeedGroupAddVerticalItem.kt | 10 +++++----- ....xml => feed_group_add_new_vertical_item.xml} | 0 .../res/layout/feed_group_card_vertical_item.xml | 13 +++++++------ app/src/main/res/values/dimens.xml | 2 +- 5 files changed, 20 insertions(+), 21 deletions(-) rename app/src/main/res/layout/{feed_group_add_new_item_vertical.xml => feed_group_add_new_vertical_item.xml} (100%) diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt index 89d394a4a..348dd5897 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt @@ -78,9 +78,7 @@ class SubscriptionFragment : BaseStateFragment() { private val groupAdapter = GroupAdapter>() private val feedGroupsSection = Section() - private val feedGroupsVerticalSection = Section() private var feedGroupsCarousel: FeedGroupCarouselItem? = null - private var feedGroupsVerticalCarousel: FeedGroupCarouselItem? = null private lateinit var feedGroupsSortMenuItem: HeaderWithMenuItem private val subscriptionsSection = Section() private var defaultListView: Boolean = true @@ -284,7 +282,7 @@ class SubscriptionFragment : BaseStateFragment() { getString(R.string.feed_groups_header_title), R.drawable.ic_list, R.drawable.ic_sort, - listViewOnClickListener = ::changeLayout, + listViewOnClickListener = ::changeVerticalLayout, menuItemOnClickListener = ::openReorderDialog ) @@ -307,13 +305,13 @@ class SubscriptionFragment : BaseStateFragment() { view?.let { initViews(it, savedInstanceState = Bundle()) } } - private fun changeLayout() { + private fun changeVerticalLayout() { defaultListView = false Section().apply { val carouselAdapter = GroupAdapter>() carouselAdapter.add(FeedGroupCardVerticalItem(-1, getString(R.string.all), FeedGroupIcon.RSS)) - carouselAdapter.add(feedGroupsVerticalSection) + carouselAdapter.add(feedGroupsSection) carouselAdapter.add(FeedGroupAddVerticalItem()) carouselAdapter.setOnItemClickListener { item, _ -> @@ -328,7 +326,7 @@ class SubscriptionFragment : BaseStateFragment() { listenerFeedVerticalGroups.held(item) return@setOnItemLongClickListener true } - feedGroupsVerticalCarousel = FeedGroupCarouselItem(requireContext(), carouselAdapter, RecyclerView.VERTICAL) + feedGroupsCarousel = FeedGroupCarouselItem(requireContext(), carouselAdapter, RecyclerView.VERTICAL) feedGroupsSortMenuItem = HeaderWithMenuItem( getString(R.string.feed_groups_header_title), @@ -337,7 +335,7 @@ class SubscriptionFragment : BaseStateFragment() { listViewOnClickListener = ::setupInitialLayout, menuItemOnClickListener = ::openReorderDialog ) - add(Section(feedGroupsSortMenuItem, listOf(feedGroupsVerticalCarousel))) + add(Section(feedGroupsSortMenuItem, listOf(feedGroupsCarousel))) groupAdapter.clear() groupAdapter.add(this) } @@ -499,10 +497,10 @@ class SubscriptionFragment : BaseStateFragment() { private fun handleFeedGroupsVertical(groups: List) { if (!defaultListView) { - feedGroupsVerticalSection.update(groups) + feedGroupsSection.update(groups) if (feedGroupsListVerticalState != null) { - feedGroupsVerticalCarousel?.onRestoreInstanceState(feedGroupsListVerticalState) + feedGroupsCarousel?.onRestoreInstanceState(feedGroupsListVerticalState) feedGroupsListVerticalState = null } diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupAddVerticalItem.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupAddVerticalItem.kt index eae8bd5f2..049728591 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupAddVerticalItem.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupAddVerticalItem.kt @@ -3,10 +3,10 @@ package org.schabi.newpipe.local.subscription.item import android.view.View import com.xwray.groupie.viewbinding.BindableItem import org.schabi.newpipe.R -import org.schabi.newpipe.databinding.FeedGroupAddNewItemVerticalBinding +import org.schabi.newpipe.databinding.FeedGroupAddNewVerticalItemBinding -class FeedGroupAddVerticalItem : BindableItem() { - override fun getLayout(): Int = R.layout.feed_group_add_new_item_vertical - override fun bind(viewBinding: FeedGroupAddNewItemVerticalBinding, position: Int) {} - override fun initializeViewBinding(view: View) = FeedGroupAddNewItemVerticalBinding.bind(view) +class FeedGroupAddVerticalItem : BindableItem() { + override fun getLayout(): Int = R.layout.feed_group_add_new_vertical_item + override fun bind(viewBinding: FeedGroupAddNewVerticalItemBinding, position: Int) {} + override fun initializeViewBinding(view: View) = FeedGroupAddNewVerticalItemBinding.bind(view) } diff --git a/app/src/main/res/layout/feed_group_add_new_item_vertical.xml b/app/src/main/res/layout/feed_group_add_new_vertical_item.xml similarity index 100% rename from app/src/main/res/layout/feed_group_add_new_item_vertical.xml rename to app/src/main/res/layout/feed_group_add_new_vertical_item.xml diff --git a/app/src/main/res/layout/feed_group_card_vertical_item.xml b/app/src/main/res/layout/feed_group_card_vertical_item.xml index aadfc95a8..2924483c2 100644 --- a/app/src/main/res/layout/feed_group_card_vertical_item.xml +++ b/app/src/main/res/layout/feed_group_card_vertical_item.xml @@ -17,10 +17,10 @@ diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 419b3ca43..86bf9da5b 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -125,7 +125,7 @@ 12dp - 2dp + 4dp 4dp 16sp From c607089cbb7f2345594115875968f4bbff912cc5 Mon Sep 17 00:00:00 2001 From: Samuel Wu Date: Wed, 26 Oct 2022 00:06:48 +1100 Subject: [PATCH 15/35] Altered grid view similar to Youtube app layout --- .../local/subscription/item/FeedGroupCarouselItem.kt | 3 ++- app/src/main/res/layout/feed_group_card_item.xml | 10 ++++++---- app/src/main/res/values/dimens.xml | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCarouselItem.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCarouselItem.kt index a574fa01b..01f058913 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCarouselItem.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCarouselItem.kt @@ -3,6 +3,7 @@ package org.schabi.newpipe.local.subscription.item import android.content.Context import android.os.Parcelable import android.view.View +import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import com.xwray.groupie.GroupAdapter import com.xwray.groupie.viewbinding.BindableItem @@ -43,7 +44,7 @@ class FeedGroupCarouselItem( adapter = carouselAdapter addItemDecoration(feedGroupCarouselDecoration) } - + viewHolder.recyclerView.setLayoutManager(GridLayoutManager(view.context, 3)) return viewHolder } diff --git a/app/src/main/res/layout/feed_group_card_item.xml b/app/src/main/res/layout/feed_group_card_item.xml index e57a8167f..5e87216cb 100644 --- a/app/src/main/res/layout/feed_group_card_item.xml +++ b/app/src/main/res/layout/feed_group_card_item.xml @@ -2,9 +2,9 @@ @@ -39,7 +41,7 @@ android:padding="2dp" android:textAllCaps="false" android:textColor="?attr/colorAccent" - android:textSize="10sp" + android:textSize="14sp" android:textStyle="bold" tools:ignore="SmallSp" tools:text="ALL" /> diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 86bf9da5b..ad0e029dd 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -125,7 +125,7 @@ 12dp - 4dp + 12dp 4dp 16sp From 16860603fd77e016f5217a60e4ab86c2eac0eb81 Mon Sep 17 00:00:00 2001 From: Yuuu2990 <110877395+Yuuu2990@users.noreply.github.com> Date: Wed, 26 Oct 2022 18:59:51 +1100 Subject: [PATCH 16/35] Add Link to FAQ in the app (#9164) * Link to FAQ in the app #4447 * remove redundant comments produced by me. * Update app/src/main/res/values/strings.xml Update FAQ description Co-authored-by: opusforlife2 <53176348+opusforlife2@users.noreply.github.com> * Format the CodeStyle and readjust the layout. * Update app/src/main/res/layout/fragment_about.xml Remove redundant id. Co-authored-by: Stypox * Update app/src/main/res/layout/fragment_about.xml Remove redundant id. Co-authored-by: Stypox * Update app/src/main/res/values/strings.xml Keep the uppercase for consistency. Co-authored-by: Stypox * Update app/src/main/res/values/strings.xml Modify the description of FAQ. Co-authored-by: Stypox Co-authored-by: opusforlife2 <53176348+opusforlife2@users.noreply.github.com> Co-authored-by: Stypox --- .../org/schabi/newpipe/about/AboutActivity.kt | 1 + app/src/main/res/layout/fragment_about.xml | 20 +++++++++++++++++++ app/src/main/res/values/donottranslate.xml | 1 + app/src/main/res/values/strings.xml | 5 ++++- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/about/AboutActivity.kt b/app/src/main/java/org/schabi/newpipe/about/AboutActivity.kt index 50a3984e3..c1eec1526 100644 --- a/app/src/main/java/org/schabi/newpipe/about/AboutActivity.kt +++ b/app/src/main/java/org/schabi/newpipe/about/AboutActivity.kt @@ -78,6 +78,7 @@ class AboutActivity : AppCompatActivity() { aboutDonationLink.openLink(R.string.donation_url) aboutWebsiteLink.openLink(R.string.website_url) aboutPrivacyPolicyLink.openLink(R.string.privacy_policy_url) + faqLink.openLink(R.string.faq_url) return root } } diff --git a/app/src/main/res/layout/fragment_about.xml b/app/src/main/res/layout/fragment_about.xml index 1807acb10..5e6e11d00 100644 --- a/app/src/main/res/layout/fragment_about.xml +++ b/app/src/main/res/layout/fragment_about.xml @@ -44,6 +44,26 @@ android:paddingBottom="5dp" android:text="@string/app_description" /> + + + + +