Skip to content

Commit

Permalink
Merge pull request #35 from codeDamon/dev-branch
Browse files Browse the repository at this point in the history
Added Settings Page
  • Loading branch information
mishraaditya595 authored Jan 29, 2021
2 parents 23e8e35 + 8b00429 commit ee01a86
Show file tree
Hide file tree
Showing 183 changed files with 350 additions and 3,366 deletions.
7 changes: 7 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,16 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'org.jetbrains:annotations-java5:15.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'

implementation 'androidx.preference:preference:1.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'

testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

implementation project(':monscanner')
implementation "androidx.core:core-ktx:1.3.2"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
android:roundIcon="@mipmap/scanit_icon_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".ui.activities.AboutAppActivity"></activity>
<activity android:name=".ui.activities.QRBarcodeScanResultActivity"></activity>
<activity android:name=".ui.activities.SettingsActivity"></activity>
<activity android:name=".ui.activities.AboutAppActivity" />
<activity android:name=".ui.activities.QRBarcodeScanResultActivity" />
<activity android:name=".ui.activities.GenerateQRActivity" />
<activity android:name=".ui.activities.SplashScreenActivity">
<intent-filter>
Expand Down
45 changes: 22 additions & 23 deletions app/src/main/java/com/vob/scanit/ui/activities/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
package com.vob.scanit.ui.activities

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.widget.AdapterView
import android.widget.ImageView
import android.widget.SearchView
import androidx.appcompat.app.ActionBar
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.core.view.MenuCompat
import androidx.core.view.MenuItemCompat
import androidx.fragment.app.Fragment
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.firebase.FirebaseApp
import com.rbddevs.splashy.Splashy
import com.vob.scanit.R

import com.vob.scanit.adapters.PDFAdapter
import com.vob.scanit.ui.fragments.DocumentFragment

import com.vob.scanit.ui.fragments.HomeFragment
import com.vob.scanit.ui.fragments.OCRFragment
import com.vob.scanit.ui.fragments.QRFragment
Expand Down Expand Up @@ -88,23 +84,28 @@ class MainActivity : AppCompatActivity() {
}

private fun setupToolbar() {
var toolbar = findViewById<Toolbar>(R.id.main_toolbar)
val toolbar = findViewById<Toolbar>(R.id.main_toolbar)
//toolbar.setTitle("ScanIt")
//toolbar.setTitleTextAppearance(applicationContext, R.style.TextAppearance_AppCompat_Headline)
// toolbar.setTitleTextColor(-0x1)
// toolbar.inflateMenu(R.menu.toolbar_menu)

// toolbar.setOnMenuItemClickListener{
// when(it.itemId)
// {
// R.id.about_item ->
// {
// val intent = Intent(this, AboutAppActivity::class.java)
// startActivity(intent)
// }
// }
// true
// }
toolbar.inflateMenu(R.menu.toolbar_menu)

toolbar.setOnMenuItemClickListener{
when(it.itemId)
{
/*R.id.about_item ->
{
val intent = Intent(this, AboutAppActivity::class.java)
startActivity(intent)
}*/
R.id.settings_item -> {
val intent = Intent(this, SettingsActivity::class.java)
startActivity(intent)
}
}
true
}

}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
Expand All @@ -118,6 +119,4 @@ class MainActivity : AppCompatActivity() {
transaction.addToBackStack(null)
transaction.commit()
}


}
21 changes: 21 additions & 0 deletions app/src/main/java/com/vob/scanit/ui/activities/SettingsActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.vob.scanit.ui.activities

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.vob.scanit.R
import com.vob.scanit.ui.fragments.SettingsFragment

class SettingsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setTheme(R.style.SettingsTheme)
setContentView(R.layout.activity_settings)

if (savedInstanceState == null) {
supportFragmentManager
.beginTransaction()
.replace(R.id.settings, SettingsFragment())
.commit()
}
}
}
58 changes: 58 additions & 0 deletions app/src/main/java/com/vob/scanit/ui/fragments/SettingsFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.vob.scanit.ui.fragments

