4 Commits

Author SHA1 Message Date
Balazs Toldi
134c895cd4 The .profm sorting in build.gradle instead of excluding them from the build
Signed-off-by: Balazs Toldi <balazs@toldi.eu>
2023-10-20 07:49:58 +02:00
Balazs Toldi
ec6567b9b2 Add python to build
Signed-off-by: Balazs Toldi <balazs@toldi.eu>
2023-10-20 07:49:14 +02:00
Balazs Toldi
40fa3a1987 Fully reproducible build
Signed-off-by: Balazs Toldi <balazs@toldi.eu>
2023-10-20 07:39:12 +02:00
Balazs Toldi
05123c7068 Reproducible classes2.dex
Signed-off-by: Balazs Toldi <balazs@toldi.eu>
2023-10-19 22:00:03 +02:00
265 changed files with 12705 additions and 15728 deletions

BIN
.assets/IzzyOnDroid.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

View File

@@ -1,28 +0,0 @@
---
name: "Feature request"
about: "Request a feature!"
title: "[Feature] "
ref: "master"
labels:
- Kind/Feature
---
### Description
<!-- A clear and concise description of what the feature is and what problem it solves. -->
### Background
<!-- Any background information or context that would be helpful. -->
### Proposed Solution
<!--
- Describe the solution you'd like.
- A clear and concise description of what you want to happen.
- Include any alternative solutions or features you've considered.
- Add any technical details, mockups, or examples if available.
-->
### Additional Context
<!-- Add any other context, screenshots, or links to existing issues/discussions about the feature here. -->

2
.gitignore vendored
View File

@@ -56,8 +56,6 @@ gen-external-apklibs
# NDK
obj/
**/ndkHelperBin
**/.cxx
# IntelliJ IDEA
*.iml

View File

@@ -1,5 +1,5 @@
<h1 align="center">
Eternity for Lemmy
Eternity (formerly Infinity for Lemmy)
</h1>
<div align="center">
@@ -20,13 +20,12 @@ A Lemmy client for Android written in Java. It's a fork of the [Infinity for Red
</div>
<div align="center">
<a href="https://f-droid.org/packages/eu.toldi.infinityforlemmy/">
<img src="./.assets/fdroid-badge.png" height="80">
</a>
<a href="https://play.google.com/store/apps/details?id=eu.toldi.infinityforlemmy">
<img src="./.assets/google-play-badge.png" height="80">
</a>
<a href="https://apt.izzysoft.de/fdroid/index/apk/eu.toldi.infinityforlemmy">
<img src="./.assets/IzzyOnDroid.png" height="80">
</a>
<a href="https://codeberg.org/Bazsalanszky/Eternity/releases/">
<img src="./.assets/codeberg.png" height="80">
</a>
@@ -37,62 +36,24 @@ A Lemmy client for Android written in Java. It's a fork of the [Infinity for Red
---
## Features
## Action Items for Eternity
Eternity is currently in the early stages of development. Expect many unfinished features and bugs!
### Browsing Lemmy
- Explore various feeds (Subscribed/Local/All) and communities
- Subscribe or unsubscribe from specific communities, with the option to block
- Discover communities federated with the current instance
- Favorite a community for quick access
- Manage your subscriptions and blocked communities
### Content Engagement
- Engage with content by voting, saving, sharing, and creating posts or comments
- Enjoy endless scrolling through feeds and posts
- Tailor the view settings for posts (card,compact, gallery)
- Set default preferences for post and comment sorting
- Stay updated with notifications for replies
### Account Management
- Sign in to multiple accounts or instances, and effortlessly switch between them
- Use the inbox features to view replies, mentions, and private messages
- Access your profile to view your posts, comments, and saved content
### Customization
- Choose between various theme options including Light, Dark, OLED
- Support Material You theming
- Explore user-created themes
- Customize font settings
- Optional bottom navigation bar
- Discover a plethora of other customization features
<img
src="https://codeberg.org/Bazsalanszky/Eternity/raw/branch/master/fastlane/metadata/android/en-US/images/phoneScreenshots/1.png"
alt="Screenshot 1"
height="200" >
<img
src="https://codeberg.org/Bazsalanszky/Eternity/raw/branch/master/fastlane/metadata/android/en-US/images/phoneScreenshots/2.png"
alt="Screenshot 2"
height="200" >
<img
src="https://codeberg.org/Bazsalanszky/Eternity/raw/branch/master/fastlane/metadata/android/en-US/images/phoneScreenshots/3.png"
alt="Screenshot 3"
height="200" >
<img
src="https://codeberg.org/Bazsalanszky/Eternity/raw/branch/master/fastlane/metadata/android/en-US/images/phoneScreenshots/4.png"
alt="Screenshot 4"
height="200" >
<img
src="https://codeberg.org/Bazsalanszky/Eternity/raw/branch/master/fastlane/metadata/android/en-US/images/phoneScreenshots/5.png"
alt="Screenshot 5"
height="200" >
- [x] Implementation of basic post browsing feature
- [x] Support for multiple account handling
- [x] Functionality for post upvotes/downvotes
- [x] Functionality to browse comments
- [x] Capability for creating a new post
- [x] Ability to create comments
- [x] Edit/Delete posts and comments
- [x] Basic inbox
- [ ] Elimination of code/string references specific to Reddit
- [x] Incorporation of private messaging feature
- [x] Feature for saving posts/comments
- [x] Resolving links
- [ ] Account editing function
- [ ] Multi community view?
## Contributing
@@ -111,7 +72,7 @@ Don't forget to give the project a star! Thanks again!
### Translation
You can also help Eternity by translating it to your native langugage! Translations are done via [Weblate](https://translate.codeberg.org/projects/infinity-for-lemmy/app/)!
You can alos help Eternity by translating it to your native langugage! Translations are done via [Weblate](https://translate.codeberg.org/projects/infinity-for-lemmy/app/)!
[![Translation](https://translate.codeberg.org/widgets/infinity-for-lemmy/-/app/multi-auto.svg)](https://translate.codeberg.org/engage/Eternity/)

View File

@@ -21,8 +21,8 @@ android {
applicationId "eu.toldi.infinityforlemmy"
minSdk 21
targetSdk 33
versionCode 131
versionName "0.1.2"
versionCode 130
versionName "0.1.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
@@ -33,8 +33,7 @@ android {
buildTypes {
release {
minifyEnabled true
shrinkResources true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
@@ -98,17 +97,11 @@ android {
packagingOptions {
doNotStrip '**/*.so'
}
// Kotlin jvm target
kotlinOptions {
jvmTarget = '11'
}
namespace 'eu.toldi.infinityforlemmy'
task rearrangeClass(type: Exec) {
commandLine 'python3', '../scripts/fixEventBus.py'
commandLine 'python', '../scripts/fixEventBus.py'
}
applicationVariants.all { variant ->
@@ -232,7 +225,7 @@ dependencies {
implementation 'com.github.santalu:aspect-ratio-imageview:1.0.9'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.23'
def bivVersion = "1.8.1"
implementation "com.github.piasy:BigImageViewer:$bivVersion"
implementation "com.github.piasy:BigImageViewer:bivVersion"
implementation "com.github.piasy:GlideImageLoader:$bivVersion"
implementation "com.github.piasy:GlideImageViewFactory:$bivVersion"
@@ -271,8 +264,6 @@ dependencies {
implementation 'com.otaliastudios:zoomlayout:1.9.0'
implementation 'androidx.core:core-splashscreen:1.0.1'
/**** Builds and flavors ****/
// debugImplementation because LeakCanary should only run in debug builds.

View File

@@ -5,8 +5,6 @@
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
-dontobfuscate
-keepattributes SourceFile,LineNumberTable
## Preferences reflection
-keep class * extends androidx.preference.PreferenceFragmentCompat

View File

@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="eu.toldi.infinityforlemmy">
xmlns:tools="http://schemas.android.com/tools">
<queries>
<intent>
@@ -23,7 +22,6 @@
android:maxSdkVersion="28" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<application
@@ -42,23 +40,6 @@
android:configChanges="orientation|screenLayout|screenSize|layoutDirection"
android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.Slidable" />
<activity
android:name=".activities.CommentFilterUsageListingActivity"
android:parentActivityName=".activities.SettingsActivity"
android:theme="@style/AppTheme.NoActionBar"
android:exported="false" />
<activity
android:name=".activities.CustomizeCommentFilterActivity"
android:label="@string/customize_comment_filter_activity_label"
android:parentActivityName=".activities.SettingsActivity"
android:theme="@style/AppTheme.NoActionBar"
android:exported="false" />
<activity
android:name=".activities.CommentFilterPreferenceActivity"
android:label="@string/comment_filter_preference_activity_label"
android:parentActivityName=".activities.SettingsActivity"
android:theme="@style/AppTheme.NoActionBar"
android:exported="false" />
<activity
android:name=".activities.HistoryActivity"
android:exported="false"
@@ -426,6 +407,11 @@
android:label="@string/subscriptions"
android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.Slidable" />
<activity
android:name=".activities.BlockedThingListingActivity"
android:label="@string/blocks"
android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.Slidable" />
<activity
android:name=".activities.SubredditSelectionActivity"
android:label="@string/community_selection_activity_label"
@@ -455,37 +441,11 @@
android:theme="@style/AppTheme.Launcher"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity-alias
android:name=".DefaultIcon"
android:targetActivity=".activities.MainActivity"
android:label="@string/application_name"
android:enabled="true"
android:icon="@mipmap/ic_launcher"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
<activity-alias
android:name=".OriginalIcon"
android:targetActivity=".activities.MainActivity"
android:label="@string/application_name"
android:enabled="false"
android:icon="@mipmap/original_ic_launcher"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
<activity
android:name=".activities.LoginActivity"
android:configChanges="orientation|screenLayout|screenSize|layoutDirection"
@@ -514,7 +474,6 @@
android:name=".activities.ViewUserDetailActivity"
android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.Slidable" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

View File

@@ -12,12 +12,9 @@ import eu.toldi.infinityforlemmy.activities.AccountPostsActivity;
import eu.toldi.infinityforlemmy.activities.AccountSavedThingActivity;
import eu.toldi.infinityforlemmy.activities.BlockedThingListingActivity;
import eu.toldi.infinityforlemmy.activities.CommentActivity;
import eu.toldi.infinityforlemmy.activities.CommentFilterPreferenceActivity;
import eu.toldi.infinityforlemmy.activities.CommentFilterUsageListingActivity;
import eu.toldi.infinityforlemmy.activities.CreateMultiRedditActivity;
import eu.toldi.infinityforlemmy.activities.CustomThemeListingActivity;
import eu.toldi.infinityforlemmy.activities.CustomThemePreviewActivity;
import eu.toldi.infinityforlemmy.activities.CustomizeCommentFilterActivity;
import eu.toldi.infinityforlemmy.activities.CustomizePostFilterActivity;
import eu.toldi.infinityforlemmy.activities.CustomizeThemeActivity;
import eu.toldi.infinityforlemmy.activities.EditCommentActivity;
@@ -28,6 +25,7 @@ import eu.toldi.infinityforlemmy.activities.FetchRandomSubredditOrPostActivity;
import eu.toldi.infinityforlemmy.activities.FilteredPostsActivity;
import eu.toldi.infinityforlemmy.activities.FullMarkdownActivity;
import eu.toldi.infinityforlemmy.activities.GiveAwardActivity;
import eu.toldi.infinityforlemmy.activities.HistoryActivity;
import eu.toldi.infinityforlemmy.activities.InboxActivity;
import eu.toldi.infinityforlemmy.activities.InstanceInfoActivity;
import eu.toldi.infinityforlemmy.activities.LinkResolverActivity;
@@ -77,6 +75,7 @@ import eu.toldi.infinityforlemmy.fragments.BlockedCommunitiesListingFragment;
import eu.toldi.infinityforlemmy.fragments.BlockedUsersListingFragment;
import eu.toldi.infinityforlemmy.fragments.CommentsListingFragment;
import eu.toldi.infinityforlemmy.fragments.FollowedUsersListingFragment;
import eu.toldi.infinityforlemmy.fragments.HistoryPostFragment;
import eu.toldi.infinityforlemmy.fragments.InboxFragment;
import eu.toldi.infinityforlemmy.fragments.MorePostsInfoFragment;
import eu.toldi.infinityforlemmy.fragments.MultiRedditListingFragment;
@@ -310,6 +309,10 @@ public interface AppComponent {
void inject(MaterialYouWorker materialYouWorker);
void inject(HistoryPostFragment historyPostFragment);
void inject(HistoryActivity historyActivity);
void inject(MorePostsInfoFragment morePostsInfoFragment);
void inject(BlockedThingListingActivity blockedThingListingActivity);
@@ -324,12 +327,6 @@ public interface AppComponent {
void inject(@NotNull InstanceInfoActivity instanceInfoActivity);
void inject(CommentFilterPreferenceActivity commentFilterPreferenceActivity);
void inject(CustomizeCommentFilterActivity customizeCommentFilterActivity);
void inject(CommentFilterUsageListingActivity commentFilterUsageListingActivity);
@Component.Factory
interface Factory {
AppComponent create(@BindsInstance Application application);

View File

@@ -255,13 +255,4 @@ abstract class NetworkModule {
static LemmyPrivateMessageAPI provideLemmyPrivateMessageAPI(@Named("base") RetrofitHolder retrofit) {
return new LemmyPrivateMessageAPI(retrofit);
}
@Provides
@Named("lemmyVerse")
@Singleton
static Retrofit provideLemmyVerseRetrofit(@Named("base") RetrofitHolder retrofit) {
return retrofit.getRetrofit().newBuilder()
.baseUrl(APIUtils.LEMMYVERSE_API_BASE_URI)
.build();
}
}

View File

@@ -17,10 +17,6 @@ import eu.toldi.infinityforlemmy.blockedcommunity.BlockedCommunityDao;
import eu.toldi.infinityforlemmy.blockedcommunity.BlockedCommunityData;
import eu.toldi.infinityforlemmy.blockeduser.BlockedUserDao;
import eu.toldi.infinityforlemmy.blockeduser.BlockedUserData;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilter;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilterDao;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilterUsage;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilterUsageDao;
import eu.toldi.infinityforlemmy.customtheme.CustomTheme;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeDao;
import eu.toldi.infinityforlemmy.multireddit.AnonymousMultiredditSubreddit;
@@ -46,8 +42,7 @@ import eu.toldi.infinityforlemmy.user.UserData;
@Database(entities = {Account.class, SubredditData.class, SubscribedSubredditData.class, UserData.class,
SubscribedUserData.class, MultiReddit.class, CustomTheme.class, RecentSearchQuery.class,
ReadPost.class, PostFilter.class, PostFilterUsage.class, AnonymousMultiredditSubreddit.class,
BlockedUserData.class, BlockedCommunityData.class, CommentFilter.class, CommentFilterUsage.class}, version = 28)
ReadPost.class, PostFilter.class, PostFilterUsage.class, AnonymousMultiredditSubreddit.class, BlockedUserData.class, BlockedCommunityData.class}, version = 27)
public abstract class RedditDataRoomDatabase extends RoomDatabase {
public static RedditDataRoomDatabase create(final Context context) {
@@ -58,7 +53,7 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
MIGRATION_9_10, MIGRATION_10_11, MIGRATION_11_12, MIGRATION_12_13,
MIGRATION_13_14, MIGRATION_14_15, MIGRATION_15_16, MIGRATION_16_17,
MIGRATION_17_18, MIGRATION_18_19, MIGRATION_19_20, MIGRATION_20_21,
MIGRATION_21_22, MIGRATION_22_23, MIGRATION_23_24, MIGRATION_24_25, MIGRATION_25_26, MIGRATION_26_27, MIGRATION_27_28)
MIGRATION_21_22, MIGRATION_22_23, MIGRATION_23_24, MIGRATION_24_25, MIGRATION_25_26, MIGRATION_26_27)
.build();
}
@@ -90,10 +85,6 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
public abstract AnonymousMultiredditSubredditDao anonymousMultiredditSubredditDao();
public abstract CommentFilterDao commentFilterDao();
public abstract CommentFilterUsageDao commentFilterUsageDao();
private static final Migration MIGRATION_1_2 = new Migration(1, 2) {
@Override
public void migrate(SupportSQLiteDatabase database) {
@@ -433,16 +424,4 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
+ " ADD COLUMN is_favorite INTEGER DEFAULT 0 NOT NULL");
}
};
private static final Migration MIGRATION_27_28 = new Migration(27, 28) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
database.execSQL("ALTER TABLE custom_themes ADD COLUMN filled_card_view_background_color INTEGER DEFAULT " + Color.parseColor("#E6F4FF") + " NOT NULL");
database.execSQL("ALTER TABLE custom_themes ADD COLUMN read_post_filled_card_view_background_color INTEGER DEFAULT " + Color.parseColor("#F5F5F5") + " NOT NULL");
database.execSQL("CREATE TABLE comment_filter " +
"(name TEXT NOT NULL PRIMARY KEY, max_vote INTEGER NOT NULL, min_vote INTEGER NOT NULL, exclude_strings TEXT, exclude_users TEXT)");
database.execSQL("CREATE TABLE comment_filter_usage (name TEXT NOT NULL, usage INTEGER NOT NULL, " +
"name_of_usage TEXT NOT NULL, PRIMARY KEY(name, usage, name_of_usage), FOREIGN KEY(name) REFERENCES comment_filter(name) ON DELETE CASCADE)");
}
};
}

View File

@@ -48,10 +48,7 @@ public class SortType {
TOP_SIX_MONTHS("TopSixMonths", "Top"),
TOP_NINE_MONTHS("TopNineMonths", "Top"),
TOP_YEAR("TopYear", "Top"),
TOP_ALL("TopAll", "Top"),
SCALED("Scaled", "Scaled"),
CONTROVERSIAL("Controversial", "Controversial");
TOP_ALL("TopAll", "Top");
public final String value;
public final String fullName;

View File

@@ -205,7 +205,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
}
};
Markwon postBodyMarkwon = MarkdownUtils.createFullRedditMarkwon(this,
miscPlugin, parentTextColor, parentSpoilerBackgroundColor, null, mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false));
miscPlugin, parentTextColor, parentSpoilerBackgroundColor, null);
MarkwonAdapter markwonAdapter = MarkdownUtils.createTablesAdapter();
binding.commentContentMarkdownView.setLayoutManager(new LinearLayoutManagerBugFixed(this));
binding.commentContentMarkdownView.setAdapter(markwonAdapter);

View File

@@ -1,126 +0,0 @@
package eu.toldi.infinityforlemmy.activities;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.MenuItem;
import androidx.annotation.NonNull;
import androidx.lifecycle.ViewModelProvider;
import java.util.concurrent.Executor;
import javax.inject.Inject;
import javax.inject.Named;
import butterknife.ButterKnife;
import eu.toldi.infinityforlemmy.Infinity;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
import eu.toldi.infinityforlemmy.adapters.CommentFilterWithUsageRecyclerViewAdapter;
import eu.toldi.infinityforlemmy.bottomsheetfragments.CommentFilterOptionsBottomSheetFragment;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilter;
import eu.toldi.infinityforlemmy.commentfilter.DeleteCommentFilter;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.databinding.ActivityCommentFilterPreferenceBinding;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilterWithUsageViewModel;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
public class CommentFilterPreferenceActivity extends BaseActivity {
private ActivityCommentFilterPreferenceBinding binding;
@Inject
@Named("default")
SharedPreferences sharedPreferences;
@Inject
RedditDataRoomDatabase redditDataRoomDatabase;
@Inject
CustomThemeWrapper customThemeWrapper;
@Inject
Executor executor;
public CommentFilterWithUsageViewModel commentFilterWithUsageViewModel;
private CommentFilterWithUsageRecyclerViewAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
((Infinity) getApplication()).getAppComponent().inject(this);
setImmersiveModeNotApplicable();
super.onCreate(savedInstanceState);
binding = ActivityCommentFilterPreferenceBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
ButterKnife.bind(this);
applyCustomTheme();
setSupportActionBar(binding.toolbarCommentFilterPreferenceActivity);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
binding.fabCommentFilterPreferenceActivity.setOnClickListener(view -> {
Intent intent = new Intent(this, CustomizeCommentFilterActivity.class);
intent.putExtra(CustomizeCommentFilterActivity.EXTRA_FROM_SETTINGS, true);
startActivity(intent);
});
adapter = new CommentFilterWithUsageRecyclerViewAdapter(this, commentFilter -> {
CommentFilterOptionsBottomSheetFragment commentFilterOptionsBottomSheetFragment = new CommentFilterOptionsBottomSheetFragment();
Bundle bundle = new Bundle();
bundle.putParcelable(CommentFilterOptionsBottomSheetFragment.EXTRA_POST_FILTER, commentFilter);
commentFilterOptionsBottomSheetFragment.setArguments(bundle);
commentFilterOptionsBottomSheetFragment.show(getSupportFragmentManager(), commentFilterOptionsBottomSheetFragment.getTag());
});
binding.recyclerViewCommentFilterPreferenceActivity.setAdapter(adapter);
commentFilterWithUsageViewModel = new ViewModelProvider(this,
new CommentFilterWithUsageViewModel.Factory(redditDataRoomDatabase)).get(CommentFilterWithUsageViewModel.class);
commentFilterWithUsageViewModel.getCommentFilterWithUsageListLiveData().observe(this, commentFilterWithUsages -> adapter.setCommentFilterWithUsageList(commentFilterWithUsages));
}
public void editCommentFilter(CommentFilter commentFilter) {
Intent intent = new Intent(this, CustomizeCommentFilterActivity.class);
intent.putExtra(CustomizeCommentFilterActivity.EXTRA_COMMENT_FILTER, commentFilter);
intent.putExtra(CustomizeCommentFilterActivity.EXTRA_FROM_SETTINGS, true);
startActivity(intent);
}
public void applyCommentFilterTo(CommentFilter commentFilter) {
Intent intent = new Intent(this, CommentFilterUsageListingActivity.class);
intent.putExtra(CommentFilterUsageListingActivity.EXTRA_COMMENT_FILTER, commentFilter);
startActivity(intent);
}
public void deleteCommentFilter(CommentFilter commentFilter) {
DeleteCommentFilter.deleteCommentFilter(redditDataRoomDatabase, executor, commentFilter);
}
@Override
protected SharedPreferences getDefaultSharedPreferences() {
return sharedPreferences;
}
@Override
protected CustomThemeWrapper getCustomThemeWrapper() {
return customThemeWrapper;
}
@Override
protected void applyCustomTheme() {
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(binding.appbarLayoutCommentFilterPreferenceActivity, binding.collapsingToolbarLayoutCommentFilterPreferenceActivity, binding.toolbarCommentFilterPreferenceActivity);
applyFABTheme(binding.fabCommentFilterPreferenceActivity, sharedPreferences.getBoolean(SharedPreferencesUtils.USE_CIRCULAR_FAB, false));
binding.getRoot().setBackgroundColor(customThemeWrapper.getBackgroundColor());
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
return false;
}
}

View File

@@ -1,181 +0,0 @@
package eu.toldi.infinityforlemmy.activities;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.os.Bundle;
import android.os.Handler;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.lifecycle.ViewModelProvider;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
import java.util.concurrent.Executor;
import javax.inject.Inject;
import javax.inject.Named;
import eu.toldi.infinityforlemmy.Infinity;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
import eu.toldi.infinityforlemmy.bottomsheetfragments.CommentFilterUsageOptionsBottomSheetFragment;
import eu.toldi.infinityforlemmy.bottomsheetfragments.NewCommentFilterUsageBottomSheetFragment;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilter;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilterUsage;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilterUsageViewModel;
import eu.toldi.infinityforlemmy.commentfilter.DeleteCommentFilterUsage;
import eu.toldi.infinityforlemmy.commentfilter.SaveCommentFilterUsage;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.databinding.ActivityCommentFilterUsageListingBinding;
import eu.toldi.infinityforlemmy.adapters.CommentFilterUsageRecyclerViewAdapter;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
import eu.toldi.infinityforlemmy.utils.Utils;
public class CommentFilterUsageListingActivity extends BaseActivity {
public static final String EXTRA_COMMENT_FILTER = "ECF";
@Inject
@Named("default")
SharedPreferences sharedPreferences;
@Inject
RedditDataRoomDatabase redditDataRoomDatabase;
@Inject
CustomThemeWrapper customThemeWrapper;
@Inject
Executor executor;
private ActivityCommentFilterUsageListingBinding binding;
public CommentFilterUsageViewModel commentFilterUsageViewModel;
private CommentFilterUsageRecyclerViewAdapter adapter;
private CommentFilter commentFilter;
@Override
protected void onCreate(Bundle savedInstanceState) {
((Infinity) getApplication()).getAppComponent().inject(this);
setImmersiveModeNotApplicable();
super.onCreate(savedInstanceState);
binding = ActivityCommentFilterUsageListingBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
applyCustomTheme();
setSupportActionBar(binding.toolbarCommentFilterUsageListingActivity);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
commentFilter = getIntent().getParcelableExtra(EXTRA_COMMENT_FILTER);
setTitle(commentFilter.name);
binding.fabCommentFilterUsageListingActivity.setOnClickListener(view -> {
NewCommentFilterUsageBottomSheetFragment newCommentFilterUsageBottomSheetFragment = new NewCommentFilterUsageBottomSheetFragment();
newCommentFilterUsageBottomSheetFragment.show(getSupportFragmentManager(), newCommentFilterUsageBottomSheetFragment.getTag());
});
adapter = new CommentFilterUsageRecyclerViewAdapter(this, customThemeWrapper, commentFilterUsage -> {
CommentFilterUsageOptionsBottomSheetFragment commentFilterUsageOptionsBottomSheetFragment = new CommentFilterUsageOptionsBottomSheetFragment();
Bundle bundle = new Bundle();
bundle.putParcelable(CommentFilterUsageOptionsBottomSheetFragment.EXTRA_COMMENT_FILTER_USAGE, commentFilterUsage);
commentFilterUsageOptionsBottomSheetFragment.setArguments(bundle);
commentFilterUsageOptionsBottomSheetFragment.show(getSupportFragmentManager(), commentFilterUsageOptionsBottomSheetFragment.getTag());
});
binding.recyclerViewCommentFilterUsageListingActivity.setAdapter(adapter);
commentFilterUsageViewModel = new ViewModelProvider(this,
new CommentFilterUsageViewModel.Factory(redditDataRoomDatabase, commentFilter.name)).get(CommentFilterUsageViewModel.class);
commentFilterUsageViewModel.getCommentFilterUsageListLiveData().observe(this, commentFilterUsages -> adapter.setCommentFilterUsages(commentFilterUsages));
}
public void newCommentFilterUsage(int type) {
switch (type) {
case CommentFilterUsage.SUBREDDIT_TYPE:
editAndCommentFilterUsageNameOfUsage(type, null);
break;
}
}
private void editAndCommentFilterUsageNameOfUsage(int type, String nameOfUsage) {
View dialogView = getLayoutInflater().inflate(R.layout.dialog_edit_post_or_comment_filter_name_of_usage, null);
TextView messageTextView = dialogView.findViewById(R.id.message_text_view_edit_post_or_comment_filter_name_of_usage_dialog);
messageTextView.setVisibility(View.GONE);
TextInputLayout textInputLayout = dialogView.findViewById(R.id.text_input_layout_edit_post_or_comment_filter_name_of_usage_dialog);
TextInputEditText textInputEditText = dialogView.findViewById(R.id.text_input_edit_text_edit_post_or_comment_filter_name_of_usage_dialog);
int primaryTextColor = customThemeWrapper.getPrimaryTextColor();
textInputLayout.setBoxStrokeColor(primaryTextColor);
textInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
textInputEditText.setTextColor(primaryTextColor);
if (nameOfUsage != null) {
textInputEditText.setText(nameOfUsage);
}
textInputEditText.requestFocus();
int titleStringId = R.string.community;
switch (type) {
case CommentFilterUsage.SUBREDDIT_TYPE:
textInputEditText.setHint(R.string.settings_tab_community_name);
break;
}
Utils.showKeyboard(this, new Handler(), textInputEditText);
new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
.setTitle(titleStringId)
.setView(dialogView)
.setPositiveButton(R.string.ok, (editTextDialogInterface, i1)
-> {
Utils.hideKeyboard(this);
CommentFilterUsage commentFilterUsage;
if (!textInputEditText.getText().toString().equals("")) {
commentFilterUsage = new CommentFilterUsage(commentFilter.name, type, textInputEditText.getText().toString());
SaveCommentFilterUsage.saveCommentFilterUsage(redditDataRoomDatabase, executor, commentFilterUsage);
}
})
.setNegativeButton(R.string.cancel, null)
.setOnDismissListener(editTextDialogInterface -> {
Utils.hideKeyboard(this);
})
.show();
}
public void editCommentFilterUsage(CommentFilterUsage commentFilterUsage) {
editAndCommentFilterUsageNameOfUsage(commentFilterUsage.usage, commentFilterUsage.nameOfUsage);
}
public void deleteCommentFilterUsage(CommentFilterUsage commentFilterUsage) {
DeleteCommentFilterUsage.deleteCommentFilterUsage(redditDataRoomDatabase, executor, commentFilterUsage);
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
return false;
}
@Override
protected SharedPreferences getDefaultSharedPreferences() {
return sharedPreferences;
}
@Override
protected CustomThemeWrapper getCustomThemeWrapper() {
return customThemeWrapper;
}
@Override
protected void applyCustomTheme() {
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(binding.appbarLayoutCommentFilterUsageListingActivity, binding.collapsingToolbarLayoutCommentFilterUsageListingActivity, binding.toolbarCommentFilterUsageListingActivity);
applyFABTheme(binding.fabCommentFilterUsageListingActivity, sharedPreferences.getBoolean(SharedPreferencesUtils.USE_CIRCULAR_FAB, false));
binding.getRoot().setBackgroundColor(customThemeWrapper.getBackgroundColor());
}
}

View File

@@ -1,302 +0,0 @@
package eu.toldi.infinityforlemmy.activities;
import android.app.Activity;
import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.concurrent.Executor;
import java.util.regex.PatternSyntaxException;
import javax.inject.Inject;
import javax.inject.Named;
import eu.toldi.infinityforlemmy.Infinity;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilter;
import eu.toldi.infinityforlemmy.commentfilter.SaveCommentFilter;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.databinding.ActivityCustomizeCommentFilterBinding;
import eu.toldi.infinityforlemmy.utils.Utils;
public class CustomizeCommentFilterActivity extends BaseActivity {
public static final String EXTRA_COMMENT_FILTER = "ECF";
public static final String EXTRA_FROM_SETTINGS = "EFS";
public static final String RETURN_EXTRA_COMMENT_FILTER = "RECF";
private static final String COMMENT_FILTER_STATE = "CFS";
private static final String ORIGINAL_NAME_STATE = "ONS";
@Inject
RedditDataRoomDatabase mRedditDataRoomDatabase;
@Inject
@Named("default")
SharedPreferences mSharedPreferences;
@Inject
@Named("current_account")
SharedPreferences currentAccountSharedPreferences;
@Inject
CustomThemeWrapper mCustomThemeWrapper;
@Inject
Executor mExecutor;
private CommentFilter commentFilter;
private boolean fromSettings;
private String originalName;
private ActivityCustomizeCommentFilterBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
((Infinity) getApplication()).getAppComponent().inject(this);
setImmersiveModeNotApplicable();
super.onCreate(savedInstanceState);
binding = ActivityCustomizeCommentFilterBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
applyCustomTheme();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) {
addOnOffsetChangedListener(binding.appbarLayoutCustomizeCommentFilterActivity);
}
setSupportActionBar(binding.toolbarCustomizeCommentFilterActivity);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setToolbarGoToTop(binding.toolbarCustomizeCommentFilterActivity);
ActivityResultLauncher<Intent> requestAddUsersLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
Intent data = result.getData();
if (data == null) {
return;
}
ArrayList<String> usernames = data.getStringArrayListExtra(SearchActivity.RETURN_EXTRA_SELECTED_USERNAMES);
String currentUsers = binding.excludeUsersTextInputEditTextCustomizeCommentFilterActivity.getText().toString().trim();
if (usernames != null && !usernames.isEmpty()) {
if (!currentUsers.isEmpty() && currentUsers.charAt(currentUsers.length() - 1) != ',') {
String newString = currentUsers + ",";
binding.excludeUsersTextInputEditTextCustomizeCommentFilterActivity.setText(newString);
}
StringBuilder stringBuilder = new StringBuilder();
for (String s : usernames) {
stringBuilder.append(s).append(",");
}
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
binding.excludeUsersTextInputEditTextCustomizeCommentFilterActivity.append(stringBuilder.toString());
}
});
binding.addUsersImageViewCustomizeCommentFilterActivity.setOnClickListener(view -> {
Intent intent = new Intent(this, SearchActivity.class);
intent.putExtra(SearchActivity.EXTRA_SEARCH_ONLY_USERS, true);
intent.putExtra(SearchActivity.EXTRA_IS_MULTI_SELECTION, true);
requestAddUsersLauncher.launch(intent);
});
fromSettings = getIntent().getBooleanExtra(EXTRA_FROM_SETTINGS, false);
if (savedInstanceState != null) {
commentFilter = savedInstanceState.getParcelable(COMMENT_FILTER_STATE);
originalName = savedInstanceState.getString(ORIGINAL_NAME_STATE);
} else {
commentFilter = getIntent().getParcelableExtra(EXTRA_COMMENT_FILTER);
if (commentFilter == null) {
commentFilter = new CommentFilter();
originalName = "";
} else {
if (!fromSettings) {
originalName = "";
} else {
originalName = commentFilter.name;
}
}
bindView();
}
}
private void bindView() {
binding.nameTextInputEditTextCustomizeCommentFilterActivity.setText(commentFilter.name);
binding.excludeStringsTextInputEditTextCustomizeCommentFilterActivity.setText(commentFilter.excludeStrings);
binding.excludeUsersTextInputEditTextCustomizeCommentFilterActivity.setText(commentFilter.excludeUsers);
binding.minVoteTextInputEditTextCustomizeCommentFilterActivity.setText(Integer.toString(commentFilter.minVote));
binding.maxVoteTextInputEditTextCustomizeCommentFilterActivity.setText(Integer.toString(commentFilter.maxVote));
}
@Override
protected SharedPreferences getDefaultSharedPreferences() {
return mSharedPreferences;
}
@Override
protected CustomThemeWrapper getCustomThemeWrapper() {
return mCustomThemeWrapper;
}
@Override
protected void applyCustomTheme() {
binding.getRoot().setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(binding.appbarLayoutCustomizeCommentFilterActivity, binding.collapsingToolbarLayoutCustomizeCommentFilterActivity, binding.toolbarCustomizeCommentFilterActivity);
int primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor();
int primaryIconColor = mCustomThemeWrapper.getPrimaryIconColor();
Drawable cursorDrawable = Utils.getTintedDrawable(this, R.drawable.edit_text_cursor, primaryTextColor);
binding.nameTextInputLayoutCustomizeCommentFilterActivity.setBoxStrokeColor(primaryTextColor);
binding.nameTextInputLayoutCustomizeCommentFilterActivity.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
binding.nameTextInputEditTextCustomizeCommentFilterActivity.setTextColor(primaryTextColor);
binding.excludeStringsTextInputLayoutCustomizeCommentFilterActivity.setBoxStrokeColor(primaryTextColor);
binding.excludeStringsTextInputLayoutCustomizeCommentFilterActivity.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
binding.excludeStringsTextInputEditTextCustomizeCommentFilterActivity.setTextColor(primaryTextColor);
binding.excludeUsersTextInputLayoutCustomizeCommentFilterActivity.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
binding.excludeUsersTextInputEditTextCustomizeCommentFilterActivity.setTextColor(primaryTextColor);
binding.addUsersImageViewCustomizeCommentFilterActivity.setImageDrawable(Utils.getTintedDrawable(this, R.drawable.ic_add_24dp, primaryIconColor));
binding.minVoteTextInputLayoutCustomizeCommentFilterActivity.setBoxStrokeColor(primaryTextColor);
binding.minVoteTextInputLayoutCustomizeCommentFilterActivity.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
binding.minVoteTextInputEditTextCustomizeCommentFilterActivity.setTextColor(primaryTextColor);
binding.maxVoteTextInputLayoutCustomizeCommentFilterActivity.setBoxStrokeColor(primaryTextColor);
binding.maxVoteTextInputLayoutCustomizeCommentFilterActivity.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
binding.maxVoteTextInputEditTextCustomizeCommentFilterActivity.setTextColor(primaryTextColor);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
binding.nameTextInputEditTextCustomizeCommentFilterActivity.setTextCursorDrawable(cursorDrawable);
binding.excludeStringsTextInputEditTextCustomizeCommentFilterActivity.setTextCursorDrawable(cursorDrawable);
binding.excludeUsersTextInputEditTextCustomizeCommentFilterActivity.setTextCursorDrawable(cursorDrawable);
binding.minVoteTextInputEditTextCustomizeCommentFilterActivity.setTextCursorDrawable(cursorDrawable);
binding.maxVoteTextInputEditTextCustomizeCommentFilterActivity.setTextCursorDrawable(cursorDrawable);
} else {
setCursorDrawableColor(binding.nameTextInputEditTextCustomizeCommentFilterActivity, primaryTextColor);
setCursorDrawableColor(binding.excludeStringsTextInputEditTextCustomizeCommentFilterActivity, primaryTextColor);
setCursorDrawableColor(binding.excludeUsersTextInputEditTextCustomizeCommentFilterActivity, primaryTextColor);
setCursorDrawableColor(binding.minVoteTextInputEditTextCustomizeCommentFilterActivity, primaryTextColor);
setCursorDrawableColor(binding.maxVoteTextInputEditTextCustomizeCommentFilterActivity, primaryTextColor);
}
if (typeface != null) {
Utils.setFontToAllTextViews(binding.getRoot(), typeface);
}
}
public void setCursorDrawableColor(EditText editText, int color) {
try {
Field fCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes");
fCursorDrawableRes.setAccessible(true);
int mCursorDrawableRes = fCursorDrawableRes.getInt(editText);
Field fEditor = TextView.class.getDeclaredField("mEditor");
fEditor.setAccessible(true);
Object editor = fEditor.get(editText);
Class<?> clazz = editor.getClass();
Field fCursorDrawable = clazz.getDeclaredField("mCursorDrawable");
fCursorDrawable.setAccessible(true);
Drawable[] drawables = new Drawable[2];
drawables[0] = editText.getContext().getResources().getDrawable(mCursorDrawableRes);
drawables[1] = editText.getContext().getResources().getDrawable(mCursorDrawableRes);
drawables[0].setColorFilter(color, PorterDuff.Mode.SRC_IN);
drawables[1].setColorFilter(color, PorterDuff.Mode.SRC_IN);
fCursorDrawable.set(editor, drawables);
} catch (Throwable ignored) {
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.customize_comment_filter_activity, menu);
if (fromSettings) {
menu.findItem(R.id.action_save_customize_comment_filter_activity).setVisible(false);
}
applyMenuItemTheme(menu);
return true;
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
} else if (item.getItemId() == R.id.action_save_customize_comment_filter_activity) {
try {
constructCommentFilter();
Intent returnIntent = new Intent();
returnIntent.putExtra(RETURN_EXTRA_COMMENT_FILTER, commentFilter);
setResult(Activity.RESULT_OK, returnIntent);
finish();
} catch (PatternSyntaxException e) {
Toast.makeText(this, R.string.invalid_regex, Toast.LENGTH_SHORT).show();
}
return true;
} else if (item.getItemId() == R.id.action_save_to_database_customize_comment_filter_activity) {
try {
constructCommentFilter();
if (!commentFilter.name.equals("")) {
saveCommentFilter(originalName);
} else {
Toast.makeText(CustomizeCommentFilterActivity.this, R.string.comment_filter_requires_a_name, Toast.LENGTH_LONG).show();
}
} catch (PatternSyntaxException e) {
Toast.makeText(this, R.string.invalid_regex, Toast.LENGTH_SHORT).show();
}
}
return false;
}
private void saveCommentFilter(String originalName) {
SaveCommentFilter.saveCommentFilter(mExecutor, new Handler(), mRedditDataRoomDatabase, commentFilter, originalName,
new SaveCommentFilter.SaveCommentFilterListener() {
@Override
public void success() {
Intent returnIntent = new Intent();
returnIntent.putExtra(RETURN_EXTRA_COMMENT_FILTER, commentFilter);
setResult(Activity.RESULT_OK, returnIntent);
finish();
}
@Override
public void duplicate() {
new MaterialAlertDialogBuilder(CustomizeCommentFilterActivity.this, R.style.MaterialAlertDialogTheme)
.setTitle(getString(R.string.duplicate_comment_filter_dialog_title, commentFilter.name))
.setMessage(R.string.duplicate_comment_filter_dialog_message)
.setPositiveButton(R.string.override, (dialogInterface, i) -> saveCommentFilter(commentFilter.name))
.setNegativeButton(R.string.cancel, null)
.show();
}
});
}
private void constructCommentFilter() throws PatternSyntaxException {
commentFilter.name = binding.nameTextInputEditTextCustomizeCommentFilterActivity.getText().toString();
commentFilter.excludeStrings = binding.excludeStringsTextInputEditTextCustomizeCommentFilterActivity.getText().toString();
commentFilter.excludeUsers = binding.excludeUsersTextInputEditTextCustomizeCommentFilterActivity.getText().toString();
commentFilter.maxVote = binding.maxVoteTextInputEditTextCustomizeCommentFilterActivity.getText() == null || binding.maxVoteTextInputEditTextCustomizeCommentFilterActivity.getText().toString().equals("") ? -1 : Integer.parseInt(binding.maxVoteTextInputEditTextCustomizeCommentFilterActivity.getText().toString());
commentFilter.minVote = binding.minVoteTextInputEditTextCustomizeCommentFilterActivity.getText() == null || binding.minVoteTextInputEditTextCustomizeCommentFilterActivity.getText().toString().equals("") ? -1 : Integer.parseInt(binding.minVoteTextInputEditTextCustomizeCommentFilterActivity.getText().toString());
}
@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putParcelable(COMMENT_FILTER_STATE, commentFilter);
outState.putString(ORIGINAL_NAME_STATE, originalName);
}
}

