Minor code improvements (#1218)

* Move mAccessToken and mAccountName initialization upper

* Marked INSTANCE as a volatile to be DCL compliant

* fix a typo in a method name and remove redundant switch

* remove redundant ifs

* removed DCL on RedditDataRoomDatabase as its controlled by dagger

* remove redundant ifs in PostGalleryActivity as nColumns can be either 2 or 3 only

* replace MediaStore.Video.Media.IS_PENDING with MediaStore.MediaColumns.IS_PENDING

* reverting simplified ifs as it going to be used in the future

* reverting HistoryPostViewModel
This commit is contained in:
Anatolii Afanasev 2022-11-19 14:23:31 +00:00 committed by GitHub
parent da58688586
commit 1abda7c6e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 29 additions and 82 deletions

View File

@ -2,5 +2,5 @@ package ml.docilealligator.infinityforreddit;
public interface ActivityToolbarInterface {
void onLongPress();
default void displaySortType() {};
default void displaySortType() {}
}

View File

@ -234,7 +234,7 @@ class AppModule {
@Provides
@Singleton
RedditDataRoomDatabase provideRedditDataRoomDatabase() {
return RedditDataRoomDatabase.getDatabase(mApplication);
return RedditDataRoomDatabase.create(mApplication);
}
@Provides

View File

@ -230,10 +230,8 @@ public class PullNotificationWorker extends Worker {
return fetchMessages(account, retryCount - 1);
}
return null;
} else {
return null;
}
return null;
}
}

View File

@ -40,25 +40,17 @@ import ml.docilealligator.infinityforreddit.user.UserData;
SubscribedUserData.class, MultiReddit.class, CustomTheme.class, RecentSearchQuery.class,
ReadPost.class, PostFilter.class, PostFilterUsage.class, AnonymousMultiredditSubreddit.class}, version = 23)
public abstract class RedditDataRoomDatabase extends RoomDatabase {
private static RedditDataRoomDatabase INSTANCE;
public static RedditDataRoomDatabase getDatabase(final Context context) {
if (INSTANCE == null) {
synchronized (RedditDataRoomDatabase.class) {
if (INSTANCE == null) {
INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
RedditDataRoomDatabase.class, "reddit_data")
.addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5,
MIGRATION_5_6, MIGRATION_6_7, MIGRATION_7_8, MIGRATION_8_9,
MIGRATION_9_10, MIGRATION_10_11, MIGRATION_11_12, MIGRATION_12_13,
MIGRATION_13_14, MIGRATION_14_15, MIGRATION_15_16, MIGRATION_16_17,
MIGRATION_17_18, MIGRATION_18_19, MIGRATION_19_20, MIGRATION_20_21,
MIGRATION_21_22, MIGRATION_22_23)
.build();
}
}
}
return INSTANCE;
public static RedditDataRoomDatabase create(final Context context) {
return Room.databaseBuilder(context.getApplicationContext(),
RedditDataRoomDatabase.class, "reddit_data")
.addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5,
MIGRATION_5_6, MIGRATION_6_7, MIGRATION_7_8, MIGRATION_8_9,
MIGRATION_9_10, MIGRATION_10_11, MIGRATION_11_12, MIGRATION_12_13,
MIGRATION_13_14, MIGRATION_14_15, MIGRATION_15_16, MIGRATION_16_17,
MIGRATION_17_18, MIGRATION_18_19, MIGRATION_19_20, MIGRATION_20_21,
MIGRATION_21_22, MIGRATION_22_23)
.build();
}
public abstract AccountDao accountDao();

View File

