use of androidx.appcompat.widget.Toolbar in project collect by opendatakit.
the class FormEntryActivity method initToolbar.
private void initToolbar() {
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
setTitle(getString(R.string.loading_form));
}
use of androidx.appcompat.widget.Toolbar in project collect by opendatakit.
the class FormHierarchyActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.hierarchy_layout);
Collect.getInstance().getComponent().inject(this);
recyclerView = findViewById(R.id.list);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
TextView emptyView = findViewById(android.R.id.empty);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FormController formController = Collect.getInstance().getFormController();
// https://github.com/getodk/collect/issues/998
if (formController == null) {
finish();
Timber.w("FormController is null");
return;
}
formEntryViewModel = new ViewModelProvider(this, formEntryViewModelFactory).get(FormEntryViewModel.class);
formEntryViewModel.formLoaded(Collect.getInstance().getFormController());
startIndex = formController.getFormIndex();
setTitle(formController.getFormTitle());
groupPathTextView = findViewById(R.id.pathtext);
jumpBeginningButton = findViewById(R.id.jumpBeginningButton);
jumpEndButton = findViewById(R.id.jumpEndButton);
configureButtons(formController);
restoreInstanceState(savedInstanceState);
refreshView();
// TODO: avoid another iteration through all displayed elements
if (recyclerView != null && recyclerView.getAdapter() != null && recyclerView.getAdapter().getItemCount() > 0) {
emptyView.setVisibility(View.GONE);
recyclerView.post(() -> {
int position = 0;
// startIndex which can either represent a question or a field list.
for (HierarchyElement hierarchyElement : elementsToDisplay) {
FormIndex indexToCheck = hierarchyElement.getFormIndex();
if (startIndex.equals(indexToCheck) || (formController.indexIsInFieldList(startIndex) && indexToCheck.toString().startsWith(startIndex.toString()))) {
position = elementsToDisplay.indexOf(hierarchyElement);
break;
}
}
((LinearLayoutManager) recyclerView.getLayoutManager()).scrollToPositionWithOffset(position, 0);
});
}
}
use of androidx.appcompat.widget.Toolbar in project collect by opendatakit.
the class AboutActivity method initToolbar.
private void initToolbar() {
Toolbar toolbar = findViewById(R.id.toolbar);
setTitle(getString(R.string.about_preferences));
setSupportActionBar(toolbar);
}
use of androidx.appcompat.widget.Toolbar in project ToyShark by LipiLee.
the class DetailActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG).setAction("Action", null).show();
}
});
final ActionBar back = getSupportActionBar();
if (back != null) {
back.setDisplayHomeAsUpEnabled(true);
}
}
use of androidx.appcompat.widget.Toolbar in project Slide by ccrama.
the class MainActivity method doDrawer.
public void doDrawer() {
drawerSubList = (ListView) findViewById(R.id.drawerlistview);
drawerSubList.setDividerHeight(0);
drawerSubList.setDescendantFocusability(ListView.FOCUS_BEFORE_DESCENDANTS);
final LayoutInflater inflater = getLayoutInflater();
final View header;
if (Authentication.isLoggedIn && Authentication.didOnline) {
header = inflater.inflate(R.layout.drawer_loggedin, drawerSubList, false);
headerMain = header;
hea = header.findViewById(R.id.back);
drawerSubList.addHeaderView(header, null, false);
((TextView) header.findViewById(R.id.name)).setText(Authentication.name);
header.findViewById(R.id.multi).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
if (runAfterLoad == null) {
Intent inte = new Intent(MainActivity.this, MultiredditOverview.class);
MainActivity.this.startActivity(inte);
}
}
});
header.findViewById(R.id.multi).setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
new MaterialDialog.Builder(MainActivity.this).inputRange(3, 20).alwaysCallInputCallback().input(getString(R.string.user_enter), null, new MaterialDialog.InputCallback() {
@Override
public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
final EditText editText = dialog.getInputEditText();
EditTextValidator.validateUsername(editText);
if (input.length() >= 3 && input.length() <= 20) {
dialog.getActionButton(DialogAction.POSITIVE).setEnabled(true);
}
}
}).positiveText(R.string.user_btn_gotomultis).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
if (runAfterLoad == null) {
Intent inte = new Intent(MainActivity.this, MultiredditOverview.class);
inte.putExtra(Profile.EXTRA_PROFILE, dialog.getInputEditText().getText().toString());
MainActivity.this.startActivity(inte);
}
}
}).negativeText(R.string.btn_cancel).show();
return true;
}
});
header.findViewById(R.id.discover).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Intent inte = new Intent(MainActivity.this, Discover.class);
MainActivity.this.startActivity(inte);
}
});
header.findViewById(R.id.prof_click).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Intent inte = new Intent(MainActivity.this, Profile.class);
inte.putExtra(Profile.EXTRA_PROFILE, Authentication.name);
MainActivity.this.startActivity(inte);
}
});
header.findViewById(R.id.saved).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Intent inte = new Intent(MainActivity.this, Profile.class);
inte.putExtra(Profile.EXTRA_PROFILE, Authentication.name);
inte.putExtra(Profile.EXTRA_SAVED, true);
MainActivity.this.startActivity(inte);
}
});
header.findViewById(R.id.later).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Intent inte = new Intent(MainActivity.this, PostReadLater.class);
MainActivity.this.startActivity(inte);
}
});
header.findViewById(R.id.history).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Intent inte = new Intent(MainActivity.this, Profile.class);
inte.putExtra(Profile.EXTRA_PROFILE, Authentication.name);
inte.putExtra(Profile.EXTRA_HISTORY, true);
MainActivity.this.startActivity(inte);
}
});
header.findViewById(R.id.commented).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Intent inte = new Intent(MainActivity.this, Profile.class);
inte.putExtra(Profile.EXTRA_PROFILE, Authentication.name);
inte.putExtra(Profile.EXTRA_COMMENT, true);
MainActivity.this.startActivity(inte);
}
});
header.findViewById(R.id.submitted).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Intent inte = new Intent(MainActivity.this, Profile.class);
inte.putExtra(Profile.EXTRA_PROFILE, Authentication.name);
inte.putExtra(Profile.EXTRA_SUBMIT, true);
MainActivity.this.startActivity(inte);
}
});
header.findViewById(R.id.upvoted).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Intent inte = new Intent(MainActivity.this, Profile.class);
inte.putExtra(Profile.EXTRA_PROFILE, Authentication.name);
inte.putExtra(Profile.EXTRA_UPVOTE, true);
MainActivity.this.startActivity(inte);
}
});
/**
* If the user is a known mod, show the "Moderation" drawer item quickly to
* stop the UI from jumping
*/
if (modOf != null && !modOf.isEmpty() && Authentication.mod) {
header.findViewById(R.id.mod).setVisibility(View.VISIBLE);
}
// update notification badge
final LinearLayout profStuff = header.findViewById(R.id.accountsarea);
profStuff.setVisibility(View.GONE);
findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (profStuff.getVisibility() == View.GONE) {
expand(profStuff);
header.setContentDescription(getResources().getString(R.string.btn_collapse));
AnimatorUtil.flipAnimator(false, header.findViewById(R.id.headerflip)).start();
} else {
collapse(profStuff);
header.setContentDescription(getResources().getString(R.string.btn_expand));
AnimatorUtil.flipAnimator(true, header.findViewById(R.id.headerflip)).start();
}
}
});
for (String s : Authentication.authentication.getStringSet("accounts", new HashSet<String>())) {
if (s.contains(":")) {
accounts.put(s.split(":")[0], s.split(":")[1]);
} else {
accounts.put(s, "");
}
}
final ArrayList<String> keys = new ArrayList<>(accounts.keySet());
final LinearLayout accountList = header.findViewById(R.id.accountsarea);
for (final String accName : keys) {
LogUtil.v(accName);
final View t = getLayoutInflater().inflate(R.layout.account_textview_white, accountList, false);
((TextView) t.findViewById(R.id.name)).setText(accName);
LogUtil.v("Adding click to " + ((TextView) t.findViewById(R.id.name)).getText());
t.findViewById(R.id.remove).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new AlertDialog.Builder(MainActivity.this).setTitle(R.string.profile_remove).setMessage(R.string.profile_remove_account).setNegativeButton(R.string.btn_delete, (dialog2, which2) -> {
Set<String> accounts2 = Authentication.authentication.getStringSet("accounts", new HashSet<>());
Set<String> done = new HashSet<>();
for (String s : accounts2) {
if (!s.contains(accName)) {
done.add(s);
}
}
Authentication.authentication.edit().putStringSet("accounts", done).commit();
dialog2.dismiss();
accountList.removeView(t);
if (accName.equalsIgnoreCase(Authentication.name)) {
boolean d = false;
for (String s : keys) {
if (!s.equalsIgnoreCase(accName)) {
d = true;
LogUtil.v("Switching to " + s);
for (Map.Entry<String, String> e : accounts.entrySet()) {
LogUtil.v(e.getKey() + ":" + e.getValue());
}
if (accounts.containsKey(s) && !accounts.get(s).isEmpty()) {
Authentication.authentication.edit().putString("lasttoken", accounts.get(s)).remove("backedCreds").commit();
} else {
ArrayList<String> tokens = new ArrayList<>(Authentication.authentication.getStringSet("tokens", new HashSet<>()));
int index = keys.indexOf(s);
if (keys.indexOf(s) > tokens.size()) {
index -= 1;
}
Authentication.authentication.edit().putString("lasttoken", tokens.get(index)).remove("backedCreds").commit();
}
Authentication.name = s;
UserSubscriptions.switchAccounts();
Reddit.forceRestart(MainActivity.this, true);
break;
}
}
if (!d) {
Authentication.name = "LOGGEDOUT";
Authentication.isLoggedIn = false;
Authentication.authentication.edit().remove("lasttoken").remove("backedCreds").commit();
UserSubscriptions.switchAccounts();
Reddit.forceRestart(MainActivity.this, true);
}
} else {
accounts.remove(accName);
keys.remove(accName);
}
}).setPositiveButton(R.string.btn_cancel, null).show();
}
});
t.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String accName = ((TextView) t.findViewById(R.id.name)).getText().toString();
LogUtil.v("Found name is " + accName);
if (!accName.equalsIgnoreCase(Authentication.name)) {
LogUtil.v("Switching to " + accName);
if (!accounts.get(accName).isEmpty()) {
LogUtil.v("Using token " + accounts.get(accName));
Authentication.authentication.edit().putString("lasttoken", accounts.get(accName)).remove("backedCreds").apply();
} else {
ArrayList<String> tokens = new ArrayList<>(Authentication.authentication.getStringSet("tokens", new HashSet<String>()));
Authentication.authentication.edit().putString("lasttoken", tokens.get(keys.indexOf(accName))).remove("backedCreds").apply();
}
Authentication.name = accName;
UserSubscriptions.switchAccounts();
Reddit.forceRestart(MainActivity.this, true);
}
}
});
accountList.addView(t);
}
header.findViewById(R.id.godown).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
LinearLayout body = header.findViewById(R.id.expand_profile);
if (body.getVisibility() == View.GONE) {
expand(body);
AnimatorUtil.flipAnimator(false, view).start();
view.findViewById(R.id.godown).setContentDescription(getResources().getString(R.string.btn_collapse));
} else {
collapse(body);
AnimatorUtil.flipAnimator(true, view).start();
view.findViewById(R.id.godown).setContentDescription(getResources().getString(R.string.btn_expand));
}
}
});
header.findViewById(R.id.guest_mode).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
Authentication.name = "LOGGEDOUT";
Authentication.isLoggedIn = false;
Authentication.authentication.edit().remove("lasttoken").remove("backedCreds").apply();
UserSubscriptions.switchAccounts();
Reddit.forceRestart(MainActivity.this, true);
}
});
header.findViewById(R.id.add).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Intent inte = new Intent(MainActivity.this, Login.class);
MainActivity.this.startActivity(inte);
}
});
header.findViewById(R.id.offline).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Reddit.appRestart.edit().putBoolean("forceoffline", true).commit();
Reddit.forceRestart(MainActivity.this, false);
}
});
header.findViewById(R.id.inbox).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Intent inte = new Intent(MainActivity.this, Inbox.class);
MainActivity.this.startActivityForResult(inte, INBOX_RESULT);
}
});
headerMain = header;
if (runAfterLoad == null) {
new AsyncNotificationBadge().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
} else if (Authentication.didOnline) {
header = inflater.inflate(R.layout.drawer_loggedout, drawerSubList, false);
drawerSubList.addHeaderView(header, null, false);
headerMain = header;
hea = header.findViewById(R.id.back);
final LinearLayout profStuff = header.findViewById(R.id.accountsarea);
profStuff.setVisibility(View.GONE);
findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (profStuff.getVisibility() == View.GONE) {
expand(profStuff);
AnimatorUtil.flipAnimator(false, header.findViewById(R.id.headerflip)).start();
header.findViewById(R.id.headerflip).setContentDescription(getResources().getString(R.string.btn_collapse));
} else {
collapse(profStuff);
AnimatorUtil.flipAnimator(true, header.findViewById(R.id.headerflip)).start();
header.findViewById(R.id.headerflip).setContentDescription(getResources().getString(R.string.btn_expand));
}
}
});
final HashMap<String, String> accounts = new HashMap<>();
for (String s : Authentication.authentication.getStringSet("accounts", new HashSet<String>())) {
if (s.contains(":")) {
accounts.put(s.split(":")[0], s.split(":")[1]);
} else {
accounts.put(s, "");
}
}
final ArrayList<String> keys = new ArrayList<>(accounts.keySet());
final LinearLayout accountList = header.findViewById(R.id.accountsarea);
for (final String accName : keys) {
LogUtil.v(accName);
final View t = getLayoutInflater().inflate(R.layout.account_textview_white, accountList, false);
((TextView) t.findViewById(R.id.name)).setText(accName);
t.findViewById(R.id.remove).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new AlertDialog.Builder(MainActivity.this).setTitle(R.string.profile_remove).setMessage(R.string.profile_remove_account).setNegativeButton(R.string.btn_delete, (dialog2, which2) -> {
Set<String> accounts2 = Authentication.authentication.getStringSet("accounts", new HashSet<>());
Set<String> done = new HashSet<>();
for (String s : accounts2) {
if (!s.contains(accName)) {
done.add(s);
}
}
Authentication.authentication.edit().putStringSet("accounts", done).commit();
dialog2.dismiss();
accountList.removeView(t);
if (accName.equalsIgnoreCase(Authentication.name)) {
boolean d = false;
for (String s : keys) {
if (!s.equalsIgnoreCase(accName)) {
d = true;
LogUtil.v("Switching to " + s);
if (!accounts.get(s).isEmpty()) {
Authentication.authentication.edit().putString("lasttoken", accounts.get(s)).remove("backedCreds").commit();
} else {
ArrayList<String> tokens = new ArrayList<>(Authentication.authentication.getStringSet("tokens", new HashSet<>()));
Authentication.authentication.edit().putString("lasttoken", tokens.get(keys.indexOf(s))).remove("backedCreds").commit();
}
Authentication.name = s;
UserSubscriptions.switchAccounts();
Reddit.forceRestart(MainActivity.this, true);
}
}
if (!d) {
Authentication.name = "LOGGEDOUT";
Authentication.isLoggedIn = false;
Authentication.authentication.edit().remove("lasttoken").remove("backedCreds").commit();
UserSubscriptions.switchAccounts();
Reddit.forceRestart(MainActivity.this, true);
}
} else {
accounts.remove(accName);
keys.remove(accName);
}
}).setPositiveButton(R.string.btn_cancel, null).show();
}
});
t.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
if (!accName.equalsIgnoreCase(Authentication.name)) {
if (!accounts.get(accName).isEmpty()) {
Authentication.authentication.edit().putString("lasttoken", accounts.get(accName)).remove("backedCreds").commit();
} else {
ArrayList<String> tokens = new ArrayList<>(Authentication.authentication.getStringSet("tokens", new HashSet<String>()));
Authentication.authentication.edit().putString("lasttoken", tokens.get(keys.indexOf(accName))).remove("backedCreds").commit();
}
Authentication.isLoggedIn = true;
Authentication.name = accName;
UserSubscriptions.switchAccounts();
Reddit.forceRestart(MainActivity.this, true);
}
}
});
accountList.addView(t);
}
header.findViewById(R.id.add).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Intent inte = new Intent(MainActivity.this, Login.class);
MainActivity.this.startActivity(inte);
}
});
header.findViewById(R.id.offline).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Reddit.appRestart.edit().putBoolean("forceoffline", true).commit();
Reddit.forceRestart(MainActivity.this, false);
}
});
headerMain = header;
header.findViewById(R.id.multi).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new MaterialDialog.Builder(MainActivity.this).inputRange(3, 20).alwaysCallInputCallback().input(getString(R.string.user_enter), null, new MaterialDialog.InputCallback() {
@Override
public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
final EditText editText = dialog.getInputEditText();
EditTextValidator.validateUsername(editText);
if (input.length() >= 3 && input.length() <= 20) {
dialog.getActionButton(DialogAction.POSITIVE).setEnabled(true);
}
}
}).positiveText(R.string.user_btn_gotomultis).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
if (runAfterLoad == null) {
Intent inte = new Intent(MainActivity.this, MultiredditOverview.class);
inte.putExtra(Profile.EXTRA_PROFILE, dialog.getInputEditText().getText().toString());
MainActivity.this.startActivity(inte);
}
}
}).negativeText(R.string.btn_cancel).show();
}
});
} else {
header = inflater.inflate(R.layout.drawer_offline, drawerSubList, false);
headerMain = header;
drawerSubList.addHeaderView(header, null, false);
hea = header.findViewById(R.id.back);
header.findViewById(R.id.online).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Reddit.appRestart.edit().remove("forceoffline").commit();
Reddit.forceRestart(MainActivity.this, false);
}
});
}
final LinearLayout expandSettings = header.findViewById(R.id.expand_settings);
header.findViewById(R.id.godown_settings).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (expandSettings.getVisibility() == View.GONE) {
expand(expandSettings);
header.findViewById(R.id.godown_settings).setContentDescription(getResources().getString(R.string.btn_collapse));
AnimatorUtil.flipAnimator(false, v).start();
} else {
collapse(expandSettings);
header.findViewById(R.id.godown_settings).setContentDescription(getResources().getString(R.string.btn_expand));
AnimatorUtil.flipAnimator(true, v).start();
}
}
});
{
// Set up quick setting toggles
final SwitchCompat toggleNightMode = expandSettings.findViewById(R.id.toggle_night_mode);
if (SettingValues.isPro) {
toggleNightMode.setVisibility(View.VISIBLE);
toggleNightMode.setChecked(inNightMode);
toggleNightMode.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SettingValues.forcedNightModeState = isChecked ? SettingValues.ForcedState.FORCED_ON : SettingValues.ForcedState.FORCED_OFF;
restartTheme();
}
});
}
final SwitchCompat toggleImmersiveMode = expandSettings.findViewById(R.id.toggle_immersive_mode);
toggleImmersiveMode.setChecked(SettingValues.immersiveMode);
toggleImmersiveMode.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SettingValues.immersiveMode = isChecked;
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_IMMERSIVE_MODE, isChecked).apply();
if (isChecked) {
hideDecor();
} else {
showDecor();
}
}
});
final SwitchCompat toggleNSFW = expandSettings.findViewById(R.id.toggle_nsfw);
toggleNSFW.setChecked(SettingValues.showNSFWContent);
toggleNSFW.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SettingValues.showNSFWContent = isChecked;
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_SHOW_NSFW_CONTENT, isChecked).apply();
reloadSubs();
}
});
final SwitchCompat toggleRightThumbnails = expandSettings.findViewById(R.id.toggle_right_thumbnails);
toggleRightThumbnails.setChecked(SettingValues.switchThumb);
toggleRightThumbnails.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SettingValues.switchThumb = isChecked;
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_SWITCH_THUMB, isChecked).apply();
reloadSubs();
}
});
final SwitchCompat toggleReaderMode = expandSettings.findViewById(R.id.toggle_reader_mode);
toggleReaderMode.setChecked(SettingValues.readerMode);
toggleReaderMode.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SettingValues.readerMode = isChecked;
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_READER_MODE, isChecked).apply();
}
});
}
header.findViewById(R.id.manage).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Intent i = new Intent(MainActivity.this, ManageOfflineContent.class);
startActivity(i);
}
});
if (Authentication.didOnline) {
View support = header.findViewById(R.id.support);
if (SettingValues.isPro) {
support.setVisibility(View.GONE);
} else {
support.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
ProUtil.proUpgradeMsg(MainActivity.this, R.string.settings_support_slide).setNegativeButton(R.string.btn_no_thanks, (dialog, whichButton) -> dialog.dismiss()).show();
}
});
}
header.findViewById(R.id.prof).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new MaterialDialog.Builder(MainActivity.this).inputRange(3, 20).alwaysCallInputCallback().input(getString(R.string.user_enter), null, new MaterialDialog.InputCallback() {
@Override
public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
final EditText editText = dialog.getInputEditText();
EditTextValidator.validateUsername(editText);
if (input.length() >= 3 && input.length() <= 20) {
dialog.getActionButton(DialogAction.POSITIVE).setEnabled(true);
}
}
}).positiveText(R.string.user_btn_goto).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
Intent inte = new Intent(MainActivity.this, Profile.class);
// noinspection ConstantConditions
inte.putExtra(Profile.EXTRA_PROFILE, dialog.getInputEditText().getText().toString());
MainActivity.this.startActivity(inte);
}
}).negativeText(R.string.btn_cancel).show();
}
});
}
header.findViewById(R.id.settings).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
Intent i = new Intent(MainActivity.this, SettingsActivity.class);
startActivity(i);
// Cancel sub loading because exiting the settings will reload it anyway
if (mAsyncGetSubreddit != null)
mAsyncGetSubreddit.cancel(true);
drawerLayout.closeDrawers();
}
});
/* footer.findViewById(R.id.settings).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent inte = new Intent(Overview.this, Setting.class);
Overview.this.startActivityForResult(inte, 3);
}
});*/
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
final ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(MainActivity.this, drawerLayout, toolbar, R.string.btn_open, R.string.btn_close) {
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
// this disables the animation
super.onDrawerSlide(drawerView, 0);
}
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
if (drawerLayout.isDrawerOpen(GravityCompat.END)) {
int current = pager.getCurrentItem();
if (current == toOpenComments && toOpenComments != 0) {
current -= 1;
}
String compare = usedArray.get(current);
if (compare.equals("random") || compare.equals("myrandom") || compare.equals("randnsfw")) {
if (adapter != null && adapter.getCurrentFragment() != null && ((SubmissionsView) adapter.getCurrentFragment()).adapter.dataSet.subredditRandom != null) {
String sub = ((SubmissionsView) adapter.getCurrentFragment()).adapter.dataSet.subredditRandom;
doSubSidebarNoLoad(sub);
doSubSidebar(sub);
}
} else {
doSubSidebar(usedArray.get(current));
}
}
}
@Override
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
KeyboardUtil.hideKeyboard(MainActivity.this, drawerLayout.getWindowToken(), 0);
}
};
drawerLayout.addDrawerListener(actionBarDrawerToggle);
actionBarDrawerToggle.syncState();
header.findViewById(R.id.back).setBackgroundColor(Palette.getColor("alsdkfjasld"));
accountsArea = header.findViewById(R.id.accountsarea);
if (accountsArea != null) {
accountsArea.setBackgroundColor(Palette.getDarkerColor("alsdkfjasld"));
}
setDrawerSubList();
hideDrawerItems();
}
Aggregations