improvements with follow requests

This commit is contained in:
tom79 2017-06-07 13:58:21 +02:00
parent f2a20c3ed3
commit ce2133f091
7 changed files with 63 additions and 18 deletions

View File

@ -141,6 +141,13 @@ public class MainActivity extends AppCompatActivity
Account account = new AccountDAO(getApplicationContext(), db).getAccountByToken(prefKeyOauthTokenT);
updateHeaderAccountInfo(MainActivity.this, account, headerLayout, imageLoader, options);
//Locked account can see follow request
if (account.isLocked()) {
navigationView.getMenu().findItem(R.id.nav_follow_request).setVisible(true);
} else {
navigationView.getMenu().findItem(R.id.nav_follow_request).setVisible(false);
}
LinearLayout owner_container = (LinearLayout) headerLayout.findViewById(R.id.owner_container);
owner_container.setOnClickListener(new View.OnClickListener() {
@Override

View File

@ -99,7 +99,7 @@ public class SearchResultActivity extends AppCompatActivity implements OnRetriev
Toast.makeText(getApplicationContext(), error.getError(),Toast.LENGTH_LONG).show();
return;
}
if( results == null){
if( results == null || (results.getAccounts().size() == 0 && results.getStatuses().size() == 0 && results.getHashtags().size() == 0)){
RelativeLayout no_result = (RelativeLayout) findViewById(R.id.no_result);
no_result.setVisibility(View.VISIBLE);
return;

View File

@ -19,6 +19,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.graphics.PorterDuff;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
@ -27,6 +28,7 @@ import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
@ -224,7 +226,9 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
account_follow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if( doAction == action.FOLLOW){
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){
@ -323,11 +327,13 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
Toast.makeText(getApplicationContext(), error.getError(),Toast.LENGTH_LONG).show();
return;
}
account_follow.setEnabled(true);
if( relationship.isBlocking()){
account_follow.setText(R.string.action_unblock);
doAction = action.UNBLOCK;
}else if( relationship.isRequested()){
account_follow.setText(R.string.request_sent);
account_follow.getBackground().setColorFilter(ContextCompat.getColor(this, R.color.colorPrimary), PorterDuff.Mode.MULTIPLY);
doAction = action.NOTHING;
}else if( relationship.isFollowing()){
account_follow.setText(R.string.action_unfollow);
@ -336,13 +342,12 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
account_follow.setText(R.string.action_follow);
doAction = action.FOLLOW;
}else{
account_follow.setText(R.string.action_no_action);
account_follow.getBackground().setColorFilter(ContextCompat.getColor(this, R.color.red_1), PorterDuff.Mode.MULTIPLY);
doAction = action.NOTHING;
}
if( doAction == action.NOTHING){
account_follow.setEnabled(false);
}else {
account_follow.setEnabled(true);
}
//The authenticated account is followed by the account
if( relationship.isFollowed_by()){

View File

@ -16,8 +16,12 @@ package fr.gouv.etalab.mastodon.drawers;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.PorterDuff;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -35,6 +39,7 @@ import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
import java.util.ArrayList;
import java.util.List;
import fr.gouv.etalab.mastodon.activities.ShowAccountActivity;
import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask;
import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.Entities.Account;
@ -101,10 +106,24 @@ public class AccountsFollowRequestAdapter extends BaseAdapter implements OnPostA
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.btn_authorize.getBackground().setColorFilter(ContextCompat.getColor(context, R.color.green_1), PorterDuff.Mode.MULTIPLY);
holder.btn_reject.getBackground().setColorFilter(ContextCompat.getColor(context, R.color.red_1), PorterDuff.Mode.MULTIPLY);
holder.account_un.setText(String.format("@%s", account.getUsername()));
//Profile picture
imageLoader.displayImage(account.getAvatar(), holder.account_pp, options);
holder.account_pp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openAccountDetails(account.getId());
}
});
holder.account_un.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openAccountDetails(account.getId());
}
});
holder.btn_authorize.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -120,6 +139,14 @@ public class AccountsFollowRequestAdapter extends BaseAdapter implements OnPostA
return convertView;
}
private void openAccountDetails(String userId){
Intent intent = new Intent(context, ShowAccountActivity.class);
Bundle b = new Bundle();
b.putString("accountId", userId);
intent.putExtras(b);
context.startActivity(intent);
}
@Override
public void onPostAction(int statusCode, API.StatusAction statusAction, String userId, Error error) {
if( error != null){

View File

@ -25,15 +25,17 @@
<ImageView
android:layout_gravity="center"
android:id="@+id/account_pp"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_width="60dp"
android:layout_height="60dp"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/account_un"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:padding="5dp"
android:maxLines="1"
android:layout_gravity="center_vertical"
android:gravity="center"
android:textSize="16sp"
android:layout_gravity="center"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
@ -41,7 +43,7 @@
android:layout_width="wrap_content"
android:gravity="end"
android:layout_height="wrap_content"
android:orientation="horizontal">
android:orientation="vertical">
<Button
android:id="@+id/btn_authorize"
android:text="@string/authorize"
@ -49,8 +51,9 @@
android:layout_marginLeft="5dp"
android:layout_gravity="end"
android:gravity="center"
style="@style/Base.Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:textColor="@color/white"
style="@style/Base.Widget.AppCompat.Button.Small"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/btn_reject"
@ -59,9 +62,9 @@
android:text="@string/reject"
android:layout_gravity="end"
android:gravity="center"
android:textColor="@color/white"
style="@style/Base.Widget.AppCompat.Button.Small"
android:textColor="@color/red_1"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>

View File

@ -21,5 +21,6 @@
<color name="background_image">#282c37</color>
<color name="green_1">#009688</color>
<color name="red_1">#F44336</color>
</resources>

View File

@ -203,6 +203,7 @@
<string name="toast_error_loading_account">Une erreur s\'est produite en chargeant le compte !</string>
<string name="toast_error_login">Impossible de vous connecter !</string>
<string name="toast_update_credential_ok">Les données du profil ont été sauvegardées !</string>
<string name="nothing_to_do">Aucune action ne peut être réalisée</string>
<!-- Settings -->
<string name="settings_title_optimisation">Optimisation du chargement</string>
<string name="set_toots_page">Nombre de pouets par chargement</string>
@ -241,6 +242,7 @@
<string name="action_block">Bloquer</string>
<string name="action_unblock">Débloquer</string>
<string name="action_mute">Masquer</string>
<string name="action_no_action">Aucune action</string>
<string name="action_unmute">Afficher</string>
<string name="request_sent">Demande envoyée</string>
<string name="followed_by">Vous suit</string>