Search in sources :

Example 1 with PostFilter

use of ml.docilealligator.infinityforreddit.postfilter.PostFilter in project Infinity-For-Reddit by Docile-Alligator.

the class PostFilterUsageListingActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    ((Infinity) getApplication()).getAppComponent().inject(this);
    setImmersiveModeNotApplicable();
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_post_filter_application);
    ButterKnife.bind(this);
    applyCustomTheme();
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    postFilter = getIntent().getParcelableExtra(EXTRA_POST_FILTER);
    setTitle(postFilter.name);
    fab.setOnClickListener(view -> {
        NewPostFilterUsageBottomSheetFragment newPostFilterUsageBottomSheetFragment = new NewPostFilterUsageBottomSheetFragment();
        newPostFilterUsageBottomSheetFragment.show(getSupportFragmentManager(), newPostFilterUsageBottomSheetFragment.getTag());
    });
    adapter = new PostFilterUsageRecyclerViewAdapter(this, postFilterUsage -> {
        PostFilterUsageOptionsBottomSheetFragment postFilterUsageOptionsBottomSheetFragment = new PostFilterUsageOptionsBottomSheetFragment();
        Bundle bundle = new Bundle();
        bundle.putParcelable(PostFilterUsageOptionsBottomSheetFragment.EXTRA_POST_FILTER_USAGE, postFilterUsage);
        postFilterUsageOptionsBottomSheetFragment.setArguments(bundle);
        postFilterUsageOptionsBottomSheetFragment.show(getSupportFragmentManager(), postFilterUsageOptionsBottomSheetFragment.getTag());
    });
    recyclerView.setAdapter(adapter);
    postFilterUsageViewModel = new ViewModelProvider(this, new PostFilterUsageViewModel.Factory(redditDataRoomDatabase, postFilter.name)).get(PostFilterUsageViewModel.class);
    postFilterUsageViewModel.getPostFilterUsageListLiveData().observe(this, postFilterUsages -> adapter.setPostFilterUsages(postFilterUsages));
}
Also used : PostFilterUsageRecyclerViewAdapter(ml.docilealligator.infinityforreddit.adapters.PostFilterUsageRecyclerViewAdapter) Context(android.content.Context) TextInputEditText(com.google.android.material.textfield.TextInputEditText) Bundle(android.os.Bundle) PostFilter(ml.docilealligator.infinityforreddit.postfilter.PostFilter) ButterKnife(butterknife.ButterKnife) NonNull(androidx.annotation.NonNull) R(ml.docilealligator.infinityforreddit.R) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) TextInputLayout(com.google.android.material.textfield.TextInputLayout) Infinity(ml.docilealligator.infinityforreddit.Infinity) CustomThemeWrapper(ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper) AppBarLayout(com.google.android.material.appbar.AppBarLayout) PostFilterUsageRecyclerViewAdapter(ml.docilealligator.infinityforreddit.adapters.PostFilterUsageRecyclerViewAdapter) MenuItem(android.view.MenuItem) InputMethodManager(android.view.inputmethod.InputMethodManager) BindView(butterknife.BindView) ColorStateList(android.content.res.ColorStateList) Inject(javax.inject.Inject) PostFilterUsageViewModel(ml.docilealligator.infinityforreddit.postfilter.PostFilterUsageViewModel) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) PostFilterUsage(ml.docilealligator.infinityforreddit.postfilter.PostFilterUsage) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Named(javax.inject.Named) RedditDataRoomDatabase(ml.docilealligator.infinityforreddit.RedditDataRoomDatabase) PostFilterUsageOptionsBottomSheetFragment(ml.docilealligator.infinityforreddit.bottomsheetfragments.PostFilterUsageOptionsBottomSheetFragment) CoordinatorLayout(androidx.coordinatorlayout.widget.CoordinatorLayout) ViewModelProvider(androidx.lifecycle.ViewModelProvider) Executor(java.util.concurrent.Executor) NewPostFilterUsageBottomSheetFragment(ml.docilealligator.infinityforreddit.bottomsheetfragments.NewPostFilterUsageBottomSheetFragment) CollapsingToolbarLayout(com.google.android.material.appbar.CollapsingToolbarLayout) SharedPreferences(android.content.SharedPreferences) DeletePostFilterUsage(ml.docilealligator.infinityforreddit.postfilter.DeletePostFilterUsage) Toolbar(androidx.appcompat.widget.Toolbar) SavePostFilterUsage(ml.docilealligator.infinityforreddit.postfilter.SavePostFilterUsage) Bundle(android.os.Bundle) NewPostFilterUsageBottomSheetFragment(ml.docilealligator.infinityforreddit.bottomsheetfragments.NewPostFilterUsageBottomSheetFragment) PostFilterUsageOptionsBottomSheetFragment(ml.docilealligator.infinityforreddit.bottomsheetfragments.PostFilterUsageOptionsBottomSheetFragment) PostFilterUsageViewModel(ml.docilealligator.infinityforreddit.postfilter.PostFilterUsageViewModel) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 2 with PostFilter

