Skip to content

Commit

Permalink
drawer link clickable
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandr-ru committed May 6, 2023
1 parent 8a562b3 commit 1ee611b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
17 changes: 16 additions & 1 deletion app/src/main/java/ru/aleksandr/dccppthrottle/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ package ru.aleksandr.dccppthrottle

import android.content.Intent
import android.content.res.Configuration
import android.net.Uri
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.os.PersistableBundle
import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.widget.Switch
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.ActionBarDrawerToggle
import com.google.android.material.navigation.NavigationView
Expand All @@ -33,6 +36,8 @@ import java.io.File

class MainActivity : AwakeActivity(), NavigationView.OnNavigationItemSelectedListener {

private val TAG = javaClass.simpleName

private lateinit var binding: ActivityMainBinding
private lateinit var actionBarDrawerToggle: ActionBarDrawerToggle
private lateinit var viewPager: ViewPager2
Expand Down Expand Up @@ -61,6 +66,13 @@ class MainActivity : AwakeActivity(), NavigationView.OnNavigationItemSelectedLis
val navigationView = findViewById<NavigationView>(R.id.nav_view)
navigationView.setNavigationItemSelectedListener(this)

val subtitle = navigationView.getHeaderView(0).findViewById<TextView>(R.id.textDrawerSubtitle)
subtitle.setOnClickListener {
val uri = Uri.parse(String.format("http://%s", subtitle.text))
val intent = Intent(Intent.ACTION_VIEW, uri)
startActivity(intent)
}

val menuItem = navigationView.menu.findItem(R.id.power_switch_item)
val powerSwitch = menuItem.actionView.findViewById<Switch>(R.id.power_switch)
powerSwitch.setOnClickListener {
Expand Down Expand Up @@ -194,7 +206,7 @@ class MainActivity : AwakeActivity(), NavigationView.OnNavigationItemSelectedLis
val prefKeyConnectStartup = getString(R.string.pref_key_connect_startup)
val prefsEditor = PreferenceManager.getDefaultSharedPreferences(this).edit()
prefsEditor.putBoolean(prefKeyConnectStartup, false)
prefsEditor.commit()
prefsEditor.apply()

super.onBackPressed()
}
Expand All @@ -212,18 +224,21 @@ class MainActivity : AwakeActivity(), NavigationView.OnNavigationItemSelectedLis

try {
saveStoreToFile(LocomotivesStore)
if (BuildConfig.DEBUG) Log.i(TAG, "Locomotives store saved")
}
catch (e: Exception) {
Toast.makeText(this, R.string.message_failed_save_locos, Toast.LENGTH_SHORT).show()
}
try {
saveStoreToFile(AccessoriesStore)
if (BuildConfig.DEBUG) Log.i(TAG, "Accessories store saved")
}
catch (e: Exception) {
Toast.makeText(this, R.string.message_failed_save_acc, Toast.LENGTH_SHORT).show()
}
try {
saveStoreToFile(RoutesStore)
if (BuildConfig.DEBUG) Log.i(TAG, "Routes store saved")
}
catch (e: Exception) {
Toast.makeText(this, R.string.message_failed_save_routes, Toast.LENGTH_SHORT).show()
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/nav_header_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

<TextView
android:id="@+id/textView"
android:id="@+id/textDrawerSubtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_subtitle" />
Expand Down
4 changes: 2 additions & 2 deletions app/version.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Sat May 06 17:09:07 MSK 2023
VERSION_CODE=877
#Sun May 07 00:42:20 MSK 2023
VERSION_CODE=886

0 comments on commit 1ee611b

Please sign in to comment.