mirror of
https://codeberg.org/tom79/Fedilab
synced 2024-12-12 03:16:36 +01:00
Fix issue #529 - Lists are ordered alphabetically 'ASC' by default can be reverted with a button
This commit is contained in:
parent
099b18014e
commit
23d2626370
@ -15,8 +15,6 @@ package app.fedilab.android.activities;
|
|||||||
* see <http://www.gnu.org/licenses>. */
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
|
||||||
|
|
||||||
import static app.fedilab.android.helper.PinnedTimelineHelper.sortListPositionAsc;
|
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -39,6 +37,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
|
|||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import app.fedilab.android.BaseMainActivity;
|
import app.fedilab.android.BaseMainActivity;
|
||||||
@ -78,6 +77,7 @@ public class MastodonListActivity extends BaseActivity implements MastodonListAd
|
|||||||
private boolean flagLoading;
|
private boolean flagLoading;
|
||||||
private String max_id;
|
private String max_id;
|
||||||
private FragmentMastodonTimeline fragmentMastodonTimeline;
|
private FragmentMastodonTimeline fragmentMastodonTimeline;
|
||||||
|
private boolean orderASC;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
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)));
|
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
|
||||||
}
|
}
|
||||||
flagLoading = false;
|
flagLoading = false;
|
||||||
|
orderASC = true;
|
||||||
max_id = null;
|
max_id = null;
|
||||||
accountsVM = new ViewModelProvider(MastodonListActivity.this).get(AccountsVM.class);
|
accountsVM = new ViewModelProvider(MastodonListActivity.this).get(AccountsVM.class);
|
||||||
timelinesVM = new ViewModelProvider(MastodonListActivity.this).get(TimelinesVM.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 = new MastodonListAdapter(mastodonListList);
|
||||||
mastodonListAdapter.actionOnList = this;
|
mastodonListAdapter.actionOnList = this;
|
||||||
binding.notContent.setVisibility(View.GONE);
|
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
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
if (item.getItemId() == android.R.id.home) {
|
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.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
|
||||||
dialogBuilder.create().show();
|
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);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
@ -403,6 +427,14 @@ public class MastodonListActivity extends BaseActivity implements MastodonListAd
|
|||||||
public boolean onCreateOptionsMenu(@NonNull Menu menu) {
|
public boolean onCreateOptionsMenu(@NonNull Menu menu) {
|
||||||
if (!canGoBack) {
|
if (!canGoBack) {
|
||||||
getMenuInflater().inflate(R.menu.menu_main_list, menu);
|
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 {
|
} else {
|
||||||
getMenuInflater().inflate(R.menu.menu_list, menu);
|
getMenuInflater().inflate(R.menu.menu_list, menu);
|
||||||
}
|
}
|
||||||
|
@ -1031,7 +1031,7 @@ public class Helper {
|
|||||||
final Activity activity = (Activity) context;
|
final Activity activity = (Activity) context;
|
||||||
return !activity.isDestroyed() && !activity.isFinishing();
|
return !activity.isDestroyed() && !activity.isFinishing();
|
||||||
}
|
}
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
15
app/src/main/res/drawable/ic_baseline_filter_asc_24.xml
Normal file
15
app/src/main/res/drawable/ic_baseline_filter_asc_24.xml
Normal 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>
|
10
app/src/main/res/drawable/ic_baseline_filter_desc_24.xml
Normal file
10
app/src/main/res/drawable/ic_baseline_filter_desc_24.xml
Normal 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>
|
@ -1,6 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
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
|
<item
|
||||||
android:id="@+id/action_add_list"
|
android:id="@+id/action_add_list"
|
||||||
android:icon="@drawable/ic_baseline_playlist_add_24"
|
android:icon="@drawable/ic_baseline_playlist_add_24"
|
||||||
|
@ -1931,4 +1931,5 @@
|
|||||||
<string name="set_notif_user_sign_up">New sign-up (moderators)</string>
|
<string name="set_notif_user_sign_up">New sign-up (moderators)</string>
|
||||||
<string name="set_notif_admin_report">New report (moderators)</string>
|
<string name="set_notif_admin_report">New report (moderators)</string>
|
||||||
<string name="open_with_account">Open with another account</string>
|
<string name="open_with_account">Open with another account</string>
|
||||||
|
<string name="order_lists">Order lists</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue
Block a user