remember chat filter selection across rotations
This commit is contained in:
parent
d54978f593
commit
b8f3472af0
|
@ -4,12 +4,19 @@ import com.google.common.base.Preconditions;
|
||||||
import com.google.common.io.BaseEncoding;
|
import com.google.common.io.BaseEncoding;
|
||||||
import com.google.common.io.ByteSource;
|
import com.google.common.io.ByteSource;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Random;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class IDs {
|
public class IDs {
|
||||||
|
|
||||||
|
private static final Random RANDOM = new Random();
|
||||||
|
|
||||||
private static final long UUID_VERSION_MASK = 4 << 12;
|
private static final long UUID_VERSION_MASK = 4 << 12;
|
||||||
|
|
||||||
|
public static int quickInt() {
|
||||||
|
return RANDOM.nextInt();
|
||||||
|
}
|
||||||
|
|
||||||
public static String huge() {
|
public static String huge() {
|
||||||
final var random = new byte[96];
|
final var random = new byte[96];
|
||||||
Conversations.SECURE_RANDOM.nextBytes(random);
|
Conversations.SECURE_RANDOM.nextBytes(random);
|
||||||
|
|
|
@ -50,6 +50,7 @@ public abstract class RosterDao extends GroupDao {
|
||||||
deleteEmptyGroups();
|
deleteEmptyGroups();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transaction
|
||||||
public void update(
|
public void update(
|
||||||
final Account account, final String version, final Collection<Item> updates) {
|
final Account account, final String version, final Collection<Item> updates) {
|
||||||
for (final Item item : updates) {
|
for (final Item item : updates) {
|
||||||
|
|
|
@ -31,6 +31,7 @@ public class AccountIdentifier implements ChatFilter {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NonNull
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return MoreObjects.toStringHelper(this).add("id", id).add("address", address).toString();
|
return MoreObjects.toStringHelper(this).add("id", id).add("address", address).toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package im.conversations.android.database.model;
|
package im.conversations.android.database.model;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import com.google.common.base.MoreObjects;
|
import com.google.common.base.MoreObjects;
|
||||||
|
import com.google.common.base.Objects;
|
||||||
|
|
||||||
public class GroupIdentifier implements ChatFilter {
|
public class GroupIdentifier implements ChatFilter {
|
||||||
|
|
||||||
|
@ -8,6 +10,7 @@ public class GroupIdentifier implements ChatFilter {
|
||||||
public final String name;
|
public final String name;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NonNull
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return MoreObjects.toStringHelper(this).add("id", id).add("name", name).toString();
|
return MoreObjects.toStringHelper(this).add("id", id).add("name", name).toString();
|
||||||
}
|
}
|
||||||
|
@ -16,4 +19,17 @@ public class GroupIdentifier implements ChatFilter {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
GroupIdentifier that = (GroupIdentifier) o;
|
||||||
|
return id == that.id && Objects.equal(name, that.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(id, name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package im.conversations.android.ui.fragment.main;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -13,6 +14,7 @@ import androidx.fragment.app.Fragment;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import com.google.android.material.elevation.SurfaceColors;
|
import com.google.android.material.elevation.SurfaceColors;
|
||||||
import com.google.android.material.search.SearchView;
|
import com.google.android.material.search.SearchView;
|
||||||
|
import im.conversations.android.IDs;
|
||||||
import im.conversations.android.R;
|
import im.conversations.android.R;
|
||||||
import im.conversations.android.database.model.AccountIdentifier;
|
import im.conversations.android.database.model.AccountIdentifier;
|
||||||
import im.conversations.android.database.model.ChatFilter;
|
import im.conversations.android.database.model.ChatFilter;
|
||||||
|
@ -59,7 +61,9 @@ public class OverviewFragment extends Fragment {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
binding.navigationView.setNavigationItemSelectedListener(this::onNavigationItemSelected);
|
binding.navigationView.setNavigationItemSelectedListener(this::onNavigationItemSelected);
|
||||||
binding.navigationView.setCheckedItem(R.id.chats);
|
if (this.overviewViewModel.getChatFilter() == null) {
|
||||||
|
binding.navigationView.setCheckedItem(R.id.chats);
|
||||||
|
}
|
||||||
this.overviewViewModel
|
this.overviewViewModel
|
||||||
.getAccounts()
|
.getAccounts()
|
||||||
.observe(getViewLifecycleOwner(), this::onAccountsUpdated);
|
.observe(getViewLifecycleOwner(), this::onAccountsUpdated);
|
||||||
|
@ -117,14 +121,18 @@ public class OverviewFragment extends Fragment {
|
||||||
menuItemSpaces.setVisible(false);
|
menuItemSpaces.setVisible(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
final var chatFilter = this.overviewViewModel.getChatFilter();
|
||||||
menuItemSpaces.setVisible(true);
|
menuItemSpaces.setVisible(true);
|
||||||
final var subMenu = menuItemSpaces.getSubMenu();
|
final var subMenu = menuItemSpaces.getSubMenu();
|
||||||
subMenu.clear();
|
subMenu.clear();
|
||||||
for (final GroupIdentifier group : groups) {
|
for (final GroupIdentifier group : groups) {
|
||||||
final var menuItemSpace = subMenu.add(group.name);
|
final var menuItemSpace = subMenu.add(Menu.NONE, IDs.quickInt(), Menu.NONE, group.name);
|
||||||
menuItemSpace.setCheckable(true);
|
menuItemSpace.setCheckable(true);
|
||||||
menuItemSpace.setIcon(R.drawable.ic_workspaces_24dp);
|
menuItemSpace.setIcon(R.drawable.ic_workspaces_24dp);
|
||||||
menuItemSpace.setIntent(Intents.of(group));
|
menuItemSpace.setIntent(Intents.of(group));
|
||||||
|
if (group.equals(chatFilter)) {
|
||||||
|
this.binding.navigationView.setCheckedItem(menuItemSpace);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,14 +143,19 @@ public class OverviewFragment extends Fragment {
|
||||||
menuItemAccounts.setVisible(false);
|
menuItemAccounts.setVisible(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
final var chatFilter = this.overviewViewModel.getChatFilter();
|
||||||
menuItemAccounts.setVisible(true);
|
menuItemAccounts.setVisible(true);
|
||||||
final var subMenu = menuItemAccounts.getSubMenu();
|
final var subMenu = menuItemAccounts.getSubMenu();
|
||||||
subMenu.clear();
|
subMenu.clear();
|
||||||
for (final AccountIdentifier account : accounts) {
|
for (final AccountIdentifier account : accounts) {
|
||||||
final var menuItemAccount = subMenu.add(account.address);
|
final var menuItemAccount =
|
||||||
|
subMenu.add(Menu.NONE, IDs.quickInt(), Menu.NONE, account.address);
|
||||||
menuItemAccount.setCheckable(true);
|
menuItemAccount.setCheckable(true);
|
||||||
menuItemAccount.setIcon(R.drawable.ic_person_24dp);
|
menuItemAccount.setIcon(R.drawable.ic_person_24dp);
|
||||||
menuItemAccount.setIntent(Intents.of(account));
|
menuItemAccount.setIntent(Intents.of(account));
|
||||||
|
if (account.equals(chatFilter)) {
|
||||||
|
this.binding.navigationView.setCheckedItem(menuItemAccount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,12 +46,11 @@ public class OverviewViewModel extends AndroidViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<List<AccountIdentifier>> getAccounts() {
|
public LiveData<List<AccountIdentifier>> getAccounts() {
|
||||||
return Transformations.distinctUntilChanged(this.accountRepository.getAccounts());
|
return Transformations.distinctUntilChanged(this.accounts);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO change into GroupIdentifier
|
|
||||||
public LiveData<List<GroupIdentifier>> getGroups() {
|
public LiveData<List<GroupIdentifier>> getGroups() {
|
||||||
return Transformations.distinctUntilChanged(this.chatRepository.getGroups());
|
return Transformations.distinctUntilChanged(this.groups);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<Boolean> getChatFilterAvailable() {
|
public LiveData<Boolean> getChatFilterAvailable() {
|
||||||
|
|
Loading…
Reference in a new issue