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

Commit

Permalink
fix: show empty state hints for bottom sheet fragments (closes #1157, c…
Browse files Browse the repository at this point in the history
…loses #1158)
  • Loading branch information
itsaky committed Jul 31, 2023
1 parent bd0bfe8 commit 94bbd0a
Show file tree
Hide file tree
Showing 18 changed files with 398 additions and 268 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import com.itsaky.androidide.fragments.DiagnosticsListFragment;
import com.itsaky.androidide.fragments.IDELogFragment;
import com.itsaky.androidide.fragments.SearchResultFragment;
import com.itsaky.androidide.fragments.SimpleOutputFragment;
import com.itsaky.androidide.fragments.BuildOutputFragment;
import com.itsaky.androidide.utils.ILogger;

import java.util.ArrayList;
Expand All @@ -48,7 +48,7 @@ public EditorBottomSheetTabAdapter(@NonNull FragmentActivity fragmentActivity) {
this.fragments.add(
new Tab(
fragmentActivity.getString(R.string.build_output),
SimpleOutputFragment.class,
BuildOutputFragment.class,
++index));
this.fragments.add(
new Tab(fragmentActivity.getString(R.string.app_logs), AppLogFragment.class, ++index));
Expand Down Expand Up @@ -117,8 +117,8 @@ public String getTitle(int position) {
}

@Nullable
public SimpleOutputFragment getBuildOutputFragment() {
return findFragmentByClass(SimpleOutputFragment.class);
public BuildOutputFragment getBuildOutputFragment() {
return findFragmentByClass(BuildOutputFragment.class);
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ package com.itsaky.androidide.fragments
import android.os.Bundle
import android.view.View
import com.blankj.utilcode.util.ThreadUtils
import com.itsaky.androidide.R

class SimpleOutputFragment : NonEditableEditorFragment() {
class BuildOutputFragment : NonEditableEditorFragment() {
private val unsavedLines: MutableList<String?> = ArrayList()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
emptyStateViewModel.emptyMessage.value = getString(R.string.msg_emptyview_buildoutput)
if (unsavedLines.isNotEmpty()) {
for (line in unsavedLines) {
editor?.append("${line!!.trim()}\n")
Expand All @@ -48,7 +50,9 @@ class SimpleOutputFragment : NonEditableEditorFragment() {
} else {
"${output}\n"
}
editor!!.append(message)
editor!!.append(message).also {
emptyStateViewModel.isEmpty.value = false
}
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* This file is part of AndroidIDE.
*
* AndroidIDE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* AndroidIDE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
*/
package com.itsaky.androidide.fragments

import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.itsaky.androidide.R
import com.itsaky.androidide.adapters.DiagnosticsAdapter

class DiagnosticsListFragment : RecyclerViewFragment<DiagnosticsAdapter>() {

override fun onCreateAdapter(): RecyclerView.Adapter<*> {
return DiagnosticsAdapter(ArrayList(), null)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
emptyStateViewModel.emptyMessage.value = getString(R.string.msg_emptyview_diagnostics)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* This file is part of AndroidIDE.
*
* AndroidIDE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* AndroidIDE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
*/

package com.itsaky.androidide.fragments

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.viewModels
import androidx.viewbinding.ViewBinding
import com.itsaky.androidide.databinding.FragmentEmptyStateBinding
import com.itsaky.androidide.viewmodel.EmptyStateFragmentViewModel

/**
* A fragment that shows a message when there is no data to show in the subclass fragment.
*
* @author Akash Yadav
*/
abstract class EmptyStateFragment<T : ViewBinding>(layout: Int,
bind: (View) -> T) : FragmentWithBinding<T>(layout, bind) {

protected var emptyStateBinding: FragmentEmptyStateBinding? = null
private set

protected val emptyStateViewModel by viewModels<EmptyStateFragmentViewModel>()

internal var isEmpty: Boolean
get() = emptyStateViewModel.isEmpty.value ?: false
set(value) {
emptyStateViewModel.isEmpty.value = value
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View {

return FragmentEmptyStateBinding.inflate(inflater, container, false).also { emptyStateBinding ->
this.emptyStateBinding = emptyStateBinding

// add the main fragment view
emptyStateBinding.root.addView(
super.onCreateView(inflater, emptyStateBinding.root, savedInstanceState)
)
}.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

emptyStateViewModel.isEmpty.observe(viewLifecycleOwner) { isEmpty ->
emptyStateBinding?.apply {
root.displayedChild = if (isEmpty) 0 else 1
}
}

emptyStateViewModel.emptyMessage.observe(viewLifecycleOwner) { message ->
emptyStateBinding?.emptyView?.message = message
}
}

override fun onDestroyView() {
this.emptyStateBinding = null
super.onDestroyView()
}
}
13 changes: 13 additions & 0 deletions app/src/main/java/com/itsaky/androidide/fragments/LogFragments.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

package com.itsaky.androidide.fragments

import android.os.Bundle
import android.view.View
import com.itsaky.androidide.R
import com.itsaky.androidide.utils.ILogger

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

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
emptyStateViewModel.emptyMessage.value = getString(R.string.msg_emptyview_idelogs)
}

override fun onDestroy() {
super.onDestroy()
ILogger.removeLogListener(logListener)
Expand All @@ -57,4 +65,9 @@ class IDELogFragment : LogViewFragment() {
class AppLogFragment : LogViewFragment() {
override fun isSimpleFormattingEnabled() = false
override fun getFilename() = "app_logs"

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
emptyStateViewModel.emptyMessage.value = getString(R.string.msg_emptyview_applogs)
}
}
Loading

0 comments on commit 94bbd0a

Please sign in to comment.