パスをサブタイトルに表示するように

This commit is contained in:
ろむねこ 2024-01-26 18:33:02 +09:00
parent c2f62a5a84
commit e96d213c33
No known key found for this signature in database
GPG Key ID: FA1F39A1BA37D168
2 changed files with 26 additions and 5 deletions

View File

@ -23,6 +23,7 @@ import dagger.hilt.android.AndroidEntryPoint;
import one.nem.lacerta.component.viewer.ViewerMainActivity;
import one.nem.lacerta.data.LacertaLibrary;
import one.nem.lacerta.model.LibraryItemPage;
import one.nem.lacerta.model.ListItemType;
import one.nem.lacerta.utils.FeatureSwitch;
import one.nem.lacerta.utils.LacertaLogger;
@ -43,6 +44,7 @@ public class LibraryPageFragment extends Fragment {
String folderId;
String title;
String parentId;
Toolbar toolbar;
@Inject
@ -128,12 +130,19 @@ public class LibraryPageFragment extends Fragment {
logger.debug("LibraryTopFragment", "getArguments() is null(maybe root)");
this.libraryItemPage = new LibraryItemPage();
}
this.toolbar = view.findViewById(R.id.library_toolbar);
// Toolbar Setup
toolbarSetup(view.findViewById(R.id.library_toolbar), this.folderId != null, this.title != null ? this.title : "ライブラリ");
toolbarSetup(this.toolbar, this.folderId != null, this.title != null ? this.title : "ライブラリ");
if(this.folderId == null) {
updateToolbarSubtitle(this.toolbar, null); //負荷軽減のため+邪魔なのでfolderIdがnullの場合はルートフォルダを表示しているので
} else {
lacertaLibrary.getPublicPath(this.folderId, ListItemType.ITEM_TYPE_FOLDER).thenAccept(publicPath -> {
updateToolbarSubtitle(this.toolbar, "/" + publicPath.parent().getStringPath());
});
}
// RecyclerView Setup
RecyclerView recyclerView = view.findViewById(R.id.library_item_recycler_view);
this.listItemAdapter = new ListItemAdapter(new DocumentSelectListener() {
@Override
@ -168,6 +177,7 @@ public class LibraryPageFragment extends Fragment {
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
// Get library page and update RecyclerView items
lacertaLibrary.getLibraryPage(this.folderId, 10).thenAccept(libraryItemPage -> {
this.libraryItemPage = libraryItemPage;
@ -216,6 +226,7 @@ public class LibraryPageFragment extends Fragment {
lacertaLibrary.createFolder(pageId, input.getText().toString()).thenAccept(folderId -> {
// Refresh
updateItem(pageId);
});
});
builder.setNegativeButton("キャンセル", (dialog, which) -> {
@ -226,7 +237,7 @@ public class LibraryPageFragment extends Fragment {
}
/**
* RecyclerViewのアイテムを更新する
* RecyclerViewのアイテムとUIを更新する
*/
private void updateItem(String pageId) {
lacertaLibrary.getLibraryPage(pageId, 10).thenAccept(libraryItemPage -> {
@ -242,6 +253,16 @@ public class LibraryPageFragment extends Fragment {
});
}
/**
* Toolbarのサブタイトルを更新
* @param subtitle サブタイトル
*/
private void updateToolbarSubtitle(Toolbar toolbar, String subtitle) {
getActivity().runOnUiThread(() -> {
toolbar.setSubtitle(subtitle);
});
}
/**
* ToolbarをInitする
*

View File

@ -13,7 +13,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.CollapsingToolbarLayout
<com.google.android.material.appbar.SubtitleCollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
app:contentScrim="@color/colorSecondaryContainer"
android:background="@color/colorSurface"
@ -35,7 +35,7 @@
app:layout_collapseMode="pin"
app:title="HOGE" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.SubtitleCollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>