use of ml.docilealligator.infinityforreddit.postfilter.PostFilter in project Infinity-For-Reddit by Docile-Alligator.

the class BackupSettings method backupSettings.

public static void backupSettings(Context context, Executor executor, Handler handler, ContentResolver contentResolver, Uri destinationDirUri, RedditDataRoomDatabase redditDataRoomDatabase, SharedPreferences defaultSharedPreferences, SharedPreferences lightThemeSharedPreferences, SharedPreferences darkThemeSharedPreferences, SharedPreferences amoledThemeSharedPreferences, SharedPreferences sortTypeSharedPreferences, SharedPreferences postLayoutSharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, SharedPreferences mainActivityTabsSharedPreferences, SharedPreferences nsfwAndSpoilerSharedPreferencs, SharedPreferences bottomAppBarSharedPreferences, SharedPreferences postHistorySharedPreferences, BackupSettingsListener backupSettingsListener) {
    executor.execute(() -> {
        String backupDir = context.getExternalCacheDir() + "/Backup/" + BuildConfig.VERSION_NAME;
        File backupDirFile = new File(backupDir);
        if (new File(backupDir).exists()) {
            try {
                FileUtils.deleteDirectory(backupDirFile);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        backupDirFile.mkdirs();
        File databaseDirFile = new File(backupDir + "/database");
        databaseDirFile.mkdirs();
        boolean res = saveSharedPreferencesToFile(defaultSharedPreferences, backupDir, SharedPreferencesUtils.DEFAULT_PREFERENCES_FILE);
        boolean res1 = saveSharedPreferencesToFile(lightThemeSharedPreferences, backupDir, CustomThemeSharedPreferencesUtils.LIGHT_THEME_SHARED_PREFERENCES_FILE);
        boolean res2 = saveSharedPreferencesToFile(darkThemeSharedPreferences, backupDir, CustomThemeSharedPreferencesUtils.DARK_THEME_SHARED_PREFERENCES_FILE);
        boolean res3 = saveSharedPreferencesToFile(amoledThemeSharedPreferences, backupDir, CustomThemeSharedPreferencesUtils.AMOLED_THEME_SHARED_PREFERENCES_FILE);
        boolean res4 = saveSharedPreferencesToFile(sortTypeSharedPreferences, backupDir, SharedPreferencesUtils.SORT_TYPE_SHARED_PREFERENCES_FILE);
        boolean res5 = saveSharedPreferencesToFile(postLayoutSharedPreferences, backupDir, SharedPreferencesUtils.POST_LAYOUT_SHARED_PREFERENCES_FILE);
        boolean res6 = saveSharedPreferencesToFile(postFeedScrolledPositionSharedPreferences, backupDir, SharedPreferencesUtils.FRONT_PAGE_SCROLLED_POSITION_SHARED_PREFERENCES_FILE);
        boolean res7 = saveSharedPreferencesToFile(mainActivityTabsSharedPreferences, backupDir, SharedPreferencesUtils.MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE);
        boolean res8 = saveSharedPreferencesToFile(nsfwAndSpoilerSharedPreferencs, backupDir, SharedPreferencesUtils.NSFW_AND_SPOILER_SHARED_PREFERENCES_FILE);
        boolean res9 = saveSharedPreferencesToFile(bottomAppBarSharedPreferences, backupDir, SharedPreferencesUtils.BOTTOM_APP_BAR_SHARED_PREFERENCES_FILE);
        boolean res10 = saveSharedPreferencesToFile(postHistorySharedPreferences, backupDir, SharedPreferencesUtils.POST_HISTORY_SHARED_PREFERENCES_FILE);
        List<SubscribedSubredditData> anonymousSubscribedSubredditsData = redditDataRoomDatabase.subscribedSubredditDao().getAllSubscribedSubredditsList("-");
        String anonymousSubscribedSubredditsDataJson = new Gson().toJson(anonymousSubscribedSubredditsData);
        boolean res11 = saveDatabaseTableToFile(anonymousSubscribedSubredditsDataJson, databaseDirFile.getAbsolutePath(), "/anonymous_subscribed_subreddits.json");
        List<SubscribedUserData> anonymousSubscribedUsersData = redditDataRoomDatabase.subscribedUserDao().getAllSubscribedUsersList("-");
        String anonymousSubscribedUsersDataJson = new Gson().toJson(anonymousSubscribedUsersData);
        boolean res12 = saveDatabaseTableToFile(anonymousSubscribedUsersDataJson, databaseDirFile.getAbsolutePath(), "/anonymous_subscribed_users.json");
        List<MultiReddit> anonymousMultireddits = redditDataRoomDatabase.multiRedditDao().getAllMultiRedditsList("-");
        String anonymousMultiredditsJson = new Gson().toJson(anonymousMultireddits);
        boolean res13 = saveDatabaseTableToFile(anonymousMultiredditsJson, databaseDirFile.getAbsolutePath(), "/anonymous_multireddits.json");
        List<AnonymousMultiredditSubreddit> anonymousMultiredditSubreddits = redditDataRoomDatabase.anonymousMultiredditSubredditDao().getAllSubreddits();
        String anonymousMultiredditSubredditsJson = new Gson().toJson(anonymousMultiredditSubreddits);
        boolean res14 = saveDatabaseTableToFile(anonymousMultiredditSubredditsJson, databaseDirFile.getAbsolutePath(), "/anonymous_multireddit_subreddits.json");
        List<CustomTheme> customThemes = redditDataRoomDatabase.customThemeDao().getAllCustomThemesList();
        String customThemesJson = new Gson().toJson(customThemes);
        boolean res15 = saveDatabaseTableToFile(customThemesJson, databaseDirFile.getAbsolutePath(), "/custom_themes.json");
        List<PostFilter> postFilters = redditDataRoomDatabase.postFilterDao().getAllPostFilters();
        String postFiltersJson = new Gson().toJson(postFilters);
        boolean res16 = saveDatabaseTableToFile(postFiltersJson, databaseDirFile.getAbsolutePath(), "/post_filters.json");
        List<PostFilterUsage> postFilterUsage = redditDataRoomDatabase.postFilterUsageDao().getAllPostFilterUsageForBackup();
        String postFilterUsageJson = new Gson().toJson(postFilterUsage);
        boolean res17 = saveDatabaseTableToFile(postFilterUsageJson, databaseDirFile.getAbsolutePath(), "/post_filter_usage.json");
        boolean zipRes = zipAndMoveToDestinationDir(context, contentResolver, destinationDirUri);
        try {
            FileUtils.deleteDirectory(new File(context.getExternalCacheDir() + "/Backup/"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        handler.post(() -> {
            boolean finalResult = res && res1 && res2 && res3 && res4 && res5 && res6 && res7 && res8 && res9 && res10 && res11 && res12 && res13 && res14 && res15 && res16 && res17 && zipRes;
            if (finalResult) {
                backupSettingsListener.success();
            } else {
                if (!zipRes) {
                    backupSettingsListener.failed(context.getText(R.string.create_zip_in_destination_directory_failed).toString());
                } else {
                    backupSettingsListener.failed(context.getText(R.string.backup_some_settings_failed).toString());
                }
            }
        });
    });
}
Also used : SubscribedSubredditData(ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData) Gson(com.google.gson.Gson) IOException(java.io.IOException) SubscribedUserData(ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserData) MultiReddit(ml.docilealligator.infinityforreddit.multireddit.MultiReddit) CustomTheme(ml.docilealligator.infinityforreddit.customtheme.CustomTheme) PostFilterUsage(ml.docilealligator.infinityforreddit.postfilter.PostFilterUsage) AnonymousMultiredditSubreddit(ml.docilealligator.infinityforreddit.multireddit.AnonymousMultiredditSubreddit) File(java.io.File) DocumentFile(androidx.documentfile.provider.DocumentFile) ZipFile(net.lingala.zip4j.ZipFile) PostFilter(ml.docilealligator.infinityforreddit.postfilter.PostFilter)

Example 3 with PostFilter

use of ml.docilealligator.infinityforreddit.postfilter.PostFilter in project Infinity-For-Reddit by Docile-Alligator.

the class CustomizePostFilterActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    ((Infinity) getApplication()).getAppComponent().inject(this);
    setImmersiveModeNotApplicable();
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_customize_post_filter);
    ButterKnife.bind(this);
    applyCustomTheme();
    if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK, true)) {
        Slidr.attach(this);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) {
        addOnOffsetChangedListener(appBarLayout);
    }
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    setToolbarGoToTop(toolbar);
    fromSettings = getIntent().getBooleanExtra(EXTRA_FROM_SETTINGS, false);
    postTypeTextLinearLayout.setOnClickListener(view -> {
        postTypeTextCheckBox.performClick();
    });
    postTypeLinkLinearLayout.setOnClickListener(view -> {
        postTypeLinkCheckBox.performClick();
    });
    postTypeImageLinearLayout.setOnClickListener(view -> {
        postTypeImageCheckBox.performClick();
    });
    postTypeGifLinearLayout.setOnClickListener(view -> {
        postTypeGifCheckBox.performClick();
    });
    postTypeVideoLinearLayout.setOnClickListener(view -> {
        postTypeVideoCheckBox.performClick();
    });
    postTypeGalleryLinearLayout.setOnClickListener(view -> {
        postTypeGalleryCheckBox.performClick();
    });
    onlyNSFWLinearLayout.setOnClickListener(view -> {
        onlyNSFWSwitch.performClick();
    });
    onlySpoilerLinearLayout.setOnClickListener(view -> {
        onlySpoilerSwitch.performClick();
    });
    String accessToken = currentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
    addSubredditsImageView.setOnClickListener(view -> {
        if (accessToken == null) {
            Intent intent = new Intent(this, SearchActivity.class);
            intent.putExtra(SearchActivity.EXTRA_SEARCH_ONLY_SUBREDDITS, true);
            intent.putExtra(SearchActivity.EXTRA_IS_MULTI_SELECTION, true);
            startActivityForResult(intent, ADD_SUBREDDITS_ANONYMOUS_REQUEST_CODE);
        } else {
            Intent intent = new Intent(this, SubredditMultiselectionActivity.class);
            startActivityForResult(intent, ADD_SUBREDDITS_REQUEST_CODE);
        }
    });
    addUsersImageView.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);
        startActivityForResult(intent, ADD_USERS_REQUEST_CODE);
    });
    if (savedInstanceState != null) {
        postFilter = savedInstanceState.getParcelable(POST_FILTER_STATE);
        originalName = savedInstanceState.getString(ORIGINAL_NAME_STATE);
    } else {
        postFilter = getIntent().getParcelableExtra(EXTRA_POST_FILTER);
        if (postFilter == null) {
            postFilter = new PostFilter();
            originalName = "";
        } else {
            if (!fromSettings) {
                originalName = "";
            } else {
                originalName = postFilter.name;
            }
        }
        bindView();
    }
}
Also used : Intent(android.content.Intent) PostFilter(ml.docilealligator.infinityforreddit.postfilter.PostFilter) SavePostFilter(ml.docilealligator.infinityforreddit.postfilter.SavePostFilter)

