Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit 94bbd0a

Browse files
committed
fix: show empty state hints for bottom sheet fragments (closes #1157, closes #1158)
1 parent bd0bfe8 commit 94bbd0a

File tree

18 files changed

+398
-268
lines changed

18 files changed

+398
-268
lines changed

app/src/main/java/com/itsaky/androidide/adapters/EditorBottomSheetTabAdapter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import com.itsaky.androidide.fragments.DiagnosticsListFragment;
3030
import com.itsaky.androidide.fragments.IDELogFragment;
3131
import com.itsaky.androidide.fragments.SearchResultFragment;
32-
import com.itsaky.androidide.fragments.SimpleOutputFragment;
32+
import com.itsaky.androidide.fragments.BuildOutputFragment;
3333
import com.itsaky.androidide.utils.ILogger;
3434

3535
import java.util.ArrayList;
@@ -48,7 +48,7 @@ public EditorBottomSheetTabAdapter(@NonNull FragmentActivity fragmentActivity) {
4848
this.fragments.add(
4949
new Tab(
5050
fragmentActivity.getString(R.string.build_output),
51-
SimpleOutputFragment.class,
51+
BuildOutputFragment.class,
5252
++index));
5353
this.fragments.add(
5454
new Tab(fragmentActivity.getString(R.string.app_logs), AppLogFragment.class, ++index));
@@ -117,8 +117,8 @@ public String getTitle(int position) {
117117
}
118118

119119
@Nullable
120-
public SimpleOutputFragment getBuildOutputFragment() {
121-
return findFragmentByClass(SimpleOutputFragment.class);
120+
public BuildOutputFragment getBuildOutputFragment() {
121+
return findFragmentByClass(BuildOutputFragment.class);
122122
}
123123

124124
@Nullable

app/src/main/java/com/itsaky/androidide/fragments/SimpleOutputFragment.kt renamed to app/src/main/java/com/itsaky/androidide/fragments/BuildOutputFragment.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ package com.itsaky.androidide.fragments
1919
import android.os.Bundle
2020
import android.view.View
2121
import com.blankj.utilcode.util.ThreadUtils
22+
import com.itsaky.androidide.R
2223

23-
class SimpleOutputFragment : NonEditableEditorFragment() {
24+
class BuildOutputFragment : NonEditableEditorFragment() {
2425
private val unsavedLines: MutableList<String?> = ArrayList()
2526
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
2627
super.onViewCreated(view, savedInstanceState)
28+
emptyStateViewModel.emptyMessage.value = getString(R.string.msg_emptyview_buildoutput)
2729
if (unsavedLines.isNotEmpty()) {
2830
for (line in unsavedLines) {
2931
editor?.append("${line!!.trim()}\n")
@@ -48,7 +50,9 @@ class SimpleOutputFragment : NonEditableEditorFragment() {
4850
} else {
4951
"${output}\n"
5052
}
51-
editor!!.append(message)
53+
editor!!.append(message).also {
54+
emptyStateViewModel.isEmpty.value = false
55+
}
5256
}
5357
}
5458
}

app/src/main/java/com/itsaky/androidide/fragments/DiagnosticsListFragment.java

Lines changed: 0 additions & 95 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* This file is part of AndroidIDE.
3+
*
4+
* AndroidIDE is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* AndroidIDE is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
package com.itsaky.androidide.fragments
18+
19+
import android.os.Bundle
20+
import android.view.View
21+
import androidx.recyclerview.widget.RecyclerView
22+
import com.itsaky.androidide.R
23+
import com.itsaky.androidide.adapters.DiagnosticsAdapter
24+
25+
class DiagnosticsListFragment : RecyclerViewFragment<DiagnosticsAdapter>() {
26+
27+
override fun onCreateAdapter(): RecyclerView.Adapter<*> {
28+
return DiagnosticsAdapter(ArrayList(), null)
29+
}
30+
31+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
32+
super.onViewCreated(view, savedInstanceState)
33+
emptyStateViewModel.emptyMessage.value = getString(R.string.msg_emptyview_diagnostics)
34+
}
35+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* This file is part of AndroidIDE.
3+
*
4+
* AndroidIDE is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* AndroidIDE is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.itsaky.androidide.fragments
19+
20+
import android.os.Bundle
21+
import android.view.LayoutInflater
22+
import android.view.View
23+
import android.view.ViewGroup
24+
import androidx.fragment.app.viewModels
25+
import androidx.viewbinding.ViewBinding
26+
import com.itsaky.androidide.databinding.FragmentEmptyStateBinding
27+
import com.itsaky.androidide.viewmodel.EmptyStateFragmentViewModel
28+
29+
/**
30+
* A fragment that shows a message when there is no data to show in the subclass fragment.
31+
*
32+
* @author Akash Yadav
33+
*/
34+
abstract class EmptyStateFragment<T : ViewBinding>(layout: Int,
35+
bind: (View) -> T) : FragmentWithBinding<T>(layout, bind) {
36+
37+
protected var emptyStateBinding: FragmentEmptyStateBinding? = null
38+
private set
39+
40+
protected val emptyStateViewModel by viewModels<EmptyStateFragmentViewModel>()
41+
42+
internal var isEmpty: Boolean
43+
get() = emptyStateViewModel.isEmpty.value ?: false
44+
set(value) {
45+
emptyStateViewModel.isEmpty.value = value
46+
}
47+
48+
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
49+
savedInstanceState: Bundle?): View {
50+
51+
return FragmentEmptyStateBinding.inflate(inflater, container, false).also { emptyStateBinding ->
52+
this.emptyStateBinding = emptyStateBinding
53+
54+
// add the main fragment view
55+
emptyStateBinding.root.addView(
56+
super.onCreateView(inflater, emptyStateBinding.root, savedInstanceState)
57+
)
58+
}.root
59+
}
60+
61+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
62+
super.onViewCreated(view, savedInstanceState)
63+
64+
emptyStateViewModel.isEmpty.observe(viewLifecycleOwner) { isEmpty ->
65+
emptyStateBinding?.apply {
66+
root.displayedChild = if (isEmpty) 0 else 1
67+
}
68+
}
69+
70+
emptyStateViewModel.emptyMessage.observe(viewLifecycleOwner) { message ->
71+
emptyStateBinding?.emptyView?.message = message
72+
}
73+
}
74+
75+
override fun onDestroyView() {
76+
this.emptyStateBinding = null
77+
super.onDestroyView()
78+
}
79+
}

app/src/main/java/com/itsaky/androidide/fragments/LogFragments.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
package com.itsaky.androidide.fragments
1919

20+
import android.os.Bundle
21+
import android.view.View
22+
import com.itsaky.androidide.R
2023
import com.itsaky.androidide.utils.ILogger
2124

2225
/**
@@ -43,6 +46,11 @@ class IDELogFragment : LogViewFragment() {
4346
override fun isSimpleFormattingEnabled() = true
4447
override fun getFilename() = "ide_logs"
4548

49+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
50+
super.onViewCreated(view, savedInstanceState)
51+
emptyStateViewModel.emptyMessage.value = getString(R.string.msg_emptyview_idelogs)
52+
}
53+
4654
override fun onDestroy() {
4755
super.onDestroy()
4856
ILogger.removeLogListener(logListener)
@@ -57,4 +65,9 @@ class IDELogFragment : LogViewFragment() {
5765
class AppLogFragment : LogViewFragment() {
5866
override fun isSimpleFormattingEnabled() = false
5967
override fun getFilename() = "app_logs"
68+
69+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
70+
super.onViewCreated(view, savedInstanceState)
71+
emptyStateViewModel.emptyMessage.value = getString(R.string.msg_emptyview_applogs)
72+
}
6073
}

0 commit comments

Comments
 (0)