LinkResolverActivity to resolve lemmy communities

Signed-off-by: Balazs Toldi <balazs@toldi.eu>
This commit is contained in:
Balazs Toldi 2023-07-26 16:20:51 +02:00
parent 7f74877fd8
commit 2fbcb95db8
No known key found for this signature in database
GPG Key ID: 6C7D440036F99D58
2 changed files with 99 additions and 88 deletions

View File

@ -38,7 +38,7 @@ public class LinkResolverActivity extends AppCompatActivity {
private static final String POST_PATTERN_2 = "/(u|U|user)/[\\w-]+/comments/\\w+/?\\w+/?"; private static final String POST_PATTERN_2 = "/(u|U|user)/[\\w-]+/comments/\\w+/?\\w+/?";
private static final String POST_PATTERN_3 = "/[\\w-]+$"; private static final String POST_PATTERN_3 = "/[\\w-]+$";
private static final String COMMENT_PATTERN = "/(r|u|U|user)/[\\w-]+/comments/\\w+/?[\\w-]+/\\w+/?"; private static final String COMMENT_PATTERN = "/(r|u|U|user)/[\\w-]+/comments/\\w+/?[\\w-]+/\\w+/?";
private static final String SUBREDDIT_PATTERN = "/[rR]/[\\w-]+/?"; private static final String SUBREDDIT_PATTERN = "/[cC]/[\\w@.-]+/?";
private static final String USER_PATTERN = "/(u|U|user)/[\\w-]+/?"; private static final String USER_PATTERN = "/(u|U|user)/[\\w-]+/?";
private static final String SIDEBAR_PATTERN = "/[rR]/[\\w-]+/about/sidebar"; private static final String SIDEBAR_PATTERN = "/[rR]/[\\w-]+/about/sidebar";
private static final String MULTIREDDIT_PATTERN = "/user/[\\w-]+/m/\\w+/?"; private static final String MULTIREDDIT_PATTERN = "/user/[\\w-]+/m/\\w+/?";
@ -221,7 +221,7 @@ public class LinkResolverActivity extends AppCompatActivity {
startActivity(intent); startActivity(intent);
} else if (path.matches(SUBREDDIT_PATTERN)) { } else if (path.matches(SUBREDDIT_PATTERN)) {
Intent intent = new Intent(this, ViewSubredditDetailActivity.class); Intent intent = new Intent(this, ViewSubredditDetailActivity.class);
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, path.substring(3)); intent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, path.substring(3));
intent.putExtra(ViewSubredditDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); intent.putExtra(ViewSubredditDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname);
intent.putExtra(ViewSubredditDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); intent.putExtra(ViewSubredditDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName);
startActivity(intent); startActivity(intent);

View File

