improve adding/removing users from lists
This commit is contained in:
parent
625134605b
commit
5c593a1025
|
@ -3,6 +3,8 @@ package org.joinmastodon.android.fragments;
|
|||
import android.app.Activity;
|
||||
import android.media.MediaRouter;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
|
@ -33,6 +35,13 @@ public class ListTimelineFragment extends StatusListFragment {
|
|||
listID=getArguments().getString("listID");
|
||||
listTitle=getArguments().getString("listTitle");
|
||||
setTitle(listTitle);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
// inflater.inflate(R.menu.list, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -58,7 +58,7 @@ public class ListTimelinesFragment extends BaseRecyclerFragment<ListTimeline> im
|
|||
profileAccountId=args.getString("profileAccount");
|
||||
profileDisplayUsername=args.getString("profileDisplayUsername");
|
||||
setTitle(getString(R.string.lists_with_user, profileDisplayUsername));
|
||||
setHasOptionsMenu(true);
|
||||
// setHasOptionsMenu(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,55 +69,30 @@ public class ListTimelinesFragment extends BaseRecyclerFragment<ListTimeline> im
|
|||
loadData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
Button saveButton=new Button(getActivity());
|
||||
saveButton.setText(R.string.save);
|
||||
saveButton.setOnClickListener(this::onSaveClick);
|
||||
LinearLayout wrap=new LinearLayout(getActivity());
|
||||
wrap.setOrientation(LinearLayout.HORIZONTAL);
|
||||
wrap.addView(saveButton, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
wrap.setPadding(V.dp(16), V.dp(4), V.dp(16), V.dp(8));
|
||||
wrap.setClipToPadding(false);
|
||||
MenuItem item=menu.add(R.string.save);
|
||||
item.setActionView(wrap);
|
||||
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||
}
|
||||
// @Override
|
||||
// public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
// Button saveButton=new Button(getActivity());
|
||||
// saveButton.setText(R.string.save);
|
||||
// saveButton.setOnClickListener(this::onSaveClick);
|
||||
// LinearLayout wrap=new LinearLayout(getActivity());
|
||||
// wrap.setOrientation(LinearLayout.HORIZONTAL);
|
||||
// wrap.addView(saveButton, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
// wrap.setPadding(V.dp(16), V.dp(4), V.dp(16), V.dp(8));
|
||||
// wrap.setClipToPadding(false);
|
||||
// MenuItem item=menu.add(R.string.save);
|
||||
// item.setActionView(wrap);
|
||||
// item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||
// }
|
||||
|
||||
private void onSaveClick(View view) {
|
||||
List<String> addUserToLists = new ArrayList<>();
|
||||
List<String> removeUserFromLists = new ArrayList<>();
|
||||
for (Map.Entry<String, Boolean> entry : userInList.entrySet()) {
|
||||
Boolean changedValue = entry.getValue();
|
||||
String id = entry.getKey();
|
||||
if (changedValue != null && !changedValue.equals(userInListBefore.get(id))) {
|
||||
(changedValue ? addUserToLists : removeUserFromLists).add(id);
|
||||
}
|
||||
}
|
||||
private void saveListMembership(String listId, boolean isMember) {
|
||||
userInList.put(listId, isMember);
|
||||
List<String> accountIdList = Collections.singletonList(profileAccountId);
|
||||
for (String listId : addUserToLists) {
|
||||
inProgress++;
|
||||
new AddAccountsToList(listId, accountIdList).setCallback(new SimpleCallback<>(this) {
|
||||
MastodonAPIRequest<Object> req = isMember ? new AddAccountsToList(listId, accountIdList) : new RemoveAccountsFromList(listId, accountIdList);
|
||||
req.setCallback(new SimpleCallback<>(this) {
|
||||
@Override
|
||||
public void onSuccess(Object o) { onRequestComplete(); }
|
||||
@Override
|
||||
public void onError(ErrorResponse error) { super.onError(error); onSuccess(null); }
|
||||
public void onSuccess(Object o) {}
|
||||
}).exec(accountId);
|
||||
}
|
||||
for (String listId : removeUserFromLists) {
|
||||
inProgress++;
|
||||
new RemoveAccountsFromList(listId, accountIdList).setCallback(new SimpleCallback<>(this) {
|
||||
@Override
|
||||
public void onSuccess(Object o) { onRequestComplete(); }
|
||||
@Override
|
||||
public void onError(ErrorResponse error) { super.onError(error); onSuccess(null); }
|
||||
}).exec(accountId);
|
||||
}
|
||||
}
|
||||
|
||||
private void onRequestComplete() {
|
||||
if (--inProgress == 0) reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doLoadData(int offset, int count){
|
||||
|
@ -129,7 +104,7 @@ public class ListTimelinesFragment extends BaseRecyclerFragment<ListTimeline> im
|
|||
public void onSuccess(List<ListTimeline> lists) {
|
||||
for (ListTimeline l : lists) userInListBefore.put(l.id, true);
|
||||
userInList.putAll(userInListBefore);
|
||||
onDataLoaded(lists, false);
|
||||
if (profileAccountId == null || !lists.isEmpty()) onDataLoaded(lists, false);
|
||||
if (profileAccountId == null) return;
|
||||
|
||||
currentRequest=new GetLists().setCallback(new SimpleCallback<>(ListTimelinesFragment.this) {
|
||||
|
@ -202,9 +177,7 @@ public class ListTimelinesFragment extends BaseRecyclerFragment<ListTimeline> im
|
|||
}
|
||||
|
||||
private void onClickToggle(View view) {
|
||||
if (view instanceof CheckBox cb) {
|
||||
userInList.put(item.id, cb.isChecked());
|
||||
}
|
||||
saveListMembership(item.id, listToggle.isChecked());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -532,10 +532,12 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
|
|||
menu.findItem(R.id.mute).setTitle(getString(relationship.muting ? R.string.unmute_user : R.string.mute_user, account.getDisplayUsername()));
|
||||
menu.findItem(R.id.block).setTitle(getString(relationship.blocking ? R.string.unblock_user : R.string.block_user, account.getDisplayUsername()));
|
||||
menu.findItem(R.id.report).setTitle(getString(R.string.report_user, account.getDisplayUsername()));
|
||||
if(relationship.following)
|
||||
if(relationship.following) {
|
||||
menu.findItem(R.id.hide_boosts).setTitle(getString(relationship.showingReblogs ? R.string.hide_boosts_from_user : R.string.show_boosts_from_user, account.getDisplayUsername()));
|
||||
else
|
||||
}else {
|
||||
menu.findItem(R.id.hide_boosts).setVisible(false);
|
||||
menu.findItem(R.id.manage_user_lists).setVisible(false);
|
||||
}
|
||||
if(!account.isLocal())
|
||||
menu.findItem(R.id.block_domain).setTitle(getString(relationship.domainBlocking ? R.string.unblock_domain : R.string.block_domain, account.getDomain()));
|
||||
else
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
|
||||
<path android:pathData="M10 5h4c0-1.105-0.895-2-2-2s-2 0.895-2 2zM8.5 5c0-1.933 1.567-3.5 3.5-3.5s3.5 1.567 3.5 3.5h5.75C21.664 5 22 5.336 22 5.75S21.664 6.5 21.25 6.5h-1.32l-1.17 12.111C18.573 20.533 16.957 22 15.026 22H8.974c-1.931 0-3.547-1.467-3.733-3.389L4.07 6.5H2.75C2.336 6.5 2 6.164 2 5.75S2.336 5 2.75 5H8.5zm2 4.75C10.5 9.336 10.164 9 9.75 9S9 9.336 9 9.75v7.5C9 17.664 9.336 18 9.75 18s0.75-0.336 0.75-0.75v-7.5zM14.25 9C14.664 9 15 9.336 15 9.75v7.5c0 0.414-0.336 0.75-0.75 0.75s-0.75-0.336-0.75-0.75v-7.5C13.5 9.336 13.836 9 14.25 9zm-7.516 9.467C6.846 19.62 7.815 20.5 8.974 20.5h6.052c1.159 0 2.128-0.88 2.24-2.033L18.424 6.5H5.576l1.158 11.967z" android:fillColor="@color/fluent_default_icon_tint"/>
|
||||
</vector>
|
|
@ -3,23 +3,18 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="56dp"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:tint="?android:textColorSecondary"
|
||||
android:src="@drawable/ic_fluent_people_community_24_regular"
|
||||
android:importantForAccessibility="no"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:drawableLeft="@drawable/ic_fluent_people_community_24_regular"
|
||||
android:drawableTint="?android:textColorSecondary"
|
||||
android:drawablePadding="16dp"
|
||||
android:textAppearance="@style/m3_title_medium"
|
||||
android:fontFamily="sans-serif"
|
||||
android:singleLine="true"
|
||||
|
@ -28,7 +23,9 @@
|
|||
|
||||
<CheckBox
|
||||
android:id="@+id/list_toggle"
|
||||
android:clickable="false"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
android:layout_height="match_parent"
|
||||
android:paddingRight="16dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:id="@+id/edit"
|
||||
android:title="@string/edit"
|
||||
android:icon="@drawable/ic_fluent_edit_24_regular"
|
||||
android:showAsAction="always"/>
|
||||
<item
|
||||
android:id="@+id/delete"
|
||||
android:title="@string/delete"
|
||||
android:icon="@drawable/ic_fluent_delete_24_regular"
|
||||
android:showAsAction="always"/>
|
||||
</menu>
|
|
@ -6,6 +6,6 @@
|
|||
<item android:id="@+id/report" android:title="@string/report_user"/>
|
||||
<item android:id="@+id/block_domain" android:title="@string/block_domain"/>
|
||||
<item android:id="@+id/hide_boosts" android:title="@string/hide_boosts_from_user"/>
|
||||
<item android:id="@+id/open_in_browser" android:title="@string/open_in_browser"/>
|
||||
<item android:id="@+id/manage_user_lists" android:title="@string/lists_with_user"/>
|
||||
<item android:id="@+id/open_in_browser" android:title="@string/open_in_browser"/>
|
||||
</menu>
|
Loading…
Reference in New Issue