Skip to content
Snippets Groups Projects
Commit 30b3e574 authored by Jawnnypoo's avatar Jawnnypoo
Browse files

Use property access syntax for prefs

parent 1941b76a
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -31,14 +31,12 @@ class ActivityActivity : BaseActivity() {
}
}
 
@BindView(R.id.drawer_layout)
lateinit var drawerLayout: DrawerLayout
@BindView(R.id.toolbar)
lateinit var toolbar: Toolbar
@BindView(R.id.drawer_layout) lateinit var drawerLayout: DrawerLayout
@BindView(R.id.toolbar) lateinit var toolbar: Toolbar
 
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Prefs.setStartingView(Prefs.STARTING_VIEW_ACTIVITY)
Prefs.startingView = Prefs.STARTING_VIEW_ACTIVITY
setContentView(R.layout.activity_activity)
ButterKnife.bind(this)
 
Loading
Loading
Loading
Loading
@@ -44,16 +44,11 @@ class GroupsActivity : BaseActivity() {
}
}
 
@BindView(R.id.drawer_layout)
lateinit var drawerLayout: DrawerLayout
@BindView(R.id.toolbar)
lateinit var toolbar: Toolbar
@BindView(R.id.swipe_layout)
lateinit var swipeRefreshLayout: SwipeRefreshLayout
@BindView(R.id.list)
lateinit var listGroups: RecyclerView
@BindView(R.id.message_text)
lateinit var textMessage: TextView
@BindView(R.id.drawer_layout) lateinit var drawerLayout: DrawerLayout
@BindView(R.id.toolbar) lateinit var toolbar: Toolbar
@BindView(R.id.swipe_layout) lateinit var swipeRefreshLayout: SwipeRefreshLayout
@BindView(R.id.list) lateinit var listGroups: RecyclerView
@BindView(R.id.message_text) lateinit var textMessage: TextView
 
lateinit var adapterGroup: GroupAdapter
lateinit var layoutManager: DynamicGridLayoutManager
Loading
Loading
@@ -75,7 +70,7 @@ class GroupsActivity : BaseActivity() {
 
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Prefs.setStartingView(Prefs.STARTING_VIEW_GROUPS)
Prefs.startingView = Prefs.STARTING_VIEW_GROUPS
setContentView(R.layout.activity_groups)
ButterKnife.bind(this)
App.bus().register(this)
Loading
Loading
Loading
Loading
@@ -9,7 +9,6 @@ import android.os.Bundle
import android.view.ViewGroup
import butterknife.BindView
import butterknife.ButterKnife
import com.commit451.gitlab.App
import com.commit451.gitlab.R
import com.commit451.gitlab.data.Prefs
import com.commit451.gitlab.model.Account
Loading
Loading
@@ -56,7 +55,7 @@ class LaunchActivity : BaseActivity() {
if (accounts.isEmpty()) {
Navigator.navigateToLogin(this)
finish()
} else if (Prefs.isRequiredDeviceAuth()) {
} else if (Prefs.isRequiredDeviceAuth) {
showKeyguard()
} else {
if (PRIVATE_KEY_ENABLED) {
Loading
Loading
Loading
Loading
@@ -122,7 +122,7 @@ class ProjectActivity : BaseActivity() {
 
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Prefs.setStartingView(Prefs.STARTING_VIEW_PROJECTS)
Prefs.startingView = Prefs.STARTING_VIEW_PROJECTS
setContentView(R.layout.activity_project)
ButterKnife.bind(this)
var project: Project? = Parcels.unwrap<Project>(intent.getParcelableExtra<Parcelable>(EXTRA_PROJECT))
Loading
Loading
Loading
Loading
@@ -52,10 +52,12 @@ class SettingsActivity : BaseActivity() {
}
 
bindPrefs()
switchRequireAuth.setOnCheckedChangeListener { compoundButton, b -> Prefs.setRequiredDeviceAuth(b) }
switchRequireAuth.setOnCheckedChangeListener { compoundButton, b ->
Prefs.isRequiredDeviceAuth = b
}
}
 
fun bindPrefs() {
switchRequireAuth.isChecked = Prefs.isRequiredDeviceAuth()
switchRequireAuth.isChecked = Prefs.isRequiredDeviceAuth
}
}
Loading
Loading
@@ -44,7 +44,7 @@ class TodosActivity : BaseActivity() {
 
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Prefs.setStartingView(Prefs.STARTING_VIEW_TODOS)
Prefs.startingView = Prefs.STARTING_VIEW_TODOS
setContentView(R.layout.activity_todos)
ButterKnife.bind(this)
App.bus().register(this)
Loading
Loading
Loading
Loading
@@ -30,7 +30,7 @@ object Prefs {
 
lateinit private var prefs: SharedPreferences
 
fun init(context : Context) {
fun init(context: Context) {
if (context !is Application) {
throw IllegalArgumentException("This should be the application context. Not the activity context")
}
Loading
Loading
@@ -83,25 +83,16 @@ object Prefs {
setAccounts(accounts)
}
 
fun getStartingView(): Int {
@StartingView
val start = prefs.getInt(KEY_STARTING_VIEW, STARTING_VIEW_PROJECTS)
return start
}
fun setStartingView(@StartingView startingView: Int) {
prefs.edit()
.putInt(KEY_STARTING_VIEW, startingView)
@StartingView
var startingView: Int
get() = prefs.getInt(KEY_STARTING_VIEW, STARTING_VIEW_PROJECTS)
set(value) = prefs.edit()
.putInt(KEY_STARTING_VIEW, value)
.apply()
}
 
fun isRequiredDeviceAuth(): Boolean {
return prefs.getBoolean(KEY_REQUIRE_DEVICE_AUTH, false)
}
fun setRequiredDeviceAuth(require: Boolean) {
prefs.edit()
.putBoolean(KEY_REQUIRE_DEVICE_AUTH, require)
var isRequiredDeviceAuth: Boolean
get() = prefs.getBoolean(KEY_REQUIRE_DEVICE_AUTH, false)
set(value) = prefs.edit()
.putBoolean(KEY_REQUIRE_DEVICE_AUTH, value)
.apply()
}
}
Loading
Loading
@@ -52,7 +52,7 @@ object Navigator {
}
 
fun navigateToStartingActivity(activity: Activity) {
val startingActivity = Prefs.getStartingView()
val startingActivity = Prefs.startingView
when (startingActivity) {
Prefs.STARTING_VIEW_PROJECTS -> navigateToProjects(activity)
Prefs.STARTING_VIEW_GROUPS -> navigateToGroups(activity)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment