Browse Source

code cleanup. added version text to about page

pull/1/head
Nareshkumar Rao 4 years ago
parent
commit
9e941a3c74
  1. 2
      app/src/main/AndroidManifest.xml
  2. 21
      app/src/main/java/com/nareshkumarrao/eiweblog/AboutActivity.kt
  3. 8
      app/src/main/java/com/nareshkumarrao/eiweblog/MainActivity.kt
  4. 8
      app/src/main/java/com/nareshkumarrao/eiweblog/NotificationSettingsActivity.kt
  5. 2
      app/src/main/java/com/nareshkumarrao/eiweblog/UpdateWorker.kt
  6. 10
      app/src/main/java/com/nareshkumarrao/eiweblog/Utilities.kt
  7. 7
      app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/ItemArticleAdapter.kt
  8. 6
      app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/SectionsFragment.kt
  9. 2
      app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/SectionsPagerAdapter.kt
  10. 18
      app/src/main/res/layout/activity_about.xml
  11. 6
      app/src/main/res/layout/activity_main.xml
  12. 1
      app/src/main/res/layout/activity_notification_settings.xml
  13. 12
      app/src/main/res/layout/item_article.xml
  14. 1
      app/src/main/res/values/strings.xml
  15. 2
      build.gradle

2
app/src/main/AndroidManifest.xml

@ -5,7 +5,7 @@
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<application <application
android:allowBackup="true"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"

21
app/src/main/java/com/nareshkumarrao/eiweblog/AboutActivity.kt

@ -1,15 +1,18 @@
package com.nareshkumarrao.eiweblog package com.nareshkumarrao.eiweblog
import android.annotation.SuppressLint
import android.content.Intent import android.content.Intent
import android.content.pm.PackageInfo
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.AppCompatButton
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
class AboutActivity : AppCompatActivity() { class AboutActivity : AppCompatActivity() {
@SuppressLint("SetTextI18n")
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_about) setContentView(R.layout.activity_about)
@ -18,19 +21,27 @@ class AboutActivity : AppCompatActivity() {
setSupportActionBar(aboutToolbar) setSupportActionBar(aboutToolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowTitleEnabled(false) supportActionBar?.setDisplayShowTitleEnabled(false)
val pInfo: PackageInfo = packageManager.getPackageInfo(packageName, 0)
val version = pInfo.versionName
findViewById<TextView>(R.id.app_version_view).text = "App Version: $version"
} }
fun sendBeer(view: View) { fun sendBeer(view: View) {
startActivity( Intent(
startActivity(
Intent(
Intent.ACTION_VIEW, Intent.ACTION_VIEW,
Uri.parse("https://paypal.me/naresh97") Uri.parse("https://paypal.me/naresh97")
))
)
)
} }
fun githubRepo(view: View){ fun githubRepo(view: View){
startActivity( Intent(
startActivity(
Intent(
Intent.ACTION_VIEW, Intent.ACTION_VIEW,
Uri.parse("https://github.com/naresh97/ei-weblog-android") Uri.parse("https://github.com/naresh97/ei-weblog-android")
))
)
)
} }
} }

8
app/src/main/java/com/nareshkumarrao/eiweblog/MainActivity.kt

@ -1,10 +1,6 @@
package com.nareshkumarrao.eiweblog package com.nareshkumarrao.eiweblog
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
@ -47,8 +43,8 @@ class MainActivity : AppCompatActivity() {
} }
override fun onCreateOptionsMenu(menu: Menu?): Boolean { 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){ fun showNotificationSettings(item: MenuItem){

8
app/src/main/java/com/nareshkumarrao/eiweblog/NotificationSettingsActivity.kt

@ -2,8 +2,6 @@ package com.nareshkumarrao.eiweblog
import android.content.Context import android.content.Context
import android.os.Bundle import android.os.Bundle
import android.widget.CompoundButton
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.SwitchCompat import androidx.appcompat.widget.SwitchCompat
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
@ -24,13 +22,13 @@ class NotificationSettingsActivity : AppCompatActivity() {
val notificationSwitch = findViewById<SwitchCompat>(R.id.notification_switch) val notificationSwitch = findViewById<SwitchCompat>(R.id.notification_switch)
notificationSwitch.isChecked = weblogResponse!! 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) putBoolean(getString(R.string.enable_notifications_key), isChecked)
apply() apply()
} }
//Toast.makeText(this, "Notifications are set to $isChecked", Toast.LENGTH_SHORT).show() //Toast.makeText(this, "Notifications are set to $isChecked", Toast.LENGTH_SHORT).show()
})
}
} }

