Skip to content

Commit

Permalink
added indicator for selected source
Browse files Browse the repository at this point in the history
  • Loading branch information
AP-Atul committed Dec 20, 2022
1 parent 2b7dfbc commit 22797a8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/src/main/java/org/ranobe/ranobe/config/Ranobe.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package org.ranobe.ranobe.ui.explore.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;

import org.ranobe.ranobe.config.Ranobe;
import org.ranobe.ranobe.databinding.ItemSourceBinding;
import org.ranobe.ranobe.models.DataSource;

Expand All @@ -17,10 +19,12 @@
public class SourceAdapter extends RecyclerView.Adapter<SourceAdapter.MyViewHolder> {
private final List<DataSource> sources;
private final OnSourceSelected listener;
private final int currentSource;

public SourceAdapter(List<DataSource> sources, OnSourceSelected listener) {
this.sources = sources;
this.listener = listener;
this.currentSource = Ranobe.getCurrentSource();
}

@NonNull
Expand All @@ -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(
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/layout/item_source.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@
android:textColor="?colorOnSurfaceVariant"
android:textSize="@dimen/text_small" />

<TextView
android:id="@+id/active"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/currently_active"
android:textStyle="bold"
android:visibility="gone"
android:textColor="?colorTertiary"
android:textSize="@dimen/text_small" />

</LinearLayout>

</LinearLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
<string name="sources">Sources</string>
<string name="no_results_err">we didn\'t find anything for you!</string>
<string name="retry">Retry</string>
<string name="currently_active">Currently active</string>

</resources>

0 comments on commit 22797a8

Please sign in to comment.