From 9e941a3c74cd4926aaa29b548d2eec6a3558c1a9 Mon Sep 17 00:00:00 2001 From: Nareshkumar Rao Date: Wed, 24 Mar 2021 11:47:51 +0100 Subject: [PATCH] code cleanup. added version text to about page --- app/src/main/AndroidManifest.xml | 2 +- .../nareshkumarrao/eiweblog/AboutActivity.kt | 21 ++++++++++++++----- .../nareshkumarrao/eiweblog/MainActivity.kt | 8 ++----- .../eiweblog/NotificationSettingsActivity.kt | 8 +++---- .../nareshkumarrao/eiweblog/UpdateWorker.kt | 2 +- .../com/nareshkumarrao/eiweblog/Utilities.kt | 10 ++++----- .../eiweblog/ui/main/ItemArticleAdapter.kt | 7 ++----- .../eiweblog/ui/main/SectionsFragment.kt | 6 +++--- .../eiweblog/ui/main/SectionsPagerAdapter.kt | 2 +- app/src/main/res/layout/activity_about.xml | 18 ++++++++++++---- app/src/main/res/layout/activity_main.xml | 6 ++---- .../layout/activity_notification_settings.xml | 1 - app/src/main/res/layout/item_article.xml | 12 +++++++---- app/src/main/res/values/strings.xml | 1 + build.gradle | 2 +- 15 files changed, 60 insertions(+), 46 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 21250d8..2669787 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -5,7 +5,7 @@ (R.id.app_version_view).text = "App Version: $version" } fun sendBeer(view: View) { - startActivity( Intent( + startActivity( + Intent( Intent.ACTION_VIEW, Uri.parse("https://paypal.me/naresh97") - )) + ) + ) } fun githubRepo(view: View){ - startActivity( Intent( + startActivity( + Intent( Intent.ACTION_VIEW, Uri.parse("https://github.com/naresh97/ei-weblog-android") - )) + ) + ) } } \ No newline at end of file diff --git a/app/src/main/java/com/nareshkumarrao/eiweblog/MainActivity.kt b/app/src/main/java/com/nareshkumarrao/eiweblog/MainActivity.kt index cfeb7ec..6e34284 100644 --- a/app/src/main/java/com/nareshkumarrao/eiweblog/MainActivity.kt +++ b/app/src/main/java/com/nareshkumarrao/eiweblog/MainActivity.kt @@ -1,10 +1,6 @@ package com.nareshkumarrao.eiweblog -import android.app.NotificationChannel -import android.app.NotificationManager -import android.content.Context import android.content.Intent -import android.os.Build import android.os.Bundle import android.view.Menu import android.view.MenuItem @@ -47,8 +43,8 @@ class MainActivity : AppCompatActivity() { } override fun onCreateOptionsMenu(menu: Menu?): Boolean { - menuInflater.inflate(R.menu.toolbar_menu, menu); - return true; + menuInflater.inflate(R.menu.toolbar_menu, menu) + return true } fun showNotificationSettings(item: MenuItem){ diff --git a/app/src/main/java/com/nareshkumarrao/eiweblog/NotificationSettingsActivity.kt b/app/src/main/java/com/nareshkumarrao/eiweblog/NotificationSettingsActivity.kt index f92a036..b4069bd 100644 --- a/app/src/main/java/com/nareshkumarrao/eiweblog/NotificationSettingsActivity.kt +++ b/app/src/main/java/com/nareshkumarrao/eiweblog/NotificationSettingsActivity.kt @@ -2,8 +2,6 @@ package com.nareshkumarrao.eiweblog import android.content.Context import android.os.Bundle -import android.widget.CompoundButton -import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.SwitchCompat import androidx.appcompat.widget.Toolbar @@ -24,13 +22,13 @@ class NotificationSettingsActivity : AppCompatActivity() { val notificationSwitch = findViewById(R.id.notification_switch) notificationSwitch.isChecked = weblogResponse!! - notificationSwitch.setOnCheckedChangeListener(CompoundButton.OnCheckedChangeListener { _, isChecked -> - with (sharedPref.edit()) { + notificationSwitch.setOnCheckedChangeListener { _, isChecked -> + with(sharedPref.edit()) { putBoolean(getString(R.string.enable_notifications_key), isChecked) apply() } //Toast.makeText(this, "Notifications are set to $isChecked", Toast.LENGTH_SHORT).show() - }) + } } diff --git a/app/src/main/java/com/nareshkumarrao/eiweblog/UpdateWorker.kt b/app/src/main/java/com/nareshkumarrao/eiweblog/UpdateWorker.kt index 0db6903..52b3cb2 100644 --- a/app/src/main/java/com/nareshkumarrao/eiweblog/UpdateWorker.kt +++ b/app/src/main/java/com/nareshkumarrao/eiweblog/UpdateWorker.kt @@ -12,7 +12,7 @@ class UpdateWorker(private val context: Context, workerParams: WorkerParameters) val sharedPref = context.getSharedPreferences(context.getString(R.string.preference_file_key), Context.MODE_PRIVATE) val notificationsEnabled = sharedPref?.getBoolean(context.getString(R.string.enable_notifications_key), true) if(!notificationsEnabled!!){ - return Result.success(); + return Result.success() } Utilities.weblogList(context) { articles -> diff --git a/app/src/main/java/com/nareshkumarrao/eiweblog/Utilities.kt b/app/src/main/java/com/nareshkumarrao/eiweblog/Utilities.kt index 07489f3..4ad466f 100644 --- a/app/src/main/java/com/nareshkumarrao/eiweblog/Utilities.kt +++ b/app/src/main/java/com/nareshkumarrao/eiweblog/Utilities.kt @@ -22,8 +22,8 @@ import java.io.StringReader internal object Utilities { fun weblogList(context: Context?, function: (d: List
) -> Unit){ - val sharedPref = context?.getSharedPreferences(context?.getString(R.string.preference_file_key), Context.MODE_PRIVATE) - val weblogResponse = sharedPref?.getString( context?.getString(R.string.weblog_response_key), null) + val sharedPref = context?.getSharedPreferences(context.getString(R.string.preference_file_key), Context.MODE_PRIVATE) + val weblogResponse = sharedPref?.getString(context.getString(R.string.weblog_response_key), null) if (weblogResponse == null){ fetchWeblogXML(context, function) return @@ -46,10 +46,10 @@ internal object Utilities { { response -> val responseStr = String(response.toByteArray(Charsets.ISO_8859_1), Charsets.UTF_8) - val sharedPref = context?.getSharedPreferences(context?.getString(R.string.preference_file_key), Context.MODE_PRIVATE) + val sharedPref = context?.getSharedPreferences(context.getString(R.string.preference_file_key), Context.MODE_PRIVATE) if (sharedPref != null) { with (sharedPref.edit()) { - putString(context?.getString(R.string.weblog_response_key), responseStr) + putString(context.getString(R.string.weblog_response_key), responseStr) apply() } } @@ -139,7 +139,7 @@ internal object Utilities { } val pendingIntent: PendingIntent = PendingIntent.getActivity(context, 0, intent, 0) - var builder = NotificationCompat.Builder(context!!, context.getString(R.string.channel_id)) + val builder = NotificationCompat.Builder(context!!, context.getString(R.string.channel_id)) .setSmallIcon(R.drawable.ic_stat_name) .setContentTitle(article.title) .setStyle(NotificationCompat.BigTextStyle() diff --git a/app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/ItemArticleAdapter.kt b/app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/ItemArticleAdapter.kt index 8beabbf..c1f225a 100644 --- a/app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/ItemArticleAdapter.kt +++ b/app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/ItemArticleAdapter.kt @@ -1,7 +1,5 @@ package com.nareshkumarrao.eiweblog.ui.main -import android.os.Build -import android.text.Html import android.text.util.Linkify import android.view.LayoutInflater import android.view.ViewGroup @@ -9,7 +7,6 @@ import android.widget.TextView import androidx.core.text.HtmlCompat import androidx.recyclerview.widget.RecyclerView import com.nareshkumarrao.eiweblog.R -import org.w3c.dom.Text data class Article(val title: String, val content: String, val date: String, val author: String, val category: String) @@ -30,7 +27,7 @@ class ItemArticleAdapter(private val articles: List
) : RecyclerView.Ada fun bind(article: Article) { title?.text = article.title content?.text = HtmlCompat.fromHtml(article.content, HtmlCompat.FROM_HTML_MODE_COMPACT) - content?.let { Linkify.addLinks(it, Linkify.WEB_URLS) }; + content?.let { Linkify.addLinks(it, Linkify.WEB_URLS) } author?.text = article.author date?.text = article.date } @@ -38,7 +35,7 @@ class ItemArticleAdapter(private val articles: List
) : RecyclerView.Ada } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemArticleAdapter.ViewHolder { - var inflater = LayoutInflater.from(parent.context) + val inflater = LayoutInflater.from(parent.context) return ViewHolder(inflater, parent) } diff --git a/app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/SectionsFragment.kt b/app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/SectionsFragment.kt index 8383f51..d12f4f6 100644 --- a/app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/SectionsFragment.kt +++ b/app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/SectionsFragment.kt @@ -11,14 +11,14 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout import com.nareshkumarrao.eiweblog.R import com.nareshkumarrao.eiweblog.Utilities -class SectionsFragment() : Fragment() { +class SectionsFragment : Fragment() { private var swipeRefreshLayout: SwipeRefreshLayout? = null override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { val rootView = inflater.inflate(R.layout.fragment_sections, container, false) - this.swipeRefreshLayout = rootView.findViewById(R.id.sectionsSwipeRefresh) + this.swipeRefreshLayout = rootView.findViewById(R.id.sectionsSwipeRefresh) this.swipeRefreshLayout?.setOnRefreshListener { Utilities.fetchWeblogXML(this.context, ::updateView) } @@ -50,7 +50,7 @@ class SectionsFragment() : Fragment() { private fun updateView(get_articles: List
){ this.swipeRefreshLayout?.isRefreshing=false - var articles: MutableList
= mutableListOf() + val articles: MutableList
= mutableListOf() val title = arguments?.getString(ARG_SECTION_NAME) ?: return for (article in get_articles){ if(article.category == title){ diff --git a/app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/SectionsPagerAdapter.kt b/app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/SectionsPagerAdapter.kt index c3a230a..6149753 100644 --- a/app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/SectionsPagerAdapter.kt +++ b/app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/SectionsPagerAdapter.kt @@ -19,7 +19,7 @@ class SectionsPagerAdapter(private val context: Context, fm: FragmentManager) return SectionsFragment.newInstance( context.resources.getString(TAB_TITLES[position]) ) } - override fun getPageTitle(position: Int): CharSequence? { + override fun getPageTitle(position: Int): CharSequence { return context.resources.getString(TAB_TITLES[position]) } diff --git a/app/src/main/res/layout/activity_about.xml b/app/src/main/res/layout/activity_about.xml index 4efb1cf..14fbb8a 100644 --- a/app/src/main/res/layout/activity_about.xml +++ b/app/src/main/res/layout/activity_about.xml @@ -18,7 +18,6 @@ @@ -110,6 +107,19 @@ app:layout_constraintStart_toStartOf="@+id/textView2" app:layout_constraintTop_toBottomOf="@+id/textView2" /> + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 1a87dd3..de7d460 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -7,7 +7,6 @@ tools:context=".MainActivity"> + android:textSize="25sp" + tools:ignore="RelativeOverlap" /> diff --git a/app/src/main/res/layout/activity_notification_settings.xml b/app/src/main/res/layout/activity_notification_settings.xml index b0e9359..175418b 100644 --- a/app/src/main/res/layout/activity_notification_settings.xml +++ b/app/src/main/res/layout/activity_notification_settings.xml @@ -18,7 +18,6 @@ + app:layout_constraintTop_toTopOf="parent" + tools:ignore="HardcodedText" /> + app:layout_constraintTop_toTopOf="@+id/dateText" + tools:ignore="HardcodedText" /> + app:layout_constraintTop_toBottomOf="@+id/dateText" + tools:ignore="HardcodedText" /> + app:layout_constraintTop_toBottomOf="@+id/titleText" + tools:ignore="HardcodedText" /> \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index de38962..239dbdc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -30,4 +30,5 @@ Benachrichtigung Notify me when new updates are posted to the weblog com.nareshkumarrao.notifications.key + GitHub Repository \ No newline at end of file diff --git a/build.gradle b/build.gradle index 32e2667..6966571 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = "1.3.72" + ext.kotlin_version = "1.4.31" repositories { google() jcenter()