Browse Source

basic color selection

pull/20/head
Jannik 2 years ago
parent
commit
ec74a8e4f8
  1. 5
      app/build.gradle
  2. 29
      app/src/main/java/org/mosad/seil0/projectlaogai/MainActivity.kt
  3. 8
      app/src/main/java/org/mosad/seil0/projectlaogai/fragments/SettingsFragment.kt
  4. 6
      app/src/main/res/drawable/side_nav_bar.xml
  5. 2
      app/src/main/res/layout/app_bar_main.xml
  6. 2
      app/src/main/res/layout/nav_header_main.xml

5
app/build.gradle

@ -35,9 +35,10 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
implementation 'org.jsoup:jsoup:1.11.3'
implementation 'org.jetbrains.anko:anko-commons:0.10.8'
implementation 'com.afollestad:aesthetic:1.0.0-beta05'
implementation 'com.afollestad.material-dialogs:core:2.0.0-rc3'
implementation 'com.afollestad.material-dialogs:color:2.0.0-rc3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

29
app/src/main/java/org/mosad/seil0/projectlaogai/MainActivity.kt

@ -22,6 +22,7 @@
package org.mosad.seil0.projectlaogai
import android.graphics.Color
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
@ -29,10 +30,12 @@ import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.GravityCompat
import androidx.fragment.app.FragmentTransaction
import com.afollestad.aesthetic.Aesthetic
import com.afollestad.materialdialogs.MaterialDialog
import com.google.android.material.navigation.NavigationView
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.app_bar_main.*
import org.jetbrains.anko.colorAttr
import org.jetbrains.anko.doAsync
import org.jetbrains.anko.uiThread
import org.mosad.seil0.projectlaogai.fragments.*
@ -52,10 +55,26 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
private lateinit var course: CourseTTLink
override fun onCreate(savedInstanceState: Bundle?) {
Aesthetic.attach(this)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)
// If we haven't set any defaults, do that now
if (Aesthetic.isFirstTime) {
// this is executed on the first app start, use this to show tutorial etc.
Aesthetic.config {
colorPrimary(Color.YELLOW)
apply()
}
} else {
Aesthetic.config {
colorPrimary(Color.YELLOW)
colorPrimaryDark(Color.YELLOW)
apply()
}
}
// load mensa and timetable
load()
@ -76,6 +95,16 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
nav_view.setNavigationItemSelectedListener(this)
}
override fun onResume() {
super.onResume()
Aesthetic.resume(this)
}
override fun onPause() {
super.onPause()
Aesthetic.pause(this)
}
override fun onBackPressed() {
if (drawer_layout.isDrawerOpen(GravityCompat.START)) {
drawer_layout.closeDrawer(GravityCompat.START)

8
app/src/main/java/org/mosad/seil0/projectlaogai/fragments/SettingsFragment.kt

@ -29,6 +29,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import com.afollestad.aesthetic.Aesthetic
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.color.colorChooser
import com.afollestad.materialdialogs.customview.customView
@ -125,12 +126,17 @@ class SettingsFragment : Fragment() {
linLayoutMainColor.setOnClickListener {
// open a new color chooser dialog
val colors = intArrayOf(Color.BLACK, Color.RED, Color.GREEN, Color.BLUE)
val colors = intArrayOf(Color.BLACK, Color.CYAN, Color.MAGENTA, Color.YELLOW)
MaterialDialog(context!!)
.title(R.string.primary_color)
.colorChooser(colors, initialSelection = Color.BLACK) { _, color ->
viewPrimaryColor.setBackgroundColor(color)
Aesthetic.config {
colorPrimary(color)
colorPrimaryDark(color)
apply()
}
}
.positiveButton(R.string.select)
.show()

6
app/src/main/res/drawable/side_nav_bar.xml

@ -2,8 +2,8 @@
android:shape="rectangle">
<gradient
android:angle="135"
android:centerColor="@color/colorPrimary"
android:endColor="@color/colorPrimaryDark"
android:startColor="@color/colorPrimary"
android:centerColor="?colorPrimary"
android:endColor="?colorPrimaryDark"
android:startColor="?colorPrimary"
android:type="linear"/>
</shape>

2
app/src/main/res/layout/app_bar_main.xml

@ -20,7 +20,7 @@
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
android:background="?colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</com.google.android.material.appbar.AppBarLayout>

2
app/src/main/res/layout/nav_header_main.xml

@ -4,7 +4,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="@dimen/nav_header_height"
android:background="@drawable/side_nav_bar"
android:background="?colorPrimary"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"

Loading…
Cancel
Save