View File

@@ -226,6 +226,10 @@ public class CustomizePostFilterActivity extends BaseActivity {
applyCustomTheme();
if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK, true)) {
Slidr.attach(this);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) {
addOnOffsetChangedListener(appBarLayout);
}

View File

@@ -139,7 +139,7 @@ public class FullMarkdownActivity extends BaseActivity {
}
};
Markwon markwon = MarkdownUtils.createFullRedditMarkwon(this,
miscPlugin, markdownColor, spoilerBackgroundColor, null, mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false));
miscPlugin, markdownColor, spoilerBackgroundColor, null);
MarkwonAdapter markwonAdapter = MarkdownUtils.createTablesAdapter();
LinearLayoutManagerBugFixed linearLayoutManager = new SwipeLockLinearLayoutManager(this, new SwipeLockInterface() {

View File

@@ -0,0 +1,336 @@
package eu.toldi.infinityforlemmy.activities;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.google.android.material.tabs.TabLayout;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import javax.inject.Inject;
import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import eu.toldi.infinityforlemmy.ActivityToolbarInterface;
import eu.toldi.infinityforlemmy.Infinity;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.bottomsheetfragments.PostLayoutBottomSheetFragment;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.customviews.slidr.Slidr;
import eu.toldi.infinityforlemmy.events.ChangeNSFWEvent;
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
import eu.toldi.infinityforlemmy.fragments.CommentsListingFragment;
import eu.toldi.infinityforlemmy.fragments.HistoryPostFragment;
import eu.toldi.infinityforlemmy.fragments.PostFragment;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
public class HistoryActivity extends BaseActivity implements ActivityToolbarInterface,
PostLayoutBottomSheetFragment.PostLayoutSelectionCallback {
@BindView(R.id.coordinator_layout_history_activity)
CoordinatorLayout coordinatorLayout;
@BindView(R.id.appbar_layout_history_activity)
AppBarLayout appBarLayout;
@BindView(R.id.collapsing_toolbar_layout_history_activity)
CollapsingToolbarLayout collapsingToolbarLayout;
@BindView(R.id.toolbar_history_activity)
Toolbar toolbar;
@BindView(R.id.tab_layout_tab_layout_history_activity_activity)
TabLayout tabLayout;
@BindView(R.id.view_pager_history_activity)
ViewPager2 viewPager2;
@Inject
@Named("default")
SharedPreferences mSharedPreferences;
@Inject
@Named("post_layout")
SharedPreferences mPostLayoutSharedPreferences;
@Inject
@Named("current_account")
SharedPreferences mCurrentAccountSharedPreferences;
@Inject
CustomThemeWrapper mCustomThemeWrapper;
private FragmentManager fragmentManager;
private SectionsPagerAdapter sectionsPagerAdapter;
private String mAccessToken;
private String mAccountName;
@Override
protected void onCreate(Bundle savedInstanceState) {
((Infinity) getApplication()).getAppComponent().inject(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
ButterKnife.bind(this);
EventBus.getDefault().register(this);
applyCustomTheme();
if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK, true)) {
mSliderPanel = Slidr.attach(this);
}
//mViewPager2 = viewPager2;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Window window = getWindow();
if (isChangeStatusBarIconColor()) {
addOnOffsetChangedListener(appBarLayout);
}
if (isImmersiveInterface()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
window.setDecorFitsSystemWindows(false);
} else {
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
adjustToolbar(toolbar);
}
}
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setToolbarGoToTop(toolbar);
fragmentManager = getSupportFragmentManager();
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
initializeViewPager();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (sectionsPagerAdapter != null) {
return sectionsPagerAdapter.handleKeyDown(keyCode) || super.onKeyDown(keyCode, event);
}
return super.onKeyDown(keyCode, event);
}
@Override
public SharedPreferences getDefaultSharedPreferences() {
return mSharedPreferences;
}
@Override
protected CustomThemeWrapper getCustomThemeWrapper() {
return mCustomThemeWrapper;
}
@Override
protected void applyCustomTheme() {
coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar);
applyTabLayoutTheme(tabLayout);
}
private void initializeViewPager() {
sectionsPagerAdapter = new SectionsPagerAdapter(this);
tabLayout.setVisibility(View.GONE);
viewPager2.setAdapter(sectionsPagerAdapter);
viewPager2.setOffscreenPageLimit(2);
//viewPager2.setUserInputEnabled(!mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_SWIPING_BETWEEN_TABS, false));
viewPager2.setUserInputEnabled(false);
/*new TabLayoutMediator(tabLayout, viewPager2, (tab, position) -> {
switch (position) {
case 0:
Utils.setTitleWithCustomFontToTab(typeface, tab, getString(R.string.posts));
break;
}
}).attach();*/
viewPager2.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
@Override
public void onPageSelected(int position) {
if (position == 0) {
unlockSwipeRightToGoBack();
} else {
lockSwipeRightToGoBack();
}
}
});
fixViewPager2Sensitivity(viewPager2);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.history_activity, menu);
applyMenuItemTheme(menu);
return true;
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
int itemId = item.getItemId();
if (itemId == android.R.id.home) {
finish();
return true;
} else if (itemId == R.id.action_refresh_history_activity) {
sectionsPagerAdapter.refresh();
return true;
} else if (itemId == R.id.action_change_post_layout_history_activity) {
PostLayoutBottomSheetFragment postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
return true;
}
return false;
}
@Override
protected void onDestroy() {
super.onDestroy();
EventBus.getDefault().unregister(this);
}
@Subscribe
public void onAccountSwitchEvent(SwitchAccountEvent event) {
finish();
}
@Subscribe
public void onChangeNSFWEvent(ChangeNSFWEvent changeNSFWEvent) {
sectionsPagerAdapter.changeNSFW(changeNSFWEvent.nsfw);
}
@Override
public void onLongPress() {
if (sectionsPagerAdapter != null) {
sectionsPagerAdapter.goBackToTop();
}
}
@Override
public void lockSwipeRightToGoBack() {
if (mSliderPanel != null) {
mSliderPanel.lock();
}
}
@Override
public void unlockSwipeRightToGoBack() {
if (mSliderPanel != null) {
mSliderPanel.unlock();
}
}
@Override
public void postLayoutSelected(int postLayout) {
if (sectionsPagerAdapter != null) {
mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.HISTORY_POST_LAYOUT_READ_POST, postLayout).apply();
sectionsPagerAdapter.changePostLayout(postLayout);
}
}
private class SectionsPagerAdapter extends FragmentStateAdapter {
SectionsPagerAdapter(FragmentActivity fa) {
super(fa);
}
@NonNull
@Override
public Fragment createFragment(int position) {
if (position == 0) {
HistoryPostFragment fragment = new HistoryPostFragment();
Bundle bundle = new Bundle();
bundle.putInt(HistoryPostFragment.EXTRA_HISTORY_TYPE, HistoryPostFragment.HISTORY_TYPE_READ_POSTS);
bundle.putString(HistoryPostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(HistoryPostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
fragment.setArguments(bundle);
return fragment;
} else {
HistoryPostFragment fragment = new HistoryPostFragment();
Bundle bundle = new Bundle();
bundle.putInt(HistoryPostFragment.EXTRA_HISTORY_TYPE, HistoryPostFragment.HISTORY_TYPE_READ_POSTS);
bundle.putString(HistoryPostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(HistoryPostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
fragment.setArguments(bundle);
return fragment;
}
}
@Nullable
private Fragment getCurrentFragment() {
if (viewPager2 == null || fragmentManager == null) {
return null;
}
return fragmentManager.findFragmentByTag("f" + viewPager2.getCurrentItem());
}
public boolean handleKeyDown(int keyCode) {
if (viewPager2.getCurrentItem() == 0) {
Fragment fragment = getCurrentFragment();
if (fragment instanceof PostFragment) {
return ((PostFragment) fragment).handleKeyDown(keyCode);
}
}
return false;
}
public void refresh() {
Fragment fragment = getCurrentFragment();
if (fragment instanceof PostFragment) {
((PostFragment) fragment).refresh();
} else if (fragment instanceof CommentsListingFragment) {
((CommentsListingFragment) fragment).refresh();
}
}
public void changeNSFW(boolean nsfw) {
Fragment fragment = getCurrentFragment();
if (fragment instanceof PostFragment) {
((PostFragment) fragment).changeNSFW(nsfw);
}
}
public void changePostLayout(int postLayout) {
Fragment fragment = getCurrentFragment();
if (fragment instanceof HistoryPostFragment) {
((HistoryPostFragment) fragment).changePostLayout(postLayout);
}
}
public void goBackToTop() {
Fragment fragment = getCurrentFragment();
if (fragment instanceof PostFragment) {
((PostFragment) fragment).goBackToTop();
} else if (fragment instanceof CommentsListingFragment) {
((CommentsListingFragment) fragment).goBackToTop();
}
}
@Override
public int getItemCount() {
return 1;
}
}
}

View File

@@ -149,7 +149,7 @@ public class InstanceInfoActivity extends BaseActivity {
};
mPostDetailMarkwon = MarkdownUtils.createFullRedditMarkwon(this,
miscPlugin, markdownColor, postSpoilerBackgroundColor, null, mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false));
miscPlugin, markdownColor, postSpoilerBackgroundColor, null);
mMarkwonAdapter = MarkdownUtils.createTablesAdapter();
mContentMarkdownView.setAdapter(mMarkwonAdapter);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);

View File

@@ -342,6 +342,64 @@ public class LinkResolverActivity extends AppCompatActivity {
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_V_REDD_IT);
intent.putExtra(ViewVideoActivity.EXTRA_V_REDD_IT_URL, uri.toString());
startActivity(intent);
} else if (authority.contains("reddit.com") || authority.contains("redd.it") || authority.contains("reddit.app")) {
if (authority.equals("reddit.app.link") && path.isEmpty()) {
String redirect = uri.getQueryParameter("$og_redirect");
if (redirect != null) {
handleUri(Uri.parse(redirect));
} else {
deepLinkError(uri);
}
} else if (path.isEmpty()) {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
} else if (path.equals("/report")) {
openInWebView(uri);
} else if (path.matches(POST_PATTERN_3)) {
Intent intent = new Intent(this, ViewPostDetailActivity.class);
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, path.substring(1));
intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname);
intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName);
startActivity(intent);
} else if (path.matches(WIKI_PATTERN)) {
String[] pathSegments = path.split("/");
String wikiPage;
if (pathSegments.length == 4) {
wikiPage = "index";
} else {
int lengthThroughWiki = 0;
for (int i = 1; i <= 3; ++i) {
lengthThroughWiki += pathSegments[i].length() + 1;
}
wikiPage = path.substring(lengthThroughWiki);
}
Intent intent = new Intent(this, WikiActivity.class);
intent.putExtra(WikiActivity.EXTRA_SUBREDDIT_NAME, segments.get(1));
intent.putExtra(WikiActivity.EXTRA_WIKI_PATH, wikiPage);
startActivity(intent);
} else if (path.matches(SIDEBAR_PATTERN)) {
Intent intent = new Intent(this, ViewSubredditDetailActivity.class);
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, path.substring(3, path.length() - 14));
intent.putExtra(ViewSubredditDetailActivity.EXTRA_VIEW_SIDEBAR, true);
startActivity(intent);
} else if (path.matches(MULTIREDDIT_PATTERN)) {
Intent intent = new Intent(this, ViewMultiRedditDetailActivity.class);
intent.putExtra(ViewMultiRedditDetailActivity.EXTRA_MULTIREDDIT_PATH, path);
startActivity(intent);
} else if (path.matches(MULTIREDDIT_PATTERN_2)) {
String subredditName = path.substring(3);
Intent intent = new Intent(this, ViewSubredditDetailActivity.class);
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, subredditName);
intent.putExtra(ViewSubredditDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname);
intent.putExtra(ViewSubredditDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName);
startActivity(intent);
} else if (authority.equals("redd.it") && path.matches(REDD_IT_POST_PATTERN)) {
Intent intent = new Intent(this, ViewPostDetailActivity.class);
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, path.substring(1));
startActivity(intent);
} else {
deepLinkError(uri);
}
} else if (authority.equals("click.redditmail.com")) {
if (path.startsWith("/CL0/")) {
handleUri(Uri.parse(path.substring("/CL0/".length())));
@@ -430,7 +488,7 @@ public class LinkResolverActivity extends AppCompatActivity {
String authority = uri.getAuthority();
if(authority != null && (authority.contains("reddit.com") || authority.contains("redd.it") || authority.contains("reddit.app.link"))) {
openInBrowser(uri, pm, false);
openInCustomTabs(uri, pm, false);
return;
}

View File

@@ -10,14 +10,12 @@ import android.text.Editable;
import android.util.Log;
import android.view.InflateException;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatAutoCompleteTextView;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
@@ -30,8 +28,6 @@ import org.json.JSONObject;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;
import javax.inject.Inject;
@@ -44,15 +40,11 @@ import eu.toldi.infinityforlemmy.Infinity;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
import eu.toldi.infinityforlemmy.RetrofitHolder;
import eu.toldi.infinityforlemmy.adapters.CustomArrayAdapter;
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
import eu.toldi.infinityforlemmy.asynctasks.ParseAndInsertNewAccount;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.customviews.slidr.Slidr;
import eu.toldi.infinityforlemmy.dto.AccountLoginDTO;
import eu.toldi.infinityforlemmy.lemmyverse.FetchInstancesListener;
import eu.toldi.infinityforlemmy.lemmyverse.LemmyInstance;
import eu.toldi.infinityforlemmy.lemmyverse.LemmyVerseFetchInstances;
import eu.toldi.infinityforlemmy.site.FetchSiteInfo;
import eu.toldi.infinityforlemmy.site.SiteInfo;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
@@ -67,9 +59,6 @@ public class LoginActivity extends BaseActivity {
private static final String ENABLE_DOM_STATE = "EDS";
private static final String IS_AGREE_TO_USER_AGGREMENT_STATE = "IATUAS";
public static final String EXTRA_INPUT_USERNAME = "INPUT_USERNAME";
public static final String EXTRA_INPUT_INSTANCE = "INPUT_INSTANCE";
@BindView(R.id.coordinator_layout_login_activity)
CoordinatorLayout coordinatorLayout;
@BindView(R.id.appbar_layout_login_activity)
@@ -80,7 +69,7 @@ public class LoginActivity extends BaseActivity {
TextView twoFAInfoTextView;
@BindView(R.id.instance_url_input)
AppCompatAutoCompleteTextView instance_input;
TextInputEditText instance_input;
@BindView(R.id.username_input)
TextInputEditText username_input;
@BindView(R.id.user_password_input)
@@ -97,11 +86,9 @@ public class LoginActivity extends BaseActivity {
@Inject
@Named("no_oauth")
RetrofitHolder mRetrofit;
@Inject
@Named("lemmyVerse")
Retrofit mLemmyVerseRetrofit;
@Named("oauth")
Retrofit mOauthRetrofit;
@Inject
RedditDataRoomDatabase mRedditDataRoomDatabase;
@Inject
@@ -152,34 +139,9 @@ public class LoginActivity extends BaseActivity {
isAgreeToUserAgreement = savedInstanceState.getBoolean(IS_AGREE_TO_USER_AGGREMENT_STATE);
}
// Get username and instance from intent
Intent intent = getIntent();
String username_intent = intent.getStringExtra(EXTRA_INPUT_USERNAME);
String instance_intent = intent.getStringExtra(EXTRA_INPUT_INSTANCE);
if (username_intent != null) {
username_input.setText(username_intent);
}
if (instance_intent != null) {
instance_input.setText(instance_intent);
}
LemmyVerseFetchInstances.INSTANCE.fetchInstances(mLemmyVerseRetrofit, new FetchInstancesListener() {
@Override
public void onFetchInstancesSuccess(@NonNull List<LemmyInstance> instances) {
ArrayList<String> instanceNames = new ArrayList<>();
for (LemmyInstance instance : instances) {
instanceNames.add(instance.getFqdn());
}
ArrayAdapter<String> adapter = new CustomArrayAdapter(LoginActivity.this, android.R.layout.simple_dropdown_item_1line, instanceNames, mCustomThemeWrapper);
instance_input.setAdapter(adapter);
}
});
loginButton.setOnClickListener(view -> {
Log.i("LoginActivity", "Login button clicked");
if (!checkFields())
if(!checkFields())
return;
loginButton.setEnabled(false);
progressBar.setVisibility(ProgressBar.VISIBLE);
@@ -376,7 +338,6 @@ public class LoginActivity extends BaseActivity {
if (typeface != null) {
twoFAInfoTextView.setTypeface(typeface);
}
instance_input.setTextColor(mCustomThemeWrapper.getPrimaryTextColor());
}
@Override

View File

@@ -33,7 +33,6 @@ import androidx.appcompat.app.AppCompatDelegate;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.splashscreen.SplashScreen;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
@@ -248,12 +247,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
private int fabOption;
private int inboxCount;
private boolean mBearerTokenUsed = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.installSplashScreen(this);
((Infinity) getApplication()).getAppComponent().inject(this);
setTheme(R.style.AppTheme_NoActionBarWithTransparentStatusBar);
@@ -341,8 +336,9 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
fragmentManager = getSupportFragmentManager();
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
mRetrofit.setAccessToken(mAccessToken);
mBearerTokenUsed = mCurrentAccountSharedPreferences.getBoolean(SharedPreferencesUtils.BEARER_TOKEN_AUTH, true);
if (mCurrentAccountSharedPreferences.getBoolean(SharedPreferencesUtils.BEARER_TOKEN_AUTH, true)) {
mRetrofit.setAccessToken(mAccessToken);
}
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
mAccountQualifiedName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
@@ -376,8 +372,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
mRetrofit.setBaseURL(instancePreference);
this.recreate();
}
} else {
checkUserToken();
}
}
@@ -830,6 +824,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
} else if (stringId == R.string.multi_reddit) {
intent = new Intent(MainActivity.this, SubscribedThingListingActivity.class);
intent.putExtra(SubscribedThingListingActivity.EXTRA_SHOW_MULTIREDDITS, true);
} else if (stringId == R.string.history) {
intent = new Intent(MainActivity.this, HistoryActivity.class);
} else if (stringId == R.string.trending) {
intent = new Intent(MainActivity.this, TrendingActivity.class);
} else if (stringId == R.string.upvoted) {
@@ -931,7 +927,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
sectionsPagerAdapter = new SectionsPagerAdapter(this, tabCount, mShowFavoriteMultiReddits,
mShowMultiReddits, mShowFavoriteSubscribedSubreddits, mShowSubscribedSubreddits);
viewPager2.setAdapter(sectionsPagerAdapter);
viewPager2.setOffscreenPageLimit(ViewPager2.OFFSCREEN_PAGE_LIMIT_DEFAULT);
viewPager2.setOffscreenPageLimit(1);
viewPager2.setUserInputEnabled(!mDisableSwipingBetweenTabs);
if (mMainActivityTabsSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_TAB_NAMES, true)) {
if (mShowFavoriteMultiReddits || mShowMultiReddits || mShowFavoriteSubscribedSubreddits || mShowSubscribedSubreddits) {
@@ -1085,34 +1081,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
}
}
private void checkUserToken() {
if (mBearerTokenUsed) {
FetchUserData.validateAuthToken(mRetrofit.getRetrofit(), new FetchUserData.ValidateAuthTokenListener() {
@Override
public void onValidateAuthTokenSuccess() {
}
@Override
public void onValidateAuthTokenFailed() {
// Alert user that the token is invalid and they need to re-login
new MaterialAlertDialogBuilder(MainActivity.this, R.style.MaterialAlertDialogTheme)
.setTitle(R.string.token_expired)
.setMessage(R.string.token_expired_message)
.setPositiveButton(R.string.ok, (dialogInterface, i) -> {
Intent intent = new Intent(MainActivity.this, LoginActivity.class);
// Username without instance
String username = mAccountName.substring(0, mAccountQualifiedName.indexOf("@"));
intent.putExtra(LoginActivity.EXTRA_INPUT_USERNAME, username);
intent.putExtra(LoginActivity.EXTRA_INPUT_INSTANCE, mRetrofit.getBaseURL());
startActivity(intent);
})
.setCancelable(false)
.show();
}
});
}
}
private void loadUserData() {
if (!mFetchUserInfoSuccess) {
FetchUserData.fetchUnreadCount(mRetrofit.getRetrofit(), mAccessToken, new FetchUserData.FetchUserUnreadCountListener() {
@@ -1698,7 +1666,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
}
public void doNotShowRedditAPIInfoAgain() {
mInternalSharedPreferences.edit().putBoolean(SharedPreferencesUtils.DO_NOT_SHOW_REDDIT_API_INFO_V2_AGAIN, true).apply();
mInternalSharedPreferences.edit().putBoolean(SharedPreferencesUtils.DO_NOT_SHOW_REDDIT_API_INFO_AGAIN, true).apply();
}
private class SectionsPagerAdapter extends FragmentStateAdapter {

View File

@@ -8,7 +8,6 @@ import android.view.MenuItem;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.RecyclerView;
@@ -17,7 +16,6 @@ import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.util.List;
import java.util.concurrent.Executor;
import javax.inject.Inject;
@@ -28,14 +26,13 @@ import butterknife.ButterKnife;
import eu.toldi.infinityforlemmy.Infinity;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
import eu.toldi.infinityforlemmy.adapters.PostFilterWithUsageRecyclerViewAdapter;
import eu.toldi.infinityforlemmy.adapters.PostFilterRecyclerViewAdapter;
import eu.toldi.infinityforlemmy.bottomsheetfragments.PostFilterOptionsBottomSheetFragment;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.post.Post;
import eu.toldi.infinityforlemmy.postfilter.DeletePostFilter;
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
import eu.toldi.infinityforlemmy.postfilter.PostFilterWithUsageViewModel;
import eu.toldi.infinityforlemmy.postfilter.PostFilterWithUsage;
import eu.toldi.infinityforlemmy.postfilter.PostFilterViewModel;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
public class PostFilterPreferenceActivity extends BaseActivity {
@@ -65,8 +62,8 @@ public class PostFilterPreferenceActivity extends BaseActivity {
CustomThemeWrapper customThemeWrapper;
@Inject
Executor executor;
public PostFilterWithUsageViewModel postFilterWithUsageViewModel;
private PostFilterWithUsageRecyclerViewAdapter adapter;
public PostFilterViewModel postFilterViewModel;
private PostFilterRecyclerViewAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -102,7 +99,7 @@ public class PostFilterPreferenceActivity extends BaseActivity {
}
});
adapter = new PostFilterWithUsageRecyclerViewAdapter(this, customThemeWrapper, postFilter -> {
adapter = new PostFilterRecyclerViewAdapter(this, customThemeWrapper, postFilter -> {
if (post != null) {
showPostFilterOptions(post, postFilter);
} else if (subredditName != null) {
@@ -120,15 +117,10 @@ public class PostFilterPreferenceActivity extends BaseActivity {
recyclerView.setAdapter(adapter);
postFilterWithUsageViewModel = new ViewModelProvider(this,
new PostFilterWithUsageViewModel.Factory(redditDataRoomDatabase)).get(PostFilterWithUsageViewModel.class);
postFilterViewModel = new ViewModelProvider(this,
new PostFilterViewModel.Factory(redditDataRoomDatabase)).get(PostFilterViewModel.class);
postFilterWithUsageViewModel.getPostFilterWithUsageListLiveData().observe(this, new Observer<List<PostFilterWithUsage>>() {
@Override
public void onChanged(List<PostFilterWithUsage> postFilterWithUsages) {
adapter.setPostFilterWithUsageList(postFilterWithUsages);
}
});
postFilterViewModel.getPostFilterListLiveData().observe(this, postFilters -> adapter.setPostFilterList(postFilters));
}
public void showPostFilterOptions(Post post, PostFilter postFilter) {

View File

@@ -126,9 +126,9 @@ public class PostFilterUsageListingActivity extends BaseActivity {
}
private void editAndPostFilterUsageNameOfUsage(int type, String nameOfUsage) {
View dialogView = getLayoutInflater().inflate(R.layout.dialog_edit_post_or_comment_filter_name_of_usage, null);
TextInputLayout textInputLayout = dialogView.findViewById(R.id.text_input_layout_edit_post_or_comment_filter_name_of_usage_dialog);
TextInputEditText textInputEditText = dialogView.findViewById(R.id.text_input_edit_text_edit_post_or_comment_filter_name_of_usage_dialog);
View dialogView = getLayoutInflater().inflate(R.layout.dialog_edit_post_filter_name_of_usage, null);
TextInputLayout textInputLayout = dialogView.findViewById(R.id.text_input_layout_edit_post_filter_name_of_usage_dialog);
TextInputEditText textInputEditText = dialogView.findViewById(R.id.text_input_edit_text_edit_post_filter_name_of_usage_dialog);
int primaryTextColor = customThemeWrapper.getPrimaryTextColor();
textInputLayout.setBoxStrokeColor(primaryTextColor);
textInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));

View File

@@ -132,7 +132,7 @@ public class RulesActivity extends BaseActivity {
mSubredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME);
mAdapter = new RulesRecyclerViewAdapter(this, mCustomThemeWrapper, sliderPanel, mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false));
mAdapter = new RulesRecyclerViewAdapter(this, mCustomThemeWrapper, sliderPanel);
recyclerView.setAdapter(mAdapter);
FetchSubredditData.fetchSubredditData(mRetrofit.getRetrofit(), mSubredditName, mAccessToken, new FetchSubredditData.FetchSubredditDataListener() {
@Override

View File

@@ -3,7 +3,6 @@ package eu.toldi.infinityforlemmy.activities;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@@ -28,14 +27,11 @@ import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import java.util.ArrayList;
import java.util.concurrent.Executor;
import javax.inject.Inject;
import javax.inject.Named;
@@ -51,6 +47,7 @@ import eu.toldi.infinityforlemmy.apis.RedditAPI;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.customviews.slidr.Slidr;
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
import eu.toldi.infinityforlemmy.recentsearchquery.DeleteRecentSearchQuery;
import eu.toldi.infinityforlemmy.recentsearchquery.RecentSearchQuery;
import eu.toldi.infinityforlemmy.recentsearchquery.RecentSearchQueryViewModel;
import eu.toldi.infinityforlemmy.subreddit.ParseSubredditData;
@@ -101,8 +98,6 @@ public class SearchActivity extends BaseActivity {
ImageView clearSearchTextImageView;
@BindView(R.id.link_handler_image_view_search_activity)
ImageView linkHandlerImageView;
@BindView(R.id.delete_all_recent_searches_button_search_activity)
MaterialButton deleteAllSearchesButton;
@BindView(R.id.subreddit_name_relative_layout_search_activity)
RelativeLayout subredditNameRelativeLayout;
@BindView(R.id.search_in_text_view_search_activity)
@@ -129,8 +124,6 @@ public class SearchActivity extends BaseActivity {
SharedPreferences mNsfwAndSpoilerSharedPreferences;
@Inject
CustomThemeWrapper mCustomThemeWrapper;
@Inject
Executor executor;
private String mAccountName;
private String mAccessToken;
private String query;
@@ -170,7 +163,6 @@ public class SearchActivity extends BaseActivity {
setSupportActionBar(toolbar);
clearSearchTextImageView.setVisibility(View.GONE);
deleteAllSearchesButton.setVisibility(View.GONE);
searchOnlySubreddits = getIntent().getBooleanExtra(EXTRA_SEARCH_ONLY_SUBREDDITS, false);
searchOnlyUsers = getIntent().getBooleanExtra(EXTRA_SEARCH_ONLY_USERS, false);
@@ -284,17 +276,6 @@ public class SearchActivity extends BaseActivity {
}
});
deleteAllSearchesButton.setOnClickListener(view -> {
new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
.setTitle(R.string.confirm)
.setMessage(R.string.confirm_delete_all_recent_searches)
.setPositiveButton(R.string.yes, (dialogInterface, i) -> {
executor.execute(() -> mRedditDataRoomDatabase.recentSearchQueryDao().deleteAllRecentSearchQueries(mAccountName));
})
.setNegativeButton(R.string.no, null)
.show();
});
if (savedInstanceState != null) {
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
subredditIsUser = savedInstanceState.getBoolean(SUBREDDIT_IS_USER_STATE);
@@ -338,7 +319,7 @@ public class SearchActivity extends BaseActivity {
@Override
public void onDelete(RecentSearchQuery recentSearchQuery) {
executor.execute(() -> mRedditDataRoomDatabase.recentSearchQueryDao().deleteRecentSearchQueries(recentSearchQuery));
DeleteRecentSearchQuery.deleteRecentSearchQueryListener(mRedditDataRoomDatabase, recentSearchQuery, () -> {});
}
});
recyclerView.setVisibility(View.VISIBLE);
@@ -353,10 +334,8 @@ public class SearchActivity extends BaseActivity {
mRecentSearchQueryViewModel.getAllRecentSearchQueries().observe(this, recentSearchQueries -> {
if (recentSearchQueries != null && !recentSearchQueries.isEmpty()) {
divider.setVisibility(View.VISIBLE);
deleteAllSearchesButton.setVisibility(View.VISIBLE);
} else {
divider.setVisibility(View.GONE);
deleteAllSearchesButton.setVisibility(View.GONE);
}
adapter.setRecentSearchQueries(recentSearchQueries);
});
@@ -422,7 +401,6 @@ public class SearchActivity extends BaseActivity {
linkHandlerImageView.setColorFilter(mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor(), android.graphics.PorterDuff.Mode.SRC_IN);
int colorAccent = mCustomThemeWrapper.getColorAccent();
searchInTextView.setTextColor(colorAccent);
deleteAllSearchesButton.setIconTint(ColorStateList.valueOf(mCustomThemeWrapper.getPrimaryIconColor()));
subredditNameTextView.setTextColor(mCustomThemeWrapper.getPrimaryTextColor());
divider.setBackgroundColor(mCustomThemeWrapper.getDividerColor());
if (typeface != null) {

View File

@@ -38,7 +38,6 @@ import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import java.util.ArrayList;
import java.util.concurrent.Executor;
import javax.inject.Inject;
import javax.inject.Named;
@@ -131,11 +130,10 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
SharedPreferences mCurrentAccountSharedPreferences;
@Inject
CustomThemeWrapper mCustomThemeWrapper;
@Inject
Executor executor;
private Call<String> subredditAutocompleteCall;
private String mAccessToken;
private String mAccountName;
private String mAccountQualifiedName;
private String mQuery;
private String mSubredditName;
@@ -246,7 +244,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
private void bindView(Bundle savedInstanceState) {
sectionsPagerAdapter = new SectionsPagerAdapter(this);
viewPager2.setAdapter(sectionsPagerAdapter);
viewPager2.setOffscreenPageLimit(ViewPager2.OFFSCREEN_PAGE_LIMIT_DEFAULT);
viewPager2.setOffscreenPageLimit(3);
viewPager2.setUserInputEnabled(!mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_SWIPING_BETWEEN_TABS, false));
viewPager2.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
@Override
@@ -394,8 +392,8 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
});
if (mAccountName != null && mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_SEARCH_HISTORY, true) && !mInsertSearchQuerySuccess && mQuery != null) {
InsertRecentSearchQuery.insertRecentSearchQueryListener(executor, new Handler(getMainLooper()),
mRedditDataRoomDatabase, mAccountQualifiedName, mQuery, () -> mInsertSearchQuerySuccess = true);
InsertRecentSearchQuery.insertRecentSearchQueryListener(mRedditDataRoomDatabase, mAccountQualifiedName,
mQuery, () -> mInsertSearchQuerySuccess = true);
}
}

View File

@@ -112,6 +112,8 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
View divider1;
@BindView(R.id.flair_custom_text_view_submit_crosspost_activity)
CustomTextView flairTextView;
@BindView(R.id.spoiler_custom_text_view_submit_crosspost_activity)
CustomTextView spoilerTextView;
@BindView(R.id.nsfw_custom_text_view_submit_crosspost_activity)
CustomTextView nsfwTextView;
@BindView(R.id.divider_2_submit_crosspost_activity)
@@ -257,6 +259,11 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
flairTextView.setBorderColor(flairBackgroundColor);
flairTextView.setTextColor(flairTextColor);
}
if (isSpoiler) {
spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
spoilerTextView.setBorderColor(spoilerBackgroundColor);
spoilerTextView.setTextColor(spoilerTextColor);
}
if (isNSFW) {
nsfwTextView.setBackgroundColor(nsfwBackgroundColor);
nsfwTextView.setBorderColor(nsfwBackgroundColor);
@@ -280,14 +287,13 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
titleEditText.setText(post.getTitle());
}
if (post.getPostType() == Post.TEXT_TYPE || post.getPostType() == Post.LINK_TYPE || post.getPostType() == Post.NO_PREVIEW_LINK_TYPE) {
if (post.getPostType() == Post.TEXT_TYPE) {
contentTextView.setVisibility(View.VISIBLE);
contentTextView.setText(generateCrossPostText(post));
contentTextView.setText(post.getSelfTextPlain());
} else if (post.getPostType() == Post.LINK_TYPE || post.getPostType() == Post.NO_PREVIEW_LINK_TYPE) {
contentTextView.setVisibility(View.VISIBLE);
contentTextView.setText(post.getUrl());
} else {
if (post.getSelfTextPlain() != null && !post.getSelfTextPlain().equals("")) {
contentTextView.setVisibility(View.VISIBLE);
contentTextView.setText(generateCrossPostText(post));
}
Post.Preview preview = getPreview(post);
if (preview != null) {
frameLayout.setVisibility(View.VISIBLE);
@@ -362,6 +368,18 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
}
});
spoilerTextView.setOnClickListener(view -> {
if (!isSpoiler) {
spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
spoilerTextView.setBorderColor(spoilerBackgroundColor);
spoilerTextView.setTextColor(spoilerTextColor);
isSpoiler = true;
} else {
spoilerTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
spoilerTextView.setTextColor(primaryTextColor);
isSpoiler = false;
}
});
nsfwTextView.setOnClickListener(view -> {
if (!isNSFW) {
@@ -443,6 +461,7 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
nsfwBackgroundColor = mCustomThemeWrapper.getNsfwBackgroundColor();
nsfwTextColor = mCustomThemeWrapper.getNsfwTextColor();
flairTextView.setTextColor(primaryTextColor);
spoilerTextView.setTextColor(primaryTextColor);
nsfwTextView.setTextColor(primaryTextColor);
titleEditText.setTextColor(primaryTextColor);
titleEditText.setHintTextColor(secondaryTextColor);
@@ -455,6 +474,7 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
rulesButton.setTypeface(typeface);
receivePostReplyNotificationsTextView.setTypeface(typeface);
flairTextView.setTypeface(typeface);
spoilerTextView.setTypeface(typeface);
nsfwTextView.setTypeface(typeface);
titleEditText.setTypeface(typeface);
}
@@ -541,19 +561,22 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
mPostingSnackbar.show();
String subredditName = subredditNameTextView.getText().toString();
String subredditName;
if (subredditIsUser) {
subredditName = "u_" + subredditNameTextView.getText().toString();
} else {
subredditName = subredditNameTextView.getText().toString();
}
Intent intent = new Intent(this, SubmitPostService.class);
intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, selectedAccount);
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, communityData.getId());
intent.putExtra(SubmitPostService.EXTRA_TITLE, titleEditText.getText().toString());
intent.putExtra(SubmitPostService.EXTRA_BODY, generateCrossPostText(post));
if (post.getUrl() != null && !post.getUrl().equals("")) {
intent.putExtra(SubmitPostService.EXTRA_URL, post.getUrl());
if (post.isCrosspost()) {
intent.putExtra(SubmitPostService.EXTRA_BODY, "t3_" + post.getCrosspostParentId());
} else {
intent.putExtra(SubmitPostService.EXTRA_BODY, post.getFullName());
}
intent.putExtra(SubmitPostService.EXTRA_KIND, APIUtils.KIND_CROSSPOST);
intent.putExtra(SubmitPostService.EXTRA_FLAIR, flair);
intent.putExtra(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler);
@@ -676,15 +699,4 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
}
}
}
private static String generateCrossPostText(Post post) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("cross-posted from: ").append(post.getPermalink()).append("\n");
String[] lines = post.getSelfTextPlain().split("\n");
for (String line : lines) {
stringBuilder.append("> ").append(line).append("\n");
}
return stringBuilder.toString();
}
}

View File

@@ -112,9 +112,6 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
@Named("current_account")
SharedPreferences mCurrentAccountSharedPreferences;
@Inject
@Named("internal")
SharedPreferences mInternalSharedPreferences;
@Inject
CustomThemeWrapper mCustomThemeWrapper;
@Inject
Executor mExecutor;
@@ -326,10 +323,6 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
}
public void loadSubscriptions(boolean forceLoad) {
if (!forceLoad && System.currentTimeMillis() - mInternalSharedPreferences.getLong(SharedPreferencesUtils.SUBSCRIBED_THINGS_SYNC_TIME, 0L) < 24 * 60 * 60 * 1000) {
return;
}
if (mAccessToken != null && !(!forceLoad && mInsertSuccess)) {
FetchSubscribedThing.fetchSubscribedThing(mRetrofit.getRetrofit(), mAccessToken, mAccountQualifiedName, null,
new ArrayList<>(), new ArrayList<>(),
@@ -339,7 +332,6 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
public void onFetchSubscribedThingSuccess(ArrayList<SubscribedSubredditData> subscribedSubredditData,
ArrayList<SubscribedUserData> subscribedUserData,
ArrayList<SubredditData> subredditData) {
mInternalSharedPreferences.edit().putLong(SharedPreferencesUtils.SUBSCRIBED_THINGS_SYNC_TIME, System.currentTimeMillis()).apply();
InsertSubscribedThings.insertSubscribedThings(
mExecutor,
new Handler(),

View File

@@ -557,7 +557,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
// TODO: Implement anonymous front page
default:
String type = (subredditName == null) ? "Subscribed" : (subredditName.equals("all")) ? "All" : "Local";
String type = (subredditName.equals("all")) ? "All" : (subredditName.equals("local")) ? "Local" : "Subscribed";
call = api.getPosts(type, sortType.value, nextPage, 25, null, null, false, mAccessToken);
}

View File

@@ -1,13 +1,9 @@
package eu.toldi.infinityforlemmy.activities;
import static android.graphics.BitmapFactory.decodeResource;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.graphics.Bitmap;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@@ -44,8 +40,6 @@ import androidx.viewpager2.widget.ViewPager2;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
import com.evernote.android.state.State;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
@@ -110,7 +104,6 @@ import eu.toldi.infinityforlemmy.post.MarkPostAsRead;
import eu.toldi.infinityforlemmy.post.Post;
import eu.toldi.infinityforlemmy.post.PostPagingSource;
import eu.toldi.infinityforlemmy.readpost.InsertReadPost;
import eu.toldi.infinityforlemmy.shortcut.ShortcutManager;
import eu.toldi.infinityforlemmy.subreddit.CommunitySubscription;
import eu.toldi.infinityforlemmy.subreddit.FetchSubredditData;
import eu.toldi.infinityforlemmy.subreddit.ParseSubredditData;
@@ -267,14 +260,10 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
private int subscribedColor;
private int fabOption;
private MaterialAlertDialogBuilder nsfwWarningBuilder;
private Bitmap subredditIconBitmap;
private boolean showStatistics;
private boolean disableImagePreview;
private boolean hideSubredditDescription;
private boolean isKbinMagazine = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -288,7 +277,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
hideFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_FAB_IN_POST_FEED, false);
showStatistics = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_STATISTICS, true);
disableImagePreview = mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false);
showBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.BOTTOM_APP_BAR_KEY, false);
navigationWrapper = new NavigationWrapper(findViewById(R.id.bottom_app_bar_bottom_app_bar), findViewById(R.id.linear_layout_bottom_app_bar),
findViewById(R.id.option_1_bottom_app_bar), findViewById(R.id.option_2_bottom_app_bar),
@@ -550,7 +538,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
return true;
};
Markwon markwon = MarkdownUtils.createDescriptionMarkwon(this, miscPlugin, onLinkLongClickListener, mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false));
Markwon markwon = MarkdownUtils.createDescriptionMarkwon(this, miscPlugin, onLinkLongClickListener);
descriptionTextView.setOnLongClickListener(view -> {
if (description != null && !description.equals("") && descriptionTextView.getSelectionStart() == -1 && descriptionTextView.getSelectionEnd() == -1) {
@@ -558,14 +546,10 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
}
return true;
});
String actorID = (!isKbinMagazine) ? LemmyUtils.qualifiedCommunityName2ActorId(qualifiedName) : LemmyUtils.qualifiedMagazineName2ActorId(qualifiedName);
mSubredditViewModel = new ViewModelProvider(this,
new SubredditViewModel.Factory(getApplication(), mRedditDataRoomDatabase, actorID))
.get(SubredditViewModel.class);
addObserverToLiveData();
}
private void addObserverToLiveData() {
mSubredditViewModel = new ViewModelProvider(this,
new SubredditViewModel.Factory(getApplication(), mRedditDataRoomDatabase, LemmyUtils.qualifiedCommunityName2ActorId(qualifiedName)))
.get(SubredditViewModel.class);
mSubredditViewModel.getSubredditLiveData().observe(this, subredditData -> {
if (subredditData != null) {
isNsfwSubreddit = subredditData.isNSFW();
@@ -591,23 +575,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
.into(iconGifImageView);
iconGifImageView.setOnClickListener(null);
} else {
glide.asBitmap()
.load(subredditData.getIconUrl())
glide.load(subredditData.getIconUrl())
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(216, 0)))
.error(glide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(216, 0))))
.into(new CustomTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
subredditIconBitmap = resource;
iconGifImageView.setImageBitmap(resource);
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
subredditIconBitmap = null;
}
});
.into(iconGifImageView);
iconGifImageView.setOnClickListener(view -> {
Intent intent = new Intent(ViewSubredditDetailActivity.this, ViewImageOrGifActivity.class);
intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, subredditData.getIconUrl());
@@ -773,14 +745,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
communityName = communityData.getTitle();
}
mCommunityStats = communityData.getCommunityStats();
if (communityData.getActorId().contains("/m/")) {
isKbinMagazine = true;
if (mSubredditViewModel != null) {
// Remove current observer
mSubredditViewModel.getSubredditLiveData().removeObservers(ViewSubredditDetailActivity.this);
addObserverToLiveData();
}
}
setupVisibleElements();
communityId = communityData.getId();
ViewSubredditDetailActivity.this.communityData = communityData;
@@ -1184,7 +1148,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
}
});
viewPager2.setAdapter(sectionsPagerAdapter);
viewPager2.setOffscreenPageLimit(ViewPager2.OFFSCREEN_PAGE_LIMIT_DEFAULT);
viewPager2.setOffscreenPageLimit(2);
viewPager2.setUserInputEnabled(!mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_SWIPING_BETWEEN_TABS, false));
new TabLayoutMediator(tabLayout, viewPager2, (tab, position) -> {
switch (position) {
@@ -1310,9 +1274,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
}
});
return true;
} else if (itemId == R.id.action_add_to_home_screen_view_subreddit_detail_activity) {
Bitmap icon = subredditIconBitmap == null ? decodeResource(getResources(), R.drawable.subreddit_default_icon) : subredditIconBitmap;
return ShortcutManager.requestPinShortcut(this, qualifiedName, icon);
}
return false;
}
@@ -1747,7 +1708,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
bundle.putString(SidebarFragment.EXTRA_SUBREDDIT_NAME, communityName);
bundle.putString(SidebarFragment.EXTRA_COMMUNITY_QUALIFIED_NAME, qualifiedName);
bundle.putBoolean(SidebarFragment.EXTRA_SHOW_STATISTICS, !showStatistics);
bundle.putBoolean(SidebarFragment.EXTRA_DISABLE_IMAGE_PREVIEW, disableImagePreview);
fragment.setArguments(bundle);
return fragment;
}