2
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 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) val notificationsEnabled = sharedPref?.getBoolean(context.getString(R.string.enable_notifications_key), true)
if(!notificationsEnabled!!){ if(!notificationsEnabled!!){
return Result.success();
return Result.success()
} }
Utilities.weblogList(context) { articles -> Utilities.weblogList(context) { articles ->

10
app/src/main/java/com/nareshkumarrao/eiweblog/Utilities.kt

@ -22,8 +22,8 @@ import java.io.StringReader
internal object Utilities { internal object Utilities {
fun weblogList(context: Context?, function: (d: List<Article>) -> Unit){ fun weblogList(context: Context?, function: (d: List<Article>) -> 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){ if (weblogResponse == null){
fetchWeblogXML(context, function) fetchWeblogXML(context, function)
return return
@ -46,10 +46,10 @@ internal object Utilities {
{ response -> { response ->
val responseStr = String(response.toByteArray(Charsets.ISO_8859_1), Charsets.UTF_8) 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) { if (sharedPref != null) {
with (sharedPref.edit()) { with (sharedPref.edit()) {
putString(context?.getString(R.string.weblog_response_key), responseStr)
putString(context.getString(R.string.weblog_response_key), responseStr)
apply() apply()
} }
} }
@ -139,7 +139,7 @@ internal object Utilities {
} }
val pendingIntent: PendingIntent = PendingIntent.getActivity(context, 0, intent, 0) 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) .setSmallIcon(R.drawable.ic_stat_name)
.setContentTitle(article.title) .setContentTitle(article.title)
.setStyle(NotificationCompat.BigTextStyle() .setStyle(NotificationCompat.BigTextStyle()

7
app/src/main/java/com/nareshkumarrao/eiweblog/ui/main/ItemArticleAdapter.kt

@ -1,7 +1,5 @@
package com.nareshkumarrao.eiweblog.ui.main package com.nareshkumarrao.eiweblog.ui.main
import android.os.Build
import android.text.Html
import android.text.util.Linkify import android.text.util.Linkify
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
@ -9,7 +7,6 @@ import android.widget.TextView
import androidx.core.text.HtmlCompat import androidx.core.text.HtmlCompat
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.nareshkumarrao.eiweblog.R 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) 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<Article>) : RecyclerView.Ada
fun bind(article: Article) { fun bind(article: Article) {
title?.text = article.title title?.text = article.title
content?.text = HtmlCompat.fromHtml(article.content, HtmlCompat.FROM_HTML_MODE_COMPACT) 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 author?.text = article.author
date?.text = article.date date?.text = article.date
} }
@ -38,7 +35,7 @@ class ItemArticleAdapter(private val articles: List<Article>) : RecyclerView.Ada
} }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemArticleAdapter.ViewHolder { 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) return ViewHolder(inflater, parent)
} }

6
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.R
import com.nareshkumarrao.eiweblog.Utilities import com.nareshkumarrao.eiweblog.Utilities
class SectionsFragment() : Fragment() {
class SectionsFragment : Fragment() {
private var swipeRefreshLayout: SwipeRefreshLayout? = null private var swipeRefreshLayout: SwipeRefreshLayout? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val rootView = inflater.inflate(R.layout.fragment_sections, container, false) val rootView = inflater.inflate(R.layout.fragment_sections, container, false)
this.swipeRefreshLayout = rootView.findViewById<SwipeRefreshLayout>(R.id.sectionsSwipeRefresh)
this.swipeRefreshLayout = rootView.findViewById(R.id.sectionsSwipeRefresh)
this.swipeRefreshLayout?.setOnRefreshListener { this.swipeRefreshLayout?.setOnRefreshListener {
Utilities.fetchWeblogXML(this.context, ::updateView) Utilities.fetchWeblogXML(this.context, ::updateView)
} }
@ -50,7 +50,7 @@ class SectionsFragment() : Fragment() {
private fun updateView(get_articles: List<Article>){ private fun updateView(get_articles: List<Article>){
this.swipeRefreshLayout?.isRefreshing=false this.swipeRefreshLayout?.isRefreshing=false
var articles: MutableList<Article> = mutableListOf()
val articles: MutableList<Article> = mutableListOf()
val title = arguments?.getString(ARG_SECTION_NAME) ?: return val title = arguments?.getString(ARG_SECTION_NAME) ?: return
for (article in get_articles){ for (article in get_articles){
if(article.category == title){ if(article.category == title){

2
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]) ) 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]) return context.resources.getString(TAB_TITLES[position])
} }

18
app/src/main/res/layout/activity_about.xml

@ -18,7 +18,6 @@
<TextView <TextView
android:id="@+id/title"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:fontFamily="@font/hsdsans_elektro" android:fontFamily="@font/hsdsans_elektro"
@ -75,13 +74,11 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="20dp" android:layout_marginTop="20dp"
android:layout_marginBottom="16dp"
android:background="#FFFFFF" android:background="#FFFFFF"
android:onClick="githubRepo" android:onClick="githubRepo"
android:text="GitHub Repository"
android:text="@string/github_repository"
android:textColor="@color/white" android:textColor="@color/white"
app:backgroundTint="@color/black" app:backgroundTint="@color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@+id/textView" app:layout_constraintStart_toStartOf="@+id/textView"
app:layout_constraintTop_toBottomOf="@+id/textView" /> app:layout_constraintTop_toBottomOf="@+id/textView" />
@ -110,6 +107,19 @@
app:layout_constraintStart_toStartOf="@+id/textView2" app:layout_constraintStart_toStartOf="@+id/textView2"
app:layout_constraintTop_toBottomOf="@+id/textView2" /> app:layout_constraintTop_toBottomOf="@+id/textView2" />
<TextView
android:id="@+id/app_version_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:text="App Version: v0.00"
android:textColor="@color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@+id/button2"
app:layout_constraintTop_toBottomOf="@+id/button2"
tools:ignore="HardcodedText" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView> </ScrollView>

6
app/src/main/res/layout/activity_main.xml

@ -7,7 +7,6 @@
tools:context=".MainActivity"> tools:context=".MainActivity">
<com.google.android.material.appbar.AppBarLayout <com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/white" android:background="@color/white"
@ -24,7 +23,6 @@
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<TextView <TextView
android:id="@+id/title"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentStart="true" android:layout_alignParentStart="true"
@ -39,7 +37,6 @@
android:textSize="25sp" /> android:textSize="25sp" />
<TextView <TextView
android:id="@+id/hsd_symb"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
@ -50,7 +47,8 @@
android:text="@string/hsd_symbol" android:text="@string/hsd_symbol"
android:textAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Title" android:textAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Title"
android:textColor="@color/fh_red" android:textColor="@color/fh_red"
android:textSize="25sp" />
android:textSize="25sp"
tools:ignore="RelativeOverlap" />
</RelativeLayout> </RelativeLayout>
</androidx.appcompat.widget.Toolbar> </androidx.appcompat.widget.Toolbar>

1
app/src/main/res/layout/activity_notification_settings.xml

@ -18,7 +18,6 @@
<TextView <TextView
android:id="@+id/title"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:fontFamily="@font/hsdsans_elektro" android:fontFamily="@font/hsdsans_elektro"

12
app/src/main/res/layout/item_article.xml

@ -16,7 +16,8 @@
android:textColor="@color/black" android:textColor="@color/black"
android:textStyle="bold" android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
tools:ignore="HardcodedText" />
<TextView <TextView
android:id="@+id/authorText" android:id="@+id/authorText"
@ -28,7 +29,8 @@
android:textColor="@color/black" android:textColor="@color/black"
app:layout_constraintBottom_toBottomOf="@+id/dateText" app:layout_constraintBottom_toBottomOf="@+id/dateText"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/dateText" />
app:layout_constraintTop_toTopOf="@+id/dateText"
tools:ignore="HardcodedText" />
<TextView <TextView
android:id="@+id/titleText" android:id="@+id/titleText"
@ -41,7 +43,8 @@
android:textStyle="bold" android:textStyle="bold"
app:layout_constraintEnd_toEndOf="@+id/authorText" app:layout_constraintEnd_toEndOf="@+id/authorText"
app:layout_constraintStart_toStartOf="@+id/dateText" app:layout_constraintStart_toStartOf="@+id/dateText"
app:layout_constraintTop_toBottomOf="@+id/dateText" />
app:layout_constraintTop_toBottomOf="@+id/dateText"
tools:ignore="HardcodedText" />
<TextView <TextView
android:id="@+id/contentText" android:id="@+id/contentText"
@ -54,5 +57,6 @@
app:layout_constraintEnd_toEndOf="@+id/titleText" app:layout_constraintEnd_toEndOf="@+id/titleText"
app:layout_constraintHorizontal_bias="0.498" app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="@+id/titleText" app:layout_constraintStart_toStartOf="@+id/titleText"
app:layout_constraintTop_toBottomOf="@+id/titleText" />
app:layout_constraintTop_toBottomOf="@+id/titleText"
tools:ignore="HardcodedText" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

1
app/src/main/res/values/strings.xml

@ -30,4 +30,5 @@
<string name="notifications_title">Benachrichtigung</string> <string name="notifications_title">Benachrichtigung</string>
<string name="enable_notifications">Notify me when new updates are posted to the weblog</string> <string name="enable_notifications">Notify me when new updates are posted to the weblog</string>
<string name="enable_notifications_key" translatable="false">com.nareshkumarrao.notifications.key</string> <string name="enable_notifications_key" translatable="false">com.nareshkumarrao.notifications.key</string>
<string name="github_repository" translatable="false">GitHub Repository</string>
</resources> </resources>

2
build.gradle

@ -1,6 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules. // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript { buildscript {
ext.kotlin_version = "1.3.72"
ext.kotlin_version = "1.4.31"
repositories { repositories {
google() google()
jcenter() jcenter()

Loading…
Cancel
Save