From 22797a86b65c264247370582bbdb30f90fd126db Mon Sep 17 00:00:00 2001 From: ap-atul Date: Tue, 20 Dec 2022 18:53:04 +0530 Subject: [PATCH] added indicator for selected source --- app/src/main/java/org/ranobe/ranobe/config/Ranobe.java | 2 +- .../ranobe/ui/explore/adapter/SourceAdapter.java | 8 ++++++++ app/src/main/res/layout/item_source.xml | 10 ++++++++++ app/src/main/res/values/strings.xml | 1 + 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/ranobe/ranobe/config/Ranobe.java b/app/src/main/java/org/ranobe/ranobe/config/Ranobe.java index 271decc..0c50bc1 100644 --- a/app/src/main/java/org/ranobe/ranobe/config/Ranobe.java +++ b/app/src/main/java/org/ranobe/ranobe/config/Ranobe.java @@ -79,6 +79,6 @@ public static void saveCurrentSource(int sourceId) { } public static int getCurrentSource() { - return getSharedPref(App.getContext()).getInt(Ranobe.SETTING_SELECTED_SOURCE, 1); + return getSharedPref(App.getContext()).getInt(Ranobe.SETTING_SELECTED_SOURCE, 3); } } diff --git a/app/src/main/java/org/ranobe/ranobe/ui/explore/adapter/SourceAdapter.java b/app/src/main/java/org/ranobe/ranobe/ui/explore/adapter/SourceAdapter.java index c57852d..f5261f6 100644 --- a/app/src/main/java/org/ranobe/ranobe/ui/explore/adapter/SourceAdapter.java +++ b/app/src/main/java/org/ranobe/ranobe/ui/explore/adapter/SourceAdapter.java @@ -1,6 +1,7 @@ package org.ranobe.ranobe.ui.explore.adapter; import android.view.LayoutInflater; +import android.view.View; import android.view.ViewGroup; import androidx.annotation.NonNull; @@ -8,6 +9,7 @@ import com.bumptech.glide.Glide; +import org.ranobe.ranobe.config.Ranobe; import org.ranobe.ranobe.databinding.ItemSourceBinding; import org.ranobe.ranobe.models.DataSource; @@ -17,10 +19,12 @@ public class SourceAdapter extends RecyclerView.Adapter { private final List sources; private final OnSourceSelected listener; + private final int currentSource; public SourceAdapter(List sources, OnSourceSelected listener) { this.sources = sources; this.listener = listener; + this.currentSource = Ranobe.getCurrentSource(); } @NonNull @@ -34,6 +38,10 @@ public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) public void onBindViewHolder(@NonNull MyViewHolder holder, int position) { DataSource source = sources.get(position); + if (source.sourceId == currentSource) { + holder.binding.active.setVisibility(View.VISIBLE); + } + holder.binding.sourceId.setText(String.valueOf(source.sourceId)); holder.binding.sourceName.setText(source.name); holder.binding.sourceContent.setText(String.format( diff --git a/app/src/main/res/layout/item_source.xml b/app/src/main/res/layout/item_source.xml index b2b99d0..3764b6f 100644 --- a/app/src/main/res/layout/item_source.xml +++ b/app/src/main/res/layout/item_source.xml @@ -58,6 +58,16 @@ android:textColor="?colorOnSurfaceVariant" android:textSize="@dimen/text_small" /> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0941fe1..c3904c8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -22,5 +22,6 @@ Sources we didn\'t find anything for you! Retry + Currently active \ No newline at end of file