fedilab-Android-App/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowAccountActivity.java

988 lines
46 KiB
Java
Raw Normal View History

2017-05-05 16:36:04 +02:00
/* Copyright 2017 Thomas Schneider
*
2017-07-10 10:33:24 +02:00
* This file is a part of Mastalab
2017-05-05 16:36:04 +02:00
*
* 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.
*
2017-07-10 10:33:24 +02:00
* Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
2017-05-05 16:36:04 +02:00
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
2017-08-04 11:11:27 +02:00
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
2017-05-05 16:36:04 +02:00
* see <http://www.gnu.org/licenses>. */
package fr.gouv.etalab.mastodon.activities;
import android.content.Context;
import android.content.DialogInterface;
2017-08-26 19:39:11 +02:00
import android.content.Intent;
2017-05-05 16:36:04 +02:00
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
2017-08-01 10:33:50 +02:00
import android.graphics.drawable.Drawable;
2017-05-05 16:36:04 +02:00
import android.os.AsyncTask;
import android.os.Build;
2017-05-05 16:36:04 +02:00
import android.os.Bundle;
import android.support.annotation.NonNull;
2017-08-23 09:56:42 +02:00
import android.support.design.widget.AppBarLayout;
2017-07-31 19:29:14 +02:00
import android.support.design.widget.FloatingActionButton;
2017-05-05 16:36:04 +02:00
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
2017-08-01 10:33:50 +02:00
import android.support.v4.content.ContextCompat;
2017-12-02 12:23:38 +01:00
import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
2017-05-05 16:36:04 +02:00
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AlertDialog;
2017-10-15 09:22:56 +02:00
import android.support.v7.widget.PopupMenu;
2017-07-31 19:29:14 +02:00
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.text.style.UnderlineSpan;
import android.view.Menu;
2017-05-05 16:36:04 +02:00
import android.view.MenuItem;
import android.view.View;
2017-10-15 09:22:56 +02:00
import android.view.ViewGroup;
import android.widget.ImageButton;
2017-05-05 16:36:04 +02:00
import android.widget.ImageView;
import android.widget.LinearLayout;
2017-05-05 16:36:04 +02:00
import android.widget.TextView;
import android.widget.Toast;
2017-06-11 14:28:29 +02:00
2017-12-02 11:02:25 +01:00
import com.bumptech.glide.Glide;
2017-12-09 12:14:36 +01:00
import com.bumptech.glide.request.RequestOptions;
2017-12-02 11:02:25 +01:00
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
2017-05-05 16:36:04 +02:00
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
2017-05-05 16:36:04 +02:00
import java.util.List;
import java.util.Map;
2017-05-05 16:36:04 +02:00
2017-12-02 12:23:38 +01:00
import fr.gouv.etalab.mastodon.R;
2017-05-05 16:36:04 +02:00
import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveAccountAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveAccountsAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveRelationshipAsyncTask;
import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.APIResponse;
2017-05-05 16:36:04 +02:00
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.Entities.Error;
2017-05-05 16:36:04 +02:00
import fr.gouv.etalab.mastodon.client.Entities.Status;
import fr.gouv.etalab.mastodon.drawers.StatusListAdapter;
import fr.gouv.etalab.mastodon.fragments.DisplayAccountsFragment;
import fr.gouv.etalab.mastodon.fragments.DisplayStatusFragment;
2018-08-16 14:29:57 +02:00
import fr.gouv.etalab.mastodon.helper.CrossActions;
2017-05-05 16:36:04 +02:00
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveAccountInterface;
2018-08-15 14:31:15 +02:00
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveEmojiAccountInterface;
2017-05-05 16:36:04 +02:00
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsAccountInterface;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface;
2017-05-05 16:36:04 +02:00
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRelationshipInterface;
import fr.gouv.etalab.mastodon.client.Entities.Relationship;
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
import fr.gouv.etalab.mastodon.sqlite.TempMuteDAO;
2018-05-13 12:28:55 +02:00
import static fr.gouv.etalab.mastodon.helper.Helper.THEME_BLACK;
import static fr.gouv.etalab.mastodon.helper.Helper.THEME_DARK;
2017-08-01 10:33:50 +02:00
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
2017-11-25 11:01:34 +01:00
import static fr.gouv.etalab.mastodon.helper.Helper.withSuffix;
2017-08-01 10:33:50 +02:00
2017-05-05 16:36:04 +02:00
/**
* Created by Thomas on 01/05/2017.
* Show account activity class
*/
2018-08-15 14:31:15 +02:00
public class ShowAccountActivity extends BaseActivity implements OnPostActionInterface, OnRetrieveAccountInterface, OnRetrieveFeedsAccountInterface, OnRetrieveRelationshipInterface, OnRetrieveFeedsInterface, OnRetrieveEmojiAccountInterface {
2017-05-05 16:36:04 +02:00
private List<Status> statuses;
private StatusListAdapter statusListAdapter;
2017-07-31 19:29:14 +02:00
private FloatingActionButton account_follow;
2017-05-05 16:36:04 +02:00
private static final int NUM_PAGES = 3;
2017-05-05 16:36:04 +02:00
private ViewPager mPager;
private String accountId;
private TabLayout tabLayout;
2017-07-31 19:29:14 +02:00
private TextView account_note, account_follow_request;
2017-05-20 19:40:46 +02:00
private String userId;
2017-07-31 20:18:14 +02:00
private Relationship relationship;
private boolean showMediaOnly, showPinned;
private ImageView pp_actionBar;
2017-11-03 19:12:34 +01:00
private FloatingActionButton header_edit_profile;
private List<Status> pins;
private String accountUrl;
2017-10-14 10:14:55 +02:00
private int maxScrollSize;
private boolean avatarShown = true;
2017-10-15 09:22:56 +02:00
private DisplayStatusFragment displayStatusFragment;
2017-12-02 12:23:38 +01:00
private ImageView account_pp;
2017-10-18 09:15:19 +02:00
private TextView account_dn;
private TextView account_un;
private Account account;
private boolean show_boosts, show_replies;
2017-10-15 09:22:56 +02:00
2018-08-15 14:31:15 +02:00
2017-05-05 16:36:04 +02:00
public enum action{
FOLLOW,
UNFOLLOW,
UNBLOCK,
NOTHING
}
private action doAction;
private API.StatusAction doActionAccount;
2017-10-13 19:06:39 +02:00
2017-05-05 16:36:04 +02:00
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
2017-06-30 17:09:07 +02:00
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
2018-05-11 11:28:05 +02:00
switch (theme){
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme_NoActionBar);
break;
case Helper.THEME_DARK:
setTheme(R.style.AppThemeDark_NoActionBar);
break;
case Helper.THEME_BLACK:
setTheme(R.style.AppThemeBlack_NoActionBar);
break;
default:
setTheme(R.style.AppThemeDark_NoActionBar);
2017-06-30 17:09:07 +02:00
}
2017-05-05 16:36:04 +02:00
setContentView(R.layout.activity_show_account);
2017-08-13 11:30:28 +02:00
setTitle("");
pins = new ArrayList<>();
Bundle b = getIntent().getExtras();
2017-10-18 09:15:19 +02:00
account_follow = findViewById(R.id.account_follow);
account_follow_request = findViewById(R.id.account_follow_request);
header_edit_profile = findViewById(R.id.header_edit_profile);
2017-05-05 16:36:04 +02:00
account_follow.setEnabled(false);
2017-10-18 09:15:19 +02:00
account_pp = findViewById(R.id.account_pp);
account_dn = findViewById(R.id.account_dn);
account_un = findViewById(R.id.account_un);
2017-10-30 13:26:22 +01:00
2017-05-05 16:36:04 +02:00
if(b != null){
accountId = b.getString("accountId");
new RetrieveRelationshipAsyncTask(getApplicationContext(), accountId,ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new RetrieveAccountAsyncTask(getApplicationContext(),accountId, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
2017-05-20 19:40:46 +02:00
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
2017-05-05 16:36:04 +02:00
}else{
Toast.makeText(this,R.string.toast_error_loading_account,Toast.LENGTH_LONG).show();
}
accountUrl = null;
showMediaOnly = false;
showPinned = false;
show_boosts = true;
show_replies = true;
2017-12-02 11:02:25 +01:00
statuses = new ArrayList<>();
boolean isOnWifi = Helper.isOnWIFI(getApplicationContext());
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
2017-08-25 16:08:40 +02:00
int positionSpinnerTrans = sharedpreferences.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_YANDEX);
statusListAdapter = new StatusListAdapter(getApplicationContext(), RetrieveFeedsAsyncTask.Type.USER, accountId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, this.statuses);
2017-12-02 11:02:25 +01:00
2017-05-05 16:36:04 +02:00
2017-10-18 09:15:19 +02:00
tabLayout = findViewById(R.id.account_tabLayout);
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.toots)));
2017-05-05 16:36:04 +02:00
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.following)));
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.followers)));
2017-09-15 19:15:23 +02:00
2017-10-18 09:15:19 +02:00
mPager = findViewById(R.id.account_viewpager);
mPager.setOffscreenPageLimit(3);
2017-05-05 16:36:04 +02:00
PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
mPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
TabLayout.Tab tab = tabLayout.getTabAt(position);
if( tab != null)
tab.select();
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
mPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
Fragment fragment = null;
if( mPager.getAdapter() != null)
fragment = (Fragment) mPager.getAdapter().instantiateItem(mPager, tab.getPosition());
switch (tab.getPosition()){
case 0:
if( displayStatusFragment != null )
displayStatusFragment.scrollToTop();
break;
case 1:
case 2:
if( fragment != null) {
DisplayAccountsFragment displayAccountsFragment = ((DisplayAccountsFragment) fragment);
displayAccountsFragment.scrollToTop();
}
break;
}
2017-05-05 16:36:04 +02:00
}
});
2017-05-20 19:40:46 +02:00
2017-10-18 09:15:19 +02:00
account_note = findViewById(R.id.account_note);
2017-05-20 19:40:46 +02:00
2018-08-16 14:29:57 +02:00
header_edit_profile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(ShowAccountActivity.this, EditProfileActivity.class);
startActivity(intent);
}
});
2017-10-15 09:22:56 +02:00
2017-10-18 09:15:19 +02:00
final ImageButton account_menu = findViewById(R.id.account_menu);
2017-10-30 13:26:22 +01:00
ImageButton action_more = findViewById(R.id.action_more);
2017-10-15 09:22:56 +02:00
account_menu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
2017-10-30 13:26:22 +01:00
showMenu(account_menu);
}
});
action_more.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showMenu(account_menu);
}
});
}
private void showMenu(View account_menu){
if( account == null)
return;
final PopupMenu popup = new PopupMenu(ShowAccountActivity.this, account_menu);
popup.getMenuInflater()
.inflate(R.menu.main_showaccount, popup.getMenu());
if( !Helper.canPin ) {
2017-10-30 13:26:22 +01:00
popup.getMenu().findItem(R.id.action_show_pinned).setVisible(false);
}
final String[] stringArrayConf;
final boolean isOwner = account.getId().equals(userId);
if( isOwner) {
popup.getMenu().findItem(R.id.action_block).setVisible(false);
popup.getMenu().findItem(R.id.action_mute).setVisible(false);
popup.getMenu().findItem(R.id.action_mention).setVisible(false);
2017-10-30 13:26:22 +01:00
stringArrayConf = getResources().getStringArray(R.array.more_action_owner_confirm);
}else {
popup.getMenu().findItem(R.id.action_block).setVisible(true);
popup.getMenu().findItem(R.id.action_mute).setVisible(true);
popup.getMenu().findItem(R.id.action_mention).setVisible(true);
2017-10-30 13:26:22 +01:00
stringArrayConf = getResources().getStringArray(R.array.more_action_confirm);
}
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
AlertDialog.Builder builderInner;
switch (item.getItemId()) {
case R.id.action_show_pinned:
showPinned = !showPinned;
if( tabLayout.getTabAt(0) != null)
//noinspection ConstantConditions
tabLayout.getTabAt(0).select();
PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
return true;
case R.id.action_show_media:
showMediaOnly = !showMediaOnly;
if( tabLayout.getTabAt(0) != null)
//noinspection ConstantConditions
tabLayout.getTabAt(0).select();
mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
return true;
case R.id.action_open_browser:
if( accountUrl != null) {
if( !accountUrl.startsWith("http://") && ! accountUrl.startsWith("https://"))
accountUrl = "http://" + accountUrl;
Helper.openBrowser(ShowAccountActivity.this, accountUrl);
2017-10-15 09:22:56 +02:00
}
return true;
case R.id.action_mention:
Intent intent = new Intent(getApplicationContext(), TootActivity.class);
Bundle b = new Bundle();
b.putString("mentionAccount", account.getAcct());
intent.putExtras(b);
startActivity(intent);
return true;
2017-10-30 13:26:22 +01:00
case R.id.action_mute:
builderInner = new AlertDialog.Builder(ShowAccountActivity.this);
builderInner.setTitle(stringArrayConf[0]);
doActionAccount = API.StatusAction.MUTE;
break;
case R.id.action_block:
builderInner = new AlertDialog.Builder(ShowAccountActivity.this);
builderInner.setTitle(stringArrayConf[1]);
doActionAccount = API.StatusAction.BLOCK;
break;
default:
return true;
}
builderInner.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int which) {
dialog.dismiss();
2017-10-15 09:22:56 +02:00
}
});
2017-10-30 13:26:22 +01:00
builderInner.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int which) {
new PostActionAsyncTask(getApplicationContext(), doActionAccount, account.getId(), ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
dialog.dismiss();
}
});
builderInner.show();
return true;
2017-10-15 09:22:56 +02:00
}
});
2017-10-30 13:26:22 +01:00
popup.show();
2017-05-05 16:36:04 +02:00
}
@Override
public void onPostAction(int statusCode,API.StatusAction statusAction, String targetedId, Error error) {
if( error != 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(), error.getError(),Toast.LENGTH_LONG).show();
return;
}
2017-05-05 16:36:04 +02:00
Helper.manageMessageStatusCode(getApplicationContext(), statusCode, statusAction);
new RetrieveRelationshipAsyncTask(getApplicationContext(), accountId,ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
2017-08-26 19:39:11 +02:00
2017-05-05 16:36:04 +02:00
@Override
public void onRetrieveAccount(final Account account, Error error) {
if( error != 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(), error.getError(),Toast.LENGTH_LONG).show();
return;
}
this.account = account;
accountUrl = account.getUrl();
2017-08-01 10:33:50 +02:00
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
2018-05-13 12:28:55 +02:00
if( theme == Helper.THEME_BLACK){
changeDrawableColor(getApplicationContext(), R.drawable.ic_lock_outline,R.color.dark_icon);
2017-08-01 10:33:50 +02:00
}else {
2017-10-28 14:32:18 +02:00
changeDrawableColor(getApplicationContext(), R.drawable.ic_lock_outline,R.color.mastodonC4);
2017-08-01 10:33:50 +02:00
}
2017-10-27 15:34:53 +02:00
String urlHeader = account.getHeader();
2018-08-19 10:57:24 +02:00
if (urlHeader != null && urlHeader.startsWith("/")) {
2018-01-24 15:56:33 +01:00
urlHeader = Helper.getLiveInstanceWithProtocol(ShowAccountActivity.this) + account.getHeader();
2017-10-27 15:34:53 +02:00
}
2018-08-19 10:57:24 +02:00
if (urlHeader != null && !urlHeader.contains("missing.png")) {
2017-12-02 11:02:25 +01:00
Glide.with(getApplicationContext())
.asBitmap()
.load(urlHeader)
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
ImageView banner_pp = findViewById(R.id.banner_pp);
2018-01-10 10:37:55 +01:00
banner_pp.setImageBitmap(resource);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
banner_pp.setImageAlpha(60);
}else {
banner_pp.setAlpha(60);
}
2017-12-02 11:02:25 +01:00
}
});
2017-10-27 15:34:53 +02:00
}
2017-08-01 10:33:50 +02:00
//Redraws icon for locked accounts
final float scale = getResources().getDisplayMetrics().density;
2017-10-27 15:34:53 +02:00
if(account.isLocked()){
2017-10-28 14:32:18 +02:00
Drawable img = ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_lock_outline);
assert img != null;
2017-08-01 10:33:50 +02:00
img.setBounds(0,0,(int) (20 * scale + 0.5f),(int) (20 * scale + 0.5f));
account_dn.setCompoundDrawables( img, null, null, null);
}else{
account_dn.setCompoundDrawables( null, null, null, null);
}
2017-05-20 19:40:46 +02:00
2017-10-14 11:09:12 +02:00
2017-10-27 15:34:53 +02:00
TextView actionbar_title = findViewById(R.id.show_account_title);
if( account.getAcct() != null)
actionbar_title.setText(account.getAcct());
pp_actionBar = findViewById(R.id.pp_actionBar);
String url = account.getAvatar();
if( url.startsWith("/") ){
2018-01-24 15:56:33 +01:00
url = Helper.getLiveInstanceWithProtocol(getApplicationContext()) + account.getAvatar();
2017-10-27 15:34:53 +02:00
}
2017-12-02 11:02:25 +01:00
Glide.with(getApplicationContext())
.asBitmap()
.load(url)
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
BitmapDrawable ppDrawable = new BitmapDrawable(getResources(), Bitmap.createScaledBitmap(resource, (int) Helper.convertDpToPixel(25, getApplicationContext()), (int) Helper.convertDpToPixel(25, getApplicationContext()), true));
if( pp_actionBar != null){
pp_actionBar.setImageDrawable(ppDrawable);
}
}
});
2017-12-02 12:23:38 +01:00
2017-10-27 15:34:53 +02:00
final AppBarLayout appBar = findViewById(R.id.appBar);
maxScrollSize = appBar.getTotalScrollRange();
2017-10-13 19:06:39 +02:00
final TextView warning_message = findViewById(R.id.warning_message);
final SpannableString content = new SpannableString(getString(R.string.disclaimer_full));
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
warning_message.setText(content);
warning_message.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if( !accountUrl.startsWith("http://") && ! accountUrl.startsWith("https://"))
accountUrl = "http://" + accountUrl;
Helper.openBrowser(ShowAccountActivity.this, accountUrl);
}
});
//Timed muted account
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
final SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
final Account authenticatedAccount = new AccountDAO(getApplicationContext(), db).getAccountByID(userId);
boolean isTimedMute = new TempMuteDAO(getApplicationContext(), db).isTempMuted(authenticatedAccount, account.getId());
if( isTimedMute){
String date_mute = new TempMuteDAO(getApplicationContext(), db).getMuteDateByID(authenticatedAccount, account.getId());
if( date_mute != null) {
final TextView temp_mute = findViewById(R.id.temp_mute);
temp_mute.setVisibility(View.VISIBLE);
SpannableString content_temp_mute = new SpannableString(getString(R.string.timed_mute_profile, account.getAcct(), date_mute));
content_temp_mute.setSpan(new UnderlineSpan(), 0, content_temp_mute.length(), 0);
temp_mute.setText(content_temp_mute);
temp_mute.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new TempMuteDAO(getApplicationContext(), db).remove(authenticatedAccount, account.getId());
Toast.makeText(getApplicationContext(), R.string.toast_unmute, Toast.LENGTH_LONG).show();
temp_mute.setVisibility(View.GONE);
}
});
}
}
//This account was moved to another one
if( account.getMoved_to_account() != null){
TextView account_moved = findViewById(R.id.account_moved);
account_moved.setVisibility(View.VISIBLE);
2018-05-13 12:28:55 +02:00
if( theme == THEME_DARK || theme == THEME_BLACK)
changeDrawableColor(ShowAccountActivity.this, R.drawable.ic_card_travel,R.color.dark_icon);
else
changeDrawableColor(ShowAccountActivity.this, R.drawable.ic_card_travel,R.color.black);
Drawable imgTravel = ContextCompat.getDrawable(ShowAccountActivity.this, R.drawable.ic_card_travel);
assert imgTravel != null;
imgTravel.setBounds(0,0,(int) (20 * scale + 0.5f),(int) (20 * scale + 0.5f));
account_moved.setCompoundDrawables(imgTravel, null, null, null);
//Retrieves content and make account names clickable
SpannableString spannableString = account.moveToText(ShowAccountActivity.this);
account_moved.setText(spannableString, TextView.BufferType.SPANNABLE);
account_moved.setMovementMethod(LinkMovementMethod.getInstance());
}
2018-08-15 10:00:24 +02:00
if( account.getAcct().contains("@") )
warning_message.setVisibility(View.VISIBLE);
else
warning_message.setVisibility(View.GONE);
2017-10-27 15:34:53 +02:00
appBar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
LinearLayout toolbarContent = findViewById(R.id.toolbar_content);
if( toolbarContent != null) {
if (Math.abs(verticalOffset) - appBar.getTotalScrollRange() == 0) {
if (toolbarContent.getVisibility() == View.GONE)
toolbarContent.setVisibility(View.VISIBLE);
} else {
if (toolbarContent.getVisibility() == View.VISIBLE)
toolbarContent.setVisibility(View.GONE);
2017-08-23 09:56:42 +02:00
}
2017-10-27 15:34:53 +02:00
}
if (maxScrollSize == 0)
maxScrollSize = appBarLayout.getTotalScrollRange();
2017-10-14 11:09:12 +02:00
2017-10-27 15:34:53 +02:00
int percentage = (Math.abs(verticalOffset)) * 100 / maxScrollSize;
2017-10-14 11:09:12 +02:00
2017-10-27 15:34:53 +02:00
if (percentage >= 40 && avatarShown) {
avatarShown = false;
2017-10-14 11:09:12 +02:00
2017-10-27 15:34:53 +02:00
account_pp.animate()
.scaleY(0).scaleX(0)
.setDuration(400)
.start();
warning_message.setVisibility(View.GONE);
2017-10-14 11:09:12 +02:00
}
2017-10-27 15:34:53 +02:00
if (percentage <= 40 && !avatarShown) {
avatarShown = true;
account_pp.animate()
.scaleY(1).scaleX(1)
.start();
if( account.getAcct().contains("@") )
warning_message.setVisibility(View.VISIBLE);
else
warning_message.setVisibility(View.GONE);
2017-10-27 15:34:53 +02:00
}
}
});
2018-08-15 14:31:15 +02:00
if ( account.getFields() != null && account.getFields().size() > 0){
HashMap<String, String> fields = account.getFields();
Iterator it = fields.entrySet().iterator();
int i = 1;
LinearLayout fields_container = findViewById(R.id.fields_container);
if( fields_container != null)
fields_container.setVisibility(View.VISIBLE);
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
String label = (String)pair.getKey();
String value = (String)pair.getValue();
LinearLayout field;
TextView labelView;
TextView valueView;
switch(i){
case 1:
field = findViewById(R.id.field1);
labelView = findViewById(R.id.label1);
valueView = findViewById(R.id.value1);
break;
case 2:
field = findViewById(R.id.field2);
labelView = findViewById(R.id.label2);
valueView = findViewById(R.id.value2);
break;
case 3:
field = findViewById(R.id.field3);
labelView = findViewById(R.id.label3);
valueView = findViewById(R.id.value3);
break;
case 4:
field = findViewById(R.id.field4);
labelView = findViewById(R.id.label4);
valueView = findViewById(R.id.value4);
break;
default:
field = findViewById(R.id.field1);
labelView = findViewById(R.id.label1);
valueView = findViewById(R.id.value1);
break;
}
if( field != null && labelView != null && valueView != null) {
switch (theme){
case Helper.THEME_LIGHT:
labelView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_light_2));
valueView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_light_4));
break;
case Helper.THEME_DARK:
labelView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_dark_2));
valueView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_dark_4));
break;
case Helper.THEME_BLACK:
labelView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_black_2));
valueView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_black_4));
break;
default:
labelView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_dark_2));
valueView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_dark_4));
}
field.setVisibility(View.VISIBLE);
2018-08-15 14:31:15 +02:00
SpannableString spannableValueString = Helper.clickableElementsDescription(ShowAccountActivity.this, value, account.getEmojis());
valueView.setText(spannableValueString, TextView.BufferType.SPANNABLE);
valueView.setMovementMethod(LinkMovementMethod.getInstance());
labelView.setText(label);
}
i++;
2018-08-15 14:31:15 +02:00
// it.remove();
}
}
2017-10-27 15:34:53 +02:00
account_dn.setText(Helper.shortnameToUnicode(account.getDisplay_name(), true));
account_un.setText(String.format("@%s", account.getAcct()));
2018-08-15 14:31:15 +02:00
SpannableString spannableString = Helper.clickableElementsDescription(ShowAccountActivity.this, account.getNote(), account.getEmojis());
2018-08-15 10:00:24 +02:00
account.setNoteSpan(spannableString);
2018-08-15 14:31:15 +02:00
account.makeEmojisAccount(ShowAccountActivity.this, ShowAccountActivity.this);
account_note.setText(account.getNoteSpan(), TextView.BufferType.SPANNABLE);
2017-10-27 15:34:53 +02:00
account_note.setMovementMethod(LinkMovementMethod.getInstance());
if (tabLayout.getTabAt(0) != null && tabLayout.getTabAt(1) != null && tabLayout.getTabAt(2) != null) {
//noinspection ConstantConditions
2017-11-25 11:01:34 +01:00
tabLayout.getTabAt(0).setText(getString(R.string.status_cnt, withSuffix(account.getStatuses_count())));
2017-10-27 15:34:53 +02:00
//noinspection ConstantConditions
2017-11-25 11:01:34 +01:00
tabLayout.getTabAt(1).setText(getString(R.string.following_cnt, withSuffix(account.getFollowing_count())));
2017-10-27 15:34:53 +02:00
//noinspection ConstantConditions
2017-11-25 11:01:34 +01:00
tabLayout.getTabAt(2).setText(getString(R.string.followers_cnt, withSuffix(account.getFollowers_count())));
2017-10-27 15:34:53 +02:00
//Allows to filter by long click
final LinearLayout tabStrip = (LinearLayout) tabLayout.getChildAt(0);
tabStrip.getChildAt(0).setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
PopupMenu popup = new PopupMenu(ShowAccountActivity.this, tabStrip.getChildAt(0));
popup.getMenuInflater()
.inflate(R.menu.option_filter_toots_account, popup.getMenu());
Menu menu = popup.getMenu();
if( !Helper.canPin ) {
2017-10-27 15:34:53 +02:00
popup.getMenu().findItem(R.id.action_show_pinned).setVisible(false);
}
final MenuItem itemShowPined = menu.findItem(R.id.action_show_pinned);
final MenuItem itemShowMedia = menu.findItem(R.id.action_show_media);
final MenuItem itemShowBoosts = menu.findItem(R.id.action_show_boosts);
final MenuItem itemShowReplies = menu.findItem(R.id.action_show_replies);
2017-10-27 15:34:53 +02:00
itemShowMedia.setChecked(showMediaOnly);
itemShowPined.setChecked(showPinned);
itemShowBoosts.setChecked(show_boosts);
itemShowReplies.setChecked(show_replies);
2017-10-27 15:34:53 +02:00
popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
@Override
public void onDismiss(PopupMenu menu) {
if( displayStatusFragment != null)
displayStatusFragment.refreshFilter();
2017-10-15 09:22:56 +02:00
}
2017-10-27 15:34:53 +02:00
});
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
item.setActionView(new View(getApplicationContext()));
item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
return false;
2017-10-15 09:22:56 +02:00
}
2017-10-27 15:34:53 +02:00
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
return false;
}
});
switch (item.getItemId()) {
case R.id.action_show_pinned:
showPinned = !showPinned;
break;
case R.id.action_show_media:
showMediaOnly = !showMediaOnly;
break;
case R.id.action_show_boosts:
show_boosts = !show_boosts;
break;
case R.id.action_show_replies:
show_replies = !show_replies;
2017-10-27 15:34:53 +02:00
break;
}
if( tabLayout.getTabAt(0) != null)
//noinspection ConstantConditions
tabLayout.getTabAt(0).select();
PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
2017-10-27 15:34:53 +02:00
itemShowMedia.setChecked(showMediaOnly);
itemShowPined.setChecked(showPinned);
itemShowReplies.setChecked(show_replies);
itemShowBoosts.setChecked(show_boosts);
2017-10-27 15:34:53 +02:00
return false;
}
});
popup.show();
return true;
}
});
2017-10-15 09:22:56 +02:00
2017-10-27 15:34:53 +02:00
}
boolean disableGif = sharedpreferences.getBoolean(Helper.SET_DISABLE_GIF, false);
if( !disableGif)
Glide.with(getApplicationContext()).load(account.getAvatar()).apply(RequestOptions.circleCropTransform()).into(account_pp);
else
Glide.with(getApplicationContext())
.asBitmap()
.load(account.getAvatar())
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), Helper.addBorder(resource, account_pp.getContext()));
circularBitmapDrawable.setCircular(true);
account_pp.setImageDrawable(circularBitmapDrawable);
}
});
2018-08-16 14:29:57 +02:00
//Follow button
account_follow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if( doAction == action.NOTHING){
Toast.makeText(getApplicationContext(), R.string.nothing_to_do, Toast.LENGTH_LONG).show();
}else if( doAction == action.FOLLOW){
account_follow.setEnabled(false);
new PostActionAsyncTask(getApplicationContext(), API.StatusAction.FOLLOW, accountId, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else if( doAction == action.UNFOLLOW){
account_follow.setEnabled(false);
new PostActionAsyncTask(getApplicationContext(), API.StatusAction.UNFOLLOW, accountId, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else if( doAction == action.UNBLOCK){
account_follow.setEnabled(false);
new PostActionAsyncTask(getApplicationContext(), API.StatusAction.UNBLOCK, accountId, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
});
account_follow.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
2018-08-21 16:20:20 +02:00
CrossActions.doCrossAction(ShowAccountActivity.this, null, null, account, API.StatusAction.FOLLOW , null, ShowAccountActivity.this, false);
2018-08-16 14:29:57 +02:00
return false;
}
});
2017-12-02 12:23:38 +01:00
}
2017-10-15 09:22:56 +02:00
2017-12-02 12:38:58 +01:00
2017-05-05 16:36:04 +02:00
@Override
public void onRetrieveFeedsAccount(List<Status> statuses) {
if( statuses != null) {
2017-10-27 15:34:53 +02:00
this.statuses.addAll(statuses);
2017-05-05 16:36:04 +02:00
statusListAdapter.notifyDataSetChanged();
}
}
@Override
public void onRetrieveFeeds(APIResponse apiResponse) {
if( apiResponse.getError() != null){
final SharedPreferences sharedpreferences = getApplicationContext().getSharedPreferences(Helper.APP_PREFS, android.content.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;
}
pins = apiResponse.getStatuses();
2017-09-15 19:15:23 +02:00
if (pins != null && pins.size() > 0) {
if( pins.get(0).isPinned()) {
2017-10-27 15:34:53 +02:00
this.statuses.addAll(pins);
2017-09-15 19:15:23 +02:00
//noinspection ConstantConditions
tabLayout.getTabAt(3).setText(getString(R.string.pins_cnt, pins.size()));
statusListAdapter.notifyDataSetChanged();
}
}
}
2017-05-20 19:40:46 +02:00
2017-05-05 16:36:04 +02:00
@Override
public void onRetrieveRelationship(Relationship relationship, Error error) {
if( error != 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(), error.getError(),Toast.LENGTH_LONG).show();
return;
}
2017-07-31 20:18:14 +02:00
this.relationship = relationship;
manageButtonVisibility();
//The authenticated account is followed by the account
2018-08-16 14:29:57 +02:00
if( relationship != null && relationship.isFollowed_by()){
2017-10-18 09:15:19 +02:00
TextView account_followed_by = findViewById(R.id.account_followed_by);
2017-07-31 20:18:14 +02:00
account_followed_by.setVisibility(View.VISIBLE);
}
}
//Manages the visibility of the button
private void manageButtonVisibility(){
if( relationship == null)
return;
2017-06-07 13:58:21 +02:00
account_follow.setEnabled(true);
2017-08-01 17:09:08 +02:00
if( accountId != null && accountId.equals(userId)){
account_follow.setVisibility(View.GONE);
header_edit_profile.setVisibility(View.VISIBLE);
2017-11-03 19:12:34 +01:00
header_edit_profile.bringToFront();
2017-08-01 17:09:08 +02:00
}else if( relationship.isBlocking()){
2017-10-28 17:59:50 +02:00
account_follow.setImageResource(R.drawable.ic_lock_open);
2017-05-05 16:36:04 +02:00
doAction = action.UNBLOCK;
2017-07-31 20:18:14 +02:00
account_follow.setVisibility(View.VISIBLE);
2017-05-05 16:36:04 +02:00
}else if( relationship.isRequested()){
2017-07-31 19:29:14 +02:00
account_follow_request.setVisibility(View.VISIBLE);
account_follow.setVisibility(View.GONE);
2017-05-05 16:36:04 +02:00
doAction = action.NOTHING;
}else if( relationship.isFollowing()){
2017-07-31 19:29:14 +02:00
account_follow.setImageResource(R.drawable.ic_user_times);
2017-05-05 16:36:04 +02:00
doAction = action.UNFOLLOW;
2017-07-31 20:18:14 +02:00
account_follow.setVisibility(View.VISIBLE);
2017-05-05 16:36:04 +02:00
}else if( !relationship.isFollowing()){
2017-07-31 19:29:14 +02:00
account_follow.setImageResource(R.drawable.ic_user_plus);
2017-05-05 16:36:04 +02:00
doAction = action.FOLLOW;
2017-07-31 20:18:14 +02:00
account_follow.setVisibility(View.VISIBLE);
2017-05-05 16:36:04 +02:00
}else{
2017-07-31 19:29:14 +02:00
account_follow.setVisibility(View.GONE);
2017-05-05 16:36:04 +02:00
doAction = action.NOTHING;
}
}
/**
* Pager adapter for the 4 fragments
2017-05-05 16:36:04 +02:00
*/
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
ScreenSlidePagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
Bundle bundle = new Bundle();
switch (position){
case 0:
2017-10-15 09:22:56 +02:00
displayStatusFragment = new DisplayStatusFragment();
2017-05-05 16:36:04 +02:00
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.USER);
bundle.putString("targetedId", accountId);
bundle.putBoolean("showMediaOnly",showMediaOnly);
bundle.putBoolean("showPinned",showPinned);
2017-05-05 16:36:04 +02:00
displayStatusFragment.setArguments(bundle);
return displayStatusFragment;
case 1:
DisplayAccountsFragment displayAccountsFragment = new DisplayAccountsFragment();
bundle.putSerializable("type", RetrieveAccountsAsyncTask.Type.FOLLOWING);
bundle.putString("targetedId", accountId);
displayAccountsFragment.setArguments(bundle);
return displayAccountsFragment;
case 2:
displayAccountsFragment = new DisplayAccountsFragment();
bundle.putSerializable("type", RetrieveAccountsAsyncTask.Type.FOLLOWERS);
bundle.putString("targetedId", accountId);
displayAccountsFragment.setArguments(bundle);
return displayAccountsFragment;
}
return null;
}
@NonNull
2017-10-15 09:22:56 +02:00
@Override
public Object instantiateItem(ViewGroup container, int position) {
Fragment createdFragment = (Fragment) super.instantiateItem(container, position);
// save the appropriate reference depending on position
switch (position) {
case 0:
displayStatusFragment = (DisplayStatusFragment) createdFragment;
break;
}
return createdFragment;
}
2017-05-05 16:36:04 +02:00
@Override
public int getCount() {
return NUM_PAGES;
}
}
2018-08-15 14:31:15 +02:00
@Override
public void onRetrieveEmojiAccount(Account account) {
account_note.setText(account.getNoteSpan(), TextView.BufferType.SPANNABLE);
2018-08-17 11:53:21 +02:00
account_dn.setText(account.getdisplayNameSpanSpan(), TextView.BufferType.SPANNABLE);;
2018-08-15 14:31:15 +02:00
if ( account.getFieldsSpan() != null && account.getFieldsSpan().size() > 0){
HashMap<String, SpannableString> fieldsSpan = account.getFieldsSpan();
Iterator it = fieldsSpan.entrySet().iterator();
int i = 1;
LinearLayout fields_container = findViewById(R.id.fields_container);
if( fields_container != null)
fields_container.setVisibility(View.VISIBLE);
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
String label = (String)pair.getKey();
2018-08-15 15:10:33 +02:00
SpannableString value = (SpannableString)pair.getValue();
2018-08-15 14:31:15 +02:00
LinearLayout field;
TextView labelView;
TextView valueView;
switch(i){
case 1:
field = findViewById(R.id.field1);
labelView = findViewById(R.id.label1);
valueView = findViewById(R.id.value1);
break;
case 2:
field = findViewById(R.id.field2);
labelView = findViewById(R.id.label2);
valueView = findViewById(R.id.value2);
break;
case 3:
field = findViewById(R.id.field3);
labelView = findViewById(R.id.label3);
valueView = findViewById(R.id.value3);
break;
case 4:
field = findViewById(R.id.field4);
labelView = findViewById(R.id.label4);
valueView = findViewById(R.id.value4);
break;
default:
field = findViewById(R.id.field1);
labelView = findViewById(R.id.label1);
valueView = findViewById(R.id.value1);
break;
}
if( field != null && labelView != null && valueView != null) {
field.setVisibility(View.VISIBLE);
valueView.setText(value, TextView.BufferType.SPANNABLE);
valueView.setMovementMethod(LinkMovementMethod.getInstance());
labelView.setText(label);
}
i++;
}
}
}
public boolean showReplies(){
return show_replies;
}
public boolean showBoosts(){
return show_boosts;
}
2017-05-05 16:36:04 +02:00
}