Skip to content

Commit

Permalink
[ADDED] implement function to add categories
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruan625Br committed Jul 18, 2023
1 parent 04e7dec commit 30bf56b
Show file tree
Hide file tree
Showing 13 changed files with 292 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,8 @@ dependencies {
// https://mvnrepository.com/artifact/net.sf.sevenzipjbinding/sevenzipjbinding
implementation("net.sf.sevenzipjbinding:sevenzipjbinding:16.02-2.01")

//Google
implementation 'com.google.code.gson:gson:2.10.1'


}
Original file line number Diff line number Diff line change
Expand Up @@ -993,8 +993,8 @@ class HomeFragment : Fragment(), PopupSettingsListener, androidx.appcompat.view.


private fun showBottomSheetMoreActionFile(fileItem: FileModel) {

val isArchive = MimeTypeUtil().isSpecificFileType(
val mimeType = fileUtil.getMimeType(null, fileItem.filePath)
val isArchive = if (mimeType == null) false else MimeTypeUtil().isSpecificFileType(
fileUtil.getMimeType(null, fileItem.filePath).toString(), MimeTypeIcon.ARCHIVE
)

Expand Down
45 changes: 32 additions & 13 deletions app/src/main/java/com/etb/filemanager/fragment/RecentFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import android.provider.Settings
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import androidx.activity.OnBackPressedCallback
Expand All @@ -38,11 +39,11 @@ import com.etb.filemanager.manager.util.FileUtils
import com.etb.filemanager.manager.util.FileUtils.SpaceType
import com.etb.filemanager.manager.util.MaterialDialogUtils
import com.etb.filemanager.settings.preference.Preferences
import com.etb.filemanager.ui.view.ModalBottomSheetAddCategory
import com.google.android.material.progressindicator.CircularProgressIndicator
import com.google.android.material.progressindicator.LinearProgressIndicator
import kotlinx.coroutines.*
import java.nio.file.Path
import java.nio.file.Paths

// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
Expand All @@ -67,6 +68,8 @@ class RecentFragment : Fragment(), ItemListener {
private lateinit var cInternalStorage: ConstraintLayout
private lateinit var cCategoryFileItem: ConstraintLayout
private lateinit var cBaseItem: ConstraintLayout
private lateinit var btnAddCategory: Button
private lateinit var adapter: CategoryFileModelAdapter


override fun onCreate(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -101,6 +104,7 @@ class RecentFragment : Fragment(), ItemListener {
cInternalStorage = view.findViewById(R.id.cInternalStorage)
cCategoryFileItem = view.findViewById(R.id.cCategoryItem)
cRecentImg = view.findViewById(R.id.cRecentImage)
btnAddCategory = view.findViewById(R.id.btnAddCategory)

//requestStoragePermission()
// initStyleView()
Expand All @@ -123,6 +127,8 @@ class RecentFragment : Fragment(), ItemListener {

@SuppressLint("SuspiciousIndentation")
fun initCategoryItem() {
val listCategoryName = Preferences.Behavior.categoryNameList
val listCategoryPath = Preferences.Behavior.categoryPathList
val recyclerView = requireView().findViewById<RecyclerView>(R.id.recyclerView)
val dcimPath =
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).absolutePath
Expand All @@ -134,57 +140,67 @@ class RecentFragment : Fragment(), ItemListener {
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC).absolutePath
val downloadsPath =
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).absolutePath
val whatsappPath = getString(R.string.path_whatsapp)

val whatsappPath = getString(R.string.path_whatsapp)


val categoryFileModels = ArrayList<CategoryFileModel>()
categoryFileModels.add(
CategoryFileModel(
R.drawable.ic_image,
"Images",
dcimPath,
R.color.category_icon_blue
dcimPath
)
)
categoryFileModels.add(
CategoryFileModel(
R.drawable.ic_video,
"Video",
moviesPath,
R.color.category_icon_orange
moviesPath
)
)
categoryFileModels.add(
CategoryFileModel(
R.drawable.ic_document, "Document", documentsPath, R.color.category_icon_purple
R.drawable.ic_document, "Document", documentsPath
)
)
categoryFileModels.add(
CategoryFileModel(
R.drawable.ic_music,
"Music",
musicPath,
R.color.category_icon_pink
musicPath
)
)

categoryFileModels.add(
CategoryFileModel(
R.drawable.ic_download, "Download", downloadsPath, R.color.category_icon_light_red
R.drawable.ic_download, "Download", downloadsPath
)
)
categoryFileModels.add(
CategoryFileModel(
R.drawable.ic_whatsapp, "Whatsapp", whatsappPath, R.color.category_icon_green
R.drawable.ic_whatsapp, "Whatsapp", whatsappPath
)
)
if (!listCategoryName.isNullOrEmpty()) {
for ((index, name) in listCategoryName.withIndex()) {
val mName = name
val mPath = listCategoryPath[index]
categoryFileModels.add(CategoryFileModel(R.drawable.ic_folder, mName, mPath))
}
}
recyclerView.layoutManager = GridLayoutManager(requireContext(), 4)
val adapter = CategoryFileModelAdapter(this, categoryFileModels, requireContext())
adapter = CategoryFileModelAdapter(this, categoryFileModels, requireContext())
recyclerView.adapter = adapter

}

private fun showBottomSheetAddCategory() {
val modalBottomSheetAddCategory = ModalBottomSheetAddCategory()


modalBottomSheetAddCategory.show(parentFragmentManager, ModalBottomSheetAddCategory.TAG)
}

@OptIn(DelicateCoroutinesApi::class)
fun setRecentImages() {
val recyclerView = requireView().findViewById<RecyclerView>(R.id.recy_recents_images)
Expand Down Expand Up @@ -217,6 +233,8 @@ class RecentFragment : Fragment(), ItemListener {
ivSettings.setOnClickListener {
(requireActivity() as MainActivity).startNewFragment(settingsFragment)
}
btnAddCategory.setOnClickListener { showBottomSheetAddCategory() }

}

private fun openListFiles() {
Expand Down Expand Up @@ -391,6 +409,7 @@ class RecentFragment : Fragment(), ItemListener {
(requireActivity() as MainActivity).startNewFragment(homeFragment)

}

companion object {
/**
* Use this factory method to create a new instance of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package com.etb.filemanager.manager.category.adapter



class CategoryFileModel(var icon: Int, var title: String, var path: String, var backgroundTint: Int)
class CategoryFileModel(var icon: Int, var title: String, var path: String)
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public enum PreferenceKey {
//Behavior
PREF_DEFAULT_FOLDER_STR,
PREF_SELECT_FILE_LONG_CLICK_BOOL,
PREF_LIST_CATEGORIES_NAME_STR,
PREF_LIST_CATEGORIES_PATH_STR,

//Popup
PREF_SORT_BY_STR,
Expand Down Expand Up @@ -295,6 +297,11 @@ public Object getDefaultValue(@NonNull PreferenceKey key){
return mContext.getResources().getBoolean(R.bool.default_is_enabled_rounded_corners);
case PREF_DYNAMIC_COLORS_BOOL:
return mContext.getResources().getBoolean(R.bool.default_is_enabled_dynamic_colors);
case PREF_LIST_CATEGORIES_NAME_STR:
return mContext.getResources().getString(R.string.default_list_categories_name);
case PREF_LIST_CATEGORIES_PATH_STR:
return mContext.getResources().getString(R.string.default_list_categories_path);

}
throw new IllegalArgumentException("Pref key not found.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package com.etb.filemanager.settings.preference

import com.etb.filemanager.manager.files.filelist.FileSortOptions
import com.etb.filemanager.manager.files.filelist.FileSortOptions.SortBy
import com.etb.filemanager.util.file.jsonStringToList
import com.etb.filemanager.util.file.stringListToJsonString


class Preferences {
object Appearance {
Expand All @@ -12,7 +15,9 @@ class Preferences {
}
var isEnabledDynamicColors: Boolean
get() = AppPreference.getBoolean(AppPreference.PreferenceKey.PREF_DYNAMIC_COLORS_BOOL)
set(value) { AppPreference.set(AppPreference.PreferenceKey.PREF_DYNAMIC_COLORS_BOOL, value)}
set(value) {
AppPreference.set(AppPreference.PreferenceKey.PREF_DYNAMIC_COLORS_BOOL, value)
}
}

object Interface {
Expand All @@ -24,20 +29,43 @@ class Preferences {
}
var isEnabledRoundedCorners: Boolean
get() = AppPreference.getBoolean(AppPreference.PreferenceKey.PREF_ROUNDED_CORNERS_BOOL)
set(value) { AppPreference.set(AppPreference.PreferenceKey.PREF_ROUNDED_CORNERS_BOOL, value)}
set(value) {
AppPreference.set(AppPreference.PreferenceKey.PREF_ROUNDED_CORNERS_BOOL, value)
}
}

object Behavior {
var defaultFolder: String
get() = AppPreference.getString(AppPreference.PreferenceKey.PREF_DEFAULT_FOLDER_STR)
set(defaultFolder) {
AppPreference.set(AppPreference.PreferenceKey.PREF_DEFAULT_FOLDER_STR, defaultFolder)
AppPreference.set(
AppPreference.PreferenceKey.PREF_DEFAULT_FOLDER_STR, defaultFolder
)
}

var selectFileLongClick: Boolean
get() = AppPreference.getBoolean(AppPreference.PreferenceKey.PREF_SELECT_FILE_LONG_CLICK_BOOL)
set(value) {
AppPreference.set(AppPreference.PreferenceKey.PREF_SELECT_FILE_LONG_CLICK_BOOL, value)
AppPreference.set(
AppPreference.PreferenceKey.PREF_SELECT_FILE_LONG_CLICK_BOOL, value
)
}

var categoryNameList: List<String>
get() = jsonStringToList(AppPreference.getString(AppPreference.PreferenceKey.PREF_LIST_CATEGORIES_NAME_STR))
set(value) {
AppPreference.set(
AppPreference.PreferenceKey.PREF_LIST_CATEGORIES_NAME_STR,
stringListToJsonString(value)
)
}
var categoryPathList: List<String>
get() = jsonStringToList(AppPreference.getString(AppPreference.PreferenceKey.PREF_LIST_CATEGORIES_PATH_STR))
set(value) {
AppPreference.set(
AppPreference.PreferenceKey.PREF_LIST_CATEGORIES_PATH_STR,
stringListToJsonString(value)
)
}
}

Expand All @@ -50,7 +78,9 @@ class Preferences {
var isDirectoriesFirst: Boolean
get() = AppPreference.getBoolean(AppPreference.PreferenceKey.PREF_DIRECTORIES_FIRST_BOOL)
set(directoriesFirst) {
AppPreference.set(AppPreference.PreferenceKey.PREF_DIRECTORIES_FIRST_BOOL, directoriesFirst)
AppPreference.set(
AppPreference.PreferenceKey.PREF_DIRECTORIES_FIRST_BOOL, directoriesFirst
)
}

var orderFiles: FileSortOptions.Order
Expand All @@ -65,6 +95,8 @@ class Preferences {
}
var isGridEnabled: Boolean
get() = AppPreference.getBoolean(AppPreference.PreferenceKey.PREF_GRID_TOGGLE_BOOL)
set(value) {AppPreference.set(AppPreference.PreferenceKey.PREF_GRID_TOGGLE_BOOL, value)}
set(value) {
AppPreference.set(AppPreference.PreferenceKey.PREF_GRID_TOGGLE_BOOL, value)
}
}
}
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"

}
}
Loading

0 comments on commit 30bf56b

Please sign in to comment.