showReceivers methods

This commit is contained in:
Rubén Martín Hidalgo 2016-08-09 19:00:28 +02:00
parent b966b422dc
commit e4b6aee5c9
4 changed files with 103 additions and 96 deletions

View File

@ -37,6 +37,8 @@ import android.widget.TextView;
import android.widget.Toast;
import com.nostra13.universalimageloader.core.ImageLoader;
import org.ksoap2.serialization.SoapObject;
import org.w3c.dom.Text;
import java.util.ArrayList;
import java.util.Vector;
import es.ugr.swad.swadroid.Constants;
@ -170,32 +172,7 @@ public class Messages extends Module {
sender = getIntent().getStringExtra("sender");
senderPhoto = getIntent().getStringExtra("photo");
LayoutInflater inflater = LayoutInflater.from(this);
final View linearLayout = inflater.inflate(R.layout.receivers_item, null, false);
final TextView textName = (TextView) linearLayout.findViewById(R.id.textName);
textName.setText(sender);
ImageView photo = (ImageView) linearLayout.findViewById(R.id.imageView);
String userPhoto = senderPhoto;
if (Utils.connectionAvailable(this)
&& (userPhoto != null) && !userPhoto.equals("")
&& !userPhoto.equals(Constants.NULL_VALUE)) {
ImageFactory.displayImage(loader, userPhoto, photo);
} else {
Log.d(TAG, "No connection or no photo " + userPhoto);
}
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.topMargin = 8;
linearLayout.setPadding(1, 1, 20, 1);
linearLayout.setLayoutParams(params);
layout.addView(linearLayout);
ImageButton button = (ImageButton)linearLayout.findViewById(R.id.buttonDelete);
button.setVisibility(View.GONE);
showSenderReplyMessage();
}
final ImageButton button = (ImageButton) findViewById(R.id.action_addUser);
@ -370,76 +347,7 @@ public class Messages extends Module {
Log.d(TAG, "Receivers of SearchUsers: " + receivers);
writeData();
// if there are not receivers, hide view group
layout.removeAllViewsInLayout();
layout.setVisibility(View.GONE);
if(sender != ""){
layout.setVisibility(View.VISIBLE);
LayoutInflater inflater = LayoutInflater.from(this);
final View linearLayout = inflater.inflate(R.layout.receivers_item, null, false);
final TextView textName = (TextView) linearLayout.findViewById(R.id.textName);
textName.setText(sender);
ImageView photo = (ImageView) linearLayout.findViewById(R.id.imageView);
String userPhoto = senderPhoto;
if (Utils.connectionAvailable(this)
&& (userPhoto != null) && !userPhoto.equals("")
&& !userPhoto.equals(Constants.NULL_VALUE)) {
ImageFactory.displayImage(loader, userPhoto, photo);
} else {
Log.d(TAG, "No connection or no photo " + userPhoto);
}
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.topMargin = 8;
linearLayout.setPadding(1, 1, 25, 1);
linearLayout.setLayoutParams(params);
layout.addView(linearLayout);
ImageButton button = (ImageButton)linearLayout.findViewById(R.id.buttonDelete);
button.setVisibility(View.GONE);
}
for(int i=0; i<arrayReceiversNames.size(); i++){
layout.setVisibility(View.VISIBLE);
LayoutInflater inflater = LayoutInflater.from(this);
final View linearLayout = inflater.inflate(R.layout.receivers_item, null, false);
final TextView textName = (TextView) linearLayout.findViewById(R.id.textName);
textName.setText(arrayReceiversNames.get(i).toString());
final TextView textNickname = (TextView) linearLayout.findViewById(R.id.textNickname);
textNickname.setText(arrayReceivers.get(i).toString());
ImageView photo = (ImageView) linearLayout.findViewById(R.id.imageView);
String userPhoto = arrayPhotos.get(i).toString();
if (Utils.connectionAvailable(this)
&& (userPhoto != null) && !userPhoto.equals("")
&& !userPhoto.equals(Constants.NULL_VALUE)) {
ImageFactory.displayImage(loader, userPhoto, photo);
} else {
Log.d(TAG, "No connection or no photo " + userPhoto);
}
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.topMargin = 8;
linearLayout.setPadding(1, 1, 1, 1);
linearLayout.setLayoutParams(params);
layout.addView(linearLayout);
ImageButton button = (ImageButton)linearLayout.findViewById(R.id.buttonDelete);
button.setOnClickListener( new View.OnClickListener() {
public void onClick(View view){
showDialogDelete(linearLayout, textNickname, textName.getText().toString());
}
});
}
showReceivers();
}
super.onActivityResult(requestCode, resultCode, data);
}
@ -532,4 +440,93 @@ public class Messages extends Module {
AlertDialog alert = builder.create();
alert.show();
}
private void showSenderReplyMessage (){
LayoutInflater inflater = LayoutInflater.from(this);
final View linearLayout = inflater.inflate(R.layout.receivers_item, null, false);
final TextView textName = (TextView) linearLayout.findViewById(R.id.textName);
textName.setText(sender);
ImageView photo = (ImageView) linearLayout.findViewById(R.id.imageView);
String userPhoto = senderPhoto;
if (Utils.connectionAvailable(this)
&& (userPhoto != null) && !userPhoto.equals("")
&& !userPhoto.equals(Constants.NULL_VALUE)) {
ImageFactory.displayImage(loader, userPhoto, photo);
} else {
Log.d(TAG, "No connection or no photo " + userPhoto);
}
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.topMargin = 8;
linearLayout.setPadding(1, 1, 25, 1);
linearLayout.setLayoutParams(params);
layout.addView(linearLayout);
ImageButton button = (ImageButton)linearLayout.findViewById(R.id.buttonDelete);
button.setVisibility(View.GONE);
}
private void showReceivers (){
// restart layout
layout.removeAllViewsInLayout();
layout.setVisibility(View.GONE);
if(sender != ""){ // add the sender of reply message to receivers list
layout.setVisibility(View.VISIBLE);
showSenderReplyMessage();
}
TextView seeAll = (TextView) findViewById(R.id.see_more_receivers);
int i;
if (arrayReceiversNames.size() > 3) {
i = arrayReceiversNames.size() - 3;
seeAll.setVisibility(View.VISIBLE);
}
else {
i = 0;
seeAll.setVisibility(View.GONE);
}
while (i < arrayReceiversNames.size()){
layout.setVisibility(View.VISIBLE);
LayoutInflater inflater = LayoutInflater.from(this);
final View linearLayout = inflater.inflate(R.layout.receivers_item, null, false);
final TextView textName = (TextView) linearLayout.findViewById(R.id.textName);
textName.setText(arrayReceiversNames.get(i).toString());
final TextView textNickname = (TextView) linearLayout.findViewById(R.id.textNickname);
textNickname.setText(arrayReceivers.get(i).toString());
ImageView photo = (ImageView) linearLayout.findViewById(R.id.imageView);
String userPhoto = arrayPhotos.get(i).toString();
if (Utils.connectionAvailable(this)
&& (userPhoto != null) && !userPhoto.equals("")
&& !userPhoto.equals(Constants.NULL_VALUE)) {
ImageFactory.displayImage(loader, userPhoto, photo);
} else {
Log.d(TAG, "No connection or no photo " + userPhoto);
}
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.topMargin = 8;
linearLayout.setPadding(1, 1, 1, 1);
linearLayout.setLayoutParams(params);
layout.addView(linearLayout);
ImageButton button = (ImageButton)linearLayout.findViewById(R.id.buttonDelete);
button.setOnClickListener( new View.OnClickListener() {
public void onClick(View view){
showDialogDelete(linearLayout, textNickname, textName.getText().toString());
}
});
i++;
}
}
}

View File

@ -89,6 +89,14 @@
android:layout_marginBottom="5dp"/>
</LinearLayout>
<TextView
android:id="@+id/see_more_receivers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/see_all"
android:layout_margin="5dp"
android:visibility="gone"/>
<View
android:layout_width="match_parent"
android:layout_height="1.5dp"

View File

@ -330,5 +330,6 @@
<string name="cancelRemoveReceivers">¿Quiere quitar a #nameUser# de la lista de destinatarios?</string>
<string name="user_added">Usuario añadido</string>
<string name="user_deleted">Usuario eliminado</string>
<string name="see_all">Ver todos</string>
</resources>

View File

@ -340,5 +340,6 @@
<string name="cancelRemoveReceivers">Do you want to remove #nameUser# from the list of receivers?</string>
<string name="user_added">User added</string>
<string name="user_deleted">User deleted</string>
<string name="see_all">See all</string>
</resources>