Follow Peertube channel
This commit is contained in:
parent
f605fdda95
commit
bfe66fd93c
|
@ -20,6 +20,7 @@ import android.content.SharedPreferences;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
|
@ -40,6 +41,7 @@ import fr.gouv.etalab.mastodon.asynctasks.RetrieveAccountsAsyncTask;
|
||||||
import fr.gouv.etalab.mastodon.client.API;
|
import fr.gouv.etalab.mastodon.client.API;
|
||||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||||
|
import fr.gouv.etalab.mastodon.helper.CrossActions;
|
||||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||||
import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface;
|
import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface;
|
||||||
import fr.gouv.etalab.mastodon.activities.ShowAccountActivity;
|
import fr.gouv.etalab.mastodon.activities.ShowAccountActivity;
|
||||||
|
@ -74,13 +76,14 @@ public class AccountsListAdapter extends RecyclerView.Adapter implements OnPostA
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
return new ViewHolder(layoutInflater.inflate(R.layout.drawer_account, parent, false));
|
return new ViewHolder(layoutInflater.inflate(R.layout.drawer_account, parent, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
|
||||||
final AccountsListAdapter.ViewHolder holder = (AccountsListAdapter.ViewHolder) viewHolder;
|
final AccountsListAdapter.ViewHolder holder = (AccountsListAdapter.ViewHolder) viewHolder;
|
||||||
final Account account = accounts.get(position);
|
final Account account = accounts.get(position);
|
||||||
|
|
||||||
|
@ -90,6 +93,9 @@ public class AccountsListAdapter extends RecyclerView.Adapter implements OnPostA
|
||||||
else if( action == RetrieveAccountsAsyncTask.Type.MUTED)
|
else if( action == RetrieveAccountsAsyncTask.Type.MUTED)
|
||||||
account.setFollowType(Account.followAction.MUTE);
|
account.setFollowType(Account.followAction.MUTE);
|
||||||
|
|
||||||
|
if( action == RetrieveAccountsAsyncTask.Type.CHANNELS)
|
||||||
|
account.setFollowType(Account.followAction.NOT_FOLLOW);
|
||||||
|
|
||||||
if (account.getFollowType() == Account.followAction.NOTHING){
|
if (account.getFollowType() == Account.followAction.NOTHING){
|
||||||
holder.account_follow.hide();
|
holder.account_follow.hide();
|
||||||
holder.account_follow_request.setVisibility(View.GONE);
|
holder.account_follow_request.setVisibility(View.GONE);
|
||||||
|
@ -173,22 +179,30 @@ public class AccountsListAdapter extends RecyclerView.Adapter implements OnPostA
|
||||||
holder.account_follow.setOnClickListener(new View.OnClickListener() {
|
holder.account_follow.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if( doAction != null) {
|
if( action != RetrieveAccountsAsyncTask.Type.CHANNELS) {
|
||||||
account.setMakingAction(true);
|
if (doAction != null) {
|
||||||
new PostActionAsyncTask(context, doAction, account.getId(), AccountsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
account.setMakingAction(true);
|
||||||
|
new PostActionAsyncTask(context, doAction, account.getId(), AccountsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
CrossActions.followPeertubeChannel(context, account, AccountsListAdapter.this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
holder.account_pp.setOnClickListener(new View.OnClickListener() {
|
holder.account_pp.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
//Avoid to reopen details about the current account
|
if(action != RetrieveAccountsAsyncTask.Type.CHANNELS) {
|
||||||
if( targetedId == null || !targetedId.equals(account.getId())){
|
//Avoid to reopen details about the current account
|
||||||
Intent intent = new Intent(context, ShowAccountActivity.class);
|
if (targetedId == null || !targetedId.equals(account.getId())) {
|
||||||
Bundle b = new Bundle();
|
Intent intent = new Intent(context, ShowAccountActivity.class);
|
||||||
b.putString("accountId", account.getId());
|
Bundle b = new Bundle();
|
||||||
intent.putExtras(b);
|
b.putString("accountId", account.getId());
|
||||||
context.startActivity(intent);
|
intent.putExtras(b);
|
||||||
|
context.startActivity(intent);
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
CrossActions.doCrossProfile(context, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ import android.os.Bundle;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
@ -199,6 +200,37 @@ public class CrossActions {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void followPeertubeChannel(final Context context, Account remoteAccount, OnPostActionInterface onPostActionInterface){
|
||||||
|
new AsyncTask<Void, Void, Void>() {
|
||||||
|
private WeakReference<Context> contextReference = new WeakReference<>(context);
|
||||||
|
Results response;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPreExecute() {
|
||||||
|
Toast.makeText(contextReference.get(), R.string.retrieve_remote_account, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(Void... voids) {
|
||||||
|
API api = new API(contextReference.get());
|
||||||
|
String url;
|
||||||
|
url = "https://" + remoteAccount.getHost() + "/video-channels/" + remoteAccount.getAcct().split("@")[0];
|
||||||
|
response = api.search(url);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Void result) {
|
||||||
|
if( response == null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<Account> remoteAccounts = response.getAccounts();
|
||||||
|
if( remoteAccounts != null && remoteAccounts.size() > 0) {
|
||||||
|
new PostActionAsyncTask(context, null, remoteAccounts.get(0), API.StatusAction.FOLLOW, onPostActionInterface).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR );
|
||||||
|
}
|
||||||
|
|
||||||
public static void doCrossProfile(final Context context, Account remoteAccount){
|
public static void doCrossProfile(final Context context, Account remoteAccount){
|
||||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
||||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||||
|
|
Loading…
Reference in New Issue