Merge changes from Infinity

This commit merges the changes that were made in the upstream infinity repo
This commit is contained in:
Balazs Toldi 2023-10-27 15:10:00 +02:00
parent 262d9f02ba
commit 4397e09016
No known key found for this signature in database
GPG Key ID: 6C7D440036F99D58
182 changed files with 12490 additions and 11105 deletions

2
.gitignore vendored
View File

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

View File

@ -232,7 +232,7 @@ dependencies {
implementation 'com.github.santalu:aspect-ratio-imageview:1.0.9' implementation 'com.github.santalu:aspect-ratio-imageview:1.0.9'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.23' implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.23'
def bivVersion = "1.8.1" 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:GlideImageLoader:$bivVersion"
implementation "com.github.piasy:GlideImageViewFactory:$bivVersion" implementation "com.github.piasy:GlideImageViewFactory:$bivVersion"
@ -271,6 +271,8 @@ dependencies {
implementation 'com.otaliastudios:zoomlayout:1.9.0' implementation 'com.otaliastudios:zoomlayout:1.9.0'
implementation 'androidx.core:core-splashscreen:1.0.1'
/**** Builds and flavors ****/ /**** Builds and flavors ****/
// debugImplementation because LeakCanary should only run in debug builds. // debugImplementation because LeakCanary should only run in debug builds.

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools"
package="eu.toldi.infinityforlemmy">
<queries> <queries>
<intent> <intent>
@ -22,6 +23,7 @@
android:maxSdkVersion="28" /> android:maxSdkVersion="28" />
<uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" /> <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<application <application
@ -40,6 +42,23 @@
android:configChanges="orientation|screenLayout|screenSize|layoutDirection" android:configChanges="orientation|screenLayout|screenSize|layoutDirection"
android:parentActivityName=".activities.MainActivity" android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.Slidable" /> 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 <activity
android:name=".activities.HistoryActivity" android:name=".activities.HistoryActivity"
android:exported="false" android:exported="false"
@ -407,11 +426,6 @@
android:label="@string/subscriptions" android:label="@string/subscriptions"
android:parentActivityName=".activities.MainActivity" android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.Slidable" /> android:theme="@style/AppTheme.Slidable" />
<activity
android:name=".activities.BlockedThingListingActivity"
android:label="@string/blocks"
android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.Slidable" />
<activity <activity
android:name=".activities.SubredditSelectionActivity" android:name=".activities.SubredditSelectionActivity"
android:label="@string/community_selection_activity_label" android:label="@string/community_selection_activity_label"
@ -454,6 +468,7 @@
android:exported="true"> android:exported="true">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity-alias> </activity-alias>
@ -499,6 +514,7 @@
android:name=".activities.ViewUserDetailActivity" android:name=".activities.ViewUserDetailActivity"
android:parentActivityName=".activities.MainActivity" android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.Slidable" /> android:theme="@style/AppTheme.Slidable" />
<provider <provider
android:name="androidx.core.content.FileProvider" android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider" android:authorities="${applicationId}.provider"

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

View File

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

View File

@ -17,6 +17,10 @@ import eu.toldi.infinityforlemmy.blockedcommunity.BlockedCommunityDao;
import eu.toldi.infinityforlemmy.blockedcommunity.BlockedCommunityData; import eu.toldi.infinityforlemmy.blockedcommunity.BlockedCommunityData;
import eu.toldi.infinityforlemmy.blockeduser.BlockedUserDao; import eu.toldi.infinityforlemmy.blockeduser.BlockedUserDao;
import eu.toldi.infinityforlemmy.blockeduser.BlockedUserData; 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.CustomTheme;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeDao; import eu.toldi.infinityforlemmy.customtheme.CustomThemeDao;
import eu.toldi.infinityforlemmy.multireddit.AnonymousMultiredditSubreddit; import eu.toldi.infinityforlemmy.multireddit.AnonymousMultiredditSubreddit;
@ -42,7 +46,8 @@ import eu.toldi.infinityforlemmy.user.UserData;
@Database(entities = {Account.class, SubredditData.class, SubscribedSubredditData.class, UserData.class, @Database(entities = {Account.class, SubredditData.class, SubscribedSubredditData.class, UserData.class,
SubscribedUserData.class, MultiReddit.class, CustomTheme.class, RecentSearchQuery.class, SubscribedUserData.class, MultiReddit.class, CustomTheme.class, RecentSearchQuery.class,
ReadPost.class, PostFilter.class, PostFilterUsage.class, AnonymousMultiredditSubreddit.class, BlockedUserData.class, BlockedCommunityData.class}, version = 27) ReadPost.class, PostFilter.class, PostFilterUsage.class, AnonymousMultiredditSubreddit.class,
BlockedUserData.class, BlockedCommunityData.class, CommentFilter.class, CommentFilterUsage.class}, version = 28)
public abstract class RedditDataRoomDatabase extends RoomDatabase { public abstract class RedditDataRoomDatabase extends RoomDatabase {
public static RedditDataRoomDatabase create(final Context context) { public static RedditDataRoomDatabase create(final Context context) {
@ -53,7 +58,7 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
MIGRATION_9_10, MIGRATION_10_11, MIGRATION_11_12, MIGRATION_12_13, 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_13_14, MIGRATION_14_15, MIGRATION_15_16, MIGRATION_16_17,
MIGRATION_17_18, MIGRATION_18_19, MIGRATION_19_20, MIGRATION_20_21, 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_21_22, MIGRATION_22_23, MIGRATION_23_24, MIGRATION_24_25, MIGRATION_25_26, MIGRATION_26_27, MIGRATION_27_28)
.build(); .build();
} }
@ -85,6 +90,10 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
public abstract AnonymousMultiredditSubredditDao anonymousMultiredditSubredditDao(); public abstract AnonymousMultiredditSubredditDao anonymousMultiredditSubredditDao();
public abstract CommentFilterDao commentFilterDao();
public abstract CommentFilterUsageDao commentFilterUsageDao();
private static final Migration MIGRATION_1_2 = new Migration(1, 2) { private static final Migration MIGRATION_1_2 = new Migration(1, 2) {
@Override @Override
public void migrate(SupportSQLiteDatabase database) { public void migrate(SupportSQLiteDatabase database) {
@ -424,4 +433,16 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
+ " ADD COLUMN is_favorite INTEGER DEFAULT 0 NOT NULL"); + " 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

@ -0,0 +1,126 @@
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

@ -0,0 +1,181 @@
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

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

View File

@ -1,336 +0,0 @@
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

@ -33,6 +33,7 @@ import androidx.appcompat.app.AppCompatDelegate;
import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.core.splashscreen.SplashScreen;
import androidx.drawerlayout.widget.DrawerLayout; import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
@ -249,6 +250,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
SplashScreen.installSplashScreen(this);
((Infinity) getApplication()).getAppComponent().inject(this); ((Infinity) getApplication()).getAppComponent().inject(this);
setTheme(R.style.AppTheme_NoActionBarWithTransparentStatusBar); setTheme(R.style.AppTheme_NoActionBarWithTransparentStatusBar);
@ -823,8 +826,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
} else if (stringId == R.string.multi_reddit) { } else if (stringId == R.string.multi_reddit) {
intent = new Intent(MainActivity.this, SubscribedThingListingActivity.class); intent = new Intent(MainActivity.this, SubscribedThingListingActivity.class);
intent.putExtra(SubscribedThingListingActivity.EXTRA_SHOW_MULTIREDDITS, true); 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) { } else if (stringId == R.string.trending) {
intent = new Intent(MainActivity.this, TrendingActivity.class); intent = new Intent(MainActivity.this, TrendingActivity.class);
} else if (stringId == R.string.upvoted) { } else if (stringId == R.string.upvoted) {
@ -926,7 +927,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
sectionsPagerAdapter = new SectionsPagerAdapter(this, tabCount, mShowFavoriteMultiReddits, sectionsPagerAdapter = new SectionsPagerAdapter(this, tabCount, mShowFavoriteMultiReddits,
mShowMultiReddits, mShowFavoriteSubscribedSubreddits, mShowSubscribedSubreddits); mShowMultiReddits, mShowFavoriteSubscribedSubreddits, mShowSubscribedSubreddits);
viewPager2.setAdapter(sectionsPagerAdapter); viewPager2.setAdapter(sectionsPagerAdapter);
viewPager2.setOffscreenPageLimit(1); viewPager2.setOffscreenPageLimit(ViewPager2.OFFSCREEN_PAGE_LIMIT_DEFAULT);
viewPager2.setUserInputEnabled(!mDisableSwipingBetweenTabs); viewPager2.setUserInputEnabled(!mDisableSwipingBetweenTabs);
if (mMainActivityTabsSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_TAB_NAMES, true)) { if (mMainActivityTabsSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_TAB_NAMES, true)) {
if (mShowFavoriteMultiReddits || mShowMultiReddits || mShowFavoriteSubscribedSubreddits || mShowSubscribedSubreddits) { if (mShowFavoriteMultiReddits || mShowMultiReddits || mShowFavoriteSubscribedSubreddits || mShowSubscribedSubreddits) {
@ -1665,7 +1666,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
} }
public void doNotShowRedditAPIInfoAgain() { public void doNotShowRedditAPIInfoAgain() {
mInternalSharedPreferences.edit().putBoolean(SharedPreferencesUtils.DO_NOT_SHOW_REDDIT_API_INFO_AGAIN, true).apply(); mInternalSharedPreferences.edit().putBoolean(SharedPreferencesUtils.DO_NOT_SHOW_REDDIT_API_INFO_V2_AGAIN, true).apply();
} }
private class SectionsPagerAdapter extends FragmentStateAdapter { private class SectionsPagerAdapter extends FragmentStateAdapter {

View File

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

View File

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

View File

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

View File

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

View File

@ -1,9 +1,13 @@
package eu.toldi.infinityforlemmy.activities; package eu.toldi.infinityforlemmy.activities;
import static android.graphics.BitmapFactory.decodeResource;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
@ -40,6 +44,8 @@ import androidx.viewpager2.widget.ViewPager2;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager; import com.bumptech.glide.RequestManager;
import com.bumptech.glide.request.RequestOptions; 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.evernote.android.state.State;
import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout; import com.google.android.material.appbar.CollapsingToolbarLayout;
@ -104,6 +110,7 @@ import eu.toldi.infinityforlemmy.post.MarkPostAsRead;
import eu.toldi.infinityforlemmy.post.Post; import eu.toldi.infinityforlemmy.post.Post;
import eu.toldi.infinityforlemmy.post.PostPagingSource; import eu.toldi.infinityforlemmy.post.PostPagingSource;
import eu.toldi.infinityforlemmy.readpost.InsertReadPost; import eu.toldi.infinityforlemmy.readpost.InsertReadPost;
import eu.toldi.infinityforlemmy.shortcut.ShortcutManager;
import eu.toldi.infinityforlemmy.subreddit.CommunitySubscription; import eu.toldi.infinityforlemmy.subreddit.CommunitySubscription;
import eu.toldi.infinityforlemmy.subreddit.FetchSubredditData; import eu.toldi.infinityforlemmy.subreddit.FetchSubredditData;
import eu.toldi.infinityforlemmy.subreddit.ParseSubredditData; import eu.toldi.infinityforlemmy.subreddit.ParseSubredditData;
@ -260,6 +267,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
private int subscribedColor; private int subscribedColor;
private int fabOption; private int fabOption;
private MaterialAlertDialogBuilder nsfwWarningBuilder; private MaterialAlertDialogBuilder nsfwWarningBuilder;
private Bitmap subredditIconBitmap;
private boolean showStatistics; private boolean showStatistics;
@ -575,11 +583,23 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
.into(iconGifImageView); .into(iconGifImageView);
iconGifImageView.setOnClickListener(null); iconGifImageView.setOnClickListener(null);
} else { } else {
glide.load(subredditData.getIconUrl()) glide.asBitmap()
.load(subredditData.getIconUrl())
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(216, 0))) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(216, 0)))
.error(glide.load(R.drawable.subreddit_default_icon) .error(glide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(216, 0)))) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(216, 0))))
.into(iconGifImageView); .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;
}
});
iconGifImageView.setOnClickListener(view -> { iconGifImageView.setOnClickListener(view -> {
Intent intent = new Intent(ViewSubredditDetailActivity.this, ViewImageOrGifActivity.class); Intent intent = new Intent(ViewSubredditDetailActivity.this, ViewImageOrGifActivity.class);
intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, subredditData.getIconUrl()); intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, subredditData.getIconUrl());
@ -1148,7 +1168,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
} }
}); });
viewPager2.setAdapter(sectionsPagerAdapter); viewPager2.setAdapter(sectionsPagerAdapter);
viewPager2.setOffscreenPageLimit(2); viewPager2.setOffscreenPageLimit(ViewPager2.OFFSCREEN_PAGE_LIMIT_DEFAULT);
viewPager2.setUserInputEnabled(!mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_SWIPING_BETWEEN_TABS, false)); viewPager2.setUserInputEnabled(!mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_SWIPING_BETWEEN_TABS, false));
new TabLayoutMediator(tabLayout, viewPager2, (tab, position) -> { new TabLayoutMediator(tabLayout, viewPager2, (tab, position) -> {
switch (position) { switch (position) {
@ -1274,6 +1294,9 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
} }
}); });
return true; 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; return false;
} }

