Prettify profiles, add floating follow/unfollow button to them

This commit is contained in:
Eugen Rochko 2017-03-06 20:48:31 +01:00
parent a4ac24dea6
commit 7a752be83f
9 changed files with 171 additions and 73 deletions

View file

@ -30,5 +30,7 @@ dependencies {
compile 'com.android.support:support-v13:25.1.0'
compile 'com.android.volley:volley:1.0.0'
compile 'com.android.support:design:25.1.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.pkmmte.view:circularimageview:1.1'
testCompile 'junit:junit:4.12'
}

View file

@ -19,9 +19,13 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.icu.text.NumberFormat;
import android.media.Image;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
@ -31,6 +35,7 @@ import android.text.method.LinkMovementMethod;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.android.volley.AuthFailureError;
@ -41,6 +46,8 @@ import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.JsonArrayRequest;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.NetworkImageView;
import com.pkmmte.view.CircularImageView;
import com.squareup.picasso.Picasso;
import org.json.JSONArray;
import org.json.JSONException;
@ -78,11 +85,21 @@ public class AccountActivity extends BaseActivity {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
NetworkImageView avatar = (NetworkImageView) findViewById(R.id.account_avatar);
NetworkImageView header = (NetworkImageView) findViewById(R.id.account_header);
avatar.setDefaultImageResId(R.drawable.avatar_default);
avatar.setErrorImageResId(R.drawable.avatar_error);
header.setDefaultImageResId(R.drawable.account_header_default);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setTitle(null);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
}
FloatingActionButton floatingBtn = (FloatingActionButton) findViewById(R.id.floating_btn);
floatingBtn.hide();
CircularImageView avatar = (CircularImageView) findViewById(R.id.account_avatar);
ImageView header = (ImageView) findViewById(R.id.account_header);
avatar.setImageResource(R.drawable.avatar_default);
header.setImageResource(R.drawable.account_header_default);
obtainAccount();
if (!accountId.equals(loggedInAccountId)) {
@ -165,39 +182,43 @@ public class AccountActivity extends BaseActivity {
TextView username = (TextView) findViewById(R.id.account_username);
TextView displayName = (TextView) findViewById(R.id.account_display_name);
TextView note = (TextView) findViewById(R.id.account_note);
NetworkImageView avatar = (NetworkImageView) findViewById(R.id.account_avatar);
NetworkImageView header = (NetworkImageView) findViewById(R.id.account_header);
CircularImageView avatar = (CircularImageView) findViewById(R.id.account_avatar);
ImageView header = (ImageView) findViewById(R.id.account_header);
String usernameFormatted = String.format(
getString(R.string.status_username_format), account.username);
username.setText(usernameFormatted);
displayName.setText(account.displayName);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setTitle(account.displayName);
}
note.setText(account.note);
note.setLinksClickable(true);
note.setMovementMethod(LinkMovementMethod.getInstance());
ImageLoader imageLoader = VolleySingleton.getInstance(this).getImageLoader();
if (!account.avatar.isEmpty()) {
avatar.setImageUrl(account.avatar, imageLoader);
Picasso.with(this)
.load(account.avatar)
.placeholder(R.drawable.avatar_default)
.error(R.drawable.avatar_error)
.into(avatar);
}
if (!account.header.isEmpty()) {
header.setImageUrl(account.header, imageLoader);
Picasso.with(this)
.load(account.header)
.placeholder(R.drawable.account_header_default)
.into(header);
}
openInWebUrl = account.url;
java.text.NumberFormat nf = java.text.NumberFormat.getInstance();
// Add counts to the tabs in the TabLayout.
String[] counts = {
account.statusesCount,
account.followingCount,
account.followersCount,
nf.format(Integer.parseInt(account.statusesCount)),
nf.format(Integer.parseInt(account.followingCount)),
nf.format(Integer.parseInt(account.followersCount)),
};
for (int i = 0; i < tabLayout.getTabCount(); i++) {
TabLayout.Tab tab = tabLayout.getTabAt(i);
if (tab != null) {
@ -261,9 +282,37 @@ public class AccountActivity extends BaseActivity {
private void onObtainRelationshipsSuccess(boolean following, boolean blocking) {
this.following = following;
this.blocking = blocking;
if (!following || !blocking) {
invalidateOptionsMenu();
}
updateButtons();
}
private void updateButtons() {
invalidateOptionsMenu();
FloatingActionButton floatingBtn = (FloatingActionButton) findViewById(R.id.floating_btn);
if(!isSelf && !blocking) {
floatingBtn.show();
if (!following) {
floatingBtn.setImageResource(R.drawable.ic_person_add_24dp);
} else {
floatingBtn.setImageResource(R.drawable.ic_person_outline_24dp);
}
floatingBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
follow(accountId);
}
});
} else if(!isSelf && blocking) {
// TODO: floating button becomes unblock
}
}
private void onObtainRelationshipsFailure(Exception exception) {
@ -337,7 +386,7 @@ public class AccountActivity extends BaseActivity {
return;
}
following = followingValue;
invalidateOptionsMenu();
updateButtons();
}
},
new Response.ErrorListener() {
@ -385,7 +434,7 @@ public class AccountActivity extends BaseActivity {
return;
}
blocking = blockingValue;
invalidateOptionsMenu();
updateButtons();
}
},
new Response.ErrorListener() {
@ -417,10 +466,8 @@ public class AccountActivity extends BaseActivity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_back: {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
case android.R.id.home: {
onBackPressed();
return true;
}
case R.id.action_open_in_web: {

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:angle="90"
android:startColor="#FF000000"
android:endColor="#00000000"
android:type="linear" />
</shape>
</item>
</selector>

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@color/toolbar_icon_dark"
android:pathData="M15,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM6,10L6,7L4,7v3L1,10v2h3v3h2v-3h3v-2L6,10zM15,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z"/>
</vector>

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@color/toolbar_icon_dark"
android:pathData="M12,5.9c1.16,0 2.1,0.94 2.1,2.1s-0.94,2.1 -2.1,2.1S9.9,9.16 9.9,8s0.94,-2.1 2.1,-2.1m0,9c2.97,0 6.1,1.46 6.1,2.1v1.1L5.9,18.1L5.9,17c0,-0.64 3.13,-2.1 6.1,-2.1M12,4C9.79,4 8,5.79 8,8s1.79,4 4,4 4,-1.79 4,-4 -1.79,-4 -4,-4zM12,13c-2.67,0 -8,1.34 -8,4v3h16v-3c0,-2.66 -5.33,-4 -8,-4z"/>
</vector>

View file

@ -10,46 +10,60 @@
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:theme="@style/AppTheme"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/toolbar_background_color"
android:fitsSystemWindows="true"
app:titleEnabled="false">
<LinearLayout
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="?attr/actionBarSize"
android:background="?attr/account_header_background_color">
<com.android.volley.toolbox.NetworkImageView
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:id="@+id/account_header"
android:scaleType="fitCenter"
android:scaleType="centerCrop"
app:layout_collapseMode="pin"
android:fitsSystemWindows="true"
android:adjustViewBounds="true" />
<LinearLayout
android:orientation="vertical"
android:paddingTop="?attr/actionBarSize"
android:background="@drawable/account_header_gradient"
android:layout_width="match_parent"
app:layout_collapseMode="parallax"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:layout_height="wrap_content">
<com.android.volley.toolbox.NetworkImageView
<com.pkmmte.view.CircularImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:id="@+id/account_avatar"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="8dp" />
android:layout_marginRight="10dp"
android:id="@+id/account_avatar" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_toRightOf="@id/account_avatar"
android:layout_centerVertical="true">
android:layout_centerVertical="true"
android:layout_toRightOf="@id/account_avatar">
<TextView
android:layout_width="wrap_content"
@ -71,16 +85,18 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/account_note"
android:padding="8dp" />
android:padding="16dp"
android:paddingTop="10dp"/>
</LinearLayout>
</FrameLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/toolbar_background_color"
android:background="@android:color/transparent"
android:layout_gravity="top"
android:layout_alignParentTop="true"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
@ -119,4 +135,12 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/floating_btn"
android:layout_width="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_person_add_24dp"/>
</android.support.design.widget.CoordinatorLayout>

View file

@ -2,11 +2,6 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_back"
android:title="@string/action_back"
android:icon="@drawable/ic_back"
app:showAsAction="always" />
<item android:id="@+id/action_open_in_web"
android:title="@string/action_open_in_web"
app:showAsAction="never" />

View file

@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.android.tools.build:gradle:2.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

View file

@ -1,6 +1,6 @@
#Mon Dec 28 10:00:20 PST 2015
#Mon Mar 06 17:29:49 CET 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip