Adds remote follow & some improvements
This commit is contained in:
parent
6f463ec872
commit
a45cc626c2
|
@ -26,7 +26,6 @@ import android.support.v7.app.ActionBar;
|
|||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
@ -236,7 +235,7 @@ public class RemoteFollowActivity extends AppCompatActivity implements OnRetriev
|
|||
rf_no_result.setVisibility(View.GONE);
|
||||
if( screen_name.startsWith("@"))
|
||||
screen_name = screen_name.substring(1);
|
||||
new RetrieveRemoteAccountsAsyncTask(RemoteFollowActivity.this, screen_name, instance_name, RemoteFollowActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
new RetrieveRemoteAccountsAsyncTask(screen_name, instance_name, RemoteFollowActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -252,59 +251,25 @@ public class RemoteFollowActivity extends AppCompatActivity implements OnRetriev
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@Override
|
||||
public void onRetrieveSearchAccounts(APIResponse apiResponse) {
|
||||
rf_search.setEnabled(true);
|
||||
public void onRetrieveRemoteAccount(boolean error, String name, String username, boolean locked, String avatar, String bio, int statusCount, int followingCount, int followersCount) {
|
||||
loader.setVisibility(View.GONE);
|
||||
if( apiResponse.getError() != null){
|
||||
final SharedPreferences sharedpreferences = 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(getApplicationContext(), apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
final List<Account> accounts = apiResponse.getAccounts();
|
||||
Log.v(Helper.TAG,"accounts: " + accounts);
|
||||
if( accounts != null && accounts.size() > 0 && accounts.get(0) != null) {
|
||||
List<Account> selectedAccount = new ArrayList<>();
|
||||
for(Account account: accounts){
|
||||
if(account.getAcct().contains("@" + instance_name) || (account.getUsername().equals(account.getAcct()) && account.getUsername().equals(screen_name)))
|
||||
selectedAccount.add(account);
|
||||
}
|
||||
if( selectedAccount.size() > 0) {
|
||||
AccountsListAdapter accountsListAdapter = new AccountsListAdapter(RemoteFollowActivity.this, RetrieveAccountsAsyncTask.Type.FOLLOWERS, null, selectedAccount);
|
||||
lv_account.setAdapter(accountsListAdapter);
|
||||
lv_account.setVisibility(View.VISIBLE);
|
||||
}else {
|
||||
rf_no_result.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}else if( firstSearch){
|
||||
firstSearch = false;
|
||||
new RetrieveSearchAccountsAsyncTask(RemoteFollowActivity.this, screen_name, 50, RemoteFollowActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}else {
|
||||
rf_no_result.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
@Override
|
||||
public void onRetrieveRemoteAccount(boolean error, String name, String avatar, String bio, int statusCount, int followingCount, int followersCount) {
|
||||
if( error){
|
||||
rf_no_result.setVisibility(View.VISIBLE);
|
||||
Toast.makeText(getApplicationContext(), R.string.toast_error,Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
loader.setVisibility(View.GONE);
|
||||
Account account = new Account();
|
||||
account.setInstance(instance_name);
|
||||
account.setAcct(screen_name + "@" + instance_name);
|
||||
account.setAvatar(avatar);
|
||||
account.setDisplay_name(name);
|
||||
account.setDisplay_name(username);
|
||||
account.setStatuses_count(statusCount);
|
||||
account.setFollowers_count(followersCount);
|
||||
account.setFollowing_count(followingCount);
|
||||
account.setUsername(name);
|
||||
account.setLocked(locked);
|
||||
account.setNote(bio);
|
||||
List<Account> selectedAccount = new ArrayList<>();
|
||||
selectedAccount.add(account);
|
||||
|
|
|
@ -14,14 +14,11 @@
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
package fr.gouv.etalab.mastodon.asynctasks;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.select.Elements;
|
||||
import java.io.IOException;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRemoteAccountInterface;
|
||||
|
||||
|
||||
|
@ -32,16 +29,15 @@ import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRemoteAccountInterface;
|
|||
|
||||
public class RetrieveRemoteAccountsAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private Context context;
|
||||
private OnRetrieveRemoteAccountInterface listener;
|
||||
private String url;
|
||||
private String avatar, name, bio;
|
||||
private String avatar, name, username, bio;
|
||||
private int statusCount, followingCount, followersCount;
|
||||
private boolean islocked;
|
||||
private boolean error = false;
|
||||
private String instance;
|
||||
|
||||
public RetrieveRemoteAccountsAsyncTask(Context context, String username, String instance, OnRetrieveRemoteAccountInterface onRetrieveRemoteAccountInterface){
|
||||
this.context = context;
|
||||
public RetrieveRemoteAccountsAsyncTask(String username, String instance, OnRetrieveRemoteAccountInterface onRetrieveRemoteAccountInterface){
|
||||
this.url = "https://" + instance + "/@" + username;
|
||||
this.listener = onRetrieveRemoteAccountInterface;
|
||||
this.instance = instance;
|
||||
|
@ -58,14 +54,17 @@ public class RetrieveRemoteAccountsAsyncTask extends AsyncTask<Void, Void, Void>
|
|||
avatar = avatarElement.get(0).getElementsByClass("u-photo").get(0).attr("src");
|
||||
avatar = "https://" + instance + avatar;
|
||||
Elements nameElement = document.getElementsByClass("name");
|
||||
name = nameElement.get(0).html();
|
||||
name = nameElement.get(0).getElementsByClass("p-name").get(0).html();
|
||||
username = nameElement.get(0).getElementsByTag("span").get(1).html();
|
||||
islocked = nameElement.get(0).getElementsByClass("fa-lock") != null;
|
||||
|
||||
Elements bioElement = document.getElementsByClass("bio");
|
||||
bio = bioElement.get(0).html();;
|
||||
Elements countElement = document.getElementsByClass("counter-number");
|
||||
statusCount = Integer.parseInt(countElement.get(0).html());
|
||||
followingCount = Integer.parseInt(countElement.get(1).html());
|
||||
followersCount = Integer.parseInt(countElement.get(2).html());
|
||||
} catch (IOException e) {
|
||||
} catch (IOException | IndexOutOfBoundsException e) {
|
||||
error = true;
|
||||
}
|
||||
return null;
|
||||
|
@ -73,7 +72,7 @@ public class RetrieveRemoteAccountsAsyncTask extends AsyncTask<Void, Void, Void>
|
|||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrieveRemoteAccount(error, name, avatar, bio, statusCount, followingCount, followersCount);
|
||||
listener.onRetrieveRemoteAccount(error, name, username, islocked, avatar, bio, statusCount, followingCount, followersCount);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -815,6 +815,11 @@ public class API {
|
|||
case FOLLOW:
|
||||
action = String.format("/accounts/%s/follow", targetedId);
|
||||
break;
|
||||
case REMOTE_FOLLOW:
|
||||
action = "/accounts/follows";
|
||||
params = new RequestParams();
|
||||
params.put("uri", targetedId);
|
||||
break;
|
||||
case UNFOLLOW:
|
||||
action = String.format("/accounts/%s/unfollow", targetedId);
|
||||
break;
|
||||
|
|
|
@ -16,9 +16,11 @@ package fr.gouv.etalab.mastodon.drawers;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.text.Html;
|
||||
import android.text.util.Linkify;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -47,6 +49,8 @@ import fr.gouv.etalab.mastodon.helper.Helper;
|
|||
import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface;
|
||||
import mastodon.etalab.gouv.fr.mastodon.R;
|
||||
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Thomas on 22/08/2017.
|
||||
|
@ -106,7 +110,7 @@ public class AccountSearchWebAdapter extends BaseAdapter implements OnPostAction
|
|||
holder = new ViewHolder();
|
||||
holder.account_pp = (ImageView) convertView.findViewById(R.id.account_pp);
|
||||
holder.account_dn = (TextView) convertView.findViewById(R.id.account_dn);
|
||||
|
||||
holder.account_un = (TextView) convertView.findViewById(R.id.account_un);
|
||||
holder.account_ds = (TextView) convertView.findViewById(R.id.account_ds);
|
||||
holder.account_sc = (TextView) convertView.findViewById(R.id.account_sc);
|
||||
holder.account_fgc = (TextView) convertView.findViewById(R.id.account_fgc);
|
||||
|
@ -116,18 +120,28 @@ public class AccountSearchWebAdapter extends BaseAdapter implements OnPostAction
|
|||
} else {
|
||||
holder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
|
||||
//Redraws icon for locked accounts
|
||||
final float scale = context.getResources().getDisplayMetrics().density;
|
||||
if( account != null && account.isLocked()){
|
||||
Drawable img = ContextCompat.getDrawable(context, R.drawable.ic_action_lock_closed);
|
||||
img.setBounds(0,0,(int) (20 * scale + 0.5f),(int) (20 * scale + 0.5f));
|
||||
holder.account_dn.setCompoundDrawables( null, null, img, null);
|
||||
}else{
|
||||
holder.account_dn.setCompoundDrawables( null, null, null, null);
|
||||
}
|
||||
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
holder.account_ds.setText(Html.fromHtml(account.getNote(), Html.FROM_HTML_MODE_LEGACY));
|
||||
holder.account_dn.setText(Html.fromHtml(Helper.shortnameToUnicode(account.getDisplay_name(), true), Html.FROM_HTML_MODE_LEGACY));
|
||||
holder.account_un.setText(Html.fromHtml(Helper.shortnameToUnicode(account.getUsername(), true), Html.FROM_HTML_MODE_LEGACY));
|
||||
}else {
|
||||
//noinspection deprecation
|
||||
holder.account_ds.setText(Html.fromHtml(account.getNote()));
|
||||
holder.account_dn.setText(Html.fromHtml(Helper.shortnameToUnicode(account.getDisplay_name(), true)));
|
||||
holder.account_un.setText(Html.fromHtml(Helper.shortnameToUnicode(account.getUsername(), true)));
|
||||
}
|
||||
changeDrawableColor(context, R.drawable.ic_action_lock_closed,R.color.mastodonC4);
|
||||
holder.account_ds.setAutoLinkMask(Linkify.WEB_URLS);
|
||||
holder.account_sc.setText(String.valueOf(account.getStatuses_count()));
|
||||
holder.account_fgc.setText(String.valueOf(account.getFollowing_count()));
|
||||
|
@ -139,7 +153,7 @@ public class AccountSearchWebAdapter extends BaseAdapter implements OnPostAction
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
holder.account_follow.setEnabled(false);
|
||||
new PostActionAsyncTask(context, API.StatusAction.REMOTE_FOLLOW, null, AccountSearchWebAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
new PostActionAsyncTask(context, API.StatusAction.REMOTE_FOLLOW, account.getAcct(), AccountSearchWebAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -164,6 +178,7 @@ public class AccountSearchWebAdapter extends BaseAdapter implements OnPostAction
|
|||
private class ViewHolder {
|
||||
ImageView account_pp;
|
||||
TextView account_dn;
|
||||
TextView account_un;
|
||||
TextView account_ds;
|
||||
TextView account_sc;
|
||||
TextView account_fgc;
|
||||
|
|
|
@ -20,5 +20,5 @@ package fr.gouv.etalab.mastodon.interfaces;
|
|||
* Interface for retrieving a remote account
|
||||
*/
|
||||
public interface OnRetrieveRemoteAccountInterface {
|
||||
void onRetrieveRemoteAccount(boolean error, String name, String avatar, String bio, int statusCount, int followingCount, int followersCount);
|
||||
void onRetrieveRemoteAccount(boolean error, String name, String username, boolean locked, String avatar, String bio, int statusCount, int followingCount, int followersCount);
|
||||
}
|
||||
|
|
|
@ -39,21 +39,38 @@
|
|||
<ImageView
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:id="@+id/account_pp"
|
||||
android:layout_margin="10dp"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="60dp"
|
||||
tools:ignore="ContentDescription" />
|
||||
<TextView
|
||||
android:id="@+id/account_dn"
|
||||
<LinearLayout
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
|
||||
android:orientation="vertical">
|
||||
<TextView
|
||||
android:id="@+id/account_dn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
|
||||
<TextView
|
||||
android:id="@+id/account_un"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
|
||||
</LinearLayout>
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:layout_gravity="center"
|
||||
app:fabSize="mini"
|
||||
android:id="@+id/account_follow"
|
||||
android:textAllCaps="false"
|
||||
android:src="@drawable/ic_user_plus"
|
||||
android:gravity="center"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
|
|
Loading…
Reference in New Issue