Skip to content

Commit

Permalink
Numerous fixes
Browse files Browse the repository at this point in the history
Social icons are always centered
OnBackPressedCallback > OnBackPressedCallback
'drawable.length() == 0' can be replaced with 'drawable.isEmpty()'
Statement lambda can be replaced with expression lambda
Explicit type argument String, Object can be replaced with <>
'isConnected()' is deprecated
  • Loading branch information
Donnnno committed Jan 2, 2025
1 parent 19955ae commit 9f2bee7
Show file tree
Hide file tree
Showing 45 changed files with 344 additions and 300 deletions.
1 change: 1 addition & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ dependencies {

implementation 'androidx.work:work-runtime:2.10.0'
implementation 'androidx.recyclerview:recyclerview:1.3.2'
implementation 'androidx.activity:activity:1.9.3'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'androidx.palette:palette:1.0.0'
implementation 'com.google.android.material:material:1.12.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBarDrawerToggle;
Expand Down Expand Up @@ -200,6 +201,30 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {

mFragManager = getSupportFragmentManager();

getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
if (mFragManager.getBackStackEntryCount() > 0) {
clearBackStack();
return;
}

if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
mDrawerLayout.closeDrawers();
return;
}

if (mFragmentTag != Extras.Tag.HOME) {
mPosition = mLastPosition = 0;
setFragment(getFragment(mPosition));
return;
}

setEnabled(false);
getOnBackPressedDispatcher().onBackPressed();
}
});

initNavigationView(toolbar);
initNavigationViewHeader();

Expand Down Expand Up @@ -432,26 +457,6 @@ protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
}

@Override
public void onBackPressed() {
if (mFragManager.getBackStackEntryCount() > 0) {
clearBackStack();
return;
}

if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
mDrawerLayout.closeDrawers();
return;
}

if (mFragmentTag != Extras.Tag.HOME) {
mPosition = mLastPosition = 0;
setFragment(getFragment(mPosition));
return;
}
super.onBackPressed();
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
Expand Down Expand Up @@ -865,7 +870,7 @@ private void initNavigationViewHeader() {
image.setRatio(16, 9);
}

