-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADDED] implement function to add categories
- Loading branch information
Showing
13 changed files
with
292 additions
and
37 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
app/src/main/java/com/etb/filemanager/ui/view/ModalBottomSheetAddCategory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.etb.filemanager.ui.view | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.Button | ||
import com.etb.filemanager.R | ||
import com.etb.filemanager.settings.preference.Preferences | ||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment | ||
import com.google.android.material.textfield.TextInputEditText | ||
import com.google.android.material.textfield.TextInputLayout | ||
import java.io.File | ||
|
||
class ModalBottomSheetAddCategory : BottomSheetDialogFragment() { | ||
|
||
private lateinit var eCategoryName: TextInputLayout | ||
private lateinit var eCategoryPath: TextInputLayout | ||
private lateinit var dCategoryName: TextInputEditText | ||
private lateinit var dCategoryPath: TextInputEditText | ||
private lateinit var btnAddCategory: Button | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? | ||
): View? = inflater.inflate(R.layout.bottom_sheet_add_category, container, false) | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
eCategoryName = view.findViewById(R.id.eInputLayoutName) | ||
eCategoryPath = view.findViewById(R.id.eInputLayoutPath) | ||
dCategoryName = view.findViewById(R.id.categoryName) | ||
dCategoryPath = view.findViewById(R.id.categoryPath) | ||
btnAddCategory = view.findViewById(R.id.addCategory) | ||
|
||
btnAddCategory.setOnClickListener { | ||
val categoryName = dCategoryName.text?.trim().toString() | ||
val categoryPath = dCategoryPath.text?.trim().toString() | ||
|
||
val file = File(categoryPath) | ||
|
||
var isValid = true | ||
|
||
if (categoryName.isEmpty()) { | ||
eCategoryName.error = getString(R.string.error_empty) | ||
isValid = false | ||
} else { | ||
eCategoryName.error = null | ||
} | ||
|
||
if (categoryPath.isEmpty()) { | ||
eCategoryPath.error = getString(R.string.error_empty) | ||
isValid = false | ||
} else { | ||
eCategoryPath.error = null | ||
} | ||
|
||
if (!file.exists() || file.isFile) { | ||
eCategoryPath.error = getString(R.string.invalid_path) | ||
isValid = false | ||
} else { | ||
eCategoryPath.error = null | ||
|
||
} | ||
|
||
|
||
if (isValid) { | ||
dismiss() | ||
addCategory(categoryName, categoryPath) | ||
} | ||
} | ||
} | ||
|
||
private fun addCategory(name: String, path: String) { | ||
val listNameCategory = Preferences.Behavior.categoryNameList.toMutableList() | ||
val listPathCategory = Preferences.Behavior.categoryPathList.toMutableList() | ||
|
||
listNameCategory.add(name) | ||
listPathCategory.add(path) | ||
|
||
Preferences.Behavior.categoryNameList = listNameCategory.toList() | ||
Preferences.Behavior.categoryPathList = listPathCategory.toList() | ||
} | ||
|
||
companion object { | ||
const val TAG = "ModalBottomSheetAddCategory" | ||
|
||
} | ||
} |
Oops, something went wrong.