View File

@@ -472,7 +472,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
urlMenuBottomSheetFragment.show(getSupportFragmentManager(), null);
return true;
};
Markwon markwon = MarkdownUtils.createDescriptionMarkwon(this, miscPlugin, onLinkLongClickListener, mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false));
Markwon markwon = MarkdownUtils.createDescriptionMarkwon(this, miscPlugin, onLinkLongClickListener);
descriptionTextView.setOnLongClickListener(view -> {
if (description != null && !description.equals("") && descriptionTextView.getSelectionStart() == -1 && descriptionTextView.getSelectionEnd() == -1) {
@@ -761,7 +761,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
private void initializeViewPager() {
sectionsPagerAdapter = new SectionsPagerAdapter(this);
viewPager2.setAdapter(sectionsPagerAdapter);
viewPager2.setOffscreenPageLimit(ViewPager2.OFFSCREEN_PAGE_LIMIT_DEFAULT);
viewPager2.setOffscreenPageLimit(2);
viewPager2.setUserInputEnabled(!mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_SWIPING_BETWEEN_TABS, false));
new TabLayoutMediator(tabLayout, viewPager2, (tab, position) -> {
switch (position) {

View File

@@ -23,11 +23,14 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.text.Html;
import android.view.Menu;
import android.view.MenuItem;
import android.view.OrientationEventListener;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
@@ -67,7 +70,6 @@ import com.google.android.exoplayer2.upstream.cache.SimpleCache;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.video.VideoSize;
import com.google.android.material.bottomappbar.BottomAppBar;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.snackbar.Snackbar;
import com.google.common.collect.ImmutableList;
import com.otaliastudios.zoom.ZoomEngine;
@@ -130,7 +132,7 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
public static final String EXTRA_VIDEO_DOWNLOAD_URL = "EVDU";
public static final String EXTRA_SUBREDDIT = "ES";
public static final String EXTRA_ID = "EI";
public static final String EXTRA_POST = "EP";
public static final String EXTRA_POST_TITLE = "EPT";
public static final String EXTRA_PROGRESS_SECONDS = "EPS";
public static final String EXTRA_VIDEO_TYPE = "EVT";
public static final String EXTRA_GFYCAT_ID = "EGI";
@@ -161,19 +163,17 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
@BindView(R.id.progress_bar_view_video_activity)
ProgressBar progressBar;
@BindView(R.id.mute_exo_playback_control_view)
MaterialButton muteButton;
ImageButton muteButton;
@BindView(R.id.hd_exo_playback_control_view)
MaterialButton hdButton;
ImageButton hdButton;
@BindView(R.id.bottom_navigation_exo_playback_control_view)
BottomAppBar bottomAppBar;
@BindView(R.id.title_text_view_exo_playback_control_view)
TextView titleTextView;
@BindView(R.id.back_button_exo_playback_control_view)
MaterialButton backButton;
@BindView(R.id.download_image_view_exo_playback_control_view)
MaterialButton downloadButton;
ImageView downloadImageView;
@BindView(R.id.playback_speed_image_view_exo_playback_control_view)
MaterialButton playbackSpeedButton;
ImageView playbackSpeedImageView;
@BindView(R.id.lockable_nested_scroll_view_view_video_activity)
LockableNestedScrollView nestedScrollView;
@@ -301,12 +301,6 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
ButterKnife.bind(this);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
setTitle(" ");
if (typeface != null) {
titleTextView.setTypeface(typeface);
}
Resources resources = getResources();
getWindow().getDecorView().setSystemUiVisibility(
@@ -318,11 +312,7 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
if (useBottomAppBar) {
getSupportActionBar().hide();
bottomAppBar.setVisibility(View.VISIBLE);
backButton.setOnClickListener(view -> {
finish();
});
downloadButton.setOnClickListener(view -> {
downloadImageView.setOnClickListener(view -> {
if (isDownloading) {
return;
}
@@ -336,8 +326,12 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
requestPermissionAndDownload();
});
playbackSpeedButton.setOnClickListener(view -> {
changePlaybackSpeed();
playbackSpeedImageView.setOnClickListener(view -> {
PlaybackSpeedBottomSheetFragment playbackSpeedBottomSheetFragment = new PlaybackSpeedBottomSheetFragment();
Bundle bundle = new Bundle();
bundle.putInt(PlaybackSpeedBottomSheetFragment.EXTRA_PLAYBACK_SPEED, playbackSpeed);
playbackSpeedBottomSheetFragment.setArguments(bundle);
playbackSpeedBottomSheetFragment.show(getSupportFragmentManager(), playbackSpeedBottomSheetFragment.getTag());
});
} else {
ActionBar actionBar = getSupportActionBar();
@@ -408,15 +402,12 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
};
orientationEventListener.enable();
}
} catch (Exception ignore) {
}
} catch (Exception ignore) {}
}
}
Post post = intent.getParcelableExtra(EXTRA_POST);
if (post != null) {
titleTextView.setText(post.getTitle());
}
String postTitle = intent.getStringExtra(EXTRA_POST_TITLE);
setSmallTitle(postTitle);
trackSelector = new DefaultTrackSelector(this);
if (videoType == VIDEO_TYPE_NORMAL && isDataSavingMode && dataSavingModeDefaultResolution > 0) {
@@ -607,6 +598,20 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
}
}
private void setSmallTitle(String title) {
if (title != null) {
if (useBottomAppBar) {
titleTextView.setText(Html.fromHtml(String.format("<font color=\"#FFFFFF\"><small>%s</small></font>", title)));
} else {
setTitle(Utils.getTabTextWithCustomFont(typeface, Html.fromHtml(String.format("<font color=\"#FFFFFF\"><small>%s</small></font>", title))));
}
} else {
if (!useBottomAppBar) {
setTitle("");
}
}
}
private void preparePlayer(Bundle savedInstanceState) {
if (mSharedPreferences.getBoolean(SharedPreferencesUtils.LOOP_VIDEO, true)) {
player.setRepeatMode(Player.REPEAT_MODE_ALL);
@@ -626,17 +631,17 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
isMute = savedInstanceState.getBoolean(IS_MUTE_STATE);
if (isMute) {
player.setVolume(0f);
muteButton.setIconResource(R.drawable.ic_mute_24dp);
muteButton.setImageResource(R.drawable.ic_mute_24dp);
} else {
player.setVolume(1f);
muteButton.setIconResource(R.drawable.ic_unmute_24dp);
muteButton.setImageResource(R.drawable.ic_unmute_24dp);
}
} else if (muteVideo) {
isMute = true;
player.setVolume(0f);
muteButton.setIconResource(R.drawable.ic_mute_24dp);
muteButton.setImageResource(R.drawable.ic_mute_24dp);
} else {
muteButton.setIconResource(R.drawable.ic_unmute_24dp);
muteButton.setImageResource(R.drawable.ic_unmute_24dp);
}
player.addListener(new Player.Listener() {
@@ -680,11 +685,11 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
if (isMute) {
isMute = false;
player.setVolume(1f);
muteButton.setIconResource(R.drawable.ic_unmute_24dp);
muteButton.setImageResource(R.drawable.ic_unmute_24dp);
} else {
isMute = true;
player.setVolume(0f);
muteButton.setIconResource(R.drawable.ic_mute_24dp);
muteButton.setImageResource(R.drawable.ic_mute_24dp);
}
});
}
@@ -697,14 +702,6 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
});
}
private void changePlaybackSpeed() {
PlaybackSpeedBottomSheetFragment playbackSpeedBottomSheetFragment = new PlaybackSpeedBottomSheetFragment();
Bundle bundle = new Bundle();
bundle.putInt(PlaybackSpeedBottomSheetFragment.EXTRA_PLAYBACK_SPEED, playbackSpeed);
playbackSpeedBottomSheetFragment.setArguments(bundle);
playbackSpeedBottomSheetFragment.show(getSupportFragmentManager(), playbackSpeedBottomSheetFragment.getTag());
}
private int inferPrimaryTrackType(Format format) {
int trackType = MimeTypes.getTrackType(format.sampleMimeType);
if (trackType != C.TRACK_TYPE_UNKNOWN) {
@@ -887,7 +884,7 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
Toast.makeText(ViewVideoActivity.this, R.string.fetch_streamable_video_failed, Toast.LENGTH_SHORT).show();
return;
}
titleTextView.setText(streamableVideo.title);
setSmallTitle(streamableVideo.title);
progressBar.setVisibility(View.GONE);
videoDownloadUrl = streamableVideo.mp4 == null ? streamableVideo.mp4Mobile.url : streamableVideo.mp4.url;
mVideoUri = Uri.parse(videoDownloadUrl);
@@ -942,7 +939,11 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
requestPermissionAndDownload();
return true;
} else if (itemId == R.id.action_playback_speed_view_video_activity) {
changePlaybackSpeed();
PlaybackSpeedBottomSheetFragment playbackSpeedBottomSheetFragment = new PlaybackSpeedBottomSheetFragment();
Bundle bundle = new Bundle();
bundle.putInt(PlaybackSpeedBottomSheetFragment.EXTRA_PLAYBACK_SPEED, playbackSpeed);
playbackSpeedBottomSheetFragment.setArguments(bundle);
playbackSpeedBottomSheetFragment.show(getSupportFragmentManager(), playbackSpeedBottomSheetFragment.getTag());
return true;
}

View File

@@ -176,7 +176,7 @@ public class WikiActivity extends BaseActivity {
return true;
};
markwon = MarkdownUtils.createFullRedditMarkwon(this,
miscPlugin, markdownColor, spoilerBackgroundColor, onLinkLongClickListener, mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false));
miscPlugin, markdownColor, spoilerBackgroundColor, onLinkLongClickListener);
markwonAdapter = MarkdownUtils.createTablesAdapter();
LinearLayoutManagerBugFixed linearLayoutManager = new SwipeLockLinearLayoutManager(this, new SwipeLockInterface() {

View File

@@ -1,76 +0,0 @@
package eu.toldi.infinityforlemmy.adapters;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.activities.BaseActivity;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilterUsage;
import eu.toldi.infinityforlemmy.databinding.ItemCommentFilterUsageEmbeddedBinding;
public class CommentFilterUsageEmbeddedRecyclerViewAdapter extends RecyclerView.Adapter<CommentFilterUsageEmbeddedRecyclerViewAdapter.EntryViewHolder> {
private BaseActivity baseActivity;
private List<CommentFilterUsage> commentFilterUsageList;
public CommentFilterUsageEmbeddedRecyclerViewAdapter(BaseActivity baseActivity) {
this.baseActivity = baseActivity;
}
@NonNull
@Override
public EntryViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new EntryViewHolder(ItemCommentFilterUsageEmbeddedBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));
}
@Override
public void onBindViewHolder(@NonNull EntryViewHolder holder, int position) {
if (commentFilterUsageList == null || commentFilterUsageList.isEmpty()) {
holder.textView.setText(R.string.comment_filter_applied_to_all_subreddits);
} else if (holder.getBindingAdapterPosition() > 4) {
holder.textView.setText(baseActivity.getString(R.string.comment_filter_usage_embedded_more_count, commentFilterUsageList.size() - 5));
} else {
CommentFilterUsage commentFilterUsage = commentFilterUsageList.get(holder.getBindingAdapterPosition());
switch (commentFilterUsage.usage) {
case CommentFilterUsage.SUBREDDIT_TYPE:
holder.textView.setText("r/" + commentFilterUsage.nameOfUsage);
break;
}
}
}
@Override
public int getItemCount() {
return commentFilterUsageList == null || commentFilterUsageList.isEmpty() ? 1 : (commentFilterUsageList.size() > 5 ? 6 : commentFilterUsageList.size());
}
public void setCommentFilterUsageList(List<CommentFilterUsage> commentFilterUsageList) {
this.commentFilterUsageList = commentFilterUsageList;
notifyDataSetChanged();
}
class EntryViewHolder extends RecyclerView.ViewHolder {
TextView textView;
public EntryViewHolder(@NonNull ItemCommentFilterUsageEmbeddedBinding binding) {
super(binding.getRoot());
textView = binding.getRoot();
textView.setTextColor(baseActivity.customThemeWrapper.getSecondaryTextColor());
if (baseActivity.typeface != null) {
textView.setTypeface(baseActivity.typeface);
}
textView.setOnClickListener(view -> {
Toast.makeText(baseActivity, textView.getText(), Toast.LENGTH_SHORT).show();
});
}
}
}

View File

@@ -1,80 +0,0 @@
package eu.toldi.infinityforlemmy.adapters;
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;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.activities.BaseActivity;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilterUsage;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
public class CommentFilterUsageRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private List<CommentFilterUsage> commentFilterUsages;
private BaseActivity activity;
private CustomThemeWrapper customThemeWrapper;
private CommentFilterUsageRecyclerViewAdapter.OnItemClickListener onItemClickListener;
public interface OnItemClickListener {
void onClick(CommentFilterUsage commentFilterUsage);
}
public CommentFilterUsageRecyclerViewAdapter(BaseActivity activity, CustomThemeWrapper customThemeWrapper,
CommentFilterUsageRecyclerViewAdapter.OnItemClickListener onItemClickListener) {
this.activity = activity;
this.customThemeWrapper = customThemeWrapper;
this.onItemClickListener = onItemClickListener;
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new CommentFilterUsageRecyclerViewAdapter.CommentFilterUsageViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_filter_usage, parent, false));
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
CommentFilterUsage commentFilterUsage = commentFilterUsages.get(position);
switch (commentFilterUsage.usage) {
case CommentFilterUsage.SUBREDDIT_TYPE:
((CommentFilterUsageRecyclerViewAdapter.CommentFilterUsageViewHolder) holder).usageTextView.setText(activity.getString(R.string.post_filter_usage_community, commentFilterUsage.nameOfUsage));
break;
}
}
@Override
public int getItemCount() {
return commentFilterUsages == null ? 0 : commentFilterUsages.size();
}
public void setCommentFilterUsages(List<CommentFilterUsage> commentFilterUsages) {
this.commentFilterUsages = commentFilterUsages;
notifyDataSetChanged();
}
private class CommentFilterUsageViewHolder extends RecyclerView.ViewHolder {
TextView usageTextView;
public CommentFilterUsageViewHolder(@NonNull View itemView) {
super(itemView);
usageTextView = (TextView) itemView;
usageTextView.setTextColor(customThemeWrapper.getPrimaryTextColor());
if (activity.typeface != null) {
usageTextView.setTypeface(activity.typeface);
}
usageTextView.setOnClickListener(view -> {
onItemClickListener.onClick(commentFilterUsages.get(getBindingAdapterPosition()));
});
}
}
}

View File

@@ -1,81 +0,0 @@
package eu.toldi.infinityforlemmy.adapters;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
import eu.toldi.infinityforlemmy.activities.BaseActivity;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilter;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilterWithUsage;
import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
import eu.toldi.infinityforlemmy.databinding.ItemCommentFilterWithUsageBinding;
public class CommentFilterWithUsageRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private BaseActivity activity;
private final OnItemClickListener onItemClickListener;
private List<CommentFilterWithUsage> commentFilterWithUsageList;
private RecyclerView.RecycledViewPool recycledViewPool;
public interface OnItemClickListener {
void onItemClick(CommentFilter commentFilter);
}
public CommentFilterWithUsageRecyclerViewAdapter(BaseActivity activity, OnItemClickListener onItemClickListener) {
this.activity = activity;
this.recycledViewPool = new RecyclerView.RecycledViewPool();
this.onItemClickListener = onItemClickListener;
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new CommentFilterViewHolder(ItemCommentFilterWithUsageBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if (holder instanceof CommentFilterViewHolder) {
((CommentFilterViewHolder) holder).binding.commentFilterNameTextViewItemCommentFilter.setText(commentFilterWithUsageList.get(position).commentFilter.name);
((CommentFilterViewHolder) holder).adapter.setCommentFilterUsageList(commentFilterWithUsageList.get(position).commentFilterUsageList);
}
}
@Override
public int getItemCount() {
return commentFilterWithUsageList == null ? 0 : commentFilterWithUsageList.size();
}
public void setCommentFilterWithUsageList(List<CommentFilterWithUsage> commentFilterWithUsageList) {
this.commentFilterWithUsageList = commentFilterWithUsageList;
notifyDataSetChanged();
}
private class CommentFilterViewHolder extends RecyclerView.ViewHolder {
ItemCommentFilterWithUsageBinding binding;
CommentFilterUsageEmbeddedRecyclerViewAdapter adapter;
public CommentFilterViewHolder(@NonNull ItemCommentFilterWithUsageBinding binding) {
super(binding.getRoot());
this.binding = binding;
binding.commentFilterNameTextViewItemCommentFilter.setTextColor(activity.customThemeWrapper.getPrimaryTextColor());
if (activity.typeface != null) {
binding.commentFilterNameTextViewItemCommentFilter.setTypeface(activity.typeface);
}
binding.getRoot().setOnClickListener(view -> {
onItemClickListener.onItemClick(commentFilterWithUsageList.get(getBindingAdapterPosition()).commentFilter);
});
binding.commentFilterUsageRecyclerViewItemCommentFilter.setRecycledViewPool(recycledViewPool);
binding.commentFilterUsageRecyclerViewItemCommentFilter.setLayoutManager(new LinearLayoutManagerBugFixed(activity));
adapter = new CommentFilterUsageEmbeddedRecyclerViewAdapter(activity);
binding.commentFilterUsageRecyclerViewItemCommentFilter.setAdapter(adapter);
}
}
}

View File

