-
Notifications
You must be signed in to change notification settings - Fork 55
Allow users to add more attachments to report a bug #22
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
Open
hplin
wants to merge
4
commits into
linkedin:main
Choose a base branch
from
hplin:master
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
43 changes: 43 additions & 0 deletions
43
shaky/src/main/java/com/linkedin/android/shaky/AttachmentData.java
This file contains hidden or 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,43 @@ | ||
package com.linkedin.android.shaky; | ||
|
||
import android.net.Uri; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
|
||
class AttachmentData { | ||
|
||
final Uri uri; | ||
final String displayName; | ||
final boolean removable; | ||
|
||
AttachmentData(@NonNull Uri uri) { | ||
this(uri, null, false); | ||
} | ||
|
||
AttachmentData(@NonNull Uri uri, @Nullable String displayName, boolean removable) { | ||
this.uri = uri; | ||
this.displayName = displayName; | ||
this.removable = removable; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
AttachmentData that = (AttachmentData) o; | ||
|
||
return uri.equals(that.uri); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return uri.hashCode(); | ||
} | ||
|
||
|
||
} |
65 changes: 65 additions & 0 deletions
65
shaky/src/main/java/com/linkedin/android/shaky/AttachmentListAdapter.java
This file contains hidden or 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,65 @@ | ||
package com.linkedin.android.shaky; | ||
|
||
import android.content.Context; | ||
import android.net.Uri; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ArrayAdapter; | ||
|
||
import java.util.ArrayList; | ||
|
||
class AttachmentListAdapter extends ArrayAdapter<AttachmentData> { | ||
|
||
private final AttachmentViewHolder.OnAttachmentClickListener onAttachmentClickListener; | ||
|
||
AttachmentListAdapter(@NonNull Context context, | ||
@NonNull AttachmentViewHolder.OnAttachmentClickListener onAttachmentClickListener) { | ||
super(context, 0); | ||
this.onAttachmentClickListener = onAttachmentClickListener; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { | ||
if (convertView == null) { | ||
convertView = LayoutInflater.from(parent.getContext()).inflate( | ||
R.layout.shaky_attachment_view, parent, false); | ||
AttachmentViewHolder viewHolder = new AttachmentViewHolder(convertView, onAttachmentClickListener); | ||
convertView.setTag(viewHolder); | ||
} | ||
AttachmentViewHolder viewHolder = (AttachmentViewHolder) convertView.getTag(); | ||
if (viewHolder != null) { | ||
viewHolder.bind(getItem(position)); | ||
} | ||
return convertView; | ||
} | ||
|
||
boolean containsAttachmentUri(@NonNull Uri uri) { | ||
int size = getCount(); | ||
AttachmentData data; | ||
for (int i = 1; i < size; i++) { | ||
data = getItem(i); | ||
if (data != null && uri.equals(data.uri)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
ArrayList<Uri> getAttachmentUriList() { | ||
int size = getCount(); | ||
AttachmentData data; | ||
ArrayList<Uri> list = new ArrayList<>(size); | ||
// Do not add screenshot | ||
for (int i = 1; i < size; i++) { | ||
data = getItem(i); | ||
if (data != null) { | ||
list.add(data.uri); | ||
} | ||
} | ||
return list; | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
shaky/src/main/java/com/linkedin/android/shaky/AttachmentViewHolder.java
This file contains hidden or 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 com.linkedin.android.shaky; | ||
|
||
import android.net.Uri; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.text.Html; | ||
import android.text.TextUtils; | ||
import android.view.View; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
class AttachmentViewHolder { | ||
|
||
interface OnAttachmentClickListener { | ||
|
||
void onRemoved(@NonNull Uri fileUri); | ||
|
||
void onClicked(@NonNull Uri fileUri); | ||
} | ||
|
||
private static final String IMAGE_PREFIX = "image/"; | ||
private final TextView filenameView; | ||
private final ImageView thumbnailView; | ||
private final ImageView deleteIcon; | ||
private final View rootView; | ||
|
||
AttachmentViewHolder(@NonNull View view, @NonNull final OnAttachmentClickListener listener) { | ||
filenameView = (TextView) view.findViewById(R.id.filename_view); | ||
deleteIcon = (ImageView) view.findViewById(R.id.delete_icon); | ||
thumbnailView = (ImageView) view.findViewById(R.id.thumbnail_view); | ||
rootView = view; | ||
filenameView.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
if (v.getTag() instanceof Uri) { | ||
listener.onClicked((Uri) v.getTag()); | ||
} | ||
} | ||
}); | ||
thumbnailView.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
if (v.getTag() instanceof Uri) { | ||
listener.onClicked((Uri) v.getTag()); | ||
} | ||
} | ||
}); | ||
deleteIcon.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
if (v.getTag() instanceof Uri) { | ||
listener.onRemoved((Uri) v.getTag()); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
private void bind(@NonNull Uri fileUri, @Nullable String defaultFilename, boolean removable) { | ||
filenameView.setText(Html.fromHtml(getFilename(fileUri, defaultFilename))); | ||
deleteIcon.setVisibility(removable ? View.VISIBLE : View.GONE); | ||
filenameView.setTag(fileUri); | ||
deleteIcon.setTag(fileUri); | ||
thumbnailView.setTag(fileUri); | ||
String mimeType = Utils.getMimeType(rootView.getContext(), fileUri); | ||
if (mimeType != null && mimeType.startsWith(IMAGE_PREFIX)) { | ||
thumbnailView.setVisibility(View.VISIBLE); | ||
thumbnailView.setImageURI(fileUri); | ||
} else { | ||
thumbnailView.setVisibility(View.GONE); | ||
} | ||
} | ||
|
||
void bind(@Nullable AttachmentData item) { | ||
if (item == null) { | ||
// edge case | ||
rootView.setVisibility(View.GONE); | ||
} else { | ||
rootView.setVisibility(View.VISIBLE); | ||
bind(item.uri, item.displayName, item.removable); | ||
} | ||
} | ||
|
||
private String getFilename(@NonNull Uri fileUri, @Nullable String defaultFilename) { | ||
return TextUtils.isEmpty(defaultFilename) ? Utils.getFilename(rootView.getContext(), fileUri) | ||
: defaultFilename; | ||
} | ||
} |
This file contains hidden or 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.
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.
Any reason we need to define EXTRA_ATTACHMENTS in both the fragment and the activity?
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.
Well, I just follow the same logic. When delegate tried to get the bundled values, it can use the constants defined in the same class.
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.
Yea makes sense, i guess these are two different semantic bundles. Sounds good!