use of me.ccrama.redditslide.SpoilerRobotoTextView in project Slide by ccrama.
the class CommentOverflow method formatTable.
private TableLayout formatTable(String text, String subreddit, OnClickListener click, OnLongClickListener longClick) {
TableRow.LayoutParams rowParams = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
Context context = getContext();
TableLayout table = new TableLayout(context);
TableLayout.LayoutParams params = new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT);
table.setLayoutParams(params);
final String tableStart = "<table>";
final String tableEnd = "</table>";
final String tableHeadStart = "<thead>";
final String tableHeadEnd = "</thead>";
final String tableRowStart = "<tr>";
final String tableRowEnd = "</tr>";
final String tableColumnStart = "<td>";
final String tableColumnEnd = "</td>";
final String tableColumnStartLeft = "<td align=\"left\">";
final String tableColumnStartRight = "<td align=\"right\">";
final String tableColumnStartCenter = "<td align=\"center\">";
final String tableHeaderStart = "<th>";
final String tableHeaderStartLeft = "<th align=\"left\">";
final String tableHeaderStartRight = "<th align=\"right\">";
final String tableHeaderStartCenter = "<th align=\"center\">";
final String tableHeaderEnd = "</th>";
int i = 0;
int columnStart = 0;
int columnEnd;
int gravity = Gravity.START;
boolean columnStarted = false;
TableRow row = null;
while (i < text.length()) {
if (text.charAt(i) != '<') {
// quick check otherwise it falls through to else
i += 1;
} else if (text.subSequence(i, i + tableStart.length()).toString().equals(tableStart)) {
i += tableStart.length();
} else if (text.subSequence(i, i + tableHeadStart.length()).toString().equals(tableHeadStart)) {
i += tableHeadStart.length();
} else if (text.subSequence(i, i + tableRowStart.length()).toString().equals(tableRowStart)) {
row = new TableRow(context);
row.setLayoutParams(rowParams);
i += tableRowStart.length();
} else if (text.subSequence(i, i + tableRowEnd.length()).toString().equals(tableRowEnd)) {
table.addView(row);
i += tableRowEnd.length();
} else if (text.subSequence(i, i + tableEnd.length()).toString().equals(tableEnd)) {
i += tableEnd.length();
} else if (text.subSequence(i, i + tableHeadEnd.length()).toString().equals(tableHeadEnd)) {
i += tableHeadEnd.length();
} else if (!columnStarted && i + tableColumnStart.length() < text.length() && (text.subSequence(i, i + tableColumnStart.length()).toString().equals(tableColumnStart) || text.subSequence(i, i + tableHeaderStart.length()).toString().equals(tableHeaderStart))) {
columnStarted = true;
gravity = Gravity.START;
i += tableColumnStart.length();
columnStart = i;
} else if (!columnStarted && i + tableColumnStartRight.length() < text.length() && (text.subSequence(i, i + tableColumnStartRight.length()).toString().equals(tableColumnStartRight) || text.subSequence(i, i + tableHeaderStartRight.length()).toString().equals(tableHeaderStartRight))) {
columnStarted = true;
gravity = Gravity.END;
i += tableColumnStartRight.length();
columnStart = i;
} else if (!columnStarted && i + tableColumnStartCenter.length() < text.length() && (text.subSequence(i, i + tableColumnStartCenter.length()).toString().equals(tableColumnStartCenter) || text.subSequence(i, i + tableHeaderStartCenter.length()).toString().equals(tableHeaderStartCenter))) {
columnStarted = true;
gravity = Gravity.CENTER;
i += tableColumnStartCenter.length();
columnStart = i;
} else if (!columnStarted && i + tableColumnStartLeft.length() < text.length() && (text.subSequence(i, i + tableColumnStartLeft.length()).toString().equals(tableColumnStartLeft) || text.subSequence(i, i + tableHeaderStartLeft.length()).toString().equals(tableHeaderStartLeft))) {
columnStarted = true;
gravity = Gravity.START;
i += tableColumnStartLeft.length();
columnStart = i;
} else if (text.substring(i).startsWith("<td")) {
// case for <td colspan="2" align="left">
// See last table in https://www.reddit.com/r/GlobalOffensive/comments/51s3r8/virtuspro_vs_vgcyberzen_sl_ileague_s2_finals/
columnStarted = true;
i += text.substring(i).indexOf(">") + 1;
columnStart = i;
} else if (text.subSequence(i, i + tableColumnEnd.length()).toString().equals(tableColumnEnd) || text.subSequence(i, i + tableHeaderEnd.length()).toString().equals(tableHeaderEnd)) {
columnEnd = i;
SpoilerRobotoTextView textView = new SpoilerRobotoTextView(context);
textView.setTextHtml(text.subSequence(columnStart, columnEnd), subreddit);
setStyle(textView, subreddit);
textView.setLayoutParams(COLUMN_PARAMS);
textView.setGravity(gravity);
if (click != null)
textView.setOnClickListener(click);
if (longClick != null)
textView.setOnLongClickListener(longClick);
if (text.subSequence(i, i + tableHeaderEnd.length()).toString().equals(tableHeaderEnd)) {
textView.setTypeface(null, Typeface.BOLD);
}
if (row != null) {
row.addView(textView);
}
columnStart = 0;
columnStarted = false;
i += tableColumnEnd.length();
} else {
i += 1;
}
}
return table;
}
use of me.ccrama.redditslide.SpoilerRobotoTextView in project Slide by ccrama.
the class MainActivity method onCreate.
@Override
protected void onCreate(final Bundle savedInstanceState) {
inNightMode = SettingValues.isNight();
disableSwipeBackLayout();
super.onCreate(savedInstanceState);
if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
// Activity was brought to front and not created
finish();
return;
}
if (!Slide.hasStarted) {
Slide.hasStarted = true;
}
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 1);
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}
boolean first = false;
if (Reddit.colors != null && !Reddit.colors.contains("firstStart53")) {
new AlertDialogWrapper.Builder(this).setTitle("Content settings have moved!").setMessage("NSFW content is now disabled by default. If you are over the age of 18, to re-enable NSFW content, visit Settings > Content settings").setPositiveButton(R.string.btn_ok, null).setCancelable(false).show();
Reddit.colors.edit().putBoolean("firstStart53", true).apply();
}
if (Reddit.colors != null && !Reddit.colors.contains("Tutorial")) {
first = true;
if (Reddit.appRestart == null) {
Reddit.appRestart = getSharedPreferences("appRestart", 0);
}
Reddit.appRestart.edit().putBoolean("firststart52", true).apply();
Intent i = new Intent(this, Tutorial.class);
doForcePrefs();
startActivity(i);
} else {
if (Authentication.didOnline && NetworkUtil.isConnected(MainActivity.this) && !checkedPopups) {
runAfterLoad = new Runnable() {
@Override
public void run() {
runAfterLoad = null;
if (Authentication.isLoggedIn) {
new AsyncNotificationBadge().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
if (!Reddit.appRestart.getString(CheckForMail.SUBS_TO_GET, "").isEmpty()) {
new CheckForMail.AsyncGetSubs(MainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
new AsyncTask<Void, Void, Submission>() {
@Override
protected Submission doInBackground(Void... params) {
if (Authentication.isLoggedIn)
UserSubscriptions.doOnlineSyncing();
try {
SubredditPaginator p = new SubredditPaginator(Authentication.reddit, "slideforreddit");
p.setLimit(2);
ArrayList<Submission> posts = new ArrayList<>(p.next());
for (Submission s : posts) {
String version = BuildConfig.VERSION_NAME;
if (version.length() > 5) {
version = version.substring(0, version.lastIndexOf("."));
}
if (s.isStickied() && s.getSubmissionFlair().getText() != null && s.getSubmissionFlair().getText().equalsIgnoreCase("Announcement") && !Reddit.appRestart.contains("announcement" + s.getFullName()) && s.getTitle().contains(version)) {
Reddit.appRestart.edit().putBoolean("announcement" + s.getFullName(), true).apply();
return s;
} else if (BuildConfig.VERSION_NAME.contains("alpha") && s.isStickied() && s.getSubmissionFlair().getText() != null && s.getSubmissionFlair().getText().equalsIgnoreCase("Alpha") && !Reddit.appRestart.contains("announcement" + s.getFullName()) && s.getTitle().contains(BuildConfig.VERSION_NAME)) {
Reddit.appRestart.edit().putBoolean("announcement" + s.getFullName(), true).apply();
return s;
} else if (s.isStickied() && s.getSubmissionFlair().getText().equalsIgnoreCase("PRO") && !SettingValues.tabletUI && !Reddit.appRestart.contains("announcement" + s.getFullName())) {
Reddit.appRestart.edit().putBoolean("announcement" + s.getFullName(), true).apply();
return s;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(final Submission s) {
checkedPopups = true;
if (s != null) {
Reddit.appRestart.edit().putString("page", s.getDataNode().get("selftext_html").asText()).apply();
Reddit.appRestart.edit().putString("title", s.getTitle()).apply();
Reddit.appRestart.edit().putString("url", s.getUrl()).apply();
String title;
if (s.getTitle().toLowerCase(Locale.ENGLISH).contains("release")) {
title = getString(R.string.btn_changelog);
} else {
title = getString(R.string.btn_view);
}
Snackbar snack = Snackbar.make(pager, s.getTitle(), Snackbar.LENGTH_INDEFINITE).setAction(title, new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
Intent i = new Intent(MainActivity.this, Announcement.class);
startActivity(i);
}
});
View view = snack.getView();
TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
snack.show();
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
// todo this new AsyncStartNotifSocket().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
};
}
}
if (savedInstanceState != null && !changed) {
Authentication.isLoggedIn = savedInstanceState.getBoolean(LOGGED_IN);
Authentication.name = savedInstanceState.getString(USERNAME, "LOGGEDOUT");
Authentication.didOnline = savedInstanceState.getBoolean(IS_ONLINE);
} else {
changed = false;
}
if (getIntent().getBooleanExtra("EXIT", false))
finish();
applyColorTheme();
setContentView(R.layout.activity_overview);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
setSupportActionBar(mToolbar);
if (getIntent() != null && getIntent().hasExtra(EXTRA_PAGE_TO)) {
toGoto = getIntent().getIntExtra(EXTRA_PAGE_TO, 0);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = this.getWindow();
window.setStatusBarColor(Palette.getDarkerColor(Palette.getDarkerColor(Palette.getDefaultColor())));
}
mTabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
header = findViewById(R.id.header);
// Gets the height of the header
if (header != null) {
header.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
headerHeight = header.getHeight();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
header.getViewTreeObserver().removeOnGlobalLayoutListener(this);
} else {
header.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
}
});
}
pager = (ToggleSwipeViewPager) findViewById(R.id.content_view);
singleMode = SettingValues.single;
if (singleMode) {
commentPager = SettingValues.commentPager;
}
// Inflate tabs if single mode is disabled
if (!singleMode) {
mTabLayout = (TabLayout) ((ViewStub) findViewById(R.id.stub_tabs)).inflate();
}
// Disable swiping if single mode is enabled
if (singleMode) {
pager.setSwipingEnabled(false);
}
sidebarBody = (SpoilerRobotoTextView) findViewById(R.id.sidebar_text);
sidebarOverflow = (CommentOverflow) findViewById(R.id.commentOverflow);
if (!Reddit.appRestart.getBoolean("isRestarting", false) && Reddit.colors.contains("Tutorial")) {
LogUtil.v("Starting main " + Authentication.name);
Authentication.isLoggedIn = Reddit.appRestart.getBoolean("loggedin", false);
Authentication.name = Reddit.appRestart.getString("name", "LOGGEDOUT");
UserSubscriptions.doMainActivitySubs(this);
} else if (!first) {
LogUtil.v("Starting main 2 " + Authentication.name);
Authentication.isLoggedIn = Reddit.appRestart.getBoolean("loggedin", false);
Authentication.name = Reddit.appRestart.getString("name", "LOGGEDOUT");
Reddit.appRestart.edit().putBoolean("isRestarting", false).commit();
Reddit.isRestarting = false;
UserSubscriptions.doMainActivitySubs(this);
}
final SharedPreferences seen = getSharedPreferences("SEEN", 0);
if (!seen.contains("isCleared") && !seen.getAll().isEmpty() || !Reddit.appRestart.contains("hasCleared")) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
KVManger m = KVStore.getInstance();
Map<String, ?> values = seen.getAll();
for (Map.Entry<String, ?> entry : values.entrySet()) {
if (entry.getKey().length() == 6 && entry.getValue() instanceof Boolean) {
m.insert(entry.getKey(), "true");
} else if (entry.getValue() instanceof Long) {
m.insert(entry.getKey(), String.valueOf(seen.getLong(entry.getKey(), 0)));
}
}
seen.edit().clear().putBoolean("isCleared", true).apply();
if (getSharedPreferences("HIDDEN_POSTS", 0).getAll().size() != 0) {
getSharedPreferences("HIDDEN", 0).edit().clear().apply();
getSharedPreferences("HIDDEN_POSTS", 0).edit().clear().apply();
}
if (!Reddit.appRestart.contains("hasCleared")) {
SharedPreferences.Editor e = Reddit.appRestart.edit();
Map<String, ?> toClear = Reddit.appRestart.getAll();
for (Map.Entry<String, ?> entry : toClear.entrySet()) {
if (entry.getValue() instanceof String && ((String) entry.getValue()).length() > 300) {
e.remove(entry.getKey());
}
}
e.putBoolean("hasCleared", true);
e.apply();
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
dismissProgressDialog();
}
@Override
protected void onPreExecute() {
d = new MaterialDialog.Builder(MainActivity.this).title(R.string.misc_setting_up).content(R.string.misc_setting_up_message).progress(true, 100).cancelable(false).build();
d.show();
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
if (!FDroid.isFDroid && Authentication.isLoggedIn && NetworkUtil.isConnected(MainActivity.this)) {
// Display an snackbar that asks the user to rate the app after this
// activity was created 6 times, never again when once clicked or with a maximum of
// two times.
SnackEngage.from(MainActivity.this).withSnack(new RateSnack().withConditions(new NeverAgainWhenClickedOnce(), new AfterNumberOfOpportunities(10), new WithLimitedNumberOfTimes(2)).overrideActionText(getString(R.string.misc_rate_msg)).overrideTitleText(getString(R.string.misc_rate_title)).withDuration(BaseSnack.DURATION_LONG)).build().engageWhenAppropriate();
}
if (SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_TOOLBAR || SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_BOTH) {
setupSubredditSearchToolbar();
}
/**
* int for the current base theme selected.
* 0 = Dark, 1 = Light, 2 = AMOLED, 3 = Dark blue, 4 = AMOLED with contrast, 5 = Sepia
*/
SettingValues.currentTheme = new ColorPreferences(this).getFontStyle().getThemeType();
networkStateReceiver = new NetworkStateReceiver();
networkStateReceiver.addListener(this);
try {
this.registerReceiver(networkStateReceiver, new IntentFilter(android.net.ConnectivityManager.CONNECTIVITY_ACTION));
} catch (Exception e) {
}
}
use of me.ccrama.redditslide.SpoilerRobotoTextView in project Slide by ccrama.
the class CommentAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder firstHolder, int old) {
int pos = old != 0 ? old - 1 : old;
if (firstHolder instanceof CommentViewHolder) {
final CommentViewHolder holder = (CommentViewHolder) firstHolder;
int datasetPosition = pos - 1;
datasetPosition = getRealPosition(datasetPosition);
if (pos > toShiftTo) {
shifted = 0;
}
if (pos < shiftFrom) {
shifted = 0;
}
final CommentNode baseNode = currentComments.get(datasetPosition).comment;
final Comment comment = baseNode.getComment();
if (pos == getItemCount() - 1) {
holder.itemView.setPadding(0, 0, 0, (int) mContext.getResources().getDimension(R.dimen.overview_top_padding_single));
} else {
holder.itemView.setPadding(0, 0, 0, 0);
}
doScoreText(holder, comment, this);
// Long click listeners
View.OnLongClickListener onLongClickListener = new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (SettingValues.swap) {
doOnClick(holder, comment, baseNode);
} else {
doLongClick(holder, comment, baseNode);
}
return true;
}
};
holder.firstTextView.setOnLongClickListener(onLongClickListener);
holder.commentOverflow.setOnLongClickListener(onLongClickListener);
holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (!currentlyEditingId.equals(comment.getFullName())) {
if (SettingValues.swap) {
doOnClick(holder, comment, baseNode);
} else {
doLongClick(holder, comment, baseNode);
}
}
return true;
}
});
// Single click listeners
OnSingleClickListener singleClick = new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
if (!currentlyEditingId.equals(comment.getFullName())) {
if (SettingValues.swap) {
doLongClick(holder, comment, baseNode);
} else {
doOnClick(holder, comment, baseNode);
}
}
}
};
holder.itemView.setOnClickListener(singleClick);
holder.commentOverflow.setOnClickListener(singleClick);
if (!toCollapse.contains(comment.getFullName()) && SettingValues.collapseComments || !SettingValues.collapseComments) {
setViews(comment.getDataNode().get("body_html").asText(), submission.getSubredditName(), holder, singleClick, onLongClickListener);
}
holder.firstTextView.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
SpoilerRobotoTextView SpoilerRobotoTextView = (SpoilerRobotoTextView) v;
if (SettingValues.swap) {
if (!SpoilerRobotoTextView.isSpoilerClicked()) {
doLongClick(holder, comment, baseNode);
} else if (SpoilerRobotoTextView.isSpoilerClicked()) {
SpoilerRobotoTextView.resetSpoilerClicked();
}
} else if (!SpoilerRobotoTextView.isSpoilerClicked()) {
doOnClick(holder, comment, baseNode);
} else if (SpoilerRobotoTextView.isSpoilerClicked()) {
SpoilerRobotoTextView.resetSpoilerClicked();
}
}
});
if (ImageFlairs.isSynced(comment.getSubredditName()) && comment.getAuthorFlair() != null && !comment.getAuthorFlair().getText().isEmpty() && !comment.getAuthorFlair().getCssClass().isEmpty()) {
boolean set = false;
for (String s : comment.getAuthorFlair().getCssClass().split(" ")) {
File file = DiskCacheUtils.findInCache(comment.getSubredditName().toLowerCase(Locale.ENGLISH) + ":" + s.toLowerCase(Locale.ENGLISH), ImageFlairs.getFlairImageLoader(mContext).getInstance().getDiskCache());
if (file != null && file.exists()) {
set = true;
holder.imageFlair.setVisibility(View.VISIBLE);
String decodedImgUri = Uri.fromFile(file).toString();
ImageFlairs.getFlairImageLoader(mContext).displayImage(decodedImgUri, holder.imageFlair);
break;
}
}
if (!set) {
holder.imageFlair.setImageDrawable(null);
holder.imageFlair.setVisibility(View.GONE);
}
} else {
holder.imageFlair.setVisibility(View.GONE);
}
// Set typeface for body
int type = new FontPreferences(mContext).getFontTypeComment().getTypeface();
Typeface typeface;
if (type >= 0) {
typeface = RobotoTypefaces.obtainTypeface(mContext, type);
} else {
typeface = Typeface.DEFAULT;
}
holder.firstTextView.setTypeface(typeface);
// Show padding on top
if (baseNode.isTopLevel()) {
holder.itemView.findViewById(R.id.next).setVisibility(View.VISIBLE);
} else if (holder.itemView.findViewById(R.id.next).getVisibility() == View.VISIBLE) {
holder.itemView.findViewById(R.id.next).setVisibility(View.GONE);
}
// Should be collapsed?
if (hiddenPersons.contains(comment.getFullName()) || toCollapse.contains(comment.getFullName())) {
int childnumber = getChildNumber(baseNode);
if (hiddenPersons.contains(comment.getFullName()) && childnumber > 0) {
holder.childrenNumber.setVisibility(View.VISIBLE);
holder.childrenNumber.setText("+" + childnumber);
} else {
holder.childrenNumber.setVisibility(View.GONE);
}
if (SettingValues.collapseComments && toCollapse.contains(comment.getFullName())) {
holder.firstTextView.setVisibility(View.GONE);
holder.commentOverflow.setVisibility(View.GONE);
}
} else {
holder.childrenNumber.setVisibility(View.GONE);
holder.commentOverflow.setVisibility(View.VISIBLE);
}
holder.dot.setVisibility(View.VISIBLE);
int dwidth = (int) ((SettingValues.largeDepth ? 5 : 3) * Resources.getSystem().getDisplayMetrics().density);
int width = 0;
// Padding on the left, starting with the third comment
for (int i = 2; i < baseNode.getDepth(); i++) {
width += dwidth;
}
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
params.setMargins(width, 0, 0, 0);
holder.itemView.setLayoutParams(params);
RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) holder.dot.getLayoutParams();
params2.width = dwidth;
holder.dot.setLayoutParams(params2);
if (baseNode.getDepth() - 1 > 0) {
int i22 = baseNode.getDepth() - 2;
String commentOp = dataSet.commentOPs.get(comment.getId());
if (SettingValues.highlightCommentOP && commentOp != null && comment != null && commentOp.equals(comment.getAuthor())) {
holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, R.color.md_purple_500));
} else {
if (i22 % 5 == 0) {
holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, !SettingValues.colorCommentDepth ? R.color.md_grey_700 : R.color.md_blue_500));
} else if (i22 % 4 == 0) {
holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, !SettingValues.colorCommentDepth ? R.color.md_grey_600 : R.color.md_green_500));
} else if (i22 % 3 == 0) {
holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, !SettingValues.colorCommentDepth ? R.color.md_grey_500 : R.color.md_yellow_500));
} else if (i22 % 2 == 0) {
holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, !SettingValues.colorCommentDepth ? R.color.md_grey_400 : R.color.md_orange_500));
} else {
holder.dot.setBackgroundColor(ContextCompat.getColor(mContext, !SettingValues.colorCommentDepth ? R.color.md_grey_300 : R.color.md_red_500));
}
}
} else {
holder.dot.setVisibility(View.GONE);
}
if (currentSelectedItem != null && comment.getFullName().contains(currentSelectedItem) && !currentSelectedItem.isEmpty() && !currentlyEditingId.equals(comment.getFullName())) {
doHighlighted(holder, comment, baseNode, false);
} else if (!currentlyEditingId.equals(comment.getFullName())) {
setCommentStateUnhighlighted(holder, baseNode, false);
}
if (deleted.contains(comment.getFullName())) {
holder.firstTextView.setText(R.string.comment_deleted);
holder.content.setText(R.string.comment_deleted);
}
if (currentlyEditingId.equals(comment.getFullName())) {
setCommentStateUnhighlighted(holder, baseNode, false);
setCommentStateHighlighted(holder, comment, baseNode, true, false);
}
} else if (firstHolder instanceof SubmissionViewHolder && submission != null) {
submissionViewHolder = (SubmissionViewHolder) firstHolder;
new PopulateSubmissionViewHolder().populateSubmissionViewHolder((SubmissionViewHolder) firstHolder, submission, (Activity) mContext, true, true, null, listView, false, false, null, this);
if (Authentication.isLoggedIn && Authentication.didOnline) {
if (submission.isArchived() || submission.isLocked()) {
firstHolder.itemView.findViewById(R.id.reply).setVisibility(View.GONE);
} else {
firstHolder.itemView.findViewById(R.id.reply).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
doReplySubmission(firstHolder);
}
});
firstHolder.itemView.findViewById(R.id.discard).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
firstHolder.itemView.findViewById(R.id.innerSend).setVisibility(View.GONE);
currentlyEditing = null;
editingPosition = -1;
if (SettingValues.fastscroll) {
mPage.fastScroll.setVisibility(View.VISIBLE);
}
if (mPage.fab != null)
mPage.fab.setVisibility(View.VISIBLE);
mPage.overrideFab = false;
currentlyEditingId = "";
backedText = "";
View view = ((Activity) mContext).getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
});
}
} else {
firstHolder.itemView.findViewById(R.id.innerSend).setVisibility(View.GONE);
firstHolder.itemView.findViewById(R.id.reply).setVisibility(View.GONE);
}
firstHolder.itemView.findViewById(R.id.more).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
firstHolder.itemView.findViewById(R.id.menu).callOnClick();
}
});
} else if (firstHolder instanceof MoreCommentViewHolder) {
final MoreCommentViewHolder holder = (MoreCommentViewHolder) firstHolder;
int nextPos = pos - 1;
nextPos = getRealPosition(nextPos);
final MoreChildItem baseNode = (MoreChildItem) currentComments.get(nextPos);
if (baseNode.children.getCount() > 0) {
try {
holder.content.setText(mContext.getString(R.string.comment_load_more_string_new, baseNode.children.getLocalizedCount()));
} catch (Exception e) {
holder.content.setText(R.string.comment_load_more_number_unknown);
}
} else if (!baseNode.children.getChildrenIds().isEmpty()) {
holder.content.setText(R.string.comment_load_more_number_unknown);
} else {
holder.content.setText(R.string.thread_continue);
}
int dwidth = (int) ((SettingValues.largeDepth ? 5 : 3) * Resources.getSystem().getDisplayMetrics().density);
int width = 0;
for (int i = 1; i < baseNode.comment.getDepth(); i++) {
width += dwidth;
}
final View progress = holder.loading;
progress.setVisibility(View.GONE);
final int finalNextPos = nextPos;
holder.content.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
if (baseNode.children.getChildrenIds().isEmpty()) {
String toGoTo = "https://reddit.com" + submission.getPermalink() + baseNode.comment.getComment().getId() + "?context=0";
new OpenRedditLink(mContext, toGoTo, true);
} else if (progress.getVisibility() == View.GONE) {
progress.setVisibility(View.VISIBLE);
holder.content.setText(R.string.comment_loading_more);
currentLoading = new AsyncLoadMore(getRealPosition(holder.getAdapterPosition() - 2), holder.getAdapterPosition(), holder, finalNextPos, baseNode.comment.getComment().getFullName());
currentLoading.execute(baseNode);
}
}
});
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
params.setMargins(width, 0, 0, 0);
holder.itemView.setLayoutParams(params);
}
if (firstHolder instanceof SpacerViewHolder) {
// Make a space the size of the toolbar minus 1 so there isn't a gap
firstHolder.itemView.findViewById(R.id.height).setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, (Constants.SINGLE_HEADER_VIEW_OFFSET - Reddit.dpToPxVertical(1) + mPage.shownHeaders)));
}
}
use of me.ccrama.redditslide.SpoilerRobotoTextView in project Slide by ccrama.
the class CommentOverflow method setViews.
/**
* Set the text for the corresponding views.
*
* @param blocks list of all blocks to be set
* @param subreddit
*/
public void setViews(List<String> blocks, String subreddit, OnClickListener click, OnLongClickListener longClick) {
Context context = getContext();
int type = new FontPreferences(context).getFontTypeComment().getTypeface();
if (type >= 0) {
typeface = RobotoTypefaces.obtainTypeface(context, type);
} else {
typeface = Typeface.DEFAULT;
}
TypedValue typedValue = new TypedValue();
Resources.Theme theme = context.getTheme();
theme.resolveAttribute(R.attr.fontColor, typedValue, true);
textColor = typedValue.data;
TypedValue fontSizeTypedValue = new TypedValue();
theme.resolveAttribute(R.attr.font_commentbody, fontSizeTypedValue, true);
TypedArray a = context.obtainStyledAttributes(null, new int[] { R.attr.font_commentbody }, R.attr.font_commentbody, new FontPreferences(context).getCommentFontStyle().getResId());
fontSize = a.getDimensionPixelSize(0, -1);
a.recycle();
removeAllViews();
if (!blocks.isEmpty()) {
setVisibility(View.VISIBLE);
}
for (String block : blocks) {
if (block.startsWith("<table>")) {
HorizontalScrollView scrollView = new HorizontalScrollView(context);
scrollView.setScrollbarFadingEnabled(false);
TableLayout table = formatTable(block, subreddit, click, longClick);
scrollView.setLayoutParams(MARGIN_PARAMS);
table.setPaddingRelative(0, 0, 0, Reddit.dpToPxVertical(10));
scrollView.addView(table);
addView(scrollView);
} else if (block.equals("<hr/>")) {
View line = new View(context);
line.setLayoutParams(HR_PARAMS);
line.setBackgroundColor(textColor);
line.setAlpha(0.6f);
addView(line);
} else if (block.startsWith("<pre>")) {
HorizontalScrollView scrollView = new HorizontalScrollView(context);
scrollView.setScrollbarFadingEnabled(false);
SpoilerRobotoTextView newTextView = new SpoilerRobotoTextView(context);
newTextView.setTextHtml(block, subreddit);
setStyle(newTextView, subreddit);
scrollView.setLayoutParams(MARGIN_PARAMS);
newTextView.setPaddingRelative(0, 0, 0, Reddit.dpToPxVertical(10));
scrollView.addView(newTextView);
if (click != null)
newTextView.setOnClickListener(click);
if (longClick != null)
newTextView.setOnLongClickListener(longClick);
addView(scrollView);
} else {
SpoilerRobotoTextView newTextView = new SpoilerRobotoTextView(context);
newTextView.setTextHtml(block, subreddit);
setStyle(newTextView, subreddit);
newTextView.setLayoutParams(MARGIN_PARAMS);
if (click != null)
newTextView.setOnClickListener(click);
if (longClick != null)
newTextView.setOnLongClickListener(longClick);
addView(newTextView);
}
}
}
use of me.ccrama.redditslide.SpoilerRobotoTextView in project Slide by ccrama.
the class DoEditorActions method doActions.
public static void doActions(final EditText editText, final View baseView, final FragmentManager fm, final Activity a, final String oldComment, @Nullable final String[] authors) {
baseView.findViewById(R.id.bold).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (editText.hasSelection()) {
wrapString("**", // If the user has text selected, wrap that text in the symbols
editText);
} else {
// If the user doesn't have text selected, put the symbols around the cursor's position
int pos = editText.getSelectionStart();
editText.getText().insert(pos, "**");
editText.getText().insert(pos + 1, "**");
// put the cursor between the symbols
editText.setSelection(pos + 2);
}
}
});
if (baseView.findViewById(R.id.author) != null) {
if (authors != null && authors.length > 0) {
baseView.findViewById(R.id.author).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (authors.length == 1) {
int pos = editText.getSelectionStart();
String author = "/u/" + authors[0];
editText.setText(editText.getText().toString() + author);
// put the cursor between the symbols
editText.setSelection(pos + author.length());
} else {
new AlertDialogWrapper.Builder(a).setTitle(R.string.authors_above).setItems(authors, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int pos = editText.getSelectionStart();
String author = "/u/" + authors[which];
editText.setText(editText.getText().toString() + author);
// put the cursor between the symbols
editText.setSelection(pos + author.length());
}
}).setNeutralButton(R.string.btn_cancel, null).show();
}
}
});
} else {
baseView.findViewById(R.id.author).setVisibility(View.GONE);
}
}
baseView.findViewById(R.id.italics).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (editText.hasSelection()) {
wrapString("*", // If the user has text selected, wrap that text in the symbols
editText);
} else {
// If the user doesn't have text selected, put the symbols around the cursor's position
int pos = editText.getSelectionStart();
editText.getText().insert(pos, "*");
editText.getText().insert(pos + 1, "*");
// put the cursor between the symbols
editText.setSelection(pos + 1);
}
}
});
baseView.findViewById(R.id.strike).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (editText.hasSelection()) {
wrapString("~~", // If the user has text selected, wrap that text in the symbols
editText);
} else {
// If the user doesn't have text selected, put the symbols around the cursor's position
int pos = editText.getSelectionStart();
editText.getText().insert(pos, "~~");
editText.getText().insert(pos + 1, "~~");
// put the cursor between the symbols
editText.setSelection(pos + 2);
}
}
});
baseView.findViewById(R.id.savedraft).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Drafts.addDraft(editText.getText().toString());
Snackbar s = Snackbar.make(baseView.findViewById(R.id.savedraft), "Draft saved", Snackbar.LENGTH_SHORT);
View view = s.getView();
TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
s.setAction(R.string.btn_discard, new View.OnClickListener() {
@Override
public void onClick(View view) {
Drafts.deleteDraft(Drafts.getDrafts().size() - 1);
}
});
s.show();
}
});
baseView.findViewById(R.id.draft).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final ArrayList<String> drafts = Drafts.getDrafts();
Collections.reverse(drafts);
final String[] draftText = new String[drafts.size()];
for (int i = 0; i < drafts.size(); i++) {
draftText[i] = drafts.get(i);
}
if (drafts.isEmpty()) {
new AlertDialogWrapper.Builder(a).setTitle(R.string.dialog_no_drafts).setMessage(R.string.dialog_no_drafts_msg).setPositiveButton(R.string.btn_ok, null).show();
} else {
new AlertDialogWrapper.Builder(a).setTitle(R.string.choose_draft).setItems(draftText, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
editText.setText(editText.getText().toString() + draftText[which]);
}
}).setNeutralButton(R.string.btn_cancel, null).setPositiveButton(R.string.manage_drafts, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final boolean[] selected = new boolean[drafts.size()];
new AlertDialogWrapper.Builder(a).setTitle(R.string.choose_draft).setNeutralButton(R.string.btn_cancel, null).alwaysCallMultiChoiceCallback().setNegativeButton(R.string.btn_delete, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new AlertDialogWrapper.Builder(a).setTitle(R.string.really_delete_drafts).setCancelable(false).setPositiveButton(R.string.btn_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ArrayList<String> draf = new ArrayList<>();
for (int i = 0; i < draftText.length; i++) {
if (!selected[i]) {
draf.add(draftText[i]);
}
}
Drafts.save(draf);
}
}).setNegativeButton(R.string.btn_no, null).show();
}
}).setMultiChoiceItems(draftText, selected, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
selected[which] = isChecked;
}
}).show();
}
}).show();
}
}
});
/*todo baseView.findViewById(R.id.strikethrough).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
wrapString("~~", editText);
}
});*/
baseView.findViewById(R.id.imagerep).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
e = editText.getText();
sStart = editText.getSelectionStart();
sEnd = editText.getSelectionEnd();
TedBottomPicker tedBottomPicker = new TedBottomPicker.Builder(editText.getContext()).setOnImageSelectedListener(new TedBottomPicker.OnImageSelectedListener() {
@Override
public void onImageSelected(List<Uri> uri) {
handleImageIntent(uri, editText, a);
}
}).setLayoutResource(R.layout.image_sheet_dialog).setTitle("Choose a photo").create();
tedBottomPicker.show(fm);
InputMethodManager imm = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
}
});
baseView.findViewById(R.id.draw).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (SettingValues.tabletUI) {
doDraw(a, editText, fm);
} else {
AlertDialogWrapper.Builder b = new AlertDialogWrapper.Builder(a).setTitle(R.string.general_cropdraw_ispro).setMessage(R.string.pro_upgrade_msg).setPositiveButton(R.string.btn_yes_exclaim, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
try {
a.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=me.ccrama.slideforreddittabletuiunlock")));
} catch (ActivityNotFoundException e) {
a.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=me.ccrama.slideforreddittabletuiunlock")));
}
}
}).setNegativeButton(R.string.btn_no_danks, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
}
});
if (SettingValues.previews > 0) {
b.setNeutralButton(a.getString(R.string.pro_previews, SettingValues.previews), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SettingValues.prefs.edit().putInt(SettingValues.PREVIEWS_LEFT, SettingValues.previews - 1).apply();
SettingValues.previews = SettingValues.prefs.getInt(SettingValues.PREVIEWS_LEFT, 10);
doDraw(a, editText, fm);
}
});
}
b.show();
}
}
});
/*todo baseView.findViewById(R.id.superscript).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
insertBefore("^", editText);
}
});*/
baseView.findViewById(R.id.size).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
insertBefore("#", editText);
}
});
baseView.findViewById(R.id.quote).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (oldComment != null) {
final TextView showText = new TextView(a);
showText.setText(oldComment);
showText.setTextIsSelectable(true);
int sixteen = Reddit.dpToPxVertical(24);
showText.setPadding(sixteen, 0, sixteen, 0);
AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(a);
builder.setView(showText).setTitle(R.string.editor_actions_quote_comment).setCancelable(true).setPositiveButton(a.getString(R.string.btn_select), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String selected = showText.getText().toString().substring(showText.getSelectionStart(), showText.getSelectionEnd());
if (selected.equals("")) {
insertBefore("> " + oldComment, editText);
} else {
insertBefore("> " + selected + "\n\n", editText);
}
}
}).setNegativeButton(a.getString(R.string.btn_cancel), null).show();
} else {
insertBefore("> ", editText);
}
}
});
baseView.findViewById(R.id.bulletlist).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
insertBefore("* ", editText);
}
});
baseView.findViewById(R.id.numlist).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
insertBefore("1. ", editText);
}
});
baseView.findViewById(R.id.preview).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
List<Extension> extensions = Arrays.asList(TablesExtension.create(), StrikethroughExtension.create());
Parser parser = Parser.builder().extensions(extensions).build();
HtmlRenderer renderer = HtmlRenderer.builder().extensions(extensions).build();
Node document = parser.parse(editText.getText().toString());
String html = renderer.render(document);
LayoutInflater inflater = a.getLayoutInflater();
final View dialoglayout = inflater.inflate(R.layout.parent_comment_dialog, null);
final AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(a);
setViews(html, "NO sub", (SpoilerRobotoTextView) dialoglayout.findViewById(R.id.firstTextView), (CommentOverflow) dialoglayout.findViewById(R.id.commentOverflow));
builder.setView(dialoglayout);
builder.show();
}
});
baseView.findViewById(R.id.link).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final LayoutInflater inflater = LayoutInflater.from(a);
final LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.insert_link, null);
int[] attrs = { R.attr.fontColor };
TypedArray ta = baseView.getContext().obtainStyledAttributes(new ColorPreferences(baseView.getContext()).getFontStyle().getBaseId(), attrs);
ta.recycle();
String selectedText = "";
// if the user highlighted text before inputting a URL, use that text for the descriptionBox
if (editText.hasSelection()) {
final int startSelection = editText.getSelectionStart();
final int endSelection = editText.getSelectionEnd();
selectedText = editText.getText().toString().substring(startSelection, endSelection);
}
final boolean selectedTextNotEmpty = !selectedText.isEmpty();
final MaterialDialog dialog = new MaterialDialog.Builder(editText.getContext()).title(R.string.editor_title_link).customView(layout, false).positiveColorAttr(R.attr.tintColor).positiveText(R.string.editor_action_link).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
final EditText urlBox = (EditText) dialog.findViewById(R.id.url_box);
final EditText textBox = (EditText) dialog.findViewById(R.id.text_box);
dialog.dismiss();
final String s = "[".concat(textBox.getText().toString()).concat("](").concat(urlBox.getText().toString()).concat(")");
int start = Math.max(editText.getSelectionStart(), 0);
int end = Math.max(editText.getSelectionEnd(), 0);
editText.getText().insert(Math.max(start, end), s);
// delete the selected text to avoid duplication
if (selectedTextNotEmpty) {
editText.getText().delete(start, end);
}
}
}).build();
// Tint the hint text if the base theme is Sepia
if (SettingValues.currentTheme == 5) {
((EditText) dialog.findViewById(R.id.url_box)).setHintTextColor(ContextCompat.getColor(dialog.getContext(), R.color.md_grey_600));
((EditText) dialog.findViewById(R.id.text_box)).setHintTextColor(ContextCompat.getColor(dialog.getContext(), R.color.md_grey_600));
}
// use the selected text as the text for the link
if (!selectedText.isEmpty()) {
((EditText) dialog.findViewById(R.id.text_box)).setText(selectedText);
}
dialog.show();
}
});
try {
((ImageInsertEditText) editText).setImageSelectedCallback(new ImageInsertEditText.ImageSelectedCallback() {
@Override
public void onImageSelected(final Uri content, String mimeType) {
e = editText.getText();
sStart = editText.getSelectionStart();
sEnd = editText.getSelectionEnd();
handleImageIntent(new ArrayList<Uri>() {
{
add(content);
}
}, editText, a);
}
});
} catch (Exception e) {
// if thrown, there is likely an issue implementing this on the user's version of Android. There shouldn't be an issue, but just in case
}
}
Aggregations