forked from sk22/megalodon
-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: readd all the new bottom sheet code
- Loading branch information
1 parent
0d7e10c
commit 71dd974
Showing
21 changed files
with
1,075 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...src/main/java/org/joinmastodon/android/ui/sheets/AccountRestrictionConfirmationSheet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package org.joinmastodon.android.ui.sheets; | ||
|
||
import android.content.Context; | ||
import android.content.res.ColorStateList; | ||
import android.graphics.drawable.ColorDrawable; | ||
import android.graphics.drawable.InsetDrawable; | ||
import android.view.Gravity; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.Button; | ||
import android.widget.ImageView; | ||
import android.widget.LinearLayout; | ||
import android.widget.TextView; | ||
|
||
import org.joinmastodon.android.R; | ||
import org.joinmastodon.android.model.Account; | ||
import org.joinmastodon.android.ui.drawables.EmptyDrawable; | ||
import org.joinmastodon.android.ui.utils.UiUtils; | ||
import org.joinmastodon.android.ui.views.ProgressBarButton; | ||
|
||
import androidx.annotation.DrawableRes; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.StringRes; | ||
import me.grishka.appkit.utils.V; | ||
import me.grishka.appkit.views.BottomSheet; | ||
|
||
public abstract class AccountRestrictionConfirmationSheet extends BottomSheet{ | ||
private LinearLayout contentWrap; | ||
protected Button cancelBtn; | ||
protected ProgressBarButton confirmBtn, secondaryBtn; | ||
protected TextView titleView, subtitleView; | ||
protected ImageView icon; | ||
protected boolean loading; | ||
|
||
public AccountRestrictionConfirmationSheet(@NonNull Context context, Account user, ConfirmCallback confirmCallback){ | ||
super(context); | ||
View content=context.getSystemService(LayoutInflater.class).inflate(R.layout.sheet_restrict_account, null); | ||
setContentView(content); | ||
setNavigationBarBackground(new ColorDrawable(UiUtils.alphaBlendColors(UiUtils.getThemeColor(context, R.attr.colorM3Surface), | ||
UiUtils.getThemeColor(context, R.attr.colorM3Primary), 0.05f)), !UiUtils.isDarkTheme()); | ||
|
||
contentWrap=findViewById(R.id.content_wrap); | ||
titleView=findViewById(R.id.title); | ||
subtitleView=findViewById(R.id.text); | ||
cancelBtn=findViewById(R.id.btn_cancel); | ||
confirmBtn=findViewById(R.id.btn_confirm); | ||
secondaryBtn=findViewById(R.id.btn_secondary); | ||
icon=findViewById(R.id.icon); | ||
|
||
contentWrap.setDividerDrawable(new EmptyDrawable(1, V.dp(8))); | ||
contentWrap.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE); | ||
confirmBtn.setOnClickListener(v->{ | ||
if(loading) | ||
return; | ||
loading=true; | ||
confirmBtn.setProgressBarVisible(true); | ||
confirmCallback.onConfirmed(this::dismiss, ()->{ | ||
confirmBtn.setProgressBarVisible(false); | ||
loading=false; | ||
}); | ||
}); | ||
cancelBtn.setOnClickListener(v->{ | ||
if(!loading) | ||
dismiss(); | ||
}); | ||
} | ||
|
||
protected void addRow(@DrawableRes int icon, CharSequence text){ | ||
TextView tv=new TextView(getContext()); | ||
tv.setTextAppearance(R.style.m3_body_large); | ||
tv.setTextColor(UiUtils.getThemeColor(getContext(), R.attr.colorM3OnSurfaceVariant)); | ||
tv.setCompoundDrawableTintList(ColorStateList.valueOf(UiUtils.getThemeColor(getContext(), R.attr.colorM3Primary))); | ||
tv.setGravity(Gravity.START | Gravity.CENTER_VERTICAL); | ||
tv.setText(text); | ||
InsetDrawable drawable=new InsetDrawable(getContext().getResources().getDrawable(icon, getContext().getTheme()), V.dp(8)); | ||
drawable.setBounds(0, 0, V.dp(40), V.dp(40)); | ||
tv.setCompoundDrawablesRelative(drawable, null, null, null); | ||
tv.setCompoundDrawablePadding(V.dp(16)); | ||
contentWrap.addView(tv, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); | ||
} | ||
|
||
protected void addRow(@DrawableRes int icon, @StringRes int text){ | ||
addRow(icon, getContext().getString(text)); | ||
} | ||
|
||
public interface ConfirmCallback{ | ||
void onConfirmed(Runnable onSuccess, Runnable onError); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
mastodon/src/main/java/org/joinmastodon/android/ui/sheets/BlockAccountConfirmationSheet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.joinmastodon.android.ui.sheets; | ||
|
||
import android.content.Context; | ||
import android.view.View; | ||
|
||
import org.joinmastodon.android.R; | ||
import org.joinmastodon.android.model.Account; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
public class BlockAccountConfirmationSheet extends AccountRestrictionConfirmationSheet{ | ||
public BlockAccountConfirmationSheet(@NonNull Context context, Account user, ConfirmCallback confirmCallback){ | ||
super(context, user, confirmCallback); | ||
titleView.setText(R.string.block_user_confirm_title); | ||
confirmBtn.setText(R.string.do_block); | ||
secondaryBtn.setVisibility(View.GONE); | ||
icon.setImageResource(R.drawable.ic_fluent_shield_24_regular); | ||
subtitleView.setText(user.getDisplayUsername()); | ||
addRow(R.drawable.ic_campaign_24px, R.string.user_can_see_blocked); | ||
addRow(R.drawable.ic_fluent_eye_off_24_regular, R.string.user_cant_see_each_other_posts); | ||
addRow(R.drawable.ic_fluent_mention_24_regular, R.string.you_wont_see_user_mentions); | ||
addRow(R.drawable.ic_fluent_arrow_reply_24_regular, R.string.user_cant_mention_or_follow_you); | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
...odon/src/main/java/org/joinmastodon/android/ui/sheets/DecentralizationExplainerSheet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package org.joinmastodon.android.ui.sheets; | ||
|
||
import android.content.ClipData; | ||
import android.content.ClipboardManager; | ||
import android.content.Context; | ||
import android.graphics.drawable.ColorDrawable; | ||
import android.text.SpannableStringBuilder; | ||
import android.text.Spanned; | ||
import android.text.TextUtils; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.widget.TextView; | ||
|
||
import org.joinmastodon.android.R; | ||
import org.joinmastodon.android.api.session.AccountSessionManager; | ||
import org.joinmastodon.android.model.Account; | ||
import org.joinmastodon.android.ui.M3AlertDialogBuilder; | ||
import org.joinmastodon.android.ui.Snackbar; | ||
import org.joinmastodon.android.ui.text.LinkSpan; | ||
import org.joinmastodon.android.ui.utils.UiUtils; | ||
import org.joinmastodon.android.ui.views.RippleAnimationTextView; | ||
import org.jsoup.Jsoup; | ||
import org.jsoup.nodes.Element; | ||
import org.jsoup.nodes.Node; | ||
import org.jsoup.nodes.TextNode; | ||
import org.jsoup.select.NodeVisitor; | ||
|
||
import androidx.annotation.NonNull; | ||
import me.grishka.appkit.views.BottomSheet; | ||
|
||
public class DecentralizationExplainerSheet extends BottomSheet{ | ||
private final String handleStr; | ||
|
||
public DecentralizationExplainerSheet(@NonNull Context context, String accountID, Account account){ | ||
super(context); | ||
View content=context.getSystemService(LayoutInflater.class).inflate(R.layout.sheet_decentralization_info, null); | ||
setContentView(content); | ||
setNavigationBarBackground(new ColorDrawable(UiUtils.alphaBlendColors(UiUtils.getThemeColor(context, R.attr.colorM3Surface), | ||
UiUtils.getThemeColor(context, R.attr.colorM3Primary), 0.05f)), !UiUtils.isDarkTheme()); | ||
|
||
TextView handleTitle=findViewById(R.id.handle_title); | ||
RippleAnimationTextView handle=findViewById(R.id.handle); | ||
TextView usernameExplanation=findViewById(R.id.username_text); | ||
TextView serverExplanation=findViewById(R.id.server_text); | ||
TextView handleExplanation=findViewById(R.id.handle_explanation); | ||
findViewById(R.id.btn_cancel).setOnClickListener(v->dismiss()); | ||
|
||
String domain=account.getDomain(); | ||
if(TextUtils.isEmpty(domain)) | ||
domain=AccountSessionManager.get(accountID).domain; | ||
handleStr="@"+account.username+"@"+domain; | ||
boolean isSelf=AccountSessionManager.getInstance().isSelf(accountID, account); | ||
|
||
handleTitle.setText(isSelf ? R.string.handle_title_own : R.string.handle_title); | ||
handle.setText(handleStr); | ||
usernameExplanation.setText(isSelf ? R.string.handle_username_explanation_own : R.string.handle_username_explanation); | ||
serverExplanation.setText(isSelf ? R.string.handle_server_explanation_own : R.string.handle_server_explanation); | ||
|
||
String explanation=context.getString(isSelf ? R.string.handle_explanation_own : R.string.handle_explanation); | ||
SpannableStringBuilder ssb=new SpannableStringBuilder(); | ||
Jsoup.parseBodyFragment(explanation).body().traverse(new NodeVisitor(){ | ||
private int spanStart; | ||
@Override | ||
public void head(Node node, int depth){ | ||
if(node instanceof TextNode tn){ | ||
ssb.append(tn.text()); | ||
}else if(node instanceof Element){ | ||
spanStart=ssb.length(); | ||
} | ||
} | ||
|
||
@Override | ||
public void tail(Node node, int depth){ | ||
if(node instanceof Element){ | ||
ssb.setSpan(new LinkSpan("", DecentralizationExplainerSheet.this::showActivityPubAlert, LinkSpan.Type.CUSTOM, null, null, null), spanStart, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); | ||
} | ||
} | ||
}); | ||
handleExplanation.setText(ssb); | ||
|
||
findViewById(R.id.handle_wrap).setOnClickListener(v->{ | ||
context.getSystemService(ClipboardManager.class).setPrimaryClip(ClipData.newPlainText(null, handleStr)); | ||
if(UiUtils.needShowClipboardToast()){ | ||
new Snackbar.Builder(context) | ||
.setText(R.string.handle_copied) | ||
.show(); | ||
} | ||
}); | ||
String _domain=domain; | ||
findViewById(R.id.username_row).setOnClickListener(v->handle.animate(1, account.username.length()+1)); | ||
findViewById(R.id.server_row).setOnClickListener(v->handle.animate(handleStr.length()-_domain.length(), handleStr.length())); | ||
} | ||
|
||
private void showActivityPubAlert(LinkSpan s){ | ||
new M3AlertDialogBuilder(getContext()) | ||
.setTitle(R.string.what_is_activitypub_title) | ||
.setMessage(R.string.what_is_activitypub) | ||
.setPositiveButton(R.string.ok, null) | ||
.show(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
mastodon/src/main/java/org/joinmastodon/android/ui/sheets/MuteAccountConfirmationSheet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.joinmastodon.android.ui.sheets; | ||
|
||
import android.content.Context; | ||
import android.view.View; | ||
|
||
import org.joinmastodon.android.R; | ||
import org.joinmastodon.android.model.Account; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
public class MuteAccountConfirmationSheet extends AccountRestrictionConfirmationSheet{ | ||
public MuteAccountConfirmationSheet(@NonNull Context context, Account user, ConfirmCallback confirmCallback){ | ||
super(context, user, confirmCallback); | ||
titleView.setText(R.string.mute_user_confirm_title); | ||
confirmBtn.setText(R.string.do_mute); | ||
secondaryBtn.setVisibility(View.GONE); | ||
icon.setImageResource(R.drawable.ic_fluent_speaker_mute_24_regular); | ||
subtitleView.setText(user.getDisplayUsername()); | ||
addRow(R.drawable.ic_campaign_24px, R.string.user_wont_know_muted); | ||
addRow(R.drawable.ic_fluent_eye_off_24_regular, R.string.user_can_still_see_your_posts); | ||
addRow(R.drawable.ic_fluent_mention_24_regular, R.string.you_wont_see_user_mentions); | ||
addRow(R.drawable.ic_fluent_arrow_reply_24_regular, R.string.user_can_mention_and_follow_you); | ||
} | ||
} |
Oops, something went wrong.