@ -106,7 +106,6 @@ public class LinkResolverActivity extends AppCompatActivity {
private void handleUri(Uri uri) {
if (uri == null) {
Toast.makeText(this, R.string.no_link_available, Toast.LENGTH_SHORT).show();
finish();
} else {
String path = uri.getPath();
if (path == null) {
@ -339,8 +338,8 @@ public class LinkResolverActivity extends AppCompatActivity {
}
}
finish();
}
finish();
}
private void deepLinkError(Uri uri) {

View File

@ -322,12 +322,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
mMessageFullname = savedInstanceState.getString(MESSAGE_FULLNAME_STATE);
mNewAccountName = savedInstanceState.getString(NEW_ACCOUNT_NAME_STATE);
inboxCount = savedInstanceState.getInt(INBOX_COUNT_STATE);
initializeNotificationAndBindView();
} else {
mMessageFullname = getIntent().getStringExtra(EXTRA_MESSSAGE_FULLNAME);
mNewAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME);
initializeNotificationAndBindView();
}
initializeNotificationAndBindView();
}
@Override
@ -754,11 +753,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
intent = new Intent(MainActivity.this, ViewUserDetailActivity.class);
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mAccountName);
} else if (stringId == R.string.subscriptions) {
if (mAccessToken != null) {
intent = new Intent(MainActivity.this, SubscribedThingListingActivity.class);
} else {
intent = new Intent(MainActivity.this, SubscribedThingListingActivity.class);
}
intent = new Intent(MainActivity.this, SubscribedThingListingActivity.class);
} else if (stringId == R.string.multi_reddit) {
intent = new Intent(MainActivity.this, SubscribedThingListingActivity.class);
intent.putExtra(SubscribedThingListingActivity.EXTRA_SHOW_MULTIREDDITS, true);
@ -1101,7 +1096,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
}
@Override
public void onBackPressed() {;
public void onBackPressed() {
if (drawer.isOpen()) {
drawer.close();
} else {

View File

@ -236,28 +236,9 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
imagesRecyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
@Override
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
GridLayoutManager.LayoutParams layoutParams = (GridLayoutManager.LayoutParams) view.getLayoutParams();
int spanIndex = layoutParams.getSpanIndex();
int offset = (int) (Utils.convertDpToPixel(16, PostGalleryActivity.this));
int halfOffset = offset / 2;
if (nColumns == 2) {
if (spanIndex == 0) {
outRect.set(halfOffset, 0, halfOffset, offset);
} else {
outRect.set(halfOffset, 0, halfOffset, offset);
}
} else if (nColumns == 3) {
if (spanIndex == 0) {
outRect.set(halfOffset, 0, halfOffset, offset);
} else if (spanIndex == 1) {
outRect.set(halfOffset, 0, halfOffset, offset);
} else {
outRect.set(halfOffset, 0, halfOffset, offset);
}
}
outRect.set(halfOffset, 0, halfOffset, offset);
}
});

View File

@ -58,11 +58,7 @@ public class SubredditMultiselectionRecyclerViewAdapter extends RecyclerView.Ada
.error(glide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
.into(((SubscribedSubredditViewHolder) holder).iconImageView);
if (subscribedSubreddits.get(position).isSelected()) {
((SubscribedSubredditViewHolder) holder).checkBox.setChecked(true);
} else {
((SubscribedSubredditViewHolder) holder).checkBox.setChecked(false);
}
((SubscribedSubredditViewHolder) holder).checkBox.setChecked(subscribedSubreddits.get(position).isSelected());
((SubscribedSubredditViewHolder) holder).checkBox.setOnClickListener(view -> {
if (subscribedSubreddits.get(position).isSelected()) {
((SubscribedSubredditViewHolder) holder).checkBox.setChecked(false);

View File

@ -277,7 +277,7 @@ public interface RedditAPI {
default Call<String> getWiki(@Path("subredditName") String subredditName) {
return getWikiPage(subredditName, "index");
};
}
@GET("/r/{subredditName}/wiki/{wikiPage}.json?raw_json=1")
Call<String> getWikiPage(@Path("subredditName") String subredditName, @Path("wikiPage") String wikiPage);

View File

@ -876,7 +876,6 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
}
}
return;
} else {
for (int i = currentSearchIndex - 1; i >= 0; i--) {
if (visibleComments.get(i).getCommentRawText() != null &&
@ -894,8 +893,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
}
}
return;
}
return;
}
}
}

View File

@ -269,7 +269,7 @@ public class DownloadMediaService extends Service {
contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, destinationFileName);
contentValues.put(MediaStore.MediaColumns.MIME_TYPE, mediaType == EXTRA_MEDIA_TYPE_VIDEO ? "video/*" : "image/*");
contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, destinationFileUriString);
contentValues.put(mediaType == EXTRA_MEDIA_TYPE_VIDEO ? MediaStore.Video.Media.IS_PENDING : MediaStore.Images.Media.IS_PENDING, 1);
contentValues.put(MediaStore.MediaColumns.IS_PENDING, 1);
final Uri contentUri = mediaType == EXTRA_MEDIA_TYPE_VIDEO ? MediaStore.Video.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY) : MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY);
Uri uri = contentResolver.insert(contentUri, contentValues);
@ -291,7 +291,7 @@ public class DownloadMediaService extends Service {
stream.write(buf, 0, len);
}
contentValues.clear();
contentValues.put(mediaType == EXTRA_MEDIA_TYPE_VIDEO ? MediaStore.Video.Media.IS_PENDING : MediaStore.Images.Media.IS_PENDING, 0);
contentValues.put(MediaStore.MediaColumns.IS_PENDING, 0);
contentResolver.update(uri, contentValues, null, null);
destinationFileUriString = uri.toString();
}

