Skip to content

Commit

Permalink
added color scheme setting and bugs fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
T8RIN committed Jan 16, 2022
1 parent 257e70b commit 663e829
Show file tree
Hide file tree
Showing 39 changed files with 702 additions and 99 deletions.
8 changes: 6 additions & 2 deletions .idea/misc.xml

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

4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId = "ru.tech.easysearch"
minSdk = 21
targetSdk = 31
versionCode = 3
versionName = "1.0.5"
versionCode = 4
versionName = "1.0.6"
}

buildTypes {
Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 3,
"versionName": "1.0.5",
"versionCode": 4,
"versionName": "1.0.6",
"outputFile": "app-release.apk"
}
],
Expand Down
12 changes: 8 additions & 4 deletions app/src/main/java/ru/tech/easysearch/activity/BrowserActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import android.widget.ImageButton
import android.widget.ImageSwitcher
import android.widget.ImageView
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.progressindicator.LinearProgressIndicator
Expand All @@ -45,6 +46,7 @@ import ru.tech.easysearch.data.DataArrays
import ru.tech.easysearch.data.DataArrays.translateSite
import ru.tech.easysearch.data.SharedPreferencesAccess.HIDE_PANELS
import ru.tech.easysearch.data.SharedPreferencesAccess.getSetting
import ru.tech.easysearch.data.SharedPreferencesAccess.loadTheme
import ru.tech.easysearch.database.ESearchDatabase
import ru.tech.easysearch.extensions.Extensions.fetchFavicon
import ru.tech.easysearch.extensions.Extensions.generateBrowserPopupMenu
Expand Down Expand Up @@ -115,11 +117,12 @@ class BrowserActivity : AppCompatActivity(), DesktopInterface {
if (openedTabs.isEmpty()) loadOpenedTabs(progressBar)
}

@RequiresApi(Build.VERSION_CODES.M)
@SuppressLint("SetJavaScriptEnabled", "ClickableViewAccessibility")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setTheme(R.style.Theme_ESearch)
setTheme(loadTheme((this)))

