Android TV Enhancements: - SectionAdapter.java: New section-based content organization - Enhanced MainActivity with improved section management - Optimized ChannelAdapter for better TV navigation - Modernized activity_main.xml with section layout - Professional color scheme for Android TV - Updated strings for better TV experience New UI Components: - bg_section_indicator.xml: Visual section indicators - item_section.xml: Section-based layout structure - color/**: State-aware colors for TV focus states - Enhanced focus management for D-pad navigation Technical Improvements: - Better memory management with section-based loading - Improved RecyclerView performance - Enhanced visual feedback for TV remote control - Professional color palette optimized for TV screens - Consistent design language throughout app All v8.0 features maintained: - Audio background fix (onStop() lifecycle) - Real-time events with Argentina timezone - Alphabetical channel sorting - DNS bypass for global access - Tab navigation (Channels/Events) - Complete Android TV optimization 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
89 lines
2.5 KiB
Java
89 lines
2.5 KiB
Java
package com.streamplayer;
|
|
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.TextView;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import java.util.List;
|
|
|
|
public class SectionAdapter extends RecyclerView.Adapter<SectionAdapter.SectionViewHolder> {
|
|
|
|
public interface OnSectionSelectedListener {
|
|
void onSectionSelected(int position);
|
|
}
|
|
|
|
private final List<String> sections;
|
|
private final OnSectionSelectedListener listener;
|
|
private int selectedIndex = 0;
|
|
|
|
public SectionAdapter(List<String> sections, OnSectionSelectedListener listener) {
|
|
this.sections = sections;
|
|
this.listener = listener;
|
|
}
|
|
|
|
@NonNull
|
|
@Override
|
|
public SectionViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
View view = LayoutInflater.from(parent.getContext())
|
|
.inflate(R.layout.item_section, parent, false);
|
|
return new SectionViewHolder(view);
|
|
}
|
|
|
|
@Override
|
|
public void onBindViewHolder(@NonNull SectionViewHolder holder, int position) {
|
|
holder.title.setText(sections.get(position));
|
|
holder.itemView.setSelected(position == selectedIndex);
|
|
holder.itemView.setOnClickListener(v -> notifySelection(holder));
|
|
holder.itemView.setOnFocusChangeListener((v, hasFocus) -> {
|
|
if (hasFocus) {
|
|
notifySelection(holder);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override
|
|
public int getItemCount() {
|
|
return sections.size();
|
|
}
|
|
|
|
public void setSelectedIndex(int index) {
|
|
if (index < 0 || index >= sections.size()) {
|
|
return;
|
|
}
|
|
if (selectedIndex == index) {
|
|
return;
|
|
}
|
|
int previous = selectedIndex;
|
|
selectedIndex = index;
|
|
notifyItemChanged(previous);
|
|
notifyItemChanged(selectedIndex);
|
|
}
|
|
|
|
public int getSelectedIndex() {
|
|
return selectedIndex;
|
|
}
|
|
|
|
private void notifySelection(SectionViewHolder holder) {
|
|
int position = holder.getBindingAdapterPosition();
|
|
if (position == RecyclerView.NO_POSITION) {
|
|
return;
|
|
}
|
|
if (listener != null) {
|
|
listener.onSectionSelected(position);
|
|
}
|
|
}
|
|
|
|
static class SectionViewHolder extends RecyclerView.ViewHolder {
|
|
final TextView title;
|
|
|
|
SectionViewHolder(@NonNull View itemView) {
|
|
super(itemView);
|
|
title = itemView.findViewById(R.id.section_title);
|
|
}
|
|
}
|
|
}
|