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

653 lines
30 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;
2017-08-26 10:57:08 +02:00
import android.annotation.SuppressLint;
2017-08-26 19:39:11 +02:00
import android.content.BroadcastReceiver;
2017-05-05 16:36:04 +02:00
import android.content.Context;
2017-08-26 19:39:11 +02:00
import android.content.Intent;
import android.content.IntentFilter;
2017-05-05 16:36:04 +02:00
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.LightingColorFilter;
import android.graphics.Matrix;
import android.graphics.Paint;
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;
2017-08-26 19:39:11 +02:00
import android.os.Handler;
import android.support.annotation.RequiresApi;
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-08-26 19:39:11 +02:00
import android.support.v4.content.LocalBroadcastManager;
2017-05-05 16:36:04 +02:00
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
2017-07-31 19:29:14 +02:00
import android.support.v7.app.ActionBar;
2017-05-05 16:36:04 +02:00
import android.support.v7.app.AppCompatActivity;
2017-07-31 19:29:14 +02:00
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.Menu;
2017-05-05 16:36:04 +02:00
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
2017-05-05 16:36:04 +02:00
import android.widget.TextView;
import android.widget.Toast;
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
2017-05-05 16:36:04 +02:00
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.FailReason;
2017-07-31 19:29:14 +02:00
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
2017-06-11 14:28:29 +02:00
2017-05-05 16:36:04 +02:00
import java.io.File;
2017-05-05 16:36:04 +02:00
import java.util.ArrayList;
import java.util.List;
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.client.PatchBaseImageDownloader;
2017-05-05 16:36:04 +02:00
import fr.gouv.etalab.mastodon.drawers.StatusListAdapter;
import fr.gouv.etalab.mastodon.fragments.DisplayAccountsFragment;
import fr.gouv.etalab.mastodon.fragments.DisplayStatusFragment;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveAccountInterface;
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 mastodon.etalab.gouv.fr.mastodon.R;
import fr.gouv.etalab.mastodon.client.Entities.Relationship;
2017-08-01 10:33:50 +02:00
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
2017-05-05 16:36:04 +02:00
/**
* Created by Thomas on 01/05/2017.
* Show account activity class
*/
public class ShowAccountActivity extends AppCompatActivity implements OnPostActionInterface, OnRetrieveAccountInterface, OnRetrieveFeedsAccountInterface, OnRetrieveRelationshipInterface, OnRetrieveFeedsInterface {
2017-05-05 16:36:04 +02:00
private ImageLoader imageLoader;
private DisplayImageOptions options;
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;
private static int instanceValue = 0;
2017-07-31 20:18:14 +02:00
private Relationship relationship;
private boolean showMediaOnly, showPinned;
private ImageView pp_actionBar;
2017-08-26 19:39:11 +02:00
private BroadcastReceiver hide_header;
private boolean isHiddingShowing = false;
private LinearLayout main_header_container;
private ImageView header_edit_profile;
private List<Status> pins;
2017-05-05 16:36:04 +02:00
public enum action{
FOLLOW,
UNFOLLOW,
UNBLOCK,
NOTHING
}
private action doAction;
@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);
2017-06-30 17:09:07 +02:00
if( theme == Helper.THEME_LIGHT){
setTheme(R.style.AppTheme);
}else {
setTheme(R.style.AppThemeDark);
}
2017-05-05 16:36:04 +02:00
setContentView(R.layout.activity_show_account);
2017-08-13 11:30:28 +02:00
setTitle("");
instanceValue += 1;
pins = new ArrayList<>();
Bundle b = getIntent().getExtras();
2017-07-31 19:29:14 +02:00
account_follow = (FloatingActionButton) findViewById(R.id.account_follow);
account_follow_request = (TextView) findViewById(R.id.account_follow_request);
2017-08-26 19:39:11 +02:00
main_header_container = (LinearLayout) findViewById(R.id.main_header_container);
header_edit_profile = (ImageView) findViewById(R.id.header_edit_profile);
2017-05-05 16:36:04 +02:00
account_follow.setEnabled(false);
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();
}
showMediaOnly = false;
showPinned = false;
imageLoader = ImageLoader.getInstance();
File cacheDir = new File(getCacheDir(), getString(R.string.app_name));
ImageLoaderConfiguration configImg = new ImageLoaderConfiguration.Builder(this)
.imageDownloader(new PatchBaseImageDownloader(getApplicationContext()))
.threadPoolSize(5)
.threadPriority(Thread.MIN_PRIORITY + 3)
.denyCacheImageMultipleSizesInMemory()
.diskCache(new UnlimitedDiskCache(cacheDir))
.build();
imageLoader.init(configImg);
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-07-31 19:29:14 +02:00
options = new DisplayImageOptions.Builder().displayer(new RoundedBitmapDisplayer(80)).cacheInMemory(false)
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
2017-05-05 16:36:04 +02:00
if( getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
tabLayout = (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-05-05 16:36:04 +02:00
mPager = (ViewPager) findViewById(R.id.account_viewpager);
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 = (Fragment) mPager.getAdapter().instantiateItem(mPager, tab.getPosition());
switch (tab.getPosition()){
case 0:
DisplayStatusFragment displayStatusFragment = ((DisplayStatusFragment) fragment);
if( displayStatusFragment != null )
displayStatusFragment.scrollToTop();
break;
case 1:
case 2:
DisplayAccountsFragment displayAccountsFragment = ((DisplayAccountsFragment) fragment);
if (displayAccountsFragment != null)
displayAccountsFragment.scrollToTop();
break;
}
2017-05-05 16:36:04 +02:00
}
});
2017-05-20 19:40:46 +02:00
account_note = (TextView) findViewById(R.id.account_note);
2017-05-05 16:36:04 +02:00
//Follow button
account_follow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
2017-06-07 13:58:21 +02:00
if( doAction == action.NOTHING){
Toast.makeText(getApplicationContext(), R.string.nothing_to_do, Toast.LENGTH_LONG).show();
}else if( doAction == action.FOLLOW){
2017-05-05 16:36:04 +02:00
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);
}
}
});
2017-08-26 19:39:11 +02:00
if( Build.VERSION.SDK_INT < 21) {
//Register LocalBroadcast to receive selected accounts after search
hide_header = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (!isHiddingShowing) {
isHiddingShowing = true;
ImageView account_pp = (ImageView) findViewById(R.id.account_pp);
boolean hide = intent.getBooleanExtra("hide", false);
if (hide) {
main_header_container.setVisibility(View.GONE);
if (pp_actionBar != null)
pp_actionBar.setVisibility(View.VISIBLE);
tabLayout.setVisibility(View.GONE);
} else {
manageButtonVisibility();
tabLayout.setVisibility(View.VISIBLE);
main_header_container.setVisibility(View.VISIBLE);
if (pp_actionBar != null)
pp_actionBar.setVisibility(View.GONE);
}
account_pp.requestLayout();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
isHiddingShowing = false;
}
}, 700);
}
}
};
LocalBroadcastManager.getInstance(this).registerReceiver(hide_header, new IntentFilter(Helper.HEADER_ACCOUNT + String.valueOf(instanceValue)));
}
header_edit_profile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(ShowAccountActivity.this, EditProfileActivity.class);
startActivity(intent);
}
});
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);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_showaccount, menu);
//TODO: if one day pinned toots from another account can be displayed, we need to remove the condition !accountId.equals(userId)
if( !Helper.canPin || !accountId.equals(userId)) {
menu.findItem(R.id.action_show_pinned).setVisible(false);
}
return true;
}
2017-05-05 16:36:04 +02:00
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
case R.id.action_show_pinned:
showPinned = !showPinned;
if( showPinned )
item.setIcon(R.drawable.ic_clear_all);
else
item.setIcon(R.drawable.ic_action_pin);
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( showMediaOnly )
item.setIcon(R.drawable.ic_clear_all);
else
item.setIcon(R.drawable.ic_perm_media);
2017-08-26 10:57:08 +02:00
if( tabLayout.getTabAt(0) != null)
//noinspection ConstantConditions
tabLayout.getTabAt(0).select();
mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
return true;
2017-05-05 16:36:04 +02:00
default:
return super.onOptionsItemSelected(item);
}
}
2017-08-26 19:39:11 +02:00
@Override
public void onDestroy(){
super.onDestroy();
LocalBroadcastManager.getInstance(this).unregisterReceiver(hide_header);
}
2017-05-05 16:36:04 +02:00
@Override
public void onRetrieveAccount(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;
}
2017-05-05 16:36:04 +02:00
ImageView account_pp = (ImageView) findViewById(R.id.account_pp);
TextView account_dn = (TextView) findViewById(R.id.account_dn);
TextView account_un = (TextView) findViewById(R.id.account_un);
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);
if( theme == Helper.THEME_DARK){
changeDrawableColor(getApplicationContext(), R.drawable.ic_action_lock_closed,R.color.mastodonC4);
2017-08-01 10:33:50 +02:00
}else {
changeDrawableColor(getApplicationContext(), R.drawable.ic_action_lock_closed,R.color.mastodonC4);
2017-08-01 10:33:50 +02:00
}
if( account!= null) {
String urlHeader = account.getHeader();
if (urlHeader.startsWith("/")) {
urlHeader = "https://" + Helper.getLiveInstance(ShowAccountActivity.this) + account.getHeader();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && !urlHeader.contains("missing.png")) {
DisplayImageOptions optionNew = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false)
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
imageLoader.loadImage(urlHeader, optionNew, new SimpleImageLoadingListener() {
@RequiresApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
super.onLoadingComplete(imageUri, view, loadedImage);
LinearLayout main_header_container = (LinearLayout) findViewById(R.id.main_header_container);
Bitmap workingBitmap = Bitmap.createBitmap(loadedImage);
Bitmap mutableBitmap = workingBitmap.copy(Bitmap.Config.ARGB_8888, true);
Canvas canvas = new Canvas(mutableBitmap);
Paint p = new Paint(Color.BLACK);
ColorFilter filter = new LightingColorFilter(0xFF7F7F7F, 0x00000000);
2017-08-18 19:22:04 +02:00
p.setColorFilter(filter);
canvas.drawBitmap(mutableBitmap, new Matrix(), p);
BitmapDrawable background = new BitmapDrawable(getResources(), mutableBitmap);
main_header_container.setBackground(background);
}
@Override
public void onLoadingFailed(java.lang.String imageUri, android.view.View view, FailReason failReason) {
LinearLayout main_header_container = (LinearLayout) findViewById(R.id.main_header_container);
main_header_container.setBackgroundResource(R.drawable.side_nav_bar);
}
});
}
}
2017-08-01 10:33:50 +02:00
//Redraws icon for locked accounts
final float scale = getResources().getDisplayMetrics().density;
if( account != null && account.isLocked()){
Drawable img = ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_action_lock_closed);
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-08-23 09:56:42 +02:00
final ActionBar actionBar = getSupportActionBar();
2017-07-31 19:29:14 +02:00
LayoutInflater mInflater = LayoutInflater.from(ShowAccountActivity.this);
if( actionBar != null && account != null){
2017-08-26 10:57:08 +02:00
@SuppressLint("InflateParams") View show_account_actionbar = mInflater.inflate(R.layout.showaccount_actionbar, null);
2017-07-31 19:29:14 +02:00
TextView actionbar_title = (TextView) show_account_actionbar.findViewById(R.id.show_account_title);
if( account.getAcct() != null)
2017-07-31 19:29:14 +02:00
actionbar_title.setText(account.getAcct());
actionBar.setCustomView(show_account_actionbar);
actionBar.setDisplayShowCustomEnabled(true);
pp_actionBar = (ImageView) actionBar.getCustomView().findViewById(R.id.pp_actionBar);
String url = account.getAvatar();
if( url.startsWith("/") ){
url = "https://" + Helper.getLiveInstance(getApplicationContext()) + account.getAvatar();
}
DisplayImageOptions optionsPP = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false)
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
imageLoader.loadImage(url, optionsPP, new SimpleImageLoadingListener(){
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
super.onLoadingComplete(imageUri, view, loadedImage);
BitmapDrawable ppDrawable = new BitmapDrawable(getResources(), Bitmap.createScaledBitmap(loadedImage, (int) Helper.convertDpToPixel(25, getApplicationContext()), (int) Helper.convertDpToPixel(25, getApplicationContext()), true));
if( pp_actionBar != null){
pp_actionBar.setImageDrawable(ppDrawable);
}
}
@Override
public void onLoadingFailed(java.lang.String imageUri, android.view.View view, FailReason failReason){
}});
2017-08-26 19:44:39 +02:00
if( Build.VERSION.SDK_INT >= 21) {
AppBarLayout appBar = (AppBarLayout) findViewById(R.id.appBar);
appBar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
if (verticalOffset > 10 ) {
pp_actionBar.setVisibility(View.GONE);
} else {
pp_actionBar.setVisibility(View.VISIBLE);
}
2017-08-23 09:56:42 +02:00
}
2017-08-26 19:44:39 +02:00
});
}
2017-07-31 19:29:14 +02:00
}else {
if( account != null && account.getAcct() != null)
setTitle(account.getAcct());
}
2017-05-05 16:36:04 +02:00
if( account != null){
account_dn.setText(Helper.shortnameToUnicode(account.getDisplay_name(), true));
account_un.setText(String.format("@%s", account.getUsername()));
2017-07-31 19:29:14 +02:00
SpannableString spannableString = Helper.clickableElementsDescription(ShowAccountActivity.this, account.getNote());
account_note.setText(spannableString, TextView.BufferType.SPANNABLE);
account_note.setMovementMethod(LinkMovementMethod.getInstance());
2017-09-15 19:15:23 +02:00
if (tabLayout.getTabAt(0) != null && tabLayout.getTabAt(1) != null && tabLayout.getTabAt(2) != null) {
2017-08-26 10:57:08 +02:00
//noinspection ConstantConditions
tabLayout.getTabAt(0).setText(getString(R.string.status_cnt, account.getStatuses_count()));
//noinspection ConstantConditions
tabLayout.getTabAt(1).setText(getString(R.string.following_cnt, account.getFollowing_count()));
//noinspection ConstantConditions
tabLayout.getTabAt(2).setText(getString(R.string.followers_cnt, account.getFollowers_count()));
2017-08-26 10:57:08 +02:00
}
2017-05-05 16:36:04 +02:00
imageLoader.displayImage(account.getAvatar(), account_pp, options);
}
}
@Override
public void onRetrieveFeedsAccount(List<Status> statuses) {
if( statuses != null) {
for(Status tmpStatus: statuses){
this.statuses.add(tmpStatus);
}
statusListAdapter.notifyDataSetChanged();
}
}
@Override
public void onRetrieveFeeds(APIResponse apiResponse, boolean refreshData) {
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-09-15 19:15:23 +02:00
for (Status pin : pins) {
this.statuses.add(pin);
}
//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
if( relationship.isFollowed_by()){
TextView account_followed_by = (TextView) findViewById(R.id.account_followed_by);
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-08-01 17:09:08 +02:00
}else if( relationship.isBlocking()){
2017-07-31 19:29:14 +02:00
account_follow.setImageResource(R.drawable.ic_unlock_alt);
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:
DisplayStatusFragment displayStatusFragment = new DisplayStatusFragment();
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.USER);
bundle.putString("targetedId", accountId);
2017-05-20 19:40:46 +02:00
bundle.putBoolean("hideHeader",true);
bundle.putBoolean("showMediaOnly",showMediaOnly);
bundle.putBoolean("showPinned",showPinned);
bundle.putString("hideHeaderValue",String.valueOf(instanceValue));
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);
2017-05-20 19:40:46 +02:00
bundle.putBoolean("hideHeader",true);
bundle.putString("hideHeaderValue",String.valueOf(instanceValue));
2017-05-05 16:36:04 +02:00
displayAccountsFragment.setArguments(bundle);
return displayAccountsFragment;
case 2:
displayAccountsFragment = new DisplayAccountsFragment();
bundle.putSerializable("type", RetrieveAccountsAsyncTask.Type.FOLLOWERS);
bundle.putString("targetedId", accountId);
2017-05-20 19:40:46 +02:00
bundle.putBoolean("hideHeader",true);
bundle.putString("hideHeaderValue",String.valueOf(instanceValue));
2017-05-05 16:36:04 +02:00
displayAccountsFragment.setArguments(bundle);
return displayAccountsFragment;
}
return null;
}
@Override
public int getCount() {
return NUM_PAGES;
}
}
}