/* * mygram-droid: Android TV client for Foldergram. * Copyright (C) 2026 Danilo M. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. */ package mygram.droid; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.TextView; import androidx.recyclerview.widget.RecyclerView; import java.util.Collections; /** One folder as a grid, shuffled once per open. */ public final class FolderActivity extends Activity { private FrameLayout content; private RecyclerView grid; static void open(Context c, Api.Folder f) { c.startActivity(new Intent(c, FolderActivity.class).putExtra("slug", f.slug).putExtra("name", f.name)); } @Override protected void onCreate(Bundle state) { super.onCreate(state); LinearLayout column = new LinearLayout(this); column.setOrientation(LinearLayout.VERTICAL); TextView title = Ui.text(this, getIntent().getStringExtra("name"), 24); title.setPadding(Ui.dp(this, 36), Ui.dp(this, 24), 0, 0); column.addView(title); content = new FrameLayout(this); column.addView(content, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1)); setContentView(column); show(Ui.text(this, "Loading…", 18)); Api.async(() -> Api.folderPosts(getIntent().getStringExtra("slug")), posts -> { Collections.shuffle(posts); grid = Ui.grid(this, Ui.postTiles(this, posts), Ui.POST_W, Ui.POST_H, 6); show(grid); grid.requestFocus(); }, e -> show(Ui.text(this, "Cannot load folder: " + e.getMessage(), 18))); } @Override protected void onResume() { super.onResume(); if (grid != null && grid.getAdapter() != null) grid.getAdapter().notifyItemRangeChanged(0, grid.getAdapter().getItemCount()); } private void show(android.view.View v) { content.removeAllViews(); content.addView(v); } }