Skip to content

Commit

Permalink
[DEV][about feature is completed]
Browse files Browse the repository at this point in the history
  • Loading branch information
Emre Esen authored and Emre Esen committed Feb 13, 2024
1 parent 351744c commit 2f74a94
Show file tree
Hide file tree
Showing 28 changed files with 672 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
.cxx
local.properties
app/release/
app/google-services.json
3 changes: 2 additions & 1 deletion app/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/build
/build
google-services.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,11 @@ fun Context.shareFiles(uris: List<Uri>): Boolean {
false
}
}

fun Context.startActivitySafely(intent: Intent) {
try {
startActivity(intent)
} catch (e: ActivityNotFoundException) {
// Todo
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.sn.snfilemanager.feature.about

import android.content.Intent
import android.net.Uri
import androidx.navigation.fragment.findNavController
import com.sn.snfilemanager.core.base.BaseFragment
import com.sn.snfilemanager.core.extensions.click
import com.sn.snfilemanager.core.extensions.startActivitySafely
import com.sn.snfilemanager.databinding.FragmentAboutBinding
import com.sn.snfilemanager.view.dialog.license.LicenseDialog

class AboutFragment : BaseFragment<FragmentAboutBinding, AboutViewModel>() {
override fun getViewModelClass() = AboutViewModel::class.java

override fun getViewBinding() = FragmentAboutBinding.inflate(layoutInflater)

companion object {
const val GITHUB_URL =
"https://github.com/emreesen27/Android-Sn-File-Manager"
const val PRIVACY_URL =
"https://github.com/emreesen27/Android-Sn-File-Manager/blob/develop/PRIVACY.md"
}

override fun setupViews() {
binding.vm = viewModel
binding.lifecycleOwner = viewLifecycleOwner
initClicks()
}

private fun initClicks() {
binding.toolbar.setNavigationOnClickListener { findNavController().popBackStack() }
binding.btnGithub.click { openUrl(GITHUB_URL) }
binding.btnLicense.click { showLicensesDialog() }
binding.btnPrivacy.click { openUrl(PRIVACY_URL) }
}

private fun showLicensesDialog() {
LicenseDialog().show(childFragmentManager, LicenseDialog.TAG)
}

private fun openUrl(url: String) {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
context?.startActivitySafely(intent)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.sn.snfilemanager.feature.about

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.sn.snfilemanager.BuildConfig

class AboutViewModel : ViewModel() {
private val _versionLiveData: MutableLiveData<String> = MutableLiveData()
val versionLiveData: LiveData<String> = _versionLiveData

init {
getVersion()
}

private fun getVersion() {
_versionLiveData.value = BuildConfig.VERSION_NAME
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ class HomeFragment : BaseFragment<FragmentHomeBinding, HomeViewModel>() {
btnSettings.click {
navigate(HomeFragmentDirections.actionSettings())
}
btnAbout.click {
navigate(HomeFragmentDirections.actionAbout())
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.content.SharedPreferences
import android.content.SharedPreferences.OnSharedPreferenceChangeListener
import android.os.Bundle
import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreferenceCompat
import com.sn.snfilemanager.R
Expand All @@ -19,13 +18,6 @@ class SettingsFragment : PreferenceFragmentCompat() {
) {
setPreferencesFromResource(R.xml.preferences, rootKey)

val aboutButton: Preference? = findPreference(SettingsUtils.SN_ABOUT)
aboutButton?.setOnPreferenceClickListener {
// todo
// findNavController().navigate(SettingsFragmentDirections.actionSettingsToAbout())
true
}

val themeListPreference: ListPreference? = findPreference(SettingsUtils.SN_THEME_MODE)
val hiddenFilePreference: SwitchPreferenceCompat? =
findPreference(SettingsUtils.SN_HIDDEN_FILE)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.sn.snfilemanager.feature.settings

import android.content.Context
import android.util.AttributeSet
import androidx.navigation.findNavController
import androidx.preference.Preference
import androidx.preference.PreferenceViewHolder
import com.google.android.material.appbar.MaterialToolbar
import com.sn.snfilemanager.R

class SettingsToolbar
@JvmOverloads
constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
) : Preference(context, attrs, defStyleAttr) {
override fun onBindViewHolder(holder: PreferenceViewHolder) {
super.onBindViewHolder(holder)

val toolbar = holder.findViewById(R.id.toolbar_settings) as MaterialToolbar
toolbar.setNavigationOnClickListener {
toolbar.findNavController().popBackStack()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import androidx.appcompat.app.AppCompatDelegate
import androidx.preference.PreferenceManager

object SettingsUtils {
const val SECRETIVE_REPOSITORY_LINK = "https://github.com/emreesen27/Secretive"

const val SN_THEME_MODE = "sn.theme.mode"
const val SN_ABOUT = "sn.about"
const val SN_HIDDEN_FILE = "sn.hidden.file"

const val SYSTEM = "System"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import androidx.appcompat.widget.AppCompatImageView
import androidx.constraintlayout.widget.ConstraintLayout
import com.google.android.material.textview.MaterialTextView
import com.sn.snfilemanager.R
import com.sn.snfilemanager.core.extensions.gone
import com.sn.snfilemanager.core.extensions.visible

class HrImageButton
@JvmOverloads
Expand All @@ -23,10 +25,11 @@ class HrImageButton
titleTextView.text = value
}

var subTitle: String
var subTitle: String?
get() = subTitleTextView.text.toString()
set(value) {
subTitleTextView.text = value
checkSubTitle()
}

init {
Expand All @@ -44,4 +47,12 @@ class HrImageButton

attributes.recycle()
}

private fun checkSubTitle() {
if (subTitle.isNullOrEmpty()) {
subTitleTextView.gone()
} else {
subTitleTextView.visible()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.sn.snfilemanager.view.dialog.license

data class License(
val name: String,
val url: String,
val license: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.sn.snfilemanager.view.dialog.license

import android.content.Context
import android.content.Intent
import android.net.Uri
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.sn.snfilemanager.core.extensions.click
import com.sn.snfilemanager.core.extensions.startActivitySafely
import com.sn.snfilemanager.databinding.ItemLicenseBinding

class LicenseAdapter(private val context: Context) :
RecyclerView.Adapter<LicenseAdapter.LicenseViewHolder>() {
private val licenses: List<License> =
listOf(
License(
"Glide",
"https://github.com/bumptech/glide",
"https://github.com/bumptech/glide/blob/master/LICENSE",
),
License(
"Nested Progress",
"https://github.com/emreesen27/Android-Nested-Progress",
"https://github.com/emreesen27/Android-Nested-Progress/blob/master/LICENSE",
),
License(
"Toasty",
"https://github.com/GrenderG/Toasty",
"https://github.com/GrenderG/Toasty/blob/master/LICENSE",
),
License(
"Lottie Android",
"https://github.com/airbnb/lottie-android",
"https://github.com/airbnb/lottie-android/blob/master/LICENSE",
),
License(
"Ssp",
"https://github.com/intuit/ssp",
"https://github.com/intuit/ssp/blob/master/LICENSE",
),
License(
"Android Animation",
"https://github.com/gayanvoice/android-animations",
"https://github.com/gayanvoice/android-animations/blob/master/LICENSE",
),
)

override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int,
): LicenseAdapter.LicenseViewHolder {
val binding =
ItemLicenseBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return LicenseViewHolder(binding)
}

override fun onBindViewHolder(
holder: LicenseAdapter.LicenseViewHolder,
position: Int,
) {
holder.bind(licenses[position])
}

override fun getItemCount(): Int {
return licenses.size
}

inner class LicenseViewHolder(private val binding: ItemLicenseBinding) :
RecyclerView.ViewHolder(binding.root) {
init {
binding.mtvGithub.click {
if (adapterPosition != RecyclerView.NO_POSITION) {
val clickedLicense = licenses[adapterPosition]
openUrl(clickedLicense.url)
}
}
binding.mtvLicense.click {
if (adapterPosition != RecyclerView.NO_POSITION) {
val clickedLicense = licenses[adapterPosition]
openUrl(clickedLicense.license)
}
}
}

fun bind(model: License) {
binding.mtvName.text = model.name
}
}

private fun openUrl(url: String) {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
context.startActivitySafely(intent)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.sn.snfilemanager.view.dialog.license

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.fragment.app.DialogFragment
import com.sn.snfilemanager.R
import com.sn.snfilemanager.core.extensions.click
import com.sn.snfilemanager.databinding.DialogLicenseBinding

class LicenseDialog : DialogFragment() {
companion object {
const val TAG = "LICENSE_DIALOG"
}

private val binding: DialogLicenseBinding by lazy {
DialogLicenseBinding.inflate(layoutInflater)
}

override fun onStart() {
super.onStart()
dialog?.window?.setLayout(
ConstraintLayout.LayoutParams.MATCH_PARENT,
ConstraintLayout.LayoutParams.MATCH_PARENT,
)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(STYLE_NO_TITLE, R.style.DialogTheme_transparent)
dialog?.window?.setBackgroundDrawableResource(R.drawable.dialog_rounded)
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?,
): View {
return binding.root
}

override fun onViewCreated(
view: View,
savedInstanceState: Bundle?,
) {
super.onViewCreated(view, savedInstanceState)
binding.recycler.adapter = LicenseAdapter(requireContext())
binding.ivClose.click { dismiss() }
}
}
15 changes: 15 additions & 0 deletions app/src/main/res/drawable/ic_app_icon_small.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="128"
android:viewportHeight="128">
<path
android:fillColor="@color/main_color"
android:pathData="M64,64m-64,0a64,64 0,1 1,128 0a64,64 0,1 1,-128 0" />
<path
android:fillColor="#FFFFFF"
android:pathData="M32.5,43H104c0,-2.2 -1.8,-4 -4,-4H47.5l-1.3,-2.1c-0.7,-1.2 -2,-1.9 -3.4,-1.9H28c-2.2,0 -4,1.8 -4,4v20v25.7l4.6,-38.1C28.8,44.5 30.5,43 32.5,43z" />
<path
android:fillColor="#FFFFFF"
android:pathData="M108.5,47h-72c-2,0 -3.7,1.5 -4,3.5l-5,42c-0.3,2.4 1.6,4.5 4,4.5h71.9c2,0 3.7,-1.5 4,-3.5l5,-42C112.7,49.1 110.9,47 108.5,47z" />
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_circle_small.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="6dp"
android:height="6dp"
android:tint="@color/first_text_color"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/first_text_color"
android:pathData="M12,2C6.47,2 2,6.47 2,12s4.47,10 10,10 10,-4.47 10,-10S17.53,2 12,2z" />
</vector>
15 changes: 15 additions & 0 deletions app/src/main/res/drawable/ic_github.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#00000000"
android:fillType="evenOdd"
android:pathData="M12,2C6.475,2 2,6.475 2,12C2,16.425 4.863,20.163 8.837,21.487C9.337,21.575 9.525,21.275 9.525,21.013C9.525,20.775 9.512,19.987 9.512,19.15C7,19.612 6.35,18.538 6.15,17.975C6.037,17.688 5.55,16.8 5.125,16.563C4.775,16.375 4.275,15.913 5.113,15.9C5.9,15.887 6.463,16.625 6.65,16.925C7.55,18.438 8.988,18.013 9.563,17.75C9.65,17.1 9.913,16.663 10.2,16.413C7.975,16.163 5.65,15.3 5.65,11.475C5.65,10.387 6.037,9.488 6.675,8.788C6.575,8.538 6.225,7.512 6.775,6.137C6.775,6.137 7.613,5.875 9.525,7.162C10.325,6.938 11.175,6.825 12.025,6.825C12.875,6.825 13.725,6.938 14.525,7.162C16.438,5.863 17.275,6.137 17.275,6.137C17.825,7.512 17.475,8.538 17.375,8.788C18.013,9.488 18.4,10.375 18.4,11.475C18.4,15.313 16.063,16.163 13.837,16.413C14.2,16.725 14.512,17.325 14.512,18.263C14.512,19.6 14.5,20.675 14.5,21.013C14.5,21.275 14.688,21.587 15.188,21.487C17.173,20.817 18.898,19.542 20.12,17.84C21.342,16.138 22,14.095 22,12C22,6.475 17.525,2 12,2Z"
android:strokeWidth="1.3"
android:strokeColor="@color/first_text_color"
android:strokeLineJoin="round"
tools:ignore="VectorPath" />
</vector>
Loading

0 comments on commit 2f74a94

Please sign in to comment.