Skip to content

Commit

Permalink
Completely overhauled UI.
Browse files Browse the repository at this point in the history
Use Bottom App Bar instead of Bottom navigation bar.
Use list preference for changing the theme.
Better use of colors.
Refactored code in many places.

Signed-off-by: Akilesh <akilesh.t.15@gmail.com>
  • Loading branch information
Akilesh-T committed Jun 2, 2019
1 parent 228aad0 commit 48d3def
Show file tree
Hide file tree
Showing 52 changed files with 1,247 additions and 1,522 deletions.
6 changes: 4 additions & 2 deletions .idea/assetWizardSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/build
/build
8 changes: 5 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ android {
applicationId "app.akilesh.nex"
minSdkVersion 27
targetSdkVersion 28
versionCode 6
versionName "1.4"
versionCode 7
versionName "1.5"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
Expand All @@ -25,12 +26,13 @@ dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.1.0-alpha05'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta1'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.android.material:material:1.1.0-alpha06'
testImplementation 'junit:junit:4.13-beta-3'
androidTestImplementation 'androidx.test:runner:1.2.0-beta01'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-beta01'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.preference:preference:1.1.0-alpha05'
}
repositories {
mavenCentral()
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:name=".ThemeApplication"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
Expand Down
96 changes: 54 additions & 42 deletions app/src/main/java/app/akilesh/nex/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,87 +1,99 @@
package app.akilesh.nex

import androidx.appcompat.app.ActionBar
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.fragment.app.Fragment
import app.akilesh.nex.fragments.AboutFragment
import app.akilesh.nex.fragments.DeviceFragment
import app.akilesh.nex.fragments.HelpFragment
import app.akilesh.nex.fragments.HomeFragment
import app.akilesh.nex.fragments.ThemeFragment


import android.content.res.Configuration
import android.os.Build
import android.os.Bundle
import android.preference.PreferenceManager

import android.view.Menu

import com.google.android.material.bottomnavigation.BottomNavigationView
import java.util.Objects

import android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
import android.view.View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
import android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
import android.widget.Toast
import app.akilesh.nex.fragments.*
import android.view.MenuItem
import kotlinx.android.synthetic.main.activity_main.*
import com.google.android.material.floatingactionbutton.FloatingActionButton


class MainActivity : AppCompatActivity() {

class MainActivity : AppCompatActivity(), HomeFragment.OnFragmentInteractionListener, AboutFragment.OnFragmentInteractionListener, HelpFragment.OnFragmentInteractionListener, ThemeFragment.OnFragmentInteractionListener, DeviceFragment.OnFragmentInteractionListener {
private var currentNightMode: Int = 0
private var currentNightMode: Int = -1
private val brand: String = Build.BRAND

override fun onCreate(savedInstanceState: Bundle?) {

if(brand != "Nokia") {
Toast.makeText(this, "This app is only for Nokia phones!", Toast.LENGTH_SHORT).show()
Toast.makeText(this, "This app is only for Nokia phones!", Toast.LENGTH_LONG).show()
this.finishAffinity()
}

super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

val sharedPref = PreferenceManager.getDefaultSharedPreferences(this)
val themeID = sharedPref.getInt("ThemePrefs", -1)
AppCompatDelegate.setDefaultNightMode(themeID)
currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK

Objects.requireNonNull<ActionBar>(supportActionBar).displayOptions = ActionBar.DISPLAY_SHOW_CUSTOM
supportActionBar!!.setCustomView(R.layout.abs_layout)
setSupportActionBar(bar)

val decorView = window.decorView
decorView.systemUiVisibility = FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS

currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
when (currentNightMode) {
Configuration.UI_MODE_NIGHT_NO ->
// Night mode is not active, we're in day time
decorView.systemUiVisibility = SYSTEM_UI_FLAG_LIGHT_STATUS_BAR or SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
}

val bottomNavigationView = findViewById<BottomNavigationView>(R.id.bottom_navigation)
bottomNavigationView.setOnNavigationItemSelectedListener { item ->
var fragment: Fragment? = null
when (item.itemId) {
R.id.menu_home -> fragment = HomeFragment.newInstance()
R.id.menu_info -> fragment = AboutFragment.newInstance()
R.id.menu_help -> fragment = HelpFragment.newInstance()
if(savedInstanceState == null)
showFragment(HomeFragment.TAG)

R.id.menu_invert -> fragment = ThemeFragment.newInstance()
val fab = findViewById<FloatingActionButton>(R.id.fab)
fab.setOnClickListener {
showFragment(HomeFragment.TAG)
}

R.id.device_info -> fragment = DeviceFragment.newInstance()
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
val inflater = menuInflater
inflater.inflate(R.menu.bottom_appbar_menu, menu)
return true
}

override fun onOptionsItemSelected(item: MenuItem?): Boolean {
when(item?.itemId){
android.R.id.home -> {
val bottomNavDrawerFragment = BottomNavigationDrawerFragment()
bottomNavDrawerFragment.show(supportFragmentManager, bottomNavDrawerFragment.tag)
}
if (fragment != null) {
val fragmentTransaction = supportFragmentManager.beginTransaction()
fragmentTransaction.replace(R.id.frameLayout, fragment)
fragmentTransaction.commit()

R.id.app_bar_settings -> {
showFragment(SettingsFragment.TAG)
}
true
}
return true
}

val fragmentTransaction = supportFragmentManager.beginTransaction()
fragmentTransaction.replace(R.id.frameLayout, HomeFragment.newInstance())
fragmentTransaction.commit()
private fun showFragment(tag: String) {
var fragment = supportFragmentManager.findFragmentByTag(tag)
if (fragment == null) {
when (tag) {
HomeFragment.TAG -> {
fragment = HomeFragment()
}
SettingsFragment.TAG -> {
fragment = SettingsFragment()
}
}
}

fragment?.let {
supportFragmentManager
.beginTransaction()
.replace(R.id.frameLayout, it, tag)
.commit()
}
}

}


14 changes: 14 additions & 0 deletions app/src/main/java/app/akilesh/nex/ThemeApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package app.akilesh.nex

import android.app.Application
import android.preference.PreferenceManager

class ThemeApplication : Application() {

override fun onCreate() {
super.onCreate()
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
val themePref = sharedPreferences.getString("themePref", ThemeHelper().default )
ThemeHelper().applyTheme(themePref)
}
}
30 changes: 30 additions & 0 deletions app/src/main/java/app/akilesh/nex/ThemeHelper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package app.akilesh.nex

import androidx.appcompat.app.AppCompatDelegate

class ThemeHelper {
private val lightMode = "light"
private val darkMode = "dark"
private val batterySaverMode = "battery"
val default = "default"

fun applyTheme(theme: String?) {
when (theme) {
lightMode -> {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
}

darkMode -> {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
}

batterySaverMode -> {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY)
}

default -> {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
}
}
}
}
33 changes: 27 additions & 6 deletions app/src/main/java/app/akilesh/nex/fragments/AboutFragment.kt
Original file line number Diff line number Diff line change
@@ -1,30 +1,51 @@
package app.akilesh.nex.fragments

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import app.akilesh.nex.BuildConfig
import app.akilesh.nex.R
import java.io.*


class AboutFragment : Fragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.about_fragment, container, false)
val view = inflater.inflate(R.layout.fragment_about, container, false)

val ver = view.findViewById<TextView>(R.id.version)
val versionName = BuildConfig.VERSION_NAME
ver.text = String.format("%s", versionName)

val propPath = "/sbin/.magisk/modules/nokia-extensions/module.prop"
val magiskVer = view.findViewById<TextView>(R.id.nex_version)
var modVer = "Unknown"
if(File(propPath).exists()) {
try {
val p = Runtime.getRuntime().exec("sed -n s/^version=//p $propPath | head -n 1")

val stdInput = BufferedReader(InputStreamReader(p.inputStream) as Reader?)
modVer = stdInput.readLine().trimStart('v')

} catch (e: IOException) {
e.printStackTrace()
}
}
else {
modVer = "Not found"
Log.e(TAG, "$propPath doesn't exist")
}
magiskVer.text = String.format("%s", modVer)

return view
}

interface OnFragmentInteractionListener

companion object {

fun newInstance(): AboutFragment {
return AboutFragment()
}
internal const val TAG = "AboutFragmentTag"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package app.akilesh.nex.fragments

import android.app.Dialog
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import app.akilesh.nex.R
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.google.android.material.bottomsheet.BottomSheetDialog
import kotlinx.android.synthetic.main.fragment_bottomsheet.*

class BottomNavigationDrawerFragment: BottomSheetDialogFragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_bottomsheet, container, false)
}
override fun getTheme(): Int = R.style.BottomSheetDialogTheme

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog = BottomSheetDialog(requireContext(), theme)

private fun showFragment(tag: String) {
var fragment = fragmentManager!!.findFragmentByTag(tag)
if (fragment == null) {
when (tag) {
HelpFragment.TAG -> {
fragment = HelpFragment()
}
DeviceFragment.TAG -> {
fragment = DeviceFragment()
}
AboutFragment.TAG -> {
fragment = AboutFragment()
}
else -> {
fragment = HomeFragment()
}
}
}

fragmentManager!!
.beginTransaction()
.replace(R.id.frameLayout, fragment, tag)
.commit()
}

override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)

navigation_view.setNavigationItemSelectedListener { menuItem ->
when (menuItem.itemId) {
R.id.navigation_help -> {
showFragment(HelpFragment.TAG)
dismiss()
}
R.id.navigation_device_info -> {
showFragment(DeviceFragment.TAG)
dismiss()
}
R.id.navigation_about -> {
showFragment(AboutFragment.TAG)
dismiss()
}
}
true
}
}

}

0 comments on commit 48d3def

Please sign in to comment.