added function to remove user from lists, bug fixes
This commit is contained in:
parent
2b616bfed6
commit
077463822d
4
.idea/assetWizardSettings.xml
generated
4
.idea/assetWizardSettings.xml
generated
@ -20,8 +20,8 @@
|
||||
<map>
|
||||
<entry key="assetSourceType" value="FILE" />
|
||||
<entry key="autoMirrored" value="true" />
|
||||
<entry key="outputName" value="list_subscribe" />
|
||||
<entry key="sourceFile" value="$USER_HOME$/Schreibtisch/2.svg" />
|
||||
<entry key="outputName" value="list_subscriber" />
|
||||
<entry key="sourceFile" value="$USER_HOME$/Schreibtisch/4.svg" />
|
||||
</map>
|
||||
</option>
|
||||
</PersistentState>
|
||||
|
@ -88,7 +88,7 @@ public class ListDetail extends AppCompatActivity implements OnTabSelectedListen
|
||||
private String title = "";
|
||||
private String description = "";
|
||||
private boolean isPublic = false;
|
||||
private boolean belongsToCurrentUser = false;
|
||||
private boolean currentUserOwnsList = false;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle b) {
|
||||
@ -115,8 +115,8 @@ public class ListDetail extends AppCompatActivity implements OnTabSelectedListen
|
||||
title = param.getString(KEY_LISTDETAIL_TITLE, "");
|
||||
description = param.getString(KEY_LISTDETAIL_DESCR, "");
|
||||
isPublic = param.getBoolean(KEY_LISTDETAIL_VISIB, false);
|
||||
belongsToCurrentUser = param.getBoolean(KEY_CURRENT_USER_OWNS, false);
|
||||
adapter.setupListContentPage(listId);
|
||||
currentUserOwnsList = param.getBoolean(KEY_CURRENT_USER_OWNS, false);
|
||||
adapter.setupListContentPage(listId, currentUserOwnsList);
|
||||
Tab tweetTab = tablayout.getTabAt(0);
|
||||
Tab userTab = tablayout.getTabAt(1);
|
||||
if (tweetTab != null && userTab != null) {
|
||||
@ -137,7 +137,7 @@ public class ListDetail extends AppCompatActivity implements OnTabSelectedListen
|
||||
MenuItem search = m.findItem(R.id.menu_list_add_user);
|
||||
MenuItem editList = m.findItem(R.id.menu_list_edit);
|
||||
SearchView searchUser = (SearchView) search.getActionView();
|
||||
if (belongsToCurrentUser) {
|
||||
if (currentUserOwnsList) {
|
||||
searchUser.setQueryHint(getString(R.string.menu_add_user));
|
||||
searchUser.setOnQueryTextListener(this);
|
||||
} else {
|
||||
@ -230,7 +230,7 @@ public class ListDetail extends AppCompatActivity implements OnTabSelectedListen
|
||||
|
||||
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
public void onSuccess(String[] names) {
|
||||
adapter.notifySettingsChanged();
|
||||
Toast.makeText(this, R.string.info_user_added_to_list, Toast.LENGTH_SHORT).show();
|
||||
invalidateOptionsMenu();
|
||||
|
@ -28,6 +28,7 @@ import static org.nuclearfog.twidda.fragment.TweetFragment.TWEET_FRAG_LIST;
|
||||
import static org.nuclearfog.twidda.fragment.TweetFragment.TWEET_FRAG_MENT;
|
||||
import static org.nuclearfog.twidda.fragment.TweetFragment.TWEET_FRAG_SEARCH;
|
||||
import static org.nuclearfog.twidda.fragment.TweetFragment.TWEET_FRAG_TWEETS;
|
||||
import static org.nuclearfog.twidda.fragment.UserFragment.KEY_FRAG_DEL_USER;
|
||||
import static org.nuclearfog.twidda.fragment.UserFragment.KEY_FRAG_USER_ID;
|
||||
import static org.nuclearfog.twidda.fragment.UserFragment.KEY_FRAG_USER_MODE;
|
||||
import static org.nuclearfog.twidda.fragment.UserFragment.KEY_FRAG_USER_SEARCH;
|
||||
@ -292,14 +293,16 @@ public class FragmentAdapter extends FragmentStatePagerAdapter {
|
||||
* setup adapter for a page of tweets and users in an user list
|
||||
*
|
||||
* @param listId ID of an user list
|
||||
* @param ownerOfList true if current user owns the list
|
||||
*/
|
||||
public void setupListContentPage(long listId) {
|
||||
public void setupListContentPage(long listId, boolean ownerOfList) {
|
||||
Bundle tweetParam = new Bundle();
|
||||
Bundle userParam = new Bundle();
|
||||
tweetParam.putLong(KEY_FRAG_TWEET_ID, listId);
|
||||
userParam.putLong(KEY_FRAG_USER_ID, listId);
|
||||
tweetParam.putInt(KEY_FRAG_TWEET_MODE, TWEET_FRAG_LIST);
|
||||
userParam.putInt(KEY_FRAG_USER_MODE, USER_FRAG_LISTS);
|
||||
userParam.putBoolean(KEY_FRAG_DEL_USER, ownerOfList);
|
||||
userParam.putLong(KEY_FRAG_USER_ID, listId);
|
||||
fragments = new Fragment[2];
|
||||
fragments[0] = new TweetFragment();
|
||||
fragments[1] = new UserFragment();
|
||||
|
@ -25,7 +25,6 @@ import org.nuclearfog.twidda.database.GlobalSettings;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.INVISIBLE;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;
|
||||
@ -136,22 +135,18 @@ public class ListAdapter extends Adapter<ViewHolder> {
|
||||
}
|
||||
}
|
||||
});
|
||||
vh.followList.setOnClickListener(new OnClickListener() {
|
||||
vh.action.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int position = vh.getLayoutPosition();
|
||||
if (position != NO_POSITION) {
|
||||
listener.onClick(data.get(position), ListClickListener.Action.FOLLOW);
|
||||
TwitterList list = data.get(position);
|
||||
if (list.isListOwner()) {
|
||||
listener.onClick(list, ListClickListener.Action.DELETE);
|
||||
} else {
|
||||
listener.onClick(list, ListClickListener.Action.FOLLOW);
|
||||
}
|
||||
}
|
||||
});
|
||||
vh.deleteList.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int position = vh.getLayoutPosition();
|
||||
if (position != NO_POSITION) {
|
||||
listener.onClick(data.get(position), ListClickListener.Action.DELETE);
|
||||
}
|
||||
}
|
||||
});
|
||||
vh.subscriberCount.setOnClickListener(new OnClickListener() {
|
||||
@ -214,17 +209,14 @@ public class ListAdapter extends Adapter<ViewHolder> {
|
||||
}
|
||||
Picasso.get().load(pbLink).error(R.drawable.no_image).into(vh.pb_image);
|
||||
}
|
||||
if (item.isFollowing()) {
|
||||
vh.followList.setText(R.string.user_unfollow);
|
||||
} else {
|
||||
vh.followList.setText(R.string.user_follow);
|
||||
}
|
||||
if (item.isListOwner()) {
|
||||
vh.followList.setVisibility(VISIBLE);
|
||||
vh.deleteList.setVisibility(GONE);
|
||||
vh.action.setText(R.string.delete_list);
|
||||
} else {
|
||||
vh.followList.setVisibility(GONE);
|
||||
vh.deleteList.setVisibility(VISIBLE);
|
||||
if (item.isFollowing()) {
|
||||
vh.action.setText(R.string.user_unfollow);
|
||||
} else {
|
||||
vh.action.setText(R.string.user_follow);
|
||||
}
|
||||
}
|
||||
if (item.isPrivate()) {
|
||||
vh.title.setCompoundDrawablesWithIntrinsicBounds(R.drawable.lock, 0, 0, 0);
|
||||
@ -257,15 +249,14 @@ public class ListAdapter extends Adapter<ViewHolder> {
|
||||
|
||||
static class ListHolder extends ViewHolder {
|
||||
final ImageView pb_image;
|
||||
final Button followList, deleteList;
|
||||
final Button action;
|
||||
final TextView title, ownername, description, createdAt;
|
||||
final TextView memberCount, subscriberCount;
|
||||
|
||||
ListHolder(View v) {
|
||||
super(v);
|
||||
pb_image = v.findViewById(R.id.list_owner_profile);
|
||||
followList = v.findViewById(R.id.list_follow);
|
||||
deleteList = v.findViewById(R.id.list_delete);
|
||||
action = v.findViewById(R.id.list_action);
|
||||
title = v.findViewById(R.id.list_title);
|
||||
ownername = v.findViewById(R.id.list_ownername);
|
||||
description = v.findViewById(R.id.list_description);
|
||||
|
@ -5,6 +5,7 @@ import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
@ -23,6 +24,7 @@ import org.nuclearfog.twidda.backend.items.TwitterUser;
|
||||
import org.nuclearfog.twidda.backend.utils.FontTool;
|
||||
import org.nuclearfog.twidda.database.GlobalSettings;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.INVISIBLE;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static androidx.recyclerview.widget.RecyclerView.NO_ID;
|
||||
@ -44,6 +46,7 @@ public class UserAdapter extends Adapter<ViewHolder> {
|
||||
|
||||
private final TwitterUserList data;
|
||||
private int loadingIndex;
|
||||
private boolean userRemovable = false;
|
||||
|
||||
|
||||
public UserAdapter(UserClickListener itemClickListener, GlobalSettings settings) {
|
||||
@ -77,6 +80,18 @@ public class UserAdapter extends Adapter<ViewHolder> {
|
||||
}
|
||||
|
||||
|
||||
@MainThread
|
||||
public void removeUser(String username) {
|
||||
for (int pos = 0; pos < data.size(); pos++) {
|
||||
if (data.get(pos).getScreenname().equals(username)) {
|
||||
data.remove(pos);
|
||||
notifyItemRemoved(pos);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return data.size();
|
||||
@ -116,6 +131,20 @@ public class UserAdapter extends Adapter<ViewHolder> {
|
||||
}
|
||||
}
|
||||
});
|
||||
if (userRemovable) {
|
||||
vh.delete.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int position = vh.getLayoutPosition();
|
||||
TwitterUser user = data.get(position);
|
||||
if (position != NO_POSITION && user != null) {
|
||||
itemClickListener.onDelete(user.getScreenname());
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
vh.delete.setVisibility(GONE);
|
||||
}
|
||||
return vh;
|
||||
} else {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_placeholder, parent, false);
|
||||
@ -180,7 +209,21 @@ public class UserAdapter extends Adapter<ViewHolder> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* enables delete button for an user item
|
||||
*
|
||||
* @param enable true to enable delete button
|
||||
*/
|
||||
public void enableDeleteButton(boolean enable) {
|
||||
userRemovable = enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the TextView icons
|
||||
*
|
||||
* @param tv TextView to add an icon
|
||||
* @param icon icon drawable
|
||||
*/
|
||||
private void setIcon(TextView tv, @DrawableRes int icon) {
|
||||
tv.setCompoundDrawablesWithIntrinsicBounds(icon, 0, 0, 0);
|
||||
}
|
||||
@ -189,12 +232,14 @@ public class UserAdapter extends Adapter<ViewHolder> {
|
||||
static class ItemHolder extends ViewHolder {
|
||||
final ImageView profileImg;
|
||||
final TextView username, screenname;
|
||||
final ImageButton delete;
|
||||
|
||||
ItemHolder(View v) {
|
||||
super(v);
|
||||
username = v.findViewById(R.id.username_detail);
|
||||
screenname = v.findViewById(R.id.screenname_detail);
|
||||
profileImg = v.findViewById(R.id.user_profileimg);
|
||||
delete = v.findViewById(R.id.useritem_del_user);
|
||||
}
|
||||
}
|
||||
|
||||
@ -229,5 +274,12 @@ public class UserAdapter extends Adapter<ViewHolder> {
|
||||
* @param cursor next cursor of the list
|
||||
*/
|
||||
void onFooterClick(long cursor);
|
||||
|
||||
/**
|
||||
* remove user from a list
|
||||
*
|
||||
* @param name screen name of the user
|
||||
*/
|
||||
void onDelete(String name);
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@ import java.lang.ref.WeakReference;
|
||||
* Backend class to manage users on user lists
|
||||
* Twitter users can be added and removed
|
||||
*/
|
||||
public class UserListManager extends AsyncTask<String, Void, Boolean> {
|
||||
public class UserListManager extends AsyncTask<String, Void, String[]> {
|
||||
|
||||
public enum Action {
|
||||
ADD_USER,
|
||||
@ -40,7 +40,7 @@ public class UserListManager extends AsyncTask<String, Void, Boolean> {
|
||||
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(String... strings) {
|
||||
protected String[] doInBackground(String... strings) {
|
||||
try {
|
||||
switch (mode) {
|
||||
case ADD_USER:
|
||||
@ -54,17 +54,17 @@ public class UserListManager extends AsyncTask<String, Void, Boolean> {
|
||||
|
||||
} catch (EngineException err) {
|
||||
this.err = err;
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
return true;
|
||||
return strings;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Boolean success) {
|
||||
protected void onPostExecute(String[] names) {
|
||||
if (callback.get() != null) {
|
||||
if (success) {
|
||||
callback.get().onSuccess();
|
||||
if (names != null) {
|
||||
callback.get().onSuccess(names);
|
||||
} else {
|
||||
callback.get().onFailure(err);
|
||||
}
|
||||
@ -78,8 +78,10 @@ public class UserListManager extends AsyncTask<String, Void, Boolean> {
|
||||
|
||||
/**
|
||||
* Called when AsyncTask finished successfully
|
||||
*
|
||||
* @param names the names of the users added or removed from list
|
||||
*/
|
||||
void onSuccess();
|
||||
void onSuccess(String[] names);
|
||||
|
||||
/**
|
||||
* called when an error occurs
|
||||
|
@ -30,7 +30,7 @@ public class TwitterList {
|
||||
isPrivate = !list.isPublic();
|
||||
memberCount = list.getMemberCount();
|
||||
subscriberCnt = list.getSubscriberCount();
|
||||
isOwner = homeId != owner.getId();
|
||||
isOwner = homeId == owner.getId();
|
||||
this.title = title != null ? title : "";
|
||||
this.description = description != null ? description : "";
|
||||
this.isFollowing = isFollowing;
|
||||
|
@ -8,6 +8,7 @@ import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@ -83,7 +84,6 @@ public class ListFragment extends Fragment implements OnRefreshListener, ListCli
|
||||
public static final int LIST_USER_SUBSCR_TO = 2;
|
||||
|
||||
private TwitterListLoader listTask;
|
||||
private GlobalSettings settings;
|
||||
|
||||
private SwipeRefreshLayout reloadLayout;
|
||||
private RecyclerView list;
|
||||
@ -97,7 +97,7 @@ public class ListFragment extends Fragment implements OnRefreshListener, ListCli
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup parent, @Nullable Bundle param) {
|
||||
Context context = inflater.getContext();
|
||||
|
||||
settings = GlobalSettings.getInstance(context);
|
||||
GlobalSettings settings = GlobalSettings.getInstance(context);
|
||||
adapter = new ListAdapter(this, settings);
|
||||
|
||||
list = new RecyclerView(inflater.getContext());
|
||||
@ -163,28 +163,27 @@ public class ListFragment extends Fragment implements OnRefreshListener, ListCli
|
||||
followDialog.show();
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(requireContext(), R.string.info_following_list, Toast.LENGTH_SHORT).show();
|
||||
listTask = new TwitterListLoader(this, FOLLOW, listItem.getId(), "");
|
||||
listTask.execute(listItem.getId());
|
||||
}
|
||||
break;
|
||||
|
||||
case SUBSCRIBER:
|
||||
Intent following = new Intent(getContext(), UserDetail.class);
|
||||
following.putExtra(KEY_USERDETAIL_ID, listItem.getId());
|
||||
following.putExtra(KEY_USERDETAIL_MODE, USERLIST_SUBSCRBR);
|
||||
startActivity(following);
|
||||
Intent subscriberIntent = new Intent(getContext(), UserDetail.class);
|
||||
subscriberIntent.putExtra(KEY_USERDETAIL_ID, listItem.getId());
|
||||
subscriberIntent.putExtra(KEY_USERDETAIL_MODE, USERLIST_SUBSCRBR);
|
||||
startActivity(subscriberIntent);
|
||||
break;
|
||||
|
||||
case MEMBER:
|
||||
Intent detailedList = new Intent(getContext(), ListDetail.class);
|
||||
Bundle param = getArguments();
|
||||
if (param != null && param.getLong(KEY_FRAG_LIST_OWNER_ID) == settings.getUserId())
|
||||
detailedList.putExtra(KEY_CURRENT_USER_OWNS, true);
|
||||
detailedList.putExtra(KEY_LISTDETAIL_ID, listItem.getId());
|
||||
detailedList.putExtra(KEY_LISTDETAIL_TITLE, listItem.getTitle());
|
||||
detailedList.putExtra(KEY_LISTDETAIL_DESCR, listItem.getDescription());
|
||||
detailedList.putExtra(KEY_LISTDETAIL_VISIB, !listItem.isPrivate());
|
||||
startActivity(detailedList);
|
||||
Intent listIntent = new Intent(getContext(), ListDetail.class);
|
||||
listIntent.putExtra(KEY_CURRENT_USER_OWNS, listItem.isListOwner());
|
||||
listIntent.putExtra(KEY_LISTDETAIL_ID, listItem.getId());
|
||||
listIntent.putExtra(KEY_LISTDETAIL_TITLE, listItem.getTitle());
|
||||
listIntent.putExtra(KEY_LISTDETAIL_DESCR, listItem.getDescription());
|
||||
listIntent.putExtra(KEY_LISTDETAIL_VISIB, !listItem.isPrivate());
|
||||
startActivity(listIntent);
|
||||
break;
|
||||
|
||||
case DELETE:
|
||||
@ -238,6 +237,9 @@ public class ListFragment extends Fragment implements OnRefreshListener, ListCli
|
||||
|
||||
@Override
|
||||
public void onTabChange() {
|
||||
if (list != null) {
|
||||
list.smoothScrollToPosition(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,46 +1,71 @@
|
||||
package org.nuclearfog.twidda.fragment;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout.OnRefreshListener;
|
||||
|
||||
import org.nuclearfog.twidda.R;
|
||||
import org.nuclearfog.twidda.activity.UserProfile;
|
||||
import org.nuclearfog.twidda.adapter.FragmentAdapter.FragmentChangeObserver;
|
||||
import org.nuclearfog.twidda.adapter.UserAdapter;
|
||||
import org.nuclearfog.twidda.adapter.UserAdapter.UserClickListener;
|
||||
import org.nuclearfog.twidda.backend.UserListLoader;
|
||||
import org.nuclearfog.twidda.backend.UserListLoader.Action;
|
||||
import org.nuclearfog.twidda.backend.UserListManager;
|
||||
import org.nuclearfog.twidda.backend.engine.EngineException;
|
||||
import org.nuclearfog.twidda.backend.holder.TwitterUserList;
|
||||
import org.nuclearfog.twidda.backend.items.TwitterUser;
|
||||
import org.nuclearfog.twidda.backend.utils.ErrorHandler;
|
||||
import org.nuclearfog.twidda.database.GlobalSettings;
|
||||
|
||||
import static android.content.DialogInterface.BUTTON_POSITIVE;
|
||||
import static android.os.AsyncTask.Status.FINISHED;
|
||||
import static android.os.AsyncTask.Status.RUNNING;
|
||||
import static org.nuclearfog.twidda.activity.UserProfile.KEY_PROFILE_ID;
|
||||
import static org.nuclearfog.twidda.backend.UserListLoader.NO_CURSOR;
|
||||
import static org.nuclearfog.twidda.backend.UserListManager.Action.DEL_USER;
|
||||
|
||||
/**
|
||||
* Fragment class for lists a list of users
|
||||
*/
|
||||
public class UserFragment extends Fragment implements OnRefreshListener, UserClickListener, FragmentChangeObserver {
|
||||
public class UserFragment extends Fragment implements OnRefreshListener, UserClickListener,
|
||||
FragmentChangeObserver, DialogInterface.OnClickListener, UserListManager.ListManagerCallback {
|
||||
|
||||
/**
|
||||
* key to set the type of user list to show
|
||||
*/
|
||||
public static final String KEY_FRAG_USER_MODE = "user_mode";
|
||||
|
||||
/**
|
||||
* key to define search string
|
||||
*/
|
||||
public static final String KEY_FRAG_USER_SEARCH = "user_search";
|
||||
|
||||
/**
|
||||
* key to define user, tweet or list ID
|
||||
*/
|
||||
public static final String KEY_FRAG_USER_ID = "user_id";
|
||||
|
||||
/**
|
||||
* key to enable function to remove users from list
|
||||
*/
|
||||
public static final String KEY_FRAG_DEL_USER = "user_en_del";
|
||||
|
||||
public static final int USER_FRAG_FOLLOWS = 1;
|
||||
public static final int USER_FRAG_FRIENDS = 2;
|
||||
public static final int USER_FRAG_RETWEET = 3;
|
||||
@ -49,13 +74,22 @@ public class UserFragment extends Fragment implements OnRefreshListener, UserCli
|
||||
public static final int USER_FRAG_SUBSCR = 6;
|
||||
public static final int USER_FRAG_LISTS = 7;
|
||||
|
||||
private SwipeRefreshLayout reload;
|
||||
private UserAdapter adapter;
|
||||
private UserListLoader userTask;
|
||||
private UserListManager listTask;
|
||||
|
||||
private SwipeRefreshLayout reload;
|
||||
private RecyclerView list;
|
||||
private Dialog deleteDialog;
|
||||
private UserAdapter adapter;
|
||||
|
||||
private String deleteUserName = "";
|
||||
private String search = "";
|
||||
private long id = 0;
|
||||
private int mode = 0;
|
||||
private boolean delUser = false;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup parent, @Nullable Bundle param) {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup parent, @Nullable Bundle b) {
|
||||
Context context = inflater.getContext();
|
||||
GlobalSettings settings = GlobalSettings.getInstance(context);
|
||||
|
||||
@ -65,6 +99,13 @@ public class UserFragment extends Fragment implements OnRefreshListener, UserCli
|
||||
list.setHasFixedSize(true);
|
||||
list.setAdapter(adapter);
|
||||
|
||||
Bundle param = getArguments();
|
||||
if (param != null) {
|
||||
mode = param.getInt(KEY_FRAG_USER_MODE, 0);
|
||||
id = param.getLong(KEY_FRAG_USER_ID, 0);
|
||||
search = param.getString(KEY_FRAG_USER_SEARCH, "");
|
||||
delUser = param.getBoolean(KEY_FRAG_DEL_USER, false);
|
||||
}
|
||||
reload = new SwipeRefreshLayout(context);
|
||||
reload.setProgressBackgroundColorSchemeColor(settings.getHighlightColor());
|
||||
reload.setOnRefreshListener(this);
|
||||
@ -115,6 +156,21 @@ public class UserFragment extends Fragment implements OnRefreshListener, UserCli
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDelete(String name) {
|
||||
deleteUserName = name;
|
||||
if (deleteDialog == null) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext(), R.style.ConfirmDialog);
|
||||
builder.setMessage(R.string.confirm_remove_user_from_list);
|
||||
builder.setPositiveButton(android.R.string.ok, this);
|
||||
builder.setNegativeButton(android.R.string.cancel, null);
|
||||
deleteDialog = builder.show();
|
||||
} else if (!deleteDialog.isShowing()) {
|
||||
deleteDialog.show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onTabChange() {
|
||||
if (list != null) {
|
||||
@ -131,6 +187,32 @@ public class UserFragment extends Fragment implements OnRefreshListener, UserCli
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (which == BUTTON_POSITIVE && dialog == deleteDialog) {
|
||||
if (listTask == null || listTask.getStatus() != RUNNING) {
|
||||
listTask = new UserListManager(id, DEL_USER, requireContext(), this);
|
||||
listTask.execute(deleteUserName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onSuccess(String[] names) {
|
||||
Toast.makeText(requireContext(), R.string.info_user_removed, Toast.LENGTH_SHORT).show();
|
||||
adapter.removeUser(names[0]);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onFailure(EngineException err) {
|
||||
if (err != null) {
|
||||
ErrorHandler.handleFailure(requireContext(), err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set List data
|
||||
*
|
||||
@ -182,11 +264,6 @@ public class UserFragment extends Fragment implements OnRefreshListener, UserCli
|
||||
* @param cursor cursor of the list or {@link UserListLoader#NO_CURSOR} if there is none
|
||||
*/
|
||||
private void load(long cursor) {
|
||||
Bundle param = getArguments();
|
||||
if (param != null) {
|
||||
int mode = param.getInt(KEY_FRAG_USER_MODE, 0);
|
||||
long id = param.getLong(KEY_FRAG_USER_ID, 0);
|
||||
String search = param.getString(KEY_FRAG_USER_SEARCH, "");
|
||||
Action action = Action.NONE;
|
||||
switch (mode) {
|
||||
case USER_FRAG_FOLLOWS:
|
||||
@ -217,11 +294,11 @@ public class UserFragment extends Fragment implements OnRefreshListener, UserCli
|
||||
action = Action.LIST;
|
||||
break;
|
||||
}
|
||||
adapter.enableDeleteButton(delUser);
|
||||
userTask = new UserListLoader(this, action, id, search);
|
||||
userTask.execute(cursor);
|
||||
if (cursor == NO_CURSOR) {
|
||||
setRefresh(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,22 +1,22 @@
|
||||
<vector android:autoMirrored="true"
|
||||
android:height="30dp"
|
||||
android:width="45dp"
|
||||
android:viewportHeight="1000"
|
||||
android:viewportWidth="1500"
|
||||
android:viewportWidth="1200"
|
||||
android:width="36dp"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<group>
|
||||
<clip-path android:pathData="M0,0h1500v1000h-1500z" />
|
||||
<clip-path android:pathData="M0,0h1200v1000h-1200z" />
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="evenOdd"
|
||||
android:pathData="M743,500L514,310 514,424 248,424 248,576 514,576 514,690 743,500 743,500ZM133,233L438,233 438,157 133,157C91,157 57,191 57,233L57,767C57,809 91,843 133,843L438,843 438,767 133,767 133,233 133,233Z"
|
||||
android:pathData="M614,450L413,283 413,383 179,383 179,517 413,517 413,617 614,450 614,450 614,450ZM78,216L346,216 346,149 78,149C41,149 12,179 12,216L12,684C12,721 41,751 78,751L346,751 346,684 78,684 78,216 78,216 78,216Z"
|
||||
android:strokeColor="#00000000"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="28.222" />
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="evenOdd"
|
||||
android:pathData="M1150,238C1197,238 1236,199 1236,152 1236,105 1197,66 1150,66 1103,66 1064,105 1064,152 1064,199 1103,238 1150,238L1150,238ZM1406,563C1390,487 1361,362 1319,310 1278,260 1195,258 1150,258L1150,258C1105,258 1022,260 981,310 939,362 910,487 894,563 885,605 943,620 959,578 981,515 999,462 1037,418 1058,543 983,759 979,881 979,904 998,924 1021,924 1040,924 1055,912 1061,896 1081,828 1150,639 1150,639L1150,639 1150,639C1150,639 1219,828 1239,896 1245,912 1260,924 1279,924 1302,924 1321,904 1321,881 1317,759 1242,543 1263,418 1301,462 1319,515 1341,578 1357,620 1415,605 1406,563L1406,563Z"
|
||||
android:pathData="M971,220C1012,220 1047,186 1047,145 1047,104 1012,69 971,69 930,69 896,104 896,145 896,186 930,220 971,220L971,220 971,220ZM1196,505C1182,439 1156,329 1119,283 1084,240 1011,238 971,238L971,238C932,238 859,240 823,283 786,329 760,439 746,505 739,542 789,555 803,518 823,463 839,417 872,378 890,488 825,677 821,784 821,804 838,822 858,822 875,822 888,811 893,797 911,738 971,572 971,572L971,572 971,572C971,572 1032,738 1049,797 1055,811 1068,822 1084,822 1105,822 1121,804 1121,784 1118,677 1052,488 1070,378 1104,417 1119,463 1139,518 1153,555 1204,542 1196,505L1196,505 1196,505Z"
|
||||
android:strokeColor="#00000000"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="28.222" />
|
||||
|
@ -1,22 +1,22 @@
|
||||
<vector android:autoMirrored="true"
|
||||
android:height="30dp"
|
||||
android:width="45dp"
|
||||
android:viewportHeight="1000"
|
||||
android:viewportWidth="1500"
|
||||
android:viewportWidth="1200"
|
||||
android:width="36dp"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<group>
|
||||
<clip-path android:pathData="M0,0h1500v1000h-1500z" />
|
||||
<clip-path android:pathData="M0,0h1200v1000h-1200z" />
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="evenOdd"
|
||||
android:pathData="M350,238C397,238 436,199 436,152 436,105 397,66 350,66 303,66 264,105 264,152 264,199 303,238 350,238L350,238ZM606,563C590,487 561,362 519,310 478,260 395,258 350,258L350,258C305,258 222,260 181,310 139,362 110,487 94,563 85,605 143,620 159,578 181,515 199,462 237,418 258,543 183,759 179,881 179,904 198,924 221,924 240,924 255,912 261,896 281,828 350,639 350,639L350,639 350,639C350,639 419,828 439,896 445,912 460,924 479,924 502,924 521,904 521,881 517,759 442,543 463,418 501,462 519,515 541,578 557,620 615,605 606,563L606,563Z"
|
||||
android:pathData="M241,272C283,272 317,237 317,196 317,154 283,120 241,120 200,120 165,154 165,196 165,237 200,272 241,272L241,272 241,272ZM468,559C453,492 428,381 391,335 354,291 281,289 241,289L241,289C201,289 128,291 92,335 55,381 29,492 15,559 7,596 58,609 72,572 92,516 108,469 141,431 160,541 94,732 90,839 90,860 107,877 127,877 144,877 157,867 163,853 180,793 241,626 241,626L241,626 241,626C241,626 302,793 320,853 325,867 339,877 355,877 376,877 392,860 392,839 389,732 323,541 341,431 375,469 391,516 410,572 424,609 476,596 468,559L468,559 468,559Z"
|
||||
android:strokeColor="#00000000"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="28.222" />
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="evenOdd"
|
||||
android:pathData="M1207,500L979,310 979,424 712,424 712,576 979,576 979,690 1207,500 1207,500ZM1322,767L1017,767 1017,843 1322,843C1364,843 1398,809 1398,767L1398,233C1398,191 1364,157 1322,157L1017,157 1017,233 1322,233 1322,767 1322,767Z"
|
||||
android:pathData="M999,503L798,335 798,436 561,436 561,570 798,570 798,671 999,503 999,503 999,503ZM1101,739L831,739 831,806 1101,806C1138,806 1168,776 1168,739L1168,267C1168,230 1138,200 1101,200L831,200 831,267 1101,267 1101,739 1101,739 1101,739Z"
|
||||
android:strokeColor="#00000000"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="28.222" />
|
||||
|
@ -106,7 +106,7 @@
|
||||
app:drawableStartCompat="@drawable/subscriber" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/list_follow"
|
||||
android:id="@+id/list_action"
|
||||
style="@style/Widget.AppCompat.Button.Borderless"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="@dimen/listitem_button_height"
|
||||
@ -117,19 +117,6 @@
|
||||
android:text="@string/user_follow"
|
||||
android:textSize="@dimen/listitem_textsize_button" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/list_delete"
|
||||
style="@style/Widget.AppCompat.Button.Borderless"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="@dimen/listitem_button_height"
|
||||
android:layout_margin="@dimen/listitem_margin"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/button"
|
||||
android:singleLine="true"
|
||||
android:text="@string/delete_list"
|
||||
android:textSize="@dimen/listitem_textsize_button"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
style="@style/CardViewStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
@ -26,10 +27,11 @@
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/useritem_margin_layout"
|
||||
android:layout_marginLeft="@dimen/useritem_margin_layout"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
@ -48,6 +50,13 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/useritem_del_user"
|
||||
android:layout_width="@dimen/useritem_button_size"
|
||||
android:layout_height="@dimen/useritem_button_size"
|
||||
android:background="@drawable/button"
|
||||
app:srcCompat="@drawable/cross" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
@ -169,4 +169,7 @@
|
||||
<string name="userlist_create_new_list">Neue Liste erstellen</string>
|
||||
<string name="edit_list">Liste bearbeiten</string>
|
||||
<string name="update_list">Liste aktualisieren</string>
|
||||
<string name="confirm_remove_user_from_list">Nutzer von der Liste entfernen?</string>
|
||||
<string name="info_user_removed">Nutzer von der Liste entfernt!</string>
|
||||
<string name="info_following_list">folge Liste..</string>
|
||||
</resources>
|
@ -94,6 +94,7 @@
|
||||
<dimen name="useritem_image_size">40sp</dimen>
|
||||
<dimen name="useritem_margin_layout">5dp</dimen>
|
||||
<dimen name="useritem_padding_drawable">5dp</dimen>
|
||||
<dimen name="useritem_button_size">36dp</dimen>
|
||||
|
||||
<!--dimens of item_list.xml-->
|
||||
<dimen name="listitem_padding">5dp</dimen>
|
||||
|
@ -175,4 +175,7 @@
|
||||
<string name="userlist_create_new_list">Create a new userlist</string>
|
||||
<string name="edit_list">Edit list</string>
|
||||
<string name="update_list">update list</string>
|
||||
<string name="confirm_remove_user_from_list">remov user from list?</string>
|
||||
<string name="info_user_removed">user removed from list!</string>
|
||||
<string name="info_following_list">following list..</string>
|
||||
</resources>
|
Loading…
x
Reference in New Issue
Block a user