Skip to content

Commit

Permalink
Continue migrating to view binding.
Browse files Browse the repository at this point in the history
  • Loading branch information
Docile-Alligator committed Jan 13, 2024
1 parent de7bc2d commit cec83ca
Show file tree
Hide file tree
Showing 2 changed files with 215 additions and 365 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,11 @@
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
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.ArrayList;
Expand All @@ -29,14 +21,13 @@
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.ActivityCreateMultiRedditBinding;
import ml.docilealligator.infinityforreddit.multireddit.CreateMultiReddit;
import ml.docilealligator.infinityforreddit.multireddit.MultiRedditJSONModel;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
Expand All @@ -47,30 +38,6 @@ public class CreateMultiRedditActivity extends BaseActivity {

private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 1;
private static final String SELECTED_SUBREDDITS_STATE = "SSS";
@BindView(R.id.coordinator_layout_create_multi_reddit_activity)
CoordinatorLayout coordinatorLayout;
@BindView(R.id.appbar_layout_create_multi_reddit_activity)
AppBarLayout appBarLayout;
@BindView(R.id.collapsing_toolbar_layout_create_multi_reddit_activity)
CollapsingToolbarLayout collapsingToolbarLayout;
@BindView(R.id.toolbar_create_multi_reddit_activity)
Toolbar toolbar;
@BindView(R.id.multi_reddit_name_edit_text_create_multi_reddit_activity)
EditText nameEditText;
@BindView(R.id.divider_1_create_multi_reddit_activity)
View divider1;
@BindView(R.id.description_edit_text_create_multi_reddit_activity)
EditText descriptionEditText;
@BindView(R.id.divider_2_create_multi_reddit_activity)
View divider2;
@BindView(R.id.visibility_wrapper_linear_layout_create_multi_reddit_activity)
LinearLayout visibilityLinearLayout;
@BindView(R.id.visibility_text_view_create_multi_reddit_activity)
TextView visibilityTextView;
@BindView(R.id.visibility_switch_create_multi_reddit_activity)
Switch visibilitySwitch;
@BindView(R.id.select_subreddit_text_view_create_multi_reddit_activity)
TextView selectSubredditTextView;
@Inject
@Named("oauth")
Retrofit mOauthRetrofit;
Expand All @@ -86,6 +53,7 @@ public class CreateMultiRedditActivity extends BaseActivity {
CustomThemeWrapper mCustomThemeWrapper;
@Inject
Executor mExecutor;
private ActivityCreateMultiRedditBinding binding;
private String mAccessToken;
private String mAccountName;
private ArrayList<String> mSubreddits;
Expand All @@ -97,9 +65,8 @@ protected void onCreate(Bundle savedInstanceState) {
setImmersiveModeNotApplicable();

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_multi_reddit);

ButterKnife.bind(this);
binding = ActivityCreateMultiRedditBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

applyCustomTheme();

Expand All @@ -108,20 +75,20 @@ protected void onCreate(Bundle savedInstanceState) {
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) {
addOnOffsetChangedListener(appBarLayout);
addOnOffsetChangedListener(binding.appbarLayoutCreateMultiRedditActivity);
}

setSupportActionBar(toolbar);
setSupportActionBar(binding.toolbarCreateMultiRedditActivity);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT);

if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) {
visibilityLinearLayout.setVisibility(View.GONE);
binding.visibilityWrapperLinearLayoutCreateMultiRedditActivity.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.multiRedditNameEditTextCreateMultiRedditActivity.setImeOptions(binding.multiRedditNameEditTextCreateMultiRedditActivity.getImeOptions() | EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING);
binding.descriptionEditTextCreateMultiRedditActivity.setImeOptions(binding.descriptionEditTextCreateMultiRedditActivity.getImeOptions() | EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING);
}
}

Expand All @@ -134,7 +101,7 @@ protected void onCreate(Bundle savedInstanceState) {
}

