mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-17 07:22:50 +00:00
Move entry divider logic to EntryListView
This patch makes EntryListView responsible for providing the divider between entries, instead of setting a margin on every entry like we do now. It also fixes a couple of miscellaneous issues, like use of the old package name.
This commit is contained in:
parent
eb29be587f
commit
02c9a0cb1c
18 changed files with 84 additions and 38 deletions
|
@ -30,4 +30,15 @@ public enum ViewMode {
|
|||
return R.layout.card_entry;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the height (in dp) that the divider between entries should have in this view mode.
|
||||
*/
|
||||
public float getDividerHeight() {
|
||||
if (this == ViewMode.COMPACT) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 20;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ public class EntryHolder extends RecyclerView.ViewHolder {
|
|||
private ImageView _profileDrawable;
|
||||
private DatabaseEntry _entry;
|
||||
private ImageView _buttonRefresh;
|
||||
private View _entryDivider;
|
||||
|
||||
private boolean _hidden;
|
||||
private int _tapToRevealTime;
|
||||
|
@ -46,8 +45,6 @@ public class EntryHolder extends RecyclerView.ViewHolder {
|
|||
_profileDrawable = view.findViewById(R.id.ivTextDrawable);
|
||||
_buttonRefresh = view.findViewById(R.id.buttonRefresh);
|
||||
|
||||
_entryDivider = view.findViewById(R.id.entryDivider);
|
||||
|
||||
_progressBar = view.findViewById(R.id.progressBar);
|
||||
int primaryColorId = view.getContext().getResources().getColor(R.color.colorPrimary);
|
||||
_progressBar.getProgressDrawable().setColorFilter(primaryColorId, PorterDuff.Mode.SRC_IN);
|
||||
|
@ -122,11 +119,6 @@ public class EntryHolder extends RecyclerView.ViewHolder {
|
|||
_progressBar.setVisibility(showProgress ? View.VISIBLE : View.GONE);
|
||||
if (showProgress) {
|
||||
_progressBar.setPeriod(((TotpInfo) _entry.getInfo()).getPeriod());
|
||||
|
||||
if (_entryDivider != null) {
|
||||
_entryDivider.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
startRefreshLoop();
|
||||
} else {
|
||||
stopRefreshLoop();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.beemdevelopment.aegis.ui.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -18,7 +19,10 @@ import com.beemdevelopment.aegis.otp.TotpInfo;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
@ -29,8 +33,10 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
|
|||
private SimpleItemTouchHelperCallback _touchCallback;
|
||||
|
||||
private RecyclerView _recyclerView;
|
||||
private RecyclerView.ItemDecoration _dividerDecoration;
|
||||
private PeriodProgressBar _progressBar;
|
||||
private boolean _showProgress;
|
||||
private ViewMode _viewMode;
|
||||
|
||||
private UiRefresher _refresher;
|
||||
|
||||
|
@ -38,11 +44,10 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
|
|||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
_adapter = new EntryAdapter(this);
|
||||
_showProgress = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_entry_list_view, container, false);
|
||||
_progressBar = view.findViewById(R.id.progressBar);
|
||||
|
||||
|
@ -106,7 +111,9 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
|
|||
}
|
||||
|
||||
public void setViewMode(ViewMode mode) {
|
||||
_adapter.setViewMode(mode);
|
||||
_viewMode = mode;
|
||||
updateDividerDecoration();
|
||||
_adapter.setViewMode(_viewMode);
|
||||
}
|
||||
|
||||
public void refresh(boolean hard) {
|
||||
|
@ -147,7 +154,7 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
|
|||
|
||||
@Override
|
||||
public void onPeriodUniformityChanged(boolean isUniform) {
|
||||
_showProgress = isUniform;
|
||||
setShowProgress(isUniform);
|
||||
if (_showProgress) {
|
||||
_progressBar.setVisibility(View.VISIBLE);
|
||||
_progressBar.setPeriod(_adapter.getUniformPeriod());
|
||||
|
@ -199,6 +206,28 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
|
|||
_recyclerView.scheduleLayoutAnimation();
|
||||
}
|
||||
|
||||
private void setShowProgress(boolean showProgress) {
|
||||
_showProgress = showProgress;
|
||||
updateDividerDecoration();
|
||||
}
|
||||
|
||||
private void updateDividerDecoration() {
|
||||
if (_dividerDecoration != null) {
|
||||
_recyclerView.removeItemDecoration(_dividerDecoration);
|
||||
}
|
||||
|
||||
float height = _viewMode.getDividerHeight();
|
||||
if (_showProgress && height == 0) {
|
||||
DividerItemDecoration divider = new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL);
|
||||
divider.setDrawable(ContextCompat.getDrawable(getContext(), R.drawable.entry_divider));
|
||||
_dividerDecoration = divider;
|
||||
} else {
|
||||
_dividerDecoration = new VerticalSpaceItemDecoration(height);
|
||||
}
|
||||
|
||||
_recyclerView.addItemDecoration(_dividerDecoration);
|
||||
}
|
||||
|
||||
public interface Listener {
|
||||
void onEntryClick(DatabaseEntry entry);
|
||||
void onEntryMove(DatabaseEntry entry1, DatabaseEntry entry2);
|
||||
|
@ -206,4 +235,22 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
|
|||
void onEntryChange(DatabaseEntry entry);
|
||||
void onScroll(int dx, int dy);
|
||||
}
|
||||
|
||||
private class VerticalSpaceItemDecoration extends RecyclerView.ItemDecoration {
|
||||
private int _height;
|
||||
|
||||
private VerticalSpaceItemDecoration(float dp) {
|
||||
// convert dp to pixels
|
||||
_height = (int) (dp * (getContext().getResources().getDisplayMetrics().densityDpi / 160f));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
|
||||
if (parent.getChildAdapterPosition(view) == 0) {
|
||||
// the first item should also have a top margin
|
||||
outRect.top = _height;
|
||||
}
|
||||
outRect.bottom = _height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
6
app/src/main/res/drawable/entry_divider.xml
Normal file
6
app/src/main/res/drawable/entry_divider.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="@color/divider"/>
|
||||
<size android:height="0.1dp"/>
|
||||
</shape>
|
|
@ -5,7 +5,7 @@
|
|||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
android:background="?attr/background"
|
||||
tools:context="com.beemdevelopment.aegis.com.impy.aegis.ui.AuthActivity">
|
||||
tools:context="com.beemdevelopment.aegis.ui.AuthActivity">
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:background="?attr/background"
|
||||
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
tools:context="com.beemdevelopment.aegis.ui.EditEntryActivity">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -6,12 +6,12 @@
|
|||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
android:background="?attr/background"
|
||||
tools:context="com.beemdevelopment.aegis.com.impy.aegis.ui.GroupManagerActivity">
|
||||
tools:context="com.beemdevelopment.aegis.ui.GroupManagerActivity">
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -5,6 +5,6 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
tools:context="com.beemdevelopment.aegis.com.impy.aegis.ui.IntroActivity">
|
||||
tools:context="com.beemdevelopment.aegis.ui.IntroActivity">
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
|
|
@ -6,14 +6,14 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
tools:context="com.beemdevelopment.aegis.com.impy.aegis.ui.MainActivity">
|
||||
tools:context="com.beemdevelopment.aegis.ui.MainActivity">
|
||||
|
||||
<fragment
|
||||
android:name="com.beemdevelopment.aegis.ui.views.EntryListView"
|
||||
android:id="@+id/key_profiles"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
|
||||
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"/>
|
||||
|
||||
<!-- note: the fab should always be the last element to be sure it's displayed on top -->
|
||||
<com.getbase.floatingactionbutton.FloatingActionsMenu
|
||||
|
|
|
@ -9,6 +9,6 @@
|
|||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context="com.beemdevelopment.aegis.com.impy.aegis.ui.ScannerActivity">
|
||||
tools:context="com.beemdevelopment.aegis.ui.ScannerActivity">
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
|
@ -6,15 +6,12 @@
|
|||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
android:background="?attr/background"
|
||||
|
||||
tools:context="com.beemdevelopment.aegis.com.impy.aegis.ui.SlotManagerActivity">
|
||||
|
||||
|
||||
tools:context="com.beemdevelopment.aegis.ui.SlotManagerActivity">
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
|
|
|
@ -128,10 +128,4 @@
|
|||
android:layout_weight="1"/>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/entryDivider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0.1dp"
|
||||
android:background="@color/divider" />
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="com.beemdevelopment.aegis.com.impy.aegis.ui.EditEntryActivity">
|
||||
tools:context="com.beemdevelopment.aegis.ui.EditEntryActivity">
|
||||
<item
|
||||
android:id="@+id/action_save"
|
||||
app:showAsAction="ifRoom"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="com.beemdevelopment.aegis.com.impy.aegis.ui.MainActivity">
|
||||
tools:context="com.beemdevelopment.aegis.ui.MainActivity">
|
||||
<item
|
||||
android:id="@+id/mi_search"
|
||||
android:title="@string/search"
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="com.beemdevelopment.aegis.com.impy.aegis.ui.ScannerActivity">
|
||||
tools:context="com.beemdevelopment.aegis.ui.ScannerActivity">
|
||||
<item
|
||||
android:id="@+id/action_camera"
|
||||
android:icon="@drawable/ic_camera_front_24dp"
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="com.beemdevelopment.aegis.com.impy.aegis.ui.SlotManagerActivity">
|
||||
tools:context="com.beemdevelopment.aegis.ui.SlotManagerActivity">
|
||||
<item
|
||||
android:id="@+id/action_save"
|
||||
app:showAsAction="ifRoom"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue