diff --git a/app/src/main/java/app/fedilab/android/activities/ShowAccountActivity.java b/app/src/main/java/app/fedilab/android/activities/ShowAccountActivity.java index 6c3478ea3..8adb1294a 100644 --- a/app/src/main/java/app/fedilab/android/activities/ShowAccountActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ShowAccountActivity.java @@ -16,7 +16,6 @@ package app.fedilab.android.activities; import android.content.ClipData; import android.content.ClipboardManager; -import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.ColorStateList; @@ -63,6 +62,8 @@ import com.bumptech.glide.request.transition.Transition; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.tabs.TabLayout; +import org.jetbrains.annotations.NotNull; + import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -231,30 +232,17 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt account_note = findViewById(R.id.account_note); - header_edit_profile.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Intent intent = new Intent(ShowAccountActivity.this, EditProfileActivity.class); - startActivity(intent); - } + header_edit_profile.setOnClickListener(v -> { + Intent intent = new Intent(ShowAccountActivity.this, EditProfileActivity.class); + startActivity(intent); }); final ImageView account_menu = findViewById(R.id.account_menu); ImageView action_more = findViewById(R.id.action_more); ImageView reload_tabs = findViewById(R.id.reload_tabs); ImageView action_back = findViewById(R.id.action_back); - account_menu.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - showMenu(account_menu); - } - }); - action_more.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - showMenu(account_menu); - } - }); + account_menu.setOnClickListener(v -> showMenu(account_menu)); + action_more.setOnClickListener(v -> showMenu(account_menu)); reload_tabs.setOnClickListener(view -> { if (mPager != null && mPager @@ -285,12 +273,7 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt } } }); - action_back.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - finish(); - } - }); + action_back.setOnClickListener(v -> finish()); if (account != null) { ManageAccount(); } @@ -381,13 +364,10 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt content.setSpan(new ForegroundColorSpan(ContextCompat.getColor(ShowAccountActivity.this, R.color.cyanea_accent_reference)), 0, content.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); warning_message.setText(content); - warning_message.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (!accountUrl.toLowerCase().startsWith("http://") && !accountUrl.toLowerCase().startsWith("https://")) - accountUrl = "http://" + accountUrl; - Helper.openBrowser(ShowAccountActivity.this, accountUrl); - } + warning_message.setOnClickListener(view -> { + if (!accountUrl.toLowerCase().startsWith("http://") && !accountUrl.toLowerCase().startsWith("https://")) + accountUrl = "http://" + accountUrl; + Helper.openBrowser(ShowAccountActivity.this, accountUrl); }); //Timed muted account String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); @@ -403,14 +383,11 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt SpannableString content_temp_mute = new SpannableString(getString(R.string.timed_mute_profile, account.getAcct(), date_mute)); content_temp_mute.setSpan(new UnderlineSpan(), 0, content_temp_mute.length(), 0); temp_mute.setText(content_temp_mute); - temp_mute.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - new TempMuteDAO(getApplicationContext(), db).remove(authenticatedAccount, accountId); - mutedAccount.remove(accountId); - Toasty.success(getApplicationContext(), getString(R.string.toast_unmute), Toast.LENGTH_LONG).show(); - temp_mute.setVisibility(View.GONE); - } + temp_mute.setOnClickListener(view -> { + new TempMuteDAO(getApplicationContext(), db).remove(authenticatedAccount, accountId); + mutedAccount.remove(accountId); + Toasty.success(getApplicationContext(), getString(R.string.toast_unmute), Toast.LENGTH_LONG).show(); + temp_mute.setVisibility(View.GONE); }); } } @@ -433,43 +410,40 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt warning_message.setVisibility(View.VISIBLE); else warning_message.setVisibility(View.GONE); - appBar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { - @Override - public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { - LinearLayout toolbarContent = findViewById(R.id.toolbar_content); - if (toolbarContent != null) { - if (Math.abs(verticalOffset) - appBar.getTotalScrollRange() == 0) { - if (toolbarContent.getVisibility() == View.GONE) - toolbarContent.setVisibility(View.VISIBLE); - } else { - if (toolbarContent.getVisibility() == View.VISIBLE) - toolbarContent.setVisibility(View.GONE); - } + appBar.addOnOffsetChangedListener((appBarLayout, verticalOffset) -> { + LinearLayout toolbarContent = findViewById(R.id.toolbar_content); + if (toolbarContent != null) { + if (Math.abs(verticalOffset) - appBar.getTotalScrollRange() == 0) { + if (toolbarContent.getVisibility() == View.GONE) + toolbarContent.setVisibility(View.VISIBLE); + } else { + if (toolbarContent.getVisibility() == View.VISIBLE) + toolbarContent.setVisibility(View.GONE); } - if (maxScrollSize == 0) - maxScrollSize = appBarLayout.getTotalScrollRange(); + } + if (maxScrollSize == 0) + maxScrollSize = appBarLayout.getTotalScrollRange(); - int percentage = (Math.abs(verticalOffset)) * 100 / maxScrollSize; + int percentage = (Math.abs(verticalOffset)) * 100 / maxScrollSize; - if (percentage >= 40 && avatarShown) { - avatarShown = false; + if (percentage >= 40 && avatarShown) { + avatarShown = false; - account_pp.animate() - .scaleY(0).scaleX(0) - .setDuration(400) - .start(); + account_pp.animate() + .scaleY(0).scaleX(0) + .setDuration(400) + .start(); + warning_message.setVisibility(View.GONE); + } + if (percentage <= 40 && !avatarShown) { + avatarShown = true; + account_pp.animate() + .scaleY(1).scaleX(1) + .start(); + if (account.getAcct().contains("@")) + warning_message.setVisibility(View.VISIBLE); + else warning_message.setVisibility(View.GONE); - } - if (percentage <= 40 && !avatarShown) { - avatarShown = true; - account_pp.animate() - .scaleY(1).scaleX(1) - .start(); - if (account.getAcct().contains("@")) - warning_message.setVisibility(View.VISIBLE); - else - warning_message.setVisibility(View.GONE); - } } }); mPager = findViewById(R.id.account_viewpager); @@ -599,18 +573,12 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt valueView = findViewById(R.id.value3); verifiedView = findViewById(R.id.value3BG); break; - case 4: + default: field = findViewById(R.id.field4); labelView = findViewById(R.id.label4); valueView = findViewById(R.id.value4); verifiedView = findViewById(R.id.value4BG); break; - default: - field = findViewById(R.id.field1); - labelView = findViewById(R.id.label1); - valueView = findViewById(R.id.value1); - verifiedView = findViewById(R.id.value1BG); - break; } if (field != null && labelView != null && valueView != null) { field.setVisibility(View.VISIBLE); @@ -627,19 +595,16 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt account_dn.setText(Helper.shortnameToUnicode(account.getDisplay_name(), true)); if (!ischannel || account.getAcct().split("-").length < 4) { account_un.setText(String.format("@%s", account.getAcct())); - account_un.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); - String account_id = account.getAcct(); - if (account_id.split("@").length == 1) - account_id += "@" + Helper.getLiveInstance(getApplicationContext()); - ClipData clip = ClipData.newPlainText("mastodon_account_id", "@" + account_id); - Toasty.info(getApplicationContext(), getString(R.string.account_id_clipbloard), Toast.LENGTH_SHORT).show(); - assert clipboard != null; - clipboard.setPrimaryClip(clip); - return false; - } + account_un.setOnLongClickListener(v -> { + ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); + String account_id = account.getAcct(); + if (account_id.split("@").length == 1) + account_id += "@" + Helper.getLiveInstance(getApplicationContext()); + ClipData clip = ClipData.newPlainText("mastodon_account_id", "@" + account_id); + Toasty.info(getApplicationContext(), getString(R.string.account_id_clipbloard), Toast.LENGTH_SHORT).show(); + assert clipboard != null; + clipboard.setPrimaryClip(clip); + return false; }); } else { account_un.setVisibility(View.GONE); @@ -660,172 +625,147 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt //Allows to filter by long click final LinearLayout tabStrip = (LinearLayout) tabLayout.getChildAt(0); - tabStrip.getChildAt(0).setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - PopupMenu popup = new PopupMenu(ShowAccountActivity.this, tabStrip.getChildAt(0)); - popup.getMenuInflater() - .inflate(R.menu.option_filter_toots_account, popup.getMenu()); - Menu menu = popup.getMenu(); + tabStrip.getChildAt(0).setOnLongClickListener(v -> { + PopupMenu popup = new PopupMenu(ShowAccountActivity.this, tabStrip.getChildAt(0)); + popup.getMenuInflater() + .inflate(R.menu.option_filter_toots_account, popup.getMenu()); + Menu menu = popup.getMenu(); - popup.getMenu().findItem(R.id.action_show_pinned).setVisible(false); - final MenuItem itemShowPined = menu.findItem(R.id.action_show_pinned); - final MenuItem itemShowMedia = menu.findItem(R.id.action_show_media); - final MenuItem itemShowBoosts = menu.findItem(R.id.action_show_boosts); - final MenuItem itemShowReplies = menu.findItem(R.id.action_show_replies); + popup.getMenu().findItem(R.id.action_show_pinned).setVisible(false); + final MenuItem itemShowPined = menu.findItem(R.id.action_show_pinned); + final MenuItem itemShowMedia = menu.findItem(R.id.action_show_media); + final MenuItem itemShowBoosts = menu.findItem(R.id.action_show_boosts); + final MenuItem itemShowReplies = menu.findItem(R.id.action_show_replies); + itemShowMedia.setChecked(showMediaOnly); + itemShowPined.setChecked(showPinned); + itemShowBoosts.setChecked(show_boosts); + itemShowReplies.setChecked(show_replies); + + popup.setOnDismissListener(menu1 -> { + if (mPager != null && mPager + .getAdapter() != null) { + if (mPager + .getAdapter() + .instantiateItem(mPager, mPager.getCurrentItem()) instanceof TabLayoutTootsFragment) { + TabLayoutTootsFragment tabLayoutTootsFragment = (TabLayoutTootsFragment) mPager + .getAdapter() + .instantiateItem(mPager, mPager.getCurrentItem()); + ViewPager viewPager = tabLayoutTootsFragment.getViewPager(); + if (viewPager != null && viewPager.getAdapter() != null && viewPager + .getAdapter() + .instantiateItem(viewPager, viewPager.getCurrentItem()) instanceof DisplayStatusFragment) { + DisplayStatusFragment displayStatusFragment = (DisplayStatusFragment) viewPager + .getAdapter() + .instantiateItem(viewPager, viewPager.getCurrentItem()); + displayStatusFragment.pullToRefresh(); + displayStatusFragment.refreshFilter(); + } + + } + } + + }); + popup.setOnMenuItemClickListener(item -> { + item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); + item.setActionView(new View(getApplicationContext())); + item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() { + @Override + public boolean onMenuItemActionExpand(MenuItem item) { + return false; + } + + @Override + public boolean onMenuItemActionCollapse(MenuItem item) { + return false; + } + }); + switch (item.getItemId()) { + case R.id.action_show_pinned: + showPinned = !showPinned; + break; + case R.id.action_show_media: + showMediaOnly = !showMediaOnly; + break; + case R.id.action_show_boosts: + show_boosts = !show_boosts; + + break; + case R.id.action_show_replies: + show_replies = !show_replies; + break; + } + if (tabLayout.getTabAt(0) != null) + //noinspection ConstantConditions + tabLayout.getTabAt(0).select(); + PagerAdapter mPagerAdapter1 = new ScreenSlidePagerAdapter(getSupportFragmentManager()); + mPager.setAdapter(mPagerAdapter1); itemShowMedia.setChecked(showMediaOnly); itemShowPined.setChecked(showPinned); - itemShowBoosts.setChecked(show_boosts); itemShowReplies.setChecked(show_replies); - - popup.setOnDismissListener(new PopupMenu.OnDismissListener() { - @Override - public void onDismiss(PopupMenu menu) { - if (mPager != null && mPager - .getAdapter() != null) { - if (mPager - .getAdapter() - .instantiateItem(mPager, mPager.getCurrentItem()) instanceof TabLayoutTootsFragment) { - TabLayoutTootsFragment tabLayoutTootsFragment = (TabLayoutTootsFragment) mPager - .getAdapter() - .instantiateItem(mPager, mPager.getCurrentItem()); - ViewPager viewPager = tabLayoutTootsFragment.getViewPager(); - if (viewPager != null && viewPager.getAdapter() != null && viewPager - .getAdapter() - .instantiateItem(viewPager, viewPager.getCurrentItem()) instanceof DisplayStatusFragment) { - DisplayStatusFragment displayStatusFragment = (DisplayStatusFragment) viewPager - .getAdapter() - .instantiateItem(viewPager, viewPager.getCurrentItem()); - displayStatusFragment.pullToRefresh(); - displayStatusFragment.refreshFilter(); - } - - } - } - - } - }); - popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - public boolean onMenuItemClick(MenuItem item) { - item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); - item.setActionView(new View(getApplicationContext())); - item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() { - @Override - public boolean onMenuItemActionExpand(MenuItem item) { - return false; - } - - @Override - public boolean onMenuItemActionCollapse(MenuItem item) { - return false; - } - }); - switch (item.getItemId()) { - case R.id.action_show_pinned: - showPinned = !showPinned; - break; - case R.id.action_show_media: - showMediaOnly = !showMediaOnly; - break; - case R.id.action_show_boosts: - show_boosts = !show_boosts; - - break; - case R.id.action_show_replies: - show_replies = !show_replies; - break; - } - if (tabLayout.getTabAt(0) != null) - //noinspection ConstantConditions - tabLayout.getTabAt(0).select(); - PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager()); - mPager.setAdapter(mPagerAdapter); - itemShowMedia.setChecked(showMediaOnly); - itemShowPined.setChecked(showPinned); - itemShowReplies.setChecked(show_replies); - itemShowBoosts.setChecked(show_boosts); - return true; - } - }); - popup.show(); + itemShowBoosts.setChecked(show_boosts); return true; - } + }); + popup.show(); + return true; }); } Helper.loadGiF(getApplicationContext(), account.getAvatar(), account_pp); - account_pp.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Intent intent = new Intent(ShowAccountActivity.this, SlideMediaActivity.class); - Bundle b = new Bundle(); - Attachment attachment = new Attachment(); - attachment.setDescription(account.getAcct()); - attachment.setPreview_url(account.getAvatar()); - attachment.setUrl(account.getAvatar()); - attachment.setRemote_url(account.getAvatar()); - attachment.setType("image"); - ArrayList attachments = new ArrayList<>(); - attachments.add(attachment); - intent.putParcelableArrayListExtra("mediaArray", attachments); - b.putInt("position", 1); - intent.putExtras(b); - startActivity(intent); - } + account_pp.setOnClickListener(v -> { + Intent intent = new Intent(ShowAccountActivity.this, SlideMediaActivity.class); + Bundle b = new Bundle(); + Attachment attachment = new Attachment(); + attachment.setDescription(account.getAcct()); + attachment.setPreview_url(account.getAvatar()); + attachment.setUrl(account.getAvatar()); + attachment.setRemote_url(account.getAvatar()); + attachment.setType("image"); + ArrayList attachments = new ArrayList<>(); + attachments.add(attachment); + intent.putParcelableArrayListExtra("mediaArray", attachments); + b.putInt("position", 1); + intent.putExtras(b); + startActivity(intent); }); //Follow button String target = account.getId(); if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) target = account.getAcct(); String finalTarget = target; - account_follow.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (doAction == action.NOTHING) { - Toasty.info(getApplicationContext(), getString(R.string.nothing_to_do), Toast.LENGTH_LONG).show(); - } else if (doAction == action.FOLLOW) { - account_follow.setEnabled(false); - new PostActionAsyncTask(getApplicationContext(), API.StatusAction.FOLLOW, finalTarget, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } else if (doAction == action.UNFOLLOW) { - boolean confirm_unfollow = sharedpreferences.getBoolean(Helper.SET_UNFOLLOW_VALIDATION, true); - if (confirm_unfollow) { - AlertDialog.Builder unfollowConfirm = new AlertDialog.Builder(ShowAccountActivity.this, style); - unfollowConfirm.setTitle(getString(R.string.unfollow_confirm)); - unfollowConfirm.setMessage(account.getAcct()); - unfollowConfirm.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - } - }); - unfollowConfirm.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - account_follow.setEnabled(false); - new PostActionAsyncTask(getApplicationContext(), API.StatusAction.UNFOLLOW, finalTarget, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - dialog.dismiss(); - } - }); - unfollowConfirm.show(); - } else { + account_follow.setOnClickListener(v -> { + if (doAction == action.NOTHING) { + Toasty.info(getApplicationContext(), getString(R.string.nothing_to_do), Toast.LENGTH_LONG).show(); + } else if (doAction == action.FOLLOW) { + account_follow.setEnabled(false); + new PostActionAsyncTask(getApplicationContext(), API.StatusAction.FOLLOW, finalTarget, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } else if (doAction == action.UNFOLLOW) { + boolean confirm_unfollow = sharedpreferences.getBoolean(Helper.SET_UNFOLLOW_VALIDATION, true); + if (confirm_unfollow) { + AlertDialog.Builder unfollowConfirm = new AlertDialog.Builder(ShowAccountActivity.this, style); + unfollowConfirm.setTitle(getString(R.string.unfollow_confirm)); + unfollowConfirm.setMessage(account.getAcct()); + unfollowConfirm.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); + unfollowConfirm.setPositiveButton(R.string.yes, (dialog, which) -> { account_follow.setEnabled(false); new PostActionAsyncTask(getApplicationContext(), API.StatusAction.UNFOLLOW, finalTarget, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - - } else if (doAction == action.UNBLOCK) { + dialog.dismiss(); + }); + unfollowConfirm.show(); + } else { account_follow.setEnabled(false); - new PostActionAsyncTask(getApplicationContext(), API.StatusAction.UNBLOCK, finalTarget, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + new PostActionAsyncTask(getApplicationContext(), API.StatusAction.UNFOLLOW, finalTarget, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } + + } else if (doAction == action.UNBLOCK) { + account_follow.setEnabled(false); + new PostActionAsyncTask(getApplicationContext(), API.StatusAction.UNBLOCK, finalTarget, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } }); - account_follow.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - CrossActions.doCrossAction(ShowAccountActivity.this, null, null, account, API.StatusAction.FOLLOW, null, ShowAccountActivity.this, false); - return false; - } + account_follow.setOnLongClickListener(v -> { + CrossActions.doCrossAction(ShowAccountActivity.this, null, null, account, API.StatusAction.FOLLOW, null, ShowAccountActivity.this, false); + return false; }); UserNote userNote = new NotesDAO(getApplicationContext(), db).getUserNote(account.getAcct()); @@ -844,29 +784,21 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt input.setText(userNote.getNote()); input.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION); builderInner.setView(input); - builderInner.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); + builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); + builderInner.setPositiveButton(R.string.validate, (dialog, which) -> { + UserNote userNote1 = new NotesDAO(getApplicationContext(), db).getUserNote(account.getAcct()); + if (userNote1 == null) { + userNote1 = new UserNote(); + userNote1.setAcct(account.getAcct()); } - }); - builderInner.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - UserNote userNote = new NotesDAO(getApplicationContext(), db).getUserNote(account.getAcct()); - if (userNote == null) { - userNote = new UserNote(); - userNote.setAcct(account.getAcct()); - } - userNote.setNote(input.getText().toString()); - new NotesDAO(getApplicationContext(), db).insertInstance(userNote); - if (input.getText().toString().trim().length() > 0) { - account_personal_note.setVisibility(View.VISIBLE); - } else { - account_personal_note.setVisibility(View.GONE); - } - dialog.dismiss(); + userNote1.setNote(input.getText().toString()); + new NotesDAO(getApplicationContext(), db).insertInstance(userNote1); + if (input.getText().toString().trim().length() > 0) { + account_personal_note.setVisibility(View.VISIBLE); + } else { + account_personal_note.setVisibility(View.GONE); } + dialog.dismiss(); }); builderInner.show(); }); @@ -875,37 +807,32 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt TextView account_date = findViewById(R.id.account_date); account_date.setText(Helper.shortDateToString(account.getCreated_at())); account_date.setVisibility(View.VISIBLE); - new Thread(new Runnable() { - @Override - public void run() { - - String instance = getLiveInstance(getApplicationContext()); - if (account.getAcct().split("@").length > 1) { - instance = account.getAcct().split("@")[1]; - } - InstanceNodeInfo instanceNodeInfo = new API(ShowAccountActivity.this).displayNodeInfo(instance); - String finalInstance = instance; - runOnUiThread(new Runnable() { - public void run() { - if (instanceNodeInfo != null && instanceNodeInfo.getName() != null) { - TextView instance_info = findViewById(R.id.instance_info); - instance_info.setText(instanceNodeInfo.getName()); - instance_info.setVisibility(View.VISIBLE); - - instance_info.setOnClickListener(v -> { - Intent intent = new Intent(getApplicationContext(), InstanceProfileActivity.class); - Bundle b = new Bundle(); - b.putString("instance", finalInstance); - intent.putExtras(b); - startActivity(intent); - - }); - } - } - }); - + new Thread(() -> { + String instance1 = getLiveInstance(getApplicationContext()); + if (account.getAcct().split("@").length > 1) { + instance1 = account.getAcct().split("@")[1]; } + InstanceNodeInfo instanceNodeInfo = new API(ShowAccountActivity.this).displayNodeInfo(instance1); + String finalInstance = instance1; + runOnUiThread(() -> { + if (instanceNodeInfo != null && instanceNodeInfo.getName() != null) { + TextView instance_info = findViewById(R.id.instance_info); + instance_info.setText(instanceNodeInfo.getName()); + instance_info.setVisibility(View.VISIBLE); + + instance_info.setOnClickListener(v -> { + Intent intent = new Intent(getApplicationContext(), InstanceProfileActivity.class); + Bundle b = new Bundle(); + b.putString("instance", finalInstance); + intent.putExtras(b); + startActivity(intent); + + }); + } + }); + + }).start(); } @@ -1089,12 +1016,7 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt boolean disableAnimatedEmoji = sharedpreferences.getBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, false); if (!disableAnimatedEmoji) { scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); - scheduledExecutorService.scheduleAtFixedRate(new Runnable() { - @Override - public void run() { - account_dn.invalidate(); - } - }, 0, 130, TimeUnit.MILLISECONDS); + scheduledExecutorService.scheduleAtFixedRate(() -> account_dn.invalidate(), 0, 130, TimeUnit.MILLISECONDS); } } } @@ -1165,310 +1087,264 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt } } - popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - public boolean onMenuItemClick(MenuItem item) { - AlertDialog.Builder builderInner; - SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); - int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); - int style; - if (theme == Helper.THEME_DARK) { - style = R.style.DialogDark; - } else if (theme == Helper.THEME_BLACK) { - style = R.style.DialogBlack; - } else { - style = R.style.Dialog; - } - final SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - switch (item.getItemId()) { - case R.id.action_follow_instance: - String finalInstanceName = splitAcct[1]; - List remoteInstances = new InstancesDAO(ShowAccountActivity.this, db).getInstanceByName(finalInstanceName); - if (remoteInstances != null && remoteInstances.size() > 0) { - Toasty.info(getApplicationContext(), getString(R.string.toast_instance_already_added), Toast.LENGTH_LONG).show(); - Intent intent = new Intent(getApplicationContext(), MainActivity.class); - Bundle bundle = new Bundle(); - bundle.putInt(Helper.INTENT_ACTION, Helper.SEARCH_INSTANCE); - bundle.putString(Helper.INSTANCE_NAME, finalInstanceName); - intent.putExtras(bundle); - startActivity(intent); + popup.setOnMenuItemClickListener(item -> { + AlertDialog.Builder builderInner; + SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); + int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); + int style; + if (theme == Helper.THEME_DARK) { + style = R.style.DialogDark; + } else if (theme == Helper.THEME_BLACK) { + style = R.style.DialogBlack; + } else { + style = R.style.Dialog; + } + final SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); + switch (item.getItemId()) { + case R.id.action_follow_instance: + String finalInstanceName = splitAcct[1]; + List remoteInstances = new InstancesDAO(ShowAccountActivity.this, db).getInstanceByName(finalInstanceName); + if (remoteInstances != null && remoteInstances.size() > 0) { + Toasty.info(getApplicationContext(), getString(R.string.toast_instance_already_added), Toast.LENGTH_LONG).show(); + Intent intent = new Intent(getApplicationContext(), MainActivity.class); + Bundle bundle = new Bundle(); + bundle.putInt(Helper.INTENT_ACTION, Helper.SEARCH_INSTANCE); + bundle.putString(Helper.INSTANCE_NAME, finalInstanceName); + intent.putExtras(bundle); + startActivity(intent); + return true; + } + new Thread(() -> { + try { + if (!peertubeAccount) { + //Here we can't know if the instance is a Mastodon one or not + try { //Testing Mastodon + new HttpsConnection(ShowAccountActivity.this, null).get("https://" + finalInstanceName + "/api/v1/timelines/public?local=true", 10, null, null); + } catch (Exception ignored) { + new HttpsConnection(ShowAccountActivity.this, null).get("https://" + finalInstanceName + "/api/v1/videos/", 10, null, null); + peertubeAccount = true; + } + } else + new HttpsConnection(ShowAccountActivity.this, null).get("https://" + finalInstanceName + "/api/v1/videos/", 10, null, null); + + runOnUiThread(() -> { + if (!peertubeAccount) + new InstancesDAO(ShowAccountActivity.this, db).insertInstance(finalInstanceName, "MASTODON"); + else + new InstancesDAO(ShowAccountActivity.this, db).insertInstance(finalInstanceName, "PEERTUBE"); + Toasty.success(getApplicationContext(), getString(R.string.toast_instance_followed), Toast.LENGTH_LONG).show(); + Intent intent = new Intent(getApplicationContext(), MainActivity.class); + Bundle bundle = new Bundle(); + bundle.putInt(Helper.INTENT_ACTION, Helper.SEARCH_INSTANCE); + bundle.putString(Helper.INSTANCE_NAME, finalInstanceName); + intent.putExtras(bundle); + startActivity(intent); + }); + } catch (final Exception e) { + e.printStackTrace(); + runOnUiThread(() -> Toasty.warning(getApplicationContext(), getString(R.string.toast_instance_unavailable), Toast.LENGTH_LONG).show()); + } + }).start(); + return true; + case R.id.action_filter: + AlertDialog.Builder filterTagDialog = new AlertDialog.Builder(ShowAccountActivity.this, style); + Set featuredTagsSet = sharedpreferences.getStringSet(Helper.SET_FEATURED_TAGS, null); + List tags = new ArrayList<>(); + if (featuredTagsSet != null) { + tags = new ArrayList<>(featuredTagsSet); + } + tags.add(0, getString(R.string.no_tags)); + String[] tagsString = tags.toArray(new String[tags.size()]); + List finalTags = tags; + String tag = sharedpreferences.getString(Helper.SET_FEATURED_TAG_ACTION, null); + int checkedposition = 0; + int i = 0; + for (String _t : tags) { + if (_t.equals(tag)) + checkedposition = i; + i++; + } + filterTagDialog.setSingleChoiceItems(tagsString, checkedposition, (dialog, item1) -> { + String tag1; + if (item1 == 0) { + tag1 = null; + } else { + tag1 = finalTags.get(item1); + } + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putString(Helper.SET_FEATURED_TAG_ACTION, tag1); + editor.apply(); + dialog.dismiss(); + }); + filterTagDialog.show(); + return true; + case R.id.action_endorse: + if (relationship != null) + if (relationship.isEndorsed()) { + new PostActionAsyncTask(getApplicationContext(), API.StatusAction.UNENDORSE, account.getId(), ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } else { + new PostActionAsyncTask(getApplicationContext(), API.StatusAction.ENDORSE, account.getId(), ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + return true; + case R.id.action_hide_boost: + if (relationship != null) + if (relationship.isShowing_reblogs()) { + new PostActionAsyncTask(getApplicationContext(), API.StatusAction.HIDE_BOOST, account.getId(), ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } else { + new PostActionAsyncTask(getApplicationContext(), API.StatusAction.SHOW_BOOST, account.getId(), ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + return true; + case R.id.action_direct_message: + Intent intent = new Intent(getApplicationContext(), TootActivity.class); + Bundle b = new Bundle(); + b.putString("mentionAccount", account.getAcct()); + b.putString("visibility", "direct"); + intent.putExtras(b); + startActivity(intent); + return true; + case R.id.action_add_to_list: + if (timelines != null) { + ArrayAdapter arrayAdapter = new ArrayAdapter<>(ShowAccountActivity.this, android.R.layout.select_dialog_item); + boolean hasLists = false; + for (ManageTimelines timeline : timelines) { + if (timeline.getListTimeline() != null) { + arrayAdapter.add(timeline.getListTimeline().getTitle()); + hasLists = true; + } + } + if (!hasLists) { + Toasty.info(getApplicationContext(), getString(R.string.action_lists_empty), Toast.LENGTH_SHORT).show(); return true; } - new Thread(new Runnable() { - @Override - public void run() { - try { - if (!peertubeAccount) { - //Here we can't know if the instance is a Mastodon one or not - try { //Testing Mastodon - new HttpsConnection(ShowAccountActivity.this, null).get("https://" + finalInstanceName + "/api/v1/timelines/public?local=true", 10, null, null); - } catch (Exception ignored) { - new HttpsConnection(ShowAccountActivity.this, null).get("https://" + finalInstanceName + "/api/v1/videos/", 10, null, null); - peertubeAccount = true; - } - } else - new HttpsConnection(ShowAccountActivity.this, null).get("https://" + finalInstanceName + "/api/v1/videos/", 10, null, null); + AlertDialog.Builder builderSingle = new AlertDialog.Builder(ShowAccountActivity.this, style); + builderSingle.setTitle(getString(R.string.action_lists_add_to)); + builderSingle.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); - runOnUiThread(new Runnable() { - public void run() { - if (!peertubeAccount) - new InstancesDAO(ShowAccountActivity.this, db).insertInstance(finalInstanceName, "MASTODON"); - else - new InstancesDAO(ShowAccountActivity.this, db).insertInstance(finalInstanceName, "PEERTUBE"); - Toasty.success(getApplicationContext(), getString(R.string.toast_instance_followed), Toast.LENGTH_LONG).show(); - Intent intent = new Intent(getApplicationContext(), MainActivity.class); - Bundle bundle = new Bundle(); - bundle.putInt(Helper.INTENT_ACTION, Helper.SEARCH_INSTANCE); - bundle.putString(Helper.INSTANCE_NAME, finalInstanceName); - intent.putExtras(bundle); - startActivity(intent); - } - }); - } catch (final Exception e) { - e.printStackTrace(); - runOnUiThread(new Runnable() { - public void run() { - Toasty.warning(getApplicationContext(), getString(R.string.toast_instance_unavailable), Toast.LENGTH_LONG).show(); - } - }); - } - } - }).start(); - return true; - case R.id.action_filter: - AlertDialog.Builder filterTagDialog = new AlertDialog.Builder(ShowAccountActivity.this, style); - Set featuredTagsSet = sharedpreferences.getStringSet(Helper.SET_FEATURED_TAGS, null); - List tags = new ArrayList<>(); - if (featuredTagsSet != null) { - tags = new ArrayList<>(featuredTagsSet); - } - tags.add(0, getString(R.string.no_tags)); - String[] tagsString = tags.toArray(new String[tags.size()]); - List finalTags = tags; - String tag = sharedpreferences.getString(Helper.SET_FEATURED_TAG_ACTION, null); - int checkedposition = 0; - int i = 0; - for (String _t : tags) { - if (tag != null && _t.equals(tag)) - checkedposition = i; - i++; - } - filterTagDialog.setSingleChoiceItems(tagsString, checkedposition, new DialogInterface - .OnClickListener() { - public void onClick(DialogInterface dialog, int item) { - String tag; - if (item == 0) { - tag = null; - } else { - tag = finalTags.get(item); - } - SharedPreferences.Editor editor = sharedpreferences.edit(); - editor.putString(Helper.SET_FEATURED_TAG_ACTION, tag); - editor.apply(); - dialog.dismiss(); - } - }); - filterTagDialog.show(); - return true; - case R.id.action_endorse: - if (relationship != null) - if (relationship.isEndorsed()) { - new PostActionAsyncTask(getApplicationContext(), API.StatusAction.UNENDORSE, account.getId(), ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } else { - new PostActionAsyncTask(getApplicationContext(), API.StatusAction.ENDORSE, account.getId(), ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - return true; - case R.id.action_hide_boost: - if (relationship != null) - if (relationship.isShowing_reblogs()) { - new PostActionAsyncTask(getApplicationContext(), API.StatusAction.HIDE_BOOST, account.getId(), ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } else { - new PostActionAsyncTask(getApplicationContext(), API.StatusAction.SHOW_BOOST, account.getId(), ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - return true; - case R.id.action_direct_message: - Intent intent = new Intent(getApplicationContext(), TootActivity.class); - Bundle b = new Bundle(); - b.putString("mentionAccount", account.getAcct()); - b.putString("visibility", "direct"); - intent.putExtras(b); - startActivity(intent); - return true; - case R.id.action_add_to_list: - if (timelines != null) { - ArrayAdapter arrayAdapter = new ArrayAdapter(ShowAccountActivity.this, android.R.layout.select_dialog_item); - boolean hasLists = false; + builderSingle.setAdapter(arrayAdapter, (dialog, which) -> { + String listTitle = arrayAdapter.getItem(which); for (ManageTimelines timeline : timelines) { - if (timeline.getListTimeline() != null) { - arrayAdapter.add(timeline.getListTimeline().getTitle()); - hasLists = true; - } - } - if (!hasLists) { - Toasty.info(getApplicationContext(), getString(R.string.action_lists_empty), Toast.LENGTH_SHORT).show(); - return true; - } - AlertDialog.Builder builderSingle = new AlertDialog.Builder(ShowAccountActivity.this, style); - builderSingle.setTitle(getString(R.string.action_lists_add_to)); - builderSingle.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - } - }); - - builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - String listTitle = arrayAdapter.getItem(which); - for (ManageTimelines timeline : timelines) { - if (timeline.getListTimeline() != null && timeline.getListTimeline().getTitle().equals(listTitle)) { - app.fedilab.android.client.Entities.List list = timeline.getListTimeline(); - if (relationship == null || !relationship.isFollowing()) { - addToList = list.getId(); - new PostActionAsyncTask(getApplicationContext(), API.StatusAction.FOLLOW, account.getId(), ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } else { - new ManageListsAsyncTask(ShowAccountActivity.this, ManageListsAsyncTask.action.ADD_USERS, new String[]{account.getId()}, null, list.getId(), null, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - break; - } + if (timeline.getListTimeline() != null && timeline.getListTimeline().getTitle().equals(listTitle)) { + app.fedilab.android.client.Entities.List list = timeline.getListTimeline(); + if (relationship == null || !relationship.isFollowing()) { + addToList = list.getId(); + new PostActionAsyncTask(getApplicationContext(), API.StatusAction.FOLLOW, account.getId(), ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } else { + new ManageListsAsyncTask(ShowAccountActivity.this, ManageListsAsyncTask.action.ADD_USERS, new String[]{account.getId()}, null, list.getId(), null, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } + break; } - }); - builderSingle.show(); - } - return true; - case R.id.action_open_browser: - if (accountUrl != null) { - if (!accountUrl.toLowerCase().startsWith("http://") && !accountUrl.toLowerCase().startsWith("https://")) - accountUrl = "http://" + accountUrl; - Helper.openBrowser(ShowAccountActivity.this, accountUrl); - } - return true; - case R.id.action_mention: - intent = new Intent(getApplicationContext(), TootActivity.class); - b = new Bundle(); - b.putString("mentionAccount", account.getAcct()); - intent.putExtras(b); - startActivity(intent); - return true; - case R.id.action_mute: - if (relationship.isMuting()) { - builderInner = new AlertDialog.Builder(ShowAccountActivity.this, style); - builderInner.setTitle(stringArrayConf[4]); - doActionAccount = API.StatusAction.UNMUTE; - } else { - builderInner = new AlertDialog.Builder(ShowAccountActivity.this, style); - builderInner.setTitle(stringArrayConf[0]); - doActionAccount = API.StatusAction.MUTE; - } - break; - case R.id.action_report: - builderInner = new AlertDialog.Builder(ShowAccountActivity.this, style); - builderInner.setTitle(R.string.report_account); - //Text for report - EditText input = new EditText(ShowAccountActivity.this); - LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.MATCH_PARENT, - LinearLayout.LayoutParams.WRAP_CONTENT); - input.setLayoutParams(lp); - builderInner.setView(input); - doActionAccount = API.StatusAction.REPORT; - builderInner.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); } }); - builderInner.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - String targetedId; - String comment = null; - if (input.getText() != null) - comment = input.getText().toString(); - new PostActionAsyncTask(getApplicationContext(), doActionAccount, account.getId(), null, comment, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - dialog.dismiss(); - } - }); - builderInner.show(); - return true; - case R.id.action_add_notes: - UserNote userNote = new NotesDAO(getApplicationContext(), db).getUserNote(account.getAcct()); - builderInner = new AlertDialog.Builder(ShowAccountActivity.this, style); - builderInner.setTitle(R.string.note_for_account); - input = new EditText(ShowAccountActivity.this); - lp = new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.MATCH_PARENT, - LinearLayout.LayoutParams.WRAP_CONTENT); - input.setLayoutParams(lp); - input.setSingleLine(false); - if (userNote != null) { - input.setText(userNote.getNote()); - } - input.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION); - builderInner.setView(input); - builderInner.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - } - }); - builderInner.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - UserNote userNote = new NotesDAO(getApplicationContext(), db).getUserNote(account.getAcct()); - if (userNote == null) { - userNote = new UserNote(); - userNote.setAcct(account.getAcct()); - } - userNote.setNote(input.getText().toString()); - new NotesDAO(getApplicationContext(), db).insertInstance(userNote); - if (input.getText().toString().trim().length() > 0) { - account_personal_note.setVisibility(View.VISIBLE); - } else { - account_personal_note.setVisibility(View.GONE); - } - dialog.dismiss(); - } - }); - builderInner.show(); - return true; - case R.id.action_block: - builderInner = new AlertDialog.Builder(ShowAccountActivity.this, style); - builderInner.setTitle(stringArrayConf[1]); - doActionAccount = API.StatusAction.BLOCK; - break; - case R.id.action_block_instance: - builderInner = new AlertDialog.Builder(ShowAccountActivity.this, style); - doActionAccount = API.StatusAction.BLOCK_DOMAIN; - String domain = account.getAcct().split("@")[1]; - builderInner.setMessage(getString(R.string.block_domain_confirm_message, domain)); - break; - default: - return true; - } - builderInner.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); + builderSingle.show(); } - }); - builderInner.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { + return true; + case R.id.action_open_browser: + if (accountUrl != null) { + if (!accountUrl.toLowerCase().startsWith("http://") && !accountUrl.toLowerCase().startsWith("https://")) + accountUrl = "http://" + accountUrl; + Helper.openBrowser(ShowAccountActivity.this, accountUrl); + } + return true; + case R.id.action_mention: + intent = new Intent(getApplicationContext(), TootActivity.class); + b = new Bundle(); + b.putString("mentionAccount", account.getAcct()); + intent.putExtras(b); + startActivity(intent); + return true; + case R.id.action_mute: + if (relationship.isMuting()) { + builderInner = new AlertDialog.Builder(ShowAccountActivity.this, style); + builderInner.setTitle(stringArrayConf[4]); + doActionAccount = API.StatusAction.UNMUTE; + } else { + builderInner = new AlertDialog.Builder(ShowAccountActivity.this, style); + builderInner.setTitle(stringArrayConf[0]); + doActionAccount = API.StatusAction.MUTE; + } + break; + case R.id.action_report: + builderInner = new AlertDialog.Builder(ShowAccountActivity.this, style); + builderInner.setTitle(R.string.report_account); + //Text for report + EditText input = new EditText(ShowAccountActivity.this); + LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT); + input.setLayoutParams(lp); + builderInner.setView(input); + doActionAccount = API.StatusAction.REPORT; + builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); + builderInner.setPositiveButton(R.string.yes, (dialog, which) -> { String targetedId; - if (item.getItemId() == R.id.action_block_instance) { - targetedId = account.getAcct().split("@")[1]; - } else { - targetedId = account.getId(); - } - new PostActionAsyncTask(getApplicationContext(), doActionAccount, targetedId, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + String comment = null; + if (input.getText() != null) + comment = input.getText().toString(); + new PostActionAsyncTask(getApplicationContext(), doActionAccount, account.getId(), null, comment, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); dialog.dismiss(); + }); + builderInner.show(); + return true; + case R.id.action_add_notes: + UserNote userNote = new NotesDAO(getApplicationContext(), db).getUserNote(account.getAcct()); + builderInner = new AlertDialog.Builder(ShowAccountActivity.this, style); + builderInner.setTitle(R.string.note_for_account); + input = new EditText(ShowAccountActivity.this); + lp = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT); + input.setLayoutParams(lp); + input.setSingleLine(false); + if (userNote != null) { + input.setText(userNote.getNote()); } - }); - builderInner.show(); - return true; + input.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION); + builderInner.setView(input); + builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); + builderInner.setPositiveButton(R.string.validate, (dialog, which) -> { + UserNote userNote1 = new NotesDAO(getApplicationContext(), db).getUserNote(account.getAcct()); + if (userNote1 == null) { + userNote1 = new UserNote(); + userNote1.setAcct(account.getAcct()); + } + userNote1.setNote(input.getText().toString()); + new NotesDAO(getApplicationContext(), db).insertInstance(userNote1); + if (input.getText().toString().trim().length() > 0) { + account_personal_note.setVisibility(View.VISIBLE); + } else { + account_personal_note.setVisibility(View.GONE); + } + dialog.dismiss(); + }); + builderInner.show(); + return true; + case R.id.action_block: + builderInner = new AlertDialog.Builder(ShowAccountActivity.this, style); + builderInner.setTitle(stringArrayConf[1]); + doActionAccount = API.StatusAction.BLOCK; + break; + case R.id.action_block_instance: + builderInner = new AlertDialog.Builder(ShowAccountActivity.this, style); + doActionAccount = API.StatusAction.BLOCK_DOMAIN; + String domain = account.getAcct().split("@")[1]; + builderInner.setMessage(getString(R.string.block_domain_confirm_message, domain)); + break; + default: + return true; } + builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); + builderInner.setPositiveButton(R.string.yes, (dialog, which) -> { + String targetedId; + if (item.getItemId() == R.id.action_block_instance) { + targetedId = account.getAcct().split("@")[1]; + } else { + targetedId = account.getId(); + } + new PostActionAsyncTask(getApplicationContext(), doActionAccount, targetedId, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + dialog.dismiss(); + }); + builderInner.show(); + return true; }); popup.show(); } @@ -1590,12 +1466,7 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt builder.setView(identityProofsView); builder .setTitle(R.string.identity_proofs) - .setPositiveButton(R.string.close, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - } - }) + .setPositiveButton(R.string.close, (dialog, which) -> dialog.dismiss()) .show(); }); @@ -1619,6 +1490,7 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt super(fm); } + @NotNull @Override public Fragment getItem(int position) { Bundle bundle = new Bundle(); @@ -1667,7 +1539,7 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt return displayAccountsFragment; } - case 2: + default: DisplayAccountsFragment displayAccountsFragment = new DisplayAccountsFragment(); bundle.putSerializable("type", RetrieveAccountsAsyncTask.Type.FOLLOWERS); bundle.putString("targetedid", account.getId()); @@ -1675,7 +1547,6 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt return displayAccountsFragment; } - return null; }