@@ -4,6 +4,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.net.Uri;
import android.os.Bundle;
import android.text.Spanned;
@@ -11,6 +12,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
@@ -24,8 +26,6 @@ import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.button.MaterialButton;
import java.util.Locale;
import butterknife.BindView;
@@ -49,7 +49,6 @@ import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
import eu.toldi.infinityforlemmy.customviews.SpoilerOnClickTextView;
import eu.toldi.infinityforlemmy.customviews.SwipeLockInterface;
import eu.toldi.infinityforlemmy.customviews.SwipeLockLinearLayoutManager;
import eu.toldi.infinityforlemmy.databinding.ItemCommentBinding;
import eu.toldi.infinityforlemmy.markdown.MarkdownUtils;
import eu.toldi.infinityforlemmy.utils.APIUtils;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
@@ -170,7 +169,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
return true;
};
mMarkwon = MarkdownUtils.createFullRedditMarkwon(mActivity,
miscPlugin, mCommentColor, commentSpoilerBackgroundColor, onLinkLongClickListener, sharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false));
miscPlugin, mCommentColor, commentSpoilerBackgroundColor, onLinkLongClickListener);
recycledViewPool = new RecyclerView.RecycledViewPool();
}
@@ -178,7 +177,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
if (viewType == VIEW_TYPE_DATA) {
return new CommentViewHolder(ItemCommentBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));
return new CommentViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_comment, parent, false));
} else if (viewType == VIEW_TYPE_ERROR) {
return new ErrorViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_footer_error, parent, false));
} else {
@@ -188,24 +187,24 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if (holder instanceof CommentBaseViewHolder) {
if (holder instanceof CommentViewHolder) {
Comment comment = getItem(holder.getBindingAdapterPosition());
if (comment != null) {
String name = comment.getCommunityQualifiedName();
((CommentBaseViewHolder) holder).authorTextView.setText(name);
((CommentBaseViewHolder) holder).authorTextView.setTextColor(mSubredditColor);
((CommentViewHolder) holder).authorTextView.setText(name);
((CommentViewHolder) holder).authorTextView.setTextColor(mSubredditColor);
if (mShowElapsedTime) {
((CommentBaseViewHolder) holder).commentTimeTextView.setText(
((CommentViewHolder) holder).commentTimeTextView.setText(
Utils.getElapsedTime(mActivity, comment.getCommentTimeMillis()));
} else {
((CommentBaseViewHolder) holder).commentTimeTextView.setText(Utils.getFormattedTime(mLocale, comment.getCommentTimeMillis(), mTimeFormatPattern));
((CommentViewHolder) holder).commentTimeTextView.setText(Utils.getFormattedTime(mLocale, comment.getCommentTimeMillis(), mTimeFormatPattern));
}
((CommentViewHolder) holder).markwonAdapter.setMarkdown(mMarkwon, comment.getCommentMarkdown());
// noinspection NotifyDataSetChanged
((CommentBaseViewHolder) holder).markwonAdapter.notifyDataSetChanged();
((CommentViewHolder) holder).markwonAdapter.notifyDataSetChanged();
String commentText = Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType());
@@ -214,21 +213,21 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
switch (comment.getVoteType()) {
case Comment.VOTE_TYPE_UPVOTE:
((CommentBaseViewHolder) holder).upvoteButton.setIconResource(R.drawable.ic_upvote_filled_24dp);
((CommentBaseViewHolder) holder).upvoteButton.setIconTint(ColorStateList.valueOf(mUpvotedColor));
((CommentBaseViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor);
((CommentViewHolder) holder).upvoteButton
.setColorFilter(mUpvotedColor, PorterDuff.Mode.SRC_IN);
((CommentViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor);
break;
case Comment.VOTE_TYPE_DOWNVOTE:
((CommentBaseViewHolder) holder).downvoteButton.setIconResource(R.drawable.ic_downvote_filled_24dp);
((CommentBaseViewHolder) holder).downvoteButton.setIconTint(ColorStateList.valueOf(mDownvotedColor));
((CommentBaseViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor);
((CommentViewHolder) holder).downvoteButton
.setColorFilter(mDownvotedColor, PorterDuff.Mode.SRC_IN);
((CommentViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor);
break;
}
if (comment.isSaved()) {
((CommentBaseViewHolder) holder).saveButton.setIconResource(R.drawable.ic_bookmark_grey_24dp);
((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
} else {
((CommentBaseViewHolder) holder).saveButton.setIconResource(R.drawable.ic_bookmark_border_grey_24dp);
((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
}
}
}
@@ -250,16 +249,14 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
@Override
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
if (holder instanceof CommentBaseViewHolder) {
((CommentBaseViewHolder) holder).authorFlairTextView.setText("");
((CommentBaseViewHolder) holder).authorFlairTextView.setVisibility(View.GONE);
((CommentBaseViewHolder) holder).awardsTextView.setText("");
((CommentBaseViewHolder) holder).awardsTextView.setVisibility(View.GONE);
((CommentBaseViewHolder) holder).upvoteButton.setIconResource(R.drawable.ic_upvote_24dp);
((CommentBaseViewHolder) holder).upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
((CommentBaseViewHolder) holder).scoreTextView.setTextColor(mCommentIconAndInfoColor);
((CommentBaseViewHolder) holder).downvoteButton.setIconResource(R.drawable.ic_downvote_24dp);
((CommentBaseViewHolder) holder).downvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
if (holder instanceof CommentViewHolder) {
((CommentViewHolder) holder).authorFlairTextView.setText("");
((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.GONE);
((CommentViewHolder) holder).awardsTextView.setText("");
((CommentViewHolder) holder).awardsTextView.setVisibility(View.GONE);
((CommentViewHolder) holder).upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
((CommentViewHolder) holder).downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
((CommentViewHolder) holder).scoreTextView.setTextColor(mCommentIconAndInfoColor);
}
}
@@ -292,18 +289,18 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
}
public void onItemSwipe(RecyclerView.ViewHolder viewHolder, int direction, int swipeLeftAction, int swipeRightAction) {
if (viewHolder instanceof CommentBaseViewHolder) {
if (viewHolder instanceof CommentViewHolder) {
if (direction == ItemTouchHelper.LEFT || direction == ItemTouchHelper.START) {
if (swipeLeftAction == SharedPreferencesUtils.SWIPE_ACITON_UPVOTE) {
((CommentBaseViewHolder) viewHolder).upvoteButton.performClick();
((CommentViewHolder) viewHolder).upvoteButton.performClick();
} else if (swipeLeftAction == SharedPreferencesUtils.SWIPE_ACITON_DOWNVOTE) {
((CommentBaseViewHolder) viewHolder).downvoteButton.performClick();
((CommentViewHolder) viewHolder).downvoteButton.performClick();
}
} else {
if (swipeRightAction == SharedPreferencesUtils.SWIPE_ACITON_UPVOTE) {
((CommentBaseViewHolder) viewHolder).upvoteButton.performClick();
((CommentViewHolder) viewHolder).upvoteButton.performClick();
} else if (swipeRightAction == SharedPreferencesUtils.SWIPE_ACITON_DOWNVOTE) {
((CommentBaseViewHolder) viewHolder).downvoteButton.performClick();
((CommentViewHolder) viewHolder).downvoteButton.performClick();
}
}
}
@@ -321,60 +318,46 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
void retryLoadingMore();
}
public class CommentBaseViewHolder extends RecyclerView.ViewHolder {
public class CommentViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.vertical_block_indentation_item_comment)
CommentIndentationView commentIndentationView;
@BindView(R.id.linear_layout_item_comment)
LinearLayout linearLayout;
@BindView(R.id.author_text_view_item_post_comment)
TextView authorTextView;
@BindView(R.id.author_flair_text_view_item_post_comment)
TextView authorFlairTextView;
@BindView(R.id.comment_time_text_view_item_post_comment)
TextView commentTimeTextView;
@BindView(R.id.awards_text_view_item_comment)
TextView awardsTextView;
@BindView(R.id.comment_markdown_view_item_post_comment)
RecyclerView commentMarkdownView;
@BindView(R.id.bottom_constraint_layout_item_post_comment)
ConstraintLayout bottomConstraintLayout;
MaterialButton upvoteButton;
@BindView(R.id.up_vote_button_item_post_comment)
ImageView upvoteButton;
@BindView(R.id.score_text_view_item_post_comment)
TextView scoreTextView;
MaterialButton downvoteButton;
@BindView(R.id.down_vote_button_item_post_comment)
ImageView downvoteButton;
@BindView(R.id.placeholder_item_post_comment)
View placeholder;
MaterialButton moreButton;
MaterialButton saveButton;
MaterialButton replyButton;
@BindView(R.id.more_button_item_post_comment)
ImageView moreButton;
@BindView(R.id.save_button_item_post_comment)
ImageView saveButton;
@BindView(R.id.expand_button_item_post_comment)
TextView expandButton;
@BindView(R.id.reply_button_item_post_comment)
ImageView replyButton;
@BindView(R.id.divider_item_comment)
View commentDivider;
CustomMarkwonAdapter markwonAdapter;
CommentBaseViewHolder(@NonNull View itemView) {
CommentViewHolder(View itemView) {
super(itemView);
}
void setBaseView(LinearLayout linearLayout,
TextView authorTextView,
TextView authorFlairTextView,
TextView commentTimeTextView,
TextView awardsTextView,
RecyclerView commentMarkdownView,
ConstraintLayout bottomConstraintLayout,
MaterialButton upvoteButton,
TextView scoreTextView,
MaterialButton downvoteButton,
View placeholder,
MaterialButton moreButton,
MaterialButton saveButton,
TextView expandButton,
MaterialButton replyButton,
CommentIndentationView commentIndentationView,
View commentDivider) {
this.linearLayout = linearLayout;
this.authorTextView = authorTextView;
this.authorFlairTextView = authorFlairTextView;
this.commentTimeTextView = commentTimeTextView;
this.awardsTextView = awardsTextView;
this.commentMarkdownView = commentMarkdownView;
this.bottomConstraintLayout = bottomConstraintLayout;
this.upvoteButton = upvoteButton;
this.scoreTextView = scoreTextView;
this.downvoteButton = downvoteButton;
this.placeholder = placeholder;
this.moreButton = moreButton;
this.saveButton = saveButton;
this.replyButton = replyButton;
this.commentDivider = commentDivider;
ButterKnife.bind(this, itemView);
replyButton.setVisibility(View.GONE);
@@ -430,19 +413,19 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
authorFlairTextView.setTypeface(mActivity.typeface);
commentTimeTextView.setTypeface(mActivity.typeface);
awardsTextView.setTypeface(mActivity.typeface);
upvoteButton.setTypeface(mActivity.typeface);
scoreTextView.setTypeface(mActivity.typeface);
}
itemView.setBackgroundColor(mCommentBackgroundColor);
authorTextView.setTextColor(mUsernameColor);
authorFlairTextView.setTextColor(mAuthorFlairColor);
commentTimeTextView.setTextColor(mSecondaryTextColor);
awardsTextView.setTextColor(mSecondaryTextColor);
upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
scoreTextView.setTextColor(mCommentIconAndInfoColor);
downvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
moreButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
saveButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
replyButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
moreButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
saveButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
replyButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
commentDivider.setBackgroundColor(mDividerColor);
authorTextView.setOnClickListener(view -> {
@@ -534,22 +517,20 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
int previousVoteType = comment.getVoteType();
int newVoteType;
downvoteButton.setIconResource(R.drawable.ic_downvote_24dp);
downvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
if (previousVoteType != Comment.VOTE_TYPE_UPVOTE) {
//Not upvoted before
comment.setVoteType(Comment.VOTE_TYPE_UPVOTE);
newVoteType = Integer.parseInt(APIUtils.DIR_UPVOTE);
upvoteButton.setIconResource(R.drawable.ic_upvote_filled_24dp);
upvoteButton.setIconTint(ColorStateList.valueOf(mUpvotedColor));
upvoteButton
.setColorFilter(mUpvotedColor, PorterDuff.Mode.SRC_IN);
scoreTextView.setTextColor(mUpvotedColor);
} else {
//Upvoted before
comment.setVoteType(Comment.VOTE_TYPE_NO_VOTE);
newVoteType = Integer.parseInt(APIUtils.DIR_UNVOTE);
upvoteButton.setIconResource(R.drawable.ic_upvote_24dp);
upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
scoreTextView.setTextColor(mCommentIconAndInfoColor);
}
@@ -565,25 +546,23 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
if (newVoteType == Integer.parseInt(APIUtils.DIR_UPVOTE)) {
comment.setVoteType(Comment.VOTE_TYPE_UPVOTE);
if (currentPosition == position) {
upvoteButton.setIconResource(R.drawable.ic_upvote_filled_24dp);
upvoteButton.setIconTint(ColorStateList.valueOf(mUpvotedColor));
upvoteButton.setColorFilter(mUpvotedColor, PorterDuff.Mode.SRC_IN);
scoreTextView.setTextColor(mUpvotedColor);
}
} else {
comment.setVoteType(Comment.VOTE_TYPE_NO_VOTE);
if (currentPosition == position) {
upvoteButton.setIconResource(R.drawable.ic_upvote_24dp);
upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
scoreTextView.setTextColor(mCommentIconAndInfoColor);
}
}
if (currentPosition == position) {
downvoteButton.setIconResource(R.drawable.ic_downvote_24dp);
downvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
}
}
@@ -594,10 +573,6 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
}
});
scoreTextView.setOnClickListener(view -> {
upvoteButton.performClick();
});
downvoteButton.setOnClickListener(view -> {
if (mAccessToken == null) {
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
@@ -613,22 +588,19 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
int previousVoteType = comment.getVoteType();
int newVoteType;
upvoteButton.setIconResource(R.drawable.ic_upvote_24dp);
upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
if (previousVoteType != Comment.VOTE_TYPE_DOWNVOTE) {
//Not downvoted before
comment.setVoteType(Comment.VOTE_TYPE_DOWNVOTE);
newVoteType = Integer.parseInt(APIUtils.DIR_DOWNVOTE);
downvoteButton.setIconResource(R.drawable.ic_downvote_filled_24dp);
downvoteButton.setIconTint(ColorStateList.valueOf(mDownvotedColor));
downvoteButton.setColorFilter(mDownvotedColor, PorterDuff.Mode.SRC_IN);
scoreTextView.setTextColor(mDownvotedColor);
} else {
//Downvoted before
comment.setVoteType(Comment.VOTE_TYPE_NO_VOTE);
newVoteType = Integer.parseInt(APIUtils.DIR_UNVOTE);
downvoteButton.setIconResource(R.drawable.ic_downvote_24dp);
downvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
scoreTextView.setTextColor(mCommentIconAndInfoColor);
}
@@ -644,24 +616,22 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
if (newVoteType == Integer.parseInt(APIUtils.DIR_DOWNVOTE)) {
comment.setVoteType(Comment.VOTE_TYPE_DOWNVOTE);
if (currentPosition == position) {
downvoteButton.setIconResource(R.drawable.ic_downvote_filled_24dp);
downvoteButton.setIconTint(ColorStateList.valueOf(mDownvotedColor));
downvoteButton.setColorFilter(mDownvotedColor, PorterDuff.Mode.SRC_IN);
scoreTextView.setTextColor(mDownvotedColor);
}
} else {
comment.setVoteType(Comment.VOTE_TYPE_NO_VOTE);
if (currentPosition == position) {
downvoteButton.setIconResource(R.drawable.ic_downvote_24dp);
downvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
scoreTextView.setTextColor(mCommentIconAndInfoColor);
}
}
if (currentPosition == position) {
upvoteButton.setIconResource(R.drawable.ic_upvote_24dp);
upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
}
}
@@ -687,7 +657,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
public void success() {
comment.setSaved(false);
if (getBindingAdapterPosition() == position) {
saveButton.setIconResource(R.drawable.ic_bookmark_border_grey_24dp);
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
}
Toast.makeText(mActivity, R.string.comment_unsaved_success, Toast.LENGTH_SHORT).show();
}
@@ -696,7 +666,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
public void failed() {
comment.setSaved(true);
if (getBindingAdapterPosition() == position) {
saveButton.setIconResource(R.drawable.ic_bookmark_grey_24dp);
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
}
Toast.makeText(mActivity, R.string.comment_unsaved_failed, Toast.LENGTH_SHORT).show();
}
@@ -708,7 +678,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
public void success() {
comment.setSaved(true);
if (getBindingAdapterPosition() == position) {
saveButton.setIconResource(R.drawable.ic_bookmark_grey_24dp);
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
}
Toast.makeText(mActivity, R.string.comment_saved_success, Toast.LENGTH_SHORT).show();
}
@@ -717,7 +687,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
public void failed() {
comment.setSaved(false);
if (getBindingAdapterPosition() == position) {
saveButton.setIconResource(R.drawable.ic_bookmark_border_grey_24dp);
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
}
Toast.makeText(mActivity, R.string.comment_saved_failed, Toast.LENGTH_SHORT).show();
}
@@ -728,32 +698,6 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
}
}
class CommentViewHolder extends CommentBaseViewHolder {
ItemCommentBinding binding;
CommentViewHolder(ItemCommentBinding binding) {
super(binding.getRoot());
this.binding = binding;
setBaseView(binding.linearLayoutItemComment,
binding.authorTextViewItemPostComment,
binding.authorFlairTextViewItemPostComment,
binding.commentTimeTextViewItemPostComment,
binding.awardsTextViewItemComment,
binding.commentMarkdownViewItemPostComment,
binding.bottomConstraintLayoutItemPostComment,
binding.upvoteButtonItemPostComment,
binding.scoreTextViewItemPostComment,
binding.downvoteButtonItemPostComment,
binding.placeholderItemPostComment,
binding.moreButtonItemPostComment,
binding.saveButtonItemPostComment,
binding.expandButtonItemPostComment,
binding.replyButtonItemPostComment,
binding.verticalBlockIndentationItemComment,
binding.dividerItemComment);
}
}
class ErrorViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.error_text_view_item_footer_error)
TextView errorTextView;

View File

@@ -4,6 +4,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
@@ -30,7 +31,6 @@ import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.request.RequestOptions;
import com.google.android.material.button.MaterialButton;
import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar;
import java.util.ArrayList;
@@ -58,7 +58,6 @@ import eu.toldi.infinityforlemmy.bottomsheetfragments.CommentMoreBottomSheetFrag
import eu.toldi.infinityforlemmy.bottomsheetfragments.UrlMenuBottomSheetFragment;
import eu.toldi.infinityforlemmy.comment.Comment;
import eu.toldi.infinityforlemmy.comment.FetchComment;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilter;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.customviews.CommentIndentationView;
import eu.toldi.infinityforlemmy.customviews.CustomMarkwonAdapter;
@@ -66,7 +65,6 @@ import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
import eu.toldi.infinityforlemmy.customviews.SpoilerOnClickTextView;
import eu.toldi.infinityforlemmy.customviews.SwipeLockInterface;
import eu.toldi.infinityforlemmy.customviews.SwipeLockLinearLayoutManager;
import eu.toldi.infinityforlemmy.databinding.ItemCommentBinding;
import eu.toldi.infinityforlemmy.fragments.ViewPostDetailFragment;
import eu.toldi.infinityforlemmy.markdown.MarkdownUtils;
import eu.toldi.infinityforlemmy.post.Post;
@@ -162,6 +160,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
private int mSingleCommentThreadBackgroundColor;
private int mVoteAndReplyUnavailableVoteButtonColor;
private int mButtonTextColor;
private int mPostIconAndInfoColor;
private int mCommentIconAndInfoColor;
private int mFullyCollapsedCommentBackgroundColor;
private int mAwardedCommentBackgroundColor;
@@ -221,7 +220,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
return true;
};
mCommentMarkwon = MarkdownUtils.createFullRedditMarkwon(mActivity,
miscPlugin, mCommentTextColor, commentSpoilerBackgroundColor, onLinkLongClickListener, sharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false));
miscPlugin, mCommentTextColor, commentSpoilerBackgroundColor, onLinkLongClickListener);
recycledViewPool = new RecyclerView.RecycledViewPool();
mAccessToken = accessToken;
mAccountQualifiedName = accountName;
@@ -279,6 +278,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
mSingleCommentThreadBackgroundColor = customThemeWrapper.getSingleCommentThreadBackgroundColor();
mVoteAndReplyUnavailableVoteButtonColor = customThemeWrapper.getVoteAndReplyUnavailableButtonColor();
mButtonTextColor = customThemeWrapper.getButtonTextColor();
mPostIconAndInfoColor = customThemeWrapper.getPostIconAndInfoColor();
mCommentIconAndInfoColor = customThemeWrapper.getCommentIconAndInfoColor();
mFullyCollapsedCommentBackgroundColor = customThemeWrapper.getFullyCollapsedCommentBackgroundColor();
mAwardedCommentBackgroundColor = customThemeWrapper.getAwardedCommentBackgroundColor();
@@ -360,7 +360,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
case VIEW_TYPE_NO_COMMENT_PLACEHOLDER:
return new NoCommentViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_no_comment_placeholder, parent, false));
case VIEW_TYPE_COMMENT:
return new CommentViewHolder(ItemCommentBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));
return new CommentViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_comment, parent, false));
case VIEW_TYPE_COMMENT_FULLY_COLLAPSED:
return new CommentFullyCollapsedViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_comment_fully_collapsed, parent, false));
case VIEW_TYPE_LOAD_MORE_CHILD_COMMENTS:
@@ -376,7 +376,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if (holder instanceof CommentBaseViewHolder) {
if (holder instanceof CommentViewHolder) {
Comment comment = getCurrentComment(position);
if (comment != null) {
if (mIsSingleCommentThreadMode && comment.getId() == mSingleCommentId) {
@@ -384,23 +384,23 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
}
String authorDisplayName = (mShowUserDisplayName) ? comment.getAuthorName() : comment.getAuthor().getUsername();
String authorInstance = (mHideUserInstance) ? "" : "@" + comment.getAuthor().getQualifiedName().split(Pattern.quote("@"))[1];
((CommentBaseViewHolder) holder).authorTextView.setText(authorDisplayName + authorInstance);
((CommentViewHolder) holder).authorTextView.setText(authorDisplayName + authorInstance);
if (comment.isSubmitter()) {
((CommentBaseViewHolder) holder).authorTextView.setTextColor(mSubmitterColor);
((CommentViewHolder) holder).authorTextView.setTextColor(mSubmitterColor);
Drawable submitterDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_mic_14dp, mSubmitterColor);
((CommentBaseViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(
((CommentViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(
submitterDrawable, null, null, null);
} else if (comment.isModerator()) {
((CommentBaseViewHolder) holder).authorTextView.setTextColor(mModeratorColor);
((CommentViewHolder) holder).authorTextView.setTextColor(mModeratorColor);
Drawable moderatorDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_verified_user_14dp, mModeratorColor);
((CommentBaseViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(
((CommentViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(
moderatorDrawable, null, null, null);
} else if (comment.getAuthorQualifiedName().equals(mAccountQualifiedName)) {
((CommentBaseViewHolder) holder).authorTextView.setTextColor(mCurrentUserColor);
((CommentViewHolder) holder).authorTextView.setTextColor(mCurrentUserColor);
Drawable currentUserDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_current_user_14dp, mCurrentUserColor);
((CommentBaseViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(
((CommentViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(
currentUserDrawable, null, null, null);
}
@@ -416,7 +416,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
.error(mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
.into(((CommentBaseViewHolder) holder).authorIconImageView);
.into(((CommentViewHolder) holder).authorIconImageView);
}
});
} else {
@@ -424,33 +424,33 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
.error(mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
.into(((CommentBaseViewHolder) holder).authorIconImageView);
.into(((CommentViewHolder) holder).authorIconImageView);
}
if (mShowElapsedTime) {
((CommentBaseViewHolder) holder).commentTimeTextView.setText(
((CommentViewHolder) holder).commentTimeTextView.setText(
Utils.getElapsedTime(mActivity, comment.getCommentTimeMillis()));
} else {
((CommentBaseViewHolder) holder).commentTimeTextView.setText(Utils.getFormattedTime(mLocale, comment.getCommentTimeMillis(), mTimeFormatPattern));
((CommentViewHolder) holder).commentTimeTextView.setText(Utils.getFormattedTime(mLocale, comment.getCommentTimeMillis(), mTimeFormatPattern));
}
if (mCommentToolbarHidden) {
((CommentBaseViewHolder) holder).bottomConstraintLayout.getLayoutParams().height = 0;
((CommentViewHolder) holder).bottomConstraintLayout.getLayoutParams().height = 0;
if (!mHideTheNumberOfVotes) {
((CommentBaseViewHolder) holder).topScoreTextView.setVisibility(View.VISIBLE);
((CommentViewHolder) holder).topScoreTextView.setVisibility(View.VISIBLE);
}
} else {
((CommentBaseViewHolder) holder).bottomConstraintLayout.getLayoutParams().height = LinearLayout.LayoutParams.WRAP_CONTENT;
((CommentBaseViewHolder) holder).topScoreTextView.setVisibility(View.GONE);
((CommentViewHolder) holder).bottomConstraintLayout.getLayoutParams().height = LinearLayout.LayoutParams.WRAP_CONTENT;
((CommentViewHolder) holder).topScoreTextView.setVisibility(View.GONE);
}
((CommentBaseViewHolder) holder).mMarkwonAdapter.setMarkdown(mCommentMarkwon, comment.getCommentMarkdown());
((CommentViewHolder) holder).mMarkwonAdapter.setMarkdown(mCommentMarkwon, comment.getCommentMarkdown());
// noinspection NotifyDataSetChanged
((CommentBaseViewHolder) holder).mMarkwonAdapter.notifyDataSetChanged();
((CommentViewHolder) holder).mMarkwonAdapter.notifyDataSetChanged();
if (mHideDownvotes) {
((CommentBaseViewHolder) holder).downvoteButton.setVisibility(View.GONE);
((CommentBaseViewHolder) holder).downvoteTextView.setVisibility(View.GONE);
((CommentViewHolder) holder).downvoteButton.setVisibility(View.GONE);
((CommentViewHolder) holder).downvoteTextView.setVisibility(View.GONE);
}
if (!mHideTheNumberOfVotes) {
@@ -466,89 +466,96 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
if (mSeperateUpandDownvote) {
int upvotes = (comment.getVoteType() == 1) ? comment.getUpvotes() + 1 : comment.getUpvotes();
int downvotes = (comment.getVoteType() == -1) ? comment.getDownvotes() + 1 : comment.getDownvotes();
((CommentBaseViewHolder) holder).downvoteTextView.setVisibility(View.VISIBLE);
((CommentBaseViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, upvotes));
((CommentBaseViewHolder) holder).downvoteTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, downvotes));
((CommentBaseViewHolder) holder).scoreTextView.setGravity(Gravity.START);
((CommentBaseViewHolder) holder).scoreTextView.getLayoutParams().width = (int) (32 * mActivity.getResources().getDisplayMetrics().density);
((CommentViewHolder) holder).downvoteTextView.setVisibility(View.VISIBLE);
((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, upvotes));
((CommentViewHolder) holder).downvoteTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, downvotes));
((CommentViewHolder) holder).scoreTextView.setGravity(Gravity.START);
((CommentViewHolder) holder).scoreTextView.getLayoutParams().width = (int) (32 * mActivity.getResources().getDisplayMetrics().density);
((CommentBaseViewHolder) holder).scoreTextView.setPadding(0, 0, 6, 0);
((CommentBaseViewHolder) holder).downvoteButton.setPadding(24, 0, 12, 0);
((CommentBaseViewHolder) holder).upvoteButton.setPadding(24, 0, 12, 0);
((CommentViewHolder) holder).scoreTextView.setPadding(0, 0, 6, 0);
((CommentViewHolder) holder).downvoteButton.setPadding(24, 0, 12, 0);
((CommentViewHolder) holder).upvoteButton.setPadding(24, 0, 12, 0);
} else {
((CommentBaseViewHolder) holder).scoreTextView.setText(commentText);
((CommentViewHolder) holder).scoreTextView.setText(commentText);
}
((CommentBaseViewHolder) holder).topScoreTextView.setText(topScoreText);
((CommentViewHolder) holder).topScoreTextView.setText(topScoreText);
} else {
((CommentBaseViewHolder) holder).scoreTextView.setText(mActivity.getString(R.string.vote));
((CommentViewHolder) holder).scoreTextView.setText(mActivity.getString(R.string.vote));
}
if (comment.isEdited()) {
((CommentBaseViewHolder) holder).editedTextView.setVisibility(View.VISIBLE);
((CommentViewHolder) holder).editedTextView.setVisibility(View.VISIBLE);
} else {
((CommentBaseViewHolder) holder).editedTextView.setVisibility(View.GONE);
((CommentViewHolder) holder).editedTextView.setVisibility(View.GONE);
}
((CommentBaseViewHolder) holder).commentIndentationView.setShowOnlyOneDivider(mShowOnlyOneCommentLevelIndicator);
((CommentBaseViewHolder) holder).commentIndentationView.setLevelAndColors(comment.getDepth(), verticalBlockColors);
((CommentViewHolder) holder).commentIndentationView.setShowOnlyOneDivider(mShowOnlyOneCommentLevelIndicator);
((CommentViewHolder) holder).commentIndentationView.setLevelAndColors(comment.getDepth(), verticalBlockColors);
if (comment.getDepth() >= mDepthThreshold) {
((CommentBaseViewHolder) holder).saveButton.setVisibility(View.GONE);
((CommentBaseViewHolder) holder).replyButton.setVisibility(View.GONE);
((CommentViewHolder) holder).saveButton.setVisibility(View.GONE);
((CommentViewHolder) holder).replyButton.setVisibility(View.GONE);
} else {
((CommentBaseViewHolder) holder).saveButton.setVisibility(View.VISIBLE);
((CommentBaseViewHolder) holder).replyButton.setVisibility(View.VISIBLE);
((CommentViewHolder) holder).saveButton.setVisibility(View.VISIBLE);
((CommentViewHolder) holder).replyButton.setVisibility(View.VISIBLE);
}
if (comment.hasReply()) {
if (comment.getChildCount() > 0 && (mAlwaysShowChildCommentCount || !comment.isExpanded())) {
((CommentBaseViewHolder) holder).expandButton.setText("+" + comment.getChildCount());
((CommentViewHolder) holder).expandButton.setText("+" + comment.getChildCount());
}
if (comment.isExpanded()) {
((CommentBaseViewHolder) holder).expandButton.setCompoundDrawablesWithIntrinsicBounds(collapseDrawable, null, null, null);
((CommentViewHolder) holder).expandButton.setCompoundDrawablesWithIntrinsicBounds(collapseDrawable, null, null, null);
} else {
((CommentBaseViewHolder) holder).expandButton.setCompoundDrawablesWithIntrinsicBounds(expandDrawable, null, null, null);
((CommentViewHolder) holder).expandButton.setCompoundDrawablesWithIntrinsicBounds(expandDrawable, null, null, null);
}
((CommentBaseViewHolder) holder).expandButton.setVisibility(View.VISIBLE);
((CommentViewHolder) holder).expandButton.setVisibility(View.VISIBLE);
}
switch (comment.getVoteType()) {
case Comment.VOTE_TYPE_UPVOTE:
((CommentBaseViewHolder) holder).upvoteButton.setIconResource(R.drawable.ic_upvote_filled_24dp);
((CommentBaseViewHolder) holder).upvoteButton.setIconTint(ColorStateList.valueOf(mUpvotedColor));
((CommentBaseViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor);
((CommentBaseViewHolder) holder).topScoreTextView.setTextColor(mUpvotedColor);
((CommentBaseViewHolder) holder).downvoteTextView.setTextColor(mCommentIconAndInfoColor);
((CommentViewHolder) holder).upvoteButton
.setColorFilter(mUpvotedColor, PorterDuff.Mode.SRC_IN);
((CommentViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor);
((CommentViewHolder) holder).topScoreTextView.setTextColor(mUpvotedColor);
((CommentViewHolder) holder).downvoteTextView.setTextColor(mCommentIconAndInfoColor);
break;
case Comment.VOTE_TYPE_DOWNVOTE:
((CommentBaseViewHolder) holder).downvoteButton.setIconResource(R.drawable.ic_downvote_filled_24dp);
((CommentBaseViewHolder) holder).downvoteButton.setIconTint(ColorStateList.valueOf(mDownvotedColor));
if (mSeperateUpandDownvote) {
((CommentBaseViewHolder) holder).downvoteTextView.setTextColor(mDownvotedColor);
((CommentBaseViewHolder) holder).scoreTextView.setTextColor(mCommentIconAndInfoColor);
((CommentViewHolder) holder).downvoteButton
.setColorFilter(mDownvotedColor, PorterDuff.Mode.SRC_IN);
if(mSeperateUpandDownvote) {
((CommentViewHolder) holder).downvoteTextView.setTextColor(mDownvotedColor);
((CommentViewHolder) holder).scoreTextView.setTextColor(mCommentIconAndInfoColor);
} else {
((CommentBaseViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor);
((CommentViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor);
}
((CommentBaseViewHolder) holder).topScoreTextView.setTextColor(mDownvotedColor);
((CommentViewHolder) holder).topScoreTextView.setTextColor(mDownvotedColor);
break;
default:
((CommentBaseViewHolder) holder).downvoteTextView.setTextColor(mCommentIconAndInfoColor);
((CommentViewHolder) holder).downvoteTextView.setTextColor(mCommentIconAndInfoColor);
}
if (mPost.isArchived()) {
((CommentBaseViewHolder) holder).replyButton.setIconTint(ColorStateList.valueOf(mVoteAndReplyUnavailableVoteButtonColor));
((CommentBaseViewHolder) holder).upvoteButton.setIconTint(ColorStateList.valueOf(mVoteAndReplyUnavailableVoteButtonColor));
((CommentBaseViewHolder) holder).scoreTextView.setTextColor(mVoteAndReplyUnavailableVoteButtonColor);
((CommentBaseViewHolder) holder).downvoteButton.setIconTint(ColorStateList.valueOf(mVoteAndReplyUnavailableVoteButtonColor));
((CommentViewHolder) holder).replyButton
.setColorFilter(mVoteAndReplyUnavailableVoteButtonColor,
PorterDuff.Mode.SRC_IN);
((CommentViewHolder) holder).upvoteButton
.setColorFilter(mVoteAndReplyUnavailableVoteButtonColor,
PorterDuff.Mode.SRC_IN);
((CommentViewHolder) holder).downvoteButton
.setColorFilter(mVoteAndReplyUnavailableVoteButtonColor,
PorterDuff.Mode.SRC_IN);
}
if (mPost.isLocked()) {
((CommentBaseViewHolder) holder).replyButton.setIconTint(ColorStateList.valueOf(mVoteAndReplyUnavailableVoteButtonColor));
((CommentViewHolder) holder).replyButton
.setColorFilter(mVoteAndReplyUnavailableVoteButtonColor,
PorterDuff.Mode.SRC_IN);
}
if (comment.isSaved()) {
((CommentBaseViewHolder) holder).saveButton.setIconResource(R.drawable.ic_bookmark_grey_24dp);
((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
} else {
((CommentBaseViewHolder) holder).saveButton.setIconResource(R.drawable.ic_bookmark_border_grey_24dp);
((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
}
if (position == mSearchCommentIndex) {
@@ -654,7 +661,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
SortType.Type sortType = mCommentRecyclerViewAdapterCallback.getSortType();
FetchComment.fetchComments(mExecutor, new Handler(), retrofit, mAccessToken,
mPost.getId(), parentComment.getId(), sortType,
mExpandChildren, 1, new CommentFilter(), new FetchComment.FetchCommentListener() {
mExpandChildren, 1, new FetchComment.FetchCommentListener() {
@Override
public void onFetchCommentSuccess(ArrayList<Comment> expandedComments, Integer parentId, ArrayList<Integer> children) {
if (parentComment.getId() == mVisibleComments.get(parentPosition).getId()) {
@@ -811,6 +818,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
/**
* Find position of comment with given {@code fullName} and
* {@link Comment#NOT_PLACEHOLDER} placeholder type
*
* @return position of the placeholder or -1 if not found
*/
private int findCommentPosition(int fullName, int positionHint) {
@@ -820,6 +828,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
/**
* Find position of comment with given {@code fullName} and
* {@link Comment#PLACEHOLDER_LOAD_MORE_COMMENTS} placeholder type
*
* @return position of the placeholder or -1 if not found
*/
private int findLoadMoreCommentsPlaceholderPosition(int id, int positionHint) {
@@ -1114,18 +1123,18 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
}
public void onItemSwipe(RecyclerView.ViewHolder viewHolder, int direction, int swipeLeftAction, int swipeRightAction) {
if (viewHolder instanceof CommentBaseViewHolder) {
if (viewHolder instanceof CommentViewHolder) {
if (direction == ItemTouchHelper.LEFT || direction == ItemTouchHelper.START) {
if (swipeLeftAction == SharedPreferencesUtils.SWIPE_ACITON_UPVOTE) {
((CommentBaseViewHolder) viewHolder).upvoteButton.performClick();
((CommentViewHolder) viewHolder).upvoteButton.performClick();
} else if (swipeLeftAction == SharedPreferencesUtils.SWIPE_ACITON_DOWNVOTE) {
((CommentBaseViewHolder) viewHolder).downvoteButton.performClick();
((CommentViewHolder) viewHolder).downvoteButton.performClick();
}
} else {
if (swipeRightAction == SharedPreferencesUtils.SWIPE_ACITON_UPVOTE) {
((CommentBaseViewHolder) viewHolder).upvoteButton.performClick();
((CommentViewHolder) viewHolder).upvoteButton.performClick();
} else if (swipeRightAction == SharedPreferencesUtils.SWIPE_ACITON_DOWNVOTE) {
((CommentBaseViewHolder) viewHolder).downvoteButton.performClick();
((CommentViewHolder) viewHolder).downvoteButton.performClick();
}
}
}
@@ -1152,23 +1161,21 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
@Override
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
if (holder instanceof CommentBaseViewHolder) {
if (holder instanceof CommentViewHolder) {
holder.itemView.setBackgroundColor(mCommentBackgroundColor);
((CommentBaseViewHolder) holder).authorTextView.setTextColor(mUsernameColor);
((CommentBaseViewHolder) holder).authorFlairTextView.setVisibility(View.GONE);
((CommentBaseViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
mGlide.clear(((CommentBaseViewHolder) holder).authorIconImageView);
((CommentBaseViewHolder) holder).topScoreTextView.setTextColor(mSecondaryTextColor);
((CommentBaseViewHolder) holder).awardsTextView.setText("");
((CommentBaseViewHolder) holder).awardsTextView.setVisibility(View.GONE);
((CommentBaseViewHolder) holder).expandButton.setVisibility(View.GONE);
((CommentBaseViewHolder) holder).upvoteButton.setIconResource(R.drawable.ic_upvote_24dp);
((CommentBaseViewHolder) holder).upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
((CommentBaseViewHolder) holder).scoreTextView.setTextColor(mCommentIconAndInfoColor);
((CommentBaseViewHolder) holder).downvoteButton.setIconResource(R.drawable.ic_downvote_24dp);
((CommentBaseViewHolder) holder).downvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
((CommentBaseViewHolder) holder).expandButton.setText("");
((CommentBaseViewHolder) holder).replyButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
((CommentViewHolder) holder).authorTextView.setTextColor(mUsernameColor);
((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.GONE);
((CommentViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
mGlide.clear(((CommentViewHolder) holder).authorIconImageView);
((CommentViewHolder) holder).topScoreTextView.setTextColor(mSecondaryTextColor);
((CommentViewHolder) holder).awardsTextView.setText("");
((CommentViewHolder) holder).awardsTextView.setVisibility(View.GONE);
((CommentViewHolder) holder).expandButton.setVisibility(View.GONE);
((CommentViewHolder) holder).upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
((CommentViewHolder) holder).scoreTextView.setTextColor(mCommentIconAndInfoColor);
((CommentViewHolder) holder).downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
((CommentViewHolder) holder).expandButton.setText("");
((CommentViewHolder) holder).replyButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
params.setMargins(0, 0, 0, 0);
}
@@ -1203,76 +1210,55 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
SortType.Type getSortType();
}
public class CommentBaseViewHolder extends RecyclerView.ViewHolder {
public class CommentViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.linear_layout_item_comment)
LinearLayout linearLayout;
@BindView(R.id.author_icon_image_view_item_post_comment)
ImageView authorIconImageView;
@BindView(R.id.author_text_view_item_post_comment)
TextView authorTextView;
@BindView(R.id.author_flair_text_view_item_post_comment)
TextView authorFlairTextView;
@BindView(R.id.comment_time_text_view_item_post_comment)
TextView commentTimeTextView;
@BindView(R.id.top_score_text_view_item_post_comment)
TextView topScoreTextView;
@BindView(R.id.awards_text_view_item_comment)
TextView awardsTextView;
@BindView(R.id.comment_markdown_view_item_post_comment)
RecyclerView commentMarkdownView;
@BindView(R.id.edited_text_view_item_post_comment)
TextView editedTextView;
@BindView(R.id.bottom_constraint_layout_item_post_comment)
ConstraintLayout bottomConstraintLayout;
MaterialButton upvoteButton;
@BindView(R.id.up_vote_button_item_post_comment)
ImageView upvoteButton;
@BindView(R.id.score_text_view_item_post_comment)
TextView scoreTextView;
@BindView(R.id.downvote_text_view_item_post_comment)
TextView downvoteTextView;
MaterialButton downvoteButton;
@BindView(R.id.down_vote_button_item_post_comment)
ImageView downvoteButton;
@BindView(R.id.placeholder_item_post_comment)
View placeholder;
MaterialButton moreButton;
MaterialButton saveButton;
@BindView(R.id.more_button_item_post_comment)
ImageView moreButton;
@BindView(R.id.save_button_item_post_comment)
ImageView saveButton;
@BindView(R.id.expand_button_item_post_comment)
TextView expandButton;
MaterialButton replyButton;
@BindView(R.id.reply_button_item_post_comment)
ImageView replyButton;
@BindView(R.id.vertical_block_indentation_item_comment)
CommentIndentationView commentIndentationView;
@BindView(R.id.divider_item_comment)
View commentDivider;
CustomMarkwonAdapter mMarkwonAdapter;
CommentBaseViewHolder(@NonNull View itemView) {
CommentViewHolder(View itemView) {
super(itemView);
}
void setBaseView(LinearLayout linearLayout,
ImageView authorIconImageView,
TextView authorTextView,
TextView authorFlairTextView,
TextView commentTimeTextView,
TextView topScoreTextView,
TextView awardsTextView,
RecyclerView commentMarkdownView,
TextView editedTextView,
ConstraintLayout bottomConstraintLayout,
MaterialButton upvoteButton,
TextView scoreTextView,
MaterialButton downvoteButton,
TextView downvoteTextView,
View placeholder,
MaterialButton moreButton,
MaterialButton saveButton,
TextView expandButton,
MaterialButton replyButton,
CommentIndentationView commentIndentationView,
View commentDivider) {
this.linearLayout = linearLayout;
this.authorIconImageView = authorIconImageView;
this.authorTextView = authorTextView;
this.authorFlairTextView = authorFlairTextView;
this.commentTimeTextView = commentTimeTextView;
this.topScoreTextView = topScoreTextView;
this.awardsTextView = awardsTextView;
this.commentMarkdownView = commentMarkdownView;
this.editedTextView = editedTextView;
this.bottomConstraintLayout = bottomConstraintLayout;
this.upvoteButton = upvoteButton;
this.scoreTextView = scoreTextView;
this.downvoteButton = downvoteButton;
this.downvoteTextView = downvoteTextView;
this.placeholder = placeholder;
this.moreButton = moreButton;
this.saveButton = saveButton;
this.expandButton = expandButton;
this.replyButton = replyButton;
this.commentIndentationView = commentIndentationView;
this.commentDivider = commentDivider;
ButterKnife.bind(this, itemView);
if (mVoteButtonsOnTheRight) {
ConstraintSet constraintSet = new ConstraintSet();
@@ -1374,14 +1360,14 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
editedTextView.setTextColor(mSecondaryTextColor);
awardsTextView.setTextColor(mSecondaryTextColor);
commentDivider.setBackgroundColor(mDividerColor);
upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
scoreTextView.setTextColor(mCommentIconAndInfoColor);
downvoteTextView.setTextColor(mCommentIconAndInfoColor);
downvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
moreButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
moreButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
expandButton.setTextColor(mCommentIconAndInfoColor);
saveButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
replyButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
saveButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
replyButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
authorFlairTextView.setOnClickListener(view -> authorTextView.performClick());
@@ -1468,23 +1454,20 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
int previousVoteType = comment.getVoteType();
int newVoteType;
downvoteButton.setIconResource(R.drawable.ic_downvote_24dp);
downvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
if (previousVoteType != Comment.VOTE_TYPE_UPVOTE) {
//Not upvoted before
comment.setVoteType(Comment.VOTE_TYPE_UPVOTE);
newVoteType = Integer.parseInt(APIUtils.DIR_UPVOTE);
upvoteButton.setIconResource(R.drawable.ic_upvote_filled_24dp);
upvoteButton.setIconTint(ColorStateList.valueOf(mUpvotedColor));
upvoteButton.setColorFilter(mUpvotedColor, PorterDuff.Mode.SRC_IN);
scoreTextView.setTextColor(mUpvotedColor);
topScoreTextView.setTextColor(mUpvotedColor);
} else {
//Upvoted before
comment.setVoteType(Comment.VOTE_TYPE_NO_VOTE);
newVoteType = Integer.parseInt(APIUtils.DIR_UNVOTE);
upvoteButton.setIconResource(R.drawable.ic_upvote_24dp);
upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
scoreTextView.setTextColor(mCommentIconAndInfoColor);
downvoteTextView.setTextColor(mCommentIconAndInfoColor);
topScoreTextView.setTextColor(mSecondaryTextColor);
@@ -1514,8 +1497,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
if (newVoteType == Integer.parseInt(APIUtils.DIR_UPVOTE)) {
comment.setVoteType(Comment.VOTE_TYPE_UPVOTE);
if (currentPosition == position) {
upvoteButton.setIconResource(R.drawable.ic_upvote_filled_24dp);
upvoteButton.setIconTint(ColorStateList.valueOf(mUpvotedColor));
upvoteButton.setColorFilter(mUpvotedColor, PorterDuff.Mode.SRC_IN);
scoreTextView.setTextColor(mUpvotedColor);
topScoreTextView.setTextColor(mUpvotedColor);
downvoteTextView.setTextColor(mCommentIconAndInfoColor);
@@ -1523,8 +1505,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
} else {
comment.setVoteType(Comment.VOTE_TYPE_NO_VOTE);
if (currentPosition == position) {
upvoteButton.setIconResource(R.drawable.ic_upvote_24dp);
upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
scoreTextView.setTextColor(mCommentIconAndInfoColor);
topScoreTextView.setTextColor(mSecondaryTextColor);
downvoteTextView.setTextColor(mCommentIconAndInfoColor);
@@ -1532,10 +1513,9 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
}
if (currentPosition == position) {
downvoteButton.setIconResource(R.drawable.ic_downvote_24dp);
downvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
if (!mHideTheNumberOfVotes) {
if (mSeperateUpandDownvote) {
if(mSeperateUpandDownvote){
int upvoteCount = (comment.getVoteType() == 1) ? comment.getUpvotes() + 1 : comment.getUpvotes();
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
upvoteCount));
@@ -1560,14 +1540,6 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
}
});
scoreTextView.setOnClickListener(view -> {
upvoteButton.performClick();
});
downvoteTextView.setOnClickListener(view -> {
downvoteButton.performClick();
});
downvoteButton.setOnClickListener(view -> {
if (mPost.isArchived()) {
Toast.makeText(mActivity, R.string.archived_post_vote_unavailable, Toast.LENGTH_SHORT).show();
@@ -1584,19 +1556,17 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
int previousVoteType = comment.getVoteType();
int newVoteType;
upvoteButton.setIconResource(R.drawable.ic_upvote_24dp);
upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
if (previousVoteType != Comment.VOTE_TYPE_DOWNVOTE) {
//Not downvoted before
comment.setVoteType(Comment.VOTE_TYPE_DOWNVOTE);
newVoteType = Integer.parseInt(APIUtils.DIR_DOWNVOTE);
downvoteButton.setIconResource(R.drawable.ic_downvote_filled_24dp);
downvoteButton.setIconTint(ColorStateList.valueOf(mDownvotedColor));
if (mSeperateUpandDownvote) {
downvoteButton.setColorFilter(mDownvotedColor, PorterDuff.Mode.SRC_IN);
if(mSeperateUpandDownvote){
downvoteTextView.setTextColor(mDownvotedColor);
scoreTextView.setTextColor(mCommentIconAndInfoColor);
} else {
}else {
scoreTextView.setTextColor(mDownvotedColor);
}
topScoreTextView.setTextColor(mDownvotedColor);
@@ -1604,8 +1574,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
//Downvoted before
comment.setVoteType(Comment.VOTE_TYPE_NO_VOTE);
newVoteType = Integer.parseInt(APIUtils.DIR_UNVOTE);
downvoteButton.setIconResource(R.drawable.ic_downvote_24dp);
downvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
downvoteTextView.setTextColor(mCommentIconAndInfoColor);
scoreTextView.setTextColor(mCommentIconAndInfoColor);
topScoreTextView.setTextColor(mSecondaryTextColor);
@@ -1635,8 +1604,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
if (newVoteType == Integer.parseInt(APIUtils.DIR_DOWNVOTE)) {
comment.setVoteType(Comment.VOTE_TYPE_DOWNVOTE);
if (currentPosition == position) {
downvoteButton.setIconResource(R.drawable.ic_downvote_filled_24dp);
downvoteButton.setIconTint(ColorStateList.valueOf(mDownvotedColor));
downvoteButton.setColorFilter(mDownvotedColor, PorterDuff.Mode.SRC_IN);
if (mSeperateUpandDownvote) {
downvoteTextView.setTextColor(mDownvotedColor);
} else {
@@ -1647,8 +1615,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
} else {
comment.setVoteType(Comment.VOTE_TYPE_NO_VOTE);
if (currentPosition == position) {
downvoteButton.setIconResource(R.drawable.ic_downvote_24dp);
downvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
scoreTextView.setTextColor(mCommentIconAndInfoColor);
downvoteTextView.setTextColor(mCommentIconAndInfoColor);
topScoreTextView.setTextColor(mSecondaryTextColor);
@@ -1656,12 +1623,11 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
}
if (currentPosition == position) {
upvoteButton.setIconResource(R.drawable.ic_upvote_24dp);
upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
if (!mHideTheNumberOfVotes) {
if (mSeperateUpandDownvote) {
int downvotes = (comment.getVoteType() == -1) ? comment.getDownvotes() + 1 : comment.getDownvotes();
int upvotes = (comment.getVoteType() == 1) ? comment.getUpvotes() + 1 : comment.getUpvotes();
if(mSeperateUpandDownvote){
int downvotes = (comment.getVoteType() == -1) ? comment.getDownvotes() +1 : comment.getDownvotes();
int upvotes = (comment.getVoteType() == 1) ? comment.getUpvotes() +1 : comment.getUpvotes();
downvoteTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, downvotes));
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
upvotes));
@@ -1669,6 +1635,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
}
topScoreTextView.setText(mActivity.getString(R.string.top_score,
Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType())));
@@ -1695,7 +1662,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
public void success() {
comment.setSaved(false);
if (getBindingAdapterPosition() == position) {
saveButton.setIconResource(R.drawable.ic_bookmark_border_grey_24dp);
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
}
Toast.makeText(mActivity, R.string.comment_unsaved_success, Toast.LENGTH_SHORT).show();
}
@@ -1704,7 +1671,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
public void failed() {
comment.setSaved(true);
if (getBindingAdapterPosition() == position) {
saveButton.setIconResource(R.drawable.ic_bookmark_grey_24dp);
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
}
Toast.makeText(mActivity, R.string.comment_unsaved_failed, Toast.LENGTH_SHORT).show();
}
@@ -1716,7 +1683,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
public void success() {
comment.setSaved(true);
if (getBindingAdapterPosition() == position) {
saveButton.setIconResource(R.drawable.ic_bookmark_grey_24dp);
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
}
Toast.makeText(mActivity, R.string.comment_saved_success, Toast.LENGTH_SHORT).show();
}
@@ -1725,7 +1692,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
public void failed() {
comment.setSaved(false);
if (getBindingAdapterPosition() == position) {
saveButton.setIconResource(R.drawable.ic_bookmark_border_grey_24dp);
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
}
Toast.makeText(mActivity, R.string.comment_saved_failed, Toast.LENGTH_SHORT).show();
}
@@ -1863,36 +1830,6 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
}
}
class CommentViewHolder extends CommentBaseViewHolder {
ItemCommentBinding binding;
CommentViewHolder(ItemCommentBinding binding) {
super(binding.getRoot());
this.binding = binding;
setBaseView(binding.linearLayoutItemComment,
binding.authorIconImageViewItemPostComment,
binding.authorTextViewItemPostComment,
binding.authorFlairTextViewItemPostComment,
binding.commentTimeTextViewItemPostComment,
binding.topScoreTextViewItemPostComment,
binding.awardsTextViewItemComment,
binding.commentMarkdownViewItemPostComment,
binding.editedTextViewItemPostComment,
binding.bottomConstraintLayoutItemPostComment,
binding.upvoteButtonItemPostComment,
binding.scoreTextViewItemPostComment,
binding.downvoteButtonItemPostComment,
binding.downvoteTextViewItemPostComment,
binding.placeholderItemPostComment,
binding.moreButtonItemPostComment,
binding.saveButtonItemPostComment,
binding.expandButtonItemPostComment,
binding.replyButtonItemPostComment,
binding.verticalBlockIndentationItemComment,
binding.dividerItemComment);
}
}
@Nullable
private Comment getCurrentComment(RecyclerView.ViewHolder holder) {
return getCurrentComment(holder.getBindingAdapterPosition());

View File

@@ -1,41 +0,0 @@
package eu.toldi.infinityforlemmy.adapters;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import androidx.annotation.NonNull;
import java.util.List;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
public class CustomArrayAdapter extends ArrayAdapter<String> {
CustomThemeWrapper customThemeWrapper;
public CustomArrayAdapter(@NonNull Context context, int textViewResourceId, @NonNull List<String> objects, CustomThemeWrapper customThemeWrapper) {
super(context, textViewResourceId, objects);
this.customThemeWrapper = customThemeWrapper;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView itemView = (TextView) super.getView(position, convertView, parent);
itemView.setTextColor(customThemeWrapper.getPrimaryTextColor()); // Set the text color
itemView.setBackgroundColor(customThemeWrapper.getBackgroundColor()); // Set the background color
// Apply any other styling as needed
return itemView;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
TextView itemView = (TextView) super.getDropDownView(position, convertView, parent);
itemView.setTextColor(customThemeWrapper.getPrimaryTextColor()); // Set the text color
itemView.setBackgroundColor(customThemeWrapper.getBackgroundColor()); // Set the background color
// Apply any other styling as needed
return itemView;
}
}

View File

@@ -12,15 +12,11 @@ import java.util.List;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.activities.BaseActivity;
import eu.toldi.infinityforlemmy.adapters.navigationdrawer.PostFilterUsageEmbeddedRecyclerViewAdapter;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
import eu.toldi.infinityforlemmy.databinding.ItemPostFilterWithUsageBinding;
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
import eu.toldi.infinityforlemmy.postfilter.PostFilterWithUsage;
import eu.toldi.infinityforlemmy.utils.Utils;
public class PostFilterWithUsageRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
public class PostFilterRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int VIEW_TYPE_HEADER = 1;
private static final int VIEW_TYPE_POST_FILTER = 2;
@@ -28,18 +24,16 @@ public class PostFilterWithUsageRecyclerViewAdapter extends RecyclerView.Adapter
private BaseActivity activity;
private CustomThemeWrapper customThemeWrapper;
private final OnItemClickListener onItemClickListener;
private List<PostFilterWithUsage> postFilterWithUsageList;
private RecyclerView.RecycledViewPool recycledViewPool;
private List<PostFilter> postFilterList;
public interface OnItemClickListener {
void onItemClick(PostFilter postFilter);
}
public PostFilterWithUsageRecyclerViewAdapter(BaseActivity activity, CustomThemeWrapper customThemeWrapper,
OnItemClickListener onItemClickListener) {
public PostFilterRecyclerViewAdapter(BaseActivity activity, CustomThemeWrapper customThemeWrapper,
OnItemClickListener onItemClickListener) {
this.activity = activity;
this.customThemeWrapper = customThemeWrapper;
this.recycledViewPool = new RecyclerView.RecycledViewPool();
this.onItemClickListener = onItemClickListener;
}
@@ -57,49 +51,43 @@ public class PostFilterWithUsageRecyclerViewAdapter extends RecyclerView.Adapter
if (viewType == VIEW_TYPE_HEADER) {
return new HeaderViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_filter_fragment_header, parent, false));
} else {
return new PostFilterViewHolder(ItemPostFilterWithUsageBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));
return new PostFilterViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_filter, parent, false));
}
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if (holder instanceof PostFilterViewHolder) {
((PostFilterViewHolder) holder).binding.postFilterNameTextViewItemPostFilter.setText(postFilterWithUsageList.get(position - 1).postFilter.name);
((PostFilterViewHolder) holder).adapter.setPostFilterUsageList(postFilterWithUsageList.get(position - 1).postFilterUsages);
((PostFilterViewHolder) holder).textView.setText(postFilterList.get(position - 1).name);
}
}
@Override
public int getItemCount() {
return postFilterWithUsageList == null ? 1 : 1 + postFilterWithUsageList.size();
return postFilterList == null ? 1 : 1 + postFilterList.size();
}
public void setPostFilterWithUsageList(List<PostFilterWithUsage> postFilterWithUsageList) {
this.postFilterWithUsageList = postFilterWithUsageList;
public void setPostFilterList(List<PostFilter> postFilterList) {
this.postFilterList = postFilterList;
notifyDataSetChanged();
}
private class PostFilterViewHolder extends RecyclerView.ViewHolder {
ItemPostFilterWithUsageBinding binding;
PostFilterUsageEmbeddedRecyclerViewAdapter adapter;
TextView textView;
public PostFilterViewHolder(@NonNull ItemPostFilterWithUsageBinding binding) {
super(binding.getRoot());
this.binding = binding;
binding.postFilterNameTextViewItemPostFilter.setTextColor(customThemeWrapper.getPrimaryTextColor());
public PostFilterViewHolder(@NonNull View itemView) {
super(itemView);
textView = (TextView) itemView;
textView.setTextColor(customThemeWrapper.getPrimaryTextColor());
if (activity.typeface != null) {
binding.postFilterNameTextViewItemPostFilter.setTypeface(activity.typeface);
textView.setTypeface(activity.typeface);
}
binding.getRoot().setOnClickListener(view -> {
onItemClickListener.onItemClick(postFilterWithUsageList.get(getBindingAdapterPosition() - 1).postFilter);
itemView.setOnClickListener(view -> {
onItemClickListener.onItemClick(postFilterList.get(getBindingAdapterPosition() - 1));
});
binding.postFilterUsageRecyclerViewItemPostFilter.setRecycledViewPool(recycledViewPool);
binding.postFilterUsageRecyclerViewItemPostFilter.setLayoutManager(new LinearLayoutManagerBugFixed(activity));
adapter = new PostFilterUsageEmbeddedRecyclerViewAdapter(activity);
binding.postFilterUsageRecyclerViewItemPostFilter.setAdapter(adapter);
}
}
@@ -112,4 +100,4 @@ public class PostFilterWithUsageRecyclerViewAdapter extends RecyclerView.Adapter
infoTextView.setCompoundDrawablesWithIntrinsicBounds(Utils.getTintedDrawable(activity, R.drawable.ic_info_preference_24dp, activity.customThemeWrapper.getPrimaryIconColor()), null, null, null);
}
}
}
}

View File

@@ -37,7 +37,6 @@ import me.saket.bettermovementmethod.BetterLinkMovementMethod;
public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecyclerViewAdapter.RuleViewHolder> {
private BaseActivity activity;
private Markwon markwon;
private boolean mDisableImagePreview;
@Nullable
private final SliderPanel sliderPanel;
private ArrayList<Rule> rules;
@@ -45,11 +44,10 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler
public RulesRecyclerViewAdapter(@NonNull BaseActivity activity,
@NonNull CustomThemeWrapper customThemeWrapper,
@Nullable SliderPanel sliderPanel, boolean disableImagePreview) {
@Nullable SliderPanel sliderPanel) {
this.activity = activity;
this.sliderPanel = sliderPanel;
mPrimaryTextColor = customThemeWrapper.getPrimaryTextColor();
mDisableImagePreview = disableImagePreview;
int spoilerBackgroundColor = mPrimaryTextColor | 0xFF000000;
MarkwonPlugin miscPlugin = new AbstractMarkwonPlugin() {
@Override
@@ -84,7 +82,7 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler
return true;
};
markwon = MarkdownUtils.createFullRedditMarkwon(activity,
miscPlugin, mPrimaryTextColor, spoilerBackgroundColor, onLinkLongClickListener, mDisableImagePreview);
miscPlugin, mPrimaryTextColor, spoilerBackgroundColor, onLinkLongClickListener);
}
@NonNull

View File

@@ -2,17 +2,21 @@ package eu.toldi.infinityforlemmy.adapters;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.activities.BaseActivity;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.databinding.ItemRecentSearchQueryBinding;
import eu.toldi.infinityforlemmy.recentsearchquery.RecentSearchQuery;
import eu.toldi.infinityforlemmy.utils.Utils;
@@ -41,14 +45,14 @@ public class SearchActivityRecyclerViewAdapter extends RecyclerView.Adapter<Recy
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new RecentSearchQueryViewHolder(ItemRecentSearchQueryBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));
return new RecentSearchQueryViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recent_search_query, parent, false));
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if (holder instanceof RecentSearchQueryViewHolder) {
if (recentSearchQueries != null && !recentSearchQueries.isEmpty() && position < recentSearchQueries.size()) {
((RecentSearchQueryViewHolder) holder).binding.recentSearchQueryTextViewItemRecentSearchQuery.setText(recentSearchQueries.get(position).getSearchQuery());
((RecentSearchQueryViewHolder) holder).recentSearchQueryTextView.setText(recentSearchQueries.get(position).getSearchQuery());
}
}
}
@@ -64,18 +68,22 @@ public class SearchActivityRecyclerViewAdapter extends RecyclerView.Adapter<Recy
}
class RecentSearchQueryViewHolder extends RecyclerView.ViewHolder {
ItemRecentSearchQueryBinding binding;
@BindView(R.id.recent_search_query_text_view_item_recent_search_query)
TextView recentSearchQueryTextView;
@BindView(R.id.delete_image_view_item_recent_search_query)
ImageView deleteImageView;
public RecentSearchQueryViewHolder(@NonNull ItemRecentSearchQueryBinding binding) {
super(binding.getRoot());
this.binding = binding;
public RecentSearchQueryViewHolder(@NonNull View itemView) {
super(itemView);
binding.recentSearchQueryTextViewItemRecentSearchQuery.setTextColor(primaryTextColor);
binding.recentSearchQueryTextViewItemRecentSearchQuery.setCompoundDrawablesWithIntrinsicBounds(historyIcon, null, null, null);
binding.deleteButtonItemRecentSearchQuery.setIcon(deleteIcon);
ButterKnife.bind(this, itemView);
recentSearchQueryTextView.setTextColor(primaryTextColor);
recentSearchQueryTextView.setCompoundDrawablesWithIntrinsicBounds(historyIcon, null, null, null);
deleteImageView.setImageDrawable(deleteIcon);
if (activity.typeface != null) {
binding.recentSearchQueryTextViewItemRecentSearchQuery.setTypeface(activity.typeface);
recentSearchQueryTextView.setTypeface(activity.typeface);
}
itemView.setOnClickListener(view -> {
@@ -84,7 +92,7 @@ public class SearchActivityRecyclerViewAdapter extends RecyclerView.Adapter<Recy
}
});
binding.deleteButtonItemRecentSearchQuery.setOnClickListener(view -> {
deleteImageView.setOnClickListener(view -> {
itemOnClickListener.onDelete(recentSearchQueries.get(getBindingAdapterPosition()));
});
}

View File

@@ -1,102 +0,0 @@
package eu.toldi.infinityforlemmy.adapters.navigationdrawer;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.activities.BaseActivity;
import eu.toldi.infinityforlemmy.databinding.ItemPostFilterUsageEmbeddedBinding;
import eu.toldi.infinityforlemmy.postfilter.PostFilterUsage;
public class PostFilterUsageEmbeddedRecyclerViewAdapter extends RecyclerView.Adapter<PostFilterUsageEmbeddedRecyclerViewAdapter.EntryViewHolder> {
private BaseActivity baseActivity;
private List<PostFilterUsage> postFilterUsageList;
public PostFilterUsageEmbeddedRecyclerViewAdapter(BaseActivity baseActivity) {
this.baseActivity = baseActivity;
}
@NonNull
@Override
public EntryViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new EntryViewHolder(ItemPostFilterUsageEmbeddedBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));
}
@Override
public void onBindViewHolder(@NonNull EntryViewHolder holder, int position) {
if (postFilterUsageList == null || postFilterUsageList.isEmpty()) {
holder.textView.setText(R.string.click_to_apply_post_filter);
} else if (holder.getBindingAdapterPosition() > 4) {
holder.textView.setText(baseActivity.getString(R.string.post_filter_usage_embedded_more_count, postFilterUsageList.size() - 5));
} else {
PostFilterUsage postFilterUsage = postFilterUsageList.get(holder.getBindingAdapterPosition());
switch (postFilterUsage.usage) {
case PostFilterUsage.HOME_TYPE:
holder.textView.setText(R.string.post_filter_usage_home);
break;
case PostFilterUsage.SUBREDDIT_TYPE:
if (postFilterUsage.nameOfUsage.equals(PostFilterUsage.NO_USAGE)) {
holder.textView.setText(R.string.post_filter_usage_embedded_subreddit_all);
} else {
holder.textView.setText("r/" + postFilterUsage.nameOfUsage);
}
break;
case PostFilterUsage.USER_TYPE:
if (postFilterUsage.nameOfUsage.equals(PostFilterUsage.NO_USAGE)) {
holder.textView.setText(R.string.post_filter_usage_embedded_user_all);
} else {
holder.textView.setText("u/" + postFilterUsage.nameOfUsage);
}
break;
case PostFilterUsage.SEARCH_TYPE:
holder.textView.setText(R.string.post_filter_usage_search);
break;
case PostFilterUsage.MULTIREDDIT_TYPE:
if (postFilterUsage.nameOfUsage.equals(PostFilterUsage.NO_USAGE)) {
holder.textView.setText(R.string.post_filter_usage_embedded_multireddit_all);
} else {
holder.textView.setText(postFilterUsage.nameOfUsage);
}
break;
}
}
}
@Override
public int getItemCount() {
return postFilterUsageList == null || postFilterUsageList.isEmpty() ? 1 : (postFilterUsageList.size() > 5 ? 6 : postFilterUsageList.size());
}
public void setPostFilterUsageList(List<PostFilterUsage> postFilterUsageList) {
this.postFilterUsageList = postFilterUsageList;
notifyDataSetChanged();
}
class EntryViewHolder extends RecyclerView.ViewHolder {
TextView textView;
public EntryViewHolder(@NonNull ItemPostFilterUsageEmbeddedBinding binding) {
super(binding.getRoot());
textView = binding.getRoot();
textView.setTextColor(baseActivity.customThemeWrapper.getSecondaryTextColor());
if (baseActivity.typeface != null) {
textView.setTypeface(baseActivity.typeface);
}
textView.setOnClickListener(view -> {
Toast.makeText(baseActivity, textView.getText(), Toast.LENGTH_SHORT).show();
});
}
}
}

View File

@@ -66,9 +66,6 @@ public interface LemmyAPI {
@GET("api/v3/user/unread_count")
Call<MessageCount> userUnreadCount(@NonNull @Query("auth") String access_token);
@GET("api/v3/user/validate_auth")
Call<String> userValidateAuth();
@Headers("Content-Type: application/json")
@POST("api/v3/user/mention/mark_as_read")
Call<String> userMentionMarkAsRead(@Body ReadMessageDTO params);

View File

@@ -54,19 +54,19 @@ public interface RedditAPI {
@GET("user/{username}/about.json?raw_json=1")
Call<String> getUserData(@Path("username") String username);
@GET("user/{username}/about.json?raw_json=1&limit=100")
@GET("user/{username}/about.json?raw_json=1")
Call<String> getUserDataOauth(@HeaderMap Map<String, String> headers, @Path("username") String username);
@GET("user/{username}/comments.json?raw_json=1&limit=100")
@GET("user/{username}/comments.json?raw_json=1")
Call<String> getUserComments(@Path("username") String username, @Query("after") String after,
@Query("sort") SortType.Type sortType, @Query("t") SortType.Time sortTime);
@GET("user/{username}/comments.json?raw_json=1&limit=100")
@GET("user/{username}/comments.json?raw_json=1")
Call<String> getUserCommentsOauth(@HeaderMap Map<String, String> headers, @Path("username") String username,
@Query("after") String after, @Query("sort") SortType.Type sortType,
@Query("t") SortType.Time sortTime);
@GET("user/{username}/{where}.json?&type=comments&raw_json=1&limit=100")
@GET("user/{username}/{where}.json?&type=comments&raw_json=1&limit=25")
Call<String> getUserSavedCommentsOauth(@Path("username") String username, @Path("where") String where,
@Query("after") String lastItem, @Query("sort") SortType.Type sortType,
@Query("t") SortType.Time sortTime, @HeaderMap Map<String, String> headers);
@@ -273,108 +273,108 @@ public interface RedditAPI {
@GET("/r/{subredditName}/wiki/{wikiPage}.json?raw_json=1")
Call<String> getWikiPage(@Path("subredditName") String subredditName, @Path("wikiPage") String wikiPage);
@GET("{sortType}?raw_json=1&limit=100")
@GET("{sortType}?raw_json=1")
ListenableFuture<Response<String>> getBestPostsListenableFuture(@Path("sortType") SortType.Type sortType, @Query("t") SortType.Time sortTime,
@Query("after") String lastItem, @HeaderMap Map<String, String> headers);
@GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=100&always_show_media=1")
@GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=25&always_show_media=1")
ListenableFuture<Response<String>> getSubredditBestPostsOauthListenableFuture(@Path("subredditName") String subredditName, @Path("sortType") SortType.Type sortType,
@Query("t") SortType.Time sortTime, @Query("after") String lastItem,
@HeaderMap Map<String, String> headers);
@GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=100&always_show_media=1")
@GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=25&always_show_media=1")
ListenableFuture<Response<String>> getSubredditBestPostsListenableFuture(@Path("subredditName") String subredditName, @Path("sortType") SortType.Type sortType,
@Query("t") SortType.Time sortTime, @Query("after") String lastItem);
@GET("user/{username}/{where}.json?&type=links&raw_json=1&limit=100")
@GET("user/{username}/{where}.json?&type=links&raw_json=1&limit=25")
ListenableFuture<Response<String>> getUserPostsOauthListenableFuture(@Path("username") String username, @Path("where") String where,
@Query("after") String lastItem, @Query("sort") SortType.Type sortType,
@Query("t") SortType.Time sortTime, @HeaderMap Map<String, String> headers);
@GET("user/{username}/submitted.json?raw_json=1&limit=100")
@GET("user/{username}/submitted.json?raw_json=1&limit=25")
ListenableFuture<Response<String>> getUserPostsListenableFuture(@Path("username") String username, @Query("after") String lastItem,
@Query("sort") SortType.Type sortType, @Query("t") SortType.Time sortTime);
@GET("search.json?include_over_18=1&raw_json=1&limit=100&type=link")
@GET("search.json?include_over_18=1&raw_json=1&type=link")
ListenableFuture<Response<String>> searchPostsOauthListenableFuture(@Query("q") String query, @Query("after") String after,
@Query("sort") SortType.Type sort, @Query("t") SortType.Time sortTime,
@Query("source") String source,
@HeaderMap Map<String, String> headers);
@GET("search.json?include_over_18=1&raw_json=1&limit=100&type=link")
@GET("search.json?include_over_18=1&raw_json=1&type=link")
ListenableFuture<Response<String>> searchPostsListenableFuture(@Query("q") String query, @Query("after") String after,
@Query("sort") SortType.Type sort, @Query("t") SortType.Time sortTime,
@Query("source") String source);
@GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&limit=100&type=link&restrict_sr=true")
@GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&type=link&restrict_sr=true")
ListenableFuture<Response<String>> searchPostsInSpecificSubredditOauthListenableFuture(@Path("subredditName") String subredditName,
@Query("q") String query, @Query("sort") SortType.Type sort,
@Query("t") SortType.Time sortTime, @Query("after") String after,
@HeaderMap Map<String, String> headers);
@GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&limit=100&type=link&restrict_sr=true")
@GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&type=link&restrict_sr=true")
ListenableFuture<Response<String>> searchPostsInSpecificSubredditListenableFuture(@Path("subredditName") String subredditName,
@Query("q") String query, @Query("sort") SortType.Type sort,
@Query("t") SortType.Time sortTime, @Query("after") String after);
@GET("{multipath}?raw_json=1&limit=100")
@GET("{multipath}?raw_json=1")
ListenableFuture<Response<String>> getMultiRedditPostsListenableFuture(@Path(value = "multipath", encoded = true) String multiPath,
@Query("after") String after, @Query("t") SortType.Time sortTime);
@GET("{multipath}.json?raw_json=1&limit=100")
@GET("{multipath}.json?raw_json=1")
ListenableFuture<Response<String>> getMultiRedditPostsOauthListenableFuture(@Path(value = "multipath", encoded = true) String multiPath,
@Query("after") String after, @Query("t") SortType.Time sortTime,
@HeaderMap Map<String, String> headers);
@GET("{sortType}?raw_json=1&limit=100")
@GET("{sortType}?raw_json=1")
Call<String> getBestPosts(@Path("sortType") SortType.Type sortType, @Query("t") SortType.Time sortTime,
@Query("after") String lastItem, @HeaderMap Map<String, String> headers);
@GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=100&always_show_media=1")
@GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=25&always_show_media=1")
Call<String> getSubredditBestPostsOauth(@Path("subredditName") String subredditName, @Path("sortType") SortType.Type sortType,
@Query("t") SortType.Time sortTime, @Query("after") String lastItem,
@HeaderMap Map<String, String> headers);
@GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=100&always_show_media=1")
@GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=25&always_show_media=1")
Call<String> getSubredditBestPosts(@Path("subredditName") String subredditName, @Path("sortType") SortType.Type sortType,
@Query("t") SortType.Time sortTime, @Query("after") String lastItem);
@GET("user/{username}/{where}.json?&type=links&raw_json=1&limit=100")
@GET("user/{username}/{where}.json?&type=links&raw_json=1&limit=25")
Call<String> getUserPostsOauth(@Path("username") String username, @Path("where") String where,
@Query("after") String lastItem, @Query("sort") SortType.Type sortType,
@Query("t") SortType.Time sortTime, @HeaderMap Map<String, String> headers);
@GET("user/{username}/submitted.json?raw_json=1&limit=100")
@GET("user/{username}/submitted.json?raw_json=1&limit=25")
Call<String> getUserPosts(@Path("username") String username, @Query("after") String lastItem,
@Query("sort") SortType.Type sortType, @Query("t") SortType.Time sortTime);
@GET("search.json?include_over_18=1&raw_json=1&limit=100&type=link")
@GET("search.json?include_over_18=1&raw_json=1&type=link")
Call<String> searchPostsOauth(@Query("q") String query, @Query("after") String after,
@Query("sort") SortType.Type sort, @Query("t") SortType.Time sortTime,
@Query("source") String source,
@HeaderMap Map<String, String> headers);
@GET("search.json?include_over_18=1&raw_json=1&limit=100&type=link")
@GET("search.json?include_over_18=1&raw_json=1&type=link")
Call<String> searchPosts(@Query("q") String query, @Query("after") String after,
@Query("sort") SortType.Type sort, @Query("t") SortType.Time sortTime,
@Query("source") String source);
@GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&limit=100&type=link&restrict_sr=true")
@GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&type=link&restrict_sr=true")
Call<String> searchPostsInSpecificSubredditOauth(@Path("subredditName") String subredditName,
@Query("q") String query, @Query("sort") SortType.Type sort,
@Query("t") SortType.Time sortTime, @Query("after") String after,
@HeaderMap Map<String, String> headers);
@GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&limit=100&type=link&restrict_sr=true")
@GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&type=link&restrict_sr=true")
Call<String> searchPostsInSpecificSubreddit(@Path("subredditName") String subredditName,
@Query("q") String query, @Query("sort") SortType.Type sort,
@Query("t") SortType.Time sortTime, @Query("after") String after);
@GET("{multipath}?raw_json=1&limit=100")
@GET("{multipath}?raw_json=1")
Call<String> getMultiRedditPosts(@Path(value = "multipath", encoded = true) String multiPath,
@Query("after") String after, @Query("t") SortType.Time sortTime);
@GET("{multipath}.json?raw_json=1&limit=100")
@GET("{multipath}.json?raw_json=1")
Call<String> getMultiRedditPostsOauth(@Path(value = "multipath", encoded = true) String multiPath,
@Query("after") String after, @Query("t") SortType.Time sortTime,
@HeaderMap Map<String, String> headers);

View File

@@ -49,7 +49,6 @@ public class InsertSubscribedThings {
for (SubscribedSubredditData s : subscribedSubredditDataList) {
if (existingSubscribedSubredditDataList.contains(s)) {
subscribedSubredditDao.updateSubscribedSubreddit(s.getQualified_name(), s.getName(), s.getIconUrl(), accountName);
continue;
}
subscribedSubredditDao.insert(s);

View File

@@ -1,63 +0,0 @@
package eu.toldi.infinityforlemmy.bottomsheetfragments;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import eu.toldi.infinityforlemmy.activities.CommentFilterPreferenceActivity;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilter;
import eu.toldi.infinityforlemmy.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment;
import eu.toldi.infinityforlemmy.databinding.FragmentCommentFilterOptionsBottomSheetBinding;
import eu.toldi.infinityforlemmy.utils.Utils;
public class CommentFilterOptionsBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment {
public static final String EXTRA_POST_FILTER = "EPF";
private CommentFilterPreferenceActivity activity;
public CommentFilterOptionsBottomSheetFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
FragmentCommentFilterOptionsBottomSheetBinding binding = FragmentCommentFilterOptionsBottomSheetBinding.inflate(inflater, container, false);
CommentFilter commentFilter = getArguments().getParcelable(EXTRA_POST_FILTER);
binding.editTextViewCommentFilterOptionsBottomSheetFragment.setOnClickListener(view -> {
activity.editCommentFilter(commentFilter);
dismiss();
});
binding.applyToTextViewCommentFilterOptionsBottomSheetFragment.setOnClickListener(view -> {
activity.applyCommentFilterTo(commentFilter);
dismiss();
});
binding.deleteTextViewCommentFilterOptionsBottomSheetFragment.setOnClickListener(view -> {
activity.deleteCommentFilter(commentFilter);
dismiss();
});
if (activity.typeface != null) {
Utils.setFontToAllTextViews(binding.getRoot(), activity.typeface);
}
return binding.getRoot();
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
activity = (CommentFilterPreferenceActivity) context;
}
}

View File

@@ -1,57 +0,0 @@
package eu.toldi.infinityforlemmy.bottomsheetfragments;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import eu.toldi.infinityforlemmy.activities.CommentFilterUsageListingActivity;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilterUsage;
import eu.toldi.infinityforlemmy.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment;
import eu.toldi.infinityforlemmy.databinding.FragmentCommentFilterUsageOptionsBottomSheetBinding;
import eu.toldi.infinityforlemmy.utils.Utils;
public class CommentFilterUsageOptionsBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment {
public static final String EXTRA_COMMENT_FILTER_USAGE = "ECFU";
private CommentFilterUsageListingActivity activity;
public CommentFilterUsageOptionsBottomSheetFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
FragmentCommentFilterUsageOptionsBottomSheetBinding binding = FragmentCommentFilterUsageOptionsBottomSheetBinding.inflate(inflater, container, false);
CommentFilterUsage commentFilterUsage = getArguments().getParcelable(EXTRA_COMMENT_FILTER_USAGE);
binding.editTextViewCommentFilterUsageOptionsBottomSheetFragment.setOnClickListener(view -> {
activity.editCommentFilterUsage(commentFilterUsage);
dismiss();
});
binding.deleteTextViewCommentFilterUsageOptionsBottomSheetFragment.setOnClickListener(view -> {
activity.deleteCommentFilterUsage(commentFilterUsage);
dismiss();
});
if (activity.typeface != null) {
Utils.setFontToAllTextViews(binding.getRoot(), activity.typeface);
}
return binding.getRoot();
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
activity = (CommentFilterUsageListingActivity) context;
}
}

View File

@@ -1,48 +0,0 @@
package eu.toldi.infinityforlemmy.bottomsheetfragments;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import eu.toldi.infinityforlemmy.activities.CommentFilterUsageListingActivity;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilterUsage;
import eu.toldi.infinityforlemmy.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment;
import eu.toldi.infinityforlemmy.databinding.FragmentNewCommentFilterUsageBottomSheetBinding;
import eu.toldi.infinityforlemmy.utils.Utils;
public class NewCommentFilterUsageBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment {
private CommentFilterUsageListingActivity activity;
public NewCommentFilterUsageBottomSheetFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
FragmentNewCommentFilterUsageBottomSheetBinding binding = FragmentNewCommentFilterUsageBottomSheetBinding.inflate(inflater, container, false);
binding.subredditTextViewNewCommentFilterUsageBottomSheetFragment.setOnClickListener(view -> {
activity.newCommentFilterUsage(CommentFilterUsage.SUBREDDIT_TYPE);
dismiss();
});
if (activity.typeface != null) {
Utils.setFontToAllTextViews(binding.getRoot(), activity.typeface);
}
return binding.getRoot();
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
activity = (CommentFilterUsageListingActivity) context;
}
}

View File

@@ -5,17 +5,26 @@ import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import butterknife.BindView;
import butterknife.ButterKnife;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.activities.PostFilterPreferenceActivity;
import eu.toldi.infinityforlemmy.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment;
import eu.toldi.infinityforlemmy.databinding.FragmentPostFilterOptionsBottomSheetBinding;
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
import eu.toldi.infinityforlemmy.utils.Utils;
public class PostFilterOptionsBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment {
@BindView(R.id.edit_text_view_post_filter_options_bottom_sheet_fragment)
TextView editTextView;
@BindView(R.id.apply_to_text_view_post_filter_options_bottom_sheet_fragment)
TextView applyToTextView;
@BindView(R.id.delete_text_view_post_filter_options_bottom_sheet_fragment)
TextView deleteTextView;
public static final String EXTRA_POST_FILTER = "EPF";
private PostFilterPreferenceActivity activity;
@@ -27,30 +36,32 @@ public class PostFilterOptionsBottomSheetFragment extends LandscapeExpandedRound
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
FragmentPostFilterOptionsBottomSheetBinding binding = FragmentPostFilterOptionsBottomSheetBinding.inflate(inflater, container, false);
View rootView = inflater.inflate(R.layout.fragment_post_filter_options_bottom_sheet, container, false);
ButterKnife.bind(this, rootView);
PostFilter postFilter = getArguments().getParcelable(EXTRA_POST_FILTER);
binding.editTextViewPostFilterOptionsBottomSheetFragment.setOnClickListener(view -> {
editTextView.setOnClickListener(view -> {
activity.editPostFilter(postFilter);
dismiss();
});
binding.applyToTextViewPostFilterOptionsBottomSheetFragment.setOnClickListener(view -> {
applyToTextView.setOnClickListener(view -> {
activity.applyPostFilterTo(postFilter);
dismiss();
});
binding.deleteTextViewPostFilterOptionsBottomSheetFragment.setOnClickListener(view -> {
deleteTextView.setOnClickListener(view -> {
activity.deletePostFilter(postFilter);
dismiss();
});
if (activity.typeface != null) {
Utils.setFontToAllTextViews(binding.getRoot(), activity.typeface);
Utils.setFontToAllTextViews(rootView, activity.typeface);
}
return binding.getRoot();
return rootView;
}
@Override

View File

@@ -6,13 +6,16 @@ import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import butterknife.BindView;
import butterknife.ButterKnife;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.activities.BaseActivity;
import eu.toldi.infinityforlemmy.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment;
import eu.toldi.infinityforlemmy.databinding.FragmentPostLayoutBottomSheetBinding;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
import eu.toldi.infinityforlemmy.utils.Utils;
@@ -21,7 +24,14 @@ import eu.toldi.infinityforlemmy.utils.Utils;
*/
public class PostLayoutBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment {
private FragmentPostLayoutBottomSheetBinding binding;
@BindView(R.id.card_layout_text_view_post_layout_bottom_sheet_fragment)
TextView cardLayoutTextView;
@BindView(R.id.card_layout_2_text_view_post_layout_bottom_sheet_fragment)
TextView cardLayout2TextView;
@BindView(R.id.compact_layout_text_view_post_layout_bottom_sheet_fragment)
TextView compactLayoutTextView;
@BindView(R.id.gallery_layout_text_view_post_layout_bottom_sheet_fragment)
TextView galleryLayoutTextView;
private BaseActivity activity;
public PostLayoutBottomSheetFragment() {
// Required empty public constructor
@@ -29,36 +39,33 @@ public class PostLayoutBottomSheetFragment extends LandscapeExpandedRoundedBotto
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
binding = FragmentPostLayoutBottomSheetBinding.inflate(inflater, container, false);
View rootView = inflater.inflate(R.layout.fragment_post_layot_bottom_sheet, container, false);
ButterKnife.bind(this, rootView);
binding.cardLayoutTextViewPostLayoutBottomSheetFragment.setOnClickListener(view -> {
cardLayoutTextView.setOnClickListener(view -> {
((PostLayoutSelectionCallback) activity).postLayoutSelected(SharedPreferencesUtils.POST_LAYOUT_CARD);
dismiss();
});
binding.compactLayoutTextViewPostLayoutBottomSheetFragment.setOnClickListener(view -> {
compactLayoutTextView.setOnClickListener(view -> {
((PostLayoutSelectionCallback) activity).postLayoutSelected(SharedPreferencesUtils.POST_LAYOUT_COMPACT);
dismiss();
});
binding.galleryLayoutTextViewPostLayoutBottomSheetFragment.setOnClickListener(view -> {
galleryLayoutTextView.setOnClickListener(view -> {
((PostLayoutSelectionCallback) activity).postLayoutSelected(SharedPreferencesUtils.POST_LAYOUT_GALLERY);
dismiss();
});
binding.cardLayout2TextViewPostLayoutBottomSheetFragment.setOnClickListener(view -> {
cardLayout2TextView.setOnClickListener(view -> {
((PostLayoutSelectionCallback) activity).postLayoutSelected(SharedPreferencesUtils.POST_LAYOUT_CARD_2);
dismiss();
});
binding.cardLayout3TextViewPostLayoutBottomSheetFragment.setOnClickListener(view -> {
((PostLayoutSelectionCallback) activity).postLayoutSelected(SharedPreferencesUtils.POST_LAYOUT_CARD_3);
dismiss();
});
if (activity.typeface != null) {
Utils.setFontToAllTextViews(binding.getRoot(), activity.typeface);
Utils.setFontToAllTextViews(rootView, activity.typeface);
}
return binding.getRoot();
return rootView;
}
@Override

View File

@@ -0,0 +1,73 @@
package eu.toldi.infinityforlemmy.bottomsheetfragments;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.util.Linkify;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import me.saket.bettermovementmethod.BetterLinkMovementMethod;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.activities.LinkResolverActivity;
import eu.toldi.infinityforlemmy.activities.MainActivity;
import eu.toldi.infinityforlemmy.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment;
import eu.toldi.infinityforlemmy.databinding.FragmentRedditApiInfoBottomSheetBinding;
import eu.toldi.infinityforlemmy.utils.Utils;
public class RedditAPIInfoBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment {
private MainActivity mainActivity;
public RedditAPIInfoBottomSheetFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
FragmentRedditApiInfoBottomSheetBinding binding = FragmentRedditApiInfoBottomSheetBinding.inflate(inflater, container, false);
if (mainActivity != null && mainActivity.typeface != null) {
Utils.setFontToAllTextViews(binding.getRoot(), mainActivity.typeface);
}
binding.getRoot().setNestedScrollingEnabled(true);
SpannableString message = new SpannableString(getString(R.string.reddit_api_info, "https://www.reddit.com/r/reddit/comments/145bram/addressing_the_community_about_changes_to_our_api", "https://www.reddit.com/r/Infinity_For_Reddit/comments/147bhsg/the_future_of_infinity"));
Linkify.addLinks(message, Linkify.WEB_URLS);
binding.messageTextViewRedditApiInfoBottomSheetFragment.setText(message);
binding.messageTextViewRedditApiInfoBottomSheetFragment.setMovementMethod(BetterLinkMovementMethod.newInstance().setOnLinkClickListener((textView, url) -> {
Intent intent = new Intent(mainActivity, LinkResolverActivity.class);
intent.setData(Uri.parse(url));
startActivity(intent);
return true;
}));
binding.messageTextViewRedditApiInfoBottomSheetFragment.setLinkTextColor(getResources().getColor(R.color.colorAccent));
binding.doNotShowThisAgainTextView.setOnClickListener(view -> {
binding.doNotShowThisAgainCheckBox.toggle();
});
binding.continueButtonRedditApiInfoBottomSheetFragment.setOnClickListener(view -> {
if (binding.doNotShowThisAgainCheckBox.isChecked()) {
mainActivity.doNotShowRedditAPIInfoAgain();
}
dismiss();
});
return binding.getRoot();
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
mainActivity = (MainActivity) context;
}
}

View File

@@ -43,12 +43,6 @@ public class SortTypeBottomSheetFragment extends LandscapeExpandedRoundedBottomS
@BindView(R.id.top_type_text_view_sort_type_bottom_sheet_fragment)
TextView topTypeTextView;
@BindView(R.id.scaled_type_text_view_sort_type_bottom_sheet_fragment)
TextView scaledTypeTextView;
@BindView(R.id.controversial_type_text_view_sort_type_bottom_sheet_fragment)
TextView controversialTypeTextView;
private BaseActivity activity;
public SortTypeBottomSheetFragment() {
@@ -95,10 +89,6 @@ public class SortTypeBottomSheetFragment extends LandscapeExpandedRoundedBottomS
oldTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(oldTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null);
} else if (currentSortType.equals(SortType.Type.TOP.fullName)) {
topTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(topTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null);
} else if (currentSortType.equals(SortType.Type.SCALED.fullName)) {
scaledTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(scaledTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null);
} else if (currentSortType.equals(SortType.Type.CONTROVERSIAL.fullName)) {
controversialTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(controversialTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null);
}
hotTypeTextView.setOnClickListener(view -> {
@@ -121,16 +111,6 @@ public class SortTypeBottomSheetFragment extends LandscapeExpandedRoundedBottomS
dismiss();
});
scaledTypeTextView.setOnClickListener(view -> {
((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.SCALED));
dismiss();
});
controversialTypeTextView.setOnClickListener(view -> {
((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.CONTROVERSIAL));
dismiss();
});
if (activity.typeface != null) {
Utils.setFontToAllTextViews(rootView, activity.typeface);

View File

@@ -35,14 +35,13 @@ public class CommentViewModel extends ViewModel {
hasCommentLiveData = Transformations.switchMap(commentDataSourceFactory.getCommentDataSourceLiveData(),
CommentDataSource::hasPostLiveData);
sortTypeLiveData = new MutableLiveData<>(sortType);
sortTypeLiveData = new MutableLiveData<>();
sortTypeLiveData.postValue(sortType);
PagedList.Config pagedListConfig =
(new PagedList.Config.Builder())
.setEnablePlaceholders(false)
.setPageSize(100)
.setPrefetchDistance(10)
.setInitialLoadSizeHint(10)
.setPageSize(25)
.build();
comments = Transformations.switchMap(sortTypeLiveData, sort -> {

View File

@@ -13,7 +13,6 @@ import java.util.concurrent.Executor;
import eu.toldi.infinityforlemmy.SortType;
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilter;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
@@ -23,20 +22,19 @@ public class FetchComment {
public static void fetchComments(Executor executor, Handler handler, Retrofit retrofit,
@Nullable String accessToken, Integer article,
Integer commentId, SortType.Type sortType, boolean expandChildren,
Integer page, CommentFilter commentFilter, FetchCommentListener fetchCommentListener) {
Integer page, FetchCommentListener fetchCommentListener) {
LemmyAPI api = retrofit.create(LemmyAPI.class);
Call<String> comments;
comments = api.getComments("All", sortType.value, 8, page, 25, null, null, article, commentId, false, accessToken);
comments.enqueue(new Callback<>() {
comments.enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
if (response.isSuccessful()) {
ParseComment.parseComments(executor, handler, response.body(), commentId,
expandChildren, commentFilter,
new ParseComment.ParseCommentListener() {
expandChildren, new ParseComment.ParseCommentListener() {
@Override
public void onParseCommentSuccess(ArrayList<Comment> topLevelComments,
ArrayList<Comment> expandedComments,
@@ -72,7 +70,7 @@ public class FetchComment {
moreComments = api.getComments("All", sortType.value, 8, page, 25, null, null, article, commentId, false, accessToken);
moreComments.enqueue(new Callback<>() {
moreComments.enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
if (response.isSuccessful()) {

View File

@@ -24,14 +24,14 @@ import java.util.TimeZone;
import java.util.concurrent.Executor;
import java.util.regex.Pattern;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilter;
import eu.toldi.infinityforlemmy.user.BasicUserInfo;
import eu.toldi.infinityforlemmy.utils.JSONUtils;
import eu.toldi.infinityforlemmy.utils.LemmyUtils;
public class ParseComment {
public static void parseComments(Executor executor, Handler handler, String response, Integer commentId,
boolean expandChildren, CommentFilter commentFilter,
boolean expandChildren,
ParseCommentListener parseCommentListener) {
executor.execute(() -> {
try {
@@ -50,9 +50,6 @@ public class ParseComment {
orderedComments.add(singleComment);
parsedComments.put(singleComment.getId(), singleComment);
if (singleComment.getDepth() == 0) {
if (!CommentFilter.isCommentAllowed(singleComment, commentFilter)) {
continue;
}
topLevelComments.add(singleComment);
}
}
@@ -61,9 +58,7 @@ public class ParseComment {
if (parentComment.getDepth() == 0) {
parentComment = null;
} else {
if (CommentFilter.isCommentAllowed(parentComment, commentFilter)) {
expandedNewComments.add(parentComment);
}
expandedNewComments.add(parentComment);
}
}
@@ -73,9 +68,6 @@ public class ParseComment {
if (c.getParentId() != null) {
Comment parent = parsedComments.get(c.getParentId());
if (parent != null) {
if (!CommentFilter.isCommentAllowed(c, commentFilter)) {
continue;
}
parent.addChild(c);
}
}
@@ -89,13 +81,8 @@ public class ParseComment {
if (topLevelComments.isEmpty() && !parsedComments.isEmpty() && parentComment != null) {
for (int i = 0; i < orderedComments.size(); i++) {
Comment c = orderedComments.get(i);
if (c.getParentId() == parentComment.getId()) {
if (!CommentFilter.isCommentAllowed(c, commentFilter)) {
continue;
}
if (c.getParentId() == parentComment.getId())
expandedNewComments.add(c);
}
}
}
@@ -218,8 +205,7 @@ public class ParseComment {
}
private static void parseCommentRecursion(JSONArray comments, ArrayList<Comment> newCommentData,
ArrayList<String> moreChildrenIds, int depth,
CommentFilter commentFilter) throws JSONException {
ArrayList<String> moreChildrenIds, int depth) throws JSONException {
int actualCommentLength;
if (comments.length() == 0) {

View File

@@ -1,123 +0,0 @@
package eu.toldi.infinityforlemmy.commentfilter;
import android.os.Parcel;
import android.os.Parcelable;
import androidx.annotation.NonNull;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.PrimaryKey;
import java.util.List;
import eu.toldi.infinityforlemmy.comment.Comment;
@Entity(tableName = "comment_filter")
public class CommentFilter implements Parcelable {
@PrimaryKey
@NonNull
public String name = "New Filter";
@ColumnInfo(name = "max_vote")
public int maxVote = -1;
@ColumnInfo(name = "min_vote")
public int minVote = -1;
@ColumnInfo(name = "exclude_strings")
public String excludeStrings;
@ColumnInfo(name = "exclude_users")
public String excludeUsers;
public CommentFilter() {
}
protected CommentFilter(Parcel in) {
name = in.readString();
maxVote = in.readInt();
minVote = in.readInt();
excludeStrings = in.readString();
excludeUsers = in.readString();
}
public static final Creator<CommentFilter> CREATOR = new Creator<CommentFilter>() {
@Override
public CommentFilter createFromParcel(Parcel in) {
return new CommentFilter(in);
}
@Override
public CommentFilter[] newArray(int size) {
return new CommentFilter[size];
}
};
public static boolean isCommentAllowed(Comment comment, CommentFilter commentFilter) {
int score = comment.getScore() + comment.getVoteType();
if (commentFilter.maxVote >= 0 && score > commentFilter.maxVote) {
return false;
}
if (commentFilter.minVote >= 0 && score < commentFilter.minVote) {
return false;
}
if (commentFilter.excludeStrings != null && !commentFilter.excludeStrings.equals("")) {
String[] titles = commentFilter.excludeStrings.split(",", 0);
for (String t : titles) {
if (!t.trim().equals("") && comment.getCommentRawText().toLowerCase().contains(t.toLowerCase().trim())) {
return false;
}
}
}
if (commentFilter.excludeUsers != null && !commentFilter.excludeUsers.equals("")) {
String[] users = commentFilter.excludeUsers.split(",", 0);
for (String u : users) {
if (!u.trim().equals("") && comment.getAuthor().getQualifiedName().equalsIgnoreCase(u.trim())) {
return false;
}
}
}
return true;
}
public static CommentFilter mergeCommentFilter(List<CommentFilter> commentFilterList) {
if (commentFilterList.size() == 1) {
return commentFilterList.get(0);
}
CommentFilter commentFilter = new CommentFilter();
StringBuilder stringBuilder;
commentFilter.name = "Merged";
for (CommentFilter c : commentFilterList) {
commentFilter.maxVote = Math.min(c.maxVote, commentFilter.maxVote);
commentFilter.minVote = Math.max(c.minVote, commentFilter.minVote);
if (c.excludeStrings != null && !c.excludeStrings.equals("")) {
stringBuilder = new StringBuilder(commentFilter.excludeStrings == null ? "" : commentFilter.excludeStrings);
stringBuilder.append(",").append(c.excludeStrings);
commentFilter.excludeStrings = stringBuilder.toString();
}
if (c.excludeUsers != null && !c.excludeUsers.equals("")) {
stringBuilder = new StringBuilder(commentFilter.excludeUsers == null ? "" : commentFilter.excludeUsers);
stringBuilder.append(",").append(c.excludeUsers);
commentFilter.excludeUsers = stringBuilder.toString();
}
}
return commentFilter;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeString(name);
dest.writeInt(maxVote);
dest.writeInt(minVote);
dest.writeString(excludeStrings);
dest.writeString(excludeUsers);
}
}

View File

@@ -1,47 +0,0 @@
package eu.toldi.infinityforlemmy.commentfilter;
import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Transaction;
import java.util.List;
@Dao
public interface CommentFilterDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insert(CommentFilter CommentFilter);
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insertAll(List<CommentFilter> CommentFilters);
@Query("DELETE FROM comment_filter")
void deleteAllCommentFilters();
@Delete
void deleteCommentFilter(CommentFilter CommentFilter);
@Query("DELETE FROM comment_filter WHERE name = :name")
void deleteCommentFilter(String name);
@Query("SELECT * FROM comment_filter WHERE name = :name LIMIT 1")
CommentFilter getCommentFilter(String name);
@Query("SELECT * FROM comment_filter ORDER BY name")
LiveData<List<CommentFilter>> getAllCommentFiltersLiveData();
@Query("SELECT * FROM comment_filter")
List<CommentFilter> getAllCommentFilters();
@Query("SELECT * FROM comment_filter WHERE (comment_filter.name IN " +
"(SELECT comment_filter_usage.name FROM comment_filter_usage WHERE (usage = :usage AND name_of_usage = :nameOfUsage COLLATE NOCASE)))" +
" OR (comment_filter.name NOT IN (SELECT comment_filter_usage.name FROM comment_filter_usage))")
List<CommentFilter> getValidCommentFilters(int usage, String nameOfUsage);
@Transaction
@Query("SELECT * FROM comment_filter ORDER BY name")
public LiveData<List<CommentFilterWithUsage>> getAllCommentFilterWithUsageLiveData();
}

View File

@@ -1,61 +0,0 @@
package eu.toldi.infinityforlemmy.commentfilter;
import android.os.Parcel;
import android.os.Parcelable;
import androidx.annotation.NonNull;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.ForeignKey;
@Entity(tableName = "comment_filter_usage", primaryKeys = {"name", "usage", "name_of_usage"},
foreignKeys = @ForeignKey(entity = CommentFilter.class, parentColumns = "name",
childColumns = "name", onDelete = ForeignKey.CASCADE))
public class CommentFilterUsage implements Parcelable {
public static final int SUBREDDIT_TYPE = 1;
@NonNull
@ColumnInfo(name = "name")
public String name;
@ColumnInfo(name = "usage")
public int usage;
@NonNull
@ColumnInfo(name = "name_of_usage")
public String nameOfUsage;
public CommentFilterUsage(@NonNull String name, int usage, @NonNull String nameOfUsage) {
this.name = name;
this.usage = usage;
this.nameOfUsage = nameOfUsage;
}
protected CommentFilterUsage(Parcel in) {
name = in.readString();
usage = in.readInt();
nameOfUsage = in.readString();
}
public static final Creator<CommentFilterUsage> CREATOR = new Creator<CommentFilterUsage>() {
@Override
public CommentFilterUsage createFromParcel(Parcel in) {
return new CommentFilterUsage(in);
}
@Override
public CommentFilterUsage[] newArray(int size) {
return new CommentFilterUsage[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeString(name);
dest.writeInt(usage);
dest.writeString(nameOfUsage);
}
}

View File

@@ -1,31 +0,0 @@
package eu.toldi.infinityforlemmy.commentfilter;
import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import java.util.List;
@Dao
public interface CommentFilterUsageDao {
@Query("SELECT * FROM comment_filter_usage WHERE name = :name")
LiveData<List<CommentFilterUsage>> getAllCommentFilterUsageLiveData(String name);
@Query("SELECT * FROM comment_filter_usage WHERE name = :name")
List<CommentFilterUsage> getAllCommentFilterUsage(String name);
@Query("SELECT * FROM comment_filter_usage")
List<CommentFilterUsage> getAllCommentFilterUsageForBackup();
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insert(CommentFilterUsage CommentFilterUsage);
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insertAll(List<CommentFilterUsage> CommentFilterUsageList);
@Delete
void deleteCommentFilterUsage(CommentFilterUsage CommentFilterUsage);
}

View File

@@ -1,41 +0,0 @@
package eu.toldi.infinityforlemmy.commentfilter;
import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;
import java.util.List;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
public class CommentFilterUsageViewModel extends ViewModel {
private LiveData<List<CommentFilterUsage>> mCommentFilterUsageListLiveData;
public CommentFilterUsageViewModel(RedditDataRoomDatabase redditDataRoomDatabase, String name) {
mCommentFilterUsageListLiveData = redditDataRoomDatabase.commentFilterUsageDao().getAllCommentFilterUsageLiveData(name);
}
public LiveData<List<CommentFilterUsage>> getCommentFilterUsageListLiveData() {
return mCommentFilterUsageListLiveData;
}
public static class Factory extends ViewModelProvider.NewInstanceFactory {
private final RedditDataRoomDatabase mRedditDataRoomDatabase;
private final String mName;
public Factory(RedditDataRoomDatabase redditDataRoomDatabase, String name) {
mRedditDataRoomDatabase = redditDataRoomDatabase;
mName = name;
}
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
//noinspection unchecked
return (T) new CommentFilterUsageViewModel(mRedditDataRoomDatabase, mName);
}
}
}

View File

@@ -1,16 +0,0 @@
package eu.toldi.infinityforlemmy.commentfilter;
import androidx.room.Embedded;
import androidx.room.Relation;
import java.util.List;
public class CommentFilterWithUsage {
@Embedded
public CommentFilter commentFilter;
@Relation(
parentColumn = "name",
entityColumn = "name"
)
public List<CommentFilterUsage> commentFilterUsageList;
}

View File

@@ -1,39 +0,0 @@
package eu.toldi.infinityforlemmy.commentfilter;
import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;
import java.util.List;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
public class CommentFilterWithUsageViewModel extends ViewModel {
private LiveData<List<CommentFilterWithUsage>> mCommentFilterWithUsageListLiveData;
public CommentFilterWithUsageViewModel(RedditDataRoomDatabase redditDataRoomDatabase) {
mCommentFilterWithUsageListLiveData = redditDataRoomDatabase.commentFilterDao().getAllCommentFilterWithUsageLiveData();
}
public LiveData<List<CommentFilterWithUsage>> getCommentFilterWithUsageListLiveData() {
return mCommentFilterWithUsageListLiveData;
}
public static class Factory extends ViewModelProvider.NewInstanceFactory {
private final RedditDataRoomDatabase mRedditDataRoomDatabase;
public Factory(RedditDataRoomDatabase redditDataRoomDatabase) {
mRedditDataRoomDatabase = redditDataRoomDatabase;
}
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
//noinspection unchecked
return (T) new CommentFilterWithUsageViewModel(mRedditDataRoomDatabase);
}
}
}

View File

@@ -1,12 +0,0 @@
package eu.toldi.infinityforlemmy.commentfilter;
import java.util.concurrent.Executor;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
public class DeleteCommentFilter {
public static void deleteCommentFilter(RedditDataRoomDatabase redditDataRoomDatabase, Executor executor, CommentFilter commentFilter) {
executor.execute(() -> redditDataRoomDatabase.commentFilterDao().deleteCommentFilter(commentFilter));
}
}

View File

@@ -1,13 +0,0 @@
package eu.toldi.infinityforlemmy.commentfilter;
import java.util.concurrent.Executor;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
public class DeleteCommentFilterUsage {
public static void deleteCommentFilterUsage(RedditDataRoomDatabase redditDataRoomDatabase, Executor executor,
CommentFilterUsage commentFilterUsage) {
executor.execute(() -> redditDataRoomDatabase.commentFilterUsageDao().deleteCommentFilterUsage(commentFilterUsage));
}
}

View File

@@ -1,25 +0,0 @@
package eu.toldi.infinityforlemmy.commentfilter;
import android.os.Handler;
import java.util.List;
import java.util.concurrent.Executor;
;import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
public class FetchCommentFilter {
public static void fetchCommentFilter(Executor executor, Handler handler,
RedditDataRoomDatabase redditDataRoomDatabase,
String subreddit, FetchCommentFilterListener fetchCommentFilterListener) {
executor.execute(() -> {
List<CommentFilter> commentFilterList = redditDataRoomDatabase.commentFilterDao().getValidCommentFilters(CommentFilterUsage.SUBREDDIT_TYPE, subreddit);
CommentFilter commentFilter = CommentFilter.mergeCommentFilter(commentFilterList);
handler.post(() -> fetchCommentFilterListener.success(commentFilter));
});
}
public interface FetchCommentFilterListener {
void success(CommentFilter commentFilter);
}
}

View File

@@ -1,38 +0,0 @@
package eu.toldi.infinityforlemmy.commentfilter;
import android.os.Handler;
import java.util.List;
import java.util.concurrent.Executor;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
public class SaveCommentFilter {
public interface SaveCommentFilterListener {
void success();
void duplicate();
}
public static void saveCommentFilter(Executor executor, Handler handler, RedditDataRoomDatabase redditDataRoomDatabase,
CommentFilter commentFilter, String originalName, SaveCommentFilter.SaveCommentFilterListener saveCommentFilterListener) {
executor.execute(() -> {
if (!originalName.equals(commentFilter.name) &&
redditDataRoomDatabase.commentFilterDao().getCommentFilter(commentFilter.name) != null) {
handler.post(saveCommentFilterListener::duplicate);
} else {
List<CommentFilterUsage> commentFilterUsages = redditDataRoomDatabase.commentFilterUsageDao().getAllCommentFilterUsage(originalName);
if (!originalName.equals(commentFilter.name)) {
redditDataRoomDatabase.commentFilterDao().deleteCommentFilter(originalName);
}
redditDataRoomDatabase.commentFilterDao().insert(commentFilter);
for (CommentFilterUsage commentFilterUsage : commentFilterUsages) {
commentFilterUsage.name = commentFilter.name;
redditDataRoomDatabase.commentFilterUsageDao().insert(commentFilterUsage);
}
handler.post(saveCommentFilterListener::success);
}
});
}
}

View File

@@ -1,13 +0,0 @@
package eu.toldi.infinityforlemmy.commentfilter;
import java.util.concurrent.Executor;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
public class SaveCommentFilterUsage {
public static void saveCommentFilterUsage(RedditDataRoomDatabase redditDataRoomDatabase, Executor executor,
CommentFilterUsage commentFilterUsage) {
executor.execute(() -> redditDataRoomDatabase.commentFilterUsageDao().insert(commentFilterUsage));
}
}

View File

@@ -64,10 +64,6 @@ public class CustomTheme {
public int cardViewBackgroundColor;
@ColumnInfo(name = "read_post_card_view_background_color")
public int readPostCardViewBackgroundColor;
@ColumnInfo(name = "filled_card_view_background_color")
public int filledCardViewBackgroundColor;
@ColumnInfo(name = "read_post_filled_card_view_background_color")
public int readPostFilledCardViewBackgroundColor;
@ColumnInfo(name = "comment_background_color")
public int commentBackgroundColor;
@ColumnInfo(name = "bottom_app_bar_background_color")
@@ -259,73 +255,71 @@ public class CustomTheme {
customTheme.backgroundColor = customThemeSettingsItems.get(19).colorValue;
customTheme.cardViewBackgroundColor = customThemeSettingsItems.get(20).colorValue;
customTheme.readPostCardViewBackgroundColor = customThemeSettingsItems.get(21).colorValue;
customTheme.filledCardViewBackgroundColor = customThemeSettingsItems.get(22).colorValue;
customTheme.readPostFilledCardViewBackgroundColor = customThemeSettingsItems.get(23).colorValue;
customTheme.commentBackgroundColor = customThemeSettingsItems.get(24).colorValue;
customTheme.fullyCollapsedCommentBackgroundColor = customThemeSettingsItems.get(25).colorValue;
customTheme.awardedCommentBackgroundColor = customThemeSettingsItems.get(26).colorValue;
customTheme.receivedMessageBackgroundColor = customThemeSettingsItems.get(27).colorValue;
customTheme.sentMessageBackgroundColor = customThemeSettingsItems.get(28).colorValue;
customTheme.bottomAppBarBackgroundColor = customThemeSettingsItems.get(29).colorValue;
customTheme.primaryIconColor = customThemeSettingsItems.get(30).colorValue;
customTheme.bottomAppBarIconColor = customThemeSettingsItems.get(31).colorValue;
customTheme.postIconAndInfoColor = customThemeSettingsItems.get(32).colorValue;
customTheme.commentIconAndInfoColor = customThemeSettingsItems.get(33).colorValue;
customTheme.fabIconColor = customThemeSettingsItems.get(34).colorValue;
customTheme.sendMessageIconColor = customThemeSettingsItems.get(35).colorValue;
customTheme.toolbarPrimaryTextAndIconColor = customThemeSettingsItems.get(36).colorValue;
customTheme.toolbarSecondaryTextColor = customThemeSettingsItems.get(37).colorValue;
customTheme.circularProgressBarBackground = customThemeSettingsItems.get(38).colorValue;
customTheme.mediaIndicatorIconColor = customThemeSettingsItems.get(39).colorValue;
customTheme.mediaIndicatorBackgroundColor = customThemeSettingsItems.get(40).colorValue;
customTheme.tabLayoutWithExpandedCollapsingToolbarTabBackground = customThemeSettingsItems.get(41).colorValue;
customTheme.tabLayoutWithExpandedCollapsingToolbarTextColor = customThemeSettingsItems.get(42).colorValue;
customTheme.tabLayoutWithExpandedCollapsingToolbarTabIndicator = customThemeSettingsItems.get(43).colorValue;
customTheme.tabLayoutWithCollapsedCollapsingToolbarTabBackground = customThemeSettingsItems.get(44).colorValue;
customTheme.tabLayoutWithCollapsedCollapsingToolbarTextColor = customThemeSettingsItems.get(45).colorValue;
customTheme.tabLayoutWithCollapsedCollapsingToolbarTabIndicator = customThemeSettingsItems.get(46).colorValue;
customTheme.upvoted = customThemeSettingsItems.get(47).colorValue;
customTheme.downvoted = customThemeSettingsItems.get(48).colorValue;
customTheme.postTypeBackgroundColor = customThemeSettingsItems.get(49).colorValue;
customTheme.postTypeTextColor = customThemeSettingsItems.get(50).colorValue;
customTheme.spoilerBackgroundColor = customThemeSettingsItems.get(51).colorValue;
customTheme.spoilerTextColor = customThemeSettingsItems.get(52).colorValue;
customTheme.nsfwBackgroundColor = customThemeSettingsItems.get(53).colorValue;
customTheme.nsfwTextColor = customThemeSettingsItems.get(54).colorValue;
customTheme.flairBackgroundColor = customThemeSettingsItems.get(55).colorValue;
customTheme.flairTextColor = customThemeSettingsItems.get(56).colorValue;
customTheme.awardsBackgroundColor = customThemeSettingsItems.get(57).colorValue;
customTheme.awardsTextColor = customThemeSettingsItems.get(58).colorValue;
customTheme.archivedTint = customThemeSettingsItems.get(59).colorValue;
customTheme.lockedIconTint = customThemeSettingsItems.get(60).colorValue;
customTheme.crosspostIconTint = customThemeSettingsItems.get(61).colorValue;
customTheme.upvoteRatioIconTint = customThemeSettingsItems.get(62).colorValue;
customTheme.stickiedPostIconTint = customThemeSettingsItems.get(63).colorValue;
customTheme.noPreviewPostTypeIconTint = customThemeSettingsItems.get(64).colorValue;
customTheme.subscribed = customThemeSettingsItems.get(65).colorValue;
customTheme.unsubscribed = customThemeSettingsItems.get(66).colorValue;
customTheme.username = customThemeSettingsItems.get(67).colorValue;
customTheme.subreddit = customThemeSettingsItems.get(68).colorValue;
customTheme.authorFlairTextColor = customThemeSettingsItems.get(69).colorValue;
customTheme.submitter = customThemeSettingsItems.get(70).colorValue;
customTheme.moderator = customThemeSettingsItems.get(71).colorValue;
customTheme.currentUser = customThemeSettingsItems.get(72).colorValue;
customTheme.singleCommentThreadBackgroundColor = customThemeSettingsItems.get(73).colorValue;
customTheme.unreadMessageBackgroundColor = customThemeSettingsItems.get(74).colorValue;
customTheme.dividerColor = customThemeSettingsItems.get(75).colorValue;
customTheme.noPreviewPostTypeBackgroundColor = customThemeSettingsItems.get(76).colorValue;
customTheme.voteAndReplyUnavailableButtonColor = customThemeSettingsItems.get(77).colorValue;
customTheme.commentVerticalBarColor1 = customThemeSettingsItems.get(78).colorValue;
customTheme.commentVerticalBarColor2 = customThemeSettingsItems.get(79).colorValue;
customTheme.commentVerticalBarColor3 = customThemeSettingsItems.get(80).colorValue;
customTheme.commentVerticalBarColor4 = customThemeSettingsItems.get(81).colorValue;
customTheme.commentVerticalBarColor5 = customThemeSettingsItems.get(82).colorValue;
customTheme.commentVerticalBarColor6 = customThemeSettingsItems.get(83).colorValue;
customTheme.commentVerticalBarColor7 = customThemeSettingsItems.get(84).colorValue;
customTheme.navBarColor = customThemeSettingsItems.get(85).colorValue;
customTheme.isLightStatusBar = customThemeSettingsItems.get(86).isEnabled;
customTheme.isLightNavBar = customThemeSettingsItems.get(87).isEnabled;
customTheme.isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface = customThemeSettingsItems.get(88).isEnabled;
customTheme.commentBackgroundColor = customThemeSettingsItems.get(22).colorValue;
customTheme.fullyCollapsedCommentBackgroundColor = customThemeSettingsItems.get(23).colorValue;
customTheme.awardedCommentBackgroundColor = customThemeSettingsItems.get(24).colorValue;
customTheme.receivedMessageBackgroundColor = customThemeSettingsItems.get(25).colorValue;
customTheme.sentMessageBackgroundColor = customThemeSettingsItems.get(26).colorValue;
customTheme.bottomAppBarBackgroundColor = customThemeSettingsItems.get(27).colorValue;
customTheme.primaryIconColor = customThemeSettingsItems.get(28).colorValue;
customTheme.bottomAppBarIconColor = customThemeSettingsItems.get(29).colorValue;
customTheme.postIconAndInfoColor = customThemeSettingsItems.get(30).colorValue;
customTheme.commentIconAndInfoColor = customThemeSettingsItems.get(31).colorValue;
customTheme.fabIconColor = customThemeSettingsItems.get(32).colorValue;
customTheme.sendMessageIconColor = customThemeSettingsItems.get(33).colorValue;
customTheme.toolbarPrimaryTextAndIconColor = customThemeSettingsItems.get(34).colorValue;
customTheme.toolbarSecondaryTextColor = customThemeSettingsItems.get(35).colorValue;
customTheme.circularProgressBarBackground = customThemeSettingsItems.get(36).colorValue;
customTheme.mediaIndicatorIconColor = customThemeSettingsItems.get(37).colorValue;
customTheme.mediaIndicatorBackgroundColor = customThemeSettingsItems.get(38).colorValue;
customTheme.tabLayoutWithExpandedCollapsingToolbarTabBackground = customThemeSettingsItems.get(39).colorValue;
customTheme.tabLayoutWithExpandedCollapsingToolbarTextColor = customThemeSettingsItems.get(40).colorValue;
customTheme.tabLayoutWithExpandedCollapsingToolbarTabIndicator = customThemeSettingsItems.get(41).colorValue;
customTheme.tabLayoutWithCollapsedCollapsingToolbarTabBackground = customThemeSettingsItems.get(42).colorValue;
customTheme.tabLayoutWithCollapsedCollapsingToolbarTextColor = customThemeSettingsItems.get(43).colorValue;
customTheme.tabLayoutWithCollapsedCollapsingToolbarTabIndicator = customThemeSettingsItems.get(44).colorValue;
customTheme.upvoted = customThemeSettingsItems.get(45).colorValue;
customTheme.downvoted = customThemeSettingsItems.get(46).colorValue;
customTheme.postTypeBackgroundColor = customThemeSettingsItems.get(47).colorValue;
customTheme.postTypeTextColor = customThemeSettingsItems.get(48).colorValue;
customTheme.spoilerBackgroundColor = customThemeSettingsItems.get(49).colorValue;
customTheme.spoilerTextColor = customThemeSettingsItems.get(50).colorValue;
customTheme.nsfwBackgroundColor = customThemeSettingsItems.get(51).colorValue;
customTheme.nsfwTextColor = customThemeSettingsItems.get(52).colorValue;
customTheme.flairBackgroundColor = customThemeSettingsItems.get(53).colorValue;
customTheme.flairTextColor = customThemeSettingsItems.get(54).colorValue;
customTheme.awardsBackgroundColor = customThemeSettingsItems.get(55).colorValue;
customTheme.awardsTextColor = customThemeSettingsItems.get(56).colorValue;
customTheme.archivedTint = customThemeSettingsItems.get(57).colorValue;
customTheme.lockedIconTint = customThemeSettingsItems.get(58).colorValue;
customTheme.crosspostIconTint = customThemeSettingsItems.get(59).colorValue;
customTheme.upvoteRatioIconTint = customThemeSettingsItems.get(60).colorValue;
customTheme.stickiedPostIconTint = customThemeSettingsItems.get(61).colorValue;
customTheme.noPreviewPostTypeIconTint = customThemeSettingsItems.get(62).colorValue;
customTheme.subscribed = customThemeSettingsItems.get(63).colorValue;
customTheme.unsubscribed = customThemeSettingsItems.get(64).colorValue;
customTheme.username = customThemeSettingsItems.get(65).colorValue;
customTheme.subreddit = customThemeSettingsItems.get(66).colorValue;
customTheme.authorFlairTextColor = customThemeSettingsItems.get(67).colorValue;
customTheme.submitter = customThemeSettingsItems.get(68).colorValue;
customTheme.moderator = customThemeSettingsItems.get(69).colorValue;
customTheme.currentUser = customThemeSettingsItems.get(70).colorValue;
customTheme.singleCommentThreadBackgroundColor = customThemeSettingsItems.get(71).colorValue;
customTheme.unreadMessageBackgroundColor = customThemeSettingsItems.get(72).colorValue;
customTheme.dividerColor = customThemeSettingsItems.get(73).colorValue;
customTheme.noPreviewPostTypeBackgroundColor = customThemeSettingsItems.get(74).colorValue;
customTheme.voteAndReplyUnavailableButtonColor = customThemeSettingsItems.get(75).colorValue;
customTheme.commentVerticalBarColor1 = customThemeSettingsItems.get(76).colorValue;
customTheme.commentVerticalBarColor2 = customThemeSettingsItems.get(77).colorValue;
customTheme.commentVerticalBarColor3 = customThemeSettingsItems.get(78).colorValue;
customTheme.commentVerticalBarColor4 = customThemeSettingsItems.get(79).colorValue;
customTheme.commentVerticalBarColor5 = customThemeSettingsItems.get(80).colorValue;
customTheme.commentVerticalBarColor6 = customThemeSettingsItems.get(81).colorValue;
customTheme.commentVerticalBarColor7 = customThemeSettingsItems.get(82).colorValue;
customTheme.navBarColor = customThemeSettingsItems.get(83).colorValue;
customTheme.isLightStatusBar = customThemeSettingsItems.get(84).isEnabled;
customTheme.isLightNavBar = customThemeSettingsItems.get(85).isEnabled;
customTheme.isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface = customThemeSettingsItems.get(86).isEnabled;
return customTheme;
}

View File

@@ -144,14 +144,6 @@ public class CustomThemeSettingsItem implements Parcelable {
context.getString(R.string.theme_item_read_post_card_view_background_color),
context.getString(R.string.theme_item_read_post_card_view_background_color_detail),
customTheme.readPostCardViewBackgroundColor));
customThemeSettingsItems.add(new CustomThemeSettingsItem(
context.getString(R.string.theme_item_filled_card_view_background_color),
context.getString(R.string.theme_item_filled_card_view_background_color_detail),
customTheme.filledCardViewBackgroundColor));
customThemeSettingsItems.add(new CustomThemeSettingsItem(
context.getString(R.string.theme_item_read_post_filled_card_view_background_color),
context.getString(R.string.theme_item_read_post_filled_card_view_background_color_detail),
customTheme.readPostFilledCardViewBackgroundColor));
customThemeSettingsItems.add(new CustomThemeSettingsItem(
context.getString(R.string.theme_item_comment_background_color),
context.getString(R.string.theme_item_comment_background_color_detail),

View File

@@ -127,16 +127,6 @@ public class CustomThemeWrapper {
getDefaultColor("#F2E9E1", "#2B3B51", "#282828"));
}
public int getFilledCardViewBackgroundColor() {
return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.FILLED_CARD_VIEW_BACKGROUND_COLOR,
getDefaultColor("#E6F4FF", "#242424", "#000000"));
}
public int getReadPostFilledCardViewBackgroundColor() {
return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.READ_POST_FILLED_CARD_VIEW_BACKGROUND_COLOR,
getDefaultColor("#F5F5F5", "#101010", "#000000"));
}
public int getCommentBackgroundColor() {
return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.COMMENT_BACKGROUND_COLOR,
getDefaultColor("#F6F2EE", "#192330", "#282828"));
@@ -558,8 +548,6 @@ public class CustomThemeWrapper {
customTheme.backgroundColor = Color.parseColor("#FFFFFF");
customTheme.cardViewBackgroundColor = Color.parseColor("#FFFFFF");
customTheme.readPostCardViewBackgroundColor = Color.parseColor("#F5F5F5");
customTheme.filledCardViewBackgroundColor = Color.parseColor("#E6F4FF");
customTheme.readPostFilledCardViewBackgroundColor = Color.parseColor("#F5F5F5");
customTheme.commentBackgroundColor = Color.parseColor("#FFFFFF");
customTheme.bottomAppBarBackgroundColor = Color.parseColor("#FFFFFF");
customTheme.primaryIconColor = Color.parseColor("#000000");
@@ -653,8 +641,6 @@ public class CustomThemeWrapper {
customTheme.backgroundColor = Color.parseColor("#121212");
customTheme.cardViewBackgroundColor = Color.parseColor("#242424");
customTheme.readPostCardViewBackgroundColor = Color.parseColor("#101010");
customTheme.filledCardViewBackgroundColor = Color.parseColor("#242424");
customTheme.readPostFilledCardViewBackgroundColor = Color.parseColor("#101010");
customTheme.commentBackgroundColor = Color.parseColor("#242424");
customTheme.bottomAppBarBackgroundColor = Color.parseColor("#121212");
customTheme.primaryIconColor = Color.parseColor("#FFFFFF");
@@ -748,8 +734,6 @@ public class CustomThemeWrapper {
customTheme.backgroundColor = Color.parseColor("#000000");
customTheme.cardViewBackgroundColor = Color.parseColor("#000000");
customTheme.readPostCardViewBackgroundColor = Color.parseColor("#000000");
customTheme.filledCardViewBackgroundColor = Color.parseColor("#000000");
customTheme.readPostFilledCardViewBackgroundColor = Color.parseColor("#000000");
customTheme.commentBackgroundColor = Color.parseColor("#000000");
customTheme.bottomAppBarBackgroundColor = Color.parseColor("#000000");
customTheme.primaryIconColor = Color.parseColor("#FFFFFF");
@@ -843,8 +827,6 @@ public class CustomThemeWrapper {
customTheme.backgroundColor = Color.parseColor("#FFFFFF");
customTheme.cardViewBackgroundColor = Color.parseColor("#FFFFFF");
customTheme.readPostCardViewBackgroundColor = Color.parseColor("#F5F5F5");
customTheme.filledCardViewBackgroundColor = Color.parseColor("#E6F4FF");
customTheme.readPostFilledCardViewBackgroundColor = Color.parseColor("#F5F5F5");
customTheme.commentBackgroundColor = Color.parseColor("#FFFFFF");
customTheme.bottomAppBarBackgroundColor = Color.parseColor("#FFFFFF");
customTheme.primaryIconColor = Color.parseColor("#000000");
@@ -938,8 +920,6 @@ public class CustomThemeWrapper {
customTheme.backgroundColor = Color.parseColor("#121212");
customTheme.cardViewBackgroundColor = Color.parseColor("#242424");
customTheme.readPostCardViewBackgroundColor = Color.parseColor("#101010");
customTheme.filledCardViewBackgroundColor = Color.parseColor("#242424");
customTheme.readPostFilledCardViewBackgroundColor = Color.parseColor("#101010");
customTheme.commentBackgroundColor = Color.parseColor("#242424");
customTheme.bottomAppBarBackgroundColor = Color.parseColor("#121212");
customTheme.primaryIconColor = Color.parseColor("#FFFFFF");
@@ -1033,8 +1013,6 @@ public class CustomThemeWrapper {
customTheme.backgroundColor = Color.parseColor("#000000");
customTheme.cardViewBackgroundColor = Color.parseColor("#000000");
customTheme.readPostCardViewBackgroundColor = Color.parseColor("#000000");
customTheme.filledCardViewBackgroundColor = Color.parseColor("#000000");
customTheme.readPostFilledCardViewBackgroundColor = Color.parseColor("#000000");
customTheme.commentBackgroundColor = Color.parseColor("#000000");
customTheme.bottomAppBarBackgroundColor = Color.parseColor("#000000");
customTheme.primaryIconColor = Color.parseColor("#FFFFFF");
@@ -1128,8 +1106,6 @@ public class CustomThemeWrapper {
customTheme.backgroundColor = Color.parseColor("#FFFFFF");
customTheme.cardViewBackgroundColor = Color.parseColor("#FFFFFF");
customTheme.readPostCardViewBackgroundColor = Color.parseColor("#F5F5F5");
customTheme.filledCardViewBackgroundColor = Color.parseColor("#FFE9F3");
customTheme.readPostFilledCardViewBackgroundColor = Color.parseColor("#F5F5F5");
customTheme.commentBackgroundColor = Color.parseColor("#FFFFFF");
customTheme.bottomAppBarBackgroundColor = Color.parseColor("#FFFFFF");
customTheme.primaryIconColor = Color.parseColor("#000000");
@@ -1223,8 +1199,6 @@ public class CustomThemeWrapper {
customTheme.backgroundColor = Color.parseColor("#121212");
customTheme.cardViewBackgroundColor = Color.parseColor("#242424");
customTheme.readPostCardViewBackgroundColor = Color.parseColor("#101010");
customTheme.filledCardViewBackgroundColor = Color.parseColor("#242424");
customTheme.readPostFilledCardViewBackgroundColor = Color.parseColor("#101010");
customTheme.commentBackgroundColor = Color.parseColor("#242424");
customTheme.bottomAppBarBackgroundColor = Color.parseColor("#121212");
customTheme.primaryIconColor = Color.parseColor("#FFFFFF");
@@ -1318,8 +1292,6 @@ public class CustomThemeWrapper {
customTheme.backgroundColor = Color.parseColor("#000000");
customTheme.cardViewBackgroundColor = Color.parseColor("#000000");
customTheme.readPostCardViewBackgroundColor = Color.parseColor("#000000");
customTheme.filledCardViewBackgroundColor = Color.parseColor("#000000");
customTheme.readPostFilledCardViewBackgroundColor = Color.parseColor("#000000");
customTheme.commentBackgroundColor = Color.parseColor("#000000");
customTheme.bottomAppBarBackgroundColor = Color.parseColor("#000000");
customTheme.primaryIconColor = Color.parseColor("#FFFFFF");
@@ -1413,8 +1385,6 @@ public class CustomThemeWrapper {
customTheme.backgroundColor = Color.parseColor("#282A36");
customTheme.cardViewBackgroundColor = Color.parseColor("#393A59");
customTheme.readPostCardViewBackgroundColor = Color.parseColor("#1C1F3D");
customTheme.filledCardViewBackgroundColor = Color.parseColor("#393A59");
customTheme.readPostFilledCardViewBackgroundColor = Color.parseColor("#1C1F3D");
customTheme.commentBackgroundColor = Color.parseColor("#393A59");
customTheme.bottomAppBarBackgroundColor = Color.parseColor("#393A59");
customTheme.primaryIconColor = Color.parseColor("#FFFFFF");
@@ -1508,8 +1478,6 @@ public class CustomThemeWrapper {
customTheme.backgroundColor = Color.parseColor("#DAD0DE");
customTheme.cardViewBackgroundColor = Color.parseColor("#C0F0F4");
customTheme.readPostCardViewBackgroundColor = Color.parseColor("#D2E7EA");
customTheme.filledCardViewBackgroundColor = Color.parseColor("#C0F0F4");
customTheme.readPostFilledCardViewBackgroundColor = Color.parseColor("#D2E7EA");
customTheme.commentBackgroundColor = Color.parseColor("#C0F0F4");
customTheme.bottomAppBarBackgroundColor = Color.parseColor("#D48AE0");
customTheme.primaryIconColor = Color.parseColor("#000000");

View File

@@ -1,31 +0,0 @@
package eu.toldi.infinityforlemmy.customviews;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.LinearLayout;
import androidx.annotation.Nullable;
public class InterceptTouchEventLinearLayout extends LinearLayout {
public InterceptTouchEventLinearLayout(Context context) {
super(context);
}
public InterceptTouchEventLinearLayout(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public InterceptTouchEventLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return true;
}
public InterceptTouchEventLinearLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
}

View File

@@ -389,7 +389,7 @@ public class SliderPanel extends FrameLayout {
/**
* The drag helper callbacks for dragging the slidr attachment from the bottom of the screen
* The drag helper callbacks for dragging the slidr attachment from the bottom of hte screen
*/
private final ViewDragHelper.Callback bottomCallback = new ViewDragHelper.Callback() {
@Override

View File

@@ -154,7 +154,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
@Override
public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) {
if (!(viewHolder instanceof CommentsListingRecyclerViewAdapter.CommentBaseViewHolder)) {
if (!(viewHolder instanceof CommentsListingRecyclerViewAdapter.CommentViewHolder)) {
return makeMovementFlags(0, 0);
}
int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END;

File diff suppressed because it is too large Load Diff

View File

@@ -66,7 +66,6 @@ public class SidebarFragment extends Fragment {
public static final String EXTRA_COMMUNITY_QUALIFIED_NAME = "ECQN";
public static final String EXTRA_SHOW_STATISTICS = "ESS";
public static final String EXTRA_DISABLE_IMAGE_PREVIEW = "EDIP";
public SubredditViewModel mSubredditViewModel;
@BindView(R.id.swipe_refresh_layout_sidebar_fragment)
SwipeRefreshLayout swipeRefreshLayout;
@@ -127,11 +126,7 @@ public class SidebarFragment extends Fragment {
private boolean mShowStatistics;
private boolean mDisableImagePreview;
private String communityQualifiedName;
private boolean isKbinMagazine = false;
private LinearLayoutManagerBugFixed linearLayoutManager;
private int markdownColor;
private String sidebarDescription;
@@ -139,8 +134,6 @@ public class SidebarFragment extends Fragment {
@State
CommunityStats mCommunityStats;
private BasicUserRecyclerViewAdapter moderatorAdapter;
private Markwon markwon;
private MarkwonAdapter markwonAdapter;
public SidebarFragment() {
// Required empty public constructor
@@ -160,7 +153,6 @@ public class SidebarFragment extends Fragment {
subredditName = getArguments().getString(EXTRA_SUBREDDIT_NAME);
communityQualifiedName = getArguments().getString(EXTRA_COMMUNITY_QUALIFIED_NAME);
mShowStatistics = getArguments().getBoolean(EXTRA_SHOW_STATISTICS, true);
mDisableImagePreview = getArguments().getBoolean(EXTRA_DISABLE_IMAGE_PREVIEW, false);
if (communityQualifiedName == null) {
Toast.makeText(activity, R.string.error_getting_community_name, Toast.LENGTH_SHORT).show();
return rootView;
@@ -231,9 +223,9 @@ public class SidebarFragment extends Fragment {
urlMenuBottomSheetFragment.show(getChildFragmentManager(), null);
return true;
};
markwon = MarkdownUtils.createFullRedditMarkwon(activity,
miscPlugin, markdownColor, spoilerBackgroundColor, onLinkLongClickListener, mDisableImagePreview);
markwonAdapter = MarkdownUtils.createTablesAdapter();
Markwon markwon = MarkdownUtils.createFullRedditMarkwon(activity,
miscPlugin, markdownColor, spoilerBackgroundColor, onLinkLongClickListener);
MarkwonAdapter markwonAdapter = MarkdownUtils.createTablesAdapter();
linearLayoutManager = new LinearLayoutManagerBugFixed(activity);
recyclerView.setLayoutManager(linearLayoutManager);
@@ -256,17 +248,8 @@ public class SidebarFragment extends Fragment {
moderatorsRecyclerView.setAdapter(moderatorAdapter);
mSubredditViewModel = new ViewModelProvider(activity,
new SubredditViewModel.Factory(activity.getApplication(), mRedditDataRoomDatabase, (!isKbinMagazine) ? LemmyUtils.qualifiedCommunityName2ActorId(communityQualifiedName) :
LemmyUtils.qualifiedMagazineName2ActorId(communityQualifiedName)))
new SubredditViewModel.Factory(activity.getApplication(), mRedditDataRoomDatabase, LemmyUtils.qualifiedCommunityName2ActorId(communityQualifiedName)))
.get(SubredditViewModel.class);
addLiveDataObserver();
swipeRefreshLayout.setOnRefreshListener(this::fetchSubredditData);
return rootView;
}
private void addLiveDataObserver() {
mSubredditViewModel.getSubredditLiveData().observe(getViewLifecycleOwner(), subredditData -> {
if (subredditData != null) {
sidebarDescription = subredditData.getSidebarDescription();
@@ -289,6 +272,10 @@ public class SidebarFragment extends Fragment {
fetchSubredditData();
}
});
swipeRefreshLayout.setOnRefreshListener(this::fetchSubredditData);
return rootView;
}
@Override
@@ -305,12 +292,6 @@ public class SidebarFragment extends Fragment {
swipeRefreshLayout.setRefreshing(false);
mCommunityStats = subredditData.getCommunityStats();
moderatorAdapter.setUsers(subredditData.getModerators());
if (subredditData.getActorId().contains("/m/")) {
isKbinMagazine = true;
mSubredditViewModel.getSubredditLiveData().removeObservers(getViewLifecycleOwner());
mSubredditViewModel.setSubredditName(LemmyUtils.qualifiedMagazineName2ActorId(communityQualifiedName));
addLiveDataObserver();
}
InsertSubredditData.insertSubredditData(mExecutor, new Handler(), mRedditDataRoomDatabase,
subredditData, () -> swipeRefreshLayout.setRefreshing(false));
}

View File

@@ -1,28 +1,100 @@
package eu.toldi.infinityforlemmy.fragments;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import eu.toldi.infinityforlemmy.R;
import butterknife.BindView;
import butterknife.ButterKnife;
import eu.toldi.infinityforlemmy.activities.CustomThemePreviewActivity;
import eu.toldi.infinityforlemmy.customtheme.CustomTheme;
import eu.toldi.infinityforlemmy.databinding.FragmentThemePreviewCommentsBinding;
import eu.toldi.infinityforlemmy.utils.Utils;
import eu.toldi.infinityforlemmy.R;
/**
* A simple {@link Fragment} subclass.
*/
public class ThemePreviewCommentsFragment extends Fragment {
private FragmentThemePreviewCommentsBinding binding;
@BindView(R.id.linear_layout_theme_preview_comments_fragment)
LinearLayout linearLayout;
@BindView(R.id.vertical_block_theme_preview_comments_fragment)
View verticalBlock;
@BindView(R.id.author_type_image_view_theme_preview_comments_fragment)
ImageView authorTypeImageView;
@BindView(R.id.author_text_view_theme_preview_comments_fragment)
TextView authorTextView;
@BindView(R.id.author_flair_text_view_theme_preview_comments_fragment)
TextView flairTextView;
@BindView(R.id.comment_time_text_view_theme_preview_comments_fragment)
TextView commentTimeTextView;
@BindView(R.id.comment_markdown_view_theme_preview_comments_fragment)
TextView contentTextView;
@BindView(R.id.up_vote_button_theme_preview_comments_fragment)
ImageView upvoteButton;
@BindView(R.id.score_text_view_theme_preview_comments_fragment)
TextView scoreTextView;
@BindView(R.id.down_vote_button_theme_preview_comments_fragment)
ImageView downvoteButton;
@BindView(R.id.more_button_theme_preview_comments_fragment)
ImageView moreButton;
@BindView(R.id.expand_button_theme_preview_comments_fragment)
ImageView expandButton;
@BindView(R.id.save_button_theme_preview_comments_fragment)
ImageView saveButton;
@BindView(R.id.reply_button_theme_preview_comments_fragment)
ImageView replyButton;
@BindView(R.id.divider_theme_preview_comments_fragment)
View divider;
@BindView(R.id.linear_layout_award_background_theme_preview_comments_fragment)
LinearLayout linearLayoutAwardBackground;
@BindView(R.id.vertical_block_award_background_theme_preview_comments_fragment)
View verticalBlockAwardBackground;
@BindView(R.id.author_type_image_view_award_background_theme_preview_comments_fragment)
ImageView authorTypeImageViewAwardBackground;
@BindView(R.id.author_text_view_award_background_theme_preview_comments_fragment)
TextView authorTextViewAwardBackground;
@BindView(R.id.author_flair_text_view_award_background_theme_preview_comments_fragment)
TextView flairTextViewAwardBackground;
@BindView(R.id.comment_time_text_view_award_background_theme_preview_comments_fragment)
TextView commentTimeTextViewAwardBackground;
@BindView(R.id.comment_markdown_view_award_background_theme_preview_comments_fragment)
TextView contentTextViewAwardBackground;
@BindView(R.id.up_vote_button_award_background_theme_preview_comments_fragment)
ImageView upvoteButtonAwardBackground;
@BindView(R.id.score_text_view_award_background_theme_preview_comments_fragment)
TextView scoreTextViewAwardBackground;
@BindView(R.id.down_vote_button_award_background_theme_preview_comments_fragment)
ImageView downvoteButtonAwardBackground;
@BindView(R.id.more_button_award_background_theme_preview_comments_fragment)
ImageView moreButtonAwardBackground;
@BindView(R.id.expand_button_award_background_theme_preview_comments_fragment)
ImageView expandButtonAwardBackground;
@BindView(R.id.save_button_award_background_theme_preview_comments_fragment)
ImageView saveButtonAwardBackground;
@BindView(R.id.reply_button_award_background_theme_preview_comments_fragment)
ImageView replyButtonAwardBackground;
@BindView(R.id.divider_award_background_theme_preview_comments_fragment)
View dividerAwardBackground;
@BindView(R.id.linear_layout_fully_collapsed_theme_preview_comments_fragment)
LinearLayout linearLayoutFullyCollapsed;
@BindView(R.id.vertical_block_fully_collapsed_theme_preview_comments_fragment)
View verticalBlockFullyCollapsed;
@BindView(R.id.author_text_view_fully_collapsed_theme_preview_comments_fragment)
TextView authorTextViewFullyCollapsed;
@BindView(R.id.score_text_view_fully_collapsed_theme_preview_comments_fragment)
TextView scoreTextViewFullyCollapsed;
@BindView(R.id.time_text_view_fully_collapsed_theme_preview_comments_fragment)
TextView timeTextViewFullyCollapsed;
private CustomThemePreviewActivity activity;
public ThemePreviewCommentsFragment() {
@@ -31,69 +103,65 @@ public class ThemePreviewCommentsFragment extends Fragment {
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
binding = FragmentThemePreviewCommentsBinding.inflate(inflater, container, false);
View rootView = inflater.inflate(R.layout.fragment_theme_preview_comments, container, false);
ButterKnife.bind(this, rootView);
CustomTheme customTheme = activity.getCustomTheme();
linearLayout.setBackgroundColor(customTheme.commentBackgroundColor);
authorTypeImageView.setColorFilter(customTheme.moderator, android.graphics.PorterDuff.Mode.SRC_IN);
authorTextView.setTextColor(customTheme.moderator);
commentTimeTextView.setTextColor(customTheme.secondaryTextColor);
contentTextView.setTextColor(customTheme.commentColor);
flairTextView.setTextColor(customTheme.authorFlairTextColor);
divider.setBackgroundColor(customTheme.dividerColor);
upvoteButton.setColorFilter(customTheme.commentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
scoreTextView.setTextColor(customTheme.commentIconAndInfoColor);
downvoteButton.setColorFilter(customTheme.commentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
moreButton.setColorFilter(customTheme.commentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
expandButton.setColorFilter(customTheme.commentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
saveButton.setColorFilter(customTheme.commentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
replyButton.setColorFilter(customTheme.commentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
Drawable expandDrawable = Utils.getTintedDrawable(activity, R.drawable.ic_expand_more_grey_24dp, customTheme.commentIconAndInfoColor);
linearLayoutAwardBackground.setBackgroundColor(customTheme.awardedCommentBackgroundColor);
authorTypeImageViewAwardBackground.setColorFilter(customTheme.moderator, android.graphics.PorterDuff.Mode.SRC_IN);
authorTextViewAwardBackground.setTextColor(customTheme.moderator);
commentTimeTextViewAwardBackground.setTextColor(customTheme.secondaryTextColor);
contentTextViewAwardBackground.setTextColor(customTheme.commentColor);
flairTextViewAwardBackground.setTextColor(customTheme.authorFlairTextColor);
dividerAwardBackground.setBackgroundColor(customTheme.dividerColor);
upvoteButtonAwardBackground.setColorFilter(customTheme.commentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
scoreTextViewAwardBackground.setTextColor(customTheme.commentIconAndInfoColor);
downvoteButtonAwardBackground.setColorFilter(customTheme.commentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
moreButtonAwardBackground.setColorFilter(customTheme.commentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
expandButtonAwardBackground.setColorFilter(customTheme.commentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
saveButtonAwardBackground.setColorFilter(customTheme.commentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
replyButtonAwardBackground.setColorFilter(customTheme.commentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
binding.linearLayoutThemePreviewCommentsFragment.setBackgroundColor(customTheme.commentBackgroundColor);
binding.authorTypeImageViewThemePreviewCommentsFragment.setColorFilter(customTheme.moderator, android.graphics.PorterDuff.Mode.SRC_IN);
binding.authorTextViewThemePreviewCommentsFragment.setTextColor(customTheme.moderator);
binding.commentTimeTextViewThemePreviewCommentsFragment.setTextColor(customTheme.secondaryTextColor);
binding.commentMarkdownViewThemePreviewCommentsFragment.setTextColor(customTheme.commentColor);
binding.authorFlairTextViewThemePreviewCommentsFragment.setTextColor(customTheme.authorFlairTextColor);
binding.dividerThemePreviewCommentsFragment.setBackgroundColor(customTheme.dividerColor);
binding.upvoteButtonThemePreviewCommentsFragment.setIconTint(ColorStateList.valueOf(customTheme.commentIconAndInfoColor));
binding.upvoteButtonThemePreviewCommentsFragment.setTextColor(customTheme.commentIconAndInfoColor);
binding.downvoteButtonThemePreviewCommentsFragment.setIconTint(ColorStateList.valueOf(customTheme.commentIconAndInfoColor));
binding.moreButtonThemePreviewCommentsFragment.setIconTint(ColorStateList.valueOf(customTheme.commentIconAndInfoColor));
binding.expandButtonThemePreviewCommentsFragment.setCompoundDrawablesWithIntrinsicBounds(expandDrawable, null, null, null);
binding.saveButtonThemePreviewCommentsFragment.setIconTint(ColorStateList.valueOf(customTheme.commentIconAndInfoColor));
binding.replyButtonThemePreviewCommentsFragment.setIconTint(ColorStateList.valueOf(customTheme.commentIconAndInfoColor));
binding.linearLayoutAwardBackgroundThemePreviewCommentsFragment.setBackgroundColor(customTheme.awardedCommentBackgroundColor);
binding.authorTypeImageViewAwardBackgroundThemePreviewCommentsFragment.setColorFilter(customTheme.moderator, android.graphics.PorterDuff.Mode.SRC_IN);
binding.authorTextViewAwardBackgroundThemePreviewCommentsFragment.setTextColor(customTheme.moderator);
binding.commentTimeTextViewAwardBackgroundThemePreviewCommentsFragment.setTextColor(customTheme.secondaryTextColor);
binding.commentMarkdownViewAwardBackgroundThemePreviewCommentsFragment.setTextColor(customTheme.commentColor);
binding.authorFlairTextViewAwardBackgroundThemePreviewCommentsFragment.setTextColor(customTheme.authorFlairTextColor);
binding.dividerAwardBackgroundThemePreviewCommentsFragment.setBackgroundColor(customTheme.dividerColor);
binding.upvoteButtonAwardBackgroundThemePreviewCommentsFragment.setIconTint(ColorStateList.valueOf(customTheme.commentIconAndInfoColor));
binding.upvoteButtonAwardBackgroundThemePreviewCommentsFragment.setTextColor(customTheme.commentIconAndInfoColor);
binding.downvoteButtonAwardBackgroundThemePreviewCommentsFragment.setIconTint(ColorStateList.valueOf(customTheme.commentIconAndInfoColor));
binding.moreButtonAwardBackgroundThemePreviewCommentsFragment.setIconTint(ColorStateList.valueOf(customTheme.commentIconAndInfoColor));
binding.expandButtonAwardBackgroundThemePreviewCommentsFragment.setCompoundDrawablesWithIntrinsicBounds(expandDrawable, null, null, null);
binding.saveButtonAwardBackgroundThemePreviewCommentsFragment.setIconTint(ColorStateList.valueOf(customTheme.commentIconAndInfoColor));
binding.replyButtonAwardBackgroundThemePreviewCommentsFragment.setIconTint(ColorStateList.valueOf(customTheme.commentIconAndInfoColor));
binding.linearLayoutFullyCollapsedThemePreviewCommentsFragment.setBackgroundColor(customTheme.fullyCollapsedCommentBackgroundColor);
binding.authorTextViewFullyCollapsedThemePreviewCommentsFragment.setTextColor(customTheme.username);
binding.scoreTextViewFullyCollapsedThemePreviewCommentsFragment.setTextColor(customTheme.secondaryTextColor);
binding.timeTextViewFullyCollapsedThemePreviewCommentsFragment.setTextColor(customTheme.secondaryTextColor);
linearLayoutFullyCollapsed.setBackgroundColor(customTheme.fullyCollapsedCommentBackgroundColor);
authorTextViewFullyCollapsed.setTextColor(customTheme.username);
scoreTextViewFullyCollapsed.setTextColor(customTheme.secondaryTextColor);
timeTextViewFullyCollapsed.setTextColor(customTheme.secondaryTextColor);
if (activity.typeface != null) {
binding.authorTextViewThemePreviewCommentsFragment.setTypeface(activity.typeface);
binding.commentTimeTextViewThemePreviewCommentsFragment.setTypeface(activity.typeface);
binding.authorFlairTextViewThemePreviewCommentsFragment.setTypeface(activity.typeface);
binding.upvoteButtonThemePreviewCommentsFragment.setTypeface(activity.typeface);
binding.authorTextViewAwardBackgroundThemePreviewCommentsFragment.setTypeface(activity.typeface);
binding.commentTimeTextViewAwardBackgroundThemePreviewCommentsFragment.setTypeface(activity.typeface);
binding.authorFlairTextViewAwardBackgroundThemePreviewCommentsFragment.setTypeface(activity.typeface);
binding.upvoteButtonAwardBackgroundThemePreviewCommentsFragment.setTypeface(activity.typeface);
binding.authorTextViewFullyCollapsedThemePreviewCommentsFragment.setTypeface(activity.typeface);
binding.scoreTextViewFullyCollapsedThemePreviewCommentsFragment.setTypeface(activity.typeface);
binding.timeTextViewFullyCollapsedThemePreviewCommentsFragment.setTypeface(activity.typeface);
authorTextView.setTypeface(activity.typeface);
commentTimeTextView.setTypeface(activity.typeface);
flairTextView.setTypeface(activity.typeface);
scoreTextView.setTypeface(activity.typeface);
authorTextViewAwardBackground.setTypeface(activity.typeface);
commentTimeTextViewAwardBackground.setTypeface(activity.typeface);
flairTextViewAwardBackground.setTypeface(activity.typeface);
scoreTextViewAwardBackground.setTypeface(activity.typeface);
authorTextViewFullyCollapsed.setTypeface(activity.typeface);
scoreTextViewFullyCollapsed.setTypeface(activity.typeface);
timeTextViewFullyCollapsed.setTypeface(activity.typeface);
}
if (activity.contentTypeface != null) {
binding.commentMarkdownViewThemePreviewCommentsFragment.setTypeface(activity.contentTypeface);
binding.commentMarkdownViewAwardBackgroundThemePreviewCommentsFragment.setTypeface(activity.contentTypeface);
contentTextView.setTypeface(activity.contentTypeface);
contentTextViewAwardBackground.setTypeface(activity.contentTypeface);
}
return binding.getRoot();
return rootView;
}
@Override

View File

@@ -8,26 +8,82 @@ import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.cardview.widget.CardView;
import androidx.fragment.app.Fragment;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.libRG.CustomTextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.activities.CustomThemePreviewActivity;
import eu.toldi.infinityforlemmy.customtheme.CustomTheme;
import eu.toldi.infinityforlemmy.databinding.FragmentThemePreviewPostsBinding;
import eu.toldi.infinityforlemmy.customviews.AspectRatioGifImageView;
/**
* A simple {@link Fragment} subclass.
*/
public class ThemePreviewPostsFragment extends Fragment {
private FragmentThemePreviewPostsBinding binding;
@BindView(R.id.card_view_theme_preview_posts_fragment)
CardView cardView;
@BindView(R.id.icon_gif_image_view_theme_preview_posts_fragment)
AspectRatioGifImageView iconImageView;
@BindView(R.id.subreddit_name_text_view_theme_preview_posts_fragment)
TextView subredditNameTextView;
@BindView(R.id.user_text_view_theme_preview_posts_fragment)
TextView usernameTextView;
@BindView(R.id.stickied_post_image_view_theme_preview_posts_fragment)
ImageView stickiedPostImageView;
@BindView(R.id.post_time_text_view_best_theme_preview_posts_fragment)
TextView postTimeTextView;
@BindView(R.id.title_text_view_best_theme_preview_posts_fragment)
TextView titleTextView;
@BindView(R.id.content_text_view_theme_preview_posts_fragment)
TextView contentTextView;
@BindView(R.id.type_text_view_theme_preview_posts_fragment)
CustomTextView typeTextView;
@BindView(R.id.spoiler_custom_text_view_theme_preview_posts_fragment)
CustomTextView spoilerTextView;
@BindView(R.id.nsfw_text_view_theme_preview_posts_fragment)
CustomTextView nsfwTextView;
@BindView(R.id.flair_custom_text_view_theme_preview_posts_fragment)
CustomTextView flairTextView;
@BindView(R.id.awards_text_view_theme_preview_posts_fragment)
CustomTextView awardsTextView;
@BindView(R.id.archived_image_view_theme_preview_posts_fragment)
ImageView archivedImageView;
@BindView(R.id.locked_image_view_theme_preview_posts_fragment)
ImageView lockedImageView;
@BindView(R.id.crosspost_image_view_theme_preview_posts_fragment)
ImageView crosspostImageView;
@BindView(R.id.link_text_view_theme_preview_posts_fragment)
TextView linkTextView;
@BindView(R.id.progress_bar_theme_preview_posts_fragment)
ProgressBar progressBar;
@BindView(R.id.image_view_no_preview_link_theme_preview_posts_fragment)
ImageView noPreviewLinkImageView;
@BindView(R.id.plus_button_theme_preview_posts_fragment)
ImageView upvoteButton;
@BindView(R.id.score_text_view_theme_preview_posts_fragment)
TextView scoreTextView;
@BindView(R.id.minus_button_theme_preview_posts_fragment)
ImageView downvoteButton;
@BindView(R.id.comments_count_theme_preview_posts_fragment)
TextView commentsCountTextView;
@BindView(R.id.save_button_theme_preview_posts_fragment)
ImageView saveButton;
@BindView(R.id.share_button_theme_preview_posts_fragment)
ImageView shareButton;
private CustomThemePreviewActivity activity;
public ThemePreviewPostsFragment() {
@@ -38,74 +94,74 @@ public class ThemePreviewPostsFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
binding = FragmentThemePreviewPostsBinding.inflate(inflater, container, false);
View rootView = inflater.inflate(R.layout.fragment_theme_preview_posts, container, false);
ButterKnife.bind(this, rootView);
CustomTheme customTheme = activity.getCustomTheme();
binding.cardViewThemePreviewPostsFragment.setBackgroundTintList(ColorStateList.valueOf(customTheme.cardViewBackgroundColor));
cardView.setBackgroundTintList(ColorStateList.valueOf(customTheme.cardViewBackgroundColor));
Glide.with(this).load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
.into(binding.iconGifImageViewThemePreviewPostsFragment);
binding.subredditNameTextViewThemePreviewPostsFragment.setTextColor(customTheme.subreddit);
binding.userTextViewThemePreviewPostsFragment.setTextColor(customTheme.username);
binding.postTimeTextViewBestThemePreviewPostsFragment.setTextColor(customTheme.secondaryTextColor);
binding.titleTextViewBestThemePreviewPostsFragment.setTextColor(customTheme.postTitleColor);
binding.contentTextViewThemePreviewPostsFragment.setTextColor(customTheme.postContentColor);
binding.stickiedPostImageViewThemePreviewPostsFragment.setColorFilter(customTheme.stickiedPostIconTint, PorterDuff.Mode.SRC_IN);
binding.typeTextViewThemePreviewPostsFragment.setBackgroundColor(customTheme.postTypeBackgroundColor);
binding.typeTextViewThemePreviewPostsFragment.setBorderColor(customTheme.postTypeBackgroundColor);
binding.typeTextViewThemePreviewPostsFragment.setTextColor(customTheme.postTypeTextColor);
binding.spoilerCustomTextViewThemePreviewPostsFragment.setBackgroundColor(customTheme.spoilerBackgroundColor);
binding.spoilerCustomTextViewThemePreviewPostsFragment.setBorderColor(customTheme.spoilerBackgroundColor);
binding.spoilerCustomTextViewThemePreviewPostsFragment.setTextColor(customTheme.spoilerTextColor);
binding.nsfwTextViewThemePreviewPostsFragment.setBackgroundColor(customTheme.nsfwBackgroundColor);
binding.nsfwTextViewThemePreviewPostsFragment.setBorderColor(customTheme.nsfwBackgroundColor);
binding.nsfwTextViewThemePreviewPostsFragment.setTextColor(customTheme.nsfwTextColor);
binding.flairCustomTextViewThemePreviewPostsFragment.setBackgroundColor(customTheme.flairBackgroundColor);
binding.flairCustomTextViewThemePreviewPostsFragment.setBorderColor(customTheme.flairBackgroundColor);
binding.flairCustomTextViewThemePreviewPostsFragment.setTextColor(customTheme.flairTextColor);
binding.awardsTextViewThemePreviewPostsFragment.setBackgroundColor(customTheme.awardsBackgroundColor);
binding.awardsTextViewThemePreviewPostsFragment.setBorderColor(customTheme.awardsBackgroundColor);
binding.awardsTextViewThemePreviewPostsFragment.setTextColor(customTheme.awardsTextColor);
binding.archivedImageViewThemePreviewPostsFragment.setColorFilter(customTheme.archivedTint, PorterDuff.Mode.SRC_IN);
binding.lockedImageViewThemePreviewPostsFragment.setColorFilter(customTheme.lockedIconTint, PorterDuff.Mode.SRC_IN);
binding.crosspostImageViewThemePreviewPostsFragment.setColorFilter(customTheme.crosspostIconTint, PorterDuff.Mode.SRC_IN);
binding.linkTextViewThemePreviewPostsFragment.setTextColor(customTheme.secondaryTextColor);
binding.progressBarThemePreviewPostsFragment.setIndeterminateTintList(ColorStateList.valueOf(customTheme.colorAccent));
binding.imageViewNoPreviewLinkThemePreviewPostsFragment.setBackgroundColor(customTheme.noPreviewPostTypeBackgroundColor);
binding.upvoteButtonThemePreviewPostsFragment.setIconTint(ColorStateList.valueOf(customTheme.postIconAndInfoColor));
binding.upvoteButtonThemePreviewPostsFragment.setTextColor(customTheme.postIconAndInfoColor);
binding.downvoteButtonThemePreviewPostsFragment.setIconTint(ColorStateList.valueOf(customTheme.postIconAndInfoColor));
binding.commentsCountButtonThemePreviewPostsFragment.setTextColor(customTheme.postIconAndInfoColor);
.into(iconImageView);
subredditNameTextView.setTextColor(customTheme.subreddit);
usernameTextView.setTextColor(customTheme.username);
postTimeTextView.setTextColor(customTheme.secondaryTextColor);
titleTextView.setTextColor(customTheme.postTitleColor);
contentTextView.setTextColor(customTheme.postContentColor);
stickiedPostImageView.setColorFilter(customTheme.stickiedPostIconTint, PorterDuff.Mode.SRC_IN);
typeTextView.setBackgroundColor(customTheme.postTypeBackgroundColor);
typeTextView.setBorderColor(customTheme.postTypeBackgroundColor);
typeTextView.setTextColor(customTheme.postTypeTextColor);
spoilerTextView.setBackgroundColor(customTheme.spoilerBackgroundColor);
spoilerTextView.setBorderColor(customTheme.spoilerBackgroundColor);
spoilerTextView.setTextColor(customTheme.spoilerTextColor);
nsfwTextView.setBackgroundColor(customTheme.nsfwBackgroundColor);
nsfwTextView.setBorderColor(customTheme.nsfwBackgroundColor);
nsfwTextView.setTextColor(customTheme.nsfwTextColor);
flairTextView.setBackgroundColor(customTheme.flairBackgroundColor);
flairTextView.setBorderColor(customTheme.flairBackgroundColor);
flairTextView.setTextColor(customTheme.flairTextColor);
awardsTextView.setBackgroundColor(customTheme.awardsBackgroundColor);
awardsTextView.setBorderColor(customTheme.awardsBackgroundColor);
awardsTextView.setTextColor(customTheme.awardsTextColor);
archivedImageView.setColorFilter(customTheme.archivedTint, PorterDuff.Mode.SRC_IN);
lockedImageView.setColorFilter(customTheme.lockedIconTint, PorterDuff.Mode.SRC_IN);
crosspostImageView.setColorFilter(customTheme.crosspostIconTint, PorterDuff.Mode.SRC_IN);
linkTextView.setTextColor(customTheme.secondaryTextColor);
progressBar.setIndeterminateTintList(ColorStateList.valueOf(customTheme.colorAccent));
noPreviewLinkImageView.setBackgroundColor(customTheme.noPreviewPostTypeBackgroundColor);
upvoteButton.setColorFilter(customTheme.postIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
scoreTextView.setTextColor(customTheme.postIconAndInfoColor);
downvoteButton.setColorFilter(customTheme.postIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
commentsCountTextView.setTextColor(customTheme.postIconAndInfoColor);
Drawable commentIcon = AppCompatResources.getDrawable(activity, R.drawable.ic_comment_grey_24dp);
if (commentIcon != null) {
commentIcon.setTint(customTheme.postIconAndInfoColor);
}
binding.commentsCountButtonThemePreviewPostsFragment.setCompoundDrawablesWithIntrinsicBounds(commentIcon, null, null, null);
binding.saveButtonThemePreviewPostsFragment.setIconTint(ColorStateList.valueOf(customTheme.postIconAndInfoColor));
binding.shareButtonThemePreviewPostsFragment.setIconTint(ColorStateList.valueOf(customTheme.postIconAndInfoColor));
commentsCountTextView.setCompoundDrawablesWithIntrinsicBounds(commentIcon, null, null, null);
saveButton.setColorFilter(customTheme.postIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
shareButton.setColorFilter(customTheme.postIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
if (activity.typeface != null) {
binding.subredditNameTextViewThemePreviewPostsFragment.setTypeface(activity.typeface);
binding.userTextViewThemePreviewPostsFragment.setTypeface(activity.typeface);
binding.postTimeTextViewBestThemePreviewPostsFragment.setTypeface(activity.typeface);
binding.typeTextViewThemePreviewPostsFragment.setTypeface(activity.typeface);
binding.spoilerCustomTextViewThemePreviewPostsFragment.setTypeface(activity.typeface);
binding.nsfwTextViewThemePreviewPostsFragment.setTypeface(activity.typeface);
binding.flairCustomTextViewThemePreviewPostsFragment.setTypeface(activity.typeface);
binding.awardsTextViewThemePreviewPostsFragment.setTypeface(activity.typeface);
binding.linkTextViewThemePreviewPostsFragment.setTypeface(activity.typeface);
binding.upvoteButtonThemePreviewPostsFragment.setTypeface(activity.typeface);
binding.commentsCountButtonThemePreviewPostsFragment.setTypeface(activity.typeface);
subredditNameTextView.setTypeface(activity.typeface);
usernameTextView.setTypeface(activity.typeface);
postTimeTextView.setTypeface(activity.typeface);
typeTextView.setTypeface(activity.typeface);
spoilerTextView.setTypeface(activity.typeface);
nsfwTextView.setTypeface(activity.typeface);
flairTextView.setTypeface(activity.typeface);
awardsTextView.setTypeface(activity.typeface);
linkTextView.setTypeface(activity.typeface);
scoreTextView.setTypeface(activity.typeface);
commentsCountTextView.setTypeface(activity.typeface);
}
if (activity.titleTypeface != null) {
binding.titleTextViewBestThemePreviewPostsFragment.setTypeface(activity.titleTypeface);
titleTextView.setTypeface(activity.titleTypeface);
}
if (activity.contentTypeface != null) {
binding.contentTextViewThemePreviewPostsFragment.setTypeface(activity.contentTypeface);
contentTextView.setTypeface(activity.contentTypeface);
}
return binding.getRoot();
return rootView;
}
@Override

View File

@@ -15,6 +15,8 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
@@ -37,7 +39,6 @@ import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
import com.google.android.exoplayer2.upstream.cache.CacheDataSource;
import com.google.android.exoplayer2.upstream.cache.SimpleCache;
import com.google.android.material.bottomappbar.BottomAppBar;
import com.google.android.material.button.MaterialButton;
import com.google.common.collect.ImmutableList;
import javax.inject.Inject;
@@ -67,17 +68,13 @@ public class ViewImgurVideoFragment extends Fragment {
@BindView(R.id.player_view_view_imgur_video_fragment)
PlayerView videoPlayerView;
@BindView(R.id.mute_exo_playback_control_view)
MaterialButton muteButton;
ImageButton muteButton;
@BindView(R.id.bottom_navigation_exo_playback_control_view)
BottomAppBar bottomAppBar;
@BindView(R.id.title_text_view_exo_playback_control_view)
TextView titleTextView;
@BindView(R.id.back_button_exo_playback_control_view)
MaterialButton backButton;
@BindView(R.id.download_image_view_exo_playback_control_view)
MaterialButton downloadButton;
@BindView(R.id.playback_speed_image_view_exo_playback_control_view)
MaterialButton playbackSpeedButton;
ImageView downloadImageView;
private ViewImgurMediaActivity activity;
private ImgurMedia imgurMedia;
private ExoPlayer player;
@@ -108,10 +105,6 @@ public class ViewImgurVideoFragment extends Fragment {
setHasOptionsMenu(true);
if (activity.typeface != null) {
titleTextView.setTypeface(activity.typeface);
}
activity.setVolumeControlStream(AudioManager.STREAM_MUSIC);
imgurMedia = getArguments().getParcelable(EXTRA_IMGUR_VIDEO);
@@ -165,40 +158,22 @@ public class ViewImgurVideoFragment extends Fragment {
setPlaybackSpeed(Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.DEFAULT_PLAYBACK_SPEED, "100")));
preparePlayer(savedInstanceState);
titleTextView.setText(getString(R.string.view_imgur_media_activity_video_label,
getArguments().getInt(EXTRA_INDEX) + 1, getArguments().getInt(EXTRA_MEDIA_COUNT)));
if (activity.isUseBottomAppBar()) {
bottomAppBar.setVisibility(View.VISIBLE);
backButton.setOnClickListener(view -> {
activity.finish();
});
downloadButton.setOnClickListener(view -> {
titleTextView.setText(getString(R.string.view_imgur_media_activity_video_label,
getArguments().getInt(EXTRA_INDEX) + 1, getArguments().getInt(EXTRA_MEDIA_COUNT)));
downloadImageView.setOnClickListener(view -> {
if (isDownloading) {
return;
}
isDownloading = true;
requestPermissionAndDownload();
});
playbackSpeedButton.setOnClickListener(view -> {
changePlaybackSpeed();
});
}
return rootView;
}
private void changePlaybackSpeed() {
PlaybackSpeedBottomSheetFragment playbackSpeedBottomSheetFragment = new PlaybackSpeedBottomSheetFragment();
Bundle bundle = new Bundle();
bundle.putInt(PlaybackSpeedBottomSheetFragment.EXTRA_PLAYBACK_SPEED, playbackSpeed);
playbackSpeedBottomSheetFragment.setArguments(bundle);
playbackSpeedBottomSheetFragment.show(getChildFragmentManager(), playbackSpeedBottomSheetFragment.getTag());
}
@Override
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
inflater.inflate(R.menu.view_imgur_video_fragment, menu);
@@ -216,7 +191,11 @@ public class ViewImgurVideoFragment extends Fragment {
requestPermissionAndDownload();
return true;
} else if (item.getItemId() == R.id.action_playback_speed_view_imgur_video_fragment) {
changePlaybackSpeed();
PlaybackSpeedBottomSheetFragment playbackSpeedBottomSheetFragment = new PlaybackSpeedBottomSheetFragment();
Bundle bundle = new Bundle();
bundle.putInt(PlaybackSpeedBottomSheetFragment.EXTRA_PLAYBACK_SPEED, playbackSpeed);
playbackSpeedBottomSheetFragment.setArguments(bundle);
playbackSpeedBottomSheetFragment.show(getChildFragmentManager(), playbackSpeedBottomSheetFragment.getTag());
return true;
}
return false;
@@ -287,17 +266,17 @@ public class ViewImgurVideoFragment extends Fragment {
isMute = savedInstanceState.getBoolean(IS_MUTE_STATE);
if (isMute) {
player.setVolume(0f);
muteButton.setIconResource(R.drawable.ic_mute_24dp);
muteButton.setImageResource(R.drawable.ic_mute_24dp);
} else {
player.setVolume(1f);
muteButton.setIconResource(R.drawable.ic_unmute_24dp);
muteButton.setImageResource(R.drawable.ic_unmute_24dp);
}
} else if (muteVideo) {
isMute = true;
player.setVolume(0f);
muteButton.setIconResource(R.drawable.ic_mute_24dp);
muteButton.setImageResource(R.drawable.ic_mute_24dp);
} else {
muteButton.setIconResource(R.drawable.ic_unmute_24dp);
muteButton.setImageResource(R.drawable.ic_unmute_24dp);
}
player.addListener(new Player.Listener() {
@@ -313,11 +292,11 @@ public class ViewImgurVideoFragment extends Fragment {
if (isMute) {
isMute = false;
player.setVolume(1f);
muteButton.setIconResource(R.drawable.ic_unmute_24dp);
muteButton.setImageResource(R.drawable.ic_unmute_24dp);
} else {
isMute = true;
player.setVolume(0f);
muteButton.setIconResource(R.drawable.ic_mute_24dp);
muteButton.setImageResource(R.drawable.ic_mute_24dp);
}
});
break;

View File

@@ -17,7 +17,6 @@ import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.HapticFeedbackConstants;
import android.view.LayoutInflater;
import android.view.Menu;
@@ -95,8 +94,6 @@ import eu.toldi.infinityforlemmy.comment.Comment;
import eu.toldi.infinityforlemmy.comment.FetchComment;
import eu.toldi.infinityforlemmy.comment.FetchRemovedComment;
import eu.toldi.infinityforlemmy.comment.FetchRemovedCommentReveddit;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilter;
import eu.toldi.infinityforlemmy.commentfilter.FetchCommentFilter;
import eu.toldi.infinityforlemmy.community.BlockCommunity;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.customviews.CustomToroContainer;
@@ -235,10 +232,6 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
boolean mRespectSubredditRecommendedSortType;
@State
long viewPostDetailFragmentId;
@State
boolean commentFilterFetched;
@State
CommentFilter mCommentFilter = new CommentFilter();
@State
boolean isCommunityBlocked;
@@ -299,7 +292,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
applyTheme();
mRecyclerView.addOnWindowFocusChangedListener(this::onWindowFocusChanged);
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
@@ -466,7 +459,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
@Override
public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) {
if (!(viewHolder instanceof CommentsRecyclerViewAdapter.CommentBaseViewHolder)) {
if (!(viewHolder instanceof CommentsRecyclerViewAdapter.CommentViewHolder)) {
return makeMovementFlags(0, 0);
}
int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END;
@@ -561,7 +554,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
touchHelper.attachToRecyclerView((mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView));
}
mSwipeRefreshLayout.setOnRefreshListener(() -> refresh());
mSwipeRefreshLayout.setOnRefreshListener(() -> refresh(true, true));
mSmoothScroller = new LinearSmoothScroller(activity) {
@Override
@@ -651,7 +644,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
public SortType.Type getSortType() {
return sortType;
}
});
} );
if (mCommentsRecyclerView != null) {
mRecyclerView.setAdapter(mPostAdapter);
mCommentsRecyclerView.setAdapter(mCommentsAdapter);
@@ -660,15 +653,21 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
mRecyclerView.setAdapter(mConcatAdapter);
}
if (commentFilterFetched) {
fetchCommentsAfterCommentFilterAvailable();
if (comments == null) {
fetchCommentsRespectRecommendedSort(false);
} else {
FetchCommentFilter.fetchCommentFilter(mExecutor, new Handler(Looper.getMainLooper()), mRedditDataRoomDatabase, mPost.getSubredditName(),
commentFilter -> {
mCommentFilter = commentFilter;
commentFilterFetched = true;
fetchCommentsAfterCommentFilterAvailable();
});
if (isRefreshing) {
isRefreshing = false;
refresh(true, true);
} else if (isFetchingComments) {
fetchCommentsRespectRecommendedSort(false);
} else {
mCommentsAdapter.addComments(comments, hasMoreChildren);
if (isLoadingMoreChildren) {
isLoadingMoreChildren = false;
fetchMoreComments();
}
}
}
}
@@ -679,25 +678,6 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
});
}
public void fetchCommentsAfterCommentFilterAvailable() {
if (comments == null) {
fetchCommentsRespectRecommendedSort(false);
} else {
if (isRefreshing) {
isRefreshing = false;
refresh(true, true);
} else if (isFetchingComments) {
fetchCommentsRespectRecommendedSort(false);
} else {
mCommentsAdapter.addComments(comments, hasMoreChildren);
if (isLoadingMoreChildren) {
isLoadingMoreChildren = false;
fetchMoreComments();
}
}
}
}
private void setupMenu() {
if (mMenu != null) {
MenuItem saveItem = mMenu.findItem(R.id.action_save_view_post_detail_fragment);
@@ -1368,7 +1348,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
mPostDetailsSharedPreferences, mExoCreator,
post1 -> EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)));
mSwipeRefreshLayout.setRefreshing(false);
FetchComment.fetchComments(mExecutor, new Handler(), mRetrofit.getRetrofit(), mAccessToken, post.getId(), mSingleCommentId == null || mSingleCommentId == 0 ? null : mSingleCommentParentId == 0 ? mSingleCommentId : mSingleCommentParentId, sortType, mExpandChildren, 1, mCommentFilter, new FetchComment.FetchCommentListener() {
FetchComment.fetchComments(mExecutor, new Handler(), mRetrofit.getRetrofit(), mAccessToken, post.getId(), mSingleCommentId == null || mSingleCommentId == 0 ? null : mSingleCommentParentId == 0 ? mSingleCommentId : mSingleCommentParentId, sortType, mExpandChildren, 1, new FetchComment.FetchCommentListener() {
@Override
public void onFetchCommentSuccess(ArrayList<Comment> expandedComments, Integer parentId, ArrayList<Integer> children) {
pages_loaded++;
@@ -1407,8 +1387,12 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
fetchCommentsRespectRecommendedSort(false);
}
ViewPostDetailFragment.this.children = children;
}
hasMoreChildren = false;
mCommentsAdapter.addComments(expandedComments, hasMoreChildren);
}
@Override
public void onFetchCommentFailed() {
@@ -1484,7 +1468,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
FetchComment.fetchComments(mExecutor, new Handler(), mRetrofit.getRetrofit(), mAccessToken, mPost.getId(), mSingleCommentId == null || mSingleCommentId == 0 ? null : mSingleCommentParentId == 0 ? mSingleCommentId : mSingleCommentParentId, sortType, mExpandChildren, pages_loaded + 1,
mCommentFilter, new FetchComment.FetchCommentListener() {
new FetchComment.FetchCommentListener() {
@Override
public void onFetchCommentSuccess(ArrayList<Comment> expandedComments,
Integer parentId, ArrayList<Integer> children) {
@@ -1573,7 +1557,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
isLoadingMoreChildren = true;
FetchComment.fetchComments(mExecutor, new Handler(), mRetrofit.getRetrofit(), mAccessToken,
mPost.getId(), (mSingleCommentId == null || mSingleCommentId == 0) ? null : (mSingleCommentParentId == null || mSingleCommentParentId == 0 ? mSingleCommentId : mSingleCommentParentId), sortType, mExpandChildren, pages_loaded + 1, mCommentFilter, new FetchComment.FetchCommentListener() {
mPost.getId(), (mSingleCommentId == null || mSingleCommentId == 0) ? null : (mSingleCommentParentId == null || mSingleCommentParentId == 0 ? mSingleCommentId : mSingleCommentParentId), sortType, mExpandChildren, pages_loaded + 1, new FetchComment.FetchCommentListener() {
@Override
public void onFetchCommentSuccess(ArrayList<Comment> expandedComments, Integer parentId, ArrayList<Integer> children) {
pages_loaded++;

View File

@@ -16,6 +16,7 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
@@ -38,7 +39,6 @@ import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
import com.google.android.exoplayer2.upstream.cache.CacheDataSource;
import com.google.android.exoplayer2.upstream.cache.SimpleCache;
import com.google.android.material.bottomappbar.BottomAppBar;
import com.google.android.material.button.MaterialButton;
import com.google.common.collect.ImmutableList;
import javax.inject.Inject;
@@ -75,12 +75,8 @@ public class ViewRedditGalleryVideoFragment extends Fragment {
BottomAppBar bottomAppBar;
@BindView(R.id.title_text_view_exo_playback_control_view)
TextView titleTextView;
@BindView(R.id.back_button_exo_playback_control_view)
MaterialButton backButton;
@BindView(R.id.download_image_view_exo_playback_control_view)
MaterialButton downloadButton;
@BindView(R.id.playback_speed_image_view_exo_playback_control_view)
MaterialButton playbackSpeedButton;
ImageView downloadImageView;
private ViewRedditGalleryActivity activity;
private Post.Gallery galleryVideo;
private String subredditName;
@@ -172,37 +168,22 @@ public class ViewRedditGalleryVideoFragment extends Fragment {
Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.DEFAULT_PLAYBACK_SPEED, "100"));
preparePlayer(savedInstanceState);
titleTextView.setText(getString(R.string.view_reddit_gallery_activity_video_label,
getArguments().getInt(EXTRA_INDEX) + 1, getArguments().getInt(EXTRA_MEDIA_COUNT)));
if (activity.isUseBottomAppBar()) {
bottomAppBar.setVisibility(View.VISIBLE);
backButton.setOnClickListener(view -> {
activity.finish();
});
downloadButton.setOnClickListener(view -> {
titleTextView.setText(getString(R.string.view_reddit_gallery_activity_video_label,
getArguments().getInt(EXTRA_INDEX) + 1, getArguments().getInt(EXTRA_MEDIA_COUNT)));
downloadImageView.setOnClickListener(view -> {
if (isDownloading) {
return;
}
isDownloading = true;
requestPermissionAndDownload();
});
playbackSpeedButton.setOnClickListener(view -> {
changePlaybackSpeed();
});
}
return rootView;
}
private void changePlaybackSpeed() {
PlaybackSpeedBottomSheetFragment playbackSpeedBottomSheetFragment = new PlaybackSpeedBottomSheetFragment();
Bundle bundle = new Bundle();
bundle.putInt(PlaybackSpeedBottomSheetFragment.EXTRA_PLAYBACK_SPEED, playbackSpeed);
playbackSpeedBottomSheetFragment.setArguments(bundle);
playbackSpeedBottomSheetFragment.show(getChildFragmentManager(), playbackSpeedBottomSheetFragment.getTag());
}
@Override
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
inflater.inflate(R.menu.view_reddit_gallery_video_fragment, menu);
@@ -220,7 +201,11 @@ public class ViewRedditGalleryVideoFragment extends Fragment {
requestPermissionAndDownload();
return true;
} else if (item.getItemId() == R.id.action_playback_speed_view_reddit_gallery_video_fragment) {
PlaybackSpeedBottomSheetFragment playbackSpeedBottomSheetFragment = new PlaybackSpeedBottomSheetFragment();
Bundle bundle = new Bundle();
bundle.putInt(PlaybackSpeedBottomSheetFragment.EXTRA_PLAYBACK_SPEED, playbackSpeed);
playbackSpeedBottomSheetFragment.setArguments(bundle);
playbackSpeedBottomSheetFragment.show(getChildFragmentManager(), playbackSpeedBottomSheetFragment.getTag());
return true;
}
return false;

View File

@@ -38,84 +38,44 @@ public class MarkdownUtils {
@NonNull MarkwonPlugin miscPlugin,
int markdownColor,
int spoilerBackgroundColor,
@Nullable BetterLinkMovementMethod.OnLinkLongClickListener onLinkLongClickListener, boolean dataSaverEnabled) {
Markwon result;
if (dataSaverEnabled) {
result = Markwon.builder(context)
.usePlugin(MarkwonInlineParserPlugin.create(plugin -> {
plugin.excludeInlineProcessor(HtmlInlineProcessor.class);
}))
.usePlugin(miscPlugin)
.usePlugin(SuperscriptPlugin.create())
.usePlugin(SpoilerParserPlugin.create(markdownColor, spoilerBackgroundColor))
.usePlugin(RedditHeadingPlugin.create())
.usePlugin(StrikethroughPlugin.create())
.usePlugin(MovementMethodPlugin.create(new SpoilerAwareMovementMethod()
.setOnLinkLongClickListener(onLinkLongClickListener)))
.usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS))
.usePlugin(TableEntryPlugin.create(context))
.usePlugin(new MarkwonLemmyLinkPlugin())
.build();
} else {
result = Markwon.builder(context)
.usePlugin(GlideImagesPlugin.create(context.getApplicationContext()))
.usePlugin(MarkwonInlineParserPlugin.create(plugin -> {
plugin.excludeInlineProcessor(HtmlInlineProcessor.class);
}))
.usePlugin(miscPlugin)
.usePlugin(SuperscriptPlugin.create())
.usePlugin(SpoilerParserPlugin.create(markdownColor, spoilerBackgroundColor))
.usePlugin(RedditHeadingPlugin.create())
.usePlugin(StrikethroughPlugin.create())
.usePlugin(MovementMethodPlugin.create(new SpoilerAwareMovementMethod()
.setOnLinkLongClickListener(onLinkLongClickListener)))
.usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS))
.usePlugin(TableEntryPlugin.create(context))
.usePlugin(ClickableGlideImagesPlugin.create(context))
.usePlugin(new MarkwonLemmyLinkPlugin())
.build();
}
return result;
@Nullable BetterLinkMovementMethod.OnLinkLongClickListener onLinkLongClickListener) {
return Markwon.builder(context)
.usePlugin(GlideImagesPlugin.create(context.getApplicationContext()))
.usePlugin(MarkwonInlineParserPlugin.create(plugin -> {
plugin.excludeInlineProcessor(HtmlInlineProcessor.class);
}))
.usePlugin(miscPlugin)
.usePlugin(SuperscriptPlugin.create())
.usePlugin(SpoilerParserPlugin.create(markdownColor, spoilerBackgroundColor))
.usePlugin(RedditHeadingPlugin.create())
.usePlugin(StrikethroughPlugin.create())
.usePlugin(MovementMethodPlugin.create(new SpoilerAwareMovementMethod()
.setOnLinkLongClickListener(onLinkLongClickListener)))
.usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS))
.usePlugin(TableEntryPlugin.create(context))
.usePlugin(ClickableGlideImagesPlugin.create(context))
.usePlugin(new MarkwonLemmyLinkPlugin())
.build();
}
@NonNull
public static Markwon createDescriptionMarkwon(Activity context, MarkwonPlugin miscPlugin,
BetterLinkMovementMethod.OnLinkLongClickListener onLinkLongClickListener, boolean dataSaverEnabled) {
Markwon result;
if (dataSaverEnabled) {
result = Markwon.builder(context)
.usePlugin(MarkwonInlineParserPlugin.create(plugin -> {
plugin.excludeInlineProcessor(HtmlInlineProcessor.class);
}))
.usePlugin(miscPlugin)
.usePlugin(SuperscriptPlugin.create())
.usePlugin(RedditHeadingPlugin.create())
.usePlugin(StrikethroughPlugin.create())
.usePlugin(MovementMethodPlugin.create(new SpoilerAwareMovementMethod()
.setOnLinkLongClickListener(onLinkLongClickListener)))
.usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS))
.usePlugin(TableEntryPlugin.create(context))
.usePlugin(new MarkwonLemmyLinkPlugin())
.build();
} else {
result = Markwon.builder(context)
.usePlugin(MarkwonInlineParserPlugin.create(plugin -> {
plugin.excludeInlineProcessor(HtmlInlineProcessor.class);
}))
.usePlugin(miscPlugin)
.usePlugin(SuperscriptPlugin.create())
.usePlugin(RedditHeadingPlugin.create())
.usePlugin(StrikethroughPlugin.create())
.usePlugin(MovementMethodPlugin.create(new SpoilerAwareMovementMethod()
.setOnLinkLongClickListener(onLinkLongClickListener)))
.usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS))
.usePlugin(TableEntryPlugin.create(context))
.usePlugin(GlideImagesPlugin.create(context.getApplicationContext()))
.usePlugin(new MarkwonLemmyLinkPlugin())
.build();
}
return result;
BetterLinkMovementMethod.OnLinkLongClickListener onLinkLongClickListener) {
return Markwon.builder(context)
.usePlugin(MarkwonInlineParserPlugin.create(plugin -> {
plugin.excludeInlineProcessor(HtmlInlineProcessor.class);
}))
.usePlugin(miscPlugin)
.usePlugin(SuperscriptPlugin.create())
.usePlugin(RedditHeadingPlugin.create())
.usePlugin(StrikethroughPlugin.create())
.usePlugin(MovementMethodPlugin.create(new SpoilerAwareMovementMethod()
.setOnLinkLongClickListener(onLinkLongClickListener)))
.usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS))
.usePlugin(TableEntryPlugin.create(context))
.usePlugin(GlideImagesPlugin.create(context.getApplicationContext()))
.usePlugin(new MarkwonLemmyLinkPlugin())
.build();
}
/**

View File

@@ -32,7 +32,8 @@ public class MessageViewModel extends ViewModel {
hasMessageLiveData = Transformations.switchMap(messageDataSourceFactory.getMessageDataSourceLiveData(),
MessageDataSource::hasPostLiveData);
whereLiveData = new MutableLiveData<>(where);
whereLiveData = new MutableLiveData<>();
whereLiveData.postValue(where);
PagedList.Config pagedListConfig =
(new PagedList.Config.Builder())

View File

@@ -23,7 +23,8 @@ public class MultiRedditViewModel extends AndroidViewModel {
public MultiRedditViewModel(Application application, RedditDataRoomDatabase redditDataRoomDatabase, String accountName) {
super(application);
mMultiRedditRepository = new MultiRedditRepository(redditDataRoomDatabase, accountName);
searchQueryLiveData = new MutableLiveData<>("");
searchQueryLiveData = new MutableLiveData<>();
searchQueryLiveData.postValue("");
mAllMultiReddits = Transformations.switchMap(searchQueryLiveData, searchQuery -> mMultiRedditRepository.getAllMultiRedditsWithSearchQuery(searchQuery));
mAllFavoriteMultiReddits = Transformations.switchMap(searchQueryLiveData, searchQuery -> mMultiRedditRepository.getAllFavoriteMultiRedditsWithSearchQuery(searchQuery));

View File

@@ -49,9 +49,10 @@ public class HistoryPostViewModel extends ViewModel {
this.postFilter = postFilter;
this.postEnricher = postEnricher;
postFilterLiveData = new MutableLiveData<>(postFilter);
postFilterLiveData = new MutableLiveData<>();
postFilterLiveData.postValue(postFilter);
Pager<String, Post> pager = new Pager<>(new PagingConfig(25, 4, false, 10), this::returnPagingSource);
Pager<String, Post> pager = new Pager<>(new PagingConfig(25, 25, false), this::returnPagingSource);
posts = Transformations.switchMap(postFilterLiveData, postFilterValue -> PagingLiveData.cachedIn(PagingLiveData.getLiveData(pager), ViewModelKt.getViewModelScope(this)));
}

View File

@@ -181,7 +181,6 @@ public class ParsePost {
boolean nsfw = post.getBoolean("nsfw");
boolean locked = post.getBoolean("locked");
boolean saved = data.getBoolean("saved");
boolean deleted = post.getBoolean("deleted");
String distinguished = creator.optBoolean("admin") ? "admin" : "";
String suggestedSort = "";
ArrayList<Post.Preview> previews = new ArrayList<>();
@@ -195,7 +194,7 @@ public class ParsePost {
return parseData(data, permalink, id, communityInfo,
authorInfo, postTimeMillis, title, previews,
downvotes, upvotes, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted,
downvotes, upvotes, voteType, nComments, upvoteRatio, nsfw, locked, saved,
distinguished, suggestedSort);
}
@@ -204,7 +203,7 @@ public class ParsePost {
long postTimeMillis, String title, ArrayList<Post.Preview> previews,
int downvotes, int upvotes, int voteType, int nComments, int upvoteRatio,
boolean nsfw, boolean locked,
boolean saved, boolean deleted,
boolean saved,
String distinguished, String suggestedSort) throws JSONException {
Post post;
@@ -224,7 +223,7 @@ public class ParsePost {
post = new Post(id, communityInfo, author,
postTimeMillis, title, permalink, downvotes, upvotes,
postType, voteType, nComments, upvoteRatio, nsfw,
locked, saved, deleted, distinguished, suggestedSort);
locked, saved, distinguished, suggestedSort);
String body = data.getJSONObject("post").getString("body");
post.setSelfText(body);
post.setSelfTextPlain(body);
@@ -236,7 +235,7 @@ public class ParsePost {
post = new Post(id, communityInfo, author,
postTimeMillis, title, url, permalink, downvotes, upvotes,
postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted, distinguished, suggestedSort);
postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, distinguished, suggestedSort);
if (previews.isEmpty()) {
previews.add(new Post.Preview(url, 0, 0, "", ""));
@@ -248,7 +247,7 @@ public class ParsePost {
int postType = Post.VIDEO_TYPE;
post = new Post(id, communityInfo, author, postTimeMillis, title, permalink, downvotes, upvotes, postType, voteType,
nComments, upvoteRatio, nsfw, locked, saved, deleted, distinguished, suggestedSort);
nComments, upvoteRatio, nsfw, locked, saved, distinguished, suggestedSort);
post.setVideoUrl(url);
post.setVideoDownloadUrl(url);
@@ -257,7 +256,7 @@ public class ParsePost {
int postType = Post.NO_PREVIEW_LINK_TYPE;
post = new Post(id, communityInfo, author,
postTimeMillis, title, url, permalink, downvotes, upvotes,
postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted, distinguished, suggestedSort);
postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, distinguished, suggestedSort);
if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
post.setSelfText("");
} else {
@@ -292,7 +291,7 @@ public class ParsePost {
post = new Post(id, communityInfo, author,
postTimeMillis, title, permalink, downvotes, upvotes,
postType, voteType, nComments, upvoteRatio, nsfw,
locked, saved, deleted, distinguished, suggestedSort);
locked, saved, distinguished, suggestedSort);
String body = "";
post.setSelfText(body);
post.setSelfTextPlain(body);
@@ -329,7 +328,7 @@ public class ParsePost {
String videoDownloadUrl = redditVideoObject.getString(JSONUtils.FALLBACK_URL_KEY);
post = new Post(id, communityInfo, author, postTimeMillis, title, permalink, downvotes, upvotes, postType, voteType,
nComments, upvoteRatio, nsfw, locked, saved, deleted, distinguished, suggestedSort);
nComments, upvoteRatio, nsfw, locked, saved, distinguished, suggestedSort);
post.setPreviews(previews);
post.setVideoUrl(videoUrl);
@@ -341,7 +340,7 @@ public class ParsePost {
post = new Post(id, communityInfo, author,
postTimeMillis, title, url, permalink, downvotes, upvotes,
postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted,
postType, voteType, nComments, upvoteRatio, nsfw, locked, saved,
distinguished, suggestedSort);
if (previews.isEmpty()) {
@@ -354,7 +353,7 @@ public class ParsePost {
post = new Post(id, communityInfo, author,
postTimeMillis, title, url, permalink, downvotes, upvotes,
postType, voteType, nComments, upvoteRatio,
nsfw, locked, saved, deleted,
nsfw, locked, saved,
distinguished, suggestedSort);
post.setPreviews(previews);
@@ -370,7 +369,7 @@ public class ParsePost {
post = new Post(id, communityInfo, author,
postTimeMillis, title, url, permalink, downvotes, upvotes,
postType, voteType, nComments, upvoteRatio,
nsfw, locked, saved, deleted,
nsfw, locked, saved,
distinguished, suggestedSort);
post.setPreviews(previews);
post.setVideoUrl(url);
@@ -382,7 +381,7 @@ public class ParsePost {
post = new Post(id, communityInfo, author,
postTimeMillis, title, url, permalink, downvotes, upvotes,
postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted,
postType, voteType, nComments, upvoteRatio, nsfw, locked, saved,
distinguished, suggestedSort);
post.setPreviews(previews);
post.setVideoUrl(url);
@@ -393,7 +392,7 @@ public class ParsePost {
post = new Post(id, communityInfo, author,
postTimeMillis, title, url, permalink, downvotes, upvotes,
postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted,
postType, voteType, nComments, upvoteRatio, nsfw, locked, saved,
distinguished, suggestedSort);
if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
post.setSelfText("");
@@ -434,7 +433,7 @@ public class ParsePost {
post = new Post(id, communityInfo, author,
postTimeMillis, title, url, permalink, downvotes, upvotes,
postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted, distinguished, suggestedSort);
postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, distinguished, suggestedSort);
if (previews.isEmpty()) {
previews.add(new Post.Preview(url, 0, 0, "", ""));
@@ -446,7 +445,7 @@ public class ParsePost {
post = new Post(id, communityInfo, author,
postTimeMillis, title, url, permalink, downvotes, upvotes,
postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted, distinguished, suggestedSort);
postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, distinguished, suggestedSort);
post.setPreviews(previews);
post.setVideoUrl(url);
post.setVideoDownloadUrl(url);
@@ -456,7 +455,7 @@ public class ParsePost {
post = new Post(id, communityInfo, author,
postTimeMillis, title, url, permalink, downvotes, upvotes,
postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, deleted, distinguished, suggestedSort);
postType, voteType, nComments, upvoteRatio, nsfw, locked, saved, distinguished, suggestedSort);
//Need attention
if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
post.setSelfText("");

View File

@@ -72,8 +72,6 @@ public class Post implements Parcelable {
private boolean saved;
private boolean isCrosspost;
private boolean isRead;
private boolean deleted;
private String crosspostParentId;
private String distinguished;
private String suggestedSort;
@@ -84,7 +82,7 @@ public class Post implements Parcelable {
BasicUserInfo userInfo, long postTimeMillis,
String title, String permalink, int downvotes, int upvotes, int postType, int voteType, int nComments,
int upvoteRatio,
boolean nsfw, boolean locked, boolean saved, boolean deleted,
boolean nsfw, boolean locked, boolean saved,
String distinguished, String suggestedSort) {
this.id = id;
this.communityInfo = communityInfo;
@@ -101,7 +99,6 @@ public class Post implements Parcelable {
this.hidden = hidden;
this.nsfw = nsfw;
this.archived = archived;
this.deleted = deleted;
this.locked = locked;
this.saved = saved;
this.isCrosspost = isCrosspost;
@@ -114,7 +111,7 @@ public class Post implements Parcelable {
BasicUserInfo author, long postTimeMillis, String title,
String url, String permalink, int downvotes, int upvotes, int postType, int voteType, int nComments,
int upvoteRatio,
boolean nsfw, boolean locked, boolean saved, boolean deleted, String distinguished, String suggestedSort) {
boolean nsfw, boolean locked, boolean saved, String distinguished, String suggestedSort) {
this.id = id;
this.communityInfo = communityInfo;
this.author = author;
@@ -133,7 +130,6 @@ public class Post implements Parcelable {
this.archived = archived;
this.locked = locked;
this.saved = saved;
this.deleted = deleted;
this.isCrosspost = isCrosspost;
this.distinguished = distinguished;
this.suggestedSort = suggestedSort;
@@ -172,7 +168,6 @@ public class Post implements Parcelable {
archived = in.readByte() != 0;
locked = in.readByte() != 0;
saved = in.readByte() != 0;
deleted = in.readByte() != 0;
isCrosspost = in.readByte() != 0;
isRead = in.readByte() != 0;
crosspostParentId = in.readString();
@@ -508,10 +503,6 @@ public class Post implements Parcelable {
return author;
}
public boolean isDeleted() {
return deleted;
}
@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeInt(id);
@@ -545,7 +536,6 @@ public class Post implements Parcelable {
parcel.writeByte((byte) (archived ? 1 : 0));
parcel.writeByte((byte) (locked ? 1 : 0));
parcel.writeByte((byte) (saved ? 1 : 0));
parcel.writeByte((byte) (deleted ? 1 : 0));
parcel.writeByte((byte) (isCrosspost ? 1 : 0));
parcel.writeByte((byte) (isRead ? 1 : 0));
parcel.writeString(crosspostParentId);

View File

@@ -69,8 +69,10 @@ public class PostViewModel extends ViewModel {
this.name = option;
this.postEnricher = postEnricher;
sortTypeLiveData = new MutableLiveData<>(sortType);
postFilterLiveData = new MutableLiveData<>(postFilter);
sortTypeLiveData = new MutableLiveData<>();
sortTypeLiveData.postValue(sortType);
postFilterLiveData = new MutableLiveData<>();
postFilterLiveData.postValue(postFilter);
sortTypeAndPostFilterLiveData = new SortTypeAndPostFilterLiveData(sortTypeLiveData, postFilterLiveData);
@@ -110,8 +112,10 @@ public class PostViewModel extends ViewModel {
this.name = subredditName;
this.postEnricher = postEnricher;
sortTypeLiveData = new MutableLiveData<>(sortType);
postFilterLiveData = new MutableLiveData<>(postFilter);
sortTypeLiveData = new MutableLiveData<>();
sortTypeLiveData.postValue(sortType);
postFilterLiveData = new MutableLiveData<>();
postFilterLiveData.postValue(postFilter);
sortTypeAndPostFilterLiveData = new SortTypeAndPostFilterLiveData(sortTypeLiveData, postFilterLiveData);
@@ -154,8 +158,10 @@ public class PostViewModel extends ViewModel {
this.userWhere = userWhere;
this.postEnricher = postEnricher;
sortTypeLiveData = new MutableLiveData<>(sortType);
postFilterLiveData = new MutableLiveData<>(postFilter);
sortTypeLiveData = new MutableLiveData<>();
sortTypeLiveData.postValue(sortType);
postFilterLiveData = new MutableLiveData<>();
postFilterLiveData.postValue(postFilter);
sortTypeAndPostFilterLiveData = new SortTypeAndPostFilterLiveData(sortTypeLiveData, postFilterLiveData);
@@ -198,8 +204,10 @@ public class PostViewModel extends ViewModel {
this.trendingSource = trendingSource;
this.postEnricher = postEnricher;
sortTypeLiveData = new MutableLiveData<>(sortType);
postFilterLiveData = new MutableLiveData<>(postFilter);
sortTypeLiveData = new MutableLiveData<>();
sortTypeLiveData.postValue(sortType);
postFilterLiveData = new MutableLiveData<>();
postFilterLiveData.postValue(postFilter);
sortTypeAndPostFilterLiveData = new SortTypeAndPostFilterLiveData(sortTypeLiveData, postFilterLiveData);

View File

@@ -55,11 +55,11 @@ public class SubmitPost {
public static void submitCrosspost(Executor executor, Handler handler, Retrofit oauthRetrofit, String accessToken,
int communityId, String title, String crosspostFullname,
String url, boolean isSpoiler, boolean isNSFW,
Flair flair, boolean isSpoiler, boolean isNSFW,
boolean receivePostReplyNotifications, String kind, PostEnricher postEnricher,
SubmitPostListener submitPostListener) {
submitPost(executor, handler, oauthRetrofit, accessToken, communityId, title, crosspostFullname,
isNSFW, receivePostReplyNotifications, kind, url, postEnricher, submitPostListener);
isNSFW, receivePostReplyNotifications, kind, null, postEnricher, submitPostListener);
}
private static void submitPost(Executor executor, Handler handler, Retrofit oauthRetrofit, String accessToken,

View File

@@ -6,7 +6,6 @@ import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Transaction;
import java.util.List;
@@ -37,11 +36,7 @@ public interface PostFilterDao {
List<PostFilter> getAllPostFilters();
@Query("SELECT * FROM post_filter WHERE post_filter.name IN " +
"(SELECT post_filter_usage.name FROM post_filter_usage WHERE (usage = :usage AND name_of_usage = :nameOfUsage COLLATE NOCASE) " +
"(SELECT post_filter_usage.name FROM post_filter_usage WHERE (usage = :usage AND name_of_usage = :nameOfUsage) " +
"OR (usage =:usage AND name_of_usage = '--'))")
List<PostFilter> getValidPostFilters(int usage, String nameOfUsage);
@Transaction
@Query("SELECT * FROM post_filter ORDER BY name")
public LiveData<List<PostFilterWithUsage>> getAllPostFilterWithUsageLiveData();
}

View File

@@ -8,16 +8,15 @@ import java.util.List;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
public class PostFilterViewModel extends ViewModel {
private LiveData<List<PostFilter>> mPostFilterListLiveData;
public class PostFilterWithUsageViewModel extends ViewModel {
private LiveData<List<PostFilterWithUsage>> mPostFilterWithUsageListLiveData;
public PostFilterWithUsageViewModel(RedditDataRoomDatabase redditDataRoomDatabase) {
mPostFilterWithUsageListLiveData = redditDataRoomDatabase.postFilterDao().getAllPostFilterWithUsageLiveData();
public PostFilterViewModel(RedditDataRoomDatabase redditDataRoomDatabase) {
mPostFilterListLiveData = redditDataRoomDatabase.postFilterDao().getAllPostFiltersLiveData();
}
public LiveData<List<PostFilterWithUsage>> getPostFilterWithUsageListLiveData() {
return mPostFilterWithUsageListLiveData;
public LiveData<List<PostFilter>> getPostFilterListLiveData() {
return mPostFilterListLiveData;
}
public static class Factory extends ViewModelProvider.NewInstanceFactory {
@@ -31,7 +30,7 @@ public class PostFilterWithUsageViewModel extends ViewModel {
@Override
public <T extends ViewModel> T create(Class<T> modelClass) {
//noinspection unchecked
return (T) new PostFilterWithUsageViewModel(mRedditDataRoomDatabase);
return (T) new PostFilterViewModel(mRedditDataRoomDatabase);
}
}
}
}

View File

@@ -1,16 +0,0 @@
package eu.toldi.infinityforlemmy.postfilter;
import androidx.room.Embedded;
import androidx.room.Relation;
import java.util.List;
public class PostFilterWithUsage {
@Embedded
public PostFilter postFilter;
@Relation(
parentColumn = "name",
entityColumn = "name"
)
public List<PostFilterUsage> postFilterUsages;
}

View File

@@ -0,0 +1,44 @@
package eu.toldi.infinityforlemmy.recentsearchquery;
import android.os.AsyncTask;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
public class DeleteRecentSearchQuery {
public interface DeleteRecentSearchQueryListener {
void success();
}
public static void deleteRecentSearchQueryListener(RedditDataRoomDatabase redditDataRoomDatabase,
RecentSearchQuery recentSearchQuery,
DeleteRecentSearchQueryListener deleteRecentSearchQueryListener) {
new DeleteRecentSearchQueryAsyncTask(redditDataRoomDatabase, recentSearchQuery, deleteRecentSearchQueryListener).execute();
}
private static class DeleteRecentSearchQueryAsyncTask extends AsyncTask<Void, Void, Void> {
private RecentSearchQueryDao recentSearchQueryDao;
private RecentSearchQuery recentSearchQuery;
private DeleteRecentSearchQueryListener deleteRecentSearchQueryListener;
public DeleteRecentSearchQueryAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase,
RecentSearchQuery recentSearchQuery,
DeleteRecentSearchQueryListener deleteRecentSearchQueryListener) {
this.recentSearchQueryDao = redditDataRoomDatabase.recentSearchQueryDao();
this.recentSearchQuery = recentSearchQuery;
this.deleteRecentSearchQueryListener = deleteRecentSearchQueryListener;
}
@Override
protected Void doInBackground(Void... voids) {
recentSearchQueryDao.deleteRecentSearchQueries(recentSearchQuery);
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
deleteRecentSearchQueryListener.success();
}
}
}

View File

@@ -1,9 +1,8 @@
package eu.toldi.infinityforlemmy.recentsearchquery;
import android.os.Handler;
import android.os.AsyncTask;
import java.util.List;
import java.util.concurrent.Executor;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
@@ -12,13 +11,28 @@ public class InsertRecentSearchQuery {
void success();
}
public static void insertRecentSearchQueryListener(Executor executor, Handler handler,
RedditDataRoomDatabase redditDataRoomDatabase,
String username,
String recentSearchQuery,
InsertRecentSearchQueryListener insertRecentSearchQueryListener) {
executor.execute(() -> {
RecentSearchQueryDao recentSearchQueryDao = redditDataRoomDatabase.recentSearchQueryDao();
public static void insertRecentSearchQueryListener(RedditDataRoomDatabase redditDataRoomDatabase, String username,
String recentSearchQuery, InsertRecentSearchQueryListener insertRecentSearchQueryListener) {
new InsertRecentSearchQueryAsyncTask(redditDataRoomDatabase, username, recentSearchQuery, insertRecentSearchQueryListener).execute();
}
private static class InsertRecentSearchQueryAsyncTask extends AsyncTask<Void, Void, Void> {
private RecentSearchQueryDao recentSearchQueryDao;
private String username;
private String recentSearchQuery;
private InsertRecentSearchQueryListener insertRecentSearchQueryListener;
public InsertRecentSearchQueryAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, String username,
String recentSearchQuery, InsertRecentSearchQueryListener insertRecentSearchQueryListener) {
this.recentSearchQueryDao = redditDataRoomDatabase.recentSearchQueryDao();
this.username = username;
this.recentSearchQuery = recentSearchQuery;
this.insertRecentSearchQueryListener = insertRecentSearchQueryListener;
}
@Override
protected Void doInBackground(Void... voids) {
List<RecentSearchQuery> recentSearchQueries = recentSearchQueryDao.getAllRecentSearchQueries(username);
if (recentSearchQueries.size() >= 5) {
for (int i = 4; i < recentSearchQueries.size(); i++) {
@@ -27,8 +41,13 @@ public class InsertRecentSearchQuery {
}
recentSearchQueryDao.insert(new RecentSearchQuery(username, recentSearchQuery));
return null;
}
handler.post(insertRecentSearchQueryListener::success);
});
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
insertRecentSearchQueryListener.success();
}
}
}

Some files were not shown because too many files have changed in this diff Show More