-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
52 changed files
with
1,247 additions
and
1,522 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
/build | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
33
app/src/main/java/app/akilesh/nex/fragments/AboutFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
app/src/main/java/app/akilesh/nex/fragments/BottomNavigationDrawerFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.