Skip to content

Commit

Permalink
fix multiple file display issue
Browse files Browse the repository at this point in the history
  • Loading branch information
xionxiao committed Jul 18, 2018
1 parent 7392cbc commit ddad32c
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Switch;
import android.widget.Toast;

Expand Down Expand Up @@ -112,9 +108,9 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in
public void onEventMainThread(OnMediaChangeEvent event) {
Ln.d("OnMediaChangeEvent: " + event.callEvent);
if (event.callEvent instanceof CallObserver.SendingSharingEvent) {
Ln.d("Activity SendingSharingEvent: " + ((CallObserver.SendingSharingEvent)event.callEvent).isSending());
if (!((CallObserver.SendingSharingEvent)event.callEvent).isSending()){
cancelNotication();
Ln.d("Activity SendingSharingEvent: " + ((CallObserver.SendingSharingEvent) event.callEvent).isSending());
if (!((CallObserver.SendingSharingEvent) event.callEvent).isSending()) {
cancelNotification();
moveToFront();
updateSharingSwitch(false);
Toast.makeText(this, "Stop to share content", Toast.LENGTH_SHORT).show();
Expand Down Expand Up @@ -143,12 +139,12 @@ protected void moveToFront() {
}
}

private void cancelNotication(){
private void cancelNotification() {
NotificationManager notifyManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
notifyManager.cancel(1);
}

private void updateSharingSwitch(boolean flag){
private void updateSharingSwitch(boolean flag) {
Switch shareSwitch = (Switch) findViewById(R.id.switchShareContent);
if (shareSwitch != null && shareSwitch.isChecked())
shareSwitch.setChecked(flag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,10 @@ private LocalFile[] generateLocalFiles() {
localFile.progressHandler = x -> {
text_status.setText("sending " + localFile.name + "... " + x + "%");
};
/*
localFile.thumbnail = new LocalFile.Thumbnail();
localFile.thumbnail.path = thumbnail_file.getPath();
localFile.thumbnail.path = f.getPath();
localFile.thumbnail.width = 622;
localFile.thumbnail.height = 492;
*/
arrayList.add(localFile);
}
}
Expand Down Expand Up @@ -271,6 +269,77 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
}
}

class FilesAdapter extends RecyclerView.Adapter<FilesAdapter.FilesViewHolder> {
private final LayoutInflater mLayoutInflater;
private final Context mContext;
private ArrayList<RemoteFile> mData;

FilesAdapter(Context context) {
mContext = context;
mLayoutInflater = LayoutInflater.from(mContext);
mData = new ArrayList<>();
}

@Override
public FilesAdapter.FilesViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new FilesViewHolder(mLayoutInflater.inflate(R.layout.listitem_file, parent, false));
}

@Override
public void onBindViewHolder(FilesAdapter.FilesViewHolder holder, int position) {
RemoteFile file = mData.get(position);
holder.textView.setText(file.displayName);
agent.downloadThumbnail(file, null, null, (uri) -> {
holder.imageView.setImageURI(uri.getData());
holder.progressBar.setVisibility(View.GONE);
});
}

@Override
public int getItemCount() {
return mData.size();
}

class FilesViewHolder extends RecyclerView.ViewHolder {

@BindView(R.id.message_item_file)
ImageView imageView;

@BindView(R.id.message_item_file_download_progress)
ProgressBar progressBar;

@BindView(R.id.message_item_file_download)
ImageButton downloadButton;

@BindView(R.id.message_item_load_process)
TextView loadProcess;

@BindView(R.id.message_item_filename)
TextView textView;

@OnClick(R.id.message_item_file_download)
public void download() {
RemoteFile file = mData.get(getAdapterPosition());
agent.downloadFile(
file,
null,
progress -> {
loadProcess.setText(String.format("%s", Math.round(progress)));
},
uri -> {
loadProcess.setText("complete");
//message_file.setImageURI(uri.getData());
}
);
}

public FilesViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
}
}

class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.MessageViewHolder> {
private final LayoutInflater mLayoutInflater;
private final Context mContext;
Expand Down Expand Up @@ -307,10 +376,17 @@ public void onBindViewHolder(MessageViewHolder holder, int position) {
}
List<RemoteFile> list = message.getRemoteFiles();
if (list != null && list.size() > 0) {
holder.message_file.setVisibility(View.VISIBLE);
holder.message_filename.setVisibility(View.VISIBLE);
holder.message_filename.setText(list.get(0).displayName);
FilesAdapter adapter = new FilesAdapter(mContext);
holder.recycler_files.setLayoutManager(new LinearLayoutManager(mContext));
holder.recycler_files.setAdapter(adapter);
adapter.mData.addAll(list);
adapter.notifyDataSetChanged();

//holder.message_file.setVisibility(View.VISIBLE);
//holder.message_filename.setVisibility(View.VISIBLE);
//holder.message_filename.setText(list.get(0).displayName);

/*
if (message.getRemoteFiles().get(0).thumbnail != null) {
holder.progressBar.setVisibility(View.VISIBLE);
RemoteFile file = message.getRemoteFiles().get(0);
Expand All @@ -319,11 +395,12 @@ public void onBindViewHolder(MessageViewHolder holder, int position) {
holder.progressBar.setVisibility(View.GONE);
});
}
*/
} else {
holder.message_file.setVisibility(View.GONE);
holder.message_filename.setVisibility(View.GONE);
holder.message_file_process.setVisibility(View.GONE);
holder.message_download_button.setVisibility(View.GONE);
//holder.message_file.setVisibility(View.GONE);
//holder.message_filename.setVisibility(View.GONE);
//holder.message_file_process.setVisibility(View.GONE);
//holder.message_download_button.setVisibility(View.GONE);
}
}

Expand All @@ -333,6 +410,9 @@ public int getItemCount() {
}

class MessageViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.messageLayout)
View message_layout;

@BindView(R.id.message_item_text)
TextView message_text;

Expand All @@ -342,30 +422,15 @@ class MessageViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.message_item_mention)
TextView message_mention;

@BindView(R.id.message_item_file)
ImageView message_file;

@BindView(R.id.message_item_filename)
TextView message_filename;

@BindView(R.id.message_item_file_process)
TextView message_file_process;
@BindView(R.id.message_item_list_files)
RecyclerView recycler_files;

@BindView(R.id.message_item_payload)
TextView message_payload;

@BindView(R.id.messageLayout)
View message_layout;

@BindView(R.id.payloadLayout)
View message_payload_layout;

@BindView(R.id.message_item_file_download)
View message_download_button;

@BindView(R.id.message_item_file_progressbar)
ProgressBar progressBar;

@OnClick(R.id.expand)
public void expand() {
if (message_payload_layout.getVisibility() != View.VISIBLE) {
Expand All @@ -377,10 +442,11 @@ public void expand() {
}
}

/*
@OnClick(R.id.message_item_file_download)
public void download(View view) {
view.setEnabled(false);
message_file_process.setText("0");
//message_file_process.setText("0");
Message msg = mData.get(getAdapterPosition());
Ln.e(msg.toString());
if (msg.getRemoteFiles() != null) {
Expand All @@ -391,15 +457,16 @@ public void download(View view) {
file,
null,
progress -> {
message_file_process.setText(String.format("%s", Math.round(progress)));
//message_file_process.setText(String.format("%s", Math.round(progress)));
},
uri -> {
message_file_process.setText("complete");
//message_file_process.setText("complete");
//message_file.setImageURI(uri.getData());
}
);
}
}
*/

MessageViewHolder(View view) {
super(view);
Expand Down
70 changes: 70 additions & 0 deletions app/src/main/res/layout/listitem_file.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
android:id="@+id/message_item_file"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:maxHeight="@android:dimen/thumbnail_height"
android:maxWidth="@android:dimen/thumbnail_width"
android:src="@drawable/ic_file_unknown"
android:visibility="visible"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ProgressBar
android:id="@+id/message_item_file_download_progress"
style="?android:attr/progressBarStyle"
android:layout_width="20sp"
android:layout_height="20sp"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="@+id/message_item_file"
app:layout_constraintEnd_toEndOf="@+id/message_item_file"
app:layout_constraintStart_toStartOf="@+id/message_item_file"
app:layout_constraintTop_toTopOf="@+id/message_item_file" />

<ImageButton
android:id="@+id/message_item_file_download"
android:layout_width="18sp"
android:layout_height="18sp"
android:layout_marginEnd="8dp"
android:background="@android:color/transparent"
android:src="@android:drawable/stat_sys_download"
android:tint="@android:color/holo_green_light"
app:layout_constraintBottom_toBottomOf="@+id/message_item_file"
app:layout_constraintEnd_toStartOf="@+id/message_item_load_process"
app:layout_constraintTop_toTopOf="@+id/message_item_file"
app:layout_constraintVertical_bias="0.777" />

<TextView
android:id="@+id/message_item_load_process"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_weight="1"
android:textAlignment="viewEnd"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="@+id/message_item_file_download"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/message_item_file_download" />

<TextView
android:id="@+id/message_item_filename"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_weight="1"
android:text="FileName"
android:visibility="visible"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/message_item_file" />

</android.support.constraint.ConstraintLayout>
Loading

0 comments on commit ddad32c

Please sign in to comment.