diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-04-22 03:04:33 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-04-22 03:04:33 +0000 |
commit | b598da636053154670642ec326b104c9a11914d2 (patch) | |
tree | 983395b6d8f79000c5e7fd80f7ebab3dad1716dc /app/src | |
parent | 7d3f23473546e151977c52f5e073c7341ff59fbc (diff) | |
download | infinity-for-reddit-b598da636053154670642ec326b104c9a11914d2.tar infinity-for-reddit-b598da636053154670642ec326b104c9a11914d2.tar.gz infinity-for-reddit-b598da636053154670642ec326b104c9a11914d2.tar.bz2 infinity-for-reddit-b598da636053154670642ec326b104c9a11914d2.tar.lz infinity-for-reddit-b598da636053154670642ec326b104c9a11914d2.tar.xz infinity-for-reddit-b598da636053154670642ec326b104c9a11914d2.tar.zst infinity-for-reddit-b598da636053154670642ec326b104c9a11914d2.zip |
Start adding support for online themes.
Diffstat (limited to 'app/src')
7 files changed, 223 insertions, 36 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java index fccfc347..28a266cb 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java @@ -69,6 +69,7 @@ import ml.docilealligator.infinityforreddit.activities.WikiActivity; import ml.docilealligator.infinityforreddit.bottomsheetfragments.AccountChooserBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment; import ml.docilealligator.infinityforreddit.fragments.CommentsListingFragment; +import ml.docilealligator.infinityforreddit.fragments.CustomThemeListingFragment; import ml.docilealligator.infinityforreddit.fragments.FollowedUsersListingFragment; import ml.docilealligator.infinityforreddit.fragments.HistoryPostFragment; import ml.docilealligator.infinityforreddit.fragments.InboxFragment; @@ -313,6 +314,8 @@ public interface AppComponent { void inject(CommentFilterUsageListingActivity commentFilterUsageListingActivity); + void inject(CustomThemeListingFragment customThemeListingFragment); + @Component.Factory interface Factory { AppComponent create(@BindsInstance Application application); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemeListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemeListingActivity.java index fc22565d..f2421ac6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemeListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemeListingActivity.java @@ -13,17 +13,17 @@ import android.widget.EditText; import android.widget.Toast; import androidx.annotation.NonNull; -import androidx.appcompat.widget.Toolbar; -import androidx.coordinatorlayout.widget.CoordinatorLayout; +import androidx.annotation.Nullable; import androidx.core.app.ActivityCompat; -import androidx.lifecycle.ViewModelProvider; -import androidx.recyclerview.widget.RecyclerView; +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.dialog.MaterialAlertDialogBuilder; -import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.snackbar.Snackbar; +import com.google.android.material.tabs.TabLayoutMediator; import com.google.gson.JsonParseException; import org.greenrobot.eventbus.EventBus; @@ -34,12 +34,10 @@ import java.util.concurrent.Executor; import javax.inject.Inject; import javax.inject.Named; -import butterknife.BindView; -import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.adapters.CustomThemeListingRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.asynctasks.ChangeThemeName; import ml.docilealligator.infinityforreddit.asynctasks.DeleteTheme; import ml.docilealligator.infinityforreddit.asynctasks.GetCustomTheme; @@ -47,16 +45,18 @@ import ml.docilealligator.infinityforreddit.asynctasks.InsertCustomTheme; import ml.docilealligator.infinityforreddit.bottomsheetfragments.CreateThemeBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.CustomThemeOptionsBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomTheme; -import ml.docilealligator.infinityforreddit.customtheme.CustomThemeViewModel; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.databinding.ActivityCustomThemeListingBinding; import ml.docilealligator.infinityforreddit.events.RecreateActivityEvent; +import ml.docilealligator.infinityforreddit.fragments.CustomThemeListingFragment; import ml.docilealligator.infinityforreddit.utils.CustomThemeSharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.Utils; public class CustomThemeListingActivity extends BaseActivity implements CustomThemeOptionsBottomSheetFragment.CustomThemeOptionsBottomSheetFragmentListener, - CreateThemeBottomSheetFragment.SelectBaseThemeBottomSheetFragmentListener { + CreateThemeBottomSheetFragment.SelectBaseThemeBottomSheetFragmentListener, + RecyclerViewContentScrollingInterface { @Inject @Named("default") @@ -79,7 +79,8 @@ public class CustomThemeListingActivity extends BaseActivity implements SharedPreferences amoledThemeSharedPreferences; @Inject Executor executor; - public CustomThemeViewModel customThemeViewModel; + private FragmentManager fragmentManager; + private SectionsPagerAdapter sectionsPagerAdapter; private ActivityCustomThemeListingBinding binding; @Override @@ -99,29 +100,44 @@ public class CustomThemeListingActivity extends BaseActivity implements setSupportActionBar(binding.toolbarCustomizeThemeListingActivity); getSupportActionBar().setDisplayHomeAsUpEnabled(true); - CustomThemeListingRecyclerViewAdapter adapter = new CustomThemeListingRecyclerViewAdapter(this, - CustomThemeWrapper.getPredefinedThemes(this)); - binding.recyclerViewCustomizeThemeListingActivity.setAdapter(adapter); - binding.recyclerViewCustomizeThemeListingActivity.addOnScrollListener(new RecyclerView.OnScrollListener() { + binding.fabCustomThemeListingActivity.setOnClickListener(view -> { + CreateThemeBottomSheetFragment createThemeBottomSheetFragment = new CreateThemeBottomSheetFragment(); + createThemeBottomSheetFragment.show(getSupportFragmentManager(), createThemeBottomSheetFragment.getTag()); + }); + + fragmentManager = getSupportFragmentManager(); + + initializeViewPager(); + } + + private void initializeViewPager() { + sectionsPagerAdapter = new SectionsPagerAdapter(this); + binding.viewPager2CustomizeThemeListingActivity.setAdapter(sectionsPagerAdapter); + binding.viewPager2CustomizeThemeListingActivity.setUserInputEnabled(!sharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_SWIPING_BETWEEN_TABS, false)); + new TabLayoutMediator(binding.tabLayoutCustomizeThemeListingActivity, binding.viewPager2CustomizeThemeListingActivity, (tab, position) -> { + switch (position) { + case 0: + Utils.setTitleWithCustomFontToTab(typeface, tab, getString(R.string.local)); + break; + case 1: + Utils.setTitleWithCustomFontToTab(typeface, tab, getString(R.string.online)); + break; + } + }).attach(); + + binding.viewPager2CustomizeThemeListingActivity.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() { @Override - public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { - if (dy > 0) { - binding.fabCustomThemeListingActivity.hide(); - } else if (dy < 0) { - binding.fabCustomThemeListingActivity.show(); + public void onPageSelected(int position) { + binding.fabCustomThemeListingActivity.show(); + if (position == 0) { + unlockSwipeRightToGoBack(); + } else { + lockSwipeRightToGoBack(); } } }); - customThemeViewModel = new ViewModelProvider(this, - new CustomThemeViewModel.Factory(redditDataRoomDatabase)) - .get(CustomThemeViewModel.class); - customThemeViewModel.getAllCustomThemes().observe(this, adapter::setUserThemes); - - binding.fabCustomThemeListingActivity.setOnClickListener(view -> { - CreateThemeBottomSheetFragment createThemeBottomSheetFragment = new CreateThemeBottomSheetFragment(); - createThemeBottomSheetFragment.show(getSupportFragmentManager(), createThemeBottomSheetFragment.getTag()); - }); + fixViewPager2Sensitivity(binding.viewPager2CustomizeThemeListingActivity); } @Override @@ -153,6 +169,7 @@ public class CustomThemeListingActivity extends BaseActivity implements binding.coordinatorLayoutCustomThemeListingActivity.setBackgroundColor(customThemeWrapper.getBackgroundColor()); applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(binding.appbarLayoutCustomizeThemeListingActivity, binding.collapsingToolbarLayoutCustomizeThemeListingActivity, binding.toolbarCustomizeThemeListingActivity); applyFABTheme(binding.fabCustomThemeListingActivity); + applyTabLayoutTheme(binding.tabLayoutCustomizeThemeListingActivity); } @Override @@ -278,6 +295,16 @@ public class CustomThemeListingActivity extends BaseActivity implements } } + @Override + public void contentScrollUp() { + binding.fabCustomThemeListingActivity.show(); + } + + @Override + public void contentScrollDown() { + binding.fabCustomThemeListingActivity.hide(); + } + private void checkDuplicateAndImportTheme(CustomTheme customTheme, boolean checkDuplicate) { InsertCustomTheme.insertCustomTheme(executor, new Handler(), redditDataRoomDatabase, lightThemeSharedPreferences, darkThemeSharedPreferences, amoledThemeSharedPreferences, customTheme, checkDuplicate, @@ -324,4 +351,35 @@ public class CustomThemeListingActivity extends BaseActivity implements } }); } + + private class SectionsPagerAdapter extends FragmentStateAdapter { + + SectionsPagerAdapter(FragmentActivity fa) { + super(fa); + } + + @NonNull + @Override + public Fragment createFragment(int position) { + if (position == 0) { + CustomThemeListingFragment fragment = new CustomThemeListingFragment(); + return fragment; + } + CustomThemeListingFragment fragment = new CustomThemeListingFragment(); + return fragment; + } + + @Nullable + private Fragment getCurrentFragment() { + if (fragmentManager == null) { + return null; + } + return fragmentManager.findFragmentByTag("f" + binding.viewPager2CustomizeThemeListingActivity.getCurrentItem()); + } + + @Override + public int getItemCount() { + return 2; + } + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CustomThemeListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CustomThemeListingFragment.java new file mode 100644 index 00000000..c10bee15 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CustomThemeListingFragment.java @@ -0,0 +1,95 @@ +package ml.docilealligator.infinityforreddit.fragments; + +import android.content.Context; +import android.content.SharedPreferences; +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 androidx.lifecycle.ViewModelProvider; +import androidx.recyclerview.widget.RecyclerView; + +import java.util.concurrent.Executor; + +import javax.inject.Inject; +import javax.inject.Named; + +import ml.docilealligator.infinityforreddit.Infinity; +import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface; +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; +import ml.docilealligator.infinityforreddit.adapters.CustomThemeListingRecyclerViewAdapter; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeViewModel; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.databinding.FragmentCustomThemeListingBinding; + +public class CustomThemeListingFragment extends Fragment { + + @Inject + @Named("default") + SharedPreferences sharedPreferences; + @Inject + @Named("current_account") + SharedPreferences mCurrentAccountSharedPreferences; + @Inject + RedditDataRoomDatabase redditDataRoomDatabase; + @Inject + CustomThemeWrapper customThemeWrapper; + @Inject + @Named("light_theme") + SharedPreferences lightThemeSharedPreferences; + @Inject + @Named("dark_theme") + SharedPreferences darkThemeSharedPreferences; + @Inject + @Named("amoled_theme") + SharedPreferences amoledThemeSharedPreferences; + @Inject + Executor executor; + public CustomThemeViewModel customThemeViewModel; + private BaseActivity activity; + private FragmentCustomThemeListingBinding binding; + + public CustomThemeListingFragment() { + // Required empty public constructor + } + + @Override + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + ((Infinity) activity.getApplication()).getAppComponent().inject(this); + + // Inflate the layout for this fragment + binding = FragmentCustomThemeListingBinding.inflate(inflater, container, false); + + CustomThemeListingRecyclerViewAdapter adapter = new CustomThemeListingRecyclerViewAdapter(activity, + CustomThemeWrapper.getPredefinedThemes(activity)); + binding.recyclerViewCustomizeThemeListingActivity.setAdapter(adapter); + binding.recyclerViewCustomizeThemeListingActivity.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { + if (dy > 0) { + ((RecyclerViewContentScrollingInterface) activity).contentScrollDown(); + } else if (dy < 0) { + ((RecyclerViewContentScrollingInterface) activity).contentScrollUp(); + } + } + }); + + customThemeViewModel = new ViewModelProvider(this, + new CustomThemeViewModel.Factory(redditDataRoomDatabase)) + .get(CustomThemeViewModel.class); + customThemeViewModel.getAllCustomThemes().observe(getViewLifecycleOwner(), adapter::setUserThemes); + + return binding.getRoot(); + } + + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); + activity = (BaseActivity) context; + } +}
\ No newline at end of file diff --git a/app/src/main/res/layout/activity_account_saved_thing.xml b/app/src/main/res/layout/activity_account_saved_thing.xml index f6660c4b..5687b205 100644 --- a/app/src/main/res/layout/activity_account_saved_thing.xml +++ b/app/src/main/res/layout/activity_account_saved_thing.xml @@ -50,7 +50,6 @@ <androidx.viewpager2.widget.ViewPager2 android:id="@+id/account_saved_thing_view_pager_2" android:layout_width="match_parent" - android:layout_height="match_parent" - app:layout_behavior="@string/appbar_scrolling_view_behavior" /> + android:layout_height="match_parent" /> </androidx.coordinatorlayout.widget.CoordinatorLayout>
\ No newline at end of file diff --git a/app/src/main/res/layout/activity_custom_theme_listing.xml b/app/src/main/res/layout/activity_custom_theme_listing.xml index 57168d04..c694b6c2 100644 --- a/app/src/main/res/layout/activity_custom_theme_listing.xml +++ b/app/src/main/res/layout/activity_custom_theme_listing.xml @@ -26,18 +26,31 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="?attr/actionBarSize" + app:layout_collapseMode="pin" + app:layout_scrollFlags="scroll|enterAlways" app:popupTheme="@style/AppTheme.PopupOverlay" app:navigationIcon="?attr/homeAsUpIndicator" /> </com.google.android.material.appbar.CollapsingToolbarLayout> + <com.google.android.material.tabs.TabLayout + android:id="@+id/tab_layout_customize_theme_listing_activity" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="bottom" + app:layout_scrollFlags="scroll|enterAlways" + app:tabGravity="fill" + app:tabIndicatorHeight="3dp" + app:tabMode="fixed" + app:tabRippleColor="?attr/colorControlHighlight" + app:tabUnboundedRipple="false" /> + </com.google.android.material.appbar.AppBarLayout> - <androidx.recyclerview.widget.RecyclerView - android:id="@+id/recycler_view_customize_theme_listing_activity" + <androidx.viewpager2.widget.ViewPager2 + android:id="@+id/view_pager_2_customize_theme_listing_activity" android:layout_width="match_parent" android:layout_height="match_parent" - app:layoutManager="ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> <com.google.android.material.floatingactionbutton.FloatingActionButton diff --git a/app/src/main/res/layout/fragment_custom_theme_listing.xml b/app/src/main/res/layout/fragment_custom_theme_listing.xml new file mode 100644 index 00000000..4df0fcc2 --- /dev/null +++ b/app/src/main/res/layout/fragment_custom_theme_listing.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8"?> +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + xmlns:app="http://schemas.android.com/apk/res-auto" + tools:context=".fragments.CustomThemeListingFragment"> + + <androidx.recyclerview.widget.RecyclerView + android:id="@+id/recycler_view_customize_theme_listing_activity" + android:layout_width="match_parent" + android:layout_height="match_parent" + app:layoutManager="ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed" + app:layout_behavior="@string/appbar_scrolling_view_behavior" /> + +</FrameLayout>
\ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index abf8e083..86dafe41 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1383,4 +1383,7 @@ <string name="add_to_comment_filter">Add to Comment Filter</string> <string name="cannot_edit_post_with_images">Editing posts with images is not allowed.</string> + <string name="local">Local</string> + <string name="online">Online</string> + </resources> |