mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-30 12:57:12 +01:00
Add an option to filter subreddits in popular and all.
This commit is contained in:
parent
e1b0b568ec
commit
84e4dd09c3
@ -32,7 +32,13 @@
|
||||
android:theme="@style/AppTheme"
|
||||
android:usesCleartextTraffic="true"
|
||||
tools:replace="android:label">
|
||||
<activity android:name=".Activity.FetchRandomSubredditOrPostActivity"
|
||||
<activity android:name=".Activity.SubredditFilterPopularAndAllActivity"
|
||||
android:label="@string/subreddit_filter_popular_and_all_activity_label"
|
||||
android:parentActivityName=".Activity.SettingsActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:windowSoftInputMode="adjustResize" />
|
||||
<activity
|
||||
android:name=".Activity.FetchRandomSubredditOrPostActivity"
|
||||
android:parentActivityName=".Activity.MainActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar" />
|
||||
<activity
|
||||
|
@ -0,0 +1,155 @@
|
||||
package ml.docilealligator.infinityforreddit.Activity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.appbar.AppBarLayout;
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import ml.docilealligator.infinityforreddit.Adapter.SubredditFilterRecyclerViewAdapter;
|
||||
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
|
||||
import ml.docilealligator.infinityforreddit.Infinity;
|
||||
import ml.docilealligator.infinityforreddit.R;
|
||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||
import ml.docilealligator.infinityforreddit.SubredditFilter.DeleteSubredditFilter;
|
||||
import ml.docilealligator.infinityforreddit.SubredditFilter.InsertSubredditFilter;
|
||||
import ml.docilealligator.infinityforreddit.SubredditFilter.SubredditFilter;
|
||||
import ml.docilealligator.infinityforreddit.SubredditFilter.SubredditFilterViewModel;
|
||||
|
||||
public class SubredditFilterPopularAndAllActivity extends BaseActivity {
|
||||
|
||||
@BindView(R.id.coordinator_layout_subreddit_filter_popular_and_all_activity)
|
||||
CoordinatorLayout coordinatorLayout;
|
||||
@BindView(R.id.appbar_layout_subreddit_filter_popular_and_all_activity)
|
||||
AppBarLayout appBarLayout;
|
||||
@BindView(R.id.toolbar_subreddit_filter_popular_and_all_activity)
|
||||
Toolbar toolbar;
|
||||
@BindView(R.id.recycler_view_subreddit_filter_popular_and_all_activity)
|
||||
RecyclerView recyclerView;
|
||||
@BindView(R.id.fab_subreddit_filter_popular_and_all_activity)
|
||||
FloatingActionButton fab;
|
||||
@Inject
|
||||
@Named("default")
|
||||
SharedPreferences sharedPreferences;
|
||||
@Inject
|
||||
RedditDataRoomDatabase redditDataRoomDatabase;
|
||||
@Inject
|
||||
CustomThemeWrapper customThemeWrapper;
|
||||
SubredditFilterViewModel subredditFilterViewModel;
|
||||
private SubredditFilterRecyclerViewAdapter adapter;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
((Infinity) getApplication()).getAppComponent().inject(this);
|
||||
|
||||
setImmersiveModeNotApplicable();
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_subreddit_filter_popular_and_all);
|
||||
|
||||
ButterKnife.bind(this);
|
||||
|
||||
applyCustomTheme();
|
||||
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
adapter = new SubredditFilterRecyclerViewAdapter(subredditFilter -> DeleteSubredditFilter.deleteSubredditFilter(redditDataRoomDatabase, subredditFilter, () -> {}));
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
recyclerView.setAdapter(adapter);
|
||||
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
||||
if (dy > 0) {
|
||||
fab.hide();
|
||||
} else if (dy < 0) {
|
||||
fab.show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
subredditFilterViewModel = new ViewModelProvider(this,
|
||||
new SubredditFilterViewModel.Factory(redditDataRoomDatabase))
|
||||
.get(SubredditFilterViewModel.class);
|
||||
subredditFilterViewModel.getSubredditFilterLiveData().observe(this, subredditFilters -> adapter.updateSubredditsName(subredditFilters));
|
||||
|
||||
fab.setOnClickListener(view -> {
|
||||
EditText thingEditText = (EditText) getLayoutInflater().inflate(R.layout.dialog_go_to_thing_edit_text, null);
|
||||
thingEditText.requestFocus();
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
if (imm != null) {
|
||||
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
|
||||
}
|
||||
new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
|
||||
.setTitle(R.string.choose_a_subreddit)
|
||||
.setView(thingEditText)
|
||||
.setPositiveButton(R.string.ok, (dialogInterface, i)
|
||||
-> {
|
||||
if (imm != null) {
|
||||
imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0);
|
||||
}
|
||||
SubredditFilter subredditFilter = new SubredditFilter(thingEditText.getText().toString(), SubredditFilter.TYPE_POPULAR_AND_ALL);
|
||||
InsertSubredditFilter.insertSubredditFilter(redditDataRoomDatabase, subredditFilter,
|
||||
() -> {});
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.setNeutralButton(R.string.search, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
if (imm != null) {
|
||||
imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0);
|
||||
}
|
||||
}
|
||||
})
|
||||
.setOnDismissListener(dialogInterface -> {
|
||||
if (imm != null) {
|
||||
imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0);
|
||||
}
|
||||
})
|
||||
.show();
|
||||
});
|
||||
}
|
||||
|
||||
@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() {
|
||||
applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package ml.docilealligator.infinityforreddit.Adapter;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import ml.docilealligator.infinityforreddit.R;
|
||||
import ml.docilealligator.infinityforreddit.SubredditFilter.SubredditFilter;
|
||||
|
||||
public class SubredditFilterRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
private List<SubredditFilter> subredditFilters;
|
||||
private ItemClickListener itemClickListener;
|
||||
|
||||
public SubredditFilterRecyclerViewAdapter(ItemClickListener itemClickListener) {
|
||||
this.itemClickListener = itemClickListener;
|
||||
}
|
||||
|
||||
public interface ItemClickListener {
|
||||
void onItemDelete(SubredditFilter subredditFilter);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
return new SubredditNameViewHolder(LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.item_selected_subreddit, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||
if (holder instanceof SubredditNameViewHolder) {
|
||||
((SubredditNameViewHolder) holder).subredditRedditNameTextView.setText(subredditFilters.get(position).getSubredditName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return subredditFilters == null ? 0 : subredditFilters.size();
|
||||
}
|
||||
|
||||
public void updateSubredditsName(List<SubredditFilter> subredditFilters) {
|
||||
this.subredditFilters = subredditFilters;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
class SubredditNameViewHolder extends RecyclerView.ViewHolder {
|
||||
@BindView(R.id.subreddit_name_item_selected_subreddit)
|
||||
TextView subredditRedditNameTextView;
|
||||
@BindView(R.id.delete_image_view_item_selected_subreddit)
|
||||
ImageView deleteImageView;
|
||||
|
||||
public SubredditNameViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
|
||||
ButterKnife.bind(this, itemView);
|
||||
|
||||
deleteImageView.setOnClickListener(view -> {
|
||||
itemClickListener.onItemDelete(subredditFilters.get(getAdapterPosition()));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -35,6 +35,7 @@ import ml.docilealligator.infinityforreddit.Activity.SelectedSubredditsActivity;
|
||||
import ml.docilealligator.infinityforreddit.Activity.SendPrivateMessageActivity;
|
||||
import ml.docilealligator.infinityforreddit.Activity.SettingsActivity;
|
||||
import ml.docilealligator.infinityforreddit.Activity.SubmitCrosspostActivity;
|
||||
import ml.docilealligator.infinityforreddit.Activity.SubredditFilterPopularAndAllActivity;
|
||||
import ml.docilealligator.infinityforreddit.Activity.SubredditMultiselectionActivity;
|
||||
import ml.docilealligator.infinityforreddit.Activity.SubredditSelectionActivity;
|
||||
import ml.docilealligator.infinityforreddit.Activity.SubscribedThingListingActivity;
|
||||
@ -224,4 +225,6 @@ public interface AppComponent {
|
||||
void inject(FetchRandomSubredditOrPostActivity fetchRandomSubredditOrPostActivity);
|
||||
|
||||
void inject(MiscellaneousPreferenceFragment miscellaneousPreferenceFragment);
|
||||
|
||||
void inject(SubredditFilterPopularAndAllActivity subredditFilterPopularAndAllActivity);
|
||||
}
|
||||
|
@ -20,6 +20,8 @@ import ml.docilealligator.infinityforreddit.RecentSearchQuery.RecentSearchQuery;
|
||||
import ml.docilealligator.infinityforreddit.RecentSearchQuery.RecentSearchQueryDao;
|
||||
import ml.docilealligator.infinityforreddit.Subreddit.SubredditDao;
|
||||
import ml.docilealligator.infinityforreddit.Subreddit.SubredditData;
|
||||
import ml.docilealligator.infinityforreddit.SubredditFilter.SubredditFilter;
|
||||
import ml.docilealligator.infinityforreddit.SubredditFilter.SubredditFilterDao;
|
||||
import ml.docilealligator.infinityforreddit.SubscribedSubreddit.SubscribedSubredditDao;
|
||||
import ml.docilealligator.infinityforreddit.SubscribedSubreddit.SubscribedSubredditData;
|
||||
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserDao;
|
||||
@ -28,7 +30,7 @@ import ml.docilealligator.infinityforreddit.User.UserDao;
|
||||
import ml.docilealligator.infinityforreddit.User.UserData;
|
||||
|
||||
@Database(entities = {Account.class, SubredditData.class, SubscribedSubredditData.class, UserData.class,
|
||||
SubscribedUserData.class, MultiReddit.class, CustomTheme.class, RecentSearchQuery.class}, version = 11)
|
||||
SubscribedUserData.class, MultiReddit.class, CustomTheme.class, RecentSearchQuery.class, SubredditFilter.class}, version = 12)
|
||||
public abstract class RedditDataRoomDatabase extends RoomDatabase {
|
||||
private static RedditDataRoomDatabase INSTANCE;
|
||||
|
||||
@ -40,7 +42,7 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
|
||||
RedditDataRoomDatabase.class, "reddit_data")
|
||||
.addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5,
|
||||
MIGRATION_5_6, MIGRATION_6_7, MIGRATION_7_8, MIGRATION_8_9,
|
||||
MIGRATION_9_10, MIGRATION_10_11)
|
||||
MIGRATION_9_10, MIGRATION_10_11, MIGRATION_11_12)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@ -64,6 +66,8 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
|
||||
|
||||
public abstract RecentSearchQueryDao recentSearchQueryDao();
|
||||
|
||||
public abstract SubredditFilterDao subredditFilterDao();
|
||||
|
||||
private static final Migration MIGRATION_1_2 = new Migration(1, 2) {
|
||||
@Override
|
||||
public void migrate(SupportSQLiteDatabase database) {
|
||||
@ -243,4 +247,12 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
|
||||
+ " ADD COLUMN over_18 INTEGER DEFAULT 0 NOT NULL");
|
||||
}
|
||||
};
|
||||
|
||||
private static final Migration MIGRATION_11_12 = new Migration(11, 12) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||
database.execSQL("CREATE TABLE subreddit_filter" +
|
||||
"(subreddit_name TEXT NOT NULL, type INTEGER NOT NULL, PRIMARY KEY(subreddit_name, type))");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
package ml.docilealligator.infinityforreddit.Settings;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
|
||||
import ml.docilealligator.infinityforreddit.Activity.SubredditFilterPopularAndAllActivity;
|
||||
import ml.docilealligator.infinityforreddit.R;
|
||||
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
|
||||
|
||||
public class FilterPreferenceFragment extends PreferenceFragmentCompat {
|
||||
|
||||
private Activity activity;
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
setPreferencesFromResource(R.xml.filter_preferences, rootKey);
|
||||
|
||||
Preference subredditFilterPopularAndAllPreference = findPreference(SharedPreferencesUtils.SUBREDDIT_FILTER_POPULAR_AND_ALL);
|
||||
|
||||
subredditFilterPopularAndAllPreference.setOnPreferenceClickListener(preference -> {
|
||||
Intent intent = new Intent(activity, SubredditFilterPopularAndAllActivity.class);
|
||||
activity.startActivity(intent);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(@NonNull Context context) {
|
||||
super.onAttach(context);
|
||||
activity = (Activity) context;
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package ml.docilealligator.infinityforreddit.SubredditFilter;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||
|
||||
public class DeleteSubredditFilter {
|
||||
public interface DeleteSubredditFilterListener {
|
||||
void success();
|
||||
}
|
||||
|
||||
public static void deleteSubredditFilter(RedditDataRoomDatabase redditDataRoomDatabase, SubredditFilter subredditFilter,
|
||||
DeleteSubredditFilterListener deleteSubredditFilterListener) {
|
||||
new DeleteSubredditFilterAsyncTask(redditDataRoomDatabase, subredditFilter, deleteSubredditFilterListener).execute();
|
||||
}
|
||||
|
||||
private static class DeleteSubredditFilterAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
private RedditDataRoomDatabase redditDataRoomDatabase;
|
||||
private SubredditFilter subredditFilter;
|
||||
private DeleteSubredditFilterListener deleteSubredditFilterListener;
|
||||
|
||||
DeleteSubredditFilterAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, SubredditFilter subredditFilter,
|
||||
DeleteSubredditFilterListener deleteSubredditFilterListener) {
|
||||
this.redditDataRoomDatabase = redditDataRoomDatabase;
|
||||
this.subredditFilter = subredditFilter;
|
||||
this.deleteSubredditFilterListener = deleteSubredditFilterListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
redditDataRoomDatabase.subredditFilterDao().deleteSubredditFilter(subredditFilter);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid) {
|
||||
super.onPostExecute(aVoid);
|
||||
deleteSubredditFilterListener.success();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package ml.docilealligator.infinityforreddit.SubredditFilter;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||
|
||||
public class InsertSubredditFilter {
|
||||
public interface InsertSubredditFilterListener {
|
||||
void success();
|
||||
}
|
||||
|
||||
public static void insertSubredditFilter(RedditDataRoomDatabase redditDataRoomDatabase, SubredditFilter subredditFilter,
|
||||
InsertSubredditFilterListener insertSubredditFilterListener) {
|
||||
new InsertSubredditFilterAsyncTask(redditDataRoomDatabase, subredditFilter, insertSubredditFilterListener).execute();
|
||||
}
|
||||
|
||||
private static class InsertSubredditFilterAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
private RedditDataRoomDatabase redditDataRoomDatabase;
|
||||
private SubredditFilter subredditFilter;
|
||||
private InsertSubredditFilterListener insertSubredditFilterListener;
|
||||
|
||||
InsertSubredditFilterAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, SubredditFilter subredditFilter,
|
||||
InsertSubredditFilterListener insertSubredditFilterListener) {
|
||||
this.redditDataRoomDatabase = redditDataRoomDatabase;
|
||||
this.subredditFilter = subredditFilter;
|
||||
this.insertSubredditFilterListener = insertSubredditFilterListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
redditDataRoomDatabase.subredditFilterDao().insert(subredditFilter);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid) {
|
||||
super.onPostExecute(aVoid);
|
||||
insertSubredditFilterListener.success();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package ml.docilealligator.infinityforreddit.SubredditFilter;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.room.ColumnInfo;
|
||||
import androidx.room.Entity;
|
||||
|
||||
@Entity(tableName = "subreddit_filter", primaryKeys = {"subreddit_name", "type"})
|
||||
public class SubredditFilter {
|
||||
public static int TYPE_POPULAR_AND_ALL = 0;
|
||||
@NonNull
|
||||
@ColumnInfo(name = "subreddit_name")
|
||||
private String subredditName;
|
||||
@ColumnInfo(name = "type")
|
||||
private int type;
|
||||
|
||||
public SubredditFilter(@NonNull String subredditName, int type) {
|
||||
this.subredditName = subredditName;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getSubredditName() {
|
||||
return subredditName;
|
||||
}
|
||||
|
||||
public void setSubredditName(@NonNull String subredditName) {
|
||||
this.subredditName = subredditName;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package ml.docilealligator.infinityforreddit.SubredditFilter;
|
||||
|
||||
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 SubredditFilterDao {
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
void insert(SubredditFilter subredditFilter);
|
||||
|
||||
@Query("SELECT * FROM subreddit_filter")
|
||||
LiveData<List<SubredditFilter>> getAllSubredditFiltersLiveData();
|
||||
|
||||
@Query("SELECT * FROM subreddit_filter")
|
||||
List<SubredditFilter> getAllSubredditFilters();
|
||||
|
||||
@Delete
|
||||
void deleteSubredditFilter(SubredditFilter subredditFilter);
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package ml.docilealligator.infinityforreddit.SubredditFilter;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||
|
||||
public class SubredditFilterViewModel extends ViewModel {
|
||||
private LiveData<List<SubredditFilter>> subredditFilterLiveData;
|
||||
|
||||
public SubredditFilterViewModel(RedditDataRoomDatabase redditDataRoomDatabase) {
|
||||
subredditFilterLiveData = redditDataRoomDatabase.subredditFilterDao().getAllSubredditFiltersLiveData();
|
||||
}
|
||||
|
||||
public LiveData<List<SubredditFilter>> getSubredditFilterLiveData() {
|
||||
return subredditFilterLiveData;
|
||||
}
|
||||
|
||||
public static class Factory extends ViewModelProvider.NewInstanceFactory {
|
||||
private RedditDataRoomDatabase redditDataRoomDatabase;
|
||||
|
||||
public Factory(RedditDataRoomDatabase redditDataRoomDatabase) {
|
||||
this.redditDataRoomDatabase = redditDataRoomDatabase;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
||||
return (T) new SubredditFilterViewModel(redditDataRoomDatabase);
|
||||
}
|
||||
}
|
||||
}
|
@ -136,6 +136,7 @@ public class SharedPreferencesUtils {
|
||||
public static final String DATA_SAVING_MODE_ALWAYS = "2";
|
||||
public static final String NATIONAL_FLAGS = "national_flags";
|
||||
public static final String RESPECT_SUBREDDIT_RECOMMENDED_COMMENT_SORT_TYPE = "respect_subreddit_recommended_comment_sort_type";
|
||||
public static final String SUBREDDIT_FILTER_POPULAR_AND_ALL = "subreddit_filter_popular_and_all";
|
||||
|
||||
public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs";
|
||||
public static final String MAIN_PAGE_TAB_COUNT = "_main_page_tab_count";
|
||||
|
9
app/src/main/res/drawable-night/ic_filter_24dp.xml
Normal file
9
app/src/main/res/drawable-night/ic_filter_24dp.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<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="#FFFFFF"
|
||||
android:pathData="M7,6h10l-5.01,6.3L7,6zM4.25,5.61C6.27,8.2 10,13 10,13v6c0,0.55 0.45,1 1,1h2c0.55,0 1,-0.45 1,-1v-6c0,0 3.72,-4.8 5.74,-7.39C20.25,4.95 19.78,4 18.95,4H5.04C4.21,4 3.74,4.95 4.25,5.61z"/>
|
||||
</vector>
|
9
app/src/main/res/drawable/ic_filter_24dp.xml
Normal file
9
app/src/main/res/drawable/ic_filter_24dp.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<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="#000000"
|
||||
android:pathData="M7,6h10l-5.01,6.3L7,6zM4.25,5.61C6.27,8.2 10,13 10,13v6c0,0.55 0.45,1 1,1h2c0.55,0 1,-0.45 1,-1v-6c0,0 3.72,-4.8 5.74,-7.39C20.25,4.95 19.78,4 18.95,4H5.04C4.21,4 3.74,4.95 4.25,5.61z"/>
|
||||
</vector>
|
@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/coordinator_layout_subreddit_filter_popular_and_all_activity"
|
||||
tools:context=".Activity.SubredditFilterPopularAndAllActivity">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/appbar_layout_subreddit_filter_popular_and_all_activity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/AppTheme.AppBarOverlay">
|
||||
|
||||
<com.google.android.material.appbar.CollapsingToolbarLayout
|
||||
android:id="@+id/collapsing_toolbar_layout_subreddit_filter_popular_and_all_activity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_scrollFlags="scroll|enterAlways"
|
||||
app:titleEnabled="false"
|
||||
app:toolbarId="@+id/toolbar_subreddit_filter_popular_and_all_activity">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar_subreddit_filter_popular_and_all_activity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?attr/actionBarSize"
|
||||
app:popupTheme="@style/AppTheme.PopupOverlay"
|
||||
app:navigationIcon="?attr/homeAsUpIndicator" />
|
||||
|
||||
</com.google.android.material.appbar.CollapsingToolbarLayout>
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_view_subreddit_filter_popular_and_all_activity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fab_subreddit_filter_popular_and_all_activity"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:layout_gravity="bottom|end"
|
||||
app:backgroundTint="?attr/colorPrimaryLightTheme"
|
||||
app:srcCompat="@drawable/ic_add_day_night_24dp"
|
||||
app:tint="@android:color/white" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
@ -15,6 +15,7 @@
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:textSize="?attr/font_default"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:fontFamily="?attr/font_family" />
|
||||
|
||||
<ImageView
|
||||
@ -22,6 +23,9 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:src="@drawable/ic_delete_24dp" />
|
||||
android:src="@drawable/ic_delete_24dp"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:background="?attr/selectableItemBackground" />
|
||||
|
||||
</LinearLayout>
|
@ -33,6 +33,7 @@
|
||||
<string name="view_reddit_gallery_activity_video_label">Video %1$d/%2$d</string>
|
||||
<string name="submit_crosspost_activity_label">Crosspost</string>
|
||||
<string name="give_award_activity_label">Give Award</string>
|
||||
<string name="subreddit_filter_popular_and_all_activity_label">r/all and r/popular</string>
|
||||
|
||||
<string name="navigation_drawer_open">Open navigation drawer</string>
|
||||
<string name="navigation_drawer_close">Close navigation drawer</string>
|
||||
@ -497,6 +498,9 @@
|
||||
<string name="settings_miscellaneous_title">Miscellaneous</string>
|
||||
<string name="settings_respect_subreddit_recommended_comment_sort_type_title">Respect Subreddit Recommended Comment Sort Type</string>
|
||||
<string name="settings_respect_subreddit_recommended_comment_sort_type_summary">Comment sort type will not be saved</string>
|
||||
<string name="settings_filter_title">Filter</string>
|
||||
<string name="settings_subreddit_filter_category">Subreddit Filter</string>
|
||||
<string name="settings_subreddit_filter_popular_and_all">r/popular and r/all</string>
|
||||
|
||||
<string name="no_link_available">Cannot get the link</string>
|
||||
|
||||
|
11
app/src/main/res/xml/filter_preferences.xml
Normal file
11
app/src/main/res/xml/filter_preferences.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<PreferenceCategory
|
||||
app:title="@string/settings_subreddit_filter_category" />
|
||||
|
||||
<Preference
|
||||
app:key="subreddit_filter_popular_and_all"
|
||||
app:title="@string/settings_subreddit_filter_popular_and_all" />
|
||||
|
||||
</PreferenceScreen>
|
@ -58,6 +58,11 @@
|
||||
app:title="@string/settings_nsfw_and_spoiler_title"
|
||||
app:fragment="ml.docilealligator.infinityforreddit.Settings.NsfwAndBlurringFragment"/>
|
||||
|
||||
<Preference
|
||||
app:icon="@drawable/ic_filter_24dp"
|
||||
app:title="@string/settings_filter_title"
|
||||
app:fragment="ml.docilealligator.infinityforreddit.Settings.FilterPreferenceFragment"/>
|
||||
|
||||
<Preference
|
||||
app:icon="@drawable/ic_miscellaneous_24dp"
|
||||
app:title="@string/settings_miscellaneous_title"
|
||||
|
Loading…
Reference in New Issue
Block a user