Android TV v9.0 Final - Enhanced Section-Based Layout
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>
This commit is contained in:
@@ -3,106 +3,147 @@ package com.streamplayer;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private RecyclerView channelGrid;
|
||||
private RecyclerView eventsList;
|
||||
private View eventsContainer;
|
||||
private ProgressBar eventsProgress;
|
||||
private TextView eventsError;
|
||||
private Button tabChannels;
|
||||
private Button tabEvents;
|
||||
private RecyclerView sectionList;
|
||||
private RecyclerView contentList;
|
||||
private ProgressBar loadingIndicator;
|
||||
private TextView messageView;
|
||||
private TextView contentTitle;
|
||||
|
||||
private ChannelAdapter channelAdapter;
|
||||
private EventAdapter eventAdapter;
|
||||
private EventRepository eventRepository;
|
||||
private boolean eventsLoaded = false;
|
||||
private SectionAdapter sectionAdapter;
|
||||
private GridLayoutManager channelLayoutManager;
|
||||
private LinearLayoutManager eventLayoutManager;
|
||||
private final List<EventItem> cachedEvents = new ArrayList<>();
|
||||
private List<SectionEntry> sections;
|
||||
private SectionEntry currentSection;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
channelGrid = findViewById(R.id.channel_grid);
|
||||
eventsList = findViewById(R.id.events_list);
|
||||
eventsContainer = findViewById(R.id.events_container);
|
||||
eventsProgress = findViewById(R.id.events_progress);
|
||||
eventsError = findViewById(R.id.events_error);
|
||||
tabChannels = findViewById(R.id.tab_channels);
|
||||
tabEvents = findViewById(R.id.tab_events);
|
||||
sectionList = findViewById(R.id.section_list);
|
||||
contentList = findViewById(R.id.content_list);
|
||||
loadingIndicator = findViewById(R.id.loading_indicator);
|
||||
messageView = findViewById(R.id.message_view);
|
||||
contentTitle = findViewById(R.id.content_title);
|
||||
|
||||
channelGrid.setLayoutManager(new GridLayoutManager(this, getSpanCount()));
|
||||
channelGrid.setHasFixedSize(true);
|
||||
ChannelAdapter channelAdapter = new ChannelAdapter(
|
||||
ChannelRepository.getChannels(),
|
||||
channelAdapter = new ChannelAdapter(
|
||||
channel -> openPlayer(channel.getName(), channel.getPageUrl()));
|
||||
channelGrid.setAdapter(channelAdapter);
|
||||
|
||||
eventsList.setLayoutManager(new GridLayoutManager(this, 1));
|
||||
eventAdapter = new EventAdapter(event -> openPlayer(event.getTitle(), event.getPageUrl()));
|
||||
eventsList.setAdapter(eventAdapter);
|
||||
|
||||
eventRepository = new EventRepository();
|
||||
channelLayoutManager = new GridLayoutManager(this, getSpanCount());
|
||||
eventLayoutManager = new LinearLayoutManager(this);
|
||||
|
||||
tabChannels.setOnClickListener(v -> showChannels());
|
||||
tabEvents.setOnClickListener(v -> showEvents());
|
||||
sections = buildSections();
|
||||
sectionList.setLayoutManager(new LinearLayoutManager(this));
|
||||
sectionAdapter = new SectionAdapter(getSectionTitles(), this::selectSection);
|
||||
sectionList.setAdapter(sectionAdapter);
|
||||
|
||||
showChannels();
|
||||
channelGrid.post(channelGrid::requestFocus);
|
||||
selectSection(0);
|
||||
}
|
||||
|
||||
private void showChannels() {
|
||||
channelGrid.setVisibility(View.VISIBLE);
|
||||
eventsContainer.setVisibility(View.GONE);
|
||||
tabChannels.setSelected(true);
|
||||
tabEvents.setSelected(false);
|
||||
private void selectSection(int index) {
|
||||
if (sections == null || sections.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (index < 0 || index >= sections.size()) {
|
||||
index = 0;
|
||||
}
|
||||
sectionAdapter.setSelectedIndex(index);
|
||||
currentSection = sections.get(index);
|
||||
if (currentSection.type == SectionEntry.Type.EVENTS) {
|
||||
showEvents();
|
||||
} else {
|
||||
showChannels(currentSection);
|
||||
}
|
||||
}
|
||||
|
||||
private void showChannels(SectionEntry section) {
|
||||
contentTitle.setText(section.title);
|
||||
contentList.setLayoutManager(channelLayoutManager);
|
||||
contentList.setAdapter(channelAdapter);
|
||||
loadingIndicator.setVisibility(View.GONE);
|
||||
channelAdapter.submitList(section.channels);
|
||||
if (section.channels.isEmpty()) {
|
||||
messageView.setVisibility(View.VISIBLE);
|
||||
messageView.setText(R.string.message_no_channels);
|
||||
} else {
|
||||
messageView.setVisibility(View.GONE);
|
||||
contentList.post(() -> contentList.scrollToPosition(0));
|
||||
}
|
||||
}
|
||||
|
||||
private void showEvents() {
|
||||
channelGrid.setVisibility(View.GONE);
|
||||
eventsContainer.setVisibility(View.VISIBLE);
|
||||
tabChannels.setSelected(false);
|
||||
tabEvents.setSelected(true);
|
||||
if (!eventsLoaded) {
|
||||
contentTitle.setText(currentSection != null ? currentSection.title : getString(R.string.section_events));
|
||||
contentList.setLayoutManager(eventLayoutManager);
|
||||
contentList.setAdapter(eventAdapter);
|
||||
if (cachedEvents.isEmpty()) {
|
||||
loadEvents(false);
|
||||
} else {
|
||||
displayEvents();
|
||||
}
|
||||
}
|
||||
|
||||
private void loadEvents(boolean forceRefresh) {
|
||||
eventsProgress.setVisibility(View.VISIBLE);
|
||||
eventsError.setVisibility(View.GONE);
|
||||
eventsList.setVisibility(View.GONE);
|
||||
loadingIndicator.setVisibility(View.VISIBLE);
|
||||
messageView.setVisibility(View.GONE);
|
||||
eventRepository.loadEvents(this, forceRefresh, new EventRepository.Callback() {
|
||||
@Override
|
||||
public void onSuccess(List<EventItem> events) {
|
||||
runOnUiThread(() -> {
|
||||
eventsProgress.setVisibility(View.GONE);
|
||||
eventAdapter.submitList(events);
|
||||
eventsList.setVisibility(View.VISIBLE);
|
||||
eventsLoaded = true;
|
||||
cachedEvents.clear();
|
||||
cachedEvents.addAll(events);
|
||||
if (currentSection != null && currentSection.type == SectionEntry.Type.EVENTS) {
|
||||
displayEvents();
|
||||
} else {
|
||||
loadingIndicator.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String message) {
|
||||
runOnUiThread(() -> {
|
||||
eventsProgress.setVisibility(View.GONE);
|
||||
eventsError.setText("No se pudieron cargar los eventos: " + message);
|
||||
eventsError.setVisibility(View.VISIBLE);
|
||||
loadingIndicator.setVisibility(View.GONE);
|
||||
messageView.setVisibility(View.VISIBLE);
|
||||
messageView.setText(getString(R.string.message_events_error, message));
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void displayEvents() {
|
||||
loadingIndicator.setVisibility(View.GONE);
|
||||
if (cachedEvents.isEmpty()) {
|
||||
messageView.setVisibility(View.VISIBLE);
|
||||
messageView.setText(R.string.message_no_events);
|
||||
eventAdapter.submitList(new ArrayList<>());
|
||||
} else {
|
||||
messageView.setVisibility(View.GONE);
|
||||
eventAdapter.submitList(new ArrayList<>(cachedEvents));
|
||||
}
|
||||
}
|
||||
|
||||
private void openPlayer(String name, String pageUrl) {
|
||||
Intent intent = new Intent(MainActivity.this, PlayerActivity.class);
|
||||
intent.putExtra(PlayerActivity.EXTRA_CHANNEL_NAME, name);
|
||||
@@ -113,4 +154,90 @@ public class MainActivity extends AppCompatActivity {
|
||||
private int getSpanCount() {
|
||||
return getResources().getInteger(R.integer.channel_grid_span);
|
||||
}
|
||||
|
||||
private List<SectionEntry> buildSections() {
|
||||
List<SectionEntry> list = new ArrayList<>();
|
||||
list.add(SectionEntry.events(getString(R.string.section_events)));
|
||||
|
||||
Map<String, List<StreamChannel>> grouped = new HashMap<>();
|
||||
List<StreamChannel> allChannels = ChannelRepository.getChannels();
|
||||
for (StreamChannel channel : allChannels) {
|
||||
String key = deriveGroupName(channel.getName());
|
||||
grouped.computeIfAbsent(key, k -> new ArrayList<>()).add(channel);
|
||||
}
|
||||
|
||||
List<StreamChannel> espnChannels = grouped.remove("ESPN");
|
||||
if (espnChannels != null && !espnChannels.isEmpty()) {
|
||||
list.add(SectionEntry.channels("ESPN", espnChannels));
|
||||
}
|
||||
|
||||
List<String> remaining = new ArrayList<>(grouped.keySet());
|
||||
Collections.sort(remaining, String.CASE_INSENSITIVE_ORDER);
|
||||
for (String key : remaining) {
|
||||
List<StreamChannel> channels = grouped.get(key);
|
||||
if (channels == null || channels.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
list.add(SectionEntry.channels(key, channels));
|
||||
}
|
||||
|
||||
list.add(SectionEntry.channels(getString(R.string.section_all_channels), allChannels));
|
||||
return list;
|
||||
}
|
||||
|
||||
private List<String> getSectionTitles() {
|
||||
List<String> titles = new ArrayList<>();
|
||||
for (SectionEntry entry : sections) {
|
||||
titles.add(entry.title);
|
||||
}
|
||||
return titles;
|
||||
}
|
||||
|
||||
private String deriveGroupName(String name) {
|
||||
if (name == null) {
|
||||
return getString(R.string.section_all_channels);
|
||||
}
|
||||
String upper = name.toUpperCase(Locale.US);
|
||||
if (upper.startsWith("ESPN")) {
|
||||
return "ESPN";
|
||||
} else if (upper.contains("FOX SPORTS")) {
|
||||
return "Fox Sports";
|
||||
} else if (upper.contains("FOX")) {
|
||||
return "Fox";
|
||||
} else if (upper.contains("TNT")) {
|
||||
return "TNT";
|
||||
} else if (upper.contains("DAZN")) {
|
||||
return "DAZN";
|
||||
} else if (upper.contains("TUDN")) {
|
||||
return "TUDN";
|
||||
} else if (upper.contains("TYC")) {
|
||||
return "TyC";
|
||||
} else if (upper.contains("GOL")) {
|
||||
return "Gol";
|
||||
}
|
||||
int spaceIndex = upper.indexOf(' ');
|
||||
return spaceIndex > 0 ? upper.substring(0, spaceIndex) : upper;
|
||||
}
|
||||
|
||||
private static class SectionEntry {
|
||||
enum Type { EVENTS, CHANNELS }
|
||||
|
||||
final String title;
|
||||
final Type type;
|
||||
final List<StreamChannel> channels;
|
||||
|
||||
private SectionEntry(String title, Type type, List<StreamChannel> channels) {
|
||||
this.title = title;
|
||||
this.type = type;
|
||||
this.channels = channels == null ? new ArrayList<>() : new ArrayList<>(channels);
|
||||
}
|
||||
|
||||
static SectionEntry events(String title) {
|
||||
return new SectionEntry(title, Type.EVENTS, null);
|
||||
}
|
||||
|
||||
static SectionEntry channels(String title, List<StreamChannel> channels) {
|
||||
return new SectionEntry(title, Type.CHANNELS, channels);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user