private void bindView() {
selectSubredditTextView.setOnClickListener(view -> {
binding.selectSubredditTextViewCreateMultiRedditActivity.setOnClickListener(view -> {
Intent intent = new Intent(CreateMultiRedditActivity.this, SelectedSubredditsAndUsersActivity.class);
intent.putStringArrayListExtra(SelectedSubredditsAndUsersActivity.EXTRA_SELECTED_SUBREDDITS, mSubreddits);
startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE);
Expand All @@ -155,16 +122,16 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
finish();
return true;
} else if (itemId == R.id.action_save_create_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.multiRedditNameEditTextCreateMultiRedditActivity.getText() == null || binding.multiRedditNameEditTextCreateMultiRedditActivity.getText().toString().equals("")) {
Snackbar.make(binding.coordinatorLayoutCreateMultiRedditActivity, R.string.no_multi_reddit_name, Snackbar.LENGTH_SHORT).show();
return true;
}

if (!mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) {
String jsonModel = new MultiRedditJSONModel(nameEditText.getText().toString(), descriptionEditText.getText().toString(),
visibilitySwitch.isChecked(), mSubreddits).createJSONModel();
String jsonModel = new MultiRedditJSONModel(binding.multiRedditNameEditTextCreateMultiRedditActivity.getText().toString(), binding.descriptionEditTextCreateMultiRedditActivity.getText().toString(),
binding.visibilitySwitchCreateMultiRedditActivity.isChecked(), mSubreddits).createJSONModel();
CreateMultiReddit.createMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase, mAccessToken,
"/user/" + mAccountName + "/m/" + nameEditText.getText().toString(),
"/user/" + mAccountName + "/m/" + binding.multiRedditNameEditTextCreateMultiRedditActivity.getText().toString(),
jsonModel, new CreateMultiReddit.CreateMultiRedditListener() {
@Override
public void success() {
Expand All @@ -174,16 +141,16 @@ public void success() {
@Override
public void failed(int errorCode) {
if (errorCode == 409) {
Snackbar.make(coordinatorLayout, R.string.duplicate_multi_reddit, Snackbar.LENGTH_SHORT).show();
Snackbar.make(binding.coordinatorLayoutCreateMultiRedditActivity, R.string.duplicate_multi_reddit, Snackbar.LENGTH_SHORT).show();
} else {
Snackbar.make(coordinatorLayout, R.string.create_multi_reddit_failed, Snackbar.LENGTH_SHORT).show();
Snackbar.make(binding.coordinatorLayoutCreateMultiRedditActivity, R.string.create_multi_reddit_failed, Snackbar.LENGTH_SHORT).show();
}
}
});
} else {
CreateMultiReddit.anonymousCreateMultiReddit(mExecutor, new Handler(), mRedditDataRoomDatabase,
"/user/-/m/" + nameEditText.getText().toString(),
nameEditText.getText().toString(), descriptionEditText.getText().toString(),
"/user/-/m/" + binding.multiRedditNameEditTextCreateMultiRedditActivity.getText().toString(),
binding.multiRedditNameEditTextCreateMultiRedditActivity.getText().toString(), binding.descriptionEditTextCreateMultiRedditActivity.getText().toString(),
mSubreddits, new CreateMultiReddit.CreateMultiRedditListener() {
@Override
public void success() {
Expand Down Expand Up @@ -229,22 +196,23 @@ public CustomThemeWrapper getCustomThemeWrapper() {

@Override
protected void applyCustomTheme() {
coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar);
binding.coordinatorLayoutCreateMultiRedditActivity.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(binding.appbarLayoutCreateMultiRedditActivity,
binding.collapsingToolbarLayoutCreateMultiRedditActivity, binding.toolbarCreateMultiRedditActivity);
int primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor();
int secondaryTextColor = mCustomThemeWrapper.getSecondaryTextColor();
nameEditText.setTextColor(primaryTextColor);
nameEditText.setHintTextColor(secondaryTextColor);
binding.multiRedditNameEditTextCreateMultiRedditActivity.setTextColor(primaryTextColor);
binding.multiRedditNameEditTextCreateMultiRedditActivity.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.divider1CreateMultiRedditActivity.setBackgroundColor(dividerColor);
binding.divider2CreateMultiRedditActivity.setBackgroundColor(dividerColor);
binding.descriptionEditTextCreateMultiRedditActivity.setTextColor(primaryTextColor);
binding.descriptionEditTextCreateMultiRedditActivity.setHintTextColor(secondaryTextColor);
binding.visibilityTextViewCreateMultiRedditActivity.setTextColor(primaryTextColor);
binding.selectSubredditTextViewCreateMultiRedditActivity.setTextColor(primaryTextColor);

if (typeface != null) {
Utils.setFontToAllTextViews(coordinatorLayout, typeface);
Utils.setFontToAllTextViews(binding.coordinatorLayoutCreateMultiRedditActivity, typeface);
}
}
}
Loading

0 comments on commit cec83ca

Please sign in to comment.