import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.widget.Toast
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.res.ResourcesCompat
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreferenceCompat
import com.vob.scanit.R

class SettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener {

override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.root_preferences, rootKey)

findPreference<Preference>("privacy")?.onPreferenceClickListener = this
findPreference<Preference>("licence")?.onPreferenceClickListener = this

val pref = findPreference<SwitchPreferenceCompat>("theme_toggle")
if (pref != null) {
pref.onPreferenceChangeListener = this
}
}

override fun onPreferenceClick(preference: Preference?): Boolean {

if (preference != null) {
when (preference.key) {
"privacy" -> {
Toast.makeText(context, "Privacy Policy", Toast.LENGTH_SHORT).show()
//TODO
}
"licence" -> {
Toast.makeText(context, "Open source licences", Toast.LENGTH_SHORT).show()
//TODO
}
}
}
return true
}

override fun onPreferenceChange(preference: Preference?, newValue: Any?): Boolean {
if (preference is SwitchPreferenceCompat) {
if (preference.key == "theme_toggle") {
if (preference.isChecked)
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
else
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
}
}
return true
}
}
31 changes: 31 additions & 0 deletions app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.activities.SettingsActivity">

<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:id="@+id/appBarLayout">

<androidx.appcompat.widget.Toolbar
android:id="@+id/main_toolbar"
android:background="@color/colorPrimaryDark"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:title="@string/settings"
>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>

<FrameLayout
android:id="@+id/settings"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/appBarLayout" />

</RelativeLayout>
9 changes: 7 additions & 2 deletions app/src/main/res/menu/toolbar_menu.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
<!--<item
android:id="@+id/search_item"
android:icon="@drawable/ic_baseline_search_24"
app:showAsAction="always"
/>
android:title="Search" />
<item
android:id="@+id/about_item"
android:title="About"
app:showAsAction="never"
/>-->
<item
android:id="@+id/settings_item"
android:title="@string/settings"
app:showAsAction="never"
/>
</menu>
9 changes: 9 additions & 0 deletions app/src/main/res/values-night/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#ED744A</color>
<color name="colorPrimaryDark">#F87D52</color>
<color name="colorAccent">#009688</color>
<color name="NavyBlue">#141d26</color>
<color name="Red">#FF0000</color>
<color name="colorBackground">#121212</color>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
<color name="colorAccent">#009688</color>
<color name="NavyBlue">#141d26</color>
<color name="Red">#FF0000</color>
<color name="colorBackground">#FFF</color>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<string name="app_name" translatable="false">ScanIt</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment" translatable="false">Hello blank fragment</string>
<string name="settings" translatable="false">Settings</string>
</resources>
8 changes: 7 additions & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="iconTint">@color/iconTint</item>
</style>

<style name="customFAB">
Expand All @@ -23,4 +24,9 @@
<item name="android:textSize">18sp</item>
<item name="android:drawablePadding">5dp</item>
</style>

<!-- Settings Page Theme -->
<style name="SettingsTheme" parent="AppTheme">
<item name="android:windowBackground">@color/colorBackground</item>
</style>
</resources>
28 changes: 28 additions & 0 deletions app/src/main/res/xml/root_preferences.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">

<PreferenceCategory app:title="General"
app:iconSpaceReserved="false">

<SwitchPreferenceCompat
app:iconSpaceReserved="false"
app:key="theme_toggle"
app:summaryOn="Dark"
app:summaryOff="Light"
app:title="Theme" />

</PreferenceCategory>
<PreferenceCategory app:title="About"
app:iconSpaceReserved="false">

<Preference app:title="Open-source licences"
app:key="licence"
app:summary="Licence details for open-source software"
app:iconSpaceReserved="false" />

<Preference app:title="Privacy Policy"
app:key="privacy"
app:summary="Read Privacy Policy"
app:iconSpaceReserved="false" />

</PreferenceCategory>
</PreferenceScreen>
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit ee01a86

Please sign in to comment.