mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-07 11:17:25 +01:00
View subreddit sidebar is now available.
This commit is contained in:
parent
d74c7f50fa
commit
a60c249b16
@ -21,7 +21,11 @@
|
||||
android:theme="@style/AppTheme"
|
||||
android:usesCleartextTraffic="true"
|
||||
tools:replace="android:label">
|
||||
<activity android:name=".Activity.ViewMultiRedditDetailActivity"
|
||||
<activity android:name=".Activity.ViewSidebarActivity"
|
||||
android:parentActivityName=".Activity.MainActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar" />
|
||||
<activity
|
||||
android:name=".Activity.ViewMultiRedditDetailActivity"
|
||||
android:parentActivityName=".Activity.MainActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar" />
|
||||
<activity
|
||||
|
@ -0,0 +1,185 @@
|
||||
package ml.docilealligator.infinityforreddit.Activity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.style.SuperscriptSpan;
|
||||
import android.text.util.Linkify;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.appbar.AppBarLayout;
|
||||
|
||||
import org.commonmark.ext.gfm.tables.TableBlock;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import io.noties.markwon.AbstractMarkwonPlugin;
|
||||
import io.noties.markwon.Markwon;
|
||||
import io.noties.markwon.MarkwonConfiguration;
|
||||
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin;
|
||||
import io.noties.markwon.linkify.LinkifyPlugin;
|
||||
import io.noties.markwon.recycler.MarkwonAdapter;
|
||||
import io.noties.markwon.recycler.table.TableEntry;
|
||||
import io.noties.markwon.recycler.table.TableEntryPlugin;
|
||||
import io.noties.markwon.simple.ext.SimpleExtPlugin;
|
||||
import io.noties.markwon.urlprocessor.UrlProcessorRelativeToAbsolute;
|
||||
import ml.docilealligator.infinityforreddit.AppBarStateChangeListener;
|
||||
import ml.docilealligator.infinityforreddit.Infinity;
|
||||
import ml.docilealligator.infinityforreddit.R;
|
||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditViewModel;
|
||||
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
|
||||
|
||||
public class ViewSidebarActivity extends BaseActivity {
|
||||
|
||||
public static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
||||
@BindView(R.id.appbar_layout_view_sidebar_activity)
|
||||
AppBarLayout appBarLayout;
|
||||
@BindView(R.id.toolbar_view_sidebar_activity)
|
||||
Toolbar toolbar;
|
||||
@BindView(R.id.markdown_recycler_view_view_sidebar_activity)
|
||||
RecyclerView markdownRecyclerView;
|
||||
@Inject
|
||||
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||
@Inject
|
||||
SharedPreferences mSharedPreferences;
|
||||
private SubredditViewModel mSubredditViewModel;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
((Infinity) getApplication()).getAppComponent().inject(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_view_sidebar);
|
||||
|
||||
ButterKnife.bind(this);
|
||||
|
||||
Resources resources = getResources();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1
|
||||
&& (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT
|
||||
|| resources.getBoolean(R.bool.isTablet))
|
||||
&& mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) {
|
||||
Window window = getWindow();
|
||||
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
|
||||
|
||||
boolean lightNavBar = false;
|
||||
if ((resources.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) {
|
||||
lightNavBar = true;
|
||||
}
|
||||
boolean finalLightNavBar = lightNavBar;
|
||||
|
||||
View decorView = window.getDecorView();
|
||||
if (finalLightNavBar) {
|
||||
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
|
||||
}
|
||||
appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() {
|
||||
@Override
|
||||
public void onStateChanged(AppBarLayout appBarLayout, AppBarStateChangeListener.State state) {
|
||||
if (state == State.COLLAPSED) {
|
||||
if (finalLightNavBar) {
|
||||
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
|
||||
}
|
||||
} else if (state == State.EXPANDED) {
|
||||
if (finalLightNavBar) {
|
||||
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
int statusBarResourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
|
||||
if (statusBarResourceId > 0) {
|
||||
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
|
||||
params.topMargin = getResources().getDimensionPixelSize(statusBarResourceId);
|
||||
toolbar.setLayoutParams(params);
|
||||
}
|
||||
}
|
||||
|
||||
String subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME);
|
||||
if (subredditName == null) {
|
||||
Toast.makeText(this, R.string.error_getting_subreddit_name, Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
toolbar.setTitle("r/" + subredditName);
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
Markwon markwon = Markwon.builder(this)
|
||||
.usePlugin(new AbstractMarkwonPlugin() {
|
||||
@Override
|
||||
public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) {
|
||||
builder.linkResolver((view, link) -> {
|
||||
Intent intent = new Intent(ViewSidebarActivity.this, LinkResolverActivity.class);
|
||||
Uri uri = Uri.parse(link);
|
||||
if (uri.getScheme() == null && uri.getHost() == null) {
|
||||
intent.setData(LinkResolverActivity.getRedditUriByPath(link));
|
||||
} else {
|
||||
intent.setData(uri);
|
||||
}
|
||||
ViewSidebarActivity.this.startActivity(intent);
|
||||
}).urlProcessor(new UrlProcessorRelativeToAbsolute("https://www.reddit.com"));
|
||||
}
|
||||
})
|
||||
.usePlugin(StrikethroughPlugin.create())
|
||||
.usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS))
|
||||
.usePlugin(SimpleExtPlugin.create(plugin ->
|
||||
plugin.addExtension(1, '^', (configuration, props) -> {
|
||||
return new SuperscriptSpan();
|
||||
})
|
||||
)
|
||||
)
|
||||
.usePlugin(TableEntryPlugin.create(this))
|
||||
.build();
|
||||
MarkwonAdapter markwonAdapter = MarkwonAdapter.builder(R.layout.adapter_default_entry, R.id.text)
|
||||
.include(TableBlock.class, TableEntry.create(builder -> builder
|
||||
.tableLayout(R.layout.adapter_table_block, R.id.table_layout)
|
||||
.textLayoutIsRoot(R.layout.view_table_entry_cell)))
|
||||
.build();
|
||||
|
||||
markdownRecyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
markdownRecyclerView.setAdapter(markwonAdapter);
|
||||
|
||||
mSubredditViewModel = new ViewModelProvider(this,
|
||||
new SubredditViewModel.Factory(getApplication(), mRedditDataRoomDatabase, subredditName))
|
||||
.get(SubredditViewModel.class);
|
||||
mSubredditViewModel.getSubredditLiveData().observe(this, subredditData -> {
|
||||
if (subredditData != null) {
|
||||
markwonAdapter.setMarkdown(markwon, subredditData.getSidebarDescription());
|
||||
markwonAdapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SharedPreferences getSharedPreferences() {
|
||||
return mSharedPreferences;
|
||||
}
|
||||
}
|
@ -548,6 +548,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
case R.id.action_change_post_layout_view_subreddit_detail_activity:
|
||||
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
|
||||
return true;
|
||||
case R.id.action_view_side_bar_view_subreddit_detail_activity:
|
||||
Intent sidebarIntent = new Intent(this, ViewSidebarActivity.class);
|
||||
sidebarIntent.putExtra(ViewSidebarActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
startActivity(sidebarIntent);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ import ml.docilealligator.infinityforreddit.Activity.ViewImageActivity;
|
||||
import ml.docilealligator.infinityforreddit.Activity.ViewMessageActivity;
|
||||
import ml.docilealligator.infinityforreddit.Activity.ViewMultiRedditDetailActivity;
|
||||
import ml.docilealligator.infinityforreddit.Activity.ViewPostDetailActivity;
|
||||
import ml.docilealligator.infinityforreddit.Activity.ViewSidebarActivity;
|
||||
import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity;
|
||||
import ml.docilealligator.infinityforreddit.Activity.ViewUserDetailActivity;
|
||||
import ml.docilealligator.infinityforreddit.Fragment.CommentsListingFragment;
|
||||
@ -122,4 +123,6 @@ public interface AppComponent {
|
||||
void inject(MultiRedditListingActivity multiRedditListingActivity);
|
||||
|
||||
void inject(ViewMultiRedditDetailActivity viewMultiRedditDetailActivity);
|
||||
|
||||
void inject(ViewSidebarActivity viewSidebarActivity);
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ class ParseSubredditData {
|
||||
String id = subredditDataJsonObject.getString(JSONUtils.NAME_KEY);
|
||||
String subredditFullName = subredditDataJsonObject.getString(JSONUtils.DISPLAY_NAME);
|
||||
String description = subredditDataJsonObject.getString(JSONUtils.PUBLIC_DESCRIPTION_KEY).trim();
|
||||
String sidebarDescription = subredditDataJsonObject.getString(JSONUtils.DESCRIPTION_KEY).trim();
|
||||
|
||||
String bannerImageUrl;
|
||||
if (subredditDataJsonObject.isNull(JSONUtils.BANNER_BACKGROUND_IMAGE_KEY)) {
|
||||
@ -50,7 +51,8 @@ class ParseSubredditData {
|
||||
nSubscribers = subredditDataJsonObject.getInt(JSONUtils.SUBSCRIBERS_KEY);
|
||||
}
|
||||
|
||||
return new SubredditData(id, subredditFullName, iconUrl, bannerImageUrl, description, nSubscribers);
|
||||
return new SubredditData(id, subredditFullName, iconUrl, bannerImageUrl, description,
|
||||
sidebarDescription, nSubscribers);
|
||||
}
|
||||
|
||||
interface ParseSubredditDataListener {
|
||||
|
@ -97,9 +97,11 @@ class ParseSubscribedThing {
|
||||
} else {
|
||||
String subredditFullName = data.getString(JSONUtils.DISPLAY_NAME);
|
||||
String description = data.getString(JSONUtils.PUBLIC_DESCRIPTION_KEY).trim();
|
||||
String sidebarDescription = data.getString(JSONUtils.DESCRIPTION_KEY);
|
||||
int nSubscribers = data.getInt(JSONUtils.SUBSCRIBERS_KEY);
|
||||
newSubscribedSubredditData.add(new SubscribedSubredditData(id, name, iconUrl, accountName, isFavorite));
|
||||
newSubredditData.add(new SubredditData(id, subredditFullName, iconUrl, bannerImageUrl, description, nSubscribers));
|
||||
newSubredditData.add(new SubredditData(id, subredditFullName, iconUrl,
|
||||
bannerImageUrl, description, sidebarDescription, nSubscribers));
|
||||
}
|
||||
}
|
||||
lastItem = jsonResponse.getJSONObject(JSONUtils.DATA_KEY).getString(JSONUtils.AFTER_KEY);
|
||||
|
@ -23,7 +23,7 @@ import ml.docilealligator.infinityforreddit.User.UserDao;
|
||||
import ml.docilealligator.infinityforreddit.User.UserData;
|
||||
|
||||
@Database(entities = {Account.class, SubredditData.class, SubscribedSubredditData.class, UserData.class,
|
||||
SubscribedUserData.class, MultiReddit.class}, version = 4)
|
||||
SubscribedUserData.class, MultiReddit.class}, version = 5)
|
||||
public abstract class RedditDataRoomDatabase extends RoomDatabase {
|
||||
private static RedditDataRoomDatabase INSTANCE;
|
||||
|
||||
@ -33,7 +33,7 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
|
||||
RedditDataRoomDatabase.class, "reddit_data")
|
||||
.addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4)
|
||||
.addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@ -98,4 +98,12 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
|
||||
"FOREIGN KEY(username) REFERENCES accounts(username) ON DELETE CASCADE)");
|
||||
}
|
||||
};
|
||||
|
||||
private static final Migration MIGRATION_4_5 = new Migration(4, 5) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||
database.execSQL("ALTER TABLE subreddits"
|
||||
+ " ADD COLUMN sidebar_description TEXT");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -19,15 +19,19 @@ public class SubredditData {
|
||||
private String bannerUrl;
|
||||
@ColumnInfo(name = "description")
|
||||
private String description;
|
||||
@ColumnInfo(name = "sidebar_description")
|
||||
private String sidebarDescription;
|
||||
@ColumnInfo(name = "subscribers_count")
|
||||
private int nSubscribers;
|
||||
|
||||
public SubredditData(@NonNull String id, String name, String iconUrl, String bannerUrl, String description, int nSubscribers) {
|
||||
public SubredditData(@NonNull String id, String name, String iconUrl, String bannerUrl,
|
||||
String description, String sidebarDescription, int nSubscribers) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.iconUrl = iconUrl;
|
||||
this.bannerUrl = bannerUrl;
|
||||
this.description = description;
|
||||
this.sidebarDescription = sidebarDescription;
|
||||
this.nSubscribers = nSubscribers;
|
||||
}
|
||||
|
||||
@ -52,6 +56,10 @@ public class SubredditData {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getSidebarDescription() {
|
||||
return sidebarDescription;
|
||||
}
|
||||
|
||||
public int getNSubscribers() {
|
||||
return nSubscribers;
|
||||
}
|
||||
|
44
app/src/main/res/layout/activity_view_sidebar.xml
Normal file
44
app/src/main/res/layout/activity_view_sidebar.xml
Normal file
@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/backgroundColor"
|
||||
tools:context=".Activity.ViewSidebarActivity">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/appbar_layout_view_sidebar_activity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/toolbarAndTabBackgroundColor"
|
||||
android:theme="@style/AppTheme.AppBarOverlay">
|
||||
|
||||
<com.google.android.material.appbar.CollapsingToolbarLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_scrollFlags="scroll|enterAlways"
|
||||
app:titleEnabled="false"
|
||||
app:toolbarId="@+id/toolbar_view_sidebar_activity">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar_view_sidebar_activity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
app:popupTheme="@style/AppTheme.PopupOverlay"
|
||||
app:navigationIcon="?attr/homeAsUpIndicator" />
|
||||
|
||||
</com.google.android.material.appbar.CollapsingToolbarLayout>
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/markdown_recycler_view_view_sidebar_activity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="16dp"
|
||||
android:clipToPadding="false"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
@ -2,12 +2,7 @@
|
||||
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingRight="16dp"
|
||||
android:paddingBottom="8dp"
|
||||
android:layout_margin="16dp"
|
||||
android:scrollbarStyle="outsideInset">
|
||||
|
||||
<TableLayout
|
||||
|
@ -34,4 +34,10 @@
|
||||
android:orderInCategory="5"
|
||||
android:title="@string/action_change_post_layout"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_view_side_bar_view_subreddit_detail_activity"
|
||||
android:orderInCategory="6"
|
||||
android:title="@string/action_view_side_bar"
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
@ -43,6 +43,7 @@
|
||||
<string name="action_unmark_spoiler">Unmark Spoiler</string>
|
||||
<string name="action_edit_flair">Edit Flair</string>
|
||||
<string name="action_change_post_layout">Change Post Layout</string>
|
||||
<string name="action_view_side_bar">View Sidebar</string>
|
||||
|
||||
<string name="parse_json_response_error">Error occurred when parsing the JSON response</string>
|
||||
<string name="retrieve_token_error">Error Retrieving the token</string>
|
||||
@ -384,4 +385,6 @@
|
||||
<string name="error_loading_subscriptions">Cannot sync subscriptions</string>
|
||||
|
||||
<string name="share_this_app">Check out Infinity for Reddit, an awesome Reddit client!\nhttps://play.google.com/store/apps/details?id=ml.docilealligator.infinityforreddit</string>
|
||||
|
||||
<string name="error_getting_subreddit_name">Error getting subreddit name</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user