-
-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement image description viewer #129
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
899c9cd
implement alt text as toast messages
sk22 11d88ae
implement alt text as bottom sheet
sk22 a0a28a0
implement scroll-to-close
sk22 9aa9541
make text selectable
sk22 ac81f10
make button disappear when no description
sk22 f0cef21
Merge branch 'mastodon:master' into feature/display-alt-text
sk22 7e736d3
clean up code
sk22 7cd5ca7
Merge remote-tracking branch 'origin/feature/display-alt-text' into f…
sk22 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
mastodon/src/main/java/org/joinmastodon/android/ui/ImageDescriptionSheet.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,87 @@ | ||
package org.joinmastodon.android.ui; | ||
|
||
import android.app.Activity; | ||
import android.graphics.Typeface; | ||
import android.graphics.drawable.ColorDrawable; | ||
import android.os.Build; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.view.WindowInsets; | ||
import android.widget.FrameLayout; | ||
import android.widget.LinearLayout; | ||
import android.widget.TextView; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.recyclerview.widget.LinearLayoutManager; | ||
|
||
import org.joinmastodon.android.R; | ||
import org.joinmastodon.android.model.Attachment; | ||
import org.joinmastodon.android.ui.utils.UiUtils; | ||
|
||
import me.grishka.appkit.utils.SingleViewRecyclerAdapter; | ||
import me.grishka.appkit.utils.V; | ||
import me.grishka.appkit.views.BottomSheet; | ||
import me.grishka.appkit.views.UsableRecyclerView; | ||
|
||
public class ImageDescriptionSheet extends BottomSheet{ | ||
private UsableRecyclerView list; | ||
|
||
public ImageDescriptionSheet(@NonNull Activity activity, Attachment attachment){ | ||
super(activity); | ||
|
||
View handleView=new View(activity); | ||
handleView.setBackgroundResource(R.drawable.bg_bottom_sheet_handle); | ||
ViewGroup handle=new FrameLayout(activity); | ||
handle.addView(handleView); | ||
handle.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, V.dp(24))); | ||
|
||
TextView textView = new TextView(activity); | ||
if (attachment.description == null || attachment.description.isEmpty()) { | ||
textView.setText(R.string.media_no_description); | ||
textView.setTypeface(null, Typeface.ITALIC); | ||
} else { | ||
textView.setText(attachment.description); | ||
textView.setTextIsSelectable(true); | ||
} | ||
|
||
TextView heading=new TextView(activity); | ||
heading.setText(R.string.image_description); | ||
heading.setAllCaps(true); | ||
heading.setTypeface(null, Typeface.BOLD); | ||
heading.setPadding(0, V.dp(24), 0, V.dp(8)); | ||
Comment on lines
+47
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure about this. Is there a specific styling more suitable for headings? |
||
|
||
LinearLayout linearLayout = new LinearLayout(activity); | ||
linearLayout.setOrientation(LinearLayout.VERTICAL); | ||
linearLayout.setPadding(V.dp(24), 0, V.dp(24), 0); | ||
linearLayout.addView(heading); | ||
linearLayout.addView(textView); | ||
|
||
FrameLayout layout=new FrameLayout(activity); | ||
layout.addView(handle); | ||
layout.addView(linearLayout); | ||
|
||
list=new UsableRecyclerView(activity); | ||
list.setLayoutManager(new LinearLayoutManager(activity)); | ||
list.setBackgroundResource(R.drawable.bg_bottom_sheet); | ||
list.setAdapter(new SingleViewRecyclerAdapter(layout)); | ||
list.setClipToPadding(false); | ||
|
||
setContentView(list); | ||
setNavigationBarBackground(new ColorDrawable(UiUtils.getThemeColor(activity, R.attr.colorWindowBackground)), !UiUtils.isDarkTheme()); | ||
} | ||
|
||
@Override | ||
protected void onWindowInsetsUpdated(WindowInsets insets){ | ||
if(Build.VERSION.SDK_INT>=29){ | ||
int tappableBottom=insets.getTappableElementInsets().bottom; | ||
int insetBottom=insets.getSystemWindowInsetBottom(); | ||
if(tappableBottom==0 && insetBottom>0){ | ||
list.setPadding(0, 0, 0, V.dp(48)-insetBottom); | ||
}else{ | ||
list.setPadding(0, 0, 0, V.dp(24)); | ||
} | ||
}else{ | ||
list.setPadding(0, 0, 0, V.dp(24)); | ||
} | ||
} | ||
} |
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
3 changes: 3 additions & 0 deletions
3
mastodon/src/main/res/drawable/ic_fluent_image_alt_text_24_regular.xml
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,3 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24"> | ||
<path android:pathData="M1 3c0-1.105 0.895-2 2-2h7c1.105 0 2 0.895 2 2v6c0 1.105-0.895 2-2 2H3c-1.105 0-2-0.895-2-2V3zm2.5 1C3.224 4 3 4.224 3 4.5S3.224 5 3.5 5h6C9.776 5 10 4.776 10 4.5S9.776 4 9.5 4h-6zm0 3C3.224 7 3 7.224 3 7.5S3.224 8 3.5 8h6C9.776 8 10 7.776 10 7.5S9.776 7 9.5 7h-6zM4 12h1.5v6.75c0 0.208 0.036 0.408 0.103 0.594l5.823-5.701c0.833-0.816 2.142-0.854 3.02-0.116l0.128 0.116 5.822 5.702c0.067-0.186 0.104-0.386 0.104-0.595V7.25c0-0.966-0.784-1.75-1.75-1.75H13V4h5.75C20.545 4 22 5.455 22 7.25v11.5c0 1.795-1.455 3.25-3.25 3.25H7.25C5.455 22 4 20.545 4 18.75V12zm15.33 8.401l-5.805-5.686c-0.265-0.26-0.675-0.283-0.966-0.071l-0.084 0.07-5.807 5.687C6.85 20.465 7.046 20.5 7.25 20.5h11.5c0.203 0 0.399-0.035 0.58-0.099zM16.253 7.5c1.244 0 2.252 1.008 2.252 2.252 0 1.244-1.008 2.252-2.252 2.252-1.244 0-2.252-1.008-2.252-2.252C14 8.508 15.008 7.5 16.252 7.5zm0 1.5C15.837 9 15.5 9.337 15.5 9.752s0.337 0.752 0.752 0.752c0.416 0 0.752-0.336 0.752-0.752C17.004 9.337 16.667 9 16.252 9z" android:fillColor="@color/fluent_default_icon_tint"/> | ||
</vector> |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't find where or if the AccountSwitcherSheet sets the height of the handle somewhere - setting it to 24dp manually was the only solution I could find; might be a bit hacky.