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.
Domain badges & info sheet & my fanciest animation yet
- Loading branch information
Showing
12 changed files
with
669 additions
and
70 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
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(); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...n/java/org/joinmastodon/android/ui/text/ImageSpanThatDoesNotBreakShitForNoGoodReason.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,67 @@ | ||
package org.joinmastodon.android.ui.text; | ||
|
||
import android.content.Context; | ||
import android.graphics.Bitmap; | ||
import android.graphics.Paint; | ||
import android.graphics.drawable.Drawable; | ||
import android.net.Uri; | ||
import android.text.style.ImageSpan; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
public class ImageSpanThatDoesNotBreakShitForNoGoodReason extends ImageSpan{ | ||
public ImageSpanThatDoesNotBreakShitForNoGoodReason(@NonNull Bitmap b){ | ||
super(b); | ||
} | ||
|
||
public ImageSpanThatDoesNotBreakShitForNoGoodReason(@NonNull Bitmap b, int verticalAlignment){ | ||
super(b, verticalAlignment); | ||
} | ||
|
||
public ImageSpanThatDoesNotBreakShitForNoGoodReason(@NonNull Context context, @NonNull Bitmap bitmap){ | ||
super(context, bitmap); | ||
} | ||
|
||
public ImageSpanThatDoesNotBreakShitForNoGoodReason(@NonNull Context context, @NonNull Bitmap bitmap, int verticalAlignment){ | ||
super(context, bitmap, verticalAlignment); | ||
} | ||
|
||
public ImageSpanThatDoesNotBreakShitForNoGoodReason(@NonNull Drawable drawable){ | ||
super(drawable); | ||
} | ||
|
||
public ImageSpanThatDoesNotBreakShitForNoGoodReason(@NonNull Drawable drawable, int verticalAlignment){ | ||
super(drawable, verticalAlignment); | ||
} | ||
|
||
public ImageSpanThatDoesNotBreakShitForNoGoodReason(@NonNull Drawable drawable, @NonNull String source){ | ||
super(drawable, source); | ||
} | ||
|
||
public ImageSpanThatDoesNotBreakShitForNoGoodReason(@NonNull Drawable drawable, @NonNull String source, int verticalAlignment){ | ||
super(drawable, source, verticalAlignment); | ||
} | ||
|
||
public ImageSpanThatDoesNotBreakShitForNoGoodReason(@NonNull Context context, @NonNull Uri uri){ | ||
super(context, uri); | ||
} | ||
|
||
public ImageSpanThatDoesNotBreakShitForNoGoodReason(@NonNull Context context, @NonNull Uri uri, int verticalAlignment){ | ||
super(context, uri, verticalAlignment); | ||
} | ||
|
||
public ImageSpanThatDoesNotBreakShitForNoGoodReason(@NonNull Context context, int resourceId){ | ||
super(context, resourceId); | ||
} | ||
|
||
public ImageSpanThatDoesNotBreakShitForNoGoodReason(@NonNull Context context, int resourceId, int verticalAlignment){ | ||
super(context, resourceId, verticalAlignment); | ||
} | ||
|
||
@Override | ||
public int getSize(@NonNull Paint paint, CharSequence text, int start, int end, @Nullable Paint.FontMetricsInt fm){ | ||
// Purposefully not touching the font metrics | ||
return getDrawable().getBounds().right; | ||
} | ||
} |
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
Oops, something went wrong.