View File

@ -44,11 +44,7 @@ public class GesturesAndButtonsPreferenceFragment extends CustomFontPreferenceFr
if (lockJumpToNextTopLevelCommentButtonSwitch != null && lockBottomAppBarSwitch != null &&
swipeUpToHideJumpToNextTopLevelCommentButtonSwitch != null) {
lockJumpToNextTopLevelCommentButtonSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
if ((Boolean) newValue) {
swipeUpToHideJumpToNextTopLevelCommentButtonSwitch.setVisible(false);
} else {
swipeUpToHideJumpToNextTopLevelCommentButtonSwitch.setVisible(true);
}
swipeUpToHideJumpToNextTopLevelCommentButtonSwitch.setVisible(!((Boolean) newValue));
return true;
});

View File

@ -24,20 +24,12 @@ public class ImmersiveInterfacePreferenceFragment extends CustomFontPreferenceFr
if (immersiveInterfaceSwitch != null && immersiveInterfaceIgnoreNavBarSwitch != null
&& disableImmersiveInterfaceInLandscapeModeSwitch != null) {
immersiveInterfaceSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
if ((Boolean) newValue) {
immersiveInterfaceIgnoreNavBarSwitch.setVisible(true);
} else {
immersiveInterfaceIgnoreNavBarSwitch.setVisible(false);
}
immersiveInterfaceIgnoreNavBarSwitch.setVisible((Boolean) newValue);
EventBus.getDefault().post(new RecreateActivityEvent());
return true;
});
if (immersiveInterfaceSwitch.isChecked()) {
immersiveInterfaceIgnoreNavBarSwitch.setVisible(true);
} else {
immersiveInterfaceIgnoreNavBarSwitch.setVisible(false);
}
immersiveInterfaceIgnoreNavBarSwitch.setVisible(immersiveInterfaceSwitch.isChecked());
immersiveInterfaceIgnoreNavBarSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
EventBus.getDefault().post(new RecreateActivityEvent());

View File

@ -132,7 +132,7 @@ public class JSONUtils {
public static final String TOTAL_KARMA_KEY = "total_karma";
public static final String AWARDER_KARMA_KEY = "awarder_karma";
public static final String AWARDEE_KARMA_KEY = "awardee_karma";
public static final String CONTENT_URLS_KEY = "content_urls";;
public static final String CONTENT_URLS_KEY = "content_urls";
public static final String WEBM_KEY = "webm";
public static final String WEBM_URL_KEY = "webmUrl";
public static final String UPVOTE_RATIO_KEY = "upvote_ratio";

View File

@ -129,7 +129,7 @@ public class MaterialYouUtils {
darkTheme.navBarColor = darkTheme.colorPrimary;
darkTheme.primaryTextColor = context.getColor(android.R.color.system_neutral1_10);
darkTheme.secondaryTextColor = context.getColor(android.R.color.system_neutral1_10);
darkTheme.bottomAppBarIconColor = context.getColor(android.R.color.system_accent1_100);;
darkTheme.bottomAppBarIconColor = context.getColor(android.R.color.system_accent1_100);
darkTheme.primaryIconColor = context.getColor(android.R.color.system_accent1_100);
darkTheme.fabIconColor = context.getColor(android.R.color.system_neutral1_900);
darkTheme.toolbarPrimaryTextAndIconColor = context.getColor(android.R.color.system_accent2_100);

View File

@ -252,7 +252,6 @@ public final class Utils {
}
} catch (SecurityException ignore) {
}
return NETWORK_TYPE_OTHER;
} else {
boolean isWifi = false;
boolean isCellular = false;
@ -274,8 +273,8 @@ public final class Utils {
return NETWORK_TYPE_CELLULAR;
}
return NETWORK_TYPE_OTHER;
}
return NETWORK_TYPE_OTHER;
}
return NETWORK_TYPE_OTHER;