Commit 22e5f322 authored by Thomas's avatar Thomas
Browse files

- Add discussions view for trending links

parent c0f8c744
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -229,6 +229,9 @@
        <activity
            android:name=".mastodon.activities.HashTagActivity"
            android:configChanges="keyboardHidden|orientation|screenSize" />
        <activity
            android:name=".mastodon.activities.LinkTimelineActivity"
            android:configChanges="keyboardHidden|orientation|screenSize" />
        <activity
            android:name=".mastodon.activities.AnnouncementActivity"
            android:configChanges="keyboardHidden|orientation|screenSize" />
+91 −0
Original line number Diff line number Diff line
package app.fedilab.android.mastodon.activities;
/* Copyright 2026 Thomas Schneider
 *
 * This file is a part of Fedilab
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software Foundation; either version 3 of the
 * License, or (at your option) any later version.
 *
 * Fedilab 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.
 *
 * You should have received a copy of the GNU General Public License along with Fedilab; if not,
 * see <http://www.gnu.org/licenses>. */


import android.os.Bundle;
import android.view.MenuItem;

import androidx.appcompat.app.ActionBar;

import app.fedilab.android.R;
import app.fedilab.android.databinding.ActivityLinkTimelineBinding;
import app.fedilab.android.mastodon.client.entities.app.CachedBundle;
import app.fedilab.android.mastodon.helper.Helper;
import app.fedilab.android.mastodon.ui.fragment.timeline.FragmentMastodonLinkTimeline;


public class LinkTimelineActivity extends BaseActivity {

    private String url;
    private ActivityLinkTimelineBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        binding = ActivityLinkTimelineBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        Bundle args = getIntent().getExtras();
        if (args != null) {
            long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1);
            new CachedBundle(LinkTimelineActivity.this).getBundle(bundleId, Helper.getCurrentAccount(LinkTimelineActivity.this), this::initializeAfterBundle);
        } else {
            initializeAfterBundle(null);
        }
    }

    private void initializeAfterBundle(Bundle bundle) {
        if (bundle != null) {
            url = bundle.getString(Helper.ARG_URL, null);
        }
        String title = null;
        if (bundle != null) {
            title = bundle.getString(Helper.ARG_TITLE, null);
        }
        if (url == null) {
            finish();
            return;
        }

        setSupportActionBar(binding.toolbar);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayShowTitleEnabled(false);
        }
        binding.title.setText(title != null ? title : url);
        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setDisplayShowHomeEnabled(true);
        }

        Bundle bundleFragment = new Bundle();
        bundleFragment.putString(Helper.ARG_URL, url);
        FragmentMastodonLinkTimeline fragment = new FragmentMastodonLinkTimeline();
        fragment.setArguments(bundleFragment);
        Helper.addFragment(getSupportFragmentManager(), R.id.nav_host_fragment_link, fragment, null, null, null);

        binding.openLink.setOnClickListener(v -> Helper.openBrowser(LinkTimelineActivity.this, url));
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
+11 −0
Original line number Diff line number Diff line
@@ -86,6 +86,17 @@ public interface MastodonTimelinesService {
                                   @Query("offset") Integer offset,
                                   @Query("limit") Integer limit);

    //Timeline for a specific link
    @GET("timelines/link")
    Call<List<Status>> getLinkTimeline(
            @Header("Authorization") String token,
            @Query("url") String url,
            @Query("max_id") String max_id,
            @Query("since_id") String since_id,
            @Query("min_id") String min_id,
            @Query("limit") Integer limit
    );

    //Public Tags timelines
    @GET("timelines/tag/{hashtag}")
    Call<List<Status>> getHashTag(
+2 −0
Original line number Diff line number Diff line
@@ -260,6 +260,8 @@ public class Helper {
    public static final String ARG_SHARE_URL_MEDIA = "ARG_SHARE_URL_MEDIA";
    public static final String ARG_SHARE_URL = "ARG_SHARE_URL";
    public static final String ARG_SHARE_TITLE = "ARG_SHARE_TITLE";
    public static final String ARG_URL = "ARG_URL";
    public static final String ARG_TITLE = "ARG_TITLE";
    public static final String ARG_SHARE_SUBJECT = "ARG_SHARE_SUBJECT";
    public static final String ARG_SHARE_DESCRIPTION = "ARG_SHARE_DESCRIPTION";
    public static final String ARG_SHARE_CONTENT = "ARG_SHARE_CONTENT";
+14 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import java.util.List;

import app.fedilab.android.R;
import app.fedilab.android.databinding.DrawerLinkBinding;
import app.fedilab.android.mastodon.activities.LinkTimelineActivity;
import app.fedilab.android.mastodon.activities.MediaActivity;
import app.fedilab.android.mastodon.client.entities.api.Attachment;
import app.fedilab.android.mastodon.client.entities.api.History;
@@ -162,6 +163,19 @@ public class LinkAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
        linkViewHolder.binding.chart.invalidate();

        linkViewHolder.binding.getRoot().setOnClickListener(v -> Helper.openBrowser(context, link.url));

        linkViewHolder.binding.showDiscussions.setOnClickListener(v -> {
            Intent intent = new Intent(context, LinkTimelineActivity.class);
            Bundle args = new Bundle();
            args.putString(Helper.ARG_URL, link.url);
            args.putString(Helper.ARG_TITLE, link.title);
            new CachedBundle(context).insertBundle(args, Helper.getCurrentAccount(context), bundleId -> {
                Bundle bundle = new Bundle();
                bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
                intent.putExtras(bundle);
                context.startActivity(intent);
            });
        });
    }

    @Override
Loading