mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-04-20 13:59:14 +00:00
Improve key profile adapter notification code
This commit is contained in:
parent
ed86d6ac8e
commit
a66d94a743
3 changed files with 8 additions and 13 deletions
|
@ -8,7 +8,6 @@ import android.view.ViewGroup;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import me.impy.aegis.helpers.ItemTouchHelperAdapter;
|
||||
|
||||
|
@ -25,12 +24,13 @@ public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileHolder> im
|
|||
|
||||
public void addKey(KeyProfile profile) {
|
||||
_keyProfiles.add(profile);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void addKeys(List<KeyProfile> profiles) {
|
||||
_keyProfiles.addAll(profiles);
|
||||
notifyDataSetChanged();
|
||||
int position = getItemCount() - 1;
|
||||
if (position == 0) {
|
||||
notifyDataSetChanged();
|
||||
} else {
|
||||
notifyItemInserted(position);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeKey(KeyProfile profile) {
|
||||
|
|
|
@ -33,8 +33,7 @@ public class KeyProfileHolder extends RecyclerView.ViewHolder {
|
|||
}
|
||||
|
||||
public void setData(KeyProfile profile) {
|
||||
_keyProfile = profile;
|
||||
if (_keyProfile == null) {
|
||||
if ((_keyProfile = profile) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,6 @@ import java.io.ByteArrayOutputStream;
|
|||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.UndeclaredThrowableException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -486,18 +485,15 @@ public class MainActivity extends AppCompatActivity implements KeyProfileAdapter
|
|||
private void loadKeyProfiles() {
|
||||
updateLockIcon();
|
||||
|
||||
List<KeyProfile> profiles = new ArrayList<>();
|
||||
try {
|
||||
for (DatabaseEntry entry : _db.getKeys()) {
|
||||
profiles.add(new KeyProfile(entry));
|
||||
_keyProfileAdapter.addKey(new KeyProfile(entry));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(this, "An error occurred while trying to load database entries", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
_keyProfileAdapter.addKeys(profiles);
|
||||
}
|
||||
|
||||
private void updateLockIcon() {
|
||||
|
|
Loading…
Add table
Reference in a new issue