Example 4 with PostFilter

use of ml.docilealligator.infinityforreddit.postfilter.PostFilter in project Infinity-For-Reddit by Docile-Alligator.

the class FetchPostFilterReadPostsAndConcatenatedSubredditNames method fetchPostFilterAndConcatenatedSubredditNames.

public static void fetchPostFilterAndConcatenatedSubredditNames(RedditDataRoomDatabase redditDataRoomDatabase, Executor executor, Handler handler, int postFilterUsage, String nameOfUsage, FetchPostFilterAndConcatenatecSubredditNamesListener fetchPostFilterAndConcatenatecSubredditNamesListener) {
    executor.execute(() -> {
        List<PostFilter> postFilters = redditDataRoomDatabase.postFilterDao().getValidPostFilters(postFilterUsage, nameOfUsage);
        PostFilter mergedPostFilter = PostFilter.mergePostFilter(postFilters);
        List<SubscribedSubredditData> anonymousSubscribedSubreddits = redditDataRoomDatabase.subscribedSubredditDao().getAllSubscribedSubredditsList("-");
        if (anonymousSubscribedSubreddits != null && !anonymousSubscribedSubreddits.isEmpty()) {
            StringBuilder stringBuilder = new StringBuilder();
            for (SubscribedSubredditData s : anonymousSubscribedSubreddits) {
                stringBuilder.append(s.getName()).append("+");
            }
            if (stringBuilder.length() > 0) {
                stringBuilder.deleteCharAt(stringBuilder.length() - 1);
            }
            handler.post(() -> fetchPostFilterAndConcatenatecSubredditNamesListener.success(mergedPostFilter, stringBuilder.toString()));
        } else {
            handler.post(() -> fetchPostFilterAndConcatenatecSubredditNamesListener.success(mergedPostFilter, null));
        }
    });
}
Also used : SubscribedSubredditData(ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData) PostFilter(ml.docilealligator.infinityforreddit.postfilter.PostFilter)

