diff --git a/androidApp/build.gradle.kts b/androidApp/build.gradle.kts index 00e1abc..713cc7b 100644 --- a/androidApp/build.gradle.kts +++ b/androidApp/build.gradle.kts @@ -129,7 +129,6 @@ dependencies { implementation("androidx.recyclerview:recyclerview:1.3.0-alpha01") implementation("androidx.legacy:legacy-support-v4:1.0.0") implementation("androidx.vectordrawable:vectordrawable:1.2.0-alpha02") - implementation("androidx.browser:browser:1.4.0") implementation("androidx.cardview:cardview:1.0.0") implementation("androidx.annotation:annotation:1.3.0") implementation("androidx.work:work-runtime-ktx:2.7.1") @@ -167,8 +166,6 @@ dependencies { implementation("com.mikepenz:materialdrawer:8.4.5") // Themes - implementation("com.52inc:scoops:1.0.0") - implementation("com.jaredrummler:colorpicker:1.1.0") implementation("com.github.rubensousa:floatingtoolbar:1.5.1") // Pager diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/AddSourceActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/AddSourceActivity.kt index 137764b..26b1239 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/AddSourceActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/AddSourceActivity.kt @@ -7,13 +7,10 @@ import android.widget.* import androidx.appcompat.app.AppCompatActivity import androidx.constraintlayout.widget.ConstraintLayout import bou.amine.apps.readerforselfossv2.android.databinding.ActivityAddSourceBinding -import bou.amine.apps.readerforselfossv2.android.themes.AppColors -import bou.amine.apps.readerforselfossv2.android.themes.Toppings import bou.amine.apps.readerforselfossv2.android.utils.isBaseUrlInvalid import bou.amine.apps.readerforselfossv2.model.NetworkUnavailableException import bou.amine.apps.readerforselfossv2.repository.Repository import bou.amine.apps.readerforselfossv2.service.AppSettingsService -import com.ftinc.scoop.Scoop import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -26,7 +23,6 @@ class AddSourceActivity : AppCompatActivity(), DIAware { private var mSpoutsValue: String? = null - private lateinit var appColors: AppColors private lateinit var binding: ActivityAddSourceBinding override val di by closestDI() @@ -34,43 +30,18 @@ class AddSourceActivity : AppCompatActivity(), DIAware { private val appSettingsService : AppSettingsService by instance() override fun onCreate(savedInstanceState: Bundle?) { - appColors = AppColors(this@AddSourceActivity) - super.onCreate(savedInstanceState) binding = ActivityAddSourceBinding.inflate(layoutInflater) val view = binding.root setContentView(view) - val scoop = Scoop.getInstance() - scoop.bind(this, Toppings.PRIMARY.value, binding.toolbar) - scoop.bindStatusBar(this, Toppings.PRIMARY_DARK.value) - - val drawable = binding.nameInput.background - drawable.setTint(appColors.colorAccent) - - - // TODO: clean - binding.nameInput.background = drawable - - val drawable1 = binding.sourceUri.background - drawable1.setTint(appColors.colorAccent) - - binding.sourceUri.background = drawable1 - - val drawable2 = binding.tags.background - drawable2.setTint(appColors.colorAccent) - - binding.tags.background = drawable2 - setSupportActionBar(binding.toolbar) supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true) maybeGetDetailsFromIntentSharing(intent, binding.sourceUri, binding.nameInput) - binding.saveBtn.setTextColor(appColors.colorAccent) - binding.saveBtn.setOnClickListener { handleSaveSource( binding.tags, diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt index 50f212c..87828ad 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt @@ -15,6 +15,9 @@ import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.ActionBarDrawerToggle import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity +import androidx.appcompat.app.AppCompatDelegate +import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO +import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES import androidx.appcompat.widget.SearchView import androidx.core.view.doOnNextLayout import androidx.drawerlayout.widget.DrawerLayout @@ -29,11 +32,8 @@ import bou.amine.apps.readerforselfossv2.android.adapters.ItemsAdapter import bou.amine.apps.readerforselfossv2.android.background.LoadingWorker import bou.amine.apps.readerforselfossv2.android.databinding.ActivityHomeBinding import bou.amine.apps.readerforselfossv2.android.settings.SettingsActivity -import bou.amine.apps.readerforselfossv2.android.themes.AppColors -import bou.amine.apps.readerforselfossv2.android.themes.Toppings import bou.amine.apps.readerforselfossv2.android.utils.bottombar.maybeShow import bou.amine.apps.readerforselfossv2.android.utils.bottombar.removeBadge -import bou.amine.apps.readerforselfossv2.android.utils.customtabs.CustomTabActivityHelper import bou.amine.apps.readerforselfossv2.model.SelfossModel import bou.amine.apps.readerforselfossv2.repository.Repository import bou.amine.apps.readerforselfossv2.service.AppSettingsService @@ -43,7 +43,6 @@ import com.ashokvarma.bottomnavigation.BottomNavigationItem import com.ashokvarma.bottomnavigation.TextBadgeItem import com.bumptech.glide.Glide import com.bumptech.glide.request.RequestOptions -import com.ftinc.scoop.Scoop import com.mikepenz.aboutlibraries.LibsBuilder import com.mikepenz.materialdrawer.holder.BadgeStyle import com.mikepenz.materialdrawer.holder.ColorHolder @@ -80,8 +79,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar private lateinit var tabNewBadge: TextBadgeItem private lateinit var tabArchiveBadge: TextBadgeItem private lateinit var tabStarredBadge: TextBadgeItem - private lateinit var customTabActivityHelper: CustomTabActivityHelper - private lateinit var appColors: AppColors private var offset: Int = 0 private var firstVisible: Int = 0 private lateinit var recyclerViewScrollListener: RecyclerView.OnScrollListener @@ -95,7 +92,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar private val settingsLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { appSettingsService.refreshUserSettings() - recreate() } override val di by closestDI() @@ -104,16 +100,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar data class DrawerData(val tags: List?, val sources: List?) - override fun onStart() { - super.onStart() - customTabActivityHelper.bindCustomTabsService(this) - } - override fun onCreate(savedInstanceState: Bundle?) { - - // Add appcolors to DI - appColors = AppColors(this@HomeActivity) - super.onCreate(savedInstanceState) binding = ActivityHomeBinding.inflate(layoutInflater) val view = binding.root @@ -127,8 +114,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar setContentView(view) - handleThemeBinding() - setSupportActionBar(binding.toolBar) supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setHomeButtonEnabled(true) @@ -136,8 +121,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar binding.drawerContainer.addDrawerListener(mDrawerToggle) mDrawerToggle.syncState() - customTabActivityHelper = CustomTabActivityHelper() - handleBottomBar() initDrawer() @@ -234,27 +217,24 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar tabNewBadge = TextBadgeItem() .setText("") .setHideOnSelect(false).hide(false) - .setBackgroundColor(appColors.colorPrimary) tabArchiveBadge = TextBadgeItem() .setText("") .setHideOnSelect(false).hide(false) - .setBackgroundColor(appColors.colorPrimary) tabStarredBadge = TextBadgeItem() .setText("") .setHideOnSelect(false).hide(false) - .setBackgroundColor(appColors.colorPrimary) val tabNew = BottomNavigationItem( R.drawable.ic_tab_fiber_new_black_24dp, getString(R.string.tab_new) - ).setActiveColor(appColors.colorAccent) + ) .setBadgeItem(tabNewBadge) val tabArchive = BottomNavigationItem( R.drawable.ic_tab_archive_black_24dp, getString(R.string.tab_read) - ).setActiveColor(appColors.colorAccentDark) + ) .setBadgeItem(tabArchiveBadge) val tabStarred = BottomNavigationItem( @@ -270,7 +250,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar .setFirstSelectedPosition(0) .initialise() binding.bottomBar.setMode(BottomNavigationBar.MODE_SHIFTING) - binding.bottomBar.setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_STATIC) if (fromTabShortcut) { binding.bottomBar.selectTab(elementsShown.position - 1) @@ -280,12 +259,8 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar override fun onResume() { super.onResume() - appColors = AppColors(this@HomeActivity) - handleDrawerItems() - handleThemeUpdate() - reloadLayoutManager() if (appSettingsService.isInfiniteLoadingEnabled()) { @@ -305,25 +280,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar getElementsAccordingToTab() } - override fun onStop() { - super.onStop() - customTabActivityHelper.unbindCustomTabsService(this) - } - - private fun handleThemeBinding() { - val scoop = Scoop.getInstance() - scoop.bind(this, Toppings.PRIMARY.value, binding.toolBar) - scoop.bindStatusBar(this, Toppings.PRIMARY_DARK.value) - } - - private fun handleThemeUpdate() { - - val scoop = Scoop.getInstance() - scoop.update(Toppings.PRIMARY.value, appColors.colorPrimary) - - scoop.update(Toppings.PRIMARY_DARK.value, appColors.colorPrimaryDark) - } - private fun initDrawer() { DrawerImageLoader.init(object : AbstractDrawerImageLoader() { override fun set(imageView: ImageView, uri: Uri, placeholder: Drawable, tag: String?) { @@ -508,7 +464,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar val gdColor = try { Color.parseColor(it.color) } catch (e: IllegalArgumentException) { - appColors.colorPrimary + resources.getColor(R.color.colorPrimary) } gd.setColor(gdColor) gd.shape = GradientDrawable.RECTANGLE @@ -522,7 +478,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar iconDrawable = gd badgeStyle = BadgeStyle().apply { textColor = ColorHolder.fromColor(Color.WHITE) - color = ColorHolder.fromColor(appColors.colorAccent) + color = ColorHolder.fromColor(resources.getColor(R.color.colorAccent)) } onDrawerItemClickListener = { _, _, _ -> repository.tagFilter = it @@ -745,8 +701,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar ItemCardAdapter( this, items, - customTabActivityHelper, - appColors, ) { updateItems(it) } @@ -755,8 +709,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar ItemListAdapter( this, items, - customTabActivityHelper, - appColors, ) { updateItems(it) } diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/LoginActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/LoginActivity.kt index 657feb6..880b3d1 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/LoginActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/LoginActivity.kt @@ -12,8 +12,8 @@ import android.view.inputmethod.EditorInfo import android.widget.TextView import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity +import androidx.appcompat.app.AppCompatDelegate import bou.amine.apps.readerforselfossv2.android.databinding.ActivityLoginBinding -import bou.amine.apps.readerforselfossv2.android.themes.AppColors import bou.amine.apps.readerforselfossv2.android.utils.isBaseUrlInvalid import bou.amine.apps.readerforselfossv2.repository.Repository import bou.amine.apps.readerforselfossv2.service.AppSettingsService @@ -30,7 +30,6 @@ class LoginActivity : AppCompatActivity(), DIAware { private var inValidCount: Int = 0 private var isWithLogin = false - private lateinit var appColors: AppColors private lateinit var binding: ActivityLoginBinding override val di by closestDI() @@ -38,9 +37,9 @@ class LoginActivity : AppCompatActivity(), DIAware { private val appSettingsService : AppSettingsService by instance() override fun onCreate(savedInstanceState: Bundle?) { - appColors = AppColors(this@LoginActivity) - super.onCreate(savedInstanceState) + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO) + binding = ActivityLoginBinding.inflate(layoutInflater) val view = binding.root diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/MyApp.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/MyApp.kt index 4e7c2d4..0268a1e 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/MyApp.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/MyApp.kt @@ -21,7 +21,6 @@ import bou.amine.apps.readerforselfossv2.repository.Repository import bou.amine.apps.readerforselfossv2.service.AppSettingsService import com.bumptech.glide.Glide import com.bumptech.glide.request.RequestOptions -import com.ftinc.scoop.Scoop import com.github.ln_12.library.ConnectivityStatus import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader import com.mikepenz.materialdrawer.util.DrawerImageLoader @@ -54,8 +53,6 @@ class MyApp : MultiDexApplication(), DIAware { initDrawerImageLoader() - initTheme() - tryToHandleBug() handleNotificationChannels() @@ -117,14 +114,6 @@ class MyApp : MultiDexApplication(), DIAware { }) } - private fun initTheme() { - Scoop.waffleCone() - .addFlavor(getString(R.string.default_theme), R.style.NoBar, true) - .addFlavor(getString(R.string.default_dark_theme), R.style.NoBarDark, false) - .setSharedPreferences(PreferenceManager.getDefaultSharedPreferences(this)) - .initialize() - } - private fun tryToHandleBug() { val oldHandler = Thread.getDefaultUncaughtExceptionHandler() diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ReaderActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ReaderActivity.kt index ad6a23c..4214ef4 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ReaderActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ReaderActivity.kt @@ -12,12 +12,9 @@ import androidx.viewpager2.adapter.FragmentStateAdapter import androidx.viewpager2.widget.ViewPager2 import bou.amine.apps.readerforselfossv2.android.databinding.ActivityReaderBinding import bou.amine.apps.readerforselfossv2.android.fragments.ArticleFragment -import bou.amine.apps.readerforselfossv2.android.themes.AppColors -import bou.amine.apps.readerforselfossv2.android.themes.Toppings import bou.amine.apps.readerforselfossv2.model.SelfossModel import bou.amine.apps.readerforselfossv2.repository.Repository import bou.amine.apps.readerforselfossv2.service.AppSettingsService -import com.ftinc.scoop.Scoop import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -28,7 +25,6 @@ import org.kodein.di.instance class ReaderActivity : AppCompatActivity(), DIAware { private var currentItem: Int = 0 - private lateinit var appColors: AppColors private lateinit var toolbarMenu: Menu @@ -56,16 +52,11 @@ class ReaderActivity : AppCompatActivity(), DIAware { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - appColors = AppColors(this) binding = ActivityReaderBinding.inflate(layoutInflater) val view = binding.root setContentView(view) - val scoop = Scoop.getInstance() - scoop.bind(this, Toppings.PRIMARY.value, binding.toolBar) - scoop.bindStatusBar(this, Toppings.PRIMARY_DARK.value) - setSupportActionBar(binding.toolBar) supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/SourcesActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/SourcesActivity.kt index d28b290..4a99f96 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/SourcesActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/SourcesActivity.kt @@ -8,11 +8,8 @@ import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager import bou.amine.apps.readerforselfossv2.android.adapters.SourcesListAdapter import bou.amine.apps.readerforselfossv2.android.databinding.ActivitySourcesBinding -import bou.amine.apps.readerforselfossv2.android.themes.AppColors -import bou.amine.apps.readerforselfossv2.android.themes.Toppings import bou.amine.apps.readerforselfossv2.model.SelfossModel import bou.amine.apps.readerforselfossv2.repository.Repository -import com.ftinc.scoop.Scoop import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -22,21 +19,15 @@ import org.kodein.di.instance class SourcesActivity : AppCompatActivity(), DIAware { - private lateinit var appColors: AppColors private lateinit var binding: ActivitySourcesBinding override val di by closestDI() private val repository : Repository by instance() override fun onCreate(savedInstanceState: Bundle?) { - appColors = AppColors(this@SourcesActivity) binding = ActivitySourcesBinding.inflate(layoutInflater) val view = binding.root - val scoop = Scoop.getInstance() - scoop.bind(this, Toppings.PRIMARY.value, binding.toolbar) - scoop.bindStatusBar(this, Toppings.PRIMARY_DARK.value) - super.onCreate(savedInstanceState) setContentView(view) @@ -45,8 +36,8 @@ class SourcesActivity : AppCompatActivity(), DIAware { supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true) - binding.fab.rippleColor = appColors.colorAccentDark - binding.fab.backgroundTintList = ColorStateList.valueOf(appColors.colorAccent) + binding.fab.rippleColor = resources.getColor(R.color.colorAccentDark) + binding.fab.backgroundTintList = ColorStateList.valueOf(resources.getColor(R.color.colorAccent)) } override fun onStop() { diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemCardAdapter.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemCardAdapter.kt index 23073d7..fa26bf4 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemCardAdapter.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemCardAdapter.kt @@ -10,9 +10,7 @@ import androidx.recyclerview.widget.RecyclerView import bou.amine.apps.readerforselfossv2.android.R import bou.amine.apps.readerforselfossv2.android.databinding.CardItemBinding import bou.amine.apps.readerforselfossv2.android.model.toTextDrawableString -import bou.amine.apps.readerforselfossv2.android.themes.AppColors import bou.amine.apps.readerforselfossv2.android.utils.* -import bou.amine.apps.readerforselfossv2.android.utils.customtabs.CustomTabActivityHelper import bou.amine.apps.readerforselfossv2.android.utils.glide.bitmapCenterCrop import bou.amine.apps.readerforselfossv2.android.utils.glide.circularBitmapDrawable import bou.amine.apps.readerforselfossv2.model.SelfossModel @@ -34,8 +32,6 @@ import org.kodein.di.instance class ItemCardAdapter( override val app: Activity, override var items: ArrayList, - private val helper: CustomTabActivityHelper, - override val appColors: AppColors, override val updateItems: (ArrayList) -> Unit ) : ItemsAdapter() { private val c: Context = app.baseContext @@ -44,8 +40,8 @@ class ItemCardAdapter( c.resources.getDimension(R.dimen.card_image_max_height).toInt() override val di: DI by closestDI(app) - override val repository : Repository by instance() - override val appSettingsService : AppSettingsService by instance() + override val repository: Repository by instance() + override val appSettingsService: AppSettingsService by instance() override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { val binding = CardItemBinding.inflate(LayoutInflater.from(parent.context), parent, false) @@ -61,7 +57,7 @@ class ItemCardAdapter( binding.title.setOnTouchListener(LinkOnTouchListener()) - binding.title.setLinkTextColor(appColors.colorAccent) + binding.title.setLinkTextColor(c.resources.getColor(R.color.colorAccent)) binding.sourceTitleAndDate.text = itm.sourceAndDateText(repository.dateUtils) @@ -83,10 +79,10 @@ class ItemCardAdapter( val color = generator.getColor(itm.title.getHtmlDecoded()) val drawable = - TextDrawable - .builder() - .round() - .build(itm.title.getHtmlDecoded().toTextDrawableString(), color) + TextDrawable + .builder() + .round() + .build(itm.title.getHtmlDecoded().toTextDrawableString(), color) binding.sourceImage.setImageDrawable(drawable) } else { c.circularBitmapDrawable(itm.getIcon(repository.baseUrl), binding.sourceImage) @@ -101,7 +97,7 @@ class ItemCardAdapter( inner class ViewHolder(val binding: CardItemBinding) : RecyclerView.ViewHolder(binding.root) { init { handleClickListeners() - handleCustomTabActions() + handleLinkOpening() } private fun handleClickListeners() { @@ -111,41 +107,34 @@ class ItemCardAdapter( if (item.starred) { CoroutineScope(Dispatchers.IO).launch { repository.unstarr(item) - // TODO: Handle failure } item.starred = false binding.favButton.isSelected = false } else { CoroutineScope(Dispatchers.IO).launch { repository.starr(item) - // TODO: Handle failure } item.starred = true binding.favButton.isSelected = true } } - binding.shareBtn.setOnClickListener { - val item = items[bindingAdapterPosition] - c.shareLink(item.getLinkDecoded(), item.title.getHtmlDecoded()) - } - - binding.browserBtn.setOnClickListener { - c.openInBrowserAsNewTask(items[bindingAdapterPosition]) - } + binding.shareBtn.setOnClickListener { + val item = items[bindingAdapterPosition] + c.shareLink(item.getLinkDecoded(), item.title.getHtmlDecoded()) } - private fun handleCustomTabActions() { - val customTabsIntent = c.buildCustomTabsIntent() - helper.bindCustomTabsService(app) + binding.browserBtn.setOnClickListener { + c.openInBrowserAsNewTask(items[bindingAdapterPosition]) + } + } + private fun handleLinkOpening() { binding.root.setOnClickListener { c.openItemUrl( items, bindingAdapterPosition, items[bindingAdapterPosition].getLinkDecoded(), - customTabsIntent, - appSettingsService.isInternalBrowserEnabled(), appSettingsService.isArticleViewerEnabled(), app ) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemListAdapter.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemListAdapter.kt index b4fef63..de6e91e 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemListAdapter.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemListAdapter.kt @@ -5,12 +5,10 @@ import android.content.Context import android.view.LayoutInflater import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView +import bou.amine.apps.readerforselfossv2.android.R import bou.amine.apps.readerforselfossv2.android.databinding.ListItemBinding import bou.amine.apps.readerforselfossv2.android.model.toTextDrawableString -import bou.amine.apps.readerforselfossv2.android.themes.AppColors import bou.amine.apps.readerforselfossv2.android.utils.LinkOnTouchListener -import bou.amine.apps.readerforselfossv2.android.utils.buildCustomTabsIntent -import bou.amine.apps.readerforselfossv2.android.utils.customtabs.CustomTabActivityHelper import bou.amine.apps.readerforselfossv2.android.utils.glide.bitmapCenterCrop import bou.amine.apps.readerforselfossv2.android.utils.glide.circularBitmapDrawable import bou.amine.apps.readerforselfossv2.android.utils.openItemUrl @@ -29,8 +27,6 @@ import org.kodein.di.instance class ItemListAdapter( override val app: Activity, override var items: ArrayList, - private val helper: CustomTabActivityHelper, - override val appColors: AppColors, override val updateItems: (ArrayList) -> Unit ) : ItemsAdapter() { private val generator: ColorGenerator = ColorGenerator.MATERIAL @@ -53,7 +49,7 @@ class ItemListAdapter( binding.title.setOnTouchListener(LinkOnTouchListener()) - binding.title.setLinkTextColor(appColors.colorAccent) + binding.title.setLinkTextColor(c.resources.getColor(R.color.colorAccent)) binding.sourceTitleAndDate.text = itm.sourceAndDateText(repository.dateUtils) @@ -83,20 +79,15 @@ class ItemListAdapter( inner class ViewHolder(val binding: ListItemBinding) : RecyclerView.ViewHolder(binding.root) { init { - handleCustomTabActions() + handleLinkOpening() } - private fun handleCustomTabActions() { - val customTabsIntent = c.buildCustomTabsIntent() - helper.bindCustomTabsService(app) - + private fun handleLinkOpening() { binding.root.setOnClickListener { c.openItemUrl( items, bindingAdapterPosition, items[bindingAdapterPosition].getLinkDecoded(), - customTabsIntent, - appSettingsService.isInternalBrowserEnabled(), appSettingsService.isArticleViewerEnabled(), app ) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemsAdapter.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemsAdapter.kt index d66be45..b310bd0 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemsAdapter.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemsAdapter.kt @@ -5,7 +5,6 @@ import android.graphics.Color import android.widget.TextView import androidx.recyclerview.widget.RecyclerView import bou.amine.apps.readerforselfossv2.android.R -import bou.amine.apps.readerforselfossv2.android.themes.AppColors import bou.amine.apps.readerforselfossv2.model.SelfossModel import bou.amine.apps.readerforselfossv2.repository.Repository import bou.amine.apps.readerforselfossv2.service.AppSettingsService @@ -21,7 +20,6 @@ abstract class ItemsAdapter : RecyclerView.Adapte abstract val repository: Repository abstract val appSettingsService: AppSettingsService abstract val app: Activity - abstract val appColors: AppColors abstract val updateItems: (ArrayList) -> Unit fun updateAllItems(items: ArrayList) { diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt index 7e24dea..4e9ada7 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt @@ -8,6 +8,7 @@ import android.graphics.Typeface import android.graphics.drawable.ColorDrawable import android.net.Uri import android.os.Bundle +import android.util.TypedValue import android.view.* import android.webkit.WebResourceResponse import android.webkit.WebSettings @@ -15,7 +16,6 @@ import android.webkit.WebView import android.webkit.WebViewClient import android.widget.Toast import androidx.appcompat.app.AlertDialog -import androidx.browser.customtabs.CustomTabsIntent import androidx.core.content.res.ResourcesCompat import androidx.core.widget.NestedScrollView import androidx.fragment.app.Fragment @@ -27,12 +27,8 @@ import bou.amine.apps.readerforselfossv2.android.databinding.FragmentArticleBind import bou.amine.apps.readerforselfossv2.android.model.ParecelableItem import bou.amine.apps.readerforselfossv2.android.model.toModel import bou.amine.apps.readerforselfossv2.android.model.toParcelable -import bou.amine.apps.readerforselfossv2.android.themes.AppColors -import bou.amine.apps.readerforselfossv2.android.utils.buildCustomTabsIntent -import bou.amine.apps.readerforselfossv2.android.utils.customtabs.CustomTabActivityHelper import bou.amine.apps.readerforselfossv2.android.utils.glide.getBitmapInputStream import bou.amine.apps.readerforselfossv2.android.utils.openInBrowserAsNewTask -import bou.amine.apps.readerforselfossv2.android.utils.openItemUrlInternalBrowser import bou.amine.apps.readerforselfossv2.android.utils.shareLink import bou.amine.apps.readerforselfossv2.model.SelfossModel import bou.amine.apps.readerforselfossv2.repository.Repository @@ -61,10 +57,10 @@ import java.net.URL import java.util.* import java.util.concurrent.ExecutionException + class ArticleFragment : Fragment(), DIAware { private var fontSize: Int = 16 private lateinit var item: SelfossModel.Item - private var mCustomTabActivityHelper: CustomTabActivityHelper? = null private lateinit var url: String private lateinit var contentText: String private lateinit var contentSource: String @@ -72,7 +68,6 @@ class ArticleFragment : Fragment(), DIAware { private lateinit var contentTitle: String private lateinit var allImages : ArrayList private lateinit var fab: FloatingActionButton - private lateinit var appColors: AppColors private lateinit var textAlignment: String private var _binding: FragmentArticleBinding? = null private val binding get() = _binding!! @@ -86,16 +81,7 @@ class ArticleFragment : Fragment(), DIAware { private var font = "" private var staticBar = false - override fun onStop() { - super.onStop() - if (mCustomTabActivityHelper != null) { - mCustomTabActivityHelper!!.unbindCustomTabsService(activity) - } - } - override fun onCreate(savedInstanceState: Bundle?) { - appColors = AppColors(requireActivity()) - super.onCreate(savedInstanceState) val pi: ParecelableItem = requireArguments().getParcelable(ARG_ITEMS)!! @@ -136,25 +122,19 @@ class ArticleFragment : Fragment(), DIAware { fab = binding.fab - fab.backgroundTintList = ColorStateList.valueOf(appColors.colorAccent) + fab.backgroundTintList = ColorStateList.valueOf(resources.getColor(R.color.colorAccent)) - fab.rippleColor = appColors.colorAccentDark + fab.rippleColor = resources.getColor(R.color.colorAccentDark) val floatingToolbar: FloatingToolbar = binding.floatingToolbar floatingToolbar.attachFab(fab) - floatingToolbar.background = ColorDrawable(appColors.colorAccent) - - val customTabsIntent = requireActivity().buildCustomTabsIntent() - mCustomTabActivityHelper = CustomTabActivityHelper() - mCustomTabActivityHelper!!.bindCustomTabsService(activity) - + floatingToolbar.background = ColorDrawable(resources.getColor(R.color.colorAccent)) floatingToolbar.setClickListener( object : FloatingToolbar.ItemClickListener { override fun onItemClick(item: MenuItem) { when (item.itemId) { - R.id.more_action -> getContentFromMercury(customTabsIntent) R.id.share_action -> requireActivity().shareLink(url, contentTitle) R.id.open_action -> requireActivity().openInBrowserAsNewTask(this@ArticleFragment.item) R.id.unread_action -> if (context != null) { @@ -200,7 +180,7 @@ class ArticleFragment : Fragment(), DIAware { } if (contentText.isEmptyOrNullOrNullString()) { - getContentFromMercury(customTabsIntent) + getContentFromMercury() } else { binding.titleView.text = contentTitle if (typeface != null) { @@ -266,7 +246,7 @@ class ArticleFragment : Fragment(), DIAware { } } - private fun getContentFromMercury(customTabsIntent: CustomTabsIntent) { + private fun getContentFromMercury() { if (repository.isNetworkAvailable()) { binding.progressBar.visibility = View.VISIBLE val parser = MercuryApi() @@ -333,7 +313,7 @@ class ArticleFragment : Fragment(), DIAware { } } else { try { - openInBrowserAfterFailing(customTabsIntent) + openInBrowserAfterFailing() } catch (e: Exception) { if (context != null) { } @@ -348,14 +328,13 @@ class ArticleFragment : Fragment(), DIAware { override fun onFailure( call: Call, t: Throwable - ) = openInBrowserAfterFailing(customTabsIntent) + ) = openInBrowserAfterFailing() } ) } } private fun htmlToWebview() { - val stringColor = String.format("#%06X", 0xFFFFFF and appColors.colorAccent) val attrs: IntArray = intArrayOf(android.R.attr.fontFamily) val a: TypedArray = requireContext().obtainStyledAttributes(resId, attrs) @@ -364,12 +343,11 @@ class ArticleFragment : Fragment(), DIAware { binding.webcontent.settings.standardFontFamily = a.getString(0) binding.webcontent.visibility = View.VISIBLE - // TODO: Set the color strings programmatically - val (stringTextColor, stringBackgroundColor) = if (appColors.isDarkTheme) { - Pair("#FFFFFF", "#303030") - } else { - Pair("#212121", "#FAFAFA") - } + val colorOnSurface = TypedValue() + requireContext().theme.resolveAttribute(R.attr.colorOnSurface, colorOnSurface, true) + + val colorSurface = TypedValue() + requireContext().theme.resolveAttribute(R.attr.colorSurface, colorSurface, true) binding.webcontent.settings.useWideViewPort = true binding.webcontent.settings.loadWithOverviewMode = true @@ -458,10 +436,10 @@ class ArticleFragment : Fragment(), DIAware { | max-width: 100%; | } | a { - | color: $stringColor !important; + | color: ${String.format("#%06X", 0xFFFFFF and resources.getColor(R.color.colorAccent))} !important; | } | *:not(a) { - | color: $stringTextColor; + | color: ${String.format("#%06X", 0xFFFFFF and colorOnSurface.data)}; | } | * { | font-size: ${fontSize}px; @@ -469,11 +447,11 @@ class ArticleFragment : Fragment(), DIAware { | word-break: break-word; | overflow:hidden; | line-height: 1.5em; - | background-color: $stringBackgroundColor; + | background-color: ${String.format("#%06X", 0xFFFFFF and colorSurface.data)}; | } | body, html { - | background-color: $stringBackgroundColor !important; - | border-color: $stringBackgroundColor !important; + | background-color: ${String.format("#%06X", 0xFFFFFF and colorSurface.data)} !important; + | border-color: ${String.format("#%06X", 0xFFFFFF and colorSurface.data)} !important; | padding: 0 !important; | margin: 0 !important; | } @@ -483,7 +461,7 @@ class ArticleFragment : Fragment(), DIAware { | pre, code { | white-space: pre-wrap; | width:100%; - | background-color: $stringBackgroundColor; + | background-color: ${String.format("#%06X", 0xFFFFFF and colorSurface.data)}; | } | | $fontLinkAndStyle @@ -507,13 +485,9 @@ class ArticleFragment : Fragment(), DIAware { binding.nestedScrollView.smoothScrollBy(0, -height/2) } - private fun openInBrowserAfterFailing(customTabsIntent: CustomTabsIntent) { + private fun openInBrowserAfterFailing() { binding.progressBar.visibility = View.GONE - requireActivity().openItemUrlInternalBrowser( - url, - customTabsIntent, - requireActivity() - ) + requireActivity().openInBrowserAsNewTask(this@ArticleFragment.item) } companion object { diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/settings/SettingsActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/settings/SettingsActivity.kt index 67148bb..a99ce0e 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/settings/SettingsActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/settings/SettingsActivity.kt @@ -7,22 +7,16 @@ import android.text.Editable import android.text.InputFilter import android.text.InputType import android.text.TextWatcher -import android.view.Menu -import android.view.MenuInflater -import android.view.MenuItem import android.widget.Toast import androidx.appcompat.app.AppCompatActivity +import androidx.appcompat.app.AppCompatDelegate import androidx.core.widget.addTextChangedListener import androidx.preference.EditTextPreference import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat -import androidx.preference.PreferenceManager import bou.amine.apps.readerforselfossv2.android.R import bou.amine.apps.readerforselfossv2.android.databinding.ActivitySettingsBinding -import bou.amine.apps.readerforselfossv2.android.themes.AppColors -import bou.amine.apps.readerforselfossv2.android.themes.Toppings import bou.amine.apps.readerforselfossv2.service.AppSettingsService -import com.ftinc.scoop.Scoop private const val TITLE_TAG = "settingsActivityTitle" @@ -31,15 +25,8 @@ class SettingsActivity : AppCompatActivity(), override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("dark_theme", false)) { - setTheme(R.style.NoBarDark) - } val binding = ActivitySettingsBinding.inflate(layoutInflater) - val scoop = Scoop.getInstance() - scoop.bind(this, Toppings.PRIMARY.value, binding.toolbar) - scoop.bindStatusBar(this, Toppings.PRIMARY_DARK.value) - setContentView(binding.root) if (savedInstanceState == null) { supportFragmentManager @@ -169,21 +156,11 @@ class SettingsActivity : AppCompatActivity(), class ThemePreferenceFragment : PreferenceFragmentCompat() { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { setPreferencesFromResource(R.xml.pref_theme, rootKey) - setHasOptionsMenu(true) - } - override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { - super.onCreateOptionsMenu(menu, inflater) - inflater.inflate(R.menu.settings_theme, menu) - } - - override fun onOptionsItemSelected(item: MenuItem): Boolean { - val id = item.itemId - if (id == R.id.clear) { - AppColors.resetColors() - requireActivity().recreate() + preferenceManager.findPreference("currentMode")?.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue -> + AppCompatDelegate.setDefaultNightMode(newValue.toString().toInt()) // ListPreference Only takes string-arrays ¯\_(ツ)_/¯ + true } - return super.onOptionsItemSelected(item) } } diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/themes/AppColors.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/themes/AppColors.kt deleted file mode 100644 index bd01677..0000000 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/themes/AppColors.kt +++ /dev/null @@ -1,72 +0,0 @@ -package bou.amine.apps.readerforselfossv2.android.themes - -import android.app.Activity -import androidx.annotation.ColorInt -import bou.amine.apps.readerforselfossv2.android.R -import com.russhwolf.settings.Settings - -class AppColors(a: Activity) { - - @ColorInt val colorPrimary: Int - @ColorInt val colorPrimaryDark: Int - @ColorInt val colorAccent: Int - @ColorInt val colorAccentDark: Int - @ColorInt val colorBackground: Int - @ColorInt val textColor: Int - val isDarkTheme: Boolean - - init { - val settings = Settings() - - colorPrimary = - settings.getInt( - "color_primary", - a.resources.getColor(R.color.colorPrimary) - ) - colorPrimaryDark = - settings.getInt( - "color_primary_dark", - a.resources.getColor(R.color.colorPrimaryDark) - ) - colorAccent = - settings.getInt( - "color_accent", - a.resources.getColor(R.color.colorAccent) - ) - colorAccentDark = - settings.getInt( - "color_accent_dark", - a.resources.getColor(R.color.colorAccentDark) - ) - isDarkTheme = - settings.getBoolean( - "dark_theme", - false - ) - - colorBackground = if (isDarkTheme) { - a.setTheme(R.style.NoBarDark) - a.resources.getColor(R.color.darkBackground) - } else { - a.setTheme(R.style.NoBar) - a.resources.getColor(R.color.grey_50) - } - - textColor = if (isDarkTheme) { - a.resources.getColor(R.color.white) - } else { - a.resources.getColor(R.color.grey_900) - } - } - - companion object { - fun resetColors() { - val settings = Settings() - settings.remove("color_primary") - settings.remove("color_primary_dark") - settings.remove("color_accent") - settings.remove("color_accent_dark") - settings.remove("dark_theme") - } - } -} diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/themes/Toppings.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/themes/Toppings.kt deleted file mode 100644 index ecda680..0000000 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/themes/Toppings.kt +++ /dev/null @@ -1,8 +0,0 @@ -package bou.amine.apps.readerforselfossv2.android.themes - -enum class Toppings(val value: Int) { - PRIMARY(1), - PRIMARY_DARK(2), - ACCENT(3), - ACCENT_DARK(4) -} \ No newline at end of file diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/LinksUtils.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/LinksUtils.kt index 20cc998..2dfa44e 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/LinksUtils.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/LinksUtils.kt @@ -15,109 +15,16 @@ import android.view.MotionEvent import android.view.View import android.widget.TextView import android.widget.Toast -import androidx.browser.customtabs.CustomTabsIntent import bou.amine.apps.readerforselfossv2.android.R import bou.amine.apps.readerforselfossv2.android.ReaderActivity -import bou.amine.apps.readerforselfossv2.android.utils.customtabs.CustomTabActivityHelper import bou.amine.apps.readerforselfossv2.model.SelfossModel import bou.amine.apps.readerforselfossv2.utils.toStringUriWithHttp import okhttp3.HttpUrl.Companion.toHttpUrlOrNull -fun Context.buildCustomTabsIntent(): CustomTabsIntent { - - val actionIntent = Intent(Intent.ACTION_SEND) - actionIntent.type = "text/plain" - val pflags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - PendingIntent.FLAG_IMMUTABLE - } else { - 0 - } - val createPendingShareIntent: PendingIntent = PendingIntent.getActivity( - this, - 0, - actionIntent, - pflags - ) - - val intentBuilder = CustomTabsIntent.Builder() - - // TODO: change to primary when it's possible to customize custom tabs title color - //intentBuilder.setToolbarColor(c.getResources().getColor(R.color.colorPrimary)); - intentBuilder.setToolbarColor(resources.getColor(R.color.colorAccentDark)) - intentBuilder.setShowTitle(true) - - - intentBuilder.setStartAnimations( - this, - R.anim.slide_in_right, - R.anim.slide_out_left - ) - intentBuilder.setExitAnimations( - this, - android.R.anim.slide_in_left, - android.R.anim.slide_out_right - ) - - val closeicon = BitmapFactory.decodeResource(resources, R.drawable.ic_close_white_24dp) - intentBuilder.setCloseButtonIcon(closeicon) - - val shareLabel = this.getString(R.string.label_share) - val icon = BitmapFactory.decodeResource( - resources, - R.drawable.ic_share_white_24dp - ) - intentBuilder.setActionButton(icon, shareLabel, createPendingShareIntent) - - return intentBuilder.build() -} - -fun Context.openItemUrlInternally( - allItems: ArrayList, - currentItem: Int, - linkDecoded: String, - customTabsIntent: CustomTabsIntent, - articleViewer: Boolean, - app: Activity -) { - if (articleViewer) { - ReaderActivity.allItems = allItems - val intent = Intent(this, ReaderActivity::class.java) - intent.putExtra("currentItem", currentItem) - app.startActivity(intent) - } else { - this.openItemUrlInternalBrowser( - linkDecoded, - customTabsIntent, - app) - } -} - -fun Context.openItemUrlInternalBrowser( - linkDecoded: String, - customTabsIntent: CustomTabsIntent, - app: Activity -) { - try { - CustomTabActivityHelper.openCustomTab( - app, - customTabsIntent, - Uri.parse(linkDecoded) - ) { _, uri -> - val intent = Intent(Intent.ACTION_VIEW, uri) - intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK - startActivity(intent) - } - } catch (e: Exception) { - openInBrowser(linkDecoded, app) - } -} - fun Context.openItemUrl( allItems: ArrayList, currentItem: Int, linkDecoded: String, - customTabsIntent: CustomTabsIntent, - internalBrowser: Boolean, articleViewer: Boolean, app: Activity ) { @@ -129,37 +36,20 @@ fun Context.openItemUrl( Toast.LENGTH_LONG ).show() } else { - if (!internalBrowser) { - openInBrowser(linkDecoded, app) - } else if (articleViewer) { - this.openItemUrlInternally( - allItems, - currentItem, - linkDecoded, - customTabsIntent, - articleViewer, - app - ) + if (articleViewer) { + ReaderActivity.allItems = allItems + val intent = Intent(this, ReaderActivity::class.java) + intent.putExtra("currentItem", currentItem) + app.startActivity(intent) } else { - this.openItemUrlInternalBrowser( - linkDecoded, - customTabsIntent, - app - ) + val intent = Intent(Intent.ACTION_VIEW) + intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK + intent.data = Uri.parse(linkDecoded.toStringUriWithHttp()) + startActivity(intent) } } } -private fun openInBrowser(linkDecoded: String, app: Activity) { - val intent = Intent(Intent.ACTION_VIEW) - intent.data = Uri.parse(linkDecoded) - try { - app.startActivity(intent) - } catch (e: ActivityNotFoundException) { - Toast.makeText(app.baseContext, e.message, Toast.LENGTH_LONG).show() - } -} - fun String.isUrlValid(): Boolean = this.toHttpUrlOrNull() != null && Patterns.WEB_URL.matcher(this).matches() @@ -181,7 +71,7 @@ fun Context.openInBrowserAsNewTask(i: SelfossModel.Item) { startActivity(intent) } -class LinkOnTouchListener: View.OnTouchListener { +class LinkOnTouchListener : View.OnTouchListener { override fun onTouch(v: View?, event: MotionEvent?): Boolean { var ret = false val widget: TextView = v as TextView @@ -191,7 +81,8 @@ class LinkOnTouchListener: View.OnTouchListener { val action = event!!.action if (action == MotionEvent.ACTION_UP || - action == MotionEvent.ACTION_DOWN) { + action == MotionEvent.ACTION_DOWN + ) { var x: Float = event.x var y: Float = event.y diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/customtabs/CustomTabActivityHelper.java b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/customtabs/CustomTabActivityHelper.java deleted file mode 100644 index cfdd8d8..0000000 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/customtabs/CustomTabActivityHelper.java +++ /dev/null @@ -1,153 +0,0 @@ -package bou.amine.apps.readerforselfossv2.android.utils.customtabs; - - -import android.app.Activity; -import android.net.Uri; -import android.os.Bundle; -import androidx.browser.customtabs.CustomTabsClient; -import androidx.browser.customtabs.CustomTabsIntent; -import androidx.browser.customtabs.CustomTabsServiceConnection; -import androidx.browser.customtabs.CustomTabsSession; - -import java.util.List; - -/** - * This is a helper class to manage the connection to the Custom Tabs Service. - */ -public class CustomTabActivityHelper implements ServiceConnectionCallback { - private CustomTabsSession mCustomTabsSession; - private CustomTabsClient mClient; - private CustomTabsServiceConnection mConnection; - private ConnectionCallback mConnectionCallback; - - /** - * Opens the URL on a Custom Tab if possible. Otherwise fallsback to opening it on a WebView. - * - * @param activity The host activity. - * @param customTabsIntent a CustomTabsIntent to be used if Custom Tabs is available. - * @param uri the Uri to be opened. - * @param fallback a CustomTabFallback to be used if Custom Tabs is not available. - */ - public static void openCustomTab(Activity activity, - CustomTabsIntent customTabsIntent, - Uri uri, - CustomTabFallback fallback) { - String packageName = CustomTabsHelper.getPackageNameToUse(activity); - - //If we cant find a package name, it means theres no browser that supports - //Chrome Custom Tabs installed. So, we fallback to the webview - if (packageName == null) { - if (fallback != null) { - fallback.openUri(activity, uri); - } - } else { - customTabsIntent.intent.setPackage(packageName); - customTabsIntent.launchUrl(activity, uri); - } - } - - /** - * Unbinds the Activity from the Custom Tabs Service. - * - * @param activity the activity that is connected to the service. - */ - public void unbindCustomTabsService(Activity activity) { - if (mConnection == null) return; - activity.unbindService(mConnection); - mClient = null; - mCustomTabsSession = null; - mConnection = null; - } - - /** - * Creates or retrieves an exiting CustomTabsSession. - * - * @return a CustomTabsSession. - */ - public CustomTabsSession getSession() { - if (mClient == null) { - mCustomTabsSession = null; - } else if (mCustomTabsSession == null) { - mCustomTabsSession = mClient.newSession(null); - } - return mCustomTabsSession; - } - - /** - * Register a Callback to be called when connected or disconnected from the Custom Tabs Service. - * - * @param connectionCallback - */ - public void setConnectionCallback(ConnectionCallback connectionCallback) { - this.mConnectionCallback = connectionCallback; - } - - /** - * Binds the Activity to the Custom Tabs Service. - * - * @param activity the activity to be binded to the service. - */ - public void bindCustomTabsService(Activity activity) { - if (mClient != null) return; - - String packageName = CustomTabsHelper.getPackageNameToUse(activity); - if (packageName == null) return; - - mConnection = new ServiceConnection(this); - CustomTabsClient.bindCustomTabsService(activity, packageName, mConnection); - } - - /** - * @return true if call to mayLaunchUrl was accepted. - * @see {@link CustomTabsSession#mayLaunchUrl(Uri, Bundle, List)}. - */ - public boolean mayLaunchUrl(Uri uri, Bundle extras, List otherLikelyBundles) { - if (mClient == null) return false; - - CustomTabsSession session = getSession(); - return session != null && session.mayLaunchUrl(uri, extras, otherLikelyBundles); - - } - - @Override - public void onServiceConnected(CustomTabsClient client) { - mClient = client; - mClient.warmup(0L); - if (mConnectionCallback != null) mConnectionCallback.onCustomTabsConnected(); - } - - @Override - public void onServiceDisconnected() { - mClient = null; - mCustomTabsSession = null; - if (mConnectionCallback != null) mConnectionCallback.onCustomTabsDisconnected(); - } - - /** - * A Callback for when the service is connected or disconnected. Use those callbacks to - * handle UI changes when the service is connected or disconnected. - */ - public interface ConnectionCallback { - /** - * Called when the service is connected. - */ - void onCustomTabsConnected(); - - /** - * Called when the service is disconnected. - */ - void onCustomTabsDisconnected(); - } - - /** - * To be used as a fallback to open the Uri when Custom Tabs is not available. - */ - public interface CustomTabFallback { - /** - * @param activity The Activity that wants to open the Uri. - * @param uri The uri to be opened by the fallback. - */ - void openUri(Activity activity, Uri uri); - } - -} \ No newline at end of file diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/customtabs/CustomTabsHelper.java b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/customtabs/CustomTabsHelper.java deleted file mode 100644 index f4fe0d4..0000000 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/customtabs/CustomTabsHelper.java +++ /dev/null @@ -1,129 +0,0 @@ -package bou.amine.apps.readerforselfossv2.android.utils.customtabs; - - -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; -import android.net.Uri; -import android.text.TextUtils; -import android.util.Log; -import androidx.browser.customtabs.CustomTabsService; -import bou.amine.apps.readerforselfossv2.android.utils.customtabs.helpers.KeepAliveService; - -import java.util.ArrayList; -import java.util.List; - -@SuppressWarnings("ALL") -class CustomTabsHelper { - private static final String TAG = "CustomTabsHelper"; - private static final String STABLE_PACKAGE = "com.android.chrome"; - private static final String BETA_PACKAGE = "com.chrome.beta"; - private static final String DEV_PACKAGE = "com.chrome.dev"; - private static final String LOCAL_PACKAGE = "com.google.android.apps.chrome"; - private static final String EXTRA_CUSTOM_TABS_KEEP_ALIVE = - "android.support.customtabs.extra.KEEP_ALIVE"; - - private static String sPackageNameToUse; - - private CustomTabsHelper() { - } - - public static void addKeepAliveExtra(Context context, Intent intent) { - Intent keepAliveIntent = new Intent().setClassName( - context.getPackageName(), KeepAliveService.class.getCanonicalName()); - intent.putExtra(EXTRA_CUSTOM_TABS_KEEP_ALIVE, keepAliveIntent); - } - - /** - * Goes through all apps that handle VIEW intents and have a warmup service. Picks - * the one chosen by the user if there is one, otherwise makes a best effort to return a - * valid package name. - *

- * This is not threadsafe. - * - * @param context {@link Context} to use for accessing {@link PackageManager}. - * @return The package name recommended to use for connecting to custom tabs related components. - */ - public static String getPackageNameToUse(Context context) { - if (sPackageNameToUse != null) return sPackageNameToUse; - - PackageManager pm = context.getPackageManager(); - // Get default VIEW intent handler. - Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com")); - ResolveInfo defaultViewHandlerInfo = pm.resolveActivity(activityIntent, 0); - String defaultViewHandlerPackageName = null; - if (defaultViewHandlerInfo != null) { - defaultViewHandlerPackageName = defaultViewHandlerInfo.activityInfo.packageName; - } - - // Get all apps that can handle VIEW intents. - List resolvedActivityList = pm.queryIntentActivities(activityIntent, 0); - List packagesSupportingCustomTabs = new ArrayList<>(); - for (ResolveInfo info : resolvedActivityList) { - Intent serviceIntent = new Intent(); - serviceIntent.setAction(CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION); - serviceIntent.setPackage(info.activityInfo.packageName); - if (pm.resolveService(serviceIntent, 0) != null) { - packagesSupportingCustomTabs.add(info.activityInfo.packageName); - } - } - - // Now packagesSupportingCustomTabs contains all apps that can handle both VIEW intents - // and service calls. - if (packagesSupportingCustomTabs.isEmpty()) { - sPackageNameToUse = null; - } else if (packagesSupportingCustomTabs.size() == 1) { - sPackageNameToUse = packagesSupportingCustomTabs.get(0); - } else if (!TextUtils.isEmpty(defaultViewHandlerPackageName) - && !hasSpecializedHandlerIntents(context, activityIntent) - && packagesSupportingCustomTabs.contains(defaultViewHandlerPackageName)) { - sPackageNameToUse = defaultViewHandlerPackageName; - } else if (packagesSupportingCustomTabs.contains(STABLE_PACKAGE)) { - sPackageNameToUse = STABLE_PACKAGE; - } else if (packagesSupportingCustomTabs.contains(BETA_PACKAGE)) { - sPackageNameToUse = BETA_PACKAGE; - } else if (packagesSupportingCustomTabs.contains(DEV_PACKAGE)) { - sPackageNameToUse = DEV_PACKAGE; - } else if (packagesSupportingCustomTabs.contains(LOCAL_PACKAGE)) { - sPackageNameToUse = LOCAL_PACKAGE; - } - return sPackageNameToUse; - } - - /** - * Used to check whether there is a specialized handler for a given intent. - * - * @param intent The intent to check with. - * @return Whether there is a specialized handler for the given intent. - */ - private static boolean hasSpecializedHandlerIntents(Context context, Intent intent) { - try { - PackageManager pm = context.getPackageManager(); - List handlers = pm.queryIntentActivities( - intent, - PackageManager.GET_RESOLVED_FILTER); - if (handlers == null || handlers.isEmpty()) { - return false; - } - for (ResolveInfo resolveInfo : handlers) { - IntentFilter filter = resolveInfo.filter; - if (filter == null) continue; - if (filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0) continue; - if (resolveInfo.activityInfo == null) continue; - return true; - } - } catch (RuntimeException e) { - Log.e(TAG, "Runtime exception while getting specialized handlers"); - } - return false; - } - - /** - * @return All possible chrome package names that provide custom tabs feature. - */ - public static String[] getPackages() { - return new String[]{"", STABLE_PACKAGE, BETA_PACKAGE, DEV_PACKAGE, LOCAL_PACKAGE}; - } -} diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/customtabs/ServiceConnection.java b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/customtabs/ServiceConnection.java deleted file mode 100644 index f1c2214..0000000 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/customtabs/ServiceConnection.java +++ /dev/null @@ -1,33 +0,0 @@ -package bou.amine.apps.readerforselfossv2.android.utils.customtabs; - - -import android.content.ComponentName; -import androidx.browser.customtabs.CustomTabsClient; -import androidx.browser.customtabs.CustomTabsServiceConnection; - -import java.lang.ref.WeakReference; - -/** - * Implementation for the CustomTabsServiceConnection that avoids leaking the - * ServiceConnectionCallback - */ -public class ServiceConnection extends CustomTabsServiceConnection { - // A weak reference to the ServiceConnectionCallback to avoid leaking it. - private WeakReference mConnectionCallback; - - public ServiceConnection(ServiceConnectionCallback connectionCallback) { - mConnectionCallback = new WeakReference<>(connectionCallback); - } - - @Override - public void onCustomTabsServiceConnected(ComponentName name, CustomTabsClient client) { - ServiceConnectionCallback connectionCallback = mConnectionCallback.get(); - if (connectionCallback != null) connectionCallback.onServiceConnected(client); - } - - @Override - public void onServiceDisconnected(ComponentName name) { - ServiceConnectionCallback connectionCallback = mConnectionCallback.get(); - if (connectionCallback != null) connectionCallback.onServiceDisconnected(); - } -} \ No newline at end of file diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/customtabs/ServiceConnectionCallback.java b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/customtabs/ServiceConnectionCallback.java deleted file mode 100644 index 78a34fa..0000000 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/customtabs/ServiceConnectionCallback.java +++ /dev/null @@ -1,19 +0,0 @@ -package bou.amine.apps.readerforselfossv2.android.utils.customtabs; - - -import androidx.browser.customtabs.CustomTabsClient; - - -public interface ServiceConnectionCallback { - /** - * Called when the service is connected. - * - * @param client a CustomTabsClient - */ - void onServiceConnected(CustomTabsClient client); - - /** - * Called when the service is disconnected. - */ - void onServiceDisconnected(); -} diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/customtabs/helpers/KeepAliveService.java b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/customtabs/helpers/KeepAliveService.java deleted file mode 100644 index c754941..0000000 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/customtabs/helpers/KeepAliveService.java +++ /dev/null @@ -1,15 +0,0 @@ -package bou.amine.apps.readerforselfossv2.android.utils.customtabs.helpers; - -import android.app.Service; -import android.content.Intent; -import android.os.Binder; -import android.os.IBinder; - -public class KeepAliveService extends Service { - private static final Binder sBinder = new Binder(); - - @Override - public IBinder onBind(Intent intent) { - return sBinder; - } -} diff --git a/androidApp/src/main/res/drawable/background_splash.xml b/androidApp/src/main/res/drawable/background_splash.xml index 32241ec..bef5ded 100644 --- a/androidApp/src/main/res/drawable/background_splash.xml +++ b/androidApp/src/main/res/drawable/background_splash.xml @@ -1,8 +1,11 @@ - + + + + + - - diff --git a/androidApp/src/main/res/layout/activity_add_source.xml b/androidApp/src/main/res/layout/activity_add_source.xml index 9998207..7767d7a 100644 --- a/androidApp/src/main/res/layout/activity_add_source.xml +++ b/androidApp/src/main/res/layout/activity_add_source.xml @@ -14,12 +14,12 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - + + /> @@ -107,8 +107,7 @@ app:layout_constraintTop_toBottomOf="@+id/tags" app:layout_constraintRight_toRightOf="parent" app:layout_constraintLeft_toLeftOf="parent" - android:layout_height="40dp" - android:theme="@style/App.Spinner"/> + android:layout_height="40dp"/>