View File

@ -761,7 +761,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
private void initializeViewPager() { private void initializeViewPager() {
sectionsPagerAdapter = new SectionsPagerAdapter(this); sectionsPagerAdapter = new SectionsPagerAdapter(this);
viewPager2.setAdapter(sectionsPagerAdapter); viewPager2.setAdapter(sectionsPagerAdapter);
viewPager2.setOffscreenPageLimit(2); viewPager2.setOffscreenPageLimit(ViewPager2.OFFSCREEN_PAGE_LIMIT_DEFAULT);
viewPager2.setUserInputEnabled(!mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_SWIPING_BETWEEN_TABS, false)); viewPager2.setUserInputEnabled(!mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_SWIPING_BETWEEN_TABS, false));
new TabLayoutMediator(tabLayout, viewPager2, (tab, position) -> { new TabLayoutMediator(tabLayout, viewPager2, (tab, position) -> {
switch (position) { switch (position) {

View File

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

View File

@ -0,0 +1,76 @@
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

@ -0,0 +1,80 @@
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

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,102 @@
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

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

View File

@ -0,0 +1,63 @@
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

@ -0,0 +1,57 @@
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

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

View File

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

View File

@ -1,73 +0,0 @@
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

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

View File

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

View File

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

View File

@ -0,0 +1,122 @@
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) {
if (commentFilter.maxVote > 0 && comment.getVoteType() + comment.getScore() > commentFilter.maxVote) {
return false;
}
if (commentFilter.minVote > 0 && comment.getVoteType() + comment.getScore() < 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

@ -0,0 +1,47 @@
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

@ -0,0 +1,61 @@
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

@ -0,0 +1,31 @@
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

@ -0,0 +1,41 @@
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

@ -0,0 +1,16 @@
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

@ -0,0 +1,39 @@
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

@ -0,0 +1,12 @@
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

@ -0,0 +1,13 @@
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

@ -0,0 +1,25 @@
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

@ -0,0 +1,38 @@
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

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

View File

@ -144,6 +144,14 @@ 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),
context.getString(R.string.theme_item_read_post_card_view_background_color_detail), context.getString(R.string.theme_item_read_post_card_view_background_color_detail),
customTheme.readPostCardViewBackgroundColor)); 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( customThemeSettingsItems.add(new CustomThemeSettingsItem(
context.getString(R.string.theme_item_comment_background_color), context.getString(R.string.theme_item_comment_background_color),
context.getString(R.string.theme_item_comment_background_color_detail), context.getString(R.string.theme_item_comment_background_color_detail),

View File

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

View File

@ -0,0 +1,31 @@
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 hte screen * The drag helper callbacks for dragging the slidr attachment from the bottom of the screen
*/ */
private final ViewDragHelper.Callback bottomCallback = new ViewDragHelper.Callback() { private final ViewDragHelper.Callback bottomCallback = new ViewDragHelper.Callback() {
@Override @Override

View File

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

View File

@ -1,100 +1,28 @@
package eu.toldi.infinityforlemmy.fragments; package eu.toldi.infinityforlemmy.fragments;
import android.content.Context; import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import butterknife.BindView; import eu.toldi.infinityforlemmy.R;
import butterknife.ButterKnife;
import eu.toldi.infinityforlemmy.activities.CustomThemePreviewActivity; import eu.toldi.infinityforlemmy.activities.CustomThemePreviewActivity;
import eu.toldi.infinityforlemmy.customtheme.CustomTheme; import eu.toldi.infinityforlemmy.customtheme.CustomTheme;
import eu.toldi.infinityforlemmy.R; import eu.toldi.infinityforlemmy.databinding.FragmentThemePreviewCommentsBinding;
import eu.toldi.infinityforlemmy.utils.Utils;
/** /**
* A simple {@link Fragment} subclass. * A simple {@link Fragment} subclass.
*/ */
public class ThemePreviewCommentsFragment extends Fragment { public class ThemePreviewCommentsFragment extends Fragment {
@BindView(R.id.linear_layout_theme_preview_comments_fragment) private FragmentThemePreviewCommentsBinding binding;
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; private CustomThemePreviewActivity activity;
public ThemePreviewCommentsFragment() { public ThemePreviewCommentsFragment() {
@ -103,65 +31,69 @@ public class ThemePreviewCommentsFragment extends Fragment {
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_theme_preview_comments, container, false); binding = FragmentThemePreviewCommentsBinding.inflate(inflater, container, false);
ButterKnife.bind(this, rootView);
CustomTheme customTheme = activity.getCustomTheme(); 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);
linearLayoutAwardBackground.setBackgroundColor(customTheme.awardedCommentBackgroundColor); Drawable expandDrawable = Utils.getTintedDrawable(activity, R.drawable.ic_expand_more_grey_24dp, customTheme.commentIconAndInfoColor);
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);
linearLayoutFullyCollapsed.setBackgroundColor(customTheme.fullyCollapsedCommentBackgroundColor); binding.linearLayoutThemePreviewCommentsFragment.setBackgroundColor(customTheme.commentBackgroundColor);
authorTextViewFullyCollapsed.setTextColor(customTheme.username); binding.authorTypeImageViewThemePreviewCommentsFragment.setColorFilter(customTheme.moderator, android.graphics.PorterDuff.Mode.SRC_IN);
scoreTextViewFullyCollapsed.setTextColor(customTheme.secondaryTextColor); binding.authorTextViewThemePreviewCommentsFragment.setTextColor(customTheme.moderator);
timeTextViewFullyCollapsed.setTextColor(customTheme.secondaryTextColor); 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);
if (activity.typeface != null) { if (activity.typeface != null) {
authorTextView.setTypeface(activity.typeface); binding.authorTextViewThemePreviewCommentsFragment.setTypeface(activity.typeface);
commentTimeTextView.setTypeface(activity.typeface); binding.commentTimeTextViewThemePreviewCommentsFragment.setTypeface(activity.typeface);
flairTextView.setTypeface(activity.typeface); binding.authorFlairTextViewThemePreviewCommentsFragment.setTypeface(activity.typeface);
scoreTextView.setTypeface(activity.typeface); binding.upvoteButtonThemePreviewCommentsFragment.setTypeface(activity.typeface);
authorTextViewAwardBackground.setTypeface(activity.typeface);
commentTimeTextViewAwardBackground.setTypeface(activity.typeface); binding.authorTextViewAwardBackgroundThemePreviewCommentsFragment.setTypeface(activity.typeface);
flairTextViewAwardBackground.setTypeface(activity.typeface); binding.commentTimeTextViewAwardBackgroundThemePreviewCommentsFragment.setTypeface(activity.typeface);
scoreTextViewAwardBackground.setTypeface(activity.typeface); binding.authorFlairTextViewAwardBackgroundThemePreviewCommentsFragment.setTypeface(activity.typeface);
authorTextViewFullyCollapsed.setTypeface(activity.typeface); binding.upvoteButtonAwardBackgroundThemePreviewCommentsFragment.setTypeface(activity.typeface);
scoreTextViewFullyCollapsed.setTypeface(activity.typeface);
timeTextViewFullyCollapsed.setTypeface(activity.typeface); binding.authorTextViewFullyCollapsedThemePreviewCommentsFragment.setTypeface(activity.typeface);
binding.scoreTextViewFullyCollapsedThemePreviewCommentsFragment.setTypeface(activity.typeface);
binding.timeTextViewFullyCollapsedThemePreviewCommentsFragment.setTypeface(activity.typeface);
} }
if (activity.contentTypeface != null) { if (activity.contentTypeface != null) {
contentTextView.setTypeface(activity.contentTypeface); binding.commentMarkdownViewThemePreviewCommentsFragment.setTypeface(activity.contentTypeface);
contentTextViewAwardBackground.setTypeface(activity.contentTypeface); binding.commentMarkdownViewAwardBackgroundThemePreviewCommentsFragment.setTypeface(activity.contentTypeface);
} }
return rootView; return binding.getRoot();
} }
@Override @Override

View File

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

View File

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

View File

@ -17,6 +17,7 @@ import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Looper;
import android.view.HapticFeedbackConstants; import android.view.HapticFeedbackConstants;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
@ -94,6 +95,9 @@ import eu.toldi.infinityforlemmy.comment.Comment;
import eu.toldi.infinityforlemmy.comment.FetchComment; import eu.toldi.infinityforlemmy.comment.FetchComment;
import eu.toldi.infinityforlemmy.comment.FetchRemovedComment; import eu.toldi.infinityforlemmy.comment.FetchRemovedComment;
import eu.toldi.infinityforlemmy.comment.FetchRemovedCommentReveddit; import eu.toldi.infinityforlemmy.comment.FetchRemovedCommentReveddit;
import eu.toldi.infinityforlemmy.comment.ParseComment;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilter;
import eu.toldi.infinityforlemmy.commentfilter.FetchCommentFilter;
import eu.toldi.infinityforlemmy.community.BlockCommunity; import eu.toldi.infinityforlemmy.community.BlockCommunity;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper; import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.customviews.CustomToroContainer; import eu.toldi.infinityforlemmy.customviews.CustomToroContainer;
@ -232,6 +236,10 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
boolean mRespectSubredditRecommendedSortType; boolean mRespectSubredditRecommendedSortType;
@State @State
long viewPostDetailFragmentId; long viewPostDetailFragmentId;
@State
boolean commentFilterFetched;
@State
CommentFilter mCommentFilter;
@State @State
boolean isCommunityBlocked; boolean isCommunityBlocked;
@ -292,7 +300,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
applyTheme(); applyTheme();
mRecyclerView.addOnWindowFocusChangedListener(this::onWindowFocusChanged);
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null); mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
@ -459,7 +467,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
@Override @Override
public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) {
if (!(viewHolder instanceof CommentsRecyclerViewAdapter.CommentViewHolder)) { if (!(viewHolder instanceof CommentsRecyclerViewAdapter.CommentBaseViewHolder)) {
return makeMovementFlags(0, 0); return makeMovementFlags(0, 0);
} }
int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END; int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END;
@ -554,7 +562,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
touchHelper.attachToRecyclerView((mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView)); touchHelper.attachToRecyclerView((mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView));
} }
mSwipeRefreshLayout.setOnRefreshListener(() -> refresh(true, true)); mSwipeRefreshLayout.setOnRefreshListener(() -> refresh());
mSmoothScroller = new LinearSmoothScroller(activity) { mSmoothScroller = new LinearSmoothScroller(activity) {
@Override @Override
@ -644,7 +652,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
public SortType.Type getSortType() { public SortType.Type getSortType() {
return sortType; return sortType;
} }
} ); });
if (mCommentsRecyclerView != null) { if (mCommentsRecyclerView != null) {
mRecyclerView.setAdapter(mPostAdapter); mRecyclerView.setAdapter(mPostAdapter);
mCommentsRecyclerView.setAdapter(mCommentsAdapter); mCommentsRecyclerView.setAdapter(mCommentsAdapter);
@ -653,6 +661,26 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
mRecyclerView.setAdapter(mConcatAdapter); mRecyclerView.setAdapter(mConcatAdapter);
} }
if (commentFilterFetched) {
fetchCommentsAfterCommentFilterAvailable();
} else {
FetchCommentFilter.fetchCommentFilter(mExecutor, new Handler(Looper.getMainLooper()), mRedditDataRoomDatabase, mPost.getSubredditName(),
commentFilter -> {
mCommentFilter = commentFilter;
commentFilterFetched = true;
fetchCommentsAfterCommentFilterAvailable();
});
}
}
mRecyclerView.setCacheManager(mPostAdapter);
mRecyclerView.setPlayerInitializer(order -> {
VolumeInfo volumeInfo = new VolumeInfo(true, 0f);
return new PlaybackInfo(INDEX_UNSET, TIME_UNSET, volumeInfo);
});
}
public void fetchCommentsAfterCommentFilterAvailable() {
if (comments == null) { if (comments == null) {
fetchCommentsRespectRecommendedSort(false); fetchCommentsRespectRecommendedSort(false);
} else { } else {
@ -671,13 +699,6 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
} }
} }
mRecyclerView.setCacheManager(mPostAdapter);
mRecyclerView.setPlayerInitializer(order -> {
VolumeInfo volumeInfo = new VolumeInfo(true, 0f);
return new PlaybackInfo(INDEX_UNSET, TIME_UNSET, volumeInfo);
});
}
private void setupMenu() { private void setupMenu() {
if (mMenu != null) { if (mMenu != null) {
MenuItem saveItem = mMenu.findItem(R.id.action_save_view_post_detail_fragment); MenuItem saveItem = mMenu.findItem(R.id.action_save_view_post_detail_fragment);
@ -1348,7 +1369,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
mPostDetailsSharedPreferences, mExoCreator, mPostDetailsSharedPreferences, mExoCreator,
post1 -> EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition))); post1 -> EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)));
mSwipeRefreshLayout.setRefreshing(false); 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, 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, mCommentFilter, new FetchComment.FetchCommentListener() {
@Override @Override
public void onFetchCommentSuccess(ArrayList<Comment> expandedComments, Integer parentId, ArrayList<Integer> children) { public void onFetchCommentSuccess(ArrayList<Comment> expandedComments, Integer parentId, ArrayList<Integer> children) {
pages_loaded++; pages_loaded++;
@ -1387,13 +1408,9 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
fetchCommentsRespectRecommendedSort(false); fetchCommentsRespectRecommendedSort(false);
} }
ViewPostDetailFragment.this.children = children; ViewPostDetailFragment.this.children = children;
hasMoreChildren = false;
mCommentsAdapter.addComments(expandedComments, hasMoreChildren);
} }
@Override @Override
public void onFetchCommentFailed() { public void onFetchCommentFailed() {
if (isAdded()) { if (isAdded()) {
@ -1468,7 +1485,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, FetchComment.fetchComments(mExecutor, new Handler(), mRetrofit.getRetrofit(), mAccessToken, mPost.getId(), mSingleCommentId == null || mSingleCommentId == 0 ? null : mSingleCommentParentId == 0 ? mSingleCommentId : mSingleCommentParentId, sortType, mExpandChildren, pages_loaded + 1,
new FetchComment.FetchCommentListener() { mCommentFilter, new FetchComment.FetchCommentListener() {
@Override @Override
public void onFetchCommentSuccess(ArrayList<Comment> expandedComments, public void onFetchCommentSuccess(ArrayList<Comment> expandedComments,
Integer parentId, ArrayList<Integer> children) { Integer parentId, ArrayList<Integer> children) {
@ -1557,7 +1574,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
isLoadingMoreChildren = true; isLoadingMoreChildren = true;
FetchComment.fetchComments(mExecutor, new Handler(), mRetrofit.getRetrofit(), mAccessToken, 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, new FetchComment.FetchCommentListener() { mPost.getId(), (mSingleCommentId == null || mSingleCommentId == 0) ? null : (mSingleCommentParentId == null || mSingleCommentParentId == 0 ? mSingleCommentId : mSingleCommentParentId), sortType, mExpandChildren, pages_loaded + 1, mCommentFilter, new FetchComment.FetchCommentListener() {
@Override @Override
public void onFetchCommentSuccess(ArrayList<Comment> expandedComments, Integer parentId, ArrayList<Integer> children) { public void onFetchCommentSuccess(ArrayList<Comment> expandedComments, Integer parentId, ArrayList<Integer> children) {
pages_loaded++; pages_loaded++;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,16 @@
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

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

View File

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

View File

@ -20,6 +20,9 @@ public interface RecentSearchQueryDao {
@Query("SELECT * FROM recent_search_queries WHERE username = :username ORDER BY time DESC") @Query("SELECT * FROM recent_search_queries WHERE username = :username ORDER BY time DESC")
List<RecentSearchQuery> getAllRecentSearchQueries(String username); List<RecentSearchQuery> getAllRecentSearchQueries(String username);
@Query("DELETE FROM recent_search_queries WHERE username = :username")
void deleteAllRecentSearchQueries(String username);
@Delete @Delete
void deleteRecentSearchQueries(RecentSearchQuery recentSearchQuery); void deleteRecentSearchQueries(RecentSearchQuery recentSearchQuery);
} }

View File

@ -26,6 +26,8 @@ import android.os.Message;
import android.os.Process; import android.os.Process;
import android.provider.MediaStore; import android.provider.MediaStore;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationChannelCompat; import androidx.core.app.NotificationChannelCompat;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat; import androidx.core.app.NotificationManagerCompat;
@ -83,6 +85,7 @@ public class DownloadRedditVideoService extends Service {
private ServiceHandler serviceHandler; private ServiceHandler serviceHandler;
private NotificationManagerCompat notificationManager; private NotificationManagerCompat notificationManager;
private NotificationCompat.Builder builder; private NotificationCompat.Builder builder;
private final String[] possibleAudioUrlSuffices = new String[]{"/DASH_AUDIO_128.mp4", "/DASH_audio.mp4", "/DASH_audio", "/audio.mp4", "/audio"};
public DownloadRedditVideoService() { public DownloadRedditVideoService() {
} }
@ -95,7 +98,9 @@ public class DownloadRedditVideoService extends Service {
public void handleMessage(Message msg) { public void handleMessage(Message msg) {
Bundle intent = msg.getData(); Bundle intent = msg.getData();
String videoUrl = intent.getString(EXTRA_VIDEO_URL); String videoUrl = intent.getString(EXTRA_VIDEO_URL);
String audioUrl = Build.VERSION.SDK_INT > Build.VERSION_CODES.N ? videoUrl.substring(0, videoUrl.lastIndexOf('/')) + "/DASH_audio.mp4" : null;
String audioUrlPrefix = Build.VERSION.SDK_INT > Build.VERSION_CODES.N ? videoUrl.substring(0, videoUrl.lastIndexOf('/')) : null;
String subredditName = intent.getString(EXTRA_SUBREDDIT); String subredditName = intent.getString(EXTRA_SUBREDDIT);
String fileNameWithoutExtension = subredditName + "-" + intent.getString(EXTRA_POST_ID); String fileNameWithoutExtension = subredditName + "-" + intent.getString(EXTRA_POST_ID);
boolean isNsfw = intent.getBoolean(EXTRA_IS_NSFW, false); boolean isNsfw = intent.getBoolean(EXTRA_IS_NSFW, false);
@ -104,7 +109,8 @@ public class DownloadRedditVideoService extends Service {
final DownloadProgressResponseBody.ProgressListener progressListener = new DownloadProgressResponseBody.ProgressListener() { final DownloadProgressResponseBody.ProgressListener progressListener = new DownloadProgressResponseBody.ProgressListener() {
long time = 0; long time = 0;
@Override public void update(long bytesRead, long contentLength, boolean done) { @Override
public void update(long bytesRead, long contentLength, boolean done) {
if (!done) { if (!done) {
if (contentLength != -1) { if (contentLength != -1) {
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
@ -129,7 +135,7 @@ public class DownloadRedditVideoService extends Service {
retrofit = retrofit.newBuilder().client(client).build(); retrofit = retrofit.newBuilder().client(client).build();
DownloadFile downloadFile = retrofit.create(DownloadFile.class); DownloadFile downloadFileRetrofit = retrofit.create(DownloadFile.class);
boolean separateDownloadFolder = sharedPreferences.getBoolean(SharedPreferencesUtils.SEPARATE_FOLDER_FOR_EACH_SUBREDDIT, false); boolean separateDownloadFolder = sharedPreferences.getBoolean(SharedPreferencesUtils.SEPARATE_FOLDER_FOR_EACH_SUBREDDIT, false);
@ -138,7 +144,7 @@ public class DownloadRedditVideoService extends Service {
String destinationFileName = fileNameWithoutExtension + ".mp4"; String destinationFileName = fileNameWithoutExtension + ".mp4";
try { try {
Response<ResponseBody> videoResponse = downloadFile.downloadFile(videoUrl).execute(); Response<ResponseBody> videoResponse = downloadFileRetrofit.downloadFile(videoUrl).execute();
if (videoResponse.isSuccessful() && videoResponse.body() != null) { if (videoResponse.isSuccessful() && videoResponse.body() != null) {
String externalCacheDirectoryPath = externalCacheDirectory.getAbsolutePath() + "/"; String externalCacheDirectoryPath = externalCacheDirectory.getAbsolutePath() + "/";
String destinationFileDirectory; String destinationFileDirectory;
@ -218,13 +224,13 @@ public class DownloadRedditVideoService extends Service {
return; return;
} }
if (audioUrl != null) { if (audioUrlPrefix != null) {
Response<ResponseBody> audioResponse = downloadFile.downloadFile(audioUrl).execute(); ResponseBody audioResponse = getAudioResponse(downloadFileRetrofit, audioUrlPrefix, 0);
String outputFilePath = externalCacheDirectoryPath + fileNameWithoutExtension + ".mp4"; String outputFilePath = externalCacheDirectoryPath + fileNameWithoutExtension + ".mp4";
if (audioResponse.isSuccessful() && audioResponse.body() != null) { if (audioResponse != null) {
String audioFilePath = externalCacheDirectoryPath + fileNameWithoutExtension + "-cache.mp3"; String audioFilePath = externalCacheDirectoryPath + fileNameWithoutExtension + "-cache.mp3";
String savedAudioFilePath = writeResponseBodyToDisk(audioResponse.body(), audioFilePath); String savedAudioFilePath = writeResponseBodyToDisk(audioResponse, audioFilePath);
if (savedAudioFilePath == null) { if (savedAudioFilePath == null) {
downloadFinished(null, ERROR_AUDIO_FILE_CANNOT_SAVE, randomNotificationIdOffset); downloadFinished(null, ERROR_AUDIO_FILE_CANNOT_SAVE, randomNotificationIdOffset);
return; return;
@ -298,6 +304,22 @@ public class DownloadRedditVideoService extends Service {
} }
} }
@Nullable
private ResponseBody getAudioResponse(DownloadFile downloadFileRetrofit, @NonNull String audioUrlPrefix, int audioSuffixIndex) throws IOException {
if (audioSuffixIndex >= possibleAudioUrlSuffices.length) {
return null;
}
String audioUrl = audioUrlPrefix + possibleAudioUrlSuffices[audioSuffixIndex];
Response<ResponseBody> audioResponse = downloadFileRetrofit.downloadFile(audioUrl).execute();
ResponseBody responseBody = audioResponse.body();
if (audioResponse.isSuccessful() && responseBody != null) {
return responseBody;
}
return getAudioResponse(downloadFileRetrofit, audioUrlPrefix, audioSuffixIndex + 1);
}
private String writeResponseBodyToDisk(ResponseBody body, String filePath) { private String writeResponseBodyToDisk(ResponseBody body, String filePath) {
try { try {
File file = new File(filePath); File file = new File(filePath);

View File

@ -8,6 +8,7 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.biometric.BiometricManager; import androidx.biometric.BiometricManager;
import androidx.preference.Preference; import androidx.preference.Preference;
@ -19,6 +20,10 @@ import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.activities.PostFilterPreferenceActivity; import eu.toldi.infinityforlemmy.activities.PostFilterPreferenceActivity;
import eu.toldi.infinityforlemmy.customviews.CustomFontPreferenceFragmentCompat; import eu.toldi.infinityforlemmy.customviews.CustomFontPreferenceFragmentCompat;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils; import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
import eu.toldi.infinityforlemmy.activities.CommentFilterPreferenceActivity;
import eu.toldi.infinityforlemmy.activities.LinkResolverActivity;
import eu.toldi.infinityforlemmy.activities.PostFilterPreferenceActivity;
import eu.toldi.infinityforlemmy.customviews.CustomFontPreferenceFragmentCompat;
public class MainPreferenceFragment extends CustomFontPreferenceFragmentCompat { public class MainPreferenceFragment extends CustomFontPreferenceFragmentCompat {
@ -33,6 +38,7 @@ public class MainPreferenceFragment extends CustomFontPreferenceFragmentCompat {
Preference securityPreference = findPreference(SharedPreferencesUtils.SECURITY); Preference securityPreference = findPreference(SharedPreferencesUtils.SECURITY);
Preference postFilterPreference = findPreference(SharedPreferencesUtils.POST_FILTER); Preference postFilterPreference = findPreference(SharedPreferencesUtils.POST_FILTER);
Preference commentFilterPreference = findPreference(SharedPreferencesUtils.COMMENT_FILTER);
Preference privacyPolicyPreference = findPreference(SharedPreferencesUtils.PRIVACY_POLICY_KEY); Preference privacyPolicyPreference = findPreference(SharedPreferencesUtils.PRIVACY_POLICY_KEY);
Preference redditUserAgreementPreference = findPreference(SharedPreferencesUtils.REDDIT_USER_AGREEMENT_KEY); Preference redditUserAgreementPreference = findPreference(SharedPreferencesUtils.REDDIT_USER_AGREEMENT_KEY);
@ -50,5 +56,16 @@ public class MainPreferenceFragment extends CustomFontPreferenceFragmentCompat {
return true; return true;
}); });
} }
if (commentFilterPreference != null) {
commentFilterPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(@NonNull Preference preference) {
Intent intent = new Intent(activity, CommentFilterPreferenceActivity.class);
activity.startActivity(intent);
return true;
}
});
}
} }
} }

View File

@ -0,0 +1,37 @@
package eu.toldi.infinityforlemmy.shortcut;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import androidx.annotation.NonNull;
import androidx.core.content.pm.ShortcutInfoCompat;
import androidx.core.content.pm.ShortcutManagerCompat;
import androidx.core.graphics.drawable.IconCompat;
import eu.toldi.infinityforlemmy.BuildConfig;
import eu.toldi.infinityforlemmy.activities.ViewSubredditDetailActivity;
public class ShortcutManager {
private static ShortcutInfoCompat getInfo(Context context, @NonNull String subreddit, @NonNull Bitmap icon) {
final Intent shortcut = new Intent(context, ViewSubredditDetailActivity.class);
shortcut.setPackage(context.getPackageName());
shortcut.setAction(Intent.ACTION_MAIN);
shortcut.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcut.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, subreddit);
String shortcutId = BuildConfig.APPLICATION_ID + ".shortcut." + subreddit;
String subredditName = subreddit;
return new ShortcutInfoCompat.Builder(context, shortcutId)
.setIntent(shortcut)
.setShortLabel(subredditName)
.setAlwaysBadged()
.setIcon(IconCompat.createWithBitmap(icon))
.build();
}
public static boolean requestPinShortcut(Context context, @NonNull String subreddit, @NonNull Bitmap icon) {
return ShortcutManagerCompat.requestPinShortcut(context, getInfo(context, subreddit, icon), null);
}
}

View File

@ -31,8 +31,7 @@ public class SubredditListingViewModel extends ViewModel {
hasSubredditLiveData = Transformations.switchMap(subredditListingDataSourceFactory.getSubredditListingDataSourceMutableLiveData(), hasSubredditLiveData = Transformations.switchMap(subredditListingDataSourceFactory.getSubredditListingDataSourceMutableLiveData(),
SubredditListingDataSource::hasSubredditLiveData); SubredditListingDataSource::hasSubredditLiveData);
sortTypeLiveData = new MutableLiveData<>(); sortTypeLiveData = new MutableLiveData<>(sortType);
sortTypeLiveData.postValue(sortType);
PagedList.Config pagedListConfig = PagedList.Config pagedListConfig =
(new PagedList.Config.Builder()) (new PagedList.Config.Builder())

View File

@ -23,8 +23,7 @@ public class SubscribedSubredditViewModel extends AndroidViewModel {
public SubscribedSubredditViewModel(Application application, RedditDataRoomDatabase redditDataRoomDatabase, String accountName) { public SubscribedSubredditViewModel(Application application, RedditDataRoomDatabase redditDataRoomDatabase, String accountName) {
super(application); super(application);
mSubscribedSubredditRepository = new SubscribedSubredditRepository(redditDataRoomDatabase, accountName); mSubscribedSubredditRepository = new SubscribedSubredditRepository(redditDataRoomDatabase, accountName);
searchQueryLiveData = new MutableLiveData<>(); searchQueryLiveData = new MutableLiveData<>("");
searchQueryLiveData.postValue("");
mAllSubscribedSubreddits = Transformations.switchMap(searchQueryLiveData, searchQuery -> mSubscribedSubredditRepository.getAllSubscribedSubredditsWithSearchQuery(searchQuery)); mAllSubscribedSubreddits = Transformations.switchMap(searchQueryLiveData, searchQuery -> mSubscribedSubredditRepository.getAllSubscribedSubredditsWithSearchQuery(searchQuery));
mAllFavoriteSubscribedSubreddits = Transformations.switchMap(searchQueryLiveData, searchQuery -> mSubscribedSubredditRepository.getAllFavoriteSubscribedSubredditsWithSearchQuery(searchQuery)); mAllFavoriteSubscribedSubreddits = Transformations.switchMap(searchQueryLiveData, searchQuery -> mSubscribedSubredditRepository.getAllFavoriteSubscribedSubredditsWithSearchQuery(searchQuery));

View File

@ -23,8 +23,7 @@ public class SubscribedUserViewModel extends AndroidViewModel {
public SubscribedUserViewModel(Application application, RedditDataRoomDatabase redditDataRoomDatabase, String accountName) { public SubscribedUserViewModel(Application application, RedditDataRoomDatabase redditDataRoomDatabase, String accountName) {
super(application); super(application);
mSubscribedUserRepository = new SubscribedUserRepository(redditDataRoomDatabase, accountName); mSubscribedUserRepository = new SubscribedUserRepository(redditDataRoomDatabase, accountName);
searchQueryLiveData = new MutableLiveData<>(); searchQueryLiveData = new MutableLiveData<>("");
searchQueryLiveData.postValue("");
mAllSubscribedUsers = Transformations.switchMap(searchQueryLiveData, searchQuery -> mSubscribedUserRepository.getAllSubscribedUsersWithSearchQuery(searchQuery)); mAllSubscribedUsers = Transformations.switchMap(searchQueryLiveData, searchQuery -> mSubscribedUserRepository.getAllSubscribedUsersWithSearchQuery(searchQuery));
mAllFavoriteSubscribedUsers = Transformations.switchMap(searchQueryLiveData, searchQuery -> mSubscribedUserRepository.getAllFavoriteSubscribedUsersWithSearchQuery(searchQuery)); mAllFavoriteSubscribedUsers = Transformations.switchMap(searchQueryLiveData, searchQuery -> mSubscribedUserRepository.getAllFavoriteSubscribedUsersWithSearchQuery(searchQuery));

View File

@ -31,8 +31,7 @@ public class UserListingViewModel extends ViewModel {
hasUserLiveData = Transformations.switchMap(userListingDataSourceFactory.getUserListingDataSourceMutableLiveData(), hasUserLiveData = Transformations.switchMap(userListingDataSourceFactory.getUserListingDataSourceMutableLiveData(),
UserListingDataSource::hasUserLiveData); UserListingDataSource::hasUserLiveData);
sortTypeLiveData = new MutableLiveData<>(); sortTypeLiveData = new MutableLiveData<>(sortType);
sortTypeLiveData.postValue(sortType);
PagedList.Config pagedListConfig = PagedList.Config pagedListConfig =
(new PagedList.Config.Builder()) (new PagedList.Config.Builder())

View File

@ -1,5 +1,4 @@
package eu.toldi.infinityforlemmy.utils; package eu.toldi.infinityforlemmy.utils;
import android.util.Base64; import android.util.Base64;
import java.util.HashMap; import java.util.HashMap;
@ -117,11 +116,6 @@ public class APIUtils {
public static final String REFERER_KEY = "Referer"; public static final String REFERER_KEY = "Referer";
public static final String REVEDDIT_REFERER = "https://www.reveddit.com/"; public static final String REVEDDIT_REFERER = "https://www.reveddit.com/";
/*public static final String HOST_KEY = "Host";
public static final String REDGIFS_HOST = "api.redgifs.com";
public static final String CONTENT_TYPE_KEY = "Content-Type";
public static final String */
public static Map<String, String> getHttpBasicAuthHeader() { public static Map<String, String> getHttpBasicAuthHeader() {
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
String credentials = String.format("%s:%s", APIUtils.CLIENT_ID, ""); String credentials = String.format("%s:%s", APIUtils.CLIENT_ID, "");

View File

@ -29,6 +29,8 @@ public class CustomThemeSharedPreferencesUtils {
public static final String BACKGROUND_COLOR = "backgroundColor"; public static final String BACKGROUND_COLOR = "backgroundColor";
public static final String CARD_VIEW_BACKGROUND_COLOR = "cardViewBackgroundColor"; public static final String CARD_VIEW_BACKGROUND_COLOR = "cardViewBackgroundColor";
public static final String READ_POST_CARD_VIEW_BACKGROUND_COLOR = "readPostCardViewBackgroundColor"; public static final String READ_POST_CARD_VIEW_BACKGROUND_COLOR = "readPostCardViewBackgroundColor";
public static final String FILLED_CARD_VIEW_BACKGROUND_COLOR = "filledCardViewBackgroundColor";
public static final String READ_POST_FILLED_CARD_VIEW_BACKGROUND_COLOR = "readPostFilledCardViewBackgroundColor";
public static final String COMMENT_BACKGROUND_COLOR = "commentBackgroundColor"; public static final String COMMENT_BACKGROUND_COLOR = "commentBackgroundColor";
public static final String BOTTOM_APP_BAR_BACKGROUND_COLOR = "bottomAppBarBackgroundColor"; public static final String BOTTOM_APP_BAR_BACKGROUND_COLOR = "bottomAppBarBackgroundColor";
public static final String PRIMARY_ICON_COLOR = "primaryIconColor"; public static final String PRIMARY_ICON_COLOR = "primaryIconColor";
@ -113,6 +115,8 @@ public class CustomThemeSharedPreferencesUtils {
editor.putInt(BACKGROUND_COLOR, customTheme.backgroundColor); editor.putInt(BACKGROUND_COLOR, customTheme.backgroundColor);
editor.putInt(CARD_VIEW_BACKGROUND_COLOR, customTheme.cardViewBackgroundColor); editor.putInt(CARD_VIEW_BACKGROUND_COLOR, customTheme.cardViewBackgroundColor);
editor.putInt(READ_POST_CARD_VIEW_BACKGROUND_COLOR, customTheme.readPostCardViewBackgroundColor); editor.putInt(READ_POST_CARD_VIEW_BACKGROUND_COLOR, customTheme.readPostCardViewBackgroundColor);
editor.putInt(FILLED_CARD_VIEW_BACKGROUND_COLOR, customTheme.filledCardViewBackgroundColor);
editor.putInt(READ_POST_FILLED_CARD_VIEW_BACKGROUND_COLOR, customTheme.readPostFilledCardViewBackgroundColor);
editor.putInt(COMMENT_BACKGROUND_COLOR, customTheme.commentBackgroundColor); editor.putInt(COMMENT_BACKGROUND_COLOR, customTheme.commentBackgroundColor);
editor.putInt(BOTTOM_APP_BAR_BACKGROUND_COLOR, customTheme.bottomAppBarBackgroundColor); editor.putInt(BOTTOM_APP_BAR_BACKGROUND_COLOR, customTheme.bottomAppBarBackgroundColor);
editor.putInt(PRIMARY_ICON_COLOR, customTheme.primaryIconColor); editor.putInt(PRIMARY_ICON_COLOR, customTheme.primaryIconColor);

View File

@ -93,6 +93,7 @@ public class MaterialYouUtils {
lightTheme.colorPrimaryLightTheme = lightTheme.colorPrimary; lightTheme.colorPrimaryLightTheme = lightTheme.colorPrimary;
lightTheme.backgroundColor = context.getColor(android.R.color.system_neutral1_50); lightTheme.backgroundColor = context.getColor(android.R.color.system_neutral1_50);
lightTheme.cardViewBackgroundColor = context.getColor(android.R.color.system_neutral2_10); lightTheme.cardViewBackgroundColor = context.getColor(android.R.color.system_neutral2_10);
lightTheme.filledCardViewBackgroundColor = lightTheme.cardViewBackgroundColor;
lightTheme.commentBackgroundColor = context.getColor(android.R.color.system_neutral2_10); lightTheme.commentBackgroundColor = context.getColor(android.R.color.system_neutral2_10);
lightTheme.awardedCommentBackgroundColor = context.getColor(android.R.color.system_neutral2_10); lightTheme.awardedCommentBackgroundColor = context.getColor(android.R.color.system_neutral2_10);
lightTheme.bottomAppBarBackgroundColor = lightTheme.colorPrimary; lightTheme.bottomAppBarBackgroundColor = lightTheme.colorPrimary;
@ -123,6 +124,7 @@ public class MaterialYouUtils {
darkTheme.colorPrimaryLightTheme = lightTheme.colorPrimary; darkTheme.colorPrimaryLightTheme = lightTheme.colorPrimary;
darkTheme.backgroundColor = context.getColor(android.R.color.system_neutral1_900); darkTheme.backgroundColor = context.getColor(android.R.color.system_neutral1_900);
darkTheme.cardViewBackgroundColor = context.getColor(android.R.color.system_neutral2_800); darkTheme.cardViewBackgroundColor = context.getColor(android.R.color.system_neutral2_800);
darkTheme.filledCardViewBackgroundColor = darkTheme.cardViewBackgroundColor;
darkTheme.commentBackgroundColor = darkTheme.cardViewBackgroundColor; darkTheme.commentBackgroundColor = darkTheme.cardViewBackgroundColor;
darkTheme.awardedCommentBackgroundColor = darkTheme.cardViewBackgroundColor; darkTheme.awardedCommentBackgroundColor = darkTheme.cardViewBackgroundColor;
darkTheme.bottomAppBarBackgroundColor = darkTheme.colorPrimary; darkTheme.bottomAppBarBackgroundColor = darkTheme.colorPrimary;
@ -189,6 +191,7 @@ public class MaterialYouUtils {
lightTheme.colorPrimaryLightTheme = colorPrimaryInt; lightTheme.colorPrimaryLightTheme = colorPrimaryInt;
lightTheme.backgroundColor = backgroundColor; lightTheme.backgroundColor = backgroundColor;
lightTheme.cardViewBackgroundColor = cardViewBackgroundColor; lightTheme.cardViewBackgroundColor = cardViewBackgroundColor;
lightTheme.filledCardViewBackgroundColor = cardViewBackgroundColor;
lightTheme.commentBackgroundColor = cardViewBackgroundColor; lightTheme.commentBackgroundColor = cardViewBackgroundColor;
lightTheme.awardedCommentBackgroundColor = cardViewBackgroundColor; lightTheme.awardedCommentBackgroundColor = cardViewBackgroundColor;
lightTheme.bottomAppBarBackgroundColor = colorPrimaryInt; lightTheme.bottomAppBarBackgroundColor = colorPrimaryInt;

View File

@ -89,6 +89,7 @@ public class SharedPreferencesUtils {
public static final int POST_LAYOUT_COMPACT = 1; public static final int POST_LAYOUT_COMPACT = 1;
public static final int POST_LAYOUT_GALLERY = 2; public static final int POST_LAYOUT_GALLERY = 2;
public static final int POST_LAYOUT_CARD_2 = 3; public static final int POST_LAYOUT_CARD_2 = 3;
public static final int POST_LAYOUT_CARD_3 = 4;
public static final String FRONT_PAGE_SCROLLED_POSITION_SHARED_PREFERENCES_FILE = "eu.toldi.infinityforlemmy.front_page_scrolled_position"; public static final String FRONT_PAGE_SCROLLED_POSITION_SHARED_PREFERENCES_FILE = "eu.toldi.infinityforlemmy.front_page_scrolled_position";
public static final String FRONT_PAGE_SCROLLED_POSITION_FRONT_PAGE_BASE = "_front_page"; public static final String FRONT_PAGE_SCROLLED_POSITION_FRONT_PAGE_BASE = "_front_page";
@ -233,6 +234,8 @@ public class SharedPreferencesUtils {
public static final String EASIER_TO_WATCH_IN_FULL_SCREEN = "easier_to_watch_in_full_screen"; public static final String EASIER_TO_WATCH_IN_FULL_SCREEN = "easier_to_watch_in_full_screen";
public static final String HIDE_THE_NUMBER_OF_VOTES_IN_COMMENTS = "hide_the_number_of_votes_in_comments"; public static final String HIDE_THE_NUMBER_OF_VOTES_IN_COMMENTS = "hide_the_number_of_votes_in_comments";
public static final String COMMENT_DIVIDER_TYPE = "comment_divider_type"; public static final String COMMENT_DIVIDER_TYPE = "comment_divider_type";
public static final String SUBSCRIBED_THINGS_SYNC_TIME = "subscribed_things_sync_time";
public static final String COMMENT_FILTER = "comment_filter";
public static final String DEFAULT_PREFERENCES_FILE = "eu.toldi.infinityforlemmy_preferences"; public static final String DEFAULT_PREFERENCES_FILE = "eu.toldi.infinityforlemmy_preferences";
public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "eu.toldi.infinityforlemmy.main_page_tabs"; public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "eu.toldi.infinityforlemmy.main_page_tabs";
@ -387,7 +390,7 @@ public class SharedPreferencesUtils {
public static final String INTERNAL_SHARED_PREFERENCES_FILE = "eu.toldi.infinityforlemmy.internal"; public static final String INTERNAL_SHARED_PREFERENCES_FILE = "eu.toldi.infinityforlemmy.internal";
public static final String HAS_REQUESTED_NOTIFICATION_PERMISSION = "has_requested_notification_permission"; public static final String HAS_REQUESTED_NOTIFICATION_PERMISSION = "has_requested_notification_permission";
public static final String DO_NOT_SHOW_REDDIT_API_INFO_AGAIN = "do_not_show_reddit_api_info_again"; public static final String DO_NOT_SHOW_REDDIT_API_INFO_V2_AGAIN = "do_not_show_reddit_api_info_v2_again";
//Legacy Settings //Legacy Settings
public static final String MAIN_PAGE_TAB_1_TITLE_LEGACY = "main_page_tab_1_title"; public static final String MAIN_PAGE_TAB_1_TITLE_LEGACY = "main_page_tab_1_title";

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#000000"
android:endColor="@android:color/transparent"
android:angle="90"
android:type="linear"
android:useLevel="true" />
</shape>

View File

@ -0,0 +1,11 @@
<vector android:autoMirrored="true"
android:height="24dp"
android:tint="#FFFFFF"
android:viewportHeight="24"
android:viewportWidth="24"
android:width="24dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<path
android:fillColor="@android:color/white"
android:pathData="M19,11H7.83l4.88,-4.88c0.39,-0.39 0.39,-1.03 0,-1.42 -0.39,-0.39 -1.02,-0.39 -1.41,0l-6.59,6.59c-0.39,0.39 -0.39,1.02 0,1.41l6.59,6.59c0.39,0.39 1.02,0.39 1.41,0 0.39,-0.39 0.39,-1.02 0,-1.41L7.83,13H19c0.55,0 1,-0.45 1,-1s-0.45,-1 -1,-1z" />
</vector>

View File

@ -0,0 +1,10 @@
<vector android:height="24dp"
android:tint="#000000"
android:viewportHeight="24"
android:viewportWidth="24"
android:width="24dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<path
android:fillColor="@android:color/white"
android:pathData="M15,16h4v2h-4zM15,8h7v2h-7zM15,12h6v2h-6zM3,18c0,1.1 0.9,2 2,2h6c1.1,0 2,-0.9 2,-2L13,8L3,8v10zM5,10h6v8L5,18v-8zM10,4L6,4L5,5L2,5v2h12L14,5h-3z" />
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="#FF000000"
android:pathData="M640,160l-0,280L756,440q26,-0 36.5,22.5T787,505l-276,337q-12,15 -31,15t-31,-15l-276,-337q-16,-20 -5.5,-42.5T204,440L320,440l-0,-280q-0,-17 11.5,-28.5T360,120L600,120q17,-0 28.5,11.5T640,160ZM560,200l-160,-0l-0,320l-111,-0L480,754 671,520l-111,-0l-0,-320ZM480,520Z" />
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="#FF000000"
android:pathData="M640,160l-0,280L756,440q26,-0 36.5,22.5T787,505l-276,337q-12,15 -31,15t-31,-15l-276,-337q-16,-20 -5.5,-42.5T204,440L320,440l-0,-280q-0,-17 11.5,-28.5T360,120L600,120q17,-0 28.5,11.5T640,160Z" />
</vector>

View File

@ -0,0 +1,10 @@
<vector android:height="24dp"
android:tint="#FFFFFF"
android:viewportHeight="24"
android:viewportWidth="24"
android:width="24dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<path
android:fillColor="@android:color/white"
android:pathData="M5.58,16.89l5.77,-4.07c0.56,-0.4 0.56,-1.24 0,-1.63L5.58,7.11C4.91,6.65 4,7.12 4,7.93v8.14c0,0.81 0.91,1.28 1.58,0.82zM13,7.93v8.14c0,0.81 0.91,1.28 1.58,0.82l5.77,-4.07c0.56,-0.4 0.56,-1.24 0,-1.63l-5.77,-4.07c-0.67,-0.47 -1.58,0 -1.58,0.81z" />
</vector>

View File

@ -0,0 +1,10 @@
<vector android:height="24dp"
android:tint="#FFFFFF"
android:viewportHeight="24"
android:viewportWidth="24"
android:width="24dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<path
android:fillColor="@android:color/white"
android:pathData="M11,16.07L11,7.93c0,-0.81 -0.91,-1.28 -1.58,-0.82l-5.77,4.07c-0.56,0.4 -0.56,1.24 0,1.63l5.77,4.07c0.67,0.47 1.58,0 1.58,-0.81zM12.66,12.82l5.77,4.07c0.66,0.47 1.58,-0.01 1.58,-0.82L20.01,7.93c0,-0.81 -0.91,-1.28 -1.58,-0.82l-5.77,4.07c-0.57,0.4 -0.57,1.24 0,1.64z" />
</vector>

View File

@ -1,5 +1,10 @@
<vector android:height="24dp" <vector android:height="24dp"
android:viewportHeight="24.0" android:viewportWidth="24.0" android:tint="#FFFFFF"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> android:viewportHeight="24"
<path android:fillColor="#FFFFFFFF" android:pathData="M19,9h-4V3H9v6H5l7,7 7,-7zM5,18v2h14v-2H5z"/> android:viewportWidth="24"
android:width="24dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<path
android:fillColor="@android:color/white"
android:pathData="M16.59,9H15V4c0,-0.55 -0.45,-1 -1,-1h-4c-0.55,0 -1,0.45 -1,1v5H7.41c-0.89,0 -1.34,1.08 -0.71,1.71l4.59,4.59c0.39,0.39 1.02,0.39 1.41,0l4.59,-4.59c0.63,-0.63 0.19,-1.71 -0.7,-1.71zM5,19c0,0.55 0.45,1 1,1h12c0.55,0 1,-0.45 1,-1s-0.45,-1 -1,-1H6c-0.55,0 -1,0.45 -1,1z" />
</vector> </vector>

View File

@ -4,6 +4,6 @@
android:viewportWidth="24" android:viewportWidth="24"
android:viewportHeight="24"> android:viewportHeight="24">
<path <path
android:fillColor="#FFFFFFFF" android:fillColor="@android:color/white"
android:pathData="M4.34,2.93L2.93,4.34 7.29,8.7 7,9L3,9v6h4l5,5v-6.59l4.18,4.18c-0.65,0.49 -1.38,0.88 -2.18,1.11v2.06c1.34,-0.3 2.57,-0.92 3.61,-1.75l2.05,2.05 1.41,-1.41L4.34,2.93zM10,15.17L7.83,13L5,13v-2h2.83l0.88,-0.88L10,11.41v3.76zM19,12c0,0.82 -0.15,1.61 -0.41,2.34l1.53,1.53c0.56,-1.17 0.88,-2.48 0.88,-3.87 0,-4.28 -2.99,-7.86 -7,-8.77v2.06c2.89,0.86 5,3.54 5,6.71zM12,4l-1.88,1.88L12,7.76zM16.5,12c0,-1.77 -1.02,-3.29 -2.5,-4.03v1.79l2.48,2.48c0.01,-0.08 0.02,-0.16 0.02,-0.24z"/> android:pathData="M3.63,3.63c-0.39,0.39 -0.39,1.02 0,1.41L7.29,8.7 7,9L4,9c-0.55,0 -1,0.45 -1,1v4c0,0.55 0.45,1 1,1h3l3.29,3.29c0.63,0.63 1.71,0.18 1.71,-0.71v-4.17l4.18,4.18c-0.49,0.37 -1.02,0.68 -1.6,0.91 -0.36,0.15 -0.58,0.53 -0.58,0.92 0,0.72 0.73,1.18 1.39,0.91 0.8,-0.33 1.55,-0.77 2.22,-1.31l1.34,1.34c0.39,0.39 1.02,0.39 1.41,0 0.39,-0.39 0.39,-1.02 0,-1.41L5.05,3.63c-0.39,-0.39 -1.02,-0.39 -1.42,0zM19,12c0,0.82 -0.15,1.61 -0.41,2.34l1.53,1.53c0.56,-1.17 0.88,-2.48 0.88,-3.87 0,-3.83 -2.4,-7.11 -5.78,-8.4 -0.59,-0.23 -1.22,0.23 -1.22,0.86v0.19c0,0.38 0.25,0.71 0.61,0.85C17.18,6.54 19,9.06 19,12zM10.29,5.71l-0.17,0.17L12,7.76L12,6.41c0,-0.89 -1.08,-1.33 -1.71,-0.7zM16.5,12c0,-1.77 -1.02,-3.29 -2.5,-4.03v1.79l2.48,2.48c0.01,-0.08 0.02,-0.16 0.02,-0.24z" />
</vector> </vector>

View File

@ -1,9 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M3.63,3.63c-0.39,0.39 -0.39,1.02 0,1.41L7.29,8.7 7,9L4,9c-0.55,0 -1,0.45 -1,1v4c0,0.55 0.45,1 1,1h3l3.29,3.29c0.63,0.63 1.71,0.18 1.71,-0.71v-4.17l4.18,4.18c-0.49,0.37 -1.02,0.68 -1.6,0.91 -0.36,0.15 -0.58,0.53 -0.58,0.92 0,0.72 0.73,1.18 1.39,0.91 0.8,-0.33 1.55,-0.77 2.22,-1.31l1.34,1.34c0.39,0.39 1.02,0.39 1.41,0 0.39,-0.39 0.39,-1.02 0,-1.41L5.05,3.63c-0.39,-0.39 -1.02,-0.39 -1.42,0zM19,12c0,0.82 -0.15,1.61 -0.41,2.34l1.53,1.53c0.56,-1.17 0.88,-2.48 0.88,-3.87 0,-3.83 -2.4,-7.11 -5.78,-8.4 -0.59,-0.23 -1.22,0.23 -1.22,0.86v0.19c0,0.38 0.25,0.71 0.61,0.85C17.18,6.54 19,9.06 19,12zM10.29,5.71l-0.17,0.17L12,7.76L12,6.41c0,-0.89 -1.08,-1.33 -1.71,-0.7zM16.5,12c0,-1.77 -1.02,-3.29 -2.5,-4.03v1.79l2.48,2.48c0.01,-0.08 0.02,-0.16 0.02,-0.24z"/>
</vector>

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