database = ESearchDatabase.getInstance(this)
setCoeff()
Expand Down Expand Up @@ -254,7 +257,7 @@ class BrowserActivity : AppCompatActivity(), DesktopInterface {
startActivity(Intent(DownloadManager.ACTION_VIEW_DOWNLOADS))
}
R.drawable.ic_baseline_settings_24 -> {
SettingsFragment().show(supportFragmentManager, "custom")
SettingsFragment().show(supportFragmentManager, "settings")
}
}
sideMenu?.dismiss()
Expand Down Expand Up @@ -399,8 +402,9 @@ class BrowserActivity : AppCompatActivity(), DesktopInterface {
popupMenu?.dismiss()
super.onConfigurationChanged(newConfig)
for (i in supportFragmentManager.fragments) {
if (i.tag == "windowsOp") {
supportFragmentManager.beginTransaction().remove(i).commit()
when (i.tag) {
"windowsOp" -> supportFragmentManager.beginTransaction().remove(i).commit()
"settings" -> (i as SettingsFragment).adapter?.notifyDataSetChanged()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import ru.tech.easysearch.data.BrowserTabs.openedTabs
import ru.tech.easysearch.data.BrowserTabs.updateTabs
import ru.tech.easysearch.data.DataArrays.prefixDict
import ru.tech.easysearch.data.SharedPreferencesAccess.loadLabelList
import ru.tech.easysearch.data.SharedPreferencesAccess.loadTheme
import ru.tech.easysearch.database.ESearchDatabase
import ru.tech.easysearch.database.shortcuts.Shortcut
import ru.tech.easysearch.databinding.ActivityMainBinding
Expand Down Expand Up @@ -134,7 +135,8 @@ class MainActivity : AppCompatActivity(), LabelListChangedInterface {

@SuppressLint("SetJavaScriptEnabled")
override fun onCreate(savedInstanceState: Bundle?) {
setTheme(R.style.Theme_ESearch)

setTheme(loadTheme((this)))

super.onCreate(savedInstanceState)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package ru.tech.easysearch.adapter.color

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.DialogFragment
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.card.MaterialCardView
import com.google.android.material.imageview.ShapeableImageView
import ru.tech.easysearch.data.DataArrays.colorListNames
import ru.tech.easysearch.data.DataArrays.colorNames
import ru.tech.easysearch.data.SharedPreferencesAccess
import ru.tech.easysearch.data.SharedPreferencesAccess.loadThemeVariant
import ru.tech.easysearch.databinding.ColorItemBinding
import ru.tech.easysearch.helper.interfaces.SettingsInterface

class ColorPickerAdapter(
var context: Context,
val fragment: DialogFragment,
private var colorList: List<Pair<Int, Int>>,
private val colorInterface: SettingsInterface?
) :
RecyclerView.Adapter<ColorPickerAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(
ColorItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
)
}

private var selectedItemPos = -1
private var lastItemSelectedPos = -1

init {
selectedItemPos = colorListNames.indexOf(loadThemeVariant(context))
lastItemSelectedPos = selectedItemPos
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.image.setStrokeColorResource(colorList[position].first)
holder.image.setImageResource(colorList[position].second)
holder.text.text = colorNames[position]
val amplifier = when (position) {
0 -> SharedPreferencesAccess.RED
1 -> SharedPreferencesAccess.PINK
2 -> SharedPreferencesAccess.VIOLET
3 -> SharedPreferencesAccess.BLUE
4 -> SharedPreferencesAccess.MINT
5 -> SharedPreferencesAccess.GREEN
6 -> SharedPreferencesAccess.YELLOW
else -> SharedPreferencesAccess.ORANGE
}

val card: MaterialCardView = holder.itemView as MaterialCardView

card.isChecked = position == selectedItemPos

holder.itemView.setOnClickListener {
colorInterface?.onPickColor(amplifier)
selectedItemPos = holder.absoluteAdapterPosition
lastItemSelectedPos = if (lastItemSelectedPos == -1)
selectedItemPos
else {
notifyItemChanged(lastItemSelectedPos)
selectedItemPos
}
notifyItemChanged(selectedItemPos)
}
}

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

inner class ViewHolder(binding: ColorItemBinding) : RecyclerView.ViewHolder(binding.root) {
val image: ShapeableImageView = binding.shapeImage
val text: TextView = binding.text
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,27 @@ import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.card.MaterialCardView
import com.google.android.material.chip.Chip
import com.google.android.material.chip.ChipGroup
import com.google.android.material.divider.MaterialDivider
import com.google.android.material.imageview.ShapeableImageView
import ru.tech.easysearch.R
import ru.tech.easysearch.data.DataArrays.colorList
import ru.tech.easysearch.data.DataArrays.colorListNames
import ru.tech.easysearch.data.SharedPreferencesAccess.EYE_PROTECTION
import ru.tech.easysearch.data.SharedPreferencesAccess.HIDE_PANELS
import ru.tech.easysearch.data.SharedPreferencesAccess.SET
import ru.tech.easysearch.data.SharedPreferencesAccess.getSetting
import ru.tech.easysearch.data.SharedPreferencesAccess.loadThemeVariant
import ru.tech.easysearch.data.SharedPreferencesAccess.needToChangeBrowserSettings
import ru.tech.easysearch.data.SharedPreferencesAccess.setSetting
import ru.tech.easysearch.databinding.BrowserSettingsItemBinding
import ru.tech.easysearch.databinding.SettingHeaderItemBinding
import ru.tech.easysearch.extensions.Extensions.dipToPixels
import ru.tech.easysearch.fragment.dialog.ColorPickerDialog
import ru.tech.easysearch.model.SettingsItem


Expand Down Expand Up @@ -113,6 +121,29 @@ class BrowserSettingsAdapter(

holder.chipGroup.addView(chip)
}

if (settingsItems[0].key == EYE_PROTECTION) {
holder.card.visibility = VISIBLE
holder.shapeImage.setStrokeColorResource(
colorList[colorListNames.indexOf(
loadThemeVariant(context)
)].first
)
holder.shapeImage.setImageResource(
colorList[colorListNames.indexOf(
loadThemeVariant(context)
)].second
)
holder.card.setOnClickListener {
val fragment = ColorPickerDialog()
if (!fragment.isAdded) fragment.show(
(context as AppCompatActivity).supportFragmentManager,
"pickColor"
)
}
} else {
holder.card.visibility = GONE
}
}
}

Expand All @@ -135,6 +166,8 @@ class BrowserSettingsAdapter(
inner class ItemViewHolder(binding: BrowserSettingsItemBinding) :
RecyclerView.ViewHolder(binding.root) {
val chipGroup: ChipGroup = binding.chipGroup
val card: MaterialCardView = binding.card
val shapeImage: ShapeableImageView = binding.shapeImage
}

inner class HeaderViewHolder(binding: SettingHeaderItemBinding) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import android.webkit.WebView.HitTestResult.*
import android.widget.ImageButton
import android.widget.TextView
import android.widget.Toast
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.content.ContextCompat
Expand Down Expand Up @@ -162,11 +163,12 @@ class BrowserView : WebView {
}
}

updateBottomGestures(context)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) updateBottomGestures(context)
}

var anim: ObjectAnimator? = null

@RequiresApi(Build.VERSION_CODES.M)
fun updateBottomGestures(ctx: Context) {
val root = (ctx as? BrowserActivity)?.root
val bottomAppBar = (ctx as? BrowserActivity)?.bottomAppBar
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/ru/tech/easysearch/data/BrowserTabs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import android.content.SharedPreferences
import android.content.res.Configuration
import android.graphics.Bitmap
import android.graphics.Canvas
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.bumptech.glide.Glide
Expand Down Expand Up @@ -121,7 +123,9 @@ object BrowserTabs {
Functions.doInIoThreadWithObservingOnMain({
fetchFavicon(url)
}, {
iconView?.let { imageView -> Glide.with(this).load(it as Bitmap).into(imageView) }
iconView?.let { imageView ->
Glide.with(applicationContext).load(it as Bitmap).into(imageView)
}
})
}
}
Expand Down Expand Up @@ -187,6 +191,7 @@ object BrowserTabs {
edit().putStringSet("tabsOpened", tabs).apply()
}

@RequiresApi(Build.VERSION_CODES.M)
fun Context.updateGestures() {
for (tab in openedTabs) tab.tab.updateBottomGestures(this)
}
Expand Down
34 changes: 34 additions & 0 deletions app/src/main/java/ru/tech/easysearch/data/DataArrays.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ru.tech.easysearch.data

import ru.tech.easysearch.R

object DataArrays {
val prefixDict: Map<String, String> = mapOf(
Pair("ic_amazon_logo", "https://www.amazon.com/s?k="),
Expand Down Expand Up @@ -69,4 +71,36 @@ object DataArrays {
Pair("X-Requested-With", "com.duckduckgo.mobile.android")
)

val colorList: ArrayList<Pair<Int, Int>> = ArrayList(
listOf(
Pair(R.color.dred2, R.color.red2),
Pair(R.color.dred, R.color.red),
Pair(R.color.dviolet, R.color.violet),
Pair(R.color.dblue, R.color.blue),
Pair(R.color.dmint, R.color.mint),
Pair(R.color.dgreen, R.color.green),
Pair(R.color.dyellow, R.color.yellow),
Pair(R.color.dorange, R.color.orange)
)
)

val colorNames: ArrayList<String> = ArrayList(
listOf(
"Apple", "Berry", "UV", "Sky", "Mint", "Classic", "Lemon", "Orange"
)
)

val colorListNames: ArrayList<String> = ArrayList(
listOf(
SharedPreferencesAccess.RED,
SharedPreferencesAccess.PINK,
SharedPreferencesAccess.VIOLET,
SharedPreferencesAccess.BLUE,
SharedPreferencesAccess.MINT,
SharedPreferencesAccess.GREEN,
SharedPreferencesAccess.YELLOW,
SharedPreferencesAccess.ORANGE
)
)

}
Loading

0 comments on commit 663e829

Please sign in to comment.