diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-03-17 13:01:46 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-03-17 13:01:46 +0000 |
commit | 41daebf702f150d7f3df0fa722d2c749931d859e (patch) | |
tree | edbf73d3a11aa92d8ef54dc9ee98727bc2601d47 | |
parent | 8e6a4d1e14f55fb7ce41b252f9335a08e35de791 (diff) | |
download | infinity-for-reddit-41daebf702f150d7f3df0fa722d2c749931d859e.tar infinity-for-reddit-41daebf702f150d7f3df0fa722d2c749931d859e.tar.gz infinity-for-reddit-41daebf702f150d7f3df0fa722d2c749931d859e.tar.bz2 infinity-for-reddit-41daebf702f150d7f3df0fa722d2c749931d859e.tar.lz infinity-for-reddit-41daebf702f150d7f3df0fa722d2c749931d859e.tar.xz infinity-for-reddit-41daebf702f150d7f3df0fa722d2c749931d859e.tar.zst infinity-for-reddit-41daebf702f150d7f3df0fa722d2c749931d859e.zip |
Migrate to ViewBinding in some activities.
9 files changed, 251 insertions, 435 deletions
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 ad951a93..fc22565d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemeListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemeListingActivity.java @@ -49,6 +49,7 @@ import ml.docilealligator.infinityforreddit.bottomsheetfragments.CustomThemeOpti 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.utils.CustomThemeSharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.Utils; @@ -57,18 +58,6 @@ public class CustomThemeListingActivity extends BaseActivity implements CustomThemeOptionsBottomSheetFragment.CustomThemeOptionsBottomSheetFragmentListener, CreateThemeBottomSheetFragment.SelectBaseThemeBottomSheetFragmentListener { - @BindView(R.id.coordinator_layout_custom_theme_listing_activity) - CoordinatorLayout coordinatorLayout; - @BindView(R.id.appbar_layout_customize_theme_listing_activity) - AppBarLayout appBarLayout; - @BindView(R.id.collapsing_toolbar_layout_customize_theme_listing_activity) - CollapsingToolbarLayout collapsingToolbarLayout; - @BindView(R.id.toolbar_customize_theme_listing_activity) - Toolbar toolbar; - @BindView(R.id.recycler_view_customize_theme_listing_activity) - RecyclerView recyclerView; - @BindView(R.id.fab_custom_theme_listing_activity) - FloatingActionButton fab; @Inject @Named("default") SharedPreferences sharedPreferences; @@ -91,6 +80,7 @@ public class CustomThemeListingActivity extends BaseActivity implements @Inject Executor executor; public CustomThemeViewModel customThemeViewModel; + private ActivityCustomThemeListingBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { @@ -99,27 +89,26 @@ public class CustomThemeListingActivity extends BaseActivity implements setImmersiveModeNotApplicable(); super.onCreate(savedInstanceState); - setContentView(R.layout.activity_custom_theme_listing); - - ButterKnife.bind(this); + binding = ActivityCustomThemeListingBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); EventBus.getDefault().register(this); applyCustomTheme(); - setSupportActionBar(toolbar); + setSupportActionBar(binding.toolbarCustomizeThemeListingActivity); getSupportActionBar().setDisplayHomeAsUpEnabled(true); CustomThemeListingRecyclerViewAdapter adapter = new CustomThemeListingRecyclerViewAdapter(this, CustomThemeWrapper.getPredefinedThemes(this)); - recyclerView.setAdapter(adapter); - recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + binding.recyclerViewCustomizeThemeListingActivity.setAdapter(adapter); + binding.recyclerViewCustomizeThemeListingActivity.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { if (dy > 0) { - fab.hide(); + binding.fabCustomThemeListingActivity.hide(); } else if (dy < 0) { - fab.show(); + binding.fabCustomThemeListingActivity.show(); } } }); @@ -129,7 +118,7 @@ public class CustomThemeListingActivity extends BaseActivity implements .get(CustomThemeViewModel.class); customThemeViewModel.getAllCustomThemes().observe(this, adapter::setUserThemes); - fab.setOnClickListener(view -> { + binding.fabCustomThemeListingActivity.setOnClickListener(view -> { CreateThemeBottomSheetFragment createThemeBottomSheetFragment = new CreateThemeBottomSheetFragment(); createThemeBottomSheetFragment.show(getSupportFragmentManager(), createThemeBottomSheetFragment.getTag()); }); @@ -161,9 +150,9 @@ public class CustomThemeListingActivity extends BaseActivity implements @Override protected void applyCustomTheme() { - coordinatorLayout.setBackgroundColor(customThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); - applyFABTheme(fab); + binding.coordinatorLayoutCustomThemeListingActivity.setBackgroundColor(customThemeWrapper.getBackgroundColor()); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(binding.appbarLayoutCustomizeThemeListingActivity, binding.collapsingToolbarLayoutCustomizeThemeListingActivity, binding.toolbarCustomizeThemeListingActivity); + applyFABTheme(binding.fabCustomThemeListingActivity); } @Override @@ -199,12 +188,12 @@ public class CustomThemeListingActivity extends BaseActivity implements if (clipboard != null) { ClipData clip = ClipData.newPlainText("simple text", jsonModel); clipboard.setPrimaryClip(clip); - Snackbar.make(coordinatorLayout, R.string.theme_copied, Snackbar.LENGTH_SHORT).show(); + Snackbar.make(binding.coordinatorLayoutCustomThemeListingActivity, R.string.theme_copied, Snackbar.LENGTH_SHORT).show(); } else { - Snackbar.make(coordinatorLayout, R.string.copy_theme_faied, Snackbar.LENGTH_SHORT).show(); + Snackbar.make(binding.coordinatorLayoutCustomThemeListingActivity, R.string.copy_theme_faied, Snackbar.LENGTH_SHORT).show(); } } else { - Snackbar.make(coordinatorLayout, R.string.cannot_find_theme, Snackbar.LENGTH_SHORT).show(); + Snackbar.make(binding.coordinatorLayoutCustomThemeListingActivity, R.string.cannot_find_theme, Snackbar.LENGTH_SHORT).show(); } }); } @@ -247,12 +236,12 @@ public class CustomThemeListingActivity extends BaseActivity implements if (clipboard != null) { ClipData clip = ClipData.newPlainText("simple text", jsonModel); clipboard.setPrimaryClip(clip); - Snackbar.make(coordinatorLayout, R.string.theme_copied, Snackbar.LENGTH_SHORT).show(); + Snackbar.make(binding.coordinatorLayoutCustomThemeListingActivity, R.string.theme_copied, Snackbar.LENGTH_SHORT).show(); } else { - Snackbar.make(coordinatorLayout, R.string.copy_theme_faied, Snackbar.LENGTH_SHORT).show(); + Snackbar.make(binding.coordinatorLayoutCustomThemeListingActivity, R.string.copy_theme_faied, Snackbar.LENGTH_SHORT).show(); } } else { - Snackbar.make(coordinatorLayout, R.string.cannot_find_theme, Snackbar.LENGTH_SHORT).show(); + Snackbar.make(binding.coordinatorLayoutCustomThemeListingActivity, R.string.cannot_find_theme, Snackbar.LENGTH_SHORT).show(); } } @@ -267,11 +256,11 @@ public class CustomThemeListingActivity extends BaseActivity implements if (clipboard != null) { // If it does contain data, decide if you can handle the data. if (!clipboard.hasPrimaryClip()) { - Snackbar.make(coordinatorLayout, R.string.no_data_in_clipboard, Snackbar.LENGTH_SHORT).show(); + Snackbar.make(binding.coordinatorLayoutCustomThemeListingActivity, R.string.no_data_in_clipboard, Snackbar.LENGTH_SHORT).show(); } else if (clipboard.getPrimaryClipDescription() != null && !clipboard.getPrimaryClipDescription().hasMimeType("text/*")) { // since the clipboard has data but it is not text - Snackbar.make(coordinatorLayout, R.string.no_data_in_clipboard, Snackbar.LENGTH_SHORT).show(); + Snackbar.make(binding.coordinatorLayoutCustomThemeListingActivity, R.string.no_data_in_clipboard, Snackbar.LENGTH_SHORT).show(); } else if (clipboard.getPrimaryClip() != null) { ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0); String json = item.coerceToText(this.getApplicationContext()).toString(); @@ -280,10 +269,10 @@ public class CustomThemeListingActivity extends BaseActivity implements CustomTheme customTheme = CustomTheme.fromJson(json); checkDuplicateAndImportTheme(customTheme, true); } catch (JsonParseException e) { - Snackbar.make(coordinatorLayout, R.string.parse_theme_failed, Snackbar.LENGTH_SHORT).show(); + Snackbar.make(binding.coordinatorLayoutCustomThemeListingActivity, R.string.parse_theme_failed, Snackbar.LENGTH_SHORT).show(); } } else { - Snackbar.make(coordinatorLayout, R.string.parse_theme_failed, Snackbar.LENGTH_SHORT).show(); + Snackbar.make(binding.coordinatorLayoutCustomThemeListingActivity, R.string.parse_theme_failed, Snackbar.LENGTH_SHORT).show(); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemePreviewActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemePreviewActivity.java index 3a603952..e66fb00f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemePreviewActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemePreviewActivity.java @@ -19,8 +19,6 @@ import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.view.Window; import android.view.WindowManager; -import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.NonNull; @@ -34,9 +32,6 @@ import androidx.fragment.app.FragmentPagerAdapter; import androidx.viewpager.widget.ViewPager; import com.google.android.material.appbar.AppBarLayout; -import com.google.android.material.appbar.CollapsingToolbarLayout; -import com.google.android.material.bottomappbar.BottomAppBar; -import com.google.android.material.chip.Chip; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.tabs.TabLayout; @@ -45,17 +40,15 @@ import java.util.ArrayList; import javax.inject.Inject; import javax.inject.Named; -import butterknife.BindView; -import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.CustomFontReceiver; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.customtheme.CustomTheme; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeSettingsItem; -import ml.docilealligator.infinityforreddit.customviews.ViewPagerBugFixed; import ml.docilealligator.infinityforreddit.customviews.slidr.Slidr; import ml.docilealligator.infinityforreddit.customviews.slidr.widget.SliderPanel; +import ml.docilealligator.infinityforreddit.databinding.ActivityThemePreviewBinding; import ml.docilealligator.infinityforreddit.font.ContentFontStyle; import ml.docilealligator.infinityforreddit.font.FontStyle; import ml.docilealligator.infinityforreddit.font.TitleFontStyle; @@ -71,46 +64,6 @@ public class CustomThemePreviewActivity extends AppCompatActivity implements Cus public Typeface titleTypeface; public Typeface contentTypeface; - @BindView(R.id.coordinator_layout_theme_preview_activity) - CoordinatorLayout coordinatorLayout; - @BindView(R.id.view_pager_theme_preview_activity) - ViewPagerBugFixed viewPager; - @BindView(R.id.appbar_layout_theme_preview_activity) - AppBarLayout appBarLayout; - @BindView(R.id.collapsing_toolbar_layout_theme_preview_activity) - CollapsingToolbarLayout collapsingToolbarLayout; - @BindView(R.id.toolbar_linear_layout_theme_preview_activity) - LinearLayout linearLayout; - @BindView(R.id.extra_padding_view_theme_preview_activity) - View extraPaddingView; - @BindView(R.id.subreddit_name_text_view_theme_preview_activity) - TextView subredditNameTextView; - @BindView(R.id.user_name_text_view_theme_preview_activity) - TextView usernameTextView; - @BindView(R.id.subscribe_subreddit_chip_theme_preview_activity) - Chip subscribeSubredditChip; - @BindView(R.id.primary_text_text_view_theme_preview_activity) - TextView primaryTextView; - @BindView(R.id.secondary_text_text_view_theme_preview_activity) - TextView secondaryTextView; - @BindView(R.id.toolbar) - Toolbar toolbar; - @BindView(R.id.tab_layout_theme_preview_activity) - TabLayout tabLayout; - @BindView(R.id.bottom_navigation_theme_preview_activity) - BottomAppBar bottomNavigationView; - @BindView(R.id.linear_layout_bottom_app_bar_theme_preview_activity) - LinearLayout linearLayoutBottomAppBar; - @BindView(R.id.subscriptions_bottom_app_bar_theme_preview_activity) - ImageView subscriptionsBottomAppBar; - @BindView(R.id.multi_reddit_bottom_app_bar_theme_preview_activity) - ImageView multiRedditBottomAppBar; - @BindView(R.id.message_bottom_app_bar_theme_preview_activity) - ImageView messageBottomAppBar; - @BindView(R.id.profile_bottom_app_bar_theme_preview_activity) - ImageView profileBottomAppBar; - @BindView(R.id.fab_theme_preview_activity) - FloatingActionButton fab; @Inject @Named("default") SharedPreferences mSharedPreferences; @@ -127,6 +80,7 @@ public class CustomThemePreviewActivity extends AppCompatActivity implements Cus private int systemVisibilityToolbarExpanded = 0; private int systemVisibilityToolbarCollapsed = 0; private SliderPanel mSliderPanel; + private ActivityThemePreviewBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { @@ -225,9 +179,8 @@ public class CustomThemePreviewActivity extends AppCompatActivity implements Cus getTheme().applyStyle(ContentFontStyle.valueOf(mSharedPreferences .getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true); - setContentView(R.layout.activity_theme_preview); - - ButterKnife.bind(this); + binding = ActivityThemePreviewBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); applyCustomTheme(); @@ -242,88 +195,88 @@ public class CustomThemePreviewActivity extends AppCompatActivity implements Cus } else { window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); } - adjustToolbar(toolbar); + adjustToolbar(binding.toolbar); Resources resources = getResources(); int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); if (navBarResourceId > 0) { int navBarHeight = resources.getDimensionPixelSize(navBarResourceId); if (navBarHeight > 0) { - CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) fab.getLayoutParams(); + CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) binding.fabThemePreviewActivity.getLayoutParams(); params.bottomMargin = navBarHeight; - fab.setLayoutParams(params); - linearLayoutBottomAppBar.setPadding(0, + binding.fabThemePreviewActivity.setLayoutParams(params); + binding.linearLayoutBottomAppBarThemePreviewActivity.setPadding(0, (int) (6 * getResources().getDisplayMetrics().density), 0, navBarHeight); } } } if (changeStatusBarIconColor) { - appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() { + binding.appbarLayoutThemePreviewActivity.addOnOffsetChangedListener(new AppBarStateChangeListener() { @Override public void onStateChanged(AppBarLayout appBarLayout, AppBarStateChangeListener.State state) { if (state == State.COLLAPSED) { decorView.setSystemUiVisibility(systemVisibilityToolbarCollapsed); - tabLayout.setTabTextColors(collapsedTabTextColor, collapsedTabTextColor); - tabLayout.setSelectedTabIndicatorColor(collapsedTabIndicatorColor); - tabLayout.setBackgroundColor(collapsedTabBackgroundColor); + binding.tabLayoutThemePreviewActivity.setTabTextColors(collapsedTabTextColor, collapsedTabTextColor); + binding.tabLayoutThemePreviewActivity.setSelectedTabIndicatorColor(collapsedTabIndicatorColor); + binding.tabLayoutThemePreviewActivity.setBackgroundColor(collapsedTabBackgroundColor); } else if (state == State.EXPANDED) { decorView.setSystemUiVisibility(systemVisibilityToolbarExpanded); - tabLayout.setTabTextColors(expandedTabTextColor, expandedTabTextColor); - tabLayout.setSelectedTabIndicatorColor(expandedTabIndicatorColor); - tabLayout.setBackgroundColor(expandedTabBackgroundColor); + binding.tabLayoutThemePreviewActivity.setTabTextColors(expandedTabTextColor, expandedTabTextColor); + binding.tabLayoutThemePreviewActivity.setSelectedTabIndicatorColor(expandedTabIndicatorColor); + binding.tabLayoutThemePreviewActivity.setBackgroundColor(expandedTabBackgroundColor); } } }); } else { - appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() { + binding.appbarLayoutThemePreviewActivity.addOnOffsetChangedListener(new AppBarStateChangeListener() { @Override public void onStateChanged(AppBarLayout appBarLayout, AppBarStateChangeListener.State state) { if (state == State.COLLAPSED) { - tabLayout.setTabTextColors(collapsedTabTextColor, collapsedTabTextColor); - tabLayout.setSelectedTabIndicatorColor(collapsedTabIndicatorColor); - tabLayout.setBackgroundColor(collapsedTabBackgroundColor); + binding.tabLayoutThemePreviewActivity.setTabTextColors(collapsedTabTextColor, collapsedTabTextColor); + binding.tabLayoutThemePreviewActivity.setSelectedTabIndicatorColor(collapsedTabIndicatorColor); + binding.tabLayoutThemePreviewActivity.setBackgroundColor(collapsedTabBackgroundColor); } else if (state == State.EXPANDED) { - tabLayout.setTabTextColors(expandedTabTextColor, expandedTabTextColor); - tabLayout.setSelectedTabIndicatorColor(expandedTabIndicatorColor); - tabLayout.setBackgroundColor(expandedTabBackgroundColor); + binding.tabLayoutThemePreviewActivity.setTabTextColors(expandedTabTextColor, expandedTabTextColor); + binding.tabLayoutThemePreviewActivity.setSelectedTabIndicatorColor(expandedTabIndicatorColor); + binding.tabLayoutThemePreviewActivity.setBackgroundColor(expandedTabBackgroundColor); } } }); } } else { - appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() { + binding.appbarLayoutThemePreviewActivity.addOnOffsetChangedListener(new AppBarStateChangeListener() { @Override public void onStateChanged(AppBarLayout appBarLayout, State state) { if (state == State.EXPANDED) { - tabLayout.setTabTextColors(expandedTabTextColor, expandedTabTextColor); - tabLayout.setSelectedTabIndicatorColor(expandedTabIndicatorColor); - tabLayout.setBackgroundColor(expandedTabBackgroundColor); + binding.tabLayoutThemePreviewActivity.setTabTextColors(expandedTabTextColor, expandedTabTextColor); + binding.tabLayoutThemePreviewActivity.setSelectedTabIndicatorColor(expandedTabIndicatorColor); + binding.tabLayoutThemePreviewActivity.setBackgroundColor(expandedTabBackgroundColor); } else if (state == State.COLLAPSED) { - tabLayout.setTabTextColors(collapsedTabTextColor, collapsedTabTextColor); - tabLayout.setSelectedTabIndicatorColor(collapsedTabIndicatorColor); - tabLayout.setBackgroundColor(collapsedTabBackgroundColor); + binding.tabLayoutThemePreviewActivity.setTabTextColors(collapsedTabTextColor, collapsedTabTextColor); + binding.tabLayoutThemePreviewActivity.setSelectedTabIndicatorColor(collapsedTabIndicatorColor); + binding.tabLayoutThemePreviewActivity.setBackgroundColor(collapsedTabBackgroundColor); } } }); } - setSupportActionBar(toolbar); + setSupportActionBar(binding.toolbar); - subscribeSubredditChip.setOnClickListener(view -> { - if (subscribeSubredditChip.getText().equals(getResources().getString(R.string.subscribe))) { - subscribeSubredditChip.setText(R.string.unsubscribe); - subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(subscribedColor)); + binding.subscribeSubredditChipThemePreviewActivity.setOnClickListener(view -> { + if (binding.subscribeSubredditChipThemePreviewActivity.getText().equals(getResources().getString(R.string.subscribe))) { + binding.subscribeSubredditChipThemePreviewActivity.setText(R.string.unsubscribe); + binding.subscribeSubredditChipThemePreviewActivity.setChipBackgroundColor(ColorStateList.valueOf(subscribedColor)); } else { - subscribeSubredditChip.setText(R.string.subscribe); - subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(unsubscribedColor)); + binding.subscribeSubredditChipThemePreviewActivity.setText(R.string.subscribe); + binding.subscribeSubredditChipThemePreviewActivity.setChipBackgroundColor(ColorStateList.valueOf(unsubscribedColor)); } }); SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); - viewPager.setAdapter(sectionsPagerAdapter); - viewPager.setOffscreenPageLimit(2); - viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { + binding.viewPagerThemePreviewActivity.setAdapter(sectionsPagerAdapter); + binding.viewPagerThemePreviewActivity.setOffscreenPageLimit(2); + binding.viewPagerThemePreviewActivity.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { if (position == 0) { @@ -333,51 +286,51 @@ public class CustomThemePreviewActivity extends AppCompatActivity implements Cus } } }); - tabLayout.setupWithViewPager(viewPager); + binding.tabLayoutThemePreviewActivity.setupWithViewPager(binding.viewPagerThemePreviewActivity); } private void applyCustomTheme() { - coordinatorLayout.setBackgroundColor(customTheme.backgroundColor); - appBarLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + binding.coordinatorLayoutThemePreviewActivity.setBackgroundColor(customTheme.backgroundColor); + binding.appbarLayoutThemePreviewActivity.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { - appBarLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this); - collapsingToolbarLayout.setScrimVisibleHeightTrigger(toolbar.getHeight() + tabLayout.getHeight() + getStatusBarHeight() * 2); + binding.appbarLayoutThemePreviewActivity.getViewTreeObserver().removeOnGlobalLayoutListener(this); + binding.collapsingToolbarLayoutThemePreviewActivity.setScrimVisibleHeightTrigger(binding.toolbar.getHeight() + binding.tabLayoutThemePreviewActivity.getHeight() + getStatusBarHeight() * 2); } }); - collapsingToolbarLayout.setContentScrimColor(customTheme.colorPrimary); - subscribeSubredditChip.setTextColor(customTheme.chipTextColor); - subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(customTheme.unsubscribed)); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + binding.collapsingToolbarLayoutThemePreviewActivity.setContentScrimColor(customTheme.colorPrimary); + binding.subscribeSubredditChipThemePreviewActivity.setTextColor(customTheme.chipTextColor); + binding.subscribeSubredditChipThemePreviewActivity.setChipBackgroundColor(ColorStateList.valueOf(customTheme.unsubscribed)); + applyAppBarLayoutAndToolbarTheme(binding.appbarLayoutThemePreviewActivity, binding.toolbar); expandedTabTextColor = customTheme.tabLayoutWithExpandedCollapsingToolbarTextColor; expandedTabIndicatorColor = customTheme.tabLayoutWithExpandedCollapsingToolbarTabIndicator; expandedTabBackgroundColor = customTheme.tabLayoutWithExpandedCollapsingToolbarTabBackground; collapsedTabTextColor = customTheme.tabLayoutWithCollapsedCollapsingToolbarTextColor; collapsedTabIndicatorColor = customTheme.tabLayoutWithCollapsedCollapsingToolbarTabIndicator; collapsedTabBackgroundColor = customTheme.tabLayoutWithCollapsedCollapsingToolbarTabBackground; - linearLayout.setBackgroundColor(customTheme.tabLayoutWithExpandedCollapsingToolbarTabBackground); - extraPaddingView.setBackgroundColor(customTheme.colorPrimary); - subredditNameTextView.setTextColor(customTheme.subreddit); - usernameTextView.setTextColor(customTheme.username); - subscribeSubredditChip.setTextColor(customTheme.chipTextColor); - primaryTextView.setTextColor(customTheme.primaryTextColor); - secondaryTextView.setTextColor(customTheme.secondaryTextColor); - bottomNavigationView.setBackgroundTint(ColorStateList.valueOf(customTheme.bottomAppBarBackgroundColor)); + binding.linearLayoutBottomAppBarThemePreviewActivity.setBackgroundColor(customTheme.tabLayoutWithExpandedCollapsingToolbarTabBackground); + binding.extraPaddingViewThemePreviewActivity.setBackgroundColor(customTheme.colorPrimary); + binding.subredditNameTextViewThemePreviewActivity.setTextColor(customTheme.subreddit); + binding.userNameTextViewThemePreviewActivity.setTextColor(customTheme.username); + binding.subscribeSubredditChipThemePreviewActivity.setTextColor(customTheme.chipTextColor); + binding.primaryTextTextViewThemePreviewActivity.setTextColor(customTheme.primaryTextColor); + binding.secondaryTextTextViewThemePreviewActivity.setTextColor(customTheme.secondaryTextColor); + binding.bottomNavigationThemePreviewActivity.setBackgroundTint(ColorStateList.valueOf(customTheme.bottomAppBarBackgroundColor)); int bottomAppBarIconColor = customTheme.bottomAppBarIconColor; - subscriptionsBottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); - multiRedditBottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); - messageBottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); - profileBottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); - applyTabLayoutTheme(tabLayout); - applyFABTheme(fab); + binding.subscriptionsBottomAppBarThemePreviewActivity.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); + binding.multiRedditBottomAppBarThemePreviewActivity.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); + binding.messageBottomAppBarThemePreviewActivity.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); + binding.profileBottomAppBarThemePreviewActivity.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); + applyTabLayoutTheme(binding.tabLayoutThemePreviewActivity); + applyFABTheme(binding.fabThemePreviewActivity); unsubscribedColor = customTheme.unsubscribed; subscribedColor = customTheme.subscribed; if (typeface != null) { - subredditNameTextView.setTypeface(typeface); - usernameTextView.setTypeface(typeface); - primaryTextView.setTypeface(typeface); - secondaryTextView.setTypeface(typeface); - subscribeSubredditChip.setTypeface(typeface); + binding.subredditNameTextViewThemePreviewActivity.setTypeface(typeface); + binding.userNameTextViewThemePreviewActivity.setTypeface(typeface); + binding.primaryTextTextViewThemePreviewActivity.setTypeface(typeface); + binding.secondaryTextTextViewThemePreviewActivity.setTypeface(typeface); + binding.subscribeSubredditChipThemePreviewActivity.setTypeface(typeface); } } @@ -420,7 +373,7 @@ public class CustomThemePreviewActivity extends AppCompatActivity implements Cus toolbar.setLayoutParams(params); TypedValue tv = new TypedValue(); if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { - ((ViewGroup.MarginLayoutParams) linearLayout.getLayoutParams()).setMargins(0, + ((ViewGroup.MarginLayoutParams) binding.linearLayoutBottomAppBarThemePreviewActivity.getLayoutParams()).setMargins(0, TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics()) + statusBarHeight, 0, 0); } } @@ -428,9 +381,9 @@ public class CustomThemePreviewActivity extends AppCompatActivity implements Cus protected void applyTabLayoutTheme(TabLayout tabLayout) { int toolbarAndTabBackgroundColor = customTheme.colorPrimary; - tabLayout.setBackgroundColor(toolbarAndTabBackgroundColor); - tabLayout.setSelectedTabIndicatorColor(customTheme.tabLayoutWithCollapsedCollapsingToolbarTabIndicator); - tabLayout.setTabTextColors(customTheme.tabLayoutWithCollapsedCollapsingToolbarTextColor, + binding.tabLayoutThemePreviewActivity.setBackgroundColor(toolbarAndTabBackgroundColor); + binding.tabLayoutThemePreviewActivity.setSelectedTabIndicatorColor(customTheme.tabLayoutWithCollapsedCollapsingToolbarTabIndicator); + binding.tabLayoutThemePreviewActivity.setTabTextColors(customTheme.tabLayoutWithCollapsedCollapsingToolbarTextColor, customTheme.tabLayoutWithCollapsedCollapsingToolbarTextColor); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeThemeActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeThemeActivity.java index 58e024bd..9b5921d4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeThemeActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeThemeActivity.java @@ -10,12 +10,7 @@ import android.view.MenuItem; import android.widget.Toast; import androidx.annotation.NonNull; -import androidx.appcompat.widget.Toolbar; -import androidx.coordinatorlayout.widget.CoordinatorLayout; -import androidx.recyclerview.widget.RecyclerView; -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.snackbar.Snackbar; @@ -27,8 +22,6 @@ 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.RedditDataRoomDatabase; @@ -38,6 +31,7 @@ import ml.docilealligator.infinityforreddit.asynctasks.InsertCustomTheme; import ml.docilealligator.infinityforreddit.customtheme.CustomTheme; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeSettingsItem; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.databinding.ActivityCustomizeThemeBinding; import ml.docilealligator.infinityforreddit.events.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.utils.CustomThemeSharedPreferencesUtils; @@ -53,16 +47,6 @@ public class CustomizeThemeActivity extends BaseActivity { private static final String CUSTOM_THEME_SETTINGS_ITEMS_STATE = "CTSIS"; private static final String THEME_NAME_STATE = "TNS"; - @BindView(R.id.coordinator_customize_theme_activity) - CoordinatorLayout coordinatorLayout; - @BindView(R.id.appbar_layout_customize_theme_activity) - AppBarLayout appBarLayout; - @BindView(R.id.collapsing_toolbar_layout_customize_theme_activity) - CollapsingToolbarLayout collapsingToolbarLayout; - @BindView(R.id.toolbar_customize_theme_activity) - Toolbar toolbar; - @BindView(R.id.recycler_view_customize_theme_activity) - RecyclerView recyclerView; @Inject @Named("default") SharedPreferences sharedPreferences; @@ -89,6 +73,7 @@ public class CustomizeThemeActivity extends BaseActivity { private boolean isPredefinedTheme; private ArrayList<CustomThemeSettingsItem> customThemeSettingsItems; private CustomizeThemeRecyclerViewAdapter adapter; + private ActivityCustomizeThemeBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { @@ -97,13 +82,12 @@ public class CustomizeThemeActivity extends BaseActivity { setImmersiveModeNotApplicable(); super.onCreate(savedInstanceState); - setContentView(R.layout.activity_customize_theme); - - ButterKnife.bind(this); + binding = ActivityCustomizeThemeBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); applyCustomTheme(); - setSupportActionBar(toolbar); + setSupportActionBar(binding.toolbarCustomizeThemeActivity); getSupportActionBar().setDisplayHomeAsUpEnabled(true); if (getIntent().getBooleanExtra(EXTRA_CREATE_THEME, false)) { @@ -152,14 +136,14 @@ public class CustomizeThemeActivity extends BaseActivity { } adapter = new CustomizeThemeRecyclerViewAdapter(this, customThemeWrapper, themeName); - recyclerView.setAdapter(adapter); + binding.recyclerViewCustomizeThemeActivity.setAdapter(adapter); adapter.setCustomThemeSettingsItem(customThemeSettingsItems); }); } else { isPredefinedTheme = getIntent().getBooleanExtra(EXTRA_IS_PREDEFIINED_THEME, false); themeName = getIntent().getStringExtra(EXTRA_THEME_NAME); adapter = new CustomizeThemeRecyclerViewAdapter(this, customThemeWrapper, themeName); - recyclerView.setAdapter(adapter); + binding.recyclerViewCustomizeThemeActivity.setAdapter(adapter); if (isPredefinedTheme) { customThemeSettingsItems = CustomThemeSettingsItem.convertCustomThemeToSettingsItem( CustomizeThemeActivity.this, @@ -167,7 +151,7 @@ public class CustomizeThemeActivity extends BaseActivity { androidVersion); adapter = new CustomizeThemeRecyclerViewAdapter(this, customThemeWrapper, themeName); - recyclerView.setAdapter(adapter); + binding.recyclerViewCustomizeThemeActivity.setAdapter(adapter); adapter.setCustomThemeSettingsItem(customThemeSettingsItems); } else { GetCustomTheme.getCustomTheme(mExecutor, new Handler(), redditDataRoomDatabase, @@ -181,7 +165,7 @@ public class CustomizeThemeActivity extends BaseActivity { } } else { adapter = new CustomizeThemeRecyclerViewAdapter(this, customThemeWrapper, themeName); - recyclerView.setAdapter(adapter); + binding.recyclerViewCustomizeThemeActivity.setAdapter(adapter); adapter.setCustomThemeSettingsItem(customThemeSettingsItems); } } @@ -209,7 +193,7 @@ public class CustomizeThemeActivity extends BaseActivity { if (adapter != null) { themeName = adapter.getThemeName(); if (themeName.equals("")) { - Snackbar.make(coordinatorLayout, R.string.no_theme_name, Snackbar.LENGTH_SHORT).show(); + Snackbar.make(binding.coordinatorCustomizeThemeActivity, R.string.no_theme_name, Snackbar.LENGTH_SHORT).show(); return true; } CustomTheme customTheme = CustomTheme.convertSettingsItemsToCustomTheme(customThemeSettingsItems, themeName); @@ -264,7 +248,7 @@ public class CustomizeThemeActivity extends BaseActivity { @Override protected void applyCustomTheme() { - applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); - coordinatorLayout.setBackgroundColor(customThemeWrapper.getBackgroundColor()); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(binding.appbarLayoutCustomizeThemeActivity, binding.collapsingToolbarLayoutCustomizeThemeActivity, binding.toolbarCustomizeThemeActivity); + binding.coordinatorCustomizeThemeActivity.setBackgroundColor(customThemeWrapper.getBackgroundColor()); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java index 1eadb47b..6a1fe4e6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java @@ -11,18 +11,13 @@ import android.os.Handler; import android.provider.MediaStore; import android.view.Menu; import android.view.MenuItem; -import android.widget.EditText; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.widget.Toolbar; -import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.content.FileProvider; 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.snackbar.Snackbar; @@ -40,8 +35,6 @@ 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.MediaMetadata; import ml.docilealligator.infinityforreddit.R; @@ -52,6 +45,7 @@ import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.bottomsheetfragments.UploadedImagesBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; +import ml.docilealligator.infinityforreddit.databinding.ActivityEditCommentBinding; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.markdown.RichTextJSONConverter; import ml.docilealligator.infinityforreddit.utils.APIUtils; @@ -77,16 +71,6 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab private static final String UPLOADED_IMAGES_STATE = "UIS"; - @BindView(R.id.coordinator_layout_edit_comment_activity) - CoordinatorLayout coordinatorLayout; - @BindView(R.id.appbar_layout_edit_comment_activity) - AppBarLayout appBarLayout; - @BindView(R.id.toolbar_edit_comment_activity) - Toolbar toolbar; - @BindView(R.id.comment_edit_text_edit_comment_activity) - EditText contentEditText; - @BindView(R.id.markdown_bottom_bar_recycler_view_edit_comment_activity) - RecyclerView markdownBottomBarRecyclerView; @Inject @Named("oauth") Retrofit mOauthRetrofit; @@ -109,6 +93,7 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab private boolean isSubmitting = false; private Uri capturedImageUri; private ArrayList<UploadedImage> uploadedImages = new ArrayList<>(); + private ActivityEditCommentBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { @@ -118,19 +103,17 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab super.onCreate(savedInstanceState); - setContentView(R.layout.activity_edit_comment); - - ButterKnife.bind(this); + binding = ActivityEditCommentBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); EventBus.getDefault().register(this); applyCustomTheme(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) { - addOnOffsetChangedListener(appBarLayout); + addOnOffsetChangedListener(binding.appbarLayoutEditCommentActivity); } - - setSupportActionBar(toolbar); + setSupportActionBar(binding.toolbarEditCommentActivity); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mFullName = getIntent().getStringExtra(EXTRA_FULLNAME); @@ -155,7 +138,7 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab } mCommentContent = sb.toString(); } - contentEditText.setText(mCommentContent); + binding.commentEditTextEditCommentActivity.setText(mCommentContent); if (savedInstanceState != null) { uploadedImages = savedInstanceState.getParcelableArrayList(UPLOADED_IMAGES_STATE); @@ -166,7 +149,7 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab @Override public void onClick(int item) { MarkdownBottomBarRecyclerViewAdapter.bindEditTextWithItemClickListener( - EditCommentActivity.this, contentEditText, item); + EditCommentActivity.this, binding.commentEditTextEditCommentActivity, item); } @Override @@ -181,12 +164,12 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab } }); - markdownBottomBarRecyclerView.setLayoutManager(new LinearLayoutManagerBugFixed(this, + binding.markdownBottomBarRecyclerViewEditCommentActivity.setLayoutManager(new LinearLayoutManagerBugFixed(this, LinearLayoutManager.HORIZONTAL, false)); - markdownBottomBarRecyclerView.setAdapter(adapter); + binding.markdownBottomBarRecyclerViewEditCommentActivity.setAdapter(adapter); - contentEditText.requestFocus(); - Utils.showKeyboard(this, new Handler(), contentEditText); + binding.commentEditTextEditCommentActivity.requestFocus(); + Utils.showKeyboard(this, new Handler(), binding.commentEditTextEditCommentActivity); } @Override @@ -206,12 +189,12 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab @Override protected void applyCustomTheme() { - coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar); - contentEditText.setTextColor(mCustomThemeWrapper.getCommentColor()); + binding.coordinatorLayoutEditCommentActivity.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(binding.appbarLayoutEditCommentActivity, null, binding.toolbarEditCommentActivity); + binding.commentEditTextEditCommentActivity.setTextColor(mCustomThemeWrapper.getCommentColor()); if (contentTypeface != null) { - contentEditText.setTypeface(contentTypeface); + binding.commentEditTextEditCommentActivity.setTypeface(contentTypeface); } } @@ -232,7 +215,7 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab public boolean onOptionsItemSelected(@NonNull MenuItem item) { if (item.getItemId() == R.id.action_preview_edit_comment_activity) { Intent intent = new Intent(this, FullMarkdownActivity.class); - intent.putExtra(FullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, contentEditText.getText().toString()); + intent.putExtra(FullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, binding.commentEditTextEditCommentActivity.getText().toString()); intent.putExtra(FullMarkdownActivity.EXTRA_SUBMIT_POST, true); startActivityForResult(intent, MARKDOWN_PREVIEW_REQUEST_CODE); } else if (item.getItemId() == R.id.action_send_edit_comment_activity) { @@ -249,9 +232,9 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab if (!isSubmitting) { isSubmitting = true; - Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_SHORT).show(); + Snackbar.make(binding.coordinatorLayoutEditCommentActivity, R.string.posting, Snackbar.LENGTH_SHORT).show(); - String content = contentEditText.getText().toString(); + String content = binding.commentEditTextEditCommentActivity.getText().toString(); Map<String, String> params = new HashMap<>(); params.put(APIUtils.THING_ID_KEY, mFullName); @@ -261,7 +244,7 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab params.put(APIUtils.TEXT_KEY, ""); } catch (JSONException e) { isSubmitting = false; - Snackbar.make(coordinatorLayout, R.string.convert_to_richtext_json_failed, Snackbar.LENGTH_SHORT).show(); + Snackbar.make(binding.coordinatorLayoutEditCommentActivity, R.string.convert_to_richtext_json_failed, Snackbar.LENGTH_SHORT).show(); return; } } else { @@ -284,14 +267,14 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab finish(); } else { - Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show(); + Snackbar.make(binding.coordinatorLayoutEditCommentActivity, R.string.post_failed, Snackbar.LENGTH_SHORT).show(); } } @Override public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) { isSubmitting = false; - Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show(); + Snackbar.make(binding.coordinatorLayoutEditCommentActivity, R.string.post_failed, Snackbar.LENGTH_SHORT).show(); } }); @@ -318,10 +301,10 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab return; } Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit, - mAccessToken, contentEditText, coordinatorLayout, data.getData(), uploadedImages); + mAccessToken, binding.commentEditTextEditCommentActivity, binding.coordinatorLayoutEditCommentActivity, data.getData(), uploadedImages); } else if (requestCode == CAPTURE_IMAGE_REQUEST_CODE) { Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit, - mAccessToken, contentEditText, coordinatorLayout, capturedImageUri, uploadedImages); + mAccessToken, binding.commentEditTextEditCommentActivity, binding.coordinatorLayoutEditCommentActivity, capturedImageUri, uploadedImages); } else if (requestCode == MARKDOWN_PREVIEW_REQUEST_CODE) { editComment(); } @@ -339,7 +322,7 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab if (isSubmitting) { promptAlertDialog(R.string.exit_when_submit, R.string.exit_when_edit_comment_detail); } else { - if (contentEditText.getText().toString().equals(mCommentContent)) { + if (binding.commentEditTextEditCommentActivity.getText().toString().equals(mCommentContent)) { finish(); } else { promptAlertDialog(R.string.discard, R.string.discard_detail); @@ -384,15 +367,15 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab @Override public void insertImageUrl(UploadedImage uploadedImage) { - int start = Math.max(contentEditText.getSelectionStart(), 0); - int end = Math.max(contentEditText.getSelectionEnd(), 0); + int start = Math.max(binding.commentEditTextEditCommentActivity.getSelectionStart(), 0); + int end = Math.max(binding.commentEditTextEditCommentActivity.getSelectionEnd(), 0); int realStart = Math.min(start, end); - if (realStart > 0 && contentEditText.getText().toString().charAt(realStart - 1) != '\n') { - contentEditText.getText().replace(realStart, Math.max(start, end), + if (realStart > 0 && binding.commentEditTextEditCommentActivity.getText().toString().charAt(realStart - 1) != '\n') { + binding.commentEditTextEditCommentActivity.getText().replace(realStart, Math.max(start, end), "\n![](" + uploadedImage.imageUrlOrKey + ")\n", 0, "\n![]()\n".length() + uploadedImage.imageUrlOrKey.length()); } else { - contentEditText.getText().replace(realStart, Math.max(start, end), + binding.commentEditTextEditCommentActivity.getText().replace(realStart, Math.max(start, end), "![](" + uploadedImage.imageUrlOrKey + ")\n", 0, "![]()\n".length() + uploadedImage.imageUrlOrKey.length()); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditMultiRedditActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditMultiRedditActivity.java index 679f5fb7..a14f4460 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditMultiRedditActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditMultiRedditActivity.java @@ -9,20 +9,11 @@ import android.os.Handler; import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.widget.EditText; -import android.widget.LinearLayout; -import android.widget.ProgressBar; -import android.widget.Switch; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.widget.Toolbar; -import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.view.inputmethod.EditorInfoCompat; -import com.google.android.material.appbar.AppBarLayout; -import com.google.android.material.appbar.CollapsingToolbarLayout; import com.google.android.material.snackbar.Snackbar; import java.util.concurrent.Executor; @@ -30,14 +21,13 @@ 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.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.slidr.Slidr; +import ml.docilealligator.infinityforreddit.databinding.ActivityEditMultiRedditBinding; import ml.docilealligator.infinityforreddit.multireddit.EditMultiReddit; import ml.docilealligator.infinityforreddit.multireddit.FetchMultiRedditInfo; import ml.docilealligator.infinityforreddit.multireddit.MultiReddit; @@ -51,34 +41,6 @@ public class EditMultiRedditActivity extends BaseActivity { private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 1; private static final String MULTI_REDDIT_STATE = "MRS"; private static final String MULTI_PATH_STATE = "MPS"; - @BindView(R.id.coordinator_layout_edit_multi_reddit_activity) - CoordinatorLayout coordinatorLayout; - @BindView(R.id.appbar_layout_edit_multi_reddit_activity) - AppBarLayout appBarLayout; - @BindView(R.id.collapsing_toolbar_layout_edit_multi_reddit_activity) - CollapsingToolbarLayout collapsingToolbarLayout; - @BindView(R.id.toolbar_edit_multi_reddit_activity) - Toolbar toolbar; - @BindView(R.id.progress_bar_edit_multi_reddit_activity) - ProgressBar progressBar; - @BindView(R.id.linear_layout_edit_multi_reddit_activity) - LinearLayout linearLayout; - @BindView(R.id.multi_reddit_name_edit_text_edit_multi_reddit_activity) - EditText nameEditText; - @BindView(R.id.divider_1_edit_multi_reddit_activity) - View divider1; - @BindView(R.id.description_edit_text_edit_multi_reddit_activity) - EditText descriptionEditText; - @BindView(R.id.divider_2_edit_multi_reddit_activity) - View divider2; - @BindView(R.id.visibility_wrapper_linear_layout_edit_multi_reddit_activity) - LinearLayout visibilityLinearLayout; - @BindView(R.id.visibility_text_view_edit_multi_reddit_activity) - TextView visibilityTextView; - @BindView(R.id.visibility_switch_edit_multi_reddit_activity) - Switch visibilitySwitch; - @BindView(R.id.select_subreddit_text_view_edit_multi_reddit_activity) - TextView selectSubredditTextView; @Inject @Named("oauth") Retrofit mRetrofit; @@ -96,6 +58,7 @@ public class EditMultiRedditActivity extends BaseActivity { Executor mExecutor; private MultiReddit multiReddit; private String multipath; + private ActivityEditMultiRedditBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { @@ -104,9 +67,8 @@ public class EditMultiRedditActivity extends BaseActivity { setImmersiveModeNotApplicable(); super.onCreate(savedInstanceState); - setContentView(R.layout.activity_edit_multi_reddit); - - ButterKnife.bind(this); + binding = ActivityEditMultiRedditBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); applyCustomTheme(); @@ -115,17 +77,17 @@ public class EditMultiRedditActivity extends BaseActivity { } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) { - addOnOffsetChangedListener(appBarLayout); + addOnOffsetChangedListener(binding.appbarLayoutEditMultiRedditActivity); } - setSupportActionBar(toolbar); + setSupportActionBar(binding.toolbarEditMultiRedditActivity); getSupportActionBar().setDisplayHomeAsUpEnabled(true); if (accountName.equals(Account.ANONYMOUS_ACCOUNT)) { - visibilityLinearLayout.setVisibility(View.GONE); + binding.visibilityWrapperLinearLayoutEditMultiRedditActivity.setVisibility(View.GONE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - nameEditText.setImeOptions(nameEditText.getImeOptions() | EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING); - descriptionEditText.setImeOptions(descriptionEditText.getImeOptions() | EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING); + binding.multiRedditNameEditTextEditMultiRedditActivity.setImeOptions(binding.multiRedditNameEditTextEditMultiRedditActivity.getImeOptions() | EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING); + binding.descriptionEditTextEditMultiRedditActivity.setImeOptions(binding.descriptionEditTextEditMultiRedditActivity.getImeOptions() | EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING); } } @@ -147,10 +109,10 @@ public class EditMultiRedditActivity extends BaseActivity { @Override public void success(MultiReddit multiReddit) { EditMultiRedditActivity.this.multiReddit = multiReddit; - progressBar.setVisibility(View.GONE); - linearLayout.setVisibility(View.VISIBLE); - nameEditText.setText(multiReddit.getDisplayName()); - descriptionEditText.setText(multiReddit.getDescription()); + binding.progressBarEditMultiRedditActivity.setVisibility(View.GONE); + binding.linearLayoutEditMultiRedditActivity.setVisibility(View.VISIBLE); + binding.multiRedditNameEditTextEditMultiRedditActivity.setText(multiReddit.getDisplayName()); + binding.descriptionEditTextEditMultiRedditActivity.setText(multiReddit.getDescription()); } @Override @@ -163,28 +125,27 @@ public class EditMultiRedditActivity extends BaseActivity { @Override public void success(MultiReddit multiReddit) { EditMultiRedditActivity.this.multiReddit = multiReddit; - progressBar.setVisibility(View.GONE); - linearLayout.setVisibility(View.VISIBLE); - nameEditText.setText(multiReddit.getDisplayName()); - descriptionEditText.setText(multiReddit.getDescription()); - visibilitySwitch.setChecked(!multiReddit.getVisibility().equals("public")); + binding.progressBarEditMultiRedditActivity.setVisibility(View.GONE); + binding.linearLayoutEditMultiRedditActivity.setVisibility(View.VISIBLE); + binding.multiRedditNameEditTextEditMultiRedditActivity.setText(multiReddit.getDisplayName()); + binding.descriptionEditTextEditMultiRedditActivity.setText(multiReddit.getDescription()); + binding.visibilitySwitchEditMultiRedditActivity.setChecked(!multiReddit.getVisibility().equals("public")); } @Override public void failed() { - Snackbar.make(coordinatorLayout, R.string.cannot_fetch_multireddit, Snackbar.LENGTH_SHORT).show(); + Snackbar.make(binding.coordinatorLayoutEditMultiRedditActivity, R.string.cannot_fetch_multireddit, Snackbar.LENGTH_SHORT).show(); } }); } } else { - progressBar.setVisibility(View.GONE); - linearLayout.setVisibility(View.VISIBLE); - nameEditText.setText(multiReddit.getDisplayName()); - descriptionEditText.setText(multiReddit.getDescription()); - visibilitySwitch.setChecked(!multiReddit.getVisibility().equals("public")); + binding.progressBarEditMultiRedditActivity.setVisibility(View.GONE); + binding.linearLayoutEditMultiRedditActivity.setVisibility(View.VISIBLE); + binding.multiRedditNameEditTextEditMultiRedditActivity.setText(multiReddit.getDisplayName()); + binding.descriptionEditTextEditMultiRedditActivity.setText(multiReddit.getDescription()); + binding.visibilitySwitchEditMultiRedditActivity.setChecked(!multiReddit.getVisibility().equals("public")); } - - selectSubredditTextView.setOnClickListener(view -> { + binding.selectSubredditTextViewEditMultiRedditActivity.setOnClickListener(view -> { Intent intent = new Intent(EditMultiRedditActivity.this, SelectedSubredditsAndUsersActivity.class); if (multiReddit.getSubreddits() != null) { intent.putStringArrayListExtra(SelectedSubredditsAndUsersActivity.EXTRA_SELECTED_SUBREDDITS, multiReddit.getSubreddits()); @@ -207,16 +168,16 @@ public class EditMultiRedditActivity extends BaseActivity { finish(); return true; } else if (itemId == R.id.action_save_edit_multi_reddit_activity) { - if (nameEditText.getText() == null || nameEditText.getText().toString().equals("")) { - Snackbar.make(coordinatorLayout, R.string.no_multi_reddit_name, Snackbar.LENGTH_SHORT).show(); + if (binding.multiRedditNameEditTextEditMultiRedditActivity.getText() == null || binding.multiRedditNameEditTextEditMultiRedditActivity.getText().toString().equals("")) { + Snackbar.make(binding.coordinatorLayoutEditMultiRedditActivity, R.string.no_multi_reddit_name, Snackbar.LENGTH_SHORT).show(); return true; } if (accountName.equals(Account.ANONYMOUS_ACCOUNT)) { - String name = nameEditText.getText().toString(); + String name = binding.multiRedditNameEditTextEditMultiRedditActivity.getText().toString(); multiReddit.setDisplayName(name); multiReddit.setName(name); - multiReddit.setDescription(descriptionEditText.getText().toString()); + multiReddit.setDescription(binding.descriptionEditTextEditMultiRedditActivity.getText().toString()); EditMultiReddit.anonymousEditMultiReddit(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddit, new EditMultiReddit.EditMultiRedditListener() { @Override @@ -230,8 +191,8 @@ public class EditMultiRedditActivity extends BaseActivity { } }); } else { - String jsonModel = new MultiRedditJSONModel(nameEditText.getText().toString(), descriptionEditText.getText().toString(), - visibilitySwitch.isChecked(), multiReddit.getSubreddits()).createJSONModel(); + String jsonModel = new MultiRedditJSONModel(binding.multiRedditNameEditTextEditMultiRedditActivity.getText().toString(), binding.descriptionEditTextEditMultiRedditActivity.getText().toString(), + binding.visibilitySwitchEditMultiRedditActivity.isChecked(), multiReddit.getSubreddits()).createJSONModel(); EditMultiReddit.editMultiReddit(mRetrofit, accessToken, multiReddit.getPath(), jsonModel, new EditMultiReddit.EditMultiRedditListener() { @Override @@ -241,7 +202,7 @@ public class EditMultiRedditActivity extends BaseActivity { @Override public void failed() { - Snackbar.make(coordinatorLayout, R.string.edit_multi_reddit_failed, Snackbar.LENGTH_SHORT).show(); + Snackbar.make(binding.coordinatorLayoutEditMultiRedditActivity, R.string.edit_multi_reddit_failed, Snackbar.LENGTH_SHORT).show(); } }); } @@ -285,23 +246,23 @@ public class EditMultiRedditActivity extends BaseActivity { @Override protected void applyCustomTheme() { - coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); - progressBar.setIndeterminateTintList(ColorStateList.valueOf(mCustomThemeWrapper.getColorAccent())); + binding.coordinatorLayoutEditMultiRedditActivity.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(binding.appbarLayoutEditMultiRedditActivity, binding.collapsingToolbarLayoutEditMultiRedditActivity, binding.toolbarEditMultiRedditActivity); + binding.progressBarEditMultiRedditActivity.setIndeterminateTintList(ColorStateList.valueOf(mCustomThemeWrapper.getColorAccent())); int primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor(); int secondaryTextColor = mCustomThemeWrapper.getSecondaryTextColor(); - nameEditText.setTextColor(primaryTextColor); - nameEditText.setHintTextColor(secondaryTextColor); + binding.multiRedditNameEditTextEditMultiRedditActivity.setTextColor(primaryTextColor); + binding.multiRedditNameEditTextEditMultiRedditActivity.setHintTextColor(secondaryTextColor); int dividerColor = mCustomThemeWrapper.getDividerColor(); - divider1.setBackgroundColor(dividerColor); - divider2.setBackgroundColor(dividerColor); - descriptionEditText.setTextColor(primaryTextColor); - descriptionEditText.setHintTextColor(secondaryTextColor); - visibilityTextView.setTextColor(primaryTextColor); - selectSubredditTextView.setTextColor(primaryTextColor); + binding.divider1EditMultiRedditActivity.setBackgroundColor(dividerColor); + binding.divider2EditMultiRedditActivity.setBackgroundColor(dividerColor); + binding.descriptionEditTextEditMultiRedditActivity.setTextColor(primaryTextColor); + binding.descriptionEditTextEditMultiRedditActivity.setHintTextColor(secondaryTextColor); + binding.visibilityTextViewEditMultiRedditActivity.setTextColor(primaryTextColor); + binding.selectSubredditTextViewEditMultiRedditActivity.setTextColor(primaryTextColor); if (typeface != null) { - Utils.setFontToAllTextViews(coordinatorLayout, typeface); + Utils.setFontToAllTextViews(binding.coordinatorLayoutEditMultiRedditActivity, typeface); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java index 7f668adc..acb06634 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java @@ -11,19 +11,12 @@ import android.os.Handler; import android.provider.MediaStore; import android.view.Menu; import android.view.MenuItem; -import android.view.View; -import android.widget.EditText; -import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.widget.Toolbar; -import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.content.FileProvider; -import androidx.recyclerview.widget.RecyclerView; -import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.snackbar.Snackbar; @@ -40,8 +33,6 @@ 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.UploadImageEnabledActivity; @@ -52,6 +43,7 @@ import ml.docilealligator.infinityforreddit.bottomsheetfragments.UploadedImagesB import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; import ml.docilealligator.infinityforreddit.customviews.slidr.Slidr; +import ml.docilealligator.infinityforreddit.databinding.ActivityEditPostBinding; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.utils.APIUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; @@ -73,20 +65,6 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled private static final String UPLOADED_IMAGES_STATE = "UIS"; - @BindView(R.id.coordinator_layout_edit_post_activity) - CoordinatorLayout coordinatorLayout; - @BindView(R.id.appbar_layout_edit_post_activity) - AppBarLayout appBarLayout; - @BindView(R.id.toolbar_edit_post_activity) - Toolbar toolbar; - @BindView(R.id.post_title_text_view_edit_post_activity) - TextView titleTextView; - @BindView(R.id.divider_edit_post_activity) - View divider; - @BindView(R.id.post_text_content_edit_text_edit_post_activity) - EditText contentEditText; - @BindView(R.id.markdown_bottom_bar_recycler_view_edit_post_activity) - RecyclerView markdownBottomBarRecyclerView; @Inject @Named("oauth") Retrofit mOauthRetrofit; @@ -109,6 +87,7 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled private boolean isSubmitting = false; private Uri capturedImageUri; private ArrayList<UploadedImage> uploadedImages = new ArrayList<>(); + private ActivityEditPostBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { @@ -117,10 +96,8 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled setImmersiveModeNotApplicable(); super.onCreate(savedInstanceState); - - setContentView(R.layout.activity_edit_post); - - ButterKnife.bind(this); + binding = ActivityEditPostBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); EventBus.getDefault().register(this); @@ -131,17 +108,17 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) { - addOnOffsetChangedListener(appBarLayout); + addOnOffsetChangedListener(binding.appbarLayoutEditPostActivity); } - setSupportActionBar(toolbar); + setSupportActionBar(binding.toolbarEditPostActivity); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mFullName = getIntent().getStringExtra(EXTRA_FULLNAME); mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); - titleTextView.setText(getIntent().getStringExtra(EXTRA_TITLE)); + binding.postTitleTextViewEditPostActivity.setText(getIntent().getStringExtra(EXTRA_TITLE)); mPostContent = getIntent().getStringExtra(EXTRA_CONTENT); - contentEditText.setText(mPostContent); + binding.postContentEditTextEditPostActivity.setText(mPostContent); if (savedInstanceState != null) { uploadedImages = savedInstanceState.getParcelableArrayList(UPLOADED_IMAGES_STATE); @@ -152,7 +129,7 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled @Override public void onClick(int item) { MarkdownBottomBarRecyclerViewAdapter.bindEditTextWithItemClickListener( - EditPostActivity.this, contentEditText, item); + EditPostActivity.this, binding.postContentEditTextEditPostActivity, item); } @Override @@ -167,12 +144,12 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled } }); - markdownBottomBarRecyclerView.setLayoutManager(new LinearLayoutManagerBugFixed(this, + binding.markdownBottomBarRecyclerViewEditPostActivity.setLayoutManager(new LinearLayoutManagerBugFixed(this, LinearLayoutManagerBugFixed.HORIZONTAL, false)); - markdownBottomBarRecyclerView.setAdapter(adapter); + binding.markdownBottomBarRecyclerViewEditPostActivity.setAdapter(adapter); - contentEditText.requestFocus(); - Utils.showKeyboard(this, new Handler(), contentEditText); + binding.postContentEditTextEditPostActivity.requestFocus(); + Utils.showKeyboard(this, new Handler(), binding.postContentEditTextEditPostActivity); } @Override @@ -192,17 +169,17 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled @Override protected void applyCustomTheme() { - coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar); - titleTextView.setTextColor(mCustomThemeWrapper.getPostTitleColor()); - divider.setBackgroundColor(mCustomThemeWrapper.getPostTitleColor()); - contentEditText.setTextColor(mCustomThemeWrapper.getPostContentColor()); + binding.coordinatorLayoutEditPostActivity.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(binding.appbarLayoutEditPostActivity, null, binding.toolbarEditPostActivity); + binding.postTitleTextViewEditPostActivity.setTextColor(mCustomThemeWrapper.getPostTitleColor()); + binding.dividerEditPostActivity.setBackgroundColor(mCustomThemeWrapper.getPostTitleColor()); + binding.postContentEditTextEditPostActivity.setTextColor(mCustomThemeWrapper.getPostContentColor()); if (titleTypeface != null) { - titleTextView.setTypeface(titleTypeface); + binding.postTitleTextViewEditPostActivity.setTypeface(titleTypeface); } if (contentTypeface != null) { - contentEditText.setTypeface(contentTypeface); + binding.postContentEditTextEditPostActivity.setTypeface(contentTypeface); } } @@ -223,7 +200,7 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled public boolean onOptionsItemSelected(@NonNull MenuItem item) { if (item.getItemId() == R.id.action_preview_edit_post_activity) { Intent intent = new Intent(this, FullMarkdownActivity.class); - intent.putExtra(FullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, contentEditText.getText().toString()); + intent.putExtra(FullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, binding.postContentEditTextEditPostActivity.getText().toString()); intent.putExtra(FullMarkdownActivity.EXTRA_SUBMIT_POST, true); startActivityForResult(intent, MARKDOWN_PREVIEW_REQUEST_CODE); } else if (item.getItemId() == R.id.action_send_edit_post_activity) { @@ -240,11 +217,11 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled if (!isSubmitting) { isSubmitting = true; - Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_SHORT).show(); + Snackbar.make(binding.coordinatorLayoutEditPostActivity, R.string.posting, Snackbar.LENGTH_SHORT).show(); Map<String, String> params = new HashMap<>(); params.put(APIUtils.THING_ID_KEY, mFullName); - params.put(APIUtils.TEXT_KEY, contentEditText.getText().toString()); + params.put(APIUtils.TEXT_KEY, binding.postContentEditTextEditPostActivity.getText().toString()); mOauthRetrofit.create(RedditAPI.class) .editPostOrComment(APIUtils.getOAuthHeader(mAccessToken), params) @@ -261,7 +238,7 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled @Override public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) { isSubmitting = false; - Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show(); + Snackbar.make(binding.coordinatorLayoutEditPostActivity, R.string.post_failed, Snackbar.LENGTH_SHORT).show(); } }); @@ -278,10 +255,10 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled return; } Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit, - mAccessToken, contentEditText, coordinatorLayout, data.getData(), uploadedImages); + mAccessToken, binding.postContentEditTextEditPostActivity, binding.coordinatorLayoutEditPostActivity, data.getData(), uploadedImages); } else if (requestCode == CAPTURE_IMAGE_REQUEST_CODE) { Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit, - mAccessToken, contentEditText, coordinatorLayout, capturedImageUri, uploadedImages); + mAccessToken, binding.postContentEditTextEditPostActivity, binding.coordinatorLayoutEditPostActivity, capturedImageUri, uploadedImages); } else if (requestCode == MARKDOWN_PREVIEW_REQUEST_CODE) { editPost(); } @@ -309,7 +286,7 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled if (isSubmitting) { promptAlertDialog(R.string.exit_when_submit, R.string.exit_when_edit_post_detail); } else { - if (contentEditText.getText().toString().equals(mPostContent)) { + if (binding.postContentEditTextEditPostActivity.getText().toString().equals(mPostContent)) { finish(); } else { promptAlertDialog(R.string.discard, R.string.discard_detail); @@ -354,9 +331,9 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled @Override public void insertImageUrl(UploadedImage uploadedImage) { - int start = Math.max(contentEditText.getSelectionStart(), 0); - int end = Math.max(contentEditText.getSelectionEnd(), 0); - contentEditText.getText().replace(Math.min(start, end), Math.max(start, end), + int start = Math.max(binding.postContentEditTextEditPostActivity.getSelectionStart(), 0); + int end = Math.max(binding.postContentEditTextEditPostActivity.getSelectionEnd(), 0); + binding.postContentEditTextEditPostActivity.getText().replace(Math.min(start, end), Math.max(start, end), "[" + uploadedImage.imageName + "](" + uploadedImage.imageUrlOrKey + ")", 0, "[]()".length() + uploadedImage.imageName.length() + uploadedImage.imageUrlOrKey.length()); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditProfileActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditProfileActivity.java index 230c0b90..44010326 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditProfileActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditProfileActivity.java @@ -45,6 +45,7 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.slidr.Slidr; +import ml.docilealligator.infinityforreddit.databinding.ActivityEditProfileBinding; import ml.docilealligator.infinityforreddit.events.SubmitChangeAvatarEvent; import ml.docilealligator.infinityforreddit.events.SubmitChangeBannerEvent; import ml.docilealligator.infinityforreddit.events.SubmitSaveProfileEvent; @@ -61,29 +62,6 @@ public class EditProfileActivity extends BaseActivity { private static final int PICK_IMAGE_BANNER_REQUEST_CODE = 0x401; private static final int PICK_IMAGE_AVATAR_REQUEST_CODE = 0x402; - @BindView(R.id.root_layout_view_edit_profile_activity) - CoordinatorLayout coordinatorLayout; - @BindView(R.id.content_view_edit_profile_activity) - LinearLayout content; - @BindView(R.id.collapsing_toolbar_layout_edit_profile_activity) - CollapsingToolbarLayout collapsingToolbarLayout; - @BindView(R.id.appbar_layout_view_edit_profile_activity) - AppBarLayout appBarLayout; - @BindView(R.id.toolbar_view_edit_profile_activity) - MaterialToolbar toolbar; - @BindView(R.id.image_view_banner_edit_profile_activity) - GifImageView bannerImageView; - @BindView(R.id.image_view_avatar_edit_profile_activity) - GifImageView avatarImageView; - @BindView(R.id.image_view_change_banner_edit_profile_activity) - ImageView changeBanner; - @BindView(R.id.image_view_change_avatar_edit_profile_activity) - ImageView changeAvatar; - @BindView(R.id.edit_text_display_name_edit_profile_activity) - EditText editTextDisplayName; - @BindView(R.id.edit_text_about_you_edit_profile_activity) - EditText editTextAboutYou; - @Inject @Named("current_account") SharedPreferences mCurrentAccountSharedPreferences; @@ -97,6 +75,7 @@ public class EditProfileActivity extends BaseActivity { RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject CustomThemeWrapper mCustomThemeWrapper; + private ActivityEditProfileBinding binding; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -105,28 +84,27 @@ public class EditProfileActivity extends BaseActivity { setImmersiveModeNotApplicable(); super.onCreate(savedInstanceState); - setContentView(R.layout.activity_edit_profile); - - ButterKnife.bind(this); + binding = ActivityEditProfileBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); EventBus.getDefault().register(this); applyCustomTheme(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) { - addOnOffsetChangedListener(appBarLayout); + addOnOffsetChangedListener(binding.appbarLayoutViewEditProfileActivity); } - setSupportActionBar(toolbar); + setSupportActionBar(binding.toolbarViewEditProfileActivity); if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK, true)) { Slidr.attach(this); } - changeBanner.setOnClickListener(view -> { + binding.imageViewChangeBannerEditProfileActivity.setOnClickListener(view -> { startPickImage(PICK_IMAGE_BANNER_REQUEST_CODE); }); - changeAvatar.setOnClickListener(view -> { + binding.imageViewChangeAvatarEditProfileActivity.setOnClickListener(view -> { startPickImage(PICK_IMAGE_AVATAR_REQUEST_CODE); }); @@ -142,18 +120,18 @@ public class EditProfileActivity extends BaseActivity { } // BANNER final String userBanner = userData.getBanner(); - LayoutParams cBannerLp = (LayoutParams) changeBanner.getLayoutParams(); + LayoutParams cBannerLp = (LayoutParams) binding.imageViewChangeBannerEditProfileActivity.getLayoutParams(); if (userBanner == null || userBanner.isEmpty()) { - changeBanner.setLongClickable(false); + binding.imageViewChangeBannerEditProfileActivity.setLongClickable(false); cBannerLp.gravity = Gravity.CENTER; - changeBanner.setLayoutParams(cBannerLp); - changeBanner.setOnLongClickListener(v -> false); + binding.imageViewChangeBannerEditProfileActivity.setLayoutParams(cBannerLp); + binding.imageViewChangeBannerEditProfileActivity.setOnLongClickListener(v -> false); } else { - changeBanner.setLongClickable(true); + binding.imageViewChangeBannerEditProfileActivity.setLongClickable(true); cBannerLp.gravity = Gravity.END | Gravity.BOTTOM; - changeBanner.setLayoutParams(cBannerLp); - glide.load(userBanner).into(bannerImageView); - changeBanner.setOnLongClickListener(view -> { + binding.imageViewChangeBannerEditProfileActivity.setLayoutParams(cBannerLp); + glide.load(userBanner).into(binding.imageViewBannerEditProfileActivity); + binding.imageViewChangeBannerEditProfileActivity.setOnLongClickListener(view -> { if (accountName.equals(Account.ANONYMOUS_ACCOUNT)) { return false; } @@ -170,7 +148,7 @@ public class EditProfileActivity extends BaseActivity { Toast.makeText(EditProfileActivity.this, R.string.message_remove_banner_success, Toast.LENGTH_SHORT).show(); - bannerImageView.setImageDrawable(null);// + binding.imageViewBannerEditProfileActivity.setImageDrawable(null);// } @Override @@ -189,14 +167,14 @@ public class EditProfileActivity extends BaseActivity { final String userAvatar = userData.getIconUrl(); glide.load(userAvatar) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(216, 0))) - .into(avatarImageView); - LayoutParams cAvatarLp = (LayoutParams) changeAvatar.getLayoutParams(); + .into(binding.imageViewAvatarEditProfileActivity); + LayoutParams cAvatarLp = (LayoutParams) binding.imageViewChangeAvatarEditProfileActivity.getLayoutParams(); if (userAvatar.contains("avatar_default_")) { - changeAvatar.setLongClickable(false); - changeAvatar.setOnLongClickListener(v -> false); + binding.imageViewChangeAvatarEditProfileActivity.setLongClickable(false); + binding.imageViewChangeAvatarEditProfileActivity.setOnLongClickListener(v -> false); } else { - changeAvatar.setLongClickable(true); - changeAvatar.setOnLongClickListener(view -> { + binding.imageViewChangeAvatarEditProfileActivity.setLongClickable(true); + binding.imageViewChangeAvatarEditProfileActivity.setOnLongClickListener(view -> { if (accountName.equals(Account.ANONYMOUS_ACCOUNT)) { return false; } @@ -228,8 +206,8 @@ public class EditProfileActivity extends BaseActivity { }); } - editTextAboutYou.setText(userData.getDescription()); - editTextDisplayName.setText(userData.getTitle()); + binding.editTextAboutYouEditProfileActivity.setText(userData.getDescription()); + binding.editTextDisplayNameEditProfileActivity.setText(userData.getTitle()); }); } @@ -273,12 +251,12 @@ public class EditProfileActivity extends BaseActivity { return true; } else if (itemId == R.id.action_save_edit_profile_activity) { String displayName = null; - if (editTextDisplayName.getText() != null) { - displayName = editTextDisplayName.getText().toString(); + if (binding.editTextDisplayNameEditProfileActivity.getText() != null) { + displayName = binding.editTextDisplayNameEditProfileActivity.getText().toString(); } String aboutYou = null; - if (editTextAboutYou.getText() != null) { - aboutYou = editTextAboutYou.getText().toString(); + if (binding.editTextAboutYouEditProfileActivity.getText() != null) { + aboutYou = binding.editTextAboutYouEditProfileActivity.getText().toString(); } if (aboutYou == null || displayName == null) return false; // @@ -343,11 +321,11 @@ public class EditProfileActivity extends BaseActivity { @Override protected void applyCustomTheme() { - applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); - coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - changeColorTextView(content, mCustomThemeWrapper.getPrimaryTextColor()); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(binding.appbarLayoutViewEditProfileActivity, binding.collapsingToolbarLayoutEditProfileActivity, binding.toolbarViewEditProfileActivity); + binding.rootLayoutViewEditProfileActivity.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); + changeColorTextView(binding.contentViewEditProfileActivity, mCustomThemeWrapper.getPrimaryTextColor()); if (typeface != null) { - Utils.setFontToAllTextViews(coordinatorLayout, typeface); + Utils.setFontToAllTextViews(binding.rootLayoutViewEditProfileActivity, typeface); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/UploadedImagesBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/UploadedImagesBottomSheetFragment.java index 3fa0aaff..0acbd12c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/UploadedImagesBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/UploadedImagesBottomSheetFragment.java @@ -8,24 +8,18 @@ import android.view.View; import android.view.ViewGroup; import androidx.annotation.NonNull; -import androidx.recyclerview.widget.RecyclerView; -import com.google.android.material.button.MaterialButton; - -import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.UploadImageEnabledActivity; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.adapters.UploadedImagesRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; +import ml.docilealligator.infinityforreddit.databinding.FragmentUploadedImagesBottomSheetBinding; import ml.docilealligator.infinityforreddit.utils.Utils; public class UploadedImagesBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment { public static final String EXTRA_UPLOADED_IMAGES = "EUI"; - private MaterialButton uploadButton; - private MaterialButton captureButton; - private RecyclerView uploadedImagesRecyclerView; private UploadedImagesRecyclerViewAdapter adapter; private UploadImageEnabledActivity activity; @@ -37,36 +31,33 @@ public class UploadedImagesBottomSheetFragment extends LandscapeExpandedRoundedB public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment - View rootView = inflater.inflate(R.layout.fragment_uploaded_images_bottom_sheet, container, false); - uploadButton = rootView.findViewById(R.id.upload_button_uploaded_images_bottom_sheet_fragment); - captureButton = rootView.findViewById(R.id.capture_button_uploaded_images_bottom_sheet_fragment); + FragmentUploadedImagesBottomSheetBinding binding = FragmentUploadedImagesBottomSheetBinding.inflate(inflater, container, false); - uploadButton.setOnClickListener(view -> { + binding.uploadButtonUploadedImagesBottomSheetFragment.setOnClickListener(view -> { activity.uploadImage(); dismiss(); }); - captureButton.setOnClickListener(view -> { + binding.captureButtonUploadedImagesBottomSheetFragment.setOnClickListener(view -> { activity.captureImage(); dismiss(); }); - uploadedImagesRecyclerView = rootView.findViewById(R.id.recycler_view_uploaded_images_bottom_sheet); adapter = new UploadedImagesRecyclerViewAdapter(getActivity(), getArguments().getParcelableArrayList(EXTRA_UPLOADED_IMAGES), uploadedImage -> { activity.insertImageUrl(uploadedImage); dismiss(); }); - uploadedImagesRecyclerView.setAdapter(adapter); + binding.recyclerViewUploadedImagesBottomSheet.setAdapter(adapter); Activity baseActivity = getActivity(); if (baseActivity instanceof BaseActivity) { if (((BaseActivity) activity).typeface != null) { - Utils.setFontToAllTextViews(rootView, ((BaseActivity) activity).typeface); + Utils.setFontToAllTextViews(binding.getRoot(), ((BaseActivity) activity).typeface); } } - return rootView; + return binding.getRoot(); } @Override diff --git a/app/src/main/res/layout/activity_edit_post.xml b/app/src/main/res/layout/activity_edit_post.xml index b2bff825..267d1cfe 100644 --- a/app/src/main/res/layout/activity_edit_post.xml +++ b/app/src/main/res/layout/activity_edit_post.xml @@ -55,7 +55,7 @@ android:layout_height="1dp" /> <EditText - android:id="@+id/post_text_content_edit_text_edit_post_activity" + android:id="@+id/post_content_edit_text_edit_post_activity" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="top" |