Adds images in notifications
This commit is contained in:
parent
e0a54db6d2
commit
77866c7136
|
@ -83,7 +83,7 @@ public class AboutActivity extends AppCompatActivity implements OnRetrieveSearcA
|
|||
about_thekinrar.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://instances.social/api/doc/"));
|
||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://instances.social/"));
|
||||
startActivity(browserIntent);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -104,7 +104,10 @@ public class LoginActivity extends AppCompatActivity {
|
|||
}
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
|
||||
if( s.length() > 2 ){
|
||||
if( s.toString().trim().startsWith("mas") && !s.toString().trim().contains(".") )
|
||||
return;
|
||||
String action = "/instances/search";
|
||||
RequestParams parameters = new RequestParams();
|
||||
parameters.add("q", s.toString().trim());
|
||||
|
|
|
@ -32,8 +32,10 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
@ -44,6 +46,7 @@ import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.activities.MediaActivity;
|
||||
import fr.gouv.etalab.mastodon.activities.ShowAccountActivity;
|
||||
import fr.gouv.etalab.mastodon.activities.ShowConversationActivity;
|
||||
import fr.gouv.etalab.mastodon.activities.TootActivity;
|
||||
|
@ -51,6 +54,7 @@ import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask;
|
|||
import fr.gouv.etalab.mastodon.asynctasks.PostNotificationsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Attachment;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnPostNotificationsActionInterface;
|
||||
|
@ -76,13 +80,18 @@ public class NotificationsListAdapter extends BaseAdapter implements OnPostActio
|
|||
private final int REBLOG = 1;
|
||||
private final int FAVOURITE = 2;
|
||||
private NotificationsListAdapter notificationsListAdapter;
|
||||
private int behaviorWithAttachments;
|
||||
private boolean isOnWifi;
|
||||
|
||||
public NotificationsListAdapter(Context context, List<Notification> notifications){
|
||||
|
||||
public NotificationsListAdapter(Context context, boolean isOnWifi, int behaviorWithAttachments, List<Notification> notifications){
|
||||
this.context = context;
|
||||
this.notifications = notifications;
|
||||
layoutInflater = LayoutInflater.from(this.context);
|
||||
imageLoader = ImageLoader.getInstance();
|
||||
notificationsListAdapter = this;
|
||||
this.isOnWifi = isOnWifi;
|
||||
this.behaviorWithAttachments = behaviorWithAttachments;
|
||||
options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false)
|
||||
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
|
||||
}
|
||||
|
@ -126,6 +135,19 @@ public class NotificationsListAdapter extends BaseAdapter implements OnPostActio
|
|||
holder.status_reply = (ImageView) convertView.findViewById(R.id.status_reply);
|
||||
holder.status_privacy = (ImageView) convertView.findViewById(R.id.status_privacy);
|
||||
holder.notification_delete = (ImageView) convertView.findViewById(R.id.notification_delete);
|
||||
|
||||
holder.status_show_more = (Button) convertView.findViewById(R.id.status_show_more);
|
||||
holder.status_prev1 = (ImageView) convertView.findViewById(R.id.status_prev1);
|
||||
holder.status_prev2 = (ImageView) convertView.findViewById(R.id.status_prev2);
|
||||
holder.status_prev3 = (ImageView) convertView.findViewById(R.id.status_prev3);
|
||||
holder.status_prev4 = (ImageView) convertView.findViewById(R.id.status_prev4);
|
||||
holder.status_prev1_play = (ImageView) convertView.findViewById(R.id.status_prev1_play);
|
||||
holder.status_prev2_play = (ImageView) convertView.findViewById(R.id.status_prev2_play);
|
||||
holder.status_prev3_play = (ImageView) convertView.findViewById(R.id.status_prev3_play);
|
||||
holder.status_prev4_play = (ImageView) convertView.findViewById(R.id.status_prev4_play);
|
||||
holder.status_container2 = (LinearLayout) convertView.findViewById(R.id.status_container2);
|
||||
holder.status_container3 = (LinearLayout) convertView.findViewById(R.id.status_container3);
|
||||
holder.status_prev4_container = (RelativeLayout) convertView.findViewById(R.id.status_prev4_container);
|
||||
convertView.setTag(holder);
|
||||
} else {
|
||||
holder = (ViewHolder) convertView.getTag();
|
||||
|
@ -284,6 +306,55 @@ public class NotificationsListAdapter extends BaseAdapter implements OnPostActio
|
|||
imgReblog.setBounds(0,0,(int) (20 * scale + 0.5f),(int) (20 * scale + 0.5f));
|
||||
holder.status_favorite_count.setCompoundDrawables(imgFav, null, null, null);
|
||||
holder.status_reblog_count.setCompoundDrawables(imgReblog, null, null, null);
|
||||
|
||||
|
||||
if( status.getReblog() == null) {
|
||||
if (status.getMedia_attachments().size() < 1) {
|
||||
holder.status_document_container.setVisibility(View.GONE);
|
||||
holder.status_show_more.setVisibility(View.GONE);
|
||||
} else {
|
||||
//If medias are loaded without any conditions or if device is on wifi
|
||||
if (!status.isSensitive() && (behaviorWithAttachments == Helper.ATTACHMENT_ALWAYS || (behaviorWithAttachments == Helper.ATTACHMENT_WIFI && isOnWifi))) {
|
||||
loadAttachments(status, holder);
|
||||
holder.status_show_more.setVisibility(View.GONE);
|
||||
status.setAttachmentShown(true);
|
||||
} else {
|
||||
//Text depending if toots is sensitive or not
|
||||
String textShowMore = (status.isSensitive()) ? context.getString(R.string.load_sensitive_attachment) : context.getString(R.string.load_attachment);
|
||||
holder.status_show_more.setText(textShowMore);
|
||||
if (!status.isAttachmentShown()) {
|
||||
holder.status_show_more.setVisibility(View.VISIBLE);
|
||||
holder.status_document_container.setVisibility(View.GONE);
|
||||
} else {
|
||||
loadAttachments(status, holder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}else { //Attachments for reblogs
|
||||
if (status.getReblog().getMedia_attachments().size() < 1) {
|
||||
holder.status_document_container.setVisibility(View.GONE);
|
||||
holder.status_show_more.setVisibility(View.GONE);
|
||||
} else {
|
||||
//If medias are loaded without any conditions or if device is on wifi
|
||||
if (!status.getReblog().isSensitive() && (behaviorWithAttachments == Helper.ATTACHMENT_ALWAYS || (behaviorWithAttachments == Helper.ATTACHMENT_WIFI && isOnWifi))) {
|
||||
loadAttachments(status.getReblog(), holder);
|
||||
holder.status_show_more.setVisibility(View.GONE);
|
||||
status.getReblog().setAttachmentShown(true);
|
||||
} else {
|
||||
//Text depending if toots is sensitive or not
|
||||
String textShowMore = (status.getReblog().isSensitive()) ? context.getString(R.string.load_sensitive_attachment) : context.getString(R.string.load_attachment);
|
||||
holder.status_show_more.setText(textShowMore);
|
||||
if (!status.isAttachmentShown()) {
|
||||
holder.status_show_more.setVisibility(View.VISIBLE);
|
||||
holder.status_document_container.setVisibility(View.GONE);
|
||||
} else {
|
||||
loadAttachments(status.getReblog(), holder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}else {
|
||||
holder.notification_status_container.setVisibility(View.GONE);
|
||||
}
|
||||
|
@ -491,6 +562,89 @@ public class NotificationsListAdapter extends BaseAdapter implements OnPostActio
|
|||
|
||||
}
|
||||
|
||||
private void loadAttachments(final Status status, ViewHolder holder){
|
||||
List<Attachment> attachments = status.getMedia_attachments();
|
||||
if( attachments != null && attachments.size() > 0){
|
||||
int i = 0;
|
||||
if( attachments.size() == 1){
|
||||
holder.status_container2.setVisibility(View.GONE);
|
||||
if( attachments.get(0).getUrl().trim().contains("missing.png"))
|
||||
holder.status_document_container.setVisibility(View.GONE);
|
||||
else
|
||||
holder.status_document_container.setVisibility(View.VISIBLE);
|
||||
}else if(attachments.size() == 2){
|
||||
holder.status_container2.setVisibility(View.VISIBLE);
|
||||
holder.status_container3.setVisibility(View.GONE);
|
||||
if( attachments.get(1).getUrl().trim().contains("missing.png"))
|
||||
holder.status_container2.setVisibility(View.GONE);
|
||||
holder.status_document_container.setVisibility(View.VISIBLE);
|
||||
}else if( attachments.size() == 3){
|
||||
holder.status_container2.setVisibility(View.VISIBLE);
|
||||
holder.status_container3.setVisibility(View.VISIBLE);
|
||||
holder.status_prev4_container.setVisibility(View.GONE);
|
||||
if( attachments.get(2).getUrl().trim().contains("missing.png"))
|
||||
holder.status_container3.setVisibility(View.GONE);
|
||||
holder.status_document_container.setVisibility(View.VISIBLE);
|
||||
}else {
|
||||
holder.status_prev4_container.setVisibility(View.VISIBLE);
|
||||
if( attachments.get(2).getUrl().trim().contains("missing.png"))
|
||||
holder.status_prev4_container.setVisibility(View.GONE);
|
||||
holder.status_document_container.setVisibility(View.VISIBLE);
|
||||
}
|
||||
int position = 1;
|
||||
for(final Attachment attachment: attachments){
|
||||
ImageView imageView;
|
||||
if( i == 0) {
|
||||
imageView = holder.status_prev1;
|
||||
if( attachment.getType().equals("image"))
|
||||
holder.status_prev1_play.setVisibility(View.GONE);
|
||||
else
|
||||
holder.status_prev1_play.setVisibility(View.VISIBLE);
|
||||
}else if( i == 1) {
|
||||
imageView = holder.status_prev2;
|
||||
if( attachment.getType().equals("image"))
|
||||
holder.status_prev2_play.setVisibility(View.GONE);
|
||||
else
|
||||
holder.status_prev2_play.setVisibility(View.VISIBLE);
|
||||
}else if(i == 2) {
|
||||
imageView = holder.status_prev3;
|
||||
if( attachment.getType().equals("image"))
|
||||
holder.status_prev3_play.setVisibility(View.GONE);
|
||||
else
|
||||
holder.status_prev3_play.setVisibility(View.VISIBLE);
|
||||
}else {
|
||||
imageView = holder.status_prev4;
|
||||
if( attachment.getType().equals("image"))
|
||||
holder.status_prev4_play.setVisibility(View.GONE);
|
||||
else
|
||||
holder.status_prev4_play.setVisibility(View.VISIBLE);
|
||||
}
|
||||
String url = attachment.getPreview_url();
|
||||
if( url == null || url.trim().equals(""))
|
||||
url = attachment.getUrl();
|
||||
if( !url.trim().contains("missing.png"))
|
||||
imageLoader.displayImage(url, imageView, options);
|
||||
final int finalPosition = position;
|
||||
imageView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(context, MediaActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
intent.putParcelableArrayListExtra("mediaArray", status.getMedia_attachments());
|
||||
b.putInt("position", finalPosition);
|
||||
intent.putExtras(b);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
i++;
|
||||
position++;
|
||||
}
|
||||
}else{
|
||||
holder.status_document_container.setVisibility(View.GONE);
|
||||
}
|
||||
holder.status_show_more.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
|
||||
private class ViewHolder {
|
||||
CardView card_status_container;
|
||||
|
@ -504,6 +658,18 @@ public class NotificationsListAdapter extends BaseAdapter implements OnPostActio
|
|||
TextView status_date;
|
||||
ImageView status_reply;
|
||||
LinearLayout status_document_container;
|
||||
Button status_show_more;
|
||||
ImageView status_prev1;
|
||||
ImageView status_prev2;
|
||||
ImageView status_prev3;
|
||||
ImageView status_prev4;
|
||||
ImageView status_prev1_play;
|
||||
ImageView status_prev2_play;
|
||||
ImageView status_prev3_play;
|
||||
ImageView status_prev4_play;
|
||||
RelativeLayout status_prev4_container;
|
||||
LinearLayout status_container2;
|
||||
LinearLayout status_container3;
|
||||
LinearLayout notification_status_container;
|
||||
ImageView status_privacy;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ import java.util.List;
|
|||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.drawers.NotificationsListAdapter;
|
||||
import fr.gouv.etalab.mastodon.drawers.StatusListAdapter;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
||||
|
@ -86,7 +85,9 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
textviewNoAction = (RelativeLayout) rootView.findViewById(R.id.no_action);
|
||||
mainLoader.setVisibility(View.VISIBLE);
|
||||
nextElementLoader.setVisibility(View.GONE);
|
||||
notificationsListAdapter = new NotificationsListAdapter(context, this.notifications);
|
||||
boolean isOnWifi = Helper.isOnWIFI(context);
|
||||
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
|
||||
notificationsListAdapter = new NotificationsListAdapter(context,isOnWifi, behaviorWithAttachments,this.notifications);
|
||||
lv_notifications.setAdapter(notificationsListAdapter);
|
||||
lv_notifications.setOnScrollListener(new AbsListView.OnScrollListener() {
|
||||
@Override
|
||||
|
@ -159,11 +160,10 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
|
||||
@Override
|
||||
public void onRetrieveNotifications(APIResponse apiResponse, String acct, String userId) {
|
||||
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
mainLoader.setVisibility(View.GONE);
|
||||
nextElementLoader.setVisibility(View.GONE);
|
||||
if( apiResponse.getError() != null){
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean show_error_messages = sharedpreferences.getBoolean(Helper.SET_SHOW_ERROR_MESSAGES, true);
|
||||
if( show_error_messages)
|
||||
Toast.makeText(context, apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
|
||||
|
@ -178,7 +178,9 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
else
|
||||
textviewNoAction.setVisibility(View.GONE);
|
||||
if( swiped ){
|
||||
notificationsListAdapter = new NotificationsListAdapter(context, this.notifications);
|
||||
boolean isOnWifi = Helper.isOnWIFI(context);
|
||||
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
|
||||
notificationsListAdapter = new NotificationsListAdapter(context,isOnWifi, behaviorWithAttachments, this.notifications);
|
||||
lv_notifications.setAdapter(notificationsListAdapter);
|
||||
swiped = false;
|
||||
}
|
||||
|
@ -194,7 +196,6 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
flag_loading = notifications != null && notifications.size() < notificationPerPage;
|
||||
//Store last notification id to avoid to notify for those that have been already seen
|
||||
if( notifications != null && notifications.size() > 0) {
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
//acct is null as userId when used in Fragment, data need to be retrieved via shared preferences and db
|
||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
|
|
|
@ -96,10 +96,131 @@
|
|||
android:layout_height="wrap_content" />
|
||||
<LinearLayout
|
||||
android:id="@+id/status_document_container"
|
||||
android:orientation="vertical"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="200dp"
|
||||
android:baselineAligned="false">
|
||||
<RelativeLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="match_parent"
|
||||
>
|
||||
<ImageView
|
||||
android:id="@+id/status_prev1"
|
||||
android:layout_width="match_parent"
|
||||
android:scaleType="centerCrop"
|
||||
android:layout_height="match_parent"
|
||||
tools:ignore="ContentDescription" />
|
||||
<ImageView
|
||||
android:id="@+id/status_prev1_play"
|
||||
android:visibility="gone"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_width="20dp"
|
||||
android:src="@drawable/ic_play_arrow"
|
||||
android:layout_height="20dp"
|
||||
tools:ignore="ContentDescription" />
|
||||
</RelativeLayout>
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="0dp"
|
||||
android:layout_marginLeft="2dp"
|
||||
android:layout_marginStart="2dp"
|
||||
android:id="@+id/status_container2"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="match_parent">
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:scaleType="centerCrop"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1">
|
||||
<ImageView
|
||||
android:id="@+id/status_prev2"
|
||||
android:layout_width="match_parent"
|
||||
android:scaleType="centerCrop"
|
||||
android:layout_height="match_parent"
|
||||
tools:ignore="ContentDescription" />
|
||||
<ImageView
|
||||
android:visibility="gone"
|
||||
android:id="@+id/status_prev2_play"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_width="20dp"
|
||||
android:src="@drawable/ic_play_arrow"
|
||||
android:layout_height="20dp"
|
||||
tools:ignore="ContentDescription" />
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_weight="1"
|
||||
android:layout_width="match_parent"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="2dp"
|
||||
android:id="@+id/status_container3"
|
||||
android:layout_height="0dp"
|
||||
android:baselineAligned="false">
|
||||
<RelativeLayout
|
||||
android:layout_marginLeft="2dp"
|
||||
android:layout_marginStart="2dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content">
|
||||
<ImageView
|
||||
android:id="@+id/status_prev3"
|
||||
android:layout_width="match_parent"
|
||||
android:scaleType="centerCrop"
|
||||
android:layout_height="match_parent"
|
||||
tools:ignore="ContentDescription" />
|
||||
<ImageView
|
||||
android:id="@+id/status_prev3_play"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_width="20dp"
|
||||
android:src="@drawable/ic_play_arrow"
|
||||
android:visibility="gone"
|
||||
android:layout_height="20dp"
|
||||
tools:ignore="ContentDescription" />
|
||||
</RelativeLayout>
|
||||
<RelativeLayout
|
||||
android:layout_marginLeft="2dp"
|
||||
android:layout_marginStart="2dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="0dp"
|
||||
android:id="@+id/status_prev4_container"
|
||||
android:layout_height="wrap_content">
|
||||
<ImageView
|
||||
android:id="@+id/status_prev4"
|
||||
android:layout_width="match_parent"
|
||||
android:scaleType="centerCrop"
|
||||
android:layout_height="match_parent"
|
||||
tools:ignore="ContentDescription" />
|
||||
<ImageView
|
||||
android:id="@+id/status_prev4_play"
|
||||
android:layout_centerInParent="true"
|
||||
android:visibility="gone"
|
||||
android:layout_width="20dp"
|
||||
android:src="@drawable/ic_play_arrow"
|
||||
android:layout_height="20dp"
|
||||
tools:ignore="ContentDescription" />
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
<Button
|
||||
android:id="@+id/status_show_more"
|
||||
android:visibility="gone"
|
||||
android:textAllCaps="false"
|
||||
android:drawableLeft="@drawable/ic_photo"
|
||||
android:drawableStart="@drawable/ic_photo"
|
||||
android:gravity="center"
|
||||
android:drawablePadding="5dp"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingRight="10dp"
|
||||
android:paddingEnd="10dp"
|
||||
android:paddingTop="5dp"
|
||||
android:paddingBottom="5dp"
|
||||
android:maxLines="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/load_attachment" />
|
||||
<LinearLayout
|
||||
android:id="@+id/status_action_container"
|
||||
android:layout_width="match_parent"
|
||||
|
|
Loading…
Reference in New Issue