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. 6
      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" />
<application
android:allowBackup="true"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"

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

@ -1,15 +1,18 @@
package com.nareshkumarrao.eiweblog
import android.annotation.SuppressLint
import android.content.Intent
import android.content.pm.PackageInfo
import android.net.Uri
import android.os.Bundle
import android.view.View
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.AppCompatButton
import androidx.appcompat.widget.Toolbar
class AboutActivity : AppCompatActivity() {
@SuppressLint("SetTextI18n")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_about)
@ -18,19 +21,27 @@ class AboutActivity : AppCompatActivity() {
setSupportActionBar(aboutToolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
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) {
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")
))
)
)
}
}

8
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){

6
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<SwitchCompat>(R.id.notification_switch)
notificationSwitch.isChecked = weblogResponse!!
notificationSwitch.setOnCheckedChangeListener(CompoundButton.OnCheckedChangeListener { _, isChecked ->
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()
})
}
}

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

7
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<Article>) : 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<Article>) : 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)
}

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.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<SwipeRefreshLayout>(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<Article>){
this.swipeRefreshLayout?.isRefreshing=false
var articles: MutableList<Article> = mutableListOf()
val articles: MutableList<Article> = mutableListOf()
val title = arguments?.getString(ARG_SECTION_NAME) ?: return
for (article in get_articles){
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]) )
}
override fun getPageTitle(position: Int): CharSequence? {
override fun getPageTitle(position: Int): CharSequence {
return context.resources.getString(TAB_TITLES[position])
}

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

@ -18,7 +18,6 @@
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/hsdsans_elektro"
@ -75,13 +74,11 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="16dp"
android:background="#FFFFFF"
android:onClick="githubRepo"
android:text="GitHub Repository"
android:text="@string/github_repository"
android:textColor="@color/white"
app:backgroundTint="@color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@+id/textView"
app:layout_constraintTop_toBottomOf="@+id/textView" />
@ -110,6 +107,19 @@
app:layout_constraintStart_toStartOf="@+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>
</ScrollView>

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

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

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

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

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

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

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

@ -30,4 +30,5 @@
<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_key" translatable="false">com.nareshkumarrao.notifications.key</string>
<string name="github_repository" translatable="false">GitHub Repository</string>
</resources>

2
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()

Loading…
Cancel
Save