Prepares cards
This commit is contained in:
parent
cb9bda30ad
commit
8332777007
|
@ -9,6 +9,7 @@ android {
|
|||
targetSdkVersion 27
|
||||
versionCode 94
|
||||
versionName "1.6.7.3"
|
||||
vectorDrawables.useSupportLibrary = true
|
||||
|
||||
}
|
||||
flavorDimensions "default"
|
||||
|
|
|
@ -47,15 +47,18 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.R;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveCardAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveContextAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Card;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Context;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||
import fr.gouv.etalab.mastodon.drawers.StatusListAdapter;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveCardInterface;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveContextInterface;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface;
|
||||
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
||||
|
@ -67,7 +70,7 @@ import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
|||
* Show conversation activity class
|
||||
*/
|
||||
|
||||
public class ShowConversationActivity extends BaseActivity implements OnRetrieveFeedsInterface, OnRetrieveContextInterface {
|
||||
public class ShowConversationActivity extends BaseActivity implements OnRetrieveFeedsInterface, OnRetrieveContextInterface, OnRetrieveCardInterface {
|
||||
|
||||
|
||||
private String statusId;
|
||||
|
@ -77,7 +80,7 @@ public class ShowConversationActivity extends BaseActivity implements OnRetrieve
|
|||
private boolean isRefreshed;
|
||||
private ImageView pp_actionBar;
|
||||
private List<Status> statuses;
|
||||
|
||||
private StatusListAdapter statusListAdapter;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -257,7 +260,7 @@ public class ShowConversationActivity extends BaseActivity implements OnRetrieve
|
|||
}
|
||||
}
|
||||
|
||||
StatusListAdapter statusListAdapter = new StatusListAdapter(ShowConversationActivity.this, position, null, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, statuses);
|
||||
statusListAdapter = new StatusListAdapter(ShowConversationActivity.this, position, null, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, statuses);
|
||||
lv_status.setAdapter(statusListAdapter);
|
||||
statusListAdapter.notifyDataSetChanged();
|
||||
loader.setVisibility(View.GONE);
|
||||
|
@ -268,7 +271,21 @@ public class ShowConversationActivity extends BaseActivity implements OnRetrieve
|
|||
}else {
|
||||
lv_status.smoothScrollToPosition(position);
|
||||
}
|
||||
new RetrieveCardAsyncTask(getApplicationContext(), initialStatus.getId(), ShowConversationActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrieveAccount(Card card) {
|
||||
int position = 0;
|
||||
for(Status status: this.statuses) {
|
||||
if( initialStatus.getId().equals(status.getId())) {
|
||||
this.statuses.get(position).setCard(card);
|
||||
initialStatus.setCard(card);
|
||||
statusListAdapter.notifyItemChanged(position);
|
||||
return;
|
||||
}
|
||||
position++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
/* Copyright 2017 Thomas Schneider
|
||||
*
|
||||
* This file is a part of Mastalab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
package fr.gouv.etalab.mastodon.asynctasks;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import java.lang.ref.WeakReference;
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Card;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveCardInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Thomas on 20/12/2017.
|
||||
* Retrieves Card
|
||||
*/
|
||||
|
||||
public class RetrieveCardAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private String statusId;
|
||||
private Card card;
|
||||
private OnRetrieveCardInterface listener;
|
||||
private WeakReference<Context> contextReference;
|
||||
|
||||
public RetrieveCardAsyncTask(Context context, String statusId, OnRetrieveCardInterface onRetrieveCardInterface){
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
this.statusId = statusId;
|
||||
this.listener = onRetrieveCardInterface;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
card = new API(contextReference.get()).getCard(statusId);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrieveAccount(card);
|
||||
}
|
||||
|
||||
}
|
|
@ -1407,6 +1407,21 @@ public class API {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get card
|
||||
* @param statusId String, the id of the status
|
||||
* @return Card, the card (null if none)
|
||||
*/
|
||||
public Card getCard(String statusId){
|
||||
|
||||
Card card = null;
|
||||
try {
|
||||
String response = new HttpsConnection().get(getAbsoluteUrl(String.format("/statuses/%s/card", statusId)), 60, null, prefKeyOauthTokenT);
|
||||
card = parseCardResponse(new JSONObject(response));
|
||||
}catch (Exception ignored) {ignored.printStackTrace();}
|
||||
return card;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a list by its id
|
||||
* @param id String, the id of the list
|
||||
|
@ -1469,6 +1484,25 @@ public class API {
|
|||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse json response an unique Car
|
||||
* @param resobj JSONObject
|
||||
* @return Card
|
||||
*/
|
||||
private Card parseCardResponse(JSONObject resobj){
|
||||
|
||||
Card card = new Card();
|
||||
try {
|
||||
card.setUrl(resobj.get("url").toString());
|
||||
card.setTitle(resobj.get("title").toString());
|
||||
card.setDescription(resobj.get("description").toString());
|
||||
card.setImage(resobj.get("image").toString());
|
||||
card.setType(resobj.get("type").toString());
|
||||
} catch (JSONException e) {
|
||||
card = null;
|
||||
}
|
||||
return card;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse json response an unique instance social result
|
||||
|
|
|
@ -14,15 +14,97 @@
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
package fr.gouv.etalab.mastodon.client.Entities;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
/**
|
||||
* Created by Thomas on 23/04/2017.
|
||||
* Manages card in toots, only used during a call to the context
|
||||
* See: https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md#card
|
||||
* All values are not implemented
|
||||
*/
|
||||
|
||||
public class Card {
|
||||
public class Card implements Parcelable {
|
||||
|
||||
public String url;
|
||||
public String title;
|
||||
public String description;
|
||||
public String image;
|
||||
private String url;
|
||||
private String title;
|
||||
private String description;
|
||||
private String image;
|
||||
private String type;
|
||||
|
||||
public Card(){}
|
||||
|
||||
public Card(Parcel in) {
|
||||
url = in.readString();
|
||||
title = in.readString();
|
||||
description = in.readString();
|
||||
image = in.readString();
|
||||
type = in.readString();
|
||||
}
|
||||
|
||||
public static final Creator<Card> CREATOR = new Creator<Card>() {
|
||||
@Override
|
||||
public Card createFromParcel(Parcel in) {
|
||||
return new Card(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Card[] newArray(int size) {
|
||||
return new Card[size];
|
||||
}
|
||||
};
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public void setImage(String image) {
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel parcel, int i) {
|
||||
parcel.writeString(url);
|
||||
parcel.writeString(title);
|
||||
parcel.writeString(description);
|
||||
parcel.writeString(image);
|
||||
parcel.writeString(type);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,6 +86,7 @@ public class Status implements Parcelable{
|
|||
private List<Emojis> emojis;
|
||||
private List<Tag> tags;
|
||||
private Application application;
|
||||
private Card card;
|
||||
private String language;
|
||||
private boolean isTranslated = false;
|
||||
private boolean isEmojiFound = false;
|
||||
|
@ -112,6 +113,7 @@ public class Status implements Parcelable{
|
|||
in_reply_to_id = in.readString();
|
||||
in_reply_to_account_id = in.readString();
|
||||
reblog = in.readParcelable(Status.class.getClassLoader());
|
||||
card = in.readParcelable(Card.class.getClassLoader());
|
||||
account = in.readParcelable(Account.class.getClassLoader());
|
||||
mentions = in.readArrayList(Mention.class.getClassLoader());
|
||||
content = in.readString();
|
||||
|
@ -334,6 +336,7 @@ public class Status implements Parcelable{
|
|||
dest.writeString(in_reply_to_account_id);
|
||||
dest.writeParcelable(reblog, flags);
|
||||
dest.writeParcelable(account, flags);
|
||||
dest.writeParcelable(card, flags);
|
||||
dest.writeList(mentions);
|
||||
dest.writeString(content);
|
||||
dest.writeString(contentTranslated);
|
||||
|
@ -751,4 +754,11 @@ public class Status implements Parcelable{
|
|||
return otherStatus != null && (otherStatus == this || otherStatus instanceof Status && this.getId().equals(((Status) otherStatus).getId()));
|
||||
}
|
||||
|
||||
public Card getCard() {
|
||||
return card;
|
||||
}
|
||||
|
||||
public void setCard(Card card) {
|
||||
this.card = card;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,6 +76,7 @@ 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;
|
||||
import fr.gouv.etalab.mastodon.activities.WebviewActivity;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveRepliesAsyncTask;
|
||||
|
@ -224,7 +225,9 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
ImageView new_element;
|
||||
LinearLayout status_spoiler_mention_container;
|
||||
TextView status_mention_spoiler;
|
||||
|
||||
LinearLayout status_cardview;
|
||||
ImageView status_cardview_image;
|
||||
TextView status_cardview_title, status_cardview_content, status_cardview_url;
|
||||
public View getView(){
|
||||
return itemView;
|
||||
}
|
||||
|
@ -274,6 +277,11 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
status_action_container = itemView.findViewById(R.id.status_action_container);
|
||||
status_spoiler_mention_container = itemView.findViewById(R.id.status_spoiler_mention_container);
|
||||
status_mention_spoiler = itemView.findViewById(R.id.status_mention_spoiler);
|
||||
status_cardview = itemView.findViewById(R.id.status_cardview);
|
||||
status_cardview_image = itemView.findViewById(R.id.status_cardview_image);
|
||||
status_cardview_title = itemView.findViewById(R.id.status_cardview_title);
|
||||
status_cardview_content = itemView.findViewById(R.id.status_cardview_content);
|
||||
status_cardview_url = itemView.findViewById(R.id.status_cardview_url);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -858,18 +866,42 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
holder.main_container.setBackgroundResource(R.color.mastodonC1_);
|
||||
}
|
||||
}else {
|
||||
if( theme == Helper.THEME_LIGHT){
|
||||
if( position == conversationPosition){
|
||||
if( position == conversationPosition){
|
||||
if( theme == Helper.THEME_LIGHT)
|
||||
holder.main_container.setBackgroundResource(R.color.mastodonC3_);
|
||||
}else {
|
||||
holder.main_container.setBackgroundResource(R.color.mastodonC3__);
|
||||
}
|
||||
}else {
|
||||
if( position == conversationPosition){
|
||||
else
|
||||
holder.main_container.setBackgroundResource(R.color.mastodonC1___);
|
||||
if( status.getCard() != null){
|
||||
holder.status_cardview_content.setText(status.getCard().getDescription());
|
||||
holder.status_cardview_title.setText(status.getCard().getTitle());
|
||||
holder.status_cardview_url.setText(status.getCard().getUrl());
|
||||
if( status.getCard().getImage() != null) {
|
||||
holder.status_cardview_image.setVisibility(View.VISIBLE);
|
||||
Glide.with(holder.status_cardview_image.getContext())
|
||||
.load(status.getCard().getImage())
|
||||
.into(holder.status_cardview_image);
|
||||
}else
|
||||
holder.status_cardview_image.setVisibility(View.GONE);
|
||||
holder.status_cardview.setVisibility(View.VISIBLE);
|
||||
holder.status_cardview.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(context, WebviewActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
b.putString("url", status.getCard().getUrl());
|
||||
intent.putExtras(b);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
}else {
|
||||
holder.main_container.setBackgroundResource(R.color.mastodonC1_);
|
||||
holder.status_cardview.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
}else {
|
||||
if( theme == Helper.THEME_LIGHT)
|
||||
holder.main_container.setBackgroundResource(R.color.mastodonC3__);
|
||||
else
|
||||
holder.main_container.setBackgroundResource(R.color.mastodonC1_);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
/* Copyright 2017 Thomas Schneider
|
||||
*
|
||||
* This file is a part of Mastalab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
package fr.gouv.etalab.mastodon.interfaces;
|
||||
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Card;
|
||||
|
||||
/**
|
||||
* Created by Thomas on 20/12/2017.
|
||||
* Interface when one card have been retrieved
|
||||
*/
|
||||
public interface OnRetrieveCardInterface {
|
||||
void onRetrieveAccount(Card card);
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="@color/transparent"/>
|
||||
|
||||
<stroke android:width="1dp"
|
||||
android:color="?attr/colorPrimary"
|
||||
/>
|
||||
|
||||
<padding android:left="1dp"
|
||||
android:top="1dp"
|
||||
android:right="1dp"
|
||||
android:bottom="1dp"
|
||||
/>
|
||||
|
||||
<corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp"
|
||||
android:topLeftRadius="7dp" android:topRightRadius="7dp"/>
|
||||
</shape>
|
|
@ -195,6 +195,54 @@
|
|||
tools:ignore="HardcodedText" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/status_cardview"
|
||||
android:padding="10dp"
|
||||
android:visibility="gone"
|
||||
android:background="@drawable/card_border"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<ImageView
|
||||
android:layout_gravity="center"
|
||||
android:id="@+id/status_cardview_image"
|
||||
android:layout_width="60dp"
|
||||
android:gravity="center"
|
||||
android:layout_height="60dp"
|
||||
tools:ignore="ContentDescription" />
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="0dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
android:textSize="14sp"
|
||||
android:maxLines="1"
|
||||
android:textStyle="bold"
|
||||
android:id="@+id/status_cardview_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView
|
||||
android:layout_marginTop="5dp"
|
||||
android:id="@+id/status_cardview_content"
|
||||
android:layout_width="match_parent"
|
||||
android:textSize="12sp"
|
||||
android:maxLines="4"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView
|
||||
android:id="@+id/status_cardview_url"
|
||||
android:layout_marginTop="5dp"
|
||||
android:textSize="12sp"
|
||||
android:textStyle="italic"
|
||||
android:maxLines="1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/status_document_container"
|
||||
android:orientation="horizontal"
|
||||
|
|
Loading…
Reference in New Issue