Fix issue #529 - Lists are ordered alphabetically 'ASC' by default can be reverted with a button

This commit is contained in:
Thomas 2022-11-25 10:08:57 +01:00
parent 099b18014e
commit 23d2626370
6 changed files with 68 additions and 4 deletions

View file

@ -15,8 +15,6 @@ package app.fedilab.android.activities;
* see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.helper.PinnedTimelineHelper.sortListPositionAsc;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
@ -39,6 +37,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import app.fedilab.android.BaseMainActivity;
@ -78,6 +77,7 @@ public class MastodonListActivity extends BaseActivity implements MastodonListAd
private boolean flagLoading;
private String max_id;
private FragmentMastodonTimeline fragmentMastodonTimeline;
private boolean orderASC;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -92,6 +92,7 @@ public class MastodonListActivity extends BaseActivity implements MastodonListAd
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
}
flagLoading = false;
orderASC = true;
max_id = null;
accountsVM = new ViewModelProvider(MastodonListActivity.this).get(AccountsVM.class);
timelinesVM = new ViewModelProvider(MastodonListActivity.this).get(TimelinesVM.class);
@ -114,7 +115,7 @@ public class MastodonListActivity extends BaseActivity implements MastodonListAd
}
}
}
sortListPositionAsc(mastodonListList);
sortAsc(mastodonListList);
mastodonListAdapter = new MastodonListAdapter(mastodonListList);
mastodonListAdapter.actionOnList = this;
binding.notContent.setVisibility(View.GONE);
@ -127,6 +128,19 @@ public class MastodonListActivity extends BaseActivity implements MastodonListAd
});
}
private void sortAsc(List<MastodonList> mastodonLists) {
Collections.sort(mastodonLists, (obj1, obj2) -> obj1.title.compareToIgnoreCase(obj2.title));
orderASC = true;
invalidateOptionsMenu();
}
private void sortDesc(List<MastodonList> mastodonLists) {
Collections.sort(mastodonLists, (obj1, obj2) -> obj2.title.compareToIgnoreCase(obj1.title));
orderASC = false;
invalidateOptionsMenu();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
@ -374,6 +388,16 @@ public class MastodonListActivity extends BaseActivity implements MastodonListAd
});
dialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
dialogBuilder.create().show();
} else if (item.getItemId() == R.id.action_order) {
if (mastodonListList != null && mastodonListList.size() > 0 && mastodonListAdapter != null) {
if (orderASC) {
sortDesc(mastodonListList);
} else {
sortAsc(mastodonListList);
}
invalidateOptionsMenu();
mastodonListAdapter.notifyItemRangeChanged(0, mastodonListList.size());
}
}
return super.onOptionsItemSelected(item);
}
@ -403,6 +427,14 @@ public class MastodonListActivity extends BaseActivity implements MastodonListAd
public boolean onCreateOptionsMenu(@NonNull Menu menu) {
if (!canGoBack) {
getMenuInflater().inflate(R.menu.menu_main_list, menu);
MenuItem order = menu.findItem(R.id.action_order);
if (order != null) {
if (orderASC) {
order.setIcon(R.drawable.ic_baseline_filter_asc_24);
} else {
order.setIcon(R.drawable.ic_baseline_filter_desc_24);
}
}
} else {
getMenuInflater().inflate(R.menu.menu_list, menu);
}

View file

@ -1031,7 +1031,7 @@ public class Helper {
final Activity activity = (Activity) context;
return !activity.isDestroyed() && !activity.isFinishing();
}
return false;
return true;
}
/**

View file

@ -0,0 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#FFFFFF"
android:viewportWidth="24"
android:viewportHeight="24">
<group
android:rotation="0"
android:scaleY="-1"
android:translateY="24.0">
<path
android:fillColor="@android:color/white"
android:pathData="M10,18h4v-2h-4v2zM3,6v2h18L21,6L3,6zM6,13h12v-2L6,11v2z" />
</group>
</vector>

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#FFFFFF"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M10,18h4v-2h-4v2zM3,6v2h18L21,6L3,6zM6,13h12v-2L6,11v2z" />
</vector>

View file

@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_order"
android:icon="@drawable/ic_baseline_filter_desc_24"
android:title="@string/order_lists"
app:showAsAction="always" />
<item
android:id="@+id/action_add_list"
android:icon="@drawable/ic_baseline_playlist_add_24"

View file

@ -1931,4 +1931,5 @@
<string name="set_notif_user_sign_up">New sign-up (moderators)</string>
<string name="set_notif_admin_report">New report (moderators)</string>
<string name="open_with_account">Open with another account</string>
<string name="order_lists">Order lists</string>
</resources>