Skip to content

Commit

Permalink
Add intermediate dialog for initial settings
Browse files Browse the repository at this point in the history
  • Loading branch information
AbandonedCart committed Apr 6, 2024
1 parent 522871a commit 41c7652
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 4 deletions.
18 changes: 14 additions & 4 deletions app/src/main/java/com/hiddenramblings/tagmo/BrowserActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import com.hiddenramblings.tagmo.eightbit.util.Zip
import com.hiddenramblings.tagmo.eightbit.view.AnimatedLinearLayout
import com.hiddenramblings.tagmo.eightbit.widget.FABulous
import com.hiddenramblings.tagmo.eightbit.widget.ProgressAlert
import com.hiddenramblings.tagmo.fragment.FittedSheets
import com.hiddenramblings.tagmo.fragment.BrowserFragment
import com.hiddenramblings.tagmo.fragment.SettingsFragment
import com.hiddenramblings.tagmo.hexcode.HexCodeViewer
Expand Down Expand Up @@ -1396,10 +1397,19 @@ class BrowserActivity : AppCompatActivity(), BrowserSettingsListener,
@Throws(ActivityNotFoundException::class)
fun onDocumentRequested() {
if (Version.isLollipop) {
onDocumentTree.launch(Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
.putExtra("android.content.extra.SHOW_ADVANCED", true)
.putExtra("android.content.extra.FANCY", true)
)
FittedSheets.newInstance().apply {
setTitleText(this@BrowserActivity.getString(R.string.storage_setup))
setPositiveButton(this@BrowserActivity.getString(R.string.proceed)) {
onDocumentTree.launch(
Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
.putExtra("android.content.extra.SHOW_ADVANCED", true)
.putExtra("android.content.extra.FANCY", true)
)
}
setNegativeButton(this@BrowserActivity.getString(R.string.close)) {
finish()
}
}.show(supportFragmentManager, "storage")
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.hiddenramblings.tagmo.fragment

import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.LinearLayout
import android.widget.TextView
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.hiddenramblings.tagmo.R


class FittedSheets: BottomSheetDialogFragment() {

private val viewList = mutableListOf<View>()
fun addView(view: View) {
viewList.add(view)
}

var title: String? = null
fun setTitleText(string: String) {
title = string
}

private var negativeText: String? = null
private var negativeCallback: (() -> Unit)? = null
fun setNegativeButton(text: String, callback: (() -> Unit)) {
negativeText = text
negativeCallback = callback
}

private var positiveText: String? = null
private var positiveCallback: (() -> Unit)? = null
fun setPositiveButton(text: String, callback: (() -> Unit)) {
positiveText = text
positiveCallback = callback
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
val view = inflater.inflate(R.layout.fitted_sheets, container, false)
val window = dialog?.window
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window?.statusBarColor = Color.TRANSPARENT
}
return view
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
view.findViewById<TextView>(R.id.bottomSheetsTitle).text = title
viewList.forEach {
view.findViewById<LinearLayout>(R.id.bottomSheetsContainer).addView(it)
}

if (negativeText != null) view.findViewById<Button>(R.id.bottomSheetsNegative).apply {
visibility = View.VISIBLE
text = negativeText
setOnClickListener {
negativeCallback?.invoke()
}
}

if (positiveText != null) view.findViewById<Button>(R.id.bottomSheetsPositive).apply {
visibility = View.VISIBLE
text = positiveText
setOnClickListener {
positiveCallback?.invoke()
}
}

}

override fun onDestroy() {
super.onDestroy()
}

companion object {
fun newInstance() = FittedSheets()
}

}
81 changes: 81 additions & 0 deletions app/src/main/res/layout/fitted_sheets.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView 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:layout_height="match_parent"
android:fillViewport="true">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/bottomSheetsTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:textAlignment="center"
android:textSize="20sp" />

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?android:attr/listDivider" />


<LinearLayout
android:id="@+id/bottomSheetsContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="32dp"
android:orientation="vertical" />

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?android:attr/listDivider" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:orientation="horizontal">

<Button
android:id="@+id/bottomSheetsNegative"
style="@style/Widget.Material3.Button.OutlinedButton"
android:layout_width="0dp"
android:layout_height="@dimen/button_height_min"
android:layout_margin="8dp"
android:layout_weight="1"
android:insetTop="0dp"
android:insetBottom="0dp"
android:padding="8dp"
android:textSize="16sp"
android:visibility="gone"
app:cornerRadius="16dp"
app:strokeColor="?attr/colorPrimaryContainer"
tools:ignore="SpeakableTextPresentCheck"
tools:visibility="visible" />

<Button
android:id="@+id/bottomSheetsPositive"
style="@style/Widget.Material3.Button.OutlinedButton"
android:layout_width="0dp"
android:layout_height="@dimen/button_height_min"
android:layout_margin="8dp"
android:layout_weight="1"
android:insetTop="0dp"
android:insetBottom="0dp"
android:padding="8dp"
android:textSize="16sp"
android:visibility="gone"
app:cornerRadius="16dp"
app:strokeColor="?attr/colorPrimaryContainer"
tools:ignore="SpeakableTextPresentCheck"
tools:visibility="visible" />
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@
<string name="physical_storage_root">Browse Physical Storage</string>
<string name="grant_file_permission">Enable "All Files" Manager</string>
<string name="force_document_storage">Enable Document Storage</string>
<string name="storage_setup">Please configure a root folder</string>
<string name="unzip_archive">Extract bins from zip file</string>
<string name="refresh_browser">Refresh Browser</string>

Expand Down

0 comments on commit 41c7652

Please sign in to comment.