Example 5 with PostFilter

use of ml.docilealligator.infinityforreddit.postfilter.PostFilter in project Infinity-For-Reddit by Docile-Alligator.

the class PostFilterOptionsBottomSheetFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.fragment_post_filter_options_bottom_sheet, container, false);
    ButterKnife.bind(this, rootView);
    PostFilter postFilter = getArguments().getParcelable(EXTRA_POST_FILTER);
    editTextView.setOnClickListener(view -> {
        activity.editPostFilter(postFilter);
        dismiss();
    });
    applyToTextView.setOnClickListener(view -> {
        activity.applyPostFilterTo(postFilter);
        dismiss();
    });
    deleteTextView.setOnClickListener(view -> {
        activity.deletePostFilter(postFilter);
        dismiss();
    });
    if (activity.typeface != null) {
        Utils.setFontToAllTextViews(rootView, activity.typeface);
    }
    return rootView;
}
Also used : BindView(butterknife.BindView) TextView(android.widget.TextView) View(android.view.View) PostFilter(ml.docilealligator.infinityforreddit.postfilter.PostFilter)

Aggregations

PostFilter (ml.docilealligator.infinityforreddit.postfilter.PostFilter)11 BindView (butterknife.BindView)5 Intent (android.content.Intent)4 SharedPreferences (android.content.SharedPreferences)4 Bundle (android.os.Bundle)4 MenuItem (android.view.MenuItem)4 NonNull (androidx.annotation.NonNull)4 CoordinatorLayout (androidx.coordinatorlayout.widget.CoordinatorLayout)4 ViewModelProvider (androidx.lifecycle.ViewModelProvider)4 RecyclerView (androidx.recyclerview.widget.RecyclerView)4 ButterKnife (butterknife.ButterKnife)4 Executor (java.util.concurrent.Executor)4 Inject (javax.inject.Inject)4 Named (javax.inject.Named)4 Infinity (ml.docilealligator.infinityforreddit.Infinity)4 R (ml.docilealligator.infinityforreddit.R)4 RedditDataRoomDatabase (ml.docilealligator.infinityforreddit.RedditDataRoomDatabase)4 CustomThemeWrapper (ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper)4 Toolbar (androidx.appcompat.widget.Toolbar)3 AppBarLayout (com.google.android.material.appbar.AppBarLayout)3