Skip to content

Commit

Permalink
hf: viewBinding + fix queries for A11+
Browse files Browse the repository at this point in the history
Signed-off-by: iTaysonLab <[email protected]>
  • Loading branch information
iTaysonLab committed Feb 14, 2022
1 parent fba217f commit ec36735
Show file tree
Hide file tree
Showing 17 changed files with 99 additions and 145 deletions.
6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
xmlns:tools="http:https://schemas.android.com/tools"
package="ua.itaysonlab.homefeeder">

<queries>
<intent>
<action android:name="ua.itaysonlab.hfsdk.HOMEFEEDER_PLUGIN_ENTRYPOINT" />
</intent>
</queries>

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.android.synthetic.main.activity_main.*
import ua.itaysonlab.homefeeder.R

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)
setSupportActionBar(findViewById(R.id.toolbar))
val navView: BottomNavigationView = findViewById(R.id.nav_view)

val navController = findNavController(R.id.nav_host_fragment)
Expand All @@ -46,6 +45,7 @@ class MainActivity : AppCompatActivity() {
permissions: Array<out String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == 1) {
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
findNavController(R.id.nav_host_fragment).navigate(R.id.navigation_settings)
Expand All @@ -56,7 +56,7 @@ class MainActivity : AppCompatActivity() {
}

private fun showStorageAlert() {
MaterialAlertDialogBuilder(this, R.style.MDialog).apply {
MaterialAlertDialogBuilder(this).apply {
setTitle(R.string.storage_alert)
setMessage(R.string.storage_desc)
setPositiveButton(R.string.storage_action) { _, _ ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.google.android.material.card.MaterialCardView
import kotlinx.android.synthetic.main.plugin_manager_entry.view.*
import kotlinx.android.synthetic.main.plugin_manager_ui.view.*
import ua.itaysonlab.homefeeder.HFApplication
import ua.itaysonlab.homefeeder.R
import ua.itaysonlab.homefeeder.databinding.PluginManagerEntryBinding
import ua.itaysonlab.homefeeder.pluginsystem.PluginFetcher
import ua.itaysonlab.homefeeder.preferences.HFPluginPreferences
import ua.itaysonlab.homefeeder.utils.Logger
import kotlin.math.ceil

class PluginsFragment : Fragment() {
Expand Down Expand Up @@ -70,7 +68,7 @@ class PluginsFragment : Fragment() {
load()
}

view.fab.setOnClickListener {
view.findViewById<View>(R.id.fab).setOnClickListener {
PluginFetcher.init(HFApplication.instance)
load()
}
Expand Down Expand Up @@ -112,14 +110,16 @@ class PluginsFragment : Fragment() {
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
if (holder !is PluginVH) return

val binding = PluginManagerEntryBinding.bind(holder.itemView)
val block = list[position]
holder.itemView.plugin_name.text = block.info.title
holder.itemView.plugin_desc.text = block.info.description
holder.itemView.plugin_author.text = block.info.author
holder.itemView.plugin_status.isChecked = block.isEnabled
holder.itemView.app_icon.setImageDrawable(HFApplication.getSmallIcon(block.info.pkg))

holder.itemView.plugin_status.setOnCheckedChangeListener { _, isChecked ->
binding.pluginName.text = block.info.title
binding.pluginDesc.text = block.info.description
binding.pluginAuthor.text = block.info.author
binding.pluginStatus.isChecked = block.isEnabled
binding.appIcon.setImageDrawable(HFApplication.getSmallIcon(block.info.pkg))

binding.pluginStatus.setOnCheckedChangeListener { _, isChecked ->
if (isChecked) {
HFPluginPreferences.add(block.info.pkg)
} else HFPluginPreferences.remove(block.info.pkg)
Expand All @@ -130,10 +130,10 @@ class PluginsFragment : Fragment() {
setStroke((holder.itemView as MaterialCardView), false, block.isEnabled)

if (!block.info.hasPluginSettings) {
holder.itemView.plugin_to_settings.visibility = View.GONE
holder.itemView.plugin_to_settings.setOnClickListener(null)
binding.pluginToSettings.visibility = View.GONE
binding.pluginToSettings.setOnClickListener(null)
} else {
holder.itemView.plugin_to_settings.setOnClickListener {
binding.pluginToSettings.setOnClickListener {
var data: ComponentName? = null

requireContext().packageManager.queryIntentActivities(Intent(PluginFetcher.INTENT_ACTION_SETTINGS), PackageManager.MATCH_DEFAULT_ONLY).forEach {
Expand Down
29 changes: 16 additions & 13 deletions app/src/main/java/ua/itaysonlab/homefeeder/overlay/OverlayKt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import android.content.res.ColorStateList
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.view.ContextThemeWrapper
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.google.android.libraries.gsa.d.a.OverlayController
import com.google.android.material.snackbar.Snackbar
import kotlinx.android.synthetic.main.overlay_header.view.*
import kotlinx.android.synthetic.main.overlay_layout.view.*
import ua.itaysonlab.hfsdk.FeedItem
import ua.itaysonlab.homefeeder.HFApplication
import ua.itaysonlab.homefeeder.R
Expand Down Expand Up @@ -82,18 +83,20 @@ class OverlayKt(val context: Context): OverlayController(context, R.style.AppThe
}*/

val theme = if (themeHolder.currentTheme.get(Theming.Colors.OVERLAY_BG.ordinal).isDark()) Theming.defaultDarkThemeColors else Theming.defaultLightThemeColors
rootView.header_preferences.imageTintList = ColorStateList.valueOf(theme.get(Theming.Colors.TEXT_COLOR_PRIMARY.ordinal))
rootView.header_title.setTextColor(theme.get(Theming.Colors.TEXT_COLOR_PRIMARY.ordinal))
rootView.findViewById<ImageView>(R.id.header_preferences).imageTintList = ColorStateList.valueOf(theme.get(Theming.Colors.TEXT_COLOR_PRIMARY.ordinal))
rootView.findViewById<TextView>(R.id.header_title).setTextColor(theme.get(Theming.Colors.TEXT_COLOR_PRIMARY.ordinal))
}

private fun initRecyclerView() {
rootView.swipe_to_refresh.setOnRefreshListener {
rootView.findViewById<SwipeRefreshLayout>(R.id.swipe_to_refresh).setOnRefreshListener {
refreshNotifications()
}

adapter = FeedAdapter()
rootView.recycler.layoutManager = LinearLayoutManager(context)
rootView.recycler.adapter = adapter
rootView.findViewById<RecyclerView>(R.id.recycler).apply {
layoutManager = LinearLayoutManager(context)
adapter = this@OverlayKt.adapter
}

/*val callback = object: SwipeToDeleteCallback(object: RecyclerItemTouchHelperListener {
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int, position: Int) {
Expand All @@ -106,7 +109,7 @@ class OverlayKt(val context: Context): OverlayController(context, R.style.AppThe
}

private fun initHeader() {
rootView.header_preferences.setOnClickListener {
rootView.findViewById<View>(R.id.header_preferences).setOnClickListener {
callMenuPopup(it)
}
}
Expand Down Expand Up @@ -140,7 +143,7 @@ class OverlayKt(val context: Context): OverlayController(context, R.style.AppThe
)
}

private fun initPermissionStub() {
/*private fun initPermissionStub() {
rootView.overlay_root.visibility = View.GONE
rootView.no_access_stub.visibility = View.VISIBLE
rootView.nas_action.setOnClickListener {
Expand All @@ -155,7 +158,7 @@ class OverlayKt(val context: Context): OverlayController(context, R.style.AppThe
Snackbar.make(rootView.user_root, R.string.overlay_no_permission_snackbar, Snackbar.LENGTH_LONG).show()
}*/
}
}
}*/

override fun onCreate(bundle: Bundle?) {
super.onCreate(bundle)
Expand All @@ -177,7 +180,7 @@ class OverlayKt(val context: Context): OverlayController(context, R.style.AppThe
list.addAll(feed)
}) {
adapter.replace(list)
rootView.swipe_to_refresh.isRefreshing = false
rootView.findViewById<SwipeRefreshLayout>(R.id.swipe_to_refresh).isRefreshing = false
}
}

Expand Down Expand Up @@ -237,7 +240,7 @@ class OverlayKt(val context: Context): OverlayController(context, R.style.AppThe
adapter = FeedAdapter()
//adapter.setCompact(value)
adapter.setTheme(themeHolder.currentTheme)
rootView.recycler.adapter = adapter
rootView.findViewById<RecyclerView>(R.id.recycler).adapter = adapter
refreshNotifications()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,37 @@ import android.net.Uri
import android.text.Html
import android.util.SparseIntArray
import android.view.View
import coil.api.load
import kotlinx.android.synthetic.main.feed_card_story_large.view.*
import coil.load
import ua.itaysonlab.hfsdk.FeedItem
import ua.itaysonlab.hfsdk.content.StoryCardContent
import ua.itaysonlab.homefeeder.databinding.FeedCardStoryLargeBinding
import ua.itaysonlab.homefeeder.kt.isDark
import ua.itaysonlab.homefeeder.theming.Theming

object StoryCardBinder: FeedBinder {
override fun bind(theme: SparseIntArray?, item: FeedItem, view: View) {
val content = item.content as StoryCardContent
val binding = FeedCardStoryLargeBinding.bind(view)

view.story_title.text = content.title
view.story_source.text = content.source.title
if (content.text == "") {
view.story_desc.visibility = View.GONE
binding.storyTitle.text = content.title
binding.storySource.text = content.source.title

if (content.text.isEmpty()) {
binding.storyDesc.visibility = View.GONE
} else {
view.story_desc.text = Html.fromHtml(content.text).toString()
binding.storyDesc.text = Html.fromHtml(content.text).toString()
}

view.story_pic.load(content.background_url)
binding.storyPic.load(content.background_url)

theme ?: return
view.story_dimmer.setBackgroundColor(theme.get(Theming.Colors.CARD_BG.ordinal))
binding.storyDimmer.setBackgroundColor(theme.get(Theming.Colors.CARD_BG.ordinal))
val themeCard = if (theme.get(Theming.Colors.CARD_BG.ordinal).isDark()) Theming.defaultDarkThemeColors else Theming.defaultLightThemeColors
view.story_title.setTextColor(themeCard.get(Theming.Colors.TEXT_COLOR_PRIMARY.ordinal))
view.story_source.setTextColor(themeCard.get(Theming.Colors.TEXT_COLOR_SECONDARY.ordinal))
view.story_desc.setTextColor(themeCard.get(Theming.Colors.TEXT_COLOR_SECONDARY.ordinal))
binding.storyTitle.setTextColor(themeCard.get(Theming.Colors.TEXT_COLOR_PRIMARY.ordinal))
binding.storySource.setTextColor(themeCard.get(Theming.Colors.TEXT_COLOR_SECONDARY.ordinal))
binding.storyDesc.setTextColor(themeCard.get(Theming.Colors.TEXT_COLOR_SECONDARY.ordinal))

view.setOnClickListener {
binding.root.setOnClickListener {
view.context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(content.link)))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,34 @@ package ua.itaysonlab.homefeeder.overlay.feed.binders

import android.util.SparseIntArray
import android.view.View
import kotlinx.android.synthetic.main.notification_generic_content.view.*
import ua.itaysonlab.hfsdk.FeedItem
import ua.itaysonlab.hfsdk.content.TextCardContent
import ua.itaysonlab.homefeeder.HFApplication
import ua.itaysonlab.homefeeder.databinding.NotificationGenericContentBinding
import ua.itaysonlab.homefeeder.utils.RelativeTimeHelper

object TextCardBinder: FeedBinder {
override fun bind(theme: SparseIntArray?, item: FeedItem, view: View) {
val content = item.content as TextCardContent
val binding = NotificationGenericContentBinding.bind(view)

view.not_title.text = content.title
view.not_title.visibility = if (content.title.isEmpty()) {
binding.notTitle.text = content.title
binding.notTitle.visibility = if (content.title.isEmpty()) {
View.GONE
} else View.VISIBLE

view.not_text.text = content.text
view.not_text.visibility = if (content.text.isEmpty()) {
binding.notText.text = content.text
binding.notText.visibility = if (content.text.isEmpty()) {
View.GONE
} else View.VISIBLE

view.not_app_subtitle.text = content.subtitle
view.not_app_subtitle.visibility = if (content.subtitle == null) {
binding.notAppSubtitle.text = content.subtitle
binding.notAppSubtitle.visibility = if (content.subtitle == null) {
View.GONE
} else View.VISIBLE

view.not_app_name.text = item.title
view.not_app_icon.visibility = View.GONE
view.not_app_date.text = RelativeTimeHelper.getDateFormattedRelative(HFApplication.instance, (item.time/1000) - 1000)
binding.notAppName.text = item.title
binding.notAppIcon.visibility = View.GONE
binding.notAppDate.text = RelativeTimeHelper.getDateFormattedRelative(HFApplication.instance, (item.time/1000) - 1000)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import kotlinx.android.synthetic.main.feed_card_text.view.*
import ua.itaysonlab.hfsdk.FeedItem
import ua.itaysonlab.hfsdk.content.TextCardContent
import ua.itaysonlab.homefeeder.R

object TextCardWithActionsBinder: FeedBinder {
override fun bind(theme: SparseIntArray?, item: FeedItem, view: View) {
TextCardBinder.bind(theme, item, view)
val valley = view.findViewById<ViewGroup>(R.id.button_valley_2)
valley.removeAllViews()
(item.content as TextCardContent).actions?.forEach {
view.button_valley_2.removeAllViews()
view.button_valley_2.addView(LayoutInflater.from(view.context).inflate(R.layout.feed_card_action, view as ViewGroup, false).apply {
valley.addView(LayoutInflater.from(view.context).inflate(R.layout.feed_card_action, view as ViewGroup, false).apply {
(this as TextView).text = it.title
})
}
Expand Down
Loading

0 comments on commit ec36735

Please sign in to comment.