@ -233,6 +233,8 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
private int fabOption; private int fabOption;
private MaterialAlertDialogBuilder nsfwWarningBuilder; private MaterialAlertDialogBuilder nsfwWarningBuilder;
private boolean hideSubredditDescription;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
((Infinity) getApplication()).getAppComponent().inject(this); ((Infinity) getApplication()).getAppComponent().inject(this);
@ -336,7 +338,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
} }
lockBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_BOTTOM_APP_BAR, false); lockBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_BOTTOM_APP_BAR, false);
boolean hideSubredditDescription = mSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_SUBREDDIT_DESCRIPTION, false); hideSubredditDescription = mSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_SUBREDDIT_DESCRIPTION, false);
subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME_KEY); subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME_KEY);
qualifiedName = getIntent().getStringExtra(EXTRA_COMMUNITY_FULL_NAME_KEY); qualifiedName = getIntent().getStringExtra(EXTRA_COMMUNITY_FULL_NAME_KEY);
@ -364,8 +366,97 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
checkNewAccountAndBindView(); checkNewAccountAndBindView();
fetchSubredditData(); fetchSubredditData();
if (subredditName != null) {
setupVisibleElements();
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (sectionsPagerAdapter != null) {
return sectionsPagerAdapter.handleKeyDown(keyCode) || super.onKeyDown(keyCode, event);
}
return super.onKeyDown(keyCode, event);
}
@Override
public SharedPreferences getDefaultSharedPreferences() {
return mSharedPreferences;
}
@Override
protected CustomThemeWrapper getCustomThemeWrapper() {
return mCustomThemeWrapper;
}
@Override
protected void applyCustomTheme() {
coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
appBarLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
appBarLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
collapsingToolbarLayout.setScrimVisibleHeightTrigger(toolbar.getHeight() + tabLayout.getHeight() + getStatusBarHeight() * 2);
}
});
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar, false);
expandedTabTextColor = mCustomThemeWrapper.getTabLayoutWithExpandedCollapsingToolbarTextColor();
expandedTabIndicatorColor = mCustomThemeWrapper.getTabLayoutWithExpandedCollapsingToolbarTabIndicator();
expandedTabBackgroundColor = mCustomThemeWrapper.getTabLayoutWithExpandedCollapsingToolbarTabBackground();
collapsedTabTextColor = mCustomThemeWrapper.getTabLayoutWithCollapsedCollapsingToolbarTextColor();
collapsedTabIndicatorColor = mCustomThemeWrapper.getTabLayoutWithCollapsedCollapsingToolbarTabIndicator();
collapsedTabBackgroundColor = mCustomThemeWrapper.getTabLayoutWithCollapsedCollapsingToolbarTabBackground();
linearLayout.setBackgroundColor(expandedTabBackgroundColor);
subredditNameTextView.setTextColor(mCustomThemeWrapper.getSubreddit());
subscribeSubredditChip.setTextColor(mCustomThemeWrapper.getChipTextColor());
int primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor();
nSubscribersTextView.setTextColor(primaryTextColor);
nOnlineSubscribersTextView.setTextColor(primaryTextColor);
sinceTextView.setTextColor(primaryTextColor);
creationTimeTextView.setTextColor(primaryTextColor);
descriptionTextView.setTextColor(primaryTextColor);
navigationWrapper.applyCustomTheme(mCustomThemeWrapper.getBottomAppBarIconColor(), mCustomThemeWrapper.getBottomAppBarBackgroundColor());
applyTabLayoutTheme(tabLayout);
applyFABTheme(navigationWrapper.floatingActionButton);
if (typeface != null) {
subredditNameTextView.setTypeface(typeface);
subscribeSubredditChip.setTypeface(typeface);
nSubscribersTextView.setTypeface(typeface);
nOnlineSubscribersTextView.setTypeface(typeface);
sinceTextView.setTypeface(typeface);
creationTimeTextView.setTypeface(typeface);
descriptionTextView.setTypeface(typeface);
}
unsubscribedColor = mCustomThemeWrapper.getUnsubscribed();
subscribedColor = mCustomThemeWrapper.getSubscribed();
}
private void checkNewAccountAndBindView() {
if (mNewAccountName != null) {
if (mAccountName == null || !mAccountName.equals(mNewAccountName)) {
SwitchAccount.switchAccount(mRedditDataRoomDatabase,mRetrofit, mCurrentAccountSharedPreferences,
mExecutor, new Handler(), mNewAccountName, newAccount -> {
EventBus.getDefault().post(new SwitchAccountEvent(getClass().getName()));
Toast.makeText(this, R.string.account_switched, Toast.LENGTH_SHORT).show();
mNewAccountName = null;
if (newAccount != null) {
mAccessToken = newAccount.getAccessToken();
mAccountName = newAccount.getAccountName();
}
bindView();
});
} else {
bindView();
}
} else {
bindView();
}
}
private void setupVisibleElements() {
subredditNameTextView.setText(subredditName); subredditNameTextView.setText(subredditName);
communityFullNameTextView.setText(qualifiedName); communityFullNameTextView.setText(qualifiedName);
@ -486,97 +577,17 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
}); });
} }
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (sectionsPagerAdapter != null) {
return sectionsPagerAdapter.handleKeyDown(keyCode) || super.onKeyDown(keyCode, event);
}
return super.onKeyDown(keyCode, event);
}
@Override
public SharedPreferences getDefaultSharedPreferences() {
return mSharedPreferences;
}
@Override
protected CustomThemeWrapper getCustomThemeWrapper() {
return mCustomThemeWrapper;
}
@Override
protected void applyCustomTheme() {
coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
appBarLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
appBarLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
collapsingToolbarLayout.setScrimVisibleHeightTrigger(toolbar.getHeight() + tabLayout.getHeight() + getStatusBarHeight() * 2);
}
});
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar, false);
expandedTabTextColor = mCustomThemeWrapper.getTabLayoutWithExpandedCollapsingToolbarTextColor();
expandedTabIndicatorColor = mCustomThemeWrapper.getTabLayoutWithExpandedCollapsingToolbarTabIndicator();
expandedTabBackgroundColor = mCustomThemeWrapper.getTabLayoutWithExpandedCollapsingToolbarTabBackground();
collapsedTabTextColor = mCustomThemeWrapper.getTabLayoutWithCollapsedCollapsingToolbarTextColor();
collapsedTabIndicatorColor = mCustomThemeWrapper.getTabLayoutWithCollapsedCollapsingToolbarTabIndicator();
collapsedTabBackgroundColor = mCustomThemeWrapper.getTabLayoutWithCollapsedCollapsingToolbarTabBackground();
linearLayout.setBackgroundColor(expandedTabBackgroundColor);
subredditNameTextView.setTextColor(mCustomThemeWrapper.getSubreddit());
subscribeSubredditChip.setTextColor(mCustomThemeWrapper.getChipTextColor());
int primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor();
nSubscribersTextView.setTextColor(primaryTextColor);
nOnlineSubscribersTextView.setTextColor(primaryTextColor);
sinceTextView.setTextColor(primaryTextColor);
creationTimeTextView.setTextColor(primaryTextColor);
descriptionTextView.setTextColor(primaryTextColor);
navigationWrapper.applyCustomTheme(mCustomThemeWrapper.getBottomAppBarIconColor(), mCustomThemeWrapper.getBottomAppBarBackgroundColor());
applyTabLayoutTheme(tabLayout);
applyFABTheme(navigationWrapper.floatingActionButton);
if (typeface != null) {
subredditNameTextView.setTypeface(typeface);
subscribeSubredditChip.setTypeface(typeface);
nSubscribersTextView.setTypeface(typeface);
nOnlineSubscribersTextView.setTypeface(typeface);
sinceTextView.setTypeface(typeface);
creationTimeTextView.setTypeface(typeface);
descriptionTextView.setTypeface(typeface);
}
unsubscribedColor = mCustomThemeWrapper.getUnsubscribed();
subscribedColor = mCustomThemeWrapper.getSubscribed();
}
private void checkNewAccountAndBindView() {
if (mNewAccountName != null) {
if (mAccountName == null || !mAccountName.equals(mNewAccountName)) {
SwitchAccount.switchAccount(mRedditDataRoomDatabase,mRetrofit, mCurrentAccountSharedPreferences,
mExecutor, new Handler(), mNewAccountName, newAccount -> {
EventBus.getDefault().post(new SwitchAccountEvent(getClass().getName()));
Toast.makeText(this, R.string.account_switched, Toast.LENGTH_SHORT).show();
mNewAccountName = null;
if (newAccount != null) {
mAccessToken = newAccount.getAccessToken();
mAccountName = newAccount.getAccountName();
}
bindView();
});
} else {
bindView();
}
} else {
bindView();
}
}
private void fetchSubredditData() { private void fetchSubredditData() {
if (!mFetchSubredditInfoSuccess) { if (!mFetchSubredditInfoSuccess) {
FetchSubredditData.fetchSubredditData(mOauthRetrofit, mRetrofit.getRetrofit(), qualifiedName, mAccessToken, new FetchSubredditData.FetchSubredditDataListener() { FetchSubredditData.fetchSubredditData(mOauthRetrofit, mRetrofit.getRetrofit(), qualifiedName, mAccessToken, new FetchSubredditData.FetchSubredditDataListener() {
@Override @Override
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) { public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
qualifiedName = LemmyUtils.actorID2FullName(subredditData.getActorId()); qualifiedName = LemmyUtils.actorID2FullName(subredditData.getActorId());
if (subredditName == null) {
subredditName = subredditData.getTitle();
setupVisibleElements();
}
mNCurrentOnlineSubscribers = nCurrentOnlineSubscribers; mNCurrentOnlineSubscribers = nCurrentOnlineSubscribers;
nOnlineSubscribersTextView.setText(getString(R.string.online_subscribers_number_detail, nCurrentOnlineSubscribers)); nOnlineSubscribersTextView.setText(getString(R.string.online_subscribers_number_detail, nCurrentOnlineSubscribers));
InsertSubredditData.insertSubredditData(mExecutor, new Handler(), mRedditDataRoomDatabase, InsertSubredditData.insertSubredditData(mExecutor, new Handler(), mRedditDataRoomDatabase,