if (titleText.length() == 0) {
if (titleText.isEmpty()) {
container.setVisibility(View.GONE);
} else {
title.setText(titleText);
Expand Down Expand Up @@ -996,7 +1001,6 @@ private void setFragment(Fragment fragment) {
private Fragment getFragment(int position) {
mFragmentTag = Extras.Tag.HOME;
if (position == Extras.Tag.HOME.idx) {
mFragmentTag = Extras.Tag.HOME;
return new HomeFragment();
} else if (position == Extras.Tag.APPLY.idx) {
mFragmentTag = Extras.Tag.APPLY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ protected boolean run() {
return false;
}

if (list.size() > 0 && list.get(0) instanceof Map) {
if (!list.isEmpty() && list.get(0) instanceof Map) {
Map<?, ?> map = (Map<?, ?>) list.get(0);
String thumbUrl = JsonHelper.getThumbUrl(map);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
Expand Down Expand Up @@ -128,6 +129,25 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
this, R.drawable.ic_toolbar_back, Color.WHITE));
mBack.setOnClickListener(this);

getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
WallpapersAdapter.sIsClickable = true;
if (mHandler != null && mRunnable != null) {
mHandler.removeCallbacks(mRunnable);
}

if (mExitTransition != null) {
mExitTransition.exit(CandyBarWallpaperActivity.this);
return;
}

// Default back press behavior
setEnabled(false);
getOnBackPressedDispatcher().onBackPressed();
}
});

String url = "";
if (savedInstanceState != null) {
url = savedInstanceState.getString(Extras.EXTRA_URL);
Expand All @@ -148,7 +168,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {

CandyBarApplication.getConfiguration().getAnalyticsHandler().logEvent(
"wallpaper",
new HashMap<String, Object>() {{
new HashMap<>() {{
put("url", mWallpaperName);
put("action", "preview");
}}
Expand Down Expand Up @@ -263,24 +283,11 @@ protected void onDestroy() {
super.onDestroy();
}

@Override
public void onBackPressed() {
WallpapersAdapter.sIsClickable = true;
if (mHandler != null && mRunnable != null)
mHandler.removeCallbacks(mRunnable);

if (mExitTransition != null) {
mExitTransition.exit(this);
return;
}
super.onBackPressed();
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
onBackPressed();
getOnBackPressedDispatcher().onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
Expand All @@ -290,7 +297,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
public void onClick(View view) {
int id = view.getId();
if (id == R.id.back) {
onBackPressed();
getOnBackPressedDispatcher().onBackPressed();
} else if (id == R.id.menu_apply) {
Popup popup = Popup.Builder(this)
.to(mMenuApply)
Expand Down Expand Up @@ -324,7 +331,7 @@ public void onClick(View view) {
if (item.getType() == PopupItem.Type.LOCKSCREEN) {
CandyBarApplication.getConfiguration().getAnalyticsHandler().logEvent(
"wallpaper",
new HashMap<String, Object>() {{
new HashMap<>() {{
put("url", mWallpaperName);
put("section", "lockscreen");
put("action", "apply");
Expand All @@ -334,7 +341,7 @@ public void onClick(View view) {
} else if (item.getType() == PopupItem.Type.HOMESCREEN) {
CandyBarApplication.getConfiguration().getAnalyticsHandler().logEvent(
"wallpaper",
new HashMap<String, Object>() {{
new HashMap<>() {{
put("url", mWallpaperName);
put("section", "homescreen");
put("action", "apply");
Expand All @@ -344,7 +351,7 @@ public void onClick(View view) {
} else if (item.getType() == PopupItem.Type.HOMESCREEN_LOCKSCREEN) {
CandyBarApplication.getConfiguration().getAnalyticsHandler().logEvent(
"wallpaper",
new HashMap<String, Object>() {{
new HashMap<>() {{
put("url", mWallpaperName);
put("section", "homescreen_and_lockscreen");
put("action", "apply");
Expand Down Expand Up @@ -478,7 +485,7 @@ private void loadWallpaper() {
.override(2000)
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.timeout(10000)
.listener(new RequestListener<Bitmap>() {
.listener(new RequestListener<>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
if (mWallpaper.getColor() == 0) {
Expand Down
20 changes: 10 additions & 10 deletions library/src/main/java/candybar/lib/adapters/AboutAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ public AboutAdapter(@NonNull Context context, int spanCount) {

mShowContributors = mContext.getResources().getBoolean(R.bool.show_contributors_dialog);

mShowPrivacyPolicy = mContext.getResources().getString(R.string.privacy_policy_link).length() > 0;
mShowPrivacyPolicy = !mContext.getResources().getString(R.string.privacy_policy_link).isEmpty();

mShowTerms = mContext.getResources().getString(R.string.terms_and_conditions_link).length() > 0;
mShowTerms = !mContext.getResources().getString(R.string.terms_and_conditions_link).isEmpty();

mShowExtraInfo = mShowContributors || mShowPrivacyPolicy || mShowTerms;

Expand Down Expand Up @@ -217,7 +217,7 @@ private class HeaderViewHolder extends RecyclerView.ViewHolder {
} else {
if (recyclerView.getLayoutParams() instanceof LinearLayout.LayoutParams) {
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) recyclerView.getLayoutParams();
if (urls.length < 7) {
if (urls.length > 1) {
params.width = LinearLayout.LayoutParams.WRAP_CONTENT;
params.gravity = Gravity.CENTER_HORIZONTAL;
recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
Expand Down Expand Up @@ -335,7 +335,7 @@ public void onClick(View view) {
if (id == R.id.contributors_title) {
CandyBarApplication.getConfiguration().getAnalyticsHandler().logEvent(
"click",
new HashMap<String, Object>() {{
new HashMap<>() {{
put("section", "about");
put("action", "open_dialog");
put("item", "contributors");
Expand All @@ -346,7 +346,7 @@ public void onClick(View view) {
} else if (id == R.id.privacy_policy_title) {
CandyBarApplication.getConfiguration().getAnalyticsHandler().logEvent(
"click",
new HashMap<String, Object>() {{
new HashMap<>() {{
put("section", "about");
put("action", "open_dialog");
put("item", "privacy_policy");
Expand All @@ -358,7 +358,7 @@ public void onClick(View view) {
} else if (id == R.id.terms_title) {
CandyBarApplication.getConfiguration().getAnalyticsHandler().logEvent(
"click",
new HashMap<String, Object>() {{
new HashMap<>() {{
put("section", "about");
put("action", "open_dialog");
put("item", "terms_and_conditions");
Expand Down Expand Up @@ -431,7 +431,7 @@ public void onClick(View view) {
if (id == R.id.about_dashboard_licenses) {
CandyBarApplication.getConfiguration().getAnalyticsHandler().logEvent(
"click",
new HashMap<String, Object>() {{
new HashMap<>() {{
put("section", "about");
put("action", "open_dialog");
put("item", "licenses");
Expand All @@ -444,7 +444,7 @@ public void onClick(View view) {
if (id == R.id.about_dashboard_contributors) {
CandyBarApplication.getConfiguration().getAnalyticsHandler().logEvent(
"click",
new HashMap<String, Object>() {{
new HashMap<>() {{
put("section", "about");
put("action", "open_dialog");
put("item", "contributors");
Expand All @@ -458,7 +458,7 @@ public void onClick(View view) {
if (id == R.id.about_dashboard_translator) {
CandyBarApplication.getConfiguration().getAnalyticsHandler().logEvent(
"click",
new HashMap<String, Object>() {{
new HashMap<>() {{
put("section", "about");
put("action", "open_dialog");
put("item", "translators");
Expand All @@ -473,7 +473,7 @@ public void onClick(View view) {
if (id == R.id.about_dashboard_github) {
CandyBarApplication.getConfiguration().getAnalyticsHandler().logEvent(
"click",
new HashMap<String, Object>() {{
new HashMap<>() {{
put("section", "about");
put("action", "open_dialog");
put("item", "github");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void onClick(View view) {

CandyBarApplication.getConfiguration().getAnalyticsHandler().logEvent(
"click",
new HashMap<String, Object>() {{
new HashMap<>() {{
put("section", "about");
put("action", "open_social");
put("url", mUrls[position]);
Expand Down
6 changes: 3 additions & 3 deletions library/src/main/java/candybar/lib/adapters/FAQsAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class ViewHolder extends RecyclerView.ViewHolder {
public void search(String string) {
String query = string.toLowerCase(Locale.getDefault()).trim();
mFAQs.clear();
if (query.length() == 0) mFAQs.addAll(mFAQsAll);
if (query.isEmpty()) mFAQs.addAll(mFAQsAll);
else {
for (int i = 0; i < mFAQsAll.size(); i++) {
FAQs faq = mFAQsAll.get(i);
Expand All @@ -145,7 +145,7 @@ public void search(String string) {
if (getFaqsCount() == 0) {
CandyBarApplication.getConfiguration().getAnalyticsHandler().logEvent(
"type",
new HashMap<String, Object>() {{
new HashMap<>() {{
put("section", "faq");
put("action", "search");
put("found", "no");
Expand All @@ -155,7 +155,7 @@ public void search(String string) {
} else {
CandyBarApplication.getConfiguration().getAnalyticsHandler().logEvent(
"type",
new HashMap<String, Object>() {{
new HashMap<>() {{
put("section", "faq");
put("action", "search");
put("found", "yes");
Expand Down
Loading

0 comments on commit 9f2bee7

Please sign in to comment.