Skip to content

Commit 6df3231

Browse files
committedMay 12, 2024
better UI for editfragment
1 parent 6433e93 commit 6df3231

File tree

9 files changed

+65
-113
lines changed

9 files changed

+65
-113
lines changed
 

‎app/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88
mavenCentral()
99
}
1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:8.3.2'
11+
classpath 'com.android.tools.build:gradle:8.4.0'
1212
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.7.7"
1313
}
1414
}
@@ -76,6 +76,6 @@ dependencies {
7676

7777
buildscript {
7878
dependencies {
79-
classpath 'com.android.tools.build:gradle:8.3.2'
79+
classpath 'com.android.tools.build:gradle:8.4.0'
8080
}
8181
}

‎app/src/main/java/fr/nuage/souvenirs/view/EditAlbumFragment.java

+3-73
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@
3434
import fr.nuage.souvenirs.viewmodel.AlbumViewModel;
3535
import fr.nuage.souvenirs.viewmodel.PageViewModel;
3636

37-
public class EditAlbumFragment extends Fragment implements SelectPageStyleFragment.OnSelectPageStyleListener {
37+
public class EditAlbumFragment extends Fragment {
3838

3939
private static final String DIALOG_CHANGE_STYLE = "DIALOG_CHANGE_STYLE";
4040

4141
private EditPageListAdapter editPageListAdapter;
4242
private AlbumViewModel albumVM;
4343
private String albumPath;
4444
private UUID initialPageFocusId;
45-
private int colNb = 1;
45+
private int colNb = 3;
4646

4747
private PageViewModel lastOperationPage;
4848

@@ -71,7 +71,6 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
7171

7272
//inflateview
7373
FragmentEditAlbumBinding binding = DataBindingUtil.inflate(inflater,R.layout.fragment_edit_album,container,false);
74-
binding.setFragment(this);
7574

7675
//set recyclerview
7776
RecyclerView pageListRecyclerView = binding.pageList;
@@ -93,6 +92,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
9392
AlbumViewModel albumVM = albumListViewModel.getAlbum(albumPath);
9493
if (albumVM != null) {
9594
setAlbumVM(albumVM);
95+
binding.setAlbum(albumVM);
9696
albumVM.getLdPages().observe(lifecycleOwner, PageViewModels -> editPageListAdapter.updateList(PageViewModels));
9797
getActivity().setTitle(albumVM.getName().getValue());
9898
albumVM.getName().observe(lifecycleOwner, s -> getActivity().setTitle(albumVM.getName().getValue()));
@@ -119,13 +119,6 @@ public void onAddPage(PageViewModel previousPage) {
119119
Navigation.findNavController(getView()).navigate(action);
120120
}
121121

122-
public void onSwitchLayout(PageViewModel p) {
123-
//save page
124-
lastOperationPage = p;
125-
//launch select style dialog
126-
SelectPageStyleDialogFragment dialog = SelectPageStyleDialogFragment.newInstance(this,-1,-1);
127-
dialog.show(getParentFragmentManager(),DIALOG_CHANGE_STYLE);
128-
}
129122

130123
public void openPageEdition(View v) {
131124
String pageId = (String)v.getTag();
@@ -135,20 +128,6 @@ public void openPageEdition(View v) {
135128
}
136129

137130

138-
@Override
139-
public void onStyleSelected(int style) {
140-
//check which dialog was launched
141-
Fragment dialogChangeStyle = getParentFragmentManager().findFragmentByTag(DIALOG_CHANGE_STYLE);
142-
if (dialogChangeStyle != null) {
143-
//dismiss dialog
144-
DialogFragment df = (DialogFragment) dialogChangeStyle;
145-
df.dismiss();
146-
//switch style
147-
albumVM.switchStyle(lastOperationPage,style);
148-
}
149-
150-
}
151-
152131
@Override
153132
public void onCreateOptionsMenu(@NonNull Menu menu, MenuInflater inflater) {
154133
inflater.inflate(R.menu.menu_edit_album, menu);
@@ -165,57 +144,8 @@ public void onCreateOptionsMenu(@NonNull Menu menu, MenuInflater inflater) {
165144
onAddPage(albumVM.getPage(-1));
166145
return true;
167146
});
168-
//set listener to switch display
169-
MenuItem displayColunmItem = menu.findItem(R.id.display_column_edit_album);
170-
displayColunmItem.setOnMenuItemClickListener(menuItem -> {
171-
//change columns
172-
colNb = (colNb == 1) ? 2 : 1;
173-
//change layout of recyclerview
174-
RecyclerView pageListRecyclerView = getView().findViewById(R.id.page_list);
175-
RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(getActivity(), colNb);
176-
pageListRecyclerView.setLayoutManager(mLayoutManager);
177-
getActivity().invalidateOptionsMenu();
178-
return true;
179-
});
180-
}
181-
182-
@Override
183-
public void onPrepareOptionsMenu (@NonNull Menu menu) {
184-
if (colNb != 1) {
185-
menu.findItem(R.id.display_column_edit_album).setIcon(R.drawable.ic_view_one_column_24dp);
186-
} else {
187-
menu.findItem(R.id.display_column_edit_album).setIcon(R.drawable.ic_view_column_black_24dp);
188-
}
189147
}
190148

191149
public AlbumViewModel getAlbumVM() { return albumVM; }
192150

193-
public void onClickPageMenu(PageViewModel pageViewModel, View view) {
194-
PopupMenu popupMenu = new PopupMenu(getContext(),view, Gravity.END);
195-
popupMenu.inflate(R.menu.page_edit_menu);
196-
popupMenu.setOnMenuItemClickListener(item -> {
197-
switch (item.getItemId()) {
198-
case R.id.menu_page_edit_insert:
199-
onAddPage(pageViewModel);
200-
return true;
201-
case R.id.menu_page_edit_dispo:
202-
onSwitchLayout(pageViewModel);
203-
return true;
204-
case R.id.menu_page_edit_delete:
205-
pageViewModel.delete();
206-
return true;
207-
case R.id.menu_page_edit_move_up:
208-
pageViewModel.moveUp();
209-
return true;
210-
case R.id.menu_page_edit_move_down:
211-
pageViewModel.moveDown();
212-
return true;
213-
}
214-
return false;
215-
});
216-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
217-
popupMenu.setForceShowIcon(true);
218-
}
219-
popupMenu.show();
220-
}
221151
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
2+
3+
<path android:fillColor="@android:color/white" android:pathData="M21,5c0,-1.1 -0.9,-2 -2,-2H5.83L21,18.17V5z"/>
4+
5+
<path android:fillColor="@android:color/white" android:pathData="M2.81,2.81L1.39,4.22L3,5.83V19c0,1.1 0.9,2 2,2h13.17l1.61,1.61l1.41,-1.41L2.81,2.81zM6,17l3,-4l2.25,3l0.82,-1.1l2.1,2.1H6z"/>
6+
7+
</vector>

‎app/src/main/res/layout/edit_item_page_list.xml

+17-27
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,27 @@
1111
type="fr.nuage.souvenirs.view.EditAlbumFragment"/>
1212
</data>
1313

14-
<com.google.android.material.card.MaterialCardView
15-
android:layout_width="match_parent"
16-
android:layout_height="wrap_content"
17-
android:layout_marginLeft="@dimen/mtrl_card_spacing"
18-
android:layout_marginTop="@dimen/mtrl_card_spacing"
19-
android:layout_marginRight="@dimen/mtrl_card_spacing"
20-
android:layout_marginBottom="@dimen/mtrl_card_spacing">
21-
2214
<androidx.constraintlayout.widget.ConstraintLayout
2315
android:id="@+id/page_parent"
2416
android:layout_width="match_parent"
2517
android:layout_height="wrap_content"
26-
android:layout_marginLeft="@dimen/mtrl_card_spacing"
27-
android:layout_marginTop="@dimen/mtrl_card_spacing"
28-
android:layout_marginRight="@dimen/mtrl_card_spacing"
29-
android:layout_marginBottom="@dimen/mtrl_card_spacing"
3018
android:tag="@{page.id.toString()}"
3119
android:clickable="true"
3220
android:onClick="@{fragment::openPageEdition}"
3321
android:focusable="true">
3422

3523

36-
<com.google.android.material.floatingactionbutton.FloatingActionButton
37-
android:id="@+id/page_menu_button"
38-
android:layout_width="wrap_content"
39-
android:layout_height="wrap_content"
40-
android:layout_marginEnd="16dp"
41-
android:layout_marginBottom="16dp"
42-
android:clickable="true"
43-
app:layout_constraintBottom_toBottomOf="@+id/page_layout"
44-
app:layout_constraintEnd_toEndOf="@+id/page_layout"
45-
app:srcCompat="@drawable/ic_baseline_menu_24"
46-
android:onClick="@{(view) -> fragment.onClickPageMenu(page,view)}"
47-
android:focusable="true" />
24+
4825

4926
<androidx.constraintlayout.widget.ConstraintLayout
5027
android:id="@+id/page_layout"
5128
android:layout_width="0dp"
5229
android:layout_height="0dp"
5330
android:layout_marginTop="8dp"
31+
android:paddingStart="8dp"
32+
android:paddingTop="8dp"
33+
android:paddingEnd="8dp"
34+
android:paddingBottom="8dp"
5435
android:focusable="true"
5536
android:focusableInTouchMode="true"
5637
app:layout_constraintDimensionRatio="1:1"
@@ -60,6 +41,18 @@
6041

6142
</androidx.constraintlayout.widget.ConstraintLayout>
6243

44+
<ImageView
45+
android:id="@+id/del_imageview"
46+
android:layout_width="40dp"
47+
android:layout_height="40dp"
48+
android:layout_marginEnd="-8dp"
49+
android:layout_marginBottom="-8dp"
50+
android:alpha="0.5"
51+
app:layout_constraintEnd_toEndOf="parent"
52+
app:layout_constraintBottom_toBottomOf="parent"
53+
app:srcCompat="@drawable/ic_delete_forever_black_24dp"
54+
android:onClick="@{() -> page.delete()}"/>
55+
6356
<ImageView
6457
android:id="@+id/page_audio_status"
6558
android:layout_width="48dp"
@@ -75,7 +68,4 @@
7568

7669
</androidx.constraintlayout.widget.ConstraintLayout>
7770

78-
79-
</com.google.android.material.card.MaterialCardView>
80-
8171
</layout>

‎app/src/main/res/layout/fragment_edit_album.xml

+33-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,46 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<layout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<layout xmlns:tools="http://schemas.android.com/tools"
3+
xmlns:android="http://schemas.android.com/apk/res/android"
34
xmlns:app="http://schemas.android.com/apk/res-auto">
45

56
<data>
6-
<variable
7-
name="fragment"
8-
type="fr.nuage.souvenirs.view.EditAlbumFragment"/>
7+
<variable name="album" type="fr.nuage.souvenirs.viewmodel.AlbumViewModel"/>
8+
<import type="android.view.View"/>
99
</data>
1010

1111
<androidx.constraintlayout.widget.ConstraintLayout
1212
android:layout_width="match_parent"
1313
android:layout_height="match_parent">
1414

15+
<androidx.constraintlayout.widget.ConstraintLayout
16+
android:layout_width="0dp"
17+
android:layout_height="0dp"
18+
app:layout_constraintBottom_toBottomOf="parent"
19+
app:layout_constraintEnd_toEndOf="parent"
20+
app:layout_constraintStart_toStartOf="parent"
21+
app:layout_constraintTop_toTopOf="parent"
22+
android:visibility="@{(album.ldPages.size == 0) ? View.VISIBLE : View.GONE}">
23+
24+
<TextView
25+
android:id="@+id/textView5"
26+
android:layout_width="wrap_content"
27+
android:layout_height="wrap_content"
28+
android:text="@string/empty_album"
29+
app:layout_constraintBottom_toBottomOf="parent"
30+
app:layout_constraintEnd_toEndOf="parent"
31+
app:layout_constraintStart_toStartOf="parent"
32+
app:layout_constraintTop_toTopOf="parent" />
33+
34+
<ImageView
35+
android:id="@+id/imageView7"
36+
android:layout_width="60dp"
37+
android:layout_height="60dp"
38+
app:layout_constraintBottom_toTopOf="@+id/textView5"
39+
app:layout_constraintEnd_toEndOf="parent"
40+
app:layout_constraintStart_toStartOf="parent"
41+
app:srcCompat="@drawable/baseline_hide_image_24" />
42+
</androidx.constraintlayout.widget.ConstraintLayout>
43+
1544
<androidx.recyclerview.widget.RecyclerView
1645
android:id="@+id/page_list"
1746
android:layout_width="match_parent"

‎app/src/main/res/menu/menu_edit_album.xml

-5
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,4 @@
1212
android:icon="@drawable/ic_note_add_page_black_24dp"
1313
android:title="@string/action_menu_add_page"
1414
app:showAsAction="always|collapseActionView" />
15-
<item
16-
android:id="@+id/display_column_edit_album"
17-
android:icon="@drawable/ic_view_column_black_24dp"
18-
android:title="@string/action_menu_display_column"
19-
app:showAsAction="always|collapseActionView" />
2015
</menu>

‎app/src/main/res/values/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,5 @@
8888
<string name="record_sound_textView">Tap on the microphone to stop recording.</string>
8989
<string name="record_sound_onair_textView">Now recroding...</string>
9090
<string name="string_album_margin_settings">Margin size between elements</string>
91+
<string name="empty_album">Album is empty.</string>
9192
</resources>

‎build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
mavenCentral()
88
}
99
dependencies {
10-
classpath 'com.android.tools.build:gradle:8.3.2'
10+
classpath 'com.android.tools.build:gradle:8.4.0'
1111
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.7.7"
1212

1313
// NOTE: Do not place your application dependencies here; they belong

‎gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip

0 commit comments

Comments
 (0)
Failed to load comments.