use of me.ccrama.redditslide.Views.ImageInsertEditText in project Slide by ccrama.
the class Submit method onCreate.
public void onCreate(Bundle savedInstanceState) {
disableSwipeBackLayout();
super.onCreate(savedInstanceState);
applyColorTheme();
setContentView(R.layout.activity_submit);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = this.getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
}
setupAppBar(R.id.toolbar, R.string.title_submit_post, true, true);
inboxReplies = (SwitchCompat) findViewById(R.id.replies);
Intent intent = getIntent();
final String subreddit = intent.getStringExtra(EXTRA_SUBREDDIT);
final String initialBody = intent.getStringExtra(EXTRA_BODY);
self = findViewById(R.id.selftext);
final AutoCompleteTextView subredditText = ((AutoCompleteTextView) findViewById(R.id.subreddittext));
image = findViewById(R.id.image);
link = findViewById(R.id.url);
image.setVisibility(View.GONE);
link.setVisibility(View.GONE);
if (subreddit != null && !subreddit.equals("frontpage") && !subreddit.equals("all") && !subreddit.equals("friends") && !subreddit.equals("mod") && !subreddit.contains("/m/") && !subreddit.contains("+")) {
subredditText.setText(subreddit);
}
if (initialBody != null) {
((ImageInsertEditText) self.findViewById(R.id.bodytext)).setText(initialBody);
}
ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, UserSubscriptions.getAllSubreddits(this));
subredditText.setAdapter(adapter);
subredditText.setThreshold(2);
subredditText.addTextChangedListener(new SimpleTextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (tchange != null) {
tchange.cancel(true);
}
findViewById(R.id.submittext).setVisibility(View.GONE);
}
});
subredditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
findViewById(R.id.submittext).setVisibility(View.GONE);
if (!hasFocus) {
tchange = new AsyncTask<Void, Void, Subreddit>() {
@Override
protected Subreddit doInBackground(Void... params) {
try {
return Authentication.reddit.getSubreddit(subredditText.getText().toString());
} catch (Exception ignored) {
}
return null;
}
@Override
protected void onPostExecute(Subreddit s) {
if (s != null) {
String text = s.getDataNode().get("submit_text_html").asText();
if (text != null && !text.isEmpty() && !text.equals("null")) {
findViewById(R.id.submittext).setVisibility(View.VISIBLE);
setViews(text, subredditText.getText().toString(), (SpoilerRobotoTextView) findViewById(R.id.submittext), (CommentOverflow) findViewById(R.id.commentOverflow));
}
if (s.getSubredditType().equals("RESTRICTED")) {
subredditText.setText("");
new AlertDialog.Builder(Submit.this).setTitle(R.string.err_submit_restricted).setMessage(R.string.err_submit_restricted_text).setPositiveButton(R.string.btn_ok, null).show();
}
} else {
findViewById(R.id.submittext).setVisibility(View.GONE);
}
}
};
tchange.execute();
}
}
});
findViewById(R.id.selftextradio).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
self.setVisibility(View.VISIBLE);
image.setVisibility(View.GONE);
link.setVisibility(View.GONE);
}
});
findViewById(R.id.imageradio).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
self.setVisibility(View.GONE);
image.setVisibility(View.VISIBLE);
link.setVisibility(View.GONE);
}
});
findViewById(R.id.linkradio).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
self.setVisibility(View.GONE);
image.setVisibility(View.GONE);
link.setVisibility(View.VISIBLE);
}
});
findViewById(R.id.flair).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showFlairChooser();
}
});
findViewById(R.id.suggest).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new AsyncTask<String, Void, String>() {
Dialog d;
@Override
protected String doInBackground(String... params) {
try {
return TitleExtractor.getPageTitle(params[0]);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPreExecute() {
d = new MaterialDialog.Builder(Submit.this).progress(true, 100).title(R.string.editor_finding_title).content(R.string.misc_please_wait).show();
}
@Override
protected void onPostExecute(String s) {
if (s != null) {
((EditText) findViewById(R.id.titletext)).setText(s);
d.dismiss();
} else {
d.dismiss();
new AlertDialog.Builder(Submit.this).setTitle(R.string.title_not_found).setPositiveButton(R.string.btn_ok, null).show();
}
}
}.execute(((EditText) findViewById(R.id.urltext)).getText().toString());
}
});
findViewById(R.id.selImage).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
TedBottomPicker tedBottomPicker = new TedBottomPicker.Builder(Submit.this).setOnImageSelectedListener(Submit.this::handleImageIntent).setLayoutResource(R.layout.image_sheet_dialog).setTitle("Choose a photo").create();
tedBottomPicker.show(getSupportFragmentManager());
KeyboardUtil.hideKeyboard(Submit.this, findViewById(R.id.bodytext).getWindowToken(), 0);
}
});
DoEditorActions.doActions(((EditText) findViewById(R.id.bodytext)), findViewById(R.id.selftext), getSupportFragmentManager(), Submit.this, null, null);
if (intent.hasExtra(Intent.EXTRA_TEXT) && !intent.getExtras().getString(Intent.EXTRA_TEXT, "").isEmpty() && !intent.getBooleanExtra(EXTRA_IS_SELF, false)) {
String data = intent.getStringExtra(Intent.EXTRA_TEXT);
if (data.contains("\n")) {
((EditText) findViewById(R.id.titletext)).setText(data.substring(0, data.indexOf("\n")));
((EditText) findViewById(R.id.urltext)).setText(data.substring(data.indexOf("\n")));
} else {
((EditText) findViewById(R.id.urltext)).setText(data);
}
self.setVisibility(View.GONE);
image.setVisibility(View.GONE);
link.setVisibility(View.VISIBLE);
((RadioButton) findViewById(R.id.linkradio)).setChecked(true);
} else if (intent.hasExtra(Intent.EXTRA_STREAM)) {
final Uri imageUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (imageUri != null) {
handleImageIntent(new ArrayList<Uri>() {
{
add(imageUri);
}
});
self.setVisibility(View.GONE);
image.setVisibility(View.VISIBLE);
link.setVisibility(View.GONE);
((RadioButton) findViewById(R.id.imageradio)).setChecked(true);
}
}
if (intent.hasExtra(Intent.EXTRA_SUBJECT) && !intent.getExtras().getString(Intent.EXTRA_SUBJECT, "").isEmpty()) {
String data = intent.getStringExtra(Intent.EXTRA_SUBJECT);
((EditText) findViewById(R.id.titletext)).setText(data);
}
findViewById(R.id.send).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
((FloatingActionButton) findViewById(R.id.send)).hide();
new AsyncDo().execute();
}
});
}
Aggregations